Setting since_tizen 3/4 on Tizen.NET API
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.StreamRecorder / StreamRecorder / StreamRecorderVideoOptions.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 Native = Interop.StreamRecorder;
19
20 namespace Tizen.Multimedia
21 {
22     /// <summary>
23     /// Specifies the options associated with video recording.
24     /// </summary>
25     /// <seealso cref="StreamRecorder"/>
26     /// <seealso cref="StreamRecorderOptions"/>
27     /// <seealso cref="StreamRecorderAudioOptions"/>
28     /// <since_tizen> 4 </since_tizen>
29     public class StreamRecorderVideoOptions
30     {
31         private const int DefaultBitRate = 0;
32
33         /// <summary>
34         /// Initialize a new instance of the <see cref="StreamRecorderVideoOptions"/> class with the specified
35         /// codec, resolution, source format, and frame rate.
36         /// </summary>
37         /// <param name="codec">The <see cref="RecorderVideoCodec"/> for encoding video stream.</param>
38         /// <param name="resolution">The resolution of video recording.</param>
39         /// <param name="sourceFormat">The format of source stream.</param>
40         /// <param name="frameRate">The frame rate for encoding video stream.</param>
41         /// <remarks>
42         /// <see cref="BitRate"/> will be set as default.
43         /// </remarks>
44         /// <exception cref="ArgumentException">
45         ///     <paramref name="codec"/> is not valid.<br/>
46         ///     -or-<br/>
47         ///     <paramref name="sourceFormat"/> is not valid.
48         /// </exception>
49         /// <exception cref="ArgumentOutOfRangeException">
50         ///     Width or height of <paramref name="resolution"/> is less than or equal to zero.<br/>
51         ///     -or-<br/>
52         ///     <paramref name="frameRate"/> is less than or equal to zero.
53         /// </exception>
54         /// <since_tizen> 4 </since_tizen>
55         public StreamRecorderVideoOptions(RecorderVideoCodec codec, Size resolution,
56             StreamRecorderVideoFormat sourceFormat, int frameRate) :
57             this(codec, resolution, sourceFormat, frameRate, DefaultBitRate)
58         {
59         }
60
61         /// <summary>
62         /// Initialize a new instance of the <see cref="StreamRecorderVideoOptions"/> class with the specified
63         /// codec, resolution, source format, frame rate, and bit rate.
64         /// </summary>
65         /// <param name="codec">The <see cref="RecorderVideoCodec"/> for encoding video stream.</param>
66         /// <param name="resolution">The resolution of video recording.</param>
67         /// <param name="sourceFormat">The format of source stream.</param>
68         /// <param name="frameRate">The frame rate for encoding video stream.</param>
69         /// <param name="bitRate">The bit rate for encoding video stream.</param>
70         /// <exception cref="ArgumentException">
71         ///     <paramref name="codec"/> is not valid.<br/>
72         ///     -or-<br/>
73         ///     <paramref name="sourceFormat"/> is not valid.<br/>
74         /// </exception>
75         /// <exception cref="ArgumentOutOfRangeException">
76         ///     Width or height of <paramref name="resolution"/> is less than or equal to zero.<br/>
77         ///     -or-<br/>
78         ///     <paramref name="frameRate"/> is less than or equal to zero.<br/>
79         ///     -or-<br/>
80         ///     <paramref name="bitRate"/> is less than zero.
81         /// </exception>
82         /// <since_tizen> 4 </since_tizen>
83         public StreamRecorderVideoOptions(RecorderVideoCodec codec, Size resolution,
84             StreamRecorderVideoFormat sourceFormat, int frameRate, int bitRate)
85         {
86             Codec = codec;
87             Resolution = resolution;
88             SourceFormat = sourceFormat;
89             FrameRate = frameRate;
90             BitRate = bitRate;
91         }
92
93         private RecorderVideoCodec _codec;
94
95         /// <summary>
96         /// Gets or sets the video codec for encoding video stream.
97         /// </summary>
98         /// <value>The codec for video stream recording.</value>
99         /// <exception cref="ArgumentException"><paramref name="value"/> is not valid.</exception>
100         /// <seealso cref="StreamRecorder.GetSupportedVideoCodecs"/>
101         /// <since_tizen> 4 </since_tizen>
102         public RecorderVideoCodec Codec
103         {
104             get => _codec;
105             set
106             {
107                 ValidationUtil.ValidateEnum(typeof(RecorderVideoCodec), value, nameof(value));
108
109                 _codec = value;
110             }
111         }
112
113         private Size _resolution;
114
115         /// <summary>
116         /// Gets or sets the resolution of the video recording.
117         /// </summary>
118         /// <value>The output resolution for video stream recording.</value>
119         /// <exception cref="ArgumentOutOfRangeException">
120         ///     Width or height of <paramref name="value"/> is less than or equal to zero.
121         /// </exception>
122         /// <seealso cref="StreamRecorder.GetSupportedVideoResolutions"/>
123         /// <since_tizen> 4 </since_tizen>
124         public Size Resolution
125         {
126             get => _resolution;
127             set
128             {
129                 if (value.Width <= 0 || value.Height <= 0)
130                 {
131                     throw new ArgumentOutOfRangeException(nameof(value), value,
132                         "Resolution can't be less than or equal to zero.");
133                 }
134
135                 _resolution = value;
136             }
137         }
138
139         private int _frameRate;
140
141         /// <summary>
142         /// Gets or sets the frame rate for recording media stream.
143         /// </summary>
144         /// <value>The frame rate value for video stream recording.</value>
145         /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than or equal to zero.</exception>
146         /// <since_tizen> 4 </since_tizen>
147         public int FrameRate
148         {
149             get => _frameRate;
150             set
151             {
152                 if (value <= 0)
153                 {
154                     throw new ArgumentOutOfRangeException(nameof(value), value,
155                         "Frame rate can't be less than or equal to zero.");
156                 }
157                 _frameRate = value;
158             }
159         }
160
161         private StreamRecorderVideoFormat _sourceFormat;
162
163         /// <summary>
164         /// Gets or sets the video source format for recording media stream.
165         /// </summary>
166         /// <value>The source format of buffers for video stream recording.</value>
167         /// <exception cref="ArgumentException"><paramref name="value"/> is not valid.</exception>
168         /// <since_tizen> 4 </since_tizen>
169         public StreamRecorderVideoFormat SourceFormat
170         {
171             get => _sourceFormat;
172             set
173             {
174                 ValidationUtil.ValidateEnum(typeof(StreamRecorderVideoFormat), value, nameof(value));
175
176                 _sourceFormat = value;
177             }
178         }
179
180         private int _bitRate;
181
182         /// <summary>
183         /// The bit rate of the video encoder in bits per second.
184         /// </summary>
185         /// <value>The bit rate value for video stream recording. The default is 0.</value>
186         /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
187         /// <since_tizen> 4 </since_tizen>
188         public int BitRate
189         {
190             get => _bitRate;
191             set
192             {
193                 if (value < 0)
194                 {
195                     throw new ArgumentOutOfRangeException(nameof(value), value,
196                         "Bit rate can't be less than or equal to zero.");
197                 }
198                 _bitRate = value;
199             }
200         }
201
202         internal void Apply(StreamRecorder recorder)
203         {
204             recorder.ValidateVideoCodec(Codec);
205
206             Native.SetVideoEncoder(recorder.Handle, Codec.ToStreamRecorderEnum()).
207                 ThrowIfError("Failed to set video codec.");
208
209             recorder.ValidateVideoResolution(Resolution);
210
211             Native.SetVideoResolution(recorder.Handle, Resolution.Width, Resolution.Height).
212                 ThrowIfError("Failed to set video resolution.");
213
214             Native.SetVideoFrameRate(recorder.Handle, FrameRate).
215                 ThrowIfError("Failed to set video frame rate.");
216
217             Native.SetVideoEncoderBitRate(recorder.Handle, BitRate).
218                 ThrowIfError("Failed to set video bit rate.");
219
220             Native.SetVideoSourceFormat(recorder.Handle, SourceFormat).
221                 ThrowIfError("Failed to set video source format.");
222         }
223     }
224
225 }