Changeset 3430:4e9790a5a08a in roaraudio for libroarpulse


Ignore:
Timestamp:
02/12/10 14:41:43 (10 years ago)
Author:
phi
Branch:
default
Message:

implemented pa_stream_readable_size() and pa_stream_writable_size()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroarpulse/stream.c

    r3429 r3430  
    5555 pa_stream_state_t state; 
    5656 pa_sample_spec    sspec; 
     57 struct roar_buffer * iobuffer; 
     58 struct { 
     59  size_t size; 
     60  size_t num; 
     61 } fragments; 
    5762 struct { 
    5863  struct _roar_pa_stream_cb change_state; 
     
    106111  return NULL; 
    107112 } 
     113 
     114 s->fragments.num  = 4; 
     115 s->fragments.size = 2048; 
    108116 
    109117 s->state = PA_STREAM_UNCONNECTED; 
     
    223231 
    224232/** Return the nember of bytes that may be written using pa_stream_write() */ 
    225 size_t pa_stream_writable_size(pa_stream *p); 
     233size_t pa_stream_writable_size(pa_stream *p) { 
     234 struct roar_buffer_stats stats; 
     235 
     236 if ( p == NULL ) 
     237  return 0; 
     238 
     239 if ( p->iobuffer == NULL ) 
     240  return 0; 
     241 
     242 if ( roar_buffer_ring_stats(p->iobuffer, &stats) == -1 ) 
     243  return 0; 
     244 
     245 if ( stats.parts > p->fragments.num ) 
     246  return 0; 
     247 
     248 return (p->fragments.num - stats.parts)*p->fragments.size; 
     249} 
    226250 
    227251/** Return the number of bytes that may be read using pa_stream_read() \since 0.8 */ 
    228 size_t pa_stream_readable_size(pa_stream *p); 
     252size_t pa_stream_readable_size(pa_stream *p) { 
     253 struct roar_buffer_stats stats; 
     254 
     255 if ( p == NULL ) 
     256  return 0; 
     257 
     258 if ( p->iobuffer == NULL ) 
     259  return 0; 
     260 
     261 if ( roar_buffer_ring_stats(p->iobuffer, &stats) == -1 ) 
     262  return 0; 
     263 
     264 return stats.bytes; 
     265} 
    229266 
    230267/** Drain a playback stream. Use this for notification when the buffer is empty */ 
Note: See TracChangeset for help on using the changeset viewer.