[WebRTC] Disable MediaPacket native handle destroy (#4642)
authorHaesu Gwon <haesu.gwon@samsung.com>
Tue, 11 Oct 2022 06:54:42 +0000 (15:54 +0900)
committerGitHub <noreply@github.com>
Tue, 11 Oct 2022 06:54:42 +0000 (15:54 +0900)
* [WebRTC] Disable MediaPacket native handle destroy

src/Tizen.Multimedia.Remoting/WebRTC/MediaPacketSource.cs
src/Tizen.Multimedia/MediaTool/MediaPacket.cs

index 6ead6c7..09fea00 100755 (executable)
@@ -225,6 +225,9 @@ namespace Tizen.Multimedia.Remoting
                 throw new ArgumentException("Audio is not configured with the current source.");
             }
 
+            // MediaPacket native handle will be destroyed internally in native webrtc fw
+            packet.DisableNativeHandleDestroy();
+
             NativeWebRTC.PushMediaPacket(WebRtc.Handle, SourceId.Value, packet.GetHandle()).
                 ThrowIfFailed("Failed to push the packet to the WebRTC");
         }
index b492ade..affdc4d 100644 (file)
@@ -547,7 +547,11 @@ namespace Tizen.Multimedia
 
             if (_handle != IntPtr.Zero)
             {
-                Native.Unref(_handle);
+                if (_isNativeHandleDestroyEnabled)
+                {
+                    Native.Unref(_handle);
+                }
+
                 _handle = IntPtr.Zero;
             }
 
@@ -565,6 +569,15 @@ namespace Tizen.Multimedia
                 throw new ObjectDisposedException("This packet has already been disposed.");
             }
         }
+
+        private bool _isNativeHandleDestroyEnabled = true;
+        /// <summary>
+        /// Disables native handle destruction when native fw destroys media packet handle itself.
+        /// </summary>
+        internal void DisableNativeHandleDestroy()
+        {
+            _isNativeHandleDestroyEnabled = false;
+        }
         #endregion
 
         internal IntPtr GetHandle()