[MediaPlayer] Added ErrorHandler registration methods for internal use. (#33)
[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(Player, "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(Player, "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(Player, "Failed to get the visible state of the display");
96
97                 return value;
98             }
99             set
100             {
101                 Native.SetVisible(Player.Handle, value).ThrowIfFailed(
102                     Player, "Failed to set the visible state of the display");
103             }
104         }
105
106         /// <summary>
107         /// Gets or sets the rotation of the display.
108         /// </summary>
109         /// <value><see cref="Rotation.Rotate0"/>, <see cref="Rotation.Rotate90"/>, <see cref="Rotation.Rotate180"/>,
110         ///     <see cref="Rotation.Rotate270"/>.</value>
111         /// <exception cref="InvalidOperationException">
112         ///     Operation failed; internal error.
113         /// </exception>
114         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
115         /// <exception cref="ArgumentException">The specified value to set is invalid.</exception>
116         /// <since_tizen> 3 </since_tizen>
117         public Rotation Rotation
118         {
119             get
120             {
121                 Native.GetRotation(Player.Handle, out var value).
122                     ThrowIfFailed(Player, "Failed to get the rotation state of the display");
123
124                 return value;
125             }
126             set
127             {
128                 ValidationUtil.ValidateEnum(typeof(Rotation), value);
129
130                 Native.SetRotation(Player.Handle, value).
131                     ThrowIfFailed(Player, "Failed to set the rotation state of the display");
132             }
133         }
134
135         /// <summary>
136         /// Sets the roi(region of interest).
137         /// </summary>
138         /// <param name="roi">The region.</param>
139         /// <remarks>
140         /// To set roi, <see cref="Mode"/> must be set to <see cref="PlayerDisplayMode.Roi"/> first.
141         /// </remarks>
142         /// <exception cref="InvalidOperationException">
143         ///     Operation failed; internal error.<br/>
144         ///     -or-<br/>
145         ///     <see cref="Mode"/> is not set to <see cref="PlayerDisplayMode.Roi"/>.
146         /// </exception>
147         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
148         /// <exception cref="ArgumentOutOfRangeException">The width or the height is less than or equal to zero.</exception>
149         /// <since_tizen> 3 </since_tizen>
150         public void SetRoi(Rectangle roi)
151         {
152             if (roi.Width <= 0)
153             {
154                 throw new ArgumentOutOfRangeException(nameof(roi), roi.Width,
155                     $"The width of the roi can't be less than or equal to zero.");
156             }
157             if (roi.Height <= 0)
158             {
159                 throw new ArgumentOutOfRangeException(nameof(roi), roi.Height,
160                     $"The height of the roi can't be less than or equal to zero.");
161             }
162
163             if (Mode != PlayerDisplayMode.Roi)
164             {
165                 throw new InvalidOperationException("Mode is not set to Roi");
166             }
167
168             Native.SetRoi(Player.Handle, roi.X, roi.Y, roi.Width, roi.Height).
169                 ThrowIfFailed(Player, "Failed to set the roi");
170         }
171     }
172 }