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 #ifndef MPLAYER_MP_CORE_H
19 #define MPLAYER_MP_CORE_H
20 
21 #include <stdbool.h>
22 #include <pthread.h>
23 
24 #include "osdep/atomic.h"
25 
26 #include "libmpv/client.h"
27 
28 #include "common/common.h"
29 #include "filters/filter.h"
30 #include "filters/f_output_chain.h"
31 #include "options/options.h"
32 #include "sub/osd.h"
33 #include "audio/aframe.h"
34 #include "video/mp_image.h"
35 #include "video/out/vo.h"
36 
37 // definitions used internally by the core player code
38 
39 enum stop_play_reason {
40     KEEP_PLAYING = 0,   // playback of a file is actually going on
41                         // must be 0, numeric values of others do not matter
42     AT_END_OF_FILE,     // file has ended, prepare to play next
43                         // also returned on unrecoverable playback errors
44     PT_NEXT_ENTRY,      // prepare to play next entry in playlist
45     PT_CURRENT_ENTRY,   // prepare to play mpctx->playlist->current
46     PT_STOP,            // stop playback / idle mode
47     PT_QUIT,            // stop playback, quit player
48     PT_ERROR,           // play next playlist entry (due to an error)
49 };
50 
51 enum mp_osd_seek_info {
52     OSD_SEEK_INFO_BAR           = 1,
53     OSD_SEEK_INFO_TEXT          = 2,
54     OSD_SEEK_INFO_CHAPTER_TEXT  = 4,
55     OSD_SEEK_INFO_CURRENT_FILE  = 8,
56 };
57 
58 
59 enum {
60     // other constants
61     OSD_LEVEL_INVISIBLE = 4,
62     OSD_BAR_SEEK = 256,
63 
64     MAX_NUM_VO_PTS = 100,
65 };
66 
67 enum seek_type {
68     MPSEEK_NONE = 0,
69     MPSEEK_RELATIVE,
70     MPSEEK_ABSOLUTE,
71     MPSEEK_FACTOR,
72     MPSEEK_BACKSTEP,
73 };
74 
75 enum seek_precision {
76     // The following values are numerically sorted by increasing precision
77     MPSEEK_DEFAULT = 0,
78     MPSEEK_KEYFRAME,
79     MPSEEK_EXACT,
80     MPSEEK_VERY_EXACT,
81 };
82 
83 enum seek_flags {
84     MPSEEK_FLAG_DELAY = 1 << 0, // give player chance to coalesce multiple seeks
85     MPSEEK_FLAG_NOFLUSH = 1 << 1, // keeping remaining data for seamless loops
86 };
87 
88 struct seek_params {
89     enum seek_type type;
90     enum seek_precision exact;
91     double amount;
92     unsigned flags; // MPSEEK_FLAG_*
93 };
94 
95 enum video_sync {
96     VS_DEFAULT = 0,
97     VS_DISP_RESAMPLE,
98     VS_DISP_RESAMPLE_VDROP,
99     VS_DISP_RESAMPLE_NONE,
100     VS_DISP_ADROP,
101     VS_DISP_VDROP,
102     VS_DISP_NONE,
103     VS_NONE,
104 };
105 
106 #define VS_IS_DISP(x) ((x) == VS_DISP_RESAMPLE ||       \
107                        (x) == VS_DISP_RESAMPLE_VDROP || \
108                        (x) == VS_DISP_RESAMPLE_NONE ||  \
109                        (x) == VS_DISP_ADROP ||          \
110                        (x) == VS_DISP_VDROP ||          \
111                        (x) == VS_DISP_NONE)
112 
113 // Information about past video frames that have been sent to the VO.
114 struct frame_info {
115     double pts;
116     double duration;        // PTS difference to next frame
117     double approx_duration; // possibly fixed/smoothed out duration
118     double av_diff;         // A/V diff at time of scheduling
119     int num_vsyncs;         // scheduled vsyncs, if using display-sync
120 };
121 
122 struct track {
123     enum stream_type type;
124 
125     // Currently used for decoding.
126     bool selected;
127 
128     // The type specific ID, also called aid (audio), sid (subs), vid (video).
129     // For UI purposes only; this ID doesn't have anything to do with any
130     // IDs coming from demuxers or container files.
131     int user_tid;
132 
133     int demuxer_id; // same as stream->demuxer_id. -1 if not set.
134     int ff_index; // same as stream->ff_index, or 0.
135 
136     char *title;
137     bool default_track, forced_track, dependent_track;
138     bool visual_impaired_track, hearing_impaired_track;
139     bool image;
140     bool attached_picture;
141     char *lang;
142 
143     // If this track is from an external file (e.g. subtitle file).
144     bool is_external;
145     bool no_default;            // pretend it's not external for auto-selection
146     bool no_auto_select;
147     char *external_filename;
148     bool auto_loaded;
149 
150     struct demuxer *demuxer;
151     // Invariant: !stream || stream->demuxer == demuxer
152     struct sh_stream *stream;
153 
154     // Current subtitle state (or cached state if selected==false).
155     struct dec_sub *d_sub;
156 
157     // Current decoding state (NULL if selected==false)
158     struct mp_decoder_wrapper *dec;
159 
160     // Where the decoded result goes to (one of them is not NULL if active)
161     struct vo_chain *vo_c;
162     struct ao_chain *ao_c;
163     struct mp_pin *sink;
164 
165     // For stream recording (remuxing mode).
166     struct mp_recorder_sink *remux_sink;
167 };
168 
169 // Summarizes video filtering and output.
170 struct vo_chain {
171     struct mp_log *log;
172 
173     struct mp_output_chain *filter;
174 
175     struct vo *vo;
176 
177     struct track *track;
178     struct mp_pin *filter_src;
179     struct mp_pin *dec_src;
180 
181     // - video consists of a single picture, which should be shown only once
182     // - do not sync audio to video in any way
183     bool is_coverart;
184     // - video consists of sparse still images
185     bool is_sparse;
186 
187     bool underrun;
188     bool underrun_signaled;
189 };
190 
191 // Like vo_chain, for audio.
192 struct ao_chain {
193     struct mp_log *log;
194     struct MPContext *mpctx;
195 
196     bool spdif_passthrough, spdif_failed;
197 
198     struct mp_output_chain *filter;
199 
200     struct ao *ao;
201     struct mp_async_queue *ao_queue;
202     struct mp_filter *queue_filter;
203     struct mp_filter *ao_filter;
204     double ao_resume_time;
205 
206     bool out_eof;
207     double last_out_pts;
208 
209     double start_pts;
210     bool start_pts_known;
211 
212     struct track *track;
213     struct mp_pin *filter_src;
214     struct mp_pin *dec_src;
215 
216     double delay;
217     bool untimed_throttle;
218 
219     bool ao_underrun;   // last known AO state
220     bool underrun;      // for cache pause logic
221 };
222 
223 /* Note that playback can be paused, stopped, etc. at any time. While paused,
224  * playback restart is still active, because you want seeking to work even
225  * if paused.
226  * The main purpose of distinguishing these states is proper reinitialization
227  * of A/V sync.
228  */
229 enum playback_status {
230     // code may compare status values numerically
231     STATUS_SYNCING,     // seeking for a position to resume
232     STATUS_READY,       // buffers full, playback can be started any time
233     STATUS_PLAYING,     // normal playback
234     STATUS_DRAINING,    // decoding has ended; still playing out queued buffers
235     STATUS_EOF,         // playback has ended, or is disabled
236 };
237 
238 const char *mp_status_str(enum playback_status st);
239 
240 extern const int num_ptracks[STREAM_TYPE_COUNT];
241 
242 // Maximum of all num_ptracks[] values.
243 #define MAX_PTRACKS 2
244 
245 typedef struct MPContext {
246     bool initialized;
247     bool is_cli;
248     struct mpv_global *global;
249     struct MPOpts *opts;
250     struct mp_log *log;
251     struct stats_ctx *stats;
252     struct m_config *mconfig;
253     struct input_ctx *input;
254     struct mp_client_api *clients;
255     struct mp_dispatch_queue *dispatch;
256     struct mp_cancel *playback_abort;
257     // Number of asynchronous tasks that still need to finish until MPContext
258     // destruction is ok. It's implied that the async tasks call
259     // mp_wakeup_core() each time this is decremented.
260     // As using an atomic+wakeup would be racy, this is a normal integer, and
261     // mp_dispatch_lock must be called to change it.
262     int64_t outstanding_async;
263 
264     struct mp_thread_pool *thread_pool; // for coarse I/O, often during loading
265 
266     struct mp_log *statusline;
267     struct osd_state *osd;
268     char *term_osd_text;
269     char *term_osd_status;
270     char *term_osd_subs;
271     char *term_osd_contents;
272     char *term_osd_title;
273     char *last_window_title;
274     struct voctrl_playback_state vo_playback_state;
275 
276     int add_osd_seek_info; // bitfield of enum mp_osd_seek_info
277     double osd_visible; // for the osd bar only
278     int osd_function;
279     double osd_function_visible;
280     double osd_msg_visible;
281     double osd_msg_next_duration;
282     double osd_last_update;
283     bool osd_force_update, osd_idle_update;
284     char *osd_msg_text;
285     bool osd_show_pos;
286     struct osd_progbar_state osd_progbar;
287 
288     struct playlist *playlist;
289     struct playlist_entry *playing; // currently playing file
290     char *filename; // immutable copy of playing->filename (or NULL)
291     char *stream_open_filename;
292     enum stop_play_reason stop_play;
293     bool playback_initialized; // playloop can be run/is running
294     int error_playing;
295 
296     // Return code to use with PT_QUIT
297     int quit_custom_rc;
298     bool has_quit_custom_rc;
299 
300     // Global file statistics
301     int files_played;       // played without issues (even if stopped by user)
302     int files_errored;      // played, but errors happened at one point
303     int files_broken;       // couldn't be played at all
304 
305     // Current file statistics
306     int64_t shown_vframes, shown_aframes;
307 
308     struct demux_chapter *chapters;
309     int num_chapters;
310 
311     struct demuxer *demuxer;
312     struct mp_tags *filtered_tags;
313 
314     struct track **tracks;
315     int num_tracks;
316 
317     char *track_layout_hash;
318 
319     // Selected tracks. NULL if no track selected.
320     // There can be num_ptracks[type] of the same STREAM_TYPE selected at once.
321     // Currently, this is used for the secondary subtitle track only.
322     struct track *current_track[MAX_PTRACKS][STREAM_TYPE_COUNT];
323 
324     struct mp_filter *filter_root;
325 
326     struct mp_filter *lavfi;
327     char *lavfi_graph;
328 
329     struct ao *ao;
330     struct mp_aframe *ao_filter_fmt; // for weak gapless audio check
331     struct ao_chain *ao_chain;
332 
333     struct vo_chain *vo_chain;
334 
335     struct vo *video_out;
336     // next_frame[0] is the next frame, next_frame[1] the one after that.
337     // The +1 is for adding 1 additional frame in backstep mode.
338     struct mp_image *next_frames[VO_MAX_REQ_FRAMES + 1];
339     int num_next_frames;
340     struct mp_image *saved_frame;   // for hrseek_lastframe and hrseek_backstep
341 
342     enum playback_status video_status, audio_status;
343     bool restart_complete;
344     int play_dir;
345     // Factors to multiply with opts->playback_speed to get the total audio or
346     // video speed (usually 1.0, but can be set to by the sync code).
347     double speed_factor_v, speed_factor_a;
348     // Redundant values set from opts->playback_speed and speed_factor_*.
349     // update_playback_speed() updates them from the other fields.
350     double audio_speed, video_speed;
351     bool display_sync_active;
352     int display_sync_drift_dir;
353     // Timing error (in seconds) due to rounding on vsync boundaries
354     double display_sync_error;
355     // Number of mistimed frames.
356     int mistimed_frames_total;
357     bool hrseek_active;     // skip all data until hrseek_pts
358     bool hrseek_lastframe;  // drop everything until last frame reached
359     bool hrseek_backstep;   // go to frame before seek target
360     double hrseek_pts;
361     struct seek_params current_seek;
362     bool ab_loop_clip;      // clip to the "b" part of an A-B loop if available
363     // AV sync: the next frame should be shown when the audio out has this
364     // much (in seconds) buffered data left. Increased when more data is
365     // written to the ao, decreased when moving to the next video frame.
366     double delay;
367     // AV sync: time in seconds until next frame should be shown
368     double time_frame;
369     // How much video timing has been changed to make it match the audio
370     // timeline. Used for status line information only.
371     double total_avsync_change;
372     // A-V sync difference when last frame was displayed. Kept to display
373     // the same value if the status line is updated at a time where no new
374     // video frame is shown.
375     double last_av_difference;
376     /* timestamp of video frame currently visible on screen
377      * (or at least queued to be flipped by VO) */
378     double video_pts;
379     // Last seek target.
380     double last_seek_pts;
381     // Frame duration field from demuxer. Only used for duration of the last
382     // video frame.
383     double last_frame_duration;
384     // Video PTS, or audio PTS if video has ended.
385     double playback_pts;
386     // For logging only.
387     double logged_async_diff;
388 
389     int last_chapter;
390 
391     // Past timestamps etc.
392     // The newest frame is at index 0.
393     struct frame_info *past_frames;
394     int num_past_frames;
395 
396     double last_idle_tick;
397     double next_cache_update;
398 
399     double sleeptime;      // number of seconds to sleep before next iteration
400 
401     double mouse_timer;
402     unsigned int mouse_event_ts;
403     bool mouse_cursor_visible;
404 
405     // used to prevent hanging in some error cases
406     double start_timestamp;
407 
408     // Timestamp from the last time some timing functions read the
409     // current time, in microseconds.
410     // Used to turn a new time value to a delta from last time.
411     int64_t last_time;
412 
413     struct seek_params seek;
414 
415     /* Heuristic for relative chapter seeks: keep track which chapter
416      * the user wanted to go to, even if we aren't exactly within the
417      * boundaries of that chapter due to an inaccurate seek. */
418     int last_chapter_seek;
419     double last_chapter_pts;
420 
421     bool paused;            // internal pause state
422     bool playback_active;   // not paused, restarting, loading, unloading
423     bool in_playloop;
424 
425     // step this many frames, then pause
426     int step_frames;
427     // Counted down each frame, stop playback if 0 is reached. (-1 = disable)
428     int max_frames;
429     bool playing_msg_shown;
430 
431     bool paused_for_cache;
432     bool demux_underrun;
433     double cache_stop_time;
434     int cache_buffer;
435     double cache_update_pts;
436 
437     // Set after showing warning about decoding being too slow for realtime
438     // playback rate. Used to avoid showing it multiple times.
439     bool drop_message_shown;
440 
441     struct mp_recorder *recorder;
442 
443     char *cached_watch_later_configdir;
444 
445     struct screenshot_ctx *screenshot_ctx;
446     struct command_ctx *command_ctx;
447     struct encode_lavc_context *encode_lavc_ctx;
448 
449     struct mp_ipc_ctx *ipc_ctx;
450 
451     int64_t builtin_script_ids[5];
452 
453     pthread_mutex_t abort_lock;
454 
455     // --- The following fields are protected by abort_lock
456     struct mp_abort_entry **abort_list;
457     int num_abort_list;
458     bool abort_all; // during final termination
459 
460     // --- Owned by MPContext
461     pthread_t open_thread;
462     bool open_active; // open_thread is a valid thread handle, all setup
463     atomic_bool open_done;
464     // --- All fields below are immutable while open_active is true.
465     //     Otherwise, they're owned by MPContext.
466     struct mp_cancel *open_cancel;
467     char *open_url;
468     char *open_format;
469     int open_url_flags;
470     bool open_for_prefetch;
471     // --- All fields below are owned by open_thread, unless open_done was set
472     //     to true.
473     struct demuxer *open_res_demuxer;
474     int open_res_error;
475 } MPContext;
476 
477 // Contains information about an asynchronous work item, how it can be aborted,
478 // and when. All fields are protected by MPContext.abort_lock.
479 struct mp_abort_entry {
480     // General conditions.
481     bool coupled_to_playback;   // trigger when playback is terminated
482     // Actual trigger to abort the work. Pointer immutable, owner may access
483     // without holding the abort_lock.
484     struct mp_cancel *cancel;
485     // For client API.
486     struct mpv_handle *client;  // non-NULL if done by a client API user
487     int client_work_type;       // client API type, e.h. MPV_EVENT_COMMAND_REPLY
488     uint64_t client_work_id;    // client API user reply_userdata value
489                                 // (only valid if client_work_type set)
490 };
491 
492 // audio.c
493 void reset_audio_state(struct MPContext *mpctx);
494 void reinit_audio_chain(struct MPContext *mpctx);
495 int init_audio_decoder(struct MPContext *mpctx, struct track *track);
496 int reinit_audio_filters(struct MPContext *mpctx);
497 double playing_audio_pts(struct MPContext *mpctx);
498 void fill_audio_out_buffers(struct MPContext *mpctx);
499 double written_audio_pts(struct MPContext *mpctx);
500 void clear_audio_output_buffers(struct MPContext *mpctx);
501 void update_playback_speed(struct MPContext *mpctx);
502 void uninit_audio_out(struct MPContext *mpctx);
503 void uninit_audio_chain(struct MPContext *mpctx);
504 int init_audio_decoder(struct MPContext *mpctx, struct track *track);
505 void reinit_audio_chain_src(struct MPContext *mpctx, struct track *track);
506 void audio_update_volume(struct MPContext *mpctx);
507 void audio_update_balance(struct MPContext *mpctx);
508 void reload_audio_output(struct MPContext *mpctx);
509 void audio_start_ao(struct MPContext *mpctx);
510 
511 // configfiles.c
512 void mp_parse_cfgfiles(struct MPContext *mpctx);
513 void mp_load_auto_profiles(struct MPContext *mpctx);
514 void mp_load_playback_resume(struct MPContext *mpctx, const char *file);
515 void mp_write_watch_later_conf(struct MPContext *mpctx);
516 void mp_delete_watch_later_conf(struct MPContext *mpctx, const char *file);
517 struct playlist_entry *mp_check_playlist_resume(struct MPContext *mpctx,
518                                                 struct playlist *playlist);
519 
520 // loadfile.c
521 void mp_abort_playback_async(struct MPContext *mpctx);
522 void mp_abort_add(struct MPContext *mpctx, struct mp_abort_entry *abort);
523 void mp_abort_remove(struct MPContext *mpctx, struct mp_abort_entry *abort);
524 void mp_abort_recheck_locked(struct MPContext *mpctx,
525                              struct mp_abort_entry *abort);
526 void mp_abort_trigger_locked(struct MPContext *mpctx,
527                              struct mp_abort_entry *abort);
528 void uninit_player(struct MPContext *mpctx, unsigned int mask);
529 int mp_add_external_file(struct MPContext *mpctx, char *filename,
530                          enum stream_type filter, struct mp_cancel *cancel,
531                          bool cover_art);
532 void mark_track_selection(struct MPContext *mpctx, int order,
533                           enum stream_type type, int value);
534 #define FLAG_MARK_SELECTION 1
535 void mp_switch_track(struct MPContext *mpctx, enum stream_type type,
536                      struct track *track, int flags);
537 void mp_switch_track_n(struct MPContext *mpctx, int order,
538                        enum stream_type type, struct track *track, int flags);
539 void mp_deselect_track(struct MPContext *mpctx, struct track *track);
540 struct track *mp_track_by_tid(struct MPContext *mpctx, enum stream_type type,
541                               int tid);
542 void add_demuxer_tracks(struct MPContext *mpctx, struct demuxer *demuxer);
543 bool mp_remove_track(struct MPContext *mpctx, struct track *track);
544 struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction,
545                                     bool force, bool mutate);
546 void mp_set_playlist_entry(struct MPContext *mpctx, struct playlist_entry *e);
547 void mp_play_files(struct MPContext *mpctx);
548 void update_demuxer_properties(struct MPContext *mpctx);
549 void print_track_list(struct MPContext *mpctx, const char *msg);
550 void reselect_demux_stream(struct MPContext *mpctx, struct track *track,
551                            bool refresh_only);
552 void prepare_playlist(struct MPContext *mpctx, struct playlist *pl);
553 void autoload_external_files(struct MPContext *mpctx, struct mp_cancel *cancel);
554 struct track *select_default_track(struct MPContext *mpctx, int order,
555                                    enum stream_type type);
556 void prefetch_next(struct MPContext *mpctx);
557 void close_recorder(struct MPContext *mpctx);
558 void close_recorder_and_error(struct MPContext *mpctx);
559 void open_recorder(struct MPContext *mpctx, bool on_init);
560 void update_lavfi_complex(struct MPContext *mpctx);
561 
562 // main.c
563 int mp_initialize(struct MPContext *mpctx, char **argv);
564 struct MPContext *mp_create(void);
565 void mp_destroy(struct MPContext *mpctx);
566 void mp_print_version(struct mp_log *log, int always);
567 void mp_update_logging(struct MPContext *mpctx, bool preinit);
568 void issue_refresh_seek(struct MPContext *mpctx, enum seek_precision min_prec);
569 
570 // misc.c
571 double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t);
572 double get_play_end_pts(struct MPContext *mpctx);
573 double get_play_start_pts(struct MPContext *mpctx);
574 bool get_ab_loop_times(struct MPContext *mpctx, double t[2]);
575 void merge_playlist_files(struct playlist *pl);
576 void update_vo_playback_state(struct MPContext *mpctx);
577 void update_window_title(struct MPContext *mpctx, bool force);
578 void error_on_track(struct MPContext *mpctx, struct track *track);
579 int stream_dump(struct MPContext *mpctx, const char *source_filename);
580 double get_track_seek_offset(struct MPContext *mpctx, struct track *track);
581 
582 // osd.c
583 void set_osd_bar(struct MPContext *mpctx, int type,
584                  double min, double max, double neutral, double val);
585 bool set_osd_msg(struct MPContext *mpctx, int level, int time,
586                  const char* fmt, ...) PRINTF_ATTRIBUTE(4,5);
587 void set_osd_function(struct MPContext *mpctx, int osd_function);
588 void term_osd_set_subs(struct MPContext *mpctx, const char *text);
589 void get_current_osd_sym(struct MPContext *mpctx, char *buf, size_t buf_size);
590 void set_osd_bar_chapters(struct MPContext *mpctx, int type);
591 
592 // playloop.c
593 void mp_wait_events(struct MPContext *mpctx);
594 void mp_set_timeout(struct MPContext *mpctx, double sleeptime);
595 void mp_wakeup_core(struct MPContext *mpctx);
596 void mp_wakeup_core_cb(void *ctx);
597 void mp_core_lock(struct MPContext *mpctx);
598 void mp_core_unlock(struct MPContext *mpctx);
599 double get_relative_time(struct MPContext *mpctx);
600 void reset_playback_state(struct MPContext *mpctx);
601 void set_pause_state(struct MPContext *mpctx, bool user_pause);
602 void update_internal_pause_state(struct MPContext *mpctx);
603 void update_core_idle_state(struct MPContext *mpctx);
604 void add_step_frame(struct MPContext *mpctx, int dir);
605 void queue_seek(struct MPContext *mpctx, enum seek_type type, double amount,
606                 enum seek_precision exact, int flags);
607 double get_time_length(struct MPContext *mpctx);
608 double get_start_time(struct MPContext *mpctx, int dir);
609 double get_current_time(struct MPContext *mpctx);
610 double get_playback_time(struct MPContext *mpctx);
611 int get_percent_pos(struct MPContext *mpctx);
612 double get_current_pos_ratio(struct MPContext *mpctx, bool use_range);
613 int get_current_chapter(struct MPContext *mpctx);
614 char *chapter_display_name(struct MPContext *mpctx, int chapter);
615 char *chapter_name(struct MPContext *mpctx, int chapter);
616 double chapter_start_time(struct MPContext *mpctx, int chapter);
617 int get_chapter_count(struct MPContext *mpctx);
618 int get_cache_buffering_percentage(struct MPContext *mpctx);
619 void execute_queued_seek(struct MPContext *mpctx);
620 void run_playloop(struct MPContext *mpctx);
621 void mp_idle(struct MPContext *mpctx);
622 void idle_loop(struct MPContext *mpctx);
623 int handle_force_window(struct MPContext *mpctx, bool force);
624 void seek_to_last_frame(struct MPContext *mpctx);
625 void update_screensaver_state(struct MPContext *mpctx);
626 void update_ab_loop_clip(struct MPContext *mpctx);
627 bool get_internal_paused(struct MPContext *mpctx);
628 
629 // scripting.c
630 struct mp_script_args {
631     const struct mp_scripting *backend;
632     struct MPContext *mpctx;
633     struct mp_log *log;
634     struct mpv_handle *client;
635     const char *filename;
636     const char *path;
637 };
638 struct mp_scripting {
639     const char *name;       // e.g. "lua script"
640     const char *file_ext;   // e.g. "lua"
641     bool no_thread;         // don't run load() on dedicated thread
642     int (*load)(struct mp_script_args *args);
643 };
644 bool mp_load_scripts(struct MPContext *mpctx);
645 void mp_load_builtin_scripts(struct MPContext *mpctx);
646 int64_t mp_load_user_script(struct MPContext *mpctx, const char *fname);
647 
648 // sub.c
649 void reset_subtitle_state(struct MPContext *mpctx);
650 void reinit_sub(struct MPContext *mpctx, struct track *track);
651 void reinit_sub_all(struct MPContext *mpctx);
652 void uninit_sub(struct MPContext *mpctx, struct track *track);
653 void uninit_sub_all(struct MPContext *mpctx);
654 void update_osd_msg(struct MPContext *mpctx);
655 bool update_subtitles(struct MPContext *mpctx, double video_pts);
656 
657 // video.c
658 int video_get_colors(struct vo_chain *vo_c, const char *item, int *value);
659 int video_set_colors(struct vo_chain *vo_c, const char *item, int value);
660 void reset_video_state(struct MPContext *mpctx);
661 int init_video_decoder(struct MPContext *mpctx, struct track *track);
662 void reinit_video_chain(struct MPContext *mpctx);
663 void reinit_video_chain_src(struct MPContext *mpctx, struct track *track);
664 int reinit_video_filters(struct MPContext *mpctx);
665 void write_video(struct MPContext *mpctx);
666 void mp_force_video_refresh(struct MPContext *mpctx);
667 void uninit_video_out(struct MPContext *mpctx);
668 void uninit_video_chain(struct MPContext *mpctx);
669 double calc_average_frame_duration(struct MPContext *mpctx);
670 int init_video_decoder(struct MPContext *mpctx, struct track *track);
671 
672 #endif /* MPLAYER_MP_CORE_H */
673