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 System.Diagnostics;
19 using Native = Interop.StreamRecorder;
21 namespace Tizen.Multimedia
24 /// Specifies the options associated with <see cref="StreamRecorder"/>.
26 /// <seealso cref="StreamRecorder"/>
27 /// <seealso cref="StreamRecorder.Prepare(StreamRecorderOptions)"/>
28 /// <seealso cref="StreamRecorderAudioOptions"/>
29 /// <seealso cref="StreamRecorderVideoOptions"/>
30 /// <since_tizen> 4 </since_tizen>
31 public class StreamRecorderOptions
34 /// Initialize a new instance of the <see cref="StreamRecorderOptions"/> class with the specified
35 /// save path and file format.
37 /// <param name="savePath">The path that the recording result is saved.</param>
38 /// <param name="fileFormat">The file format of output file.</param>
39 /// <exception cref="ArgumentNullException"><paramref name="savePath"/>is null.</exception>
40 /// <exception cref="ArgumentException">
41 /// <paramref name="savePath"/>is an empty string.<br/>
43 /// <paramref name="fileFormat"/> is not valid.
45 /// <since_tizen> 4 </since_tizen>
46 public StreamRecorderOptions(string savePath, RecorderFileFormat fileFormat)
49 FileFormat = fileFormat;
52 private string _savePath;
55 /// Gets or sets the file path to record.
58 /// If the same file already exists in the file system, then old file will be overwritten.
60 /// <exception cref="ArgumentNullException"><paramref name="value"/>is null.</exception>
61 /// <exception cref="ArgumentException"><paramref name="value"/>is an empty string.</exception>
62 /// <since_tizen> 4 </since_tizen>
63 public string SavePath
70 throw new ArgumentNullException(nameof(value));
73 if (string.IsNullOrWhiteSpace(value))
75 throw new ArgumentException("Path can't be an empty string.", nameof(value));
82 private RecorderFileFormat _fileFormat;
85 /// Gets or sets the file format for recording media stream.
87 /// <exception cref="ArgumentException"><paramref name="value"/> is not valid.</exception>
88 /// <seealso cref="StreamRecorder.GetSupportedFileFormats"/>
89 /// <since_tizen> 4 </since_tizen>
90 public RecorderFileFormat FileFormat
95 ValidationUtil.ValidateEnum(typeof(RecorderFileFormat), value, nameof(value));
101 private int _timeLimit;
104 /// Gets or sets the time limit of recording.
107 /// The maximum time of recording in seconds, or 0 for unlimited time.
110 /// After reaching the limitation, the data which is being recorded will
111 /// be discarded and not written to the file.
113 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
114 /// <seealso cref="StreamRecorder.RecordingLimitReached"/>
115 /// <seealso cref="SizeLimit"/>
116 /// <since_tizen> 4 </since_tizen>
124 throw new ArgumentOutOfRangeException(nameof(value), value,
125 "Time limit can't be less than zero.");
132 private int _sizeLimit;
135 /// Gets or sets the maximum size of a recording file.
138 /// The maximum size of a recording file in kilobytes, or 0 for unlimited size.
141 /// After reaching the limitation, the data which is being recorded will
142 /// be discarded and not written to the file.
144 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
145 /// <seealso cref="StreamRecorder.RecordingLimitReached"/>
146 /// <seealso cref="TimeLimit"/>
147 /// <since_tizen> 4 </since_tizen>
155 throw new ArgumentOutOfRangeException(nameof(value), value,
156 "Size limit can't be less than zero.");
164 /// Gets or sets the options for audio recording.
167 /// <see cref="Audio"/> or <see cref="Video"/> must be set for recording.
169 /// <seealso cref="Video"/>
170 /// <since_tizen> 4 </since_tizen>
171 public StreamRecorderAudioOptions Audio { get; set; }
174 /// Gets or sets the options for video recording.
177 /// <see cref="Audio"/> or <see cref="Video"/> must be set for recording.
179 /// <seealso cref="Audio"/>
180 /// <since_tizen> 4 </since_tizen>
181 public StreamRecorderVideoOptions Video { get; set; }
183 private StreamRecorderSourceType GetSourceType()
185 Debug.Assert(Audio != null || Video != null);
187 if (Audio != null && Video != null)
189 return StreamRecorderSourceType.VideoAudio;
192 return Audio != null ? StreamRecorderSourceType.Audio : StreamRecorderSourceType.Video;
195 internal void Apply(StreamRecorder recorder)
197 if (Audio == null && Video == null)
199 throw new ArgumentException("Both Audio and Video are not set.");
202 Native.EnableSourceBuffer(recorder.Handle, GetSourceType()).ThrowIfError("Failed to apply options.");
204 Native.SetFileName(recorder.Handle, SavePath).ThrowIfError("Failed to set save path.");
206 recorder.ValidateFileFormat(FileFormat);
207 Native.SetFileFormat(recorder.Handle, FileFormat.ToStreamRecorderEnum())
208 .ThrowIfError("Failed to set file format.");
210 Native.SetRecordingLimit(recorder.Handle, RecordingLimitType.Size, SizeLimit).
211 ThrowIfError("Failed to set size limit.");
213 Native.SetRecordingLimit(recorder.Handle, RecordingLimitType.Time, TimeLimit).
214 ThrowIfError("Failed to set time limit.");
216 Audio?.Apply(recorder);
218 Video?.Apply(recorder);