From: Haesu Gwon Date: Fri, 24 Jun 2022 06:43:54 +0000 (+0900) Subject: [MediaTool] Add new Create API to support increasing ref count (#4321) X-Git-Tag: accepted/tizen/unified/20231205.024657~889 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3e38d4f8c1a9e067800da267dddf331c78772b98;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [MediaTool] Add new Create API to support increasing ref count (#4321) * [MediaTool] Add new Create API to support increasing ref count --- diff --git a/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs b/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs index 2eba43e..d088bbf 100644 --- a/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs +++ b/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs @@ -23,6 +23,9 @@ namespace Tizen.Multimedia { internal static class MediaPacket { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void DisposedCallback(IntPtr handle, IntPtr userData); + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_create")] internal static extern int Create(IntPtr format, IntPtr finalizeCb, IntPtr cbData, out IntPtr handle); @@ -32,6 +35,18 @@ namespace Tizen.Multimedia [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_destroy")] internal static extern int Destroy(IntPtr handle); + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_new")] + internal static extern int New(IntPtr format, IntPtr disposedCb, IntPtr cbData, out IntPtr handle); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_ref")] + internal static extern int Ref(IntPtr handle); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_unref")] + internal static extern int Unref(IntPtr handle); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_add_dispose_cb")] + internal static extern int AddDisposedCallback(IntPtr handle, DisposedCallback disposedCb, IntPtr userData, out int callbackId); + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_format")] internal static extern int GetFormat(IntPtr handle, out IntPtr format); diff --git a/src/Tizen.Multimedia/MediaTool/MediaPacket.cs b/src/Tizen.Multimedia/MediaTool/MediaPacket.cs index 27fc69b..b492ade 100644 --- a/src/Tizen.Multimedia/MediaTool/MediaPacket.cs +++ b/src/Tizen.Multimedia/MediaTool/MediaPacket.cs @@ -52,6 +52,16 @@ namespace Tizen.Multimedia } /// + /// Initializes a new instance of the MediaPacket class from an original MediaPacket. + /// + /// The original MediaPacket. + internal MediaPacket(MediaPacket mediaPacket) : this(mediaPacket._handle) + { + int ret = Native.Ref(_handle); + MultimediaDebug.AssertNoError(ret); + } + + /// /// Initializes a new instance of the MediaPacket class from a native handle. /// /// The native handle to be used. @@ -60,7 +70,6 @@ namespace Tizen.Multimedia _handle = handle; int ret = Native.GetFormat(handle, out IntPtr formatHandle); - MultimediaDebug.AssertNoError(ret); try @@ -105,7 +114,7 @@ namespace Tizen.Multimedia { formatHandle = format.AsNativeHandle(); - int ret = Native.Create(formatHandle, IntPtr.Zero, IntPtr.Zero, out _handle); + int ret = Native.New(formatHandle, IntPtr.Zero, IntPtr.Zero, out _handle); MultimediaDebug.AssertNoError(ret); Debug.Assert(_handle != IntPtr.Zero, "Created handle must not be null"); @@ -116,7 +125,7 @@ namespace Tizen.Multimedia { if (_handle != IntPtr.Zero) { - Native.Destroy(_handle); + Native.Unref(_handle); _handle = IntPtr.Zero; } @@ -153,7 +162,6 @@ namespace Tizen.Multimedia default: throw new InvalidOperationException("Failed to create a packet."); } - } private readonly MediaFormat _format; @@ -174,7 +182,7 @@ namespace Tizen.Multimedia /// /// Gets or sets the PTS(Presentation Time Stamp) value of the current packet in nanoseconds. /// - /// The MediaPacket has already been disposed of. + /// The MediaPacket has already been disposed. /// /// The MediaPacket is not in the writable state, which means it is being used by another module. /// @@ -186,7 +194,6 @@ namespace Tizen.Multimedia ValidateNotDisposed(); int ret = Native.GetPts(_handle, out var value); - MultimediaDebug.AssertNoError(ret); return value; @@ -197,7 +204,6 @@ namespace Tizen.Multimedia ValidateNotLocked(); int ret = Native.SetPts(_handle, value); - MultimediaDebug.AssertNoError(ret); } } @@ -205,7 +211,7 @@ namespace Tizen.Multimedia /// /// Gets or sets the DTS(Decoding Time Stamp) value of the current packet in nanoseconds. /// - /// The MediaPacket has already been disposed of. + /// The MediaPacket has already been disposed. /// /// The MediaPacket is not in the writable state, which means it is being used by another module. /// @@ -234,7 +240,7 @@ namespace Tizen.Multimedia /// /// Gets or sets the duration value of the current packet in nanoseconds. /// - /// The MediaPacket has already been disposed of. + /// The MediaPacket has already been disposed. /// /// The MediaPacket is not in the writable state, which means it is being used by another module. /// @@ -264,7 +270,7 @@ namespace Tizen.Multimedia /// Gets a value indicating whether the packet is the encoded type. /// /// true if the packet is the encoded type; otherwise, false. - /// The MediaPacket has already been disposed of. + /// The MediaPacket has already been disposed. /// 3 public bool IsEncoded { @@ -283,7 +289,7 @@ namespace Tizen.Multimedia /// Gets or sets the rotation value of the current packet. /// /// The specified value to set is invalid. - /// The MediaPacket has already been disposed of. + /// The MediaPacket has already been disposed. /// /// The MediaPacket is not in the writable state, which means it is being used by another module. /// @@ -319,7 +325,7 @@ namespace Tizen.Multimedia /// will be ignored in set case. It's not supported in Native FW. /// /// The specified value to set is invalid. - /// The MediaPacket has already been disposed of. + /// The MediaPacket has already been disposed. /// /// The MediaPacket is not in the writable state, which means it is being used by another module. /// @@ -365,7 +371,7 @@ namespace Tizen.Multimedia /// The allocated to the packet. /// This property will return null if the packet is in the raw video format. /// - /// The MediaPacket has already been disposed of. + /// The MediaPacket has already been disposed. /// /// /// 3 @@ -387,7 +393,7 @@ namespace Tizen.Multimedia /// /// Gets or sets a length of data written in the . /// - /// The MediaPacket has already been disposed of. + /// The MediaPacket has already been disposed. /// /// The value specified for this property is less than zero or greater than the length of the . /// @@ -440,7 +446,7 @@ namespace Tizen.Multimedia /// /// The s allocated to the packet. /// This property will return null if the packet is not in the raw video format. - /// The MediaPacket has already been disposed of. + /// The MediaPacket has already been disposed. /// /// /// 3 @@ -467,7 +473,7 @@ namespace Tizen.Multimedia /// /// Gets or sets the buffer flags of the packet. /// - /// The MediaPacket has already been disposed of. + /// The MediaPacket has already been disposed. /// /// The MediaPacket is not in the writable state, which means it is being used by another module. /// @@ -479,30 +485,26 @@ namespace Tizen.Multimedia ValidateNotDisposed(); int ret = Native.GetBufferFlags(_handle, out var value); - MultimediaDebug.AssertNoError(ret); return value; } - set { ValidateNotDisposed(); ValidateNotLocked(); int ret = Native.ResetBufferFlags(_handle); - MultimediaDebug.AssertNoError(ret); ret = Native.SetBufferFlags(_handle, (int)value); - MultimediaDebug.AssertNoError(ret); } } #region Dispose support /// - /// Gets a value indicating whether the packet has been disposed of. + /// Gets a value indicating whether the packet has been disposed. /// /// true if the packet has been disposed of; otherwise, false. /// 3 @@ -545,7 +547,7 @@ namespace Tizen.Multimedia if (_handle != IntPtr.Zero) { - Native.Destroy(_handle); + Native.Unref(_handle); _handle = IntPtr.Zero; } @@ -553,14 +555,14 @@ namespace Tizen.Multimedia } /// - /// Validates the current object has not been disposed of. + /// Validates the current object has not been disposed. /// - /// The MediaPacket has already been disposed of. + /// The MediaPacket has already been disposed. private void ValidateNotDisposed() { if (_isDisposed) { - throw new ObjectDisposedException("This packet has already been disposed of."); + throw new ObjectDisposedException("This packet has already been disposed."); } } #endregion @@ -577,7 +579,7 @@ namespace Tizen.Multimedia /// /// Ensures whether the packet is writable. /// - /// The MediaPacket has already been disposed of. + /// The MediaPacket has already been disposed. /// The MediaPacket is being used by another module. internal void EnsureWritableState() { @@ -588,7 +590,7 @@ namespace Tizen.Multimedia /// /// Ensures whether the packet is readable. /// - /// The MediaPacket has already been disposed of. + /// The MediaPacket has already been disposed. internal void EnsureReadableState() { ValidateNotDisposed(); @@ -609,7 +611,6 @@ namespace Tizen.Multimedia Debug.Assert(_handle != IntPtr.Zero, "The handle is invalid!"); int ret = Native.GetNumberOfVideoPlanes(_handle, out var numberOfPlanes); - MultimediaDebug.AssertNoError(ret); MediaPacketVideoPlane[] planes = new MediaPacketVideoPlane[numberOfPlanes]; @@ -656,6 +657,22 @@ namespace Tizen.Multimedia return new SimpleMediaPacket(format); } + /// + /// Creates an object of the MediaPacket based on the original MediaPacket and increases the internal reference(hereafter ref) count by 1. + /// + /// + /// This method can be useful when user share MediaPacket instance to other module and don't know the exact time to dispose it.\n + /// In this case, user creates a new instance with and shares it to other module.\n + /// And then, each MediaPacket instances can be disposed independently without concerning other instance's life cycle. + /// + /// The media packet to increase ref count. + /// A MediaPacket object which is based on original MediaPacket instance. + /// 10 + public static MediaPacket Create(MediaPacket mediaPacket) + { + return new SimpleMediaPacket(mediaPacket); + } + internal static MediaPacket From(IntPtr handle) { return new SimpleMediaPacket(handle); @@ -675,5 +692,9 @@ namespace Tizen.Multimedia internal SimpleMediaPacket(IntPtr handle) : base(handle) { } + + internal SimpleMediaPacket(MediaPacket mediaPacket) : base(mediaPacket) + { + } } }