00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00028 #ifndef __OUTCHANNELS_H__
00029 #define __OUTCHANNELS_H__
00030
00031 #include <pthread.h>
00032 #include <shouter.h>
00033 #include <pipe.h>
00034 #include <linklist.h>
00035 #include <generic.h>
00036 #include <resample/samplerate.h>
00037
00038 #define ENCBUFFER_SIZE 128000 // 65536 // we have ram, isn't it?
00039
00040
00041
00045 enum codec {
00046 MP3,
00047 OGG
00048 };
00049
00058 class OutChannel: public Entry {
00059
00090 public:
00095 OutChannel(char *myname);
00096
00097 virtual ~OutChannel();
00098
00099
00100 char name[128];
00101 char version[128];
00102 enum codec tipo;
00103
00104 bool quit;
00105 bool running;
00106 bool initialized;
00107
00108
00110
00112
00117 int create_ice();
00118
00123 bool delete_ice(int iceid);
00124
00130 Shouter *get_ice(int iceid);
00131
00140 bool apply_ice(int iceid);
00141
00149 bool connect_ice(int iceid, bool on);
00150
00156 Linklist icelist;
00157
00159
00161
00162
00163
00165
00167
00168 INT_SET(bps,_bps);
00169
00170 INT_SET(freq,_freq);
00171
00172 INT_SET(channels,_channels);
00173
00174 FLOAT_SET(quality,_quality);
00175
00176 INT_SET(lowpass,_lowpass);
00177
00178 INT_SET(highpass,_highpass);
00179
00193 char *guess_bps();
00194
00195 char quality_desc[256];
00196
00201 unsigned int get_bitrate() { return bitrate; };
00202
00203
00204
00206
00208
00220 bool dump_start(char *file);
00225 bool dump_stop();
00226
00227 FILE *fd;
00228 char fd_name[MAX_PATH_SIZE];
00229
00230
00231
00233
00234
00236
00237
00238
00240
00241
00255 virtual bool apply_profile() =0;
00256
00257
00258 virtual bool init() = 0;
00259 virtual int encode() =0;
00260 virtual void flush() =0;
00261
00262
00263
00264 int shout();
00265 bool dump();
00266
00276 void push(void *data, int len);
00277 Pipe *erbapipa;
00278 bool encoding;
00279
00280
00281 void start();
00282 void run();
00283 void lock()
00284 { pthread_mutex_lock(&_mutex); };
00285 void unlock() { pthread_mutex_unlock(&_mutex); };
00286 void wait() { pthread_cond_wait(&_cond,&_mutex); };
00287 void signal() { pthread_cond_signal(&_cond); };
00288 void lock_ice() { pthread_mutex_lock(&_mutex_ice); };
00289 void unlock_ice() { pthread_mutex_unlock(&_mutex_ice); };
00290 void destroy() { _thread_destroy(); };
00292
00293
00294 int16_t buffer[ENC_BUFFER];
00295
00296 private:
00297
00298
00299
00300 void _thread_init();
00301 void _thread_destroy();
00302 bool _thread_initialized;
00303
00304 pthread_t _thread;
00305 pthread_attr_t _attr;
00306 pthread_mutex_t _mutex;
00307 pthread_mutex_t _mutex_ice;
00308 pthread_cond_t _cond;
00309
00310
00311 int idseed;
00312
00313 protected:
00314
00315 static void* kickoff(void *arg) { ((OutChannel *) arg)->run(); return NULL; };
00317
00318 bool calc_bitrate(int enc);
00319 int encoded;
00320 int bitrate;
00321 double now;
00322 double prev;
00323 unsigned int bytes_accu;
00324
00325 };
00326
00327
00328
00329 #endif