AliyunPlayer  v5.2.0
Aliyun Player API Reference Manual for Windows Platforms
AVPConfig.h
1 //
2 // AVPConfig.h
3 //
4 // Created by shiping.csp on 2018/11/16.
5 // Copyright © 2018年 com.alibaba.AliyunPlayer. All rights reserved.
6 //
7 
8 #ifndef AVPConfig_h
9 #define AVPConfig_h
10 
11 #include "AVPDef.h"
12 #include <corecrt_malloc.h>
13 #include <string.h>
14 
15 namespace alivc_player {
16  typedef struct _AVPConfig {
21 
26 
31 
36 
41 
46 
51 
55  char *referer;
56 
60  char *httpProxy;
61 
65  char *userAgent;
66 
70  char **httpHeaders;
71 
76 
77  _AVPConfig()
78  {
79  referer = nullptr;
80  httpProxy = nullptr;
81  userAgent = nullptr;
82  httpHeaders = nullptr;
83  networkTimeout = 15000;
85  maxBufferDuration = 500000;
86  startBufferDuration = 500;
87  highBufferDuration = 3000;
88  maxDelayTime = 5000;
89  showLastFrameWhenStop = true;
90  headerCount = 0;
91  }
92 
93  _AVPConfig(const _AVPConfig &config)
94  {
95  referer = nullptr;
96  httpProxy = nullptr;
97  userAgent = nullptr;
98  httpHeaders = nullptr;
99 
100  if (config.referer) {
101  referer = strdup(config.referer);
102  }
103  if (config.httpProxy) {
104  httpProxy = strdup(config.httpProxy);
105  }
106  if (config.userAgent) {
107  userAgent = strdup(config.userAgent);
108  }
109 
110  headerCount = config.headerCount;
111  httpHeaders = new char *[headerCount];
112  for (int i = 0; i < headerCount; i++) {
113  httpHeaders[i] = strdup(config.httpHeaders[i]);
114  }
115 
121  maxDelayTime = config.maxDelayTime;
123  }
124 
125  _AVPConfig operator=(const _AVPConfig &config)
126  {
127  if (referer) {
128  free(referer);
129  referer = nullptr;
130  }
131  if (config.referer) {
132  referer = strdup(config.referer);
133  }
134  if (httpProxy) {
135  free(httpProxy);
136  httpProxy = nullptr;
137  }
138  if (config.httpProxy) {
139  httpProxy = strdup(config.httpProxy);
140  }
141  if (userAgent) {
142  free(userAgent);
143  userAgent = nullptr;
144  }
145  if (config.userAgent) {
146  userAgent = strdup(config.userAgent);
147  }
148 
149  if (headerCount > 0) {
150  for (int i = 0; i < headerCount; i++) {
151  free(httpHeaders[i]);
152  }
153  delete[] httpHeaders;
154  httpHeaders = nullptr;
155  }
156  headerCount = config.headerCount;
157  httpHeaders = new char *[headerCount];
158  for (int i = 0; i < headerCount; i++) {
159  httpHeaders[i] = strdup(config.httpHeaders[i]);
160  }
161 
162  networkTimeout = config.networkTimeout;
163  networkRetryCount = config.networkRetryCount;
164  maxBufferDuration = config.maxBufferDuration;
165  startBufferDuration = config.startBufferDuration;
166  highBufferDuration = config.highBufferDuration;
167  maxDelayTime = config.maxDelayTime;
168  showLastFrameWhenStop = config.showLastFrameWhenStop;
169 
170  return *this;
171  }
172 
173  ~_AVPConfig()
174  {
175  if (referer) {
176  free(referer);
177  }
178  if (httpProxy) {
179  free(httpProxy);
180  }
181  if (userAgent) {
182  free(userAgent);
183  }
184  if (headerCount > 0) {
185  for (int i = 0; i < headerCount; i++) {
186  free(httpHeaders[i]);
187  }
188  delete[] httpHeaders;
189  httpHeaders = nullptr;
190  }
191  }
192 
193  } AVPConfig;
194 
195  typedef struct _AVPCacheConfig {
199  /****
200  @brief The maximum length of a single video that can be cached. Unit: seconds. Videos that exceed the maximum length are not cached.
201  */
203 
207  /****
208  @brief The maximum cache memory size. Unit: MB.
209  */
211 
215  /****
216  @brief Enable or disable content caching. Default: disabled.
217  */
218  bool enable;
219 
223  /****
224  @brief The cache directory.
225  */
226  char *path;
227 
229  {
230  maxDuration = 0;
231  maxSizeMB = 0;
232  enable = false;
233  path = nullptr;
234  }
235 
236  _AVPCacheConfig(const _AVPCacheConfig &config)
237  {
238  path = nullptr;
239  if (config.path) {
240  path = strdup(config.path);
241  }
242 
243  maxDuration = config.maxDuration;
244  maxSizeMB = config.maxSizeMB;
245  enable = config.enable;
246  }
247 
248  _AVPCacheConfig operator=(const _AVPCacheConfig &config)
249  {
250  if (path) {
251  free(path);
252  path = nullptr;
253  }
254  if (config.path) {
255  path = strdup(config.path);
256  }
257  maxDuration = config.maxDuration;
258  maxSizeMB = config.maxSizeMB;
259  enable = config.enable;
260 
261  return *this;
262  }
263 
264  ~_AVPCacheConfig()
265  {
266  if (path) {
267  free(path);
268  path = nullptr;
269  }
270  }
271  } AVPCacheConfig;
272 
273  class ALIVC_EXTERN VidPlayerConfigGenerator {
274  public:
279  /****
280  @brief Set the preview duration.
281  @param previewTime The specified preview duration in seconds.
282  */
283  void setPreviewTime(int previewTime);
284 
289  /****
290  @brief Set a UriToken for HLS standard encryption.
291  @param MtsHlsUriToken The UriToken.
292  */
293  void setHlsUriToken(const char *mtsHlsUriToken);
294 
298  /****
299  @brief Generate playerConfig. the return value should be freed width alivcFree()
300  */
301  const char *generatePlayerConfig();
302 
303  private:
304  void *mConfigData = nullptr;
305  };
306 
307 
308 };// namespace alivc_player
309 
310 #endif /* AVPConfig_h */
alivc_player::_AVPCacheConfig::maxSizeMB
int maxSizeMB
所有缓存最大占用空间,单位:MB
Definition: AVPConfig.h:210
alivc_player::_AVPConfig::networkRetryCount
int networkRetryCount
网络重试次数,每次间隔networkTimeout,networkRetryCount=0则表示不重试,重试策略app决定,默认值为2
Definition: AVPConfig.h:45
alivc_player::_AVPConfig::startBufferDuration
int startBufferDuration
开始起播缓存区数据长度,默认500ms
Definition: AVPConfig.h:30
alivc_player::_AVPConfig::maxDelayTime
int maxDelayTime
直播最大延迟 默认5000毫秒
Definition: AVPConfig.h:20
alivc_player::_AVPConfig::httpHeaders
char ** httpHeaders
添加自定义header
Definition: AVPConfig.h:70
alivc_player::_AVPConfig::userAgent
char * userAgent
user Agent
Definition: AVPConfig.h:65
alivc_player::_AVPCacheConfig::maxDuration
int maxDuration
单个视频缓存的最大时长,单位秒,即某个视频的时长超过maxDuration将不会被缓存
Definition: AVPConfig.h:202
alivc_player::_AVPConfig
Definition: AVPConfig.h:16
alivc_player::_AVPConfig::showLastFrameWhenStop
bool showLastFrameWhenStop
当stop的时候是否保留最后一帧图像显示,默认显示
Definition: AVPConfig.h:50
alivc_player::_AVPCacheConfig::enable
bool enable
是否开启缓存。默认关闭。
Definition: AVPConfig.h:218
alivc_player::_AVPCacheConfig
Definition: AVPConfig.h:195
alivc_player::_AVPConfig::networkTimeout
int networkTimeout
网络超时时间,默认15秒
Definition: AVPConfig.h:40
alivc_player::VidPlayerConfigGenerator
Definition: AVPConfig.h:273
alivc_player::_AVPCacheConfig::path
char * path
缓存目录
Definition: AVPConfig.h:226
alivc_player::VidPlayerConfigGenerator::generatePlayerConfig
const char * generatePlayerConfig()
生成playerConfig, 返回值使用后需要使用alivcFree释放。
alivc_player::VidPlayerConfigGenerator::setPreviewTime
void setPreviewTime(int previewTime)
设置预览时间
alivc_player::_AVPConfig::httpProxy
char * httpProxy
httpProxy代理
Definition: AVPConfig.h:60
alivc_player::_AVPConfig::headerCount
int headerCount
自定义header的数量
Definition: AVPConfig.h:75
alivc_player::_AVPConfig::maxBufferDuration
int maxBufferDuration
播放器最大的缓存数据长度,默认50秒
Definition: AVPConfig.h:35
alivc_player::_AVPConfig::highBufferDuration
int highBufferDuration
卡顿后缓存数据的高水位,当播放器缓存数据大于此值时开始播放
Definition: AVPConfig.h:25
alivc_player::VidPlayerConfigGenerator::setHlsUriToken
void setHlsUriToken(const char *mtsHlsUriToken)
HLS标准加密设置UriToken.
alivc_player::_AVPConfig::referer
char * referer
请求referer
Definition: AVPConfig.h:55