Skip to content

Commit 405e1ba

Browse files
committed
enhancement #9: fix windows code after android refactoring
1 parent a2113c4 commit 405e1ba

File tree

7 files changed

+33
-99
lines changed

7 files changed

+33
-99
lines changed

Plugin/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ set(SOURCE_FILES
2222
src/GstBasePipeline.cpp
2323
src/GstAVPipeline.cpp
2424
src/GstAVPipeline.h
25+
src/GstAVPipelineD3D11.h
26+
src/GstAVPipelineD3D11.cpp
2527
src/GstMicPipeline.cpp
2628
src/GstMicPipeline.h
2729
src/GstDataPipeline.cpp
@@ -30,6 +32,7 @@ set(SOURCE_FILES
3032
src/Unity/IUnityGraphics.h
3133
src/Unity/IUnityGraphicsD3D11.h
3234
src/Unity/IUnityInterface.h
35+
src/Unity/PlatformBase.h
3336
)
3437

3538
link_directories(${GST_LIBRARY_DIRS})

Plugin/src/GstAVPipeline.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class GstAVPipeline : public GstBasePipeline
1818
~GstAVPipeline();
1919

2020
void CreatePipeline(const char* uri, const char* remote_peer_id);
21-
void CreateDevice();
2221
virtual void ReleaseTexture(void* texture) = 0;
2322

2423
protected:

Plugin/src/GstAVPipelineD3D11.cpp

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -310,37 +310,6 @@ GstElement* GstAVPipelineD3D11::add_wasapi2sink(GstElement* pipeline)
310310
return wasapi2sink;
311311
}
312312

313-
GstElement* GstAVPipelineD3D11::add_webrtcsrc(GstElement* pipeline, const std::string& remote_peer_id, const std::string& uri,
314-
GstAVPipelineD3D11* self)
315-
{
316-
GstElement* webrtcsrc = gst_element_factory_make("webrtcsrc", nullptr);
317-
if (!webrtcsrc)
318-
{
319-
Debug::Log("Failed to create webrtcsrc", Level::Error);
320-
return nullptr;
321-
}
322-
323-
GObject* signaller;
324-
g_object_get(webrtcsrc, "signaller", &signaller, nullptr);
325-
if (signaller)
326-
{
327-
g_object_set(signaller, "producer-peer-id", remote_peer_id.c_str(), "uri", uri.c_str(), nullptr);
328-
g_signal_connect(G_OBJECT(signaller), "webrtcbin-ready", G_CALLBACK(webrtcbin_ready), self);
329-
g_object_unref(signaller); // Unref signaller when done
330-
}
331-
else
332-
{
333-
Debug::Log("Failed to get signaller property from webrtcsrc.", Level::Error);
334-
}
335-
336-
g_object_set(webrtcsrc, "stun-server", nullptr, "do-retransmission", false, nullptr);
337-
338-
g_signal_connect(G_OBJECT(webrtcsrc), "pad-added", G_CALLBACK(on_pad_added), self);
339-
340-
gst_bin_add(GST_BIN(pipeline), webrtcsrc);
341-
return webrtcsrc;
342-
}
343-
344313
void GstAVPipelineD3D11::on_pad_added(GstElement* src, GstPad* new_pad, gpointer data)
345314
{
346315
GstAVPipelineD3D11* avpipeline = static_cast<GstAVPipelineD3D11*>(data);
@@ -419,23 +388,17 @@ void GstAVPipelineD3D11::on_pad_added(GstElement* src, GstPad* new_pad, gpointer
419388
g_free(pad_name);
420389
}
421390

422-
void GstAVPipelineD3D11::webrtcbin_ready(GstElement* self, gchararray peer_id, GstElement* webrtcbin, gpointer udata)
423-
{
424-
Debug::Log("Configure webrtcbin", Level::Info);
425-
g_object_set(webrtcbin, "latency", 1, nullptr);
426-
}
427-
428-
void GstAVPipelineD3D11::ReleaseTexture(ID3D11Texture2D* texture)
391+
void GstAVPipelineD3D11::ReleaseTexture(void* texture)
429392
{
430393
if (texture != nullptr)
431394
{
432-
texture->Release();
395+
((ID3D11Texture2D*)(texture))->Release();
433396
texture = nullptr;
434397
}
435398
}
436399

437400
GstAVPipelineD3D11::GstAVPipelineD3D11(IUnityInterfaces* s_UnityInterfaces)
438-
: GstBasePipeline("AVPipeline"), _s_UnityInterfaces(s_UnityInterfaces)
401+
: GstAVPipeline(s_UnityInterfaces)
439402
{
440403
// preload plugins before Unity XR plugin
441404
preloaded_plugins.push_back(gst_plugin_load_by_name("rswebrtc"));
@@ -487,31 +450,6 @@ GstAVPipelineD3D11::GstAVPipelineD3D11(IUnityInterfaces* s_UnityInterfaces)
487450
_render_info = GstVideoInfo();
488451
}
489452

490-
GstAVPipelineD3D11::~GstAVPipelineD3D11()
491-
{
492-
gst_clear_object(&_device);
493-
gst_object_unref(_device);
494-
495-
for (auto& plugin : preloaded_plugins)
496-
{
497-
gst_object_unref(plugin);
498-
}
499-
preloaded_plugins.clear();
500-
}
501-
502-
void GstAVPipelineD3D11::CreatePipeline(const char* uri, const char* remote_peer_id)
503-
{
504-
Debug::Log("GstAVPipelineD3D11 create pipeline", Level::Info);
505-
Debug::Log(uri, Level::Info);
506-
Debug::Log(remote_peer_id, Level::Info);
507-
508-
GstBasePipeline::CreatePipeline();
509-
510-
GstElement* webrtcsrc = add_webrtcsrc(pipeline_, remote_peer_id, uri, this);
511-
512-
CreateBusThread();
513-
}
514-
515453
void GstAVPipelineD3D11::CreateDevice()
516454
{
517455
if (_device == nullptr)

Plugin/src/GstAVPipelineD3D11.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <vector>
1313
#include <wrl.h>
1414

15-
class GstAVPipelineD3D11 : GstAVPipeline
15+
class GstAVPipelineD3D11 : public GstAVPipeline
1616
{
1717

1818
private:
@@ -34,20 +34,17 @@ class GstAVPipelineD3D11 : GstAVPipeline
3434

3535
public:
3636
GstAVPipelineD3D11(IUnityInterfaces* s_UnityInterfaces);
37-
~GstAVPipelineD3D11();
3837

3938
void Draw(bool left);
4039

41-
void CreatePipeline(const char* uri, const char* remote_peer_id);
4240
void CreateDevice();
4341
void DestroyPipeline() override;
4442

4543
ID3D11Texture2D* CreateTexture(unsigned int width, unsigned int height, bool left = true);
46-
void ReleaseTexture(ID3D11Texture2D* texture);
44+
void ReleaseTexture(void* texture) override;
4745

4846
private:
49-
static void on_pad_added(GstElement* src, GstPad* new_pad, gpointer data);
50-
static void webrtcbin_ready(GstElement* self, gchararray peer_id, GstElement* webrtcbin, gpointer udata);
47+
void on_pad_added(GstElement* src, GstPad* new_pad, gpointer data) override;
5148

5249
static GstFlowReturn GstAVPipelineD3D11::on_new_sample(GstAppSink* appsink, gpointer user_data);
5350

@@ -63,6 +60,4 @@ class GstAVPipelineD3D11 : GstAVPipeline
6360
static GstElement* add_audioconvert(GstElement* pipeline);
6461
static GstElement* add_audioresample(GstElement* pipeline);
6562
static GstElement* add_wasapi2sink(GstElement* pipeline);
66-
static GstElement* add_webrtcsrc(GstElement* pipeline, const std::string& remote_peer_id, const std::string& uri,
67-
GstAVPipelineD3D11* self);
6863
};

Plugin/src/RenderingPlugin.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#include "GstDataPipeline.h"
66
#include "Unity/IUnityGraphics.h"
77
#include "Unity/PlatformBase.h"
8-
// #include <assert.h>
8+
//#include <assert.h>
99

10-
#if UNIY_WIN
11-
#include "GstAVPipeline.h"
10+
#if UNITY_WIN
11+
#include "GstAVPipelineD3D11.h"
1212
#include "GstMicPipeline.h"
1313

1414
static std::unique_ptr<GstMicPipeline> gstMicPipeline = nullptr;
@@ -37,7 +37,7 @@ static std::unique_ptr<GstDataPipeline> gstDataPipeline = nullptr;
3737

3838
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API CreateDevice()
3939
{
40-
#if UNIY_WIN
40+
#if UNITY_WIN
4141
gstAVPipeline->CreateDevice();
4242
#endif
4343
}
@@ -55,32 +55,28 @@ extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API SetSurface(jobject su
5555
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API CreatePipeline(const char* uri, const char* remote_peer_id)
5656
{
5757
gstAVPipeline->CreatePipeline(uri, remote_peer_id);
58-
#if UNIY_WIN
58+
#if UNITY_WIN
5959
gstMicPipeline->CreatePipeline(uri, remote_peer_id);
6060
#endif
6161
}
6262

6363
extern "C" UNITY_INTERFACE_EXPORT void* UNITY_INTERFACE_API CreateTexture(unsigned int width, unsigned int height, bool left)
6464
{
65-
#if UNIY_WIN
65+
#if UNITY_WIN
6666
return gstAVPipeline->CreateTexture(width, height, left);
6767
#endif
6868
return nullptr;
6969
}
7070

7171
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API ReleaseTexture(void* texPtr)
7272
{
73-
#if UNIY_WIN
74-
gstAVPipeline->ReleaseTexture((ID3D11Texture2D*)texPtr);
75-
#elif UNITY_ANDROID
7673
gstAVPipeline->ReleaseTexture(texPtr);
77-
#endif
7874
}
7975

8076
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API DestroyPipeline()
8177
{
8278
gstAVPipeline->DestroyPipeline();
83-
#if UNIY_WIN
79+
#if UNITY_WIN
8480
gstMicPipeline->DestroyPipeline();
8581
#endif
8682
}
@@ -124,11 +120,11 @@ extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnit
124120
{
125121
// const char* internalStoragePath = getenv("EXTERNAL_STORAGE");
126122
// td::string logFilePath = std::string(internalStoragePath) + "/gstreamer.log";
127-
setenv("GST_DEBUG_FILE", "/storage/emulated/0/Android/data/com.DefaultCompany.UnityProject/files/gstreamer.log", 1);
123+
/* setenv("GST_DEBUG_FILE", "/storage/emulated/0/Android/data/com.DefaultCompany.UnityProject/files/gstreamer.log", 1);
128124
setenv("GST_DEBUG_NO_COLOR", "1", 1);
129-
setenv("GST_DEBUG", "4", 1);
125+
setenv("GST_DEBUG", "4", 1);*/
130126

131-
#if UNIY_WIN
127+
#if UNITY_WIN
132128
gst_init(nullptr, nullptr);
133129
gstAVPipeline = std::make_unique<GstAVPipelineD3D11>(unityInterfaces);
134130
gstMicPipeline = std::make_unique<GstMicPipeline>();
@@ -153,7 +149,7 @@ extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload()
153149

154150
static void UNITY_INTERFACE_API OnRenderEvent(int eventID)
155151
{
156-
#if UNIY_WIN
152+
#if UNITY_WIN
157153
if (eventID == 1)
158154
{
159155
gstAVPipeline->Draw(true);
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:ac7fca39f57c511564e4b0125c0cd73926022b9f0f5813382e3d92a03fbfb272
3-
size 53248
2+
oid sha256:b7363bc077870c1aa62963825dd3263e2314a43e9c65ab2d7ac8597b2dc5ab37
3+
size 54272

UnityProject/Packages/com.pollenrobotics.gstreamerwebrtc/Runtime/Scripts/GstreamerRenderingPlugin.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class GStreamerRenderingPlugin
4343
private IntPtr leftTextureNativePtr;
4444

4545
private IntPtr rightTextureNativePtr;
46-
private bool nativeTexPtrSet = false;
4746

4847
private string _signallingServerURL;
4948
private BaseSignalling _signalling;
@@ -64,6 +63,9 @@ public class GStreamerRenderingPlugin
6463
private bool _autoreconnect = false;
6564

6665
#if UNITY_ANDROID
66+
67+
private bool nativeTexPtrSet = false;
68+
6769
private class PluginCallback : AndroidJavaProxy
6870
{
6971
private Action<int> callback;
@@ -119,6 +121,7 @@ public GStreamerRenderingPlugin(string ip_address, ref Texture leftTexture, ref
119121
#endif
120122
}
121123

124+
#if UNITY_ANDROID
122125
public bool IsNativePtrSet()
123126
{
124127
return nativeTexPtrSet;
@@ -136,7 +139,7 @@ public Texture SetTextures(bool left)
136139
else
137140
return CreateRenderTexture(left, ref rightTextureNativePtr);
138141
}
139-
142+
#endif
140143

141144
public void Connect()
142145
{
@@ -210,12 +213,12 @@ public void Cleanup()
210213
public void Render()
211214
{
212215
#if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN)
213-
if (_started)
214-
{
215-
_command.Clear();
216-
_command.IssuePluginEvent(GetRenderEventFunc(), 1);
217-
Graphics.ExecuteCommandBuffer(_command);
218-
}
216+
if (_started)
217+
{
218+
_command.Clear();
219+
_command.IssuePluginEvent(GetRenderEventFunc(), 1);
220+
Graphics.ExecuteCommandBuffer(_command);
221+
}
219222
#endif
220223
}
221224

0 commit comments

Comments
 (0)