You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1275 lines
42KB

  1. /*
  2. * Apple HTTP Live Streaming demuxer
  3. * Copyright (c) 2010 Martin Storsjo
  4. * Copyright (c) 2013 Anssi Hannula
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * Apple HTTP Live Streaming demuxer
  25. * http://tools.ietf.org/html/draft-pantos-http-live-streaming
  26. */
  27. #include "libavutil/avstring.h"
  28. #include "libavutil/intreadwrite.h"
  29. #include "libavutil/mathematics.h"
  30. #include "libavutil/opt.h"
  31. #include "libavutil/dict.h"
  32. #include "libavutil/time.h"
  33. #include "avformat.h"
  34. #include "internal.h"
  35. #include "avio_internal.h"
  36. #include "url.h"
  37. #define INITIAL_BUFFER_SIZE 32768
  38. #define MAX_FIELD_LEN 64
  39. #define MAX_CHARACTERISTICS_LEN 512
  40. /*
  41. * An apple http stream consists of a playlist with media segment files,
  42. * played sequentially. There may be several playlists with the same
  43. * video content, in different bandwidth variants, that are played in
  44. * parallel (preferably only one bandwidth variant at a time). In this case,
  45. * the user supplied the url to a main playlist that only lists the variant
  46. * playlists.
  47. *
  48. * If the main playlist doesn't point at any variants, we still create
  49. * one anonymous toplevel variant for this, to maintain the structure.
  50. */
  51. enum KeyType {
  52. KEY_NONE,
  53. KEY_AES_128,
  54. };
  55. struct segment {
  56. int64_t duration;
  57. int64_t url_offset;
  58. int64_t size;
  59. char url[MAX_URL_SIZE];
  60. char key[MAX_URL_SIZE];
  61. enum KeyType key_type;
  62. uint8_t iv[16];
  63. };
  64. struct rendition;
  65. /*
  66. * Each playlist has its own demuxer. If it currently is active,
  67. * it has an open AVIOContext too, and potentially an AVPacket
  68. * containing the next packet from this stream.
  69. */
  70. struct playlist {
  71. char url[MAX_URL_SIZE];
  72. AVIOContext pb;
  73. uint8_t* read_buffer;
  74. URLContext *input;
  75. AVFormatContext *parent;
  76. int index;
  77. AVFormatContext *ctx;
  78. AVPacket pkt;
  79. int stream_offset;
  80. int finished;
  81. int64_t target_duration;
  82. int start_seq_no;
  83. int n_segments;
  84. struct segment **segments;
  85. int needed, cur_needed;
  86. int cur_seq_no;
  87. int64_t cur_seg_offset;
  88. int64_t last_load_time;
  89. char key_url[MAX_URL_SIZE];
  90. uint8_t key[16];
  91. /* Renditions associated with this playlist, if any.
  92. * Alternative rendition playlists have a single rendition associated
  93. * with them, and variant main Media Playlists may have
  94. * multiple (playlist-less) renditions associated with them. */
  95. int n_renditions;
  96. struct rendition **renditions;
  97. };
  98. /*
  99. * Renditions are e.g. alternative subtitle or audio streams.
  100. * The rendition may either be an external playlist or it may be
  101. * contained in the main Media Playlist of the variant (in which case
  102. * playlist is NULL).
  103. */
  104. struct rendition {
  105. enum AVMediaType type;
  106. struct playlist *playlist;
  107. char group_id[MAX_FIELD_LEN];
  108. char language[MAX_FIELD_LEN];
  109. char name[MAX_FIELD_LEN];
  110. int disposition;
  111. };
  112. struct variant {
  113. int bandwidth;
  114. /* every variant contains at least the main Media Playlist in index 0 */
  115. int n_playlists;
  116. struct playlist **playlists;
  117. char audio_group[MAX_FIELD_LEN];
  118. char video_group[MAX_FIELD_LEN];
  119. char subtitles_group[MAX_FIELD_LEN];
  120. };
  121. typedef struct HLSContext {
  122. int n_variants;
  123. struct variant **variants;
  124. int n_playlists;
  125. struct playlist **playlists;
  126. int n_renditions;
  127. struct rendition **renditions;
  128. int cur_seq_no;
  129. int end_of_segment;
  130. int first_packet;
  131. int64_t first_timestamp;
  132. int64_t seek_timestamp;
  133. int seek_flags;
  134. AVIOInterruptCB *interrupt_callback;
  135. char *user_agent; ///< holds HTTP user agent set as an AVOption to the HTTP protocol context
  136. char *cookies; ///< holds HTTP cookie values set in either the initial response or as an AVOption to the HTTP protocol context
  137. char *headers; ///< holds HTTP headers set as an AVOption to the HTTP protocol context
  138. } HLSContext;
  139. static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
  140. {
  141. int len = ff_get_line(s, buf, maxlen);
  142. while (len > 0 && av_isspace(buf[len - 1]))
  143. buf[--len] = '\0';
  144. return len;
  145. }
  146. static void free_segment_list(struct playlist *pls)
  147. {
  148. int i;
  149. for (i = 0; i < pls->n_segments; i++)
  150. av_free(pls->segments[i]);
  151. av_freep(&pls->segments);
  152. pls->n_segments = 0;
  153. }
  154. static void free_playlist_list(HLSContext *c)
  155. {
  156. int i;
  157. for (i = 0; i < c->n_playlists; i++) {
  158. struct playlist *pls = c->playlists[i];
  159. free_segment_list(pls);
  160. av_freep(&pls->renditions);
  161. av_free_packet(&pls->pkt);
  162. av_free(pls->pb.buffer);
  163. if (pls->input)
  164. ffurl_close(pls->input);
  165. if (pls->ctx) {
  166. pls->ctx->pb = NULL;
  167. avformat_close_input(&pls->ctx);
  168. }
  169. av_free(pls);
  170. }
  171. av_freep(&c->playlists);
  172. av_freep(&c->cookies);
  173. av_freep(&c->user_agent);
  174. c->n_playlists = 0;
  175. }
  176. static void free_variant_list(HLSContext *c)
  177. {
  178. int i;
  179. for (i = 0; i < c->n_variants; i++) {
  180. struct variant *var = c->variants[i];
  181. av_freep(&var->playlists);
  182. av_free(var);
  183. }
  184. av_freep(&c->variants);
  185. c->n_variants = 0;
  186. }
  187. static void free_rendition_list(HLSContext *c)
  188. {
  189. int i;
  190. for (i = 0; i < c->n_renditions; i++)
  191. av_free(c->renditions[i]);
  192. av_freep(&c->renditions);
  193. c->n_renditions = 0;
  194. }
  195. /*
  196. * Used to reset a statically allocated AVPacket to a clean slate,
  197. * containing no data.
  198. */
  199. static void reset_packet(AVPacket *pkt)
  200. {
  201. av_init_packet(pkt);
  202. pkt->data = NULL;
  203. }
  204. static struct playlist *new_playlist(HLSContext *c, const char *url,
  205. const char *base)
  206. {
  207. struct playlist *pls = av_mallocz(sizeof(struct playlist));
  208. if (!pls)
  209. return NULL;
  210. reset_packet(&pls->pkt);
  211. ff_make_absolute_url(pls->url, sizeof(pls->url), base, url);
  212. dynarray_add(&c->playlists, &c->n_playlists, pls);
  213. return pls;
  214. }
  215. struct variant_info {
  216. char bandwidth[20];
  217. /* variant group ids: */
  218. char audio[MAX_FIELD_LEN];
  219. char video[MAX_FIELD_LEN];
  220. char subtitles[MAX_FIELD_LEN];
  221. };
  222. static struct variant *new_variant(HLSContext *c, struct variant_info *info,
  223. const char *url, const char *base)
  224. {
  225. struct variant *var;
  226. struct playlist *pls;
  227. pls = new_playlist(c, url, base);
  228. if (!pls)
  229. return NULL;
  230. var = av_mallocz(sizeof(struct variant));
  231. if (!var)
  232. return NULL;
  233. if (info) {
  234. var->bandwidth = atoi(info->bandwidth);
  235. strcpy(var->audio_group, info->audio);
  236. strcpy(var->video_group, info->video);
  237. strcpy(var->subtitles_group, info->subtitles);
  238. }
  239. dynarray_add(&c->variants, &c->n_variants, var);
  240. dynarray_add(&var->playlists, &var->n_playlists, pls);
  241. return var;
  242. }
  243. static void handle_variant_args(struct variant_info *info, const char *key,
  244. int key_len, char **dest, int *dest_len)
  245. {
  246. if (!strncmp(key, "BANDWIDTH=", key_len)) {
  247. *dest = info->bandwidth;
  248. *dest_len = sizeof(info->bandwidth);
  249. } else if (!strncmp(key, "AUDIO=", key_len)) {
  250. *dest = info->audio;
  251. *dest_len = sizeof(info->audio);
  252. } else if (!strncmp(key, "VIDEO=", key_len)) {
  253. *dest = info->video;
  254. *dest_len = sizeof(info->video);
  255. } else if (!strncmp(key, "SUBTITLES=", key_len)) {
  256. *dest = info->subtitles;
  257. *dest_len = sizeof(info->subtitles);
  258. }
  259. }
  260. struct key_info {
  261. char uri[MAX_URL_SIZE];
  262. char method[10];
  263. char iv[35];
  264. };
  265. static void handle_key_args(struct key_info *info, const char *key,
  266. int key_len, char **dest, int *dest_len)
  267. {
  268. if (!strncmp(key, "METHOD=", key_len)) {
  269. *dest = info->method;
  270. *dest_len = sizeof(info->method);
  271. } else if (!strncmp(key, "URI=", key_len)) {
  272. *dest = info->uri;
  273. *dest_len = sizeof(info->uri);
  274. } else if (!strncmp(key, "IV=", key_len)) {
  275. *dest = info->iv;
  276. *dest_len = sizeof(info->iv);
  277. }
  278. }
  279. struct rendition_info {
  280. char type[16];
  281. char uri[MAX_URL_SIZE];
  282. char group_id[MAX_FIELD_LEN];
  283. char language[MAX_FIELD_LEN];
  284. char assoc_language[MAX_FIELD_LEN];
  285. char name[MAX_FIELD_LEN];
  286. char defaultr[4];
  287. char forced[4];
  288. char characteristics[MAX_CHARACTERISTICS_LEN];
  289. };
  290. static struct rendition *new_rendition(HLSContext *c, struct rendition_info *info,
  291. const char *url_base)
  292. {
  293. struct rendition *rend;
  294. enum AVMediaType type = AVMEDIA_TYPE_UNKNOWN;
  295. char *characteristic;
  296. char *chr_ptr;
  297. char *saveptr;
  298. if (!strcmp(info->type, "AUDIO"))
  299. type = AVMEDIA_TYPE_AUDIO;
  300. else if (!strcmp(info->type, "VIDEO"))
  301. type = AVMEDIA_TYPE_VIDEO;
  302. else if (!strcmp(info->type, "SUBTITLES"))
  303. type = AVMEDIA_TYPE_SUBTITLE;
  304. else if (!strcmp(info->type, "CLOSED-CAPTIONS"))
  305. /* CLOSED-CAPTIONS is ignored since we do not support CEA-608 CC in
  306. * AVC SEI RBSP anyway */
  307. return NULL;
  308. if (type == AVMEDIA_TYPE_UNKNOWN)
  309. return NULL;
  310. /* URI is mandatory for subtitles as per spec */
  311. if (type == AVMEDIA_TYPE_SUBTITLE && !info->uri[0])
  312. return NULL;
  313. /* TODO: handle subtitles (each segment has to parsed separately) */
  314. if (type == AVMEDIA_TYPE_SUBTITLE)
  315. return NULL;
  316. rend = av_mallocz(sizeof(struct rendition));
  317. if (!rend)
  318. return NULL;
  319. dynarray_add(&c->renditions, &c->n_renditions, rend);
  320. rend->type = type;
  321. strcpy(rend->group_id, info->group_id);
  322. strcpy(rend->language, info->language);
  323. strcpy(rend->name, info->name);
  324. /* add the playlist if this is an external rendition */
  325. if (info->uri[0]) {
  326. rend->playlist = new_playlist(c, info->uri, url_base);
  327. if (rend->playlist)
  328. dynarray_add(&rend->playlist->renditions,
  329. &rend->playlist->n_renditions, rend);
  330. }
  331. if (info->assoc_language[0]) {
  332. int langlen = strlen(rend->language);
  333. if (langlen < sizeof(rend->language) - 3) {
  334. rend->language[langlen] = ',';
  335. strncpy(rend->language + langlen + 1, info->assoc_language,
  336. sizeof(rend->language) - langlen - 2);
  337. }
  338. }
  339. if (!strcmp(info->defaultr, "YES"))
  340. rend->disposition |= AV_DISPOSITION_DEFAULT;
  341. if (!strcmp(info->forced, "YES"))
  342. rend->disposition |= AV_DISPOSITION_FORCED;
  343. chr_ptr = info->characteristics;
  344. while ((characteristic = av_strtok(chr_ptr, ",", &saveptr))) {
  345. if (!strcmp(characteristic, "public.accessibility.describes-music-and-sound"))
  346. rend->disposition |= AV_DISPOSITION_HEARING_IMPAIRED;
  347. else if (!strcmp(characteristic, "public.accessibility.describes-video"))
  348. rend->disposition |= AV_DISPOSITION_VISUAL_IMPAIRED;
  349. chr_ptr = NULL;
  350. }
  351. return rend;
  352. }
  353. static void handle_rendition_args(struct rendition_info *info, const char *key,
  354. int key_len, char **dest, int *dest_len)
  355. {
  356. if (!strncmp(key, "TYPE=", key_len)) {
  357. *dest = info->type;
  358. *dest_len = sizeof(info->type);
  359. } else if (!strncmp(key, "URI=", key_len)) {
  360. *dest = info->uri;
  361. *dest_len = sizeof(info->uri);
  362. } else if (!strncmp(key, "GROUP-ID=", key_len)) {
  363. *dest = info->group_id;
  364. *dest_len = sizeof(info->group_id);
  365. } else if (!strncmp(key, "LANGUAGE=", key_len)) {
  366. *dest = info->language;
  367. *dest_len = sizeof(info->language);
  368. } else if (!strncmp(key, "ASSOC-LANGUAGE=", key_len)) {
  369. *dest = info->assoc_language;
  370. *dest_len = sizeof(info->assoc_language);
  371. } else if (!strncmp(key, "NAME=", key_len)) {
  372. *dest = info->name;
  373. *dest_len = sizeof(info->name);
  374. } else if (!strncmp(key, "DEFAULT=", key_len)) {
  375. *dest = info->defaultr;
  376. *dest_len = sizeof(info->defaultr);
  377. } else if (!strncmp(key, "FORCED=", key_len)) {
  378. *dest = info->forced;
  379. *dest_len = sizeof(info->forced);
  380. } else if (!strncmp(key, "CHARACTERISTICS=", key_len)) {
  381. *dest = info->characteristics;
  382. *dest_len = sizeof(info->characteristics);
  383. }
  384. /*
  385. * ignored:
  386. * - AUTOSELECT: client may autoselect based on e.g. system language
  387. * - INSTREAM-ID: EIA-608 closed caption number ("CC1".."CC4")
  388. */
  389. }
  390. static int parse_playlist(HLSContext *c, const char *url,
  391. struct playlist *pls, AVIOContext *in)
  392. {
  393. int ret = 0, is_segment = 0, is_variant = 0;
  394. int64_t duration = 0;
  395. enum KeyType key_type = KEY_NONE;
  396. uint8_t iv[16] = "";
  397. int has_iv = 0;
  398. char key[MAX_URL_SIZE] = "";
  399. char line[MAX_URL_SIZE];
  400. const char *ptr;
  401. int close_in = 0;
  402. int64_t seg_offset = 0;
  403. int64_t seg_size = -1;
  404. uint8_t *new_url = NULL;
  405. struct variant_info variant_info;
  406. if (!in) {
  407. AVDictionary *opts = NULL;
  408. close_in = 1;
  409. /* Some HLS servers don't like being sent the range header */
  410. av_dict_set(&opts, "seekable", "0", 0);
  411. // broker prior HTTP options that should be consistent across requests
  412. av_dict_set(&opts, "user-agent", c->user_agent, 0);
  413. av_dict_set(&opts, "cookies", c->cookies, 0);
  414. av_dict_set(&opts, "headers", c->headers, 0);
  415. ret = avio_open2(&in, url, AVIO_FLAG_READ,
  416. c->interrupt_callback, &opts);
  417. av_dict_free(&opts);
  418. if (ret < 0)
  419. return ret;
  420. }
  421. if (av_opt_get(in, "location", AV_OPT_SEARCH_CHILDREN, &new_url) >= 0)
  422. url = new_url;
  423. read_chomp_line(in, line, sizeof(line));
  424. if (strcmp(line, "#EXTM3U")) {
  425. ret = AVERROR_INVALIDDATA;
  426. goto fail;
  427. }
  428. if (pls) {
  429. free_segment_list(pls);
  430. pls->finished = 0;
  431. }
  432. while (!url_feof(in)) {
  433. read_chomp_line(in, line, sizeof(line));
  434. if (av_strstart(line, "#EXT-X-STREAM-INF:", &ptr)) {
  435. is_variant = 1;
  436. memset(&variant_info, 0, sizeof(variant_info));
  437. ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_variant_args,
  438. &variant_info);
  439. } else if (av_strstart(line, "#EXT-X-KEY:", &ptr)) {
  440. struct key_info info = {{0}};
  441. ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_key_args,
  442. &info);
  443. key_type = KEY_NONE;
  444. has_iv = 0;
  445. if (!strcmp(info.method, "AES-128"))
  446. key_type = KEY_AES_128;
  447. if (!strncmp(info.iv, "0x", 2) || !strncmp(info.iv, "0X", 2)) {
  448. ff_hex_to_data(iv, info.iv + 2);
  449. has_iv = 1;
  450. }
  451. av_strlcpy(key, info.uri, sizeof(key));
  452. } else if (av_strstart(line, "#EXT-X-MEDIA:", &ptr)) {
  453. struct rendition_info info = {{0}};
  454. ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_rendition_args,
  455. &info);
  456. new_rendition(c, &info, url);
  457. } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {
  458. if (!pls) {
  459. if (!new_variant(c, NULL, url, NULL)) {
  460. ret = AVERROR(ENOMEM);
  461. goto fail;
  462. }
  463. pls = c->playlists[c->n_playlists - 1];
  464. }
  465. pls->target_duration = atoi(ptr) * AV_TIME_BASE;
  466. } else if (av_strstart(line, "#EXT-X-MEDIA-SEQUENCE:", &ptr)) {
  467. if (!pls) {
  468. if (!new_variant(c, NULL, url, NULL)) {
  469. ret = AVERROR(ENOMEM);
  470. goto fail;
  471. }
  472. pls = c->playlists[c->n_playlists - 1];
  473. }
  474. pls->start_seq_no = atoi(ptr);
  475. } else if (av_strstart(line, "#EXT-X-ENDLIST", &ptr)) {
  476. if (pls)
  477. pls->finished = 1;
  478. } else if (av_strstart(line, "#EXTINF:", &ptr)) {
  479. is_segment = 1;
  480. duration = atof(ptr) * AV_TIME_BASE;
  481. } else if (av_strstart(line, "#EXT-X-BYTERANGE:", &ptr)) {
  482. seg_size = atoi(ptr);
  483. ptr = strchr(ptr, '@');
  484. if (ptr)
  485. seg_offset = atoi(ptr+1);
  486. } else if (av_strstart(line, "#", NULL)) {
  487. continue;
  488. } else if (line[0]) {
  489. if (is_variant) {
  490. if (!new_variant(c, &variant_info, line, url)) {
  491. ret = AVERROR(ENOMEM);
  492. goto fail;
  493. }
  494. is_variant = 0;
  495. }
  496. if (is_segment) {
  497. struct segment *seg;
  498. if (!pls) {
  499. if (!new_variant(c, 0, url, NULL)) {
  500. ret = AVERROR(ENOMEM);
  501. goto fail;
  502. }
  503. pls = c->playlists[c->n_playlists - 1];
  504. }
  505. seg = av_malloc(sizeof(struct segment));
  506. if (!seg) {
  507. ret = AVERROR(ENOMEM);
  508. goto fail;
  509. }
  510. seg->duration = duration;
  511. seg->key_type = key_type;
  512. if (has_iv) {
  513. memcpy(seg->iv, iv, sizeof(iv));
  514. } else {
  515. int seq = pls->start_seq_no + pls->n_segments;
  516. memset(seg->iv, 0, sizeof(seg->iv));
  517. AV_WB32(seg->iv + 12, seq);
  518. }
  519. ff_make_absolute_url(seg->key, sizeof(seg->key), url, key);
  520. ff_make_absolute_url(seg->url, sizeof(seg->url), url, line);
  521. dynarray_add(&pls->segments, &pls->n_segments, seg);
  522. is_segment = 0;
  523. seg->size = seg_size;
  524. if (seg_size >= 0) {
  525. seg->url_offset = seg_offset;
  526. seg_offset += seg_size;
  527. seg_size = -1;
  528. } else {
  529. seg->url_offset = 0;
  530. seg_offset = 0;
  531. }
  532. }
  533. }
  534. }
  535. if (pls)
  536. pls->last_load_time = av_gettime();
  537. fail:
  538. av_free(new_url);
  539. if (close_in)
  540. avio_close(in);
  541. return ret;
  542. }
  543. static int open_input(HLSContext *c, struct playlist *pls)
  544. {
  545. AVDictionary *opts = NULL;
  546. AVDictionary *opts2 = NULL;
  547. int ret;
  548. struct segment *seg = pls->segments[pls->cur_seq_no - pls->start_seq_no];
  549. // broker prior HTTP options that should be consistent across requests
  550. av_dict_set(&opts, "user-agent", c->user_agent, 0);
  551. av_dict_set(&opts, "cookies", c->cookies, 0);
  552. av_dict_set(&opts, "headers", c->headers, 0);
  553. av_dict_set(&opts, "seekable", "0", 0);
  554. // Same opts for key request (ffurl_open mutilates the opts so it cannot be used twice)
  555. av_dict_copy(&opts2, opts, 0);
  556. if (seg->size >= 0) {
  557. /* try to restrict the HTTP request to the part we want
  558. * (if this is in fact a HTTP request) */
  559. char offset[24] = { 0 };
  560. char end_offset[24] = { 0 };
  561. snprintf(offset, sizeof(offset) - 1, "%"PRId64,
  562. seg->url_offset);
  563. snprintf(end_offset, sizeof(end_offset) - 1, "%"PRId64,
  564. seg->url_offset + seg->size);
  565. av_dict_set(&opts, "offset", offset, 0);
  566. av_dict_set(&opts, "end_offset", end_offset, 0);
  567. }
  568. av_log(pls->parent, AV_LOG_VERBOSE, "HLS request for url '%s', offset %"PRId64", playlist %d\n",
  569. seg->url, seg->url_offset, pls->index);
  570. if (seg->key_type == KEY_NONE) {
  571. ret = ffurl_open(&pls->input, seg->url, AVIO_FLAG_READ,
  572. &pls->parent->interrupt_callback, &opts);
  573. } else if (seg->key_type == KEY_AES_128) {
  574. char iv[33], key[33], url[MAX_URL_SIZE];
  575. if (strcmp(seg->key, pls->key_url)) {
  576. URLContext *uc;
  577. if (ffurl_open(&uc, seg->key, AVIO_FLAG_READ,
  578. &pls->parent->interrupt_callback, &opts2) == 0) {
  579. if (ffurl_read_complete(uc, pls->key, sizeof(pls->key))
  580. != sizeof(pls->key)) {
  581. av_log(NULL, AV_LOG_ERROR, "Unable to read key file %s\n",
  582. seg->key);
  583. }
  584. ffurl_close(uc);
  585. } else {
  586. av_log(NULL, AV_LOG_ERROR, "Unable to open key file %s\n",
  587. seg->key);
  588. }
  589. av_strlcpy(pls->key_url, seg->key, sizeof(pls->key_url));
  590. }
  591. ff_data_to_hex(iv, seg->iv, sizeof(seg->iv), 0);
  592. ff_data_to_hex(key, pls->key, sizeof(pls->key), 0);
  593. iv[32] = key[32] = '\0';
  594. if (strstr(seg->url, "://"))
  595. snprintf(url, sizeof(url), "crypto+%s", seg->url);
  596. else
  597. snprintf(url, sizeof(url), "crypto:%s", seg->url);
  598. if ((ret = ffurl_alloc(&pls->input, url, AVIO_FLAG_READ,
  599. &pls->parent->interrupt_callback)) < 0)
  600. goto cleanup;
  601. av_opt_set(pls->input->priv_data, "key", key, 0);
  602. av_opt_set(pls->input->priv_data, "iv", iv, 0);
  603. if ((ret = ffurl_connect(pls->input, &opts)) < 0) {
  604. ffurl_close(pls->input);
  605. pls->input = NULL;
  606. goto cleanup;
  607. }
  608. ret = 0;
  609. }
  610. else
  611. ret = AVERROR(ENOSYS);
  612. /* Seek to the requested position. If this was a HTTP request, the offset
  613. * should already be where want it to, but this allows e.g. local testing
  614. * without a HTTP server. */
  615. if (ret == 0) {
  616. int seekret = ffurl_seek(pls->input, seg->url_offset, SEEK_SET);
  617. if (seekret < 0) {
  618. av_log(pls->parent, AV_LOG_ERROR, "Unable to seek to offset %"PRId64" of HLS segment '%s'\n", seg->url_offset, seg->url);
  619. ret = seekret;
  620. ffurl_close(pls->input);
  621. pls->input = NULL;
  622. }
  623. }
  624. cleanup:
  625. av_dict_free(&opts);
  626. av_dict_free(&opts2);
  627. pls->cur_seg_offset = 0;
  628. return ret;
  629. }
  630. static int read_data(void *opaque, uint8_t *buf, int buf_size)
  631. {
  632. struct playlist *v = opaque;
  633. HLSContext *c = v->parent->priv_data;
  634. int ret, i;
  635. int actual_read_size;
  636. struct segment *seg;
  637. if (!v->needed)
  638. return AVERROR_EOF;
  639. restart:
  640. if (!v->input) {
  641. /* If this is a live stream and the reload interval has elapsed since
  642. * the last playlist reload, reload the playlists now. */
  643. int64_t reload_interval = v->n_segments > 0 ?
  644. v->segments[v->n_segments - 1]->duration :
  645. v->target_duration;
  646. reload:
  647. if (!v->finished &&
  648. av_gettime() - v->last_load_time >= reload_interval) {
  649. if ((ret = parse_playlist(c, v->url, v, NULL)) < 0) {
  650. av_log(v->parent, AV_LOG_WARNING, "Failed to reload playlist %d\n",
  651. v->index);
  652. return ret;
  653. }
  654. /* If we need to reload the playlist again below (if
  655. * there's still no more segments), switch to a reload
  656. * interval of half the target duration. */
  657. reload_interval = v->target_duration / 2;
  658. }
  659. if (v->cur_seq_no < v->start_seq_no) {
  660. av_log(NULL, AV_LOG_WARNING,
  661. "skipping %d segments ahead, expired from playlists\n",
  662. v->start_seq_no - v->cur_seq_no);
  663. v->cur_seq_no = v->start_seq_no;
  664. }
  665. if (v->cur_seq_no >= v->start_seq_no + v->n_segments) {
  666. if (v->finished)
  667. return AVERROR_EOF;
  668. while (av_gettime() - v->last_load_time < reload_interval) {
  669. if (ff_check_interrupt(c->interrupt_callback))
  670. return AVERROR_EXIT;
  671. av_usleep(100*1000);
  672. }
  673. /* Enough time has elapsed since the last reload */
  674. goto reload;
  675. }
  676. ret = open_input(c, v);
  677. if (ret < 0) {
  678. av_log(v->parent, AV_LOG_WARNING, "Failed to open segment of playlist %d\n",
  679. v->index);
  680. return ret;
  681. }
  682. }
  683. /* limit read if the segment was only a part of a file */
  684. seg = v->segments[v->cur_seq_no - v->start_seq_no];
  685. if (seg->size >= 0)
  686. actual_read_size = FFMIN(buf_size, seg->size - v->cur_seg_offset);
  687. else
  688. actual_read_size = buf_size;
  689. ret = ffurl_read(v->input, buf, actual_read_size);
  690. if (ret > 0) {
  691. v->cur_seg_offset += ret;
  692. return ret;
  693. }
  694. ffurl_close(v->input);
  695. v->input = NULL;
  696. v->cur_seq_no++;
  697. c->end_of_segment = 1;
  698. c->cur_seq_no = v->cur_seq_no;
  699. if (v->ctx && v->ctx->nb_streams &&
  700. v->parent->nb_streams >= v->stream_offset + v->ctx->nb_streams) {
  701. v->needed = 0;
  702. for (i = v->stream_offset; i < v->stream_offset + v->ctx->nb_streams;
  703. i++) {
  704. if (v->parent->streams[i]->discard < AVDISCARD_ALL)
  705. v->needed = 1;
  706. }
  707. }
  708. if (!v->needed) {
  709. av_log(v->parent, AV_LOG_INFO, "No longer receiving playlist %d\n",
  710. v->index);
  711. return AVERROR_EOF;
  712. }
  713. goto restart;
  714. }
  715. static int playlist_in_multiple_variants(HLSContext *c, struct playlist *pls)
  716. {
  717. int variant_count = 0;
  718. int i, j;
  719. for (i = 0; i < c->n_variants && variant_count < 2; i++) {
  720. struct variant *v = c->variants[i];
  721. for (j = 0; j < v->n_playlists; j++) {
  722. if (v->playlists[j] == pls) {
  723. variant_count++;
  724. break;
  725. }
  726. }
  727. }
  728. return variant_count >= 2;
  729. }
  730. static void add_renditions_to_variant(HLSContext *c, struct variant *var,
  731. enum AVMediaType type, const char *group_id)
  732. {
  733. int i;
  734. for (i = 0; i < c->n_renditions; i++) {
  735. struct rendition *rend = c->renditions[i];
  736. if (rend->type == type && !strcmp(rend->group_id, group_id)) {
  737. if (rend->playlist)
  738. /* rendition is an external playlist
  739. * => add the playlist to the variant */
  740. dynarray_add(&var->playlists, &var->n_playlists, rend->playlist);
  741. else
  742. /* rendition is part of the variant main Media Playlist
  743. * => add the rendition to the main Media Playlist */
  744. dynarray_add(&var->playlists[0]->renditions,
  745. &var->playlists[0]->n_renditions,
  746. rend);
  747. }
  748. }
  749. }
  750. static void add_metadata_from_renditions(AVFormatContext *s, struct playlist *pls,
  751. enum AVMediaType type)
  752. {
  753. int rend_idx = 0;
  754. int i;
  755. for (i = 0; i < pls->ctx->nb_streams; i++) {
  756. AVStream *st = s->streams[pls->stream_offset + i];
  757. if (st->codec->codec_type != type)
  758. continue;
  759. for (; rend_idx < pls->n_renditions; rend_idx++) {
  760. struct rendition *rend = pls->renditions[rend_idx];
  761. if (rend->type != type)
  762. continue;
  763. if (rend->language[0])
  764. av_dict_set(&st->metadata, "language", rend->language, 0);
  765. if (rend->name[0])
  766. av_dict_set(&st->metadata, "comment", rend->name, 0);
  767. st->disposition |= rend->disposition;
  768. }
  769. if (rend_idx >=pls->n_renditions)
  770. break;
  771. }
  772. }
  773. static int hls_read_header(AVFormatContext *s)
  774. {
  775. URLContext *u = (s->flags & AVFMT_FLAG_CUSTOM_IO) ? NULL : s->pb->opaque;
  776. HLSContext *c = s->priv_data;
  777. int ret = 0, i, j, stream_offset = 0;
  778. c->interrupt_callback = &s->interrupt_callback;
  779. // if the URL context is good, read important options we must broker later
  780. if (u && u->prot->priv_data_class) {
  781. // get the previous user agent & set back to null if string size is zero
  782. av_freep(&c->user_agent);
  783. av_opt_get(u->priv_data, "user-agent", 0, (uint8_t**)&(c->user_agent));
  784. if (c->user_agent && !strlen(c->user_agent))
  785. av_freep(&c->user_agent);
  786. // get the previous cookies & set back to null if string size is zero
  787. av_freep(&c->cookies);
  788. av_opt_get(u->priv_data, "cookies", 0, (uint8_t**)&(c->cookies));
  789. if (c->cookies && !strlen(c->cookies))
  790. av_freep(&c->cookies);
  791. // get the previous headers & set back to null if string size is zero
  792. av_freep(&c->headers);
  793. av_opt_get(u->priv_data, "headers", 0, (uint8_t**)&(c->headers));
  794. if (c->headers && !strlen(c->headers))
  795. av_freep(&c->headers);
  796. }
  797. if ((ret = parse_playlist(c, s->filename, NULL, s->pb)) < 0)
  798. goto fail;
  799. if (c->n_variants == 0) {
  800. av_log(NULL, AV_LOG_WARNING, "Empty playlist\n");
  801. ret = AVERROR_EOF;
  802. goto fail;
  803. }
  804. /* If the playlist only contained playlists (Master Playlist),
  805. * parse each individual playlist. */
  806. if (c->n_playlists > 1 || c->playlists[0]->n_segments == 0) {
  807. for (i = 0; i < c->n_playlists; i++) {
  808. struct playlist *pls = c->playlists[i];
  809. if ((ret = parse_playlist(c, pls->url, pls, NULL)) < 0)
  810. goto fail;
  811. }
  812. }
  813. if (c->variants[0]->playlists[0]->n_segments == 0) {
  814. av_log(NULL, AV_LOG_WARNING, "Empty playlist\n");
  815. ret = AVERROR_EOF;
  816. goto fail;
  817. }
  818. /* If this isn't a live stream, calculate the total duration of the
  819. * stream. */
  820. if (c->variants[0]->playlists[0]->finished) {
  821. int64_t duration = 0;
  822. for (i = 0; i < c->variants[0]->playlists[0]->n_segments; i++)
  823. duration += c->variants[0]->playlists[0]->segments[i]->duration;
  824. s->duration = duration;
  825. }
  826. /* Associate renditions with variants */
  827. for (i = 0; i < c->n_variants; i++) {
  828. struct variant *var = c->variants[i];
  829. if (var->audio_group[0])
  830. add_renditions_to_variant(c, var, AVMEDIA_TYPE_AUDIO, var->audio_group);
  831. if (var->video_group[0])
  832. add_renditions_to_variant(c, var, AVMEDIA_TYPE_VIDEO, var->video_group);
  833. if (var->subtitles_group[0])
  834. add_renditions_to_variant(c, var, AVMEDIA_TYPE_SUBTITLE, var->subtitles_group);
  835. }
  836. /* Open the demuxer for each playlist */
  837. for (i = 0; i < c->n_playlists; i++) {
  838. struct playlist *pls = c->playlists[i];
  839. AVInputFormat *in_fmt = NULL;
  840. if (pls->n_segments == 0)
  841. continue;
  842. if (!(pls->ctx = avformat_alloc_context())) {
  843. ret = AVERROR(ENOMEM);
  844. goto fail;
  845. }
  846. pls->index = i;
  847. pls->needed = 1;
  848. pls->parent = s;
  849. /* If this is a live stream with more than 3 segments, start at the
  850. * third last segment. */
  851. pls->cur_seq_no = pls->start_seq_no;
  852. if (!pls->finished && pls->n_segments > 3)
  853. pls->cur_seq_no = pls->start_seq_no + pls->n_segments - 3;
  854. pls->read_buffer = av_malloc(INITIAL_BUFFER_SIZE);
  855. ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls,
  856. read_data, NULL, NULL);
  857. pls->pb.seekable = 0;
  858. ret = av_probe_input_buffer(&pls->pb, &in_fmt, pls->segments[0]->url,
  859. NULL, 0, 0);
  860. if (ret < 0) {
  861. /* Free the ctx - it isn't initialized properly at this point,
  862. * so avformat_close_input shouldn't be called. If
  863. * avformat_open_input fails below, it frees and zeros the
  864. * context, so it doesn't need any special treatment like this. */
  865. av_log(s, AV_LOG_ERROR, "Error when loading first segment '%s'\n", pls->segments[0]->url);
  866. avformat_free_context(pls->ctx);
  867. pls->ctx = NULL;
  868. goto fail;
  869. }
  870. pls->ctx->pb = &pls->pb;
  871. pls->stream_offset = stream_offset;
  872. ret = avformat_open_input(&pls->ctx, pls->segments[0]->url, in_fmt, NULL);
  873. if (ret < 0)
  874. goto fail;
  875. pls->ctx->ctx_flags &= ~AVFMTCTX_NOHEADER;
  876. ret = avformat_find_stream_info(pls->ctx, NULL);
  877. if (ret < 0)
  878. goto fail;
  879. /* Create new AVStreams for each stream in this playlist */
  880. for (j = 0; j < pls->ctx->nb_streams; j++) {
  881. AVStream *st = avformat_new_stream(s, NULL);
  882. AVStream *ist = pls->ctx->streams[j];
  883. if (!st) {
  884. ret = AVERROR(ENOMEM);
  885. goto fail;
  886. }
  887. st->id = i;
  888. avpriv_set_pts_info(st, ist->pts_wrap_bits, ist->time_base.num, ist->time_base.den);
  889. avcodec_copy_context(st->codec, pls->ctx->streams[j]->codec);
  890. }
  891. add_metadata_from_renditions(s, pls, AVMEDIA_TYPE_AUDIO);
  892. add_metadata_from_renditions(s, pls, AVMEDIA_TYPE_VIDEO);
  893. add_metadata_from_renditions(s, pls, AVMEDIA_TYPE_SUBTITLE);
  894. stream_offset += pls->ctx->nb_streams;
  895. }
  896. /* Create a program for each variant */
  897. for (i = 0; i < c->n_variants; i++) {
  898. struct variant *v = c->variants[i];
  899. char bitrate_str[20];
  900. AVProgram *program;
  901. snprintf(bitrate_str, sizeof(bitrate_str), "%d", v->bandwidth);
  902. program = av_new_program(s, i);
  903. if (!program)
  904. goto fail;
  905. av_dict_set(&program->metadata, "variant_bitrate", bitrate_str, 0);
  906. for (j = 0; j < v->n_playlists; j++) {
  907. struct playlist *pls = v->playlists[j];
  908. int is_shared = playlist_in_multiple_variants(c, pls);
  909. int k;
  910. for (k = 0; k < pls->ctx->nb_streams; k++) {
  911. struct AVStream *st = s->streams[pls->stream_offset + k];
  912. ff_program_add_stream_index(s, i, pls->stream_offset + k);
  913. /* Set variant_bitrate for streams unique to this variant */
  914. if (!is_shared && v->bandwidth)
  915. av_dict_set(&st->metadata, "variant_bitrate", bitrate_str, 0);
  916. }
  917. }
  918. }
  919. c->first_packet = 1;
  920. c->first_timestamp = AV_NOPTS_VALUE;
  921. c->seek_timestamp = AV_NOPTS_VALUE;
  922. return 0;
  923. fail:
  924. free_playlist_list(c);
  925. free_variant_list(c);
  926. free_rendition_list(c);
  927. return ret;
  928. }
  929. static int recheck_discard_flags(AVFormatContext *s, int first)
  930. {
  931. HLSContext *c = s->priv_data;
  932. int i, changed = 0;
  933. /* Check if any new streams are needed */
  934. for (i = 0; i < c->n_playlists; i++)
  935. c->playlists[i]->cur_needed = 0;
  936. for (i = 0; i < s->nb_streams; i++) {
  937. AVStream *st = s->streams[i];
  938. struct playlist *pls = c->playlists[s->streams[i]->id];
  939. if (st->discard < AVDISCARD_ALL)
  940. pls->cur_needed = 1;
  941. }
  942. for (i = 0; i < c->n_playlists; i++) {
  943. struct playlist *pls = c->playlists[i];
  944. if (pls->cur_needed && !pls->needed) {
  945. pls->needed = 1;
  946. changed = 1;
  947. pls->cur_seq_no = c->cur_seq_no;
  948. pls->pb.eof_reached = 0;
  949. av_log(s, AV_LOG_INFO, "Now receiving playlist %d\n", i);
  950. } else if (first && !pls->cur_needed && pls->needed) {
  951. if (pls->input)
  952. ffurl_close(pls->input);
  953. pls->input = NULL;
  954. pls->needed = 0;
  955. changed = 1;
  956. av_log(s, AV_LOG_INFO, "No longer receiving playlist %d\n", i);
  957. }
  958. }
  959. return changed;
  960. }
  961. static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
  962. {
  963. HLSContext *c = s->priv_data;
  964. int ret, i, minplaylist = -1;
  965. if (c->first_packet) {
  966. recheck_discard_flags(s, 1);
  967. c->first_packet = 0;
  968. }
  969. start:
  970. c->end_of_segment = 0;
  971. for (i = 0; i < c->n_playlists; i++) {
  972. struct playlist *pls = c->playlists[i];
  973. /* Make sure we've got one buffered packet from each open playlist
  974. * stream */
  975. if (pls->needed && !pls->pkt.data) {
  976. while (1) {
  977. int64_t ts_diff;
  978. AVStream *st;
  979. ret = av_read_frame(pls->ctx, &pls->pkt);
  980. if (ret < 0) {
  981. if (!url_feof(&pls->pb) && ret != AVERROR_EOF)
  982. return ret;
  983. reset_packet(&pls->pkt);
  984. break;
  985. } else {
  986. if (c->first_timestamp == AV_NOPTS_VALUE &&
  987. pls->pkt.dts != AV_NOPTS_VALUE)
  988. c->first_timestamp = av_rescale_q(pls->pkt.dts,
  989. pls->ctx->streams[pls->pkt.stream_index]->time_base,
  990. AV_TIME_BASE_Q);
  991. }
  992. if (c->seek_timestamp == AV_NOPTS_VALUE)
  993. break;
  994. if (pls->pkt.dts == AV_NOPTS_VALUE) {
  995. c->seek_timestamp = AV_NOPTS_VALUE;
  996. break;
  997. }
  998. st = pls->ctx->streams[pls->pkt.stream_index];
  999. ts_diff = av_rescale_rnd(pls->pkt.dts, AV_TIME_BASE,
  1000. st->time_base.den, AV_ROUND_DOWN) -
  1001. c->seek_timestamp;
  1002. if (ts_diff >= 0 && (c->seek_flags & AVSEEK_FLAG_ANY ||
  1003. pls->pkt.flags & AV_PKT_FLAG_KEY)) {
  1004. c->seek_timestamp = AV_NOPTS_VALUE;
  1005. break;
  1006. }
  1007. av_free_packet(&pls->pkt);
  1008. reset_packet(&pls->pkt);
  1009. }
  1010. }
  1011. /* Check if this stream still is on an earlier segment number, or
  1012. * has the packet with the lowest dts */
  1013. if (pls->pkt.data) {
  1014. struct playlist *minpls = minplaylist < 0 ?
  1015. NULL : c->playlists[minplaylist];
  1016. if (minplaylist < 0 || pls->cur_seq_no < minpls->cur_seq_no) {
  1017. minplaylist = i;
  1018. } else if (pls->cur_seq_no == minpls->cur_seq_no) {
  1019. int64_t dts = pls->pkt.dts;
  1020. int64_t mindts = minpls->pkt.dts;
  1021. AVStream *st = pls->ctx->streams[pls->pkt.stream_index];
  1022. AVStream *minst = minpls->ctx->streams[minpls->pkt.stream_index];
  1023. if (dts == AV_NOPTS_VALUE) {
  1024. minplaylist = i;
  1025. } else if (mindts != AV_NOPTS_VALUE) {
  1026. if (st->start_time != AV_NOPTS_VALUE)
  1027. dts -= st->start_time;
  1028. if (minst->start_time != AV_NOPTS_VALUE)
  1029. mindts -= minst->start_time;
  1030. if (av_compare_ts(dts, st->time_base,
  1031. mindts, minst->time_base) < 0)
  1032. minplaylist = i;
  1033. }
  1034. }
  1035. }
  1036. }
  1037. if (c->end_of_segment) {
  1038. if (recheck_discard_flags(s, 0))
  1039. goto start;
  1040. }
  1041. /* If we got a packet, return it */
  1042. if (minplaylist >= 0) {
  1043. *pkt = c->playlists[minplaylist]->pkt;
  1044. pkt->stream_index += c->playlists[minplaylist]->stream_offset;
  1045. reset_packet(&c->playlists[minplaylist]->pkt);
  1046. return 0;
  1047. }
  1048. return AVERROR_EOF;
  1049. }
  1050. static int hls_close(AVFormatContext *s)
  1051. {
  1052. HLSContext *c = s->priv_data;
  1053. free_playlist_list(c);
  1054. free_variant_list(c);
  1055. free_rendition_list(c);
  1056. return 0;
  1057. }
  1058. static int hls_read_seek(AVFormatContext *s, int stream_index,
  1059. int64_t timestamp, int flags)
  1060. {
  1061. HLSContext *c = s->priv_data;
  1062. int i, j, ret;
  1063. if ((flags & AVSEEK_FLAG_BYTE) || !c->variants[0]->playlists[0]->finished)
  1064. return AVERROR(ENOSYS);
  1065. c->seek_flags = flags;
  1066. c->seek_timestamp = stream_index < 0 ? timestamp :
  1067. av_rescale_rnd(timestamp, AV_TIME_BASE,
  1068. s->streams[stream_index]->time_base.den,
  1069. flags & AVSEEK_FLAG_BACKWARD ?
  1070. AV_ROUND_DOWN : AV_ROUND_UP);
  1071. timestamp = av_rescale_rnd(timestamp, AV_TIME_BASE, stream_index >= 0 ?
  1072. s->streams[stream_index]->time_base.den :
  1073. AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ?
  1074. AV_ROUND_DOWN : AV_ROUND_UP);
  1075. if (s->duration < c->seek_timestamp) {
  1076. c->seek_timestamp = AV_NOPTS_VALUE;
  1077. return AVERROR(EIO);
  1078. }
  1079. ret = AVERROR(EIO);
  1080. for (i = 0; i < c->n_playlists; i++) {
  1081. /* Reset reading */
  1082. struct playlist *pls = c->playlists[i];
  1083. int64_t pos = c->first_timestamp == AV_NOPTS_VALUE ?
  1084. 0 : c->first_timestamp;
  1085. if (pls->input) {
  1086. ffurl_close(pls->input);
  1087. pls->input = NULL;
  1088. }
  1089. av_free_packet(&pls->pkt);
  1090. reset_packet(&pls->pkt);
  1091. pls->pb.eof_reached = 0;
  1092. /* Clear any buffered data */
  1093. pls->pb.buf_end = pls->pb.buf_ptr = pls->pb.buffer;
  1094. /* Reset the pos, to let the mpegts demuxer know we've seeked. */
  1095. pls->pb.pos = 0;
  1096. /* Locate the segment that contains the target timestamp */
  1097. for (j = 0; j < pls->n_segments; j++) {
  1098. if (timestamp >= pos &&
  1099. timestamp < pos + pls->segments[j]->duration) {
  1100. pls->cur_seq_no = pls->start_seq_no + j;
  1101. ret = 0;
  1102. break;
  1103. }
  1104. pos += pls->segments[j]->duration;
  1105. }
  1106. if (ret)
  1107. c->seek_timestamp = AV_NOPTS_VALUE;
  1108. }
  1109. return ret;
  1110. }
  1111. static int hls_probe(AVProbeData *p)
  1112. {
  1113. /* Require #EXTM3U at the start, and either one of the ones below
  1114. * somewhere for a proper match. */
  1115. if (strncmp(p->buf, "#EXTM3U", 7))
  1116. return 0;
  1117. if (strstr(p->buf, "#EXT-X-STREAM-INF:") ||
  1118. strstr(p->buf, "#EXT-X-TARGETDURATION:") ||
  1119. strstr(p->buf, "#EXT-X-MEDIA-SEQUENCE:"))
  1120. return AVPROBE_SCORE_MAX;
  1121. return 0;
  1122. }
  1123. AVInputFormat ff_hls_demuxer = {
  1124. .name = "hls,applehttp",
  1125. .long_name = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming"),
  1126. .priv_data_size = sizeof(HLSContext),
  1127. .read_probe = hls_probe,
  1128. .read_header = hls_read_header,
  1129. .read_packet = hls_read_packet,
  1130. .read_close = hls_close,
  1131. .read_seek = hls_read_seek,
  1132. };