diff options
author | Hendrik Leppkes <h.leppkes@gmail.com> | 2015-08-02 10:51:53 +0200 |
---|---|---|
committer | Hendrik Leppkes <h.leppkes@gmail.com> | 2015-08-02 10:59:06 +0200 |
commit | db395bef7f9a0c8af782835aefb358e56c6bfb46 (patch) | |
tree | c88f4f21d5470604eeac0096ca7b649446a7de84 | |
parent | 2ab827389bc17972dfe58b768083593b1f1bf776 (diff) | |
parent | 80ea66112817c719b476de8f7d8d3b325f4c7dd1 (diff) | |
download | ffmpeg-db395bef7f9a0c8af782835aefb358e56c6bfb46.tar.gz |
Merge commit '80ea66112817c719b476de8f7d8d3b325f4c7dd1'
* commit '80ea66112817c719b476de8f7d8d3b325f4c7dd1':
avcodec: h264: Extract decoder methods
Conflicts:
libavcodec/h264_sei.c
Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
-rw-r--r-- | libavcodec/h264_sei.c | 133 |
1 files changed, 76 insertions, 57 deletions
diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c index dc0769d7a2..fbd582d072 100644 --- a/libavcodec/h264_sei.c +++ b/libavcodec/h264_sei.c @@ -112,11 +112,83 @@ static int decode_picture_timing(H264Context *h) return 0; } +static int decode_registered_user_data_afd(H264Context *h, int size) +{ + int flag; + + if (size-- < 1) + return AVERROR_INVALIDDATA; + skip_bits(&h->gb, 1); // 0 + flag = get_bits(&h->gb, 1); // active_format_flag + skip_bits(&h->gb, 6); // reserved + + if (flag) { + if (size-- < 1) + return AVERROR_INVALIDDATA; + skip_bits(&h->gb, 4); // reserved + h->active_format_description = get_bits(&h->gb, 4); + h->sei_reguserdata_afd_present = 1; +#if FF_API_AFD +FF_DISABLE_DEPRECATION_WARNINGS + h->avctx->dtg_active_format = h->active_format_description; +FF_ENABLE_DEPRECATION_WARNINGS +#endif /* FF_API_AFD */ + } + + 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 + + flag = get_bits(&h->gb, 1); // process_cc_data_flag + if (flag) { + skip_bits(&h->gb, 1); // zero bit + cc_count = get_bits(&h->gb, 5); + skip_bits(&h->gb, 8); // reserved + size -= 2; + + if (cc_count && size >= cc_count * 3) { + 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. */ + 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); + h->a53_caption[h->a53_caption_size++] = get_bits(&h->gb, 8); + h->a53_caption[h->a53_caption_size++] = get_bits(&h->gb, 8); + } + + skip_bits(&h->gb, 8); // marker_bits + } + } + } + + return 0; +} + static int decode_registered_user_data(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; @@ -135,62 +207,9 @@ static int decode_registered_user_data(H264Context *h, int size) switch (user_identifier) { case MKBETAG('D', 'T', 'G', '1'): // afd_data - if (size-- < 1) - return AVERROR_INVALIDDATA; - skip_bits(&h->gb, 1); // 0 - flag = get_bits(&h->gb, 1); // active_format_flag - skip_bits(&h->gb, 6); // reserved - - if (flag) { - if (size-- < 1) - return AVERROR_INVALIDDATA; - skip_bits(&h->gb, 4); // reserved - h->active_format_description = get_bits(&h->gb, 4); - h->sei_reguserdata_afd_present = 1; -#if FF_API_AFD -FF_DISABLE_DEPRECATION_WARNINGS - h->avctx->dtg_active_format = h->active_format_description; -FF_ENABLE_DEPRECATION_WARNINGS -#endif /* FF_API_AFD */ - } - break; - case MKBETAG('G', 'A', '9', '4'): // "GA94" closed captions - 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 - - flag = get_bits(&h->gb, 1); // process_cc_data_flag - if (flag) { - skip_bits(&h->gb, 1); // zero bit - cc_count = get_bits(&h->gb, 5); - skip_bits(&h->gb, 8); // reserved - 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) - 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; - - for (i = 0; i < cc_count; i++) { - h->a53_caption[h->a53_caption_size++] = get_bits(&h->gb, 8); - h->a53_caption[h->a53_caption_size++] = get_bits(&h->gb, 8); - h->a53_caption[h->a53_caption_size++] = get_bits(&h->gb, 8); - } - - skip_bits(&h->gb, 8); // marker_bits - } - } - } - break; + 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; |