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