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

Represents an MJPEG pull stream. More...

#include <MjpegPullStream.h>

Public Member Functions

 Stream (MediaRequest &request)
 Constructor. More...
 
virtual ~Stream ()
 Virtual destructor. 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...
 
bool Resume (float speed, unsigned int unixTime) override
 Send PLAY on an existing stream. More...
 
bool GoToLive () override
 Set the stream to Live and call Play. More...
 
void NewRequest (MediaRequest &request) override
 Set the stream to a new source. More...
 
- Public Member Functions inherited from MediaController::StreamBase
virtual ~StreamBase ()
 Virtual destructor. More...
 
bool Play (float speed=0, unsigned int unixTime=0) override
 Call Play on the stream. More...
 
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...
 
GstWrapperGetGstreamer () const
 Get the current GStreamer wrapper instance. More...
 
unsigned int GetLastTimestamp () const
 Gets the current time of the stream. More...
 
Mode GetMode () override
 Get the current playback mode. More...
 
- Public Member Functions inherited from MediaController::IStream
virtual ~IStream ()
 Virtual destructor. More...
 

Private Attributes

VxSdk::IVxDataSession_dataSession
 

Additional Inherited Members

- Public Types inherited from MediaController::IStream
enum  Mode {
  kStopped,
  kLive,
  kPlayback
}
 Values that represent the different playback modes. More...
 
- Public Attributes inherited from MediaController::StreamBase
StreamStatestate
 The current state of the stream. More...
 
VxSdk::VxStreamProtocol::Value protocol
 The protocol of the stream. More...
 
- Protected Member Functions inherited from MediaController::StreamBase
 StreamBase (MediaRequest &request)
 Constructor. More...
 
- Protected Attributes inherited from MediaController::StreamBase
MediaRequest _mediaRequest
 
GstWrapper_gst
 

Detailed Description

Represents an MJPEG pull stream.

Definition at line 16 of file MjpegPullStream.h.

Inherits MediaController::StreamBase.

Constructor & Destructor Documentation

MjpegPull::Stream::Stream ( MediaRequest request)

Constructor.

Parameters
requestThe requested media.
controllerA media controller object.

Definition at line 12 of file MjpegPullStream.cpp.

12  : StreamBase(request) {
13  Stream::NewRequest(request);
14 }
void NewRequest(MediaRequest &request) override
Set the stream to a new source.
StreamBase()
Default constructor.
Definition: StreamBase.cpp:10
MjpegPull::Stream::~Stream ( )
virtual

Virtual destructor.

Definition at line 16 of file MjpegPullStream.cpp.

16 {}

Member Function Documentation

bool MjpegPull::Stream::GoToLive ( )
overridevirtual

Set the stream to Live and call Play.

Implements MediaController::IStream.

Definition at line 82 of file MjpegPullStream.cpp.

82 { return true; }
void MjpegPull::Stream::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 115 of file MjpegPullStream.cpp.

115  {
116  _mediaRequest = request;
118  this->_gst->SetLocation(std::string(_dataSession->jpegUri));
119  char* authToken = nullptr;
120  int size = 0;
121  VxSdk::VxResult::Value result = _dataSession->GetAuthToken(authToken, size);
122  if (result == VxSdk::VxResult::kInsufficientSize) {
123  // Allocate enough space for authToken
124  authToken = new char[size];
125  // The result should now be kOK since we have allocated enough space
126  _dataSession->GetAuthToken(authToken, size);
127  }
128 
129  if (authToken != nullptr)
130  this->_gst->SetCookie(std::string(authToken));
131 }
VxSdk::IVxDataSource * dataSource
The data source to use to create the new video stream.
Definition: MediaRequest.h:21
virtual VxResult::Value GetAuthToken(char *token, int &size) const =0
void SetCookie(std::string cookie)
Set the cookie for MJPEG streams.
Definition: GstWrapper.cpp:289
void SetLocation(std::string location)
Set the stream location.
Definition: GstWrapper.cpp:274
MediaRequest _mediaRequest
Definition: StreamBase.h:72
virtual VxResult::Value CreateMjpegDataSession(IVxDataSession *&dataSession) const =0
VxSdk::IVxDataSession * _dataSession
void MjpegPull::Stream::Pause ( )
overridevirtual

Call Pause on the stream.

Implements MediaController::IStream.

Definition at line 58 of file MjpegPullStream.cpp.

58  {
59  // If the jpegUri is empty do not send a request.
60  if (_dataSession->jpegUri[0] == '\0')
61  return;
62 
63  // Pausing the stream moves it to playback mode so the live stream session needs to be deleted.
65  this->_gst->Pause();
66  // The timestamp is set to the last received timestamp so Resume will start at the correct time.
67  this->_gst->SetTimestamp(this->_gst->GetLastTimestamp());
68  this->state = new PausedState();
69 }
void Pause() const
Set the pipeline state to paused.
Definition: GstWrapper.cpp:540
void SetTimestamp(unsigned int seekTime)
Set the internal timestamp variable.
Definition: GstWrapper.cpp:301
unsigned int GetLastTimestamp() const
Get the last timestamp received from the stream.
Definition: GstWrapper.cpp:306
StreamState * state
The current state of the stream.
Definition: StreamBase.h:49
virtual VxResult::Value Pause()=0
VxSdk::IVxDataSession * _dataSession
Represents a stream that is currently in the paused state.
Definition: StreamState.h:71
bool MjpegPull::Stream::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 18 of file MjpegPullStream.cpp.

18  {
19  // If the jpegUri is empty send a new stream request.
20  if (_dataSession->jpegUri[0] == '\0')
22 
23  if (!this->_gst->IsPipelineActive())
24  this->_gst->CreateMjpegPipeline();
25 
26  if (unixTime == 0) {
28  if (ret != VxSdk::VxResult::kOK)
29  return false;
30 
32  }
33  else
34  {
35  VxSdk::VxResult::Value ret = _dataSession->Seek(unixTime, speed);
36  if (ret != VxSdk::VxResult::kOK)
37  return false;
38 
40  // Set the initial timestamp to the seek time.
41  this->_gst->SetTimestamp(unixTime);
42  }
43 
44  if (speed < 1.0f && speed > -1.0f) {
45  if (speed >= 0.0f)
46  speed = 1.0f;
47  else
48  speed = -1.0f;
49  }
50 
51  this->_gst->Play(speed);
52  this->state = new PlayingState();
53  return true;
54 }
void SetMode(Controller::Mode mode)
Set the playback mode.
Definition: GstWrapper.cpp:319
The stream is playing live video.
Definition: IStream.h:21
void SetTimestamp(unsigned int seekTime)
Set the internal timestamp variable.
Definition: GstWrapper.cpp:301
void NewRequest(MediaRequest &request) override
Set the stream to a new source.
The stream is playing recorded video.
Definition: IStream.h:24
void CreateMjpegPipeline()
Create the pipeline for an MJPEG stream.
Definition: GstWrapper.cpp:485
bool IsPipelineActive() const
Get the status of the pipeline.
Definition: GstWrapper.cpp:324
virtual VxResult::Value GoLive()=0
virtual VxResult::Value Seek(long long unixTime, float speed)=0
MediaRequest _mediaRequest
Definition: StreamBase.h:72
StreamState * state
The current state of the stream.
Definition: StreamBase.h:49
void Play(float speed=1.0f)
Set the pipeline state to playing and update the speed value for determining the framerate.
Definition: GstWrapper.cpp:531
Represents a stream that is currently in the playing state.
Definition: StreamState.h:55
VxSdk::IVxDataSession * _dataSession
void MjpegPull::Stream::PlayStream ( float  speed,
unsigned int  unixTime 
)
overridevirtual

Implements MediaController::IStream.

Definition at line 56 of file MjpegPullStream.cpp.

56 { }
bool MjpegPull::Stream::Resume ( float  speed,
unsigned int  unixTime 
)
overridevirtual

Send PLAY on an existing 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.

Reimplemented from MediaController::StreamBase.

Definition at line 84 of file MjpegPullStream.cpp.

84  {
85  // If the jpegUri is empty send a new stream request.
86  if (_dataSession->jpegUri[0] == '\0')
88 
89  if (!this->_gst->IsPipelineActive())
90  this->_gst->CreateMjpegPipeline();
91 
92  unsigned int seekTime = unixTime == 0 ? this->_gst->GetLastTimestamp() : unixTime;
93  // Seek to the last received timestamp generated during the Pause call.
94  VxSdk::VxResult::Value ret = _dataSession->Seek(seekTime, speed);
95  if (ret != VxSdk::VxResult::kOK)
96  return false;
97 
98  // Set the mode to playback.
100  // Set the initial timestamp to the seek time.
101  this->_gst->SetTimestamp(seekTime);
102 
103  if (speed < 1.0f && speed > -1.0f) {
104  if (speed >= 0.0f)
105  speed = 1.0f;
106  else
107  speed = -1.0f;
108  }
109 
110  this->_gst->Play(speed);
111  this->state = new PlayingState();
112  return true;
113 }
void SetMode(Controller::Mode mode)
Set the playback mode.
Definition: GstWrapper.cpp:319
void SetTimestamp(unsigned int seekTime)
Set the internal timestamp variable.
Definition: GstWrapper.cpp:301
void NewRequest(MediaRequest &request) override
Set the stream to a new source.
The stream is playing recorded video.
Definition: IStream.h:24
void CreateMjpegPipeline()
Create the pipeline for an MJPEG stream.
Definition: GstWrapper.cpp:485
bool IsPipelineActive() const
Get the status of the pipeline.
Definition: GstWrapper.cpp:324
unsigned int GetLastTimestamp() const
Get the last timestamp received from the stream.
Definition: GstWrapper.cpp:306
virtual VxResult::Value Seek(long long unixTime, float speed)=0
MediaRequest _mediaRequest
Definition: StreamBase.h:72
StreamState * state
The current state of the stream.
Definition: StreamBase.h:49
void Play(float speed=1.0f)
Set the pipeline state to playing and update the speed value for determining the framerate.
Definition: GstWrapper.cpp:531
Represents a stream that is currently in the playing state.
Definition: StreamState.h:55
VxSdk::IVxDataSession * _dataSession
void MjpegPull::Stream::Stop ( )
overridevirtual

Call TearDown on the stream.

Implements MediaController::IStream.

Definition at line 71 of file MjpegPullStream.cpp.

71  {
72  // If the jpegUri is empty do not send a request.
73  if (_dataSession->jpegUri[0] == '\0')
74  return;
75 
77  this->_gst->ClearPipeline();
79  this->state = new StoppedState();
80 }
void SetMode(Controller::Mode mode)
Set the playback mode.
Definition: GstWrapper.cpp:319
virtual VxResult::Value DeleteDataSession()=0
Represents a stream that is currently in the stopped state.
Definition: StreamState.h:86
The stream is stopped.
Definition: IStream.h:18
void ClearPipeline()
Clear the pipeline and display window.
Definition: GstWrapper.cpp:544
StreamState * state
The current state of the stream.
Definition: StreamBase.h:49
VxSdk::IVxDataSession * _dataSession

Member Data Documentation

VxSdk::IVxDataSession* MediaController::MjpegPull::Stream::_dataSession
private

Definition at line 39 of file MjpegPullStream.h.


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