From: Akihiko Odaki <akihiko.odaki@gmail.com> To: ffmpeg-devel@ffmpeg.org, Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Cc: Akihiko Odaki <akihiko.odaki@gmail.com> Subject: [FFmpeg-devel] [PATCH v2] lavc/libopenh264: Check for noopenh264 Date: Fri, 29 Mar 2024 15:49:20 +0900 Message-ID: <20240329-noopenh264-v2-1-ec34a7223def@gmail.com> (raw) 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 <akihiko.odaki@gmail.com> --- 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 <akihiko.odaki@gmail.com> _______________________________________________ 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".
reply other threads:[~2024-03-29 6:49 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240329-noopenh264-v2-1-ec34a7223def@gmail.com \ --to=akihiko.odaki@gmail.com \ --cc=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git