diff options
author | Serhii Marchuk <serhii.marchuk@gmail.com> | 2014-01-24 21:12:48 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-01-24 22:14:01 +0100 |
commit | 1d073850538694f6341e7f09cf5f8b30839df5d7 (patch) | |
tree | 31275660c14bac0143df3844efa36161d3d232c3 | |
parent | 2ebee19e1ed2a300c542cbaa06b6e27784d0314d (diff) | |
download | ffmpeg-1d073850538694f6341e7f09cf5f8b30839df5d7.tar.gz |
mpegts demuxer: store PMT values of DVB teletext to extradata
* Using extradata by TS demuxer to store values from PMT
* Support of multiple languages in one DVB teletext stream:
comma separated language codes in metadata "language" field
Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavformat/mpegts.c | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index db380cabf5..d352038771 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -1470,11 +1470,46 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type } break; case 0x56: /* DVB teletext descriptor */ - language[0] = get8(pp, desc_end); - language[1] = get8(pp, desc_end); - language[2] = get8(pp, desc_end); - language[3] = 0; - av_dict_set(&st->metadata, "language", language, 0); + { + uint8_t *extradata = NULL; + int language_count = desc_len / 5; + + if (desc_len > 0 && desc_len % 5 != 0) + return AVERROR_INVALIDDATA; + + if (language_count > 0) { + /* 4 bytes per language code (3 bytes) with comma or NUL byte should fit language buffer */ + if (language_count > sizeof(language) / 4) { + language_count = sizeof(language) / 4; + } + + if (st->codec->extradata == NULL) { + if (ff_alloc_extradata(st->codec, language_count * 2)) { + return AVERROR(ENOMEM); + } + } + + if (st->codec->extradata_size < language_count * 2) + return AVERROR_INVALIDDATA; + + extradata = st->codec->extradata; + + for (i = 0; i < language_count; i++) { + language[i * 4 + 0] = get8(pp, desc_end); + language[i * 4 + 1] = get8(pp, desc_end); + language[i * 4 + 2] = get8(pp, desc_end); + language[i * 4 + 3] = ','; + + memcpy(extradata, *pp, 2); + extradata += 2; + + *pp += 2; + } + + language[i * 4 - 1] = 0; + av_dict_set(&st->metadata, "language", language, 0); + } + } break; case 0x59: /* subtitling descriptor */ language[0] = get8(pp, desc_end); |