Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avcodec/sbcenc: port to AVCodec.get_supported_config()
@ 2025-02-18 19:28 James Almer
  2025-02-19  2:47 ` Zhao Zhili
  0 siblings, 1 reply; 4+ messages in thread
From: James Almer @ 2025-02-18 19:28 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/sbcenc.c | 50 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 41 insertions(+), 9 deletions(-)

diff --git a/libavcodec/sbcenc.c b/libavcodec/sbcenc.c
index f2c4fbe329..d85ab76cb0 100644
--- a/libavcodec/sbcenc.c
+++ b/libavcodec/sbcenc.c
@@ -194,6 +194,8 @@ static size_t sbc_pack_frame(AVPacket *avpkt, struct sbc_frame *frame,
     return put_bytes_output(&pb);
 }
 
+static const int sbc_supported_samplerates[] = { 16000, 32000, 44100, 48000, 0 };
+
 static int sbc_encode_init(AVCodecContext *avctx)
 {
     SBCEncContext *sbc = avctx->priv_data;
@@ -260,8 +262,8 @@ static int sbc_encode_init(AVCodecContext *avctx)
         avctx->frame_size = 4*((frame->subbands >> 3) + 1) * 4*(frame->blocks >> 2);
     }
 
-    for (int i = 0; avctx->codec->supported_samplerates[i]; i++)
-        if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
+    for (int i = 0; sbc_supported_samplerates[i]; i++)
+        if (avctx->sample_rate == sbc_supported_samplerates[i])
             frame->frequency = i;
 
     frame->channels = avctx->ch_layout.nb_channels;
@@ -326,6 +328,41 @@ static int sbc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     return 0;
 }
 
+static const enum AVSampleFormat sbc_sample_fmts[] = {
+   AV_SAMPLE_FMT_S16,
+   AV_SAMPLE_FMT_NONE
+};
+
+static const AVChannelLayout sbc_ch_layouts[] = {
+    AV_CHANNEL_LAYOUT_MONO,
+    AV_CHANNEL_LAYOUT_STEREO,
+    { 0 }
+};
+
+static int sbc_get_supported_config(const AVCodecContext *avctx,
+                                    const AVCodec *codec,
+                                    enum AVCodecConfig config,
+                                    unsigned flags, const void **out,
+                                    int *out_num)
+{
+    switch (config) {
+    case AV_CODEC_CONFIG_SAMPLE_RATE:
+        *out = sbc_supported_samplerates;
+        *out_num = FF_ARRAY_ELEMS(sbc_supported_samplerates) - 1;
+        return 0;
+    case AV_CODEC_CONFIG_SAMPLE_FORMAT:
+        *out = sbc_sample_fmts;
+        *out_num = FF_ARRAY_ELEMS(sbc_sample_fmts) - 1;
+        return 0;
+    case AV_CODEC_CONFIG_CHANNEL_LAYOUT:
+        *out = sbc_ch_layouts;
+        *out_num = FF_ARRAY_ELEMS(sbc_ch_layouts) - 1;
+        return 0;
+    }
+
+    return ff_default_get_supported_config(avctx, codec, config, flags, out, out_num);
+}
+
 #define OFFSET(x) offsetof(SBCEncContext, x)
 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
@@ -344,7 +381,7 @@ static const AVClass sbc_class = {
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
-const FFCodec ff_sbc_encoder = {
+FFCodec ff_sbc_encoder = {
     .p.name                = "sbc",
     CODEC_LONG_NAME("SBC (low-complexity subband codec)"),
     .p.type                = AVMEDIA_TYPE_AUDIO,
@@ -354,12 +391,7 @@ const FFCodec ff_sbc_encoder = {
     .priv_data_size        = sizeof(SBCEncContext),
     .init                  = sbc_encode_init,
     FF_CODEC_ENCODE_CB(sbc_encode_frame),
-    .p.ch_layouts          = (const AVChannelLayout[]) { AV_CHANNEL_LAYOUT_MONO,
-                                                         AV_CHANNEL_LAYOUT_STEREO,
-                                                         { 0 } },
-    .p.sample_fmts         = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16,
-                                                             AV_SAMPLE_FMT_NONE },
-    .p.supported_samplerates = (const int[]) { 16000, 32000, 44100, 48000, 0 },
+    .get_supported_config  = sbc_get_supported_config,
     .p.priv_class          = &sbc_class,
     .p.profiles            = NULL_IF_CONFIG_SMALL(ff_sbc_profiles),
 };
-- 
2.48.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-02-19  4:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-18 19:28 [FFmpeg-devel] [PATCH] avcodec/sbcenc: port to AVCodec.get_supported_config() James Almer
2025-02-19  2:47 ` Zhao Zhili
2025-02-19  3:08   ` epirat07
2025-02-19  4:02     ` Zhao Zhili

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