Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
mediastreamer2
Commits
619849fd
Commit
619849fd
authored
Apr 25, 2018
by
François Grisez
Browse files
Refactor naming
parent
aede223b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
111 additions
and
111 deletions
+111
-111
src/videofilters/h264dec.cpp
src/videofilters/h264dec.cpp
+6
-6
src/videofilters/mkv.cpp
src/videofilters/mkv.cpp
+5
-5
src/voip/rfc3984.cpp
src/voip/rfc3984.cpp
+50
-50
src/voip/rfc3984.hpp
src/voip/rfc3984.hpp
+50
-50
No files found.
src/videofilters/h264dec.cpp
View file @
619849fd
...
...
@@ -50,7 +50,7 @@ using namespace b64;
typedef
struct
_DecData
{
mblk_t
*
sps
,
*
pps
;
AVFrame
*
orig
;
Rfc3984
Unpacker
*
unpacker
;
H264Nal
Unpacker
*
unpacker
;
MSVideoSize
vsize
;
struct
SwsContext
*
sws_ctx
;
MSAverageFPS
fps
;
...
...
@@ -90,7 +90,7 @@ static void dec_init(MSFilter *f){
d
->
sps
=
NULL
;
d
->
pps
=
NULL
;
d
->
sws_ctx
=
NULL
;
d
->
unpacker
=
new
Rfc3984
Unpacker
();
d
->
unpacker
=
new
H264Nal
Unpacker
();
d
->
packet_num
=
0
;
dec_open
(
d
);
d
->
vsize
.
width
=
0
;
...
...
@@ -288,7 +288,7 @@ static void dec_process(MSFilter *f){
// Reset all contexts when an empty packet is received
if
(
msgdsize
(
im
)
==
0
)
{
delete
d
->
unpacker
;
d
->
unpacker
=
new
Rfc3984
Unpacker
();
d
->
unpacker
=
new
H264Nal
Unpacker
();
dec_reinit
(
d
);
ms_stream_regulator_reset
(
d
->
regulator
);
freemsg
(
im
);
...
...
@@ -300,9 +300,9 @@ static void dec_process(MSFilter *f){
d
->
sps
=
NULL
;
d
->
pps
=
NULL
;
}
Rfc3984
Unpacker
::
Status
ret
=
d
->
unpacker
->
unpack
(
im
,
&
nalus
);
H264Nal
Unpacker
::
Status
ret
=
d
->
unpacker
->
unpack
(
im
,
&
nalus
);
if
(
ret
.
test
(
Unpacker
::
StatusFlag
::
FrameAvailable
)){
if
(
ret
.
test
(
Nal
Unpacker
::
StatusFlag
::
FrameAvailable
)){
int
size
;
uint8_t
*
p
,
*
end
;
bool_t
need_reinit
=
FALSE
;
...
...
@@ -338,7 +338,7 @@ static void dec_process(MSFilter *f){
}
p
+=
len
;
}
if
(
ret
.
test
(
Unpacker
::
StatusFlag
::
FrameCorrupted
))
requestPLI
=
TRUE
;
if
(
ret
.
test
(
Nal
Unpacker
::
StatusFlag
::
FrameCorrupted
))
requestPLI
=
TRUE
;
}
d
->
packet_num
++
;
}
...
...
src/videofilters/mkv.cpp
View file @
619849fd
...
...
@@ -283,17 +283,17 @@ static void H264Private_load(H264Private *obj, const uint8_t *data) {
/* h264 module */
typedef
struct
{
Rfc3984
Packer
*
packer
;
Rfc3984
Unpacker
*
unpacker
;
H264Nal
Packer
*
packer
;
H264Nal
Unpacker
*
unpacker
;
H264Private
*
codecPrivate
;
H264Private
*
lastCodecPrivate
;
}
H264Module
;
static
void
*
h264_module_new
(
MSFactory
*
factory
)
{
H264Module
*
mod
=
bctbx_new0
(
H264Module
,
1
);
mod
->
packer
=
new
Rfc3984
Packer
(
factory
);
mod
->
packer
->
setMode
(
Packer
::
NonInterleavedMode
);
mod
->
unpacker
=
new
Rfc3984
Unpacker
();
mod
->
packer
=
new
H264Nal
Packer
(
factory
);
mod
->
packer
->
set
Packetization
Mode
(
Nal
Packer
::
NonInterleavedMode
);
mod
->
unpacker
=
new
H264Nal
Unpacker
();
return
mod
;
}
...
...
src/voip/rfc3984.cpp
View file @
619849fd
...
...
@@ -34,18 +34,18 @@ namespace mediastreamer2 {
// Packer
// ======
Packer
::
Packer
(
SpliterInterface
*
s
pliter
,
AggregatorInterface
*
a
ggregator
,
MSFactory
*
factory
)
:
_
s
pliter
(
s
pliter
),
_
a
ggregator
(
a
ggregator
)
{
Nal
Packer
::
Nal
Packer
(
Nalu
SpliterInterface
*
naluS
pliter
,
Nalu
AggregatorInterface
*
naluA
ggregator
,
MSFactory
*
factory
)
:
_
naluS
pliter
(
naluS
pliter
),
_
naluA
ggregator
(
naluA
ggregator
)
{
setMaxPayloadSize
(
ms_factory_get_payload_max_size
(
factory
));
}
void
Packer
::
setMaxPayloadSize
(
size_t
size
)
{
void
Nal
Packer
::
setMaxPayloadSize
(
size_t
size
)
{
_maxSize
=
size
;
_
s
pliter
->
setMaxSize
(
size
);
_
a
ggregator
->
setMaxSize
(
size
);
_
naluS
pliter
->
setMaxSize
(
size
);
_
naluA
ggregator
->
setMaxSize
(
size
);
}
void
Packer
::
pack
(
MSQueue
*
naluq
,
MSQueue
*
rtpq
,
uint32_t
ts
)
{
switch
(
_
m
ode
)
{
void
Nal
Packer
::
pack
(
MSQueue
*
naluq
,
MSQueue
*
rtpq
,
uint32_t
ts
)
{
switch
(
_
packM
ode
)
{
case
SingleNalUnitMode
:
packInSingleNalUnitMode
(
naluq
,
rtpq
,
ts
);
break
;
...
...
@@ -56,7 +56,7 @@ void Packer::pack(MSQueue *naluq, MSQueue *rtpq, uint32_t ts) {
}
// Private methods
void
Packer
::
packInSingleNalUnitMode
(
MSQueue
*
naluq
,
MSQueue
*
rtpq
,
uint32_t
ts
)
{
void
Nal
Packer
::
packInSingleNalUnitMode
(
MSQueue
*
naluq
,
MSQueue
*
rtpq
,
uint32_t
ts
)
{
while
(
mblk_t
*
m
=
ms_queue_get
(
naluq
))
{
bool
end
=
ms_queue_empty
(
naluq
);
size_t
size
=
msgdsize
(
m
);
...
...
@@ -67,19 +67,19 @@ void Packer::packInSingleNalUnitMode(MSQueue *naluq, MSQueue *rtpq, uint32_t ts)
}
}
void
Packer
::
packInNonInterleavedMode
(
MSQueue
*
naluq
,
MSQueue
*
rtpq
,
uint32_t
ts
)
{
void
Nal
Packer
::
packInNonInterleavedMode
(
MSQueue
*
naluq
,
MSQueue
*
rtpq
,
uint32_t
ts
)
{
while
(
mblk_t
*
m
=
ms_queue_get
(
naluq
))
{
bool
end
=
ms_queue_empty
(
naluq
);
size_t
sz
=
msgdsize
(
m
);
if
(
_aggregationEnabled
)
{
if
(
_
a
ggregator
->
isAggregating
())
{
mblk_t
*
stapPacket
=
_
a
ggregator
->
feed
Nalu
(
m
);
if
(
_
naluA
ggregator
->
isAggregating
())
{
mblk_t
*
stapPacket
=
_
naluA
ggregator
->
feed
(
m
);
if
(
stapPacket
)
{
sendPacket
(
rtpq
,
ts
,
stapPacket
,
false
);
}
else
continue
;
}
if
(
sz
<
(
_maxSize
/
2
))
{
_
a
ggregator
->
feed
Nalu
(
m
);
_
naluA
ggregator
->
feed
(
m
);
}
else
{
/*send as single NAL or FU-A*/
if
(
sz
>
_maxSize
)
{
...
...
@@ -100,21 +100,21 @@ void Packer::packInNonInterleavedMode(MSQueue *naluq, MSQueue *rtpq, uint32_t ts
}
}
}
if
(
_
a
ggregator
->
isAggregating
())
{
if
(
_
naluA
ggregator
->
isAggregating
())
{
ms_debug
(
"Sending Single NAL (2)"
);
sendPacket
(
rtpq
,
ts
,
_
a
ggregator
->
completeAggregation
(),
true
);
sendPacket
(
rtpq
,
ts
,
_
naluA
ggregator
->
completeAggregation
(),
true
);
}
}
void
Packer
::
fragNaluAndSend
(
MSQueue
*
rtpq
,
uint32_t
ts
,
mblk_t
*
nalu
,
bool_t
marker
)
{
_
s
pliter
->
feed
Nalu
(
nalu
);
MSQueue
*
nalus
=
_
s
pliter
->
get
Nalu
s
();
void
Nal
Packer
::
fragNaluAndSend
(
MSQueue
*
rtpq
,
uint32_t
ts
,
mblk_t
*
nalu
,
bool_t
marker
)
{
_
naluS
pliter
->
feed
(
nalu
);
MSQueue
*
nalus
=
_
naluS
pliter
->
get
Packet
s
();
while
(
mblk_t
*
m
=
ms_queue_get
(
nalus
))
{
sendPacket
(
rtpq
,
ts
,
m
,
ms_queue_empty
(
nalus
)
?
marker
:
false
);
}
}
void
Packer
::
sendPacket
(
MSQueue
*
rtpq
,
uint32_t
ts
,
mblk_t
*
m
,
bool_t
marker
)
{
void
Nal
Packer
::
sendPacket
(
MSQueue
*
rtpq
,
uint32_t
ts
,
mblk_t
*
m
,
bool_t
marker
)
{
mblk_set_timestamp_info
(
m
,
ts
);
mblk_set_marker_info
(
m
,
marker
);
mblk_set_cseq
(
m
,
_refCSeq
++
);
...
...
@@ -125,14 +125,14 @@ void Packer::sendPacket(MSQueue *rtpq, uint32_t ts, mblk_t *m, bool_t marker) {
// H264NaluToStapAggregator
// ========================
void
H264Nalu
ToStap
Aggregator
::
setMaxSize
(
size_t
maxSize
)
{
void
H264NaluAggregator
::
setMaxSize
(
size_t
maxSize
)
{
if
(
isAggregating
())
{
throw
logic_error
(
"changing payload size while aggregating NALus into a STAP-A"
);
}
_maxsize
=
maxSize
;
}
mblk_t
*
H264Nalu
ToStap
Aggregator
::
feed
Nalu
(
mblk_t
*
nalu
)
{
mblk_t
*
H264NaluAggregator
::
feed
(
mblk_t
*
nalu
)
{
size_t
size
=
msgdsize
(
nalu
);
if
(
_stap
==
nullptr
)
{
_stap
=
nalu
;
...
...
@@ -148,12 +148,12 @@ mblk_t *H264NaluToStapAggregator::feedNalu(mblk_t *nalu) {
return
nullptr
;
}
void
H264Nalu
ToStap
Aggregator
::
reset
()
{
void
H264NaluAggregator
::
reset
()
{
if
(
_stap
)
freemsg
(
_stap
);
_size
=
0
;
}
mblk_t
*
H264Nalu
ToStap
Aggregator
::
completeAggregation
()
{
mblk_t
*
H264NaluAggregator
::
completeAggregation
()
{
mblk_t
*
res
=
_stap
;
_stap
=
nullptr
;
reset
();
...
...
@@ -161,7 +161,7 @@ mblk_t *H264NaluToStapAggregator::completeAggregation() {
}
mblk_t
*
H264Nalu
ToStap
Aggregator
::
concatNalus
(
mblk_t
*
m1
,
mblk_t
*
m2
)
{
mblk_t
*
H264NaluAggregator
::
concatNalus
(
mblk_t
*
m1
,
mblk_t
*
m2
)
{
mblk_t
*
l
=
allocb
(
2
,
0
);
/*eventually append a STAP-A header to m1, if not already done*/
if
(
ms_h264_nalu_get_type
(
m1
)
!=
MSH264NaluTypeSTAPA
)
{
...
...
@@ -173,7 +173,7 @@ mblk_t *H264NaluToStapAggregator::concatNalus(mblk_t *m1, mblk_t *m2) {
return
m1
;
}
mblk_t
*
H264Nalu
ToStap
Aggregator
::
prependStapA
(
mblk_t
*
m
)
{
mblk_t
*
H264NaluAggregator
::
prependStapA
(
mblk_t
*
m
)
{
mblk_t
*
hm
=
allocb
(
3
,
0
);
H264Tools
::
nalHeaderInit
(
hm
->
b_wptr
,
ms_h264_nalu_get_nri
(
m
),
MSH264NaluTypeSTAPA
);
hm
->
b_wptr
+=
1
;
...
...
@@ -182,7 +182,7 @@ mblk_t *H264NaluToStapAggregator::prependStapA(mblk_t *m) {
return
hm
;
}
void
H264Nalu
ToStap
Aggregator
::
putNalSize
(
mblk_t
*
m
,
size_t
sz
)
{
void
H264NaluAggregator
::
putNalSize
(
mblk_t
*
m
,
size_t
sz
)
{
uint16_t
size
=
htons
((
uint16_t
)
sz
);
*
(
uint16_t
*
)
m
->
b_wptr
=
size
;
m
->
b_wptr
+=
2
;
...
...
@@ -192,7 +192,7 @@ void H264NaluToStapAggregator::putNalSize(mblk_t *m, size_t sz) {
// H264NalToFuaSpliter class
// =========================
void
H264Nalu
ToFua
Spliter
::
feed
Nalu
(
mblk_t
*
nalu
)
{
void
H264NaluSpliter
::
feed
(
mblk_t
*
nalu
)
{
mblk_t
*
m
;
int
payload_max_size
=
_maxsize
-
2
;
/*minus FU-A header*/
uint8_t
fu_indicator
;
...
...
@@ -214,15 +214,15 @@ void H264NaluToFuaSpliter::feedNalu(mblk_t *nalu) {
ms_queue_put
(
&
_q
,
m
);
}
// ========
// Unpacker
// ========
// ========
======
// Unpacker
class
// ========
======
Unpacker
::
Unpacker
(
AggregatorInterface
*
aggregator
,
SpliterInterface
*
spliter
)
:
_
nal
uAggregator
(
aggregator
),
_
nalu
Spliter
(
spliter
)
{
Nal
Unpacker
::
Nal
Unpacker
(
Fu
AggregatorInterface
*
aggregator
,
Ap
SpliterInterface
*
spliter
)
:
_
f
uAggregator
(
aggregator
),
_
ap
Spliter
(
spliter
)
{
ms_queue_init
(
&
_q
);
}
Unpacker
::
Status
Unpacker
::
unpack
(
mblk_t
*
im
,
MSQueue
*
out
)
{
Nal
Unpacker
::
Status
Nal
Unpacker
::
unpack
(
mblk_t
*
im
,
MSQueue
*
out
)
{
PacketType
type
=
getNaluType
(
im
);
int
marker
=
mblk_get_marker_info
(
im
);
uint32_t
ts
=
mblk_get_timestamp_info
(
im
);
...
...
@@ -233,7 +233,7 @@ Unpacker::Status Unpacker::unpack(mblk_t *im, MSQueue *out) {
/*a new frame is arriving, in case the marker bit was not set in previous frame, output it now,
* unless it is a FU-A packet (workaround for buggy implementations)*/
_lastTs
=
ts
;
if
(
!
_
nal
uAggregator
->
isAggregating
()
&&
!
ms_queue_empty
(
&
_q
))
{
if
(
!
_
f
uAggregator
->
isAggregating
()
&&
!
ms_queue_empty
(
&
_q
))
{
Status
status
;
status
.
set
(
StatusFlag
::
FrameAvailable
).
set
(
StatusFlag
::
FrameCorrupted
);
ret
=
outputFrame
(
out
,
status
);
...
...
@@ -258,21 +258,21 @@ Unpacker::Status Unpacker::unpack(mblk_t *im, MSQueue *out) {
switch
(
type
)
{
case
PacketType
::
SingleNalUnit
:
_
nal
uAggregator
->
reset
();
_
f
uAggregator
->
reset
();
/*single nal unit*/
ms_debug
(
"Receiving single NAL"
);
storeNal
(
im
);
break
;
case
PacketType
::
FragmentationUnit
:
{
ms_debug
(
"Receiving FU-A"
);
mblk_t
*
o
=
_
nal
uAggregator
->
feed
Nalu
(
im
);
mblk_t
*
o
=
_
f
uAggregator
->
feed
(
im
);
if
(
o
)
storeNal
(
o
);
break
;
}
case
PacketType
::
AggregationPacket
:
ms_debug
(
"Receiving STAP-A"
);
_
nalu
Spliter
->
feed
Nalu
(
im
);
while
((
im
=
ms_queue_get
(
_
nalu
Spliter
->
getNalus
())))
{
_
ap
Spliter
->
feed
(
im
);
while
((
im
=
ms_queue_get
(
_
ap
Spliter
->
getNalus
())))
{
storeNal
(
im
);
}
break
;
...
...
@@ -289,7 +289,7 @@ Unpacker::Status Unpacker::unpack(mblk_t *im, MSQueue *out) {
return
ret
;
}
Unpacker
::
Status
Unpacker
::
outputFrame
(
MSQueue
*
out
,
const
Status
&
flags
)
{
Nal
Unpacker
::
Status
Nal
Unpacker
::
outputFrame
(
MSQueue
*
out
,
const
Status
&
flags
)
{
Status
res
=
_status
;
if
(
!
ms_queue_empty
(
out
))
{
ms_warning
(
"rfc3984_unpack: output_frame invoked several times in a row, this should not happen"
);
...
...
@@ -302,7 +302,7 @@ Unpacker::Status Unpacker::outputFrame(MSQueue *out, const Status &flags) {
return
res
;
}
void
Unpacker
::
storeNal
(
mblk_t
*
nal
)
{
void
Nal
Unpacker
::
storeNal
(
mblk_t
*
nal
)
{
ms_queue_put
(
&
_q
,
nal
);
}
...
...
@@ -322,7 +322,7 @@ mblk_t *H264Tools::prependFuIndicatorAndHeader(mblk_t *m, uint8_t indicator, boo
// =======================
// H264FUAAggregator class
// =======================
mblk_t
*
H264F
UA
Aggregator
::
feed
Nalu
(
mblk_t
*
im
)
{
mblk_t
*
H264F
ua
Aggregator
::
feed
(
mblk_t
*
im
)
{
mblk_t
*
om
=
nullptr
;
uint8_t
fu_header
;
uint8_t
nri
,
type
;
...
...
@@ -368,14 +368,14 @@ mblk_t *H264FUAAggregator::feedNalu(mblk_t *im) {
return
om
;
}
void
H264F
UA
Aggregator
::
reset
()
{
void
H264F
ua
Aggregator
::
reset
()
{
if
(
_m
)
{
freemsg
(
_m
);
_m
=
nullptr
;
}
}
mblk_t
*
H264F
UA
Aggregator
::
completeAggregation
()
{
mblk_t
*
H264F
ua
Aggregator
::
completeAggregation
()
{
mblk_t
*
res
=
_m
;
_m
=
nullptr
;
return
res
;
...
...
@@ -385,7 +385,7 @@ mblk_t *H264FUAAggregator::completeAggregation() {
// H264StapASlicer class
// =====================
void
H264Stap
A
Spliter
::
feed
Nalu
(
mblk_t
*
im
)
{
void
H264Stap
a
Spliter
::
feed
(
mblk_t
*
im
)
{
uint16_t
sz
;
for
(
uint8_t
*
p
=
im
->
b_rptr
+
1
;
p
<
im
->
b_wptr
;)
{
memcpy
(
&
sz
,
p
,
2
);
...
...
@@ -412,12 +412,12 @@ void H264StapASpliter::feedNalu(mblk_t *im) {
// Public methods
// --------------
Rfc3984
Unpacker
::~
Rfc3984
Unpacker
()
{
H264Nal
Unpacker
::~
H264Nal
Unpacker
()
{
if
(
_sps
!=
nullptr
)
freemsg
(
_sps
);
if
(
_pps
!=
nullptr
)
freemsg
(
_pps
);
}
void
Rfc3984
Unpacker
::
setOutOfBandSpsPps
(
mblk_t
*
sps
,
mblk_t
*
pps
)
{
void
H264Nal
Unpacker
::
setOutOfBandSpsPps
(
mblk_t
*
sps
,
mblk_t
*
pps
)
{
if
(
_sps
)
freemsg
(
_sps
);
if
(
_pps
)
freemsg
(
_pps
);
_sps
=
sps
;
...
...
@@ -427,7 +427,7 @@ void Rfc3984Unpacker::setOutOfBandSpsPps(mblk_t *sps, mblk_t *pps) {
// Private methods
// ---------------
Unpacker
::
PacketType
Rfc3984
Unpacker
::
getNaluType
(
const
mblk_t
*
nalu
)
const
{
Nal
Unpacker
::
PacketType
H264Nal
Unpacker
::
getNaluType
(
const
mblk_t
*
nalu
)
const
{
switch
(
ms_h264_nalu_get_type
(
nalu
))
{
case
MSH264NaluTypeFUA
:
return
PacketType
::
FragmentationUnit
;
case
MSH264NaluTypeSTAPA
:
return
PacketType
::
AggregationPacket
;
...
...
@@ -435,16 +435,16 @@ Unpacker::PacketType Rfc3984Unpacker::getNaluType(const mblk_t *nalu) const {
}
}
Rfc3984
Unpacker
::
Status
Rfc3984
Unpacker
::
outputFrame
(
MSQueue
*
out
,
const
Status
&
flags
)
{
H264Nal
Unpacker
::
Status
H264Nal
Unpacker
::
outputFrame
(
MSQueue
*
out
,
const
Status
&
flags
)
{
Status
res
=
_status
;
if
(
res
.
test
(
Unpacker
::
StatusFlag
::
IsKeyFrame
)
&&
_sps
&&
_pps
)
{
if
(
res
.
test
(
Nal
Unpacker
::
StatusFlag
::
IsKeyFrame
)
&&
_sps
&&
_pps
)
{
/*prepend out of band provided sps and pps*/
ms_queue_put
(
out
,
_sps
);
ms_queue_put
(
out
,
_pps
);
_sps
=
NULL
;
_pps
=
NULL
;
}
Unpacker
::
outputFrame
(
out
,
flags
);
Nal
Unpacker
::
outputFrame
(
out
,
flags
);
return
res
;
}
...
...
@@ -457,8 +457,8 @@ Rfc3984Unpacker::Status Rfc3984Unpacker::outputFrame(MSQueue *out, const Status
struct
_Rfc3984Context
{
mediastreamer2
::
Rfc3984
Packer
packer
;
mediastreamer2
::
Rfc3984
Unpacker
unpacker
;
mediastreamer2
::
H264Nal
Packer
packer
;
mediastreamer2
::
H264Nal
Unpacker
unpacker
;
mediastreamer2
::
H264FrameAnalyser
analyser
;
_Rfc3984Context
()
=
default
;
...
...
@@ -484,7 +484,7 @@ extern "C" {
ms_error
(
"invalid RFC3984 packetization mode [%d]"
,
mode
);
return
;
}
ctx
->
packer
.
setMode
(
mode
==
0
?
mediastreamer2
::
Packer
::
SingleNalUnitMode
:
mediastreamer2
::
Packer
::
SingleNalUnitMode
);
ctx
->
packer
.
set
Packetization
Mode
(
mode
==
0
?
mediastreamer2
::
Nal
Packer
::
SingleNalUnitMode
:
mediastreamer2
::
Nal
Packer
::
SingleNalUnitMode
);
}
void
rfc3984_enable_stap_a
(
Rfc3984Context
*
ctx
,
bool_t
yesno
)
{
...
...
src/voip/rfc3984.hpp
View file @
619849fd
...
...
@@ -33,42 +33,42 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
namespace
mediastreamer2
{
class
Packer
{
class
Nal
Packer
{
public:
enum
PacketizationMode
{
SingleNalUnitMode
,
NonInterleavedMode
};
class
AggregatorInterface
{
class
Nalu
AggregatorInterface
{
public:
virtual
~
AggregatorInterface
()
=
default
;
virtual
~
Nalu
AggregatorInterface
()
=
default
;
virtual
size_t
getMaxSize
()
const
=
0
;
virtual
void
setMaxSize
(
size_t
maxSize
)
=
0
;
virtual
mblk_t
*
feed
Nalu
(
mblk_t
*
nalu
)
=
0
;
virtual
mblk_t
*
feed
(
mblk_t
*
nalu
)
=
0
;
virtual
bool
isAggregating
()
const
=
0
;
virtual
void
reset
()
=
0
;
virtual
mblk_t
*
completeAggregation
()
=
0
;
};
class
SpliterInterface
{
class
Nalu
SpliterInterface
{
public:
virtual
~
SpliterInterface
()
=
default
;
virtual
~
Nalu
SpliterInterface
()
=
default
;
virtual
size_t
getMaxSize
()
const
=
0
;
virtual
void
setMaxSize
(
size_t
maxSize
)
=
0
;
virtual
void
feed
Nalu
(
mblk_t
*
nalu
)
=
0
;
virtual
MSQueue
*
get
Nalu
s
()
=
0
;
virtual
void
feed
(
mblk_t
*
nalu
)
=
0
;
virtual
MSQueue
*
get
Packet
s
()
=
0
;
};
Packer
(
SpliterInterface
*
s
pliter
,
AggregatorInterface
*
a
ggregator
)
{}
Packer
(
SpliterInterface
*
s
pliter
,
AggregatorInterface
*
a
ggregator
,
MSFactory
*
factory
);
Nal
Packer
(
Nalu
SpliterInterface
*
naluS
pliter
,
Nalu
AggregatorInterface
*
naluAggregator
)
:
_naluSpliter
(
naluSpliter
),
_naluAggregator
(
naluA
ggregator
)
{}
Nal
Packer
(
Nalu
SpliterInterface
*
naluS
pliter
,
Nalu
AggregatorInterface
*
naluA
ggregator
,
MSFactory
*
factory
);
void
setMode
(
PacketizationMode
m
ode
)
{
_
m
ode
=
m
ode
;}
PacketizationMode
getMode
()
const
{
return
_
m
ode
;}
void
set
Packetization
Mode
(
PacketizationMode
packM
ode
)
{
_
packM
ode
=
packM
ode
;}
PacketizationMode
get
Packetization
Mode
()
const
{
return
_
packM
ode
;}
// some stupid phones don't decode STAP-A packets ...
void
enableAggregation
(
bool
yesno
)
{
_aggregationEnabled
=
yesno
;}
...
...
@@ -80,7 +80,7 @@ public:
// process NALus and pack them into RTP payloads
void
pack
(
MSQueue
*
naluq
,
MSQueue
*
rtpq
,
uint32_t
ts
);
pr
ivate
:
pr
otected
:
void
packInSingleNalUnitMode
(
MSQueue
*
naluq
,
MSQueue
*
rtpq
,
uint32_t
ts
);
void
packInNonInterleavedMode
(
MSQueue
*
naluq
,
MSQueue
*
rtpq
,
uint32_t
ts
);
void
fragNaluAndSend
(
MSQueue
*
rtpq
,
uint32_t
ts
,
mblk_t
*
nalu
,
bool_t
marker
);
...
...
@@ -88,21 +88,21 @@ private:
size_t
_maxSize
=
MS_DEFAULT_MAX_PAYLOAD_SIZE
;
uint16_t
_refCSeq
=
0
;
PacketizationMode
_
m
ode
=
SingleNalUnitMode
;
PacketizationMode
_
packM
ode
=
SingleNalUnitMode
;
bool
_aggregationEnabled
=
false
;
std
::
unique_ptr
<
SpliterInterface
>
_
s
pliter
;
std
::
unique_ptr
<
AggregatorInterface
>
_
a
ggregator
;
std
::
unique_ptr
<
Nalu
SpliterInterface
>
_
naluS
pliter
;
std
::
unique_ptr
<
Nalu
AggregatorInterface
>
_
naluA
ggregator
;
};
class
H264Nalu
ToStap
Aggregator
:
public
Packer
::
AggregatorInterface
{
class
H264NaluAggregator
:
public
Nal
Packer
::
Nalu
AggregatorInterface
{
public:
H264Nalu
ToStap
Aggregator
()
{}
~
H264Nalu
ToStap
Aggregator
()
{
reset
();}
H264NaluAggregator
()
{}
~
H264NaluAggregator
()
{
reset
();}
size_t
getMaxSize
()
const
override
{
return
_maxsize
;}
void
setMaxSize
(
size_t
maxSize
)
override
;
mblk_t
*
feed
Nalu
(
mblk_t
*
nalu
)
override
;
mblk_t
*
feed
(
mblk_t
*
nalu
)
override
;
bool
isAggregating
()
const
override
{
return
bool
(
_stap
);}
void
reset
()
override
;
mblk_t
*
completeAggregation
()
override
;
...
...
@@ -117,34 +117,34 @@ private:
size_t
_maxsize
=
MS_DEFAULT_MAX_PAYLOAD_SIZE
;
};
class
H264Nalu
ToFua
Spliter
:
public
Packer
::
SpliterInterface
{
class
H264NaluSpliter
:
public
Nal
Packer
::
Nalu
SpliterInterface
{
public:
H264Nalu
ToFua
Spliter
()
{
ms_queue_init
(
&
_q
);}
~
H264Nalu
ToFua
Spliter
()
{
ms_queue_flush
(
&
_q
);}
H264NaluSpliter
()
{
ms_queue_init
(
&
_q
);}
~
H264NaluSpliter
()
{
ms_queue_flush
(
&
_q
);}
size_t
getMaxSize
()
const
override
{
return
_maxsize
;}
void
setMaxSize
(
size_t
maxSize
)
override
{
_maxsize
=
maxSize
;}
void
feed
Nalu
(
mblk_t
*
nalu
)
override
;
MSQueue
*
get
Nalu
s
()
override
{
return
&
_q
;};
void
feed
(
mblk_t
*
nalu
)
override
;
MSQueue
*
get
Packet
s
()
override
{
return
&
_q
;};
private:
size_t
_maxsize
=
MS_DEFAULT_MAX_PAYLOAD_SIZE
;
MSQueue
_q
;
};
class
Rfc3984
Packer
:
public
Packer
{
class
H264Nal
Packer
:
public
Nal
Packer
{
public:
enum
PacketizationMode
{
SingleNalUnitMode
,
NonInterleavedMode
};
Rfc3984
Packer
()
:
Packer
(
new
H264Nalu
ToFua
Spliter
(),
new
H264Nalu
ToStap
Aggregator
())
{}
Rfc3984
Packer
(
MSFactory
*
factory
)
:
Packer
(
new
H264Nalu
ToFua
Spliter
(),
new
H264Nalu
ToStap
Aggregator
(),
factory
)
{}
H264Nal
Packer
()
:
Nal
Packer
(
new
H264NaluSpliter
(),
new
H264NaluAggregator
())
{}
H264Nal
Packer
(
MSFactory
*
factory
)
:
Nal
Packer
(
new
H264NaluSpliter
(),
new
H264NaluAggregator
(),
factory
)
{}
};
class
Unpacker
{
class
Nal
Unpacker
{
public:
class
StatusFlag
{
public:
...
...
@@ -154,24 +154,24 @@ public:
};
typedef
std
::
bitset
<
3
>
Status
;
class
AggregatorInterface
{
class
Fu
AggregatorInterface
{
public:
virtual
~
AggregatorInterface
()
=
default
;
virtual
mblk_t
*
feed
Nalu
(
mblk_t
*
nalu
)
=
0
;
virtual
~
Fu
AggregatorInterface
()
=
default
;
virtual
mblk_t
*
feed
(
mblk_t
*
packet
)
=
0
;
virtual
bool
isAggregating
()
const
=
0
;
virtual
void
reset
()
=
0
;
virtual
mblk_t
*
completeAggregation
()
=
0
;
};
class
SpliterInterface
{
class
Ap
SpliterInterface
{
public:
virtual
~
SpliterInterface
()
=
default
;
virtual
void
feed
Nalu
(
mblk_t
*
nalu
)
=
0
;
virtual
~
Ap
SpliterInterface
()
=
default
;
virtual
void
feed
(
mblk_t
*
packet
)
=
0
;
virtual
MSQueue
*
getNalus
()
=
0
;
};
Unpacker
(
AggregatorInterface
*
aggregator
,
SpliterInterface
*
spliter
);
virtual
~
Unpacker
()
{
ms_queue_flush
(
&
_q
);}
Nal
Unpacker
(
Fu
AggregatorInterface
*
aggregator
,
Ap
SpliterInterface
*
spliter
);
virtual
~
Nal
Unpacker
()
{
ms_queue_flush
(
&
_q
);}
/**
* Process incoming rtp data and output NALUs, whenever possible.
...
...
@@ -200,8 +200,8 @@ protected:
uint32_t
_lastTs
=
0x943FEA43
;
bool
_initializedRefCSeq
=
false
;
uint16_t
_refCSeq
=
0
;
std
::
unique_ptr
<
AggregatorInterface
>
_
nal
uAggregator
;
std
::
unique_ptr
<
SpliterInterface
>
_
nalu
Spliter
;
std
::
unique_ptr
<
Fu
AggregatorInterface
>
_
f
uAggregator
;
std
::
unique_ptr
<
Ap
SpliterInterface
>
_
ap
Spliter
;
};
class
H264Tools
{
...
...
@@ -210,10 +210,10 @@ public:
static
mblk_t
*
prependFuIndicatorAndHeader
(
mblk_t
*
m
,
uint8_t
indicator
,
bool_t
start
,
bool_t
end
,
uint8_t
type
);
};
class
H264F
UA
Aggregator
:
public
Unpacker
::
AggregatorInterface
{
class
H264F
ua
Aggregator
:
public
Nal
Unpacker
::
Fu
AggregatorInterface
{
public:
~
H264F
UA
Aggregator
()
{
if
(
_m
)
freemsg
(
_m
);}
mblk_t
*
feed
Nalu
(
mblk_t
*
im
)
override
;
~
H264F
ua
Aggregator
()
{
if
(
_m
)
freemsg
(
_m
);}
mblk_t
*
feed
(
mblk_t
*
im
)
override
;
bool
isAggregating
()
const
override
{
return
_m
!=
nullptr
;}
void
reset
()
override
;
mblk_t
*
completeAggregation
()
override
;
...
...
@@ -222,26 +222,26 @@ private:
mblk_t
*
_m
=
nullptr
;
};
class
H264Stap
A
Spliter
:
public
Unpacker
::
SpliterInterface
{
class
H264Stap
a
Spliter
:
public
Nal
Unpacker
::
Ap
SpliterInterface
{
public:
H264Stap
A
Spliter
()
{
ms_queue_init
(
&
_q
);}
~
H264Stap
A
Spliter
()
{
ms_queue_flush
(
&
_q
);}
void
feed
Nalu
(
mblk_t
*
im
)
override
;
H264Stap
a
Spliter
()
{
ms_queue_init
(
&
_q
);}
~
H264Stap
a
Spliter
()
{
ms_queue_flush
(
&
_q
);}
void
feed
(
mblk_t
*
im
)
override
;
MSQueue
*
getNalus
()
override
{
return
&
_q
;}
private:
MSQueue
_q
;
};
class
Rfc3984
Unpacker
:
public
Unpacker
{
class
H264Nal
Unpacker
:
public
Nal
Unpacker
{
public:
Rfc3984
Unpacker
()
:
Unpacker
(
new
H264F
UA
Aggregator
(),
new
H264Stap
A
Spliter
())
{}
~
Rfc3984
Unpacker
();
H264Nal
Unpacker
()
:
Nal
Unpacker
(
new
H264F
ua
Aggregator
(),
new
H264Stap
a
Spliter
())
{}
~
H264Nal
Unpacker
();
void
setOutOfBandSpsPps
(
mblk_t
*
sps
,
mblk_t
*
pps
);