Commit db395bef authored by Hendrik Leppkes's avatar Hendrik Leppkes

Merge commit '80ea6611'

* commit '80ea6611':
  avcodec: h264: Extract decoder methods

Conflicts:
	libavcodec/h264_sei.c
Merged-by: 's avatarHendrik Leppkes <h.leppkes@gmail.com>
parents 2ab82738 80ea6611
......@@ -112,29 +112,10 @@ static int decode_picture_timing(H264Context *h)
return 0;
}
static int decode_registered_user_data(H264Context *h, int size)
static int decode_registered_user_data_afd(H264Context *h, int size)
{
uint32_t country_code;
uint32_t user_identifier;
int flag, cc_count, user_data_type_code;
if (size < 7)
return AVERROR_INVALIDDATA;
size -= 7;
country_code = get_bits(&h->gb, 8); // itu_t_t35_country_code
if (country_code == 0xFF) {
skip_bits(&h->gb, 8); // itu_t_t35_country_code_extension_byte
size--;
}
/* itu_t_t35_payload_byte follows */
skip_bits(&h->gb, 8); // terminal provider code
skip_bits(&h->gb, 8); // terminal provider oriented code
user_identifier = get_bits_long(&h->gb, 32);
int flag;
switch (user_identifier) {
case MKBETAG('D', 'T', 'G', '1'): // afd_data
if (size-- < 1)
return AVERROR_INVALIDDATA;
skip_bits(&h->gb, 1); // 0
......@@ -153,10 +134,19 @@ FF_DISABLE_DEPRECATION_WARNINGS
FF_ENABLE_DEPRECATION_WARNINGS
#endif /* FF_API_AFD */
}
break;
case MKBETAG('G', 'A', '9', '4'): // "GA94" closed captions
return 0;
}
static int decode_registered_user_data_closed_caption(H264Context *h, int size)
{
int flag;
int user_data_type_code;
int cc_count;
if (size < 3)
return AVERROR(EINVAL);
user_data_type_code = get_bits(&h->gb, 8);
if (user_data_type_code == 0x3) {
skip_bits(&h->gb, 1); // reserved
......@@ -169,16 +159,17 @@ FF_ENABLE_DEPRECATION_WARNINGS
size -= 2;
if (cc_count && size >= cc_count * 3) {
int i;
uint8_t *tmp;
if ((int64_t)h->a53_caption_size + (int64_t)cc_count*3 > INT_MAX)
const uint64_t new_size = (h->a53_caption_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
tmp = av_realloc(h->a53_caption, h->a53_caption_size + cc_count*3);
if (!tmp)
return AVERROR(ENOMEM);
h->a53_caption = tmp;
/* Allow merging of the cc data from two fields. */
ret = av_reallocp(&h->a53_caption, new_size);
if (ret < 0)
return ret;
for (i = 0; i < cc_count; i++) {
h->a53_caption[h->a53_caption_size++] = get_bits(&h->gb, 8);
......@@ -190,7 +181,35 @@ FF_ENABLE_DEPRECATION_WARNINGS
}
}
}
break;
return 0;
}
static int decode_registered_user_data(H264Context *h, int size)
{
uint32_t country_code;
uint32_t user_identifier;
if (size < 7)
return AVERROR_INVALIDDATA;
size -= 7;
country_code = get_bits(&h->gb, 8); // itu_t_t35_country_code
if (country_code == 0xFF) {
skip_bits(&h->gb, 8); // itu_t_t35_country_code_extension_byte
size--;
}
/* itu_t_t35_payload_byte follows */
skip_bits(&h->gb, 8); // terminal provider code
skip_bits(&h->gb, 8); // terminal provider oriented code
user_identifier = get_bits_long(&h->gb, 32);
switch (user_identifier) {
case MKBETAG('D', 'T', 'G', '1'): // afd_data
return decode_registered_user_data_afd(h, size);
case MKBETAG('G', 'A', '9', '4'): // closed captions
return decode_registered_user_data_closed_caption(h, size);
default:
skip_bits(&h->gb, size * 8);
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment