comparison libmpdemux/audio_in.c @ 11775:66e491c35dc8

ALSA 1.x audio out driver
author henry
date Sun, 11 Jan 2004 17:07:32 +0000
parents 31f12f99118b
children dfbe8cd0e081
comparison
equal deleted inserted replaced
11774:28b52087c48d 11775:66e491c35dc8
22 ai->blocksize = -1; 22 ai->blocksize = -1;
23 ai->bytes_per_sample = -1; 23 ai->bytes_per_sample = -1;
24 ai->samplesize = -1; 24 ai->samplesize = -1;
25 25
26 switch (ai->type) { 26 switch (ai->type) {
27 #ifdef HAVE_ALSA9 27 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
28 case AUDIO_IN_ALSA: 28 case AUDIO_IN_ALSA:
29 ai->alsa.handle = NULL; 29 ai->alsa.handle = NULL;
30 ai->alsa.log = NULL; 30 ai->alsa.log = NULL;
31 ai->alsa.device = strdup("default"); 31 ai->alsa.device = strdup("default");
32 return 0; 32 return 0;
44 44
45 int audio_in_setup(audio_in_t *ai) 45 int audio_in_setup(audio_in_t *ai)
46 { 46 {
47 47
48 switch (ai->type) { 48 switch (ai->type) {
49 #ifdef HAVE_ALSA9 49 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
50 case AUDIO_IN_ALSA: 50 case AUDIO_IN_ALSA:
51 if (ai_alsa_init(ai) < 0) return -1; 51 if (ai_alsa_init(ai) < 0) return -1;
52 ai->setup = 1; 52 ai->setup = 1;
53 return 0; 53 return 0;
54 #endif 54 #endif
64 } 64 }
65 65
66 int audio_in_set_samplerate(audio_in_t *ai, int rate) 66 int audio_in_set_samplerate(audio_in_t *ai, int rate)
67 { 67 {
68 switch (ai->type) { 68 switch (ai->type) {
69 #ifdef HAVE_ALSA9 69 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
70 case AUDIO_IN_ALSA: 70 case AUDIO_IN_ALSA:
71 ai->req_samplerate = rate; 71 ai->req_samplerate = rate;
72 if (!ai->setup) return 0; 72 if (!ai->setup) return 0;
73 if (ai_alsa_setup(ai) < 0) return -1; 73 if (ai_alsa_setup(ai) < 0) return -1;
74 return ai->samplerate; 74 return ai->samplerate;
86 } 86 }
87 87
88 int audio_in_set_channels(audio_in_t *ai, int channels) 88 int audio_in_set_channels(audio_in_t *ai, int channels)
89 { 89 {
90 switch (ai->type) { 90 switch (ai->type) {
91 #ifdef HAVE_ALSA9 91 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
92 case AUDIO_IN_ALSA: 92 case AUDIO_IN_ALSA:
93 ai->req_channels = channels; 93 ai->req_channels = channels;
94 if (!ai->setup) return 0; 94 if (!ai->setup) return 0;
95 if (ai_alsa_setup(ai) < 0) return -1; 95 if (ai_alsa_setup(ai) < 0) return -1;
96 return ai->channels; 96 return ai->channels;
107 } 107 }
108 } 108 }
109 109
110 int audio_in_set_device(audio_in_t *ai, char *device) 110 int audio_in_set_device(audio_in_t *ai, char *device)
111 { 111 {
112 #ifdef HAVE_ALSA9 112 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
113 int i; 113 int i;
114 #endif 114 #endif
115 if (ai->setup) return -1; 115 if (ai->setup) return -1;
116 switch (ai->type) { 116 switch (ai->type) {
117 #ifdef HAVE_ALSA9 117 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
118 case AUDIO_IN_ALSA: 118 case AUDIO_IN_ALSA:
119 if (ai->alsa.device) free(ai->alsa.device); 119 if (ai->alsa.device) free(ai->alsa.device);
120 ai->alsa.device = strdup(device); 120 ai->alsa.device = strdup(device);
121 /* mplayer cannot handle colons in arguments */ 121 /* mplayer cannot handle colons in arguments */
122 for (i = 0; i < (int)strlen(ai->alsa.device); i++) { 122 for (i = 0; i < (int)strlen(ai->alsa.device); i++) {
137 137
138 int audio_in_uninit(audio_in_t *ai) 138 int audio_in_uninit(audio_in_t *ai)
139 { 139 {
140 if (ai->setup) { 140 if (ai->setup) {
141 switch (ai->type) { 141 switch (ai->type) {
142 #ifdef HAVE_ALSA9 142 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
143 case AUDIO_IN_ALSA: 143 case AUDIO_IN_ALSA:
144 if (ai->alsa.log) 144 if (ai->alsa.log)
145 snd_output_close(ai->alsa.log); 145 snd_output_close(ai->alsa.log);
146 if (ai->alsa.handle) { 146 if (ai->alsa.handle) {
147 snd_pcm_close(ai->alsa.handle); 147 snd_pcm_close(ai->alsa.handle);
161 } 161 }
162 162
163 int audio_in_start_capture(audio_in_t *ai) 163 int audio_in_start_capture(audio_in_t *ai)
164 { 164 {
165 switch (ai->type) { 165 switch (ai->type) {
166 #ifdef HAVE_ALSA9 166 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
167 case AUDIO_IN_ALSA: 167 case AUDIO_IN_ALSA:
168 return snd_pcm_start(ai->alsa.handle); 168 return snd_pcm_start(ai->alsa.handle);
169 #endif 169 #endif
170 #ifdef USE_OSS_AUDIO 170 #ifdef USE_OSS_AUDIO
171 case AUDIO_IN_OSS: 171 case AUDIO_IN_OSS:
179 int audio_in_read_chunk(audio_in_t *ai, unsigned char *buffer) 179 int audio_in_read_chunk(audio_in_t *ai, unsigned char *buffer)
180 { 180 {
181 int ret; 181 int ret;
182 182
183 switch (ai->type) { 183 switch (ai->type) {
184 #ifdef HAVE_ALSA9 184 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
185 case AUDIO_IN_ALSA: 185 case AUDIO_IN_ALSA:
186 ret = snd_pcm_readi(ai->alsa.handle, buffer, ai->alsa.chunk_size); 186 ret = snd_pcm_readi(ai->alsa.handle, buffer, ai->alsa.chunk_size);
187 if (ret != ai->alsa.chunk_size) { 187 if (ret != ai->alsa.chunk_size) {
188 if (ret < 0) { 188 if (ret < 0) {
189 mp_msg(MSGT_TV, MSGL_ERR, "\nerror reading audio: %s\n", snd_strerror(ret)); 189 mp_msg(MSGT_TV, MSGL_ERR, "\nerror reading audio: %s\n", snd_strerror(ret));