/
AdaptiveVariants.cs
179 lines (159 loc) · 6.46 KB
/
AdaptiveVariants.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* Copyright (c) 2018 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.Diagnostics;
using System.Collections.Generic;
using static Interop;
namespace Tizen.Multimedia
{
/// <summary>
/// Represents properties for the variant information.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public struct VariantInfo
{
/// <summary>
/// Initializes a new instance of the VariantInfo struct.
/// </summary>
/// <param name="bandwidth">The bandwidth of the stream can be supportable, it must be set. (deafult: -1)</param>
/// <param name="width">The width of the stream, this is optional parameter. (deafult: -1)</param>
/// <param name="height">The height of the stream, this is optional parameter. (deafult: -1)</param>
/// <since_tizen> 5 </since_tizen>
public VariantInfo(int bandwidth, int width = -1, int height = -1)
{
Bandwidth = bandwidth;
Width = width;
Height = height;
}
/// <summary>
/// Gets or sets the maximum limit of the available bandwidth. (-1 = no limit).
/// </summary>
/// <since_tizen> 5 </since_tizen>
public int Bandwidth
{
get;
set;
}
/// <summary>
/// Gets or sets the maximum limit of the available width. (-1 = no limit).
/// </summary>
/// <since_tizen> 5 </since_tizen>
public int Width
{
get;
set;
}
/// <summary>
/// Gets or sets the maximum limit of the available height. (-1 = no limit).
/// </summary>
/// <since_tizen> 5 </since_tizen>
public int Height
{
get;
set;
}
}
/// <summary>
/// Provides the ability to control the maximum limit of the available streaming variant for <see cref="Multimedia.Player"/>.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public class AdaptiveVariants
{
private IList<VariantInfo> _adaptiveVariants;
/// <summary>
/// Gets the <see cref="Multimedia.Player"/> that owns this instance.
/// </summary>
/// <since_tizen> 5 </since_tizen>
private readonly Player Player;
internal AdaptiveVariants(Player player)
{
Debug.Assert(player != null);
Player = player;
}
/// <summary>
/// Sets the maximum limit of the streaming variant.
/// </summary>
/// <exception cref="ObjectDisposedException">The <see cref="Player"/> has already been disposed of.</exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <pramref name="bandwidth"/> is less than -1.<br/>
/// -or-<br/>
/// <pramref name="width"/> is less than -1.<br/>
/// -or-<br/>
/// <pramref name="height"/> is less than -1.<br/>
/// </exception>
/// <seealso cref="GetMaxLimit()"/>
/// <since_tizen> 5 </since_tizen>
public void SetMaxLimit(int bandwidth, int width = -1, int height = -1)
{
Player.ValidateNotDisposed();
if (bandwidth < -1 || width < -1 || height < -1)
{
throw new ArgumentOutOfRangeException("invalid range");
}
NativePlayer.SetMaxLimit(Player.Handle, bandwidth, width, height).
ThrowIfFailed(Player, "Failed to set the max limit to the player");
}
/// <summary>
/// Gets the maximum limit of the streaming variant.
/// </summary>
/// <returns>The <see cref="VariantInfo"/> containing the variant information.</returns>
/// <exception cref="ObjectDisposedException">The <see cref="Player"/> has already been disposed of.</exception>
/// <seealso cref="SetMaxLimit(int, int, int)"/>
/// <since_tizen> 5 </since_tizen>
public VariantInfo GetMaxLimit()
{
Player.ValidateNotDisposed();
NativePlayer.GetMaxLimit(Player.Handle, out var bandwidth, out var width, out var height).
ThrowIfFailed(Player, "Failed to get the max limit to the player");
return new VariantInfo(bandwidth, width, height);
}
/// <summary>
/// Retrieves all the available adaptive variants.
/// </summary>
/// <returns>
/// It returns a list contained all the available adaptive variants.
/// </returns>
/// The <see cref="Player"/> must be in the <see cref="PlayerState.Ready"/>,
/// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.
/// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
/// <exception cref="ObjectDisposedException">The <see cref="Player"/> has already been disposed of.</exception>
/// <seealso cref="VariantInfo"/>
/// <since_tizen> 5 </since_tizen>
public IEnumerable<VariantInfo> AvailableAdaptiveVariants
{
get
{
if (_adaptiveVariants == null)
{
_adaptiveVariants = GetAdaptiveVariants();
}
return _adaptiveVariants;
}
}
private IList<VariantInfo> GetAdaptiveVariants()
{
List<VariantInfo> adaptiveVariants = new List<VariantInfo>();
NativePlayer.AdaptiveVariantCallback callback = (int bandwidth, int width, int height, IntPtr userData) =>
{
adaptiveVariants.Add(new VariantInfo(bandwidth, width, height));
return true;
};
NativePlayer.ForeachAdaptiveVariants(Player.Handle, callback, IntPtr.Zero).
ThrowIfFailed(Player, "Failed to get the information of adaptive variants");
return adaptiveVariants.AsReadOnly();
}
}
}