3f62ac6aba000c533ecadd2b29c56fbbb13a6d91
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Camera / Camera / Camera.Properties.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 static Interop;
20 using Native = Interop.Camera;
21
22 namespace Tizen.Multimedia
23 {
24     /// <summary>
25     /// This camera class provides methods to capture photos and supports setting up notifications
26     /// for state changes of capturing, previewing, focusing, and informing about the resolution and the binary format,
27     /// and functions for picture manipulations like sepia, negative, and many more.
28     /// It also notifies you when a significant picture parameter changes, (For example, focus).
29     /// </summary>
30     /// <since_tizen> 3 </since_tizen>
31     /// <feature> http://tizen.org/feature/camera </feature>
32     public partial class Camera : IDisposable, IDisplayable<CameraError>
33     {
34         /// <summary>
35         /// Gets or sets the various camera settings.
36         /// </summary>
37         /// <since_tizen> 4 </since_tizen>
38         public CameraSettings Settings { get; internal set; }
39
40         /// <summary>
41         /// Gets the various camera capabilities.
42         /// </summary>
43         /// <since_tizen> 4 </since_tizen>
44         public CameraCapabilities Capabilities { get; internal set; }
45
46         /// <summary>
47         /// Get/set various camera display properties.
48         /// </summary>
49         /// <since_tizen> 3 </since_tizen>
50         public CameraDisplaySettings DisplaySettings { get; internal set; }
51
52         private Display _display;
53
54         private CameraError SetDisplay(Display display)
55         {
56             if (display == null)
57             {
58                 return CameraDisplay.SetDisplay(GetHandle(), DisplayType.None, IntPtr.Zero);
59             }
60
61             return display.ApplyTo(this);
62         }
63
64         private void ReplaceDisplay(Display newDisplay)
65         {
66             _display?.SetOwner(null);
67             _display = newDisplay;
68             _display?.SetOwner(this);
69         }
70
71         /// <summary>
72         /// Sets or gets the display type and handle to show preview images.
73         /// The camera must be in the <see cref="CameraState.Created"/> state.
74         /// </summary>
75         /// <since_tizen> 3 </since_tizen>
76         /// <remarks>
77         /// This must be set before the StartPreview() method.
78         /// In custom ROI display mode, DisplayRoiArea property must be set before calling this method.
79         /// </remarks>
80         /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
81         /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception>
82         /// <exception cref="ObjectDisposedException" > The camera has already been disposed. </exception>
83         /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
84         public Display Display
85         {
86             get
87             {
88                 return _display;
89             }
90
91             set
92             {
93                 ValidateState(CameraState.Created);
94
95                 if (value?.Owner != null)
96                 {
97                     if (ReferenceEquals(this, value.Owner))
98                     {
99                         return;
100                     }
101
102                     throw new ArgumentException("The display has already been assigned to another.");
103                 }
104
105                 SetDisplay(value).ThrowIfFailed("Failed to set the camera display");
106
107                 ReplaceDisplay(value);
108             }
109         }
110
111         CameraError IDisplayable<CameraError>.ApplyEvasDisplay(DisplayType type, ElmSharp.EvasObject evasObject)
112         {
113             Debug.Assert(_disposed == false);
114             ValidationUtil.ValidateEnum(typeof(DisplayType), type, nameof(type));
115
116             return CameraDisplay.SetDisplay(GetHandle(), type, evasObject);
117         }
118
119         CameraError IDisplayable<CameraError>.ApplyEcoreWindow(IntPtr windowHandle, NUI.Rectangle rect)
120         {
121             Debug.Assert(_disposed == false);
122
123             return CameraDisplay.SetEcoreDisplay(GetHandle(), windowHandle);
124         }
125
126         /// <summary>
127         /// Gets the state of the camera.
128         /// </summary>
129         /// <since_tizen> 3 </since_tizen>
130         /// <value> None, Created, Preview, Capturing, Captured.</value>
131         /// <exception cref="ObjectDisposedException">The camera has already been disposed. </exception>
132         public CameraState State
133         {
134             get
135             {
136                 ValidateNotDisposed();
137
138                 Native.GetState(_handle, out CameraState val).ThrowIfFailed("Failed to get camera state");
139
140                 return val;
141             }
142         }
143
144         /// <summary>
145         /// The hint for the display reuse.
146         /// If the hint is set to true, the display will be reused when the camera device is changed with
147         /// the ChangeDevice method.
148         /// </summary>
149         /// <since_tizen> 3 </since_tizen>
150         /// <exception cref="ArgumentException">In case of invalid parameters.</exception>
151         /// <exception cref="InvalidOperationException">An invalid state.</exception>
152         /// <exception cref="ObjectDisposedException">The camera has already been disposed. </exception>
153         public bool DisplayReuseHint
154         {
155             get
156             {
157                 ValidateNotDisposed();
158
159                 Native.GetDisplayReuseHint(_handle, out bool val).ThrowIfFailed("Failed to get camera display reuse hint");
160
161                 return val;
162             }
163
164             set
165             {
166                 ValidateState(CameraState.Preview);
167
168                 Native.SetDisplayReuseHint(_handle, value).ThrowIfFailed("Failed to set display reuse hint.");
169             }
170         }
171
172         /// <summary>
173         /// Gets the facing direction of the camera module.
174         /// </summary>
175         /// <since_tizen> 3 </since_tizen>
176         /// <value>A <see cref="CameraFacingDirection"/> that specifies the facing direction of the camera device.</value>
177         /// <exception cref="ObjectDisposedException">The camera has already been disposed. </exception>
178         public CameraFacingDirection Direction
179         {
180             get
181             {
182                 ValidateNotDisposed();
183
184                 Native.GetFacingDirection(_handle, out var val).ThrowIfFailed("Failed to get camera direction");
185
186                 return val;
187             }
188         }
189
190         /// <summary>
191         /// Gets the camera device count.
192         /// </summary>
193         /// <since_tizen> 3 </since_tizen>
194         /// <value>This returns 2, if the device supports primary and secondary cameras.
195         /// Otherwise 1, if the device only supports primary camera.</value>
196         /// <exception cref="ObjectDisposedException">The camera has already been disposed. </exception>
197         public int CameraCount
198         {
199             get
200             {
201                 ValidateNotDisposed();
202
203                 Native.GetDeviceCount(_handle, out int val).ThrowIfFailed("Failed to get camera device count");
204
205                 return val;
206             }
207         }
208     }
209 }