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