}
/// <summary>
+ /// Initializes a new instance of the MediaPacket class from an original MediaPacket.
+ /// </summary>
+ /// <param name="mediaPacket">The original MediaPacket.</param>
+ internal MediaPacket(MediaPacket mediaPacket) : this(mediaPacket._handle)
+ {
+ int ret = Native.Ref(_handle);
+ MultimediaDebug.AssertNoError(ret);
+ }
+
+ /// <summary>
/// Initializes a new instance of the MediaPacket class from a native handle.
/// </summary>
/// <param name="handle">The native handle to be used.</param>
_handle = handle;
int ret = Native.GetFormat(handle, out IntPtr formatHandle);
-
MultimediaDebug.AssertNoError(ret);
try
{
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");
{
if (_handle != IntPtr.Zero)
{
- Native.Destroy(_handle);
+ Native.Unref(_handle);
_handle = IntPtr.Zero;
}
default:
throw new InvalidOperationException("Failed to create a packet.");
}
-
}
private readonly MediaFormat _format;
/// <summary>
/// Gets or sets the PTS(Presentation Time Stamp) value of the current packet in nanoseconds.
/// </summary>
- /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed of.</exception>
+ /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed.</exception>
/// <exception cref="InvalidOperationException">
/// The MediaPacket is not in the writable state, which means it is being used by another module.
/// </exception>
ValidateNotDisposed();
int ret = Native.GetPts(_handle, out var value);
-
MultimediaDebug.AssertNoError(ret);
return value;
ValidateNotLocked();
int ret = Native.SetPts(_handle, value);
-
MultimediaDebug.AssertNoError(ret);
}
}
/// <summary>
/// Gets or sets the DTS(Decoding Time Stamp) value of the current packet in nanoseconds.
/// </summary>
- /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed of.</exception>
+ /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed.</exception>
/// <exception cref="InvalidOperationException">
/// The MediaPacket is not in the writable state, which means it is being used by another module.
/// </exception>
/// <summary>
/// Gets or sets the duration value of the current packet in nanoseconds.
/// </summary>
- /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed of.</exception>
+ /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed.</exception>
/// <exception cref="InvalidOperationException">
/// The MediaPacket is not in the writable state, which means it is being used by another module.
/// </exception>
/// Gets a value indicating whether the packet is the encoded type.
/// </summary>
/// <value>true if the packet is the encoded type; otherwise, false.</value>
- /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed of.</exception>
+ /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed.</exception>
/// <since_tizen> 3 </since_tizen>
public bool IsEncoded
{
/// Gets or sets the rotation value of the current packet.
/// </summary>
/// <exception cref="ArgumentException">The specified value to set is invalid.</exception>
- /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed of.</exception>
+ /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed.</exception>
/// <exception cref="InvalidOperationException">
/// The MediaPacket is not in the writable state, which means it is being used by another module.
/// </exception>
/// <see cref="Flips.None"/> will be ignored in set case. It's not supported in Native FW.
/// </remarks>
/// <exception cref="ArgumentException">The specified value to set is invalid.</exception>
- /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed of.</exception>
+ /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed.</exception>
/// <exception cref="InvalidOperationException">
/// The MediaPacket is not in the writable state, which means it is being used by another module.
/// </exception>
/// The <see cref="IMediaBuffer"/> allocated to the packet.
/// This property will return null if the packet is in the raw video format.
/// </value>
- /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed of.</exception>
+ /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed.</exception>
/// <seealso cref="IsEncoded"/>
/// <seealso cref="VideoPlanes"/>
/// <since_tizen> 3 </since_tizen>
/// <summary>
/// Gets or sets a length of data written in the <see cref="Buffer"/>.
/// </summary>
- /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed of.</exception>
+ /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed.</exception>
/// <exception cref="ArgumentOutOfRangeException">
/// The value specified for this property is less than zero or greater than the length of the <see cref="Buffer"/>.</exception>
/// <exception cref="InvalidOperationException">
/// </summary>
/// <value>The <see cref="MediaPacketVideoPlane"/>s allocated to the packet.
/// This property will return null if the packet is not in the raw video format.</value>
- /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed of.</exception>
+ /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed.</exception>
/// <seealso cref="IsEncoded"/>
/// <seealso cref="Buffer"/>
/// <since_tizen> 3 </since_tizen>
/// <summary>
/// Gets or sets the buffer flags of the packet.
/// </summary>
- /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed of.</exception>
+ /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed.</exception>
/// <exception cref="InvalidOperationException">
/// The MediaPacket is not in the writable state, which means it is being used by another module.
/// </exception>
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
/// <summary>
- /// Gets a value indicating whether the packet has been disposed of.
+ /// Gets a value indicating whether the packet has been disposed.
/// </summary>
/// <value>true if the packet has been disposed of; otherwise, false.</value>
/// <since_tizen> 3 </since_tizen>
if (_handle != IntPtr.Zero)
{
- Native.Destroy(_handle);
+ Native.Unref(_handle);
_handle = IntPtr.Zero;
}
}
/// <summary>
- /// Validates the current object has not been disposed of.
+ /// Validates the current object has not been disposed.
/// </summary>
- /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed of.</exception>
+ /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed.</exception>
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
/// <summary>
/// Ensures whether the packet is writable.
/// </summary>
- /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed of.</exception>
+ /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed.</exception>
/// <exception cref="InvalidOperationException">The MediaPacket is being used by another module.</exception>
internal void EnsureWritableState()
{
/// <summary>
/// Ensures whether the packet is readable.
/// </summary>
- /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed of.</exception>
+ /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed.</exception>
internal void EnsureReadableState()
{
ValidateNotDisposed();
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];
return new SimpleMediaPacket(format);
}
+ /// <summary>
+ /// Creates an object of the MediaPacket based on the original MediaPacket and increases the internal reference(hereafter ref) count by 1.
+ /// </summary>
+ /// <remarks>
+ /// 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 <see cref="Create(MediaPacket)"/> and shares it to other module.\n
+ /// And then, each MediaPacket instances can be disposed independently without concerning other instance's life cycle.
+ /// </remarks>
+ /// <param name="mediaPacket">The media packet to increase ref count.</param>
+ /// <returns>A MediaPacket object which is based on original MediaPacket instance.</returns>
+ /// <since_tizen> 10 </since_tizen>
+ public static MediaPacket Create(MediaPacket mediaPacket)
+ {
+ return new SimpleMediaPacket(mediaPacket);
+ }
+
internal static MediaPacket From(IntPtr handle)
{
return new SimpleMediaPacket(handle);
internal SimpleMediaPacket(IntPtr handle) : base(handle)
{
}
+
+ internal SimpleMediaPacket(MediaPacket mediaPacket) : base(mediaPacket)
+ {
+ }
}
}