Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
a388e72d
Commit
a388e72d
authored
Feb 20, 2015
by
Martin Storsjö
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rtpenc_hevc: Aggregate multiple NAL units into one RTP packet, if possible
Signed-off-by:
Martin Storsjö
<
martin@martin.st
>
parent
e2220e73
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
2 deletions
+42
-2
rtpenc_hevc.c
libavformat/rtpenc_hevc.c
+42
-2
No files found.
libavformat/rtpenc_hevc.c
View file @
a388e72d
...
...
@@ -19,12 +19,28 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/intreadwrite.h"
#include "avc.h"
#include "avformat.h"
#include "rtpenc.h"
#define RTP_HEVC_HEADERS_SIZE 3
static
void
flush_buffered
(
AVFormatContext
*
s1
,
int
last
)
{
RTPMuxContext
*
s
=
s1
->
priv_data
;
if
(
s
->
buf_ptr
!=
s
->
buf
)
{
// If only sending one single NAL unit, skip the aggregation framing
if
(
s
->
buffered_nals
==
1
)
ff_rtp_send_data
(
s1
,
s
->
buf
+
4
,
s
->
buf_ptr
-
s
->
buf
-
4
,
last
);
else
ff_rtp_send_data
(
s1
,
s
->
buf
,
s
->
buf_ptr
-
s
->
buf
,
last
);
}
s
->
buf_ptr
=
s
->
buf
;
s
->
buffered_nals
=
0
;
}
static
void
nal_send
(
AVFormatContext
*
ctx
,
const
uint8_t
*
buf
,
int
len
,
int
last_packet_of_frame
)
{
RTPMuxContext
*
rtp_ctx
=
ctx
->
priv_data
;
...
...
@@ -33,9 +49,31 @@ static void nal_send(AVFormatContext *ctx, const uint8_t *buf, int len, int last
/* send it as one single NAL unit? */
if
(
len
<=
rtp_ctx
->
max_payload_size
)
{
/* use the original NAL unit buffer and transmit it as RTP payload */
ff_rtp_send_data
(
ctx
,
buf
,
len
,
last_packet_of_frame
);
int
buffered_size
=
rtp_ctx
->
buf_ptr
-
rtp_ctx
->
buf
;
/* Flush buffered NAL units if the current unit doesn't fit */
if
(
buffered_size
+
2
+
len
>
rtp_ctx
->
max_payload_size
)
{
flush_buffered
(
ctx
,
0
);
buffered_size
=
0
;
}
/* If the NAL unit fits including the framing, write the unit
* to the buffer as an aggregate packet, otherwise flush and
* send as single NAL. */
if
(
buffered_size
+
4
+
len
<=
rtp_ctx
->
max_payload_size
)
{
if
(
buffered_size
==
0
)
{
*
rtp_ctx
->
buf_ptr
++
=
48
<<
1
;
*
rtp_ctx
->
buf_ptr
++
=
1
;
}
AV_WB16
(
rtp_ctx
->
buf_ptr
,
len
);
rtp_ctx
->
buf_ptr
+=
2
;
memcpy
(
rtp_ctx
->
buf_ptr
,
buf
,
len
);
rtp_ctx
->
buf_ptr
+=
len
;
rtp_ctx
->
buffered_nals
++
;
}
else
{
flush_buffered
(
ctx
,
0
);
ff_rtp_send_data
(
ctx
,
buf
,
len
,
last_packet_of_frame
);
}
}
else
{
flush_buffered
(
ctx
,
0
);
/*
create the HEVC payload header and transmit the buffer as fragmentation units (FU)
...
...
@@ -102,6 +140,7 @@ void ff_rtp_send_hevc(AVFormatContext *ctx, const uint8_t *frame_buf, int frame_
/* use the default 90 KHz time stamp */
rtp_ctx
->
timestamp
=
rtp_ctx
->
cur_timestamp
;
rtp_ctx
->
buf_ptr
=
rtp_ctx
->
buf
;
if
(
rtp_ctx
->
nal_length_size
)
buf_ptr
=
ff_avc_mp4_find_startcode
(
frame_buf
,
buf_end
,
rtp_ctx
->
nal_length_size
)
?
frame_buf
:
buf_end
;
...
...
@@ -127,4 +166,5 @@ void ff_rtp_send_hevc(AVFormatContext *ctx, const uint8_t *frame_buf, int frame_
/* jump to the next NAL unit */
buf_ptr
=
next_NAL_unit
;
}
flush_buffered
(
ctx
,
1
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment