From patchwork Tue Feb 28 22:28:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Sabatini X-Patchwork-Id: 40556 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d046:b0:cd:afd7:272c with SMTP id hv6csp2377583pzb; Tue, 28 Feb 2023 14:29:10 -0800 (PST) X-Google-Smtp-Source: AK7set/VxjWF3kkzA7Oe2zlXMPXT+leXJZyaY89QIAy+P2ESan7gNHz+VSvD3AfdoUKnUldwd2Ee X-Received: by 2002:a17:906:e99:b0:8f1:dfa5:8117 with SMTP id p25-20020a1709060e9900b008f1dfa58117mr3673845ejf.51.1677623349966; Tue, 28 Feb 2023 14:29:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677623349; cv=none; d=google.com; s=arc-20160816; b=OJOKPrpcwAh83/NyGZwPziAvJAvES695iowG6nXgB6remGBQjELTeNV0FxROEscKF5 N7o1E9H/uok5Rp1fqnP4fZM7FdGeqR6FNdHHv2v4JaJ5FoCJdYOQMSQePei0Tz+JblTk o2O2vtq15u3Tf5DqQZurMNVbzE70s+T26SGWgI/vm2PGtzpICz43zAUH82YXjBWRTQbS QI4oGMKrlpI4Q0/5IvmgtTqTiHk6ysxMFe+HeZqsBVejZuKYhBe1fdVqfb5BiOf8diMZ 6yz4mmqgOsAVBlMoaicCcDTIcLItpvV1WV3DsKzSC/yweQtNHodYsgSR/rRjC98ayfzu W+eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=yagVOyZlMoJqBT7hvuU8aV1iqNByzJ/uPKtY99IHTa8=; b=e/Ncv3sdM8EvIZ/XoKgmsPaGOEE6TUx6noJ/IdOwN4AUREF5n9FZX27NKDZ1s/K+tj 8htYiapQ/CpleEo1OVd7OgynTWtDYE+KVldwvLAhfrpVPbaSqXctp4BV+BHpT3W82xgZ hDBwHqK3ofMb4fRybs0c3blTbzgsE+CgMDVTI7Lv0/p2uJGKD2x6bQ3DF1EPG6lyzFoF AxviQZEHNYUtQExuj19EnUlorBXoeE6CWyKNkN58VswIoNsJpqs0a28epxWPuCxjK2Xj J55RJM4U/CDW6q16ghFRFcAXWIPK///23LaDV1eH0gzFQGlX1fJzjowsONG8RQMIKtyR VWSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Uyv3lphN; 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=QUARANTINE 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 l10-20020aa7c30a000000b004aab40d7a3csi1210284edq.138.2023.02.28.14.29.09; Tue, 28 Feb 2023 14:29:09 -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 header.s=20210112 header.b=Uyv3lphN; 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=QUARANTINE 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 9AD1E68B076; Wed, 1 Mar 2023 00:29:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D41D868AFAC for ; Wed, 1 Mar 2023 00:28:59 +0200 (EET) Received: by mail-wm1-f46.google.com with SMTP id o38-20020a05600c512600b003e8320d1c11so320060wms.1 for ; Tue, 28 Feb 2023 14:28:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uUBQYGiWCht6EqB/AMt6zVE9y/fN9/YpXGe8uU7lMTQ=; b=Uyv3lphN9WMEazJ5xfivtTu7wK4JsrQKi1O2dD99uN4tydv2kPmt8iwliFJ2eFiciE MKjpbBmK6oBGS2pdMPtic+9gopT9RNifz7q8HagrfcK1CmprRKk8j2vM84+bGnSW4mMI DZB/AXslbXZEiknPK1MX/rScrxFOzx/q4JB35TEE+8sc7ZZwtX9DptOA52Ysbg7FgIbj /EuZFcn8X8iUSi20hFy8C3xHV/sni+3zuyNN2BQQ/S4WUtN+PBm4TatzlbC0Er0OVQnZ eNRdvwdR69VWyLNu+E5VVd+Df5ndyyOnZZyQ11ZNaf6V/1nKigF1gGgJCWkxqpz6ejTW kTzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uUBQYGiWCht6EqB/AMt6zVE9y/fN9/YpXGe8uU7lMTQ=; b=GqQcDuvmn8fYPyxl52eQLiJwR2JBXVCmwyYzwynW06bJnp5mgSvDHcu5aAch1exuyI zHhRJigv6uUMO8v8H8lwYSkf/vQaMJbBkoaXYyaHLFkIJ/hjYSXbyXwDxTBp5Tue0Vgj NreaAJZmIFEEsUi5EfCCIllHEZChY1JDsgaXhU1wddk3rG6Vamaca9+XtKxkpfq4nXxy 1CdAmeubbh/Cn7kH03OozzlejpcU8wuwXmC6Vd/4Al/liLQmGmKvyscd6x7PPx44OQ3y vLuAUwZmn63B7GdJpyPiudolnvlz/cJe+Rl1HfxRpNGA/MtRzx4Qucodg2ONI8dzoFPF +alQ== X-Gm-Message-State: AO0yUKUvmV/HRsRX6D5F9ssC56e3KbdCSmlVH2JSGrWO5b0BEHoUsmkH +gQD35mTur2Zl7r5aBfXTW2nTQbb2onYFA== X-Received: by 2002:a05:600c:3b26:b0:3ea:f05b:50cc with SMTP id m38-20020a05600c3b2600b003eaf05b50ccmr3895561wms.8.1677623338490; Tue, 28 Feb 2023 14:28:58 -0800 (PST) Received: from mariano (94-37-133-75.adsl-ull.clienti.tiscali.it. [94.37.133.75]) by smtp.gmail.com with ESMTPSA id ja18-20020a05600c557200b003eb0d6f48f3sm16608079wmb.27.2023.02.28.14.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 14:28:57 -0800 (PST) Received: by mariano (Postfix, from userid 1000) id 70FA0BFB73; Tue, 28 Feb 2023 23:28:56 +0100 (CET) From: Stefano Sabatini To: FFmpeg development discussions and patches Date: Tue, 28 Feb 2023 23:28:56 +0100 Message-Id: <20230228222856.39722-1-stefasab@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/avcodec.h: extend documentation for avcodec_open2() 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 Cc: Stefano Sabatini Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 5pZCLevCts4O In particular, clarify how to set options in the codec context, and mention when to use avcodec_parameters_to_context(). Fix trac issue http://trac.ffmpeg.org/ticket/5781. --- libavcodec/avcodec.h | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 9a0fe97cad..2b7fb27721 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2418,8 +2418,9 @@ int avcodec_parameters_to_context(AVCodecContext *codec, * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for * retrieving a codec. * - * @note Always call this function before using decoding routines (such as - * @ref avcodec_receive_frame()). + * Options on the codec context can be either set by providing the options + * specified in an AVDictionary, or by setting the values on the context itself, + * directly or by using the av_opt_set() API. * * @code * av_dict_set(&opts, "b", "2.5M", 0); @@ -2433,17 +2434,35 @@ int avcodec_parameters_to_context(AVCodecContext *codec, * exit(1); * @endcode * + * In case AVCodecParameters are available (e.g. when demuxing a stream using + * libavformat, and accessing the AVStream contained in the demuxer), the codec + * parameters can be copied to the codec context using + * avcodec_parameters_to_context(), as in the following code: + * + * @code + * context = avcodec_alloc_context3(codec); + * if (avcodec_parameters_to_context(*dec_ctx, codecpar) < 0) + * exit(1); + * if (avcodec_open2(context, codec, NULL) < 0) + * exit(1); + * @endcode + * + * @note Always call this function before using decoding routines (such as + * @ref avcodec_receive_frame()). + * * @param avctx The context to initialize. * @param codec The codec to open this context for. If a non-NULL codec has been * previously passed to avcodec_alloc_context3() or * for this context, then this parameter MUST be either NULL or * equal to the previously passed codec. - * @param options A dictionary filled with AVCodecContext and codec-private options. - * On return this object will be filled with options that were not found. + * @param options A dictionary filled with AVCodecContext and codec-private + * options, which are set on top of the options already set in + * avctx, can be NULL. On return this object will be filled with + * options that were not found in avctx. * * @return zero on success, a negative value on error * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(), - * av_dict_set(), av_opt_find(). + * av_dict_set(), av_opt_set(), av_opt_find(), avcodec_parameters_to_context() */ int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);