From 99030f9520f6364ca106d3feb017175c83ebc872 Mon Sep 17 00:00:00 2001
From: nam <36914158+kqjy777@users.noreply.github.com>
Date: Tue, 11 Sep 2018 16:05:58 +0900
Subject: [PATCH] [MediaPlayer] add new API to set/get the video roi area
(#453)
* [MediaPlayer] add new API to set/get the video roi area
---
.../Interop/Interop.Player.cs | 6 ++
src/Tizen.Multimedia.MediaPlayer/Player/Player.cs | 83 ++++++++++++++++++-
.../Player/ScaleRectangle.cs | 93 ++++++++++++++++++++++
3 files changed, 179 insertions(+), 3 deletions(-)
create mode 100644 src/Tizen.Multimedia.MediaPlayer/Player/ScaleRectangle.cs
diff --git a/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Player.cs b/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Player.cs
index 4655f85..500fb79 100644
--- a/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Player.cs
+++ b/src/Tizen.Multimedia.MediaPlayer/Interop/Interop.Player.cs
@@ -331,6 +331,12 @@ internal static partial class Interop
[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);
+
+ [DllImport(Libraries.Player, EntryPoint = "player_set_video_roi_area")]
+ internal static extern PlayerErrorCode SetVideoRoi(IntPtr player, double scaleX, double scaleY, double scaleWidth, double scaleHeight);
+
+ [DllImport(Libraries.Player, EntryPoint = "player_get_video_roi_area")]
+ internal static extern PlayerErrorCode GetVideoRoi(IntPtr player, out double scaleX, out double scaleY, out double scaleWidth, out double scaleHeight);
}
internal class PlayerHandle : SafeHandle
diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs b/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs
index 3390ed9..27c95c4 100644
--- a/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs
+++ b/src/Tizen.Multimedia.MediaPlayer/Player/Player.cs
@@ -203,7 +203,7 @@ namespace Tizen.Multimedia
NativePlayer.GetStreamingDownloadProgress(Handle, out start, out current).
ThrowIfFailed(this, "Failed to get download progress");
- Log.Info(PlayerLog.Tag, "get download progress : " + start + ", " + current);
+ Log.Info(PlayerLog.Tag, $"get download progress : {start}, {current}");
return new DownloadProgress(start, current);
}
@@ -551,7 +551,7 @@ namespace Tizen.Multimedia
NativePlayer.GetPlayPosition(Handle, out playPosition).
ThrowIfFailed(this, "Failed to get the play position of the player");
- Log.Info(PlayerLog.Tag, "get play position : " + playPosition);
+ Log.Info(PlayerLog.Tag, $"get play position : {playPosition}");
return playPosition;
}
@@ -643,7 +643,7 @@ namespace Tizen.Multimedia
NativePlayer.GetPlayPositionNanoseconds(Handle, out long playPosition).
ThrowIfFailed(this, "Failed to get the play position(nsec) of the player");
- Log.Info(PlayerLog.Tag, "get play position(nsec) : " + playPosition);
+ Log.Info(PlayerLog.Tag, $"get play position(nsec) : {playPosition}");
return playPosition;
}
@@ -759,6 +759,83 @@ namespace Tizen.Multimedia
ret.ThrowIfFailed(this, "Failed to set the audio stream policy to the player");
}
+
+ ///
+ /// Set the relative ROI (Region Of Interest) area as a decimal fraction based on the video source.
+ /// It can be regarded as zooming operation because the specified video area will be rendered to fit to the display.
+ ///
+ /// The containing the ROI area information.
+ ///
+ /// This function requires the ratio of the each coordinate and size to the video resolution size
+ /// to guarantee of showing the same area for the dynamic resolution video content.
+ /// This function have to be called after setting
+ ///
+ /// The player has already been disposed of.
+ ///
+ /// Operation failed; internal error.
+ /// -or-
+ /// The is not set to .
+ ///
+ ///
+ /// is less than 0.0 or greater than 1.0.
+ /// -or-
+ /// is less than 0.0 or greater than 1.0.
+ /// -or-
+ /// is less than or equal to 0.0 or greater than 1.0.
+ /// -or-
+ /// is less than or equal to 0.0 or greater than 1.0.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// 5
+ public void SetVideoRoi(ScaleRectangle scaleRectangle)
+ {
+ ValidateNotDisposed();
+
+ if (scaleRectangle.ScaleX < 0 || scaleRectangle.ScaleX > 1)
+ {
+ throw new ArgumentOutOfRangeException(nameof(scaleRectangle.ScaleX), scaleRectangle.ScaleX, "Valid range is 0 to 1.0");
+ }
+ if (scaleRectangle.ScaleY < 0 || scaleRectangle.ScaleY > 1)
+ {
+ throw new ArgumentOutOfRangeException(nameof(scaleRectangle.ScaleY), scaleRectangle.ScaleY, "Valid range is 0 to 1.0");
+ }
+ if (scaleRectangle.ScaleWidth <= 0 || scaleRectangle.ScaleWidth > 1)
+ {
+ throw new ArgumentOutOfRangeException(nameof(scaleRectangle.ScaleWidth), scaleRectangle.ScaleWidth, "Valid range is 0 to 1.0 (except 0.0)");
+ }
+ if (scaleRectangle.ScaleHeight <= 0 || scaleRectangle.ScaleHeight > 1)
+ {
+ throw new ArgumentOutOfRangeException(nameof(scaleRectangle.ScaleHeight), scaleRectangle.ScaleHeight, "Valid range is 0 to 1.0 (except 0.0)");
+ }
+
+ NativePlayer.SetVideoRoi(Handle, scaleRectangle.ScaleX, scaleRectangle.ScaleY, scaleRectangle.ScaleWidth, scaleRectangle.ScaleHeight).ThrowIfFailed(this, "Failed to set the video roi area.");
+ }
+
+ ///
+ /// Get the relative ROI (Region Of Interest) area as a decimal fraction based on the video source.
+ ///
+ /// The containing the ROI area information.
+ /// The specified ROI area is valid only in .
+ /// The player has already been disposed of.
+ ///
+ /// Operation failed; internal error.
+ ///
+ ///
+ ///
+ ///
+ /// 5
+ public ScaleRectangle GetVideoRoi()
+ {
+ ValidateNotDisposed();
+
+ NativePlayer.GetVideoRoi(Handle, out var scaleX, out var scaleY,
+ out var scaleWidth, out var scaleHeight).ThrowIfFailed(this, "Failed to get the video roi area");
+
+ return new ScaleRectangle(scaleX, scaleY, scaleWidth, scaleHeight);
+ }
#endregion
#region Preparing state
diff --git a/src/Tizen.Multimedia.MediaPlayer/Player/ScaleRectangle.cs b/src/Tizen.Multimedia.MediaPlayer/Player/ScaleRectangle.cs
new file mode 100644
index 0000000..85eef90
--- /dev/null
+++ b/src/Tizen.Multimedia.MediaPlayer/Player/ScaleRectangle.cs
@@ -0,0 +1,93 @@
+/*
+ * 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 static Interop;
+
+namespace Tizen.Multimedia
+{
+ ///
+ /// Represents properties for the relative ROI area based on video size
+ ///
+ /// 5
+ public struct ScaleRectangle
+ {
+ ///
+ /// Initializes a new instance of the struct with the specified field of view for the spherical video.
+ ///
+ /// The ratio expressed as a decimal of x coordinate to the video width. (x/video width)
+ /// x coordinate means the base point located lower-left corner of the video area.
+ /// valid range is [0, 1]. Default value is 0.
+ /// The ratio expressed as a decimal of y coordinate to the video height. (y/video height)
+ /// y coordinate means the base point located lower-left corner of the video area.
+ /// valid range is [0, 1]. Default value is 0.
+ /// The ratio expressed as a decimal of ROI width to the video width. (ROI width/video width)
+ /// valid range is (0, 1]. Default value is 1.
+ /// The ratio expressed as a decimal of ROI height to the video height. (ROI height/video height)
+ /// valid range is (0, 1]. Default value is 1.
+ /// 5
+ public ScaleRectangle(double scaleX, double scaleY, double scaleWidth, double scaleHeight)
+ {
+ ScaleX = scaleX;
+ ScaleY = scaleY;
+ ScaleWidth = scaleWidth;
+ ScaleHeight = scaleHeight;
+
+ Log.Debug(PlayerLog.Tag, $"scaleX={scaleX}, scaleY={scaleY}, scaleWidth={scaleWidth}, scaleHeight={scaleHeight}");
+ }
+
+ ///
+ /// Gets or sets the ScaleX.
+ ///
+ /// 5
+ public double ScaleX
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// Gets or sets the ScaleY.
+ ///
+ /// 5
+ public double ScaleY
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// Gets or sets the ScaleWidth.
+ ///
+ /// 5
+ public double ScaleWidth
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// Gets or sets the ScaleHeight.
+ ///
+ /// 5
+ public double ScaleHeight
+ {
+ get;
+ set;
+ }
+ }
+}
--
2.7.4