From: coderhyme Date: Fri, 2 Feb 2018 06:56:49 +0000 (+0900) Subject: [Multimedia] Code cleaning of MediaTool. (#99) X-Git-Tag: 5.0.0-preview1-00456^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=68e9e3a1f6ab5d26530a290eea6ebc7bdebad397;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Multimedia] Code cleaning of MediaTool. (#99) - Use out variable. - Validate enum with util method. - MediaPacket.Lock now uses a field of MediaPacket not packet itself. - And minor code improvement. Signed-off-by: coderhyme --- diff --git a/src/Tizen.Multimedia/Interop/Interop.EvasObject.cs b/src/Tizen.Multimedia/Interop/Interop.EvasObject.cs index 69ae936..bccd747 100644 --- a/src/Tizen.Multimedia/Interop/Interop.EvasObject.cs +++ b/src/Tizen.Multimedia/Interop/Interop.EvasObject.cs @@ -25,10 +25,9 @@ namespace Tizen.Multimedia { [DllImport("libevas.so.1")] internal static extern IntPtr evas_object_image_add(IntPtr parent); + [DllImport("libevas.so.1")] internal static extern IntPtr evas_object_evas_get(IntPtr obj); - [DllImport("libevas.so.1")] - internal static extern void evas_object_show(IntPtr obj); } } } \ No newline at end of file diff --git a/src/Tizen.Multimedia/Interop/Interop.Libc.cs b/src/Tizen.Multimedia/Interop/Interop.Libc.cs index 5c25fda..407352c 100644 --- a/src/Tizen.Multimedia/Interop/Interop.Libc.cs +++ b/src/Tizen.Multimedia/Interop/Interop.Libc.cs @@ -32,8 +32,6 @@ namespace Tizen.Multimedia [DllImport(Libraries.Libc, EntryPoint = "free")] public static extern void Free(IntPtr ptr); - - [DllImport(Libraries.Libc, EntryPoint = "access")] public static extern int Access(string path, int mode); } diff --git a/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs b/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs index f9177e5..4ab150f 100644 --- a/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs +++ b/src/Tizen.Multimedia/Interop/Interop.MediaTool.cs @@ -83,7 +83,6 @@ namespace Tizen.Multimedia [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); @@ -100,24 +99,26 @@ namespace Tizen.Multimedia 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); + internal static extern int GetType(IntPtr handle, out MediaFormatType type); [DllImport(Libraries.MediaTool, EntryPoint = "media_format_get_container_mime")] - internal static extern int GetContainerMimeType(IntPtr handle, out int mimeType); + internal static extern int GetContainerMimeType(IntPtr handle, + out MediaFormatContainerMimeType mimeType); [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_container_mime")] - internal static extern int SetContainerMimeType(IntPtr handle, int mimeType); + internal static extern int SetContainerMimeType(IntPtr handle, + MediaFormatContainerMimeType mimeType); #region Video apis [DllImport(Libraries.MediaTool, EntryPoint = "media_format_get_video_info")] - internal static extern int GetVideoInfo(IntPtr handle, out int mimeType, + internal static extern int GetVideoInfo(IntPtr handle, out MediaFormatVideoMimeType 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); + internal static extern int SetVideoMimeType(IntPtr handle, MediaFormatVideoMimeType value); [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_video_width")] internal static extern int SetVideoWidth(IntPtr handle, int value); @@ -134,14 +135,14 @@ namespace Tizen.Multimedia #region Audio apis [DllImport(Libraries.MediaTool, EntryPoint = "media_format_get_audio_info")] - internal static extern int GetAudioInfo(IntPtr handle, out int mimeType, + internal static extern int GetAudioInfo(IntPtr handle, out MediaFormatAudioMimeType 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); + internal static extern int GetAudioAacType(IntPtr handle, out MediaFormatAacType aacType); [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_audio_mime")] - internal static extern int SetAudioMimeType(IntPtr handle, int value); + internal static extern int SetAudioMimeType(IntPtr handle, MediaFormatAudioMimeType value); [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_audio_channel")] internal static extern int SetAudioChannel(IntPtr handle, int value); @@ -156,17 +157,18 @@ namespace Tizen.Multimedia 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); + internal static extern int SetAudioAacType(IntPtr handle, MediaFormatAacType value); #endregion [DllImport(Libraries.MediaTool, EntryPoint = "media_format_get_text_info")] - internal static extern int GetTextInfo(IntPtr handle, out int mimeType, out int textType); + internal static extern int GetTextInfo(IntPtr handle, + out MediaFormatTextMimeType mimeType, out MediaFormatTextType textType); [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_text_mime")] - internal static extern int SetTextMimeType(IntPtr handle, int value); + internal static extern int SetTextMimeType(IntPtr handle, MediaFormatTextMimeType value); [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_text_type")] - internal static extern int SetTextType(IntPtr handle, int value); + internal static extern int SetTextType(IntPtr handle, MediaFormatTextType value); } } } \ No newline at end of file diff --git a/src/Tizen.Multimedia/MediaTool/AudioMediaFormat.cs b/src/Tizen.Multimedia/MediaTool/AudioMediaFormat.cs index 2abf1ae..db99fff 100644 --- a/src/Tizen.Multimedia/MediaTool/AudioMediaFormat.cs +++ b/src/Tizen.Multimedia/MediaTool/AudioMediaFormat.cs @@ -25,7 +25,6 @@ namespace Tizen.Multimedia /// 3 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. @@ -42,7 +41,7 @@ namespace Tizen.Multimedia /// 3 public AudioMediaFormat(MediaFormatAudioMimeType mimeType, int channel, int sampleRate, int bit, int bitRate) - : this(mimeType, channel, sampleRate, bit, bitRate, MediaFormatAacType.None) + : this(mimeType, channel, sampleRate, bit, bitRate, MediaFormatAacType.None) { } @@ -69,30 +68,31 @@ namespace Tizen.Multimedia 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 }"); - } + ValidationUtil.ValidateEnum(typeof(MediaFormatAudioMimeType), mimeType, nameof(mimeType)); + if (channel < 0) { - throw new ArgumentOutOfRangeException("Channel value can't be negative."); + throw new ArgumentOutOfRangeException(nameof(channel), channel, + "Channel value can't be negative."); } if (sampleRate < 0) { - throw new ArgumentOutOfRangeException("Sample rate value can't be negative."); + throw new ArgumentOutOfRangeException(nameof(sampleRate), sampleRate, + "Sample rate value can't be negative."); } if (bit < 0) { - throw new ArgumentOutOfRangeException("Bit value can't be negative."); + throw new ArgumentOutOfRangeException(nameof(bit), bit, + "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 }"); + throw new ArgumentOutOfRangeException(nameof(bitRate), bitRate, + "Bit rate value can't be negative."); } + + ValidationUtil.ValidateEnum(typeof(MediaFormatAacType), aacType, nameof(aacType)); + if (!IsAacSupportedMimeType(mimeType) && aacType != MediaFormatAacType.None) { throw new ArgumentException("Aac is supported only with aac mime types."); @@ -115,29 +115,14 @@ namespace Tizen.Multimedia { Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); - MediaFormatAudioMimeType mimeType; - int channel = 0; - int sampleRate = 0; - int bit = 0; - int bitRate = 0; - MediaFormatAacType aacType; - GetInfo(handle, out mimeType, out channel, out sampleRate, out bit, out bitRate); - - if (IsAacSupportedMimeType(mimeType)) - { - GetAacType(handle, out aacType); - } - else - { - aacType = MediaFormatAacType.None; - } + GetInfo(handle, out var mimeType, out var channel, out var sampleRate, out var bit, out var bitRate); MimeType = mimeType; Channel = channel; SampleRate = sampleRate; Bit = bit; BitRate = bitRate; - AacType = aacType; + AacType = IsAacSupportedMimeType(mimeType) ? GetAacType(handle) : MediaFormatAacType.None; } /// @@ -165,12 +150,8 @@ namespace Tizen.Multimedia { 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; + out mimeType, out channel, out sampleRate, out bit, out bitRate); MultimediaDebug.AssertNoError(ret); @@ -182,27 +163,24 @@ namespace Tizen.Multimedia /// Retrieves the AAC type value from a native handle. /// /// A native handle that the properties are retrieved from. - /// An out parameter for tha AAC type. - private static void GetAacType(IntPtr handle, out MediaFormatAacType aacType) + private static MediaFormatAacType GetAacType(IntPtr handle) { Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); - int aacTypeValue = 0; - - int ret = Interop.MediaFormat.GetAudioAacType(handle, out aacTypeValue); + int ret = Interop.MediaFormat.GetAudioAacType(handle, out var aacType); MultimediaDebug.AssertNoError(ret); - aacType = (MediaFormatAacType)aacTypeValue; - Debug.Assert(Enum.IsDefined(typeof(MediaFormatAacType), aacType), "Invalid aac type!"); + + return aacType; } internal override void AsNativeHandle(IntPtr handle) { Debug.Assert(Type == MediaFormatType.Audio); - int ret = Interop.MediaFormat.SetAudioMimeType(handle, (int)MimeType); + int ret = Interop.MediaFormat.SetAudioMimeType(handle, MimeType); MultimediaDebug.AssertNoError(ret); ret = Interop.MediaFormat.SetAudioChannel(handle, Channel); @@ -217,7 +195,7 @@ namespace Tizen.Multimedia ret = Interop.MediaFormat.SetAudioAverageBps(handle, BitRate); MultimediaDebug.AssertNoError(ret); - ret = Interop.MediaFormat.SetAudioAacType(handle, (int)AacType); + ret = Interop.MediaFormat.SetAudioAacType(handle, AacType); MultimediaDebug.AssertNoError(ret); } @@ -281,7 +259,7 @@ namespace Tizen.Multimedia } return MimeType == rhs.MimeType && Channel == rhs.Channel && SampleRate == rhs.SampleRate && - Bit == rhs.Bit && BitRate == rhs.BitRate; + Bit == rhs.Bit && BitRate == rhs.BitRate && AacType == rhs.AacType; } /// @@ -290,6 +268,6 @@ namespace Tizen.Multimedia /// The hash code for this instance of . /// 3 public override int GetHashCode() - => new { MimeType, Channel, SampleRate, Bit, BitRate }.GetHashCode(); + => new { MimeType, Channel, SampleRate, Bit, BitRate, AacType }.GetHashCode(); } } diff --git a/src/Tizen.Multimedia/MediaTool/ContainerMediaFormat.cs b/src/Tizen.Multimedia/MediaTool/ContainerMediaFormat.cs index f7e89c8..3c0e501 100644 --- a/src/Tizen.Multimedia/MediaTool/ContainerMediaFormat.cs +++ b/src/Tizen.Multimedia/MediaTool/ContainerMediaFormat.cs @@ -34,10 +34,9 @@ namespace Tizen.Multimedia public ContainerMediaFormat(MediaFormatContainerMimeType mimeType) : base(MediaFormatType.Container) { - if (!Enum.IsDefined(typeof(MediaFormatContainerMimeType), mimeType)) - { - throw new ArgumentException($"Invalid mime type value : { (int)mimeType }"); - } + ValidationUtil.ValidateEnum(typeof(MediaFormatContainerMimeType), mimeType, + nameof(mimeType)); + MimeType = mimeType; } @@ -50,16 +49,14 @@ namespace Tizen.Multimedia { Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); - int mimeType = 0; - - int ret = Interop.MediaFormat.GetContainerMimeType(handle, out mimeType); + int ret = Interop.MediaFormat.GetContainerMimeType(handle, out var mimeType); MultimediaDebug.AssertNoError(ret); Debug.Assert(Enum.IsDefined(typeof(MediaFormatContainerMimeType), mimeType), "Invalid container mime type!"); - MimeType = (MediaFormatContainerMimeType)mimeType; + MimeType = mimeType; } /// @@ -72,7 +69,7 @@ namespace Tizen.Multimedia { Debug.Assert(Type == MediaFormatType.Container); - int ret = Interop.MediaFormat.SetContainerMimeType(handle, (int)MimeType); + int ret = Interop.MediaFormat.SetContainerMimeType(handle, MimeType); MultimediaDebug.AssertNoError(ret); } @@ -106,7 +103,6 @@ namespace Tizen.Multimedia /// /// The hash code for this instance of . /// 3 - public override int GetHashCode() - => (int)MimeType; + public override int GetHashCode() => MimeType.GetHashCode(); } } diff --git a/src/Tizen.Multimedia/MediaTool/MediaFormat.cs b/src/Tizen.Multimedia/MediaTool/MediaFormat.cs index 15a383d..1bd0433 100755 --- a/src/Tizen.Multimedia/MediaTool/MediaFormat.cs +++ b/src/Tizen.Multimedia/MediaTool/MediaFormat.cs @@ -39,10 +39,7 @@ namespace Tizen.Multimedia /// Gets the type of the current format. /// /// 3 - public MediaFormatType Type - { - get; - } + public MediaFormatType Type { get; } /// /// Creates a media format from a native handle. @@ -53,17 +50,16 @@ namespace Tizen.Multimedia { if (handle == IntPtr.Zero) { - throw new ArgumentException("The handle value is invalid."); + throw new ArgumentException("The handle value is invalid.", nameof(handle)); } - int type = 0; - int ret = Interop.MediaFormat.GetType(handle, out type); + int ret = Interop.MediaFormat.GetType(handle, out var type); if (ret != (int)ErrorCode.InvalidOperation) { MultimediaDebug.AssertNoError(ret); - switch ((MediaFormatType)type) + switch (type) { case MediaFormatType.Container: return new ContainerMediaFormat(handle); @@ -89,8 +85,7 @@ namespace Tizen.Multimedia /// The returned handle must be destroyed using . internal IntPtr AsNativeHandle() { - IntPtr handle; - int ret = Interop.MediaFormat.Create(out handle); + int ret = Interop.MediaFormat.Create(out var handle); MultimediaDebug.AssertNoError(ret); diff --git a/src/Tizen.Multimedia/MediaTool/MediaPacket.Lock.cs b/src/Tizen.Multimedia/MediaTool/MediaPacket.Lock.cs index 544011d..5629119 100644 --- a/src/Tizen.Multimedia/MediaTool/MediaPacket.Lock.cs +++ b/src/Tizen.Multimedia/MediaTool/MediaPacket.Lock.cs @@ -73,13 +73,7 @@ namespace Tizen.Multimedia } } - internal bool IsLocked - { - get - { - return Interlocked.CompareExchange(ref _locked, 0, 0) == LOCKED; - } - } + internal bool IsLocked => Interlocked.CompareExchange(ref _locked, 0, 0) == LOCKED; } /// @@ -101,14 +95,9 @@ namespace Tizen.Multimedia { Debug.Assert(packet != null); - lock (packet) + lock (packet._lock) { - Lock lck = FromHandle(packet._handle); - - if (lck == null) - { - lck = new Lock(packet); - } + Lock lck = FromHandle(packet._handle) ?? new Lock(packet); lck._lockCount++; @@ -154,27 +143,16 @@ namespace Tizen.Multimedia private static IntPtr GetExtra(IntPtr handle) { - IntPtr value; - - int ret = Interop.MediaPacket.GetExtra(handle, out value); + int ret = Interop.MediaPacket.GetExtra(handle, out var value); MultimediaDebug.AssertNoError(ret); return value; } - internal IntPtr GetHandle() - { - return _packet.GetHandle(); - } + internal IntPtr GetHandle() => _packet.GetHandle(); - internal MediaPacket MediaPacket - { - get - { - return _packet; - } - } + internal MediaPacket MediaPacket => _packet; private bool _isDisposed = false; @@ -182,7 +160,7 @@ namespace Tizen.Multimedia { if (!_isDisposed) { - lock (_packet) + lock (_packet._lock) { _lockCount--; @@ -195,7 +173,7 @@ namespace Tizen.Multimedia _gcHandle.Free(); } - //We can assure that at this point '_packet' is always locked by this lock. + // We can assure that at this point '_packet' is always locked by this lock. _packet._lock.SetUnlock(); } } diff --git a/src/Tizen.Multimedia/MediaTool/MediaPacket.cs b/src/Tizen.Multimedia/MediaTool/MediaPacket.cs index db06a29..d8b4a1e 100644 --- a/src/Tizen.Multimedia/MediaTool/MediaPacket.cs +++ b/src/Tizen.Multimedia/MediaTool/MediaPacket.cs @@ -45,12 +45,8 @@ namespace Tizen.Multimedia throw new ArgumentNullException(nameof(format)); } - if (format.Type == MediaFormatType.Container) - { - throw new ArgumentException("Container format can't be used to create a new packet."); - } - Initialize(format); + _format = format; _buffer = new Lazy(GetBuffer); } @@ -98,7 +94,8 @@ namespace Tizen.Multimedia { if (format.Type == MediaFormatType.Container) { - throw new ArgumentException("Creating a packet for container is not supported."); + throw new ArgumentException("Container format can't be used to create a new packet.", + nameof(format)); } IntPtr formatHandle = IntPtr.Zero; @@ -187,8 +184,7 @@ namespace Tizen.Multimedia { ValidateNotDisposed(); - ulong value = 0; - int ret = Interop.MediaPacket.GetPts(_handle, out value); + int ret = Interop.MediaPacket.GetPts(_handle, out var value); MultimediaDebug.AssertNoError(ret); @@ -219,8 +215,7 @@ namespace Tizen.Multimedia { ValidateNotDisposed(); - ulong value = 0; - int ret = Interop.MediaPacket.GetDts(_handle, out value); + int ret = Interop.MediaPacket.GetDts(_handle, out var value); MultimediaDebug.AssertNoError(ret); @@ -249,8 +244,7 @@ namespace Tizen.Multimedia { ValidateNotDisposed(); - bool value = false; - int ret = Interop.MediaPacket.IsEncoded(_handle, out value); + int ret = Interop.MediaPacket.IsEncoded(_handle, out var value); MultimediaDebug.AssertNoError(ret); @@ -304,8 +298,7 @@ namespace Tizen.Multimedia { ValidateNotDisposed(); - ulong value = 0; - int ret = Interop.MediaPacket.GetBufferSize(_handle, out value); + int ret = Interop.MediaPacket.GetBufferSize(_handle, out var value); MultimediaDebug.AssertNoError(ret); Debug.Assert(value < int.MaxValue); @@ -327,7 +320,8 @@ namespace Tizen.Multimedia if (value < 0 || value >= Buffer.Length) { - throw new ArgumentOutOfRangeException("value must be less than Buffer.Size."); + throw new ArgumentOutOfRangeException(nameof(value), value, + "value must be less than Buffer.Size."); } int ret = Interop.MediaPacket.SetBufferSize(_handle, (ulong)value); @@ -499,13 +493,7 @@ namespace Tizen.Multimedia /// Gets a value indicating whether the packet is in the raw video format. /// /// true if the packet is in the raw video format; otherwise, false. - private bool IsVideoPlaneSupported - { - get - { - return !IsEncoded && Format.Type == MediaFormatType.Video; - } - } + private bool IsVideoPlaneSupported => !IsEncoded && Format.Type == MediaFormatType.Video; /// /// Retrieves video planes of the current packet. @@ -515,8 +503,7 @@ namespace Tizen.Multimedia { Debug.Assert(_handle != IntPtr.Zero, "The handle is invalid!"); - uint numberOfPlanes = 0; - int ret = Interop.MediaPacket.GetNumberOfVideoPlanes(_handle, out numberOfPlanes); + int ret = Interop.MediaPacket.GetNumberOfVideoPlanes(_handle, out var numberOfPlanes); MultimediaDebug.AssertNoError(ret); @@ -540,15 +527,12 @@ namespace Tizen.Multimedia Debug.Assert(_handle != IntPtr.Zero, "The handle is invalid!"); - IntPtr dataHandle; - - int ret = Interop.MediaPacket.GetBufferData(_handle, out dataHandle); + int ret = Interop.MediaPacket.GetBufferData(_handle, out var dataHandle); MultimediaDebug.AssertNoError(ret); Debug.Assert(dataHandle != IntPtr.Zero, "Data handle is invalid!"); - int size = 0; - ret = Interop.MediaPacket.GetAllocatedBufferSize(_handle, out size); + ret = Interop.MediaPacket.GetAllocatedBufferSize(_handle, out var size); MultimediaDebug.AssertNoError(ret); Debug.Assert(size >= 0, "size must not be negative!"); diff --git a/src/Tizen.Multimedia/MediaTool/MediaPacketVideoPlane.cs b/src/Tizen.Multimedia/MediaTool/MediaPacketVideoPlane.cs index 9a7c0f6..a751126 100644 --- a/src/Tizen.Multimedia/MediaTool/MediaPacketVideoPlane.cs +++ b/src/Tizen.Multimedia/MediaTool/MediaPacketVideoPlane.cs @@ -47,8 +47,7 @@ namespace Tizen.Multimedia Debug.Assert(_strideWidth >= 0 && _strideHeight >= 0, "size must not be negative!"); - IntPtr dataHandle; - ret = Interop.MediaPacket.GetVideoPlaneData(packet.GetHandle(), index, out dataHandle); + ret = Interop.MediaPacket.GetVideoPlaneData(packet.GetHandle(), index, out var dataHandle); MultimediaDebug.AssertNoError(ret); Debug.Assert(dataHandle != IntPtr.Zero, "Data handle is invalid!"); diff --git a/src/Tizen.Multimedia/MediaTool/TextMediaFormat.cs b/src/Tizen.Multimedia/MediaTool/TextMediaFormat.cs index 19127e8..3c87573 100644 --- a/src/Tizen.Multimedia/MediaTool/TextMediaFormat.cs +++ b/src/Tizen.Multimedia/MediaTool/TextMediaFormat.cs @@ -38,14 +38,9 @@ namespace Tizen.Multimedia 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 }"); - } + ValidationUtil.ValidateEnum(typeof(MediaFormatTextMimeType), mimeType, nameof(mimeType)); + ValidationUtil.ValidateEnum(typeof(MediaFormatTextType), textType, nameof(textType)); + MimeType = mimeType; TextType = textType; } @@ -59,48 +54,27 @@ namespace Tizen.Multimedia { Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); - MediaFormatTextMimeType mimeType; - MediaFormatTextType textType; - - GetInfo(handle, out mimeType, out textType); - - MimeType = mimeType; - TextType = textType; - } - - /// - /// Retrieves text properties of the media format from a native handle. - /// - /// A native handle that the properties are retrieved from. - /// An out parameter for the mime type. - /// An out parameter for the 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); + int ret = Interop.MediaFormat.GetTextInfo(handle, out var mimeType, out var textType); MultimediaDebug.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!"); + + MimeType = mimeType; + TextType = textType; } internal override void AsNativeHandle(IntPtr handle) { Debug.Assert(Type == MediaFormatType.Text); - int ret = Interop.MediaFormat.SetTextMimeType(handle, (int)MimeType); + int ret = Interop.MediaFormat.SetTextMimeType(handle, MimeType); MultimediaDebug.AssertNoError(ret); - ret = Interop.MediaFormat.SetTextType(handle, (int)TextType); + ret = Interop.MediaFormat.SetTextType(handle, TextType); MultimediaDebug.AssertNoError(ret); } diff --git a/src/Tizen.Multimedia/MediaTool/VideoMediaFormat.cs b/src/Tizen.Multimedia/MediaTool/VideoMediaFormat.cs index 5125e9f..b627747 100644 --- a/src/Tizen.Multimedia/MediaTool/VideoMediaFormat.cs +++ b/src/Tizen.Multimedia/MediaTool/VideoMediaFormat.cs @@ -134,10 +134,8 @@ namespace Tizen.Multimedia int frameRate, int bitRate) : base(MediaFormatType.Video) { - if (!Enum.IsDefined(typeof(MediaFormatVideoMimeType), mimeType)) - { - throw new ArgumentException($"Invalid mime type value : { (int)mimeType }"); - } + ValidationUtil.ValidateEnum(typeof(MediaFormatVideoMimeType), mimeType, nameof(mimeType)); + if (size.Width < 0) { throw new ArgumentOutOfRangeException(nameof(size), size.Width, "Size.Width value can't be less than zero."); @@ -170,67 +168,29 @@ namespace Tizen.Multimedia { Debug.Assert(handle != IntPtr.Zero, "The handle is invalid!"); - int width = 0; - int height = 0; - int bitRate = 0; - int frameRate = 0; - MediaFormatVideoMimeType mimeType; - GetInfo(handle, out width, out height, out bitRate, out mimeType); - - GetFrameRate(handle, out frameRate); - - MimeType = mimeType; - Size = new Size(width, height); - FrameRate = frameRate; - BitRate = bitRate; - } - - /// - /// Retrieves video properties of the media format from a native handle. - /// - /// A native handle that the properties are retrieved from. - /// An out parameter for the width. - /// An out parameter for the height. - /// An out parameter for the bit rate. - /// An out parameter for the 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); + out var mimeType, out var width, out var height, out var bitRate, out var maxBps); MultimediaDebug.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 the properties are retrieved from. - /// An out parameter for the 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); + ret = Interop.MediaFormat.GetVideoFrameRate(handle, out var frameRate); MultimediaDebug.AssertNoError(ret); + + MimeType = mimeType; + Size = new Size(width, height); + FrameRate = frameRate; + BitRate = bitRate; } internal override void AsNativeHandle(IntPtr handle) { Debug.Assert(Type == MediaFormatType.Video); - int ret = Interop.MediaFormat.SetVideoMimeType(handle, (int)MimeType); + int ret = Interop.MediaFormat.SetVideoMimeType(handle, MimeType); MultimediaDebug.AssertNoError(ret); ret = Interop.MediaFormat.SetVideoWidth(handle, Size.Width);