00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00032 #ifndef __PIPE_H__
00033 #define __PIPE_H__
00034
00035 #include <pthread.h>
00036 #include <string.h>
00037 #include <inttypes.h>
00038
00074 typedef void (pipe_copy_f)(void *src, void *dst, int samples);
00075
00077 typedef struct pipe_copy_list {
00078 char *name;
00079 pipe_copy_f *callback;
00080 int src_samplesize;
00081 int dst_samplesize;
00082 };
00083
00084 class Pipe {
00085 public:
00086
00090 Pipe(int size=16384);
00092
00093 ~Pipe();
00095
00116 bool set_input_type(char *name);
00118 bool set_output_type(char *name);
00120
00121 void set_block(bool input, bool output);
00123 void set_block_timeout(int input, int output);
00125
00138 int read(int length, void *data);
00140
00153
00154
00163
00165
00175
00176
00177
00178
00189 int write(int length, void *data);
00190
00199
00200
00209
00210
00216 void block(bool val);
00217
00218 bool blocking;
00219
00223 int size();
00224
00228 int space();
00229
00230 void flush();
00231
00232 void flush(int size);
00234
00235 private:
00236 pthread_mutex_t _mutex;
00237 void _thread_init() { pthread_mutex_init (&_mutex,NULL); };
00238 void _thread_destroy() { pthread_mutex_destroy(&_mutex); };
00239 void lock() { pthread_mutex_lock(&_mutex); };
00240 void unlock() { pthread_mutex_unlock(&_mutex); };
00241
00242 void *buffer;
00243 void *bufferEnd;
00244
00245 void *start;
00246 void *end;
00247
00248 pipe_copy_list *read_copy_cb;
00249 pipe_copy_list *write_copy_cb;
00250
00251 int pipesize;
00252
00253 bool read_blocking;
00254 bool write_blocking;
00255 int read_blocking_time;
00256 int write_blocking_time;
00257
00258 };
00259
00260 #endif