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] avdevice/alsa_dec: add a ch_layout option
@ 2025-01-28 12:57 James Almer
  2025-02-01  1:43 ` Michael Niedermayer
  0 siblings, 1 reply; 5+ messages in thread
From: James Almer @ 2025-01-28 12:57 UTC (permalink / raw)
  To: ffmpeg-devel

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

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

* Re: [FFmpeg-devel] [PATCH] avdevice/alsa_dec: add a ch_layout option
  2025-01-28 12:57 [FFmpeg-devel] [PATCH] avdevice/alsa_dec: add a ch_layout option James Almer
@ 2025-02-01  1:43 ` Michael Niedermayer
  2025-02-01  1:45   ` James Almer
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Niedermayer @ 2025-02-01  1:43 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 1289 bytes --]

On Tue, Jan 28, 2025 at 09:57:57AM -0300, James Almer wrote:
> 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(-)

seems not to build on its own (if its intended to)

libavdevice/alsa_dec.c:163:59: error: ‘AV_OPT_TYPE_CH_LAYOUT’ undeclared here (not in a function); did you mean ‘AV_OPT_TYPE_CHLAYOUT’?
  163 |     { "ch_layout",   "", offsetof(AlsaData, ch_layout),   AV_OPT_TYPE_CH_LAYOUT, {.str = "2C"}, INT_MIN, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
      |                                                           ^~~~~~~~~~~~~~~~~~~~~
      |                                                           AV_OPT_TYPE_CHLAYOUT
make: *** [ffbuild/common.mak:81: libavdevice/alsa_dec.o] Error 1


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avdevice/alsa_dec: add a ch_layout option
  2025-02-01  1:43 ` Michael Niedermayer
@ 2025-02-01  1:45   ` James Almer
  2025-02-01  2:01     ` Michael Niedermayer
  0 siblings, 1 reply; 5+ messages in thread
From: James Almer @ 2025-02-01  1:45 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 1229 bytes --]

On 1/31/2025 10:43 PM, Michael Niedermayer wrote:
> On Tue, Jan 28, 2025 at 09:57:57AM -0300, James Almer wrote:
>> 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(-)
> 
> seems not to build on its own (if its intended to)

I can't test, so i wrote it blindly.

> 
> libavdevice/alsa_dec.c:163:59: error: ‘AV_OPT_TYPE_CH_LAYOUT’ undeclared here (not in a function); did you mean ‘AV_OPT_TYPE_CHLAYOUT’?
>    163 |     { "ch_layout",   "", offsetof(AlsaData, ch_layout),   AV_OPT_TYPE_CH_LAYOUT, {.str = "2C"}, INT_MIN, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
>        |                                                           ^~~~~~~~~~~~~~~~~~~~~
>        |                                                           AV_OPT_TYPE_CHLAYOUT

Is that the only error? Can you check if it compiles if you fix that typo?


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avdevice/alsa_dec: add a ch_layout option
  2025-02-01  1:45   ` James Almer
@ 2025-02-01  2:01     ` Michael Niedermayer
  2025-02-01  4:23       ` James Almer
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Niedermayer @ 2025-02-01  2:01 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 1584 bytes --]

On Fri, Jan 31, 2025 at 10:45:13PM -0300, James Almer wrote:
> On 1/31/2025 10:43 PM, Michael Niedermayer wrote:
> > On Tue, Jan 28, 2025 at 09:57:57AM -0300, James Almer wrote:
> > > 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(-)
> > 
> > seems not to build on its own (if its intended to)
> 
> I can't test, so i wrote it blindly.
> 
> > 
> > libavdevice/alsa_dec.c:163:59: error: ‘AV_OPT_TYPE_CH_LAYOUT’ undeclared here (not in a function); did you mean ‘AV_OPT_TYPE_CHLAYOUT’?
> >    163 |     { "ch_layout",   "", offsetof(AlsaData, ch_layout),   AV_OPT_TYPE_CH_LAYOUT, {.str = "2C"}, INT_MIN, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
> >        |                                                           ^~~~~~~~~~~~~~~~~~~~~
> >        |                                                           AV_OPT_TYPE_CHLAYOUT
> 
> Is that the only error? Can you check if it compiles if you fix that typo?

builds and passes fate

happy to be able to help

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I have often repented speaking, but never of holding my tongue.
-- Xenocrates

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avdevice/alsa_dec: add a ch_layout option
  2025-02-01  2:01     ` Michael Niedermayer
@ 2025-02-01  4:23       ` James Almer
  0 siblings, 0 replies; 5+ messages in thread
From: James Almer @ 2025-02-01  4:23 UTC (permalink / raw)
  To: ffmpeg-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 1484 bytes --]

On 1/31/2025 11:01 PM, Michael Niedermayer wrote:
> On Fri, Jan 31, 2025 at 10:45:13PM -0300, James Almer wrote:
>> On 1/31/2025 10:43 PM, Michael Niedermayer wrote:
>>> On Tue, Jan 28, 2025 at 09:57:57AM -0300, James Almer wrote:
>>>> 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(-)
>>>
>>> seems not to build on its own (if its intended to)
>>
>> I can't test, so i wrote it blindly.
>>
>>>
>>> libavdevice/alsa_dec.c:163:59: error: ‘AV_OPT_TYPE_CH_LAYOUT’ undeclared here (not in a function); did you mean ‘AV_OPT_TYPE_CHLAYOUT’?
>>>     163 |     { "ch_layout",   "", offsetof(AlsaData, ch_layout),   AV_OPT_TYPE_CH_LAYOUT, {.str = "2C"}, INT_MIN, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
>>>         |                                                           ^~~~~~~~~~~~~~~~~~~~~
>>>         |                                                           AV_OPT_TYPE_CHLAYOUT
>>
>> Is that the only error? Can you check if it compiles if you fix that typo?
> 
> builds and passes fate
> 
> happy to be able to help

Applied, thanks.


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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] 5+ messages in thread

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-28 12:57 [FFmpeg-devel] [PATCH] avdevice/alsa_dec: add a ch_layout option James Almer
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

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