From patchwork Sun Nov 19 04:34:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Langdale X-Patchwork-Id: 6191 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp2441929jah; Sat, 18 Nov 2017 20:34:46 -0800 (PST) X-Google-Smtp-Source: AGs4zMZKdDSiT3oGRYqahzHRMd4DUn72zHOLXmgi5otVINezhwVyYx7CxFI29cHAxCGH3We8Hr1/ X-Received: by 10.223.186.202 with SMTP id w10mr8722891wrg.132.1511066086518; Sat, 18 Nov 2017 20:34:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511066086; cv=none; d=google.com; s=arc-20160816; b=oJaLJeC52XjOIJV9PRl63h4GMtJrUapAI91bbP7z7ZxAOYDz6YWR0bksTs5wNJr87q U4dVhsKNS+j8qIoiFhZGKbKW923lt6+uFXt8guCQA1xlU6sDuwC2kXsnB4Ztsxr/alGs jF+WpoW/ByUs0yudm7XAVOsTDk5LhuHo2aU3j/clzli2kPKDiQ/dEfIxQE4S1E+gxlFr y65wCwmjoURubwIKUZ+rgIN+6VFKjDZQ6GGRPL+QYqhMQkHC/OHN1Xbk+349f9PPWTiu NqMMOANQZF2FTwa4A7zWJ12vbBI5VUWtDki0yOX/g3Aqv/r/JtGYLqbWS1A2w0ZVoqGM ovfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=3JTClKqwsyuPE7B0zcNONEgb+RFBJbORz25T+e0Z8fk=; b=TyiPpD6RZgFiVjSpXozdNt0DEL6TsYDyemAufe4cDfQfxDUiVyXz14JbVUqO/hfuSv mj/lxB53s8DDTR5JC6rO1poMxY7ZEQpirxebBBar/bMDTo7w8nWDG1mpUq4CSXZKJa5j 3pj510ihfEjlt3Djr4lA5bLqWMuAdKeTDjPKQu1xE0lMPk33RX6GoUAQTFkwDGt6b35S E7BN9XMhSXxN6AavKa2SXWl8WblOSKpGvyAjZ3luoxXCMSsPs6QSEXj9/fQ4gk6ALgsQ laVitwhP9VLLMVvD9CicpKmRD1SP+3UsgiQDpUlGeYB26gNVkkYcuF7J1g00DceQQZFQ PKTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@overt.org header.s=mail header.b=WKx59x9Z; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w8si5877698wra.407.2017.11.18.20.34.46; Sat, 18 Nov 2017 20:34:46 -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=@overt.org header.s=mail header.b=WKx59x9Z; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4E2ED689224; Sun, 19 Nov 2017 06:34:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f100.google.com (mail-it0-f100.google.com [209.85.214.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 369F7688323 for ; Sun, 19 Nov 2017 06:34:21 +0200 (EET) Received: by mail-it0-f100.google.com with SMTP id y15so8386719ita.4 for ; Sat, 18 Nov 2017 20:34:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=e5uU+fbNIWAT6EMhaJ26o2IaVbKmLKdFm7XxbdiL96M=; b=HNd0PSnEsRoSVia0zUStdFr05p0V+9gcbQOw+bXeANS063CAkk/RmrhTfXvCcC5zbw 5+bLhXMglw9zTbyKUUTyfzjheTld2Jk6GdF75UqMtyvERtJR3cmlxo4FWIO4rKlu46wq HXaefqXqkVGUercXBo/6gUlNWuU2u7Hbq0o42Fdoz30DW2l33JGP/dqgydK15RBHpvL+ VC2EKsneGGV8lOyfszcey+PXGF8oauODDdLohDathvUtUWNI4QtkLv22cq7sQg8LJHZh r1K1UW7857GjxciiFG9nZRoNXRPODxl7U/c4AIecNbfNgAeG+9Yodgke7EQQCquLemta X5cg== X-Gm-Message-State: AJaThX5vs9+rd7elf3ZV/XcdPsznx4J9Dq727OTJL3V3u9JzGVDaH25A BMU+2XaQ9muKhRWyjgvq1I5r5sslpiF7CDlWCUp8QsIxyhvsNA== X-Received: by 10.36.128.212 with SMTP id g203mr13132841itd.108.1511066076652; Sat, 18 Nov 2017 20:34:36 -0800 (PST) Received: from mail.overt.org (155.208.178.107.bc.googleusercontent.com. [107.178.208.155]) by smtp-relay.gmail.com with ESMTPS id v203sm2426363itb.6.2017.11.18.20.34.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Nov 2017 20:34:36 -0800 (PST) X-Relaying-Domain: gapps.overt.org Received: from authenticated-user (mail.overt.org [107.178.208.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.overt.org (Postfix) with ESMTPSA id 1D0C260134; Sun, 19 Nov 2017 04:34:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=overt.org; s=mail; t=1511066076; bh=3PVX5U1PZawnHNSX1ULdymLD9IdosPAR7xFVdMq+Cjw=; h=From:To:Cc:Subject:Date:From; b=WKx59x9ZG16R+FmY0kA+MXT5J28RFU9hKP8sIb2ex/slte51ARFThH9k2ZbCBvJUD VcalDek6WMht6nPeYJfYSWEG0vFN6iZzl9KYZbBxmUlW18X3TlTTrnu0rnx9nZmvxw /dZ1CG4a+VELRc7HVPaifPK/aI7Mn2fdOBITIU+JJ+j/fG0cIelqYNbN+Z8Ihp5Z1Z kr5Q7gknWKq6iZbL6BgFguLlF8HjH6cgByM18fYXYq0/ESIqjKhKnNmHpiz3cIxsxy Dpl6YkUZ4OhHHIXmdCHi/0L6Oj3CNCQt7o9icQwNaa/PKZZuc1P2uYOsGg6rMTjxqH mFMrbL7TjvmSQ== From: Philip Langdale To: ffmpeg-devel@ffmpeg.org Date: Sat, 18 Nov 2017 20:34:32 -0800 Message-Id: <20171119043432.18582-1-philipl@overt.org> Subject: [FFmpeg-devel] [PATCH] avcodec: Refactor common nvdec hwaccel logic 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 Cc: Philip Langdale MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The 'simple' hwaccels (not h.264 and hevc) all use the same bitstream management and reference lookup logic so let's refactor all that into common functions. Signed-off-by: Philip Langdale --- libavcodec/nvdec.c | 46 +++++++++++++++++++++++++++++++++++++++ libavcodec/nvdec.h | 4 ++++ libavcodec/nvdec_mpeg12.c | 53 ++++----------------------------------------- libavcodec/nvdec_vc1.c | 55 ++++++----------------------------------------- libavcodec/nvdec_vp9.c | 53 +++++---------------------------------------- 5 files changed, 65 insertions(+), 146 deletions(-) diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c index 3d62840e9f..97ff605f0f 100644 --- a/libavcodec/nvdec.c +++ b/libavcodec/nvdec.c @@ -475,6 +475,36 @@ finish: return ret; } +int ff_nvdec_simple_end_frame(AVCodecContext *avctx) +{ + NVDECContext *ctx = avctx->internal->hwaccel_priv_data; + int ret = ff_nvdec_end_frame(avctx); + ctx->bitstream = NULL; + return ret; +} + +int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, + uint32_t size) +{ + NVDECContext *ctx = avctx->internal->hwaccel_priv_data; + void *tmp; + + tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated, + (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets)); + if (!tmp) + return AVERROR(ENOMEM); + ctx->slice_offsets = tmp; + + if (!ctx->bitstream) + ctx->bitstream = (uint8_t*)buffer; + + ctx->slice_offsets[ctx->nb_slices] = buffer - ctx->bitstream; + ctx->bitstream_len += size; + ctx->nb_slices++; + + return 0; +} + int ff_nvdec_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx, int dpb_size) @@ -520,3 +550,19 @@ int ff_nvdec_frame_params(AVCodecContext *avctx, return 0; } + +int ff_nvdec_get_ref_idx(AVFrame *frame) +{ + FrameDecodeData *fdd; + NVDECFrame *cf; + + if (!frame || !frame->private_ref) + return -1; + + fdd = (FrameDecodeData*)frame->private_ref->data; + cf = (NVDECFrame*)fdd->hwaccel_priv; + if (!cf) + return -1; + + return cf->idx; +} diff --git a/libavcodec/nvdec.h b/libavcodec/nvdec.h index 14d29ee94b..90578d5a1c 100644 --- a/libavcodec/nvdec.h +++ b/libavcodec/nvdec.h @@ -58,8 +58,12 @@ int ff_nvdec_decode_init(AVCodecContext *avctx); int ff_nvdec_decode_uninit(AVCodecContext *avctx); int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame); int ff_nvdec_end_frame(AVCodecContext *avctx); +int ff_nvdec_simple_end_frame(AVCodecContext *avctx); +int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, + uint32_t size); int ff_nvdec_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx, int dpb_size); +int ff_nvdec_get_ref_idx(AVFrame *frame); #endif /* AVCODEC_NVDEC_H */ diff --git a/libavcodec/nvdec_mpeg12.c b/libavcodec/nvdec_mpeg12.c index 127e843d85..db9cebeddd 100644 --- a/libavcodec/nvdec_mpeg12.c +++ b/libavcodec/nvdec_mpeg12.c @@ -25,22 +25,6 @@ #include "nvdec.h" #include "decode.h" -static int get_ref_idx(AVFrame *frame) -{ - FrameDecodeData *fdd; - NVDECFrame *cf; - - if (!frame || !frame->private_ref) - return -1; - - fdd = (FrameDecodeData*)frame->private_ref->data; - cf = (NVDECFrame*)fdd->hwaccel_priv; - if (!cf) - return -1; - - return cf->idx; -} - static int nvdec_mpeg12_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) { MpegEncContext *s = avctx->priv_data; @@ -71,8 +55,8 @@ static int nvdec_mpeg12_start_frame(AVCodecContext *avctx, const uint8_t *buffer s->pict_type == AV_PICTURE_TYPE_P, .CodecSpecific.mpeg2 = { - .ForwardRefIdx = get_ref_idx(s->last_picture.f), - .BackwardRefIdx = get_ref_idx(s->next_picture.f), + .ForwardRefIdx = ff_nvdec_get_ref_idx(s->last_picture.f), + .BackwardRefIdx = ff_nvdec_get_ref_idx(s->next_picture.f), .picture_coding_type = s->pict_type, .full_pel_forward_vector = s->full_pel[0], @@ -99,35 +83,6 @@ static int nvdec_mpeg12_start_frame(AVCodecContext *avctx, const uint8_t *buffer return 0; } -static int nvdec_mpeg12_end_frame(AVCodecContext *avctx) -{ - NVDECContext *ctx = avctx->internal->hwaccel_priv_data; - int ret = ff_nvdec_end_frame(avctx); - ctx->bitstream = NULL; - return ret; -} - -static int nvdec_mpeg12_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) -{ - NVDECContext *ctx = avctx->internal->hwaccel_priv_data; - void *tmp; - - tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated, - (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets)); - if (!tmp) - return AVERROR(ENOMEM); - ctx->slice_offsets = tmp; - - if (!ctx->bitstream) - ctx->bitstream = (uint8_t*)buffer; - - ctx->slice_offsets[ctx->nb_slices] = buffer - ctx->bitstream; - ctx->bitstream_len += size; - ctx->nb_slices++; - - return 0; -} - static int nvdec_mpeg12_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx) { @@ -142,8 +97,8 @@ AVHWAccel ff_mpeg2_nvdec_hwaccel = { .id = AV_CODEC_ID_MPEG2VIDEO, .pix_fmt = AV_PIX_FMT_CUDA, .start_frame = nvdec_mpeg12_start_frame, - .end_frame = nvdec_mpeg12_end_frame, - .decode_slice = nvdec_mpeg12_decode_slice, + .end_frame = ff_nvdec_simple_end_frame, + .decode_slice = ff_nvdec_simple_decode_slice, .frame_params = nvdec_mpeg12_frame_params, .init = ff_nvdec_decode_init, .uninit = ff_nvdec_decode_uninit, diff --git a/libavcodec/nvdec_vc1.c b/libavcodec/nvdec_vc1.c index 588a5b9d07..c04b153a86 100644 --- a/libavcodec/nvdec_vc1.c +++ b/libavcodec/nvdec_vc1.c @@ -25,20 +25,6 @@ #include "decode.h" #include "vc1.h" -static int get_ref_idx(AVFrame *frame) -{ - FrameDecodeData *fdd; - NVDECFrame *cf; - - if (!frame || !frame->private_ref) - return -1; - - fdd = (FrameDecodeData*)frame->private_ref->data; - cf = (NVDECFrame*)fdd->hwaccel_priv; - - return cf->idx; -} - static int nvdec_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) { VC1Context *v = avctx->priv_data; @@ -73,8 +59,8 @@ static int nvdec_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u s->pict_type == AV_PICTURE_TYPE_P, .CodecSpecific.vc1 = { - .ForwardRefIdx = get_ref_idx(s->last_picture.f), - .BackwardRefIdx = get_ref_idx(s->next_picture.f), + .ForwardRefIdx = ff_nvdec_get_ref_idx(s->last_picture.f), + .BackwardRefIdx = ff_nvdec_get_ref_idx(s->next_picture.f), .FrameWidth = cur_frame->width, .FrameHeight = cur_frame->height, @@ -117,35 +103,6 @@ static int nvdec_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u return 0; } -static int nvdec_vc1_end_frame(AVCodecContext *avctx) -{ - NVDECContext *ctx = avctx->internal->hwaccel_priv_data; - int ret = ff_nvdec_end_frame(avctx); - ctx->bitstream = NULL; - return ret; -} - -static int nvdec_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) -{ - NVDECContext *ctx = avctx->internal->hwaccel_priv_data; - void *tmp; - - tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated, - (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets)); - if (!tmp) - return AVERROR(ENOMEM); - ctx->slice_offsets = tmp; - - if (!ctx->bitstream) - ctx->bitstream = (uint8_t*)buffer; - - ctx->slice_offsets[ctx->nb_slices] = buffer - ctx->bitstream; - ctx->bitstream_len += size; - ctx->nb_slices++; - - return 0; -} - static int nvdec_vc1_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx) { @@ -159,8 +116,8 @@ AVHWAccel ff_vc1_nvdec_hwaccel = { .id = AV_CODEC_ID_VC1, .pix_fmt = AV_PIX_FMT_CUDA, .start_frame = nvdec_vc1_start_frame, - .end_frame = nvdec_vc1_end_frame, - .decode_slice = nvdec_vc1_decode_slice, + .end_frame = ff_nvdec_simple_end_frame, + .decode_slice = ff_nvdec_simple_decode_slice, .frame_params = nvdec_vc1_frame_params, .init = ff_nvdec_decode_init, .uninit = ff_nvdec_decode_uninit, @@ -174,8 +131,8 @@ AVHWAccel ff_wmv3_nvdec_hwaccel = { .id = AV_CODEC_ID_WMV3, .pix_fmt = AV_PIX_FMT_CUDA, .start_frame = nvdec_vc1_start_frame, - .end_frame = nvdec_vc1_end_frame, - .decode_slice = nvdec_vc1_decode_slice, + .end_frame = ff_nvdec_simple_end_frame, + .decode_slice = ff_nvdec_simple_decode_slice, .frame_params = nvdec_vc1_frame_params, .init = ff_nvdec_decode_init, .uninit = ff_nvdec_decode_uninit, diff --git a/libavcodec/nvdec_vp9.c b/libavcodec/nvdec_vp9.c index 06c13e6f03..ed06d91416 100644 --- a/libavcodec/nvdec_vp9.c +++ b/libavcodec/nvdec_vp9.c @@ -28,20 +28,6 @@ #include "internal.h" #include "vp9shared.h" -static unsigned char get_ref_idx(AVFrame *frame) -{ - FrameDecodeData *fdd; - NVDECFrame *cf; - - if (!frame || !frame->private_ref) - return 255; - - fdd = (FrameDecodeData*)frame->private_ref->data; - cf = (NVDECFrame*)fdd->hwaccel_priv; - - return cf->idx; -} - static int nvdec_vp9_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) { VP9SharedContext *h = avctx->priv_data; @@ -72,9 +58,9 @@ static int nvdec_vp9_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u .width = cur_frame->width, .height = cur_frame->height, - .LastRefIdx = get_ref_idx(h->refs[h->h.refidx[0]].f), - .GoldenRefIdx = get_ref_idx(h->refs[h->h.refidx[1]].f), - .AltRefIdx = get_ref_idx(h->refs[h->h.refidx[2]].f), + .LastRefIdx = ff_nvdec_get_ref_idx(h->refs[h->h.refidx[0]].f), + .GoldenRefIdx = ff_nvdec_get_ref_idx(h->refs[h->h.refidx[1]].f), + .AltRefIdx = ff_nvdec_get_ref_idx(h->refs[h->h.refidx[2]].f), .profile = h->h.profile, .frameContextIdx = h->h.framectxid, @@ -176,35 +162,6 @@ static int nvdec_vp9_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u return 0; } -static int nvdec_vp9_end_frame(AVCodecContext *avctx) -{ - NVDECContext *ctx = avctx->internal->hwaccel_priv_data; - int ret = ff_nvdec_end_frame(avctx); - ctx->bitstream = NULL; - return ret; -} - -static int nvdec_vp9_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) -{ - NVDECContext *ctx = avctx->internal->hwaccel_priv_data; - void *tmp; - - tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated, - (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets)); - if (!tmp) - return AVERROR(ENOMEM); - ctx->slice_offsets = tmp; - - if (!ctx->bitstream) - ctx->bitstream = (uint8_t*)buffer; - - ctx->slice_offsets[ctx->nb_slices] = buffer - ctx->bitstream; - ctx->bitstream_len += size; - ctx->nb_slices++; - - return 0; -} - static int nvdec_vp9_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx) { @@ -218,8 +175,8 @@ AVHWAccel ff_vp9_nvdec_hwaccel = { .id = AV_CODEC_ID_VP9, .pix_fmt = AV_PIX_FMT_CUDA, .start_frame = nvdec_vp9_start_frame, - .end_frame = nvdec_vp9_end_frame, - .decode_slice = nvdec_vp9_decode_slice, + .end_frame = ff_nvdec_simple_end_frame, + .decode_slice = ff_nvdec_simple_decode_slice, .frame_params = nvdec_vp9_frame_params, .init = ff_nvdec_decode_init, .uninit = ff_nvdec_decode_uninit,