[vlc-devel] [PATCH] access/alsa.c: mmap capture mode.
Rémi Denis-Courmont
remi at remlab.net
Wed Aug 31 13:29:03 CEST 2011
@@ -68,6 +70,10 @@ static void DemuxClose( vlc_object_t * );
#define STEREO_LONGTEXT N_( \
"Capture the audio stream in stereo." )
+#define FORMAT_TEXT N_( "Format (default: s16l)" )
+#define FORMAT_LONGTEXT N_( \
+ "Sample format FOURCC (eg: s8, s16l, s24l, s32l, f64l)" )
+
These strings look obscure.
#define SAMPLERATE_TEXT N_( "Samplerate" )
#define SAMPLERATE_LONGTEXT N_( \
"Samplerate of the captured audio stream, in Hz (eg: 11025, 22050,
44100, 48000)" )
@@ -98,6 +104,8 @@ vlc_module_begin()
add_bool( CFG_PREFIX "stereo", true, STEREO_TEXT, STEREO_LONGTEXT,
true )
+ add_string( CFG_PREFIX "format", "s16l", FORMAT_TEXT,
+ FORMAT_LONGTEXT, true )
A choices list could not hurt.
add_integer( CFG_PREFIX "samplerate", 48000, SAMPLERATE_TEXT,
SAMPLERATE_LONGTEXT, true )
add_integer( CFG_PREFIX "caching", DEFAULT_PTS_DELAY / 1000,
@@ -124,6 +132,7 @@ struct demux_sys_t
int i_cache;
unsigned int i_sample_rate;
bool b_stereo;
+ vlc_fourcc_t i_format;
size_t i_max_frame_size;
block_t *p_block;
es_out_id_t *p_es;
@@ -247,6 +256,10 @@ static int DemuxOpen( vlc_object_t *p_this )
p_demux->p_sys = p_sys = calloc( 1, sizeof( demux_sys_t ) );
if( p_sys == NULL ) return VLC_ENOMEM;
+ char *psz_format = var_CreateGetString( p_demux, CFG_PREFIX "format"
);
+ p_sys->i_format = vlc_fourcc_GetCodecFromString( AUDIO_ES, psz_format
);
+ free( psz_format );
var_InheritString() should be used instead.
p_sys->i_sample_rate = var_InheritInteger( p_demux, CFG_PREFIX
"samplerate" );
p_sys->b_stereo = var_InheritBool( p_demux, CFG_PREFIX "stereo" );
p_sys->i_cache = var_InheritInteger( p_demux, CFG_PREFIX "caching" );
You need to rebase your patch here.
@@ -449,6 +462,44 @@ static block_t* GrabAudio( demux_t *p_demux )
return p_block;
}
+static snd_pcm_format_t GetAlsaPCMFormat( demux_t *p_demux, const
vlc_fourcc_t i_format )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+
+ switch( i_format )
+ {
+ case VLC_CODEC_U8: return SND_PCM_FORMAT_U8;
+ case VLC_CODEC_S8: return SND_PCM_FORMAT_S8;
G.711 could be added by the way.
+ case VLC_CODEC_U16L: return SND_PCM_FORMAT_U16_LE;
+ case VLC_CODEC_S16L: return SND_PCM_FORMAT_S16_LE;
+ case VLC_CODEC_U16B: return SND_PCM_FORMAT_U16_BE;
+ case VLC_CODEC_S16B: return SND_PCM_FORMAT_S16_BE;
+
+ case VLC_CODEC_U24L: return SND_PCM_FORMAT_U24_LE;
+ case VLC_CODEC_S24L: return SND_PCM_FORMAT_S24_LE;
+ case VLC_CODEC_U24B: return SND_PCM_FORMAT_U24_BE;
+ case VLC_CODEC_S24B: return SND_PCM_FORMAT_S24_BE;
I think this is wrong. VLC_CODEC_x24y should correspond to
SND_PCM_FORMAT_x24_3yE.
+ case VLC_CODEC_U32L: return SND_PCM_FORMAT_U32_LE;
+ case VLC_CODEC_U32B: return SND_PCM_FORMAT_U32_BE;
+ case VLC_CODEC_S32L: return SND_PCM_FORMAT_S32_LE;
+ case VLC_CODEC_S32B: return SND_PCM_FORMAT_S32_BE;
+ case VLC_CODEC_F32L: return SND_PCM_FORMAT_FLOAT_LE;
+ case VLC_CODEC_F32B: return SND_PCM_FORMAT_FLOAT_BE;
+ case VLC_CODEC_FI32: return SND_PCM_FORMAT_S32;
I think SND_PCM_FORMAT_S32 corresponds to VLC_CODEC_S32N, not FI32.
+ case VLC_CODEC_F64L: return SND_PCM_FORMAT_FLOAT64_LE;
+ case VLC_CODEC_F64B: return SND_PCM_FORMAT_FLOAT64_BE;
+
+ default:
+ msg_Err( p_demux, "ALSA: unsupported sample format '%s'
falling back to 's16l'",
+ (char *)&p_sys->i_format );
+ }
+
+ return SND_PCM_FORMAT_S16_LE;
+}
+
/*****************************************************************************
* OpenAudioDev: open and set up the audio device and probe for
capabilities
*****************************************************************************/
@@ -457,6 +508,7 @@ static int OpenAudioDevAlsa( demux_t *p_demux, const
char *psz_device )
demux_sys_t *p_sys = p_demux->p_sys;
p_sys->p_alsa_pcm = NULL;
snd_pcm_hw_params_t *p_hw_params = NULL;
+ snd_pcm_format_t i_alsa_pcm_format;
snd_pcm_uframes_t buffer_size;
snd_pcm_uframes_t chunk_size;
@@ -504,8 +556,9 @@ static int OpenAudioDevAlsa( demux_t *p_demux, const
char *psz_device )
goto adev_fail;
}
- /* Set 16 bit little endian */
- if( ( i_err = snd_pcm_hw_params_set_format( p_sys->p_alsa_pcm,
p_hw_params, SND_PCM_FORMAT_S16_LE ) ) < 0 )
+ /* Set capture format, default is signed 16 bit little endian */
+ i_alsa_pcm_format = GetAlsaPCMFormat( p_demux, p_sys->i_format );
+ if( ( i_err = snd_pcm_hw_params_set_format( p_sys->p_alsa_pcm,
p_hw_params, i_alsa_pcm_format ) ) < 0 )
{
msg_Err( p_demux, "ALSA: cannot set sample format (%s)",
snd_strerror( i_err ) );
@@ -587,7 +640,7 @@ static int OpenAudioDevAlsa( demux_t *p_demux, const
char *psz_device )
goto adev_fail;
}
- int bits_per_sample =
snd_pcm_format_physical_width(SND_PCM_FORMAT_S16_LE);
+ int bits_per_sample =
snd_pcm_format_physical_width(i_alsa_pcm_format);
int bits_per_frame = bits_per_sample * channels;
p_sys->i_alsa_chunk_size = chunk_size;
@@ -631,11 +684,11 @@ static int OpenAudioDev( demux_t *p_demux, const
char *psz_device )
p_sys->i_sample_rate );
es_format_t fmt;
- es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC('a','r','a','w') );
+ es_format_Init( &fmt, AUDIO_ES, p_sys->i_format );
fmt.audio.i_channels = p_sys->b_stereo ? 2 : 1;
fmt.audio.i_rate = p_sys->i_sample_rate;
- fmt.audio.i_bitspersample = 16;
+ fmt.audio.i_bitspersample = aout_BitsPerSample( p_sys->i_format );
fmt.audio.i_blockalign = fmt.audio.i_channels *
fmt.audio.i_bitspersample / 8;
fmt.i_bitrate = fmt.audio.i_channels * fmt.audio.i_rate *
fmt.audio.i_bitspersample;
--
Rémi Denis-Courmont
http://www.remlab.net/
More information about the vlc-devel
mailing list