# OpalBaseMixer Class Reference

`#include <opalmixer.h>`

Inheritance diagram for OpalBaseMixer:

[legend]
Collaboration diagram for OpalBaseMixer:
[legend]

## Public Types

typedef PString | Key_T

## Public Member Functions

| OpalBaseMixer (bool pushThread, unsigned periodMS, unsigned periodTS)
virtual | ~OpalBaseMixer ()
virtual bool | AddStream (const Key_T &key)
virtual void | RemoveStream (const Key_T &key)
virtual void | RemoveAllStreams ()
virtual bool | WriteStream (const Key_T &key, const RTP_DataFrame &input)
virtual RTP_DataFrame * | ReadMixed ()
virtual bool | ReadMixed (RTP_DataFrame &mixed)
virtual bool | OnMixed (RTP_DataFrame *&mixed)
void | StartPushThread ()
void | StopPushThread (bool lock=true)
unsigned | GetPeriodTS () const

## Protected Types

typedef std::map< Key_T, Stream * > | StreamMap_T

## Protected Member Functions

virtual Stream * | CreateStream ()=0
virtual bool | MixStreams (RTP_DataFrame &frame)=0
virtual size_t | GetOutputSize () const =0
virtual bool | OnPush ()
void | PushThreadMain ()

## Protected Attributes

bool | m_pushThread
unsigned | m_periodMS
unsigned | m_periodTS
StreamMap_T | m_inputStreams
unsigned | m_outputTimestamp
RTP_DataFrame * | m_pushFrame
PThread * | m_workerThread
bool | m_threadRunning
PMutex | m_mutex

## Data Structures

struct | Stream

## Detailed Description

Class base for a media mixer.

The mixer operates by re-buffering the input media into chunks each with an associated timestamp. A main mixer thread then reads from each stream at regular intervals, mixes the media and creates the output buffer.

Note the timestamps of the input media are extremely important as they are used so that breaks or too fast data in the input media is dealt with correctly.

## Member Typedef Documentation

typedef PString OpalBaseMixer::Key_T

typedef std::map<Key_T, Stream *> OpalBaseMixer::StreamMap_T `[protected]`

## Constructor & Destructor Documentation

OpalBaseMixer::OpalBaseMixer | ( | bool | pushThread,
|  | unsigned | periodMS,
|  | unsigned | periodTS |
| ) |  |  |

Parameters:

  pushThread | Indicate if the push thread should be started
  periodMS | The output buffer time in milliseconds
  periodTS | The output buffer time in RTP timestamp units

virtual OpalBaseMixer::~OpalBaseMixer | ( |  | ) | `[virtual]`

## Member Function Documentation

virtual bool OpalBaseMixer::AddStream | ( | const Key_T & | key | ) | `[virtual]`

Add a stream to mixer using the specified key.

Parameters:

  key | key for mixer stream

virtual Stream* OpalBaseMixer::CreateStream | ( |  | ) | `[protected, pure virtual]`

Implemented in OpalAudioMixer, and OpalVideoMixer.

virtual size_t OpalBaseMixer::GetOutputSize | ( |  | ) | const`[protected, pure virtual]`

Implemented in OpalAudioMixer, and OpalVideoMixer.

unsigned OpalBaseMixer::GetPeriodTS | ( |  | ) | const`[inline]`

Get the period for mixing in RTP timestamp units.

virtual bool OpalBaseMixer::MixStreams | ( | RTP_DataFrame & | frame | ) | `[protected, pure virtual]`

Implemented in OpalAudioMixer, and OpalVideoMixer.

virtual bool OpalBaseMixer::OnMixed | ( | RTP_DataFrame *& | mixed | ) | `[virtual]`

Mixed data is now available. For a push model system, this is called with mixed data as returned by ReadMixed().

The "mixed" parameter is a reference to a pointer, so if the consumer wishes to take responsibility for deleting the pointer to an RTP data frame, then they can set it to NULL.

If false is returned then the push thread is exited.

Parameters:

  mixed | Pointer to mixed media.

Reimplemented in OpalMixerNode::VideoMixer.

virtual bool OpalBaseMixer::OnPush | ( |  | ) | `[protected, virtual]`

Reimplemented in OpalMixerNode::AudioMixer.

void OpalBaseMixer::PushThreadMain | ( |  | ) | `[protected]`

virtual bool OpalBaseMixer::ReadMixed | ( | RTP_DataFrame & | mixed | ) | `[virtual]`

virtual RTP_DataFrame* OpalBaseMixer::ReadMixed | ( |  | ) | `[virtual]`

Read media from mixer. A pull model system would call this function to get the mixed media from the mixer. Note the stream indicated by the streamToIgnore key is not included in the mixing operation, allowing for example, the member of a conference to not hear themselves.

Note this function is the function that does all the "heavy lifting" for the mixer.

virtual void OpalBaseMixer::RemoveAllStreams | ( |  | ) | `[virtual]`

Remove all input streams from mixer.

Reimplemented in OpalAudioMixer.

virtual void OpalBaseMixer::RemoveStream | ( | const Key_T & | key | ) | `[virtual]`

Remove an input stream from mixer.

Parameters:

  key | key for mixer stream

void OpalBaseMixer::StartPushThread | ( |  | ) |

Start the push thread. Normally called internally.

void OpalBaseMixer::StopPushThread | ( | bool | lock = `true` | ) |

Stop the push thread. This will wait for th epush thread to terminate, so care must be taken to avoid deadlocks when calling.

virtual bool OpalBaseMixer::WriteStream | ( | const Key_T & | key,
|  | const RTP_DataFrame & | input |
| ) |  |  | `[virtual]`

Write an RTP data frame to mixer. A copy of the RTP data frame is created. This function is generally quite fast as the actual mixing is done in a different thread so minimal interference with the normal media stream processing occurs.

Parameters:

  key | key for mixer stream
  input | Input RTP data for media

## Field Documentation

StreamMap_T OpalBaseMixer::m_inputStreams `[protected]`

PMutex OpalBaseMixer::m_mutex `[protected]`

unsigned OpalBaseMixer::m_outputTimestamp `[protected]`

unsigned OpalBaseMixer::m_periodMS `[protected]`

unsigned OpalBaseMixer::m_periodTS `[protected]`

RTP_DataFrame* OpalBaseMixer::m_pushFrame `[protected]`

bool OpalBaseMixer::m_pushThread `[protected]`

bool OpalBaseMixer::m_threadRunning `[protected]`

PThread* OpalBaseMixer::m_workerThread `[protected]`

The documentation for this class was generated from the following file:

- opalmixer.h