Unified · Split
| @@ -24,6 +24,8 @@ · 23 unmodified lines | ||
| 24 | 24 | #include "libavcodec/avfft.h" |
| 25 | 25 | #include "avfilter.h" |
| 26 | 26 | #include "audio.h" |
| 27 | +#include "filters.h" | |
| 28 | +#include "internal.h" | |
| 27 | 29 | #include "formats.h" |
| 28 | 30 | #include "window_func.h" |
| 29 | 31 | |
| @@ -90,6 +92,7 @@ typedef struct AudioSurroundContext { · 60 unmodified lines | ||
| 90 | 92 | float *window_func_lut; |
| 91 | 93 | |
| 92 | 94 | int64_t pts; |
| 95 | + int eof; | |
| 93 | 96 | |
| 94 | 97 | void (*filter)(AVFilterContext *ctx); |
| 95 | 98 | void (*upmix_stereo)(AVFilterContext *ctx, |
| @@ -1491,70 +1494,91 @@ static int ifft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) · 1395 unmodified lines | ||
| 1491 | 1494 | return 0; |
| 1492 | 1495 | } |
| 1493 | 1496 | |
| 1494 | −static int filter_frame(AVFilterLink *inlink, AVFrame *in) | |
| 1497 | +static int filter_frame(AVFilterLink *inlink) | |
| 1495 | 1498 | { |
| 1496 | 1499 | AVFilterContext *ctx = inlink->dst; |
| 1497 | 1500 | AVFilterLink *outlink = ctx->outputs[0]; |
| 1498 | 1501 | AudioSurroundContext *s = ctx->priv; |
| 1502 | + AVFrame *out; | |
| 1499 | 1503 | int ret; |
| 1500 | 1504 | |
| 1501 | − ret = av_audio_fifo_write(s->fifo, (void **)in->extended_data, | |
| 1502 | − in->nb_samples); | |
| 1503 | − if (ret >= 0 && s->pts == AV_NOPTS_VALUE) | |
| 1504 | − s->pts = in->pts; | |
| 1505 | − | |
| 1506 | − av_frame_free(&in); | |
| 1505 | + ret = av_audio_fifo_peek(s->fifo, (void **)s->input->extended_data, s->buf_size); | |
| 1507 | 1506 | if (ret < 0) |
| 1508 | 1507 | return ret; |
| 1509 | 1508 | |
| 1510 | − while (av_audio_fifo_size(s->fifo) >= s->buf_size) { | |
| 1511 | − AVFrame *out; | |
| 1509 | + ctx->internal->execute(ctx, fft_channel, NULL, NULL, inlink->channels); | |
| 1512 | 1510 | |
| 1513 | − ret = av_audio_fifo_peek(s->fifo, (void **)s->input->extended_data, s->buf_size); | |
| 1514 | − if (ret < 0) | |
| 1515 | − return ret; | |
| 1511 | + s->filter(ctx); | |
| 1516 | 1512 | |
| 1517 | − ctx->internal->execute(ctx, fft_channel, NULL, NULL, inlink->channels); | |
| 1513 | + out = ff_get_audio_buffer(outlink, s->hop_size); | |
| 1514 | + if (!out) | |
| 1515 | + return AVERROR(ENOMEM); | |
| 1518 | 1516 | |
| 1519 | − s->filter(ctx); | |
| 1517 | + ctx->internal->execute(ctx, ifft_channel, out, NULL, outlink->channels); | |
| 1520 | 1518 | |
| 1521 | − out = ff_get_audio_buffer(outlink, s->hop_size); | |
| 1522 | − if (!out) | |
| 1523 | − return AVERROR(ENOMEM); | |
| 1519 | + out->pts = s->pts; | |
| 1520 | + if (s->pts != AV_NOPTS_VALUE) | |
| 1521 | + s->pts += av_rescale_q(out->nb_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base); | |
| 1522 | + av_audio_fifo_drain(s->fifo, FFMIN(av_audio_fifo_size(s->fifo), s->hop_size)); | |
| 1524 | 1523 | |
| 1525 | − ctx->internal->execute(ctx, ifft_channel, out, NULL, outlink->channels); | |
| 1524 | + return ff_filter_frame(outlink, out); | |
| 1525 | +} | |
| 1526 | 1526 | |
| 1527 | − out->pts = s->pts; | |
| 1528 | − if (s->pts != AV_NOPTS_VALUE) | |
| 1529 | − s->pts += av_rescale_q(out->nb_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base); | |
| 1530 | − av_audio_fifo_drain(s->fifo, s->hop_size); | |
| 1531 | − ret = ff_filter_frame(outlink, out); | |
| 1527 | +static int activate(AVFilterContext *ctx) | |
| 1528 | +{ | |
| 1529 | + AVFilterLink *inlink = ctx->inputs[0]; | |
| 1530 | + AVFilterLink *outlink = ctx->outputs[0]; | |
| 1531 | + AudioSurroundContext *s = ctx->priv; | |
| 1532 | + AVFrame *in = NULL; | |
| 1533 | + int ret = 0, status; | |
| 1534 | + int64_t pts; | |
| 1535 | + | |
| 1536 | + FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); | |
| 1537 | + | |
| 1538 | + if (!s->eof && av_audio_fifo_size(s->fifo) < s->buf_size) { | |
| 1539 | + ret = ff_inlink_consume_frame(inlink, &in); | |
| 1532 | 1540 | if (ret < 0) |
| 1533 | 1541 | return ret; |
| 1534 | − } | |
| 1535 | 1542 | |
| 1536 | − return 0; | |
| 1537 | −} | |
| 1543 | + if (ret > 0) { | |
| 1544 | + ret = av_audio_fifo_write(s->fifo, (void **)in->extended_data, | |
| 1545 | + in->nb_samples); | |
| 1546 | + if (ret >= 0 && s->pts == AV_NOPTS_VALUE) | |
| 1547 | + s->pts = in->pts; | |
| 1538 | 1548 | |
| 1539 | −static int request_frame(AVFilterLink *outlink) | |
| 1540 | −{ | |
| 1541 | − AVFilterContext *ctx = outlink->src; | |
| 1542 | − AudioSurroundContext *s = ctx->priv; | |
| 1543 | − int ret = 0; | |
| 1549 | + av_frame_free(&in); | |
| 1550 | + if (ret < 0) | |
| 1551 | + return ret; | |
| 1552 | + } | |
| 1553 | + } | |
| 1544 | 1554 | |
| 1545 | − ret = ff_request_frame(ctx->inputs[0]); | |
| 1555 | + if ((av_audio_fifo_size(s->fifo) >= s->buf_size) || | |
| 1556 | + (av_audio_fifo_size(s->fifo) > 0 && s->eof)) { | |
| 1557 | + ret = filter_frame(inlink); | |
| 1558 | + if (av_audio_fifo_size(s->fifo) >= s->buf_size) | |
| 1559 | + ff_filter_set_ready(ctx, 100); | |
| 1560 | + return ret; | |
| 1561 | + } | |
| 1546 | 1562 | |
| 1547 | − if (ret == AVERROR_EOF && av_audio_fifo_size(s->fifo) > 0 && av_audio_fifo_size(s->fifo) < s->buf_size) { | |
| 1548 | − AVFrame *in; | |
| 1563 | + if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts)) { | |
| 1564 | + if (status == AVERROR_EOF) { | |
| 1565 | + s->eof = 1; | |
| 1566 | + if (av_audio_fifo_size(s->fifo) >= 0) { | |
| 1567 | + ff_filter_set_ready(ctx, 100); | |
| 1568 | + return 0; | |
| 1569 | + } | |
| 1570 | + } | |
| 1571 | + } | |
| 1549 | 1572 | |
| 1550 | − in = ff_get_audio_buffer(outlink, s->buf_size - av_audio_fifo_size(s->fifo)); | |
| 1551 | − if (!in) | |
| 1552 | − return AVERROR(ENOMEM); | |
| 1553 | − ret = filter_frame(ctx->inputs[0], in); | |
| 1554 | − av_audio_fifo_drain(s->fifo, s->buf_size); | |
| 1573 | + if (s->eof && av_audio_fifo_size(s->fifo) <= 0) { | |
| 1574 | + ff_outlink_set_status(outlink, AVERROR_EOF, s->pts); | |
| 1575 | + return 0; | |
| 1555 | 1576 | } |
| 1556 | 1577 | |
| 1557 | − return ret; | |
| 1578 | + if (!s->eof) | |
| 1579 | + FF_FILTER_FORWARD_WANTED(outlink, inlink); | |
| 1580 | + | |
| 1581 | + return FFERROR_NOT_READY; | |
| 1558 | 1582 | } |
| 1559 | 1583 | |
| 1560 | 1584 | static av_cold void uninit(AVFilterContext *ctx) |
| @@ -1649,7 +1673,6 @@ static const AVFilterPad inputs[] = { · 88 unmodified lines | ||
| 1649 | 1673 | { |
| 1650 | 1674 | .name = "default", |
| 1651 | 1675 | .type = AVMEDIA_TYPE_AUDIO, |
| 1652 | − .filter_frame = filter_frame, | |
| 1653 | 1676 | .config_props = config_input, |
| 1654 | 1677 | }, |
| 1655 | 1678 | { NULL } |
| @@ -1659,7 +1682,6 @@ static const AVFilterPad outputs[] = { · 3 unmodified lines | ||
| 1659 | 1682 | { |
| 1660 | 1683 | .name = "default", |
| 1661 | 1684 | .type = AVMEDIA_TYPE_AUDIO, |
| 1662 | − .request_frame = request_frame, | |
| 1663 | 1685 | .config_props = config_output, |
| 1664 | 1686 | }, |
| 1665 | 1687 | { NULL } |
| @@ -1673,6 +1695,7 @@ AVFilter ff_af_surround = { · 7 unmodified lines | ||
| 1673 | 1695 | .priv_class = &surround_class, |
| 1674 | 1696 | .init = init, |
| 1675 | 1697 | .uninit = uninit, |
| 1698 | + .activate = activate, | |
| 1676 | 1699 | .inputs = inputs, |
| 1677 | 1700 | .outputs = outputs, |
| 1678 | 1701 | .flags = AVFILTER_FLAG_SLICE_THREADS, |