From patchwork Fri Oct 26 22:07:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 10798 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 946F044CDDD for ; Sat, 27 Oct 2018 01:07:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 07C4D68A099; Sat, 27 Oct 2018 01:07:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 300CC6899F3 for ; Sat, 27 Oct 2018 01:07:02 +0300 (EEST) Received: by mail-qt1-f194.google.com with SMTP id l11-v6so2383836qtf.7 for ; Fri, 26 Oct 2018 15:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=o24vHvbXevkCdAYQHCyBZl6pB/vRDLPhCiitLxfCSHc=; b=OX/Ml+/unf0vGyEeIaT6G4sZwjeuwKRXID1+dO9i0mTUt1QnT1rYmC8Aag/IKMaVt9 OzzHj5oeFBVQBUXWfqhCq6rsqqk4ZEO34hM+gH7Mp3L8uo9OgctCYimR/WkhsTuPUcVW f5N6VikHG8DDIeclgRH+ToV1kpH5NjzCgqV/UEsHwlgYG9VLG5dBUxmxGFDzi+0xNp0r ZyWPBAbKq+j+nS5BXqosC1nJ8kIV0gpk+9NBsSddg7ZiHgZiMi1PMQriY9a5OHI0/YnN KZ+6bReKJDpBbwUPUCeqtbc1GWRPatNiItQn8Eb0KX4mBwZULIk9zNWmq3IIP7yxLSE1 N5Iw== 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=o24vHvbXevkCdAYQHCyBZl6pB/vRDLPhCiitLxfCSHc=; b=iWIRqhRoFvygZipehd6xQjUqIh3sN5Ye52ye1zwSe+mcEt4VrX+FYMfZo1E7UYToY9 Motr9MGox7LU42OAn2paFgE7gKtxFjBP/iDb+aDsLo2QxNTV+PGaAAjoQ4L+jV9cvGiE 2VB6GJLm8pLnyK9lf9aR1JjxMocrJn1fRIb2P5lWjPMu4NB39LXRkmeBS/CB626UFl7V qRBKHr+jWa3JeZtHEAFctjHHqUr0wkmqANhY3eJ4ucYzw6vNGfQbI/8TLKkYVbyrI5ut 764ayD4Is4ouW7ho+eWYmR/qv0RgxLZIAxyIwYug4/5Y3duMFxnDxReSwaAx4Z+tjpjY qdmw== X-Gm-Message-State: AGRZ1gIzR1jEf8RItbqgrnZ3mGcKnuVepHe88gNfiLt2QFU5hP5yWOzG 5zv39hvCBcixe4FAfZXYMMH6gOHg X-Google-Smtp-Source: AJdET5deCT8mC3rnYmMrtiwILMoDm0Zt10+s5xvLvkERpdGneCfijizn6/KDt2PNHqD6TIX/cYh2jw== X-Received: by 2002:a0c:a3e4:: with SMTP id v91mr4941231qvv.247.1540591650294; Fri, 26 Oct 2018 15:07:30 -0700 (PDT) Received: from localhost.localdomain ([179.38.174.95]) by smtp.gmail.com with ESMTPSA id w81-v6sm10869352qka.87.2018.10.26.15.07.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Oct 2018 15:07:29 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 26 Oct 2018 19:07:17 -0300 Message-Id: <20181026220717.3552-1-jamrial@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181026210534.GZ3743@michaelspb> References: <20181026210534.GZ3743@michaelspb> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2 v2] avcodec/cbs_vp9: keep track of reference frames 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" Signed-off-by: James Almer --- libavcodec/cbs_vp9.h | 13 +++++++++ libavcodec/cbs_vp9_syntax_template.c | 40 +++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/libavcodec/cbs_vp9.h b/libavcodec/cbs_vp9.h index 5b99c90c2e..7eee6d5e9e 100644 --- a/libavcodec/cbs_vp9.h +++ b/libavcodec/cbs_vp9.h @@ -183,6 +183,13 @@ typedef struct VP9RawSuperframe { VP9RawSuperframeIndex index; } VP9RawSuperframe; +typedef struct VP9ReferenceFrameState { + int frame_width; // RefFrameWidth + int frame_height; // RefFrameHeight + int subsampling_x; // RefSubsamplingX + int subsampling_y; // RefSubsamplingY + int bit_depth; // RefBitDepth +} VP9ReferenceFrameState; typedef struct CodedBitstreamVP9Context { // Frame dimensions in 8x8 mode info blocks. @@ -192,6 +199,12 @@ typedef struct CodedBitstreamVP9Context { uint16_t sb64_cols; uint16_t sb64_rows; + int bit_depth; + int frame_width; + int frame_height; + + VP9ReferenceFrameState ref[VP9_NUM_REF_FRAMES]; + // Write buffer. uint8_t *write_buffer; size_t write_buffer_size; diff --git a/libavcodec/cbs_vp9_syntax_template.c b/libavcodec/cbs_vp9_syntax_template.c index b4a7f65e85..cd5b83a4f5 100644 --- a/libavcodec/cbs_vp9_syntax_template.c +++ b/libavcodec/cbs_vp9_syntax_template.c @@ -43,10 +43,14 @@ static int FUNC(frame_sync_code)(CodedBitstreamContext *ctx, RWContext *rw, static int FUNC(color_config)(CodedBitstreamContext *ctx, RWContext *rw, VP9RawFrameHeader *current, int profile) { + CodedBitstreamVP9Context *vp9 = ctx->priv_data; int err; - if (profile >= 2) + if (profile >= 2) { f(1, ten_or_twelve_bit); + vp9->bit_depth = current->ten_or_twelve_bit ? 12 : 10; + } else + vp9->bit_depth = 8; f(3, color_space); @@ -81,8 +85,11 @@ static int FUNC(frame_size)(CodedBitstreamContext *ctx, RWContext *rw, f(16, frame_width_minus_1); f(16, frame_height_minus_1); - vp9->mi_cols = (current->frame_width_minus_1 + 8) >> 3; - vp9->mi_rows = (current->frame_height_minus_1 + 8) >> 3; + vp9->frame_width = current->frame_width_minus_1 + 1; + vp9->frame_height = current->frame_height_minus_1 + 1; + + vp9->mi_cols = (vp9->frame_width + 7) >> 3; + vp9->mi_rows = (vp9->frame_height + 7) >> 3; vp9->sb64_cols = (vp9->mi_cols + 7) >> 3; vp9->sb64_rows = (vp9->mi_rows + 7) >> 3; @@ -107,12 +114,24 @@ static int FUNC(render_size)(CodedBitstreamContext *ctx, RWContext *rw, static int FUNC(frame_size_with_refs)(CodedBitstreamContext *ctx, RWContext *rw, VP9RawFrameHeader *current) { + CodedBitstreamVP9Context *vp9 = ctx->priv_data; int err, i; for (i = 0; i < VP9_REFS_PER_FRAME; i++) { fs(1, found_ref[i], 1, i); - if (current->found_ref[i]) + if (current->found_ref[i]) { + VP9ReferenceFrameState *ref = + &vp9->ref[current->ref_frame_idx[i]]; + + vp9->frame_width = ref->frame_width; + vp9->frame_height = ref->frame_height; + + vp9->mi_cols = (vp9->frame_width + 7) >> 3; + vp9->mi_rows = (vp9->frame_height + 7) >> 3; + vp9->sb64_cols = (vp9->mi_cols + 7) >> 3; + vp9->sb64_rows = (vp9->mi_rows + 7) >> 3; break; + } } if (i >= VP9_REFS_PER_FRAME) CHECK(FUNC(frame_size)(ctx, rw, current)); @@ -249,6 +268,7 @@ static int FUNC(tile_info)(CodedBitstreamContext *ctx, RWContext *rw, static int FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw, VP9RawFrameHeader *current) { + CodedBitstreamVP9Context *vp9 = ctx->priv_data; int profile, i; int err; @@ -339,6 +359,18 @@ static int FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw, f(16, header_size_in_bytes); + for (i = 0; i < VP9_NUM_REF_FRAMES; i++) { + if (current->refresh_frame_flags & (1 << i)) { + vp9->ref[i] = (VP9ReferenceFrameState) { + .frame_width = vp9->frame_width, + .frame_height = vp9->frame_height, + .subsampling_x = current->subsampling_x, + .subsampling_y = current->subsampling_y, + .bit_depth = vp9->bit_depth, + }; + } + } + return 0; }