OStreamAudioEncoder.hh

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) Massimo Cora' 2006 <maxcvs@email.it>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program 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.  See the
00012  *  GNU Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 
00020 #ifndef _OSTREAMAUDIOENCODER_H_
00021 #define _OSTREAMAUDIOENCODER_H_
00022 
00023 
00024 #include <ffmpeg/avcodec.h>
00025 #include <ffmpeg/avformat.h>
00026 
00027 #include "OStreamConfig.hh"
00028 
00030 #define MAX_AUDIO_PACKET_SIZE           (128 * 1024)
00031 
00037 class OStreamAudioEncoder
00038 {
00039 public:
00050         OStreamAudioEncoder( unsigned int io_buf_size, ostream_encoding_type encoding_type, 
00051                                                 int num_channels = 2 );
00052         virtual ~OStreamAudioEncoder();
00053 
00061         const unsigned char* encode_audio_frame( unsigned char* in_pcm_buffer, int in_pcm_buffer_size, 
00062                                                                                         int *out_size );
00063 
00064 private:        // functions
00065 
00070         bool encoder_initialize ();
00071         
00078         AVStream* create_audio_stream( AVFormatContext *io_fmt_context, int codec_id );
00079         
00085         bool open_codec( AVStream *stream );
00086 
00092         bool init_pcm_buffer( int size );
00093         
00095         void free_pcm_buffer ();
00096         
00103         int read_pcm_buffer( unsigned char *buf, int buf_size );
00104         
00110         void write_pcm_buffer( const unsigned char *buf, int buf_size );
00111         
00112 private:        // data
00114         bool _initialized;
00115 
00117         AVFormatContext *_out_fmt_context;
00118         
00120         AVStream *_audio_stream;
00121         
00123         AVOutputFormat *_out_fmt;
00124 
00126         unsigned char *_pcm_internal_buffer;
00127         
00129     unsigned char *_pcm_read_ptr, *_pcm_write_ptr, *_pcm_end_ptr;
00130         
00132         unsigned char* _internal_buffer;
00133         
00135         int _internal_buffer_size;
00136         
00138         int _encoding_type;
00139         
00141         int _frame_size;
00142         
00144         int _encoded_frame_size;
00145         
00147         unsigned char *_ready_to_encode_frame;
00148         
00150         int _num_channels;
00151 };
00152 
00153 
00154 
00155 
00156 #endif /* _OSTREAMAUDIOENCODER_H_ */
00157 

Generated on Tue Dec 26 10:32:38 2006 for Omnimeeting by  doxygen 1.4.7