From 9ee2ddd773f98d0ce815c5715bcd9bb290d8d3cd Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Fri, 4 Sep 2015 09:59:17 -0400 Subject: [PATCH] vp9_parse: fix parsing of pskip and profile 2/3. The fate results change because we now correctly timestamp the pskip frames, which means the results are now identical to -vsync 0. --- libavcodec/vp9_parser.c | 26 +++++++++++++++++++--- tests/ref/fate/vp9-10-show-existing-frame | 6 ++++- tests/ref/fate/vp9-10-show-existing-frame2 | 1 + tests/ref/fate/vp9-16-intra-only | 6 +++-- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/libavcodec/vp9_parser.c b/libavcodec/vp9_parser.c index ab33c33414..f1f7e350d2 100644 --- a/libavcodec/vp9_parser.c +++ b/libavcodec/vp9_parser.c @@ -22,6 +22,7 @@ */ #include "libavutil/intreadwrite.h" +#include "libavcodec/get_bits.h" #include "parser.h" typedef struct VP9ParseContext { @@ -30,11 +31,28 @@ typedef struct VP9ParseContext { int64_t pts; } VP9ParseContext; -static void parse_frame(AVCodecParserContext *ctx, const uint8_t *buf, int size) +static int parse_frame(AVCodecParserContext *ctx, const uint8_t *buf, int size) { VP9ParseContext *s = ctx->priv_data; + GetBitContext gb; + int res, profile, keyframe, invisible; - if (buf[0] & 0x4) { + if ((res = init_get_bits8(&gb, buf, size)) < 0) + return res; + get_bits(&gb, 2); // frame marker + profile = get_bits1(&gb); + profile |= get_bits1(&gb) << 1; + if (profile == 3) profile += get_bits1(&gb); + + if (get_bits1(&gb)) { + keyframe = 0; + invisible = 0; + } else { + keyframe = !get_bits1(&gb); + invisible = !get_bits1(&gb); + } + + if (!keyframe) { ctx->pict_type = AV_PICTURE_TYPE_P; ctx->key_frame = 0; } else { @@ -42,7 +60,7 @@ static void parse_frame(AVCodecParserContext *ctx, const uint8_t *buf, int size) ctx->key_frame = 1; } - if (buf[0] & 0x2) { + if (!invisible) { if (ctx->pts == AV_NOPTS_VALUE) ctx->pts = s->pts; s->pts = AV_NOPTS_VALUE; @@ -50,6 +68,8 @@ static void parse_frame(AVCodecParserContext *ctx, const uint8_t *buf, int size) s->pts = ctx->pts; ctx->pts = AV_NOPTS_VALUE; } + + return 0; } static int parse(AVCodecParserContext *ctx, diff --git a/tests/ref/fate/vp9-10-show-existing-frame b/tests/ref/fate/vp9-10-show-existing-frame index 266f44e5b7..2885b00566 100644 --- a/tests/ref/fate/vp9-10-show-existing-frame +++ b/tests/ref/fate/vp9-10-show-existing-frame @@ -5,10 +5,14 @@ #stream#, dts, pts, duration, size, hash 0, 0, 0, 1, 152064, 18981342ec178e082519451062c3a67f 0, 1, 1, 1, 152064, 04ab9dbeac49ec31be58f6e671698e05 +0, 4, 4, 1, 152064, 4ed58a0ba93a5d97a232a50c5876cda2 0, 6, 6, 1, 152064, a41f00034923e56ba51a0b598acc2e3a 0, 7, 7, 1, 152064, 63fa55ae9535ccdf06d44cce8065dda6 +0, 8, 8, 1, 152064, a41f00034923e56ba51a0b598acc2e3a 0, 9, 9, 1, 152064, 0e4b08e14d919edee2bbff2ecd47de57 -0, 10, 10, 1, 152064, 0e4b08e14d919edee2bbff2ecd47de57 +0, 11, 11, 1, 152064, 0e4b08e14d919edee2bbff2ecd47de57 +0, 12, 12, 1, 152064, 5d4af03fc3d410413ef2b5a6275528b7 0, 13, 13, 1, 152064, 9e932915c67a789f6877e6d3f76d3649 0, 14, 14, 1, 152064, 12f2e975c217e7ffcf334524e8acec35 0, 15, 15, 1, 152064, 9e932915c67a789f6877e6d3f76d3649 +0, 16, 16, 1, 152064, 12f2e975c217e7ffcf334524e8acec35 diff --git a/tests/ref/fate/vp9-10-show-existing-frame2 b/tests/ref/fate/vp9-10-show-existing-frame2 index cdd4369e82..b0fa669161 100644 --- a/tests/ref/fate/vp9-10-show-existing-frame2 +++ b/tests/ref/fate/vp9-10-show-existing-frame2 @@ -15,6 +15,7 @@ 0, 9, 9, 1, 152064, 7dc65a2af108379f2b9265a9a1ea7cf8 0, 10, 10, 1, 152064, c979e2f084760775a567f60f79f28198 0, 11, 11, 1, 152064, fe668a6417aa0543e4ed4d1c67c5cbcb +0, 12, 12, 1, 152064, bf9901e39815fa93cce0ed5b02b2ef2d 0, 13, 13, 1, 152064, 627466200370e6ad60ea570d31be66e3 0, 14, 14, 1, 152064, 7dc65a2af108379f2b9265a9a1ea7cf8 0, 15, 15, 1, 152064, c979e2f084760775a567f60f79f28198 diff --git a/tests/ref/fate/vp9-16-intra-only b/tests/ref/fate/vp9-16-intra-only index 5bbfaea80e..5802a53100 100644 --- a/tests/ref/fate/vp9-16-intra-only +++ b/tests/ref/fate/vp9-16-intra-only @@ -6,5 +6,7 @@ 0, 0, 0, 1, 152064, d57529601178948afa4818c3c8938884 0, 1, 1, 1, 152064, d47e00250c45733d64af067a417bcd06 0, 2, 2, 1, 152064, 984e41cd8350808ac6129746b2377818 -0, 4, 4, 1, 152064, 76ba63001170b8992fc72be5c4ace731 -0, 5, 5, 1, 152064, c4e7f96a8fd58d901b1d881926ddae09 +0, 3, 3, 1, 152064, a5fa62996b4bb52e72e335722cf55bef +0, 4, 4, 1, 152064, b71ca5ad650170ac921a71a6440fb508 +0, 5, 5, 1, 152064, 76ba63001170b8992fc72be5c4ace731 +0, 6, 6, 1, 152064, c4e7f96a8fd58d901b1d881926ddae09