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