Browse Source

emit all signals thru call to _dispatchNotification()

QGC4.4
Andrew Voznytsa 5 years ago
parent
commit
bc18446e0f
  1. 64
      src/VideoReceiver/GstVideoReceiver.cc
  2. 2
      src/VideoReceiver/GstVideoReceiver.h

64
src/VideoReceiver/GstVideoReceiver.cc

@ -78,7 +78,7 @@ GstVideoReceiver::start(const QString& uri, unsigned timeout)
if(_pipeline) { if(_pipeline) {
qCDebug(VideoReceiverLog) << "Already running!"; qCDebug(VideoReceiverLog) << "Already running!";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartComplete(STATUS_INVALID_STATE); emit onStartComplete(STATUS_INVALID_STATE);
}); });
return; return;
@ -86,7 +86,7 @@ GstVideoReceiver::start(const QString& uri, unsigned timeout)
if (uri.isEmpty()) { if (uri.isEmpty()) {
qCDebug(VideoReceiverLog) << "Failed because URI is not specified"; qCDebug(VideoReceiverLog) << "Failed because URI is not specified";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartComplete(STATUS_INVALID_URL); emit onStartComplete(STATUS_INVALID_URL);
}); });
return; return;
@ -231,14 +231,14 @@ GstVideoReceiver::start(const QString& uri, unsigned timeout)
} }
} }
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartComplete(STATUS_FAIL); emit onStartComplete(STATUS_FAIL);
}); });
} else { } else {
GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(_pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "pipeline-started"); GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(_pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "pipeline-started");
qCDebug(VideoReceiverLog) << "Started"; qCDebug(VideoReceiverLog) << "Started";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartComplete(STATUS_OK); emit onStartComplete(STATUS_OK);
}); });
} }
@ -319,12 +319,12 @@ GstVideoReceiver::stop(void)
if (_streaming) { if (_streaming) {
_streaming = false; _streaming = false;
qCDebug(VideoReceiverLog) << "Streaming stopped"; qCDebug(VideoReceiverLog) << "Streaming stopped";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit streamingChanged(); emit streamingChanged();
}); });
} else { } else {
qCDebug(VideoReceiverLog) << "Streaming did not start"; qCDebug(VideoReceiverLog) << "Streaming did not start";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit timeout(); emit timeout();
}); });
} }
@ -332,7 +332,7 @@ GstVideoReceiver::stop(void)
qCDebug(VideoReceiverLog) << "Stopped"; qCDebug(VideoReceiverLog) << "Stopped";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStopComplete(STATUS_OK); emit onStopComplete(STATUS_OK);
}); });
} }
@ -368,7 +368,7 @@ GstVideoReceiver::startDecoding(void* sink)
if(_videoSink != nullptr || _decoding) { if(_videoSink != nullptr || _decoding) {
qCDebug(VideoReceiverLog) << "Already decoding!"; qCDebug(VideoReceiverLog) << "Already decoding!";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartDecodingComplete(STATUS_INVALID_STATE); emit onStartDecodingComplete(STATUS_INVALID_STATE);
}); });
return; return;
@ -378,7 +378,7 @@ GstVideoReceiver::startDecoding(void* sink)
if ((pad = gst_element_get_static_pad(videoSink, "sink")) == nullptr) { if ((pad = gst_element_get_static_pad(videoSink, "sink")) == nullptr) {
qCCritical(VideoReceiverLog) << "Unable to find sink pad of video sink"; qCCritical(VideoReceiverLog) << "Unable to find sink pad of video sink";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartDecodingComplete(STATUS_FAIL); emit onStartDecodingComplete(STATUS_FAIL);
}); });
return; return;
@ -397,7 +397,7 @@ GstVideoReceiver::startDecoding(void* sink)
_removingDecoder = false; _removingDecoder = false;
if (!_streaming) { if (!_streaming) {
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartDecodingComplete(STATUS_OK); emit onStartDecodingComplete(STATUS_OK);
}); });
return; return;
@ -405,7 +405,7 @@ GstVideoReceiver::startDecoding(void* sink)
if (!_addDecoder(_decoderValve)) { if (!_addDecoder(_decoderValve)) {
qCCritical(VideoReceiverLog) << "_addDecoder() failed"; qCCritical(VideoReceiverLog) << "_addDecoder() failed";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartDecodingComplete(STATUS_FAIL); emit onStartDecodingComplete(STATUS_FAIL);
}); });
return; return;
@ -415,7 +415,7 @@ GstVideoReceiver::startDecoding(void* sink)
qCDebug(VideoReceiverLog) << "Decoding started"; qCDebug(VideoReceiverLog) << "Decoding started";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartDecodingComplete(STATUS_OK); emit onStartDecodingComplete(STATUS_OK);
}); });
} }
@ -435,7 +435,7 @@ GstVideoReceiver::stopDecoding(void)
// exit immediately if we are not decoding // exit immediately if we are not decoding
if (_pipeline == nullptr || !_decoding) { if (_pipeline == nullptr || !_decoding) {
qCDebug(VideoReceiverLog) << "Not decoding!"; qCDebug(VideoReceiverLog) << "Not decoding!";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStopDecodingComplete(STATUS_INVALID_STATE); emit onStopDecodingComplete(STATUS_INVALID_STATE);
}); });
return; return;
@ -449,7 +449,7 @@ GstVideoReceiver::stopDecoding(void)
// FIXME: AV: it is much better to emit onStopDecodingComplete() after decoding is really stopped // FIXME: AV: it is much better to emit onStopDecodingComplete() after decoding is really stopped
// (which happens later due to async design) but as for now it is also not so bad... // (which happens later due to async design) but as for now it is also not so bad...
_notificationHandler.dispatch([this, ret](){ _dispatchNotification([this, ret](){
emit onStopDecodingComplete(ret ? STATUS_OK : STATUS_FAIL); emit onStopDecodingComplete(ret ? STATUS_OK : STATUS_FAIL);
}); });
} }
@ -469,7 +469,7 @@ GstVideoReceiver::startRecording(const QString& videoFile, FILE_FORMAT format)
if (_pipeline == nullptr) { if (_pipeline == nullptr) {
qCDebug(VideoReceiverLog) << "Streaming is not active!"; qCDebug(VideoReceiverLog) << "Streaming is not active!";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartRecordingComplete(STATUS_INVALID_STATE); emit onStartRecordingComplete(STATUS_INVALID_STATE);
}); });
return; return;
@ -477,7 +477,7 @@ GstVideoReceiver::startRecording(const QString& videoFile, FILE_FORMAT format)
if (_recording) { if (_recording) {
qCDebug(VideoReceiverLog) << "Already recording!"; qCDebug(VideoReceiverLog) << "Already recording!";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartRecordingComplete(STATUS_INVALID_STATE); emit onStartRecordingComplete(STATUS_INVALID_STATE);
}); });
return; return;
@ -487,7 +487,7 @@ GstVideoReceiver::startRecording(const QString& videoFile, FILE_FORMAT format)
if ((_fileSink = _makeFileSink(videoFile, format)) == nullptr) { if ((_fileSink = _makeFileSink(videoFile, format)) == nullptr) {
qCCritical(VideoReceiverLog) << "_makeFileSink() failed"; qCCritical(VideoReceiverLog) << "_makeFileSink() failed";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartRecordingComplete(STATUS_FAIL); emit onStartRecordingComplete(STATUS_FAIL);
}); });
return; return;
@ -501,7 +501,7 @@ GstVideoReceiver::startRecording(const QString& videoFile, FILE_FORMAT format)
if (!gst_element_link(_recorderValve, _fileSink)) { if (!gst_element_link(_recorderValve, _fileSink)) {
qCCritical(VideoReceiverLog) << "Failed to link valve and file sink"; qCCritical(VideoReceiverLog) << "Failed to link valve and file sink";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartRecordingComplete(STATUS_FAIL); emit onStartRecordingComplete(STATUS_FAIL);
}); });
return; return;
@ -518,7 +518,7 @@ GstVideoReceiver::startRecording(const QString& videoFile, FILE_FORMAT format)
if ((probepad = gst_element_get_static_pad(_recorderValve, "src")) == nullptr) { if ((probepad = gst_element_get_static_pad(_recorderValve, "src")) == nullptr) {
qCCritical(VideoReceiverLog) << "gst_element_get_static_pad() failed"; qCCritical(VideoReceiverLog) << "gst_element_get_static_pad() failed";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartRecordingComplete(STATUS_FAIL); emit onStartRecordingComplete(STATUS_FAIL);
}); });
return; return;
@ -532,7 +532,7 @@ GstVideoReceiver::startRecording(const QString& videoFile, FILE_FORMAT format)
_recording = true; _recording = true;
qCDebug(VideoReceiverLog) << "Recording started"; qCDebug(VideoReceiverLog) << "Recording started";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStartRecordingComplete(STATUS_OK); emit onStartRecordingComplete(STATUS_OK);
emit recordingChanged(); emit recordingChanged();
}); });
@ -554,7 +554,7 @@ GstVideoReceiver::stopRecording(void)
// exit immediately if we are not recording // exit immediately if we are not recording
if (_pipeline == nullptr || !_recording) { if (_pipeline == nullptr || !_recording) {
qCDebug(VideoReceiverLog) << "Not recording!"; qCDebug(VideoReceiverLog) << "Not recording!";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onStopRecordingComplete(STATUS_INVALID_STATE); emit onStopRecordingComplete(STATUS_INVALID_STATE);
}); });
return; return;
@ -568,7 +568,7 @@ GstVideoReceiver::stopRecording(void)
// FIXME: AV: it is much better to emit onStopRecordingComplete() after recording is really stopped // FIXME: AV: it is much better to emit onStopRecordingComplete() after recording is really stopped
// (which happens later due to async design) but as for now it is also not so bad... // (which happens later due to async design) but as for now it is also not so bad...
_notificationHandler.dispatch([this, ret](){ _dispatchNotification([this, ret](){
emit onStopRecordingComplete(ret ? STATUS_OK : STATUS_FAIL); emit onStopRecordingComplete(ret ? STATUS_OK : STATUS_FAIL);
}); });
} }
@ -585,7 +585,7 @@ GstVideoReceiver::takeScreenshot(const QString& imageFile)
} }
// FIXME: AV: record screenshot here // FIXME: AV: record screenshot here
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit onTakeScreenshotComplete(STATUS_NOT_IMPLEMENTED); emit onTakeScreenshotComplete(STATUS_NOT_IMPLEMENTED);
}); });
} }
@ -612,7 +612,7 @@ GstVideoReceiver::_watchdog(void)
if (now - _lastSourceFrameTime > _timeout) { if (now - _lastSourceFrameTime > _timeout) {
qCDebug(VideoReceiverLog) << "Stream timeout, no frames for " << now - _lastSourceFrameTime; qCDebug(VideoReceiverLog) << "Stream timeout, no frames for " << now - _lastSourceFrameTime;
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit timeout(); emit timeout();
}); });
} }
@ -624,7 +624,7 @@ GstVideoReceiver::_watchdog(void)
if (now - _lastVideoFrameTime > _timeout * 2) { if (now - _lastVideoFrameTime > _timeout * 2) {
qCDebug(VideoReceiverLog) << "Video decoder timeout, no frames for " << now - _lastVideoFrameTime; qCDebug(VideoReceiverLog) << "Video decoder timeout, no frames for " << now - _lastVideoFrameTime;
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit timeout(); emit timeout();
}); });
} }
@ -932,7 +932,7 @@ GstVideoReceiver::_onNewSourcePad(GstPad* pad)
if (!_streaming) { if (!_streaming) {
_streaming = true; _streaming = true;
qCDebug(VideoReceiverLog) << "Streaming started"; qCDebug(VideoReceiverLog) << "Streaming started";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit streamingChanged(); emit streamingChanged();
}); });
} }
@ -1059,7 +1059,7 @@ GstVideoReceiver::_addVideoSink(GstPad* pad)
_decoding = true; _decoding = true;
qCDebug(VideoReceiverLog) << "Decoding started"; qCDebug(VideoReceiverLog) << "Decoding started";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit decodingChanged(); emit decodingChanged();
}); });
@ -1179,7 +1179,7 @@ GstVideoReceiver::_shutdownDecodingBranch(void)
if (_decoding) { if (_decoding) {
_decoding = false; _decoding = false;
qCDebug(VideoReceiverLog) << "Decoding stopped"; qCDebug(VideoReceiverLog) << "Decoding stopped";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit decodingChanged(); emit decodingChanged();
}); });
} }
@ -1200,7 +1200,7 @@ GstVideoReceiver::_shutdownRecordingBranch(void)
if (_recording) { if (_recording) {
_recording = false; _recording = false;
qCDebug(VideoReceiverLog) << "Recording stopped"; qCDebug(VideoReceiverLog) << "Recording stopped";
_notificationHandler.dispatch([this](){ _dispatchNotification([this](){
emit recordingChanged(); emit recordingChanged();
}); });
} }
@ -1208,6 +1208,12 @@ GstVideoReceiver::_shutdownRecordingBranch(void)
GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(_pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "pipeline-recording-stopped"); GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(_pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "pipeline-recording-stopped");
} }
void
GstVideoReceiver::_dispatchNotification(std::function<void()> notification)
{
_notificationHandler.dispatch(notification);
}
gboolean gboolean
GstVideoReceiver::_onBusMessage(GstBus* bus, GstMessage* msg, gpointer data) GstVideoReceiver::_onBusMessage(GstBus* bus, GstMessage* msg, gpointer data)
{ {

2
src/VideoReceiver/GstVideoReceiver.h

@ -122,6 +122,8 @@ protected:
virtual void _shutdownDecodingBranch (void); virtual void _shutdownDecodingBranch (void);
virtual void _shutdownRecordingBranch(void); virtual void _shutdownRecordingBranch(void);
void _dispatchNotification(std::function<void()> notification);
private: private:
static gboolean _onBusMessage(GstBus* bus, GstMessage* message, gpointer user_data); static gboolean _onBusMessage(GstBus* bus, GstMessage* message, gpointer user_data);
static void _onNewPad(GstElement* element, GstPad* pad, gpointer data); static void _onNewPad(GstElement* element, GstPad* pad, gpointer data);

Loading…
Cancel
Save