From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 180A74A9A9 for ; Mon, 6 May 2024 20:45:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3906668D702; Mon, 6 May 2024 23:45:45 +0300 (EEST) Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D74A268D6C3 for ; Mon, 6 May 2024 23:45:38 +0300 (EEST) Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a5200afe39eso615668366b.1 for ; Mon, 06 May 2024 13:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715028337; x=1715633137; darn=ffmpeg.org; h=content-transfer-encoding:content-language:to:subject:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Jp01jetHyXBl5HapGEy6djByMJwfLLMgWBbKCgzfncM=; b=FYKwj//BZfIakxfC/wcII0ycXkPeRvQEvpLFLpzruYChwdE/mP8jdqND9r97Pv/tX5 vPGMNd782m5RLaito1Jgyus8opn8KkBkgW/0sD8dpwDUp5LXuePd4T6mbIU6CDjo16tM NhZQF6fg/mXP9hOa+jJMw9XETYflh0i4G2dWZhU0YH7HTV1Kr8UVAz6nPGQcBZqKsE3G CoyLfYeb1hrZx7m3HS7QK44HurpwmfxTZRXYTz4skAvKAzFhNvHlYzfVIy1r8JRie7lb qs15v57rmhyd6d8cyQN8NroBoULfAvAeu2nNfPFrL1nV/KuepRXM6estM1nAtC/zw6vx mbBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715028337; x=1715633137; h=content-transfer-encoding:content-language:to:subject:from :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Jp01jetHyXBl5HapGEy6djByMJwfLLMgWBbKCgzfncM=; b=UhU0vVWhdPXoeuw+8kqrlr7w4vqjmTsBOB/m6E/LCD1uF03Jzhw5VrkYhv2szsTPZP TFo3dL5WMdOBA9ftv+Bi90TVDxqUpqOf+dDL+jLpJ0M0rhVvqQCh9RwYaXEBKVTeaPeJ 33YIGpYx5Vf12mSegujTkqv/L8XeAqZHwWDW7mGJ9SUGPBGB0YPKE/juldwGHaJZR6WL DCfFwDJ+zOQrxjpMrRmsIUIUWZUXX5DD9wco6T7F46BeCJDMZWkGlUN6KcaoOKbIYQne ijIvQ/BEaLGQuBW51mb2aGo7wqIaOIwB9O+a/hRTS0Bo+AlXfPQuqSNnssAbJUsjdpSj jTzg== X-Gm-Message-State: AOJu0YxQQMcgLNbGSMNezvJ+VdvW8Kr0EGxS4cPAEa5oCdiTHw1ZZft2 ZEv2HQ5oY2uMc4B+sUNwdSd+9siehySYxMudwmdVW770pMnPei6eSIZ+vfY= X-Google-Smtp-Source: AGHT+IG3kdTtjgUN3Z2TcAzzZZt44uP3WYwcL29a5FEZb9otZUh2po9r5PLmshNwerYy0NDjvQnNIA== X-Received: by 2002:a17:906:c415:b0:a59:a977:a159 with SMTP id u21-20020a170906c41500b00a59a977a159mr5977106ejz.64.1715028337507; Mon, 06 May 2024 13:45:37 -0700 (PDT) Received: from [10.111.222.0] ([176.57.69.43]) by smtp.gmail.com with ESMTPSA id me16-20020a170906aed000b00a59cb16818csm1921846ejb.100.2024.05.06.13.45.37 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 May 2024 13:45:37 -0700 (PDT) Message-ID: <821cf833-ed3d-4068-92fb-01b247b767ee@gmail.com> Date: Mon, 6 May 2024 23:44:35 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: =?UTF-8?B?0KfQtdGA0L3QtdC90LrQviDQoNGD0YHQu9Cw0L0=?= To: ffmpeg-devel@ffmpeg.org Content-Language: en-US Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/videotoolbox: av1 decoding not copying the sequence header obu into the bitstream X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: Chernenko Ruslan --- libavcodec/videotoolbox_av1.c | 102 ++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 30 deletions(-) diff --git a/libavcodec/videotoolbox_av1.c b/libavcodec/videotoolbox_av1.c index 7f7270c466..736f2548db 100644 --- a/libavcodec/videotoolbox_av1.c +++ b/libavcodec/videotoolbox_av1.c @@ -19,50 +19,90 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavformat/avio.h" -#include "libavformat/avio_internal.h" -#define CALLED_FROM_AVCODEC 1 -#include "libavformat/av1.c" -#undef CALLED_FROM_AVCODEC -#include "libavutil/avutil.h" -#include "libavutil/frame.h" -#include "libavutil/pixfmt.h" +#include "libavutil/mem.h" #include "av1dec.h" -#include "codec_id.h" #include "hwaccel_internal.h" #include "internal.h" #include "vt_internal.h" -CFDataRef ff_videotoolbox_av1c_extradata_create(AVCodecContext *avctx) + +CFDataRef ff_videotoolbox_av1c_extradata_create(AVCodecContext *avctx) { + + AV1DecContext *s = avctx->priv_data; + avctx->extradata = av_fast_realloc(avctx->extradata, + &avctx->extradata_size, + s->seq_data_ref->size + 4); + avctx->extradata_size = s->seq_data_ref->size + 4; + avctx->extradata[0] = 0x81; // version and marker (constant) + avctx->extradata[1] = s->raw_seq->seq_profile << 5 | s->raw_seq->seq_level_idx[0]; + avctx->extradata[2] = s->raw_seq->seq_tier[0] << 7 | + s->raw_seq->color_config.high_bitdepth << 6 | + s->raw_seq->color_config.twelve_bit << 5 | + s->raw_seq->color_config.mono_chrome << 4 | + s->raw_seq->color_config.subsampling_x << 3 | + s->raw_seq->color_config.subsampling_y << 2 | + s->raw_seq->color_config.chroma_sample_position; + + + if (s->raw_seq->initial_display_delay_present_flag) + avctx->extradata[3] = 0 << 5 | s->raw_seq->initial_display_delay_present_flag << 4 | s->raw_seq->initial_display_delay_minus_1[0]; + else + avctx->extradata[3] = 0x00; + memcpy(avctx->extradata + 4, s->seq_data_ref->data, s->seq_data_ref->size); + CFDataRef data = CFDataCreate(kCFAllocatorDefault, avctx->extradata, avctx->extradata_size); + return data; +}; + + +static int videotoolbox_av1_decode_params(AVCodecContext *avctx, + int header_type, + const uint8_t *buffer, + uint32_t size) { - AVIOContext *pb; - uint8_t *buf; - CFDataRef data = NULL; - int buf_size = 0; - int ret = avio_open_dyn_buf(&pb); - if (ret < 0) - return NULL; + VTContext *vtctx = avctx->internal->hwaccel_priv_data; + void *tmp; - ret = ff_isom_write_av1c(pb, avctx->extradata, avctx->extradata_size, 1); - if (ret < 0) - goto fail; + tmp = av_fast_realloc(vtctx->bitstream, + &vtctx->allocated_size, + size); - buf_size = avio_get_dyn_buf(pb, &buf); - if (buf_size) - data = CFDataCreate(kCFAllocatorDefault, buf, buf_size); + if (!tmp) + return AVERROR(ENOMEM); -fail: - ffio_free_dyn_buf(&pb); + vtctx->bitstream = tmp; - return data; + // copy the sequence header obu into the bitstream + memcpy(vtctx->bitstream + vtctx->bitstream_size, + buffer, + size); + + vtctx->bitstream_size += size; + return 0; } static int videotoolbox_av1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) { + + + VTContext *vtctx = avctx->internal->hwaccel_priv_data; + void *tmp; + + tmp = av_fast_realloc(vtctx->bitstream, + &vtctx->allocated_size, + size); + + if (!tmp) + return AVERROR(ENOMEM); + + vtctx->bitstream = tmp; + + // copy the frame data into the bitstream + memcpy(vtctx->bitstream + vtctx->bitstream_size, buffer, size); + vtctx->bitstream_size += size; return 0; } @@ -70,17 +110,18 @@ static int videotoolbox_av1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) { - VTContext *vtctx = avctx->internal->hwaccel_priv_data; - - return ff_videotoolbox_buffer_copy(vtctx, buffer, size); + return 0; } static int videotoolbox_av1_end_frame(AVCodecContext *avctx) { const AV1DecContext *s = avctx->priv_data; + VTContext *vtctx = avctx->internal->hwaccel_priv_data; AVFrame *frame = s->cur_frame.f; - return ff_videotoolbox_common_end_frame(avctx, frame); + int ret = ff_videotoolbox_common_end_frame(avctx, frame); + vtctx->bitstream_size = 0; + return ret; } const FFHWAccel ff_av1_videotoolbox_hwaccel = { @@ -89,6 +130,7 @@ const FFHWAccel ff_av1_videotoolbox_hwaccel = { .p.id = AV_CODEC_ID_AV1, .p.pix_fmt = AV_PIX_FMT_VIDEOTOOLBOX, .alloc_frame = ff_videotoolbox_alloc_frame, + .decode_params = videotoolbox_av1_decode_params, .start_frame = videotoolbox_av1_start_frame, .decode_slice = videotoolbox_av1_decode_slice, .end_frame = videotoolbox_av1_end_frame, -- 2.39.3 (Apple Git-146) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".