[FFmpeg-cvslog] avcodec/extract_extradata_bsf: use the parsing code from mpegvideo_split()
James Almer
git at videolan.org
Sun Mar 26 04:39:42 EEST 2017
ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Fri Mar 24 18:10:53 2017 -0300| [ec996163c8dbacf39c1a3d490d0467299af9a0bd] | committer: 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 73fb23dc5a5.
Required by some samples, like PVA_test-partial.pva
Reviewed-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: James Almer <jamrial at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ec996163c8dbacf39c1a3d490d0467299af9a0bd
---
libavcodec/extract_extradata_bsf.c | 46 ++++++++++++++++++++++++++++++--------
1 file changed, 37 insertions(+), 9 deletions(-)
diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c
index 0d11f86..d909ee6 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 },
};
More information about the ffmpeg-cvslog
mailing list