Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
fb46b4a1
Commit
fb46b4a1
authored
May 12, 2011
by
Jean-Paul Saman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
access/alsa.c: Todays capture cards support more than one format for audio capturing.
parent
78a52d4d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
5 deletions
+58
-5
modules/access/alsa.c
modules/access/alsa.c
+58
-5
No files found.
modules/access/alsa.c
View file @
fb46b4a1
...
@@ -44,6 +44,8 @@
...
@@ -44,6 +44,8 @@
#include <vlc_access.h>
#include <vlc_access.h>
#include <vlc_demux.h>
#include <vlc_demux.h>
#include <vlc_input.h>
#include <vlc_input.h>
#include <vlc_fourcc.h>
#include <vlc_aout.h>
#include <unistd.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
...
@@ -68,6 +70,10 @@ static void DemuxClose( vlc_object_t * );
...
@@ -68,6 +70,10 @@ static void DemuxClose( vlc_object_t * );
#define STEREO_LONGTEXT N_( \
#define STEREO_LONGTEXT N_( \
"Capture the audio stream in stereo." )
"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)" )
#define SAMPLERATE_TEXT N_( "Samplerate" )
#define SAMPLERATE_TEXT N_( "Samplerate" )
#define SAMPLERATE_LONGTEXT N_( \
#define SAMPLERATE_LONGTEXT N_( \
"Samplerate of the captured audio stream, in Hz (eg: 11025, 22050, 44100, 48000)" )
"Samplerate of the captured audio stream, in Hz (eg: 11025, 22050, 44100, 48000)" )
...
@@ -98,6 +104,8 @@ vlc_module_begin()
...
@@ -98,6 +104,8 @@ vlc_module_begin()
add_bool
(
CFG_PREFIX
"stereo"
,
true
,
STEREO_TEXT
,
STEREO_LONGTEXT
,
add_bool
(
CFG_PREFIX
"stereo"
,
true
,
STEREO_TEXT
,
STEREO_LONGTEXT
,
true
)
true
)
add_string
(
CFG_PREFIX
"format"
,
"s16l"
,
FORMAT_TEXT
,
FORMAT_LONGTEXT
,
true
)
add_integer
(
CFG_PREFIX
"samplerate"
,
48000
,
SAMPLERATE_TEXT
,
add_integer
(
CFG_PREFIX
"samplerate"
,
48000
,
SAMPLERATE_TEXT
,
SAMPLERATE_LONGTEXT
,
true
)
SAMPLERATE_LONGTEXT
,
true
)
add_integer
(
CFG_PREFIX
"caching"
,
DEFAULT_PTS_DELAY
/
1000
,
add_integer
(
CFG_PREFIX
"caching"
,
DEFAULT_PTS_DELAY
/
1000
,
...
@@ -124,6 +132,7 @@ struct demux_sys_t
...
@@ -124,6 +132,7 @@ struct demux_sys_t
int
i_cache
;
int
i_cache
;
unsigned
int
i_sample_rate
;
unsigned
int
i_sample_rate
;
bool
b_stereo
;
bool
b_stereo
;
vlc_fourcc_t
i_format
;
size_t
i_max_frame_size
;
size_t
i_max_frame_size
;
block_t
*
p_block
;
block_t
*
p_block
;
es_out_id_t
*
p_es
;
es_out_id_t
*
p_es
;
...
@@ -247,6 +256,10 @@ static int DemuxOpen( vlc_object_t *p_this )
...
@@ -247,6 +256,10 @@ static int DemuxOpen( vlc_object_t *p_this )
p_demux
->
p_sys
=
p_sys
=
calloc
(
1
,
sizeof
(
demux_sys_t
)
);
p_demux
->
p_sys
=
p_sys
=
calloc
(
1
,
sizeof
(
demux_sys_t
)
);
if
(
p_sys
==
NULL
)
return
VLC_ENOMEM
;
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
);
p_sys
->
i_sample_rate
=
var_InheritInteger
(
p_demux
,
CFG_PREFIX
"samplerate"
);
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
->
b_stereo
=
var_InheritBool
(
p_demux
,
CFG_PREFIX
"stereo"
);
p_sys
->
i_cache
=
var_InheritInteger
(
p_demux
,
CFG_PREFIX
"caching"
);
p_sys
->
i_cache
=
var_InheritInteger
(
p_demux
,
CFG_PREFIX
"caching"
);
...
@@ -449,6 +462,44 @@ static block_t* GrabAudio( demux_t *p_demux )
...
@@ -449,6 +462,44 @@ static block_t* GrabAudio( demux_t *p_demux )
return
p_block
;
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
;
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
;
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
;
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
* 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 )
...
@@ -457,6 +508,7 @@ static int OpenAudioDevAlsa( demux_t *p_demux, const char *psz_device )
demux_sys_t
*
p_sys
=
p_demux
->
p_sys
;
demux_sys_t
*
p_sys
=
p_demux
->
p_sys
;
p_sys
->
p_alsa_pcm
=
NULL
;
p_sys
->
p_alsa_pcm
=
NULL
;
snd_pcm_hw_params_t
*
p_hw_params
=
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
buffer_size
;
snd_pcm_uframes_t
chunk_size
;
snd_pcm_uframes_t
chunk_size
;
...
@@ -504,8 +556,9 @@ static int OpenAudioDevAlsa( demux_t *p_demux, const char *psz_device )
...
@@ -504,8 +556,9 @@ static int OpenAudioDevAlsa( demux_t *p_demux, const char *psz_device )
goto
adev_fail
;
goto
adev_fail
;
}
}
/* Set 16 bit little endian */
/* Set capture format, default is signed 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
)
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)"
,
msg_Err
(
p_demux
,
"ALSA: cannot set sample format (%s)"
,
snd_strerror
(
i_err
)
);
snd_strerror
(
i_err
)
);
...
@@ -587,7 +640,7 @@ static int OpenAudioDevAlsa( demux_t *p_demux, const char *psz_device )
...
@@ -587,7 +640,7 @@ static int OpenAudioDevAlsa( demux_t *p_demux, const char *psz_device )
goto
adev_fail
;
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
;
int
bits_per_frame
=
bits_per_sample
*
channels
;
p_sys
->
i_alsa_chunk_size
=
chunk_size
;
p_sys
->
i_alsa_chunk_size
=
chunk_size
;
...
@@ -631,11 +684,11 @@ static int OpenAudioDev( demux_t *p_demux, const char *psz_device )
...
@@ -631,11 +684,11 @@ static int OpenAudioDev( demux_t *p_demux, const char *psz_device )
p_sys
->
i_sample_rate
);
p_sys
->
i_sample_rate
);
es_format_t
fmt
;
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_channels
=
p_sys
->
b_stereo
?
2
:
1
;
fmt
.
audio
.
i_rate
=
p_sys
->
i_sample_rate
;
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
.
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
;
fmt
.
i_bitrate
=
fmt
.
audio
.
i_channels
*
fmt
.
audio
.
i_rate
*
fmt
.
audio
.
i_bitspersample
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment