Will be useful in following commits.
Unified · Split
| @@ -1303,11 +1303,65 @@ static void schedule_update_locked(Scheduler *sch) · 1302 unmodified lines | ||
| 1303 | 1303 | |
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | −int sch_start(Scheduler *sch) | |
| 1306 | +static int start_prepare(Scheduler *sch) | |
| 1307 | 1307 | { |
| 1308 | 1308 | int ret; |
| 1309 | 1309 | |
| 1310 | − sch->transcode_started = 1; | |
| 1310 | + for (unsigned i = 0; i < sch->nb_demux; i++) { | |
| 1311 | + SchDemux *d = &sch->demux[i]; | |
| 1312 | + | |
| 1313 | + for (unsigned j = 0; j < d->nb_streams; j++) { | |
| 1314 | + SchDemuxStream *ds = &d->streams[j]; | |
| 1315 | + | |
| 1316 | + if (!ds->nb_dst) { | |
| 1317 | + av_log(d, AV_LOG_ERROR, | |
| 1318 | + "Demuxer stream %u not connected to any sink\n", j); | |
| 1319 | + return AVERROR(EINVAL); | |
| 1320 | + } | |
| 1321 | + | |
| 1322 | + ds->dst_finished = av_calloc(ds->nb_dst, sizeof(*ds->dst_finished)); | |
| 1323 | + if (!ds->dst_finished) | |
| 1324 | + return AVERROR(ENOMEM); | |
| 1325 | + } | |
| 1326 | + } | |
| 1327 | + | |
| 1328 | + for (unsigned i = 0; i < sch->nb_dec; i++) { | |
| 1329 | + SchDec *dec = &sch->dec[i]; | |
| 1330 | + | |
| 1331 | + if (!dec->src.type) { | |
| 1332 | + av_log(dec, AV_LOG_ERROR, | |
| 1333 | + "Decoder not connected to a source\n"); | |
| 1334 | + return AVERROR(EINVAL); | |
| 1335 | + } | |
| 1336 | + if (!dec->nb_dst) { | |
| 1337 | + av_log(dec, AV_LOG_ERROR, | |
| 1338 | + "Decoder not connected to any sink\n"); | |
| 1339 | + return AVERROR(EINVAL); | |
| 1340 | + } | |
| 1341 | + | |
| 1342 | + dec->dst_finished = av_calloc(dec->nb_dst, sizeof(*dec->dst_finished)); | |
| 1343 | + if (!dec->dst_finished) | |
| 1344 | + return AVERROR(ENOMEM); | |
| 1345 | + } | |
| 1346 | + | |
| 1347 | + for (unsigned i = 0; i < sch->nb_enc; i++) { | |
| 1348 | + SchEnc *enc = &sch->enc[i]; | |
| 1349 | + | |
| 1350 | + if (!enc->src.type) { | |
| 1351 | + av_log(enc, AV_LOG_ERROR, | |
| 1352 | + "Encoder not connected to a source\n"); | |
| 1353 | + return AVERROR(EINVAL); | |
| 1354 | + } | |
| 1355 | + if (!enc->nb_dst) { | |
| 1356 | + av_log(enc, AV_LOG_ERROR, | |
| 1357 | + "Encoder not connected to any sink\n"); | |
| 1358 | + return AVERROR(EINVAL); | |
| 1359 | + } | |
| 1360 | + | |
| 1361 | + enc->dst_finished = av_calloc(enc->nb_dst, sizeof(*enc->dst_finished)); | |
| 1362 | + if (!enc->dst_finished) | |
| 1363 | + return AVERROR(ENOMEM); | |
| 1364 | + } | |
| 1311 | 1365 | |
| 1312 | 1366 | for (unsigned i = 0; i < sch->nb_mux; i++) { |
| 1313 | 1367 | SchMux *mux = &sch->mux[i]; |
| @@ -1341,35 +1395,6 @@ int sch_start(Scheduler *sch) · 27 unmodified lines | ||
| 1341 | 1395 | QUEUE_PACKETS); |
| 1342 | 1396 | if (ret < 0) |
| 1343 | 1397 | return ret; |
| 1344 | − | |
| 1345 | − if (mux->nb_streams_ready == mux->nb_streams) { | |
| 1346 | − ret = mux_init(sch, mux); | |
| 1347 | − if (ret < 0) | |
| 1348 | − return ret; | |
| 1349 | − } | |
| 1350 | − } | |
| 1351 | − | |
| 1352 | − for (unsigned i = 0; i < sch->nb_enc; i++) { | |
| 1353 | − SchEnc *enc = &sch->enc[i]; | |
| 1354 | − | |
| 1355 | − if (!enc->src.type) { | |
| 1356 | − av_log(enc, AV_LOG_ERROR, | |
| 1357 | − "Encoder not connected to a source\n"); | |
| 1358 | − return AVERROR(EINVAL); | |
| 1359 | − } | |
| 1360 | − if (!enc->nb_dst) { | |
| 1361 | − av_log(enc, AV_LOG_ERROR, | |
| 1362 | − "Encoder not connected to any sink\n"); | |
| 1363 | − return AVERROR(EINVAL); | |
| 1364 | − } | |
| 1365 | − | |
| 1366 | − enc->dst_finished = av_calloc(enc->nb_dst, sizeof(*enc->dst_finished)); | |
| 1367 | − if (!enc->dst_finished) | |
| 1368 | − return AVERROR(ENOMEM); | |
| 1369 | − | |
| 1370 | − ret = task_start(&enc->task); | |
| 1371 | − if (ret < 0) | |
| 1372 | − return ret; | |
| 1373 | 1398 | } |
| 1374 | 1399 | |
| 1375 | 1400 | for (unsigned i = 0; i < sch->nb_filters; i++) { |
| @@ -1396,6 +1421,41 @@ int sch_start(Scheduler *sch) · 20 unmodified lines | ||
| 1396 | 1421 | return AVERROR(EINVAL); |
| 1397 | 1422 | } |
| 1398 | 1423 | } |
| 1424 | + } | |
| 1425 | + | |
| 1426 | + return 0; | |
| 1427 | +} | |
| 1428 | + | |
| 1429 | +int sch_start(Scheduler *sch) | |
| 1430 | +{ | |
| 1431 | + int ret; | |
| 1432 | + | |
| 1433 | + ret = start_prepare(sch); | |
| 1434 | + if (ret < 0) | |
| 1435 | + return ret; | |
| 1436 | + | |
| 1437 | + sch->transcode_started = 1; | |
| 1438 | + | |
| 1439 | + for (unsigned i = 0; i < sch->nb_mux; i++) { | |
| 1440 | + SchMux *mux = &sch->mux[i]; | |
| 1441 | + | |
| 1442 | + if (mux->nb_streams_ready == mux->nb_streams) { | |
| 1443 | + ret = mux_init(sch, mux); | |
| 1444 | + if (ret < 0) | |
| 1445 | + return ret; | |
| 1446 | + } | |
| 1447 | + } | |
| 1448 | + | |
| 1449 | + for (unsigned i = 0; i < sch->nb_enc; i++) { | |
| 1450 | + SchEnc *enc = &sch->enc[i]; | |
| 1451 | + | |
| 1452 | + ret = task_start(&enc->task); | |
| 1453 | + if (ret < 0) | |
| 1454 | + return ret; | |
| 1455 | + } | |
| 1456 | + | |
| 1457 | + for (unsigned i = 0; i < sch->nb_filters; i++) { | |
| 1458 | + SchFilterGraph *fg = &sch->filters[i]; | |
| 1399 | 1459 | |
| 1400 | 1460 | ret = task_start(&fg->task); |
| 1401 | 1461 | if (ret < 0) |
| @@ -1405,21 +1465,6 @@ int sch_start(Scheduler *sch) · 3 unmodified lines | ||
| 1405 | 1465 | for (unsigned i = 0; i < sch->nb_dec; i++) { |
| 1406 | 1466 | SchDec *dec = &sch->dec[i]; |
| 1407 | 1467 | |
| 1408 | − if (!dec->src.type) { | |
| 1409 | − av_log(dec, AV_LOG_ERROR, | |
| 1410 | − "Decoder not connected to a source\n"); | |
| 1411 | − return AVERROR(EINVAL); | |
| 1412 | − } | |
| 1413 | − if (!dec->nb_dst) { | |
| 1414 | − av_log(dec, AV_LOG_ERROR, | |
| 1415 | − "Decoder not connected to any sink\n"); | |
| 1416 | − return AVERROR(EINVAL); | |
| 1417 | − } | |
| 1418 | − | |
| 1419 | − dec->dst_finished = av_calloc(dec->nb_dst, sizeof(*dec->dst_finished)); | |
| 1420 | − if (!dec->dst_finished) | |
| 1421 | − return AVERROR(ENOMEM); | |
| 1422 | − | |
| 1423 | 1468 | ret = task_start(&dec->task); |
| 1424 | 1469 | if (ret < 0) |
| 1425 | 1470 | return ret; |
| @@ -1431,20 +1476,6 @@ int sch_start(Scheduler *sch) · 5 unmodified lines | ||
| 1431 | 1476 | if (!d->nb_streams) |
| 1432 | 1477 | continue; |
| 1433 | 1478 | |
| 1434 | − for (unsigned j = 0; j < d->nb_streams; j++) { | |
| 1435 | − SchDemuxStream *ds = &d->streams[j]; | |
| 1436 | − | |
| 1437 | − if (!ds->nb_dst) { | |
| 1438 | − av_log(d, AV_LOG_ERROR, | |
| 1439 | − "Demuxer stream %u not connected to any sink\n", j); | |
| 1440 | − return AVERROR(EINVAL); | |
| 1441 | − } | |
| 1442 | − | |
| 1443 | − ds->dst_finished = av_calloc(ds->nb_dst, sizeof(*ds->dst_finished)); | |
| 1444 | − if (!ds->dst_finished) | |
| 1445 | − return AVERROR(ENOMEM); | |
| 1446 | − } | |
| 1447 | − | |
| 1448 | 1479 | ret = task_start(&d->task); |
| 1449 | 1480 | if (ret < 0) |
| 1450 | 1481 | return ret; |