outchannels.h Source File

Main Page Modules Class Hierarchy Compound List File List Compound Members File Members

# outchannels.h

Go to the documentation of this file.

    00001 /* MuSE - Multiple Streaming Engine
    00002  * Copyright (C) 2000-2002 Denis Rojo aka jaromil <jaromil@dyne.org>
    00003  *
    00004  * This source code is free software; you can redistribute it and/or
    00005  * modify it under the terms of the GNU Public License as published
    00006  * by the Free Software Foundation; either version 2 of the License,
    00007  * or (at your option) any later version.
    00008  *
    00009  * This source code is distributed in the hope that it will be useful,
    00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00012  * Please refer to the GNU Public License for more details.
    00013  *
    00014  * You should have received a copy of the GNU Public License along with
    00015  * this source code; if not, write to:
    00016  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00017  *
    00018  * "$Id: outchannels.h,v 1.4 2004/03/29 16:04:26 jaromil Exp $"
    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   // SHOUTERS
    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   // end of Shouters
    00161
    00162
    00163
    00165   // ENCODER SETTINGS HERE
    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   // DUMP TO FILE
    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   // end of the OutChannel public interface
    00233
    00234
    00236   // IF YOU ARE DEALING WITH A GUI
    00237   //  YOU ARE NOT INTERESTED IN WHAT
    00238   // COMES NEXT TO HERE
    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   /* pthread methods */
    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   /* pthread properties and private methods */
    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