1 /* 2 * This file is part of mpv. 3 * 4 * mpv is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * mpv is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with mpv. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #pragma once 19 20 #include <stdbool.h> 21 22 #include "filter.h" 23 24 struct sh_stream; 25 struct mp_codec_params; 26 struct mp_image_params; 27 struct mp_decoder_list; 28 struct demux_packet; 29 30 // (free with talloc_free(mp_decoder_wrapper.f) 31 struct mp_decoder_wrapper { 32 // Filter with no input and 1 output, which returns the decoded data. 33 struct mp_filter *f; 34 35 // Can be set by user. 36 struct mp_recorder_sink *recorder_sink; 37 }; 38 39 // Create the decoder wrapper for the given stream, plus underlying decoder. 40 // The src stream must be selected, and remain valid and selected until the 41 // wrapper is destroyed. 42 struct mp_decoder_wrapper *mp_decoder_wrapper_create(struct mp_filter *parent, 43 struct sh_stream *src); 44 45 // For informational purposes. 46 void mp_decoder_wrapper_get_desc(struct mp_decoder_wrapper *d, 47 char *buf, size_t buf_size); 48 49 // Legacy decoder framedrop control. 50 void mp_decoder_wrapper_set_frame_drops(struct mp_decoder_wrapper *d, int num); 51 int mp_decoder_wrapper_get_frames_dropped(struct mp_decoder_wrapper *d); 52 53 double mp_decoder_wrapper_get_container_fps(struct mp_decoder_wrapper *d); 54 55 // Whether to prefer spdif wrapper over real decoders on next reinit. 56 void mp_decoder_wrapper_set_spdif_flag(struct mp_decoder_wrapper *d, bool spdif); 57 58 // Whether to decode only 1 frame and then stop, and cache the frame across resets. 59 void mp_decoder_wrapper_set_coverart_flag(struct mp_decoder_wrapper *d, bool c); 60 61 // True if a pts reset was observed (audio only, heuristic). 62 bool mp_decoder_wrapper_get_pts_reset(struct mp_decoder_wrapper *d); 63 64 void mp_decoder_wrapper_set_play_dir(struct mp_decoder_wrapper *d, int dir); 65 66 struct mp_decoder_list *video_decoder_list(void); 67 struct mp_decoder_list *audio_decoder_list(void); 68 69 // For precise seeking: if possible, try to drop frames up until the given PTS. 70 // This is automatically unset if the target is reached, or on reset. 71 void mp_decoder_wrapper_set_start_pts(struct mp_decoder_wrapper *d, double pts); 72 73 enum dec_ctrl { 74 VDCTRL_FORCE_HWDEC_FALLBACK, // force software decoding fallback 75 VDCTRL_GET_HWDEC, 76 VDCTRL_REINIT, 77 VDCTRL_GET_BFRAMES, 78 // framedrop mode: 0=none, 1=standard, 2=hrseek 79 VDCTRL_SET_FRAMEDROP, 80 }; 81 82 int mp_decoder_wrapper_control(struct mp_decoder_wrapper *d, 83 enum dec_ctrl cmd, void *arg); 84 85 // Force it to reevaluate output parameters (for overrides like aspect). 86 void mp_decoder_wrapper_reset_params(struct mp_decoder_wrapper *d); 87 88 void mp_decoder_wrapper_get_video_dec_params(struct mp_decoder_wrapper *d, 89 struct mp_image_params *p); 90 91 bool mp_decoder_wrapper_reinit(struct mp_decoder_wrapper *d); 92 93 struct mp_decoder { 94 // Bidirectional filter; takes MP_FRAME_PACKET for input. 95 struct mp_filter *f; 96 97 // Can be set by decoder impl. on init for "special" functionality. 98 int (*control)(struct mp_filter *f, enum dec_ctrl cmd, void *arg); 99 }; 100 101 struct mp_decoder_fns { 102 struct mp_decoder *(*create)(struct mp_filter *parent, 103 struct mp_codec_params *codec, 104 const char *decoder); 105 void (*add_decoders)(struct mp_decoder_list *list); 106 }; 107 108 extern const struct mp_decoder_fns vd_lavc; 109 extern const struct mp_decoder_fns ad_lavc; 110 extern const struct mp_decoder_fns ad_spdif; 111 112 // Convenience wrapper for lavc based decoders. Treat lavc_state as private; 113 // init to all-0 on init and resets. 114 struct lavc_state { 115 bool eof_returned; 116 bool packets_sent; 117 }; 118 void lavc_process(struct mp_filter *f, struct lavc_state *state, 119 int (*send)(struct mp_filter *f, struct demux_packet *pkt), 120 int (*receive)(struct mp_filter *f, struct mp_frame *res)); 121 122 // ad_spdif.c 123 struct mp_decoder_list *select_spdif_codec(const char *codec, const char *pref); 124