summaryrefslogtreecommitdiffstats
path: root/filters/f_decoder_wrapper.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-01-28 10:08:45 +0100
committerKevin Mitchell <kevmitch@gmail.com>2018-01-30 03:10:27 -0800
commit6d36fad83c779936a012e85a1eb92ec94651c7c0 (patch)
tree76762208837d18545a4a315be890d7bffad7e47f /filters/f_decoder_wrapper.h
parenteaced0ebb03a078394ed01bcbe641b5b7a4312aa (diff)
downloadmpv-6d36fad83c779936a012e85a1eb92ec94651c7c0.tar.bz2
mpv-6d36fad83c779936a012e85a1eb92ec94651c7c0.tar.xz
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.
Diffstat (limited to 'filters/f_decoder_wrapper.h')
-rw-r--r--filters/f_decoder_wrapper.h104
1 files changed, 104 insertions, 0 deletions
diff --git a/filters/f_decoder_wrapper.h b/filters/f_decoder_wrapper.h
new file mode 100644
index 0000000000..4d970bd79a
--- /dev/null
+++ b/filters/f_decoder_wrapper.h
@@ -0,0 +1,104 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <stdbool.h>
+
+#include "filter.h"
+
+struct sh_stream;
+struct mp_codec_params;
+struct mp_image_params;
+struct mp_decoder_list;
+struct demux_packet;
+
+// (free with talloc_free(mp_decoder_wrapper.f)
+struct mp_decoder_wrapper {
+ // Filter with no input and 1 output, which returns the decoded data.
+ struct mp_filter *f;
+
+ // For informational purposes.
+ char *decoder_desc;
+
+ // Can be set by user.
+ struct mp_recorder_sink *recorder_sink;
+
+ // --- for STREAM_VIDEO
+
+ // FPS from demuxer or from user override
+ float fps;
+
+ // Framedrop control for playback (not used for hr seek etc.)
+ int attempt_framedrops; // try dropping this many frames
+ int dropped_frames; // total frames _probably_ dropped
+};
+
+// Create the decoder wrapper for the given stream, plus underlying decoder.
+// The src stream must be selected, and remain valid and selected until the
+// wrapper is destroyed.
+struct mp_decoder_wrapper *mp_decoder_wrapper_create(struct mp_filter *parent,
+ struct sh_stream *src);
+
+struct mp_decoder_list *video_decoder_list(void);
+
+// For precise seeking: if possible, try to drop frames up until the given PTS.
+// This is automatically unset if the target is reached, or on reset.
+void mp_decoder_wrapper_set_start_pts(struct mp_decoder_wrapper *d, double pts);
+
+enum dec_ctrl {
+ VDCTRL_FORCE_HWDEC_FALLBACK, // force software decoding fallback
+ VDCTRL_GET_HWDEC,
+ VDCTRL_REINIT,
+ VDCTRL_GET_BFRAMES,
+ // framedrop mode: 0=none, 1=standard, 2=hrseek
+ VDCTRL_SET_FRAMEDROP,
+};
+
+int mp_decoder_wrapper_control(struct mp_decoder_wrapper *d,
+ enum dec_ctrl cmd, void *arg);
+
+// Force it to reevaluate output parameters (for overrides like aspect).
+void mp_decoder_wrapper_reset_params(struct mp_decoder_wrapper *d);
+
+void mp_decoder_wrapper_get_video_dec_params(struct mp_decoder_wrapper *d,
+ struct mp_image_params *p);
+
+bool mp_decoder_wrapper_reinit(struct mp_decoder_wrapper *d);
+
+struct mp_decoder {
+ // Bidirectional filter; takes MP_FRAME_PACKET for input.
+ struct mp_filter *f;
+
+ // Can be set by decoder impl. on init for "special" functionality.
+ int (*control)(struct mp_filter *f, enum dec_ctrl cmd, void *arg);
+};
+
+struct mp_decoder_fns {
+ struct mp_decoder *(*create)(struct mp_filter *parent,
+ struct mp_codec_params *codec,
+ const char *decoder);
+ void (*add_decoders)(struct mp_decoder_list *list);
+};
+
+extern const struct mp_decoder_fns vd_lavc;
+
+// Convenience wrapper for lavc based decoders. eof_flag must be set to false
+// on init and resets.
+void lavc_process(struct mp_filter *f, bool *eof_flag,
+ bool (*send)(struct mp_filter *f, struct demux_packet *pkt),
+ bool (*receive)(struct mp_filter *f, struct mp_frame *res));