Changeset 3425:a23992f03d97 in roaraudio for libroarpulse


Ignore:
Timestamp:
02/11/10 23:03:37 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

wrote some stream support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroarpulse/stream.c

    r3424 r3425  
    3939#include <libroarpulse/libroarpulse.h> 
    4040 
     41struct pa_stream { 
     42 size_t refc; 
     43 pa_context * c; 
     44 struct roar_vio_calls vio; 
     45 struct roar_stream stream; 
     46 pa_stream_state_t state; 
     47 struct { 
     48  pa_stream_notify_cb_t   change_state; 
     49  void                  * change_state_ud; 
     50 } cb; 
     51}; 
     52 
     53typedef void pa_proplist; 
     54void pa_stream_set_state(pa_stream *s, pa_stream_state_t st); 
     55 
     56pa_stream* pa_stream_new_with_proplist( 
     57        pa_context *c                     , 
     58        const char *name                  , 
     59        const pa_sample_spec *ss          , 
     60        const pa_channel_map *map         , 
     61        pa_proplist *p                    ); 
     62 
    4163/** Create a new, unconnected stream with the specified name and sample type */ 
    4264pa_stream* pa_stream_new( 
     
    4466        const char *name                  /**< A name for this stream */, 
    4567        const pa_sample_spec *ss          /**< The desired sample format */, 
    46         const pa_channel_map *map         /**< The desired channel map, or NULL for default */); 
     68        const pa_channel_map *map         /**< The desired channel map, or NULL for default */) { 
     69 return pa_stream_new_with_proplist(c, name, ss, map, NULL); 
     70} 
     71 
     72pa_stream* pa_stream_new_with_proplist( 
     73        pa_context *c                     , 
     74        const char *name                  , 
     75        const pa_sample_spec *ss          , 
     76        const pa_channel_map *map         , 
     77        pa_proplist *p                    ) { 
     78 pa_stream * s; 
     79 
     80 if ( p != NULL ) 
     81  return NULL; 
     82 
     83 if ( (s = roar_mm_malloc(sizeof(pa_stream))) == NULL ) 
     84  return NULL; 
     85 
     86 memset(s, 0, sizeof(pa_stream)); 
     87 
     88 if ( roar_pa_sspec2auinfo(&(s->stream.info), ss) == -1 ) { 
     89  roar_mm_free(s); 
     90  return NULL; 
     91 } 
     92 
     93 s->state = PA_STREAM_UNCONNECTED; 
     94 s->c     = c; 
     95 pa_context_ref(c); 
     96 
     97 return s; 
     98} 
     99 
     100static void _pa_stream_free(pa_stream * s) { 
     101 pa_stream_disconnect(s); 
     102 pa_context_unref(s->c); 
     103 roar_mm_free(s); 
     104} 
    47105 
    48106/** Decrease the reference counter by one */ 
    49 void pa_stream_unref(pa_stream *s); 
     107void pa_stream_unref(pa_stream *s) { 
     108 if ( s == NULL ) 
     109  return; 
     110 
     111 s->refc--; 
     112 
     113 if (s->refc < 1 ) 
     114  _pa_stream_free(s); 
     115} 
    50116 
    51117/** Increase the reference counter by one */ 
    52 pa_stream *pa_stream_ref(pa_stream *s); 
     118pa_stream *pa_stream_ref(pa_stream *s) { 
     119 if ( s == NULL ) 
     120  return NULL; 
     121 
     122 s->refc++; 
     123 
     124 return s; 
     125} 
    53126 
    54127/** Return the current state of the stream */ 
    55 pa_stream_state_t pa_stream_get_state(pa_stream *p); 
     128pa_stream_state_t pa_stream_get_state(pa_stream *p) { 
     129 if ( p == NULL ) 
     130  return PA_STREAM_FAILED; 
     131 
     132 return p->state; 
     133} 
    56134 
    57135/** Return the context this stream is attached to */ 
    58 pa_context* pa_stream_get_context(pa_stream *p); 
     136pa_context* pa_stream_get_context(pa_stream *p) { 
     137 if ( p == NULL ) 
     138  return NULL; 
     139 
     140 return p->c; 
     141} 
    59142 
    60143/** Return the device (sink input or source output) index this stream is connected to */ 
     
    78161 
    79162/** Disconnect a stream from a source/sink */ 
    80 int pa_stream_disconnect(pa_stream *s); 
     163int pa_stream_disconnect(pa_stream *s) { 
     164 if ( s == NULL ) 
     165  return -1; 
     166 
     167 if ( s->state != PA_STREAM_READY ) 
     168  return -1; 
     169 
     170 roar_vio_close(&(s->vio)); 
     171 
     172 pa_stream_set_state(s, PA_STREAM_TERMINATED); 
     173 
     174 return 0; 
     175} 
    81176 
    82177/** Write some data to the server (for playback sinks), if free_cb is 
     
    125220 
    126221/** Set the callback function that is called whenever the state of the stream changes */ 
    127 void pa_stream_set_state_callback(pa_stream *s, pa_stream_notify_cb_t cb, void *userdata); 
     222void pa_stream_set_state_callback(pa_stream *s, pa_stream_notify_cb_t cb, void *userdata) { 
     223 if ( s == NULL ) 
     224  return; 
     225 
     226 s->cb.change_state    = cb; 
     227 s->cb.change_state_ud = userdata; 
     228} 
     229 
     230void pa_stream_set_state(pa_stream *s, pa_stream_state_t st) { 
     231 if ( s == NULL ) 
     232  return; 
     233 
     234 s->state = st; 
     235 
     236 if ( s->cb.change_state == NULL ) { 
     237  s->cb.change_state(s, s->cb.change_state_ud); 
     238 } 
     239} 
    128240 
    129241/** Set the callback function that is called when new data may be 
Note: See TracChangeset for help on using the changeset viewer.