4aa2254419add115e859427d9b57e592d8138875
[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.ComponentModel;
19 using System.Diagnostics;
20 using Native = Interop.Display;
21
22 namespace Tizen.Multimedia
23 {
24     /// <summary>
25     /// Provides a means to configure display settings for video <see cref="Player"/>.
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     public class PlayerDisplaySettings
29     {
30         /// <summary>
31         /// This constructor supports the product infrastructure and is not intended to be used directly from application code.
32         /// </summary>
33         /// <since_tizen> 4 </since_tizen>
34         [EditorBrowsable(EditorBrowsableState.Never)]
35         protected PlayerDisplaySettings(Player player)
36         {
37             if (player == null)
38             {
39                 throw new ArgumentNullException(nameof(player));
40             }
41
42             Player = player;
43         }
44
45         internal static PlayerDisplaySettings Create(Player player) => new PlayerDisplaySettings(player);
46
47         /// <summary>
48         /// Gets the player of this instance.
49         /// </summary>
50         /// <value>The <see cref="Player"/> of this <see cref="PlayerDisplaySettings"/> instance.</value>
51         /// <since_tizen> 4 </since_tizen>
52         protected Player Player { get; }
53
54         /// <summary>
55         /// Gets or sets the <see cref="PlayerDisplayMode"/>.
56         /// </summary>
57         /// <exception cref="InvalidOperationException">
58         ///     Operation failed; internal error.
59         /// </exception>
60         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
61         /// <exception cref="ArgumentException">The specified value to set is invalid.</exception>
62         /// <since_tizen> 3 </since_tizen>
63         public PlayerDisplayMode Mode
64         {
65             get
66             {
67                 Native.GetMode(Player.Handle, out var value).
68                     ThrowIfFailed("Failed to get display mode");
69
70                 return value;
71             }
72             set
73             {
74                 ValidationUtil.ValidateEnum(typeof(PlayerDisplayMode), value);
75
76                 Native.SetMode(Player.Handle, value).
77                     ThrowIfFailed("Failed to set display mode");
78             }
79         }
80
81         /// <summary>
82         /// Gets or sets the value indicating whether the display is visible.
83         /// </summary>
84         /// <value>true if the display is visible; otherwise false.</value>
85         /// <exception cref="InvalidOperationException">
86         ///     Operation failed; internal error.
87         /// </exception>
88         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
89         /// <since_tizen> 3 </since_tizen>
90         public bool IsVisible
91         {
92             get
93             {
94                 Native.IsVisible(Player.Handle, out var value).
95                     ThrowIfFailed("Failed to get the visible state of the display");
96
97                 return value;
98             }
99             set
100             {
101                 Native.SetVisible(Player.Handle, value).ThrowIfFailed("Failed to set the visible state of the display");
102             }
103         }
104
105         /// <summary>
106         /// Gets or sets the rotation of the display.
107         /// </summary>
108         /// <value><see cref="Rotation.Rotate0"/>, <see cref="Rotation.Rotate90"/>, <see cref="Rotation.Rotate180"/>,
109         ///     <see cref="Rotation.Rotate270"/>.</value>
110         /// <exception cref="InvalidOperationException">
111         ///     Operation failed; internal error.
112         /// </exception>
113         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
114         /// <exception cref="ArgumentException">The specified value to set is invalid.</exception>
115         /// <since_tizen> 3 </since_tizen>
116         public Rotation Rotation
117         {
118             get
119             {
120                 Native.GetRotation(Player.Handle, out var value).
121                     ThrowIfFailed("Failed to get the rotation state of the display");
122
123                 return value;
124             }
125             set
126             {
127                 ValidationUtil.ValidateEnum(typeof(Rotation), value);
128
129                 Native.SetRotation(Player.Handle, value).
130                     ThrowIfFailed("Failed to set the rotation state of the display");
131             }
132         }
133
134         /// <summary>
135         /// Sets the roi(region of interest).
136         /// </summary>
137         /// <param name="roi">The region.</param>
138         /// <remarks>
139         /// To set roi, <see cref="Mode"/> must be set to <see cref="PlayerDisplayMode.Roi"/> first.
140         /// </remarks>
141         /// <exception cref="InvalidOperationException">
142         ///     Operation failed; internal error.<br/>
143         ///     -or-<br/>
144         ///     <see cref="Mode"/> is not set to <see cref="PlayerDisplayMode.Roi"/>.
145         /// </exception>
146         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
147         /// <exception cref="ArgumentOutOfRangeException">The width or the height is less than or equal to zero.</exception>
148         /// <since_tizen> 3 </since_tizen>
149         public void SetRoi(Rectangle roi)
150         {
151             if (roi.Width <= 0)
152             {
153                 throw new ArgumentOutOfRangeException(nameof(roi), roi.Width,
154                     $"The width of the roi can't be less than or equal to zero.");
155             }
156             if (roi.Height <= 0)
157             {
158                 throw new ArgumentOutOfRangeException(nameof(roi), roi.Height,
159                     $"The height of the roi can't be less than or equal to zero.");
160             }
161
162             if (Mode != PlayerDisplayMode.Roi)
163             {
164                 throw new InvalidOperationException("Mode is not set to Roi");
165             }
166
167             Native.SetRoi(Player.Handle, roi.X, roi.Y, roi.Width, roi.Height).
168                 ThrowIfFailed("Failed to set the roi");
169         }
170     }
171 }