From f89864e714e13c810b1a19663498f0961c60e725 Mon Sep 17 00:00:00 2001 From: coderhyme Date: Fri, 9 Sep 2016 15:58:12 +0900 Subject: [PATCH] Added MediaTool implementation Change-Id: Id3557fb38895559926f76aac8b29a17c3962fb37 Signed-off-by: coderhyme --- src/Tizen.Multimedia/Interop/Interop.Libraries.cs | 22 +- src/Tizen.Multimedia/Interop/Interop.MediaCodec.cs | 106 +++ src/Tizen.Multimedia/Interop/Interop.MediaTool.cs | 154 +++++ src/Tizen.Multimedia/MediaTool/MediaFormat.cs | 747 +++++++++++++++++++++ .../MediaTool/MediaFormatAacType.cs | 9 + .../MediaTool/MediaFormatMimeType.cs | 513 ++++++++++++++ .../MediaTool/MediaFormatTextType.cs | 9 + src/Tizen.Multimedia/MediaTool/MediaPacket.cs | 696 +++++++++++++++++++ .../MediaTool/MediaPacketBuffer.cs | 156 +++++ .../MediaTool/MediaPacketBufferFlags.cs | 12 + .../MediaTool/MediaPacketVideoPlane.cs | 77 +++ src/Tizen.Multimedia/MediaTool/MediaToolDebug.cs | 17 + .../MediaTool/NotEnoughMemoryException.cs | 18 + src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj | 278 ++++---- src/Tizen.Multimedia/Tizen.Multimedia.csproj | 14 +- 15 files changed, 2684 insertions(+), 144 deletions(-) create mode 100644 src/Tizen.Multimedia/Interop/Interop.MediaCodec.cs create mode 100644 src/Tizen.Multimedia/Interop/Interop.MediaTool.cs create mode 100644 src/Tizen.Multimedia/MediaTool/MediaFormat.cs create mode 100644 src/Tizen.Multimedia/MediaTool/MediaFormatAacType.cs create mode 100644 src/Tizen.Multimedia/MediaTool/MediaFormatMimeType.cs create mode 100644 src/Tizen.Multimedia/MediaTool/MediaFormatTextType.cs create mode 100644 src/Tizen.Multimedia/MediaTool/MediaPacket.cs create mode 100644 src/Tizen.Multimedia/MediaTool/MediaPacketBuffer.cs create mode 100644 src/Tizen.Multimedia/MediaTool/MediaPacketBufferFlags.cs create mode 100644 src/Tizen.Multimedia/MediaTool/MediaPacketVideoPlane.cs create mode 100644 src/Tizen.Multimedia/MediaTool/MediaToolDebug.cs create mode 100644 src/Tizen.Multimedia/MediaTool/NotEnoughMemoryException.cs diff --git a/src/Tizen.Multimedia/Interop/Interop.Libraries.cs b/src/Tizen.Multimedia/Interop/Interop.Libraries.cs index 6f14cd5..5b04e6d 100755 --- a/src/Tizen.Multimedia/Interop/Interop.Libraries.cs +++ b/src/Tizen.Multimedia/Interop/Interop.Libraries.cs @@ -3,14 +3,16 @@ using System; internal static partial class Interop { - internal static partial class Libraries - { - public const string Player = "libcapi-media-player.so.0"; - public const string Recorder = "libcapi-media-recorder.so.0"; - public const string SoundManager = "libcapi-media-sound-manager.so.0"; - public const string AudioIO = "libcapi-media-audio-io.so.0"; - public const string MetadataExtractor = "libcapi-media-metadata-extractor.so.0"; - public const string MediaController = "libcapi-media-controller.so.0"; - public const string Libc = "libc.so.6"; - } + internal static partial class Libraries + { + public const string Player = "libcapi-media-player.so.0"; + public const string Recorder = "libcapi-media-recorder.so.0"; + public const string SoundManager = "libcapi-media-sound-manager.so.0"; + public const string AudioIO = "libcapi-media-audio-io.so.0"; + public const string MetadataExtractor = "libcapi-media-metadata-extractor.so.0"; + public const string MediaController = "libcapi-media-controller.so.0"; + public const string MediaTool = "libcapi-media-tool.so.0"; + public const string MediaCodec = "libcapi-media-codec.so.0"; + public const string Libc = "libc.so.6"; + } } diff --git a/src/Tizen.Multimedia/Interop/Interop.MediaCodec.cs b/src/Tizen.Multimedia/Interop/Interop.MediaCodec.cs new file mode 100644 index 0000000..e65bf8b --- /dev/null +++ b/src/Tizen.Multimedia/Interop/Interop.MediaCodec.cs @@ -0,0 +1,106 @@ +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static class MediaCodec + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void InputBufferUsedCallback(IntPtr mediaPacket, IntPtr arg); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void OutputBufferAvailableCallback(IntPtr mediaPacket, IntPtr arg); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ErrorCallback(int errorCode, IntPtr arg); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void EosCallback(IntPtr arg); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void BufferStatusCallback(int statusCode, IntPtr arg); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool SupportedCodecCallback(int codecType, IntPtr arg); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_create")] + internal static extern int Create(out IntPtr handle); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_destroy")] + internal static extern int Destroy(IntPtr handle); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_codec")] + internal static extern int Configure(IntPtr handle, int codecType, int flags); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_vdec_info")] + internal static extern int SetVideoDecoderInfo(IntPtr handle, int width, int height); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_venc_info")] + internal static extern int SetVideoEncoderInfo(IntPtr handle, int width, int height, + int fps, int targetBits); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_adec_info")] + internal static extern int SetAudioDecoderInfo(IntPtr handle, int sampleRate, int channel, + int bit); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_aenc_info")] + internal static extern int SetAudioEncoderInfo(IntPtr handle, int sampleRate, int channel, + int bit, int bitRate); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_prepare")] + internal static extern int Prepare(IntPtr handle); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unprepare")] + internal static extern int Unprepare(IntPtr handle); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_process_input")] + internal static extern int Process(IntPtr handle, IntPtr mediaPacket, ulong timeoutInUs); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_get_output")] + internal static extern int GetOutput(IntPtr handle, out IntPtr packet, ulong timeoutInUs); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_flush_buffers")] + internal static extern int FlushBuffers(IntPtr handle); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_input_buffer_used_cb")] + internal static extern int SetInputBufferUsedCb(IntPtr handle, + InputBufferUsedCallback cb, IntPtr arg); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_input_buffer_used_cb")] + internal static extern int UnsetInputBufferUsedCb(IntPtr handle); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_output_buffer_available_cb")] + internal static extern int SetOutputBufferAvaiableCb(IntPtr handle, + OutputBufferAvailableCallback cb, IntPtr arg); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_output_buffer_available_cb")] + internal static extern int UnsetOutputBufferAvaiableCb(IntPtr handle); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_error_cb")] + internal static extern int SetErrorCb(IntPtr handle, ErrorCallback cb, IntPtr arg); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_error_cb")] + internal static extern int UnsetErrorCb(IntPtr handle); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_eos_cb")] + internal static extern int SetEosCb(IntPtr handle, EosCallback cb, IntPtr arg); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_eos_cb")] + internal static extern int UnsetEosCb(IntPtr handle); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_set_buffer_status_cb")] + internal static extern int SetBufferStatusCb(IntPtr handle, BufferStatusCallback cb, + IntPtr arg); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_unset_buffer_status_cb")] + internal static extern int UnsetBufferStatusCb(IntPtr handle); + + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_get_supported_type")] + internal static extern int GetSupportedType(IntPtr handle, int codecType, bool isEncoder, + out int value); + + // TODO the native method name needs to get replaced with new one which will be added + [DllImport(Libraries.MediaCodec, EntryPoint = "mediacodec_foreach_supported_codec")] + internal static extern int ForeachSupportedCodec(SupportedCodecCallback cb, IntPtr arg); + } +} diff --git a/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs b/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs new file mode 100644 index 0000000..a11fdd5 --- /dev/null +++ b/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs @@ -0,0 +1,154 @@ +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static class MediaPacket + { + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_create")] + internal static extern int Create(IntPtr format, IntPtr finalizeCb, IntPtr cbData, out IntPtr handle); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_alloc")] + internal static extern int Alloc(IntPtr handle); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_destroy")] + internal static extern int Destroy(IntPtr handle); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_format")] + internal static extern int GetFormat(IntPtr handle, out IntPtr format); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_buffer_data_ptr")] + internal static extern int GetBufferData(IntPtr handle, out IntPtr dataHandle); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_buffer_size")] + internal static extern int GetBufferSize(IntPtr handle, out ulong size); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_set_buffer_size")] + internal static extern int SetBufferSize(IntPtr handle, ulong size); + + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_allocated_buffer_size")] + internal static extern int GetAllocatedBufferSize(IntPtr handle, out int size); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_number_of_video_planes")] + internal static extern int GetNumberOfVideoPlanes(IntPtr handle, out uint num); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_video_stride_width")] + internal static extern int GetVideoStrideWidth(IntPtr handle, int planeIndex, out int value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_video_stride_height")] + internal static extern int GetVideoStrideHeight(IntPtr handle, int planeIndex, out int value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_video_plane_data_ptr")] + internal static extern int GetVideoPlaneData(IntPtr handle, int planeIndex, out IntPtr dataHandle); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_is_encoded")] + internal static extern int IsEncoded(IntPtr handle, out bool value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_flags")] + internal static extern int GetBufferFlags(IntPtr handle, out int value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_set_flags")] + internal static extern int SetBufferFlags(IntPtr handle, int value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_reset_flags")] + internal static extern int ResetBufferFlags(IntPtr handle); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_pts")] + internal static extern int GetPts(IntPtr handle, out ulong value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_dts")] + internal static extern int GetDts(IntPtr handle, out ulong value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_set_pts")] + internal static extern int SetPts(IntPtr handle, ulong value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_set_dts")] + internal static extern int SetDts(IntPtr handle, ulong value); + + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_set_extra")] + internal static extern int SetExtra(IntPtr handle, IntPtr value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_extra")] + internal static extern int GetExtra(IntPtr handle, out IntPtr value); + } + + internal static class MediaFormat + { + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_create")] + internal static extern int Create(out IntPtr handle); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_unref")] + internal static extern int Unref(IntPtr handle); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_get_type")] + internal static extern int GetType(IntPtr handle, out int type); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_get_container_mime")] + internal static extern int GetContainerMimeType(IntPtr handle, out int mimeType); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_container_mime")] + internal static extern int SetContainerMimeType(IntPtr handle, int mimeType); + + #region Video apis + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_get_video_info")] + internal static extern int GetVideoInfo(IntPtr handle, out int mimeType, + out int width, out int height, out int averageBps, out int maxBps); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_get_video_frame_rate")] + internal static extern int GetVideoFrameRate(IntPtr handle, out int frameRate); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_video_mime")] + internal static extern int SetVideoMimeType(IntPtr handle, int value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_video_width")] + internal static extern int SetVideoWidth(IntPtr handle, int value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_video_height")] + internal static extern int SetVideoHeight(IntPtr handle, int value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_video_avg_bps")] + internal static extern int SetVideoAverageBps(IntPtr handle, int value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_video_frame_rate")] + internal static extern int SetVideoFrameRate(IntPtr handle, int value); + #endregion + + #region Audio apis + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_get_audio_info")] + internal static extern int GetAudioInfo(IntPtr handle, out int mimeType, + out int channel, out int sampleRate, out int bit, out int averageBps); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_get_audio_aac_header_type")] + internal static extern int GetAudioAacType(IntPtr handle, out int aacType); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_audio_mime")] + internal static extern int SetAudioMimeType(IntPtr handle, int value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_audio_channel")] + internal static extern int SetAudioChannel(IntPtr handle, int value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_audio_samplerate")] + internal static extern int SetAudioSampleRate(IntPtr handle, int value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_audio_bit")] + internal static extern int SetAudioBit(IntPtr handle, int value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_audio_avg_bps")] + internal static extern int SetAudioAverageBps(IntPtr handle, int value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_audio_aac_header_type")] + internal static extern int SetAudioAacType(IntPtr handle, int value); + #endregion + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_get_text_info")] + internal static extern int GetTextInfo(IntPtr handle, out int mimeType, out int textType); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_text_mime")] + internal static extern int SetTextMimeType(IntPtr handle, int value); + + [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_text_type")] + internal static extern int SetTextType(IntPtr handle, int value); + } +} diff --git a/src/Tizen.Multimedia/MediaTool/MediaFormat.cs b/src/Tizen.Multimedia/MediaTool/MediaFormat.cs new file mode 100644 index 0000000..28663ed --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/MediaFormat.cs @@ -0,0 +1,747 @@ +using System; +using System.Diagnostics; +using Tizen.Internals.Errors; + +namespace Tizen.Multimedia +{ + /// + /// MediaFormat is a base class for media formats. + /// + public abstract class MediaFormat + { + /// + /// Initializes a new instance of the ContainerMediaFormat class with a type. + /// + /// A type for the format. + internal MediaFormat(MediaFormatType type) + { + _type = type; + } + + private readonly MediaFormatType _type; + + /// + /// Gets the type of the current format. + /// + public MediaFormatType Type + { + get + { + return _type; + } + } + + /// + /// Creates a media format from a native handle. + /// + /// A native handle. + /// An object of one of subclasses of . + internal static MediaFormat FromHandle(IntPtr handle) + { + if (handle == IntPtr.Zero) + { + throw new ArgumentNullException("The handle value is null."); + } + + int type = 0; + int ret = Interop.MediaFormat.GetType(handle, out type); + + if (ret != (int)ErrorCode.InvalidOperation) + { + MediaToolDebug.AssertNoError(ret); + + switch ((MediaFormatType)type) + { + case MediaFormatType.Container: + return new ContainerMediaFormat(handle); + + case MediaFormatType.Video: + return new VideoMediaFormat(handle); + + case MediaFormatType.Audio: + return new AudioMediaFormat(handle); + + case MediaFormatType.Text: + return new TextMediaFormat(handle); + } + } + + throw new ArgumentException("looks like handle is corrupted."); + } + + /// + /// Create a native media format from this object. + /// + /// A converted native handle. + /// The returned handle must be destroyed using . + internal IntPtr AsNativeHandle() + { + IntPtr handle; + int ret = Interop.MediaFormat.Create(out handle); + + MediaToolDebug.AssertNoError(ret); + + AsNativeHandle(handle); + + return handle; + } + + /// + /// Fill out properties of a native media format with the current media format object. + /// + /// A native handle to be written. + protected abstract void AsNativeHandle(IntPtr handle); + } + + /// + /// Represents a container media format. This class cannot be inherited. + /// + public sealed class ContainerMediaFormat : MediaFormat + { + /// + /// Initializes a new instance of the ContainerMediaFormat class. + /// + /// The mime type of the container format. + /// mimeType is invalid(i.e. undefined value). + public ContainerMediaFormat(MediaFormatContainerMimeType mimeType) + : base(MediaFormatType.Container) + { + if (!Enum.IsDefined(typeof(MediaFormatContainerMimeType), mimeType)) + { + throw new ArgumentException($"Invalid mime type value : { (int)mimeType }"); + } + _mimeType = mimeType; + } + + /// + /// Initializes a new instance of the ContainerMediaFormat class from a native handle. + /// + /// A native media format handle. + internal ContainerMediaFormat(IntPtr handle) + : base(MediaFormatType.Container) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + int mimeType = 0; + + int ret = Interop.MediaFormat.GetContainerMimeType(handle, out mimeType); + + MediaToolDebug.AssertNoError(ret); + + Debug.Assert(Enum.IsDefined(typeof(MediaFormatContainerMimeType), mimeType), + "Invalid container mime type!"); + + _mimeType = (MediaFormatContainerMimeType)mimeType; + } + + private readonly MediaFormatContainerMimeType _mimeType; + + /// + /// Gets the mime type of the current format. + /// + public MediaFormatContainerMimeType MimeType + { + get + { + return _mimeType; + } + } + + protected override void AsNativeHandle(IntPtr handle) + { + Debug.Assert(Type == MediaFormatType.Container); + + int ret = Interop.MediaFormat.SetContainerMimeType(handle, (int)_mimeType); + + MediaToolDebug.AssertNoError(ret); + } + } + + /// + /// Represents a video media format. This class cannot be inherited. + /// + public sealed class VideoMediaFormat : MediaFormat + { + private const int DEFAULT_FRAME_RATE = 0; + private const int DEFAULT_BIT_RATE = 0; + + + /// + /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, width and height. + /// + /// The mime type of the format. + /// The width value of the format. + /// The height value of the format + /// mimeType is invalid(i.e. undefined value). + /// width, or height is less than zero. + public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height) + : this(mimeType, width, height, DEFAULT_FRAME_RATE) + { + } + + /// + /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, + /// width, height and frame rate. + /// + /// The mime type of the format. + /// The width value of the format. + /// The height value of the format + /// The frame rate of the format. + /// mimeType is invalid(i.e. undefined value). + /// width, height or frameRate is less than zero. + public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height, + int frameRate) + : this(mimeType, width, height, frameRate, DEFAULT_BIT_RATE) + { + } + + /// + /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, + /// width, height, frame rate and bit rate. + /// + /// The mime type of the format. + /// The width value of the format. + /// The height value of the format + /// The frame rate of the format. + /// The bit rate of the format. + /// mimeType is invalid(i.e. undefined value). + /// width, height, frameRate or bitRate is less than zero. + public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height, + int frameRate, int bitRate) + : base(MediaFormatType.Video) + { + if (!Enum.IsDefined(typeof(MediaFormatVideoMimeType), mimeType)) + { + throw new ArgumentException($"Invalid mime type value : { (int)mimeType }"); + } + if (width < 0) + { + throw new ArgumentOutOfRangeException("Width value can't be less than zero."); + } + if (height < 0) + { + throw new ArgumentOutOfRangeException("Height value can't be less than zero."); + } + if (frameRate < 0) + { + throw new ArgumentOutOfRangeException("Frame rate can't be less than zero."); + } + if (bitRate < 0) + { + throw new ArgumentOutOfRangeException("Bit rate value can't be less than zero."); + } + + _mimeType = mimeType; + _width = width; + _height = height; + _frameRate = frameRate; + _bitRate = bitRate; + } + + /// + /// Initializes a new instance of the VideoMediaForma class from a native handle. + /// + /// A native handle. + internal VideoMediaFormat(IntPtr handle) + : base(MediaFormatType.Video) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + GetInfo(handle, out _width, out _height, out _bitRate, out _mimeType); + + GetFrameRate(handle, out _frameRate); + } + + /// + /// Retrieves video properties of media format from a native handle. + /// + /// A native handle that properties are retrieved from. + /// An out parameter for width. + /// An out parameter for height. + /// An out parameter for bit rate. + /// An out parameter for mime type. + private static void GetInfo(IntPtr handle, out int width, out int height, out int bitRate, + out MediaFormatVideoMimeType mimeType) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + int mimeTypeValue = 0; + int maxBps = 0; + + int ret = Interop.MediaFormat.GetVideoInfo(handle, + out mimeTypeValue, out width, out height, out bitRate, out maxBps); + + MediaToolDebug.AssertNoError(ret); + + mimeType = (MediaFormatVideoMimeType)mimeTypeValue; + + Debug.Assert(Enum.IsDefined(typeof(MediaFormatVideoMimeType), mimeType), + "Invalid video mime type!"); + } + + /// + /// Retrieves frame rate from a native handle. + /// + /// A native handle that properties are retrieved from. + /// An out parameter for frame rate. + private static void GetFrameRate(IntPtr handle, out int frameRate) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + int ret = Interop.MediaFormat.GetVideoFrameRate(handle, out frameRate); + + MediaToolDebug.AssertNoError(ret); + } + + protected override void AsNativeHandle(IntPtr handle) + { + Debug.Assert(Type == MediaFormatType.Video); + + int ret = Interop.MediaFormat.SetVideoMimeType(handle, (int)_mimeType); + MediaToolDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetVideoWidth(handle, _width); + MediaToolDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetVideoHeight(handle, _height); + MediaToolDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetVideoAverageBps(handle, _bitRate); + MediaToolDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetVideoFrameRate(handle, _frameRate); + MediaToolDebug.AssertNoError(ret); + } + + private readonly MediaFormatVideoMimeType _mimeType; + + /// + /// Gets the mime type of the current format. + /// + public MediaFormatVideoMimeType MimeType + { + get + { + return _mimeType; + } + } + + private readonly int _width; + + /// + /// Gets the width value of the current format. + /// + public int Width + { + get + { + return _width; + } + } + + private readonly int _height; + + /// + /// Gets the width value of the current format. + /// + public int Height + { + get + { + return _height; + } + } + + private readonly int _frameRate; + + /// + /// Gets the frame rate value of the current format. + /// + public int FrameRate + { + get + { + return _frameRate; + } + } + + private readonly int _bitRate; + + /// + /// Gets the bit rate value of the current format. + /// + public int BitRate + { + get + { + return _bitRate; + } + } + } + + /// + /// Represents an audio media format. This class cannot be inherited. + /// + public sealed class AudioMediaFormat : MediaFormat + { + + /// + /// Initializes a new instance of the AudioMediaFormat class with the specified mime type, + /// channel, sample rate, bit and bit rate. + /// + /// The mime type of the format. + /// The channel value of the format. + /// The sample rate value of the format. + /// The bit value of the format. + /// The bit rate value of the format. + /// mimeType is invalid(i.e. undefined value). + /// + /// channel, sampleRate, bit or bitRate is less than zero. + public AudioMediaFormat(MediaFormatAudioMimeType mimeType, + int channel, int sampleRate, int bit, int bitRate) + : this(mimeType, channel, sampleRate, bit, bitRate, MediaFormatAacType.None) + { + } + + /// + /// Initializes a new instance of the AudioMediaFormat class with the specified mime type, + /// channel, sample rate, bit, bit rate and aac type. + /// + /// The mime type of the format. + /// The channel value of the format. + /// The sample rate value of the format. + /// The bit value of the format. + /// The bit rate value of the format. + /// + /// mimeType or aacType is invalid(i.e. undefined value). + /// - or - + /// aacType is not , but mimeType is one of aac types. + /// + /// + /// channel, sampleRate, bit or bitRate is less than zero. + public AudioMediaFormat(MediaFormatAudioMimeType mimeType, + int channel, int sampleRate, int bit, int bitRate, MediaFormatAacType aacType) + : base(MediaFormatType.Audio) + { + if (!Enum.IsDefined(typeof(MediaFormatAudioMimeType), mimeType)) + { + throw new ArgumentException($"Invalid mime type value : { (int)mimeType }"); + } + if (channel < 0) + { + throw new ArgumentOutOfRangeException("Channel value can't be negative."); + } + if (sampleRate < 0) + { + throw new ArgumentOutOfRangeException("Sample rate value can't be negative."); + } + if (bit < 0) + { + throw new ArgumentOutOfRangeException("Bit value can't be negative."); + } + if (bitRate < 0) + { + throw new ArgumentOutOfRangeException("Bit rate value can't be negative."); + } + if (!Enum.IsDefined(typeof(MediaFormatAacType), aacType)) + { + throw new ArgumentException($"Invalid aac type value : { (int)aacType }"); + } + if (!IsAacSupportedMimeType(mimeType) && aacType != MediaFormatAacType.None) + { + throw new ArgumentException("Aac is supported only with aac mime types."); + } + + _mimeType = mimeType; + _channel = channel; + _sampleRate = sampleRate; + _bit = bit; + _bitRate = bitRate; + _aacType = aacType; + } + + /// + /// Initializes a new instance of the AudioMediaFormat class from a native handle. + /// + /// A native handle. + internal AudioMediaFormat(IntPtr handle) + : base(MediaFormatType.Audio) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + GetInfo(handle, out _mimeType, out _channel, out _sampleRate, out _bit, out _bitRate); + + if (IsAacSupportedMimeType(_mimeType)) + { + GetAacType(handle, out _aacType); + } + else + { + _aacType = MediaFormatAacType.None; + } + + } + + /// + /// Returns an indication whether a specified mime type is a aac type. + /// + /// A mime type. + private static bool IsAacSupportedMimeType(MediaFormatAudioMimeType mimeType) + { + return mimeType == MediaFormatAudioMimeType.AacLC || + mimeType == MediaFormatAudioMimeType.AacHE || + mimeType == MediaFormatAudioMimeType.AacHEPS; + } + + /// + /// Retrieves audio properties of media format from a native handle. + /// + /// A native handle that properties are retrieved from. + /// An out parameter for mime type. + /// An out parameter for channel. + /// An out parameter for sample rate. + /// An out parameter for bit. + /// An out parameter for bit rate. + private static void GetInfo(IntPtr handle, out MediaFormatAudioMimeType mimeType, + out int channel, out int sampleRate, out int bit, out int bitRate) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + int mimeTypeValue = 0; + + int ret = Interop.MediaFormat.GetAudioInfo(handle, + out mimeTypeValue, out channel, out sampleRate, out bit, out bitRate); + + mimeType = (MediaFormatAudioMimeType)mimeTypeValue; + + MediaToolDebug.AssertNoError(ret); + + Debug.Assert(Enum.IsDefined(typeof(MediaFormatAudioMimeType), mimeType), + "Invalid audio mime type!"); + } + + /// + /// Retrieves aac type value from a native handle. + /// + /// A native handle that properties are retrieved from. + /// An out parameter for aac type. + private static void GetAacType(IntPtr handle, out MediaFormatAacType aacType) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + int aacTypeValue = 0; + + int ret = Interop.MediaFormat.GetAudioAacType(handle, out aacTypeValue); + + MediaToolDebug.AssertNoError(ret); + + aacType = (MediaFormatAacType)aacTypeValue; + + Debug.Assert(Enum.IsDefined(typeof(MediaFormatAacType), aacType), "Invalid aac type!"); + } + + protected override void AsNativeHandle(IntPtr handle) + { + Debug.Assert(Type == MediaFormatType.Audio); + + int ret = Interop.MediaFormat.SetAudioMimeType(handle, (int)_mimeType); + MediaToolDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetAudioChannel(handle, _channel); + MediaToolDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetAudioSampleRate(handle, _sampleRate); + MediaToolDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetAudioBit(handle, _bit); + MediaToolDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetAudioAverageBps(handle, _bitRate); + MediaToolDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetAudioAacType(handle, (int)_aacType); + MediaToolDebug.AssertNoError(ret); + } + + private readonly MediaFormatAudioMimeType _mimeType; + + /// + /// Gets the mime type of the current format. + /// + public MediaFormatAudioMimeType MimeType + { + get + { + return _mimeType; + } + } + + private readonly int _channel; + + /// + /// Gets the channel value of the current format. + /// + public int Channel + { + get + { + return _channel; + } + } + + private readonly int _sampleRate; + + /// + /// Gets the sample rate value of the current format. + /// + public int SampleRate + { + get + { + return _sampleRate; + } + } + + private readonly int _bit; + + /// + /// Gets the bit value of the current format. + /// + public int Bit + { + get + { + return _bit; + } + } + + private readonly int _bitRate; + + /// + /// Gets the bit rate value of the current format. + /// + public int BitRate + { + get + { + return _bitRate; + } + } + + private readonly MediaFormatAacType _aacType; + + /// + /// Gets the aac type of the current format. + /// + public MediaFormatAacType AacType + { + get + { + return _aacType; + } + } + } + + /// + /// Represents a text media format. This class cannot be inherited. + /// + public sealed class TextMediaFormat : MediaFormat + { + /// + /// Initializes a new instance of the TextMediaFormat class with the specified mime type + /// and text type. + /// + /// The mime type of the format. + /// The text type of the format. + /// + /// mimeType or textType is invalid(i.e. undefined value). + public TextMediaFormat(MediaFormatTextMimeType mimeType, MediaFormatTextType textType) + : base(MediaFormatType.Text) + { + if (!Enum.IsDefined(typeof(MediaFormatTextMimeType), mimeType)) + { + throw new ArgumentException($"Invalid mime type value : { (int)mimeType }"); + } + if (!Enum.IsDefined(typeof(MediaFormatTextType), textType)) + { + throw new ArgumentException($"Invalid text type value : { (int)textType }"); + } + _mimeType = mimeType; + _textType = textType; + } + + /// + /// Initializes a new instance of the TextMediaFormat class from a native handle. + /// + /// A native handle. + internal TextMediaFormat(IntPtr handle) + : base(MediaFormatType.Text) + { + Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); + + GetInfo(handle, out _mimeType, out _textType); + } + + /// + /// Retrieves text properties of media format from a native handle. + /// + /// A native handle that properties are retrieved from. + /// An out parameter for mime type. + /// An out parameter for text type. + private static void GetInfo(IntPtr handle, out MediaFormatTextMimeType mimeType, + out MediaFormatTextType textType) + { + int mimeTypeValue = 0; + int textTypeValue = 0; + + int ret = Interop.MediaFormat.GetTextInfo(handle, out mimeTypeValue, out textTypeValue); + + MediaToolDebug.AssertNoError(ret); + + mimeType = (MediaFormatTextMimeType)mimeTypeValue; + textType = (MediaFormatTextType)textTypeValue; + + Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextMimeType), mimeType), + "Invalid text mime type!"); + Debug.Assert(Enum.IsDefined(typeof(MediaFormatTextType), textType), + "Invalid text type!"); + } + + protected override void AsNativeHandle(IntPtr handle) + { + Debug.Assert(Type == MediaFormatType.Text); + + int ret = Interop.MediaFormat.SetTextMimeType(handle, (int)_mimeType); + MediaToolDebug.AssertNoError(ret); + + ret = Interop.MediaFormat.SetTextType(handle, (int)_textType); + MediaToolDebug.AssertNoError(ret); + } + + private readonly MediaFormatTextMimeType _mimeType; + + /// + /// Gets the mime type of the current format. + /// + public MediaFormatTextMimeType MimeType + { + get + { + return _mimeType; + } + } + + private readonly MediaFormatTextType _textType; + + /// + /// Gets the text type of the current format. + /// + public MediaFormatTextType TextType + { + get + { + return _textType; + } + } + } +} diff --git a/src/Tizen.Multimedia/MediaTool/MediaFormatAacType.cs b/src/Tizen.Multimedia/MediaTool/MediaFormatAacType.cs new file mode 100644 index 0000000..a7511e8 --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/MediaFormatAacType.cs @@ -0,0 +1,9 @@ +namespace Tizen.Multimedia +{ + public enum MediaFormatAacType + { + None, + Adts, + Adif + } +} diff --git a/src/Tizen.Multimedia/MediaTool/MediaFormatMimeType.cs b/src/Tizen.Multimedia/MediaTool/MediaFormatMimeType.cs new file mode 100644 index 0000000..5136db4 --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/MediaFormatMimeType.cs @@ -0,0 +1,513 @@ +namespace Tizen.Multimedia +{ + /// + /// Enumeration for media format type + /// + public enum MediaFormatType + { + /// + /// Audio + /// + Audio = 0x00100000, + + /// + /// Video + /// + Video = 0x00200000, + + /// + /// Container + /// + Container = 0x00400000, + + /// + /// Text + /// + Text = 0x00800000, + } + + /// + /// Enumeration for media format data type + /// + internal enum MediaFormatDataType + { + /// + /// Encoded type + /// + Encoded = 0x10000000, + + /// + /// Raw type + /// + Raw = 0x20000000, + } + + public enum MediaFormatAudioMimeType + { + /// + /// L16, Audio + /// + L16 = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x1010), + + /// + /// ALAW, Audio + /// + ALaw = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x1020), + + /// + /// ULAW, Audio + /// + ULaw = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x1030), + + /// + /// AMR, Audio, Alias for AmrNB + /// + Amr = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x1040), + + /// + /// AMR-NB, Audio + /// + AmrNB = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x1040), + + /// + /// AMR-WB, Audio + /// + AmrWB = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x1041), + + /// + /// G729, Audio + /// + G729 = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x1050), + + /// + /// AAC, Audio, Alias for AacLc + /// + Aac = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x1060), + + /// + /// AAC-LC (Advanced Audio Coding Low-Complexity profile), Audio + /// + AacLC = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x1060), + + /// + /// HE-AAC (High-Efficiency Advanced Audio Coding), Audio + /// + AacHE = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x1061), + + /// + /// HE-AAC-PS (High-Efficiency Advanced Audio Coding with Parametric Stereo), Audio + /// + AacHEPS = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x1062), + + /// + /// MP3, Audio + /// + MP3 = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x1070), + + /// + /// VORBIS, Audio + /// + Vorbis = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x1080), + + /// + /// FLAC, Audio + /// + Flac = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x1090), + + /// + /// Windows Media Audio 1, Audio + /// + Wma1 = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x10A0), + + /// + /// Windows Media Audio 2, Audio + /// + Wma2 = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x10A1), + + /// + /// Windows Media Audio Professional, Audio + /// + WmaPro = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x10A2), + + /// + /// Windows Media Audio Lossless, Audio + /// + WmaLossless = (MediaFormatType.Audio | MediaFormatDataType.Encoded | 0x10A3), + + /// + /// PCM, Audio, Alias for PcmS16LE + /// + Pcm = (MediaFormatType.Audio | MediaFormatDataType.Raw | 0x1510), + + /// + /// PCM signed 16-bit little-endian, Audio + /// + PcmS16LE = (MediaFormatType.Audio | MediaFormatDataType.Raw | 0x1510), + + /// + /// PCM signed 24-bit little-endian, Audio + /// + PcmS24LE = (MediaFormatType.Audio | MediaFormatDataType.Raw | 0x1511), + + /// + /// PCM signed 32-bit little-endian, Audio + /// + Pcm32LE = (MediaFormatType.Audio | MediaFormatDataType.Raw | 0x1512), + + /// + /// PCM signed 16-bit big-endian, Audio + /// + PcmS16BE = (MediaFormatType.Audio | MediaFormatDataType.Raw | 0x1513), + + /// + /// PCM signed 24-bit big-endian, Audio + /// + PcmS24BE = (MediaFormatType.Audio | MediaFormatDataType.Raw | 0x1514), + + /// + /// PCM signed 32-bit big-endian, Audio + /// + PcmS32BE = (MediaFormatType.Audio | MediaFormatDataType.Raw | 0x1515), + + /// + /// PCM 32-bit floating point little-endian, Audio + /// + PcmF32LE = (MediaFormatType.Audio | MediaFormatDataType.Raw | 0x1516), + + /// + /// PCM 32-bit floating point big-endian, Audio + /// + PcmF32BE = (MediaFormatType.Audio | MediaFormatDataType.Raw | 0x1517), + + /// + /// PCM A-law, Audio + /// + PcmALaw = (MediaFormatType.Audio | MediaFormatDataType.Raw | 0x1520), + + /// + /// PCM U-law, Audio + /// + PcmULaw = (MediaFormatType.Audio | MediaFormatDataType.Raw | 0x1530), + } + + /// + /// Enumeration for media format MIME type + /// + public enum MediaFormatVideoMimeType + { + /// + /// H261 + /// + H261 = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2010), + + /// + /// H263 + /// + H263 = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2020), + + /// + /// H263P + /// + H263P = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2021), + + /// + /// H263 Baseline Profile + /// + H263BP = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2022), + + /// + /// H263 H.320 Coding Efficiency Profile + /// + H263H320Cep = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2023), + + /// + /// H263 Backward-Compatibility Profile + /// + H263Bcp = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2024), + + /// + /// H263 Interactive and Streaming Wireless Profile + /// + H263Isw2p = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2025), + + /// + /// H263 Interactive and Streaming Wireless Profile + /// + H263Isw3p = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2026), + + /// + /// H263 Conversation High Compression Profile + /// + H263Chcp = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2027), + + /// + /// H263 Conversational Internet Profile + /// + H263CInternetP = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2028), + + /// + /// H263 Conversational Interlace Profile + /// + H263CInterlaceP = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2029), + + /// + /// H263 High Latency Profile + /// + H263Hlp = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x202A), + + /// + /// H264_SP + /// + H264SP = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2030), + + /// + /// H264_MP + /// + H264MP = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2031), + + /// + /// H264_HP + /// + H264HP = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2032), + + /// + /// H264 Extended Profile + /// + H264XP = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2033), + + /// + /// H264 High10 Profile + /// + H264H10P = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2034), + + /// + /// H264 High422 Profile + /// + H264H422P = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2035), + + /// + /// H264 High444 Profile + /// + H264H444P = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2036), + + /// + /// H264 CAVLC444 Profile + /// + H264C444P = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2037), + + /// + /// MJPEG + /// + MJpeg = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2040), + + /// + /// MPEG1 + /// + Mpeg1 = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2050), + + /// + /// MPEG2_SP + /// + Mpeg2SP = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2060), + + /// + /// MPEG2_MP + /// + Mpeg2MP = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2061), + + /// + /// MPEG2_HP + /// + Mpeg2HP = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2062), + + /// + /// MPEG4_SP + /// + Mpeg4SP = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2070), + + /// + /// MPEG4_ASP + /// + Mpeg4Asp = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2071), + + /// + /// HEVC + /// + Hevc = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2080), + + /// + /// HEVC Main Profile + /// + HevcMP = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2081), + + /// + /// HEVC Main10 Profile + /// + HevcM10P = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2082), + + /// + /// VP8 + /// + VP8 = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x2090), + + /// + /// VP9 + /// + VP9 = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x20A0), + + /// + /// VC1 + /// + VC1 = (MediaFormatType.Video | MediaFormatDataType.Encoded | 0x20B0), + + /// + /// I420 + /// + I420 = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x2510), + + /// + /// NV12 + /// + NV12 = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x2520), + + /// + /// NV12T + /// + NV12T = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x2530), + + /// + /// YV12 + /// + YV12 = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x2540), + + /// + /// NV21 + /// + NV21 = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x2550), + + /// + /// NV16 + /// + NV16 = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x2560), + + /// + /// YUYV + /// + Yuyv = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x2570), + + /// + /// UYVY + /// + Uyvy = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x2580), + + /// + /// 422P + /// + Yuv422P = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x2590), + + /// + /// RGB565 + /// + Rgb565 = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x25a0), + + /// + /// RGB888 + /// + Rgb888 = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x25b0), + + /// + /// RGBA + /// + Rgba = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x25c0), + + /// + /// ARGB + /// + Argb = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x25d0), + + /// + /// BGRA + /// + Bgra = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x25e0), + + /// + /// HW dependent + /// + NativeVideo = (MediaFormatType.Video | MediaFormatDataType.Raw | 0x7000), + } + + public enum MediaFormatContainerMimeType + { + /// + /// MP4 container, Video + /// + MP4 = (MediaFormatType.Container | 0x3010), + + /// + /// AVI container, Video + /// + Avi = (MediaFormatType.Container | 0x3020), + + /// + /// MPEG2TS container, Video + /// + Mpeg2TS = (MediaFormatType.Container | 0x3030), + + /// + /// MPEG2PS container, Video + /// + Mpeg2PS = (MediaFormatType.Container | 0x3040), + + /// + /// MATROSKA container, Video + /// + Matroska = (MediaFormatType.Container | 0x3050), + + /// + /// WEBM container, Video + /// + Webm = (MediaFormatType.Container | 0x3060), + + /// + /// 3GP container, Video + /// + ThreeGP = (MediaFormatType.Container | 0x3070), + + + + /// + /// WAV container, Audio + /// + Wav = (MediaFormatType.Container | 0x4010), + + /// + /// OGG container, Audio + /// + Ogg = (MediaFormatType.Container | 0x4020), + + /// + /// AAC_ADTS container, Audio + /// + AacAdts = (MediaFormatType.Container | 0x4030), + + /// + /// AAC_ADIF container, Audio + /// + AacAdif = (MediaFormatType.Container | 0x4031), + } + + public enum MediaFormatTextMimeType + { + /// + /// MP4 + /// + MP4 = (MediaFormatType.Text | MediaFormatDataType.Encoded | 0x8010), + + /// + /// 3GP + /// + ThreeGP = (MediaFormatType.Text | MediaFormatDataType.Encoded | 0x8020), + } + +} + diff --git a/src/Tizen.Multimedia/MediaTool/MediaFormatTextType.cs b/src/Tizen.Multimedia/MediaTool/MediaFormatTextType.cs new file mode 100644 index 0000000..adbf4b9 --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/MediaFormatTextType.cs @@ -0,0 +1,9 @@ +namespace Tizen.Multimedia +{ + public enum MediaFormatTextType + { + None, + Mp4, + ThreeGpp + } +} diff --git a/src/Tizen.Multimedia/MediaTool/MediaPacket.cs b/src/Tizen.Multimedia/MediaTool/MediaPacket.cs new file mode 100644 index 0000000..e8ff020 --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/MediaPacket.cs @@ -0,0 +1,696 @@ +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Threading; +using Tizen.Internals.Errors; + +namespace Tizen.Multimedia +{ + /// + /// Represents a packet for multimedia. + /// + public abstract class MediaPacket : IDisposable + { + private IntPtr _handle = IntPtr.Zero; + + /// + /// Initializes a new instance of the MediaPacket class with the specified media format. + /// + /// A media format containing properties for the packet. + /// format is null. + /// + /// of the specified format is . + /// Out of memory. + /// Operation failed. + internal MediaPacket(MediaFormat format) + { + if (format == null) + { + throw new ArgumentNullException("MediaFormat must be not null."); + } + + if (format.Type == MediaFormatType.Container) + { + throw new ArgumentException("Container format can't be used to create a new packet."); + } + + Initialize(format); + _format = format; + } + + /// + /// Initializes a new instance of the MediaPacket class from a native handle. + /// + /// A native handle. + internal MediaPacket(IntPtr handle) + { + _handle = handle; + + IntPtr formatHandle = IntPtr.Zero; + int ret = Interop.MediaPacket.GetFormat(handle, out formatHandle); + + MediaToolDebug.AssertNoError(ret); + + try + { + if (formatHandle != IntPtr.Zero) + { + _format = MediaFormat.FromHandle(formatHandle); + } + } + finally + { + Interop.MediaFormat.Unref(formatHandle); + } + } + + ~MediaPacket() + { + Dispose(false); + } + + /// + /// Creates and initializes a native handle for the current object. + /// + /// A format to be set to the media format. + /// Out of memory. + /// Operation failed. + private void Initialize(MediaFormat format) + { + IntPtr formatHandle = IntPtr.Zero; + + if (format.Type == MediaFormatType.Container) + { + throw new ArgumentException("Creating a packet for container is not supported."); + } + + try + { + formatHandle = format.AsNativeHandle(); + + int ret = Interop.MediaPacket.Create(formatHandle, IntPtr.Zero, IntPtr.Zero, out _handle); + MediaToolDebug.AssertNoError(ret); + + Debug.Assert(_handle != IntPtr.Zero, "Created handle must not be null"); + + Alloc(); + } + catch (Exception) + { + if (_handle != IntPtr.Zero) + { + Interop.MediaPacket.Destroy(_handle); + _handle = IntPtr.Zero; + } + + throw; + } + finally + { + if (formatHandle != IntPtr.Zero) + { + Interop.MediaFormat.Unref(formatHandle); + } + } + } + + /// + /// Allocates internal buffer. + /// + /// Out of memory. + /// Operation failed. + private void Alloc() + { + ErrorCode ret = (ErrorCode)Interop.MediaPacket.Alloc(_handle); + if (ret == ErrorCode.None) + { + return; + } + + switch (ret) + { + case ErrorCode.OutOfMemory: + throw new NotEnoughMemoryException("Failed to allocate buffer for the packet."); + + default: + throw new InvalidOperationException("Failed to create a packet."); + } + + } + + private readonly MediaFormat _format; + + /// + /// Gets the media format of the current packet. + /// + public MediaFormat Format + { + get + { + ValidateNotDisposed(); + return _format; + } + } + + /// + /// Gets or sets the PTS(Presentation Time Stamp) value of the current packet. + /// + /// The MediaPacket has already been disposed. + /// + /// The MediaPacket is not writable state which means it being used by another module. + public ulong Pts + { + get + { + ValidateNotDisposed(); + + ulong value = 0; + int ret = Interop.MediaPacket.GetPts(_handle, out value); + + MediaToolDebug.AssertNoError(ret); + + return value; + } + set + { + ValidateNotDisposed(); + ValidateNotLocked(); + + int ret = Interop.MediaPacket.SetPts(_handle, value); + + MediaToolDebug.AssertNoError(ret); + } + } + + /// + /// Gets or sets the DTS(Decoding Time Stamp) value of the current packet. + /// + /// The MediaPacket has already been disposed. + /// + /// The MediaPacket is not in writable state which means it being used by another module. + public ulong Dts + { + get + { + ValidateNotDisposed(); + + ulong value = 0; + int ret = Interop.MediaPacket.GetDts(_handle, out value); + + MediaToolDebug.AssertNoError(ret); + + return value; + } + set + { + ValidateNotDisposed(); + ValidateNotLocked(); + + int ret = Interop.MediaPacket.SetDts(_handle, value); + + MediaToolDebug.AssertNoError(ret); + } + } + + /// + /// Gets a value indicating whether the packet is encoded type. + /// + /// true if the packet is encoded type; otherwise, false. + /// The MediaPacket has already been disposed. + public bool IsEncoded + { + get + { + ValidateNotDisposed(); + + bool value = false; + int ret = Interop.MediaPacket.IsEncoded(_handle, out value); + + MediaToolDebug.AssertNoError(ret); + + return value; + } + } + + private MediaPacketBuffer _buffer; + + /// + /// Gets the buffer of the packet. + /// + /// The allocated to the packet. + /// This property will return null if the packet is raw video format. + /// The MediaPacket has already been disposed. + /// + /// + public MediaPacketBuffer Buffer + { + get + { + ValidateNotDisposed(); + + if (IsVideoPlaneSupported) + { + return null; + } + + if (_buffer == null) + { + _buffer = GetBuffer(); + } + + return _buffer; + } + } + + /// + /// Gets or sets a length of data written in the . + /// + /// The MediaPacket has already been disposed. + /// + /// The value specified for this property is less than zero or greater than . + /// + /// The MediaPacket has instead of . + /// -or- + /// The MediaPacket is not in writable state which means it being used by another module. + /// + public int BufferWrittenLength + { + get + { + ValidateNotDisposed(); + + ulong value = 0; + int ret = Interop.MediaPacket.GetBufferSize(_handle, out value); + MediaToolDebug.AssertNoError(ret); + + Debug.Assert(value < int.MaxValue); + + return (int)value; + } + set + { + ValidateNotDisposed(); + ValidateNotLocked(); + + if (IsVideoPlaneSupported) + { + throw new InvalidOperationException( + "This packet uses VideoPlanes instead of Buffer."); + } + + Debug.Assert(Buffer != null); + + if (value < 0 || value >= Buffer.Length) + { + throw new ArgumentOutOfRangeException("value must be less than Buffer.Size."); + } + + int ret = Interop.MediaPacket.SetBufferSize(_handle, (ulong)value); + MediaToolDebug.AssertNoError(ret); + } + } + + private MediaPacketVideoPlane[] _videoPlanes; + + /// + /// Gets the video planes of the packet. + /// + /// The s allocated to the packet. + /// This property will return null if the packet is not raw video format. + /// The MediaPacket has already been disposed. + /// + /// + public MediaPacketVideoPlane[] VideoPlanes + { + get + { + ValidateNotDisposed(); + + if (!IsVideoPlaneSupported) + { + return null; + } + + if (_videoPlanes == null) + { + _videoPlanes = GetVideoPlanes(); + } + + return _videoPlanes; + } + } + + /// + /// Gets or sets the buffer flags of the packet. + /// + /// The MediaPacket has already been disposed. + /// + /// The MediaPacket is not in writable state which means it being used by another module. + /// + public MediaPacketBufferFlags BufferFlags + { + get + { + ValidateNotDisposed(); + + int value = 0; + + int ret = Interop.MediaPacket.GetBufferFlags(_handle, out value); + + MediaToolDebug.AssertNoError(ret); + + return (MediaPacketBufferFlags)value; + } + + set + { + ValidateNotDisposed(); + ValidateNotLocked(); + + int ret = Interop.MediaPacket.ResetBufferFlags(_handle); + + MediaToolDebug.AssertNoError(ret); + + ret = Interop.MediaPacket.SetBufferFlags(_handle, (int)value); + + MediaToolDebug.AssertNoError(ret); + } + } + + /// + /// Gets a value indicating whether the packet has been disposed of. + /// + /// true if the packet has been disposed of; otherwise, false. + public bool IsDisposed + { + get + { + return _isDisposed; + } + } + + private bool _isDisposed = false; + + /// + /// Releases all resources. + /// + /// + /// The MediaPacket can not be disposed which means it being used by another module. + /// + public void Dispose() + { + ValidateNotLocked(); + + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (_isDisposed) + { + return; + } + + if (_handle != IntPtr.Zero) + { + Interop.MediaPacket.Destroy(_handle); + _handle = IntPtr.Zero; + } + + _isDisposed = true; + } + + internal IntPtr GetHandle() + { + ValidateNotDisposed(); + + Debug.Assert(_handle != IntPtr.Zero, "The handle is invalid!"); + + return _handle; + } + + /// + /// Validate the current object has not been disposed of. + /// + /// The MediaPacket has already been disposed of. + private void ValidateNotDisposed() + { + if (_isDisposed) + { + throw new ObjectDisposedException("This packet has already been disposed of."); + } + } + + /// + /// Validate the current object is not locked. + /// + /// The MediaPacket has already been disposed of. + /// The MediaPacket is in use by another module. + private void ValidateNotLocked() + { + ValidateNotDisposed(); + + if (_lock.IsLocked) + { + throw new InvalidOperationException("Can't perform any writing operation." + + "The packet is in use, internally."); + } + } + /// + /// Ensures whether the packet is writable. + /// + /// The MediaPacket already has been disposed of. + /// The MediaPacket is being used by another module. + internal void EnsureWritableState() + { + ValidateNotDisposed(); + ValidateNotLocked(); + } + + /// + /// Ensures whether the packet is readable. + /// + /// The MediaPacket already has been disposed of. + internal void EnsureReadableState() + { + ValidateNotDisposed(); + } + + /// + /// Gets a value indicating whether the packet is raw video format. + /// + /// true if the packet is raw video format; otherwise, false. + private bool IsVideoPlaneSupported + { + get + { + return !IsEncoded && Format.Type == MediaFormatType.Video; + } + } + + /// + /// Retrieves video planes of the current packet. + /// + /// s allocated to the current MediaPacket. + private MediaPacketVideoPlane[] GetVideoPlanes() + { + Debug.Assert(_handle != IntPtr.Zero, "The handle is invalid!"); + + uint numberOfPlanes = 0; + int ret = Interop.MediaPacket.GetNumberOfVideoPlanes(_handle, out numberOfPlanes); + + MediaToolDebug.AssertNoError(ret); + + MediaPacketVideoPlane[] planes = new MediaPacketVideoPlane[numberOfPlanes]; + + for (int i = 0; i < numberOfPlanes; ++i) + { + planes[i] = new MediaPacketVideoPlane(this, i); + } + + return planes; + } + + /// + /// Retrieves the buffer of the current packet. + /// + /// A allocated to the current MediaPacket. + private MediaPacketBuffer GetBuffer() + { + Debug.Assert(_handle != IntPtr.Zero, "The handle is invalid!"); + + IntPtr dataHandle = IntPtr.Zero; + int size = 0; + + int ret = Interop.MediaPacket.GetBufferData(_handle, out dataHandle); + MediaToolDebug.AssertNoError(ret); + + Debug.Assert(dataHandle != IntPtr.Zero, "Data handle is invalid!"); + + ret = Interop.MediaPacket.GetAllocatedBufferSize(_handle, out size); + MediaToolDebug.AssertNoError(ret); + + return new MediaPacketBuffer(this, dataHandle, size); + } + + #region Lock operations + private readonly LockState _lock = new LockState(); + + /// + /// Provides a thread-safe lock state controller. + /// + private sealed class LockState + { + const int LOCKED = 1; + const int UNLOCKED = 0; + + private int _locked = UNLOCKED; + + internal void SetLock() + { + if (Interlocked.CompareExchange(ref _locked, LOCKED, UNLOCKED) == LOCKED) + { + throw new InvalidOperationException("The packet is already locked."); + } + } + + internal void SetUnlock() + { + if (Interlocked.CompareExchange(ref _locked, UNLOCKED, LOCKED) == UNLOCKED) + { + Debug.Fail("The packet to unlock is not locked. " + + "There must be an error somewhere that a lock isn't disposed correctly."); + } + } + + internal bool IsLocked + { + get + { + return Interlocked.CompareExchange(ref _locked, 0, 0) == LOCKED; + } + } + } + + /// + /// Provides a thread-safe lock controller. + /// + /// + /// using (var lock = BaseMeadiPacket.Lock(mediaPacket)) + /// { + /// .... + /// } + /// + internal sealed class Lock : IDisposable + { + private readonly MediaPacket _packet; + private readonly GCHandle _gcHandle; + + internal Lock(MediaPacket packet) + { + Debug.Assert(packet != null, "The packet is null!"); + + packet.ValidateNotDisposed(); + + _packet = packet; + + _packet._lock.SetLock(); + + //TODO need test + _gcHandle = GCHandle.Alloc(this); + + SetExtra(GCHandle.ToIntPtr(_gcHandle)); + } + + internal static Lock FromHandle(IntPtr handle) + { + Debug.Assert(handle != IntPtr.Zero); + + IntPtr extra = GetExtra(handle); + + Debug.Assert(extra != IntPtr.Zero, "Extra of packet must not be null."); + + return (Lock)GCHandle.FromIntPtr(extra).Target; + } + + private void SetExtra(IntPtr ptr) + { + int ret = Interop.MediaPacket.SetExtra(_packet._handle, ptr); + + MediaToolDebug.AssertNoError(ret); + } + + private static IntPtr GetExtra(IntPtr handle) + { + IntPtr value = IntPtr.Zero; + + int ret = Interop.MediaPacket.GetExtra(handle, out value); + + MediaToolDebug.AssertNoError(ret); + + return value; + } + + internal IntPtr GetHandle() + { + return _packet.GetHandle(); + } + + internal MediaPacket MediaPacket + { + get + { + return _packet; + } + } + + private bool _isDisposed = false; + + public void Dispose() + { + if (!_isDisposed) + { + SetExtra(IntPtr.Zero); + + if (_gcHandle.IsAllocated) + { + _gcHandle.Free(); + } + + //We can assure that at this point '_packet' is always locked by this lock. + _packet._lock.SetUnlock(); + + _isDisposed = true; + } + } + } + #endregion + + /// + /// Creates an object of the MediaPacekt with the specified . + /// + /// A media format for the new packet. + /// A new MediaPacket object. + public static MediaPacket Create(MediaFormat format) + { + return new SimpleMediaPacket(format); + } + + internal static MediaPacket From(IntPtr handle) + { + return new SimpleMediaPacket(handle); + } + } + + internal class SimpleMediaPacket : MediaPacket + { + internal SimpleMediaPacket(MediaFormat format) : base(format) + { + } + + internal SimpleMediaPacket(IntPtr handle) : base(handle) + { + } + } +} diff --git a/src/Tizen.Multimedia/MediaTool/MediaPacketBuffer.cs b/src/Tizen.Multimedia/MediaTool/MediaPacketBuffer.cs new file mode 100644 index 0000000..f705879 --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/MediaPacketBuffer.cs @@ -0,0 +1,156 @@ +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace Tizen.Multimedia +{ + /// + /// Represents a buffer for a . + /// + public class MediaPacketBuffer + { + private readonly MediaPacket _packet; + private readonly IntPtr _dataHandle; + + internal MediaPacketBuffer(MediaPacket packet, IntPtr dataHandle, int size) + { + Debug.Assert(packet != null, "Packet is null!"); + Debug.Assert(!packet.IsDisposed, "Packet is already disposed!"); + Debug.Assert(dataHandle != IntPtr.Zero, "dataHandle is null!"); + Debug.Assert(size >= 0, "size must not be negative!"); + + _packet = packet; + _dataHandle = dataHandle; + _length = size; + } + + /// + /// Gets or sets a value at the specified index. + /// + /// The index of the value to get or set. + /// + /// index is less than zero. + /// -or- + /// index is equal to or greater than . + /// + /// The MediaPacket that owns the current buffer already has been disposed of. + /// The MediaPacket that owns the current buffer is being used by another module. + public byte this[int index] + { + get + { + _packet.EnsureReadableState(); + + if (index < 0 || index >= Length) + { + throw new ArgumentOutOfRangeException($"Valid index range is [0, { nameof(Length) })."); + } + + return Marshal.ReadByte(_dataHandle, index); + } + set + { + _packet.EnsureWritableState(); + + Marshal.WriteByte(_dataHandle, index, value); + } + } + + /// + /// Validates the range + /// + /// + /// + /// + /// offset + length is greater than . + /// -or- + /// offset or length is less than zero. + /// + private void ValidateRange(int offset, int length) + { + if (offset + length > _length) + { + throw new ArgumentOutOfRangeException("offset + length can't be greater than length of the buffer."); + } + if (length < 0) + { + throw new ArgumentOutOfRangeException($"Length can't be less than zero : { length }."); + } + if (offset < 0) + { + throw new ArgumentOutOfRangeException($"Offset can't be less than zero : { offset }."); + } + } + + /// + /// Copies data from a byte array to the buffer. + /// + /// The array to copy from. + /// The zero-based index in the source array where copying should start. + /// The number of array elements to copy. + /// The zero-based index in the buffer where copying should start. + /// startIndex, offset or length is not valid. + /// The MediaPacket that owns the current buffer already has been disposed of. + public void CopyFrom(byte[] source, int startIndex, int length, int offset = 0) + { + _packet.EnsureReadableState(); + + if (startIndex < 0) + { + throw new ArgumentOutOfRangeException("startIndex can't be less than zero."); + } + if (startIndex + length > source.Length) + { + throw new ArgumentOutOfRangeException("startIndex + length can't be greater than source.Length."); + } + + ValidateRange(offset, length); + + Marshal.Copy(source, startIndex, IntPtr.Add(_dataHandle, offset), length); + } + + /// + /// Copies data from the buffer to a byte array. + /// + /// The array to copy to. + /// The zero-based index in the dest array where copying should start. + /// The number of elements to copy. + /// The zero-based index in the buffer where copying should start. + /// startIndex, offset or length is not valid. + /// The MediaPacket that owns the current buffer already has been disposed of. + /// The MediaPacket that owns the current buffer is being used by another module. + public void CopyTo(byte[] dest, int startIndex, int length, int offset = 0) + { + _packet.EnsureWritableState(); + + if (startIndex < 0) + { + throw new ArgumentOutOfRangeException("Start index can't be less than zero."); + } + if (startIndex + length > dest.Length) + { + throw new ArgumentOutOfRangeException("startIndex + length can't be greater than dest.Length."); + } + + ValidateRange(offset, length); + + Marshal.Copy(IntPtr.Add(_dataHandle, offset), dest, startIndex, length); + } + + private readonly int _length; + + /// + /// Gets the size of the buffer, in bytes. + /// + /// The MediaPacket that owns the current buffer already has been disposed of. + public int Length + { + get + { + _packet.EnsureReadableState(); + + return _length; + } + } + } +} diff --git a/src/Tizen.Multimedia/MediaTool/MediaPacketBufferFlags.cs b/src/Tizen.Multimedia/MediaTool/MediaPacketBufferFlags.cs new file mode 100644 index 0000000..1f127e4 --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/MediaPacketBufferFlags.cs @@ -0,0 +1,12 @@ +using System; + +namespace Tizen.Multimedia +{ + [Flags] + public enum MediaPacketBufferFlags + { + CodecConfig = 0x1, + EndOfStream = 0x2, + SyncFrame = 0x4, + } +} diff --git a/src/Tizen.Multimedia/MediaTool/MediaPacketVideoPlane.cs b/src/Tizen.Multimedia/MediaTool/MediaPacketVideoPlane.cs new file mode 100644 index 0000000..12aa896 --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/MediaPacketVideoPlane.cs @@ -0,0 +1,77 @@ +using System; +using System.Diagnostics; + +namespace Tizen.Multimedia +{ + /// + /// Represents a video plane for . + /// This class is used if and only if the format of the packet is raw video. + /// + public class MediaPacketVideoPlane + { + private readonly MediaPacket _packet; + private readonly int _strideWidth; + private readonly int _strideHeight; + private readonly MediaPacketBuffer _buffer; + + internal MediaPacketVideoPlane(MediaPacket packet, int index) + { + Debug.Assert(packet != null, "The packet is null!"); + Debug.Assert(!packet.IsDisposed, "Packet is already disposed!"); + Debug.Assert(index >= 0, "Video plane index must not be negative!"); + + _packet = packet; + + int ret = Interop.MediaPacket.GetVideoStrideWidth(packet.GetHandle(), index, out _strideWidth); + MediaToolDebug.AssertNoError(ret); + + ret = Interop.MediaPacket.GetVideoStrideWidth(packet.GetHandle(), index, out _strideHeight); + MediaToolDebug.AssertNoError(ret); + + IntPtr dataHandle = IntPtr.Zero; + ret = Interop.MediaPacket.GetVideoPlaneData(packet.GetHandle(), index, out dataHandle); + MediaToolDebug.AssertNoError(ret); + + _buffer = new MediaPacketBuffer(packet, dataHandle, _strideWidth * _strideHeight); + } + + /// + /// Gets the buffer of the current video plane. + /// + /// The MediaPacket that owns the current buffer already has been disposed of. + public MediaPacketBuffer Buffer + { + get + { + _packet.EnsureReadableState(); + return _buffer; + } + } + + /// + /// Gets the stride width of the current video plane. + /// + /// The MediaPacket that owns the current buffer already has been disposed of. + public int StrideWidth + { + get + { + _packet.EnsureReadableState(); + return _strideWidth; + } + } + + /// + /// Gets the stride height of the current video plane. + /// + /// The MediaPacket that owns the current buffer already has been disposed of. + public int StrideHeight + { + get + { + _packet.EnsureReadableState(); + return _strideHeight; + } + } + } +} diff --git a/src/Tizen.Multimedia/MediaTool/MediaToolDebug.cs b/src/Tizen.Multimedia/MediaTool/MediaToolDebug.cs new file mode 100644 index 0000000..f11f08d --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/MediaToolDebug.cs @@ -0,0 +1,17 @@ + +using System.Diagnostics; +using Tizen.Internals.Errors; + +namespace Tizen.Multimedia +{ + internal class MediaToolDebug + { + + [ConditionalAttribute("DEBUG")] + internal static void AssertNoError(int errorCode) + { + Debug.Assert(errorCode == (int)ErrorCode.None, "The API is supposed not to return an error!", + "Implementation of core may have been changed, modify code to throw if the return code is not zero."); + } + } +} diff --git a/src/Tizen.Multimedia/MediaTool/NotEnoughMemoryException.cs b/src/Tizen.Multimedia/MediaTool/NotEnoughMemoryException.cs new file mode 100644 index 0000000..a258e8b --- /dev/null +++ b/src/Tizen.Multimedia/MediaTool/NotEnoughMemoryException.cs @@ -0,0 +1,18 @@ +using System; + +namespace Tizen.Multimedia +{ + /// + /// The exception that is thrown when there is no memory to allocate a new buffer for the packet. + /// + public class NotEnoughMemoryException : Exception + { + /// + /// Initializes a new instance of the NotEnoughMemoryException class with a specified error message. + /// + /// Error description. + public NotEnoughMemoryException(string message) : base(message) + { + } + } +} diff --git a/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj b/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj index de081e6..bd71381 100755 --- a/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj +++ b/src/Tizen.Multimedia/Tizen.Multimedia.Net45.csproj @@ -1,134 +1,146 @@ - - - - Debug - AnyCPU - {026550F4-E9A0-48F3-BCBF-0AB37268C3D7} - Library - Properties - Tizen.Multimedia - Tizen.Multimedia - 512 - v4.5 - - - true - full - false - bin\Debug\Net45\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\Net45\ - TRACE - prompt - 4 - - - true - - - Tizen.Multimedia.snk - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + Debug + AnyCPU + {026550F4-E9A0-48F3-BCBF-0AB37268C3D7} + Library + Properties + Tizen.Multimedia + Tizen.Multimedia + 512 + v4.5 + + + true + full + false + bin\Debug\Net45\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\Net45\ + TRACE + prompt + 4 + + + true + + + Tizen.Multimedia.snk + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Tizen.Multimedia/Tizen.Multimedia.csproj b/src/Tizen.Multimedia/Tizen.Multimedia.csproj index 27f6bbe..a46db69 100755 --- a/src/Tizen.Multimedia/Tizen.Multimedia.csproj +++ b/src/Tizen.Multimedia/Tizen.Multimedia.csproj @@ -50,8 +50,20 @@ + + + + + + + + + + + + @@ -165,4 +177,4 @@ <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) true - + \ No newline at end of file -- 2.7.4