Changeset 5174:c24a2089056a in roaraudio for plugins/alsavs/pcm_roar.c
- Timestamp:
- 10/22/11 12:11:33 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/alsavs/pcm_roar.c
r5168 r5174 46 46 struct roar_alsa_pcm * self = io->private_data; 47 47 int fh; 48 int val; 49 int err; 48 50 49 51 ROAR_DBG("roar_pcm_start(*) = ?"); … … 53 55 return 0; 54 56 55 if ( roar_vio_simple_new_stream_obj(&(self->stream_vio), &(self->roar.con), &(self->stream), 56 self->info.rate, self->info.channels, self->info.bits, self->info.codec, 57 io->stream == SND_PCM_STREAM_PLAYBACK ? ROAR_DIR_PLAY : ROAR_DIR_MONITOR 58 ) == -1 ) { 59 return -EINVAL; 57 if ( (self->vss = roar_vs_new_from_con(&(self->roar.con), &err)) == NULL ) { 58 roar_err_set(err); 59 roar_err_update(); 60 return -errno; 61 } 62 63 if ( roar_vs_stream(self->vss, &(self->info), 64 io->stream == SND_PCM_STREAM_PLAYBACK ? ROAR_DIR_PLAY : ROAR_DIR_MONITOR, 65 &err) == -1 ) { 66 roar_vs_close(self->vss, ROAR_VS_TRUE, NULL); 67 self->vss = NULL; 68 roar_err_set(err); 69 roar_err_update(); 70 return -errno; 71 } 72 73 if ( roar_vs_buffer(self->vss, self->bufsize, &err) == -1 ) { 74 roar_vs_close(self->vss, ROAR_VS_TRUE, NULL); 75 self->vss = NULL; 76 roar_err_set(err); 77 roar_err_update(); 78 return -errno; 79 } 80 81 val = ROAR_VS_ASYNCLEVEL_AUTO; 82 if ( roar_vs_ctl(self->vss, ROAR_VS_CMD_SET_ASYNC, &val, &err) == -1 ) { 83 roar_vs_close(self->vss, ROAR_VS_TRUE, NULL); 84 self->vss = NULL; 85 roar_err_set(err); 86 roar_err_update(); 87 return -errno; 60 88 } 61 89 62 90 if ( self->stream_role != ROAR_ROLE_UNKNOWN ) { 63 if ( roar_stream_set_role(&(self->roar.con), &(self->stream), self->stream_role) == -1 ) { 64 ROAR_WARN("roar_pcm_start(*): Can not set stream role: %i: %s", self->stream_role, roar_error2str(roar_error)); 91 if ( roar_vs_role(self->vss, self->stream_role, &err) == -1 ) { 92 ROAR_WARN("roar_pcm_start(*): Can not set stream role: %s(%i): %s", 93 roar_role2str(self->stream_role), self->stream_role, roar_error2str(roar_error)); 65 94 } 66 95 } 67 96 68 if ( roar_vio_ctl( &(self->stream_vio),97 if ( roar_vio_ctl(roar_vs_vio_obj(self->vss, NULL), 69 98 io->stream == SND_PCM_STREAM_PLAYBACK ? ROAR_VIO_CTL_GET_SELECT_WRITE_FH : 70 99 ROAR_VIO_CTL_GET_SELECT_READ_FH, &fh) != 1 ) { … … 81 110 self->stream_opened = 1; 82 111 83 self->bufptr = 0; 112 //RM: self->bufptr = 0; 113 ROAR_DBG("roar_pcm_start(*): Starting background thread"); 84 114 self->thread_active = 1; // We have to activate the thread before starting it, because the thread lives on that thread_active is 1. 85 115 if ( pthread_create(&(self->thread), NULL, roar_plugin_thread, self) < 0 ) { 86 116 self->thread_active = 0; 117 ROAR_DBG("roar_pcm_start(*) = -1"); 87 118 return -1; 88 119 } 89 120 pthread_mutex_lock(&(self->lock)); // wait for the background thread to wake up. 121 ROAR_DBG("roar_pcm_start(*): background thread was successfully started"); 122 123 ROAR_DBG("roar_pcm_start(*) = 0"); 90 124 return 0; 91 125 } … … 95 129 return; 96 130 97 roar_vio_close(&(self->stream_vio)); 131 roar_vs_close(self->vss, ROAR_VS_TRUE, NULL); 132 self->vss = NULL; 98 133 self->stream_opened = 0; 99 134 self->thread_active = 0; 100 self->bufptr = 0;101 self->last_ptr = 0;102 self->total_written = 0;103 self->has_written = 0;135 //RM: self->bufptr = 0; 136 //RM: self->last_ptr = 0; 137 //RM: self->total_written = 0; 138 //RM: self->has_written = 0; 104 139 } 105 140 … … 198 233 struct roar_alsa_pcm * self = io->private_data; 199 234 int ptr; 235 ssize_t avail; 200 236 201 237 ROAR_DBG("roar_pcm_pointer(*) = ?"); 238 202 239 // Did ALSA just call snd_pcm_reset() or something like that without calling the plugin? 203 240 // We should restart our stream as well. … … 207 244 } 208 245 246 #if 0 209 247 // ALSA has a weird way of calculating how much data can be written to the audio buffer. 210 248 // It uses the formula: … … 218 256 ptr = snd_pcm_bytes_to_frames(io->pcm, self->bufptr); 219 257 pthread_mutex_unlock(&(self->lock)); 258 #else 259 pthread_mutex_lock(&(self->lock)); 260 avail = roar_vs_get_avail_write(self->vss, NULL); 261 pthread_mutex_unlock(&(self->lock)); 262 263 ROAR_DBG("roar_pcm_pointer(*): avail=%lli", (long long int)avail); 264 265 ptr = snd_pcm_bytes_to_frames(io->pcm, self->bufsize - avail); 266 #endif 220 267 221 268 ptr = io->appl_ptr - ptr; … … 261 308 static int roar_pcm_delay(snd_pcm_ioplug_t *io, snd_pcm_sframes_t *delayp) { 262 309 struct roar_alsa_pcm * self = io->private_data; 310 roar_mus_t lat; 263 311 264 312 ROAR_DBG("roar_pcm_delay(*) = ?"); … … 266 314 // TODO: We need to set *delayp the latency in frames. 267 315 pthread_mutex_lock(&(self->lock)); 268 roar_plugin_drain(self); 269 *delayp = snd_pcm_bytes_to_frames(io->pcm, self->bytes_in_buffer); 316 roar_plugin_drain(self); // why do we call this? 317 318 lat = roar_vs_latency2(self->vss, ROAR_VS_BACKEND_DEFAULT, ROAR_VS_NOWAIT, NULL); 319 *delayp = lat * self->info.rate; 320 270 321 pthread_mutex_unlock(&(self->lock)); 271 322 … … 373 424 //self->bufsize = snd_pcm_frames_to_bytes(io->pcm, buffersize); 374 425 self->bufsize = self->info.bits * self->info.channels * buffersize / 8; 375 self->buffer = malloc(self->bufsize);376 if (self->buffer == NULL)377 return -1;378 self->bufptr = 0;426 //RM: self->buffer = malloc(self->bufsize); 427 //RM: if (self->buffer == NULL) 428 //RM: return -1; 429 //RM: self->bufptr = 0; 379 430 380 431 ROAR_DBG("roar_pcm_hw_params(*) Setting buffersize (bytes): %i", (int)self->bufsize); … … 398 449 pthread_cond_destroy(&(self->cond)); 399 450 400 free(self->buffer);451 //RM: free(self->buffer); 401 452 free(self); 402 453
Note: See TracChangeset
for help on using the changeset viewer.