-
Notifications
You must be signed in to change notification settings - Fork 241
/
StreamRecorder.Capabilities.cs
162 lines (135 loc) · 5.93 KB
/
StreamRecorder.Capabilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using Native = Interop.StreamRecorder;
namespace Tizen.Multimedia
{
public partial class StreamRecorder
{
internal void LoadCapabilities()
{
_videoCodecs = LoadVideoCodecs(this);
_audioCodecs = LoadAudioCodecs(this);
_fileFormats = LoadFileFormats(this);
_videoResolutions = LoadResolutions(this);
}
private static IEnumerable<RecorderVideoCodec> LoadVideoCodecs(StreamRecorder recorder)
{
var result = new List<RecorderVideoCodec>();
Native.VideoEncoderCallback callback = (codec, _) =>
{
result.Add(codec.ToRecorderEnum());
return true;
};
Native.VideoEncoders(recorder.Handle, callback).ThrowIfError("Failed to get the supported video codecs.");
return result.AsReadOnly();
}
private static IEnumerable<RecorderAudioCodec> LoadAudioCodecs(StreamRecorder recorder)
{
var result = new List<RecorderAudioCodec>();
Native.AudioEncoders(recorder.Handle, (codec, _) =>
{
result.Add(codec.ToRecorderEnum());
return true;
}).ThrowIfError("Failed to get the supported audio codecs.");
return result.AsReadOnly();
}
private static IEnumerable<RecorderFileFormat> LoadFileFormats(StreamRecorder recorder)
{
var result = new List<RecorderFileFormat>();
Native.FileFormats(recorder.Handle, (fileFormat, _) =>
{
result.Add(fileFormat.ToRecorderEnum());
return true;
}).ThrowIfError("Failed to get the supported file formats.");
return result.AsReadOnly();
}
private static IEnumerable<Size> LoadResolutions(StreamRecorder recorder)
{
List<Size> result = new List<Size>();
Native.VideoResolutionCallback callback = (width, height, _) =>
{
result.Add(new Size(width, height));
return true;
};
Native.VideoResolution(recorder.Handle, callback).
ThrowIfError("Failed to get the supported video resolutions.");
return result.AsReadOnly();
}
private IEnumerable<RecorderFileFormat> _fileFormats;
/// <summary>
/// Gets the file formats that the current device supports.
/// </summary>
/// <returns>An IEnumerable of <see cref="RecorderFileFormat"/> representing the supported file formats.</returns>
/// <since_tizen> 4 </since_tizen>
[Obsolete("Deprecated in API10; Will be removed in API12")]
public IEnumerable<RecorderFileFormat> GetSupportedFileFormats() => _fileFormats;
private IEnumerable<RecorderAudioCodec> _audioCodecs;
/// <summary>
/// Gets the audio codecs that the current device supports.
/// </summary>
/// <returns>An IEnumerable of <see cref="RecorderAudioCodec"/> representing the supported audio codecs.</returns>
/// <since_tizen> 4 </since_tizen>
[Obsolete("Deprecated in API10; Will be removed in API12")]
public IEnumerable<RecorderAudioCodec> GetSupportedAudioCodecs() => _audioCodecs;
private IEnumerable<RecorderVideoCodec> _videoCodecs;
/// <summary>
/// Gets the video codecs that the current device supports.
/// </summary>
/// <returns>An IEnumerable of <see cref="RecorderVideoCodec"/> representing the supported video codecs.</returns>
/// <since_tizen> 4 </since_tizen>
[Obsolete("Deprecated in API10; Will be removed in API12")]
public IEnumerable<RecorderVideoCodec> GetSupportedVideoCodecs() => _videoCodecs;
private IEnumerable<Size> _videoResolutions;
/// <summary>
/// Gets the video resolutions that the current device supports.
/// </summary>
/// <returns>An IEnumerable of <see cref="Size"/> representing the supported resolutions.</returns>
/// <since_tizen> 4 </since_tizen>
[Obsolete("Deprecated in API10; Will be removed in API12")]
public IEnumerable<Size> GetSupportedVideoResolutions() => _videoResolutions;
internal void ValidateFileFormat(RecorderFileFormat format)
{
if (_fileFormats.Contains(format) == false)
{
throw new NotSupportedException($"{format.ToString()} is not supported.");
}
}
internal void ValidateAudioCodec(RecorderAudioCodec codec)
{
if (_audioCodecs.Contains(codec) == false)
{
throw new NotSupportedException($"{codec.ToString()} is not supported.");
}
}
internal void ValidateVideoCodec(RecorderVideoCodec codec)
{
if (_videoCodecs.Contains(codec) == false)
{
throw new NotSupportedException($"{codec.ToString()} is not supported.");
}
}
internal void ValidateVideoResolution(Size resolution)
{
if (_videoResolutions.Contains(resolution) == false)
{
throw new NotSupportedException($"Resolution({resolution.ToString()}) is not supported.");
}
}
}
}