Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Hang in GstPipelineHandler::Stop() and VS build #49

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 54 additions & 18 deletions Plugin/VS/GStreamerUnityPlugin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|X64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
Expand Down Expand Up @@ -129,7 +129,7 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>USE_UNITY_GRABBER;USE_UNITY_NETWORK;WIN32;_DEBUG;_WINDOWS;_USRDLL;GSTREAMERUNITYPLUGIN_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>USE_UNITY_GRABBER;WIN32;_DEBUG;_WINDOWS;_USRDLL;GSTREAMERUNITYPLUGIN_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>./;../includes;../includes/Win32;../sources;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
Expand Down Expand Up @@ -163,7 +163,7 @@
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<PreprocessorDefinitions>USE_UNITY_GRABBER;__USE_UNITY_NETWORK;WIN32;NDEBUG;_WINDOWS;_USRDLL;GSTREAMERUNITYPLUGIN_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>USE_UNITY_GRABBER;WIN32;NDEBUG;_WINDOWS;_USRDLL;GSTREAMERUNITYPLUGIN_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>./;../includes;../includes/Win32;../sources;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
Expand Down Expand Up @@ -225,12 +225,27 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\includes\MutexLocks.h" />
<ClInclude Include="..\sources\CMyListener.h" />
<ClInclude Include="..\sources\CMyUDPSink.h" />
<ClInclude Include="..\sources\CMyUDPSrc.h" />
<ClInclude Include="..\sources\CMyListener.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|X64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">false</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\sources\CMyUDPSink.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|X64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\sources\CMyUDPSrc.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|X64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\sources\CustomAudioGrabber.h" />
<ClInclude Include="..\sources\DirectSoundInputStream.h" />
<ClInclude Include="..\sources\DirectSoundOutputStream.h" />
<ClInclude Include="..\sources\DirectSoundInputStream.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|X64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\sources\DirectSoundOutputStream.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|X64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\sources\GstAppAudioPlayer.h" />
<ClInclude Include="..\sources\GstAppNetAudioStreamer.h" />
<ClInclude Include="..\sources\GstAudioSampler.h" />
Expand All @@ -239,7 +254,10 @@
<ClInclude Include="..\sources\GstCustomVideoStreamer.h" />
<ClInclude Include="..\sources\GstNetworkVideoStreamer.h" />
<ClInclude Include="..\sources\GstNetworkAudioStreamer.h" />
<ClInclude Include="..\sources\GZipCompress.h" />
<ClInclude Include="..\sources\GZipCompress.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|X64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\sources\IAudioGrabber.h" />
<ClInclude Include="..\sources\NetworkAudioGrabber.h" />
<ClInclude Include="..\sources\UnityAudioGrabber.h" />
Expand Down Expand Up @@ -280,14 +298,29 @@
</ClCompile>
<ClCompile Include="../sources/IAppSinkHandler.cpp" />
<ClCompile Include="..\includes\RenderAPI_OpenGLCoreES.cpp" />
<ClCompile Include="..\sources\CMyListener.cpp" />
<ClCompile Include="..\sources\CMyUDPSink.cpp" />
<ClCompile Include="..\sources\CMyUDPSrc.cpp" />
<ClCompile Include="..\sources\CMyListener.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|X64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\sources\CMyUDPSink.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|X64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\sources\CMyUDPSrc.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|X64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\sources\CustomAudioGrabber.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|X64'">Disabled</Optimization>
</ClCompile>
<ClCompile Include="..\sources\DirectSoundInputStream.cpp" />
<ClCompile Include="..\sources\DirectSoundOutputStream.cpp" />
<ClCompile Include="..\sources\DirectSoundInputStream.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|X64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\sources\DirectSoundOutputStream.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|X64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\sources\GstAppAudioPlayer.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|X64'">Disabled</Optimization>
</ClCompile>
Expand All @@ -309,7 +342,10 @@
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|X64'">Disabled</Optimization>
</ClCompile>
<ClCompile Include="..\sources\GstNetworkVideoPlayer.cpp" />
<ClCompile Include="..\sources\GZipCompress.cpp" />
<ClCompile Include="..\sources\GZipCompress.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|X64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\sources\NetworkAudioGrabber.cpp" />
<ClCompile Include="..\sources\UnityAudioGrabber.cpp" />
<ClCompile Include="..\sources\LocalAudioGrabber.cpp" />
Expand Down
44 changes: 44 additions & 0 deletions Plugin/sources/GstCustomVideoStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class GstCustomVideoStreamerImpl : public GstPipelineHandler,
std::string m_pipeLineString;
std::string m_srcPipeLineString;

ConnectionStatusCallback m_connectionStatusCallback = nullptr;

int m_fps;
Vector2d m_frameSize;

Expand Down Expand Up @@ -60,6 +62,11 @@ class GstCustomVideoStreamerImpl : public GstPipelineHandler,
m_fps = fps;
}

void SetConnectionStatusCallback(ConnectionStatusCallback cb)
{
m_connectionStatusCallback = cb;
}

std::string GetFormatStr(EPixelFormat fmt) {
std::string format = "RGB";
switch (fmt) {
Expand Down Expand Up @@ -313,6 +320,38 @@ class GstCustomVideoStreamerImpl : public GstPipelineHandler,
virtual void OnPipelineStopped(GstPipelineHandler* p) {
m_owner->__FIRE_OnStreamerStopped(m_owner);
}
virtual void OnPipelineError(GstPipelineHandler* p, const std::string& elementName)
{
if (m_connectionStatusCallback && elementName.find("rtspclientsink") != std::string::npos)
{
m_connectionStatusCallback(false);
}
}
virtual void OnPipelineProgress(GstPipelineHandler* p, int progressType, const std::string& code, const std::string& info) override
{
if(!m_connectionStatusCallback)
{
return;
}

switch (progressType)
{
case 2: // GST_PROGRESS_TYPE_COMPLETE
if (code.find("open") != std::string::npos)
{
m_connectionStatusCallback(true);
}
break;
case 4: // GST_PROGRESS_TYPE_ERROR
if (code.find("open") != std::string::npos)
{
m_connectionStatusCallback(false);
}
break;
default:
break;
}
}
};

GstCustomVideoStreamer::GstCustomVideoStreamer() {
Expand All @@ -336,6 +375,11 @@ void GstCustomVideoStreamer::SetResolution(int width, int height, int fps) {
m_impl->SetResolution(width, height, fps);
}

void GstCustomVideoStreamer::SetConnectionStatusCallback(ConnectionStatusCallback cb)
{
m_impl->SetConnectionStatusCallback(cb);
}

void GstCustomVideoStreamer::SetVideoGrabber(IVideoGrabber* grabber0) {
m_impl->SetVideoGrabber(grabber0);
}
Expand Down
10 changes: 9 additions & 1 deletion Plugin/sources/GstCustomVideoStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ author: MHD Yamen Saraiji
#define GstCustomVideoStreamer_h__

#include "IGStreamerStreamer.h"
#include "Unity/IUnityInterface.h"
#include <string>

namespace mray
Expand All @@ -30,6 +31,12 @@ namespace video
class GstCustomVideoStreamerImpl;
class IVideoGrabber;

// Uggly fix to expose the ConnectionStatusCallback signature where relevant.
extern "C"
{
typedef void(UNITY_INTERFACE_API* ConnectionStatusCallback)(bool);
}

class GstCustomVideoStreamer :public IGStreamerStreamer
{
protected:
Expand All @@ -50,7 +57,8 @@ class GstCustomVideoStreamer :public IGStreamerStreamer
virtual void Close();

void SetVideoGrabber(IVideoGrabber* grabber0);
void SetResolution(int width, int height, int fps);
void SetResolution(int width, int height, int fps);
void SetConnectionStatusCallback(ConnectionStatusCallback cb);

virtual void SetPaused(bool paused);
virtual bool IsPaused();
Expand Down
54 changes: 40 additions & 14 deletions Plugin/sources/GstPipelineHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <gst/net/gstnet.h>

#include <mutex>
#include <string>

#include "GStreamerCore.h"
#include "IThreadManager.h"
Expand Down Expand Up @@ -368,9 +369,16 @@ long GstPipelineHandler::GetDuration() {
}
bool GstPipelineHandler::IsResettingEOS() { return m_data->_restartingEOS; }
void GstPipelineHandler::SetPaused(bool p) {
if (m_data->gstPipeline == NULL && m_data->busWatchID == 0)
{
m_data->paused = true;
m_data->Loaded = false;
m_data->playing = false;
return;
}
std::lock_guard<std::recursive_mutex> lock(GetMutex());
m_data->paused = p;
if (m_data->Loaded || true) {
if (m_data->Loaded) {
if (m_data->playing) {
GstState state;
if (m_data->paused) {
Expand Down Expand Up @@ -405,9 +413,18 @@ void GstPipelineHandler::SetPaused(bool p) {
}
}
void GstPipelineHandler::Stop() {
if (m_data->gstPipeline == NULL && m_data->busWatchID == 0)
{
m_data->paused = true;
m_data->Loaded = false;
m_data->playing = false;
return;
}

LogMessage(m_data->_name + ": GstPipelineHandler::Stop ", ELL_INFO);
if (!m_data->Loaded) return;
std::lock_guard<std::recursive_mutex> lock(GetMutex());
if (m_data->paused == true && m_data->playing == false) return;
GstState state;
m_data->_seekPos = GST_CLOCK_TIME_NONE;
// gst_element_send_event(m_data->gstPipeline, gst_event_new_eos());
Expand Down Expand Up @@ -444,11 +461,16 @@ bool GstPipelineHandler::QueryLatency(bool &isLive, ulong &minLatency,
return ok;
}
void GstPipelineHandler::Close() {
if (m_data->gstPipeline == NULL && m_data->busWatchID == 0)
{
m_data->Loaded = false;
return;
}
LogMessage(m_data->_name + ": GstPipelineHandler::Close ", ELL_INFO);
std::lock_guard<std::recursive_mutex> lock(GetMutex());
Stop();

if (true || m_data->Loaded) {
if (m_data->Loaded) {
if (m_data->busWatchID != 0) g_source_remove(m_data->busWatchID);
m_data->busWatchID = 0;

Expand Down Expand Up @@ -607,27 +629,30 @@ bool GstPipelineHandler::HandleMessage(GstBus *bus, GstMessage *msg) {
case GST_MESSAGE_PROGRESS: {
GstProgressType type;
gchar *code, *text;
bool in_progress = false;
gst_message_parse_progress(msg, &type, &code, &text);
switch (type) {
case GST_PROGRESS_TYPE_START:
case GST_PROGRESS_TYPE_CONTINUE:
in_progress = TRUE;
break;
case GST_PROGRESS_TYPE_COMPLETE:
case GST_PROGRESS_TYPE_CANCELED:
case GST_PROGRESS_TYPE_ERROR:
in_progress = FALSE;
{
const std::string progressCode(code);
const std::string progressInfo(text);
FIRE_LISTENR_METHOD(OnPipelineProgress, (this, type, progressCode, progressInfo));
}
break;
default:
break;
}
LogMessage("Progress: (" + std::string(code) + ") " + std::string(text),
ELL_INFO);
LogMessage("Progress: (" + std::to_string(type) + ") ("
+ std::string(code) + ") " + std::string(text),
ELL_INFO);
g_free(code);
g_free(text);

} break;
}
break;

case GST_MESSAGE_WARNING: {
GError *err;
Expand Down Expand Up @@ -668,15 +693,16 @@ bool GstPipelineHandler::HandleMessage(GstBus *bus, GstMessage *msg) {
std::string(" - ") + debug,
ELL_WARNING);


const std::string gstElementName(name);
if (m_data) {
FIRE_LISTENR_METHOD(OnPipelineError, (this, gstElementName));
}

g_free(name);
g_error_free(err);
g_free(debug);

if (m_data) {
FIRE_LISTENR_METHOD(OnPipelineError, (this));
// gst_element_set_state(GST_ELEMENT(m_data->gstPipeline),
// GST_STATE_NULL);
}
} break;

default:
Expand Down
Loading