diff mbox series

[FFmpeg-devel,3/5] avcodec/h264_sei: use ff_parse_a53_cc() to parse A53 Closed Captions

Message ID 20200810154941.4988-3-jamrial@gmail.com
State Accepted
Commit c93ba51ef3e2d83428360bd784166343145e7a3f
Headers show
Series [FFmpeg-devel,1/5] avcodec: split off A53 Closed Caption parsing code into its own file
Related show

Checks

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

Commit Message

James Almer Aug. 10, 2020, 3:49 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 configure             |  2 +-
 libavcodec/h264_sei.c | 48 ++-----------------------------------------
 2 files changed, 3 insertions(+), 47 deletions(-)
diff mbox series

Patch

diff --git a/configure b/configure
index 83f051fdee..5fd966035f 100755
--- a/configure
+++ b/configure
@@ -2738,7 +2738,7 @@  h263_encoder_select="h263dsp mpegvideoenc"
 h263i_decoder_select="h263_decoder"
 h263p_decoder_select="h263_decoder"
 h263p_encoder_select="h263_encoder"
-h264_decoder_select="cabac golomb h264chroma h264dsp h264parse h264pred h264qpel videodsp"
+h264_decoder_select="atsc_a53 cabac golomb h264chroma h264dsp h264parse h264pred h264qpel videodsp"
 h264_decoder_suggest="error_resilience"
 hap_decoder_select="snappy texturedsp"
 hap_encoder_deps="libsnappy"
diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c
index 7b8e6bd7ba..669560ae5f 100644
--- a/libavcodec/h264_sei.c
+++ b/libavcodec/h264_sei.c
@@ -25,6 +25,7 @@ 
  * @author Michael Niedermayer <michaelni@gmx.at>
  */
 
+#include "atsc_a53.h"
 #include "avcodec.h"
 #include "get_bits.h"
 #include "golomb.h"
@@ -173,55 +174,10 @@  static int decode_registered_user_data_closed_caption(H264SEIA53Caption *h,
                                                      GetBitContext *gb, void *logctx,
                                                      int size)
 {
-    int flag;
-    int user_data_type_code;
-    int cc_count;
-
     if (size < 3)
         return AVERROR(EINVAL);
 
-    user_data_type_code = get_bits(gb, 8);
-    if (user_data_type_code == 0x3) {
-        skip_bits(gb, 1);           // reserved
-
-        flag = get_bits(gb, 1);     // process_cc_data_flag
-        if (flag) {
-            skip_bits(gb, 1);       // zero bit
-            cc_count = get_bits(gb, 5);
-            skip_bits(gb, 8);       // reserved
-            size -= 2;
-
-            if (cc_count && size >= cc_count * 3) {
-                int old_size = h->buf_ref ? h->buf_ref->size : 0;
-                const uint64_t new_size = (old_size + cc_count
-                                           * UINT64_C(3));
-                int i, ret;
-
-                if (new_size > INT_MAX)
-                    return AVERROR(EINVAL);
-
-                /* Allow merging of the cc data from two fields. */
-                ret = av_buffer_realloc(&h->buf_ref, new_size);
-                if (ret < 0)
-                    return ret;
-
-                /* Use of av_buffer_realloc assumes buffer is writeable */
-                for (i = 0; i < cc_count; i++) {
-                    h->buf_ref->data[old_size++] = get_bits(gb, 8);
-                    h->buf_ref->data[old_size++] = get_bits(gb, 8);
-                    h->buf_ref->data[old_size++] = get_bits(gb, 8);
-                }
-
-                skip_bits(gb, 8);   // marker_bits
-            }
-        }
-    } else {
-        int i;
-        for (i = 0; i < size - 1; i++)
-            skip_bits(gb, 8);
-    }
-
-    return 0;
+    return ff_parse_a53_cc(&h->buf_ref, gb->buffer + get_bits_count(gb) / 8, size);
 }
 
 static int decode_registered_user_data(H264SEIContext *h, GetBitContext *gb,