[MediaTool] Add duration and maxBps (#539)
authorhsgwon <haesu.gwon@samsung.com>
Fri, 23 Nov 2018 04:59:13 +0000 (13:59 +0900)
committerGitHub <noreply@github.com>
Fri, 23 Nov 2018 04:59:13 +0000 (13:59 +0900)
src/Tizen.Multimedia/Interop/Interop.MediaTool.cs
src/Tizen.Multimedia/MediaTool/MediaPacket.cs
src/Tizen.Multimedia/MediaTool/VideoMediaFormat.cs

index 32104bc..35c5e4a 100644 (file)
@@ -94,6 +94,12 @@ namespace Tizen.Multimedia
 
             [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_rotate_method")]
             internal static extern int GetRotation(IntPtr handle, out RotationFlip rotationFlip);
+
+            [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_set_duration")]
+            internal static extern int SetDuration(IntPtr handle, ulong value);
+
+            [DllImport(Libraries.MediaTool, EntryPoint = "media_packet_get_duration")]
+            internal static extern int GetDuration(IntPtr handle, out ulong value);
         }
 
         internal static class MediaFormat
@@ -135,6 +141,9 @@ namespace Tizen.Multimedia
             [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_max_bps")]
+            internal static extern int SetVideoMaxBps(IntPtr handle, int value);
+
             [DllImport(Libraries.MediaTool, EntryPoint = "media_format_set_video_frame_rate")]
             internal static extern int SetVideoFrameRate(IntPtr handle, int value);
             #endregion
index dca709e..54ca5b1 100644 (file)
@@ -59,8 +59,7 @@ namespace Tizen.Multimedia
         {
             _handle = handle;
 
-            IntPtr formatHandle;
-            int ret = Interop.MediaPacket.GetFormat(handle, out formatHandle);
+            int ret = Interop.MediaPacket.GetFormat(handle, out IntPtr formatHandle);
 
             MultimediaDebug.AssertNoError(ret);
 
@@ -231,6 +230,35 @@ namespace Tizen.Multimedia
         }
 
         /// <summary>
+        /// Gets or sets the duration value of the current packet.
+        /// </summary>
+        /// <exception cref="ObjectDisposedException">The MediaPacket has already been disposed of.</exception>
+        /// <exception cref="InvalidOperationException">
+        ///     The MediaPacket is not in the writable state, which means it is being used by another module.
+        /// </exception>
+        /// <since_tizen> 6 </since_tizen>
+        public ulong Duration
+        {
+            get
+            {
+                ValidateNotDisposed();
+
+                int ret = Interop.MediaPacket.GetDuration(_handle, out var value);
+                MultimediaDebug.AssertNoError(ret);
+
+                return value;
+            }
+            set
+            {
+                ValidateNotDisposed();
+                ValidateNotLocked();
+
+                int ret = Interop.MediaPacket.SetDuration(_handle, value);
+                MultimediaDebug.AssertNoError(ret);
+            }
+        }
+
+        /// <summary>
         /// Gets a value indicating whether the packet is the encoded type.
         /// </summary>
         /// <value>true if the packet is the encoded type; otherwise, false.</value>
index b627747..652b494 100644 (file)
@@ -27,6 +27,7 @@ namespace Tizen.Multimedia
     {
         private const int DefaultFrameRate = 0;
         private const int DefaultBitRate = 0;
+        private const int DefaultMaxBps = 0;
 
         /// <summary>
         /// Initializes a new instance of the VideoMediaFormat class with the specified mime type, width, and height.
@@ -132,6 +133,31 @@ namespace Tizen.Multimedia
         /// <since_tizen> 3 </since_tizen>
         public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size,
             int frameRate, int bitRate)
+            : this (mimeType, size, frameRate, bitRate, DefaultMaxBps)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the VideoMediaFormat class with the specified mime type,
+        /// size, frame rate, and bit rate.
+        /// </summary>
+        /// <param name="mimeType">The mime type of the format.</param>
+        /// <param name="size">The size of the format.</param>
+        /// <param name="frameRate">The frame rate of the format.</param>
+        /// <param name="bitRate">The bit rate of the format.</param>
+        /// <param name="maxBps">The max bps of the format.</param>
+        /// <exception cref="ArgumentException"><paramref name="mimeType"/> is invalid (i.e. undefined value).</exception>
+        /// <exception cref="ArgumentOutOfRangeException">
+        ///     The width or the height of <paramref name="size"/> is less than zero.<br/>
+        ///     -or-<br/>
+        ///     <paramref name="frameRate"/> is less than zero.<br/>
+        ///     -or-<br/>
+        ///     <paramref name="bitRate"/> is less than zero.
+        ///     -or-<br/>
+        ///     <paramref name="maxBps"/> is less than zero.
+        /// </exception>
+        /// <since_tizen> 6 </since_tizen>
+        public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size, int frameRate, int bitRate, int maxBps)
             : base(MediaFormatType.Video)
         {
             ValidationUtil.ValidateEnum(typeof(MediaFormatVideoMimeType), mimeType, nameof(mimeType));
@@ -152,11 +178,16 @@ namespace Tizen.Multimedia
             {
                 throw new ArgumentOutOfRangeException(nameof(bitRate), bitRate, "Bit rate value can't be less than zero.");
             }
+            if (maxBps < 0)
+            {
+                throw new ArgumentOutOfRangeException(nameof(maxBps), maxBps, "Max bps value can't be less than zero.");
+            }
 
             MimeType = mimeType;
             Size = size;
             FrameRate = frameRate;
             BitRate = bitRate;
+            MaxBps = maxBps;
         }
 
         /// <summary>
@@ -184,6 +215,7 @@ namespace Tizen.Multimedia
             Size = new Size(width, height);
             FrameRate = frameRate;
             BitRate = bitRate;
+            MaxBps = maxBps;
         }
 
         internal override void AsNativeHandle(IntPtr handle)
@@ -204,6 +236,9 @@ namespace Tizen.Multimedia
 
             ret = Interop.MediaFormat.SetVideoFrameRate(handle, FrameRate);
             MultimediaDebug.AssertNoError(ret);
+
+            ret = Interop.MediaFormat.SetVideoMaxBps(handle, MaxBps);
+            MultimediaDebug.AssertNoError(ret);
         }
 
         /// <summary>
@@ -231,13 +266,19 @@ namespace Tizen.Multimedia
         public int BitRate { get; }
 
         /// <summary>
+        /// Gets the max bps value of the current format.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public int MaxBps { get; }
+
+        /// <summary>
         /// Returns a string that represents the current object.
         /// </summary>
         /// <returns>A string that represents the current object.</returns>
         /// <since_tizen> 3 </since_tizen>
         public override string ToString()
             => $@"MimeType={ MimeType.ToString() }, Size=({ Size.ToString() }), FrameRate=
-                { FrameRate.ToString() }, BitRate={ BitRate.ToString() }";
+                { FrameRate.ToString() }, BitRate={ BitRate.ToString() }, MaxBps = { MaxBps.ToString() }";
 
         /// <summary>
         /// Compares an object to an instance of <see cref="VideoMediaFormat"/> for equality.
@@ -254,7 +295,7 @@ namespace Tizen.Multimedia
             }
 
             return MimeType == rhs.MimeType && Size == rhs.Size &&
-                FrameRate == rhs.FrameRate && BitRate == rhs.BitRate;
+                FrameRate == rhs.FrameRate && BitRate == rhs.BitRate && MaxBps == rhs.MaxBps;
         }
 
         /// <summary>
@@ -263,6 +304,6 @@ namespace Tizen.Multimedia
         /// <returns>The hash code for this instance of <see cref="VideoMediaFormat"/>.</returns>
         /// <since_tizen> 3 </since_tizen>
         public override int GetHashCode()
-            => new { MimeType, Size, FrameRate, BitRate }.GetHashCode();
+            => new { MimeType, Size, FrameRate, BitRate, MaxBps }.GetHashCode();
     }
 }