diff options
author | James Almer <jamrial@gmail.com> | 2017-03-24 18:10:53 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2017-03-25 22:38:13 -0300 |
commit | ec996163c8dbacf39c1a3d490d0467299af9a0bd (patch) | |
tree | deac0d0ca803e1ae44a413299f19c5a16ee3b32f /libavcodec/extract_extradata_bsf.c | |
parent | d054069c1540ff2c7fb8097b830ee852afad7021 (diff) | |
download | ffmpeg-ec996163c8dbacf39c1a3d490d0467299af9a0bd.tar.gz |
avcodec/extract_extradata_bsf: use the parsing code from mpegvideo_split()
Changes to the parsing code originally committed to mpegvideo_parser.c
in 73fb23dc5a5.
Required by some samples, like PVA_test-partial.pva
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/extract_extradata_bsf.c')
-rw-r--r-- | libavcodec/extract_extradata_bsf.c | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c index 0d11f86304..d909ee6d17 100644 --- a/libavcodec/extract_extradata_bsf.c +++ b/libavcodec/extract_extradata_bsf.c @@ -170,19 +170,47 @@ static int extract_extradata_vc1(AVBSFContext *ctx, AVPacket *pkt, return 0; } -static int extract_extradata_mpeg124(AVBSFContext *ctx, AVPacket *pkt, +static int extract_extradata_mpeg12(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size) { ExtractExtradataContext *s = ctx->priv_data; - int is_mpeg12 = ctx->par_in->codec_id == AV_CODEC_ID_MPEG1VIDEO || - ctx->par_in->codec_id == AV_CODEC_ID_MPEG2VIDEO; + uint32_t state = UINT32_MAX; + int i, found = 0; + + for (i = 0; i < pkt->size; i++) { + state = (state << 8) | pkt->data[i]; + if (state == 0x1B3) + found = 1; + else if (found && state != 0x1B5 && state < 0x200 && state >= 0x100) { + if (i > 3) { + *size = i - 3; + *data = av_malloc(*size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!*data) + return AVERROR(ENOMEM); + + memcpy(*data, pkt->data, *size); + + if (s->remove) { + pkt->data += *size; + pkt->size -= *size; + } + } + break; + } + } + return 0; +} + +static int extract_extradata_mpeg4(AVBSFContext *ctx, AVPacket *pkt, + uint8_t **data, int *size) +{ + ExtractExtradataContext *s = ctx->priv_data; uint32_t state = UINT32_MAX; int i; for (i = 0; i < pkt->size; i++) { state = (state << 8) | pkt->data[i]; - if ((is_mpeg12 && state != 0x1B3 && state != 0x1B5 && state < 0x200 && state >= 0x100) || - (!is_mpeg12 && (state == 0x1B3 || state == 0x1B6))) { + if ((state == 0x1B3 || state == 0x1B6)) { if (i > 3) { *size = i - 3; *data = av_malloc(*size + AV_INPUT_BUFFER_PADDING_SIZE); @@ -207,12 +235,12 @@ static const struct { int (*extract)(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size); } extract_tab[] = { - { AV_CODEC_ID_CAVS, extract_extradata_mpeg124 }, + { AV_CODEC_ID_CAVS, extract_extradata_mpeg4 }, { AV_CODEC_ID_H264, extract_extradata_h2645 }, { AV_CODEC_ID_HEVC, extract_extradata_h2645 }, - { AV_CODEC_ID_MPEG1VIDEO, extract_extradata_mpeg124 }, - { AV_CODEC_ID_MPEG2VIDEO, extract_extradata_mpeg124 }, - { AV_CODEC_ID_MPEG4, extract_extradata_mpeg124 }, + { AV_CODEC_ID_MPEG1VIDEO, extract_extradata_mpeg12 }, + { AV_CODEC_ID_MPEG2VIDEO, extract_extradata_mpeg12 }, + { AV_CODEC_ID_MPEG4, extract_extradata_mpeg4 }, { AV_CODEC_ID_VC1, extract_extradata_vc1 }, }; |