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 AppleHTTPContext {
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 } AppleHTTPContext;
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(AppleHTTPContext *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(AppleHTTPContext *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(AppleHTTPContext *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 AppleHTTPContext *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 applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
00449 {
00450 AppleHTTPContext *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 AppleHTTPContext *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 applehttp_read_packet(AVFormatContext *s, AVPacket *pkt)
00594 {
00595 AppleHTTPContext *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 ret = av_read_frame(var->ctx, &var->pkt);
00613 if (ret < 0) {
00614 if (!url_feof(&var->pb)) {
00615 return ret;
00616 } else {
00617 if ((var->cur_seq_no - var->start_seq_no) == (var->n_segments)) {
00618 return AVERROR_EOF;
00619 }
00620 }
00621 reset_packet(&var->pkt);
00622 } else {
00623 if (c->first_timestamp == AV_NOPTS_VALUE)
00624 c->first_timestamp = var->pkt.dts;
00625 }
00626
00627 if (c->seek_timestamp == AV_NOPTS_VALUE)
00628 break;
00629
00630 if (var->pkt.dts == AV_NOPTS_VALUE) {
00631 c->seek_timestamp = AV_NOPTS_VALUE;
00632 break;
00633 }
00634
00635 ts_diff = var->pkt.dts - c->seek_timestamp;
00636 if (ts_diff >= 0) {
00637 if (c->seek_flags & AVSEEK_FLAG_ANY) {
00638 c->seek_timestamp = AV_NOPTS_VALUE;
00639 break;
00640 }
00641
00642
00643 if (var->pkt.flags & AV_PKT_FLAG_KEY) {
00644 c->seek_timestamp = AV_NOPTS_VALUE;
00645 break;
00646 }
00647 }
00648 }
00649 }
00650
00651 if (var->pkt.data) {
00652 if (minvariant < 0 ||
00653 var->pkt.dts < c->variants[minvariant]->pkt.dts)
00654 minvariant = i;
00655 }
00656 }
00657 if (c->end_of_segment) {
00658 if (recheck_discard_flags(s, 0))
00659 goto start;
00660 }
00661
00662 if (minvariant >= 0) {
00663 *pkt = c->variants[minvariant]->pkt;
00664 pkt->stream_index += c->variants[minvariant]->stream_offset;
00665 reset_packet(&c->variants[minvariant]->pkt);
00666 return 0;
00667 }
00668 return AVERROR_EOF;
00669 }
00670
00671 static int applehttp_close(AVFormatContext *s)
00672 {
00673 AppleHTTPContext *c = s->priv_data;
00674
00675 free_variant_list(c);
00676 return 0;
00677 }
00678
00679 static int applehttp_read_seek(AVFormatContext *s, int stream_index,
00680 int64_t timestamp, int flags)
00681 {
00682 AppleHTTPContext *c = s->priv_data;
00683 int i, j, ret;
00684
00685 if ((flags & AVSEEK_FLAG_BYTE) || !c->variants[0]->finished)
00686 return AVERROR(ENOSYS);
00687
00688 c->seek_timestamp = timestamp;
00689 c->seek_flags = flags;
00690 timestamp = av_rescale_rnd(timestamp, 1, stream_index >= 0 ?
00691 s->streams[stream_index]->time_base.den :
00692 AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ?
00693 AV_ROUND_DOWN : AV_ROUND_UP);
00694 if (s->duration < c->seek_timestamp) {
00695 c->seek_timestamp = AV_NOPTS_VALUE;
00696 return AVERROR(EIO);
00697 }
00698
00699 ret = AVERROR(EIO);
00700 for (i = 0; i < c->n_variants; i++) {
00701
00702 struct variant *var = c->variants[i];
00703 int64_t pos = c->first_timestamp == AV_NOPTS_VALUE ? 0 :
00704 av_rescale_rnd(c->first_timestamp, 1, stream_index >= 0 ?
00705 s->streams[stream_index]->time_base.den :
00706 AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ?
00707 AV_ROUND_DOWN : AV_ROUND_UP);
00708 if (var->input) {
00709 ffurl_close(var->input);
00710 var->input = NULL;
00711 }
00712 av_free_packet(&var->pkt);
00713 reset_packet(&var->pkt);
00714 var->pb.eof_reached = 0;
00715
00716
00717 for (j = 0; j < var->n_segments; j++) {
00718 if (timestamp >= pos &&
00719 timestamp < pos + var->segments[j]->duration) {
00720 var->cur_seq_no = var->start_seq_no + j;
00721 ret = 0;
00722 break;
00723 }
00724 pos += var->segments[j]->duration;
00725 }
00726 if (ret != 0)
00727 c->seek_timestamp = AV_NOPTS_VALUE;
00728 }
00729 return ret;
00730 }
00731
00732 static int applehttp_probe(AVProbeData *p)
00733 {
00734
00735
00736 if (strncmp(p->buf, "#EXTM3U", 7))
00737 return 0;
00738 if (strstr(p->buf, "#EXT-X-STREAM-INF:") ||
00739 strstr(p->buf, "#EXT-X-TARGETDURATION:") ||
00740 strstr(p->buf, "#EXT-X-MEDIA-SEQUENCE:"))
00741 return AVPROBE_SCORE_MAX;
00742 return 0;
00743 }
00744
00745 AVInputFormat ff_applehttp_demuxer = {
00746 .name = "applehttp",
00747 .long_name = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming format"),
00748 .priv_data_size = sizeof(AppleHTTPContext),
00749 .read_probe = applehttp_probe,
00750 .read_header = applehttp_read_header,
00751 .read_packet = applehttp_read_packet,
00752 .read_close = applehttp_close,
00753 .read_seek = applehttp_read_seek,
00754 };