diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-06-24 02:54:12 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-06-24 03:07:04 +0200 |
commit | 686959e87e377c0494da636640e36779dd985c30 (patch) | |
tree | 8c4674c56f291638686e6bc3efafe0ef2b921327 /libavdevice/alsa-audio-common.c | |
parent | ffc6c8a4305d25db8a5af72389a2453b17f43646 (diff) | |
parent | adbfc605f6bbe87b292c82cd1f5d4d974fa6b73c (diff) | |
download | ffmpeg-686959e87e377c0494da636640e36779dd985c30.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
doxygen: Consistently use '@' instead of '\' for Doxygen markup.
Use av_printf_format to check the usage of printf style functions
Add av_printf_format, for marking printf style format strings and their parameters
ARM: enable thumb for Cortex-M* CPUs
nsvdec: Propagate error values instead of returning 0 in nsv_read_header().
build: remove SRC_PATH_BARE variable
build: move basic rules and variables to main Makefile
build: move special targets to end of main Makefile
lavdev: improve feedback in case of invalid frame rate/size
vfwcap: prefer "framerate_q" over "fps" in vfw_read_header()
v4l2: prefer "framerate_q" over "fps" in v4l2_set_parameters()
fbdev: prefer "framerate_q" over "fps" in device context
bktr: prefer "framerate" over "fps" for grab_read_header()
ALSA: implement channel layout for playback.
alsa: support unsigned variants of already supported signed formats.
alsa: add support for more formats.
ARM: allow building in Thumb2 mode
Conflicts:
common.mak
doc/APIchanges
libavcodec/vdpau.h
libavdevice/alsa-audio-common.c
libavdevice/fbdev.c
libavdevice/libdc1394.c
libavutil/avutil.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavdevice/alsa-audio-common.c')
-rw-r--r-- | libavdevice/alsa-audio-common.c | 125 |
1 files changed, 61 insertions, 64 deletions
diff --git a/libavdevice/alsa-audio-common.c b/libavdevice/alsa-audio-common.c index 668ca02201..8c5be3c864 100644 --- a/libavdevice/alsa-audio-common.c +++ b/libavdevice/alsa-audio-common.c @@ -30,6 +30,7 @@ #include <alsa/asoundlib.h> #include "avdevice.h" +#include "libavutil/avassert.h" #include "alsa-audio.h" @@ -64,7 +65,7 @@ static av_cold snd_pcm_format_t codec_id_to_pcm_format(int codec_id) static void alsa_reorder_ ## NAME ## _out_50(const void *in_v, void *out_v, int n) \ { \ const TYPE *in = in_v; \ - TYPE * out = out_v; \ + TYPE *out = out_v; \ \ while (n-- > 0) { \ out[0] = in[0]; \ @@ -81,7 +82,7 @@ static void alsa_reorder_ ## NAME ## _out_50(const void *in_v, void *out_v, int static void alsa_reorder_ ## NAME ## _out_51(const void *in_v, void *out_v, int n) \ { \ const TYPE *in = in_v; \ - TYPE * out = out_v; \ + TYPE *out = out_v; \ \ while (n-- > 0) { \ out[0] = in[0]; \ @@ -99,7 +100,7 @@ static void alsa_reorder_ ## NAME ## _out_51(const void *in_v, void *out_v, int static void alsa_reorder_ ## NAME ## _out_71(const void *in_v, void *out_v, int n) \ { \ const TYPE *in = in_v; \ - TYPE * out = out_v; \ + TYPE *out = out_v; \ \ while (n-- > 0) { \ out[0] = in[0]; \ @@ -128,57 +129,57 @@ REORDER_OUT_50(f32, float) REORDER_OUT_51(f32, float) REORDER_OUT_71(f32, float) -#define REORDER_DUMMY ((void *)1) +#define FORMAT_I8 0 +#define FORMAT_I16 1 +#define FORMAT_I32 2 +#define FORMAT_F32 3 + +#define PICK_REORDER(layout)\ +switch(format) {\ + case FORMAT_I8: s->reorder_func = alsa_reorder_int8_out_ ##layout; break;\ + case FORMAT_I16: s->reorder_func = alsa_reorder_int16_out_ ##layout; break;\ + case FORMAT_I32: s->reorder_func = alsa_reorder_int32_out_ ##layout; break;\ + case FORMAT_F32: s->reorder_func = alsa_reorder_f32_out_ ##layout; break;\ +} -static av_cold ff_reorder_func find_reorder_func(int codec_id, - int64_t layout, - int out) +static av_cold int find_reorder_func(AlsaData *s, int codec_id, int64_t layout, int out) { - return - codec_id == CODEC_ID_PCM_U8 || codec_id == CODEC_ID_PCM_S8 || - codec_id == CODEC_ID_PCM_ALAW || codec_id == CODEC_ID_PCM_MULAW ? - layout == AV_CH_LAYOUT_QUAD || layout == AV_CH_LAYOUT_2_2 ? - REORDER_DUMMY : - layout == AV_CH_LAYOUT_5POINT0_BACK || layout == AV_CH_LAYOUT_5POINT0 ? - out ? alsa_reorder_int8_out_50 : NULL : - layout == AV_CH_LAYOUT_5POINT1_BACK || layout == AV_CH_LAYOUT_5POINT1 ? - out ? alsa_reorder_int8_out_51 : NULL : - layout == AV_CH_LAYOUT_7POINT1 ? - out ? alsa_reorder_int8_out_71 : NULL : - NULL : - codec_id == CODEC_ID_PCM_U16LE || codec_id == CODEC_ID_PCM_U16BE || - codec_id == CODEC_ID_PCM_S16LE || codec_id == CODEC_ID_PCM_S16BE ? - layout == AV_CH_LAYOUT_QUAD || layout == AV_CH_LAYOUT_2_2 ? - REORDER_DUMMY : - layout == AV_CH_LAYOUT_5POINT0_BACK || layout == AV_CH_LAYOUT_5POINT0 ? - out ? alsa_reorder_int16_out_50 : NULL : - layout == AV_CH_LAYOUT_5POINT1_BACK || layout == AV_CH_LAYOUT_5POINT1 ? - out ? alsa_reorder_int16_out_51 : NULL : - layout == AV_CH_LAYOUT_7POINT1 ? - out ? alsa_reorder_int16_out_71 : NULL : - NULL : - codec_id == CODEC_ID_PCM_U32LE || codec_id == CODEC_ID_PCM_U32BE || - codec_id == CODEC_ID_PCM_S32LE || codec_id == CODEC_ID_PCM_S32BE ? - layout == AV_CH_LAYOUT_QUAD || layout == AV_CH_LAYOUT_2_2 ? - REORDER_DUMMY : - layout == AV_CH_LAYOUT_5POINT0_BACK || layout == AV_CH_LAYOUT_5POINT0 ? - out ? alsa_reorder_int32_out_50 : NULL : - layout == AV_CH_LAYOUT_5POINT1_BACK || layout == AV_CH_LAYOUT_5POINT1 ? - out ? alsa_reorder_int32_out_51 : NULL : - layout == AV_CH_LAYOUT_7POINT1 ? - out ? alsa_reorder_int32_out_71 : NULL : - NULL : - codec_id == CODEC_ID_PCM_F32LE || codec_id == CODEC_ID_PCM_F32BE ? - layout == AV_CH_LAYOUT_QUAD || layout == AV_CH_LAYOUT_2_2 ? - REORDER_DUMMY : - layout == AV_CH_LAYOUT_5POINT0_BACK || layout == AV_CH_LAYOUT_5POINT0 ? - out ? alsa_reorder_f32_out_50 : NULL : - layout == AV_CH_LAYOUT_5POINT1_BACK || layout == AV_CH_LAYOUT_5POINT1 ? - out ? alsa_reorder_f32_out_51 : NULL : - layout == AV_CH_LAYOUT_7POINT1 ? - out ? alsa_reorder_f32_out_71 : NULL : - NULL : - NULL; + int format; + + /* reordering input is not currently supported */ + if (!out) + return AVERROR(ENOSYS); + + /* reordering is not needed for QUAD or 2_2 layout */ + if (layout == AV_CH_LAYOUT_QUAD || layout == AV_CH_LAYOUT_2_2) + return 0; + + switch (codec_id) { + case CODEC_ID_PCM_S8: + case CODEC_ID_PCM_U8: + case CODEC_ID_PCM_ALAW: + case CODEC_ID_PCM_MULAW: format = FORMAT_I8; break; + case CODEC_ID_PCM_S16LE: + case CODEC_ID_PCM_S16BE: + case CODEC_ID_PCM_U16LE: + case CODEC_ID_PCM_U16BE: format = FORMAT_I16; break; + case CODEC_ID_PCM_S32LE: + case CODEC_ID_PCM_S32BE: + case CODEC_ID_PCM_U32LE: + case CODEC_ID_PCM_U32BE: format = FORMAT_I32; break; + case CODEC_ID_PCM_F32LE: + case CODEC_ID_PCM_F32BE: format = FORMAT_F32; break; + default: return AVERROR(ENOSYS); + } + + if (layout == AV_CH_LAYOUT_5POINT0_BACK || layout == AV_CH_LAYOUT_5POINT0) + PICK_REORDER(50) + else if (layout == AV_CH_LAYOUT_5POINT1_BACK || layout == AV_CH_LAYOUT_5POINT1) + PICK_REORDER(51) + else if (layout == AV_CH_LAYOUT_7POINT1) + PICK_REORDER(71) + + return s->reorder_func ? 0 : AVERROR(ENOSYS); } av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode, @@ -286,22 +287,17 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode, snd_pcm_hw_params_free(hw_params); if (channels > 2 && layout) { - s->reorder_func = find_reorder_func(*codec_id, layout, - mode == SND_PCM_STREAM_PLAYBACK); - if (s->reorder_func == REORDER_DUMMY) { - s->reorder_func = NULL; - } else if (s->reorder_func) { + if (find_reorder_func(s, *codec_id, layout, mode == SND_PCM_STREAM_PLAYBACK) < 0) { + char name[128]; + av_get_channel_layout_string(name, sizeof(name), channels, layout); + av_log(ctx, AV_LOG_WARNING, "ALSA channel layout unknown or unimplemented for %s %s.\n", + name, mode == SND_PCM_STREAM_PLAYBACK ? "playback" : "capture"); + } + if (s->reorder_func) { s->reorder_buf_size = buffer_size; s->reorder_buf = av_malloc(s->reorder_buf_size * s->frame_size); if (!s->reorder_buf) goto fail1; - } else { - char name[32]; - av_get_channel_layout_string(name, sizeof(name), channels, layout); - av_log(ctx, AV_LOG_WARNING, - "ALSA channel layout unknown or unimplemented for %s %s.\n", - name, - mode == SND_PCM_STREAM_PLAYBACK ? "playback" : "capture"); } } @@ -350,6 +346,7 @@ int ff_alsa_extend_reorder_buf(AlsaData *s, int min_size) int size = s->reorder_buf_size; void *r; + av_assert0(size != 0); while (size < min_size) size *= 2; r = av_realloc(s->reorder_buf, size * s->frame_size); |