[Recorder] refactoring
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia / Recorder / RecorderSettings.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.Linq;
19 using System.Runtime.InteropServices;
20 using Tizen.Internals.Errors;
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 RecorderSettings
29     {
30         internal readonly Recorder _recorder = null;
31
32         internal RecorderSettings(Recorder recorder)
33         {
34             _recorder = recorder;
35         }
36
37         /// <summary>
38         /// The number of audio channel.
39         /// </summary>
40         /// <remarks>
41         /// The attribute is applied only in Created state.
42         /// For mono recording, set channel to 1.
43         /// For stereo recording, set channel to 2.
44         /// </remarks>
45         public int AudioChannel
46         {
47             get
48             {
49                 int val = 0;
50
51                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.GetAudioChannel(_recorder.GetHandle(), out val),
52                     "Failed to get audio channel.");
53
54                 return val;
55             }
56
57             set
58             {
59                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.SetAudioChannel(_recorder.GetHandle(), value),
60                     "Failed to set audio channel");
61             }
62         }
63
64         /// <summary>
65         /// The audio device for recording.
66         /// </summary>
67         public RecorderAudioDevice AudioDevice
68         {
69             get
70             {
71                 RecorderAudioDevice val = 0;
72
73                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.GetAudioDevice(_recorder.GetHandle(), out val),
74                     "Failed to get audio device.");
75
76                 return val;
77             }
78
79             set
80             {
81                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.SetAudioDevice(_recorder.GetHandle(), value),
82                     "Failed to set audio device.");
83             }
84         }
85
86         /// <summary>
87         /// Get the peak audio input level in dB
88         /// </summary>
89         /// <remarks>
90         /// 0dB indicates maximum input level, -300dB indicates minimum input level.
91         /// </remarks>
92         public double AudioLevel
93         {
94             get
95             {
96                 double level = 0;
97
98                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.GetAudioLevel(_recorder.GetHandle(), out level),
99                     "Failed to get Audio level.");
100
101                 return level;
102             }
103         }
104
105         /// <summary>
106         /// The sampling rate of an audio stream in hertz.
107         /// </summary>
108         public int AudioSampleRate
109         {
110             get
111             {
112                 int val = 0;
113
114                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.GetAudioSampleRate(_recorder.GetHandle(), out val),
115                     "Failed to get audio sample rate.");
116
117                 return val;
118             }
119
120             set
121             {
122                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.SetAudioSampleRate(_recorder.GetHandle(), value),
123                     "Failed to set audio sample rate.");
124             }
125         }
126
127         /// <summary>
128         /// The bitrate of an audio encoder in bits per second.
129         /// </summary>
130         public int AudioBitRate
131         {
132             get
133             {
134                 int val = 0;
135
136                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.GetAudioEncoderBitrate(_recorder.GetHandle(), out val),
137                     "Failed to get audio bitrate.");
138
139                 return val;
140             }
141
142             set
143             {
144                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.SetAudioEncoderBitrate(_recorder.GetHandle(), value),
145                     "Failed to set audio bitrate");
146             }
147         }
148
149         /// <summary>
150         /// The bitrate of an video encoder in bits per second.
151         /// </summary>
152         public int VideoBitRate
153         {
154             get
155             {
156                 int val = 0;
157
158                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.GetVideoEncoderBitrate(_recorder.GetHandle(), out val),
159                     "Failed to get video bitrate.");
160
161                 return val;
162             }
163
164             set
165             {
166                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.SetVideoEncoderBitrate(_recorder.GetHandle(), value),
167                     "Failed to set video bitrate");
168             }
169         }
170
171         /// <summary>
172         /// The audio codec for encoding an audio stream.
173         /// </summary>
174         public RecorderAudioCodec AudioCodec
175         {
176             get
177             {
178                 RecorderAudioCodec val = 0;
179
180                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.GetAudioEncoder(_recorder.GetHandle(), out val),
181                     "Failed to get audio codec");
182
183                 return val;
184             }
185
186             set
187             {
188                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.SetAudioEncoder(_recorder.GetHandle(), value),
189                     "Failed to set audio codec");
190             }
191         }
192
193         /// <summary>
194         /// The video codec for encoding video stream.
195         /// </summary>
196         public RecorderVideoCodec VideoCodec
197         {
198             get
199             {
200                 RecorderVideoCodec val = 0;
201
202                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.GetVideoEncoder(_recorder.GetHandle(), out val),
203                     "Failed to get video codec");
204
205                 return val;
206             }
207
208             set
209             {
210                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.SetVideoEncoder(_recorder.GetHandle(), value),
211                     "Failed to set video codec");
212             }
213         }
214
215         /// <summary>
216         /// The file format for recording media stream.
217         /// </summary>
218         public RecorderFileFormat FileFormat
219         {
220             get
221             {
222                 RecorderFileFormat val = 0;
223
224                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.GetFileFormat(_recorder.GetHandle(), out val),
225                     "Failed to get file format.");
226
227                 return val;
228             }
229
230             set
231             {
232                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.SetFileFormat(_recorder.GetHandle(), value),
233                     "Failed to set file format");
234             }
235         }
236
237         /// <summary>
238         /// The file path to record.
239         /// </summary>
240         /// <remarks>
241         /// If the same file already exists in the file system, then old file
242         /// will be overwritten.
243         /// </remarks>
244         public string FilePath
245         {
246             get
247             {
248                 IntPtr val;
249                 int ret = Interop.RecorderSettings.GetFileName(_recorder.GetHandle(), out val);
250                 if ((RecorderError)ret != RecorderError.None)
251                 {
252                     Log.Error(RecorderLog.Tag, "Failed to get filepath, " + (RecorderError)ret);
253                 }
254                 string result = Marshal.PtrToStringAnsi(val);
255                 Interop.Libc.Free(val);
256                 return result;
257             }
258
259             set
260             {
261                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.SetFileName(_recorder.GetHandle(), value),
262                     "Failed to set filepath");
263             }
264         }
265
266         /// <summary>
267         /// The maximum size of a recording file in KB(kilobytes). If 0, means
268         /// unlimited recording size.
269         /// </summary>
270         /// <remarks>
271         /// After reaching the limitation, the data which is being recorded will
272         /// be discarded and not written to the file.
273         /// The recorder state must be in 'Ready' or 'Created' state.
274         /// </remarks>
275         ///
276         public int SizeLimit
277         {
278             get
279             {
280                 int val = 0;
281
282                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.GetSizeLimit(_recorder.GetHandle(), out val),
283                     "Failed to get size limit.");
284
285                 return val;
286             }
287
288             set
289             {
290                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.SetSizeLimit(_recorder.GetHandle(), value),
291                     "Failed to set size limit");
292             }
293         }
294
295         /// <summary>
296         /// The time limit of a recording file in Seconds. If 0, means unlimited recording
297         /// time.
298         /// </summary>
299         /// <remarks>
300         /// After reaching the limitation, the data which is being recorded will
301         /// be discarded and not written to the file.
302         /// The recorder state must be in 'Ready' or 'Created' state.
303         /// </remarks>
304         public int TimeLimit
305         {
306             get
307             {
308                 int val = 0;
309
310                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.GetTimeLimit(_recorder.GetHandle(), out val),
311                     "Failed to get time limit.");
312
313                 return val;
314             }
315
316             set
317             {
318                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.SetTimeLimit(_recorder.GetHandle(), value),
319                     "Failed to set time limit.");
320             }
321         }
322
323         /// <summary>
324         /// The mute state of a recorder.
325         /// </summary>
326         public bool Mute
327         {
328             get
329             {
330                 bool ret = Interop.RecorderSettings.GetMute(_recorder.GetHandle());
331
332                 RecorderErrorFactory.ThrowIfError(ErrorFacts.GetLastResult(),
333                     "Failed to get the mute state of recorder");
334
335                 return ret;
336             }
337
338             set
339             {
340                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.SetMute(_recorder.GetHandle(), value),
341                     "Failed to set mute");
342             }
343         }
344
345         /// <summary>
346         /// The video recording motion rate
347         /// </summary>
348         /// <remarks>
349         /// The attribute is valid only in a video recorder.
350         /// If the rate is in range of 0-1, video is recorded in a slow motion mode.
351         /// If the rate is bigger than 1, video is recorded in a fast motion mode.
352         /// </remarks>
353         public double MotionRate
354         {
355             get
356             {
357                 double val = 0.0;
358
359                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.GetMotionRate(_recorder.GetHandle(), out val),
360                     "Failed to get video motion rate.");
361
362                 return val;
363             }
364
365             set
366             {
367                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.SetMotionRate(_recorder.GetHandle(), value),
368                     "Failed to set video motion rate");
369             }
370         }
371
372         /// <summary>
373         /// The orientation in a video metadata tag.
374         /// </summary>
375         public RecorderOrientation OrientationTag
376         {
377             get
378             {
379                 RecorderOrientation val = 0;
380
381                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.GetOrientationTag(_recorder.GetHandle(), out val),
382                     "Failed to get recorder orientation.");
383
384                 return val;
385             }
386
387             set
388             {
389                 RecorderErrorFactory.ThrowIfError(Interop.RecorderSettings.SetOrientationTag(_recorder.GetHandle(), value),
390                     "Failed to set recorder orientation");
391             }
392         }
393
394         /// <summary>
395         /// Resolution of the video.
396         /// </summary>
397         /// <privilege>
398         /// http://tizen.org/privilege/recorder
399         /// </privilege>
400         /// <exception cref="ArgumentException">In case of invalid parameters</exception>
401         public Size VideoResolution
402         {
403             get
404             {
405                 int width = 0;
406                 int height = 0;
407
408                 CameraErrorFactory.ThrowIfError(Interop.RecorderSettings.GetVideoResolution(_recorder.GetHandle(), out width, out height),
409                     "Failed to get camera video resolution");
410
411                 return new Size(width, height);
412             }
413
414             set
415             {
416                 Size res = value;
417
418                 CameraErrorFactory.ThrowIfError(Interop.RecorderSettings.SetVideoResolution(_recorder.GetHandle(), res.Width, res.Height),
419                     "Failed to set video resolution.");
420             }
421         }
422     }
423 }