Commit ec996163 authored by James Almer's avatar James Almer

avcodec/extract_extradata_bsf: use the parsing code from mpegvideo_split()

Changes to the parsing code originally committed to mpegvideo_parser.c
in 73fb23dc.
Required by some samples, like PVA_test-partial.pva
Reviewed-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
Signed-off-by: 's avatarJames Almer <jamrial@gmail.com>
parent d054069c
......@@ -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 },
};
......
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