Skip to content

Commit 687c63c

Browse files
committed
enhancement #9: cleanup c sharp
1 parent ae0a00e commit 687c63c

File tree

4 files changed

+32
-100
lines changed

4 files changed

+32
-100
lines changed

Plugin/src/RenderingPlugin.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API CreateDevice()
3737
{
3838
#if UNIY_WIN
3939
gstAVPipeline->CreateDevice();
40-
#elif UNITY_ANDROID
41-
// GstAVPipelineOpenGLES* avpipeline = static_cast<GstAVPipelineOpenGLES*>(gstAVPipeline.get());
42-
// ms2_vm->AttachCurrentThread(&jni_env, 0);
43-
// avpipeline->CreateNativeWindow(jni_env);
44-
// avpipeline->SetNativeWindow(jni_env, surface_plugin);
4540
#endif
4641
}
4742

@@ -71,11 +66,6 @@ extern "C" UNITY_INTERFACE_EXPORT void* UNITY_INTERFACE_API CreateTexture(unsign
7166
return nullptr;
7267
}
7368

74-
/* extern "C" UNITY_INTERFACE_EXPORT void* UNITY_INTERFACE_API GetTexturePtr(bool left)
75-
{
76-
return gstAVPipeline->GetTexturePtr(left);
77-
}*/
78-
7969
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API ReleaseTexture(void* texPtr)
8070
{
8171
#if UNIY_WIN
@@ -115,11 +105,13 @@ extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API SendBytesChannelComma
115105
gstDataPipeline->send_byte_array_channel_command(data, size);
116106
}
117107

108+
#if UNITY_ANDROID
118109
extern "C" JNIEXPORT void JNICALL Java_com_pollenrobotics_gstreamer_RenderingCallbackManager_nativeInit(JNIEnv* env,
119110
jobject obj)
120111
{
121112
gCallbackObject = env->NewGlobalRef(obj);
122113
}
114+
#endif
123115

124116
// --------------------------------------------------------------------------
125117
// UnitySetInterfaces
@@ -138,7 +130,6 @@ extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnit
138130
gstMicPipeline = std::make_unique<GstMicPipeline>();
139131
#elif UNITY_ANDROID
140132
// gst_init done in the java side
141-
// gst_init(nullptr, nullptr);
142133
gstAVPipeline = std::make_unique<GstAVPipelineOpenGLES>(unityInterfaces);
143134
#endif
144135

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:c1780dca1e4e9ad08fcfd39cd3b2bc762251f21c4452f1e004f16b24cc5c8ff0
2+
oid sha256:d361b531cbd839afff01f8b52230ce3ec1c8c37047e7dab76eec0d2beb9316ef
33
size 95904

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

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,6 @@ namespace GstreamerWebRTC
1515
{
1616
public class GStreamerPlugin : MonoBehaviour
1717
{
18-
19-
/*[DllImport("UnityGStreamerPlugin")]
20-
private static extern IntPtr GetRenderEventFunc();
21-
22-
private class PluginTestCallback : AndroidJavaProxy
23-
{
24-
private Action<int> callback;
25-
public PluginTestCallback(Action<int> callback) : base("com.pollenrobotics.unityproject.TestPlugin$OnInitializedListener")
26-
{
27-
this.callback = callback;
28-
}
29-
private void onInitialized(int textureId){
30-
this.callback(textureId);
31-
}
32-
}*/
33-
3418
[Tooltip("RawImage on which the left texture will be rendered")]
3519
public RawImage leftRawImage;
3620
[Tooltip("RawImage on which the right texture will be rendered")]
@@ -84,38 +68,6 @@ void Start()
8468

8569
protected virtual void InitAV()
8670
{
87-
88-
/*AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
89-
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
90-
91-
// Obtenez l'instance de votre classe OverrideExample
92-
AndroidJavaObject overrideExample = new AndroidJavaObject("com.pollenrobotics.unityproject.OverrideExample", activity);
93-
94-
/*using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.pollenrobotics.unityproject.OverrideExample"))
95-
using (AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("instance"))
96-
currentActivity.Call<AndroidJavaObject>("Hello from C#!");*/
97-
98-
//surfaceView =(unityPlayer.view as FrameLayout).child(0) as SurfaceView;
99-
// Appelez la méthode showMessage
100-
/*overrideExample.Call("showMessage", "Hello from C#!");
101-
Debug.Log("here2");*/
102-
103-
/* CommandBuffer commandBuffer = new CommandBuffer();
104-
commandBuffer.IssuePluginEvent(GetRenderEventFunc(), 1);
105-
Camera.main.AddCommandBuffer(CameraEvent.BeforeSkybox, commandBuffer);
106-
107-
new AndroidJavaClass("com.pollenrobotics.unityproject.TestPlugin")
108-
.CallStatic(
109-
"TestRenderingTexture",
110-
960,
111-
720,
112-
new PluginTestCallback(texId=>{
113-
nativeTexPtr = (IntPtr)texId;
114-
nativeTexPtrSet = true;
115-
})
116-
);*/
117-
118-
11971
if (leftRawImage == null)
12072
Debug.LogError("Left image is not assigned!");
12173

@@ -124,27 +76,28 @@ protected virtual void InitAV()
12476

12577
Texture left = null, right = null;
12678
renderingPlugin = new GStreamerRenderingPlugin(ip_address, ref left, ref right);
79+
#if UNITY_ANDROID
12780
StartCoroutine(WaitForNativePointer(renderingPlugin));
128-
//leftRawImage.texture = left;
129-
//rightRawImage.texture = right;
130-
/*renderingPlugin.event_OnPipelineStarted.AddListener(PipelineStarted);
81+
#elif (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN)
82+
leftRawImage.texture = left;
83+
rightRawImage.texture = right;
84+
renderingPlugin.event_OnPipelineStarted.AddListener(PipelineStarted);
13185
renderingPlugin.event_OnPipelineStopped.AddListener(PipelineStopped);
132-
renderingPlugin.Connect();*/
86+
renderingPlugin.Connect();
87+
#endif
13388
}
13489

90+
#if UNITY_ANDROID
13591
private IEnumerator WaitForNativePointer(GStreamerRenderingPlugin renderingPlugin)
13692
{
13793
yield return new WaitUntil(()=>renderingPlugin.IsNativePtrSet());
138-
//Texture2D texture2D = Texture2D.CreateExternalTexture(960,720, TextureFormat.RGBA32, false, true, nativeTexPtr);
139-
// Debug.Log($"texture created: ${nativeTexPtr}");
140-
//rawImage.texture = texture2D;
141-
//leftRawImage.texture = texture2D;*/
14294
leftRawImage.texture = renderingPlugin.SetTextures(true);
14395
rightRawImage.texture = renderingPlugin.SetTextures(false);
14496
renderingPlugin.event_OnPipelineStarted.AddListener(PipelineStarted);
14597
renderingPlugin.event_OnPipelineStopped.AddListener(PipelineStopped);
14698
renderingPlugin.Connect();
14799
}
100+
#endif
148101

149102
protected virtual void InitData()
150103
{

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

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,16 @@ namespace GstreamerWebRTC
1414
{
1515
public class GStreamerRenderingPlugin
1616
{
17-
/*
18-
#if PLATFORM_SWITCH && !UNITY_EDITOR
19-
[DllImport("__Internal")]
20-
private static extern void RegisterPlugin();
21-
#endif*/
22-
2317
[DllImport("UnityGStreamerPlugin")]
2418
private static extern void CreatePipeline(string uri, string remote_peer_id);
2519

2620
[DllImport("UnityGStreamerPlugin")]
2721
private static extern void CreateDevice();
2822

23+
#if UNITY_ANDROID
2924
[DllImport("UnityGStreamerPlugin")]
3025
private static extern void SetSurface(IntPtr surface, bool left);
26+
#endif
3127

3228
[DllImport("UnityGStreamerPlugin")]
3329
private static extern void DestroyPipeline();
@@ -67,11 +63,11 @@ public class GStreamerRenderingPlugin
6763

6864
private bool _autoreconnect = false;
6965

70-
71-
private class PluginTestCallback : AndroidJavaProxy
66+
#if UNITY_ANDROID
67+
private class PluginCallback : AndroidJavaProxy
7268
{
7369
private Action<int> callback;
74-
public PluginTestCallback(Action<int> callback) : base("com.pollenrobotics.gstreamer.GstreamerActivity$OnInitializedListener")
70+
public PluginCallback(Action<int> callback) : base("com.pollenrobotics.gstreamer.GstreamerActivity$OnInitializedListener")
7571
{
7672
this.callback = callback;
7773
}
@@ -80,6 +76,7 @@ private void onInitialized(int textureId)
8076
this.callback(textureId);
8177
}
8278
}
79+
#endif
8380

8481

8582
public GStreamerRenderingPlugin(string ip_address, ref Texture leftTexture, ref Texture rightTexture)
@@ -97,43 +94,30 @@ public GStreamerRenderingPlugin(string ip_address, ref Texture leftTexture, ref
9794
event_OnPipelineStopped = new UnityEvent();
9895
_command = new CommandBuffer();
9996

100-
/*AndroidJavaObject surfaceView = GetUnitySurfaceView();
101-
if (surfaceView != null)
102-
{
103-
Debug.Log("SurfaceView obtenue avec succès!");
104-
// Vous pouvez maintenant utiliser surfaceView comme vous le souhaitez
105-
}
106-
else
107-
{
108-
Debug.LogError("Impossible d'obtenir la SurfaceView.");
109-
}
110-
SetSurface(surfaceView.GetRawObject());*/
111-
97+
#if UNITY_ANDROID
11298
_command.IssuePluginEvent(GetRenderEventFunc(), 1);
11399
Camera.main.AddCommandBuffer(CameraEvent.BeforeSkybox, _command);
114-
//Graphics.ExecuteCommandBuffer(_command);
115100

116101
new AndroidJavaClass("com.pollenrobotics.gstreamer.GstreamerActivity")
117102
.CallStatic(
118103
"InitExternalTexture",
119104
(int)width,
120105
(int)height,
121-
new PluginTestCallback(texId =>
106+
new PluginCallback(texId =>
122107
{
123108
leftTextureNativePtr = (IntPtr)texId;
124109
}),
125-
new PluginTestCallback(texId =>
110+
new PluginCallback(texId =>
126111
{
127112
rightTextureNativePtr = (IntPtr)texId;
128113
nativeTexPtrSet = true;
129114
})
130115
);
131-
//StartCoroutine(WaitForNativePointer(ref leftTexture));
132-
116+
#elif (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN)
133117
CreateDevice();
134-
//leftTexture = CreateRenderTexture(true, ref leftTextureNativePtr);
135-
//rightTexture = CreateRenderTexture(false, ref rightTextureNativePtr);
136-
//StartCoroutine(WaitOneFrame(ref leftTexture, ref rightTexture));
118+
leftTexture = CreateRenderTexture(true, ref leftTextureNativePtr);
119+
rightTexture = CreateRenderTexture(false, ref rightTextureNativePtr);
120+
#endif
137121
}
138122

139123
public bool IsNativePtrSet()
@@ -166,7 +150,9 @@ public void Connect()
166150

167151
Texture CreateRenderTexture(bool left, ref IntPtr textureNativePtr)
168152
{
169-
//textureNativePtr = CreateTexture(width, height, left);
153+
#if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN)
154+
textureNativePtr = CreateTexture(width, height, left);
155+
#endif
170156

171157
if (textureNativePtr != IntPtr.Zero)
172158
{
@@ -222,12 +208,14 @@ public void Cleanup()
222208

223209
public void Render()
224210
{
225-
/*if (_started)
211+
#if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN)
212+
if (_started)
226213
{
227214
_command.Clear();
228215
_command.IssuePluginEvent(GetRenderEventFunc(), 1);
229216
Graphics.ExecuteCommandBuffer(_command);
230-
} */
217+
}
218+
#endif
231219
}
232220

233221
}

0 commit comments

Comments
 (0)