Mercurial > mplayer.hg
annotate libao2/ao_alsa1x.c @ 7072:113d66d78967
removed nonsense 'inline'
patch by Joey Parrish <joey@yunamusic.com>
author | arpi |
---|---|
date | Thu, 22 Aug 2002 23:28:33 +0000 |
parents | a5b2b377ab50 |
children | a24f91c247cd |
rev | line source |
---|---|
1050 | 1 /* |
2 ao_alsa9 - ALSA-0.9.x output plugin for MPlayer | |
3 | |
4 (C) Alex Beregszaszi <alex@naxine.org> | |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
5 |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
6 modified for better alsa-0.9.0beta12(rc1)-support by Joy Winter <joy@pingfm.org> |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
7 additional AC3 passthrough support by Andy Lo A Foe <andy@alsaplayer.org> |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
8 |
2209 | 9 Any bugreports regarding to this driver are welcome either to the mplayer-user-mailinglist or directly to the authors. |
1050 | 10 */ |
11 | |
12 #include <errno.h> | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
13 #include <sys/time.h> |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
14 #include <stdlib.h> |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
15 #include <math.h> |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
16 #include <string.h> |
6749 | 17 #include <sys/poll.h> |
5855
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
18 |
5857 | 19 #include "../config.h" |
20 | |
5855
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
21 #if HAVE_SYS_ASOUNDLIB_H |
1050 | 22 #include <sys/asoundlib.h> |
5855
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
23 #elif HAVE_ALSA_ASOUNDLIB_H |
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
24 #include <alsa/asoundlib.h> |
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
25 #else |
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
26 #error "asoundlib.h is not in sys/ or alsa/ - please bugreport" |
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
27 #endif |
1050 | 28 |
29 #include "audio_out.h" | |
30 #include "audio_out_internal.h" | |
1058 | 31 #include "afmt.h" |
1050 | 32 |
33 extern int verbose; | |
34 | |
35 static ao_info_t info = | |
36 { | |
37 "ALSA-0.9.x audio output", | |
38 "alsa9", | |
2209 | 39 "Alex Beregszaszi <alex@naxine.org>, Joy Winter <joy@pingfm.org>", |
1050 | 40 "under developement" |
41 }; | |
42 | |
43 LIBAO_EXTERN(alsa9) | |
44 | |
45 | |
46 static snd_pcm_t *alsa_handler; | |
47 static snd_pcm_format_t alsa_format; | |
48 static snd_pcm_hw_params_t *alsa_hwparams; | |
49 static snd_pcm_sw_params_t *alsa_swparams; | |
50 static char *alsa_device; | |
51 | |
6749 | 52 /* possible 4096, original 8192 |
53 * was only needed for calculating chunksize? */ | |
54 static int alsa_fragsize = 4096; | |
55 /* 16 sets buffersize to 16 * chunksize is as default 1024 | |
56 * which seems to be good avarge for most situations | |
57 * so buffersize is 16384 frames by default */ | |
58 static int alsa_fragcount = 16; | |
59 static int chunk_size = 1024; //is alsa_fragsize / 4 | |
2209 | 60 |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
61 static size_t bits_per_sample, bits_per_frame; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
62 static size_t chunk_bytes; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
63 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
64 int ao_mmap = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
65 int ao_noblock = 0; |
6749 | 66 int first = 1; |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
67 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
68 static int open_mode; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
69 static int set_block_mode; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
70 |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
71 #define ALSA_DEVICE_SIZE 48 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
72 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
73 #undef BUFFERTIME |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
74 #define SET_CHUNKSIZE |
6749 | 75 #undef USE_POLL |
1128 | 76 |
6749 | 77 snd_pcm_t *spdif_init(char *pcm_name) |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
78 { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
79 //char *pcm_name = "hw:0,2"; /* first card second device */ |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
80 static snd_aes_iec958_t spdif; |
6749 | 81 static snd_aes_iec958_t spdif_test; |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
82 snd_pcm_info_t *info; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
83 snd_pcm_t *handler; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
84 snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
85 unsigned int channels = 2; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
86 unsigned int rate = 48000; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
87 int err, c; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
88 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
89 if ((err = snd_pcm_open(&handler, pcm_name, SND_PCM_STREAM_PLAYBACK, 0)) < 0) |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
90 { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
91 fprintf(stderr, "open: %s\n", snd_strerror(err)); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
92 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
93 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
94 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
95 snd_pcm_info_alloca(&info); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
96 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
97 if ((err = snd_pcm_info(handler, info)) < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
98 fprintf(stderr, "info: %s\n", snd_strerror(err)); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
99 snd_pcm_close(handler); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
100 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
101 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
102 printf("device: %d, subdevice: %d\n", snd_pcm_info_get_device(info), |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
103 snd_pcm_info_get_subdevice(info)); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
104 { |
6749 | 105 |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
106 snd_ctl_elem_value_t *ctl; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
107 snd_ctl_t *ctl_handler; |
6749 | 108 snd_ctl_elem_id_t *elem_id; |
109 unsigned int elem_device; | |
110 const char *elem_name; | |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
111 char ctl_name[12]; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
112 int ctl_card; |
6749 | 113 //elem_id = 36; |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
114 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
115 spdif.status[0] = IEC958_AES0_NONAUDIO | |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
116 IEC958_AES0_CON_EMPHASIS_NONE; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
117 spdif.status[1] = IEC958_AES1_CON_ORIGINAL | |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
118 IEC958_AES1_CON_PCM_CODER; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
119 spdif.status[2] = 0; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
120 spdif.status[3] = IEC958_AES3_CON_FS_48000; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
121 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
122 snd_ctl_elem_value_alloca(&ctl); |
6749 | 123 snd_ctl_elem_id_alloca(&elem_id); |
124 snd_ctl_elem_value_set_interface(ctl, SND_CTL_ELEM_IFACE_PCM); //SND_CTL_ELEM_IFACE_MIXER | |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
125 snd_ctl_elem_value_set_device(ctl, snd_pcm_info_get_device(info)); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
126 snd_ctl_elem_value_set_subdevice(ctl, snd_pcm_info_get_subdevice(info)); |
6749 | 127 snd_ctl_elem_value_set_name(ctl,SND_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM)); //SWITCH |
128 snd_ctl_elem_value_set_iec958(ctl, &spdif); | |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
129 ctl_card = snd_pcm_info_get_card(info); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
130 if (ctl_card < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
131 fprintf(stderr, "Unable to setup the IEC958 (S/PDIF) interface - PCM has no assigned card"); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
132 goto __diga_end; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
133 } |
6749 | 134 |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
135 sprintf(ctl_name, "hw:%d", ctl_card); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
136 printf("hw:%d\n", ctl_card); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
137 if ((err = snd_ctl_open(&ctl_handler, ctl_name, 0)) < 0) { |
6702 | 138 fprintf(stderr, "Unable to open the control interface '%s': %s\n", ctl_name, snd_strerror(err)); |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
139 goto __diga_end; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
140 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
141 if ((err = snd_ctl_elem_write(ctl_handler, ctl)) < 0) { |
6749 | 142 //fprintf(stderr, "Unable to update the IEC958 control: %s\n", snd_strerror(err)); |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
143 printf("alsa-spdif-init: cant set spdif-through automatically\n"); |
6702 | 144 goto __diga_end; |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
145 } |
6749 | 146 |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
147 snd_ctl_close(ctl_handler); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
148 __diga_end: |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
149 |
6702 | 150 } |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
151 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
152 { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
153 snd_pcm_hw_params_t *params; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
154 snd_pcm_sw_params_t *swparams; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
155 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
156 snd_pcm_hw_params_alloca(¶ms); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
157 snd_pcm_sw_params_alloca(&swparams); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
158 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
159 err = snd_pcm_hw_params_any(handler, params); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
160 if (err < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
161 fprintf(stderr, "Broken configuration for this PCM: no configurations available"); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
162 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
163 } |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
164 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
165 err = snd_pcm_hw_params_set_access(handler, params,SND_PCM_ACCESS_RW_INTERLEAVED); |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
166 if (err < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
167 fprintf(stderr, "Access tyep not available"); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
168 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
169 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
170 err = snd_pcm_hw_params_set_format(handler, params, format); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
171 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
172 if (err < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
173 fprintf(stderr, "Sample format non available"); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
174 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
175 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
176 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
177 err = snd_pcm_hw_params_set_channels(handler, params, channels); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
178 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
179 if (err < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
180 fprintf(stderr, "Channels count non avaible"); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
181 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
182 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
183 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
184 err = snd_pcm_hw_params_set_rate_near(handler, params, rate, 0); assert(err >= 0); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
185 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
186 err = snd_pcm_hw_params(handler, params); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
187 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
188 if (err < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
189 fprintf(stderr, "Cannot set buffer size\n"); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
190 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
191 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
192 snd_pcm_sw_params_current(handler, swparams); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
193 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
194 return handler; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
195 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
196 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
197 |
1050 | 198 /* to set/get/query special features/parameters */ |
199 static int control(int cmd, int arg) | |
200 { | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
201 switch(cmd) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
202 case AOCONTROL_QUERY_FORMAT: |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
203 return CONTROL_TRUE; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
204 case AOCONTROL_GET_VOLUME: |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
205 case AOCONTROL_SET_VOLUME: |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
206 #ifndef WORDS_BIGENDIAN |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
207 { //seems to be a problem on macs? |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
208 { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
209 ao_control_vol_t *vol = (ao_control_vol_t *)arg; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
210 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
211 int err; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
212 snd_mixer_t *handle; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
213 snd_mixer_elem_t *elem; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
214 snd_mixer_selem_id_t *sid; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
215 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
216 const char *mix_name = "PCM"; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
217 char *card = "default"; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
218 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
219 long pmin, pmax; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
220 long get_vol, set_vol; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
221 float calc_vol, diff, f_multi; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
222 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
223 if(ao_data.format == AFMT_AC3) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
224 return CONTROL_TRUE; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
225 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
226 //allocate simple id |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
227 snd_mixer_selem_id_alloca(&sid); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
228 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
229 //sets simple-mixer index and name |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
230 snd_mixer_selem_id_set_index(sid, 0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
231 snd_mixer_selem_id_set_name(sid, mix_name); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
232 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
233 if ((err = snd_mixer_open(&handle, 0)) < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
234 printf("alsa-control: mixer open error: %s\n", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
235 return CONTROL_ERROR; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
236 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
237 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
238 if ((err = snd_mixer_attach(handle, card)) < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
239 printf("alsa-control: mixer attach %s error: %s", card, snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
240 snd_mixer_close(handle); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
241 return CONTROL_ERROR; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
242 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
243 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
244 if ((err = snd_mixer_selem_register(handle, NULL, NULL)) < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
245 printf("alsa-control: mixer register error: %s", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
246 snd_mixer_close(handle); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
247 return CONTROL_ERROR; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
248 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
249 err = snd_mixer_load(handle); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
250 if (err < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
251 printf("alsa-control: mixer load error: %s", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
252 snd_mixer_close(handle); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
253 return CONTROL_ERROR; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
254 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
255 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
256 elem = snd_mixer_find_selem(handle, sid); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
257 if (!elem) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
258 printf("alsa-control: unable to find simple control '%s',%i\n", snd_mixer_selem_id_get_name(sid), snd_mixer_selem_id_get_index(sid)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
259 snd_mixer_close(handle); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
260 return CONTROL_ERROR; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
261 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
262 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
263 snd_mixer_selem_get_playback_volume_range(elem,&pmin,&pmax); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
264 f_multi = (100 / (float)pmax); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
265 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
266 if (cmd == AOCONTROL_SET_VOLUME) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
267 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
268 diff = (vol->left+vol->right) / 2; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
269 set_vol = rint(diff / f_multi); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
270 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
271 if (set_vol < 0) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
272 set_vol = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
273 else if (set_vol > pmax) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
274 set_vol = pmax; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
275 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
276 //setting channels |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
277 if ((err = snd_mixer_selem_set_playback_volume(elem, 0, set_vol)) < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
278 printf("alsa-control: error setting left channel, %s",snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
279 return CONTROL_ERROR; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
280 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
281 if ((err = snd_mixer_selem_set_playback_volume(elem, 1, set_vol)) < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
282 printf("alsa-control: error setting right channel, %s",snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
283 return CONTROL_ERROR; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
284 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
285 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
286 //printf("diff=%f, set_vol=%i, pmax=%i, mult=%f\n", diff, set_vol, pmax, f_multi); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
287 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
288 else { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
289 snd_mixer_selem_get_playback_volume(elem, 0, &get_vol); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
290 calc_vol = get_vol; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
291 calc_vol = rintf(calc_vol * f_multi); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
292 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
293 vol->left = vol->right = (int)calc_vol; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
294 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
295 //printf("get_vol = %i, calc=%i\n",get_vol, calc_vol); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
296 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
297 snd_mixer_close(handle); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
298 return CONTROL_OK; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
299 } |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
300 }// end big-endian |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
301 #endif |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
302 #ifdef WORDS_BIGENDIAN |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
303 { |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
304 { |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
305 return (CONTROL_UNKNOWN); |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
306 } |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
307 } |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
308 #endif |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
309 |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
310 } //end witch |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
311 return(CONTROL_UNKNOWN); |
1050 | 312 } |
313 | |
1128 | 314 |
1050 | 315 /* |
316 open & setup audio device | |
317 return: 1=success 0=fail | |
318 */ | |
319 static int init(int rate_hz, int channels, int format, int flags) | |
320 { | |
321 int err; | |
322 int cards = -1; | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
323 int period_val; |
1050 | 324 snd_pcm_info_t *alsa_info; |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
325 char *str_block_mode; |
6702 | 326 int device_set = 0; |
1180 | 327 |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
328 printf("alsa-init: testing and bugreports are welcome.\n"); |
1050 | 329 printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, |
330 channels, audio_out_format_name(format)); | |
331 | |
332 alsa_handler = NULL; | |
333 | |
334 if (verbose) | |
2059 | 335 printf("alsa-init: compiled for ALSA-%s\n", SND_LIB_VERSION_STR); |
1050 | 336 |
337 if ((err = snd_card_next(&cards)) < 0 || cards < 0) | |
338 { | |
339 printf("alsa-init: no soundcards found: %s\n", snd_strerror(err)); | |
340 return(0); | |
341 } | |
342 | |
3095 | 343 ao_data.samplerate = rate_hz; |
344 ao_data.bps = channels; /* really this is bytes per frame so bad varname */ | |
345 ao_data.format = format; | |
346 ao_data.channels = channels; | |
347 ao_data.outburst = OUTBURST; | |
6749 | 348 //ao_data.buffersize = MAX_OUTBURST; // was 16384 |
1050 | 349 |
350 switch (format) | |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
351 { |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
352 case AFMT_S8: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
353 alsa_format = SND_PCM_FORMAT_S8; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
354 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
355 case AFMT_U8: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
356 alsa_format = SND_PCM_FORMAT_U8; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
357 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
358 case AFMT_U16_LE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
359 alsa_format = SND_PCM_FORMAT_U16_LE; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
360 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
361 case AFMT_U16_BE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
362 alsa_format = SND_PCM_FORMAT_U16_BE; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
363 break; |
5790 | 364 #ifndef WORDS_BIGENDIAN |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
365 case AFMT_AC3: |
5790 | 366 #endif |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
367 case AFMT_S16_LE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
368 alsa_format = SND_PCM_FORMAT_S16_LE; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
369 break; |
5790 | 370 #ifdef WORDS_BIGENDIAN |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
371 case AFMT_AC3: |
5790 | 372 #endif |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
373 case AFMT_S16_BE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
374 alsa_format = SND_PCM_FORMAT_S16_BE; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
375 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
376 case AFMT_S32_LE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
377 alsa_format = SND_PCM_FORMAT_S32_LE; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
378 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
379 case AFMT_S32_BE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
380 alsa_format = SND_PCM_FORMAT_S32_BE; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
381 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
382 |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
383 default: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
384 alsa_format = SND_PCM_FORMAT_MPEG; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
385 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
386 } |
1050 | 387 |
388 switch(alsa_format) | |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
389 { |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
390 case SND_PCM_FORMAT_S16_LE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
391 case SND_PCM_FORMAT_U16_LE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
392 ao_data.bps *= 2; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
393 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
394 case SND_PCM_FORMAT_S32_LE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
395 case SND_PCM_FORMAT_S32_BE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
396 ao_data.bps *= 4; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
397 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
398 case -1: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
399 printf("alsa-init: invalid format (%s) requested - output disabled\n", |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
400 audio_out_format_name(format)); |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
401 return(0); |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
402 default: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
403 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
404 } |
1128 | 405 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
406 if (ao_subdevice) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
407 //start parsing ao_subdevice, ugly and not thread safe! |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
408 //maybe there's a better way? |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
409 int i2 = 1; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
410 int i3 = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
411 char *sub_str; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
412 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
413 char *token_str[3]; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
414 char* test_str = strdup(ao_subdevice); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
415 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
416 //printf("subd=%s, test=%s\n", ao_subdevice,test_str); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
417 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
418 if ((strcspn(ao_subdevice, ":")) > 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
419 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
420 sub_str = strtok(test_str, ":"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
421 *(token_str) = sub_str; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
422 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
423 while (((sub_str = strtok(NULL, ":")) != NULL) && (i2 <= 3)) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
424 *(token_str+i2) = sub_str; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
425 //printf("token %i: %s\n", i2, *(token_str+i2)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
426 i2 += 1; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
427 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
428 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
429 for (i3=0; i3 <= i2-1; i3++) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
430 //printf("test %i, %s\n", i3, *(token_str+i3)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
431 if (strcmp(*(token_str + i3), "mmap") == 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
432 ao_mmap = 1; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
433 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
434 else if (strcmp(*(token_str+i3), "noblock") == 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
435 ao_noblock = 1; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
436 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
437 else if (strcmp(*(token_str+i3), "hw") == 0) { |
6702 | 438 if ((i3 < i2-1) && (strcmp(*(token_str+i3+1), "noblock") != 0) && (strcmp(*(token_str+i3+1), "mmap") != 0)) { |
439 //printf("next tok = %s\n", *(token_str+(i3+1))); | |
440 alsa_device = alloca(ALSA_DEVICE_SIZE); | |
441 snprintf(alsa_device, ALSA_DEVICE_SIZE, "hw:%s", *(token_str+(i3+1))); | |
442 device_set = 1; | |
443 } | |
444 else { | |
445 //printf("setting hw\n"); | |
446 alsa_device = *(token_str+i3); | |
447 device_set = 1; | |
448 } | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
449 } |
6702 | 450 else if (device_set == 0 && (!ao_mmap || !ao_noblock)) { |
451 //printf("setting common, %s\n", *(token_str+i3)); | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
452 alsa_device = *(token_str+i3); |
6702 | 453 device_set = 1; |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
454 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
455 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
456 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
457 } //end parsing ao_subdevice |
1207 | 458 |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
459 if (alsa_device == NULL) |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
460 { |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
461 int tmp_device, tmp_subdevice, err; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
462 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
463 if ((err = snd_pcm_info_malloc(&alsa_info)) < 0) |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
464 { |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
465 printf("alsa-init: memory allocation error: %s\n", snd_strerror(err)); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
466 return(0); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
467 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
468 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
469 if ((alsa_device = alloca(ALSA_DEVICE_SIZE)) == NULL) |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
470 { |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
471 printf("alsa-init: memory allocation error: %s\n", strerror(errno)); |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
472 return(0); |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
473 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
474 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
475 if ((tmp_device = snd_pcm_info_get_device(alsa_info)) < 0) |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
476 { |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
477 printf("alsa-init: cant get device\n"); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
478 return(0); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
479 } |
1050 | 480 |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
481 if ((tmp_subdevice = snd_pcm_info_get_subdevice(alsa_info)) < 0) |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
482 { |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
483 printf("alsa-init: cant get subdevice\n"); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
484 return(0); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
485 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
486 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
487 if (verbose) |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
488 printf("alsa-init: got device=%i, subdevice=%i\n", tmp_device, tmp_subdevice); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
489 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
490 if ((err = snprintf(alsa_device, ALSA_DEVICE_SIZE, "hw:%1d,%1d", tmp_device, tmp_subdevice)) <= 0) |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
491 { |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
492 printf("alsa-init: cant wrote device-id\n"); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
493 } |
1050 | 494 |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
495 snd_pcm_info_free(alsa_info); |
6702 | 496 printf("alsa-init: %d soundcard%s found, using: %s\n", cards+1, |
497 (cards >= 0) ? "" : "s", alsa_device); | |
498 } else if (strcmp(alsa_device, "help") == 0) { | |
499 printf("alsa-help: available options are:\n"); | |
500 printf(" mmap: sets mmap-mode\n"); | |
501 printf(" noblock: sets noblock-mode\n"); | |
502 printf(" device-name: sets device name\n"); | |
503 printf(" example -ao alsa9:mmap:noblock:hw:0,3 sets noblock-mode,\n"); | |
504 printf(" mmap-mode and the device-name as first card third device\n"); | |
505 return(0); | |
506 } else { | |
507 printf("alsa-init: soundcard set to %s\n", alsa_device); | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
508 } |
1050 | 509 |
6702 | 510 // switch for spdif |
511 // Try to initialize the SPDIF interface | |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
512 if (format == AFMT_AC3) { |
6702 | 513 if (device_set) |
514 alsa_handler = spdif_init(alsa_device); | |
515 else | |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
516 alsa_handler = spdif_init("iec958"); |
6702 | 517 } |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
518 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
519 //setting modes for block or nonblock-mode |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
520 if (ao_noblock) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
521 open_mode = SND_PCM_NONBLOCK; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
522 set_block_mode = 1; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
523 str_block_mode = "nonblock-mode"; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
524 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
525 else { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
526 open_mode = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
527 set_block_mode = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
528 str_block_mode = "block-mode"; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
529 } |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
530 |
6749 | 531 //sets buff/chunksize if its set manually |
532 if (ao_data.buffersize) { | |
533 switch (ao_data.buffersize) | |
534 { | |
535 case 1: | |
536 alsa_fragcount = 16; | |
537 chunk_size = 512; | |
538 if (verbose) { | |
539 printf("alsa-init: buffersize set manually to 8192\n"); | |
540 printf("alsa-init: chunksize set manually to 512\n"); | |
541 } | |
542 break; | |
543 case 2: | |
544 alsa_fragcount = 8; | |
545 chunk_size = 1024; | |
546 if (verbose) { | |
547 printf("alsa-init: buffersize set manually to 8192\n"); | |
548 printf("alsa-init: chunksize set manually to 1024\n"); | |
549 } | |
550 break; | |
551 case 3: | |
552 alsa_fragcount = 32; | |
553 chunk_size = 512; | |
554 if (verbose) { | |
555 printf("alsa-init: buffersize set manually to 16384\n"); | |
556 printf("alsa-init: chunksize set manually to 512\n"); | |
557 } | |
558 break; | |
559 case 4: | |
560 alsa_fragcount = 16; | |
561 chunk_size = 1024; | |
562 if (verbose) { | |
563 printf("alsa-init: buffersize set manually to 16384\n"); | |
564 printf("alsa-init: chunksize set manually to 1024\n"); | |
565 } | |
566 break; | |
567 default: | |
568 alsa_fragcount = 16; | |
569 if (ao_mmap) | |
570 chunk_size = 512; | |
571 else | |
572 chunk_size = 1024; | |
573 break; | |
574 } | |
575 } | |
576 | |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
577 if (!alsa_handler) { |
6702 | 578 //modes = 0, SND_PCM_NONBLOCK, SND_PCM_ASYNC |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
579 if ((err = snd_pcm_open(&alsa_handler, alsa_device, SND_PCM_STREAM_PLAYBACK, open_mode)) < 0) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
580 { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
581 if (ao_noblock) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
582 printf("alsa-init: open in nonblock-mode failed, trying to open in block-mode\n"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
583 if ((err = snd_pcm_open(&alsa_handler, alsa_device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
584 printf("alsa-init: playback open error: %s\n", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
585 return(0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
586 } else { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
587 set_block_mode = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
588 str_block_mode = "block-mode"; |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
589 } |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
590 } else { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
591 printf("alsa-init: playback open error: %s\n", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
592 return(0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
593 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
594 } |
1050 | 595 |
6702 | 596 if ((err = snd_pcm_nonblock(alsa_handler, set_block_mode)) < 0) { |
597 printf("alsa-init: error set block-mode %s\n", snd_strerror(err)); | |
598 } | |
599 else if (verbose) { | |
600 printf("alsa-init: pcm opend in %s\n", str_block_mode); | |
601 } | |
602 | |
603 snd_pcm_hw_params_alloca(&alsa_hwparams); | |
604 snd_pcm_sw_params_alloca(&alsa_swparams); | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
605 |
6702 | 606 // setting hw-parameters |
607 if ((err = snd_pcm_hw_params_any(alsa_handler, alsa_hwparams)) < 0) | |
608 { | |
609 printf("alsa-init: unable to get initial parameters: %s\n", | |
610 snd_strerror(err)); | |
611 return(0); | |
612 } | |
1050 | 613 |
6702 | 614 if (ao_mmap) { |
615 snd_pcm_access_mask_t *mask = alloca(snd_pcm_access_mask_sizeof()); | |
616 snd_pcm_access_mask_none(mask); | |
617 snd_pcm_access_mask_set(mask, SND_PCM_ACCESS_MMAP_INTERLEAVED); | |
618 snd_pcm_access_mask_set(mask, SND_PCM_ACCESS_MMAP_NONINTERLEAVED); | |
619 snd_pcm_access_mask_set(mask, SND_PCM_ACCESS_MMAP_COMPLEX); | |
620 err = snd_pcm_hw_params_set_access_mask(alsa_handler, alsa_hwparams, mask); | |
621 printf("alsa-init: mmap set\n"); | |
622 } else { | |
623 err = snd_pcm_hw_params_set_access(alsa_handler, alsa_hwparams,SND_PCM_ACCESS_RW_INTERLEAVED); | |
624 } | |
625 if (err < 0) { | |
626 printf("alsa-init: unable to set access type: %s\n", snd_strerror(err)); | |
627 return (0); | |
628 } | |
1050 | 629 |
6702 | 630 if ((err = snd_pcm_hw_params_set_format(alsa_handler, alsa_hwparams, |
631 alsa_format)) < 0) | |
632 { | |
633 printf("alsa-init: unable to set format: %s\n", | |
634 snd_strerror(err)); | |
635 return(0); | |
636 } | |
1050 | 637 |
6702 | 638 if ((err = snd_pcm_hw_params_set_channels(alsa_handler, alsa_hwparams, |
639 ao_data.channels)) < 0) | |
640 { | |
641 printf("alsa-init: unable to set channels: %s\n", | |
642 snd_strerror(err)); | |
643 return(0); | |
644 } | |
1050 | 645 |
6702 | 646 if ((err = snd_pcm_hw_params_set_rate_near(alsa_handler, alsa_hwparams, ao_data.samplerate, 0)) < 0) |
2059 | 647 { |
6702 | 648 printf("alsa-init: unable to set samplerate-2: %s\n", |
649 snd_strerror(err)); | |
650 return(0); | |
2059 | 651 } |
1050 | 652 |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
653 #ifdef BUFFERTIME |
6702 | 654 { |
655 int alsa_buffer_time = 500000; /* original 60 */ | |
1050 | 656 |
2059 | 657 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time, 0)) < 0) |
6702 | 658 { |
1050 | 659 printf("alsa-init: unable to set buffer time near: %s\n", |
6702 | 660 snd_strerror(err)); |
1050 | 661 return(0); |
6702 | 662 } else |
1050 | 663 alsa_buffer_time = err; |
664 | |
2209 | 665 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time/4, 0)) < 0) |
3095 | 666 /* original: alsa_buffer_time/ao_data.bps */ |
6702 | 667 { |
1050 | 668 printf("alsa-init: unable to set period time: %s\n", |
6702 | 669 snd_strerror(err)); |
1050 | 670 return(0); |
6702 | 671 } |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
672 if (verbose) |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
673 printf("alsa-init: buffer_time: %d, period_time :%d\n",alsa_buffer_time, err); |
6702 | 674 } |
1050 | 675 #endif |
676 | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
677 #ifdef SET_CHUNKSIZE |
6702 | 678 { |
679 //set chunksize | |
680 if ((err = snd_pcm_hw_params_set_period_size(alsa_handler, alsa_hwparams, chunk_size, 0)) < 0) | |
681 { | |
682 printf("alsa-init: unable to set periodsize: %s\n", snd_strerror(err)); | |
683 return(0); | |
684 } | |
685 else if (verbose) { | |
686 printf("alsa-init: chunksize set to %i\n", chunk_size); | |
687 } | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
688 |
6702 | 689 //set period_count |
690 if ((period_val = snd_pcm_hw_params_get_periods_max(alsa_hwparams, 0)) < alsa_fragcount) { | |
691 alsa_fragcount = period_val; | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
692 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
693 |
6702 | 694 if (verbose) |
695 printf("alsa-init: current val=%i, fragcount=%i\n", period_val, alsa_fragcount); | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
696 |
6702 | 697 if ((err = snd_pcm_hw_params_set_periods(alsa_handler, alsa_hwparams, alsa_fragcount, 0)) < 0) { |
698 printf("alsa-init: unable to set periods: %s\n", snd_strerror(err)); | |
699 } | |
700 } | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
701 #endif |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
702 |
6702 | 703 /* finally install hardware parameters */ |
704 if ((err = snd_pcm_hw_params(alsa_handler, alsa_hwparams)) < 0) | |
705 { | |
706 printf("alsa-init: unable to set hw-parameters: %s\n", | |
707 snd_strerror(err)); | |
708 return(0); | |
709 } | |
710 // end setting hw-params | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
711 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
712 |
6702 | 713 // gets buffersize for control |
714 if ((err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams)) < 0) | |
715 { | |
716 printf("alsa-init: unable to get buffersize: %s\n", snd_strerror(err)); | |
717 return(0); | |
718 } | |
719 else { | |
720 ao_data.buffersize = err; | |
721 if (verbose) | |
722 printf("alsa-init: got buffersize=%i\n", ao_data.buffersize); | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
723 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
724 |
6702 | 725 // setting sw-params (only avail-min) if noblocking mode was choosed |
726 if (ao_noblock) | |
727 { | |
1050 | 728 |
6702 | 729 if ((err = snd_pcm_sw_params_current(alsa_handler, alsa_swparams)) < 0) |
730 { | |
731 printf("alsa-init: unable to get parameters: %s\n",snd_strerror(err)); | |
732 return(0); | |
733 } | |
734 | |
735 //set min available frames to consider pcm ready (4) | |
736 //increased for nonblock-mode should be set dynamically later | |
6749 | 737 if ((err = snd_pcm_sw_params_set_avail_min(alsa_handler, alsa_swparams, 4)) < 0) |
6702 | 738 { |
739 printf("alsa-init: unable to set avail_min %s\n",snd_strerror(err)); | |
740 return(0); | |
741 } | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
742 |
6702 | 743 if ((err = snd_pcm_sw_params(alsa_handler, alsa_swparams)) < 0) |
744 { | |
745 printf("alsa-init: unable to install sw-params\n"); | |
746 return(0); | |
747 } | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
748 |
6702 | 749 bits_per_sample = snd_pcm_format_physical_width(alsa_format); |
750 bits_per_frame = bits_per_sample * channels; | |
751 chunk_bytes = chunk_size * bits_per_frame / 8; | |
1050 | 752 |
6702 | 753 if (verbose) { |
754 printf("alsa-init: bits per sample (bps)=%i, bits per frame (bpf)=%i, chunk_bytes=%i\n",bits_per_sample,bits_per_frame,chunk_bytes);} | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
755 |
6702 | 756 }//end swparams |
1050 | 757 |
6702 | 758 if ((err = snd_pcm_prepare(alsa_handler)) < 0) |
759 { | |
760 printf("alsa-init: pcm prepare error: %s\n", snd_strerror(err)); | |
761 return(0); | |
762 } | |
763 | |
764 printf("alsa9: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n", | |
765 ao_data.samplerate, ao_data.channels, ao_data.bps, ao_data.buffersize, | |
766 snd_pcm_format_description(alsa_format)); | |
767 | |
768 } // end switch alsa_handler (spdif) | |
1050 | 769 return(1); |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
770 } // end init |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
771 |
1050 | 772 |
773 /* close audio device */ | |
774 static void uninit() | |
775 { | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
776 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
777 if (alsa_handler) { |
1050 | 778 int err; |
779 | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
780 if (!ao_noblock) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
781 if ((err = snd_pcm_drain(alsa_handler)) < 0) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
782 { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
783 printf("alsa-uninit: pcm drain error: %s\n", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
784 return; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
785 } |
1050 | 786 } |
787 | |
788 if ((err = snd_pcm_close(alsa_handler)) < 0) | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
789 { |
1050 | 790 printf("alsa-uninit: pcm close error: %s\n", snd_strerror(err)); |
791 return; | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
792 } |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
793 else { |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
794 alsa_handler = NULL; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
795 alsa_device = NULL; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
796 printf("alsa-uninit: pcm closed\n"); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
797 } |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
798 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
799 else { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
800 printf("alsa-uninit: no handler defined!\n"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
801 } |
1050 | 802 } |
803 | |
804 static void audio_pause() | |
805 { | |
806 int err; | |
807 | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
808 if (!ao_noblock) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
809 //drain causes error in nonblock-mode! |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
810 if ((err = snd_pcm_drain(alsa_handler)) < 0) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
811 { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
812 printf("alsa-pause: pcm drain error: %s\n", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
813 return; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
814 } |
1050 | 815 } |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
816 else { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
817 if (verbose) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
818 printf("alsa-pause: paused nonblock\n"); |
1050 | 819 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
820 return; |
1050 | 821 } |
822 } | |
823 | |
824 static void audio_resume() | |
825 { | |
826 int err; | |
827 | |
828 if ((err = snd_pcm_prepare(alsa_handler)) < 0) | |
829 { | |
830 printf("alsa-resume: pcm prepare error: %s\n", snd_strerror(err)); | |
831 return; | |
832 } | |
833 } | |
834 | |
835 /* stop playing and empty buffers (for seeking/pause) */ | |
836 static void reset() | |
837 { | |
838 int err; | |
839 | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
840 if (!ao_noblock) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
841 //drain causes error in nonblock-mode! |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
842 if ((err = snd_pcm_drain(alsa_handler)) < 0) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
843 { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
844 printf("alsa-pause: pcm drain error: %s\n", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
845 return; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
846 } |
1050 | 847 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
848 if ((err = snd_pcm_prepare(alsa_handler)) < 0) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
849 { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
850 printf("alsa-reset: pcm prepare error: %s\n", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
851 return; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
852 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
853 } else { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
854 if (verbose) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
855 printf("alsa-reset: reset nonblocked"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
856 return; |
1050 | 857 } |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
858 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
859 |
6749 | 860 #ifdef USE_POLL |
861 static int wait_for_poll(snd_pcm_t *handle, struct pollfd *ufds, unsigned int count) | |
862 { | |
863 unsigned short revents; | |
864 | |
865 while (1) { | |
866 poll(ufds, count, -1); | |
867 snd_pcm_poll_descriptors_revents(handle, ufds, count, &revents); | |
868 if (revents & POLLERR) | |
869 return -EIO; | |
870 if (revents & POLLOUT) | |
871 return 0; | |
872 } | |
873 } | |
874 #endif | |
875 | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
876 #ifndef timersub |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
877 #define timersub(a, b, result) \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
878 do { \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
879 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
880 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
881 if ((result)->tv_usec < 0) { \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
882 --(result)->tv_sec; \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
883 (result)->tv_usec += 1000000; \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
884 } \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
885 } while (0) |
1129 | 886 #endif |
1050 | 887 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
888 /* I/O error handler */ |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
889 static int xrun(u_char *str_mode) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
890 { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
891 int err; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
892 snd_pcm_status_t *status; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
893 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
894 snd_pcm_status_alloca(&status); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
895 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
896 if ((err = snd_pcm_status(alsa_handler, status))<0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
897 printf("status error: %s", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
898 return(0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
899 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
900 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
901 if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
902 struct timeval now, diff, tstamp; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
903 gettimeofday(&now, 0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
904 snd_pcm_status_get_trigger_tstamp(status, &tstamp); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
905 timersub(&now, &tstamp, &diff); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
906 printf("alsa-%s: xrun of at least %.3f msecs. resetting stream\n", |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
907 str_mode, |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
908 diff.tv_sec * 1000 + diff.tv_usec / 1000.0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
909 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
910 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
911 if ((err = snd_pcm_prepare(alsa_handler))<0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
912 printf("xrun: prepare error: %s", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
913 return(0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
914 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
915 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
916 return(1); /* ok, data should be accepted again */ |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
917 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
918 |
6749 | 919 static int play(void* data, int len, int flags) |
920 { | |
921 int result; | |
922 if (ao_mmap) | |
923 result = play_mmap(data, len); | |
924 else | |
925 result = play_normal(data, len); | |
926 | |
927 return result; | |
928 } | |
929 | |
1050 | 930 /* |
931 plays 'len' bytes of 'data' | |
932 returns: number of bytes played | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
933 modified last at 29.06.02 by jp |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
934 thanxs for marius <marius@rospot.com> for giving us the light ;) |
1050 | 935 */ |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
936 |
6749 | 937 static int play_normal(void* data, int len) |
1050 | 938 { |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
939 |
6749 | 940 //ao_data.bps is always 4 for 2 chn S16_LE |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
941 int num_frames = len / ao_data.bps; |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
942 signed short *output_samples=data; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
943 snd_pcm_sframes_t res = 0; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
944 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
945 //printf("alsa-play: frames=%i, len=%i",num_frames,len); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
946 |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
947 if (!alsa_handler) { |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
948 printf("alsa-play: device configuration error"); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
949 return 0; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
950 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
951 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
952 while (num_frames > 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
953 |
6749 | 954 res = snd_pcm_writei(alsa_handler, (void *)output_samples, num_frames); |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
955 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
956 if (res == -EAGAIN) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
957 snd_pcm_wait(alsa_handler, 1000); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
958 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
959 else if (res == -EPIPE) { /* underrun */ |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
960 if (xrun("play") <= 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
961 printf("alsa-play: xrun reset error"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
962 return(0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
963 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
964 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
965 else if (res == -ESTRPIPE) { /* suspend */ |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
966 printf("alsa-play: pcm in suspend mode. trying to resume\n"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
967 while ((res = snd_pcm_resume(alsa_handler)) == -EAGAIN) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
968 sleep(1); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
969 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
970 else if (res < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
971 printf("alsa-play: unknown status, trying to reset soundcard\n"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
972 if ((res = snd_pcm_prepare(alsa_handler)) < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
973 printf("alsa-play: snd prepare error"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
974 return(0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
975 break; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
976 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
977 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
978 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
979 if (res > 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
980 output_samples += ao_data.channels * res; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
981 num_frames -= res; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
982 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
983 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
984 } //end while |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
985 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
986 if (res < 0) { |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
987 printf("alsa-play: write error %s", snd_strerror(res)); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
988 return 0; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
989 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
990 return res < 0 ? (int)res : len; |
1050 | 991 } |
992 | |
6749 | 993 /* mmap-mode mainly based on descriptions by Joshua Haberman <joshua@haberman.com> |
994 * 'An overview of the ALSA API' http://people.debian.org/~joshua/x66.html | |
995 * and some help by Paul Davis <pbd@op.net> */ | |
996 | |
997 static int play_mmap(void* data, int len) | |
998 { | |
999 snd_pcm_sframes_t commitres, frames_available; | |
1000 snd_pcm_uframes_t frames_transmit, size, offset; | |
1001 const snd_pcm_channel_area_t *area; | |
1002 void *outbuffer; | |
1003 int err, result; | |
1004 | |
1005 #ifdef USE_POLL //seems not really be needed | |
1006 struct pollfd *ufds; | |
1007 int count; | |
1008 | |
1009 count = snd_pcm_poll_descriptors_count (alsa_handler); | |
1010 ufds = malloc(sizeof(struct pollfd) * count); | |
1011 snd_pcm_poll_descriptors(alsa_handler, ufds, count); | |
1012 | |
1013 //first wait_for_poll | |
1014 if (err = (wait_for_poll(alsa_handler, ufds, count) < 0)) { | |
1015 if (snd_pcm_state(alsa_handler) == SND_PCM_STATE_XRUN || | |
1016 snd_pcm_state(alsa_handler) == SND_PCM_STATE_SUSPENDED) { | |
1017 xrun("play"); | |
1018 } | |
1019 } | |
1020 #endif | |
1021 | |
1022 outbuffer = alloca(ao_data.buffersize); | |
1023 | |
1024 //don't trust get_space() ;) | |
1025 frames_available = snd_pcm_avail_update(alsa_handler) * ao_data.bps; | |
1026 if (frames_available < 0) | |
1027 xrun("play"); | |
1028 | |
1029 if (frames_available < 4) { | |
1030 if (first) { | |
1031 first = 0; | |
1032 snd_pcm_start(alsa_handler); | |
1033 } | |
1034 else { //FIXME should break and return 0? | |
1035 snd_pcm_wait(alsa_handler, -1); | |
1036 first = 1; | |
1037 } | |
1038 } | |
1039 | |
1040 /* len is simply the available bufferspace got by get_space() | |
1041 * but real avail_buffer in frames is ab/ao_data.bps */ | |
1042 size = len / ao_data.bps; | |
1043 | |
1044 //if (verbose) | |
1045 //printf("len: %i size %i, f_avail %i, bps %i ...\n", len, size, frames_available, ao_data.bps); | |
1046 | |
1047 frames_transmit = size; | |
1048 | |
1049 /* prepare areas and set sw-pointers | |
1050 * frames_transmit returns the real available buffer-size | |
1051 * sometimes != frames_available cause of ringbuffer 'emulation' */ | |
1052 snd_pcm_mmap_begin(alsa_handler, &area, &offset, &frames_transmit); | |
1053 | |
1054 /* this is specific to interleaved streams (or non-interleaved | |
1055 * streams with only one channel) */ | |
1056 outbuffer = ((char *) area->addr + (area->first + area->step * offset) / 8); //8 | |
1057 | |
1058 //write data | |
1059 memcpy(outbuffer, data, (frames_transmit * ao_data.bps)); | |
1060 | |
1061 commitres = snd_pcm_mmap_commit(alsa_handler, offset, frames_transmit); | |
1062 | |
1063 if (commitres < 0 || commitres != frames_transmit) { | |
1064 if (snd_pcm_state(alsa_handler) == SND_PCM_STATE_XRUN || | |
1065 snd_pcm_state(alsa_handler) == SND_PCM_STATE_SUSPENDED) { | |
1066 xrun("play"); | |
1067 } | |
1068 } | |
1069 | |
1070 //if (verbose) | |
1071 //printf("mmap ft: %i, cres: %i\n", frames_transmit, commitres); | |
1072 | |
1073 /* err = snd_pcm_area_copy(&area, offset, &data, offset, len, alsa_format); */ | |
1074 /* if (err < 0) { */ | |
1075 /* printf("area-copy-error\n"); */ | |
1076 /* return 0; */ | |
1077 /* } */ | |
1078 | |
1079 | |
1080 //calculate written frames! | |
1081 result = commitres * ao_data.bps; | |
1082 | |
1083 | |
1084 /* if (verbose) { */ | |
1085 /* if (len == result) */ | |
1086 /* printf("result: %i, frames written: %i ...\n", result, frames_transmit); */ | |
1087 /* else */ | |
1088 /* printf("result: %i, frames written: %i, result != len ...\n", result, frames_transmit); */ | |
1089 /* } */ | |
1090 | |
1091 //mplayer doesn't like -result | |
1092 if (result < 0) | |
1093 result = 0; | |
1094 | |
1095 #ifdef USE_POLL | |
1096 free(ufds); | |
1097 #endif | |
1098 | |
1099 return result; | |
1100 } | |
1101 | |
1050 | 1102 /* how many byes are free in the buffer */ |
1103 static int get_space() | |
1104 { | |
1105 snd_pcm_status_t *status; | |
1106 int ret; | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1107 char *str_status; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1108 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1109 //snd_pcm_sframes_t avail_frames = 0; |
1050 | 1110 |
1111 if ((ret = snd_pcm_status_malloc(&status)) < 0) | |
1112 { | |
1113 printf("alsa-space: memory allocation error: %s\n", snd_strerror(ret)); | |
1114 return(0); | |
1115 } | |
1116 | |
1117 if ((ret = snd_pcm_status(alsa_handler, status)) < 0) | |
1118 { | |
1119 printf("alsa-space: cannot get pcm status: %s\n", snd_strerror(ret)); | |
1120 return(0); | |
1121 } | |
1122 | |
1123 switch(snd_pcm_status_get_state(status)) | |
1124 { | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1125 case SND_PCM_STATE_OPEN: |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1126 str_status = "open"; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1127 case SND_PCM_STATE_PREPARED: |
6749 | 1128 if (str_status != "open") { |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1129 str_status = "prepared"; |
6749 | 1130 first = 1; |
1131 ret = snd_pcm_status_get_avail(status) * ao_data.bps; | |
1132 if (ret == 0) //ugly workaround for hang in mmap-mode | |
1133 ret = 10; | |
1134 break; | |
1135 } | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1136 case SND_PCM_STATE_RUNNING: |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1137 ret = snd_pcm_status_get_avail(status) * ao_data.bps; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1138 //avail_frames = snd_pcm_avail_update(alsa_handler) * ao_data.bps; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1139 if (str_status != "open" && str_status != "prepared") |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1140 str_status = "running"; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1141 break; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1142 case SND_PCM_STATE_PAUSED: |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1143 if (verbose) printf("alsa-space: paused"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1144 str_status = "paused"; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1145 ret = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1146 break; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1147 case SND_PCM_STATE_XRUN: |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1148 xrun("space"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1149 str_status = "xrun"; |
6749 | 1150 first = 1; |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1151 ret = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1152 break; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1153 default: |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1154 str_status = "undefined"; |
6749 | 1155 ret = snd_pcm_status_get_avail(status) * ao_data.bps; |
1156 if (ret <= 0) { | |
1157 xrun("space"); | |
1158 } | |
1050 | 1159 } |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1160 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1161 if (verbose && str_status != "running") |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1162 printf("alsa-space: free space = %i, status=%i, %s --\n", ret, status, str_status); |
1050 | 1163 snd_pcm_status_free(status); |
1129 | 1164 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1165 if (ret < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1166 printf("negative value!!\n"); |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
1167 ret = 0; |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1168 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1169 |
1050 | 1170 return(ret); |
1171 } | |
1172 | |
3095 | 1173 /* delay in seconds between first and last sample in buffer */ |
1174 static float get_delay() | |
1050 | 1175 { |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1176 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1177 if (alsa_handler) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1178 |
1050 | 1179 snd_pcm_status_t *status; |
3095 | 1180 float ret; |
1050 | 1181 |
1182 if ((ret = snd_pcm_status_malloc(&status)) < 0) | |
1183 { | |
1184 printf("alsa-delay: memory allocation error: %s\n", snd_strerror(ret)); | |
1185 return(0); | |
1186 } | |
1187 | |
1188 if ((ret = snd_pcm_status(alsa_handler, status)) < 0) | |
1189 { | |
1190 printf("alsa-delay: cannot get pcm status: %s\n", snd_strerror(ret)); | |
1191 return(0); | |
1192 } | |
1193 | |
1194 switch(snd_pcm_status_get_state(status)) | |
1195 { | |
1196 case SND_PCM_STATE_OPEN: | |
1197 case SND_PCM_STATE_PREPARED: | |
1198 case SND_PCM_STATE_RUNNING: | |
3095 | 1199 ret = (float)snd_pcm_status_get_delay(status)/(float)ao_data.samplerate; |
1050 | 1200 break; |
1201 default: | |
1202 ret = 0; | |
1203 } | |
1204 | |
1205 snd_pcm_status_free(status); | |
1129 | 1206 |
1207 if (ret < 0) | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
1208 ret = 0; |
1050 | 1209 return(ret); |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1210 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1211 } else { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1212 return(0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1213 } |
1050 | 1214 } |