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 public class StreamRecorderVideoOptions
30 private const int DefaultBitRate = 0;
33 /// Initialize a new instance of the <see cref="StreamRecorderVideoOptions"/> class with the specified
34 /// codec, resolution, source format, and frame rate.
36 /// <param name="codec">The <see cref="RecorderVideoCodec"/> for encoding video stream.</param>
37 /// <param name="resolution">The resolution of video recording.</param>
38 /// <param name="sourceFormat">The format of source stream.</param>
39 /// <param name="frameRate">The frame rate for encoding video stream.</param>
41 /// <see cref="BitRate"/> will be set as default.
43 /// <exception cref="ArgumentException">
44 /// <paramref name="codec"/> is not valid.<br/>
46 /// <paramref name="sourceFormat"/> is not valid.
48 /// <exception cref="ArgumentOutOfRangeException">
49 /// Width or height of <paramref name="resolution"/> is less than or equal to zero.<br/>
51 /// <paramref name="frameRate"/> is less than or equal to zero.
53 public StreamRecorderVideoOptions(RecorderVideoCodec codec, Size resolution,
54 StreamRecorderVideoFormat sourceFormat, int frameRate) :
55 this(codec, resolution, sourceFormat, frameRate, DefaultBitRate)
60 /// Initialize a new instance of the <see cref="StreamRecorderVideoOptions"/> class with the specified
61 /// codec, resolution, source format, frame rate, and bit rate.
63 /// <param name="codec">The <see cref="RecorderVideoCodec"/> for encoding video stream.</param>
64 /// <param name="resolution">The resolution of video recording.</param>
65 /// <param name="sourceFormat">The format of source stream.</param>
66 /// <param name="frameRate">The frame rate for encoding video stream.</param>
67 /// <param name="bitRate">The bit rate for encoding video stream.</param>
68 /// <exception cref="ArgumentException">
69 /// <paramref name="codec"/> is not valid.<br/>
71 /// <paramref name="sourceFormat"/> is not valid.<br/>
73 /// <exception cref="ArgumentOutOfRangeException">
74 /// Width or height of <paramref name="resolution"/> is less than or equal to zero.<br/>
76 /// <paramref name="frameRate"/> is less than or equal to zero.<br/>
78 /// <paramref name="bitRate"/> is less than zero.
80 public StreamRecorderVideoOptions(RecorderVideoCodec codec, Size resolution,
81 StreamRecorderVideoFormat sourceFormat, int frameRate, int bitRate)
84 Resolution = resolution;
85 SourceFormat = sourceFormat;
86 FrameRate = frameRate;
90 private RecorderVideoCodec _codec;
93 /// Gets or sets the video codec for encoding video stream.
95 /// <value>The codec for video stream recording.</value>
96 /// <exception cref="ArgumentException"><paramref name="value"/> is not valid.</exception>
97 /// <seealso cref="StreamRecorder.GetSupportedVideoCodecs"/>
98 public RecorderVideoCodec Codec
103 ValidationUtil.ValidateEnum(typeof(RecorderVideoCodec), value, nameof(value));
109 private Size _resolution;
112 /// Gets or sets the resolution of the video recording.
114 /// <value>The output resolution for video stream recording.</value>
115 /// <exception cref="ArgumentOutOfRangeException">
116 /// Width or height of <paramref name="value"/> is less than or equal to zero.
118 /// <seealso cref="StreamRecorder.GetSupportedVideoResolutions"/>
119 public Size Resolution
124 if (value.Width <= 0 || value.Height <= 0)
126 throw new ArgumentOutOfRangeException(nameof(value), value,
127 "Resolution can't be less than or equal to zero.");
134 private int _frameRate;
137 /// Gets or sets the frame rate for recording media stream.
139 /// <value>The frame rate value for video stream recording.</value>
140 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than or equal to zero.</exception>
148 throw new ArgumentOutOfRangeException(nameof(value), value,
149 "Frame rate can't be less than or equal to zero.");
155 private StreamRecorderVideoFormat _sourceFormat;
158 /// Gets or sets the video source format for recording media stream.
160 /// <value>The source format of buffers for video stream recording.</value>
161 /// <exception cref="ArgumentException"><paramref name="value"/> is not valid.</exception>
162 public StreamRecorderVideoFormat SourceFormat
164 get => _sourceFormat;
167 ValidationUtil.ValidateEnum(typeof(StreamRecorderVideoFormat), value, nameof(value));
169 _sourceFormat = value;
173 private int _bitRate;
176 /// The bit rate of the video encoder in bits per second.
178 /// <value>The bit rate value for video stream recording. The default is 0.</value>
179 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
187 throw new ArgumentOutOfRangeException(nameof(value), value,
188 "Bit rate can't be less than or equal to zero.");
194 internal void Apply(StreamRecorder recorder)
196 recorder.ValidateVideoCodec(Codec);
198 Native.SetVideoEncoder(recorder.Handle, Codec.ToStreamRecorderEnum()).
199 ThrowIfError("Failed to set video codec.");
201 recorder.ValidateVideoResolution(Resolution);
203 Native.SetVideoResolution(recorder.Handle, Resolution.Width, Resolution.Height).
204 ThrowIfError("Failed to set video resolution.");
206 Native.SetVideoFrameRate(recorder.Handle, FrameRate).
207 ThrowIfError("Failed to set video frame rate.");
209 Native.SetVideoEncoderBitRate(recorder.Handle, BitRate).
210 ThrowIfError("Failed to set video bit rate.");
212 Native.SetVideoSourceFormat(recorder.Handle, SourceFormat).
213 ThrowIfError("Failed to set video source format.");