From patchwork Thu Aug 24 01:13:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jun Zhao X-Patchwork-Id: 4813 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp142357jao; Wed, 23 Aug 2017 18:13:20 -0700 (PDT) X-Received: by 10.28.101.139 with SMTP id z133mr2752870wmb.160.1503537200111; Wed, 23 Aug 2017 18:13:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503537200; cv=none; d=google.com; s=arc-20160816; b=aYAcn/BnoCb2wqoTjSdghcIVklpynCcW0gneSfYhfBjIFLHl0Uc/bHKw6xxEvt70LH zhapx6PwFiENr56CpDH6lF+Wi02GcEEpMR/3KCPZRk5I7J2CN5lSwUe4PlTv4P16gR+l Tf77sio2SoQuTwT2Vlo4HNthudYli3GGKOhdqcRLpXheMHfOrBLX4wXV8CGvzp9UZM6m 1GaRSRsjE091BqIGYK4WP+HiEsCMHtY4Xbf6L6e63H1hihmVMfhwZzKesRZKefPa0UY5 bDfS3w2yqcBkcJlFk9yLuVtRsEbhsuA/x7CoXcmUAVojASr6OWDyI2upvU6BSgnNZJvH Ncrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:mime-version:user-agent:date:message-id:from:to :dkim-signature:delivered-to:arc-authentication-results; bh=nPpedMtJtfq0wzt+Eer5cnh3vX5GtGmMrJ3NBvSYVpM=; b=O1vH4DRCi/d24OE+DXmZARmbHys5ccDEEaAze/FmBqY/fOLgHQH2MEdfaVlmXNcfAW 2Ja9MYJIS8Nxjq8Yp3OhZHTjT5HGtmvmiqAX76yf9guWQCGJ5RfRPONExA6bqEPu8EHp gIEaMDtxabDAHNBxB0W/Rkcb8Usx7Lleo0AxrljORQMmize1Kyy02zRNjqmPzY8Z1IMt zIxDNvgjN9K8iyb5bWI9qonRbIN8jhWLIhWwhhfAdrc21HHeW7Z05TpYvnr11N1o9Jn7 U9Ll09CGmJMdEYxp/LidApptbucq8yoQnis0/9OYVySTPFz9zcEUdtB/5vybFiEomskn lOXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=eIzQB7qI; 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 sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h1si2281815wrc.69.2017.08.23.18.13.15; Wed, 23 Aug 2017 18:13:20 -0700 (PDT) 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 header.s=20161025 header.b=eIzQB7qI; 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 sp=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 A3AF6689895; Thu, 24 Aug 2017 04:13:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f52.google.com (mail-pg0-f52.google.com [74.125.83.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BC593680640 for ; Thu, 24 Aug 2017 04:12:59 +0300 (EEST) Received: by mail-pg0-f52.google.com with SMTP id u191so8186830pgc.2 for ; Wed, 23 Aug 2017 18:13:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=tSON0ol60/V2M2npsgrMIGPZK/I+FO3TLNuM4oH0jIU=; b=eIzQB7qIHRJZvKbScjwnjg2/wJhmpCqMF52m7AIFfnA3hUwwd6PClST0hccBdzqPXK pamnNyDp0KwNcEBZuwRP67cmq/IHjxt5Hw9bfigY6DpJoTcN+8dzWR8GNpuFnmSXA5Gg dlSqj3SLJ/sc/1RKmrouGHPo3XYSazqghPrF+BXkx1GTuTN1GlJwkLG69o7z5EM01Sik H7ZDXA0mVbpA0db8wJYSxwdkCh6V27y61i1xgU1YFGjazvrotaZtnwYXX02F9lB7s4Hk OUDO4X/PZRpSBLtwmDIRCsz/cX3eTT3B97rW5fmLl5XssF1z6/7U9H6ypyj33X5u0dPb ZpEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=tSON0ol60/V2M2npsgrMIGPZK/I+FO3TLNuM4oH0jIU=; b=D4TgvzbB+rkM365HO4/0MbJDR+IJp2KdtlZTJYGDVLj46QZ/mcBcvzZkUIN1OJNCdT d1tIQmOI9c8PuHVV6AE3xLhr9GFogNvx3lpJwQtJgkgC5VMsX1tavd1h1pVdeBrrHPm8 T28Q3l7awoKyQDokGc5I0jOU3LuYeMpiFM/UISyBY8yCojIYxUCSZn+KVGu3LxXazT/a TRQ/cG9BcVoZJH3wiDnPnjOxdWND1eqIsapoIbWWMXyOzizBGpm8jFqiTt5B4bSi7Ue8 3kt/jT2CWDbNw4BZAd4DvAYuAeCKJ+wS08b942cV5Jwya6nT0l83/L5uSpZnPCdu54uw F9Vw== X-Gm-Message-State: AHYfb5gPMoNhsVe1aZB+sg7jgv5R4RZS3CWBqoz+T+sNjEgQIDKCgwoc UIbhkauD4GwfyQ== X-Received: by 10.99.127.93 with SMTP id p29mr4566593pgn.51.1503537185977; Wed, 23 Aug 2017 18:13:05 -0700 (PDT) Received: from [10.67.68.67] ([192.55.54.40]) by smtp.gmail.com with ESMTPSA id b81sm6581983pfm.62.2017.08.23.18.13.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Aug 2017 18:13:04 -0700 (PDT) To: FFmpeg development discussions and patches , Mark Thompson , Steven Liu From: Jun Zhao Message-ID: <6c45b035-87ee-64ec-5d95-3eba5fc82c7c@gmail.com> Date: Thu, 24 Aug 2017 09:13:01 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 Content-Language: en-US Subject: [FFmpeg-devel] [V5 1/4] lavc/vaapi_encode: Change the slice/parameter buffers to dynamic alloc. 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" V5: - In h265_vaapi encoder, when setting slice number > max slice number       supported by driver, report error and return. Same as h264_vaapi.     - Clean the logic when setting first_slice_segment_in_pic_flags   V4: - Change the array malloc function.     - Clean the pointless condition check when free the memory. V3: - Making pic->slices be VAAPIEncodeSlice* instead of VAAPIEncodeSlice**. - Fix resource (vaBuffer) lead when realloc pic->param_buffers fail. - Adjust max_slices location in VAAPIEncodeContext. - Re-work distributing the macro-blocks for multi-slices function. V2: - Change the slice/parameter buffers to dynamic alloc and split the mutil-slice support for AVC/HEVC. From a1078385915d53ec94559ed897eb253e537d1f65 Mon Sep 17 00:00:00 2001 From: Jun Zhao Date: Mon, 31 Jul 2017 22:46:23 -0400 Subject: [V5 1/4] lavc/vaapi_encode: Change the slice/parameter buffers to dynamic alloc. Change the slice/parameter buffers to be allocated dynamically. Signed-off-by: Wang, Yi A Signed-off-by: Jun Zhao --- libavcodec/vaapi_encode.c | 44 ++++++++++++++++++++++++++++++++------------ libavcodec/vaapi_encode.h | 6 ++---- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 22114bedbe..f49e0e3b91 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -36,13 +36,18 @@ static int vaapi_encode_make_packed_header(AVCodecContext *avctx, VAAPIEncodeContext *ctx = avctx->priv_data; VAStatus vas; VABufferID param_buffer, data_buffer; + VABufferID *tmp; VAEncPackedHeaderParameterBuffer params = { .type = type, .bit_length = bit_len, .has_emulation_bytes = 1, }; - av_assert0(pic->nb_param_buffers + 2 <= MAX_PARAM_BUFFERS); + tmp = av_realloc_array(pic->param_buffers, sizeof(*tmp), pic->nb_param_buffers + 2); + if (!tmp) { + return AVERROR(ENOMEM); + } + pic->param_buffers = tmp; vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, VAEncPackedHeaderParameterBufferType, @@ -77,9 +82,14 @@ static int vaapi_encode_make_param_buffer(AVCodecContext *avctx, { VAAPIEncodeContext *ctx = avctx->priv_data; VAStatus vas; + VABufferID *tmp; VABufferID buffer; - av_assert0(pic->nb_param_buffers + 1 <= MAX_PARAM_BUFFERS); + tmp = av_realloc_array(pic->param_buffers, sizeof(*tmp), pic->nb_param_buffers + 1); + if (!tmp) { + return AVERROR(ENOMEM); + } + pic->param_buffers = tmp; vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, type, len, 1, data, &buffer); @@ -313,15 +323,14 @@ static int vaapi_encode_issue(AVCodecContext *avctx, } } - av_assert0(pic->nb_slices <= MAX_PICTURE_SLICES); + pic->slices = av_mallocz_array(pic->nb_slices, sizeof(*pic->slices)); + if (!pic->slices) { + err = AVERROR(ENOMEM); + goto fail; + } for (i = 0; i < pic->nb_slices; i++) { - slice = av_mallocz(sizeof(*slice)); - if (!slice) { - err = AVERROR(ENOMEM); - goto fail; - } + slice = &pic->slices[i]; slice->index = i; - pic->slices[i] = slice; if (ctx->codec->slice_params_size > 0) { slice->codec_slice_params = av_mallocz(ctx->codec->slice_params_size); @@ -425,8 +434,16 @@ fail_with_picture: fail: for(i = 0; i < pic->nb_param_buffers; i++) vaDestroyBuffer(ctx->hwctx->display, pic->param_buffers[i]); + for (i = 0; i < pic->nb_slices; i++) { + if (pic->slices) { + av_freep(&pic->slices[i].priv_data); + av_freep(&pic->slices[i].codec_slice_params); + } + } fail_at_end: av_freep(&pic->codec_picture_params); + av_freep(&pic->param_buffers); + av_freep(&pic->slices); av_frame_free(&pic->recon_image); av_buffer_unref(&pic->output_buffer_ref); pic->output_buffer = VA_INVALID_ID; @@ -535,15 +552,18 @@ static int vaapi_encode_free(AVCodecContext *avctx, vaapi_encode_discard(avctx, pic); for (i = 0; i < pic->nb_slices; i++) { - av_freep(&pic->slices[i]->priv_data); - av_freep(&pic->slices[i]->codec_slice_params); - av_freep(&pic->slices[i]); + if (pic->slices) { + av_freep(&pic->slices[i].priv_data); + av_freep(&pic->slices[i].codec_slice_params); + } } av_freep(&pic->codec_picture_params); av_frame_free(&pic->input_image); av_frame_free(&pic->recon_image); + av_freep(&pic->param_buffers); + av_freep(&pic->slices); // Output buffer should already be destroyed. av_assert0(pic->output_buffer == VA_INVALID_ID); diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h index 3bf0cc87c7..364b5b8028 100644 --- a/libavcodec/vaapi_encode.h +++ b/libavcodec/vaapi_encode.h @@ -35,8 +35,6 @@ enum { MAX_CONFIG_ATTRIBUTES = 4, MAX_GLOBAL_PARAMS = 4, MAX_PICTURE_REFERENCES = 2, - MAX_PICTURE_SLICES = 112, - MAX_PARAM_BUFFERS = 128, MAX_REORDER_DELAY = 16, MAX_PARAM_BUFFER_SIZE = 1024, }; @@ -73,7 +71,7 @@ typedef struct VAAPIEncodePicture { VASurfaceID recon_surface; int nb_param_buffers; - VABufferID param_buffers[MAX_PARAM_BUFFERS]; + VABufferID *param_buffers; AVBufferRef *output_buffer_ref; VABufferID output_buffer; @@ -85,7 +83,7 @@ typedef struct VAAPIEncodePicture { struct VAAPIEncodePicture *refs[MAX_PICTURE_REFERENCES]; int nb_slices; - VAAPIEncodeSlice *slices[MAX_PICTURE_SLICES]; + VAAPIEncodeSlice *slices; } VAAPIEncodePicture; typedef struct VAAPIEncodeContext {