From patchwork Mon Nov 14 07:11:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Zhao X-Patchwork-Id: 1411 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.90.1 with SMTP id o1csp908393vsb; Sun, 13 Nov 2016 23:11:13 -0800 (PST) X-Received: by 10.28.63.3 with SMTP id m3mr9133092wma.113.1479107473560; Sun, 13 Nov 2016 23:11:13 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f1si22382855wjl.229.2016.11.13.23.11.13; Sun, 13 Nov 2016 23:11:13 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 96B79689FAF; Mon, 14 Nov 2016 09:11:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 31F20689C4F for ; Mon, 14 Nov 2016 09:11:05 +0200 (EET) Received: by mail-pf0-f193.google.com with SMTP id 144so5706249pfv.0 for ; Sun, 13 Nov 2016 23:11:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:from:subject:message-id:date:user-agent:mime-version; bh=TgUzuR43NTm6ZplKRcIYBrJR6ip8Vu/RVWnRLYTS0ow=; b=puI/keqbyYzGMIJeQlRUiz5SX1Nxcov963TYG6y3W7whX5Seqb5IOvexDTNp72Hn7W IUofU9aSvFbrRLZOQuleUCHCpgZA2+Enepj3mw2cT5RW8AYdPC2Tx1rWI3pKEU77659/ XGVC6hOB/2+nyrzuHnvVkB9Ovn4wJcXQP56CC3r43CgGyTvYjkmbffq60x0N+YpUOSDB RxyyTBE3WeJ3eqxl+MJOh2FrS6VbITp75+Zf8DoW6wBFhzFh7PCNW4EamcjK28AgIi4I QFq5ajhlBEmlGsxjFMw1A1uX+yW4bIvDl36kiKcvDaHzO7W+wzNE1Leu8yBP2G5lmx8a WFfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version; bh=TgUzuR43NTm6ZplKRcIYBrJR6ip8Vu/RVWnRLYTS0ow=; b=FkWjJoVZEHkHkWsrd+ghX0Th9WCEeDt5IwCAZNzKNi0u2TLZhmR2//+0v31JK80iIS Lt2DZoJvf9z5JW/+1LS/3DbU4uU1C7668p52V0FetVKifWdXuOkV0hgDkRex4TjlD6s2 zALB3hMaSS/ja+tk2JYpLglHBKWEgstr8A2h0NO5fHTb9lVVP6DAvaJVCVczpsX0mRFW K7UFkEiFzNtIe7AR3Ojh8OZ+zDYXmD1eXnq3UAvhH5fyd9O58uz+udAzEcEeDRJ9gfTp IFC+OAsAkxbyv3A+JmR+9+YxmnOZYJuLwAEPh/rV56X40kMVnFTMiVNULK2NaCpuvhnf Fp6A== X-Gm-Message-State: ABUngvfLymTbSqedNFYnYtOVTHju4iGpogOPnHIAv0BckRYi9G/J3hpYUHSbqdIbZzgNrA== X-Received: by 10.99.251.69 with SMTP id w5mr26895970pgj.124.1479107463463; Sun, 13 Nov 2016 23:11:03 -0800 (PST) Received: from [10.239.204.55] ([192.55.54.45]) by smtp.gmail.com with ESMTPSA id a66sm32471289pfa.64.2016.11.13.23.11.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Nov 2016 23:11:02 -0800 (PST) To: Mark Thompson , FFmpeg development discussions and patches , Yi Wang From: Jun Zhao Message-ID: <2299ba6c-c59c-b5f9-d481-d623f53b2e06@gmail.com> Date: Mon, 14 Nov 2016 15:11:00 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] lavc/vaapi_encode_h264: fix poc incorrect issue after meeting idr frame. 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" V2 : - Change the last_idr_frame filed location based on Mark code review. - Modify the commit message to actually explain the problem. From a1bf2b021effd36f8297b331855a282d775f2a44 Mon Sep 17 00:00:00 2001 From: Jun Zhao Date: Fri, 11 Nov 2016 14:53:49 +0800 Subject: [PATCH v2] lavc/vaapi_encode_h264: fix poc incorrect issue after meeting idr frame. when meeting IDR frame, vaapi_encode_h264 poc number don't reset, now fix this issue based on h264 spec. Some decoder don't care this case, but this fix will enhance the encoder action. Before this fix, poc number is negative in some case. Reviewed-by: Jun Zhao Signed-off-by: Wang, Yi A --- libavcodec/vaapi_encode_h264.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) vpic->frame_num = 0; priv->next_frame_num = 1; priv->cpb_delay = 0; + priv->last_idr_frame = pic->display_order; } else { vpic->frame_num = priv->next_frame_num; if (pic->type != PICTURE_TYPE_B) { @@ -963,8 +967,8 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, vpic->CurrPic.picture_id = pic->recon_surface; vpic->CurrPic.frame_idx = vpic->frame_num; vpic->CurrPic.flags = 0; - vpic->CurrPic.TopFieldOrderCnt = pic->display_order; - vpic->CurrPic.BottomFieldOrderCnt = pic->display_order; + vpic->CurrPic.TopFieldOrderCnt = pic->display_order - priv->last_idr_frame; + vpic->CurrPic.BottomFieldOrderCnt = pic->display_order - priv->last_idr_frame; for (i = 0; i < pic->nb_refs; i++) { VAAPIEncodePicture *ref = pic->refs[i]; @@ -972,8 +976,8 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, vpic->ReferenceFrames[i].picture_id = ref->recon_surface; vpic->ReferenceFrames[i].frame_idx = ref->encode_order; vpic->ReferenceFrames[i].flags = VA_PICTURE_H264_SHORT_TERM_REFERENCE; - vpic->ReferenceFrames[i].TopFieldOrderCnt = ref->display_order; - vpic->ReferenceFrames[i].BottomFieldOrderCnt = ref->display_order; + vpic->ReferenceFrames[i].TopFieldOrderCnt = ref->display_order - priv->last_idr_frame; + vpic->ReferenceFrames[i].BottomFieldOrderCnt = ref->display_order - priv->last_idr_frame; } for (; i < FF_ARRAY_ELEMS(vpic->ReferenceFrames); i++) { vpic->ReferenceFrames[i].picture_id = VA_INVALID_ID; @@ -1044,7 +1048,7 @@ static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx, vslice->pic_parameter_set_id = vpic->pic_parameter_set_id; vslice->idr_pic_id = priv->idr_pic_count++; - vslice->pic_order_cnt_lsb = pic->display_order & + vslice->pic_order_cnt_lsb = (pic->display_order - priv->last_idr_frame) & ((1 << (4 + vseq->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4)) - 1); for (i = 0; i < FF_ARRAY_ELEMS(vslice->RefPicList0); i++) { diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c index 5bed4e4..de2e0d9 100644 --- a/libavcodec/vaapi_encode_h264.c +++ b/libavcodec/vaapi_encode_h264.c @@ -146,8 +146,11 @@ typedef struct VAAPIEncodeH264Context { int cpb_delay; int dpb_delay; + int64_t last_idr_frame; + // Rate control configuration. int send_timing_sei; struct { VAEncMiscParameterBuffer misc; VAEncMiscParameterRateControl rc; @@ -947,6 +950,7 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,