[MediaPlayer] add class to set/get adaptive variants and property for buffering time...
authornam <36914158+kqjy777@users.noreply.github.com>
Tue, 26 Jun 2018 07:56:37 +0000 (16:56 +0900)
committerGitHub <noreply@github.com>
Tue, 26 Jun 2018 07:56:37 +0000 (16:56 +0900)
* [MediaPlayer] add class to set/get adaptive variants and property for buffering time

1.add APIs for setting buffering time
2.add AdaptiveVariants class and APIs to set values

* fix the name of values following dotnet rules

* fix the wrong descriptions

* modify Ms to Milisecond for readability

* fix descriptions

src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Player.cs
src/Tizen.Multimedia.MediaPlayer/Player/AdaptiveVariants.cs [new file with mode: 0644]
src/Tizen.Multimedia.MediaPlayer/Player/Player.Properties.cs
src/Tizen.Multimedia.MediaPlayer/Player/SphericalVideo.cs

index 94e9f54..6f14bd3 100644 (file)
@@ -60,6 +60,9 @@ internal static partial class Interop
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         internal delegate void SeekCompletedCallback(IntPtr userData);
 
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate bool AdaptiveVariantCallback(int bandwidth, int width, int height, IntPtr userData);
+
         [DllImport(Libraries.Player, EntryPoint = "player_create")]
         internal static extern PlayerErrorCode Create(out PlayerHandle player);
 
@@ -165,6 +168,12 @@ internal static partial class Interop
         [DllImport(Libraries.Player, EntryPoint = "player_get_streaming_download_progress")]
         internal static extern PlayerErrorCode GetStreamingDownloadProgress(IntPtr player, out int start, out int current);
 
+        [DllImport(Libraries.Player, EntryPoint = "player_set_streaming_buffering_time")]
+        internal static extern PlayerErrorCode SetStreamingBufferingTime(IntPtr player, int bufferingTime, int reBufferingTime);
+
+        [DllImport(Libraries.Player, EntryPoint = "player_get_streaming_buffering_time")]
+        internal static extern PlayerErrorCode GetStreamingBufferingTime(IntPtr player, out int bufferingTime, out int reBufferingTime);
+
         [DllImport(Libraries.Player, EntryPoint = "player_set_buffering_cb")]
         internal static extern PlayerErrorCode SetBufferingCb(IntPtr player,
             BufferingProgressCallback callback, IntPtr userData = default(IntPtr));
@@ -295,6 +304,14 @@ internal static partial class Interop
         [DllImport(Libraries.Player, EntryPoint = "player_360_get_field_of_view")]
         internal static extern PlayerErrorCode GetFieldOfView(IntPtr player, out int horizontalDegrees, out int verticalDegrees);
 
+        [DllImport(Libraries.Player, EntryPoint = "player_foreach_adaptive_variant")]
+        internal static extern PlayerErrorCode ForeachAdaptiveVariants(IntPtr player, AdaptiveVariantCallback callback, IntPtr userData);
+
+        [DllImport(Libraries.Player, EntryPoint = "player_set_max_adaptive_variant_limit")]
+        internal static extern PlayerErrorCode SetMaxLimit(IntPtr player, int bandwidth, int width, int height);
+
+        [DllImport(Libraries.Player, EntryPoint = "player_get_max_adaptive_variant_limit")]
+        internal static extern PlayerErrorCode GetMaxLimit(IntPtr player, out int bandwidth, out int width, out int height);
     }
 
     internal class PlayerHandle : SafeHandle
diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/AdaptiveVariants.cs b/src/Tizen.Multimedia.MediaPlayer/Player/AdaptiveVariants.cs
new file mode 100644 (file)
index 0000000..5162c95
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Diagnostics;
+using System.Collections.Generic;
+using static Interop;
+
+namespace Tizen.Multimedia
+{
+    /// <summary>
+    /// Represents properties for the variant information
+    /// </summary>
+    /// <since_tizen> 5 </since_tizen>
+    public struct VariantInfo
+    {
+        /// <summary>
+        /// Initializes a new instance of the VariantInfo struct.
+        /// </summary>
+        /// <param name="bandwidth">The bandwidth of the stream can be supportable, it must be set. (deafult: -1)</param>
+        /// <param name="width">The width of the stream, this is optional parameter. (deafult: -1)</param>
+        /// <param name="height">The height of the stream, this is optional parameter. (deafult: -1)</param>
+        /// <since_tizen> 5 </since_tizen>
+        public VariantInfo(int bandwidth, int width = -1, int height = -1)
+        {
+            Bandwidth = bandwidth;
+            Width = width;
+            Height = height;
+        }
+
+        /// <summary>
+        /// Gets or sets the maximum limit of the available bandwidth. (-1 = no limit)
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        public int Bandwidth
+        {
+            get;
+            set;
+        }
+
+        /// <summary>
+        /// Gets or sets the maximum limit of the available width. (-1 = no limit)
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        public int Width
+        {
+            get;
+            set;
+        }
+
+        /// <summary>
+        /// Gets or sets the maximum limit of the available height. (-1 = no limit)
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        public int Height
+        {
+            get;
+            set;
+        }
+    }
+
+    /// <summary>
+    /// Provides the ability to control the maximum limit of the available streaming variant for <see cref="Multimedia.Player"/>.
+    /// </summary>
+    /// <since_tizen> 5 </since_tizen>
+    public class AdaptiveVariants
+    {
+        private IList<VariantInfo> _adaptiveVariants;
+
+        /// <summary>
+        /// Gets the <see cref="Multimedia.Player"/> that owns this instance.
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        private readonly Player Player;
+
+        internal AdaptiveVariants(Player player)
+        {
+            Debug.Assert(player != null);
+            Player = player;
+        }
+
+        /// <summary>
+        /// Sets the maximum limit of the streaming variant.
+        /// </summary>
+        /// <exception cref="ObjectDisposedException">The <see cref="Player"/> has already been disposed of.</exception>
+        /// <exception cref="ArgumentOutOfRangeException">
+        ///     <pramref name="bandwidth"/> is less than -1.<br/>
+        ///     -or-<br/>
+        ///     <pramref name="width"/> is less than -1.<br/>
+        ///     -or-<br/>
+        ///     <pramref name="height"/> is less than -1.<br/>
+        /// </exception>
+        /// <seealso cref="GetMaxLimit()"/>
+        /// <since_tizen> 5 </since_tizen>
+        public void SetMaxLimit(int bandwidth, int width = -1, int height = -1)
+        {
+            Player.ValidateNotDisposed();
+
+            if (bandwidth < -1 || width < -1 || height < -1)
+            {
+                throw new ArgumentOutOfRangeException("invalid range");
+            }
+
+            NativePlayer.SetMaxLimit(Player.Handle, bandwidth, width, height).
+                    ThrowIfFailed(Player, "Failed to set the max limit to the player");
+        }
+
+        /// <summary>
+        /// Gets the maximum limit of the streaming variant.
+        /// </summary>
+        /// <returns>The <see cref="VariantInfo"/> containing the variant information.</returns>
+        /// <exception cref="ObjectDisposedException">The <see cref="Player"/> has already been disposed of.</exception>
+        /// <seealso cref="SetMaxLimit(int, int, int)"/>
+        /// <since_tizen> 5 </since_tizen>
+        public VariantInfo GetMaxLimit()
+        {
+            Player.ValidateNotDisposed();
+
+            NativePlayer.GetMaxLimit(Player.Handle, out var bandwidth, out var width, out var height).
+                    ThrowIfFailed(Player, "Failed to get the max limit to the player");
+
+            return new VariantInfo(bandwidth, width, height);
+        }
+
+        /// <summary>
+        /// Retrieves all the available adaptive variants.
+        /// </summary>
+        /// <returns>
+        /// It returns a list contained all the available adaptive variants.
+        /// </returns>
+        /// The <see cref="Player"/> must be in the <see cref="PlayerState.Ready"/>,
+        /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.
+        /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
+        /// <exception cref="ObjectDisposedException">The <see cref="Player"/> has already been disposed of.</exception>
+        /// <seealso cref="VariantInfo"/>
+        /// <since_tizen> 5 </since_tizen>
+        public IEnumerable<VariantInfo> AvailableAdaptiveVariants
+        {
+            get
+            {
+                if (_adaptiveVariants == null)
+                {
+                    _adaptiveVariants = GetAdaptiveVariants();
+                }
+
+                return _adaptiveVariants;
+            }
+        }
+
+        private IList<VariantInfo> GetAdaptiveVariants()
+        {
+            List<VariantInfo> adaptiveVariants = new List<VariantInfo>();
+
+            NativePlayer.AdaptiveVariantCallback callback = (int bandwidth, int width, int height, IntPtr userData) =>
+            {
+                adaptiveVariants.Add(new VariantInfo(bandwidth, width, height));
+                return true;
+            };
+
+            NativePlayer.ForeachAdaptiveVariants(Player.Handle, callback, IntPtr.Zero).
+                ThrowIfFailed(Player, "Failed to get the information of adaptive variants");
+
+            return adaptiveVariants.AsReadOnly();
+        }
+    }
+}
index 77a5958..eae92b9 100644 (file)
@@ -24,6 +24,46 @@ using static Interop;
 
 namespace Tizen.Multimedia
 {
+    /// <summary>
+    /// Represents properties for streaming buffering time
+    /// </summary>
+    /// <since_tizen> 5 </since_tizen>
+    public struct PlayerBufferingTime
+    {
+        /// <summary>
+        /// Initializes a new instance of the PlayerBufferingTime struct.
+        /// </summary>
+        /// <param name="preBufferMillisecond">A duration of buffering data that must be prerolled to start playback.</param>
+        /// <param name="reBufferMillisecond">A duration of buffering data that must be prerolled to resume playback
+        /// if player enters pause state for buffering.</param>
+        /// <since_tizen> 5 </since_tizen>
+        public PlayerBufferingTime(int preBufferMillisecond, int reBufferMillisecond)
+        {
+            PreBufferMillisecond = preBufferMillisecond;
+            ReBufferMillisecond = reBufferMillisecond;
+        }
+
+        /// <summary>
+        /// Gets or sets the duration of buffering data that must be prerolled to start playback
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        public int PreBufferMillisecond
+        {
+            get;
+            set;
+        }
+
+        /// <summary>
+        /// Gets or sets the duration of buffering data that must be prerolled to resume playback
+        /// if player enters pause state for buffering.
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        public int ReBufferMillisecond
+        {
+            get;
+            set;
+        }
+    }
     /// <since_tizen> 3 </since_tizen>
     public partial class Player
     {
@@ -105,6 +145,44 @@ namespace Tizen.Multimedia
                 _userAgent = value;
             }
         }
+
+        /// <summary>
+        /// Gets or sets the streaming buffering time.
+        /// </summary>
+        /// <remarks>To set, the player must be in the <see cref="PlayerState.Idle"/> state.</remarks>
+        /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
+        /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
+        /// <exception cref="ArgumentOutOfRangeException">
+        ///     <pramref name="PreBufferMillisecond"/> is less than 0.<br/>
+        ///     -or-<br/>
+        ///     <pramref name="ReBufferMillisecond"/> is less than 0.<br/>
+        /// </exception>
+        /// <seealso cref="PlayerBufferingTime"/>
+        /// <since_tizen> 5 </since_tizen>
+        public PlayerBufferingTime BufferingTime
+        {
+            get
+            {
+                ValidateNotDisposed();
+
+                NativePlayer.GetStreamingBufferingTime(Handle, out var PreBuffMillisecond, out var ReBuffMillisecond).
+                        ThrowIfFailed(this, "Failed to get the buffering time of the player");
+
+                return new PlayerBufferingTime(PreBuffMillisecond, ReBuffMillisecond);
+            }
+            set
+            {
+                ValidatePlayerState(PlayerState.Idle);
+
+                if (value.PreBufferMillisecond < 0 || value.ReBufferMillisecond < 0)
+                {
+                    throw new ArgumentOutOfRangeException("invalid range");
+                }
+
+                NativePlayer.SetStreamingBufferingTime(Handle, value.PreBufferMillisecond, value.ReBufferMillisecond).
+                    ThrowIfFailed(this, "Failed to set the buffering time of the player");
+            }
+        }
         #endregion
 
         /// <summary>
@@ -463,5 +541,24 @@ namespace Tizen.Multimedia
                 return _sphericalVideo;
             }
         }
+
+        private AdaptiveVariants _adaptiveVariants;
+
+        /// <summary>
+        /// Gets the adaptive variants settings.
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        public AdaptiveVariants AdaptiveVariants
+        {
+            get
+            {
+                if (_adaptiveVariants == null)
+                {
+                    _adaptiveVariants = new AdaptiveVariants(this);
+                }
+
+                return _adaptiveVariants;
+            }
+        }
     }
 }
index 631b150..86f60f5 100644 (file)
@@ -369,7 +369,7 @@ namespace Tizen.Multimedia
         /// <exception cref="InvalidOperationException">
         /// The <see cref="Multimedia.Player"/> that this instance belongs to is not in the valid state.
         /// </exception>
-        /// <seealso cref="DirectionOfView"/>
+        /// <seealso cref="FieldOfView"/>
         /// <since_tizen> 5 </since_tizen>
         public void SetFieldOfView(FieldOfView fieldOfView)
         {