diff mbox series

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

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

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/hevc_sei.c | 49 +++++++------------------------------------
 2 files changed, 9 insertions(+), 42 deletions(-)

Comments

Lynne Aug. 10, 2020, 4:18 p.m. UTC | #1
Aug 10, 2020, 17:49 by jamrial@gmail.com:

> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  configure             |  2 +-
>  libavcodec/hevc_sei.c | 49 +++++++------------------------------------
>  2 files changed, 9 insertions(+), 42 deletions(-)
>
> diff --git a/configure b/configure
> index 5fd966035f..762e74a8ab 100755
> --- a/configure
> +++ b/configure
> @@ -2743,7 +2743,7 @@ h264_decoder_suggest="error_resilience"
>  hap_decoder_select="snappy texturedsp"
>  hap_encoder_deps="libsnappy"
>  hap_encoder_select="texturedspenc"
> -hevc_decoder_select="bswapdsp cabac golomb hevcparse videodsp"
> +hevc_decoder_select="atsc_a53 bswapdsp cabac golomb hevcparse videodsp"
>  huffyuv_decoder_select="bswapdsp huffyuvdsp llviddsp"
>  huffyuv_encoder_select="bswapdsp huffman huffyuvencdsp llvidencdsp"
>  hymt_decoder_select="huffyuv_decoder"
> diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> index a4ec65dc1a..06e7a3a10c 100644
> --- a/libavcodec/hevc_sei.c
> +++ b/libavcodec/hevc_sei.c
> @@ -22,6 +22,7 @@
>  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>  */
>  
> +#include "atsc_a53.h"
>  #include "golomb.h"
>  #include "hevc_ps.h"
>  #include "hevc_sei.h"
> @@ -164,51 +165,17 @@ static int decode_nal_sei_pic_timing(HEVCSEI *s, GetBitContext *gb, const HEVCPa
>  static int decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetBitContext *gb,
>  int size)
>  {
> -    int flag;
> -    int user_data_type_code;
> -    int cc_count;
> +    int ret;
>  
>  if (size < 3)
>  return AVERROR(EINVAL);
>

Shouldn't all EINVALs be AVERROR_INVALIDDATA?
James Almer Aug. 10, 2020, 4:29 p.m. UTC | #2
On 8/10/2020 1:18 PM, Lynne wrote:
> Aug 10, 2020, 17:49 by jamrial@gmail.com:
> 
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  configure             |  2 +-
>>  libavcodec/hevc_sei.c | 49 +++++++------------------------------------
>>  2 files changed, 9 insertions(+), 42 deletions(-)
>>
>> diff --git a/configure b/configure
>> index 5fd966035f..762e74a8ab 100755
>> --- a/configure
>> +++ b/configure
>> @@ -2743,7 +2743,7 @@ h264_decoder_suggest="error_resilience"
>>  hap_decoder_select="snappy texturedsp"
>>  hap_encoder_deps="libsnappy"
>>  hap_encoder_select="texturedspenc"
>> -hevc_decoder_select="bswapdsp cabac golomb hevcparse videodsp"
>> +hevc_decoder_select="atsc_a53 bswapdsp cabac golomb hevcparse videodsp"
>>  huffyuv_decoder_select="bswapdsp huffyuvdsp llviddsp"
>>  huffyuv_encoder_select="bswapdsp huffman huffyuvencdsp llvidencdsp"
>>  hymt_decoder_select="huffyuv_decoder"
>> diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
>> index a4ec65dc1a..06e7a3a10c 100644
>> --- a/libavcodec/hevc_sei.c
>> +++ b/libavcodec/hevc_sei.c
>> @@ -22,6 +22,7 @@
>>  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>>  */
>>  
>> +#include "atsc_a53.h"
>>  #include "golomb.h"
>>  #include "hevc_ps.h"
>>  #include "hevc_sei.h"
>> @@ -164,51 +165,17 @@ static int decode_nal_sei_pic_timing(HEVCSEI *s, GetBitContext *gb, const HEVCPa
>>  static int decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetBitContext *gb,
>>  int size)
>>  {
>> -    int flag;
>> -    int user_data_type_code;
>> -    int cc_count;
>> +    int ret;
>>  
>>  if (size < 3)
>>  return AVERROR(EINVAL);
>>
> 
> Shouldn't all EINVALs be AVERROR_INVALIDDATA?

I thought about it, but decided to leave it as is seeing it was outside
the scope of this patch. I can change it in a separate patch.
diff mbox series

Patch

diff --git a/configure b/configure
index 5fd966035f..762e74a8ab 100755
--- a/configure
+++ b/configure
@@ -2743,7 +2743,7 @@  h264_decoder_suggest="error_resilience"
 hap_decoder_select="snappy texturedsp"
 hap_encoder_deps="libsnappy"
 hap_encoder_select="texturedspenc"
-hevc_decoder_select="bswapdsp cabac golomb hevcparse videodsp"
+hevc_decoder_select="atsc_a53 bswapdsp cabac golomb hevcparse videodsp"
 huffyuv_decoder_select="bswapdsp huffyuvdsp llviddsp"
 huffyuv_encoder_select="bswapdsp huffman huffyuvencdsp llvidencdsp"
 hymt_decoder_select="huffyuv_decoder"
diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index a4ec65dc1a..06e7a3a10c 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -22,6 +22,7 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "atsc_a53.h"
 #include "golomb.h"
 #include "hevc_ps.h"
 #include "hevc_sei.h"
@@ -164,51 +165,17 @@  static int decode_nal_sei_pic_timing(HEVCSEI *s, GetBitContext *gb, const HEVCPa
 static int decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetBitContext *gb,
                                                       int size)
 {
-    int flag;
-    int user_data_type_code;
-    int cc_count;
+    int ret;
 
     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);
-            cc_count = get_bits(gb, 5);
-            skip_bits(gb, 8); // reserved
-            size -= 2;
-
-            if (cc_count && size >= cc_count * 3) {
-                int old_size = s->buf_ref ? s->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(&s->buf_ref, new_size);
-                if (ret < 0)
-                    return ret;
-
-                for (i = 0; i < cc_count; i++) {
-                    s->buf_ref->data[old_size++] = get_bits(gb, 8);
-                    s->buf_ref->data[old_size++] = get_bits(gb, 8);
-                    s->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);
-    }
+    ret = ff_parse_a53_cc(&s->buf_ref, gb->buffer + get_bits_count(gb) / 8, size);
+
+    if (ret < 0)
+        return ret;
+
+    skip_bits_long(gb, size * 8);
 
     return 0;
 }