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