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