diff options
author | henry <henry@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2004-01-11 17:07:32 +0000 |
---|---|---|
committer | henry <henry@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2004-01-11 17:07:32 +0000 |
commit | 70162b5ef8fe51eef0480ffab3f4854afb39b32b (patch) | |
tree | a4095ae159ae5e3994bb5a8daf8828f33a7e2f31 /libmpdemux | |
parent | 9ce5d288f952870e6e5fd5e7bcab55dc47089915 (diff) | |
download | mpv-70162b5ef8fe51eef0480ffab3f4854afb39b32b.tar.bz2 mpv-70162b5ef8fe51eef0480ffab3f4854afb39b32b.tar.xz |
ALSA 1.x audio out driver
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@11776 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdemux')
-rw-r--r-- | libmpdemux/Makefile | 2 | ||||
-rw-r--r-- | libmpdemux/ai_alsa1x.c | 53 | ||||
-rw-r--r-- | libmpdemux/audio_in.c | 18 | ||||
-rw-r--r-- | libmpdemux/audio_in.h | 6 | ||||
-rw-r--r-- | libmpdemux/tv.c | 2 | ||||
-rw-r--r-- | libmpdemux/tv.h | 2 | ||||
-rw-r--r-- | libmpdemux/tvi_v4l.c | 2 | ||||
-rw-r--r-- | libmpdemux/tvi_v4l2.c | 2 |
8 files changed, 53 insertions, 34 deletions
diff --git a/libmpdemux/Makefile b/libmpdemux/Makefile index 3fce03fc7a..e3945ac9d5 100644 --- a/libmpdemux/Makefile +++ b/libmpdemux/Makefile @@ -3,7 +3,7 @@ LIBNAME = libmpdemux.a 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) SRCS += demux_xmms.c endif diff --git a/libmpdemux/ai_alsa1x.c b/libmpdemux/ai_alsa1x.c index 715c99a82e..2f1e95c058 100644 --- a/libmpdemux/ai_alsa1x.c +++ b/libmpdemux/ai_alsa1x.c @@ -4,7 +4,7 @@ #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 "audio_in.h" @@ -14,8 +14,9 @@ int ai_alsa_setup(audio_in_t *ai) { snd_pcm_hw_params_t *params; snd_pcm_sw_params_t *swparams; - int buffer_size; + snd_pcm_uframes_t buffer_size, period_size; int err; + int dir; unsigned int rate; 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"); return -1; } + err = snd_pcm_hw_params_set_access(ai->alsa.handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); if (err < 0) { mp_msg(MSGT_TV, MSGL_ERR, "Access type not available\n"); return -1; } + err = snd_pcm_hw_params_set_format(ai->alsa.handle, params, SND_PCM_FORMAT_S16_LE); if (err < 0) { mp_msg(MSGT_TV, MSGL_ERR, "Sample format not available\n"); return -1; } + err = snd_pcm_hw_params_set_channels(ai->alsa.handle, params, ai->req_channels); 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", ai->channels); } else { ai->channels = ai->req_channels; } - err = snd_pcm_hw_params_set_rate_near(ai->alsa.handle, params, ai->req_samplerate, 0); - assert(err >= 0); - rate = err; + dir = 0; + rate = ai->req_samplerate; + 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; + dir = 0; ai->alsa.buffer_time = 1000000; - ai->alsa.buffer_time = snd_pcm_hw_params_set_buffer_time_near(ai->alsa.handle, params, - ai->alsa.buffer_time, 0); - assert(ai->alsa.buffer_time >= 0); + err = snd_pcm_hw_params_set_buffer_time_near(ai->alsa.handle, params, + &ai->alsa.buffer_time, &dir); + 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 = snd_pcm_hw_params_set_period_time_near(ai->alsa.handle, params, - ai->alsa.period_time, 0); - assert(ai->alsa.period_time >= 0); + err = snd_pcm_hw_params_set_period_time_near(ai->alsa.handle, params, + &ai->alsa.period_time, &dir); + if (err < 0) { + mp_msg(MSGT_TV, MSGL_ERR, "Cannot set period time\n"); + } + err = snd_pcm_hw_params(ai->alsa.handle, params); 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); 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); - if (ai->alsa.chunk_size == buffer_size) { + + dir = -1; + 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); return -1; } + snd_pcm_sw_params_current(ai->alsa.handle, swparams); err = snd_pcm_sw_params_set_sleep_min(ai->alsa.handle, swparams,0); assert(err >= 0); @@ -166,4 +185,4 @@ int ai_alsa_xrun(audio_in_t *ai) return -1; } -#endif /* HAVE_ALSA9 */ +#endif /* HAVE_ALSA1X */ diff --git a/libmpdemux/audio_in.c b/libmpdemux/audio_in.c index 4c35df97d0..dc090f4250 100644 --- a/libmpdemux/audio_in.c +++ b/libmpdemux/audio_in.c @@ -24,7 +24,7 @@ int audio_in_init(audio_in_t *ai, int type) ai->samplesize = -1; switch (ai->type) { -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) case AUDIO_IN_ALSA: ai->alsa.handle = NULL; ai->alsa.log = NULL; @@ -46,7 +46,7 @@ int audio_in_setup(audio_in_t *ai) { switch (ai->type) { -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) case AUDIO_IN_ALSA: if (ai_alsa_init(ai) < 0) return -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) { switch (ai->type) { -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) case AUDIO_IN_ALSA: ai->req_samplerate = rate; 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) { switch (ai->type) { -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) case AUDIO_IN_ALSA: ai->req_channels = channels; 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) { -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) int i; #endif if (ai->setup) return -1; switch (ai->type) { -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) case AUDIO_IN_ALSA: if (ai->alsa.device) free(ai->alsa.device); ai->alsa.device = strdup(device); @@ -139,7 +139,7 @@ int audio_in_uninit(audio_in_t *ai) { if (ai->setup) { switch (ai->type) { -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) case AUDIO_IN_ALSA: if (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) { switch (ai->type) { -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) case AUDIO_IN_ALSA: return snd_pcm_start(ai->alsa.handle); #endif @@ -181,7 +181,7 @@ int audio_in_read_chunk(audio_in_t *ai, unsigned char *buffer) int ret; switch (ai->type) { -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) case AUDIO_IN_ALSA: ret = snd_pcm_readi(ai->alsa.handle, buffer, ai->alsa.chunk_size); if (ret != ai->alsa.chunk_size) { diff --git a/libmpdemux/audio_in.h b/libmpdemux/audio_in.h index 43d57bdda2..c4b3ea91a7 100644 --- a/libmpdemux/audio_in.h +++ b/libmpdemux/audio_in.h @@ -6,7 +6,7 @@ #include "config.h" -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) #include <alsa/asoundlib.h> typedef struct { @@ -43,7 +43,7 @@ typedef struct int bytes_per_sample; int samplesize; -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) ai_alsa_t alsa; #endif #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_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_init(audio_in_t *ai); int ai_alsa_xrun(audio_in_t *ai); diff --git a/libmpdemux/tv.c b/libmpdemux/tv.c index 16467cd97f..0e07f4b201 100644 --- a/libmpdemux/tv.c +++ b/libmpdemux/tv.c @@ -70,7 +70,7 @@ int tv_param_buffer_size = -1; int tv_param_mjpeg = 0; int tv_param_decimation = 2; int tv_param_quality = 90; -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) int tv_param_alsa = 0; #endif char* tv_param_adevice = NULL; diff --git a/libmpdemux/tv.h b/libmpdemux/tv.h index 69ec328282..72aef64b4b 100644 --- a/libmpdemux/tv.h +++ b/libmpdemux/tv.h @@ -40,7 +40,7 @@ extern int tv_param_buffer_size; extern int tv_param_mjpeg; extern int tv_param_decimation; extern int tv_param_quality; -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) extern int tv_param_alsa; #endif extern char* tv_param_adevice; diff --git a/libmpdemux/tvi_v4l.c b/libmpdemux/tvi_v4l.c index 63cb216e6a..384abd80ff 100644 --- a/libmpdemux/tvi_v4l.c +++ b/libmpdemux/tvi_v4l.c @@ -636,7 +636,7 @@ static int init(priv_t *priv) /* audio init */ if (!tv_param_noaudio) { -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) if (tv_param_alsa) audio_in_init(&priv->audio_in, AUDIO_IN_ALSA); else diff --git a/libmpdemux/tvi_v4l2.c b/libmpdemux/tvi_v4l2.c index a99cc6445e..cfd9186c1c 100644 --- a/libmpdemux/tvi_v4l2.c +++ b/libmpdemux/tvi_v4l2.c @@ -1047,7 +1047,7 @@ static int init(priv_t *priv) /* audio init */ if (!tv_param_noaudio) { -#ifdef HAVE_ALSA9 +#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) if (tv_param_alsa) audio_in_init(&priv->audio_in, AUDIO_IN_ALSA); else |