mirror of
https://github.com/mpv-player/mpv
synced 2025-04-27 11:33:39 +02:00
ALSA 1.x audio out driver
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@11776 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
9ce5d288f9
commit
70162b5ef8
@ -351,7 +351,7 @@ m_option_t tvopts_conf[]={
|
|||||||
{"mjpeg", &tv_param_mjpeg, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
{"mjpeg", &tv_param_mjpeg, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
||||||
{"decimation", &tv_param_decimation, CONF_TYPE_INT, CONF_RANGE, 1, 4, NULL},
|
{"decimation", &tv_param_decimation, CONF_TYPE_INT, CONF_RANGE, 1, 4, NULL},
|
||||||
{"quality", &tv_param_quality, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
|
{"quality", &tv_param_quality, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
{"alsa", &tv_param_alsa, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
{"alsa", &tv_param_alsa, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
||||||
#endif
|
#endif
|
||||||
{"adevice", &tv_param_adevice, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
{"adevice", &tv_param_adevice, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
||||||
|
18
configure
vendored
18
configure
vendored
@ -3936,6 +3936,7 @@ EOF
|
|||||||
fi
|
fi
|
||||||
_def_alsa5='#undef HAVE_ALSA5'
|
_def_alsa5='#undef HAVE_ALSA5'
|
||||||
_def_alsa9='#undef HAVE_ALSA9'
|
_def_alsa9='#undef HAVE_ALSA9'
|
||||||
|
_def_alsa1x='#undef HAVE_ALSA1X'
|
||||||
_def_sys_asoundlib_h='#undef HAVE_SYS_ASOUNDLIB_H'
|
_def_sys_asoundlib_h='#undef HAVE_SYS_ASOUNDLIB_H'
|
||||||
_def_alsa_asoundlib_h='#undef HAVE_ALSA_ASOUNDLIB_H'
|
_def_alsa_asoundlib_h='#undef HAVE_ALSA_ASOUNDLIB_H'
|
||||||
if test "$_alsaver" ; then
|
if test "$_alsaver" ; then
|
||||||
@ -3958,19 +3959,15 @@ if test "$_alsaver" ; then
|
|||||||
_def_alsa_asoundlib_h='#define HAVE_ALSA_ASOUNDLIB_H 1'
|
_def_alsa_asoundlib_h='#define HAVE_ALSA_ASOUNDLIB_H 1'
|
||||||
echores "yes (using alsa 0.9.x and alsa/asoundlib.h)"
|
echores "yes (using alsa 0.9.x and alsa/asoundlib.h)"
|
||||||
elif test "$_alsaver" = '1.0.x-sys' ; then
|
elif test "$_alsaver" = '1.0.x-sys' ; then
|
||||||
_aosrc="$_aosrc ao_alsa9.c"
|
_aosrc="$_aosrc ao_alsa1x.c"
|
||||||
_aomodules="alsa9 $_aomodules"
|
_aomodules="alsa1x $_aomodules"
|
||||||
_def_alsa9="#define ALSA_PCM_OLD_HW_PARAMS_API 1
|
_def_alsa1x="#define HAVE_ALSA1X 1"
|
||||||
#define ALSA_PCM_OLD_SW_PARAMS_API 1
|
|
||||||
#define HAVE_ALSA9 1"
|
|
||||||
_def_alsa_asoundlib_h='#define HAVE_SYS_ASOUNDLIB_H 1'
|
_def_alsa_asoundlib_h='#define HAVE_SYS_ASOUNDLIB_H 1'
|
||||||
echores "yes (using alsa 1.0.x and sys/asoundlib.h)"
|
echores "yes (using alsa 1.0.x and sys/asoundlib.h)"
|
||||||
elif test "$_alsaver" = '1.0.x-alsa' ; then
|
elif test "$_alsaver" = '1.0.x-alsa' ; then
|
||||||
_aosrc="$_aosrc ao_alsa9.c"
|
_aosrc="$_aosrc ao_alsa1x.c"
|
||||||
_aomodules="alsa9 $_aomodules"
|
_aomodules="alsa1x $_aomodules"
|
||||||
_def_alsa9="#define ALSA_PCM_OLD_HW_PARAMS_API 1
|
_def_alsa1x="#define HAVE_ALSA1X 1"
|
||||||
#define ALSA_PCM_OLD_SW_PARAMS_API 1
|
|
||||||
#define HAVE_ALSA9 1"
|
|
||||||
_def_alsa_asoundlib_h='#define HAVE_ALSA_ASOUNDLIB_H 1'
|
_def_alsa_asoundlib_h='#define HAVE_ALSA_ASOUNDLIB_H 1'
|
||||||
echores "yes (using alsa 1.0.x and alsa/asoundlib.h)"
|
echores "yes (using alsa 1.0.x and alsa/asoundlib.h)"
|
||||||
fi
|
fi
|
||||||
@ -6250,6 +6247,7 @@ $_def_ossaudio_devdsp
|
|||||||
$_def_ossaudio_devmixer
|
$_def_ossaudio_devmixer
|
||||||
$_def_alsa5
|
$_def_alsa5
|
||||||
$_def_alsa9
|
$_def_alsa9
|
||||||
|
$_def_alsa1x
|
||||||
$_def_arts
|
$_def_arts
|
||||||
$_def_esd
|
$_def_esd
|
||||||
$_def_esd_latency
|
$_def_esd_latency
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
ao_alsa9 - ALSA-0.9.x output plugin for MPlayer
|
ao_alsa1x - ALSA-1.x output plugin for MPlayer
|
||||||
|
|
||||||
(C) Alex Beregszaszi
|
(C) Alex Beregszaszi
|
||||||
|
|
||||||
@ -7,6 +7,8 @@
|
|||||||
additional AC3 passthrough support by Andy Lo A Foe <andy@alsaplayer.org>
|
additional AC3 passthrough support by Andy Lo A Foe <andy@alsaplayer.org>
|
||||||
08/22/2002 iec958-init rewritten and merged with common init, joy
|
08/22/2002 iec958-init rewritten and merged with common init, joy
|
||||||
|
|
||||||
|
Trivial port to ALSA 1.x API by Jindrich Makovicka
|
||||||
|
|
||||||
Any bugreports regarding to this driver are welcome.
|
Any bugreports regarding to this driver are welcome.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -36,13 +38,13 @@ extern int verbose;
|
|||||||
|
|
||||||
static ao_info_t info =
|
static ao_info_t info =
|
||||||
{
|
{
|
||||||
"ALSA-0.9.x audio output",
|
"ALSA-1.x audio output",
|
||||||
"alsa9",
|
"alsa1x",
|
||||||
"Alex Beregszaszi, Joy Winter <joy@pingfm.org>",
|
"Alex Beregszaszi, Joy Winter <joy@pingfm.org>",
|
||||||
"under developement"
|
"under developement"
|
||||||
};
|
};
|
||||||
|
|
||||||
LIBAO_EXTERN(alsa9)
|
LIBAO_EXTERN(alsa1x)
|
||||||
|
|
||||||
|
|
||||||
static snd_pcm_t *alsa_handler;
|
static snd_pcm_t *alsa_handler;
|
||||||
@ -58,7 +60,7 @@ static int alsa_fragsize = 4096;
|
|||||||
* which seems to be good avarge for most situations
|
* which seems to be good avarge for most situations
|
||||||
* so buffersize is 16384 frames by default */
|
* so buffersize is 16384 frames by default */
|
||||||
static int alsa_fragcount = 16;
|
static int alsa_fragcount = 16;
|
||||||
static int chunk_size = 1024; //is alsa_fragsize / 4
|
static snd_pcm_uframes_t chunk_size = 1024; //is alsa_fragsize / 4
|
||||||
|
|
||||||
#define MIN_CHUNK_SIZE 1024
|
#define MIN_CHUNK_SIZE 1024
|
||||||
|
|
||||||
@ -77,6 +79,8 @@ static int alsa_can_pause = 0;
|
|||||||
|
|
||||||
#undef BUFFERTIME
|
#undef BUFFERTIME
|
||||||
#define SET_CHUNKSIZE
|
#define SET_CHUNKSIZE
|
||||||
|
//#define BUFFERTIME
|
||||||
|
//#undef SET_CHUNKSIZE
|
||||||
#undef USE_POLL
|
#undef USE_POLL
|
||||||
|
|
||||||
|
|
||||||
@ -97,7 +101,7 @@ static int control(int cmd, void *arg)
|
|||||||
snd_mixer_elem_t *elem;
|
snd_mixer_elem_t *elem;
|
||||||
snd_mixer_selem_id_t *sid;
|
snd_mixer_selem_id_t *sid;
|
||||||
|
|
||||||
static const char *mix_name = NULL;
|
static char *mix_name = NULL;
|
||||||
static char *card = NULL;
|
static char *card = NULL;
|
||||||
|
|
||||||
long pmin, pmax;
|
long pmin, pmax;
|
||||||
@ -211,7 +215,8 @@ static int init(int rate_hz, int channels, int format, int flags)
|
|||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
int cards = -1;
|
int cards = -1;
|
||||||
int period_val;
|
int dir;
|
||||||
|
snd_pcm_uframes_t bufsize;
|
||||||
snd_pcm_info_t *alsa_info;
|
snd_pcm_info_t *alsa_info;
|
||||||
char *str_block_mode;
|
char *str_block_mode;
|
||||||
int device_set = 0;
|
int device_set = 0;
|
||||||
@ -358,6 +363,7 @@ static int init(int rate_hz, int channels, int format, int flags)
|
|||||||
alsa_device = devstr;
|
alsa_device = devstr;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,7 +456,7 @@ static int init(int rate_hz, int channels, int format, int flags)
|
|||||||
printf(" mmap: sets mmap-mode\n");
|
printf(" mmap: sets mmap-mode\n");
|
||||||
printf(" noblock: sets noblock-mode\n");
|
printf(" noblock: sets noblock-mode\n");
|
||||||
printf(" device-name: sets device name (change comma to point)\n");
|
printf(" device-name: sets device name (change comma to point)\n");
|
||||||
printf(" example -ao alsa9:mmap:noblock:hw:0.3 sets noblock-mode,\n");
|
printf(" example -ao alsa1x:mmap:noblock:hw:0.3 sets noblock-mode,\n");
|
||||||
printf(" mmap-mode and the device-name as first card fourth device\n");
|
printf(" mmap-mode and the device-name as first card fourth device\n");
|
||||||
return(0);
|
return(0);
|
||||||
} else {
|
} else {
|
||||||
@ -538,7 +544,7 @@ static int init(int rate_hz, int channels, int format, int flags)
|
|||||||
printf("alsa-init: error set block-mode %s\n", snd_strerror(err));
|
printf("alsa-init: error set block-mode %s\n", snd_strerror(err));
|
||||||
}
|
}
|
||||||
else if (verbose>0) {
|
else if (verbose>0) {
|
||||||
printf("alsa-init: pcm opend in %s\n", str_block_mode);
|
printf("alsa-init: pcm opened in %s\n", str_block_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
snd_pcm_hw_params_alloca(&alsa_hwparams);
|
snd_pcm_hw_params_alloca(&alsa_hwparams);
|
||||||
@ -599,7 +605,8 @@ static int init(int rate_hz, int channels, int format, int flags)
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = snd_pcm_hw_params_set_rate_near(alsa_handler, alsa_hwparams, ao_data.samplerate, 0)) < 0)
|
dir = 0;
|
||||||
|
if ((err = snd_pcm_hw_params_set_rate_near(alsa_handler, alsa_hwparams, &ao_data.samplerate, &dir)) < 0)
|
||||||
{
|
{
|
||||||
printf("alsa-init: unable to set samplerate-2: %s\n",
|
printf("alsa-init: unable to set samplerate-2: %s\n",
|
||||||
snd_strerror(err));
|
snd_strerror(err));
|
||||||
@ -609,16 +616,20 @@ static int init(int rate_hz, int channels, int format, int flags)
|
|||||||
#ifdef BUFFERTIME
|
#ifdef BUFFERTIME
|
||||||
{
|
{
|
||||||
int alsa_buffer_time = 500000; /* original 60 */
|
int alsa_buffer_time = 500000; /* original 60 */
|
||||||
|
int alsa_period_time;
|
||||||
|
|
||||||
if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time, 0)) < 0)
|
dir = 0;
|
||||||
|
if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams, &alsa_buffer_time, &dir)) < 0)
|
||||||
{
|
{
|
||||||
printf("alsa-init: unable to set buffer time near: %s\n",
|
printf("alsa-init: unable to set buffer time near: %s\n",
|
||||||
snd_strerror(err));
|
snd_strerror(err));
|
||||||
return(0);
|
return(0);
|
||||||
} else
|
}
|
||||||
alsa_buffer_time = err;
|
|
||||||
|
|
||||||
if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time/4, 0)) < 0)
|
alsa_period_time = alsa_buffer_time/4; ;
|
||||||
|
|
||||||
|
dir = 0;
|
||||||
|
if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams, alsa_period_time, &dir)) < 0)
|
||||||
/* original: alsa_buffer_time/ao_data.bps */
|
/* original: alsa_buffer_time/ao_data.bps */
|
||||||
{
|
{
|
||||||
printf("alsa-init: unable to set period time: %s\n",
|
printf("alsa-init: unable to set period time: %s\n",
|
||||||
@ -626,14 +637,15 @@ static int init(int rate_hz, int channels, int format, int flags)
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
if (verbose>0)
|
if (verbose>0)
|
||||||
printf("alsa-init: buffer_time: %d, period_time :%d\n",alsa_buffer_time, err);
|
printf("alsa-init: buffer_time: %d, period_time :%d\n",alsa_buffer_time, alsa_period_time);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SET_CHUNKSIZE
|
#ifdef SET_CHUNKSIZE
|
||||||
{
|
{
|
||||||
//set chunksize
|
//set chunksize
|
||||||
if ((err = snd_pcm_hw_params_set_period_size(alsa_handler, alsa_hwparams, chunk_size, 0)) < 0)
|
dir = 0;
|
||||||
|
if ((err = snd_pcm_hw_params_set_period_size_near(alsa_handler, alsa_hwparams, &chunk_size, &dir)) < 0)
|
||||||
{
|
{
|
||||||
printf("alsa-init: unable to set periodsize: %s\n", snd_strerror(err));
|
printf("alsa-init: unable to set periodsize: %s\n", snd_strerror(err));
|
||||||
return(0);
|
return(0);
|
||||||
@ -642,17 +654,13 @@ static int init(int rate_hz, int channels, int format, int flags)
|
|||||||
printf("alsa-init: chunksize set to %i\n", chunk_size);
|
printf("alsa-init: chunksize set to %i\n", chunk_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
//set period_count
|
dir = 0;
|
||||||
if ((period_val = snd_pcm_hw_params_get_periods_max(alsa_hwparams, 0)) < alsa_fragcount) {
|
if ((err = snd_pcm_hw_params_set_periods_near(alsa_handler, alsa_hwparams, &alsa_fragcount, &dir)) < 0) {
|
||||||
alsa_fragcount = period_val;
|
printf("alsa-init: unable to set periods: %s\n", snd_strerror(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose>0)
|
if (verbose>0)
|
||||||
printf("alsa-init: current val=%i, fragcount=%i\n", period_val, alsa_fragcount);
|
printf("alsa-init: fragcount=%i\n", alsa_fragcount);
|
||||||
|
|
||||||
if ((err = snd_pcm_hw_params_set_periods(alsa_handler, alsa_hwparams, alsa_fragcount, 0)) < 0) {
|
|
||||||
printf("alsa-init: unable to set periods: %s\n", snd_strerror(err));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -667,13 +675,13 @@ static int init(int rate_hz, int channels, int format, int flags)
|
|||||||
|
|
||||||
|
|
||||||
// gets buffersize for control
|
// gets buffersize for control
|
||||||
if ((err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams)) < 0)
|
if ((err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams, &bufsize)) < 0)
|
||||||
{
|
{
|
||||||
printf("alsa-init: unable to get buffersize: %s\n", snd_strerror(err));
|
printf("alsa-init: unable to get buffersize: %s\n", snd_strerror(err));
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ao_data.buffersize = err * bytes_per_sample;
|
ao_data.buffersize = bufsize * bytes_per_sample;
|
||||||
if (verbose>0)
|
if (verbose>0)
|
||||||
printf("alsa-init: got buffersize=%i\n", ao_data.buffersize);
|
printf("alsa-init: got buffersize=%i\n", ao_data.buffersize);
|
||||||
}
|
}
|
||||||
@ -717,7 +725,7 @@ static int init(int rate_hz, int channels, int format, int flags)
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("alsa9: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n",
|
printf("alsa1x: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n",
|
||||||
ao_data.samplerate, ao_data.channels, bytes_per_sample, ao_data.buffersize,
|
ao_data.samplerate, ao_data.channels, bytes_per_sample, ao_data.buffersize,
|
||||||
snd_pcm_format_description(alsa_format));
|
snd_pcm_format_description(alsa_format));
|
||||||
|
|
||||||
|
@ -29,6 +29,9 @@ extern ao_functions_t audio_out_null;
|
|||||||
#ifdef HAVE_ALSA9
|
#ifdef HAVE_ALSA9
|
||||||
extern ao_functions_t audio_out_alsa9;
|
extern ao_functions_t audio_out_alsa9;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_ALSA1X
|
||||||
|
extern ao_functions_t audio_out_alsa1x;
|
||||||
|
#endif
|
||||||
#ifdef HAVE_NAS
|
#ifdef HAVE_NAS
|
||||||
extern ao_functions_t audio_out_nas;
|
extern ao_functions_t audio_out_nas;
|
||||||
#endif
|
#endif
|
||||||
@ -72,6 +75,9 @@ ao_functions_t* audio_out_drivers[] =
|
|||||||
#ifdef USE_OSS_AUDIO
|
#ifdef USE_OSS_AUDIO
|
||||||
&audio_out_oss,
|
&audio_out_oss,
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_ALSA1X
|
||||||
|
&audio_out_alsa1x,
|
||||||
|
#endif
|
||||||
#ifdef HAVE_ALSA9
|
#ifdef HAVE_ALSA9
|
||||||
&audio_out_alsa9,
|
&audio_out_alsa9,
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,7 +3,7 @@ LIBNAME = libmpdemux.a
|
|||||||
|
|
||||||
include ../config.mak
|
include ../config.mak
|
||||||
|
|
||||||
SRCS = mp3_hdr.c video.c mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c muxer.c muxer_avi.c muxer_mpeg.c demux_asf.c demux_avi.c demux_mov.c parse_mp4.c demux_mpg.c demux_ty.c demux_ty_osd.c demux_pva.c demux_viv.c demuxer.c dvdnav_stream.c open.c parse_es.c stream.c stream_file.c stream_netstream.c stream_vcd.c stream_null.c stream_ftp.c tv.c tvi_dummy.c tvi_v4l.c tvi_v4l2.c tvi_bsdbt848.c frequencies.c demux_fli.c demux_real.c demux_y4m.c yuv4mpeg.c yuv4mpeg_ratio.c demux_nuv.c demux_film.c demux_roq.c mf.c demux_mf.c demux_audio.c demux_demuxers.c demux_ogg.c demux_bmp.c cdda.c demux_rawaudio.c demux_rawvideo.c cddb.c cdinfo.c demux_rawdv.c ai_alsa.c ai_oss.c audio_in.c demux_smjpeg.c demux_lmlm4.c cue_read.c extension.c demux_gif.c demux_ts.c demux_realaud.c url.c
|
SRCS = mp3_hdr.c video.c mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c muxer.c muxer_avi.c muxer_mpeg.c demux_asf.c demux_avi.c demux_mov.c parse_mp4.c demux_mpg.c demux_ty.c demux_ty_osd.c demux_pva.c demux_viv.c demuxer.c dvdnav_stream.c open.c parse_es.c stream.c stream_file.c stream_netstream.c stream_vcd.c stream_null.c stream_ftp.c tv.c tvi_dummy.c tvi_v4l.c tvi_v4l2.c tvi_bsdbt848.c frequencies.c demux_fli.c demux_real.c demux_y4m.c yuv4mpeg.c yuv4mpeg_ratio.c demux_nuv.c demux_film.c demux_roq.c mf.c demux_mf.c demux_audio.c demux_demuxers.c demux_ogg.c demux_bmp.c cdda.c demux_rawaudio.c demux_rawvideo.c cddb.c cdinfo.c demux_rawdv.c ai_alsa.c ai_alsa1x.c ai_oss.c audio_in.c demux_smjpeg.c demux_lmlm4.c cue_read.c extension.c demux_gif.c demux_ts.c demux_realaud.c url.c
|
||||||
ifeq ($(XMMS_PLUGINS),yes)
|
ifeq ($(XMMS_PLUGINS),yes)
|
||||||
SRCS += demux_xmms.c
|
SRCS += demux_xmms.c
|
||||||
endif
|
endif
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#if defined(USE_TV) && (defined(HAVE_TV_V4L) || defined(HAVE_TV_V4L2)) && defined(HAVE_ALSA9)
|
#if defined(USE_TV) && (defined(HAVE_TV_V4L) || defined(HAVE_TV_V4L2)) && defined(HAVE_ALSA1X)
|
||||||
|
|
||||||
#include <alsa/asoundlib.h>
|
#include <alsa/asoundlib.h>
|
||||||
#include "audio_in.h"
|
#include "audio_in.h"
|
||||||
@ -14,8 +14,9 @@ int ai_alsa_setup(audio_in_t *ai)
|
|||||||
{
|
{
|
||||||
snd_pcm_hw_params_t *params;
|
snd_pcm_hw_params_t *params;
|
||||||
snd_pcm_sw_params_t *swparams;
|
snd_pcm_sw_params_t *swparams;
|
||||||
int buffer_size;
|
snd_pcm_uframes_t buffer_size, period_size;
|
||||||
int err;
|
int err;
|
||||||
|
int dir;
|
||||||
unsigned int rate;
|
unsigned int rate;
|
||||||
|
|
||||||
snd_pcm_hw_params_alloca(¶ms);
|
snd_pcm_hw_params_alloca(¶ms);
|
||||||
@ -26,51 +27,69 @@ int ai_alsa_setup(audio_in_t *ai)
|
|||||||
mp_msg(MSGT_TV, MSGL_ERR, "Broken configuration for this PCM: no configurations available\n");
|
mp_msg(MSGT_TV, MSGL_ERR, "Broken configuration for this PCM: no configurations available\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = snd_pcm_hw_params_set_access(ai->alsa.handle, params,
|
err = snd_pcm_hw_params_set_access(ai->alsa.handle, params,
|
||||||
SND_PCM_ACCESS_RW_INTERLEAVED);
|
SND_PCM_ACCESS_RW_INTERLEAVED);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
mp_msg(MSGT_TV, MSGL_ERR, "Access type not available\n");
|
mp_msg(MSGT_TV, MSGL_ERR, "Access type not available\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = snd_pcm_hw_params_set_format(ai->alsa.handle, params, SND_PCM_FORMAT_S16_LE);
|
err = snd_pcm_hw_params_set_format(ai->alsa.handle, params, SND_PCM_FORMAT_S16_LE);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
mp_msg(MSGT_TV, MSGL_ERR, "Sample format not available\n");
|
mp_msg(MSGT_TV, MSGL_ERR, "Sample format not available\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = snd_pcm_hw_params_set_channels(ai->alsa.handle, params, ai->req_channels);
|
err = snd_pcm_hw_params_set_channels(ai->alsa.handle, params, ai->req_channels);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
ai->channels = snd_pcm_hw_params_get_channels(params);
|
snd_pcm_hw_params_get_channels(params, &ai->channels);
|
||||||
mp_msg(MSGT_TV, MSGL_ERR, "Channel count not available - reverting to default: %d\n",
|
mp_msg(MSGT_TV, MSGL_ERR, "Channel count not available - reverting to default: %d\n",
|
||||||
ai->channels);
|
ai->channels);
|
||||||
} else {
|
} else {
|
||||||
ai->channels = ai->req_channels;
|
ai->channels = ai->req_channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = snd_pcm_hw_params_set_rate_near(ai->alsa.handle, params, ai->req_samplerate, 0);
|
dir = 0;
|
||||||
assert(err >= 0);
|
rate = ai->req_samplerate;
|
||||||
rate = err;
|
err = snd_pcm_hw_params_set_rate_near(ai->alsa.handle, params, &rate, &dir);
|
||||||
|
if (err < 0) {
|
||||||
|
mp_msg(MSGT_TV, MSGL_ERR, "Cannot set samplerate\n");
|
||||||
|
}
|
||||||
ai->samplerate = rate;
|
ai->samplerate = rate;
|
||||||
|
|
||||||
|
dir = 0;
|
||||||
ai->alsa.buffer_time = 1000000;
|
ai->alsa.buffer_time = 1000000;
|
||||||
ai->alsa.buffer_time = snd_pcm_hw_params_set_buffer_time_near(ai->alsa.handle, params,
|
err = snd_pcm_hw_params_set_buffer_time_near(ai->alsa.handle, params,
|
||||||
ai->alsa.buffer_time, 0);
|
&ai->alsa.buffer_time, &dir);
|
||||||
assert(ai->alsa.buffer_time >= 0);
|
if (err < 0) {
|
||||||
|
mp_msg(MSGT_TV, MSGL_ERR, "Cannot set buffer time\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
dir = 0;
|
||||||
ai->alsa.period_time = ai->alsa.buffer_time / 4;
|
ai->alsa.period_time = ai->alsa.buffer_time / 4;
|
||||||
ai->alsa.period_time = snd_pcm_hw_params_set_period_time_near(ai->alsa.handle, params,
|
err = snd_pcm_hw_params_set_period_time_near(ai->alsa.handle, params,
|
||||||
ai->alsa.period_time, 0);
|
&ai->alsa.period_time, &dir);
|
||||||
assert(ai->alsa.period_time >= 0);
|
if (err < 0) {
|
||||||
|
mp_msg(MSGT_TV, MSGL_ERR, "Cannot set period time\n");
|
||||||
|
}
|
||||||
|
|
||||||
err = snd_pcm_hw_params(ai->alsa.handle, params);
|
err = snd_pcm_hw_params(ai->alsa.handle, params);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
mp_msg(MSGT_TV, MSGL_ERR, "Unable to install hw params:");
|
mp_msg(MSGT_TV, MSGL_ERR, "Unable to install hw params: %s\n", snd_strerror(err));
|
||||||
snd_pcm_hw_params_dump(params, ai->alsa.log);
|
snd_pcm_hw_params_dump(params, ai->alsa.log);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ai->alsa.chunk_size = snd_pcm_hw_params_get_period_size(params, 0);
|
|
||||||
buffer_size = snd_pcm_hw_params_get_buffer_size(params);
|
dir = -1;
|
||||||
if (ai->alsa.chunk_size == buffer_size) {
|
snd_pcm_hw_params_get_period_size(params, &period_size, &dir);
|
||||||
|
snd_pcm_hw_params_get_buffer_size(params, &buffer_size);
|
||||||
|
ai->alsa.chunk_size = period_size;
|
||||||
|
if (period_size == buffer_size) {
|
||||||
mp_msg(MSGT_TV, MSGL_ERR, "Can't use period equal to buffer size (%u == %lu)\n", ai->alsa.chunk_size, (long)buffer_size);
|
mp_msg(MSGT_TV, MSGL_ERR, "Can't use period equal to buffer size (%u == %lu)\n", ai->alsa.chunk_size, (long)buffer_size);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
snd_pcm_sw_params_current(ai->alsa.handle, swparams);
|
snd_pcm_sw_params_current(ai->alsa.handle, swparams);
|
||||||
err = snd_pcm_sw_params_set_sleep_min(ai->alsa.handle, swparams,0);
|
err = snd_pcm_sw_params_set_sleep_min(ai->alsa.handle, swparams,0);
|
||||||
assert(err >= 0);
|
assert(err >= 0);
|
||||||
@ -166,4 +185,4 @@ int ai_alsa_xrun(audio_in_t *ai)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* HAVE_ALSA9 */
|
#endif /* HAVE_ALSA1X */
|
||||||
|
@ -24,7 +24,7 @@ int audio_in_init(audio_in_t *ai, int type)
|
|||||||
ai->samplesize = -1;
|
ai->samplesize = -1;
|
||||||
|
|
||||||
switch (ai->type) {
|
switch (ai->type) {
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
case AUDIO_IN_ALSA:
|
case AUDIO_IN_ALSA:
|
||||||
ai->alsa.handle = NULL;
|
ai->alsa.handle = NULL;
|
||||||
ai->alsa.log = NULL;
|
ai->alsa.log = NULL;
|
||||||
@ -46,7 +46,7 @@ int audio_in_setup(audio_in_t *ai)
|
|||||||
{
|
{
|
||||||
|
|
||||||
switch (ai->type) {
|
switch (ai->type) {
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
case AUDIO_IN_ALSA:
|
case AUDIO_IN_ALSA:
|
||||||
if (ai_alsa_init(ai) < 0) return -1;
|
if (ai_alsa_init(ai) < 0) return -1;
|
||||||
ai->setup = 1;
|
ai->setup = 1;
|
||||||
@ -66,7 +66,7 @@ int audio_in_setup(audio_in_t *ai)
|
|||||||
int audio_in_set_samplerate(audio_in_t *ai, int rate)
|
int audio_in_set_samplerate(audio_in_t *ai, int rate)
|
||||||
{
|
{
|
||||||
switch (ai->type) {
|
switch (ai->type) {
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
case AUDIO_IN_ALSA:
|
case AUDIO_IN_ALSA:
|
||||||
ai->req_samplerate = rate;
|
ai->req_samplerate = rate;
|
||||||
if (!ai->setup) return 0;
|
if (!ai->setup) return 0;
|
||||||
@ -88,7 +88,7 @@ int audio_in_set_samplerate(audio_in_t *ai, int rate)
|
|||||||
int audio_in_set_channels(audio_in_t *ai, int channels)
|
int audio_in_set_channels(audio_in_t *ai, int channels)
|
||||||
{
|
{
|
||||||
switch (ai->type) {
|
switch (ai->type) {
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
case AUDIO_IN_ALSA:
|
case AUDIO_IN_ALSA:
|
||||||
ai->req_channels = channels;
|
ai->req_channels = channels;
|
||||||
if (!ai->setup) return 0;
|
if (!ai->setup) return 0;
|
||||||
@ -109,12 +109,12 @@ int audio_in_set_channels(audio_in_t *ai, int channels)
|
|||||||
|
|
||||||
int audio_in_set_device(audio_in_t *ai, char *device)
|
int audio_in_set_device(audio_in_t *ai, char *device)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
int i;
|
int i;
|
||||||
#endif
|
#endif
|
||||||
if (ai->setup) return -1;
|
if (ai->setup) return -1;
|
||||||
switch (ai->type) {
|
switch (ai->type) {
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
case AUDIO_IN_ALSA:
|
case AUDIO_IN_ALSA:
|
||||||
if (ai->alsa.device) free(ai->alsa.device);
|
if (ai->alsa.device) free(ai->alsa.device);
|
||||||
ai->alsa.device = strdup(device);
|
ai->alsa.device = strdup(device);
|
||||||
@ -139,7 +139,7 @@ int audio_in_uninit(audio_in_t *ai)
|
|||||||
{
|
{
|
||||||
if (ai->setup) {
|
if (ai->setup) {
|
||||||
switch (ai->type) {
|
switch (ai->type) {
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
case AUDIO_IN_ALSA:
|
case AUDIO_IN_ALSA:
|
||||||
if (ai->alsa.log)
|
if (ai->alsa.log)
|
||||||
snd_output_close(ai->alsa.log);
|
snd_output_close(ai->alsa.log);
|
||||||
@ -163,7 +163,7 @@ int audio_in_uninit(audio_in_t *ai)
|
|||||||
int audio_in_start_capture(audio_in_t *ai)
|
int audio_in_start_capture(audio_in_t *ai)
|
||||||
{
|
{
|
||||||
switch (ai->type) {
|
switch (ai->type) {
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
case AUDIO_IN_ALSA:
|
case AUDIO_IN_ALSA:
|
||||||
return snd_pcm_start(ai->alsa.handle);
|
return snd_pcm_start(ai->alsa.handle);
|
||||||
#endif
|
#endif
|
||||||
@ -181,7 +181,7 @@ int audio_in_read_chunk(audio_in_t *ai, unsigned char *buffer)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (ai->type) {
|
switch (ai->type) {
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
case AUDIO_IN_ALSA:
|
case AUDIO_IN_ALSA:
|
||||||
ret = snd_pcm_readi(ai->alsa.handle, buffer, ai->alsa.chunk_size);
|
ret = snd_pcm_readi(ai->alsa.handle, buffer, ai->alsa.chunk_size);
|
||||||
if (ret != ai->alsa.chunk_size) {
|
if (ret != ai->alsa.chunk_size) {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
#include <alsa/asoundlib.h>
|
#include <alsa/asoundlib.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -43,7 +43,7 @@ typedef struct
|
|||||||
int bytes_per_sample;
|
int bytes_per_sample;
|
||||||
int samplesize;
|
int samplesize;
|
||||||
|
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
ai_alsa_t alsa;
|
ai_alsa_t alsa;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_OSS_AUDIO
|
#ifdef USE_OSS_AUDIO
|
||||||
@ -60,7 +60,7 @@ int audio_in_uninit(audio_in_t *ai);
|
|||||||
int audio_in_start_capture(audio_in_t *ai);
|
int audio_in_start_capture(audio_in_t *ai);
|
||||||
int audio_in_read_chunk(audio_in_t *ai, unsigned char *buffer);
|
int audio_in_read_chunk(audio_in_t *ai, unsigned char *buffer);
|
||||||
|
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
int ai_alsa_setup(audio_in_t *ai);
|
int ai_alsa_setup(audio_in_t *ai);
|
||||||
int ai_alsa_init(audio_in_t *ai);
|
int ai_alsa_init(audio_in_t *ai);
|
||||||
int ai_alsa_xrun(audio_in_t *ai);
|
int ai_alsa_xrun(audio_in_t *ai);
|
||||||
|
@ -70,7 +70,7 @@ int tv_param_buffer_size = -1;
|
|||||||
int tv_param_mjpeg = 0;
|
int tv_param_mjpeg = 0;
|
||||||
int tv_param_decimation = 2;
|
int tv_param_decimation = 2;
|
||||||
int tv_param_quality = 90;
|
int tv_param_quality = 90;
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
int tv_param_alsa = 0;
|
int tv_param_alsa = 0;
|
||||||
#endif
|
#endif
|
||||||
char* tv_param_adevice = NULL;
|
char* tv_param_adevice = NULL;
|
||||||
|
@ -40,7 +40,7 @@ extern int tv_param_buffer_size;
|
|||||||
extern int tv_param_mjpeg;
|
extern int tv_param_mjpeg;
|
||||||
extern int tv_param_decimation;
|
extern int tv_param_decimation;
|
||||||
extern int tv_param_quality;
|
extern int tv_param_quality;
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
extern int tv_param_alsa;
|
extern int tv_param_alsa;
|
||||||
#endif
|
#endif
|
||||||
extern char* tv_param_adevice;
|
extern char* tv_param_adevice;
|
||||||
|
@ -636,7 +636,7 @@ static int init(priv_t *priv)
|
|||||||
/* audio init */
|
/* audio init */
|
||||||
if (!tv_param_noaudio) {
|
if (!tv_param_noaudio) {
|
||||||
|
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
if (tv_param_alsa)
|
if (tv_param_alsa)
|
||||||
audio_in_init(&priv->audio_in, AUDIO_IN_ALSA);
|
audio_in_init(&priv->audio_in, AUDIO_IN_ALSA);
|
||||||
else
|
else
|
||||||
|
@ -1047,7 +1047,7 @@ static int init(priv_t *priv)
|
|||||||
|
|
||||||
/* audio init */
|
/* audio init */
|
||||||
if (!tv_param_noaudio) {
|
if (!tv_param_noaudio) {
|
||||||
#ifdef HAVE_ALSA9
|
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
|
||||||
if (tv_param_alsa)
|
if (tv_param_alsa)
|
||||||
audio_in_init(&priv->audio_in, AUDIO_IN_ALSA);
|
audio_in_init(&priv->audio_in, AUDIO_IN_ALSA);
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user