Release 4.0.0-preview1-00201
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.MediaPlayer / Player / PlayerDisplaySettings.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Diagnostics;
19 using Native = Interop.Display;
20
21 namespace Tizen.Multimedia
22 {
23     /// <summary>
24     /// Provides a means to configure display settings for video <see cref="Player"/>.
25     /// </summary>
26     public class PlayerDisplaySettings
27     {
28         /// <summary>
29         /// This constructor supports the product infrastructure and is not intended to be used directly from application code.
30         /// </summary>
31         protected PlayerDisplaySettings(Player player)
32         {
33             if (player == null)
34             {
35                 throw new ArgumentNullException(nameof(player));
36             }
37
38             Player = player;
39         }
40
41         internal static PlayerDisplaySettings Create(Player player) => new PlayerDisplaySettings(player);
42
43         /// <summary>
44         /// Gets the player of this instance.
45         /// </summary>
46         /// <value>The <see cref="Player"/> of this <see cref="PlayerDisplaySettings"/> instance.</value>
47         protected Player Player { get; }
48
49         /// <summary>
50         /// Gets or sets the <see cref="PlayerDisplayMode"/>.
51         /// </summary>
52         /// <exception cref="InvalidOperationException">
53         ///     Operation failed; internal error.
54         /// </exception>
55         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
56         /// <exception cref="ArgumentException">The specified value to set is invalid.</exception>
57         public PlayerDisplayMode Mode
58         {
59             get
60             {
61                 Native.GetMode(Player.Handle, out var value).
62                     ThrowIfFailed("Failed to get display mode");
63
64                 return value;
65             }
66             set
67             {
68                 ValidationUtil.ValidateEnum(typeof(PlayerDisplayMode), value);
69
70                 Native.SetMode(Player.Handle, value).
71                     ThrowIfFailed("Failed to set display mode");
72             }
73         }
74
75         /// <summary>
76         /// Gets or sets the value indicating whether the display is visible.
77         /// </summary>
78         /// <value>true if the display is visible; otherwise false.</value>
79         /// <exception cref="InvalidOperationException">
80         ///     Operation failed; internal error.
81         /// </exception>
82         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
83         public bool IsVisible
84         {
85             get
86             {
87                 Native.IsVisible(Player.Handle, out var value).
88                     ThrowIfFailed("Failed to get the visible state of the display");
89
90                 return value;
91             }
92             set
93             {
94                 Native.SetVisible(Player.Handle, value).ThrowIfFailed("Failed to set the visible state of the display");
95             }
96         }
97
98         /// <summary>
99         /// Gets or sets the rotation of the display.
100         /// </summary>
101         /// <value><see cref="Rotation.Rotate0"/>, <see cref="Rotation.Rotate90"/>, <see cref="Rotation.Rotate180"/>,
102         ///     <see cref="Rotation.Rotate270"/></value>
103         /// <exception cref="InvalidOperationException">
104         ///     Operation failed; internal error.
105         /// </exception>
106         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
107         /// <exception cref="ArgumentException">The specified value to set is invalid.</exception>
108         public Rotation Rotation
109         {
110             get
111             {
112                 Native.GetRotation(Player.Handle, out var value).
113                     ThrowIfFailed("Failed to get the rotation state of the display");
114
115                 return value;
116             }
117             set
118             {
119                 ValidationUtil.ValidateEnum(typeof(Rotation), value);
120
121                 Native.SetRotation(Player.Handle, value).
122                     ThrowIfFailed("Failed to set the rotation state of the display");
123             }
124         }
125
126         /// <summary>
127         /// Sets the roi(region of interest).
128         /// </summary>
129         /// <param name="roi">The region.</param>
130         /// <remarks>
131         /// To set roi, <see cref="Mode"/> must be set to <see cref="PlayerDisplayMode.Roi"/> first.
132         /// </remarks>
133         /// <exception cref="InvalidOperationException">
134         ///     Operation failed; internal error.\n
135         ///     -or-\n
136         ///     <see cref="Mode"/> is not set to <see cref="PlayerDisplayMode.Roi"/>.
137         /// </exception>
138         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
139         /// <exception cref="ArgumentOutOfRangeException">The width or the height is less than or equal to zero.</exception>
140         public void SetRoi(Rectangle roi)
141         {
142             if (roi.Width <= 0)
143             {
144                 throw new ArgumentOutOfRangeException(nameof(roi), roi.Width,
145                     $"The width of the roi can't be less than or equal to zero.");
146             }
147             if (roi.Height <= 0)
148             {
149                 throw new ArgumentOutOfRangeException(nameof(roi), roi.Height,
150                     $"The height of the roi can't be less than or equal to zero.");
151             }
152
153             if (Mode != PlayerDisplayMode.Roi)
154             {
155                 throw new InvalidOperationException("Mode is not set to Roi");
156             }
157
158             Native.SetRoi(Player.Handle, roi.X, roi.Y, roi.Width, roi.Height).
159                 ThrowIfFailed("Failed to set the roi");
160         }
161     }
162 }