From patchwork Mon Apr 1 23:39:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 12556 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 4B441447332 for ; Tue, 2 Apr 2019 02:39:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 37AD668ABD1; Tue, 2 Apr 2019 02:39:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3AB7668ABC6 for ; Tue, 2 Apr 2019 02:39:50 +0300 (EEST) Received: by mail-wm1-f54.google.com with SMTP id v14so1325197wmf.2 for ; Mon, 01 Apr 2019 16:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=0F902xrajbvEGANkPiedYDkmj3vkU5QW7/LIbnOzYrc=; b=suHuDjtEsDG4GCgOdYYnfMTOJOI/onqo7KwGhSDRxq6RZ1TGWXnO5isuaxd+ZrB80A MLpallt8r5g92StIvv5BsQL8fL1w5Gxl5nORwpc5mPGxLLURXyrgY8b6YSIxH0SbG1Jb AmOeY2pFh2WAdOBU+MlCdsw4LMJkbHRKU402BBtbmiD/uks/VKMRhkSX2h/DK3x1SJkJ AX1k1P3Dht7wZuu1RT0a5kV7z0KKa+EW+pcY21OK6r7qiSPanhK+WcrmIMIeB520jG2G Kww27CbTAfTSVjKkQEryMjXb+o9xmsOKqPogziDstdmYqTPymZAsmNnbtr+kAs3z4cLi 6PzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0F902xrajbvEGANkPiedYDkmj3vkU5QW7/LIbnOzYrc=; b=NY3+CMOr1OtiytNxz1VkfotNSaqp481SF2bYz3kOHlxJaT0F3zQMSkBE1HK4nBLFm/ NBRlfPFgz5IhYT2wQBO4yjXQXu5AmSzTSjhI4Ut+t9alr33Ef3GTrVU+AY6C5TqN70j2 br0J2BkBFLOACyZQbvedXwlcl3EMyl4WQWiimDWUChjY/833mBXj86Jw7hOLhlvm3c5v QS80RRERjbE8ZsyB/qYTsVSWUB660iezSarkkitT5wPtLIiwKvIZmpvW6/7gCsORU7xu /MukNUIxVedcj4TZIIXVSJQGjsgVOLCfEa5TF/GOzhBWWG4VJqN7sAwcFRK6Oo1fJ01R fkaA== X-Gm-Message-State: APjAAAUNc5S1/EHjKLaUFAN9qqOibb7Ic+ni9Mw4/QRkepA/doeirWlc ueMKky0NQ2wEoxUAx/LhzMoK0RAKM/c= X-Google-Smtp-Source: APXvYqzLdvR/Vdn1JWu44tB4TcIV8vcEBhnfzLh3ejhZGUzUfTvEpJalon/5SpVv6uYqpQs4nkTK6w== X-Received: by 2002:a1c:f909:: with SMTP id x9mr1445616wmh.18.1554161989382; Mon, 01 Apr 2019 16:39:49 -0700 (PDT) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id r30sm27943044wrr.46.2019.04.01.16.39.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Apr 2019 16:39:48 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 Apr 2019 00:39:35 +0100 Message-Id: <20190401233940.5941-4-sw@jkqxz.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190401233940.5941-1-sw@jkqxz.net> References: <20190401233940.5941-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 4/9] vp9_parser: Return stream properties X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Rewrites the parser entirely, using CBS for header parsing. --- libavcodec/vp9_parser.c | 112 +++++++++++++++++++++++++++++----------- 1 file changed, 82 insertions(+), 30 deletions(-) diff --git a/libavcodec/vp9_parser.c b/libavcodec/vp9_parser.c index c957a75667..6bf4f30e80 100644 --- a/libavcodec/vp9_parser.c +++ b/libavcodec/vp9_parser.c @@ -1,8 +1,5 @@ /* - * VP9 compatible video decoder - * - * Copyright (C) 2013 Ronald S. Bultje - * Copyright (C) 2013 Clément Bœsch + * VP9 parser * * This file is part of FFmpeg. * @@ -21,50 +18,105 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/intreadwrite.h" -#include "libavcodec/get_bits.h" +#include "libavutil/avassert.h" +#include "cbs.h" +#include "cbs_vp9.h" #include "parser.h" -static int parse(AVCodecParserContext *ctx, - AVCodecContext *avctx, - const uint8_t **out_data, int *out_size, - const uint8_t *data, int size) +typedef struct VP9ParserContext { + CodedBitstreamContext *cbc; + VP9RawFrameHeader frame_header; +} VP9ParserContext; + +static const enum AVPixelFormat vp9_pix_fmts[3][2][2] = { + { // 8-bit. + { AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P }, + { AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P }, + }, + { // 10-bit. + { AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV440P10 }, + { AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV420P10 }, + }, + { // 12-bit. + { AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV440P12 }, + { AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12 }, + }, +}; + +static int vp9_parser_parse(AVCodecParserContext *ctx, + AVCodecContext *avctx, + const uint8_t **out_data, int *out_size, + const uint8_t *data, int size) { - GetBitContext gb; - int res, profile, keyframe; + VP9ParserContext *s = ctx->priv_data; + const CodedBitstreamVP9Context *vp9 = s->cbc->priv_data; + const VP9RawFrameHeader *fh; + int err; *out_data = data; *out_size = size; - if (!size || (res = init_get_bits8(&gb, data, size)) < 0) - return size; // parsers can't return errors - get_bits(&gb, 2); // frame marker - profile = get_bits1(&gb); - profile |= get_bits1(&gb) << 1; - if (profile == 3) profile += get_bits1(&gb); - if (profile > 3) - return size; + ctx->key_frame = -1; + ctx->pict_type = AV_PICTURE_TYPE_NONE; + ctx->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN; - avctx->profile = profile; + if (!size) + return 0; - if (get_bits1(&gb)) { - keyframe = 0; - } else { - keyframe = !get_bits1(&gb); + s->cbc->log_ctx = avctx; + + err = ff_cbs_parse_headers(s->cbc, &s->frame_header, data, size); + if (err < 0) { + av_log(avctx, AV_LOG_WARNING, "Failed to parse VP9 frame headers.\n"); + goto end; } + fh = &s->frame_header; - if (!keyframe) { - ctx->pict_type = AV_PICTURE_TYPE_P; - ctx->key_frame = 0; - } else { + avctx->profile = vp9->profile; + avctx->level = FF_LEVEL_UNKNOWN; + + ctx->width = ctx->coded_width = vp9->frame_width; + ctx->height = ctx->coded_height = vp9->frame_height; + + if (fh->frame_type == VP9_KEY_FRAME) { ctx->pict_type = AV_PICTURE_TYPE_I; ctx->key_frame = 1; + } else { + ctx->pict_type = fh->intra_only ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; + ctx->key_frame = 0; } + ctx->picture_structure = AV_PICTURE_STRUCTURE_FRAME; + + av_assert0(vp9->bit_depth == 8 || + vp9->bit_depth == 10 || + vp9->bit_depth == 12); + + ctx->format = vp9_pix_fmts[(vp9->bit_depth - 8) / 2] + [vp9->subsampling_x][vp9->subsampling_y]; + +end: + s->cbc->log_ctx = NULL; + return size; } +static av_cold int vp9_parser_init(AVCodecParserContext *ctx) +{ + VP9ParserContext *s = ctx->priv_data; + return ff_cbs_init(&s->cbc, AV_CODEC_ID_VP9, NULL); +} + +static av_cold void vp9_parser_close(AVCodecParserContext *ctx) +{ + VP9ParserContext *s = ctx->priv_data; + ff_cbs_close(&s->cbc); +} + AVCodecParser ff_vp9_parser = { .codec_ids = { AV_CODEC_ID_VP9 }, - .parser_parse = parse, + .priv_data_size = sizeof(VP9ParserContext), + .parser_init = &vp9_parser_init, + .parser_close = &vp9_parser_close, + .parser_parse = &vp9_parser_parse, };