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 B81854A507 for ; Fri, 29 Mar 2024 06:49:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 834BF68D627; Fri, 29 Mar 2024 08:49:32 +0200 (EET) Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4118D68D549 for ; Fri, 29 Mar 2024 08:49:26 +0200 (EET) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6ea9a605ca7so1288648b3a.0 for ; Thu, 28 Mar 2024 23:49:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711694964; x=1712299764; darn=ffmpeg.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=yE4ACW+nXFX/MSTVxM5Aje3Y8c4oQycuemg9DNCSHzU=; b=gb9iC94hjDC2ulJ14tlpQ7zms/dbsE9BRVBlgweojREPutgrQW7BlKKjhwHQcV2/NR 1HX0Wkf7BiGMYylX7shjJjsZvVEb7DkLT5csfglSnwQXmNsfNHsfuHRHuOXisA54Ib7F Cn39QdsN8O1WEz2lk7AvceZlHk/hsXLw5b1mejX5GC4OplkACbooC0Op8FYO3Z2dnxsE d6l0az8Rhw9Kr6y0UisbRZ1cz8jL/FGNCRGrlXzqJo1c06UmqX7NbX/BJ/57Ohz1RsTJ 268F+lqqvKpjg/Hu9EyP9mnWbkag3JeTVk0qsy/9xKKeuWl6WiupPTXGU1S2htxduhel QNrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711694964; x=1712299764; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yE4ACW+nXFX/MSTVxM5Aje3Y8c4oQycuemg9DNCSHzU=; b=qYFc9MoiFJeKfg/v8S3LEEaLGAKObzTfz29R0K6ZGIE3InSJW8L5H8C+i8aVLIC5si oismlu1QRrtOkC2Bu4i/qz31KhMqy9n9eIUBvE7NcwUOEkIfgOwuBXe6VadtECc3tle8 U/vI3AAdQtOJejex55YuUg9o64RVVrXHlHX3lLnAVt4nBmgaegZFW6w3341wyHmErg6j GcgZBv+mnHy7cc4Ec2LDobVly+tv9s5ixbIq9n4IfXvSeGVPLKJXqgwlRVXxJxrR0hx8 jGTbpRNr026pJVJ38rTid3H2BQiLBqM7Upth/TjTtCgt0UG1ruZ9n1wvy21cG+guxUkN Vu6g== X-Gm-Message-State: AOJu0YxtwTKys2tBG9Ta43/rjKXrAcme5h91wrTnXVelY96O+DGjsK2S uDQ0HYppxsx2S7OAX0PA/rlEdgsaXyzreNSUHklG81+qXSoaiD2i X-Google-Smtp-Source: AGHT+IFxnOu+2MLHbl9umISS1Bqo9urwjwJutngjb6eRaIHasrufzemBwxygD2bcbHoQmVAwInlZqg== X-Received: by 2002:aa7:888f:0:b0:6ea:be1a:fcbf with SMTP id z15-20020aa7888f000000b006eabe1afcbfmr2271421pfe.16.1711694964067; Thu, 28 Mar 2024 23:49:24 -0700 (PDT) Received: from localhost ([157.82.202.230]) by smtp.gmail.com with UTF8SMTPSA id k14-20020aa790ce000000b006e319d8c752sm2430359pfk.150.2024.03.28.23.49.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 28 Mar 2024 23:49:23 -0700 (PDT) From: Akihiko Odaki Date: Fri, 29 Mar 2024 15:49:20 +0900 MIME-Version: 1.0 Message-Id: <20240329-noopenh264-v2-1-ec34a7223def@gmail.com> X-B4-Tracking: v=1; b=H4sIAG9kBmYC/03MQQrCMBCF4auUWRvJpDGoK+8hXbTppB2wSUkkK CV3NxYEl/+D922QKDIluDYbRMqcOPga6tCAnXs/keCxNiiptFQohQ9hJT8ro4U5SW2Q3GDbFup hjeT4tWP3rvbM6Rnie7czftcfg/9MRoGC8Cwvchito/E2LT0/jjYs0JVSPk4GP1mkAAAA To: ffmpeg-devel@ffmpeg.org, Andreas Rheinhardt X-Mailer: b4 0.14-dev Subject: [FFmpeg-devel] [PATCH v2] lavc/libopenh264: Check for noopenh264 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: Akihiko Odaki Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: noopenh264 is a "fake implementation of the OpenH264 library we can link from regardless of the actual library being available": https://gitlab.com/freedesktop-sdk/noopenh264 A distributor may wish to link against openh264/noopenh264 and let the decoder and encoder work only if the actual library is available. On the other hand, an application may want to know if the decoder or encoder is available beforehand so that it can determine what format to download for decoding, or what format to advertise for the peer receiving the encoded video. Check the availability of the actual library at runtime initialization and do not expose the encoder and decoder if they are not available. The availability check is done by calling WelsCreateDecoder() or WelsCreateSVCEncoder(). These functions do not perform initialization tasks other than allocating objects and assigning function pointers; these tasks are performed by calling the Initialize() function pointer member of the object these functions return. By *not* calling Initialize(), we can ensure that potentially expensive and failable initialization tasks are not unconditionally performed and avoid preparing decoding/encoding parameters it requires. Signed-off-by: Akihiko Odaki --- Changes in v2: - Changed to filter codecs with av_codec_iterate(). - Clarified potentially expensive and failable initialization tasks are not performed by WelsCreateDecoder() or WelsCreateSVCEncoder() but by the Initialize() function pointer member of what they return. - Link to v1: https://lore.kernel.org/r/20240211-noopenh264-v1-1-e18090bdcfed@gmail.com --- libavcodec/allcodecs.c | 5 +++++ libavcodec/codec_internal.h | 4 ++++ libavcodec/libopenh264dec.c | 14 +++++++++++++- libavcodec/libopenh264enc.c | 14 +++++++++++++- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 2386b450a6..73dd4ebd52 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -924,6 +924,11 @@ const AVCodec *av_codec_iterate(void **opaque) uintptr_t i = (uintptr_t)*opaque; const FFCodec *c = codec_list[i]; + while (c && (c->caps_internal & FF_CODEC_CAP_DISABLED)) { + i++; + c = codec_list[i]; + } + ff_thread_once(&av_codec_static_init, av_codec_init_static); if (c) { diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h index d6757e2def..a7f833af72 100644 --- a/libavcodec/codec_internal.h +++ b/libavcodec/codec_internal.h @@ -88,6 +88,10 @@ * encoders do. */ #define FF_CODEC_CAP_EOF_FLUSH (1 << 10) +/** + * Codec was disabled at runtime. + */ +#define FF_CODEC_CAP_DISABLED (1 << 11) /** * FFCodec.codec_tags termination value diff --git a/libavcodec/libopenh264dec.c b/libavcodec/libopenh264dec.c index b6a9bba2dc..8778f490bf 100644 --- a/libavcodec/libopenh264dec.c +++ b/libavcodec/libopenh264dec.c @@ -48,6 +48,17 @@ static av_cold int svc_decode_close(AVCodecContext *avctx) return 0; } +static av_cold void svc_decode_init_static_data(FFCodec *codec) +{ + ISVCDecoder *decoder; + + if (WelsCreateDecoder(&decoder)) { + codec->caps_internal |= FF_CODEC_CAP_DISABLED; + } else { + WelsDestroyDecoder(decoder); + } +} + static av_cold int svc_decode_init(AVCodecContext *avctx) { SVCContext *s = avctx->priv_data; @@ -153,12 +164,13 @@ static int svc_decode_frame(AVCodecContext *avctx, AVFrame *avframe, return avpkt->size; } -const FFCodec ff_libopenh264_decoder = { +FFCodec ff_libopenh264_decoder = { .p.name = "libopenh264", CODEC_LONG_NAME("OpenH264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"), .p.type = AVMEDIA_TYPE_VIDEO, .p.id = AV_CODEC_ID_H264, .priv_data_size = sizeof(SVCContext), + .init_static_data = svc_decode_init_static_data, .init = svc_decode_init, FF_CODEC_DECODE_CB(svc_decode_frame), .close = svc_decode_close, diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c index eef769eed0..6203d1176e 100644 --- a/libavcodec/libopenh264enc.c +++ b/libavcodec/libopenh264enc.c @@ -106,6 +106,17 @@ static av_cold int svc_encode_close(AVCodecContext *avctx) return 0; } +static av_cold void svc_encode_init_static_data(FFCodec *codec) +{ + ISVCEncoder *encoder; + + if (WelsCreateSVCEncoder(&encoder)) { + codec->caps_internal |= FF_CODEC_CAP_DISABLED; + } else { + WelsDestroySVCEncoder(encoder); + } +} + static av_cold int svc_encode_init(AVCodecContext *avctx) { SVCContext *s = avctx->priv_data; @@ -429,7 +440,7 @@ static const FFCodecDefault svc_enc_defaults[] = { { NULL }, }; -const FFCodec ff_libopenh264_encoder = { +FFCodec ff_libopenh264_encoder = { .p.name = "libopenh264", CODEC_LONG_NAME("OpenH264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"), .p.type = AVMEDIA_TYPE_VIDEO, @@ -437,6 +448,7 @@ const FFCodec ff_libopenh264_encoder = { .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_OTHER_THREADS | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, .priv_data_size = sizeof(SVCContext), + .init_static_data = svc_encode_init_static_data, .init = svc_encode_init, FF_CODEC_ENCODE_CB(svc_encode_frame), .close = svc_encode_close, --- base-commit: 8d1093a78413be6718a23dcdbed0b21cee7fcfe6 change-id: 20240210-noopenh264-650461efbc33 Best regards, -- Akihiko Odaki _______________________________________________ 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".