Commit 248308d7 authored by Jean-Paul Saman's avatar Jean-Paul Saman

access/alsa.c: Make fourcc available for access alsa input.

Make fourcc available for access alsa input without dragging in
vlc_aout.h.
parent cc4db561
......@@ -45,6 +45,8 @@
#include <vlc_demux.h>
#include <vlc_input.h>
#include <vlc_fourcc.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
......@@ -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" )
#define FORMAT_LONGTEXT N_( \
"Sample format FOURCC (eg: araw, s8, s16l, s24l, s32l, f64l)" )
#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, NULL, STEREO_TEXT, STEREO_LONGTEXT,
true )
add_string( CFG_PREFIX "format", "araw", NULL, FORMAT_TEXT,
FORMAT_LONGTEXT, true )
add_integer( CFG_PREFIX "samplerate", 48000, NULL, SAMPLERATE_TEXT,
SAMPLERATE_LONGTEXT, true )
add_integer( CFG_PREFIX "caching", DEFAULT_PTS_DELAY / 1000, NULL,
......@@ -137,6 +145,7 @@ struct demux_sys_t
int i_cache;
unsigned int i_sample_rate;
bool b_stereo;
vlc_fourcc_t i_codec;
size_t i_max_frame_size;
block_t *p_block;
es_out_id_t *p_es;
......@@ -151,6 +160,43 @@ struct demux_sys_t
audio_grab_t *p_grab;
};
static unsigned int BitsPerSample( vlc_fourcc_t i_fourcc )
{
switch( vlc_fourcc_GetCodec( AUDIO_ES, i_fourcc ))
{
case VLC_CODEC_U8:
case VLC_CODEC_S8:
return 8;
case VLC_CODEC_U16L:
case VLC_CODEC_S16L:
case VLC_CODEC_U16B:
case VLC_CODEC_S16B:
return 16;
case VLC_CODEC_U24L:
case VLC_CODEC_S24L:
case VLC_CODEC_U24B:
case VLC_CODEC_S24B:
return 24;
case VLC_CODEC_S32L:
case VLC_CODEC_S32B:
case VLC_CODEC_F32L:
case VLC_CODEC_F32B:
case VLC_CODEC_FI32:
return 32;
case VLC_CODEC_F64L:
case VLC_CODEC_F64B:
return 64;
default: /* fall through */
break;
}
return 0;
}
static int FindMainDevice( demux_t *p_demux, const char *psz_device )
{
if( psz_device )
......@@ -265,6 +311,11 @@ static int DemuxOpen( vlc_object_t *p_this )
p_sys->i_sample_rate = var_CreateGetInteger( p_demux, CFG_PREFIX "samplerate" );
p_sys->b_stereo = var_CreateGetBool( p_demux, CFG_PREFIX "stereo" );
p_sys->i_cache = var_CreateGetInteger( p_demux, CFG_PREFIX "caching" );
char *psz_format = var_CreateGetString( p_demux, CFG_PREFIX "format" );
p_sys->i_codec = vlc_fourcc_GetCodecFromString( AUDIO_ES, psz_format );
free( psz_format );
p_sys->p_es = NULL;
p_sys->p_block = NULL;
p_sys->i_next_demux_date = -1;
......@@ -576,19 +627,20 @@ static int OpenAudioDevAlsa( demux_t *p_demux, const char *psz_device )
int i_err;
if( ( i_err = snd_pcm_open( &p_sys->p_alsa_pcm, psz_device,
SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK ) ) < 0)
SND_PCM_STREAM_CAPTURE, 0 /* SND_PCM_NONBLOCK */ ) ) < 0)
{
msg_Err( p_demux, "Cannot open ALSA audio device %s (%s)",
psz_device, snd_strerror( i_err ) );
goto adev_fail;
}
#if 0
if( ( i_err = snd_pcm_nonblock( p_sys->p_alsa_pcm, 1 ) ) < 0)
{
msg_Err( p_demux, "Cannot set ALSA nonblock (%s)",
snd_strerror( i_err ) );
goto adev_fail;
}
#endif
/* Begin setting hardware parameters */
......@@ -617,7 +669,20 @@ static int OpenAudioDevAlsa( demux_t *p_demux, const char *psz_device )
}
/* 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 )
snd_pcm_format_t i_alsa_pcm_format = SND_PCM_FORMAT_S16_LE;
switch( BitsPerSample( p_sys->i_codec ) )
{
case 8: i_alsa_pcm_format = SND_PCM_FORMAT_S8; break;
case 16: i_alsa_pcm_format = SND_PCM_FORMAT_S16_LE; break;
case 24: i_alsa_pcm_format = SND_PCM_FORMAT_S24_LE; break;
case 32: i_alsa_pcm_format = SND_PCM_FORMAT_S32_LE; break;
case 64: i_alsa_pcm_format = SND_PCM_FORMAT_FLOAT64_LE; break;
default:
msg_Err( p_demux, "ALSA: unknown sample format (%s)", (char *)&p_sys->i_codec );
goto adev_fail;
}
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 ) );
......@@ -699,7 +764,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;
......@@ -749,11 +814,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_codec );
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 = BitsPerSample( p_sys->i_codec );
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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment