| 1389 | } |
| 1390 | |
| 1391 | static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg, AVIOContext **in) |
| 1392 | { |
| 1393 | AVDictionary *opts = NULL; |
| 1394 | int ret; |
| 1395 | int is_http = 0; |
| 1396 | |
| 1397 | if (c->http_persistent) |
| 1398 | av_dict_set(&opts, "multiple_requests", "1", 0); |
| 1399 | |
| 1400 | if (seg->size >= 0) { |
| 1401 | /* try to restrict the HTTP request to the part we want |
| 1402 | * (if this is in fact a HTTP request) */ |
| 1403 | av_dict_set_int(&opts, "offset", seg->url_offset, 0); |
| 1404 | av_dict_set_int(&opts, "end_offset", seg->url_offset + seg->size, 0); |
| 1405 | } |
| 1406 | |
| 1407 | av_log(pls->parent, AV_LOG_VERBOSE, "HLS request for url '%s', offset %"PRId64", playlist %d\n", |
| 1408 | seg->url, seg->url_offset, pls->index); |
| 1409 | |
| 1410 | if (seg->key_type == KEY_AES_128 || seg->key_type == KEY_SAMPLE_AES) { |
| 1411 | if (strcmp(seg->key, pls->key_url)) { |
| 1412 | ret = read_key(c, pls, seg); |
| 1413 | if (ret < 0) |
| 1414 | goto cleanup; |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | if (seg->key_type == KEY_AES_128) { |
| 1419 | char iv[33], key[33], url[MAX_URL_SIZE]; |
| 1420 | ff_data_to_hex(iv, seg->iv, sizeof(seg->iv), 0); |
| 1421 | ff_data_to_hex(key, pls->key, sizeof(pls->key), 0); |
| 1422 | if (strstr(seg->url, "://")) |
| 1423 | snprintf(url, sizeof(url), "crypto+%s", seg->url); |
| 1424 | else |
| 1425 | snprintf(url, sizeof(url), "crypto:%s", seg->url); |
| 1426 | |
| 1427 | av_dict_set(&opts, "key", key, 0); |
| 1428 | av_dict_set(&opts, "iv", iv, 0); |
| 1429 | |
| 1430 | ret = open_url(pls->parent, in, url, &c->avio_opts, opts, &is_http); |
| 1431 | if (ret < 0) { |
| 1432 | goto cleanup; |
| 1433 | } |
| 1434 | ret = 0; |
| 1435 | } else { |
| 1436 | ret = open_url(pls->parent, in, seg->url, &c->avio_opts, opts, &is_http); |
| 1437 | } |
| 1438 | |
| 1439 | /* Seek to the requested position. If this was a HTTP request, the offset |
| 1440 | * should already be where want it to, but this allows e.g. local testing |
| 1441 | * without a HTTP server. |
| 1442 | * |
| 1443 | * This is not done for HTTP at all as avio_seek() does internal bookkeeping |
| 1444 | * of file offset which is out-of-sync with the actual offset when "offset" |
| 1445 | * AVOption is used with http protocol, causing the seek to not be a no-op |
| 1446 | * as would be expected. Wrong offset received from the server will not be |
| 1447 | * noticed without the call, though. |
| 1448 | */ |
no test coverage detected