[Multimedia] Code cleaning of MediaTool. (#99) 5.0.0-preview1-00456
authorcoderhyme <jhyo.kim@samsung.com>
Fri, 2 Feb 2018 06:56:49 +0000 (15:56 +0900)
committerGitHub <noreply@github.com>
Fri, 2 Feb 2018 06:56:49 +0000 (15:56 +0900)
- 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 <jhyo.kim@samsung.com>
src/Tizen.Multimedia/Interop/Interop.EvasObject.cs
src/Tizen.Multimedia/Interop/Interop.Libc.cs
src/Tizen.Multimedia/Interop/Interop.MediaTool.cs
src/Tizen.Multimedia/MediaTool/AudioMediaFormat.cs
src/Tizen.Multimedia/MediaTool/ContainerMediaFormat.cs
src/Tizen.Multimedia/MediaTool/MediaFormat.cs
src/Tizen.Multimedia/MediaTool/MediaPacket.Lock.cs
src/Tizen.Multimedia/MediaTool/MediaPacket.cs
src/Tizen.Multimedia/MediaTool/MediaPacketVideoPlane.cs
src/Tizen.Multimedia/MediaTool/TextMediaFormat.cs
src/Tizen.Multimedia/MediaTool/VideoMediaFormat.cs

index 69ae936..bccd747 100644 (file)
@@ -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
index 5c25fda..407352c 100644 (file)
@@ -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);
         }
index f9177e5..4ab150f 100644 (file)
@@ -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
index 2abf1ae..db99fff 100644 (file)
@@ -25,7 +25,6 @@ namespace Tizen.Multimedia
     /// <since_tizen> 3 </since_tizen>
     public sealed class AudioMediaFormat : MediaFormat
     {
-
         /// <summary>
         /// 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
         /// <since_tizen> 3 </since_tizen>
         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;
         }
 
         /// <summary>
@@ -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.
         /// </summary>
         /// <param name="handle">A native handle that the properties are retrieved from.</param>
-        /// <param name="aacType">An out parameter for tha AAC type.</param>
-        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;
         }
 
         /// <summary>
@@ -290,6 +268,6 @@ namespace Tizen.Multimedia
         /// <returns>The hash code for this instance of <see cref="AudioMediaFormat"/>.</returns>
         /// <since_tizen> 3 </since_tizen>
         public override int GetHashCode()
-            => new { MimeType, Channel, SampleRate, Bit, BitRate }.GetHashCode();
+            => new { MimeType, Channel, SampleRate, Bit, BitRate, AacType }.GetHashCode();
     }
 }
index f7e89c8..3c0e501 100644 (file)
@@ -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;
         }
 
         /// <summary>
@@ -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
         /// </summary>
         /// <returns>The hash code for this instance of <see cref="ContainerMediaFormat"/>.</returns>
         /// <since_tizen> 3 </since_tizen>
-        public override int GetHashCode()
-            => (int)MimeType;
+        public override int GetHashCode() => MimeType.GetHashCode();
     }
 }
index 15a383d..1bd0433 100755 (executable)
@@ -39,10 +39,7 @@ namespace Tizen.Multimedia
         /// Gets the type of the current format.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        public MediaFormatType Type
-        {
-            get;
-        }
+        public MediaFormatType Type { get; }
 
         /// <summary>
         /// 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
         /// <remarks>The returned handle must be destroyed using <see cref="Interop.MediaFormat.Unref(IntPtr)"/>.</remarks>
         internal IntPtr AsNativeHandle()
         {
-            IntPtr handle;
-            int ret = Interop.MediaFormat.Create(out handle);
+            int ret = Interop.MediaFormat.Create(out var handle);
 
             MultimediaDebug.AssertNoError(ret);
 
index 544011d..5629119 100644 (file)
@@ -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;
         }
 
         /// <summary>
@@ -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();
                         }
                     }
index db06a29..d8b4a1e 100644 (file)
@@ -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<IMediaBuffer>(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.
         /// </summary>
         /// <value>true if the packet is in the raw video format; otherwise, false.</value>
-        private bool IsVideoPlaneSupported
-        {
-            get
-            {
-                return !IsEncoded && Format.Type == MediaFormatType.Video;
-            }
-        }
+        private bool IsVideoPlaneSupported => !IsEncoded && Format.Type == MediaFormatType.Video;
 
         /// <summary>
         /// 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!");
index 9a7c0f6..a751126 100644 (file)
@@ -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!");
index 19127e8..3c87573 100644 (file)
@@ -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;
-        }
-
-        /// <summary>
-        /// Retrieves text properties of the media format from a native handle.
-        /// </summary>
-        /// <param name="handle">A native handle that the properties are retrieved from.</param>
-        /// <param name="mimeType">An out parameter for the mime type.</param>
-        /// <param name="textType">An out parameter for the text type.</param>
-        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);
         }
 
index 5125e9f..b627747 100644 (file)
@@ -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;
-        }
-
-        /// <summary>
-        /// Retrieves video properties of the media format from a native handle.
-        /// </summary>
-        /// <param name="handle">A native handle that the properties are retrieved from.</param>
-        /// <param name="width">An out parameter for the width.</param>
-        /// <param name="height">An out parameter for the height.</param>
-        /// <param name="bitRate">An out parameter for the bit rate.</param>
-        /// <param name="mimeType">An out parameter for the mime type.</param>
-        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!");
-        }
-
-        /// <summary>
-        /// Retrieves frame rate from a native handle.
-        /// </summary>
-        /// <param name="handle">A native handle that the properties are retrieved from.</param>
-        /// <param name="frameRate">An out parameter for the frame rate.</param>
-        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);