Changeset 5174:c24a2089056a in roaraudio for plugins/alsavs/pcm_roar.c


Ignore:
Timestamp:
10/22/11 12:11:33 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added some experimental fork of the old alsa plugin using VS API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/alsavs/pcm_roar.c

    r5168 r5174  
    4646 struct roar_alsa_pcm * self = io->private_data; 
    4747 int fh; 
     48 int val; 
     49 int err; 
    4850 
    4951 ROAR_DBG("roar_pcm_start(*) = ?"); 
     
    5355  return 0; 
    5456 
    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; 
    6088 } 
    6189 
    6290 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)); 
    6594  } 
    6695 } 
    6796 
    68  if ( roar_vio_ctl(&(self->stream_vio),  
     97 if ( roar_vio_ctl(roar_vs_vio_obj(self->vss, NULL),  
    6998    io->stream == SND_PCM_STREAM_PLAYBACK ? ROAR_VIO_CTL_GET_SELECT_WRITE_FH : 
    7099    ROAR_VIO_CTL_GET_SELECT_READ_FH, &fh) != 1 ) { 
     
    81110 self->stream_opened = 1; 
    82111 
    83  self->bufptr = 0; 
     112//RM: self->bufptr = 0; 
     113 ROAR_DBG("roar_pcm_start(*): Starting background thread"); 
    84114 self->thread_active = 1; // We have to activate the thread before starting it, because the thread lives on that thread_active is 1. 
    85115 if ( pthread_create(&(self->thread), NULL, roar_plugin_thread, self) < 0 ) { 
    86116  self->thread_active = 0; 
     117  ROAR_DBG("roar_pcm_start(*) = -1"); 
    87118  return -1; 
    88119 } 
    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"); 
    90124 return 0; 
    91125} 
     
    95129  return; 
    96130 
    97  roar_vio_close(&(self->stream_vio)); 
     131 roar_vs_close(self->vss, ROAR_VS_TRUE, NULL); 
     132 self->vss = NULL; 
    98133 self->stream_opened = 0; 
    99134 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; 
    104139} 
    105140 
     
    198233 struct roar_alsa_pcm * self = io->private_data; 
    199234 int ptr; 
     235 ssize_t avail; 
    200236 
    201237 ROAR_DBG("roar_pcm_pointer(*) = ?"); 
     238 
    202239 // Did ALSA just call snd_pcm_reset() or something like that without calling the plugin?  
    203240 // We should restart our stream as well. 
     
    207244 } 
    208245 
     246#if 0 
    209247 // ALSA has a weird way of calculating how much data can be written to the audio buffer. 
    210248 // It uses the formula: 
     
    218256 ptr = snd_pcm_bytes_to_frames(io->pcm, self->bufptr); 
    219257 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 
    220267 
    221268 ptr = io->appl_ptr - ptr; 
     
    261308static int roar_pcm_delay(snd_pcm_ioplug_t *io, snd_pcm_sframes_t *delayp) { 
    262309 struct roar_alsa_pcm * self = io->private_data; 
     310 roar_mus_t lat; 
    263311 
    264312 ROAR_DBG("roar_pcm_delay(*) = ?"); 
     
    266314 // TODO: We need to set *delayp the latency in frames. 
    267315 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 
    270321 pthread_mutex_unlock(&(self->lock)); 
    271322 
     
    373424 //self->bufsize = snd_pcm_frames_to_bytes(io->pcm, buffersize); 
    374425 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; 
    379430 
    380431 ROAR_DBG("roar_pcm_hw_params(*) Setting buffersize (bytes): %i", (int)self->bufsize); 
     
    398449 pthread_cond_destroy(&(self->cond)); 
    399450 
    400  free(self->buffer); 
     451//RM: free(self->buffer); 
    401452 free(self); 
    402453 
Note: See TracChangeset for help on using the changeset viewer.