@@ -537,6 +537,47 @@ static int do_send(Demuxer *d, DemuxStream *ds, AVPacket *pkt, unsigned flags,
return 0;
}
+static int demux_filter(Demuxer *d, DemuxThreadContext *dt, DemuxStream *ds,
+ AVBSFContext *bsf, AVPacket *pkt, void *logctx)
+{
+ int ret;
+
+ if (pkt)
+ av_packet_rescale_ts(pkt, pkt->time_base, bsf->time_base_in);
+
+ ret = av_bsf_send_packet(bsf, pkt);
+ if (ret < 0) {
+ if (pkt)
+ av_packet_unref(pkt);
+ av_log(logctx, AV_LOG_ERROR, "Error submitting a packet for filtering: %s\n",
+ av_err2str(ret));
+ return ret;
+ }
+
+ while (1) {
+ ret = av_bsf_receive_packet(bsf, dt->pkt_bsf);
+ if (ret == AVERROR(EAGAIN))
+ return 0;
+ else if (ret < 0) {
+ if (ret != AVERROR_EOF)
+ av_log(logctx, AV_LOG_ERROR,
+ "Error applying bitstream filters to a packet: %s\n",
+ av_err2str(ret));
+ break;
+ }
+
+ dt->pkt_bsf->time_base = bsf->time_base_out;
+
+ ret = do_send(d, ds, dt->pkt_bsf, 0, "filtered");
+ if (ret < 0) {
+ av_packet_unref(dt->pkt_bsf);
+ break;
+ }
+ }
+
+ return ret;
+}
+
static int demux_send(Demuxer *d, DemuxThreadContext *dt, DemuxStream *ds,
AVPacket *pkt, unsigned flags)
{
@@ -565,38 +606,9 @@ static int demux_send(Demuxer *d, DemuxThreadContext *dt, DemuxStream *ds,
}
if (ds->bsf) {
- if (pkt)
- av_packet_rescale_ts(pkt, pkt->time_base, ds->bsf->time_base_in);
-
- ret = av_bsf_send_packet(ds->bsf, pkt);
- if (ret < 0) {
- if (pkt)
- av_packet_unref(pkt);
- av_log(ds, AV_LOG_ERROR, "Error submitting a packet for filtering: %s\n",
- av_err2str(ret));
+ ret = demux_filter(d, dt, ds, ds->bsf, pkt, ds);
+ if (ret < 0)
return ret;
- }
-
- while (1) {
- ret = av_bsf_receive_packet(ds->bsf, dt->pkt_bsf);
- if (ret == AVERROR(EAGAIN))
- return 0;
- else if (ret < 0) {
- if (ret != AVERROR_EOF)
- av_log(ds, AV_LOG_ERROR,
- "Error applying bitstream filters to a packet: %s\n",
- av_err2str(ret));
- return ret;
- }
-
- dt->pkt_bsf->time_base = ds->bsf->time_base_out;
-
- ret = do_send(d, ds, dt->pkt_bsf, 0, "filtered");
- if (ret < 0) {
- av_packet_unref(dt->pkt_bsf);
- return ret;
- }
- }
} else {
ret = do_send(d, ds, pkt, flags, "demuxed");
if (ret < 0)
Will be needed by the following patch. Signed-off-by: James Almer <jamrial@gmail.com> --- fftools/ffmpeg_demux.c | 74 ++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 31 deletions(-)