1 #pragma once
2 
3 #include "options/m_option.h"
4 #include "video/mp_image.h"
5 
6 #include "filter.h"
7 
8 enum mp_output_chain_type {
9     MP_OUTPUT_CHAIN_VIDEO = 1,      // --vf
10     MP_OUTPUT_CHAIN_AUDIO,          // --af
11 };
12 
13 // A classic single-media filter chain, which reflects --vf and --af.
14 // It manages the user-specified filter chain, and VO/AO output conversions.
15 // Also handles some automatic filtering (auto rotation and such).
16 struct mp_output_chain {
17     // This filter will have 1 input (from decoder) and 1 output (to VO/AO).
18     struct mp_filter *f;
19 
20     bool got_output_eof;
21 
22     // The filter chain output could not be converted to any format the output
23     // supports.
24     bool failed_output_conversion;
25 
26     // Set if any formats in the chain changed. The user can reset the flag.
27     // For implementing change notifications out input/output_params.
28     bool reconfig_happened;
29 
30     // --- for type==MP_OUTPUT_CHAIN_VIDEO
31     struct mp_image_params input_params;
32     struct mp_image_params output_params;
33     double container_fps;
34     void (*update_subtitles)(void *ctx, double pts);
35     void *update_subtitles_ctx;
36 
37     // --- for type==MP_OUTPUT_CHAIN_AUDIO
38     struct mp_aframe *input_aformat;
39     struct mp_aframe *output_aformat;
40     // If true, there was a format change. output_aformat might have changed,
41     // and the implementation drained the filter chain and unset the internal ao
42     // reference. The API user needs to call mp_output_chain_set_ao() again.
43     // Until this is done, the filter chain will not output new data.
44     bool ao_needs_update;
45 };
46 
47 // (free by freeing mp_output_chain.f)
48 struct mp_output_chain *mp_output_chain_create(struct mp_filter *parent,
49                                                enum mp_output_chain_type type);
50 
51 // Set the VO, which will be used to determine basic capabilities like format
52 // and rotation support, and to init hardware filtering things.
53 // For type==MP_OUTPUT_CHAIN_VIDEO only.
54 struct vo;
55 void mp_output_chain_set_vo(struct mp_output_chain *p, struct vo *vo);
56 
57 // Set the AO. The AO format will be used to determine the filter chain output.
58 // The API user may be asked to update the AO midstream if ao_needs_update is
59 // set.
60 // For type==MP_OUTPUT_CHAIN_AUDIO only.
61 struct ao;
62 void mp_output_chain_set_ao(struct mp_output_chain *p, struct ao *ao);
63 
64 // Send a command to the filter with the target label.
65 bool mp_output_chain_command(struct mp_output_chain *p, const char *target,
66                              struct mp_filter_command *cmd);
67 
68 // Perform a seek reset _and_ reset all filter failure states, so that future
69 // filtering continues normally.
70 void mp_output_chain_reset_harder(struct mp_output_chain *p);
71 
72 // Try to exchange the filter list. If creation of any filter fails, roll
73 // back the changes, and return false.
74 struct m_obj_settings;
75 bool mp_output_chain_update_filters(struct mp_output_chain *p,
76                                     struct m_obj_settings *list);
77 
78 // Desired audio speed, with resample being strict resampling.
79 void mp_output_chain_set_audio_speed(struct mp_output_chain *p,
80                                      double speed, double resample, double drop);
81 
82 // Total delay incurred by the filter chain, as measured by the recent filtered
83 // frames. The intention is that this sums the measured delays for each filter,
84 // so if a filter is removed, the caller can estimate how much audio is missing
85 // due to the change.
86 // Makes sense for audio only.
87 double mp_output_get_measured_total_delay(struct mp_output_chain *p);
88