video: make decoder wrapper a filter
Move dec_video.c to filters/f_decoder_wrapper.c. It essentially becomes
a source filter. vd.h mostly disappears, because mp_filter takes care of
the dataflow, but its remains are in struct mp_decoder_fns.
One goal is to simplify dataflow by letting the filter framework handle
it (or more accurately, using its conventions). One result is that the
decode calls disappear from video.c, because we simply connect the
decoder wrapper and the filter chain with mp_pin_connect().
Another goal is to eventually remove the code duplication between the
audio and video paths for this. This commit prepares for this by trying
to make f_decoder_wrapper.c extensible, so it can be used for audio as
well later.
Decoder framedropping changes a bit. It doesn't seem to be worse than
before, and it's an obscure feature, so I'm content with its new state.
Some special code that was apparently meant to avoid dropping too many
frames in a row is removed, though.
I'm not sure how the source code tree should be organized. For one,
video/decode/vd_lavc.c is the only file in its directory, which is a bit
annoying.
2018-01-28 09:08:45 +00:00
|
|
|
#include "common/common.h"
|
|
|
|
#include "demux/demux.h"
|
|
|
|
#include "demux/packet.h"
|
|
|
|
|
|
|
|
#include "f_demux_in.h"
|
|
|
|
#include "filter_internal.h"
|
|
|
|
|
|
|
|
struct priv {
|
|
|
|
struct sh_stream *src;
|
|
|
|
bool eof_returned;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void wakeup(void *ctx)
|
|
|
|
{
|
|
|
|
struct mp_filter *f = ctx;
|
|
|
|
|
|
|
|
mp_filter_wakeup(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void process(struct mp_filter *f)
|
|
|
|
{
|
|
|
|
struct priv *p = f->priv;
|
|
|
|
|
|
|
|
if (!mp_pin_in_needs_data(f->ppins[0]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
struct demux_packet *pkt = NULL;
|
|
|
|
if (demux_read_packet_async(p->src, &pkt) == 0)
|
|
|
|
return; // wait
|
|
|
|
|
|
|
|
struct mp_frame frame = {MP_FRAME_PACKET, pkt};
|
|
|
|
if (pkt) {
|
|
|
|
p->eof_returned = false;
|
|
|
|
} else {
|
|
|
|
frame.type = MP_FRAME_EOF;
|
|
|
|
|
|
|
|
// While the demuxer will repeat EOFs, filters never do that.
|
|
|
|
if (p->eof_returned)
|
|
|
|
return;
|
|
|
|
p->eof_returned = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_pin_in_write(f->ppins[0], frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reset(struct mp_filter *f)
|
|
|
|
{
|
|
|
|
struct priv *p = f->priv;
|
|
|
|
|
|
|
|
p->eof_returned = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy(struct mp_filter *f)
|
|
|
|
{
|
|
|
|
struct priv *p = f->priv;
|
|
|
|
|
|
|
|
demux_set_stream_wakeup_cb(p->src, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct mp_filter_info demux_filter = {
|
2018-02-04 19:01:09 +00:00
|
|
|
.name = "demux_in",
|
video: make decoder wrapper a filter
Move dec_video.c to filters/f_decoder_wrapper.c. It essentially becomes
a source filter. vd.h mostly disappears, because mp_filter takes care of
the dataflow, but its remains are in struct mp_decoder_fns.
One goal is to simplify dataflow by letting the filter framework handle
it (or more accurately, using its conventions). One result is that the
decode calls disappear from video.c, because we simply connect the
decoder wrapper and the filter chain with mp_pin_connect().
Another goal is to eventually remove the code duplication between the
audio and video paths for this. This commit prepares for this by trying
to make f_decoder_wrapper.c extensible, so it can be used for audio as
well later.
Decoder framedropping changes a bit. It doesn't seem to be worse than
before, and it's an obscure feature, so I'm content with its new state.
Some special code that was apparently meant to avoid dropping too many
frames in a row is removed, though.
I'm not sure how the source code tree should be organized. For one,
video/decode/vd_lavc.c is the only file in its directory, which is a bit
annoying.
2018-01-28 09:08:45 +00:00
|
|
|
.priv_size = sizeof(struct priv),
|
|
|
|
.process = process,
|
|
|
|
.reset = reset,
|
|
|
|
.destroy = destroy,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mp_filter *mp_demux_in_create(struct mp_filter *parent,
|
|
|
|
struct sh_stream *src)
|
|
|
|
{
|
|
|
|
struct mp_filter *f = mp_filter_create(parent, &demux_filter);
|
|
|
|
if (!f)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
struct priv *p = f->priv;
|
|
|
|
p->src = src;
|
|
|
|
|
|
|
|
mp_filter_add_pin(f, MP_PIN_OUT, "out");
|
|
|
|
|
|
|
|
demux_set_stream_wakeup_cb(p->src, wakeup, f);
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|