From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] avdevice/alsa_dec: add a ch_layout option Date: Tue, 28 Jan 2025 09:57:57 -0300 Message-ID: <20250128125757.742-1-jamrial@gmail.com> (raw) Missed in ffc4fd3cc2ccb2cadb71f19849842b18ca1281c6, which after e78173557da898f18a78241cc3525b76694164b5 broke setting channel count. Should fix ticket #11434. Signed-off-by: James Almer <jamrial@gmail.com> --- libavdevice/alsa.h | 4 ++++ libavdevice/alsa_dec.c | 24 +++++++++++++++++++----- libavdevice/version_major.h | 1 + 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/libavdevice/alsa.h b/libavdevice/alsa.h index 07783c983a..3e1ba31384 100644 --- a/libavdevice/alsa.h +++ b/libavdevice/alsa.h @@ -35,6 +35,7 @@ #include "libavutil/log.h" #include "timefilter.h" #include "avdevice.h" +#include "version.h" /* XXX: we make the assumption that the soundcard accepts this format */ /* XXX: find better solution with "preinit" method, needed also in @@ -51,7 +52,10 @@ typedef struct AlsaData { int frame_size; ///< bytes per sample * channels int period_size; ///< preferred size for reads and writes, in frames int sample_rate; ///< sample rate set by user +#if FF_API_ALSA_CHANNELS int channels; ///< number of channels set by user +#endif + AVChannelLayout ch_layout; ///< Channel layout set by user int last_period; TimeFilter *timefilter; void (*reorder_func)(const void *, void *, int); diff --git a/libavdevice/alsa_dec.c b/libavdevice/alsa_dec.c index 018afaef08..b037c0bf1b 100644 --- a/libavdevice/alsa_dec.c +++ b/libavdevice/alsa_dec.c @@ -73,7 +73,14 @@ static av_cold int audio_read_header(AVFormatContext *s1) } codec_id = s1->audio_codec_id; - ret = ff_alsa_open(s1, SND_PCM_STREAM_CAPTURE, &s->sample_rate, s->channels, +#if FF_API_ALSA_CHANNELS + if (s->channels > 0) { + av_channel_layout_uninit(&s->ch_layout); + s->ch_layout.nb_channels = s->channels; + } +#endif + + ret = ff_alsa_open(s1, SND_PCM_STREAM_CAPTURE, &s->sample_rate, s->ch_layout.nb_channels, &codec_id); if (ret < 0) { return AVERROR(EIO); @@ -83,20 +90,24 @@ static av_cold int audio_read_header(AVFormatContext *s1) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = codec_id; st->codecpar->sample_rate = s->sample_rate; - st->codecpar->ch_layout.nb_channels = s->channels; + ret = av_channel_layout_copy(&st->codecpar->ch_layout, &s->ch_layout); + if (ret < 0) + goto fail; st->codecpar->frame_size = s->frame_size; avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ /* microseconds instead of seconds, MHz instead of Hz */ s->timefilter = ff_timefilter_new(1000000.0 / s->sample_rate, s->period_size, 1.5E-6); - if (!s->timefilter) + if (!s->timefilter) { + ret = AVERROR(EIO); goto fail; + } return 0; fail: snd_pcm_close(s->h); - return AVERROR(EIO); + return ret; } static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt) @@ -146,7 +157,10 @@ static int audio_get_device_list(AVFormatContext *h, AVDeviceInfoList *device_li static const AVOption options[] = { { "sample_rate", "", offsetof(AlsaData, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, - { "channels", "", offsetof(AlsaData, channels), AV_OPT_TYPE_INT, {.i64 = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, +#if FF_API_ALSA_CHANNELS + { "channels", "", offsetof(AlsaData, channels), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_DEPRECATED }, +#endif + { "ch_layout", "", offsetof(AlsaData, ch_layout), AV_OPT_TYPE_CH_LAYOUT, {.str = "2C"}, INT_MIN, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, { NULL }, }; diff --git a/libavdevice/version_major.h b/libavdevice/version_major.h index f16abb6909..50f577f295 100644 --- a/libavdevice/version_major.h +++ b/libavdevice/version_major.h @@ -39,5 +39,6 @@ #define FF_API_OPENGL_DEVICE (LIBAVDEVICE_VERSION_MAJOR < 62) // reminder to remove the sdl2 device on next major bump #define FF_API_SDL2_DEVICE (LIBAVDEVICE_VERSION_MAJOR < 62) +#define FF_API_ALSA_CHANNELS (LIBAVDEVICE_VERSION_MAJOR < 62) #endif /* AVDEVICE_VERSION_MAJOR_H */ -- 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".
next reply other threads:[~2025-01-28 12:58 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-01-28 12:57 James Almer [this message] 2025-02-01 1:43 ` Michael Niedermayer 2025-02-01 1:45 ` James Almer 2025-02-01 2:01 ` Michael Niedermayer 2025-02-01 4:23 ` James Almer
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=20250128125757.742-1-jamrial@gmail.com \ --to=jamrial@gmail.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