Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Recorder / Recorder / RecorderFeatures.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.Collections.Generic;
19 using System.Linq;
20 using Native = Interop.RecorderFeatures;
21
22 namespace Tizen.Multimedia
23 {
24     /// <summary>
25     /// The camera setting class provides methods/properties to get and
26     /// set basic camera attributes.
27     /// </summary>
28     public class RecorderFeatures
29     {
30         internal readonly Recorder _recorder = null;
31
32         private List<RecorderFileFormat> _fileFormats;
33         private List<RecorderAudioCodec> _audioCodec;
34         private List<RecorderVideoCodec> _videoCodec;
35         private List<Size> _videoResolution;
36
37         internal RecorderFeatures(Recorder recorder)
38         {
39             _recorder = recorder;
40         }
41
42         /// <summary>
43         /// Retrieves all the file formats supported by the recorder.
44         /// </summary>
45         /// <since_tizen> 3 </since_tizen>
46         /// <returns>
47         /// It returns a list containing all the supported <see cref="RecorderFileFormat"/>.
48         /// </returns>
49         /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
50         public IEnumerable<RecorderFileFormat> SupportedFileFormats
51         {
52             get
53             {
54                 if (_fileFormats == null)
55                 {
56                     try
57                     {
58                         _fileFormats = new List<RecorderFileFormat>();
59
60                         Native.FileFormatCallback callback = (RecorderFileFormat format, IntPtr userData) =>
61                         {
62                             _fileFormats.Add(format);
63                             return true;
64                         };
65                         RecorderErrorFactory.ThrowIfError(Native.FileFormats(_recorder.GetHandle(), callback, IntPtr.Zero),
66                         "Failed to get the supported fileformats");
67                     }
68                     catch
69                     {
70                         _fileFormats = null;
71                         throw;
72                     }
73                 }
74
75                 return _fileFormats;
76             }
77         }
78
79         /// <summary>
80         /// Retrieves all the audio encoders supported by the recorder.
81         /// </summary>
82         /// <since_tizen> 3 </since_tizen>
83         /// <returns>
84         /// It returns a list containing all the supported <see cref="RecorderAudioCodec"/>.
85         /// </returns>
86         /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
87         public IEnumerable<RecorderAudioCodec> SupportedAudioEncodings
88         {
89             get
90             {
91                 if (_audioCodec == null)
92                 {
93                     try
94                     {
95                         _audioCodec = new List<RecorderAudioCodec>();
96
97                         Native.AudioEncoderCallback callback = (RecorderAudioCodec codec, IntPtr userData) =>
98                         {
99                             _audioCodec.Add(codec);
100                             return true;
101                         };
102                         RecorderErrorFactory.ThrowIfError(Native.AudioEncoders(_recorder.GetHandle(), callback, IntPtr.Zero),
103                             "Failed to get the supported audio encoders");
104                     }
105                     catch
106                     {
107                         _audioCodec = null;
108                         throw;
109                     }
110                 }
111
112                 return _audioCodec;
113             }
114         }
115
116         /// <summary>
117         /// Retrieves all the video encoders supported by the recorder.
118         /// </summary>
119         /// <since_tizen> 3 </since_tizen>
120         /// <returns>
121         /// It returns a list containing all the supported <see cref="RecorderVideoCodec"/>.
122         /// by recorder.
123         /// </returns>
124         /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
125         public IEnumerable<RecorderVideoCodec> SupportedVideoEncodings
126         {
127             get
128             {
129                 if (_videoCodec == null)
130                 {
131                     try
132                     {
133                         _videoCodec = new List<RecorderVideoCodec>();
134
135                         Native.VideoEncoderCallback callback = (RecorderVideoCodec codec, IntPtr userData) =>
136                         {
137                             _videoCodec.Add(codec);
138                             return true;
139                         };
140                         RecorderErrorFactory.ThrowIfError(Native.VideoEncoders(_recorder.GetHandle(), callback, IntPtr.Zero),
141                             "Failed to get the supported video encoders");
142                     }
143                     catch
144                     {
145                         _videoCodec = null;
146                         throw;
147                     }
148                 }
149
150                 return _videoCodec;
151             }
152         }
153
154         /// <summary>
155         /// Retrieves all the video resolutions supported by the recorder.
156         /// </summary>
157         /// <since_tizen> 3 </since_tizen>
158         /// <returns>
159         /// It returns videoresolution list containing the width and height of
160         /// different resolutions supported by recorder.
161         /// </returns>
162         /// <exception cref="ObjectDisposedException">The camera already has been disposed.</exception>
163         public IEnumerable<Size> SupportedVideoResolutions
164         {
165             get
166             {
167                 if (_videoResolution == null)
168                 {
169                     try
170                     {
171                         _videoResolution = new List<Size>();
172
173                         Native.VideoResolutionCallback callback = (int width, int height, IntPtr userData) =>
174                         {
175                             _videoResolution.Add(new Size(width, height));
176                             return true;
177                         };
178                         RecorderErrorFactory.ThrowIfError(Native.VideoResolution(_recorder.GetHandle(), callback, IntPtr.Zero),
179                             "Failed to get the supported video resolutions.");
180                     }
181                     catch
182                     {
183                         _videoResolution = null;
184                         throw;
185                     }
186                 }
187
188                 return _videoResolution;
189             }
190         }
191     }
192 }