OStreamAudioEncoder Class Reference

#include <OStreamAudioEncoder.hh>

List of all members.


Detailed Description

Utility class with reusable code. Depends on libavcodec/libavformat. Encodes PCM data packets to MP3 or, extendable, to other formats.

Definition at line 37 of file OStreamAudioEncoder.hh.

Public Member Functions

 OStreamAudioEncoder (unsigned int io_buf_size, ostream_encoding_type encoding_type, int num_channels=2)
 Constructor.
virtual ~OStreamAudioEncoder ()
const unsigned char * encode_audio_frame (unsigned char *in_pcm_buffer, int in_pcm_buffer_size, int *out_size)
 Ecode an audio frame.

Private Member Functions

bool encoder_initialize ()
 Initializing function for the encoder.
AVStream * create_audio_stream (AVFormatContext *io_fmt_context, int codec_id)
 Use ffmpeg libraries to create an AVStream.
bool open_codec (AVStream *stream)
 Open a codec, givin a stream.
bool init_pcm_buffer (int size)
 Init an internal pcm data buffer.
void free_pcm_buffer ()
 Free the pcm buffer.
int read_pcm_buffer (unsigned char *buf, int buf_size)
 Get data from the ring buffer-.
void write_pcm_buffer (const unsigned char *buf, int buf_size)
 Write data to the buffer ring.

Private Attributes

bool _initialized
 Specify whether the class is initialized or not.
AVFormatContext * _out_fmt_context
AVStream * _audio_stream
AVOutputFormat * _out_fmt
unsigned char * _pcm_internal_buffer
 A buffer reserved for PCM data.
unsigned char * _pcm_read_ptr
 Ring buffer controls.
unsigned char * _pcm_write_ptr
unsigned char * _pcm_end_ptr
unsigned char * _internal_buffer
 Buffer internal used to encode.
int _internal_buffer_size
 Size of internal buffer used to encode.
int _encoding_type
 Enum parameter that specify the encoding type.
int _frame_size
 Frame size of the dest packet format.
int _encoded_frame_size
 Size of the encoded frame.
unsigned char * _ready_to_encode_frame
 The encoded bytes will be contained here.
int _num_channels
 Number of channels use in the encoding.


Constructor & Destructor Documentation

OStreamAudioEncoder::OStreamAudioEncoder ( unsigned int  io_buf_size,
ostream_encoding_type  encoding_type,
int  num_channels = 2 
)

Parameters:
io_buf_size,: internal buffer size used to store encoded frames. This must be <= fMaxSize, or liveMedia libraries will crash.
encoding_type A wrapper enum to use OStream encoding parameters.
num_channels Number of channel to encode: 1- mono, 2- stereo. Defaults to 2.
Note:
in case you want to add some new encoding type be sure to check all the "switch ( _encoding_type )" lines you'll find in the implementation file and to add them the correct parameters.

Definition at line 25 of file OStreamAudioEncoder.cpp.

References _initialized, _internal_buffer, _internal_buffer_size, _ready_to_encode_frame, DEBUG_PRINT, encoder_initialize(), and NULL.

Here is the call graph for this function:

OStreamAudioEncoder::~OStreamAudioEncoder (  )  [virtual]

Definition at line 46 of file OStreamAudioEncoder.cpp.

References _internal_buffer, _out_fmt_context, _ready_to_encode_frame, and free_pcm_buffer().

Here is the call graph for this function:


Member Function Documentation

AVStream * OStreamAudioEncoder::create_audio_stream ( AVFormatContext *  io_fmt_context,
int  codec_id 
) [private]

Parameters:
io_fmt_context Format context in a fmmpeg fashion.
codec_id CodecID in a ffmpeg fashion.
Returns:
New AVStream.

Definition at line 88 of file OStreamAudioEncoder.cpp.

References _num_channels, DEBUG_PRINT, and NULL.

Referenced by encoder_initialize().

Here is the caller graph for this function:

const unsigned char * OStreamAudioEncoder::encode_audio_frame ( unsigned char *  in_pcm_buffer,
int  in_pcm_buffer_size,
int *  out_size 
)

Parameters:
in_pcm_buffer PCM data buffer.
in_pcm_buffer_size PCM data buffer size.
out_size Encoded frame size will be written here.
Returns:
The buffer with encoded data. Its size is written on out_size.

Definition at line 186 of file OStreamAudioEncoder.cpp.

References _audio_stream, _encoded_frame_size, _initialized, _internal_buffer, _internal_buffer_size, _ready_to_encode_frame, DEBUG_PRINT, NULL, read_pcm_buffer(), and write_pcm_buffer().

Referenced by MP3FromPCM::afterGettingFrame1().

Here is the call graph for this function:

Here is the caller graph for this function:

bool OStreamAudioEncoder::encoder_initialize (  )  [private]

Returns:
true on success, false on insuccess.

Definition at line 115 of file OStreamAudioEncoder.cpp.

References _audio_stream, _encoded_frame_size, _encoding_type, _frame_size, _num_channels, _out_fmt, _out_fmt_context, _ready_to_encode_frame, create_audio_stream(), DEBUG_PRINT, init_pcm_buffer(), MAX_AUDIO_PACKET_SIZE, NULL, open_codec(), and OSTREAM_ENCODING_MP3.

Referenced by OStreamAudioEncoder().

Here is the call graph for this function:

Here is the caller graph for this function:

void OStreamAudioEncoder::free_pcm_buffer (  )  [private]

Definition at line 241 of file OStreamAudioEncoder.cpp.

References _pcm_internal_buffer, and NULL.

Referenced by ~OStreamAudioEncoder().

Here is the caller graph for this function:

bool OStreamAudioEncoder::init_pcm_buffer ( int  size  )  [private]

Parameters:
size Size of the buffer.
Returns:
true on success.

Definition at line 228 of file OStreamAudioEncoder.cpp.

References _pcm_end_ptr, _pcm_internal_buffer, _pcm_read_ptr, and _pcm_write_ptr.

Referenced by encoder_initialize().

Here is the caller graph for this function:

bool OStreamAudioEncoder::open_codec ( AVStream *  stream  )  [private]

Parameters:
stream An already initialized stream. AVStream is an ffmpeg struct.
Returns:
true on success, false else.

Definition at line 65 of file OStreamAudioEncoder.cpp.

References DEBUG_PRINT.

Referenced by encoder_initialize().

Here is the caller graph for this function:

int OStreamAudioEncoder::read_pcm_buffer ( unsigned char *  buf,
int  buf_size 
) [private]

Parameters:
buf The buffer where to store the data.
buf_size Buffer size.
Returns:
0 on success, -1 on insuccess.

Definition at line 247 of file OStreamAudioEncoder.cpp.

References _pcm_end_ptr, _pcm_internal_buffer, _pcm_read_ptr, and _pcm_write_ptr.

Referenced by encode_audio_frame().

Here is the caller graph for this function:

void OStreamAudioEncoder::write_pcm_buffer ( const unsigned char *  buf,
int  buf_size 
) [private]

Parameters:
buf The buffer to add.
buf_size Buffer size.

Definition at line 275 of file OStreamAudioEncoder.cpp.

References _pcm_end_ptr, _pcm_internal_buffer, and _pcm_write_ptr.

Referenced by encode_audio_frame().

Here is the caller graph for this function:


Member Data Documentation

AVStream* OStreamAudioEncoder::_audio_stream [private]

See also:
ffmpeg doc for this structs

Definition at line 120 of file OStreamAudioEncoder.hh.

Referenced by encode_audio_frame(), and encoder_initialize().

int OStreamAudioEncoder::_encoded_frame_size [private]

It's _encoded_frame_size = _frame_size * 2 * _num_channels;

Definition at line 144 of file OStreamAudioEncoder.hh.

Referenced by encode_audio_frame(), and encoder_initialize().

int OStreamAudioEncoder::_encoding_type [private]

Definition at line 138 of file OStreamAudioEncoder.hh.

Referenced by encoder_initialize().

int OStreamAudioEncoder::_frame_size [private]

E.g. MP3 format.

Definition at line 141 of file OStreamAudioEncoder.hh.

Referenced by encoder_initialize().

bool OStreamAudioEncoder::_initialized [private]

Definition at line 114 of file OStreamAudioEncoder.hh.

Referenced by encode_audio_frame(), and OStreamAudioEncoder().

unsigned char* OStreamAudioEncoder::_internal_buffer [private]

Definition at line 132 of file OStreamAudioEncoder.hh.

Referenced by encode_audio_frame(), OStreamAudioEncoder(), and ~OStreamAudioEncoder().

int OStreamAudioEncoder::_internal_buffer_size [private]

Definition at line 135 of file OStreamAudioEncoder.hh.

Referenced by encode_audio_frame(), and OStreamAudioEncoder().

int OStreamAudioEncoder::_num_channels [private]

Definition at line 150 of file OStreamAudioEncoder.hh.

Referenced by create_audio_stream(), and encoder_initialize().

AVOutputFormat* OStreamAudioEncoder::_out_fmt [private]

See also:
ffmpeg doc for this structs

Definition at line 123 of file OStreamAudioEncoder.hh.

Referenced by encoder_initialize().

AVFormatContext* OStreamAudioEncoder::_out_fmt_context [private]

See also:
ffmpeg doc for this structs

Definition at line 117 of file OStreamAudioEncoder.hh.

Referenced by encoder_initialize(), and ~OStreamAudioEncoder().

unsigned char * OStreamAudioEncoder::_pcm_end_ptr [private]

Definition at line 129 of file OStreamAudioEncoder.hh.

Referenced by init_pcm_buffer(), read_pcm_buffer(), and write_pcm_buffer().

unsigned char* OStreamAudioEncoder::_pcm_internal_buffer [private]

Will be a ring buffer.

Definition at line 126 of file OStreamAudioEncoder.hh.

Referenced by free_pcm_buffer(), init_pcm_buffer(), read_pcm_buffer(), and write_pcm_buffer().

unsigned char* OStreamAudioEncoder::_pcm_read_ptr [private]

Definition at line 129 of file OStreamAudioEncoder.hh.

Referenced by init_pcm_buffer(), and read_pcm_buffer().

unsigned char * OStreamAudioEncoder::_pcm_write_ptr [private]

Definition at line 129 of file OStreamAudioEncoder.hh.

Referenced by init_pcm_buffer(), read_pcm_buffer(), and write_pcm_buffer().

unsigned char* OStreamAudioEncoder::_ready_to_encode_frame [private]

Definition at line 147 of file OStreamAudioEncoder.hh.

Referenced by encode_audio_frame(), encoder_initialize(), OStreamAudioEncoder(), and ~OStreamAudioEncoder().


The documentation for this class was generated from the following files:
Generated on Tue Dec 26 10:38:15 2006 for Omnimeeting by  doxygen 1.4.7