00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00028 #include "libavutil/avstring.h"
00029 #include "libavutil/intreadwrite.h"
00030 #include "libavutil/mathematics.h"
00031 #include "libavutil/opt.h"
00032 #include "libavutil/dict.h"
00033 #include "avformat.h"
00034 #include "internal.h"
00035 #include <unistd.h>
00036 #include "avio_internal.h"
00037 #include "url.h"
00038
00039 #define INITIAL_BUFFER_SIZE 32768
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 enum KeyType {
00054 KEY_NONE,
00055 KEY_AES_128,
00056 };
00057
00058 struct segment {
00059 int duration;
00060 char url[MAX_URL_SIZE];
00061 char key[MAX_URL_SIZE];
00062 enum KeyType key_type;
00063 uint8_t iv[16];
00064 };
00065
00066
00067
00068
00069
00070
00071 struct variant {
00072 int bandwidth;
00073 char url[MAX_URL_SIZE];
00074 AVIOContext pb;
00075 uint8_t* read_buffer;
00076 URLContext *input;
00077 AVFormatContext *parent;
00078 int index;
00079 AVFormatContext *ctx;
00080 AVPacket pkt;
00081 int stream_offset;
00082
00083 int finished;
00084 int target_duration;
00085 int start_seq_no;
00086 int n_segments;
00087 struct segment **segments;
00088 int needed, cur_needed;
00089 int cur_seq_no;
00090 int64_t last_load_time;
00091
00092 char key_url[MAX_URL_SIZE];
00093 uint8_t key[16];
00094 };
00095
00096 typedef struct HLSContext {
00097 int n_variants;
00098 struct variant **variants;
00099 int cur_seq_no;
00100 int end_of_segment;
00101 int first_packet;
00102 int64_t first_timestamp;
00103 int64_t seek_timestamp;
00104 int seek_flags;
00105 AVIOInterruptCB *interrupt_callback;
00106 } HLSContext;
00107
00108 static int read_chomp_line(AVIOContext *s, char *buf, int maxlen)
00109 {
00110 int len = ff_get_line(s, buf, maxlen);
00111 while (len > 0 && isspace(buf[len - 1]))
00112 buf[--len] = '\0';
00113 return len;
00114 }
00115
00116 static void free_segment_list(struct variant *var)
00117 {
00118 int i;
00119 for (i = 0; i < var->n_segments; i++)
00120 av_free(var->segments[i]);
00121 av_freep(&var->segments);
00122 var->n_segments = 0;
00123 }
00124
00125 static void free_variant_list(HLSContext *c)
00126 {
00127 int i;
00128 for (i = 0; i < c->n_variants; i++) {
00129 struct variant *var = c->variants[i];
00130 free_segment_list(var);
00131 av_free_packet(&var->pkt);
00132 av_free(var->pb.buffer);
00133 if (var->input)
00134 ffurl_close(var->input);
00135 if (var->ctx) {
00136 var->ctx->pb = NULL;
00137 avformat_close_input(&var->ctx);
00138 }
00139 av_free(var);
00140 }
00141 av_freep(&c->variants);
00142 c->n_variants = 0;
00143 }
00144
00145
00146
00147
00148
00149 static void reset_packet(AVPacket *pkt)
00150 {
00151 av_init_packet(pkt);
00152 pkt->data = NULL;
00153 }
00154
00155 static struct variant *new_variant(HLSContext *c, int bandwidth,
00156 const char *url, const char *base)
00157 {
00158 struct variant *var = av_mallocz(sizeof(struct variant));
00159 if (!var)
00160 return NULL;
00161 reset_packet(&var->pkt);
00162 var->bandwidth = bandwidth;
00163 ff_make_absolute_url(var->url, sizeof(var->url), base, url);
00164 dynarray_add(&c->variants, &c->n_variants, var);
00165 return var;
00166 }
00167
00168 struct variant_info {
00169 char bandwidth[20];
00170 };
00171
00172 static void handle_variant_args(struct variant_info *info, const char *key,
00173 int key_len, char **dest, int *dest_len)
00174 {
00175 if (!strncmp(key, "BANDWIDTH=", key_len)) {
00176 *dest = info->bandwidth;
00177 *dest_len = sizeof(info->bandwidth);
00178 }
00179 }
00180
00181 struct key_info {
00182 char uri[MAX_URL_SIZE];
00183 char method[10];
00184 char iv[35];
00185 };
00186
00187 static void handle_key_args(struct key_info *info, const char *key,
00188 int key_len, char **dest, int *dest_len)
00189 {
00190 if (!strncmp(key, "METHOD=", key_len)) {
00191 *dest = info->method;
00192 *dest_len = sizeof(info->method);
00193 } else if (!strncmp(key, "URI=", key_len)) {
00194 *dest = info->uri;
00195 *dest_len = sizeof(info->uri);
00196 } else if (!strncmp(key, "IV=", key_len)) {
00197 *dest = info->iv;
00198 *dest_len = sizeof(info->iv);
00199 }
00200 }
00201
00202 static int parse_playlist(HLSContext *c, const char *url,
00203 struct variant *var, AVIOContext *in)
00204 {
00205 int ret = 0, duration = 0, is_segment = 0, is_variant = 0, bandwidth = 0;
00206 enum KeyType key_type = KEY_NONE;
00207 uint8_t iv[16] = "";
00208 int has_iv = 0;
00209 char key[MAX_URL_SIZE] = "";
00210 char line[1024];
00211 const char *ptr;
00212 int close_in = 0;
00213
00214 if (!in) {
00215 close_in = 1;
00216 if ((ret = avio_open2(&in, url, AVIO_FLAG_READ,
00217 c->interrupt_callback, NULL)) < 0)
00218 return ret;
00219 }
00220
00221 read_chomp_line(in, line, sizeof(line));
00222 if (strcmp(line, "#EXTM3U")) {
00223 ret = AVERROR_INVALIDDATA;
00224 goto fail;
00225 }
00226
00227 if (var) {
00228 free_segment_list(var);
00229 var->finished = 0;
00230 }
00231 while (!url_feof(in)) {
00232 read_chomp_line(in, line, sizeof(line));
00233 if (av_strstart(line, "#EXT-X-STREAM-INF:", &ptr)) {
00234 struct variant_info info = {{0}};
00235 is_variant = 1;
00236 ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_variant_args,
00237 &info);
00238 bandwidth = atoi(info.bandwidth);
00239 } else if (av_strstart(line, "#EXT-X-KEY:", &ptr)) {
00240 struct key_info info = {{0}};
00241 ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_key_args,
00242 &info);
00243 key_type = KEY_NONE;
00244 has_iv = 0;
00245 if (!strcmp(info.method, "AES-128"))
00246 key_type = KEY_AES_128;
00247 if (!strncmp(info.iv, "0x", 2) || !strncmp(info.iv, "0X", 2)) {
00248 ff_hex_to_data(iv, info.iv + 2);
00249 has_iv = 1;
00250 }
00251 av_strlcpy(key, info.uri, sizeof(key));
00252 } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {
00253 if (!var) {
00254 var = new_variant(c, 0, url, NULL);
00255 if (!var) {
00256 ret = AVERROR(ENOMEM);
00257 goto fail;
00258 }
00259 }
00260 var->target_duration = atoi(ptr);
00261 } else if (av_strstart(line, "#EXT-X-MEDIA-SEQUENCE:", &ptr)) {
00262 if (!var) {
00263 var = new_variant(c, 0, url, NULL);
00264 if (!var) {
00265 ret = AVERROR(ENOMEM);
00266 goto fail;
00267 }
00268 }
00269 var->start_seq_no = atoi(ptr);
00270 } else if (av_strstart(line, "#EXT-X-ENDLIST", &ptr)) {
00271 if (var)
00272 var->finished = 1;
00273 } else if (av_strstart(line, "#EXTINF:", &ptr)) {
00274 is_segment = 1;
00275 duration = atoi(ptr);
00276 } else if (av_strstart(line, "#", NULL)) {
00277 continue;
00278 } else if (line[0]) {
00279 if (is_variant) {
00280 if (!new_variant(c, bandwidth, line, url)) {
00281 ret = AVERROR(ENOMEM);
00282 goto fail;
00283 }
00284 is_variant = 0;
00285 bandwidth = 0;
00286 }
00287 if (is_segment) {
00288 struct segment *seg;
00289 if (!var) {
00290 var = new_variant(c, 0, url, NULL);
00291 if (!var) {
00292 ret = AVERROR(ENOMEM);
00293 goto fail;
00294 }
00295 }
00296 seg = av_malloc(sizeof(struct segment));
00297 if (!seg) {
00298 ret = AVERROR(ENOMEM);
00299 goto fail;
00300 }
00301 seg->duration = duration;
00302 seg->key_type = key_type;
00303 if (has_iv) {
00304 memcpy(seg->iv, iv, sizeof(iv));
00305 } else {
00306 int seq = var->start_seq_no + var->n_segments;
00307 memset(seg->iv, 0, sizeof(seg->iv));
00308 AV_WB32(seg->iv + 12, seq);
00309 }
00310 ff_make_absolute_url(seg->key, sizeof(seg->key), url, key);
00311 ff_make_absolute_url(seg->url, sizeof(seg->url), url, line);
00312 dynarray_add(&var->segments, &var->n_segments, seg);
00313 is_segment = 0;
00314 }
00315 }
00316 }
00317 if (var)
00318 var->last_load_time = av_gettime();
00319
00320 fail:
00321 if (close_in)
00322 avio_close(in);
00323 return ret;
00324 }
00325
00326 static int open_input(struct variant *var)
00327 {
00328 struct segment *seg = var->segments[var->cur_seq_no - var->start_seq_no];
00329 if (seg->key_type == KEY_NONE) {
00330 return ffurl_open(&var->input, seg->url, AVIO_FLAG_READ,
00331 &var->parent->interrupt_callback, NULL);
00332 } else if (seg->key_type == KEY_AES_128) {
00333 char iv[33], key[33], url[MAX_URL_SIZE];
00334 int ret;
00335 if (strcmp(seg->key, var->key_url)) {
00336 URLContext *uc;
00337 if (ffurl_open(&uc, seg->key, AVIO_FLAG_READ,
00338 &var->parent->interrupt_callback, NULL) == 0) {
00339 if (ffurl_read_complete(uc, var->key, sizeof(var->key))
00340 != sizeof(var->key)) {
00341 av_log(NULL, AV_LOG_ERROR, "Unable to read key file %s\n",
00342 seg->key);
00343 }
00344 ffurl_close(uc);
00345 } else {
00346 av_log(NULL, AV_LOG_ERROR, "Unable to open key file %s\n",
00347 seg->key);
00348 }
00349 av_strlcpy(var->key_url, seg->key, sizeof(var->key_url));
00350 }
00351 ff_data_to_hex(iv, seg->iv, sizeof(seg->iv), 0);
00352 ff_data_to_hex(key, var->key, sizeof(var->key), 0);
00353 iv[32] = key[32] = '\0';
00354 if (strstr(seg->url, "://"))
00355 snprintf(url, sizeof(url), "crypto+%s", seg->url);
00356 else
00357 snprintf(url, sizeof(url), "crypto:%s", seg->url);
00358 if ((ret = ffurl_alloc(&var->input, url, AVIO_FLAG_READ,
00359 &var->parent->interrupt_callback)) < 0)
00360 return ret;
00361 av_opt_set(var->input->priv_data, "key", key, 0);
00362 av_opt_set(var->input->priv_data, "iv", iv, 0);
00363 if ((ret = ffurl_connect(var->input, NULL)) < 0) {
00364 ffurl_close(var->input);
00365 var->input = NULL;
00366 return ret;
00367 }
00368 return 0;
00369 }
00370 return AVERROR(ENOSYS);
00371 }
00372
00373 static int read_data(void *opaque, uint8_t *buf, int buf_size)
00374 {
00375 struct variant *v = opaque;
00376 HLSContext *c = v->parent->priv_data;
00377 int ret, i;
00378
00379 restart:
00380 if (!v->input) {
00381
00382
00383 int64_t reload_interval = v->n_segments > 0 ?
00384 v->segments[v->n_segments - 1]->duration :
00385 v->target_duration;
00386 reload_interval *= 1000000;
00387
00388 reload:
00389 if (!v->finished &&
00390 av_gettime() - v->last_load_time >= reload_interval) {
00391 if ((ret = parse_playlist(c, v->url, v, NULL)) < 0)
00392 return ret;
00393
00394
00395
00396 reload_interval = v->target_duration * 500000;
00397 }
00398 if (v->cur_seq_no < v->start_seq_no) {
00399 av_log(NULL, AV_LOG_WARNING,
00400 "skipping %d segments ahead, expired from playlists\n",
00401 v->start_seq_no - v->cur_seq_no);
00402 v->cur_seq_no = v->start_seq_no;
00403 }
00404 if (v->cur_seq_no >= v->start_seq_no + v->n_segments) {
00405 if (v->finished)
00406 return AVERROR_EOF;
00407 while (av_gettime() - v->last_load_time < reload_interval) {
00408 if (ff_check_interrupt(c->interrupt_callback))
00409 return AVERROR_EXIT;
00410 usleep(100*1000);
00411 }
00412
00413 goto reload;
00414 }
00415
00416 ret = open_input(v);
00417 if (ret < 0)
00418 return ret;
00419 }
00420 ret = ffurl_read(v->input, buf, buf_size);
00421 if (ret > 0)
00422 return ret;
00423 if (ret < 0 && ret != AVERROR_EOF)
00424 return ret;
00425 ffurl_close(v->input);
00426 v->input = NULL;
00427 v->cur_seq_no++;
00428
00429 c->end_of_segment = 1;
00430 c->cur_seq_no = v->cur_seq_no;
00431
00432 if (v->ctx && v->ctx->nb_streams) {
00433 v->needed = 0;
00434 for (i = v->stream_offset; i < v->stream_offset + v->ctx->nb_streams;
00435 i++) {
00436 if (v->parent->streams[i]->discard < AVDISCARD_ALL)
00437 v->needed = 1;
00438 }
00439 }
00440 if (!v->needed) {
00441 av_log(v->parent, AV_LOG_INFO, "No longer receiving variant %d\n",
00442 v->index);
00443 return AVERROR_EOF;
00444 }
00445 goto restart;
00446 }
00447
00448 static int hls_read_header(AVFormatContext *s)
00449 {
00450 HLSContext *c = s->priv_data;
00451 int ret = 0, i, j, stream_offset = 0;
00452
00453 c->interrupt_callback = &s->interrupt_callback;
00454
00455 if ((ret = parse_playlist(c, s->filename, NULL, s->pb)) < 0)
00456 goto fail;
00457
00458 if (c->n_variants == 0) {
00459 av_log(NULL, AV_LOG_WARNING, "Empty playlist\n");
00460 ret = AVERROR_EOF;
00461 goto fail;
00462 }
00463
00464
00465 if (c->n_variants > 1 || c->variants[0]->n_segments == 0) {
00466 for (i = 0; i < c->n_variants; i++) {
00467 struct variant *v = c->variants[i];
00468 if ((ret = parse_playlist(c, v->url, v, NULL)) < 0)
00469 goto fail;
00470 }
00471 }
00472
00473 if (c->variants[0]->n_segments == 0) {
00474 av_log(NULL, AV_LOG_WARNING, "Empty playlist\n");
00475 ret = AVERROR_EOF;
00476 goto fail;
00477 }
00478
00479
00480
00481 if (c->variants[0]->finished) {
00482 int64_t duration = 0;
00483 for (i = 0; i < c->variants[0]->n_segments; i++)
00484 duration += c->variants[0]->segments[i]->duration;
00485 s->duration = duration * AV_TIME_BASE;
00486 }
00487
00488
00489 for (i = 0; i < c->n_variants; i++) {
00490 struct variant *v = c->variants[i];
00491 AVInputFormat *in_fmt = NULL;
00492 char bitrate_str[20];
00493 if (v->n_segments == 0)
00494 continue;
00495
00496 if (!(v->ctx = avformat_alloc_context())) {
00497 ret = AVERROR(ENOMEM);
00498 goto fail;
00499 }
00500
00501 v->index = i;
00502 v->needed = 1;
00503 v->parent = s;
00504
00505
00506
00507 v->cur_seq_no = v->start_seq_no;
00508 if (!v->finished && v->n_segments > 3)
00509 v->cur_seq_no = v->start_seq_no + v->n_segments - 3;
00510
00511 v->read_buffer = av_malloc(INITIAL_BUFFER_SIZE);
00512 ffio_init_context(&v->pb, v->read_buffer, INITIAL_BUFFER_SIZE, 0, v,
00513 read_data, NULL, NULL);
00514 v->pb.seekable = 0;
00515 ret = av_probe_input_buffer(&v->pb, &in_fmt, v->segments[0]->url,
00516 NULL, 0, 0);
00517 if (ret < 0) {
00518
00519
00520
00521
00522 avformat_free_context(v->ctx);
00523 v->ctx = NULL;
00524 goto fail;
00525 }
00526 v->ctx->pb = &v->pb;
00527 ret = avformat_open_input(&v->ctx, v->segments[0]->url, in_fmt, NULL);
00528 if (ret < 0)
00529 goto fail;
00530 v->stream_offset = stream_offset;
00531 snprintf(bitrate_str, sizeof(bitrate_str), "%d", v->bandwidth);
00532
00533 for (j = 0; j < v->ctx->nb_streams; j++) {
00534 AVStream *st = avformat_new_stream(s, NULL);
00535 if (!st) {
00536 ret = AVERROR(ENOMEM);
00537 goto fail;
00538 }
00539 st->id = i;
00540 avcodec_copy_context(st->codec, v->ctx->streams[j]->codec);
00541 if (v->bandwidth)
00542 av_dict_set(&st->metadata, "variant_bitrate", bitrate_str,
00543 0);
00544 }
00545 stream_offset += v->ctx->nb_streams;
00546 }
00547
00548 c->first_packet = 1;
00549 c->first_timestamp = AV_NOPTS_VALUE;
00550 c->seek_timestamp = AV_NOPTS_VALUE;
00551
00552 return 0;
00553 fail:
00554 free_variant_list(c);
00555 return ret;
00556 }
00557
00558 static int recheck_discard_flags(AVFormatContext *s, int first)
00559 {
00560 HLSContext *c = s->priv_data;
00561 int i, changed = 0;
00562
00563
00564 for (i = 0; i < c->n_variants; i++)
00565 c->variants[i]->cur_needed = 0;
00566
00567 for (i = 0; i < s->nb_streams; i++) {
00568 AVStream *st = s->streams[i];
00569 struct variant *var = c->variants[s->streams[i]->id];
00570 if (st->discard < AVDISCARD_ALL)
00571 var->cur_needed = 1;
00572 }
00573 for (i = 0; i < c->n_variants; i++) {
00574 struct variant *v = c->variants[i];
00575 if (v->cur_needed && !v->needed) {
00576 v->needed = 1;
00577 changed = 1;
00578 v->cur_seq_no = c->cur_seq_no;
00579 v->pb.eof_reached = 0;
00580 av_log(s, AV_LOG_INFO, "Now receiving variant %d\n", i);
00581 } else if (first && !v->cur_needed && v->needed) {
00582 if (v->input)
00583 ffurl_close(v->input);
00584 v->input = NULL;
00585 v->needed = 0;
00586 changed = 1;
00587 av_log(s, AV_LOG_INFO, "No longer receiving variant %d\n", i);
00588 }
00589 }
00590 return changed;
00591 }
00592
00593 static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
00594 {
00595 HLSContext *c = s->priv_data;
00596 int ret, i, minvariant = -1;
00597
00598 if (c->first_packet) {
00599 recheck_discard_flags(s, 1);
00600 c->first_packet = 0;
00601 }
00602
00603 start:
00604 c->end_of_segment = 0;
00605 for (i = 0; i < c->n_variants; i++) {
00606 struct variant *var = c->variants[i];
00607
00608
00609 if (var->needed && !var->pkt.data) {
00610 while (1) {
00611 int64_t ts_diff;
00612 AVStream *st;
00613 ret = av_read_frame(var->ctx, &var->pkt);
00614 if (ret < 0) {
00615 if (!url_feof(&var->pb))
00616 return ret;
00617 reset_packet(&var->pkt);
00618 break;
00619 } else {
00620 if (c->first_timestamp == AV_NOPTS_VALUE)
00621 c->first_timestamp = var->pkt.dts;
00622 }
00623
00624 if (c->seek_timestamp == AV_NOPTS_VALUE)
00625 break;
00626
00627 if (var->pkt.dts == AV_NOPTS_VALUE) {
00628 c->seek_timestamp = AV_NOPTS_VALUE;
00629 break;
00630 }
00631
00632 st = var->ctx->streams[var->pkt.stream_index];
00633 ts_diff = av_rescale_rnd(var->pkt.dts, AV_TIME_BASE,
00634 st->time_base.den, AV_ROUND_DOWN) -
00635 c->seek_timestamp;
00636 if (ts_diff >= 0 && (c->seek_flags & AVSEEK_FLAG_ANY ||
00637 var->pkt.flags & AV_PKT_FLAG_KEY)) {
00638 c->seek_timestamp = AV_NOPTS_VALUE;
00639 break;
00640 }
00641 }
00642 }
00643
00644 if (var->pkt.data) {
00645 if (minvariant < 0 ||
00646 var->pkt.dts < c->variants[minvariant]->pkt.dts)
00647 minvariant = i;
00648 }
00649 }
00650 if (c->end_of_segment) {
00651 if (recheck_discard_flags(s, 0))
00652 goto start;
00653 }
00654
00655 if (minvariant >= 0) {
00656 *pkt = c->variants[minvariant]->pkt;
00657 pkt->stream_index += c->variants[minvariant]->stream_offset;
00658 reset_packet(&c->variants[minvariant]->pkt);
00659 return 0;
00660 }
00661 return AVERROR_EOF;
00662 }
00663
00664 static int hls_close(AVFormatContext *s)
00665 {
00666 HLSContext *c = s->priv_data;
00667
00668 free_variant_list(c);
00669 return 0;
00670 }
00671
00672 static int hls_read_seek(AVFormatContext *s, int stream_index,
00673 int64_t timestamp, int flags)
00674 {
00675 HLSContext *c = s->priv_data;
00676 int i, j, ret;
00677
00678 if ((flags & AVSEEK_FLAG_BYTE) || !c->variants[0]->finished)
00679 return AVERROR(ENOSYS);
00680
00681 c->seek_flags = flags;
00682 c->seek_timestamp = stream_index < 0 ? timestamp :
00683 av_rescale_rnd(timestamp, AV_TIME_BASE,
00684 s->streams[stream_index]->time_base.den,
00685 flags & AVSEEK_FLAG_BACKWARD ?
00686 AV_ROUND_DOWN : AV_ROUND_UP);
00687 timestamp = av_rescale_rnd(timestamp, 1, stream_index >= 0 ?
00688 s->streams[stream_index]->time_base.den :
00689 AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ?
00690 AV_ROUND_DOWN : AV_ROUND_UP);
00691 if (s->duration < c->seek_timestamp) {
00692 c->seek_timestamp = AV_NOPTS_VALUE;
00693 return AVERROR(EIO);
00694 }
00695
00696 ret = AVERROR(EIO);
00697 for (i = 0; i < c->n_variants; i++) {
00698
00699 struct variant *var = c->variants[i];
00700 int64_t pos = c->first_timestamp == AV_NOPTS_VALUE ? 0 :
00701 av_rescale_rnd(c->first_timestamp, 1, stream_index >= 0 ?
00702 s->streams[stream_index]->time_base.den :
00703 AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ?
00704 AV_ROUND_DOWN : AV_ROUND_UP);
00705 if (var->input) {
00706 ffurl_close(var->input);
00707 var->input = NULL;
00708 }
00709 av_free_packet(&var->pkt);
00710 reset_packet(&var->pkt);
00711 var->pb.eof_reached = 0;
00712
00713 var->pb.buf_end = var->pb.buf_ptr = var->pb.buffer;
00714
00715 var->pb.pos = 0;
00716
00717
00718 for (j = 0; j < var->n_segments; j++) {
00719 if (timestamp >= pos &&
00720 timestamp < pos + var->segments[j]->duration) {
00721 var->cur_seq_no = var->start_seq_no + j;
00722 ret = 0;
00723 break;
00724 }
00725 pos += var->segments[j]->duration;
00726 }
00727 if (ret)
00728 c->seek_timestamp = AV_NOPTS_VALUE;
00729 }
00730 return ret;
00731 }
00732
00733 static int hls_probe(AVProbeData *p)
00734 {
00735
00736
00737 if (strncmp(p->buf, "#EXTM3U", 7))
00738 return 0;
00739 if (strstr(p->buf, "#EXT-X-STREAM-INF:") ||
00740 strstr(p->buf, "#EXT-X-TARGETDURATION:") ||
00741 strstr(p->buf, "#EXT-X-MEDIA-SEQUENCE:"))
00742 return AVPROBE_SCORE_MAX;
00743 return 0;
00744 }
00745
00746 AVInputFormat ff_hls_demuxer = {
00747 .name = "hls,applehttp",
00748 .long_name = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming format"),
00749 .priv_data_size = sizeof(HLSContext),
00750 .read_probe = hls_probe,
00751 .read_header = hls_read_header,
00752 .read_packet = hls_read_packet,
00753 .read_close = hls_close,
00754 .read_seek = hls_read_seek,
00755 };