Media Controller
A GStreamer implementation using the VideoXpert SDK
MediaController::Controller Class Reference

Implements the IController interface methods. More...

#include <Controller.h>

Public Member Functions

 Controller (MediaRequest &request)
 Constructor. More...
 
virtual ~Controller ()
 Virtual destructor. More...
 
void SetWindow (void *handle) override
 Set the display window using the given window handle. More...
 
bool GoToLive () override
 Set the stream to Live and call Play. More...
 
bool Play (float speed, unsigned int unixTime) override
 Call Play on the stream. More...
 
void PlayStream (float speed, unsigned int unixTime) override
 
void Pause () override
 Call Pause on the stream. More...
 
void Stop () override
 Call TearDown on the stream. More...
 
void NewRequest (MediaRequest &request) override
 Set the stream to a new source. More...
 
void AddObserver (TimestampEventCallback observer) override
 Add a new subscriber to timestamp events. More...
 
void RemoveObserver (TimestampEventCallback observer) override
 Remove an existing timestamp event subscriber. More...
 
void ClearObservers () override
 Remove all existing timestamp event subscribers. More...
 
Mode GetMode () override
 Get the current playback mode. More...
 
bool IsPipelineActive () override
 Get the status of the pipeline. More...
 
void AddEventData (void *customData) override
 Add event data to be send back during timestamp events. More...
 
- Public Member Functions inherited from MediaController::IController
virtual ~IController ()
 Virtual destructor. More...
 
- Public Member Functions inherited from MediaController::IStream
virtual ~IStream ()
 Virtual destructor. More...
 

Public Attributes

StreamBasestream
 The current video stream instance. More...
 
StreamBaseaudioStream
 The current audio stream instance. More...
 

Static Private Member Functions

static void CallSetupStream (StreamBase *stream, float speed, unsigned int unixTime, bool *result)
 
static void CallPlayStream (StreamBase *stream, float speed, unsigned int unixTime)
 

Additional Inherited Members

- Public Types inherited from MediaController::IStream
enum  Mode {
  kStopped,
  kLive,
  kPlayback
}
 Values that represent the different playback modes. More...
 

Detailed Description

Implements the IController interface methods.

Definition at line 14 of file Controller.h.

Inherits MediaController::IController.

Constructor & Destructor Documentation

Controller::Controller ( MediaRequest request)

Constructor.

Parameters
requestThe requested media.

Definition at line 30 of file Controller.cpp.

30  {
31  this->stream = StreamFactory::CreateStream(request);
33 }
static StreamBase * CreateStream(MediaRequest &request)
Create a new stream object.
StreamBase * audioStream
The current audio stream instance.
Definition: Controller.h:49
StreamBase * stream
The current video stream instance.
Definition: Controller.h:44
static StreamBase * CreateAudioStream(MediaRequest &request)
Create a new audio stream object.
Controller::~Controller ( )
virtual

Virtual destructor.

Definition at line 35 of file Controller.cpp.

35  {
36  if (this->stream != nullptr) {
37  delete this->stream;
38  this->stream = nullptr;
39  }
40 
41  if (this->audioStream != nullptr) {
42  delete this->audioStream;
43  this->audioStream = nullptr;
44  }
45 }
StreamBase * audioStream
The current audio stream instance.
Definition: Controller.h:49
StreamBase * stream
The current video stream instance.
Definition: Controller.h:44

Member Function Documentation

void Controller::AddEventData ( void *  customData)
overridevirtual

Add event data to be send back during timestamp events.

Parameters
customDataCustom data pointer.

Implements MediaController::IController.

Definition at line 150 of file Controller.cpp.

150  {
151  if (this->stream != nullptr)
152  this->stream->GetGstreamer()->AddEventData(customData);
153 }
GstWrapper * GetGstreamer() const
Get the current GStreamer wrapper instance.
Definition: StreamBase.cpp:32
void AddEventData(void *customData)
Add custom data to be stored in here, which will be send back to caller inside TimestampEvent on Time...
Definition: GstWrapper.cpp:340
StreamBase * stream
The current video stream instance.
Definition: Controller.h:44
void Controller::AddObserver ( TimestampEventCallback  observer)
overridevirtual

Add a new subscriber to timestamp events.

Parameters
observerThe TimestampEventCallback event handler.

Implements MediaController::IController.

Definition at line 145 of file Controller.cpp.

145  {
146  if (this->stream != nullptr)
147  this->stream->GetGstreamer()->AddObserver(observer);
148 }
GstWrapper * GetGstreamer() const
Get the current GStreamer wrapper instance.
Definition: StreamBase.cpp:32
void AddObserver(TimestampEventCallback observer)
Add a new subscriber to timestamp events.
Definition: GstWrapper.cpp:328
StreamBase * stream
The current video stream instance.
Definition: Controller.h:44
void Controller::CallPlayStream ( StreamBase stream,
float  speed,
unsigned int  unixTime 
)
staticprivate

Definition at line 123 of file Controller.cpp.

123  {
124  if (stream != nullptr) {
125  stream->PlayStream(speed, unixTime);
126  }
127 }
virtual void PlayStream(float speed, unsigned int unixTime)=0
void Controller::CallSetupStream ( StreamBase stream,
float  speed,
unsigned int  unixTime,
bool *  result 
)
staticprivate

Definition at line 117 of file Controller.cpp.

117  {
118  if (stream != nullptr) {
119  *result = stream->state->Play(*stream, speed, unixTime);
120  }
121 }
StreamState * state
The current state of the stream.
Definition: StreamBase.h:49
virtual bool Play(StreamBase &stream, float speed, unsigned int unixTime)
Perform the Play action based on the stream state.
Definition: StreamState.h:25
void Controller::ClearObservers ( )
overridevirtual

Remove all existing timestamp event subscribers.

Implements MediaController::IController.

Definition at line 160 of file Controller.cpp.

160  {
161  if (this->stream != nullptr)
162  this->stream->GetGstreamer()->ClearObservers();
163 }
void ClearObservers()
Remove all existing timestamp event subscribers.
Definition: GstWrapper.cpp:336
GstWrapper * GetGstreamer() const
Get the current GStreamer wrapper instance.
Definition: StreamBase.cpp:32
StreamBase * stream
The current video stream instance.
Definition: Controller.h:44
Controller::Mode Controller::GetMode ( )
overridevirtual

Get the current playback mode.

Returns
The current stream Mode.

Implements MediaController::IStream.

Definition at line 165 of file Controller.cpp.

165  {
166  if (this->stream != nullptr)
167  return this->stream->GetGstreamer()->GetMode();
168 
169  return Controller::Mode::kStopped;
170 }
GstWrapper * GetGstreamer() const
Get the current GStreamer wrapper instance.
Definition: StreamBase.cpp:32
StreamBase * stream
The current video stream instance.
Definition: Controller.h:44
Controller::Mode GetMode() const
Get the current playback mode.
Definition: GstWrapper.h:90
bool Controller::GoToLive ( )
overridevirtual

Set the stream to Live and call Play.

Implements MediaController::IStream.

Definition at line 62 of file Controller.cpp.

62  {
63  bool result = true;
64  if (this->stream != nullptr) {
65  result &= this->stream->state->GoToLive(*this->stream);
66  CallPlayStream(this->stream, 0, 0);
67  }
68 
69  if (this->audioStream != nullptr) {
70  result &= this->audioStream->state->GoToLive(*this->audioStream);
71  CallPlayStream(this->audioStream, 0, 0);
72  }
73 
74  return result;
75 }
virtual bool GoToLive(StreamBase &stream)
Perform the GoToLive action based on the stream state.
Definition: StreamState.h:43
static void CallPlayStream(StreamBase *stream, float speed, unsigned int unixTime)
Definition: Controller.cpp:123
StreamBase * audioStream
The current audio stream instance.
Definition: Controller.h:49
StreamBase * stream
The current video stream instance.
Definition: Controller.h:44
StreamState * state
The current state of the stream.
Definition: StreamBase.h:49
bool Controller::IsPipelineActive ( )
overridevirtual

Get the status of the pipeline.

Returns
True if pipeline is active, otherwise false.

Implements MediaController::IController.

Definition at line 172 of file Controller.cpp.

172  {
173  if (this->stream != nullptr)
174  return this->stream->GetGstreamer()->IsPipelineActive();
175  return false;
176 }
GstWrapper * GetGstreamer() const
Get the current GStreamer wrapper instance.
Definition: StreamBase.cpp:32
bool IsPipelineActive() const
Get the status of the pipeline.
Definition: GstWrapper.cpp:324
StreamBase * stream
The current video stream instance.
Definition: Controller.h:44
void Controller::NewRequest ( MediaRequest request)
overridevirtual

Set the stream to a new source.

Parameters
requestThe new MediaRequest to reset the stream to.

Implements MediaController::IStream.

Definition at line 52 of file Controller.cpp.

52  {
53  if (this->stream != nullptr)
54  this->stream->NewRequest(request);
55 
56  if (this->audioStream != nullptr) {
57  MediaRequest* audioRequest = StreamFactory::CreateMediaRequest(request);
58  this->audioStream->NewRequest(*audioRequest);
59  }
60 }
void NewRequest(MediaRequest &request) override
Set the stream to a new source.
Definition: StreamBase.cpp:28
Contains the information needed to start a new media stream.
Definition: MediaRequest.h:11
StreamBase * audioStream
The current audio stream instance.
Definition: Controller.h:49
static MediaRequest * CreateMediaRequest(MediaRequest &request)
Create a new audio MediaRequest object.
StreamBase * stream
The current video stream instance.
Definition: Controller.h:44
void Controller::Pause ( )
overridevirtual

Call Pause on the stream.

Implements MediaController::IStream.

Definition at line 129 of file Controller.cpp.

129  {
130  if (this->stream != nullptr)
131  this->stream->state->Pause(*this->stream);
132 
133  if (this->audioStream != nullptr)
134  this->audioStream->state->Pause(*this->audioStream);
135 }
virtual void Pause(StreamBase &stream)
Perform the Pause action based on the stream state.
Definition: StreamState.h:31
StreamBase * audioStream
The current audio stream instance.
Definition: Controller.h:49
StreamBase * stream
The current video stream instance.
Definition: Controller.h:44
StreamState * state
The current state of the stream.
Definition: StreamBase.h:49
bool Controller::Play ( float  speed,
unsigned int  unixTime 
)
overridevirtual

Call Play on the stream.

Parameters
speedThe playback speed. Negative values can be used for reverse playback. A value of 0 will resume a paused stream.
unixTimeThe start time for playback. A value of 0 will start a live stream.

Implements MediaController::IStream.

Definition at line 77 of file Controller.cpp.

77  {
78  // Setup audio stream in new thread
79  bool audioResult = true;
80  boost::thread* t1 = nullptr;
81  if (this->audioStream != nullptr) {
82  t1 = new boost::thread(CallSetupStream, this->audioStream, speed, unixTime, &audioResult);
83  }
84 
85  // Setup video stream in main thread
86  bool videoResult = true;
87  CallSetupStream(this->stream, speed, unixTime, &videoResult);
88 
89  // Wait for audio stream to complete
90  if (t1 != nullptr)
91  t1->join();
92 
93  if (!videoResult || !audioResult)
94  return false;
95 
96  // Create pipeline for audio stream in new thread
97  boost::thread* t2 = nullptr;
98  if (audioResult) {
99  t2 = new boost::thread(CallPlayStream, this->audioStream, speed, unixTime);
100  }
101 
102  // Create pipeline for video stream in main thread
103  if (videoResult) {
104  CallPlayStream(this->stream, speed, unixTime);
105  }
106 
107  // Wait for audio stream to complete
108  if (t2 != nullptr)
109  t2->join();
110 
111  return true;
112 }
static void CallPlayStream(StreamBase *stream, float speed, unsigned int unixTime)
Definition: Controller.cpp:123
StreamBase * audioStream
The current audio stream instance.
Definition: Controller.h:49
StreamBase * stream
The current video stream instance.
Definition: Controller.h:44
static void CallSetupStream(StreamBase *stream, float speed, unsigned int unixTime, bool *result)
Definition: Controller.cpp:117
void Controller::PlayStream ( float  speed,
unsigned int  unixTime 
)
overridevirtual

Implements MediaController::IStream.

Definition at line 114 of file Controller.cpp.

114  {
115 }
void Controller::RemoveObserver ( TimestampEventCallback  observer)
overridevirtual

Remove an existing timestamp event subscriber.

Parameters
observerThe TimestampEventCallback event handler.

Implements MediaController::IController.

Definition at line 155 of file Controller.cpp.

155  {
156  if (this->stream != nullptr)
157  this->stream->GetGstreamer()->RemoveObserver(observer);
158 }
GstWrapper * GetGstreamer() const
Get the current GStreamer wrapper instance.
Definition: StreamBase.cpp:32
void RemoveObserver(TimestampEventCallback observer)
Remove an existing timestamp event subscriber.
Definition: GstWrapper.cpp:332
StreamBase * stream
The current video stream instance.
Definition: Controller.h:44
void Controller::SetWindow ( void *  handle)
overridevirtual

Set the display window using the given window handle.

Parameters
handleThe window handle of the display.

Implements MediaController::IController.

Definition at line 47 of file Controller.cpp.

47  {
48  if (this->stream != nullptr)
49  this->stream->GetGstreamer()->SetWindowHandle(guintptr(handle));
50 }
GstWrapper * GetGstreamer() const
Get the current GStreamer wrapper instance.
Definition: StreamBase.cpp:32
void SetWindowHandle(guintptr winhandle)
Set the display window using the given window handle.
Definition: GstWrapper.cpp:270
StreamBase * stream
The current video stream instance.
Definition: Controller.h:44
void Controller::Stop ( )
overridevirtual

Call TearDown on the stream.

Implements MediaController::IStream.

Definition at line 137 of file Controller.cpp.

137  {
138  if (this->stream != nullptr)
139  this->stream->state->Stop(*this->stream);
140 
141  if (this->audioStream != nullptr)
142  this->audioStream->state->Stop(*this->audioStream);
143 }
virtual void Stop(StreamBase &stream)
Perform the Stop action based on the stream state.
Definition: StreamState.h:37
StreamBase * audioStream
The current audio stream instance.
Definition: Controller.h:49
StreamBase * stream
The current video stream instance.
Definition: Controller.h:44
StreamState * state
The current state of the stream.
Definition: StreamBase.h:49

Member Data Documentation

StreamBase* MediaController::Controller::audioStream

The current audio stream instance.

Definition at line 49 of file Controller.h.

StreamBase* MediaController::Controller::stream

The current video stream instance.

Definition at line 44 of file Controller.h.


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