Changeset 3425:a23992f03d97 in roaraudio for libroarpulse/stream.c
- Timestamp:
- 02/11/10 23:03:37 (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroarpulse/stream.c
r3424 r3425 39 39 #include <libroarpulse/libroarpulse.h> 40 40 41 struct 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 53 typedef void pa_proplist; 54 void pa_stream_set_state(pa_stream *s, pa_stream_state_t st); 55 56 pa_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 41 63 /** Create a new, unconnected stream with the specified name and sample type */ 42 64 pa_stream* pa_stream_new( … … 44 66 const char *name /**< A name for this stream */, 45 67 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 72 pa_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 100 static void _pa_stream_free(pa_stream * s) { 101 pa_stream_disconnect(s); 102 pa_context_unref(s->c); 103 roar_mm_free(s); 104 } 47 105 48 106 /** Decrease the reference counter by one */ 49 void pa_stream_unref(pa_stream *s); 107 void 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 } 50 116 51 117 /** Increase the reference counter by one */ 52 pa_stream *pa_stream_ref(pa_stream *s); 118 pa_stream *pa_stream_ref(pa_stream *s) { 119 if ( s == NULL ) 120 return NULL; 121 122 s->refc++; 123 124 return s; 125 } 53 126 54 127 /** Return the current state of the stream */ 55 pa_stream_state_t pa_stream_get_state(pa_stream *p); 128 pa_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 } 56 134 57 135 /** Return the context this stream is attached to */ 58 pa_context* pa_stream_get_context(pa_stream *p); 136 pa_context* pa_stream_get_context(pa_stream *p) { 137 if ( p == NULL ) 138 return NULL; 139 140 return p->c; 141 } 59 142 60 143 /** Return the device (sink input or source output) index this stream is connected to */ … … 78 161 79 162 /** Disconnect a stream from a source/sink */ 80 int pa_stream_disconnect(pa_stream *s); 163 int 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 } 81 176 82 177 /** Write some data to the server (for playback sinks), if free_cb is … … 125 220 126 221 /** 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); 222 void 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 230 void 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 } 128 240 129 241 /** Set the callback function that is called when new data may be
Note: See TracChangeset
for help on using the changeset viewer.