diff mbox series

[FFmpeg-devel,09/17] avformat/avc, movenccenc: Simplify annex B->mp4 transformation

Message ID 20200709192022.9412-1-andreas.rheinhardt@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/7] avformat/avc: Fix undefined shift and assert when reading exp-golomb num
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt July 9, 2020, 7:20 p.m. UTC
by using the new ff_avc_parse_nalu function.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/avc.c        | 11 ++---------
 libavformat/movenccenc.c | 12 ++----------
 2 files changed, 4 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/avc.c b/libavformat/avc.c
index 39078aa5be..d089051034 100644
--- a/libavformat/avc.c
+++ b/libavformat/avc.c
@@ -120,20 +120,13 @@  int ff_avc_parse_nal_units(AVIOContext *pb, const uint8_t *buf_in, int size)
 {
     const uint8_t *p = buf_in;
     const uint8_t *end = p + size;
-    const uint8_t *nal_start, *nal_end;
+    const uint8_t *nal_start, *nal_end = NULL;
 
     size = 0;
-    nal_start = ff_avc_find_startcode(p, end);
-    for (;;) {
-        while (nal_start < end && !*(nal_start++));
-        if (nal_start == end)
-            break;
-
-        nal_end = ff_avc_find_startcode(nal_start, end);
+    while (nal_start = ff_avc_parse_nalu(&p, &nal_end, end)) {
         avio_wb32(pb, nal_end - nal_start);
         avio_write(pb, nal_start, nal_end - nal_start);
         size += 4 + nal_end - nal_start;
-        nal_start = nal_end;
     }
     return size;
 }
diff --git a/libavformat/movenccenc.c b/libavformat/movenccenc.c
index b91294f706..75244ab70b 100644
--- a/libavformat/movenccenc.c
+++ b/libavformat/movenccenc.c
@@ -194,7 +194,7 @@  int ff_mov_cenc_avc_parse_nal_units(MOVMuxCencContext* ctx, AVIOContext *pb,
 {
     const uint8_t *p = buf_in;
     const uint8_t *end = p + size;
-    const uint8_t *nal_start, *nal_end;
+    const uint8_t *nal_start, *nal_end = NULL;
     int ret;
 
     ret = mov_cenc_start_packet(ctx);
@@ -203,14 +203,7 @@  int ff_mov_cenc_avc_parse_nal_units(MOVMuxCencContext* ctx, AVIOContext *pb,
     }
 
     size = 0;
-    nal_start = ff_avc_find_startcode(p, end);
-    for (;;) {
-        while (nal_start < end && !*(nal_start++));
-        if (nal_start == end)
-            break;
-
-        nal_end = ff_avc_find_startcode(nal_start, end);
-
+    while (nal_start = ff_avc_parse_nalu(&p, &nal_end, end)) {
         avio_wb32(pb, nal_end - nal_start);
         avio_w8(pb, *nal_start);
         mov_cenc_write_encrypted(ctx, pb, nal_start + 1, nal_end - nal_start - 1);
@@ -218,7 +211,6 @@  int ff_mov_cenc_avc_parse_nal_units(MOVMuxCencContext* ctx, AVIOContext *pb,
         auxiliary_info_add_subsample(ctx, 5, nal_end - nal_start - 1);
 
         size += 4 + nal_end - nal_start;
-        nal_start = nal_end;
     }
 
     ret = mov_cenc_end_packet(ctx);