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 public class StreamRecorderOptions
33 /// Initialize a new instance of the <see cref="StreamRecorderOptions"/> class with the specified
34 /// save path and file format.
36 /// <param name="savePath">The path that the recording result is saved.</param>
37 /// <param name="fileFormat">The file format of output file.</param>
38 /// <exception cref="ArgumentNullException"><paramref name="savePath"/>is null.</exception>
39 /// <exception cref="ArgumentException">
40 /// <paramref name="savePath"/>is an empty string.<br/>
42 /// <paramref name="fileFormat"/> is not valid.
44 public StreamRecorderOptions(string savePath, RecorderFileFormat fileFormat)
47 FileFormat = fileFormat;
50 private string _savePath;
53 /// Gets or sets the file path to record.
56 /// If the same file already exists in the file system, then old file will be overwritten.
58 /// <exception cref="ArgumentNullException"><paramref name="value"/>is null.</exception>
59 /// <exception cref="ArgumentException"><paramref name="value"/>is an empty string.</exception>
60 public string SavePath
67 throw new ArgumentNullException(nameof(value));
70 if (string.IsNullOrWhiteSpace(value))
72 throw new ArgumentException("Path can't be an empty string.", nameof(value));
79 private RecorderFileFormat _fileFormat;
82 /// Gets or sets the file format for recording media stream.
84 /// <exception cref="ArgumentException"><paramref name="value"/> is not valid.</exception>
85 /// <seealso cref="StreamRecorder.GetSupportedFileFormats"/>
86 public RecorderFileFormat FileFormat
91 ValidationUtil.ValidateEnum(typeof(RecorderFileFormat), value, nameof(value));
97 private int _timeLimit;
100 /// Gets or sets the time limit of recording.
103 /// The maximum time of recording in seconds, or 0 for unlimited time.
106 /// After reaching the limitation, the data which is being recorded will
107 /// be discarded and not written to the file.
109 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
110 /// <seealso cref="StreamRecorder.RecordingLimitReached"/>
111 /// <seealso cref="SizeLimit"/>
119 throw new ArgumentOutOfRangeException(nameof(value), value,
120 "Time limit can't be less than zero.");
127 private int _sizeLimit;
130 /// Gets or sets the maximum size of a recording file.
133 /// The maximum size of a recording file in kilobytes, or 0 for unlimited size.
136 /// After reaching the limitation, the data which is being recorded will
137 /// be discarded and not written to the file.
139 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
140 /// <seealso cref="StreamRecorder.RecordingLimitReached"/>
141 /// <seealso cref="TimeLimit"/>
149 throw new ArgumentOutOfRangeException(nameof(value), value,
150 "Size limit can't be less than zero.");
158 /// Gets or sets the options for audio recording.
161 /// <see cref="Audio"/> or <see cref="Video"/> must be set for recording.
163 /// <seealso cref="Video"/>
164 public StreamRecorderAudioOptions Audio { get; set; }
167 /// Gets or sets the options for video recording.
170 /// <see cref="Audio"/> or <see cref="Video"/> must be set for recording.
172 /// <seealso cref="Audio"/>
173 public StreamRecorderVideoOptions Video { get; set; }
175 private StreamRecorderSourceType GetSourceType()
177 Debug.Assert(Audio != null || Video != null);
179 if (Audio != null && Video != null)
181 return StreamRecorderSourceType.VideoAudio;
184 return Audio != null ? StreamRecorderSourceType.Audio : StreamRecorderSourceType.Video;
187 internal void Apply(StreamRecorder recorder)
189 if (Audio == null && Video == null)
191 throw new ArgumentException("Both Audio and Video are not set.");
194 Native.EnableSourceBuffer(recorder.Handle, GetSourceType()).ThrowIfError("Failed to apply options.");
196 Native.SetFileName(recorder.Handle, SavePath).ThrowIfError("Failed to set save path.");
198 recorder.ValidateFileFormat(FileFormat);
199 Native.SetFileFormat(recorder.Handle, FileFormat.ToStreamRecorderEnum())
200 .ThrowIfError("Failed to set file format.");
202 Native.SetRecordingLimit(recorder.Handle, RecordingLimitType.Size, SizeLimit).
203 ThrowIfError("Failed to set size limit.");
205 Native.SetRecordingLimit(recorder.Handle, RecordingLimitType.Time, TimeLimit).
206 ThrowIfError("Failed to set time limit.");
208 Audio?.Apply(recorder);
210 Video?.Apply(recorder);