core: move global "subdata" and "vo_sub_last" to mpctx
[mplayer/glamo.git] / mp_core.h
blobf8b286e5b9af553761267f763a15665a93431163
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer 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 General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef MPLAYER_MP_CORE_H
20 #define MPLAYER_MP_CORE_H
22 #include <stdbool.h>
24 #include "options.h"
25 #include "mixer.h"
26 #include "subreader.h"
28 // definitions used internally by the core player code
30 #define INITIALIZED_VO 1
31 #define INITIALIZED_AO 2
33 #define INITIALIZED_GETCH2 8
34 #define INITIALIZED_SPUDEC 32
35 #define INITIALIZED_STREAM 64
36 #define INITIALIZED_VOBSUB 256
37 #define INITIALIZED_DEMUXER 512
38 #define INITIALIZED_ACODEC 1024
39 #define INITIALIZED_VCODEC 2048
40 #define INITIALIZED_ALL 0xFFFF
43 #define SUB_SOURCE_SUBS 0
44 #define SUB_SOURCE_VOBSUB 1
45 #define SUB_SOURCE_DEMUX 2
46 #define SUB_SOURCES 3
49 enum stop_play_reason {
50 KEEP_PLAYING = 0, // must be 0, numeric values of others do not matter
51 AT_END_OF_FILE,
52 PT_NEXT_ENTRY,
53 PT_PREV_ENTRY,
54 PT_NEXT_SRC,
55 PT_PREV_SRC,
56 PT_UP_NEXT,
57 PT_UP_PREV,
58 PT_STOP,
61 enum exit_reason {
62 EXIT_NONE,
63 EXIT_QUIT,
64 EXIT_EOF,
65 EXIT_ERROR
68 struct content_source {
69 struct stream *stream;
70 struct demuxer *demuxer;
73 struct timeline_part {
74 double start;
75 double source_start;
76 struct content_source *source;
79 struct chapter {
80 double start;
81 char *name;
84 typedef struct MPContext {
85 struct MPOpts opts;
86 struct m_config *mconfig;
87 struct vo_x11_state *x11_state;
88 struct mp_fifo *key_fifo;
89 struct input_ctx *input;
90 struct osd_state *osd;
91 struct sub_data *subdata; // current sub_data style subtitles if any
92 // last sub_data style sub line if any, used by log_sub() only
93 struct subtitle *vo_sub_last;
95 bool add_osd_seek_info;
96 // if nonzero, hide current OSD contents when GetTimerMS() reaches this
97 unsigned int osd_show_percentage_until;
98 unsigned int osd_visible;
100 int osd_function;
101 const ao_functions_t *audio_out;
102 struct play_tree *playtree;
103 struct play_tree_iter *playtree_iter;
104 char *filename; // currently playing file
105 enum stop_play_reason stop_play;
106 int play_tree_step;
107 unsigned int initialized_flags; // which subsystems have been initialized
109 struct content_source *sources;
110 int num_sources;
111 struct timeline_part *timeline;
112 int num_timeline_parts;
113 int timeline_part;
114 struct chapter *chapters;
115 int num_chapters;
116 double video_offset;
118 struct stream *stream;
119 struct demuxer *demuxer;
120 struct sh_audio *sh_audio;
121 struct sh_video *sh_video;
122 struct demux_stream *d_audio;
123 struct demux_stream *d_video;
124 struct demux_stream *d_sub;
125 mixer_t mixer;
126 struct vo *video_out;
128 /* We're starting playback from scratch or after a seek. Show first
129 * video frame immediately and reinitialize sync. */
130 bool restart_playback;
131 /* After playback restart (above) or audio stream change, adjust audio
132 * stream by cutting samples or adding silence at the beginning to make
133 * audio playback position match video position. */
134 bool syncing_audio;
135 bool hrseek_active;
136 bool hrseek_framedrop;
137 double hrseek_pts;
138 // AV sync: the next frame should be shown when the audio out has this
139 // much (in seconds) buffered data left. Increased when more data is
140 // written to the ao, decreased when moving to the next frame.
141 // In the audio-only case used as a timer since the last seek
142 // by the audio CPU usage meter.
143 double delay;
144 // AV sync: time until next frame should be shown
145 float time_frame;
146 // How long the last vo flip() call took. Used to adjust timing with
147 // the goal of making flip() calls finish (rather than start) at the
148 // specified time.
149 float last_vo_flip_duration;
150 // How much video timing has been changed to make it match the audio
151 // timeline. Used for status line information only.
152 double total_avsync_change;
153 // A-V sync difference when last frame was displayed. Kept to display
154 // the same value if the status line is updated at a time where no new
155 // video frame is shown.
156 double last_av_difference;
157 /* timestamp of video frame currently visible on screen
158 * (or at least queued to be flipped by VO) */
159 double video_pts;
161 // used to prevent hanging in some error cases
162 unsigned int start_timestamp;
164 // Timestamp from the last time some timing functions read the
165 // current time, in (occasionally wrapping) microseconds. Used
166 // to turn a new time value to a delta from last time.
167 unsigned int last_time;
169 // Used to communicate the parameters of a seek between parts
170 struct seek_params {
171 enum seek_type {
172 MPSEEK_NONE, MPSEEK_RELATIVE, MPSEEK_ABSOLUTE, MPSEEK_FACTOR
173 } type;
174 double amount;
175 int exact; // -1 = disable, 0 = default, 1 = enable
176 // currently not set by commands, only used internally by seek()
177 int direction; // -1 = backward, 0 = default, 1 = forward
178 } seek;
180 /* Heuristic for relative chapter seeks: keep track which chapter
181 * the user wanted to go to, even if we aren't exactly within the
182 * boundaries of that chapter due to an inaccurate seek. */
183 int last_chapter_seek;
184 double last_chapter_pts;
186 float begin_skip; ///< start time of the current skip while on edlout mode
187 // audio is muted if either EDL or user activates mute
188 short edl_muted; ///< Stores whether EDL is currently in muted mode.
189 short user_muted; ///< Stores whether user wanted muted mode.
191 int global_sub_size; // this encompasses all subtitle sources
192 int global_sub_pos; // this encompasses all subtitle sources
193 int set_of_sub_pos;
194 int set_of_sub_size;
195 int sub_counts[SUB_SOURCES];
196 // set_of_ass_tracks[i] contains subtitles from set_of_subtitles[i]
197 // parsed by libass or NULL if format unsupported
198 struct ass_track *set_of_ass_tracks[MAX_SUBTITLE_FILES];
199 sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
201 int file_format;
203 int last_dvb_step;
204 int dvbin_reopen;
206 int paused;
207 // step this many frames, then pause
208 int step_frames;
210 // Set after showing warning about decoding being too slow for realtime
211 // playback rate. Used to avoid showing it multiple times.
212 bool drop_message_shown;
214 #ifdef CONFIG_DVDNAV
215 struct mp_image *nav_smpi; ///< last decoded dvdnav video image
216 unsigned char *nav_buffer; ///< last read dvdnav video frame
217 unsigned char *nav_start; ///< pointer to last read video buffer
218 int nav_in_size; ///< last read size
219 #endif
220 } MPContext;
223 // Most of these should not be globals
224 extern FILE *edl_fd;
225 extern int file_filter;
226 // These appear in options list
227 extern int forced_subs_only;
229 struct ao_data;
230 void uninit_player(struct MPContext *mpctx, unsigned int mask);
231 void reinit_audio_chain(struct MPContext *mpctx);
232 void init_vo_spudec(struct MPContext *mpctx);
233 double playing_audio_pts(struct MPContext *mpctx);
234 void exit_player_with_rc(struct MPContext *mpctx, enum exit_reason how, int rc);
235 void add_subtitles(struct MPContext *mpctx, char *filename, float fps, int noerr);
236 int reinit_video_chain(struct MPContext *mpctx);
237 void pause_player(struct MPContext *mpctx);
238 void unpause_player(struct MPContext *mpctx);
239 void add_step_frame(struct MPContext *mpctx);
240 void queue_seek(struct MPContext *mpctx, enum seek_type type, double amount,
241 int exact);
242 int seek_chapter(struct MPContext *mpctx, int chapter, double *seek_pts,
243 char **chapter_name);
244 double get_time_length(struct MPContext *mpctx);
245 double get_current_time(struct MPContext *mpctx);
246 int get_percent_pos(struct MPContext *mpctx);
247 int get_current_chapter(struct MPContext *mpctx);
248 char *chapter_display_name(struct MPContext *mpctx, int chapter);
250 #endif /* MPLAYER_MP_CORE_H */