Unified · Split
| @@ -1336,6 +1336,37 @@ static void intercept_id3(struct playlist *pls, uint8_t *buf, · 1335 unmodified lines | ||
| 1336 | 1336 | pls->is_id3_timestamped = (pls->id3_mpegts_timestamp != AV_NOPTS_VALUE); |
| 1337 | 1337 | } |
| 1338 | 1338 | |
| 1339 | +static int read_key(HLSContext *c, struct playlist *pls, struct segment *seg) | |
| 1340 | +{ | |
| 1341 | + AVIOContext *pb = NULL; | |
| 1342 | + | |
| 1343 | + int ret = open_url(pls->parent, &pb, seg->key, &c->avio_opts, NULL, NULL); | |
| 1344 | + if (ret < 0) { | |
| 1345 | + av_log(pls->parent, AV_LOG_ERROR, "Unable to open key file %s, %s\n", | |
| 1346 | + seg->key, av_err2str(ret)); | |
| 1347 | + return ret; | |
| 1348 | + } | |
| 1349 | + | |
| 1350 | + ret = avio_read(pb, pls->key, sizeof(pls->key)); | |
| 1351 | + ff_format_io_close(pls->parent, &pb); | |
| 1352 | + if (ret != sizeof(pls->key)) { | |
| 1353 | + if (ret < 0) { | |
| 1354 | + av_log(pls->parent, AV_LOG_ERROR, "Unable to read key file %s, %s\n", | |
| 1355 | + seg->key, av_err2str(ret)); | |
| 1356 | + } else { | |
| 1357 | + av_log(pls->parent, AV_LOG_ERROR, "Unable to read key file %s, read bytes %d != %zu\n", | |
| 1358 | + seg->key, ret, sizeof(pls->key)); | |
| 1359 | + ret = AVERROR_INVALIDDATA; | |
| 1360 | + } | |
| 1361 | + | |
| 1362 | + return ret; | |
| 1363 | + } | |
| 1364 | + | |
| 1365 | + av_strlcpy(pls->key_url, seg->key, sizeof(pls->key_url)); | |
| 1366 | + | |
| 1367 | + return 0; | |
| 1368 | +} | |
| 1369 | + | |
| 1339 | 1370 | static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg, AVIOContext **in) |
| 1340 | 1371 | { |
| 1341 | 1372 | AVDictionary *opts = NULL; |
| @@ -1357,19 +1388,9 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg, · 15 unmodified lines | ||
| 1357 | 1388 | |
| 1358 | 1389 | if (seg->key_type == KEY_AES_128 || seg->key_type == KEY_SAMPLE_AES) { |
| 1359 | 1390 | if (strcmp(seg->key, pls->key_url)) { |
| 1360 | − AVIOContext *pb = NULL; | |
| 1361 | − if (open_url(pls->parent, &pb, seg->key, &c->avio_opts, NULL, NULL) == 0) { | |
| 1362 | − ret = avio_read(pb, pls->key, sizeof(pls->key)); | |
| 1363 | − if (ret != sizeof(pls->key)) { | |
| 1364 | − av_log(pls->parent, AV_LOG_ERROR, "Unable to read key file %s\n", | |
| 1365 | − seg->key); | |
| 1366 | − } | |
| 1367 | − ff_format_io_close(pls->parent, &pb); | |
| 1368 | − } else { | |
| 1369 | − av_log(pls->parent, AV_LOG_ERROR, "Unable to open key file %s\n", | |
| 1370 | − seg->key); | |
| 1371 | − } | |
| 1372 | − av_strlcpy(pls->key_url, seg->key, sizeof(pls->key_url)); | |
| 1391 | + ret = read_key(c, pls, seg); | |
| 1392 | + if (ret < 0) | |
| 1393 | + goto cleanup; | |
| 1373 | 1394 | } |
| 1374 | 1395 | } |
| 1375 | 1396 | |