2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using Native = Interop.StreamRecorder;
20 namespace Tizen.Multimedia
23 /// Specifies the options associated with video recording.
25 /// <seealso cref="StreamRecorder"/>
26 /// <seealso cref="StreamRecorderOptions"/>
27 /// <seealso cref="StreamRecorderAudioOptions"/>
28 /// <since_tizen> 4 </since_tizen>
29 public class StreamRecorderVideoOptions
31 private const int DefaultBitRate = 0;
34 /// Initialize a new instance of the <see cref="StreamRecorderVideoOptions"/> class with the specified
35 /// codec, resolution, source format, and frame rate.
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>
42 /// <see cref="BitRate"/> will be set as default.
44 /// <exception cref="ArgumentException">
45 /// <paramref name="codec"/> is not valid.<br/>
47 /// <paramref name="sourceFormat"/> is not valid.
49 /// <exception cref="ArgumentOutOfRangeException">
50 /// Width or height of <paramref name="resolution"/> is less than or equal to zero.<br/>
52 /// <paramref name="frameRate"/> is less than or equal to zero.
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)
62 /// Initialize a new instance of the <see cref="StreamRecorderVideoOptions"/> class with the specified
63 /// codec, resolution, source format, frame rate, and bit rate.
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/>
73 /// <paramref name="sourceFormat"/> is not valid.<br/>
75 /// <exception cref="ArgumentOutOfRangeException">
76 /// Width or height of <paramref name="resolution"/> is less than or equal to zero.<br/>
78 /// <paramref name="frameRate"/> is less than or equal to zero.<br/>
80 /// <paramref name="bitRate"/> is less than zero.
82 /// <since_tizen> 4 </since_tizen>
83 public StreamRecorderVideoOptions(RecorderVideoCodec codec, Size resolution,
84 StreamRecorderVideoFormat sourceFormat, int frameRate, int bitRate)
87 Resolution = resolution;
88 SourceFormat = sourceFormat;
89 FrameRate = frameRate;
93 private RecorderVideoCodec _codec;
96 /// Gets or sets the video codec for encoding video stream.
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
107 ValidationUtil.ValidateEnum(typeof(RecorderVideoCodec), value, nameof(value));
113 private Size _resolution;
116 /// Gets or sets the resolution of the video recording.
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.
122 /// <seealso cref="StreamRecorder.GetSupportedVideoResolutions"/>
123 /// <since_tizen> 4 </since_tizen>
124 public Size Resolution
129 if (value.Width <= 0 || value.Height <= 0)
131 throw new ArgumentOutOfRangeException(nameof(value), value,
132 "Resolution can't be less than or equal to zero.");
139 private int _frameRate;
142 /// Gets or sets the frame rate for recording media stream.
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>
154 throw new ArgumentOutOfRangeException(nameof(value), value,
155 "Frame rate can't be less than or equal to zero.");
161 private StreamRecorderVideoFormat _sourceFormat;
164 /// Gets or sets the video source format for recording media stream.
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
171 get => _sourceFormat;
174 ValidationUtil.ValidateEnum(typeof(StreamRecorderVideoFormat), value, nameof(value));
176 _sourceFormat = value;
180 private int _bitRate;
183 /// The bit rate of the video encoder in bits per second.
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>
195 throw new ArgumentOutOfRangeException(nameof(value), value,
196 "Bit rate can't be less than or equal to zero.");
202 internal void Apply(StreamRecorder recorder)
204 recorder.ValidateVideoCodec(Codec);
206 Native.SetVideoEncoder(recorder.Handle, Codec.ToStreamRecorderEnum()).
207 ThrowIfError("Failed to set video codec.");
209 recorder.ValidateVideoResolution(Resolution);
211 Native.SetVideoResolution(recorder.Handle, Resolution.Width, Resolution.Height).
212 ThrowIfError("Failed to set video resolution.");
214 Native.SetVideoFrameRate(recorder.Handle, FrameRate).
215 ThrowIfError("Failed to set video frame rate.");
217 Native.SetVideoEncoderBitRate(recorder.Handle, BitRate).
218 ThrowIfError("Failed to set video bit rate.");
220 Native.SetVideoSourceFormat(recorder.Handle, SourceFormat).
221 ThrowIfError("Failed to set video source format.");