Mercurial > mplayer.hg
comparison mplayer.c @ 33363:02021152bad3
Prettify main MPlayer source file.
Direct use of uncrustify profile with mplayer.c
author | cboesch |
---|---|
date | Mon, 09 May 2011 18:47:27 +0000 |
parents | 552f1f7731c8 |
children | f33d61bf5da0 |
comparison
equal
deleted
inserted
replaced
33362:bf3f244d7bc1 | 33363:02021152bad3 |
---|---|
39 | 39 |
40 #ifndef __MINGW32__ | 40 #ifndef __MINGW32__ |
41 #include <sys/ioctl.h> | 41 #include <sys/ioctl.h> |
42 #include <sys/wait.h> | 42 #include <sys/wait.h> |
43 #else | 43 #else |
44 #define SIGHUP 1 /* hangup */ | 44 #define SIGHUP 1 /* hangup */ |
45 #define SIGQUIT 3 /* quit */ | 45 #define SIGQUIT 3 /* quit */ |
46 #define SIGKILL 9 /* kill (cannot be caught or ignored) */ | 46 #define SIGKILL 9 /* kill (cannot be caught or ignored) */ |
47 #define SIGBUS 10 /* bus error */ | 47 #define SIGBUS 10 /* bus error */ |
48 #define SIGPIPE 13 /* broken pipe */ | 48 #define SIGPIPE 13 /* broken pipe */ |
49 #endif | 49 #endif |
50 | 50 |
51 #ifdef HAVE_RTC | 51 #ifdef HAVE_RTC |
52 #ifdef __linux__ | 52 #ifdef __linux__ |
53 #include <linux/rtc.h> | 53 #include <linux/rtc.h> |
136 #endif | 136 #endif |
137 #ifdef CONFIG_DVDREAD | 137 #ifdef CONFIG_DVDREAD |
138 #include "stream/stream_dvd.h" | 138 #include "stream/stream_dvd.h" |
139 #endif | 139 #endif |
140 | 140 |
141 | |
142 int slave_mode; | 141 int slave_mode; |
143 int player_idle_mode; | 142 int player_idle_mode; |
144 int quiet; | 143 int quiet; |
145 int enable_mouse_movements; | 144 int enable_mouse_movements; |
146 float start_volume = -1; | 145 float start_volume = -1; |
147 double start_pts = MP_NOPTS_VALUE; | 146 double start_pts = MP_NOPTS_VALUE; |
148 char *heartbeat_cmd; | 147 char *heartbeat_cmd; |
149 | 148 |
150 m_config_t* mconfig; | 149 m_config_t *mconfig; |
151 | 150 |
152 //**************************************************************************// | 151 //**************************************************************************// |
153 // Config file | 152 // Config file |
154 //**************************************************************************// | 153 //**************************************************************************// |
155 | 154 |
156 static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;} | 155 static int cfg_inc_verbose(m_option_t *conf) |
157 | 156 { |
158 static int cfg_include(m_option_t *conf, char *filename){ | 157 ++verbose; |
159 return m_config_parse_config_file(mconfig, filename); | 158 return 0; |
159 } | |
160 | |
161 static int cfg_include(m_option_t *conf, char *filename) | |
162 { | |
163 return m_config_parse_config_file(mconfig, filename); | |
160 } | 164 } |
161 | 165 |
162 static int max_framesize; | 166 static int max_framesize; |
163 | 167 |
164 int noconsolecontrols; | 168 int noconsolecontrols; |
165 //**************************************************************************// | 169 //**************************************************************************// |
166 | 170 |
167 // Not all functions in mplayer.c take the context as an argument yet | 171 // Not all functions in mplayer.c take the context as an argument yet |
168 static MPContext mpctx_s = { | 172 static MPContext mpctx_s = { |
169 .osd_function = OSD_PLAY, | 173 .osd_function = OSD_PLAY, |
170 .begin_skip = MP_NOPTS_VALUE, | 174 .begin_skip = MP_NOPTS_VALUE, |
171 .play_tree_step = 1, | 175 .play_tree_step = 1, |
172 .global_sub_pos = -1, | 176 .global_sub_pos = -1, |
173 .set_of_sub_pos = -1, | 177 .set_of_sub_pos = -1, |
174 .file_format = DEMUXER_TYPE_UNKNOWN, | 178 .file_format = DEMUXER_TYPE_UNKNOWN, |
175 .loop_times = -1, | 179 .loop_times = -1, |
176 #ifdef CONFIG_DVBIN | 180 #ifdef CONFIG_DVBIN |
177 .last_dvb_step = 1, | 181 .last_dvb_step = 1, |
178 #endif | 182 #endif |
179 }; | 183 }; |
180 | 184 |
181 static MPContext *mpctx = &mpctx_s; | 185 static MPContext *mpctx = &mpctx_s; |
182 | 186 |
191 static int drop_frame_cnt; // total number of dropped frames | 195 static int drop_frame_cnt; // total number of dropped frames |
192 int benchmark; | 196 int benchmark; |
193 | 197 |
194 // options: | 198 // options: |
195 #define DEFAULT_STARTUP_DECODE_RETRY 8 | 199 #define DEFAULT_STARTUP_DECODE_RETRY 8 |
196 int auto_quality; | 200 int auto_quality; |
197 static int output_quality; | 201 static int output_quality; |
198 | 202 |
199 float playback_speed=1.0; | 203 float playback_speed = 1.0; |
200 | 204 |
201 int use_gui; | 205 int use_gui; |
202 | 206 |
203 #ifdef CONFIG_GUI | 207 #ifdef CONFIG_GUI |
204 int enqueue; | 208 int enqueue; |
205 #endif | 209 #endif |
206 | 210 |
207 static int list_properties; | 211 static int list_properties; |
208 | 212 |
209 int osd_level=1; | 213 int osd_level = 1; |
210 // if nonzero, hide current OSD contents when GetTimerMS() reaches this | 214 // if nonzero, hide current OSD contents when GetTimerMS() reaches this |
211 unsigned int osd_visible; | 215 unsigned int osd_visible; |
212 int osd_duration = 1000; | 216 int osd_duration = 1000; |
213 int osd_fractions; // determines how fractions of seconds are displayed | 217 int osd_fractions; // determines how fractions of seconds are displayed |
214 // on OSD | 218 // on OSD |
215 | 219 |
216 int term_osd = 1; | 220 int term_osd = 1; |
217 static char* term_osd_esc = "\x1b[A\r\x1b[K"; | 221 static char *term_osd_esc = "\x1b[A\r\x1b[K"; |
218 static char* playing_msg; | 222 static char *playing_msg; |
219 // seek: | 223 // seek: |
220 static double seek_to_sec; | 224 static double seek_to_sec; |
221 static off_t seek_to_byte; | 225 static off_t seek_to_byte; |
222 static off_t step_sec; | 226 static off_t step_sec; |
223 static int loop_seek; | 227 static int loop_seek; |
224 | 228 |
225 static m_time_size_t end_at = { .type = END_AT_NONE, .pos = 0 }; | 229 static m_time_size_t end_at = { .type = END_AT_NONE, .pos = 0 }; |
226 | 230 |
227 // A/V sync: | 231 // A/V sync: |
228 int autosync; // 30 might be a good default value. | 232 int autosync; // 30 might be a good default value. |
229 | 233 |
230 // may be changed by GUI: (FIXME!) | 234 // may be changed by GUI: (FIXME!) |
231 float rel_seek_secs; | 235 float rel_seek_secs; |
232 int abs_seek_pos; | 236 int abs_seek_pos; |
233 | 237 |
236 char **video_codec_list; // override video codec | 240 char **video_codec_list; // override video codec |
237 char **audio_fm_list; // override audio codec family | 241 char **audio_fm_list; // override audio codec family |
238 char **video_fm_list; // override video codec family | 242 char **video_fm_list; // override video codec family |
239 | 243 |
240 // streaming: | 244 // streaming: |
241 int audio_id=-1; | 245 int audio_id = -1; |
242 int video_id=-1; | 246 int video_id = -1; |
243 int dvdsub_id=-1; | 247 int dvdsub_id = -1; |
244 // this dvdsub_id was selected via slang | 248 // this dvdsub_id was selected via slang |
245 // use this to allow dvdnav to follow -slang across stream resets, | 249 // use this to allow dvdnav to follow -slang across stream resets, |
246 // in particular the subtitle ID for a language changes | 250 // in particular the subtitle ID for a language changes |
247 int dvdsub_lang_id; | 251 int dvdsub_lang_id; |
248 int vobsub_id=-1; | 252 int vobsub_id = -1; |
249 char* audio_lang; | 253 char *audio_lang; |
250 char* dvdsub_lang; | 254 char *dvdsub_lang; |
251 static char* spudec_ifo; | 255 static char *spudec_ifo; |
252 char* filename; | 256 char *filename; |
253 int forced_subs_only; | 257 int forced_subs_only; |
254 int file_filter=1; | 258 int file_filter = 1; |
255 | 259 |
256 // cache2: | 260 // cache2: |
257 int stream_cache_size=-1; | 261 int stream_cache_size = -1; |
258 #ifdef CONFIG_STREAM_CACHE | 262 #ifdef CONFIG_STREAM_CACHE |
259 float stream_cache_min_percent=20.0; | 263 float stream_cache_min_percent = 20.0; |
260 float stream_cache_seek_min_percent=50.0; | 264 float stream_cache_seek_min_percent = 50.0; |
261 #endif | 265 #endif |
262 | 266 |
263 // dump: | 267 // dump: |
264 char *stream_dump_name = "stream.dump"; | 268 char *stream_dump_name = "stream.dump"; |
265 int stream_dump_type; | 269 int stream_dump_type; |
266 int capture_dump; | 270 int capture_dump; |
267 | 271 |
268 // A-V sync: | 272 // A-V sync: |
269 static float default_max_pts_correction=-1; | 273 static float default_max_pts_correction = -1; |
270 static float max_pts_correction;//default_max_pts_correction; | 274 static float max_pts_correction; //default_max_pts_correction; |
271 static float c_total; | 275 static float c_total; |
272 float audio_delay; | 276 float audio_delay; |
273 static int ignore_start; | 277 static int ignore_start; |
274 | 278 |
275 static int softsleep; | 279 static int softsleep; |
276 | 280 |
277 double force_fps; | 281 double force_fps; |
278 static int force_srate; | 282 static int force_srate; |
279 static int audio_output_format=-1; // AF_FORMAT_UNKNOWN | 283 static int audio_output_format = -1; // AF_FORMAT_UNKNOWN |
280 int frame_dropping; // option 0=no drop 1= drop vo 2= drop decode | 284 int frame_dropping; // option 0=no drop 1= drop vo 2= drop decode |
281 static int play_n_frames=-1; | 285 static int play_n_frames = -1; |
282 static int play_n_frames_mf=-1; | 286 static int play_n_frames_mf = -1; |
283 | 287 |
284 // screen info: | 288 // screen info: |
285 char** video_driver_list; | 289 char **video_driver_list; |
286 char** audio_driver_list; | 290 char **audio_driver_list; |
287 | 291 |
288 // sub: | 292 // sub: |
289 char *font_name; | 293 char *font_name; |
290 char *sub_font_name; | 294 char *sub_font_name; |
291 float font_factor=0.75; | 295 float font_factor = 0.75; |
292 char **sub_name; | 296 char **sub_name; |
293 char **sub_paths; | 297 char **sub_paths; |
294 float sub_delay; | 298 float sub_delay; |
295 float sub_fps; | 299 float sub_fps; |
296 int sub_auto = 1; | 300 int sub_auto = 1; |
297 char *vobsub_name; | 301 char *vobsub_name; |
298 int subcc_enabled; | 302 int subcc_enabled; |
299 int suboverlap_enabled = 1; | 303 int suboverlap_enabled = 1; |
300 | 304 |
301 char* current_module; // for debugging | 305 char *current_module; // for debugging |
302 | |
303 | 306 |
304 #ifdef CONFIG_MENU | 307 #ifdef CONFIG_MENU |
305 static const vf_info_t* const libmenu_vfs[] = { | 308 static const vf_info_t *const libmenu_vfs[] = { |
306 &vf_info_menu, | 309 &vf_info_menu, |
307 NULL | 310 NULL |
308 }; | 311 }; |
309 static vf_instance_t* vf_menu; | 312 static vf_instance_t *vf_menu; |
310 int use_menu; | 313 int use_menu; |
311 static char* menu_cfg; | 314 static char *menu_cfg; |
312 static char* menu_root = "main"; | 315 static char *menu_root = "main"; |
313 #endif | 316 #endif |
314 | |
315 | 317 |
316 #ifdef HAVE_RTC | 318 #ifdef HAVE_RTC |
317 static int nortc = 1; | 319 static int nortc = 1; |
318 static char* rtc_device; | 320 static char *rtc_device; |
319 #endif | 321 #endif |
320 | 322 |
321 edl_record_ptr edl_records; ///< EDL entries memory area | 323 edl_record_ptr edl_records; ///< EDL entries memory area |
322 edl_record_ptr next_edl_record; ///< only for traversing edl_records | 324 edl_record_ptr next_edl_record; ///< only for traversing edl_records |
323 short edl_decision; ///< 1 when an EDL operation has been made. | 325 short edl_decision; ///< 1 when an EDL operation has been made. |
324 short edl_needs_reset; ///< 1 if we need to reset EDL next pointer | 326 short edl_needs_reset; ///< 1 if we need to reset EDL next pointer |
325 short edl_backward; ///< 1 if we need to skip to the beginning of the next EDL record | 327 short edl_backward; ///< 1 if we need to skip to the beginning of the next EDL record |
326 FILE* edl_fd; ///< fd to write to when in -edlout mode. | 328 FILE *edl_fd; ///< fd to write to when in -edlout mode. |
327 // Number of seconds to add to the seek when jumping out | 329 // Number of seconds to add to the seek when jumping out |
328 // of EDL scene in backward direction. This is needed to | 330 // of EDL scene in backward direction. This is needed to |
329 // have some time after the seek to decide what to do next | 331 // have some time after the seek to decide what to do next |
330 // (next seek, pause,...), otherwise after the seek it will | 332 // (next seek, pause,...), otherwise after the seek it will |
331 // enter the same scene again and skip forward immediately | 333 // enter the same scene again and skip forward immediately |
344 #endif | 346 #endif |
345 | 347 |
346 /* This header requires all the global variable declarations. */ | 348 /* This header requires all the global variable declarations. */ |
347 #include "cfg-mplayer.h" | 349 #include "cfg-mplayer.h" |
348 | 350 |
349 | |
350 const void *mpctx_get_video_out(MPContext *mpctx) | 351 const void *mpctx_get_video_out(MPContext *mpctx) |
351 { | 352 { |
352 return mpctx->video_out; | 353 return mpctx->video_out; |
353 } | 354 } |
354 | 355 |
380 int mpctx_get_osd_function(MPContext *mpctx) | 381 int mpctx_get_osd_function(MPContext *mpctx) |
381 { | 382 { |
382 return mpctx->osd_function; | 383 return mpctx->osd_function; |
383 } | 384 } |
384 | 385 |
385 static int is_valid_metadata_type (metadata_t type) { | 386 static int is_valid_metadata_type(metadata_t type) |
386 switch (type) | 387 { |
387 { | 388 switch (type) { |
388 /* check for valid video stream */ | 389 /* check for valid video stream */ |
389 case META_VIDEO_CODEC: | 390 case META_VIDEO_CODEC: |
390 case META_VIDEO_BITRATE: | 391 case META_VIDEO_BITRATE: |
391 case META_VIDEO_RESOLUTION: | 392 case META_VIDEO_RESOLUTION: |
392 if (!mpctx->sh_video) | 393 if (!mpctx->sh_video) |
393 return 0; | 394 return 0; |
394 break; | 395 break; |
395 | 396 |
396 /* check for valid audio stream */ | 397 /* check for valid audio stream */ |
397 case META_AUDIO_CODEC: | 398 case META_AUDIO_CODEC: |
398 case META_AUDIO_BITRATE: | 399 case META_AUDIO_BITRATE: |
399 case META_AUDIO_SAMPLES: | 400 case META_AUDIO_SAMPLES: |
400 if (!mpctx->sh_audio) | 401 if (!mpctx->sh_audio) |
401 return 0; | 402 return 0; |
402 break; | 403 break; |
403 | 404 |
404 /* check for valid demuxer */ | 405 /* check for valid demuxer */ |
405 case META_INFO_TITLE: | 406 case META_INFO_TITLE: |
406 case META_INFO_ARTIST: | 407 case META_INFO_ARTIST: |
407 case META_INFO_ALBUM: | 408 case META_INFO_ALBUM: |
408 case META_INFO_YEAR: | 409 case META_INFO_YEAR: |
409 case META_INFO_COMMENT: | 410 case META_INFO_COMMENT: |
410 case META_INFO_TRACK: | 411 case META_INFO_TRACK: |
411 case META_INFO_GENRE: | 412 case META_INFO_GENRE: |
412 if (!mpctx->demuxer) | 413 if (!mpctx->demuxer) |
413 return 0; | 414 return 0; |
414 break; | 415 break; |
415 | 416 |
416 default: | 417 default: |
417 break; | 418 break; |
418 } | 419 } |
419 | 420 |
420 return 1; | 421 return 1; |
421 } | 422 } |
422 | 423 |
423 static char *get_demuxer_info (char *tag) { | 424 static char *get_demuxer_info(char *tag) |
424 char **info = mpctx->demuxer->info; | 425 { |
425 int n; | 426 char **info = mpctx->demuxer->info; |
426 | 427 int n; |
427 if (!info || !tag) | 428 |
429 if (!info || !tag) | |
430 return NULL; | |
431 | |
432 for (n = 0; info[2 * n] != NULL; n++) | |
433 if (!strcasecmp(info[2 * n], tag)) | |
434 break; | |
435 | |
436 return info[2 * n + 1] ? strdup(info[2 * n + 1]) : NULL; | |
437 } | |
438 | |
439 char *get_metadata(metadata_t type) | |
440 { | |
441 sh_audio_t *const sh_audio = mpctx->sh_audio; | |
442 sh_video_t *const sh_video = mpctx->sh_video; | |
443 | |
444 if (!is_valid_metadata_type(type)) | |
445 return NULL; | |
446 | |
447 switch (type) { | |
448 case META_NAME: | |
449 return strdup(mp_basename(filename)); | |
450 | |
451 case META_VIDEO_CODEC: | |
452 if (sh_video->format == 0x10000001) | |
453 return strdup("mpeg1"); | |
454 else if (sh_video->format == 0x10000002) | |
455 return strdup("mpeg2"); | |
456 else if (sh_video->format == 0x10000004) | |
457 return strdup("mpeg4"); | |
458 else if (sh_video->format == 0x10000005) | |
459 return strdup("h264"); | |
460 else if (sh_video->format >= 0x20202020) | |
461 return mp_asprintf("%.4s", (char *)&sh_video->format); | |
462 return mp_asprintf("0x%08X", sh_video->format); | |
463 | |
464 case META_VIDEO_BITRATE: | |
465 return mp_asprintf("%d kbps", (int)(sh_video->i_bps * 8 / 1024)); | |
466 | |
467 case META_VIDEO_RESOLUTION: | |
468 return mp_asprintf("%d x %d", sh_video->disp_w, sh_video->disp_h); | |
469 | |
470 case META_AUDIO_CODEC: | |
471 if (sh_audio->codec && sh_audio->codec->name) | |
472 return strdup(sh_audio->codec->name); | |
473 break; | |
474 | |
475 case META_AUDIO_BITRATE: | |
476 return mp_asprintf("%d kbps", (int)(sh_audio->i_bps * 8 / 1000)); | |
477 | |
478 case META_AUDIO_SAMPLES: | |
479 return mp_asprintf("%d Hz, %d ch.", sh_audio->samplerate, sh_audio->channels); | |
480 | |
481 /* check for valid demuxer */ | |
482 case META_INFO_TITLE: | |
483 return get_demuxer_info("Title"); | |
484 | |
485 case META_INFO_ARTIST: | |
486 return get_demuxer_info("Artist"); | |
487 | |
488 case META_INFO_ALBUM: | |
489 return get_demuxer_info("Album"); | |
490 | |
491 case META_INFO_YEAR: | |
492 return get_demuxer_info("Year"); | |
493 | |
494 case META_INFO_COMMENT: | |
495 return get_demuxer_info("Comment"); | |
496 | |
497 case META_INFO_TRACK: | |
498 return get_demuxer_info("Track"); | |
499 | |
500 case META_INFO_GENRE: | |
501 return get_demuxer_info("Genre"); | |
502 | |
503 default: | |
504 break; | |
505 } | |
506 | |
428 return NULL; | 507 return NULL; |
429 | |
430 for (n = 0; info[2*n] != NULL ; n++) | |
431 if (!strcasecmp (info[2*n], tag)) | |
432 break; | |
433 | |
434 return info[2*n+1] ? strdup (info[2*n+1]) : NULL; | |
435 } | |
436 | |
437 char *get_metadata (metadata_t type) { | |
438 sh_audio_t * const sh_audio = mpctx->sh_audio; | |
439 sh_video_t * const sh_video = mpctx->sh_video; | |
440 | |
441 if (!is_valid_metadata_type (type)) | |
442 return NULL; | |
443 | |
444 switch (type) | |
445 { | |
446 case META_NAME: | |
447 return strdup(mp_basename(filename)); | |
448 | |
449 case META_VIDEO_CODEC: | |
450 if (sh_video->format == 0x10000001) | |
451 return strdup("mpeg1"); | |
452 else if (sh_video->format == 0x10000002) | |
453 return strdup("mpeg2"); | |
454 else if (sh_video->format == 0x10000004) | |
455 return strdup("mpeg4"); | |
456 else if (sh_video->format == 0x10000005) | |
457 return strdup("h264"); | |
458 else if (sh_video->format >= 0x20202020) | |
459 return mp_asprintf("%.4s", (char *)&sh_video->format); | |
460 return mp_asprintf("0x%08X", sh_video->format); | |
461 | |
462 case META_VIDEO_BITRATE: | |
463 return mp_asprintf("%d kbps", (int)(sh_video->i_bps * 8 / 1024)); | |
464 | |
465 case META_VIDEO_RESOLUTION: | |
466 return mp_asprintf("%d x %d", sh_video->disp_w, sh_video->disp_h); | |
467 | |
468 case META_AUDIO_CODEC: | |
469 if (sh_audio->codec && sh_audio->codec->name) | |
470 return strdup(sh_audio->codec->name); | |
471 break; | |
472 | |
473 case META_AUDIO_BITRATE: | |
474 return mp_asprintf("%d kbps", (int)(sh_audio->i_bps * 8 / 1000)); | |
475 | |
476 case META_AUDIO_SAMPLES: | |
477 return mp_asprintf("%d Hz, %d ch.", sh_audio->samplerate, sh_audio->channels); | |
478 | |
479 /* check for valid demuxer */ | |
480 case META_INFO_TITLE: | |
481 return get_demuxer_info ("Title"); | |
482 | |
483 case META_INFO_ARTIST: | |
484 return get_demuxer_info ("Artist"); | |
485 | |
486 case META_INFO_ALBUM: | |
487 return get_demuxer_info ("Album"); | |
488 | |
489 case META_INFO_YEAR: | |
490 return get_demuxer_info ("Year"); | |
491 | |
492 case META_INFO_COMMENT: | |
493 return get_demuxer_info ("Comment"); | |
494 | |
495 case META_INFO_TRACK: | |
496 return get_demuxer_info ("Track"); | |
497 | |
498 case META_INFO_GENRE: | |
499 return get_demuxer_info ("Genre"); | |
500 | |
501 default: | |
502 break; | |
503 } | |
504 | |
505 return NULL; | |
506 } | 508 } |
507 | 509 |
508 static void print_file_properties(const MPContext *mpctx, const char *filename) | 510 static void print_file_properties(const MPContext *mpctx, const char *filename) |
509 { | 511 { |
510 double video_start_pts = MP_NOPTS_VALUE; | 512 double video_start_pts = MP_NOPTS_VALUE; |
511 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_FILENAME=%s\n", | 513 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILENAME=%s\n", |
512 filename_recode(filename)); | 514 filename_recode(filename)); |
513 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_DEMUXER=%s\n", mpctx->demuxer->desc->name); | 515 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_DEMUXER=%s\n", mpctx->demuxer->desc->name); |
514 if (mpctx->sh_video) { | 516 if (mpctx->sh_video) { |
515 /* Assume FOURCC if all bytes >= 0x20 (' ') */ | 517 /* Assume FOURCC if all bytes >= 0x20 (' ') */ |
516 if (mpctx->sh_video->format >= 0x20202020) | 518 if (mpctx->sh_video->format >= 0x20202020) |
517 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FORMAT=%.4s\n", (char *)&mpctx->sh_video->format); | 519 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_FORMAT=%.4s\n", (char *)&mpctx->sh_video->format); |
520 else | |
521 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_FORMAT=0x%08X\n", mpctx->sh_video->format); | |
522 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_BITRATE=%d\n", mpctx->sh_video->i_bps * 8); | |
523 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_WIDTH=%d\n", mpctx->sh_video->disp_w); | |
524 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_HEIGHT=%d\n", mpctx->sh_video->disp_h); | |
525 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_FPS=%5.3f\n", mpctx->sh_video->fps); | |
526 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ASPECT=%1.4f\n", mpctx->sh_video->aspect); | |
527 video_start_pts = ds_get_next_pts(mpctx->d_video); | |
528 } | |
529 if (mpctx->sh_audio) { | |
530 /* Assume FOURCC if all bytes >= 0x20 (' ') */ | |
531 if (mpctx->sh_audio->format >= 0x20202020) | |
532 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", (char *)&mpctx->sh_audio->format); | |
533 else | |
534 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_FORMAT=%d\n", mpctx->sh_audio->format); | |
535 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_BITRATE=%d\n", mpctx->sh_audio->i_bps * 8); | |
536 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_RATE=%d\n", mpctx->sh_audio->samplerate); | |
537 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_NCH=%d\n", mpctx->sh_audio->channels); | |
538 start_pts = ds_get_next_pts(mpctx->d_audio); | |
539 } | |
540 if (video_start_pts != MP_NOPTS_VALUE) { | |
541 if (start_pts == MP_NOPTS_VALUE || !mpctx->sh_audio || | |
542 (mpctx->sh_video && video_start_pts < start_pts)) | |
543 start_pts = video_start_pts; | |
544 } | |
545 if (start_pts != MP_NOPTS_VALUE) | |
546 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_START_TIME=%.2f\n", start_pts); | |
518 else | 547 else |
519 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FORMAT=0x%08X\n", mpctx->sh_video->format); | 548 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_START_TIME=unknown\n"); |
520 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_BITRATE=%d\n", mpctx->sh_video->i_bps*8); | 549 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_LENGTH=%.2f\n", demuxer_get_time_length(mpctx->demuxer)); |
521 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", mpctx->sh_video->disp_w); | 550 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SEEKABLE=%d\n", |
522 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", mpctx->sh_video->disp_h); | 551 mpctx->stream->seek && (!mpctx->demuxer || mpctx->demuxer->seekable)); |
523 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FPS=%5.3f\n", mpctx->sh_video->fps); | 552 if (mpctx->demuxer) { |
524 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_ASPECT=%1.4f\n", mpctx->sh_video->aspect); | 553 if (mpctx->demuxer->num_chapters == 0) |
525 video_start_pts = ds_get_next_pts(mpctx->d_video); | 554 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters); |
526 } | 555 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CHAPTERS=%d\n", mpctx->demuxer->num_chapters); |
527 if (mpctx->sh_audio) { | 556 } |
528 /* Assume FOURCC if all bytes >= 0x20 (' ') */ | |
529 if (mpctx->sh_audio->format >= 0x20202020) | |
530 mp_msg(MSGT_IDENTIFY,MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", (char *)&mpctx->sh_audio->format); | |
531 else | |
532 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_FORMAT=%d\n", mpctx->sh_audio->format); | |
533 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_BITRATE=%d\n", mpctx->sh_audio->i_bps*8); | |
534 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_RATE=%d\n", mpctx->sh_audio->samplerate); | |
535 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_NCH=%d\n", mpctx->sh_audio->channels); | |
536 start_pts = ds_get_next_pts(mpctx->d_audio); | |
537 } | |
538 if (video_start_pts != MP_NOPTS_VALUE) { | |
539 if (start_pts == MP_NOPTS_VALUE || !mpctx->sh_audio || | |
540 (mpctx->sh_video && video_start_pts < start_pts)) | |
541 start_pts = video_start_pts; | |
542 } | |
543 if (start_pts != MP_NOPTS_VALUE) | |
544 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_START_TIME=%.2f\n", start_pts); | |
545 else | |
546 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_START_TIME=unknown\n"); | |
547 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_LENGTH=%.2f\n", demuxer_get_time_length(mpctx->demuxer)); | |
548 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_SEEKABLE=%d\n", | |
549 mpctx->stream->seek && (!mpctx->demuxer || mpctx->demuxer->seekable)); | |
550 if (mpctx->demuxer) { | |
551 if (mpctx->demuxer->num_chapters == 0) | |
552 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters); | |
553 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_CHAPTERS=%d\n", mpctx->demuxer->num_chapters); | |
554 } | |
555 } | 557 } |
556 | 558 |
557 #ifdef CONFIG_DVDNAV | 559 #ifdef CONFIG_DVDNAV |
558 static void mp_dvdnav_context_free(MPContext *ctx){ | 560 static void mp_dvdnav_context_free(MPContext *ctx) |
559 if (ctx->nav_smpi) free_mp_image(ctx->nav_smpi); | 561 { |
562 if (ctx->nav_smpi) | |
563 free_mp_image(ctx->nav_smpi); | |
560 ctx->nav_smpi = NULL; | 564 ctx->nav_smpi = NULL; |
561 free(ctx->nav_buffer); | 565 free(ctx->nav_buffer); |
562 ctx->nav_buffer = NULL; | 566 ctx->nav_buffer = NULL; |
563 ctx->nav_start = NULL; | 567 ctx->nav_start = NULL; |
564 ctx->nav_in_size = 0; | 568 ctx->nav_in_size = 0; |
565 } | 569 } |
566 #endif | 570 |
567 | 571 #endif |
568 void uninit_player(unsigned int mask){ | 572 |
569 mask &= initialized_flags; | 573 void uninit_player(unsigned int mask) |
570 | 574 { |
571 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask); | 575 mask &= initialized_flags; |
572 | 576 |
573 if(mask&INITIALIZED_ACODEC){ | 577 mp_msg(MSGT_CPLAYER, MSGL_DBG2, "\n*** uninit(0x%X)\n", mask); |
574 initialized_flags&=~INITIALIZED_ACODEC; | 578 |
575 current_module="uninit_acodec"; | 579 if (mask & INITIALIZED_ACODEC) { |
576 if(mpctx->sh_audio) uninit_audio(mpctx->sh_audio); | 580 initialized_flags &= ~INITIALIZED_ACODEC; |
581 current_module = "uninit_acodec"; | |
582 if (mpctx->sh_audio) | |
583 uninit_audio(mpctx->sh_audio); | |
577 #ifdef CONFIG_GUI | 584 #ifdef CONFIG_GUI |
578 if (use_gui) guiGetEvent(guiSetAfilter, (char *)NULL); | 585 if (use_gui) |
579 #endif | 586 guiGetEvent(guiSetAfilter, (char *)NULL); |
580 mpctx->sh_audio=NULL; | 587 #endif |
581 mpctx->mixer.afilter = NULL; | 588 mpctx->sh_audio = NULL; |
582 } | 589 mpctx->mixer.afilter = NULL; |
583 | 590 } |
584 if(mask&INITIALIZED_VCODEC){ | 591 |
585 initialized_flags&=~INITIALIZED_VCODEC; | 592 if (mask & INITIALIZED_VCODEC) { |
586 current_module="uninit_vcodec"; | 593 initialized_flags &= ~INITIALIZED_VCODEC; |
587 if(mpctx->sh_video) uninit_video(mpctx->sh_video); | 594 current_module = "uninit_vcodec"; |
588 mpctx->sh_video=NULL; | 595 if (mpctx->sh_video) |
596 uninit_video(mpctx->sh_video); | |
597 mpctx->sh_video = NULL; | |
589 #ifdef CONFIG_MENU | 598 #ifdef CONFIG_MENU |
590 vf_menu=NULL; | 599 vf_menu = NULL; |
591 #endif | 600 #endif |
592 } | 601 } |
593 | 602 |
594 if(mask&INITIALIZED_DEMUXER){ | 603 if (mask & INITIALIZED_DEMUXER) { |
595 initialized_flags&=~INITIALIZED_DEMUXER; | 604 initialized_flags &= ~INITIALIZED_DEMUXER; |
596 current_module="free_demuxer"; | 605 current_module = "free_demuxer"; |
597 if(mpctx->demuxer){ | 606 if (mpctx->demuxer) { |
598 mpctx->stream=mpctx->demuxer->stream; | 607 mpctx->stream = mpctx->demuxer->stream; |
599 free_demuxer(mpctx->demuxer); | 608 free_demuxer(mpctx->demuxer); |
600 } | 609 } |
601 mpctx->demuxer=NULL; | 610 mpctx->demuxer = NULL; |
602 } | 611 } |
603 | 612 |
604 // kill the cache process: | 613 // kill the cache process: |
605 if(mask&INITIALIZED_STREAM){ | 614 if (mask & INITIALIZED_STREAM) { |
606 initialized_flags&=~INITIALIZED_STREAM; | 615 initialized_flags &= ~INITIALIZED_STREAM; |
607 current_module="uninit_stream"; | 616 current_module = "uninit_stream"; |
608 if(mpctx->stream) free_stream(mpctx->stream); | 617 if (mpctx->stream) |
609 mpctx->stream=NULL; | 618 free_stream(mpctx->stream); |
610 } | 619 mpctx->stream = NULL; |
611 | 620 } |
612 if(mask&INITIALIZED_VO){ | 621 |
613 initialized_flags&=~INITIALIZED_VO; | 622 if (mask & INITIALIZED_VO) { |
614 current_module="uninit_vo"; | 623 initialized_flags &= ~INITIALIZED_VO; |
615 mpctx->video_out->uninit(); | 624 current_module = "uninit_vo"; |
616 mpctx->video_out=NULL; | 625 mpctx->video_out->uninit(); |
626 mpctx->video_out = NULL; | |
617 #ifdef CONFIG_DVDNAV | 627 #ifdef CONFIG_DVDNAV |
618 mp_dvdnav_context_free(mpctx); | 628 mp_dvdnav_context_free(mpctx); |
619 #endif | 629 #endif |
620 if (vo_spudec){ | 630 if (vo_spudec) { |
621 current_module="uninit_spudec"; | 631 current_module = "uninit_spudec"; |
622 spudec_free(vo_spudec); | 632 spudec_free(vo_spudec); |
623 vo_spudec=NULL; | 633 vo_spudec = NULL; |
624 } | 634 } |
625 } | 635 } |
626 | 636 |
627 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code. | 637 // Must be after libvo uninit, as few vo drivers (svgalib) have tty code. |
628 if(mask&INITIALIZED_GETCH2){ | 638 if (mask & INITIALIZED_GETCH2) { |
629 initialized_flags&=~INITIALIZED_GETCH2; | 639 initialized_flags &= ~INITIALIZED_GETCH2; |
630 current_module="uninit_getch2"; | 640 current_module = "uninit_getch2"; |
631 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n"); | 641 mp_msg(MSGT_CPLAYER, MSGL_DBG2, "\n[[[uninit getch2]]]\n"); |
632 // restore terminal: | 642 // restore terminal: |
633 getch2_disable(); | 643 getch2_disable(); |
634 } | 644 } |
635 | 645 |
636 if (mask & INITIALIZED_SUBS) { | 646 if (mask & INITIALIZED_SUBS) { |
637 initialized_flags &= ~INITIALIZED_SUBS; | 647 initialized_flags &= ~INITIALIZED_SUBS; |
638 if (mpctx->set_of_sub_size > 0) { | 648 if (mpctx->set_of_sub_size > 0) { |
639 int i; | 649 int i; |
640 current_module="sub_free"; | 650 current_module = "sub_free"; |
641 for (i = 0; i < mpctx->set_of_sub_size; ++i) { | 651 for (i = 0; i < mpctx->set_of_sub_size; ++i) { |
642 sub_free(mpctx->set_of_subtitles[i]); | 652 sub_free(mpctx->set_of_subtitles[i]); |
643 #ifdef CONFIG_ASS | 653 #ifdef CONFIG_ASS |
644 if (mpctx->set_of_ass_tracks[i]) | 654 if (mpctx->set_of_ass_tracks[i]) |
645 ass_free_track(mpctx->set_of_ass_tracks[i]); | 655 ass_free_track(mpctx->set_of_ass_tracks[i]); |
646 #endif | 656 #endif |
647 } | 657 } |
648 mpctx->set_of_sub_size = 0; | 658 mpctx->set_of_sub_size = 0; |
649 } | 659 } |
650 vo_sub_last = vo_sub= NULL; | 660 vo_sub_last = vo_sub = NULL; |
651 subdata = NULL; | 661 subdata = NULL; |
652 #ifdef CONFIG_ASS | 662 #ifdef CONFIG_ASS |
653 ass_track = NULL; | 663 ass_track = NULL; |
654 if (ass_library) | 664 if (ass_library) |
655 ass_clear_fonts(ass_library); | 665 ass_clear_fonts(ass_library); |
656 #endif | 666 #endif |
657 } | 667 } |
658 | 668 |
659 if(mask&INITIALIZED_VOBSUB){ | 669 if (mask & INITIALIZED_VOBSUB) { |
660 initialized_flags&=~INITIALIZED_VOBSUB; | 670 initialized_flags &= ~INITIALIZED_VOBSUB; |
661 current_module="uninit_vobsub"; | 671 current_module = "uninit_vobsub"; |
662 if(vo_vobsub) vobsub_close(vo_vobsub); | 672 if (vo_vobsub) |
663 vo_vobsub=NULL; | 673 vobsub_close(vo_vobsub); |
664 } | 674 vo_vobsub = NULL; |
665 | 675 } |
666 if(mask&INITIALIZED_AO){ | 676 |
667 initialized_flags&=~INITIALIZED_AO; | 677 if (mask & INITIALIZED_AO) { |
668 current_module="uninit_ao"; | 678 initialized_flags &= ~INITIALIZED_AO; |
669 if (mpctx->edl_muted) mixer_mute(&mpctx->mixer); | 679 current_module = "uninit_ao"; |
670 if (mpctx->audio_out) mpctx->audio_out->uninit(mpctx->eof?0:1); | 680 if (mpctx->edl_muted) |
671 mpctx->audio_out=NULL; | 681 mixer_mute(&mpctx->mixer); |
672 } | 682 if (mpctx->audio_out) |
683 mpctx->audio_out->uninit(mpctx->eof ? 0 : 1); | |
684 mpctx->audio_out = NULL; | |
685 } | |
673 | 686 |
674 #ifdef CONFIG_GUI | 687 #ifdef CONFIG_GUI |
675 if(mask&INITIALIZED_GUI){ | 688 if (mask & INITIALIZED_GUI) { |
676 initialized_flags&=~INITIALIZED_GUI; | 689 initialized_flags &= ~INITIALIZED_GUI; |
677 current_module="uninit_gui"; | 690 current_module = "uninit_gui"; |
678 guiDone(); | 691 guiDone(); |
679 } | 692 } |
680 #endif | 693 #endif |
681 | 694 |
682 if(mask&INITIALIZED_INPUT){ | 695 if (mask & INITIALIZED_INPUT) { |
683 initialized_flags&=~INITIALIZED_INPUT; | 696 initialized_flags &= ~INITIALIZED_INPUT; |
684 current_module="uninit_input"; | 697 current_module = "uninit_input"; |
685 mp_input_uninit(); | 698 mp_input_uninit(); |
686 #ifdef CONFIG_MENU | 699 #ifdef CONFIG_MENU |
687 if (use_menu) | 700 if (use_menu) |
688 menu_uninit(); | 701 menu_uninit(); |
689 #endif | 702 #endif |
690 } | 703 } |
691 | 704 |
692 current_module=NULL; | 705 current_module = NULL; |
693 } | 706 } |
694 | 707 |
695 void exit_player_with_rc(enum exit_reason how, int rc) | 708 void exit_player_with_rc(enum exit_reason how, int rc) |
696 { | 709 { |
697 | |
698 #ifdef CONFIG_NETWORKING | 710 #ifdef CONFIG_NETWORKING |
699 if (udp_master) | 711 if (udp_master) |
700 send_udp(udp_ip, udp_port, "bye"); | 712 send_udp(udp_ip, udp_port, "bye"); |
701 #endif /* CONFIG_NETWORKING */ | 713 #endif /* CONFIG_NETWORKING */ |
702 | 714 |
703 if (mpctx->user_muted && !mpctx->edl_muted) mixer_mute(&mpctx->mixer); | 715 if (mpctx->user_muted && !mpctx->edl_muted) |
704 uninit_player(INITIALIZED_ALL); | 716 mixer_mute(&mpctx->mixer); |
717 uninit_player(INITIALIZED_ALL); | |
705 #if defined(__MINGW32__) || defined(__CYGWIN__) | 718 #if defined(__MINGW32__) || defined(__CYGWIN__) |
706 timeEndPeriod(1); | 719 timeEndPeriod(1); |
707 #endif | 720 #endif |
708 #ifdef CONFIG_X11 | 721 #ifdef CONFIG_X11 |
709 #ifdef CONFIG_GUI | 722 #ifdef CONFIG_GUI |
710 if ( !use_gui ) | 723 if (!use_gui) |
711 #endif | 724 #endif |
712 vo_uninit(); // Close the X11 connection (if any is open). | 725 vo_uninit(); // Close the X11 connection (if any is open). |
713 #endif | 726 #endif |
714 | 727 |
715 #ifdef CONFIG_FREETYPE | 728 #ifdef CONFIG_FREETYPE |
716 current_module="uninit_font"; | 729 current_module = "uninit_font"; |
717 if (sub_font && sub_font != vo_font) free_font_desc(sub_font); | 730 if (sub_font && sub_font != vo_font) |
718 sub_font = NULL; | 731 free_font_desc(sub_font); |
719 if (vo_font) free_font_desc(vo_font); | 732 sub_font = NULL; |
720 vo_font = NULL; | 733 if (vo_font) |
721 done_freetype(); | 734 free_font_desc(vo_font); |
722 #endif | 735 vo_font = NULL; |
723 free_osd_list(); | 736 done_freetype(); |
737 #endif | |
738 free_osd_list(); | |
724 | 739 |
725 #ifdef CONFIG_ASS | 740 #ifdef CONFIG_ASS |
726 ass_library_done(ass_library); | 741 ass_library_done(ass_library); |
727 ass_library = NULL; | 742 ass_library = NULL; |
728 #endif | 743 #endif |
729 | 744 |
730 current_module="exit_player"; | 745 current_module = "exit_player"; |
731 | 746 |
732 if(mpctx->playtree_iter) | 747 if (mpctx->playtree_iter) |
733 play_tree_iter_free(mpctx->playtree_iter); | 748 play_tree_iter_free(mpctx->playtree_iter); |
734 mpctx->playtree_iter = NULL; | 749 mpctx->playtree_iter = NULL; |
735 if(mpctx->playtree) | 750 if (mpctx->playtree) |
736 play_tree_free(mpctx->playtree, 1); | 751 play_tree_free(mpctx->playtree, 1); |
737 mpctx->playtree = NULL; | 752 mpctx->playtree = NULL; |
738 | 753 |
739 | 754 free(edl_records); // free mem allocated for EDL |
740 free(edl_records); // free mem allocated for EDL | 755 edl_records = NULL; |
741 edl_records = NULL; | 756 switch (how) { |
742 switch(how) { | 757 case EXIT_QUIT: |
743 case EXIT_QUIT: | 758 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_ExitingHow, MSGTR_Exit_quit); |
744 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,MSGTR_Exit_quit); | 759 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=QUIT\n"); |
745 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=QUIT\n"); | 760 break; |
746 break; | 761 case EXIT_EOF: |
747 case EXIT_EOF: | 762 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_ExitingHow, MSGTR_Exit_eof); |
748 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,MSGTR_Exit_eof); | 763 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=EOF\n"); |
749 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=EOF\n"); | 764 break; |
750 break; | 765 case EXIT_ERROR: |
751 case EXIT_ERROR: | 766 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_ExitingHow, MSGTR_Exit_error); |
752 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,MSGTR_Exit_error); | 767 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=ERROR\n"); |
753 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=ERROR\n"); | 768 break; |
754 break; | 769 default: |
755 default: | 770 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=NONE\n"); |
756 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=NONE\n"); | 771 } |
757 } | 772 mp_msg(MSGT_CPLAYER, MSGL_DBG2, "max framesize was %d bytes\n", max_framesize); |
758 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize); | 773 |
759 | 774 // must be last since e.g. mp_msg uses option values |
760 // must be last since e.g. mp_msg uses option values | 775 // that will be freed by this. |
761 // that will be freed by this. | 776 if (mconfig) |
762 if(mconfig) | 777 m_config_free(mconfig); |
763 m_config_free(mconfig); | 778 mconfig = NULL; |
764 mconfig = NULL; | 779 |
765 | 780 exit(rc); |
766 exit(rc); | |
767 } | 781 } |
768 | 782 |
769 void exit_player(enum exit_reason how) | 783 void exit_player(enum exit_reason how) |
770 { | 784 { |
771 exit_player_with_rc(how, 1); | 785 exit_player_with_rc(how, 1); |
772 } | 786 } |
773 | 787 |
774 #ifndef __MINGW32__ | 788 #ifndef __MINGW32__ |
775 static void child_sighandler(int x){ | 789 static void child_sighandler(int x) |
776 pid_t pid; | 790 { |
777 while((pid=waitpid(-1,NULL,WNOHANG)) > 0); | 791 pid_t pid; |
778 } | 792 while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) ; |
779 #endif | 793 } |
780 | 794 |
781 static void exit_sighandler(int x){ | 795 #endif |
782 static int sig_count; | 796 |
797 static void exit_sighandler(int x) | |
798 { | |
799 static int sig_count; | |
783 #ifdef CONFIG_CRASH_DEBUG | 800 #ifdef CONFIG_CRASH_DEBUG |
784 if (!crash_debug || x != SIGTRAP) | 801 if (!crash_debug || x != SIGTRAP) |
785 #endif | 802 #endif |
786 ++sig_count; | 803 ++sig_count; |
787 if(initialized_flags==0 && sig_count>1) exit(1); | 804 if (initialized_flags == 0 && sig_count > 1) |
788 if(sig_count==5) | 805 exit(1); |
789 { | 806 if (sig_count == 5) { |
790 /* We're crashing bad and can't uninit cleanly :( | 807 /* We're crashing bad and can't uninit cleanly :( |
791 * by popular request, we make one last (dirty) | 808 * by popular request, we make one last (dirty) |
792 * effort to restore the user's | 809 * effort to restore the user's |
793 * terminal. */ | 810 * terminal. */ |
794 getch2_disable(); | 811 getch2_disable(); |
795 exit(1); | 812 exit(1); |
796 } | 813 } |
797 if(sig_count==6) exit(1); | 814 if (sig_count == 6) |
798 if(sig_count>6){ | 815 exit(1); |
799 // can't stop :( | 816 if (sig_count > 6) { |
817 // can't stop :( | |
800 #ifndef __MINGW32__ | 818 #ifndef __MINGW32__ |
801 kill(getpid(),SIGKILL); | 819 kill(getpid(), SIGKILL); |
802 #endif | 820 #endif |
803 } | 821 } |
804 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x, | 822 mp_msg(MSGT_CPLAYER, MSGL_FATAL, "\n" MSGTR_IntBySignal, x, |
805 current_module?current_module:"unknown" | 823 current_module ? current_module : "unknown" |
806 ); | 824 ); |
807 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SIGNAL=%d\n", x); | 825 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SIGNAL=%d\n", x); |
808 if(sig_count<=1) | 826 if (sig_count <= 1) |
809 switch(x){ | 827 switch (x) { |
810 case SIGINT: | 828 case SIGINT: |
811 case SIGPIPE: | 829 case SIGPIPE: |
812 case SIGQUIT: | 830 case SIGQUIT: |
813 case SIGTERM: | 831 case SIGTERM: |
814 case SIGKILL: | 832 case SIGKILL: |
815 async_quit_request = 1; | 833 async_quit_request = 1; |
816 return; // killed from keyboard (^C) or killed [-9] | 834 return; // killed from keyboard (^C) or killed [-9] |
817 case SIGILL: | 835 case SIGILL: |
818 #if CONFIG_RUNTIME_CPUDETECT | 836 #if CONFIG_RUNTIME_CPUDETECT |
819 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel); | 837 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_Exit_SIGILL_RTCpuSel); |
820 #else | 838 #else |
821 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL); | 839 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_Exit_SIGILL); |
822 #endif | 840 #endif |
823 case SIGFPE: | 841 case SIGFPE: |
824 case SIGSEGV: | 842 case SIGSEGV: |
825 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE); | 843 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_Exit_SIGSEGV_SIGFPE); |
826 default: | 844 default: |
827 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH); | 845 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_Exit_SIGCRASH); |
828 #ifdef CONFIG_CRASH_DEBUG | 846 #ifdef CONFIG_CRASH_DEBUG |
829 if (crash_debug) { | 847 if (crash_debug) { |
830 int gdb_pid; | 848 int gdb_pid; |
831 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forking...\n"); | 849 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forking...\n"); |
832 gdb_pid = fork(); | 850 gdb_pid = fork(); |
833 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forked...\n"); | 851 mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forked...\n"); |
834 if (gdb_pid == 0) { // We are the child | 852 if (gdb_pid == 0) { // We are the child |
835 char spid[20]; | 853 char spid[20]; |
836 snprintf(spid, sizeof(spid), "%i", getppid()); | 854 snprintf(spid, sizeof(spid), "%i", getppid()); |
837 getch2_disable(); // allow terminal to work properly with gdb | 855 getch2_disable(); // allow terminal to work properly with gdb |
838 if (execlp("gdb", "gdb", prog_path, spid, "-ex", "bt", NULL) == -1) | 856 if (execlp("gdb", "gdb", prog_path, spid, "-ex", "bt", NULL) == -1) |
839 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't start gdb\n"); | 857 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't start gdb\n"); |
840 } else if (gdb_pid < 0) | 858 } else if (gdb_pid < 0) |
841 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't fork\n"); | 859 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't fork\n"); |
842 else { | 860 else { |
843 waitpid(gdb_pid, NULL, 0); | 861 waitpid(gdb_pid, NULL, 0); |
844 } | 862 } |
845 if (x == SIGTRAP) return; | 863 if (x == SIGTRAP) |
846 } | 864 return; |
847 #endif | 865 } |
848 } | 866 #endif |
849 getch2_disable(); | 867 } |
850 exit(1); | 868 getch2_disable(); |
851 } | 869 exit(1); |
852 | 870 } |
853 static void parse_cfgfiles( m_config_t* conf ) | 871 |
854 { | 872 static void parse_cfgfiles(m_config_t *conf) |
855 char *conffile; | 873 { |
856 int conffile_fd; | 874 char *conffile; |
857 if (!disable_system_conf && | 875 int conffile_fd; |
858 m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0) | 876 if (!disable_system_conf && |
859 exit_player(EXIT_NONE); | 877 m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0) |
860 if ((conffile = get_path("")) == NULL) { | 878 exit_player(EXIT_NONE); |
861 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir); | 879 if ((conffile = get_path("")) == NULL) { |
862 } else { | 880 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_NoHomeDir); |
881 } else { | |
863 #ifdef __MINGW32__ | 882 #ifdef __MINGW32__ |
864 mkdir(conffile); | 883 mkdir(conffile); |
865 #else | 884 #else |
866 mkdir(conffile, 0777); | 885 mkdir(conffile, 0777); |
867 #endif | 886 #endif |
868 free(conffile); | 887 free(conffile); |
869 if ((conffile = get_path("config")) == NULL) { | 888 if ((conffile = get_path("config")) == NULL) { |
870 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem); | 889 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_GetpathProblem); |
871 } else { | 890 } else { |
872 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) { | 891 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) { |
873 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile); | 892 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CreatingCfgFile, conffile); |
874 write(conffile_fd, default_config, strlen(default_config)); | 893 write(conffile_fd, default_config, strlen(default_config)); |
875 close(conffile_fd); | 894 close(conffile_fd); |
876 } | 895 } |
877 if (!disable_user_conf && | 896 if (!disable_user_conf && |
878 m_config_parse_config_file(conf, conffile) < 0) | 897 m_config_parse_config_file(conf, conffile) < 0) |
879 exit_player(EXIT_NONE); | 898 exit_player(EXIT_NONE); |
880 free(conffile); | 899 free(conffile); |
881 } | 900 } |
882 } | 901 } |
883 } | 902 } |
884 | 903 |
885 #define PROFILE_CFG_PROTOCOL "protocol." | 904 #define PROFILE_CFG_PROTOCOL "protocol." |
886 | 905 |
887 static void load_per_protocol_config (m_config_t* conf, const char *const file) | 906 static void load_per_protocol_config(m_config_t *conf, const char *const file) |
888 { | 907 { |
889 char *str; | 908 char *str; |
890 char protocol[strlen (PROFILE_CFG_PROTOCOL) + strlen (file) + 1]; | 909 char protocol[strlen(PROFILE_CFG_PROTOCOL) + strlen(file) + 1]; |
891 m_profile_t *p; | 910 m_profile_t *p; |
892 | 911 |
893 /* does filename actually uses a protocol ? */ | 912 /* does filename actually uses a protocol ? */ |
894 str = strstr (file, "://"); | 913 str = strstr(file, "://"); |
895 if (!str) | 914 if (!str) |
896 return; | 915 return; |
897 | 916 |
898 sprintf (protocol, "%s%s", PROFILE_CFG_PROTOCOL, file); | 917 sprintf(protocol, "%s%s", PROFILE_CFG_PROTOCOL, file); |
899 protocol[strlen (PROFILE_CFG_PROTOCOL)+strlen(file)-strlen(str)] = '\0'; | 918 protocol[strlen(PROFILE_CFG_PROTOCOL) + strlen(file) - strlen(str)] = '\0'; |
900 p = m_config_get_profile (conf, protocol); | 919 p = m_config_get_profile(conf, protocol); |
901 if (p) | 920 if (p) { |
902 { | 921 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingProtocolProfile, protocol); |
903 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingProtocolProfile, protocol); | 922 m_config_set_profile(conf, p); |
904 m_config_set_profile(conf,p); | |
905 } | 923 } |
906 } | 924 } |
907 | 925 |
908 #define PROFILE_CFG_EXTENSION "extension." | 926 #define PROFILE_CFG_EXTENSION "extension." |
909 | 927 |
910 static void load_per_extension_config (m_config_t* conf, const char *const file) | 928 static void load_per_extension_config(m_config_t *conf, const char *const file) |
911 { | 929 { |
912 char *str; | 930 char *str; |
913 char extension[strlen (PROFILE_CFG_EXTENSION) + 8]; | 931 char extension[strlen(PROFILE_CFG_EXTENSION) + 8]; |
914 m_profile_t *p; | 932 m_profile_t *p; |
915 | 933 |
916 /* does filename actually have an extension ? */ | 934 /* does filename actually have an extension ? */ |
917 str = strrchr (filename, '.'); | 935 str = strrchr(filename, '.'); |
918 if (!str) | 936 if (!str) |
919 return; | 937 return; |
920 | 938 |
921 sprintf (extension, PROFILE_CFG_EXTENSION); | 939 sprintf(extension, PROFILE_CFG_EXTENSION); |
922 strncat (extension, ++str, 7); | 940 strncat(extension, ++str, 7); |
923 p = m_config_get_profile (conf, extension); | 941 p = m_config_get_profile(conf, extension); |
924 if (p) | 942 if (p) { |
925 { | 943 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingExtensionProfile, extension); |
926 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingExtensionProfile, extension); | 944 m_config_set_profile(conf, p); |
927 m_config_set_profile(conf,p); | |
928 } | 945 } |
929 } | 946 } |
930 | 947 |
931 #define PROFILE_CFG_VO "vo." | 948 #define PROFILE_CFG_VO "vo." |
932 #define PROFILE_CFG_AO "ao." | 949 #define PROFILE_CFG_AO "ao." |
933 | 950 |
934 static void load_per_output_config (m_config_t* conf, char *cfg, char *out) | 951 static void load_per_output_config(m_config_t *conf, char *cfg, char *out) |
935 { | 952 { |
936 char profile[strlen (cfg) + strlen (out) + 1]; | 953 char profile[strlen(cfg) + strlen(out) + 1]; |
937 m_profile_t *p; | 954 m_profile_t *p; |
938 | 955 |
939 sprintf (profile, "%s%s", cfg, out); | 956 sprintf(profile, "%s%s", cfg, out); |
940 p = m_config_get_profile (conf, profile); | 957 p = m_config_get_profile(conf, profile); |
941 if (p) | 958 if (p) { |
942 { | 959 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingExtensionProfile, profile); |
943 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingExtensionProfile, profile); | 960 m_config_set_profile(conf, p); |
944 m_config_set_profile(conf,p); | |
945 } | 961 } |
946 } | 962 } |
947 | 963 |
948 /** | 964 /** |
949 * @brief Tries to load a config file. | 965 * @brief Tries to load a config file. |
952 static int try_load_config(m_config_t *conf, const char *file) | 968 static int try_load_config(m_config_t *conf, const char *file) |
953 { | 969 { |
954 struct stat st; | 970 struct stat st; |
955 if (stat(file, &st)) | 971 if (stat(file, &st)) |
956 return 0; | 972 return 0; |
957 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, file); | 973 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_LoadingConfig, file); |
958 m_config_parse_config_file (conf, file); | 974 m_config_parse_config_file(conf, file); |
959 return 1; | 975 return 1; |
960 } | 976 } |
961 | 977 |
962 static void load_per_file_config (m_config_t* conf, const char *const file) | 978 static void load_per_file_config(m_config_t *conf, const char *const file) |
963 { | 979 { |
964 char *confpath; | 980 char *confpath; |
965 char cfg[PATH_MAX]; | 981 char cfg[PATH_MAX]; |
966 const char *name; | 982 const char *name; |
967 | 983 |
968 if (strlen(file) > PATH_MAX - 14) { | 984 if (strlen(file) > PATH_MAX - 14) { |
969 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Filename is too long, can not load file or directory specific config files\n"); | 985 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Filename is too long, can not load file or directory specific config files\n"); |
970 return; | 986 return; |
971 } | 987 } |
972 sprintf (cfg, "%s.conf", file); | 988 sprintf(cfg, "%s.conf", file); |
973 | 989 |
974 name = mp_basename(cfg); | 990 name = mp_basename(cfg); |
975 if (use_filedir_conf) { | 991 if (use_filedir_conf) { |
976 char dircfg[PATH_MAX]; | 992 char dircfg[PATH_MAX]; |
977 strcpy(dircfg, cfg); | 993 strcpy(dircfg, cfg); |
980 | 996 |
981 if (try_load_config(conf, cfg)) | 997 if (try_load_config(conf, cfg)) |
982 return; | 998 return; |
983 } | 999 } |
984 | 1000 |
985 if ((confpath = get_path (name)) != NULL) | 1001 if ((confpath = get_path(name)) != NULL) { |
986 { | 1002 try_load_config(conf, confpath); |
987 try_load_config(conf, confpath); | 1003 |
988 | 1004 free(confpath); |
989 free (confpath); | |
990 } | 1005 } |
991 } | 1006 } |
992 | 1007 |
993 /* When libmpdemux performs a blocking operation (network connection or | 1008 /* When libmpdemux performs a blocking operation (network connection or |
994 * cache filling) if the operation fails we use this function to check | 1009 * cache filling) if the operation fails we use this function to check |
995 * if it was interrupted by the user. | 1010 * if it was interrupted by the user. |
996 * The function returns a new value for eof. */ | 1011 * The function returns a new value for eof. */ |
997 static int libmpdemux_was_interrupted(int eof) { | 1012 static int libmpdemux_was_interrupted(int eof) |
998 mp_cmd_t* cmd; | 1013 { |
999 if((cmd = mp_input_get_cmd(0,0,0)) != NULL) { | 1014 mp_cmd_t *cmd; |
1000 switch(cmd->id) { | 1015 if ((cmd = mp_input_get_cmd(0, 0, 0)) != NULL) { |
1001 case MP_CMD_QUIT: | 1016 switch (cmd->id) { |
1002 run_command(mpctx, cmd); | 1017 case MP_CMD_QUIT: |
1003 case MP_CMD_PLAY_TREE_STEP: | 1018 run_command(mpctx, cmd); |
1004 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY; | 1019 case MP_CMD_PLAY_TREE_STEP: |
1005 mpctx->play_tree_step = (cmd->args[0].v.i == 0) ? 1 : cmd->args[0].v.i; | 1020 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY; |
1006 break; | 1021 mpctx->play_tree_step = (cmd->args[0].v.i == 0) ? 1 : cmd->args[0].v.i; |
1007 case MP_CMD_PLAY_TREE_UP_STEP: | 1022 break; |
1008 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV; | 1023 case MP_CMD_PLAY_TREE_UP_STEP: |
1009 break; | 1024 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV; |
1010 case MP_CMD_PLAY_ALT_SRC_STEP: | 1025 break; |
1011 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC; | 1026 case MP_CMD_PLAY_ALT_SRC_STEP: |
1012 break; | 1027 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC; |
1013 } | 1028 break; |
1014 mp_cmd_free(cmd); | 1029 } |
1015 } | 1030 mp_cmd_free(cmd); |
1016 return eof; | 1031 } |
1017 } | 1032 return eof; |
1018 | 1033 } |
1019 static int playtree_add_playlist(play_tree_t* entry) | 1034 |
1020 { | 1035 static int playtree_add_playlist(play_tree_t *entry) |
1021 play_tree_add_bpf(entry,filename); | 1036 { |
1037 play_tree_add_bpf(entry, filename); | |
1022 | 1038 |
1023 #ifdef CONFIG_GUI | 1039 #ifdef CONFIG_GUI |
1024 if (use_gui) { | 1040 if (use_gui) { |
1025 if (entry) { | 1041 if (entry) { |
1026 import_playtree_playlist_into_gui(entry, mconfig); | 1042 import_playtree_playlist_into_gui(entry, mconfig); |
1027 play_tree_free_list(entry,1); | 1043 play_tree_free_list(entry, 1); |
1028 } | 1044 } |
1029 } else | 1045 } else |
1030 #endif | 1046 #endif |
1031 { | 1047 { |
1032 if(!entry) { | 1048 if (!entry) { |
1033 entry = mpctx->playtree_iter->tree; | 1049 entry = mpctx->playtree_iter->tree; |
1034 if(play_tree_iter_step(mpctx->playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) { | 1050 if (play_tree_iter_step(mpctx->playtree_iter, 1, 0) != PLAY_TREE_ITER_ENTRY) { |
1035 return PT_NEXT_ENTRY; | 1051 return PT_NEXT_ENTRY; |
1036 } | 1052 } |
1037 if(mpctx->playtree_iter->tree == entry ) { // Loop with a single file | 1053 if (mpctx->playtree_iter->tree == entry) { // Loop with a single file |
1038 if(play_tree_iter_up_step(mpctx->playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) { | 1054 if (play_tree_iter_up_step(mpctx->playtree_iter, 1, 0) != PLAY_TREE_ITER_ENTRY) { |
1039 return PT_NEXT_ENTRY; | 1055 return PT_NEXT_ENTRY; |
1040 } | 1056 } |
1041 } | 1057 } |
1042 play_tree_remove(entry,1,1); | 1058 play_tree_remove(entry, 1, 1); |
1059 return PT_NEXT_SRC; | |
1060 } | |
1061 play_tree_insert_entry(mpctx->playtree_iter->tree, entry); | |
1062 play_tree_set_params_from(entry, mpctx->playtree_iter->tree); | |
1063 entry = mpctx->playtree_iter->tree; | |
1064 if (play_tree_iter_step(mpctx->playtree_iter, 1, 0) != PLAY_TREE_ITER_ENTRY) { | |
1065 return PT_NEXT_ENTRY; | |
1066 } | |
1067 play_tree_remove(entry, 1, 1); | |
1068 } | |
1043 return PT_NEXT_SRC; | 1069 return PT_NEXT_SRC; |
1044 } | |
1045 play_tree_insert_entry(mpctx->playtree_iter->tree,entry); | |
1046 play_tree_set_params_from(entry,mpctx->playtree_iter->tree); | |
1047 entry = mpctx->playtree_iter->tree; | |
1048 if(play_tree_iter_step(mpctx->playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) { | |
1049 return PT_NEXT_ENTRY; | |
1050 } | |
1051 play_tree_remove(entry,1,1); | |
1052 } | |
1053 return PT_NEXT_SRC; | |
1054 } | 1070 } |
1055 | 1071 |
1056 void add_subtitles(char *filename, float fps, int noerr) | 1072 void add_subtitles(char *filename, float fps, int noerr) |
1057 { | 1073 { |
1058 sub_data *subd; | 1074 sub_data *subd; |
1059 #ifdef CONFIG_ASS | 1075 #ifdef CONFIG_ASS |
1060 ASS_Track *asst = 0; | 1076 ASS_Track *asst = 0; |
1061 #endif | 1077 #endif |
1062 | 1078 |
1063 if (filename == NULL || mpctx->set_of_sub_size >= MAX_SUBTITLE_FILES) { | 1079 if (filename == NULL || mpctx->set_of_sub_size >= MAX_SUBTITLE_FILES) { |
1064 return; | 1080 return; |
1065 } | 1081 } |
1066 | 1082 |
1067 subd = sub_read_file(filename, fps); | 1083 subd = sub_read_file(filename, fps); |
1068 #ifdef CONFIG_ASS | 1084 #ifdef CONFIG_ASS |
1069 if (ass_enabled) | 1085 if (ass_enabled) |
1075 if (ass_enabled && subd && !asst) | 1091 if (ass_enabled && subd && !asst) |
1076 asst = ass_read_subdata(ass_library, subd, fps); | 1092 asst = ass_read_subdata(ass_library, subd, fps); |
1077 | 1093 |
1078 if (!asst && !subd) | 1094 if (!asst && !subd) |
1079 #else | 1095 #else |
1080 if(!subd) | 1096 if (!subd) |
1081 #endif | 1097 #endif |
1082 mp_msg(MSGT_CPLAYER, noerr ? MSGL_WARN : MSGL_ERR, MSGTR_CantLoadSub, | 1098 mp_msg(MSGT_CPLAYER, noerr ? MSGL_WARN : MSGL_ERR, MSGTR_CantLoadSub, |
1083 filename_recode(filename)); | 1099 filename_recode(filename)); |
1084 | 1100 |
1085 #ifdef CONFIG_ASS | 1101 #ifdef CONFIG_ASS |
1086 if (!asst && !subd) return; | 1102 if (!asst && !subd) |
1103 return; | |
1087 mpctx->set_of_ass_tracks[mpctx->set_of_sub_size] = asst; | 1104 mpctx->set_of_ass_tracks[mpctx->set_of_sub_size] = asst; |
1088 #else | 1105 #else |
1089 if (!subd) return; | 1106 if (!subd) |
1107 return; | |
1090 #endif | 1108 #endif |
1091 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = subd; | 1109 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = subd; |
1092 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", mpctx->set_of_sub_size); | 1110 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", mpctx->set_of_sub_size); |
1093 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n", | 1111 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n", |
1094 filename_recode(filename)); | 1112 filename_recode(filename)); |
1095 ++mpctx->set_of_sub_size; | 1113 ++mpctx->set_of_sub_size; |
1096 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, mpctx->set_of_sub_size, | 1114 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, mpctx->set_of_sub_size, |
1097 filename_recode(filename)); | 1115 filename_recode(filename)); |
1098 } | 1116 } |
1099 | 1117 |
1100 static int add_vob_subtitle(const char *vobname, const char * const ifo, int force, void *spu) | 1118 static int add_vob_subtitle(const char *vobname, const char *const ifo, int force, void *spu) |
1101 { | 1119 { |
1102 if (!vobname) | 1120 if (!vobname) |
1103 return 0; | 1121 return 0; |
1104 | 1122 |
1105 assert(!vo_vobsub); | 1123 assert(!vo_vobsub); |
1113 return !!vo_vobsub; | 1131 return !!vo_vobsub; |
1114 } | 1132 } |
1115 | 1133 |
1116 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken. | 1134 // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken. |
1117 void update_set_of_subtitles(void) | 1135 void update_set_of_subtitles(void) |
1136 { | |
1118 // subdata was changed, set_of_sub... have to be updated. | 1137 // subdata was changed, set_of_sub... have to be updated. |
1119 { | 1138 sub_data **const set_of_subtitles = mpctx->set_of_subtitles; |
1120 sub_data ** const set_of_subtitles = mpctx->set_of_subtitles; | |
1121 int i; | 1139 int i; |
1122 if (mpctx->set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted | 1140 if (mpctx->set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted |
1123 for (i = mpctx->set_of_sub_pos + 1; i < mpctx->set_of_sub_size; ++i) | 1141 for (i = mpctx->set_of_sub_pos + 1; i < mpctx->set_of_sub_size; ++i) |
1124 set_of_subtitles[i-1] = set_of_subtitles[i]; | 1142 set_of_subtitles[i - 1] = set_of_subtitles[i]; |
1125 set_of_subtitles[mpctx->set_of_sub_size-1] = NULL; | 1143 set_of_subtitles[mpctx->set_of_sub_size - 1] = NULL; |
1126 --mpctx->set_of_sub_size; | 1144 --mpctx->set_of_sub_size; |
1127 if (mpctx->set_of_sub_size > 0) subdata = set_of_subtitles[mpctx->set_of_sub_pos=0]; | 1145 if (mpctx->set_of_sub_size > 0) |
1128 } | 1146 subdata = set_of_subtitles[mpctx->set_of_sub_pos = 0]; |
1129 else if (mpctx->set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed | 1147 } else if (mpctx->set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed |
1130 set_of_subtitles[mpctx->set_of_sub_pos] = subdata; | 1148 set_of_subtitles[mpctx->set_of_sub_pos] = subdata; |
1131 } | 1149 } else if (mpctx->set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added |
1132 else if (mpctx->set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added | 1150 set_of_subtitles[mpctx->set_of_sub_pos = mpctx->set_of_sub_size] = subdata; |
1133 set_of_subtitles[mpctx->set_of_sub_pos=mpctx->set_of_sub_size] = subdata; | |
1134 ++mpctx->set_of_sub_size; | 1151 ++mpctx->set_of_sub_size; |
1135 } | 1152 } |
1136 } | 1153 } |
1137 | 1154 |
1138 void init_vo_spudec(void) { | 1155 void init_vo_spudec(void) |
1139 spudec_free(vo_spudec); | 1156 { |
1140 vo_spudec = NULL; | 1157 spudec_free(vo_spudec); |
1141 | 1158 vo_spudec = NULL; |
1142 // we currently can't work without video stream | 1159 |
1143 if (!mpctx->sh_video) | 1160 // we currently can't work without video stream |
1144 return; | 1161 if (!mpctx->sh_video) |
1145 | 1162 return; |
1146 if (spudec_ifo) { | 1163 |
1147 unsigned int palette[16], width, height; | 1164 if (spudec_ifo) { |
1148 current_module="spudec_init_vobsub"; | 1165 unsigned int palette[16], width, height; |
1149 if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0) | 1166 current_module = "spudec_init_vobsub"; |
1150 vo_spudec=spudec_new_scaled(palette, width, height, NULL, 0); | 1167 if (vobsub_parse_ifo(NULL, spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0) |
1151 } | 1168 vo_spudec = spudec_new_scaled(palette, width, height, NULL, 0); |
1169 } | |
1152 | 1170 |
1153 #ifdef CONFIG_DVDREAD | 1171 #ifdef CONFIG_DVDREAD |
1154 if (vo_spudec==NULL && mpctx->stream->type==STREAMTYPE_DVD) { | 1172 if (vo_spudec == NULL && mpctx->stream->type == STREAMTYPE_DVD) { |
1155 current_module="spudec_init_dvdread"; | 1173 current_module = "spudec_init_dvdread"; |
1156 vo_spudec=spudec_new_scaled(((dvd_priv_t *)(mpctx->stream->priv))->cur_pgc->palette, | 1174 vo_spudec = spudec_new_scaled(((dvd_priv_t *)(mpctx->stream->priv))->cur_pgc->palette, |
1157 mpctx->sh_video->disp_w, mpctx->sh_video->disp_h, | 1175 mpctx->sh_video->disp_w, mpctx->sh_video->disp_h, |
1158 NULL, 0); | 1176 NULL, 0); |
1159 } | 1177 } |
1160 #endif | 1178 #endif |
1161 | 1179 |
1162 #ifdef CONFIG_DVDNAV | 1180 #ifdef CONFIG_DVDNAV |
1163 if (vo_spudec==NULL && mpctx->stream->type==STREAMTYPE_DVDNAV) { | 1181 if (vo_spudec == NULL && mpctx->stream->type == STREAMTYPE_DVDNAV) { |
1164 unsigned int *palette = mp_dvdnav_get_spu_clut(mpctx->stream); | 1182 unsigned int *palette = mp_dvdnav_get_spu_clut(mpctx->stream); |
1165 current_module="spudec_init_dvdnav"; | 1183 current_module = "spudec_init_dvdnav"; |
1166 vo_spudec=spudec_new_scaled(palette, mpctx->sh_video->disp_w, mpctx->sh_video->disp_h, NULL, 0); | 1184 vo_spudec = spudec_new_scaled(palette, mpctx->sh_video->disp_w, mpctx->sh_video->disp_h, NULL, 0); |
1167 } | 1185 } |
1168 #endif | 1186 #endif |
1169 | 1187 |
1170 if (vo_spudec==NULL) { | 1188 if (vo_spudec == NULL) { |
1171 sh_sub_t *sh = mpctx->d_sub->sh; | 1189 sh_sub_t *sh = mpctx->d_sub->sh; |
1172 current_module="spudec_init_normal"; | 1190 current_module = "spudec_init_normal"; |
1173 vo_spudec=spudec_new_scaled(NULL, mpctx->sh_video->disp_w, mpctx->sh_video->disp_h, sh->extradata, sh->extradata_len); | 1191 vo_spudec = spudec_new_scaled(NULL, mpctx->sh_video->disp_w, mpctx->sh_video->disp_h, sh->extradata, sh->extradata_len); |
1174 spudec_set_font_factor(vo_spudec,font_factor); | 1192 spudec_set_font_factor(vo_spudec, font_factor); |
1175 } | 1193 } |
1176 | 1194 |
1177 if (vo_spudec!=NULL) { | 1195 if (vo_spudec != NULL) { |
1178 mp_property_do("sub_forced_only", M_PROPERTY_SET, &forced_subs_only, mpctx); | 1196 mp_property_do("sub_forced_only", M_PROPERTY_SET, &forced_subs_only, mpctx); |
1179 } | 1197 } |
1180 } | 1198 } |
1181 | 1199 |
1182 /** | 1200 /** |
1183 * @brief Append a formatted string. | 1201 * @brief Append a formatted string. |
1184 * @param buf buffer to print into | 1202 * @param buf buffer to print into |
1186 * @param len maximum number of characters in buf, not including terminating 0 | 1204 * @param len maximum number of characters in buf, not including terminating 0 |
1187 * @param format printf format string | 1205 * @param format printf format string |
1188 */ | 1206 */ |
1189 static void saddf(char *buf, unsigned *pos, int len, const char *format, ...) | 1207 static void saddf(char *buf, unsigned *pos, int len, const char *format, ...) |
1190 { | 1208 { |
1191 va_list va; | 1209 va_list va; |
1192 va_start(va, format); | 1210 va_start(va, format); |
1193 *pos += vsnprintf(&buf[*pos], len - *pos, format, va); | 1211 *pos += vsnprintf(&buf[*pos], len - *pos, format, va); |
1194 va_end(va); | 1212 va_end(va); |
1195 if (*pos >= len ) { | 1213 if (*pos >= len) { |
1196 buf[len] = 0; | 1214 buf[len] = 0; |
1197 *pos = len; | 1215 *pos = len; |
1198 } | 1216 } |
1199 } | 1217 } |
1200 | 1218 |
1201 /** | 1219 /** |
1202 * @brief Append time in the hh:mm:ss.f format. | 1220 * @brief Append time in the hh:mm:ss.f format. |
1203 * @param buf buffer to print into | 1221 * @param buf buffer to print into |
1204 * @param pos position of terminating 0 in buf | 1222 * @param pos position of terminating 0 in buf |
1205 * @param len maximum number of characters in buf, not including terminating 0 | 1223 * @param len maximum number of characters in buf, not including terminating 0 |
1206 * @param time time value to convert/append | 1224 * @param time time value to convert/append |
1207 */ | 1225 */ |
1208 static void sadd_hhmmssf(char *buf, unsigned *pos, int len, float time) { | 1226 static void sadd_hhmmssf(char *buf, unsigned *pos, int len, float time) |
1209 int64_t tenths = 10 * time; | 1227 { |
1210 int f1 = tenths % 10; | 1228 int64_t tenths = 10 * time; |
1211 int ss = (tenths / 10) % 60; | 1229 int f1 = tenths % 10; |
1212 int mm = (tenths / 600) % 60; | 1230 int ss = (tenths / 10) % 60; |
1213 int hh = tenths / 36000; | 1231 int mm = (tenths / 600) % 60; |
1214 if (time <= 0) { | 1232 int hh = tenths / 36000; |
1215 saddf(buf, pos, len, "unknown"); | 1233 if (time <= 0) { |
1216 return; | 1234 saddf(buf, pos, len, "unknown"); |
1217 } | 1235 return; |
1218 if (hh > 0) | 1236 } |
1219 saddf(buf, pos, len, "%2d:", hh); | 1237 if (hh > 0) |
1220 if (hh > 0 || mm > 0) | 1238 saddf(buf, pos, len, "%2d:", hh); |
1221 saddf(buf, pos, len, "%02d:", mm); | 1239 if (hh > 0 || mm > 0) |
1222 saddf(buf, pos, len, "%02d.%1d", ss, f1); | 1240 saddf(buf, pos, len, "%02d:", mm); |
1241 saddf(buf, pos, len, "%02d.%1d", ss, f1); | |
1223 } | 1242 } |
1224 | 1243 |
1225 /** | 1244 /** |
1226 * @brief Print the status line. | 1245 * @brief Print the status line. |
1227 * @param a_pos audio position | 1246 * @param a_pos audio position |
1228 * @param a_v A-V desynchronization | 1247 * @param a_v A-V desynchronization |
1229 * @param corr amount out A-V synchronization | 1248 * @param corr amount out A-V synchronization |
1230 */ | 1249 */ |
1231 static void print_status(float a_pos, float a_v, float corr) | 1250 static void print_status(float a_pos, float a_v, float corr) |
1232 { | 1251 { |
1233 sh_video_t * const sh_video = mpctx->sh_video; | 1252 sh_video_t *const sh_video = mpctx->sh_video; |
1234 int width; | 1253 int width; |
1235 char *line; | 1254 char *line; |
1236 unsigned pos = 0; | 1255 unsigned pos = 0; |
1237 get_screen_size(); | 1256 get_screen_size(); |
1238 if (screen_width > 0) | 1257 if (screen_width > 0) |
1239 width = screen_width; | 1258 width = screen_width; |
1240 else | 1259 else |
1241 width = 80; | 1260 width = 80; |
1242 #if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__) | 1261 #if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__) |
1243 /* Windows command line is broken (MinGW's rxvt works, but we | 1262 /* Windows command line is broken (MinGW's rxvt works, but we |
1244 * should not depend on that). */ | 1263 * should not depend on that). */ |
1245 width--; | 1264 width--; |
1246 #endif | 1265 #endif |
1247 line = malloc(width + 1); // one additional char for the terminating null | 1266 line = malloc(width + 1); // one additional char for the terminating null |
1248 | 1267 |
1249 // Audio time | 1268 // Audio time |
1250 if (mpctx->sh_audio) { | 1269 if (mpctx->sh_audio) { |
1251 saddf(line, &pos, width, "A:%6.1f ", a_pos); | 1270 saddf(line, &pos, width, "A:%6.1f ", a_pos); |
1252 if (!sh_video) { | 1271 if (!sh_video) { |
1253 float len = demuxer_get_time_length(mpctx->demuxer); | 1272 float len = demuxer_get_time_length(mpctx->demuxer); |
1254 saddf(line, &pos, width, "("); | 1273 saddf(line, &pos, width, "("); |
1255 sadd_hhmmssf(line, &pos, width, a_pos); | 1274 sadd_hhmmssf(line, &pos, width, a_pos); |
1256 saddf(line, &pos, width, ") of %.1f (", len); | 1275 saddf(line, &pos, width, ") of %.1f (", len); |
1257 sadd_hhmmssf(line, &pos, width, len); | 1276 sadd_hhmmssf(line, &pos, width, len); |
1258 saddf(line, &pos, width, ") "); | 1277 saddf(line, &pos, width, ") "); |
1259 } | 1278 } |
1260 } | 1279 } |
1261 | 1280 |
1262 // Video time | 1281 // Video time |
1263 if (sh_video) | 1282 if (sh_video) |
1264 saddf(line, &pos, width, "V:%6.1f ", sh_video->pts); | 1283 saddf(line, &pos, width, "V:%6.1f ", sh_video->pts); |
1265 | 1284 |
1266 // A-V sync | 1285 // A-V sync |
1267 if (mpctx->sh_audio && sh_video) | 1286 if (mpctx->sh_audio && sh_video) |
1268 saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr); | 1287 saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr); |
1269 | 1288 |
1270 // Video stats | 1289 // Video stats |
1271 if (sh_video) | 1290 if (sh_video) |
1272 saddf(line, &pos, width, "%3d/%3d ", | 1291 saddf(line, &pos, width, "%3d/%3d ", |
1273 (int)sh_video->num_frames, | 1292 (int)sh_video->num_frames, |
1274 (int)sh_video->num_frames_decoded); | 1293 (int)sh_video->num_frames_decoded); |
1275 | 1294 |
1276 // CPU usage | 1295 // CPU usage |
1277 if (sh_video) { | 1296 if (sh_video) { |
1278 if (sh_video->timer > 0.5) | 1297 if (sh_video->timer > 0.5) |
1279 saddf(line, &pos, width, "%2d%% %2d%% %4.1f%% ", | 1298 saddf(line, &pos, width, "%2d%% %2d%% %4.1f%% ", |
1280 (int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer), | 1299 (int)(100.0 * video_time_usage * playback_speed / (double)sh_video->timer), |
1281 (int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer), | 1300 (int)(100.0 * vout_time_usage * playback_speed / (double)sh_video->timer), |
1282 (100.0*audio_time_usage*playback_speed/(double)sh_video->timer)); | 1301 (100.0 * audio_time_usage * playback_speed / (double)sh_video->timer)); |
1283 else | 1302 else |
1284 saddf(line, &pos, width, "??%% ??%% ??,?%% "); | 1303 saddf(line, &pos, width, "??%% ??%% ??,?%% "); |
1285 } else if (mpctx->sh_audio) { | 1304 } else if (mpctx->sh_audio) { |
1286 if (mpctx->delay > 0.5) | 1305 if (mpctx->delay > 0.5) |
1287 saddf(line, &pos, width, "%4.1f%% ", | 1306 saddf(line, &pos, width, "%4.1f%% ", |
1288 100.0*audio_time_usage/(double)mpctx->delay); | 1307 100.0 * audio_time_usage / (double)mpctx->delay); |
1289 else | 1308 else |
1290 saddf(line, &pos, width, "??,?%% "); | 1309 saddf(line, &pos, width, "??,?%% "); |
1291 } | 1310 } |
1292 | 1311 |
1293 // VO stats | 1312 // VO stats |
1294 if (sh_video) | 1313 if (sh_video) |
1295 saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality); | 1314 saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality); |
1296 | 1315 |
1297 #ifdef CONFIG_STREAM_CACHE | 1316 #ifdef CONFIG_STREAM_CACHE |
1298 // cache stats | 1317 // cache stats |
1299 if (stream_cache_size > 0) | 1318 if (stream_cache_size > 0) |
1300 saddf(line, &pos, width, "%d%% ", cache_fill_status(mpctx->stream)); | 1319 saddf(line, &pos, width, "%d%% ", cache_fill_status(mpctx->stream)); |
1301 #endif | 1320 #endif |
1302 | 1321 |
1303 // other | 1322 // other |
1304 if (playback_speed != 1) | 1323 if (playback_speed != 1) |
1305 saddf(line, &pos, width, "%4.2fx ", playback_speed); | 1324 saddf(line, &pos, width, "%4.2fx ", playback_speed); |
1306 | 1325 |
1307 // end | 1326 // end |
1308 if (erase_to_end_of_line) { | 1327 if (erase_to_end_of_line) { |
1309 line[pos] = 0; | 1328 line[pos] = 0; |
1310 mp_msg(MSGT_STATUSLINE, MSGL_STATUS, "%s%s\r", line, erase_to_end_of_line); | 1329 mp_msg(MSGT_STATUSLINE, MSGL_STATUS, "%s%s\r", line, erase_to_end_of_line); |
1311 } else { | 1330 } else { |
1312 memset(&line[pos], ' ', width - pos); | 1331 memset(&line[pos], ' ', width - pos); |
1313 line[width] = 0; | 1332 line[width] = 0; |
1314 mp_msg(MSGT_STATUSLINE, MSGL_STATUS, "%s\r", line); | 1333 mp_msg(MSGT_STATUSLINE, MSGL_STATUS, "%s\r", line); |
1315 } | 1334 } |
1316 free(line); | 1335 free(line); |
1317 } | 1336 } |
1318 | 1337 |
1319 /** | 1338 /** |
1320 * @brief Build a chain of audio filters that converts the input format. | 1339 * @brief Build a chain of audio filters that converts the input format. |
1321 * to the ao's format, taking into account the current playback_speed. | 1340 * to the ao's format, taking into account the current playback_speed. |
1322 * @param sh_audio describes the requested input format of the chain. | 1341 * @param sh_audio describes the requested input format of the chain. |
1323 * @param ao_data describes the requested output format of the chain. | 1342 * @param ao_data describes the requested output format of the chain. |
1324 */ | 1343 */ |
1325 static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data) | 1344 static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data) |
1326 { | 1345 { |
1327 int new_srate; | 1346 int new_srate; |
1328 int result; | 1347 int result; |
1329 if (!sh_audio) | 1348 if (!sh_audio) { |
1330 { | |
1331 #ifdef CONFIG_GUI | 1349 #ifdef CONFIG_GUI |
1332 if (use_gui) guiGetEvent(guiSetAfilter, (char *)NULL); | 1350 if (use_gui) |
1333 #endif | 1351 guiGetEvent(guiSetAfilter, (char *)NULL); |
1334 mpctx->mixer.afilter = NULL; | 1352 #endif |
1335 return 0; | 1353 mpctx->mixer.afilter = NULL; |
1336 } | 1354 return 0; |
1337 if(af_control_any_rev(sh_audio->afilter, | 1355 } |
1338 AF_CONTROL_PLAYBACK_SPEED | AF_CONTROL_SET, | 1356 if (af_control_any_rev(sh_audio->afilter, |
1339 &playback_speed)) { | 1357 AF_CONTROL_PLAYBACK_SPEED | AF_CONTROL_SET, |
1340 new_srate = sh_audio->samplerate; | 1358 &playback_speed)) { |
1341 } else { | 1359 new_srate = sh_audio->samplerate; |
1342 new_srate = sh_audio->samplerate * playback_speed; | 1360 } else { |
1343 if (new_srate != ao_data->samplerate) { | 1361 new_srate = sh_audio->samplerate * playback_speed; |
1344 // limits are taken from libaf/af_resample.c | 1362 if (new_srate != ao_data->samplerate) { |
1345 if (new_srate < 8000) | 1363 // limits are taken from libaf/af_resample.c |
1346 new_srate = 8000; | 1364 if (new_srate < 8000) |
1347 if (new_srate > 192000) | 1365 new_srate = 8000; |
1348 new_srate = 192000; | 1366 if (new_srate > 192000) |
1349 playback_speed = (float)new_srate / (float)sh_audio->samplerate; | 1367 new_srate = 192000; |
1350 } | 1368 playback_speed = (float)new_srate / (float)sh_audio->samplerate; |
1351 } | 1369 } |
1352 result = init_audio_filters(sh_audio, new_srate, | 1370 } |
1353 &ao_data->samplerate, &ao_data->channels, &ao_data->format); | 1371 result = init_audio_filters(sh_audio, new_srate, |
1354 mpctx->mixer.afilter = sh_audio->afilter; | 1372 &ao_data->samplerate, &ao_data->channels, &ao_data->format); |
1373 mpctx->mixer.afilter = sh_audio->afilter; | |
1355 #ifdef CONFIG_GUI | 1374 #ifdef CONFIG_GUI |
1356 if (use_gui) guiGetEvent(guiSetAfilter, (char *)sh_audio->afilter); | 1375 if (use_gui) |
1357 #endif | 1376 guiGetEvent(guiSetAfilter, (char *)sh_audio->afilter); |
1358 return result; | 1377 #endif |
1359 } | 1378 return result; |
1360 | 1379 } |
1361 | 1380 |
1362 typedef struct mp_osd_msg mp_osd_msg_t; | 1381 typedef struct mp_osd_msg mp_osd_msg_t; |
1363 struct mp_osd_msg { | 1382 struct mp_osd_msg { |
1364 mp_osd_msg_t* prev; ///< Previous message on the stack | 1383 mp_osd_msg_t *prev; ///< Previous message on the stack |
1365 char msg[128]; ///< Message text | 1384 char msg[128]; ///< Message text |
1366 int id,level,started; | 1385 int id, level, started; |
1367 unsigned time; ///< Display duration in ms | 1386 unsigned time; ///< Display duration in ms |
1368 }; | 1387 }; |
1369 | 1388 |
1370 static mp_osd_msg_t* osd_msg_stack; ///< OSD message stack | 1389 static mp_osd_msg_t *osd_msg_stack; ///< OSD message stack |
1371 | 1390 |
1372 /** | 1391 /** |
1373 * @brief Add a message on the OSD message stack. | 1392 * @brief Add a message on the OSD message stack. |
1374 * | 1393 * |
1375 * If a message with the same id is already present in the stack | 1394 * If a message with the same id is already present in the stack |
1376 * it is pulled on top of the stack, otherwise a new message is created. | 1395 * it is pulled on top of the stack, otherwise a new message is created. |
1377 */ | 1396 */ |
1378 void set_osd_msg(int id, int level, int time, const char* fmt, ...) { | 1397 void set_osd_msg(int id, int level, int time, const char *fmt, ...) |
1379 mp_osd_msg_t *msg,*last=NULL; | 1398 { |
1399 mp_osd_msg_t *msg, *last = NULL; | |
1380 va_list va; | 1400 va_list va; |
1381 int r; | 1401 int r; |
1382 | 1402 |
1383 // look if the id is already in the stack | 1403 // look if the id is already in the stack |
1384 for(msg = osd_msg_stack ; msg && msg->id != id ; | 1404 for (msg = osd_msg_stack; msg && msg->id != id; |
1385 last = msg, msg = msg->prev); | 1405 last = msg, msg = msg->prev) ; |
1386 // not found: alloc it | 1406 // not found: alloc it |
1387 if(!msg) { | 1407 if (!msg) { |
1388 msg = calloc(1,sizeof(mp_osd_msg_t)); | 1408 msg = calloc(1, sizeof(mp_osd_msg_t)); |
1389 msg->prev = osd_msg_stack; | 1409 msg->prev = osd_msg_stack; |
1390 osd_msg_stack = msg; | 1410 osd_msg_stack = msg; |
1391 } else if(last) { // found, but it's not on top of the stack | 1411 } else if (last) { // found, but it's not on top of the stack |
1392 last->prev = msg->prev; | 1412 last->prev = msg->prev; |
1393 msg->prev = osd_msg_stack; | 1413 msg->prev = osd_msg_stack; |
1394 osd_msg_stack = msg; | 1414 osd_msg_stack = msg; |
1395 } | 1415 } |
1396 // write the msg | 1416 // write the msg |
1397 va_start(va,fmt); | 1417 va_start(va, fmt); |
1398 r = vsnprintf(msg->msg, 128, fmt, va); | 1418 r = vsnprintf(msg->msg, 128, fmt, va); |
1399 va_end(va); | 1419 va_end(va); |
1400 if(r >= 128) msg->msg[127] = 0; | 1420 if (r >= 128) |
1421 msg->msg[127] = 0; | |
1401 // set id and time | 1422 // set id and time |
1402 msg->id = id; | 1423 msg->id = id; |
1403 msg->level = level; | 1424 msg->level = level; |
1404 msg->time = time; | 1425 msg->time = time; |
1405 | |
1406 } | 1426 } |
1407 | 1427 |
1408 /** | 1428 /** |
1409 * @brief Remove a message from the OSD stack. | 1429 * @brief Remove a message from the OSD stack. |
1410 * | 1430 * |
1411 * This function can be used to get rid of a message right away. | 1431 * This function can be used to get rid of a message right away. |
1412 */ | 1432 */ |
1413 void rm_osd_msg(int id) { | 1433 void rm_osd_msg(int id) |
1414 mp_osd_msg_t *msg,*last=NULL; | 1434 { |
1435 mp_osd_msg_t *msg, *last = NULL; | |
1415 | 1436 |
1416 // Search for the msg | 1437 // Search for the msg |
1417 for(msg = osd_msg_stack ; msg && msg->id != id ; | 1438 for (msg = osd_msg_stack; msg && msg->id != id; |
1418 last = msg, msg = msg->prev); | 1439 last = msg, msg = msg->prev) ; |
1419 if(!msg) return; | 1440 if (!msg) |
1441 return; | |
1420 | 1442 |
1421 // Detach it from the stack and free it | 1443 // Detach it from the stack and free it |
1422 if(last) | 1444 if (last) |
1423 last->prev = msg->prev; | 1445 last->prev = msg->prev; |
1424 else | 1446 else |
1425 osd_msg_stack = msg->prev; | 1447 osd_msg_stack = msg->prev; |
1426 free(msg); | 1448 free(msg); |
1427 } | 1449 } |
1428 | 1450 |
1429 /** | 1451 /** |
1430 * @brief Remove all messages from the OSD stack. | 1452 * @brief Remove all messages from the OSD stack. |
1431 */ | 1453 */ |
1432 static void clear_osd_msgs(void) { | 1454 static void clear_osd_msgs(void) |
1433 mp_osd_msg_t* msg = osd_msg_stack, *prev = NULL; | 1455 { |
1434 while(msg) { | 1456 mp_osd_msg_t *msg = osd_msg_stack, *prev = NULL; |
1457 while (msg) { | |
1435 prev = msg->prev; | 1458 prev = msg->prev; |
1436 free(msg); | 1459 free(msg); |
1437 msg = prev; | 1460 msg = prev; |
1438 } | 1461 } |
1439 osd_msg_stack = NULL; | 1462 osd_msg_stack = NULL; |
1443 * @brief Get the current message from the OSD stack. | 1466 * @brief Get the current message from the OSD stack. |
1444 * | 1467 * |
1445 * This function decrements the message timer and destroys the old ones. | 1468 * This function decrements the message timer and destroys the old ones. |
1446 * The message that should be displayed is returned (if any). | 1469 * The message that should be displayed is returned (if any). |
1447 */ | 1470 */ |
1448 static mp_osd_msg_t* get_osd_msg(void) { | 1471 static mp_osd_msg_t *get_osd_msg(void) |
1449 mp_osd_msg_t *msg,*prev,*last = NULL; | 1472 { |
1473 mp_osd_msg_t *msg, *prev, *last = NULL; | |
1450 static unsigned last_update; | 1474 static unsigned last_update; |
1451 unsigned now = GetTimerMS(); | 1475 unsigned now = GetTimerMS(); |
1452 unsigned diff; | 1476 unsigned diff; |
1453 char hidden_dec_done = 0; | 1477 char hidden_dec_done = 0; |
1454 | 1478 |
1455 if (osd_visible) { | 1479 if (osd_visible) { |
1456 // 36000000 means max timed visibility is 1 hour into the future, if | 1480 // 36000000 means max timed visibility is 1 hour into the future, if |
1457 // the difference is greater assume it's wrapped around from below 0 | 1481 // the difference is greater assume it's wrapped around from below 0 |
1458 if (osd_visible - now > 36000000) { | 1482 if (osd_visible - now > 36000000) { |
1459 osd_visible = 0; | 1483 osd_visible = 0; |
1460 vo_osd_progbar_type = -1; // disable | 1484 vo_osd_progbar_type = -1; // disable |
1461 vo_osd_changed(OSDTYPE_PROGBAR); | 1485 vo_osd_changed(OSDTYPE_PROGBAR); |
1462 if (mpctx->osd_function != OSD_PAUSE) | 1486 if (mpctx->osd_function != OSD_PAUSE) |
1463 mpctx->osd_function = OSD_PLAY; | 1487 mpctx->osd_function = OSD_PLAY; |
1464 } | 1488 } |
1465 } | 1489 } |
1466 | 1490 |
1467 if(!last_update) last_update = now; | 1491 if (!last_update) |
1492 last_update = now; | |
1468 diff = now >= last_update ? now - last_update : 0; | 1493 diff = now >= last_update ? now - last_update : 0; |
1469 | 1494 |
1470 last_update = now; | 1495 last_update = now; |
1471 | 1496 |
1472 // Look for the first message in the stack with high enough level. | 1497 // Look for the first message in the stack with high enough level. |
1473 for(msg = osd_msg_stack ; msg ; last = msg, msg = prev) { | 1498 for (msg = osd_msg_stack; msg; last = msg, msg = prev) { |
1474 prev = msg->prev; | 1499 prev = msg->prev; |
1475 if(msg->level > osd_level && hidden_dec_done) continue; | 1500 if (msg->level > osd_level && hidden_dec_done) |
1501 continue; | |
1476 // The message has a high enough level or it is the first hidden one | 1502 // The message has a high enough level or it is the first hidden one |
1477 // in both cases we decrement the timer or kill it. | 1503 // in both cases we decrement the timer or kill it. |
1478 if(!msg->started || msg->time > diff) { | 1504 if (!msg->started || msg->time > diff) { |
1479 if(msg->started) msg->time -= diff; | 1505 if (msg->started) |
1480 else msg->started = 1; | 1506 msg->time -= diff; |
1507 else | |
1508 msg->started = 1; | |
1481 // display it | 1509 // display it |
1482 if(msg->level <= osd_level) return msg; | 1510 if (msg->level <= osd_level) |
1511 return msg; | |
1483 hidden_dec_done = 1; | 1512 hidden_dec_done = 1; |
1484 continue; | 1513 continue; |
1485 } | 1514 } |
1486 // kill the message | 1515 // kill the message |
1487 free(msg); | 1516 free(msg); |
1488 if(last) { | 1517 if (last) { |
1489 last->prev = prev; | 1518 last->prev = prev; |
1490 msg = last; | 1519 msg = last; |
1491 } else { | 1520 } else { |
1492 osd_msg_stack = prev; | 1521 osd_msg_stack = prev; |
1493 msg = NULL; | 1522 msg = NULL; |
1500 /** | 1529 /** |
1501 * @brief Display the OSD bar. | 1530 * @brief Display the OSD bar. |
1502 * | 1531 * |
1503 * Display the OSD bar or fall back on a simple message. | 1532 * Display the OSD bar or fall back on a simple message. |
1504 */ | 1533 */ |
1505 void set_osd_bar(int type,const char* name,double min,double max,double val) { | 1534 void set_osd_bar(int type, const char *name, double min, double max, double val) |
1506 | 1535 { |
1507 if(osd_level < 1) return; | 1536 if (osd_level < 1) |
1508 | 1537 return; |
1509 if(mpctx->sh_video) { | 1538 |
1539 if (mpctx->sh_video) { | |
1510 osd_visible = (GetTimerMS() + 1000) | 1; | 1540 osd_visible = (GetTimerMS() + 1000) | 1; |
1511 vo_osd_progbar_type = type; | 1541 vo_osd_progbar_type = type; |
1512 vo_osd_progbar_value = 256*(val-min)/(max-min); | 1542 vo_osd_progbar_value = 256 * (val - min) / (max - min); |
1513 vo_osd_changed(OSDTYPE_PROGBAR); | 1543 vo_osd_changed(OSDTYPE_PROGBAR); |
1514 return; | 1544 return; |
1515 } | 1545 } |
1516 | 1546 |
1517 set_osd_msg(OSD_MSG_BAR,1,osd_duration,"%s: %d %%", | 1547 set_osd_msg(OSD_MSG_BAR, 1, osd_duration, "%s: %d %%", |
1518 name,ROUND(100*(val-min)/(max-min))); | 1548 name, ROUND(100 * (val - min) / (max - min))); |
1519 } | 1549 } |
1520 | 1550 |
1521 /** | 1551 /** |
1522 * @brief Display text subtitles on the OSD. | 1552 * @brief Display text subtitles on the OSD. |
1523 */ | 1553 */ |
1524 void set_osd_subtitle(subtitle *subs) { | 1554 void set_osd_subtitle(subtitle *subs) |
1555 { | |
1525 int i; | 1556 int i; |
1526 vo_sub = subs; | 1557 vo_sub = subs; |
1527 vo_osd_changed(OSDTYPE_SUBTITLE); | 1558 vo_osd_changed(OSDTYPE_SUBTITLE); |
1528 if (!mpctx->sh_video) { | 1559 if (!mpctx->sh_video) { |
1529 // reverse order, since newest set_osd_msg is displayed first | 1560 // reverse order, since newest set_osd_msg is displayed first |
1544 * | 1575 * |
1545 * This function displays the current message on the vo OSD or on the term. | 1576 * This function displays the current message on the vo OSD or on the term. |
1546 * If the stack is empty and the OSD level is high enough the timer | 1577 * If the stack is empty and the OSD level is high enough the timer |
1547 * is displayed (only on the vo OSD). | 1578 * is displayed (only on the vo OSD). |
1548 */ | 1579 */ |
1549 static void update_osd_msg(void) { | 1580 static void update_osd_msg(void) |
1581 { | |
1550 mp_osd_msg_t *msg; | 1582 mp_osd_msg_t *msg; |
1551 static char osd_text[128] = ""; | 1583 static char osd_text[128] = ""; |
1552 static char osd_text_timer[128]; | 1584 static char osd_text_timer[128]; |
1553 | 1585 |
1554 // we need some mem for vo_osd_text | 1586 // we need some mem for vo_osd_text |
1555 vo_osd_text = (unsigned char*)osd_text; | 1587 vo_osd_text = (unsigned char *)osd_text; |
1556 | 1588 |
1557 // Look if we have a msg | 1589 // Look if we have a msg |
1558 if((msg = get_osd_msg())) { | 1590 if ((msg = get_osd_msg())) { |
1559 if(strcmp(osd_text,msg->msg)) { | 1591 if (strcmp(osd_text, msg->msg)) { |
1560 strncpy((char*)osd_text, msg->msg, 127); | 1592 strncpy((char *)osd_text, msg->msg, 127); |
1561 if(mpctx->sh_video) vo_osd_changed(OSDTYPE_OSD); else | 1593 if (mpctx->sh_video) |
1562 if(term_osd) mp_msg(MSGT_CPLAYER,MSGL_STATUS,"%s%s\n",term_osd_esc,msg->msg); | 1594 vo_osd_changed(OSDTYPE_OSD); |
1595 else if (term_osd) | |
1596 mp_msg(MSGT_CPLAYER, MSGL_STATUS, "%s%s\n", term_osd_esc, msg->msg); | |
1563 } | 1597 } |
1564 return; | 1598 return; |
1565 } | 1599 } |
1566 | 1600 |
1567 if(mpctx->sh_video) { | 1601 if (mpctx->sh_video) { |
1568 // fallback on the timer | 1602 // fallback on the timer |
1569 if(osd_level>=2) { | 1603 if (osd_level >= 2) { |
1570 int len = demuxer_get_time_length(mpctx->demuxer); | 1604 int len = demuxer_get_time_length(mpctx->demuxer); |
1571 int percentage = -1; | 1605 int percentage = -1; |
1572 char percentage_text[10]; | 1606 char percentage_text[10]; |
1573 char fractions_text[4]; | 1607 char fractions_text[4]; |
1574 int pts = demuxer_get_current_time(mpctx->demuxer); | 1608 int pts = demuxer_get_current_time(mpctx->demuxer); |
1579 if (percentage >= 0) | 1613 if (percentage >= 0) |
1580 snprintf(percentage_text, 9, " (%d%%)", percentage); | 1614 snprintf(percentage_text, 9, " (%d%%)", percentage); |
1581 else | 1615 else |
1582 percentage_text[0] = 0; | 1616 percentage_text[0] = 0; |
1583 | 1617 |
1584 if (osd_fractions==1) { | 1618 if (osd_fractions == 1) { |
1585 //print fractions as sub-second timestamp | 1619 //print fractions as sub-second timestamp |
1586 snprintf(fractions_text, sizeof(fractions_text), ".%02d", | 1620 snprintf(fractions_text, sizeof(fractions_text), ".%02d", |
1587 (int)( (mpctx->sh_video->pts - pts)* 100 + 0.5) | 1621 (int)((mpctx->sh_video->pts - pts) * 100 + 0.5) |
1588 % 100); | 1622 % 100); |
1589 } else if (osd_fractions==2) { | 1623 } else if (osd_fractions == 2) { |
1590 //print fractions by estimating the frame count within the | 1624 //print fractions by estimating the frame count within the |
1591 //second | 1625 //second |
1592 | 1626 |
1593 //rounding or cutting off numbers after the decimal point | 1627 //rounding or cutting off numbers after the decimal point |
1594 //causes problems because of float's precision and movies, | 1628 //causes problems because of float's precision and movies, |
1595 //whose first frame is not exactly at timestamp 0. Therefore, | 1629 //whose first frame is not exactly at timestamp 0. Therefore, |
1596 //we add 0.2 and cut off at the decimal point, which proved | 1630 //we add 0.2 and cut off at the decimal point, which proved |
1597 //as good heuristic | 1631 //as good heuristic |
1598 snprintf(fractions_text, sizeof(fractions_text), ".%02d", | 1632 snprintf(fractions_text, sizeof(fractions_text), ".%02d", |
1599 (int) ( ( mpctx->sh_video->pts - pts ) * | 1633 (int)((mpctx->sh_video->pts - pts) * |
1600 mpctx->sh_video->fps + 0.2 ) ); | 1634 mpctx->sh_video->fps + 0.2)); |
1601 } else { | 1635 } else { |
1602 //do not print fractions | 1636 //do not print fractions |
1603 fractions_text[0] = 0; | 1637 fractions_text[0] = 0; |
1604 } | 1638 } |
1605 | 1639 |
1606 if (osd_level == 3) | 1640 if (osd_level == 3) |
1607 snprintf(osd_text_timer, 63, | 1641 snprintf(osd_text_timer, 63, |
1608 "%c %02d:%02d:%02d%s / %02d:%02d:%02d%s", | 1642 "%c %02d:%02d:%02d%s / %02d:%02d:%02d%s", |
1609 mpctx->osd_function,pts/3600,(pts/60)%60,pts%60, | 1643 mpctx->osd_function, pts / 3600, (pts / 60) % 60, pts % 60, |
1610 fractions_text,len/3600,(len/60)%60,len%60, | 1644 fractions_text, len / 3600, (len / 60) % 60, len % 60, |
1611 percentage_text); | 1645 percentage_text); |
1612 else | 1646 else |
1613 snprintf(osd_text_timer, 63, "%c %02d:%02d:%02d%s%s", | 1647 snprintf(osd_text_timer, 63, "%c %02d:%02d:%02d%s%s", |
1614 mpctx->osd_function,pts/3600,(pts/60)%60, | 1648 mpctx->osd_function, pts / 3600, (pts / 60) % 60, |
1615 pts%60,fractions_text,percentage_text); | 1649 pts % 60, fractions_text, percentage_text); |
1616 } else | 1650 } else |
1617 osd_text_timer[0]=0; | 1651 osd_text_timer[0] = 0; |
1618 | 1652 |
1619 // always decrement the percentage timer | 1653 // always decrement the percentage timer |
1620 if(mpctx->osd_show_percentage) | 1654 if (mpctx->osd_show_percentage) |
1621 mpctx->osd_show_percentage--; | 1655 mpctx->osd_show_percentage--; |
1622 | 1656 |
1623 if(strcmp(osd_text,osd_text_timer)) { | 1657 if (strcmp(osd_text, osd_text_timer)) { |
1624 strncpy(osd_text, osd_text_timer, 63); | 1658 strncpy(osd_text, osd_text_timer, 63); |
1625 vo_osd_changed(OSDTYPE_OSD); | 1659 vo_osd_changed(OSDTYPE_OSD); |
1626 } | 1660 } |
1627 return; | 1661 return; |
1628 } | 1662 } |
1629 | 1663 |
1630 // Clear the term osd line | 1664 // Clear the term osd line |
1631 if(term_osd && osd_text[0]) { | 1665 if (term_osd && osd_text[0]) { |
1632 osd_text[0] = 0; | 1666 osd_text[0] = 0; |
1633 printf("%s\n",term_osd_esc); | 1667 printf("%s\n", term_osd_esc); |
1634 } | 1668 } |
1635 } | 1669 } |
1636 | 1670 |
1637 | 1671 void reinit_audio_chain(void) |
1638 void reinit_audio_chain(void) { | 1672 { |
1639 if (!mpctx->sh_audio) | 1673 if (!mpctx->sh_audio) |
1640 return; | 1674 return; |
1641 if (!(initialized_flags & INITIALIZED_ACODEC)) { | 1675 if (!(initialized_flags & INITIALIZED_ACODEC)) { |
1642 current_module="init_audio_codec"; | 1676 current_module = "init_audio_codec"; |
1643 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n"); | 1677 mp_msg(MSGT_CPLAYER, MSGL_INFO, "==========================================================================\n"); |
1644 if(!init_best_audio_codec(mpctx->sh_audio,audio_codec_list,audio_fm_list)){ | 1678 if (!init_best_audio_codec(mpctx->sh_audio, audio_codec_list, audio_fm_list)) { |
1645 goto init_error; | 1679 goto init_error; |
1646 } | 1680 } |
1647 initialized_flags|=INITIALIZED_ACODEC; | 1681 initialized_flags |= INITIALIZED_ACODEC; |
1648 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n"); | 1682 mp_msg(MSGT_CPLAYER, MSGL_INFO, "==========================================================================\n"); |
1649 } | 1683 } |
1650 | |
1651 | 1684 |
1652 if (!(initialized_flags & INITIALIZED_AO)) { | 1685 if (!(initialized_flags & INITIALIZED_AO)) { |
1653 current_module="af_preinit"; | 1686 current_module = "af_preinit"; |
1654 ao_data.samplerate=force_srate; | 1687 ao_data.samplerate = force_srate; |
1655 ao_data.channels=0; | 1688 ao_data.channels = 0; |
1656 ao_data.format=audio_output_format; | 1689 ao_data.format = audio_output_format; |
1657 // first init to detect best values | 1690 // first init to detect best values |
1658 if(!init_audio_filters(mpctx->sh_audio, // preliminary init | 1691 if (!init_audio_filters(mpctx->sh_audio, // preliminary init |
1659 // input: | 1692 // input: |
1660 mpctx->sh_audio->samplerate, | 1693 mpctx->sh_audio->samplerate, |
1661 // output: | 1694 // output: |
1662 &ao_data.samplerate, &ao_data.channels, &ao_data.format)){ | 1695 &ao_data.samplerate, &ao_data.channels, &ao_data.format)) { |
1663 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_AudioFilterChainPreinitError); | 1696 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_AudioFilterChainPreinitError); |
1664 exit_player(EXIT_ERROR); | 1697 exit_player(EXIT_ERROR); |
1665 } | 1698 } |
1666 current_module="ao2_init"; | 1699 current_module = "ao2_init"; |
1667 mpctx->audio_out = init_best_audio_out(audio_driver_list, | 1700 mpctx->audio_out = init_best_audio_out(audio_driver_list, |
1668 0, // plugin flag | 1701 0, // plugin flag |
1669 ao_data.samplerate, | 1702 ao_data.samplerate, |
1670 ao_data.channels, | 1703 ao_data.channels, |
1671 ao_data.format, 0); | 1704 ao_data.format, 0); |
1672 if(!mpctx->audio_out){ | 1705 if (!mpctx->audio_out) { |
1673 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO); | 1706 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CannotInitAO); |
1674 goto init_error; | 1707 goto init_error; |
1675 } | 1708 } |
1676 initialized_flags|=INITIALIZED_AO; | 1709 initialized_flags |= INITIALIZED_AO; |
1677 mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n", | 1710 mp_msg(MSGT_CPLAYER, MSGL_INFO, "AO: [%s] %dHz %dch %s (%d bytes per sample)\n", |
1678 mpctx->audio_out->info->short_name, | 1711 mpctx->audio_out->info->short_name, |
1679 ao_data.samplerate, ao_data.channels, | 1712 ao_data.samplerate, ao_data.channels, |
1680 af_fmt2str_short(ao_data.format), | 1713 af_fmt2str_short(ao_data.format), |
1681 af_fmt2bits(ao_data.format)/8 ); | 1714 af_fmt2bits(ao_data.format) / 8); |
1682 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Description: %s\nAO: Author: %s\n", | 1715 mp_msg(MSGT_CPLAYER, MSGL_V, "AO: Description: %s\nAO: Author: %s\n", |
1683 mpctx->audio_out->info->name, mpctx->audio_out->info->author); | 1716 mpctx->audio_out->info->name, mpctx->audio_out->info->author); |
1684 if(strlen(mpctx->audio_out->info->comment) > 0) | 1717 if (strlen(mpctx->audio_out->info->comment) > 0) |
1685 mp_msg(MSGT_CPLAYER,MSGL_V,"AO: Comment: %s\n", mpctx->audio_out->info->comment); | 1718 mp_msg(MSGT_CPLAYER, MSGL_V, "AO: Comment: %s\n", mpctx->audio_out->info->comment); |
1686 } | 1719 } |
1687 | 1720 |
1688 // init audio filters: | 1721 // init audio filters: |
1689 current_module="af_init"; | 1722 current_module = "af_init"; |
1690 if(!build_afilter_chain(mpctx->sh_audio, &ao_data)) { | 1723 if (!build_afilter_chain(mpctx->sh_audio, &ao_data)) { |
1691 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter); | 1724 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_NoMatchingFilter); |
1692 goto init_error; | 1725 goto init_error; |
1693 } | 1726 } |
1694 mpctx->mixer.audio_out = mpctx->audio_out; | 1727 mpctx->mixer.audio_out = mpctx->audio_out; |
1695 mpctx->mixer.volstep = volstep; | 1728 mpctx->mixer.volstep = volstep; |
1696 return; | 1729 return; |
1697 | 1730 |
1698 init_error: | 1731 init_error: |
1699 uninit_player(INITIALIZED_ACODEC|INITIALIZED_AO); // close codec and possibly AO | 1732 uninit_player(INITIALIZED_ACODEC | INITIALIZED_AO); // close codec and possibly AO |
1700 mpctx->sh_audio=mpctx->d_audio->sh=NULL; // -> nosound | 1733 mpctx->sh_audio = mpctx->d_audio->sh = NULL; // -> nosound |
1701 mpctx->d_audio->id = -2; | 1734 mpctx->d_audio->id = -2; |
1702 } | 1735 } |
1703 | |
1704 | 1736 |
1705 // Return pts value corresponding to the end point of audio written to the | 1737 // Return pts value corresponding to the end point of audio written to the |
1706 // ao so far. | 1738 // ao so far. |
1707 static double written_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio) | 1739 static double written_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio) |
1708 { | 1740 { |
1729 return a_pts; | 1761 return a_pts; |
1730 } | 1762 } |
1731 | 1763 |
1732 // Return pts value corresponding to currently playing audio. | 1764 // Return pts value corresponding to currently playing audio. |
1733 double playing_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio, | 1765 double playing_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio, |
1734 const ao_functions_t *audio_out) | 1766 const ao_functions_t *audio_out) |
1735 { | 1767 { |
1736 return written_audio_pts(sh_audio, d_audio) - playback_speed * | 1768 return written_audio_pts(sh_audio, d_audio) - playback_speed * |
1737 audio_out->get_delay(); | 1769 audio_out->get_delay(); |
1738 } | 1770 } |
1739 | 1771 |
1740 static int check_framedrop(double frame_time) { | 1772 static int check_framedrop(double frame_time) |
1741 // check for frame-drop: | 1773 { |
1742 current_module = "check_framedrop"; | 1774 // check for frame-drop: |
1743 if (mpctx->sh_audio && !mpctx->d_audio->eof) { | 1775 current_module = "check_framedrop"; |
1744 static int dropped_frames; | 1776 if (mpctx->sh_audio && !mpctx->d_audio->eof) { |
1745 float delay = playback_speed*mpctx->audio_out->get_delay(); | 1777 static int dropped_frames; |
1746 float d = delay-mpctx->delay; | 1778 float delay = playback_speed * mpctx->audio_out->get_delay(); |
1747 ++total_frame_cnt; | 1779 float d = delay - mpctx->delay; |
1748 // we should avoid dropping too many frames in sequence unless we | 1780 ++total_frame_cnt; |
1749 // are too late. and we allow 100ms A-V delay here: | 1781 // we should avoid dropping too many frames in sequence unless we |
1750 if (d < -dropped_frames*frame_time-0.100 && | 1782 // are too late. and we allow 100ms A-V delay here: |
1751 mpctx->osd_function != OSD_PAUSE) { | 1783 if (d < -dropped_frames * frame_time - 0.100 && |
1752 ++drop_frame_cnt; | 1784 mpctx->osd_function != OSD_PAUSE) { |
1753 ++dropped_frames; | 1785 ++drop_frame_cnt; |
1754 return frame_dropping; | 1786 ++dropped_frames; |
1755 } else | 1787 return frame_dropping; |
1756 dropped_frames = 0; | 1788 } else |
1757 } | 1789 dropped_frames = 0; |
1758 return 0; | 1790 } |
1791 return 0; | |
1759 } | 1792 } |
1760 | 1793 |
1761 static int generate_video_frame(sh_video_t *sh_video, demux_stream_t *d_video) | 1794 static int generate_video_frame(sh_video_t *sh_video, demux_stream_t *d_video) |
1762 { | 1795 { |
1763 unsigned char *start; | 1796 unsigned char *start; |
1764 int in_size; | 1797 int in_size; |
1765 int hit_eof=0; | 1798 int hit_eof = 0; |
1766 double pts; | 1799 double pts; |
1767 | 1800 |
1768 while (1) { | 1801 while (1) { |
1769 int drop_frame = check_framedrop(sh_video->frametime); | 1802 int drop_frame = check_framedrop(sh_video->frametime); |
1770 void *decoded_frame; | 1803 void *decoded_frame; |
1771 current_module = "decode video"; | 1804 current_module = "decode video"; |
1772 // XXX Time used in this call is not counted in any performance | 1805 // XXX Time used in this call is not counted in any performance |
1773 // timer now, OSD is not updated correctly for filter-added frames | 1806 // timer now, OSD is not updated correctly for filter-added frames |
1774 if (vf_output_queued_frame(sh_video->vfilter)) | 1807 if (vf_output_queued_frame(sh_video->vfilter)) |
1775 break; | 1808 break; |
1776 current_module = "video_read_frame"; | 1809 current_module = "video_read_frame"; |
1777 in_size = ds_get_packet_pts(d_video, &start, &pts); | 1810 in_size = ds_get_packet_pts(d_video, &start, &pts); |
1778 if (in_size < 0) { | 1811 if (in_size < 0) { |
1779 // try to extract last frames in case of decoder lag | 1812 // try to extract last frames in case of decoder lag |
1780 in_size = 0; | 1813 in_size = 0; |
1781 pts = MP_NOPTS_VALUE; | 1814 pts = MP_NOPTS_VALUE; |
1782 hit_eof = 1; | 1815 hit_eof = 1; |
1783 } | 1816 } |
1784 if (in_size > max_framesize) | 1817 if (in_size > max_framesize) |
1785 max_framesize = in_size; | 1818 max_framesize = in_size; |
1786 current_module = "decode video"; | 1819 current_module = "decode video"; |
1787 decoded_frame = decode_video(sh_video, start, in_size, drop_frame, pts, NULL); | 1820 decoded_frame = decode_video(sh_video, start, in_size, drop_frame, pts, NULL); |
1788 if (decoded_frame) { | 1821 if (decoded_frame) { |
1789 update_subtitles(sh_video, sh_video->pts, mpctx->d_sub, 0); | 1822 update_subtitles(sh_video, sh_video->pts, mpctx->d_sub, 0); |
1790 update_teletext(sh_video, mpctx->demuxer, 0); | 1823 update_teletext(sh_video, mpctx->demuxer, 0); |
1791 update_osd_msg(); | 1824 update_osd_msg(); |
1792 current_module = "filter video"; | 1825 current_module = "filter video"; |
1793 if (filter_video(sh_video, decoded_frame, sh_video->pts)) | 1826 if (filter_video(sh_video, decoded_frame, sh_video->pts)) |
1794 break; | 1827 break; |
1795 } else if (drop_frame) | 1828 } else if (drop_frame) |
1796 return -1; | 1829 return -1; |
1797 if (hit_eof) | 1830 if (hit_eof) |
1798 return 0; | 1831 return 0; |
1799 } | 1832 } |
1800 return 1; | 1833 return 1; |
1801 } | 1834 } |
1802 | 1835 |
1803 #ifdef HAVE_RTC | 1836 #ifdef HAVE_RTC |
1804 int rtc_fd = -1; | 1837 int rtc_fd = -1; |
1805 #endif | 1838 #endif |
1806 | 1839 |
1807 static float timing_sleep(float time_frame) | 1840 static float timing_sleep(float time_frame) |
1808 { | 1841 { |
1809 #ifdef HAVE_RTC | 1842 #ifdef HAVE_RTC |
1810 if (rtc_fd >= 0){ | 1843 if (rtc_fd >= 0) { |
1811 // -------- RTC ----------- | 1844 // -------- RTC ----------- |
1812 current_module="sleep_rtc"; | 1845 current_module = "sleep_rtc"; |
1813 while (time_frame > 0.000) { | 1846 while (time_frame > 0.000) { |
1814 unsigned long rtc_ts; | 1847 unsigned long rtc_ts; |
1815 if (read(rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0) | 1848 if (read(rtc_fd, &rtc_ts, sizeof(rtc_ts)) <= 0) |
1816 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno)); | 1849 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCReadError, strerror(errno)); |
1817 time_frame -= GetRelativeTime(); | 1850 time_frame -= GetRelativeTime(); |
1818 } | 1851 } |
1819 } else | 1852 } else |
1820 #endif | 1853 #endif |
1821 { | 1854 { |
1822 // assume kernel HZ=100 for softsleep, works with larger HZ but with | 1855 // assume kernel HZ=100 for softsleep, works with larger HZ but with |
1823 // unnecessarily high CPU usage | 1856 // unnecessarily high CPU usage |
1824 float margin = softsleep ? 0.011 : 0; | 1857 float margin = softsleep ? 0.011 : 0; |
1825 current_module = "sleep_timer"; | 1858 current_module = "sleep_timer"; |
1826 while (time_frame > margin) { | 1859 while (time_frame > margin) { |
1827 usec_sleep(1000000 * (time_frame - margin)); | 1860 usec_sleep(1000000 * (time_frame - margin)); |
1828 time_frame -= GetRelativeTime(); | 1861 time_frame -= GetRelativeTime(); |
1829 } | 1862 } |
1830 if (softsleep){ | 1863 if (softsleep) { |
1831 current_module = "sleep_soft"; | 1864 current_module = "sleep_soft"; |
1832 if (time_frame < 0) | 1865 if (time_frame < 0) |
1833 mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow); | 1866 mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SoftsleepUnderflow); |
1834 while (time_frame > 0) | 1867 while (time_frame > 0) |
1835 time_frame-=GetRelativeTime(); // burn the CPU | 1868 time_frame -= GetRelativeTime(); // burn the CPU |
1836 } | 1869 } |
1837 } | 1870 } |
1838 return time_frame; | 1871 return time_frame; |
1839 } | 1872 } |
1840 | 1873 |
1841 static int select_subtitle(MPContext *mpctx) | 1874 static int select_subtitle(MPContext *mpctx) |
1842 { | 1875 { |
1843 // find the best sub to use | 1876 // find the best sub to use |
1844 int id; | 1877 int id; |
1845 int found = 0; | 1878 int found = 0; |
1846 mpctx->global_sub_pos = -1; // no subs by default | 1879 mpctx->global_sub_pos = -1; // no subs by default |
1847 if (vobsub_id >= 0) { | 1880 if (vobsub_id >= 0) { |
1848 // if user asks for a vobsub id, use that first. | 1881 // if user asks for a vobsub id, use that first. |
1849 id = vobsub_id; | 1882 id = vobsub_id; |
1850 found = mp_property_do("sub_vob", M_PROPERTY_SET, &id, mpctx) == M_PROPERTY_OK; | 1883 found = mp_property_do("sub_vob", M_PROPERTY_SET, &id, mpctx) == M_PROPERTY_OK; |
1851 } | 1884 } |
1852 | 1885 |
1853 if (!found && dvdsub_id >= 0) { | 1886 if (!found && dvdsub_id >= 0) { |
1854 // if user asks for a dvd sub id, use that next. | 1887 // if user asks for a dvd sub id, use that next. |
1855 id = dvdsub_id; | 1888 id = dvdsub_id; |
1856 found = mp_property_do("sub_demux", M_PROPERTY_SET, &id, mpctx) == M_PROPERTY_OK; | 1889 found = mp_property_do("sub_demux", M_PROPERTY_SET, &id, mpctx) == M_PROPERTY_OK; |
1857 } | 1890 } |
1858 | 1891 |
1859 if (!found) { | 1892 if (!found) { |
1860 // if there are text subs to use, use those. (autosubs come last here) | 1893 // if there are text subs to use, use those. (autosubs come last here) |
1861 id = 0; | 1894 id = 0; |
1862 found = mp_property_do("sub_file", M_PROPERTY_SET, &id, mpctx) == M_PROPERTY_OK; | 1895 found = mp_property_do("sub_file", M_PROPERTY_SET, &id, mpctx) == M_PROPERTY_OK; |
1863 } | 1896 } |
1864 | 1897 |
1865 if (!found && dvdsub_id == -1) { | 1898 if (!found && dvdsub_id == -1) { |
1866 // finally select subs by language and container hints | 1899 // finally select subs by language and container hints |
1867 if (dvdsub_id == -1 && dvdsub_lang) | 1900 if (dvdsub_id == -1 && dvdsub_lang) |
1868 dvdsub_id = demuxer_sub_track_by_lang(mpctx->demuxer, dvdsub_lang); | 1901 dvdsub_id = demuxer_sub_track_by_lang(mpctx->demuxer, dvdsub_lang); |
1869 if (dvdsub_id == -1) | 1902 if (dvdsub_id == -1) |
1870 dvdsub_id = demuxer_default_sub_track(mpctx->demuxer); | 1903 dvdsub_id = demuxer_default_sub_track(mpctx->demuxer); |
1871 if (dvdsub_id >= 0) { | 1904 if (dvdsub_id >= 0) { |
1872 id = dvdsub_id; | 1905 id = dvdsub_id; |
1873 found = mp_property_do("sub_demux", M_PROPERTY_SET, &id, mpctx) == M_PROPERTY_OK; | 1906 found = mp_property_do("sub_demux", M_PROPERTY_SET, &id, mpctx) == M_PROPERTY_OK; |
1874 } | 1907 } |
1875 } | 1908 } |
1876 return found; | 1909 return found; |
1877 } | 1910 } |
1878 | 1911 |
1879 #ifdef CONFIG_DVDNAV | 1912 #ifdef CONFIG_DVDNAV |
1880 #ifndef FF_B_TYPE | 1913 #ifndef FF_B_TYPE |
1881 #define FF_B_TYPE 3 | 1914 #define FF_B_TYPE 3 |
1882 #endif | 1915 #endif |
1883 /** | 1916 /** |
1884 * @brief Store decoded video image. | 1917 * @brief Store decoded video image. |
1885 */ | 1918 */ |
1886 static mp_image_t * mp_dvdnav_copy_mpi(mp_image_t *to_mpi, | 1919 static mp_image_t *mp_dvdnav_copy_mpi(mp_image_t *to_mpi, |
1887 mp_image_t *from_mpi) { | 1920 mp_image_t *from_mpi) |
1921 { | |
1888 mp_image_t *mpi; | 1922 mp_image_t *mpi; |
1889 | 1923 |
1890 // do not store B-frames | 1924 // do not store B-frames |
1891 if (from_mpi->pict_type == FF_B_TYPE) | 1925 if (from_mpi->pict_type == FF_B_TYPE) |
1892 return to_mpi; | 1926 return to_mpi; |
1899 else { | 1933 else { |
1900 if (to_mpi) | 1934 if (to_mpi) |
1901 free_mp_image(to_mpi); | 1935 free_mp_image(to_mpi); |
1902 if (from_mpi->w == 0 || from_mpi->h == 0) | 1936 if (from_mpi->w == 0 || from_mpi->h == 0) |
1903 return NULL; | 1937 return NULL; |
1904 mpi = alloc_mpi(from_mpi->w,from_mpi->h,from_mpi->imgfmt); | 1938 mpi = alloc_mpi(from_mpi->w, from_mpi->h, from_mpi->imgfmt); |
1905 } | 1939 } |
1906 | 1940 |
1907 copy_mpi(mpi,from_mpi); | 1941 copy_mpi(mpi, from_mpi); |
1908 return mpi; | 1942 return mpi; |
1909 } | 1943 } |
1910 | 1944 |
1911 static void mp_dvdnav_reset_stream (MPContext *ctx) { | 1945 static void mp_dvdnav_reset_stream(MPContext *ctx) |
1946 { | |
1912 if (ctx->sh_video) { | 1947 if (ctx->sh_video) { |
1913 // clear video pts | 1948 // clear video pts |
1914 ctx->d_video->pts = 0.0f; | 1949 ctx->d_video->pts = 0.0f; |
1915 ctx->sh_video->pts = 0.0f; | 1950 ctx->sh_video->pts = 0.0f; |
1916 ctx->sh_video->i_pts = 0.0f; | 1951 ctx->sh_video->i_pts = 0.0f; |
1917 ctx->sh_video->last_pts = 0.0f; | 1952 ctx->sh_video->last_pts = 0.0f; |
1918 ctx->sh_video->num_buffered_pts = 0; | 1953 ctx->sh_video->num_buffered_pts = 0; |
1919 ctx->sh_video->num_frames = 0; | 1954 ctx->sh_video->num_frames = 0; |
1920 ctx->sh_video->num_frames_decoded = 0; | 1955 ctx->sh_video->num_frames_decoded = 0; |
1921 ctx->sh_video->timer = 0.0f; | 1956 ctx->sh_video->timer = 0.0f; |
1922 ctx->sh_video->stream_delay = 0.0f; | 1957 ctx->sh_video->stream_delay = 0.0f; |
1923 ctx->sh_video->timer = 0; | 1958 ctx->sh_video->timer = 0; |
1924 ctx->demuxer->stream_pts = MP_NOPTS_VALUE; | 1959 ctx->demuxer->stream_pts = MP_NOPTS_VALUE; |
1925 } | 1960 } |
1926 | 1961 |
1927 if (ctx->sh_audio) { | 1962 if (ctx->sh_audio) { |
1928 // free audio packets and reset | 1963 // free audio packets and reset |
1929 ds_free_packs(ctx->d_audio); | 1964 ds_free_packs(ctx->d_audio); |
1930 audio_delay -= ctx->sh_audio->stream_delay; | 1965 audio_delay -= ctx->sh_audio->stream_delay; |
1931 ctx->delay =- audio_delay; | 1966 ctx->delay = -audio_delay; |
1932 ctx->audio_out->reset(); | 1967 ctx->audio_out->reset(); |
1933 resync_audio_stream(ctx->sh_audio); | 1968 resync_audio_stream(ctx->sh_audio); |
1934 } | 1969 } |
1935 | 1970 |
1936 audio_delay = 0.0f; | 1971 audio_delay = 0.0f; |
1956 { | 1991 { |
1957 if (mpctx->stream->type != STREAMTYPE_DVDNAV) | 1992 if (mpctx->stream->type != STREAMTYPE_DVDNAV) |
1958 return decoded_frame; | 1993 return decoded_frame; |
1959 | 1994 |
1960 // a change occured in dvdnav stream | 1995 // a change occured in dvdnav stream |
1961 if (mp_dvdnav_cell_has_changed(mpctx->stream,0)) { | 1996 if (mp_dvdnav_cell_has_changed(mpctx->stream, 0)) { |
1962 mp_dvdnav_read_wait(mpctx->stream, 1, 1); | 1997 mp_dvdnav_read_wait(mpctx->stream, 1, 1); |
1963 mp_dvdnav_context_free(mpctx); | 1998 mp_dvdnav_context_free(mpctx); |
1964 mp_dvdnav_reset_stream(mpctx); | 1999 mp_dvdnav_reset_stream(mpctx); |
1965 mp_dvdnav_read_wait(mpctx->stream, 0, 1); | 2000 mp_dvdnav_read_wait(mpctx->stream, 0, 1); |
1966 mp_dvdnav_cell_has_changed(mpctx->stream,1); | 2001 mp_dvdnav_cell_has_changed(mpctx->stream, 1); |
1967 } | 2002 } |
1968 | 2003 |
1969 if (*in_size < 0) { | 2004 if (*in_size < 0) { |
1970 float len; | 2005 float len; |
1971 | 2006 |
1981 mp_dvdnav_skip_wait(mpctx->stream); | 2016 mp_dvdnav_skip_wait(mpctx->stream); |
1982 } | 2017 } |
1983 mpctx->sh_video->pts += 1 / mpctx->sh_video->fps; | 2018 mpctx->sh_video->pts += 1 / mpctx->sh_video->fps; |
1984 | 2019 |
1985 if (mpctx->nav_buffer) { | 2020 if (mpctx->nav_buffer) { |
1986 *start = mpctx->nav_start; | 2021 *start = mpctx->nav_start; |
1987 *in_size = mpctx->nav_in_size; | 2022 *in_size = mpctx->nav_in_size; |
1988 if (mpctx->nav_start) | 2023 if (mpctx->nav_start) |
1989 memcpy(*start,mpctx->nav_buffer,mpctx->nav_in_size); | 2024 memcpy(*start, mpctx->nav_buffer, mpctx->nav_in_size); |
1990 } | 2025 } |
1991 } | 2026 } |
1992 | 2027 |
1993 return decoded_frame; | 2028 return decoded_frame; |
1994 } | 2029 } |
2003 if (mpctx->stream->type != STREAMTYPE_DVDNAV) | 2038 if (mpctx->stream->type != STREAMTYPE_DVDNAV) |
2004 return; | 2039 return; |
2005 | 2040 |
2006 free(mpctx->nav_buffer); | 2041 free(mpctx->nav_buffer); |
2007 | 2042 |
2008 mpctx->nav_buffer = malloc(in_size); | 2043 mpctx->nav_buffer = malloc(in_size); |
2009 mpctx->nav_start = start; | 2044 mpctx->nav_start = start; |
2010 mpctx->nav_in_size = mpctx->nav_buffer ? in_size : -1; | 2045 mpctx->nav_in_size = mpctx->nav_buffer ? in_size : -1; |
2011 if (mpctx->nav_buffer) | 2046 if (mpctx->nav_buffer) |
2012 memcpy(mpctx->nav_buffer,start,in_size); | 2047 memcpy(mpctx->nav_buffer, start, in_size); |
2013 | 2048 |
2014 if (decoded_frame && mpctx->nav_smpi != decoded_frame) | 2049 if (decoded_frame && mpctx->nav_smpi != decoded_frame) |
2015 mpctx->nav_smpi = mp_dvdnav_copy_mpi(mpctx->nav_smpi,decoded_frame); | 2050 mpctx->nav_smpi = mp_dvdnav_copy_mpi(mpctx->nav_smpi, decoded_frame); |
2016 } | 2051 } |
2052 | |
2017 #endif /* CONFIG_DVDNAV */ | 2053 #endif /* CONFIG_DVDNAV */ |
2018 | 2054 |
2019 static void adjust_sync_and_print_status(int between_frames, float timing_error) | 2055 static void adjust_sync_and_print_status(int between_frames, float timing_error) |
2020 { | 2056 { |
2021 current_module="av_sync"; | 2057 current_module = "av_sync"; |
2022 | 2058 |
2023 if(mpctx->sh_audio){ | 2059 if (mpctx->sh_audio) { |
2024 double a_pts, v_pts; | 2060 double a_pts, v_pts; |
2025 | 2061 |
2026 if (autosync) | 2062 if (autosync) |
2027 /* | 2063 /* |
2028 * If autosync is enabled, the value for delay must be calculated | 2064 * If autosync is enabled, the value for delay must be calculated |
2029 * a bit differently. It is set only to the difference between | 2065 * a bit differently. It is set only to the difference between |
2030 * the audio and video timers. Any attempt to include the real | 2066 * the audio and video timers. Any attempt to include the real |
2031 * or corrected delay causes the pts_correction code below to | 2067 * or corrected delay causes the pts_correction code below to |
2032 * try to correct for the changes in delay which autosync is | 2068 * try to correct for the changes in delay which autosync is |
2033 * trying to measure. This keeps the two from competing, but still | 2069 * trying to measure. This keeps the two from competing, but still |
2034 * allows the code to correct for PTS drift *only*. (Using a delay | 2070 * allows the code to correct for PTS drift *only*. (Using a delay |
2035 * value here, even a "corrected" one, would be incompatible with | 2071 * value here, even a "corrected" one, would be incompatible with |
2036 * autosync mode.) | 2072 * autosync mode.) |
2037 */ | 2073 */ |
2038 a_pts = written_audio_pts(mpctx->sh_audio, mpctx->d_audio) - mpctx->delay; | 2074 a_pts = written_audio_pts(mpctx->sh_audio, mpctx->d_audio) - mpctx->delay; |
2039 else | 2075 else |
2040 a_pts = playing_audio_pts(mpctx->sh_audio, mpctx->d_audio, mpctx->audio_out); | 2076 a_pts = playing_audio_pts(mpctx->sh_audio, mpctx->d_audio, mpctx->audio_out); |
2041 | 2077 |
2042 v_pts = mpctx->sh_video->pts; | 2078 v_pts = mpctx->sh_video->pts; |
2043 | 2079 |
2044 { | 2080 { |
2045 static int drop_message; | 2081 static int drop_message; |
2046 double AV_delay = a_pts - audio_delay - v_pts; | 2082 double AV_delay = a_pts - audio_delay - v_pts; |
2047 double x; | 2083 double x; |
2048 // not a good idea to do A-V correction with with bogus values | 2084 // not a good idea to do A-V correction with with bogus values |
2049 if (a_pts == MP_NOPTS_VALUE || v_pts == MP_NOPTS_VALUE) | 2085 if (a_pts == MP_NOPTS_VALUE || v_pts == MP_NOPTS_VALUE) |
2050 AV_delay = 0; | 2086 AV_delay = 0; |
2051 if (AV_delay>0.5 && drop_frame_cnt>50 && drop_message==0){ | 2087 if (AV_delay > 0.5 && drop_frame_cnt > 50 && drop_message == 0) { |
2052 ++drop_message; | 2088 ++drop_message; |
2053 mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow); | 2089 mp_msg(MSGT_AVSYNC, MSGL_WARN, MSGTR_SystemTooSlow); |
2054 } | 2090 } |
2055 if (autosync) | 2091 if (autosync) |
2056 x = AV_delay*0.1f; | 2092 x = AV_delay * 0.1f; |
2057 else | 2093 else |
2058 /* Do not correct target time for the next frame if this frame | 2094 /* Do not correct target time for the next frame if this frame |
2059 * was late not because of wrong target time but because the | 2095 * was late not because of wrong target time but because the |
2060 * target time could not be met */ | 2096 * target time could not be met */ |
2061 x = (AV_delay + timing_error * playback_speed) * 0.1f; | 2097 x = (AV_delay + timing_error * playback_speed) * 0.1f; |
2062 if (x < -max_pts_correction) | 2098 if (x < -max_pts_correction) |
2063 x = -max_pts_correction; | 2099 x = -max_pts_correction; |
2064 else if (x> max_pts_correction) | 2100 else if (x > max_pts_correction) |
2065 x = max_pts_correction; | 2101 x = max_pts_correction; |
2066 if (default_max_pts_correction >= 0) | 2102 if (default_max_pts_correction >= 0) |
2067 max_pts_correction = default_max_pts_correction; | 2103 max_pts_correction = default_max_pts_correction; |
2068 else | 2104 else |
2069 max_pts_correction = mpctx->sh_video->frametime*0.10; // +-10% of time | 2105 max_pts_correction = mpctx->sh_video->frametime * 0.10; // +-10% of time |
2070 if (!between_frames) { | 2106 if (!between_frames) { |
2071 mpctx->delay+=x; | 2107 mpctx->delay += x; |
2072 c_total+=x; | 2108 c_total += x; |
2073 } | 2109 } |
2074 if(!quiet) | 2110 if (!quiet) |
2075 print_status(a_pts - audio_delay, AV_delay, c_total); | 2111 print_status(a_pts - audio_delay, AV_delay, c_total); |
2076 } | 2112 } |
2077 | |
2078 } else { | 2113 } else { |
2079 // No audio: | 2114 // No audio: |
2080 | 2115 |
2081 if (!quiet) | 2116 if (!quiet) |
2082 print_status(0, 0, 0); | 2117 print_status(0, 0, 0); |
2083 } | 2118 } |
2084 } | 2119 } |
2085 | 2120 |
2086 static int fill_audio_out_buffers(void) | 2121 static int fill_audio_out_buffers(void) |
2087 { | 2122 { |
2088 unsigned int t; | 2123 unsigned int t; |
2089 double tt; | 2124 double tt; |
2090 int playsize; | 2125 int playsize; |
2091 int playflags=0; | 2126 int playflags = 0; |
2092 int audio_eof=0; | 2127 int audio_eof = 0; |
2093 int bytes_to_write; | 2128 int bytes_to_write; |
2094 int format_change = 0; | 2129 int format_change = 0; |
2095 sh_audio_t * const sh_audio = mpctx->sh_audio; | 2130 sh_audio_t *const sh_audio = mpctx->sh_audio; |
2096 | 2131 |
2097 current_module="play_audio"; | 2132 current_module = "play_audio"; |
2098 | 2133 |
2099 while (1) { | 2134 while (1) { |
2100 int sleep_time; | 2135 int sleep_time; |
2101 // all the current uses of ao_data.pts seem to be in aos that handle | 2136 // all the current uses of ao_data.pts seem to be in aos that handle |
2102 // sync completely wrong; there should be no need to use ao_data.pts | 2137 // sync completely wrong; there should be no need to use ao_data.pts |
2103 // in get_space() | 2138 // in get_space() |
2104 ao_data.pts = ((mpctx->sh_video?mpctx->sh_video->timer:0)+mpctx->delay)*90000.0; | 2139 ao_data.pts = ((mpctx->sh_video ? mpctx->sh_video->timer : 0) + mpctx->delay) * 90000.0; |
2105 bytes_to_write = mpctx->audio_out->get_space(); | 2140 bytes_to_write = mpctx->audio_out->get_space(); |
2106 if (mpctx->sh_video || bytes_to_write >= ao_data.outburst) | 2141 if (mpctx->sh_video || bytes_to_write >= ao_data.outburst) |
2107 break; | 2142 break; |
2108 | 2143 |
2109 // handle audio-only case: | 2144 // handle audio-only case: |
2110 // this is where mplayer sleeps during audio-only playback | 2145 // this is where mplayer sleeps during audio-only playback |
2111 // to avoid 100% CPU use | 2146 // to avoid 100% CPU use |
2112 sleep_time = (ao_data.outburst - bytes_to_write) * 1000 / ao_data.bps; | 2147 sleep_time = (ao_data.outburst - bytes_to_write) * 1000 / ao_data.bps; |
2113 if (sleep_time < 10) sleep_time = 10; // limit to 100 wakeups per second | 2148 if (sleep_time < 10) |
2114 usec_sleep(sleep_time * 1000); | 2149 sleep_time = 10; // limit to 100 wakeups per second |
2150 usec_sleep(sleep_time * 1000); | |
2115 } | 2151 } |
2116 | 2152 |
2117 while (bytes_to_write) { | 2153 while (bytes_to_write) { |
2118 int res; | 2154 int res; |
2119 playsize = bytes_to_write; | 2155 playsize = bytes_to_write; |
2120 if (playsize > MAX_OUTBURST) | 2156 if (playsize > MAX_OUTBURST) |
2121 playsize = MAX_OUTBURST; | 2157 playsize = MAX_OUTBURST; |
2122 bytes_to_write -= playsize; | 2158 bytes_to_write -= playsize; |
2123 | 2159 |
2124 // Fill buffer if needed: | 2160 // Fill buffer if needed: |
2125 current_module="decode_audio"; | 2161 current_module = "decode_audio"; |
2126 t = GetTimer(); | 2162 t = GetTimer(); |
2127 if (!format_change) { | 2163 if (!format_change) { |
2128 res = mp_decode_audio(sh_audio, playsize); | 2164 res = mp_decode_audio(sh_audio, playsize); |
2129 format_change = res == -2; | 2165 format_change = res == -2; |
2130 } | 2166 } |
2131 if (!format_change && res < 0) // EOF or error | 2167 if (!format_change && res < 0) // EOF or error |
2132 if (mpctx->d_audio->eof) { | 2168 if (mpctx->d_audio->eof) { |
2133 audio_eof = 1; | 2169 audio_eof = 1; |
2134 if (sh_audio->a_out_buffer_len == 0) | 2170 if (sh_audio->a_out_buffer_len == 0) |
2135 return 0; | 2171 return 0; |
2136 } | 2172 } |
2137 t = GetTimer() - t; | 2173 t = GetTimer() - t; |
2138 tt = t*0.000001f; audio_time_usage+=tt; | 2174 tt = t * 0.000001f; |
2139 if (playsize > sh_audio->a_out_buffer_len) { | 2175 audio_time_usage += tt; |
2140 playsize = sh_audio->a_out_buffer_len; | 2176 if (playsize > sh_audio->a_out_buffer_len) { |
2141 if (audio_eof || format_change) | 2177 playsize = sh_audio->a_out_buffer_len; |
2142 playflags |= AOPLAY_FINAL_CHUNK; | 2178 if (audio_eof || format_change) |
2143 } | 2179 playflags |= AOPLAY_FINAL_CHUNK; |
2144 if (!playsize) | 2180 } |
2145 break; | 2181 if (!playsize) |
2146 | 2182 break; |
2147 // play audio: | 2183 |
2148 current_module="play_audio"; | 2184 // play audio: |
2149 | 2185 current_module = "play_audio"; |
2150 // Is this pts value actually useful for the aos that access it? | 2186 |
2151 // They're obviously badly broken in the way they handle av sync; | 2187 // Is this pts value actually useful for the aos that access it? |
2152 // would not having access to this make them more broken? | 2188 // They're obviously badly broken in the way they handle av sync; |
2153 ao_data.pts = ((mpctx->sh_video?mpctx->sh_video->timer:0)+mpctx->delay)*90000.0; | 2189 // would not having access to this make them more broken? |
2154 playsize = mpctx->audio_out->play(sh_audio->a_out_buffer, playsize, playflags); | 2190 ao_data.pts = ((mpctx->sh_video ? mpctx->sh_video->timer : 0) + mpctx->delay) * 90000.0; |
2155 | 2191 playsize = mpctx->audio_out->play(sh_audio->a_out_buffer, playsize, playflags); |
2156 if (playsize > 0) { | 2192 |
2157 sh_audio->a_out_buffer_len -= playsize; | 2193 if (playsize > 0) { |
2158 memmove(sh_audio->a_out_buffer, &sh_audio->a_out_buffer[playsize], | 2194 sh_audio->a_out_buffer_len -= playsize; |
2159 sh_audio->a_out_buffer_len); | 2195 memmove(sh_audio->a_out_buffer, &sh_audio->a_out_buffer[playsize], |
2160 mpctx->delay += playback_speed*playsize/(double)ao_data.bps; | 2196 sh_audio->a_out_buffer_len); |
2161 } | 2197 mpctx->delay += playback_speed * playsize / (double)ao_data.bps; |
2162 else if ((format_change || audio_eof) && mpctx->audio_out->get_delay() < .04) { | 2198 } else if ((format_change || audio_eof) && mpctx->audio_out->get_delay() < .04) { |
2163 // Sanity check to avoid hanging in case current ao doesn't output | 2199 // Sanity check to avoid hanging in case current ao doesn't output |
2164 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK | 2200 // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK |
2165 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Audio output truncated at end.\n"); | 2201 mp_msg(MSGT_CPLAYER, MSGL_WARN, "Audio output truncated at end.\n"); |
2166 sh_audio->a_out_buffer_len = 0; | 2202 sh_audio->a_out_buffer_len = 0; |
2167 } | 2203 } |
2168 } | 2204 } |
2169 if (format_change) { | 2205 if (format_change) { |
2170 uninit_player(INITIALIZED_AO); | 2206 uninit_player(INITIALIZED_AO); |
2171 reinit_audio_chain(); | 2207 reinit_audio_chain(); |
2172 } | 2208 } |
2173 return 1; | 2209 return 1; |
2174 } | 2210 } |
2175 | 2211 |
2176 static void handle_udp_master(double time) | 2212 static void handle_udp_master(double time) |
2177 { | 2213 { |
2178 #ifdef CONFIG_NETWORKING | 2214 #ifdef CONFIG_NETWORKING |
2179 if (udp_master) { | 2215 if (udp_master) { |
2180 char current_time[256]; | 2216 char current_time[256]; |
2181 snprintf(current_time, sizeof(current_time), "%f", time); | 2217 snprintf(current_time, sizeof(current_time), "%f", time); |
2182 send_udp(udp_ip, udp_port, current_time); | 2218 send_udp(udp_ip, udp_port, current_time); |
2183 } | 2219 } |
2184 #endif /* CONFIG_NETWORKING */ | 2220 #endif /* CONFIG_NETWORKING */ |
2185 } | 2221 } |
2186 | 2222 |
2187 static int sleep_until_update(float *time_frame, float *aq_sleep_time) | 2223 static int sleep_until_update(float *time_frame, float *aq_sleep_time) |
2188 { | 2224 { |
2189 int frame_time_remaining = 0; | 2225 int frame_time_remaining = 0; |
2190 current_module="calc_sleep_time"; | 2226 current_module = "calc_sleep_time"; |
2191 | 2227 |
2192 #ifdef CONFIG_NETWORKING | 2228 #ifdef CONFIG_NETWORKING |
2193 if (udp_slave) { | 2229 if (udp_slave) { |
2194 int udp_master_exited = udp_slave_sync(mpctx); | 2230 int udp_master_exited = udp_slave_sync(mpctx); |
2195 if (udp_master_exited) { | 2231 if (udp_master_exited) { |
2201 #endif /* CONFIG_NETWORKING */ | 2237 #endif /* CONFIG_NETWORKING */ |
2202 | 2238 |
2203 *time_frame -= GetRelativeTime(); // reset timer | 2239 *time_frame -= GetRelativeTime(); // reset timer |
2204 | 2240 |
2205 if (mpctx->sh_audio && !mpctx->d_audio->eof) { | 2241 if (mpctx->sh_audio && !mpctx->d_audio->eof) { |
2206 float delay = mpctx->audio_out->get_delay(); | 2242 float delay = mpctx->audio_out->get_delay(); |
2207 mp_dbg(MSGT_AVSYNC, MSGL_DBG2, "delay=%f\n", delay); | 2243 mp_dbg(MSGT_AVSYNC, MSGL_DBG2, "delay=%f\n", delay); |
2208 | 2244 |
2209 if (autosync) { | 2245 if (autosync) { |
2210 /* | 2246 /* |
2211 * Adjust this raw delay value by calculating the expected | 2247 * Adjust this raw delay value by calculating the expected |
2212 * delay for this frame and generating a new value which is | 2248 * delay for this frame and generating a new value which is |
2213 * weighted between the two. The higher autosync is, the | 2249 * weighted between the two. The higher autosync is, the |
2214 * closer to the delay value gets to that which "-nosound" | 2250 * closer to the delay value gets to that which "-nosound" |
2215 * would have used, and the longer it will take for A/V | 2251 * would have used, and the longer it will take for A/V |
2216 * sync to settle at the right value (but it eventually will.) | 2252 * sync to settle at the right value (but it eventually will.) |
2217 * This settling time is very short for values below 100. | 2253 * This settling time is very short for values below 100. |
2218 */ | 2254 */ |
2219 float predicted = mpctx->delay / playback_speed + *time_frame; | 2255 float predicted = mpctx->delay / playback_speed + *time_frame; |
2220 float difference = delay - predicted; | 2256 float difference = delay - predicted; |
2221 delay = predicted + difference / (float)autosync; | 2257 delay = predicted + difference / (float)autosync; |
2222 } | 2258 } |
2223 | 2259 |
2224 *time_frame = delay - mpctx->delay / playback_speed; | 2260 *time_frame = delay - mpctx->delay / playback_speed; |
2225 | 2261 |
2226 // delay = amount of audio buffered in soundcard/driver | 2262 // delay = amount of audio buffered in soundcard/driver |
2227 if (delay > 0.25) delay=0.25; else | 2263 if (delay > 0.25) |
2228 if (delay < 0.10) delay=0.10; | 2264 delay = 0.25; |
2229 if (*time_frame > delay*0.6) { | 2265 else if (delay < 0.10) |
2230 // sleep time too big - may cause audio drops (buffer underrun) | 2266 delay = 0.10; |
2231 frame_time_remaining = 1; | 2267 if (*time_frame > delay * 0.6) { |
2232 *time_frame = delay*0.5; | 2268 // sleep time too big - may cause audio drops (buffer underrun) |
2233 } | 2269 frame_time_remaining = 1; |
2270 *time_frame = delay * 0.5; | |
2271 } | |
2234 } else { | 2272 } else { |
2235 // If we're lagging more than 200 ms behind the right playback rate, | 2273 // If we're lagging more than 200 ms behind the right playback rate, |
2236 // don't try to "catch up". | 2274 // don't try to "catch up". |
2237 // If benchmark is set always output frames as fast as possible | 2275 // If benchmark is set always output frames as fast as possible |
2238 // without sleeping. | 2276 // without sleeping. |
2239 if (*time_frame < -0.2 || benchmark) | 2277 if (*time_frame < -0.2 || benchmark) |
2240 *time_frame = 0; | 2278 *time_frame = 0; |
2241 } | 2279 } |
2242 | 2280 |
2243 *aq_sleep_time += *time_frame; | 2281 *aq_sleep_time += *time_frame; |
2244 | 2282 |
2245 | |
2246 //============================== SLEEP: =================================== | 2283 //============================== SLEEP: =================================== |
2247 | 2284 |
2248 // flag 256 means: libvo driver does its timing (dvb card) | 2285 // flag 256 means: libvo driver does its timing (dvb card) |
2249 if (*time_frame > 0.001 && !(vo_flags&256)) | 2286 if (*time_frame > 0.001 && !(vo_flags & 256)) |
2250 *time_frame = timing_sleep(*time_frame); | 2287 *time_frame = timing_sleep(*time_frame); |
2251 | 2288 |
2252 handle_udp_master(mpctx->sh_video->pts); | 2289 handle_udp_master(mpctx->sh_video->pts); |
2253 | 2290 |
2254 return frame_time_remaining; | 2291 return frame_time_remaining; |
2255 } | 2292 } |
2256 | 2293 |
2257 int reinit_video_chain(void) { | 2294 int reinit_video_chain(void) |
2258 sh_video_t * const sh_video = mpctx->sh_video; | 2295 { |
2259 double ar=-1.0; | 2296 sh_video_t *const sh_video = mpctx->sh_video; |
2297 double ar = -1.0; | |
2260 //================== Init VIDEO (codec & libvo) ========================== | 2298 //================== Init VIDEO (codec & libvo) ========================== |
2261 if(!fixed_vo || !(initialized_flags&INITIALIZED_VO)){ | 2299 if (!fixed_vo || !(initialized_flags & INITIALIZED_VO)) { |
2262 current_module="preinit_libvo"; | 2300 current_module = "preinit_libvo"; |
2263 | 2301 |
2264 //shouldn't we set dvideo->id=-2 when we fail? | 2302 //shouldn't we set dvideo->id=-2 when we fail? |
2265 vo_config_count=0; | 2303 vo_config_count = 0; |
2266 //if((mpctx->video_out->preinit(vo_subdevice))!=0){ | 2304 //if((mpctx->video_out->preinit(vo_subdevice))!=0){ |
2267 if(!(mpctx->video_out=init_best_video_out(video_driver_list))){ | 2305 if (!(mpctx->video_out = init_best_video_out(video_driver_list))) { |
2268 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice); | 2306 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_ErrorInitializingVODevice); |
2269 goto err_out; | 2307 goto err_out; |
2270 } | 2308 } |
2271 initialized_flags|=INITIALIZED_VO; | 2309 initialized_flags |= INITIALIZED_VO; |
2272 } | 2310 } |
2273 | 2311 |
2274 if(stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_ASPECT_RATIO, &ar) != STREAM_UNSUPPORTED) | 2312 if (stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_ASPECT_RATIO, &ar) != STREAM_UNSUPPORTED) |
2275 mpctx->sh_video->stream_aspect = ar; | 2313 mpctx->sh_video->stream_aspect = ar; |
2276 current_module="init_video_filters"; | 2314 current_module = "init_video_filters"; |
2277 { | 2315 { |
2278 char* vf_arg[] = { "_oldargs_", (char*)mpctx->video_out , NULL }; | 2316 char *vf_arg[] = { "_oldargs_", (char *)mpctx->video_out, NULL }; |
2279 sh_video->vfilter=vf_open_filter(NULL,"vo",vf_arg); | 2317 sh_video->vfilter = vf_open_filter(NULL, "vo", vf_arg); |
2280 } | 2318 } |
2281 #ifdef CONFIG_MENU | 2319 #ifdef CONFIG_MENU |
2282 if(use_menu) { | 2320 if (use_menu) { |
2283 char* vf_arg[] = { "_oldargs_", menu_root, NULL }; | 2321 char *vf_arg[] = { "_oldargs_", menu_root, NULL }; |
2284 vf_menu = vf_open_plugin(libmenu_vfs,sh_video->vfilter,"menu",vf_arg); | 2322 vf_menu = vf_open_plugin(libmenu_vfs, sh_video->vfilter, "menu", vf_arg); |
2285 if(!vf_menu) { | 2323 if (!vf_menu) { |
2286 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantOpenLibmenuFilterWithThisRootMenu,menu_root); | 2324 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantOpenLibmenuFilterWithThisRootMenu, menu_root); |
2287 use_menu = 0; | 2325 use_menu = 0; |
2288 } | 2326 } |
2289 } | 2327 } |
2290 if(vf_menu) | 2328 if (vf_menu) |
2291 sh_video->vfilter=vf_menu; | 2329 sh_video->vfilter = vf_menu; |
2292 #endif | 2330 #endif |
2293 | 2331 |
2294 #ifdef CONFIG_ASS | 2332 #ifdef CONFIG_ASS |
2295 if(ass_enabled) { | 2333 if (ass_enabled) { |
2296 int i; | 2334 int i; |
2297 int insert = 1; | 2335 int insert = 1; |
2298 if (vf_settings) | 2336 if (vf_settings) |
2299 for (i = 0; vf_settings[i].name; ++i) | 2337 for (i = 0; vf_settings[i].name; ++i) |
2300 if (strcmp(vf_settings[i].name, "ass") == 0) { | 2338 if (strcmp(vf_settings[i].name, "ass") == 0) { |
2301 insert = 0; | 2339 insert = 0; |
2302 break; | 2340 break; |
2303 } | 2341 } |
2304 if (insert) { | 2342 if (insert) { |
2305 char* vf_arg[] = {"auto", "1", NULL}; | 2343 char *vf_arg[] = { "auto", "1", NULL }; |
2306 vf_instance_t* vf_ass = vf_open_filter(sh_video->vfilter,"ass",vf_arg); | 2344 vf_instance_t *vf_ass = vf_open_filter(sh_video->vfilter, "ass", vf_arg); |
2307 if (vf_ass) | 2345 if (vf_ass) |
2308 sh_video->vfilter=vf_ass; | 2346 sh_video->vfilter = vf_ass; |
2309 else | 2347 else |
2310 mp_msg(MSGT_CPLAYER,MSGL_ERR, "ASS: cannot add video filter\n"); | 2348 mp_msg(MSGT_CPLAYER, MSGL_ERR, "ASS: cannot add video filter\n"); |
2311 } | 2349 } |
2312 } | 2350 } |
2313 #endif | 2351 #endif |
2314 | 2352 |
2315 sh_video->vfilter=append_filters(sh_video->vfilter); | 2353 sh_video->vfilter = append_filters(sh_video->vfilter); |
2316 eosd_init(sh_video->vfilter); | 2354 eosd_init(sh_video->vfilter); |
2317 | 2355 |
2318 #ifdef CONFIG_ASS | 2356 #ifdef CONFIG_ASS |
2319 if (ass_enabled) | 2357 if (ass_enabled) |
2320 eosd_ass_init(ass_library); | 2358 eosd_ass_init(ass_library); |
2321 #endif | 2359 #endif |
2322 | 2360 |
2323 current_module="init_video_codec"; | 2361 current_module = "init_video_codec"; |
2324 | 2362 |
2325 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n"); | 2363 mp_msg(MSGT_CPLAYER, MSGL_INFO, "==========================================================================\n"); |
2326 init_best_video_codec(sh_video,video_codec_list,video_fm_list); | 2364 init_best_video_codec(sh_video, video_codec_list, video_fm_list); |
2327 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n"); | 2365 mp_msg(MSGT_CPLAYER, MSGL_INFO, "==========================================================================\n"); |
2328 | 2366 |
2329 if(!sh_video->initialized){ | 2367 if (!sh_video->initialized) { |
2330 if(!fixed_vo) uninit_player(INITIALIZED_VO); | 2368 if (!fixed_vo) |
2331 goto err_out; | 2369 uninit_player(INITIALIZED_VO); |
2332 } | 2370 goto err_out; |
2333 | 2371 } |
2334 initialized_flags|=INITIALIZED_VCODEC; | 2372 |
2335 | 2373 initialized_flags |= INITIALIZED_VCODEC; |
2336 if (sh_video->codec) | 2374 |
2337 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_CODEC=%s\n", sh_video->codec->name); | 2375 if (sh_video->codec) |
2338 | 2376 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_CODEC=%s\n", sh_video->codec->name); |
2339 sh_video->last_pts = MP_NOPTS_VALUE; | 2377 |
2340 sh_video->num_buffered_pts = 0; | 2378 sh_video->last_pts = MP_NOPTS_VALUE; |
2341 sh_video->next_frame_time = 0; | 2379 sh_video->num_buffered_pts = 0; |
2342 | 2380 sh_video->next_frame_time = 0; |
2343 if(auto_quality>0){ | 2381 |
2344 // Auto quality option enabled | 2382 if (auto_quality > 0) { |
2345 output_quality=get_video_quality_max(sh_video); | 2383 // Auto quality option enabled |
2346 if(auto_quality>output_quality) auto_quality=output_quality; | 2384 output_quality = get_video_quality_max(sh_video); |
2347 else output_quality=auto_quality; | 2385 if (auto_quality > output_quality) |
2348 mp_msg(MSGT_CPLAYER,MSGL_V,"AutoQ: setting quality to %d.\n",output_quality); | 2386 auto_quality = output_quality; |
2349 set_video_quality(sh_video,output_quality); | 2387 else |
2350 } | 2388 output_quality = auto_quality; |
2351 | 2389 mp_msg(MSGT_CPLAYER, MSGL_V, "AutoQ: setting quality to %d.\n", output_quality); |
2352 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============ | 2390 set_video_quality(sh_video, output_quality); |
2353 | 2391 } |
2354 current_module="init_vo"; | 2392 |
2355 | 2393 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============ |
2356 return 1; | 2394 |
2395 current_module = "init_vo"; | |
2396 | |
2397 return 1; | |
2357 | 2398 |
2358 err_out: | 2399 err_out: |
2359 mpctx->sh_video = mpctx->d_video->sh = NULL; | 2400 mpctx->sh_video = mpctx->d_video->sh = NULL; |
2360 return 0; | 2401 return 0; |
2361 } | 2402 } |
2362 | 2403 |
2363 static double update_video(int *blit_frame) | 2404 static double update_video(int *blit_frame) |
2364 { | 2405 { |
2365 sh_video_t * const sh_video = mpctx->sh_video; | 2406 sh_video_t *const sh_video = mpctx->sh_video; |
2366 //-------------------- Decode a frame: ----------------------- | 2407 //-------------------- Decode a frame: ----------------------- |
2367 double frame_time; | 2408 double frame_time; |
2368 *blit_frame = 0; // Don't blit if we hit EOF | 2409 *blit_frame = 0; // Don't blit if we hit EOF |
2369 if (!correct_pts) { | 2410 if (!correct_pts) { |
2370 unsigned char* start=NULL; | 2411 unsigned char *start = NULL; |
2371 void *decoded_frame = NULL; | 2412 void *decoded_frame = NULL; |
2372 int drop_frame=0; | 2413 int drop_frame = 0; |
2373 int in_size; | 2414 int in_size; |
2374 int full_frame; | 2415 int full_frame; |
2375 | 2416 |
2376 do { | 2417 do { |
2377 current_module = "video_read_frame"; | 2418 current_module = "video_read_frame"; |
2378 frame_time = sh_video->next_frame_time; | 2419 frame_time = sh_video->next_frame_time; |
2379 in_size = video_read_frame(sh_video, &sh_video->next_frame_time, | 2420 in_size = video_read_frame(sh_video, &sh_video->next_frame_time, |
2380 &start, force_fps); | 2421 &start, force_fps); |
2381 #ifdef CONFIG_DVDNAV | 2422 #ifdef CONFIG_DVDNAV |
2382 // wait, still frame or EOF | 2423 // wait, still frame or EOF |
2383 if (mpctx->stream->type == STREAMTYPE_DVDNAV && in_size < 0) { | 2424 if (mpctx->stream->type == STREAMTYPE_DVDNAV && in_size < 0) { |
2384 if (mp_dvdnav_is_eof(mpctx->stream)) | 2425 if (mp_dvdnav_is_eof(mpctx->stream)) |
2426 return -1; | |
2427 if (mpctx->d_video) | |
2428 mpctx->d_video->eof = 0; | |
2429 if (mpctx->d_audio) | |
2430 mpctx->d_audio->eof = 0; | |
2431 mpctx->stream->eof = 0; | |
2432 } else | |
2433 #endif | |
2434 if (in_size < 0) | |
2385 return -1; | 2435 return -1; |
2386 if (mpctx->d_video) | 2436 if (in_size > max_framesize) |
2387 mpctx->d_video->eof = 0; | 2437 max_framesize = in_size; // stats |
2388 if (mpctx->d_audio) | 2438 drop_frame = check_framedrop(frame_time); |
2389 mpctx->d_audio->eof = 0; | 2439 current_module = "decode_video"; |
2390 mpctx->stream->eof = 0; | |
2391 } else | |
2392 #endif | |
2393 if (in_size < 0) | |
2394 return -1; | |
2395 if (in_size > max_framesize) | |
2396 max_framesize = in_size; // stats | |
2397 drop_frame = check_framedrop(frame_time); | |
2398 current_module = "decode_video"; | |
2399 #ifdef CONFIG_DVDNAV | 2440 #ifdef CONFIG_DVDNAV |
2400 full_frame = 1; | 2441 full_frame = 1; |
2401 decoded_frame = mp_dvdnav_restore_smpi(&in_size,&start,decoded_frame); | 2442 decoded_frame = mp_dvdnav_restore_smpi(&in_size, &start, decoded_frame); |
2402 // still frame has been reached, no need to decode | 2443 // still frame has been reached, no need to decode |
2403 if (in_size > 0 && !decoded_frame) | 2444 if (in_size > 0 && !decoded_frame) |
2404 #endif | 2445 #endif |
2405 decoded_frame = decode_video(sh_video, start, in_size, drop_frame, | 2446 decoded_frame = decode_video(sh_video, start, in_size, drop_frame, |
2406 sh_video->pts, &full_frame); | 2447 sh_video->pts, &full_frame); |
2407 | 2448 |
2408 if (full_frame) { | 2449 if (full_frame) { |
2409 sh_video->timer += frame_time; | 2450 sh_video->timer += frame_time; |
2410 | 2451 |
2411 // Time-based PTS recalculation. | 2452 // Time-based PTS recalculation. |
2412 // The key to maintaining A-V sync is to not touch PTS until the proper frame is reached | 2453 // The key to maintaining A-V sync is to not touch PTS until the proper frame is reached |
2413 if (sh_video->pts != MP_NOPTS_VALUE) { | 2454 if (sh_video->pts != MP_NOPTS_VALUE) { |
2414 if (sh_video->last_pts != MP_NOPTS_VALUE) { | 2455 if (sh_video->last_pts != MP_NOPTS_VALUE) { |
2415 double pts = sh_video->last_pts + frame_time; | 2456 double pts = sh_video->last_pts + frame_time; |
2416 double ptsdiff = fabs(pts - sh_video->pts); | 2457 double ptsdiff = fabs(pts - sh_video->pts); |
2417 | 2458 |
2418 // Allow starting PTS recalculation at the appropriate frame only | 2459 // Allow starting PTS recalculation at the appropriate frame only |
2419 mpctx->framestep_found |= (ptsdiff <= frame_time * 1.5); | 2460 mpctx->framestep_found |= (ptsdiff <= frame_time * 1.5); |
2420 | 2461 |
2421 // replace PTS only if we're not too close and not too far | 2462 // replace PTS only if we're not too close and not too far |
2422 // and a correctly timed frame has been found, otherwise | 2463 // and a correctly timed frame has been found, otherwise |
2423 // keep pts to eliminate rounding errors or catch up with stream | 2464 // keep pts to eliminate rounding errors or catch up with stream |
2424 if (ptsdiff > frame_time * 20) | 2465 if (ptsdiff > frame_time * 20) |
2425 mpctx->framestep_found = 0; | 2466 mpctx->framestep_found = 0; |
2426 if (ptsdiff * 10 > frame_time && mpctx->framestep_found) | 2467 if (ptsdiff * 10 > frame_time && mpctx->framestep_found) |
2427 sh_video->pts = pts; | 2468 sh_video->pts = pts; |
2428 else | 2469 else |
2429 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"Keeping PTS at %6.2f\n", sh_video->pts); | 2470 mp_dbg(MSGT_AVSYNC, MSGL_DBG2, "Keeping PTS at %6.2f\n", sh_video->pts); |
2430 } | 2471 } |
2431 sh_video->last_pts = sh_video->pts; | 2472 sh_video->last_pts = sh_video->pts; |
2432 } | 2473 } |
2433 if (mpctx->sh_audio) | 2474 if (mpctx->sh_audio) |
2434 mpctx->delay -= frame_time; | 2475 mpctx->delay -= frame_time; |
2435 // video_read_frame can change fps (e.g. for ASF video) | 2476 // video_read_frame can change fps (e.g. for ASF video) |
2436 vo_fps = sh_video->fps; | 2477 vo_fps = sh_video->fps; |
2437 update_subtitles(sh_video, sh_video->pts, mpctx->d_sub, 0); | 2478 update_subtitles(sh_video, sh_video->pts, mpctx->d_sub, 0); |
2438 update_teletext(sh_video, mpctx->demuxer, 0); | 2479 update_teletext(sh_video, mpctx->demuxer, 0); |
2439 update_osd_msg(); | 2480 update_osd_msg(); |
2440 } | 2481 } |
2441 #ifdef CONFIG_DVDNAV | 2482 #ifdef CONFIG_DVDNAV |
2442 // save back last still frame for future display | 2483 // save back last still frame for future display |
2443 mp_dvdnav_save_smpi(in_size,start,decoded_frame); | 2484 mp_dvdnav_save_smpi(in_size, start, decoded_frame); |
2444 #endif | 2485 #endif |
2445 } while (!full_frame); | 2486 } while (!full_frame); |
2446 | 2487 |
2447 current_module = "filter_video"; | 2488 current_module = "filter_video"; |
2448 *blit_frame = (decoded_frame && filter_video(sh_video, decoded_frame, | 2489 *blit_frame = (decoded_frame && filter_video(sh_video, decoded_frame, |
2449 sh_video->pts)); | 2490 sh_video->pts)); |
2450 } | 2491 } else { |
2451 else { | 2492 int res = generate_video_frame(sh_video, mpctx->d_video); |
2452 int res = generate_video_frame(sh_video, mpctx->d_video); | 2493 if (!res) |
2453 if (!res) | 2494 return -1; |
2454 return -1; | 2495 ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, |
2455 ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, | 2496 VFCTRL_GET_PTS, &sh_video->pts); |
2456 VFCTRL_GET_PTS, &sh_video->pts); | 2497 if (sh_video->pts == MP_NOPTS_VALUE) { |
2457 if (sh_video->pts == MP_NOPTS_VALUE) { | 2498 mp_msg(MSGT_CPLAYER, MSGL_ERR, "pts after filters MISSING\n"); |
2458 mp_msg(MSGT_CPLAYER, MSGL_ERR, "pts after filters MISSING\n"); | 2499 sh_video->pts = sh_video->last_pts; |
2459 sh_video->pts = sh_video->last_pts; | 2500 } |
2460 } | 2501 if (sh_video->last_pts == MP_NOPTS_VALUE) |
2461 if (sh_video->last_pts == MP_NOPTS_VALUE) | 2502 sh_video->last_pts = sh_video->pts; |
2462 sh_video->last_pts= sh_video->pts; | 2503 else if (sh_video->last_pts > sh_video->pts) { |
2463 else if (sh_video->last_pts > sh_video->pts) { | 2504 // make a guess whether this is some kind of discontinuity |
2464 // make a guess whether this is some kind of discontinuity | 2505 // we should jump along with or some wron timestamps we |
2465 // we should jump along with or some wron timestamps we | 2506 // should replace instead |
2466 // should replace instead | |
2467 if (sh_video->pts < sh_video->last_pts - 20 * sh_video->frametime) | 2507 if (sh_video->pts < sh_video->last_pts - 20 * sh_video->frametime) |
2468 sh_video->last_pts = sh_video->pts; | 2508 sh_video->last_pts = sh_video->pts; |
2469 else | 2509 else |
2470 sh_video->pts = sh_video->last_pts + sh_video->frametime; | 2510 sh_video->pts = sh_video->last_pts + sh_video->frametime; |
2471 mp_msg(MSGT_CPLAYER, MSGL_V, "pts value < previous\n"); | 2511 mp_msg(MSGT_CPLAYER, MSGL_V, "pts value < previous\n"); |
2472 } | 2512 } |
2473 frame_time = sh_video->pts - sh_video->last_pts; | 2513 frame_time = sh_video->pts - sh_video->last_pts; |
2474 if (!frame_time) | 2514 if (!frame_time) |
2475 frame_time = sh_video->frametime; | 2515 frame_time = sh_video->frametime; |
2476 sh_video->last_pts = sh_video->pts; | 2516 sh_video->last_pts = sh_video->pts; |
2477 sh_video->timer += frame_time; | 2517 sh_video->timer += frame_time; |
2478 if(mpctx->sh_audio) | 2518 if (mpctx->sh_audio) |
2479 mpctx->delay -= frame_time; | 2519 mpctx->delay -= frame_time; |
2480 *blit_frame = res > 0; | 2520 *blit_frame = res > 0; |
2481 } | 2521 } |
2482 return frame_time; | 2522 return frame_time; |
2483 } | 2523 } |
2484 | 2524 |
2485 static void pause_loop(void) | 2525 static void pause_loop(void) |
2486 { | 2526 { |
2487 mp_cmd_t* cmd; | 2527 mp_cmd_t *cmd; |
2488 #ifdef CONFIG_STREAM_CACHE | 2528 #ifdef CONFIG_STREAM_CACHE |
2489 int old_cache_fill = stream_cache_size > 0 ? cache_fill_status(mpctx->stream) : 0; | 2529 int old_cache_fill = stream_cache_size > 0 ? cache_fill_status(mpctx->stream) : 0; |
2490 #endif | 2530 #endif |
2491 if (!quiet) { | 2531 if (!quiet) { |
2492 if (term_osd && !mpctx->sh_video) { | 2532 if (term_osd && !mpctx->sh_video) { |
2493 set_osd_msg(OSD_MSG_PAUSE, 1, 0, MSGTR_Paused); | 2533 set_osd_msg(OSD_MSG_PAUSE, 1, 0, MSGTR_Paused); |
2494 update_osd_msg(); | 2534 update_osd_msg(); |
2495 } else | 2535 } else |
2496 mp_msg(MSGT_CPLAYER,MSGL_STATUS,"\n"MSGTR_Paused"\r"); | 2536 mp_msg(MSGT_CPLAYER, MSGL_STATUS, "\n"MSGTR_Paused "\r"); |
2497 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_PAUSED\n"); | 2537 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_PAUSED\n"); |
2498 } | 2538 } |
2499 #ifdef CONFIG_GUI | 2539 #ifdef CONFIG_GUI |
2500 if (use_gui) | 2540 if (use_gui) |
2501 guiGetEvent(guiCEvent, (char *)guiSetPause); | 2541 guiGetEvent(guiCEvent, (char *)guiSetPause); |
2502 #endif | 2542 #endif |
2503 if (mpctx->video_out && mpctx->sh_video && vo_config_count) | 2543 if (mpctx->video_out && mpctx->sh_video && vo_config_count) |
2504 mpctx->video_out->control(VOCTRL_PAUSE, NULL); | 2544 mpctx->video_out->control(VOCTRL_PAUSE, NULL); |
2505 | 2545 |
2506 if (mpctx->audio_out && mpctx->sh_audio) | 2546 if (mpctx->audio_out && mpctx->sh_audio) |
2507 mpctx->audio_out->pause(); // pause audio, keep data if possible | 2547 mpctx->audio_out->pause(); // pause audio, keep data if possible |
2508 | 2548 |
2509 while ( (cmd = mp_input_get_cmd(20, 1, 1)) == NULL || cmd->pausing == 4) { | 2549 while ((cmd = mp_input_get_cmd(20, 1, 1)) == NULL || cmd->pausing == 4) { |
2510 if (cmd) { | 2550 if (cmd) { |
2511 cmd = mp_input_get_cmd(0,1,0); | 2551 cmd = mp_input_get_cmd(0, 1, 0); |
2512 run_command(mpctx, cmd); | 2552 run_command(mpctx, cmd); |
2513 mp_cmd_free(cmd); | 2553 mp_cmd_free(cmd); |
2514 continue; | 2554 continue; |
2515 } | 2555 } |
2516 if (mpctx->sh_video && mpctx->video_out && vo_config_count) | 2556 if (mpctx->sh_video && mpctx->video_out && vo_config_count) |
2517 mpctx->video_out->check_events(); | 2557 mpctx->video_out->check_events(); |
2518 #ifdef CONFIG_GUI | 2558 #ifdef CONFIG_GUI |
2519 if (use_gui) { | 2559 if (use_gui) { |
2520 guiEventHandling(); | 2560 guiEventHandling(); |
2521 guiGetEvent(guiReDraw, NULL); | 2561 guiGetEvent(guiReDraw, NULL); |
2522 if (guiIntfStruct.Playing!=2 || (rel_seek_secs || abs_seek_pos)) | 2562 if (guiIntfStruct.Playing != 2 || (rel_seek_secs || abs_seek_pos)) |
2523 break; | 2563 break; |
2524 } | 2564 } |
2525 #endif | 2565 #endif |
2526 #ifdef CONFIG_MENU | 2566 #ifdef CONFIG_MENU |
2527 if (vf_menu) | 2567 if (vf_menu) |
2530 #ifdef CONFIG_STREAM_CACHE | 2570 #ifdef CONFIG_STREAM_CACHE |
2531 if (!quiet && stream_cache_size > 0) { | 2571 if (!quiet && stream_cache_size > 0) { |
2532 int new_cache_fill = cache_fill_status(mpctx->stream); | 2572 int new_cache_fill = cache_fill_status(mpctx->stream); |
2533 if (new_cache_fill != old_cache_fill) { | 2573 if (new_cache_fill != old_cache_fill) { |
2534 if (term_osd && !mpctx->sh_video) { | 2574 if (term_osd && !mpctx->sh_video) { |
2535 set_osd_msg(OSD_MSG_PAUSE, 1, 0, MSGTR_Paused" %d%%", | 2575 set_osd_msg(OSD_MSG_PAUSE, 1, 0, MSGTR_Paused " %d%%", |
2536 new_cache_fill); | 2576 new_cache_fill); |
2537 update_osd_msg(); | 2577 update_osd_msg(); |
2538 } else | 2578 } else |
2539 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_Paused" %d%%\r", | 2579 mp_msg(MSGT_CPLAYER, MSGL_STATUS, MSGTR_Paused " %d%%\r", |
2540 new_cache_fill); | 2580 new_cache_fill); |
2541 old_cache_fill = new_cache_fill; | 2581 old_cache_fill = new_cache_fill; |
2542 } | 2582 } |
2543 } | 2583 } |
2544 #endif | 2584 #endif |
2545 if (mpctx->sh_video) | 2585 if (mpctx->sh_video) |
2546 handle_udp_master(mpctx->sh_video->pts); | 2586 handle_udp_master(mpctx->sh_video->pts); |
2547 usec_sleep(20000); | 2587 usec_sleep(20000); |
2548 } | 2588 } |
2549 if (cmd && cmd->id == MP_CMD_PAUSE) { | 2589 if (cmd && cmd->id == MP_CMD_PAUSE) { |
2550 cmd = mp_input_get_cmd(0,1,0); | 2590 cmd = mp_input_get_cmd(0, 1, 0); |
2551 mp_cmd_free(cmd); | 2591 mp_cmd_free(cmd); |
2552 } | 2592 } |
2553 mpctx->osd_function=OSD_PLAY; | 2593 mpctx->osd_function = OSD_PLAY; |
2554 if (mpctx->audio_out && mpctx->sh_audio) { | 2594 if (mpctx->audio_out && mpctx->sh_audio) { |
2555 if (mpctx->eof) // do not play remaining audio if we e.g. switch to the next file | 2595 if (mpctx->eof) // do not play remaining audio if we e.g. switch to the next file |
2556 mpctx->audio_out->reset(); | 2596 mpctx->audio_out->reset(); |
2557 else | 2597 else |
2558 mpctx->audio_out->resume(); // resume audio | 2598 mpctx->audio_out->resume(); // resume audio |
2559 } | 2599 } |
2560 if (mpctx->video_out && mpctx->sh_video && vo_config_count) | 2600 if (mpctx->video_out && mpctx->sh_video && vo_config_count) |
2561 mpctx->video_out->control(VOCTRL_RESUME, NULL); // resume video | 2601 mpctx->video_out->control(VOCTRL_RESUME, NULL); // resume video |
2562 (void)GetRelativeTime(); // ignore time that passed during pause | 2602 (void)GetRelativeTime(); // ignore time that passed during pause |
2563 #ifdef CONFIG_GUI | 2603 #ifdef CONFIG_GUI |
2564 if (use_gui) { | 2604 if (use_gui) { |
2565 if (guiIntfStruct.Playing == guiSetStop) | 2605 if (guiIntfStruct.Playing == guiSetStop) |
2566 mpctx->eof = 1; | 2606 mpctx->eof = 1; |
2587 if (!edl_records) { | 2627 if (!edl_records) { |
2588 return; | 2628 return; |
2589 } | 2629 } |
2590 | 2630 |
2591 if (!mpctx->sh_video) { | 2631 if (!mpctx->sh_video) { |
2592 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlNOsh_video); | 2632 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlNOsh_video); |
2593 free_edl(edl_records); | 2633 free_edl(edl_records); |
2594 next_edl_record = NULL; | 2634 next_edl_record = NULL; |
2595 edl_records = NULL; | 2635 edl_records = NULL; |
2596 return; | 2636 return; |
2597 } | 2637 } |
2598 | 2638 |
2599 // This indicates that we need to reset next EDL record according | 2639 // This indicates that we need to reset next EDL record according |
2600 // to new PTS due to seek or other condition | 2640 // to new PTS due to seek or other condition |
2601 if (edl_needs_reset) { | 2641 if (edl_needs_reset) { |
2602 edl_needs_reset = 0; | 2642 edl_needs_reset = 0; |
2603 mpctx->edl_muted = 0; | 2643 mpctx->edl_muted = 0; |
2604 next_edl_record = edl_records; | 2644 next_edl_record = edl_records; |
2605 | 2645 |
2606 // Find next record, also skip immediately if we are already | 2646 // Find next record, also skip immediately if we are already |
2607 // inside any record | 2647 // inside any record |
2608 while (next_edl_record) { | 2648 while (next_edl_record) { |
2609 if (next_edl_record->start_sec > mpctx->sh_video->pts) | 2649 if (next_edl_record->start_sec > mpctx->sh_video->pts) |
2610 break; | 2650 break; |
2611 if (next_edl_record->stop_sec >= mpctx->sh_video->pts) { | 2651 if (next_edl_record->stop_sec >= mpctx->sh_video->pts) { |
2612 if (edl_backward) { | 2652 if (edl_backward) { |
2613 mpctx->osd_function = OSD_REW; | 2653 mpctx->osd_function = OSD_REW; |
2614 edl_decision = 1; | 2654 edl_decision = 1; |
2615 abs_seek_pos = 0; | 2655 abs_seek_pos = 0; |
2616 rel_seek_secs = -(mpctx->sh_video->pts - | 2656 rel_seek_secs = -(mpctx->sh_video->pts - |
2617 next_edl_record->start_sec + | 2657 next_edl_record->start_sec + |
2618 edl_backward_delay); | 2658 edl_backward_delay); |
2619 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_SKIP: pts [%f], " | 2659 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_SKIP: pts [%f], " |
2620 "offset [%f], start [%f], stop [%f], length [%f]\n", | 2660 "offset [%f], start [%f], stop [%f], length [%f]\n", |
2621 mpctx->sh_video->pts, rel_seek_secs, | 2661 mpctx->sh_video->pts, rel_seek_secs, |
2622 next_edl_record->start_sec, next_edl_record->stop_sec, | 2662 next_edl_record->start_sec, next_edl_record->stop_sec, |
2623 next_edl_record->length_sec); | 2663 next_edl_record->length_sec); |
2624 return; | 2664 return; |
2625 } | 2665 } |
2628 | 2668 |
2629 if (next_edl_record->action == EDL_MUTE) | 2669 if (next_edl_record->action == EDL_MUTE) |
2630 mpctx->edl_muted = !mpctx->edl_muted; | 2670 mpctx->edl_muted = !mpctx->edl_muted; |
2631 | 2671 |
2632 next_edl_record = next_edl_record->next; | 2672 next_edl_record = next_edl_record->next; |
2633 } | 2673 } |
2634 if ((mpctx->user_muted | mpctx->edl_muted) != mpctx->mixer.muted) | 2674 if ((mpctx->user_muted | mpctx->edl_muted) != mpctx->mixer.muted) |
2635 mixer_mute(&mpctx->mixer); | 2675 mixer_mute(&mpctx->mixer); |
2636 } | 2676 } |
2637 | 2677 |
2638 if (next_edl_record && | 2678 if (next_edl_record && |
2639 mpctx->sh_video->pts >= next_edl_record->start_sec) { | 2679 mpctx->sh_video->pts >= next_edl_record->start_sec) { |
2640 if (next_edl_record->action == EDL_SKIP) { | 2680 if (next_edl_record->action == EDL_SKIP) { |
2641 mpctx->osd_function = OSD_FFW; | 2681 mpctx->osd_function = OSD_FFW; |
2642 edl_decision = 1; | 2682 edl_decision = 1; |
2643 abs_seek_pos = 0; | 2683 abs_seek_pos = 0; |
2644 rel_seek_secs = next_edl_record->stop_sec - mpctx->sh_video->pts; | 2684 rel_seek_secs = next_edl_record->stop_sec - mpctx->sh_video->pts; |
2645 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_SKIP: pts [%f], offset [%f], " | 2685 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_SKIP: pts [%f], offset [%f], " |
2646 "start [%f], stop [%f], length [%f]\n", | 2686 "start [%f], stop [%f], length [%f]\n", |
2647 mpctx->sh_video->pts, rel_seek_secs, | 2687 mpctx->sh_video->pts, rel_seek_secs, |
2648 next_edl_record->start_sec, next_edl_record->stop_sec, | 2688 next_edl_record->start_sec, next_edl_record->stop_sec, |
2649 next_edl_record->length_sec); | 2689 next_edl_record->length_sec); |
2650 } | 2690 } else if (next_edl_record->action == EDL_MUTE) { |
2651 else if (next_edl_record->action == EDL_MUTE) { | |
2652 mpctx->edl_muted = !mpctx->edl_muted; | 2691 mpctx->edl_muted = !mpctx->edl_muted; |
2653 if ((mpctx->user_muted | mpctx->edl_muted) != mpctx->mixer.muted) | 2692 if ((mpctx->user_muted | mpctx->edl_muted) != mpctx->mixer.muted) |
2654 mixer_mute(&mpctx->mixer); | 2693 mixer_mute(&mpctx->mixer); |
2655 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_MUTE: [%f]\n", | 2694 mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_MUTE: [%f]\n", |
2656 next_edl_record->start_sec ); | 2695 next_edl_record->start_sec); |
2657 } | 2696 } |
2658 next_edl_record = next_edl_record->next; | 2697 next_edl_record = next_edl_record->next; |
2659 } | 2698 } |
2660 } | 2699 } |
2661 | |
2662 | 2700 |
2663 // style & SEEK_ABSOLUTE == 0 means seek relative to current position, == 1 means absolute | 2701 // style & SEEK_ABSOLUTE == 0 means seek relative to current position, == 1 means absolute |
2664 // style & SEEK_FACTOR == 0 means amount in seconds, == 2 means fraction of file length | 2702 // style & SEEK_FACTOR == 0 means amount in seconds, == 2 means fraction of file length |
2665 // return -1 if seek failed (non-seekable stream?), 0 otherwise | 2703 // return -1 if seek failed (non-seekable stream?), 0 otherwise |
2666 static int seek(MPContext *mpctx, double amount, int style) | 2704 static int seek(MPContext *mpctx, double amount, int style) |
2667 { | 2705 { |
2668 current_module = "seek"; | 2706 current_module = "seek"; |
2669 if (demux_seek(mpctx->demuxer, amount, audio_delay, style) == 0) | 2707 if (demux_seek(mpctx->demuxer, amount, audio_delay, style) == 0) |
2670 return -1; | 2708 return -1; |
2671 | 2709 |
2672 mpctx->startup_decode_retry = DEFAULT_STARTUP_DECODE_RETRY; | 2710 mpctx->startup_decode_retry = DEFAULT_STARTUP_DECODE_RETRY; |
2673 if (mpctx->sh_video) { | 2711 if (mpctx->sh_video) { |
2674 current_module = "seek_video_reset"; | 2712 current_module = "seek_video_reset"; |
2675 if (vo_config_count) | 2713 if (vo_config_count) |
2676 mpctx->video_out->control(VOCTRL_RESET, NULL); | 2714 mpctx->video_out->control(VOCTRL_RESET, NULL); |
2677 mpctx->num_buffered_frames = 0; | 2715 mpctx->num_buffered_frames = 0; |
2678 mpctx->delay = 0; | 2716 mpctx->delay = 0; |
2679 mpctx->time_frame = 0; | 2717 mpctx->time_frame = 0; |
2680 mpctx->framestep_found = 0; | 2718 mpctx->framestep_found = 0; |
2681 // Not all demuxers set d_video->pts during seek, so this value | 2719 // Not all demuxers set d_video->pts during seek, so this value |
2682 // (which is used by at least vobsub and edl code below) may | 2720 // (which is used by at least vobsub and edl code below) may |
2683 // be completely wrong (probably 0). | 2721 // be completely wrong (probably 0). |
2684 mpctx->sh_video->pts = mpctx->d_video->pts; | 2722 mpctx->sh_video->pts = mpctx->d_video->pts; |
2685 update_subtitles(mpctx->sh_video, mpctx->sh_video->pts, mpctx->d_sub, 1); | 2723 update_subtitles(mpctx->sh_video, mpctx->sh_video->pts, mpctx->d_sub, 1); |
2686 update_teletext(mpctx->sh_video, mpctx->demuxer, 1); | 2724 update_teletext(mpctx->sh_video, mpctx->demuxer, 1); |
2687 } | 2725 } |
2688 | 2726 |
2689 if (mpctx->sh_audio) { | 2727 if (mpctx->sh_audio) { |
2690 current_module = "seek_audio_reset"; | 2728 current_module = "seek_audio_reset"; |
2691 mpctx->audio_out->reset(); // stop audio, throwing away buffered data | 2729 mpctx->audio_out->reset(); // stop audio, throwing away buffered data |
2692 if (!mpctx->sh_video) | 2730 if (!mpctx->sh_video) |
2693 update_subtitles(NULL, mpctx->sh_audio->pts, mpctx->d_sub, 1); | 2731 update_subtitles(NULL, mpctx->sh_audio->pts, mpctx->d_sub, 1); |
2694 } | 2732 } |
2695 | 2733 |
2696 if (vo_vobsub && mpctx->sh_video) { | 2734 if (vo_vobsub && mpctx->sh_video) { |
2697 current_module = "seek_vobsub_reset"; | 2735 current_module = "seek_vobsub_reset"; |
2698 vobsub_seek(vo_vobsub, mpctx->sh_video->pts); | 2736 vobsub_seek(vo_vobsub, mpctx->sh_video->pts); |
2699 } | 2737 } |
2700 | 2738 |
2701 #ifdef CONFIG_ASS | 2739 #ifdef CONFIG_ASS |
2702 if (ass_enabled && mpctx->d_sub->sh && ((sh_sub_t *)mpctx->d_sub->sh)->ass_track) | 2740 if (ass_enabled && mpctx->d_sub->sh && ((sh_sub_t *)mpctx->d_sub->sh)->ass_track) |
2703 ass_flush_events(((sh_sub_t *)mpctx->d_sub->sh)->ass_track); | 2741 ass_flush_events(((sh_sub_t *)mpctx->d_sub->sh)->ass_track); |
2704 #endif | 2742 #endif |
2705 | 2743 |
2706 if (edl_records) { | 2744 if (edl_records) { |
2707 edl_needs_reset = 1; | 2745 edl_needs_reset = 1; |
2708 edl_backward = amount < 0; | 2746 edl_backward = amount < 0; |
2709 } | 2747 } |
2710 | 2748 |
2711 c_total = 0; | 2749 c_total = 0; |
2712 max_pts_correction = 0.1; | 2750 max_pts_correction = 0.1; |
2713 audio_time_usage = 0; video_time_usage = 0; vout_time_usage = 0; | 2751 audio_time_usage = 0; |
2714 drop_frame_cnt = 0; | 2752 video_time_usage = 0; |
2753 vout_time_usage = 0; | |
2754 drop_frame_cnt = 0; | |
2715 | 2755 |
2716 current_module = NULL; | 2756 current_module = NULL; |
2717 return 0; | 2757 return 0; |
2718 } | 2758 } |
2719 | 2759 |
2720 /* This preprocessor directive is a hack to generate a mplayer-nomain.o object | 2760 /* This preprocessor directive is a hack to generate a mplayer-nomain.o object |
2721 * file for some tools to link against. */ | 2761 * file for some tools to link against. */ |
2722 #ifndef DISABLE_MAIN | 2762 #ifndef DISABLE_MAIN |
2723 int main(int argc,char* argv[]){ | 2763 int main(int argc, char *argv[]) |
2724 | 2764 { |
2725 | |
2726 // movie info: | 2765 // movie info: |
2727 | 2766 |
2728 /* Flag indicating whether MPlayer should exit without playing anything. */ | 2767 /* Flag indicating whether MPlayer should exit without playing anything. */ |
2729 int opt_exit = 0; | 2768 int opt_exit = 0; |
2730 int i; | 2769 int i; |
2731 | 2770 |
2732 int gui_no_filename=0; | 2771 int gui_no_filename = 0; |
2733 | 2772 |
2734 common_preinit(); | 2773 common_preinit(); |
2735 | 2774 |
2736 // Create the config context and register the options | 2775 // Create the config context and register the options |
2737 mconfig = m_config_new(); | 2776 mconfig = m_config_new(); |
2738 m_config_register_options(mconfig,mplayer_opts); | 2777 m_config_register_options(mconfig, mplayer_opts); |
2739 m_config_register_options(mconfig, common_opts); | 2778 m_config_register_options(mconfig, common_opts); |
2740 mp_input_register_options(mconfig); | 2779 mp_input_register_options(mconfig); |
2741 | 2780 |
2742 // Preparse the command line | 2781 // Preparse the command line |
2743 m_config_preparse_command_line(mconfig,argc,argv); | 2782 m_config_preparse_command_line(mconfig, argc, argv); |
2744 | 2783 |
2745 #ifdef CONFIG_TV | 2784 #ifdef CONFIG_TV |
2746 stream_tv_defaults.immediate = 1; | 2785 stream_tv_defaults.immediate = 1; |
2747 #endif | 2786 #endif |
2748 | 2787 |
2749 if (argc > 1 && argv[1] && | 2788 if (argc > 1 && argv[1] && |
2750 (!strcmp(argv[1], "-gui") || !strcmp(argv[1], "-nogui"))) { | 2789 (!strcmp(argv[1], "-gui") || !strcmp(argv[1], "-nogui"))) { |
2751 use_gui = !strcmp(argv[1], "-gui"); | 2790 use_gui = !strcmp(argv[1], "-gui"); |
2752 } else | 2791 } else if (argv[0] && strstr(mp_basename(argv[0]), "gmplayer")) { |
2753 if (argv[0] && strstr(mp_basename(argv[0]), "gmplayer")) { | 2792 use_gui = 1; |
2754 use_gui=1; | 2793 } |
2755 } | |
2756 | 2794 |
2757 parse_cfgfiles(mconfig); | 2795 parse_cfgfiles(mconfig); |
2758 | 2796 |
2759 #ifdef CONFIG_GUI | 2797 #ifdef CONFIG_GUI |
2760 if ( use_gui ) { | 2798 if (use_gui) { |
2761 initialized_flags|=INITIALIZED_GUI; | 2799 initialized_flags |= INITIALIZED_GUI; |
2762 cfg_read(); | 2800 cfg_read(); |
2763 } | 2801 } |
2764 #endif | 2802 #endif |
2765 | 2803 |
2766 mpctx->playtree = m_config_parse_mp_command_line(mconfig, argc, argv); | 2804 mpctx->playtree = m_config_parse_mp_command_line(mconfig, argc, argv); |
2767 if(mpctx->playtree == NULL) | 2805 if (mpctx->playtree == NULL) |
2768 opt_exit = 1; | 2806 opt_exit = 1; |
2769 else { | 2807 else { |
2770 mpctx->playtree = play_tree_cleanup(mpctx->playtree); | 2808 mpctx->playtree = play_tree_cleanup(mpctx->playtree); |
2771 if(mpctx->playtree) { | 2809 if (mpctx->playtree) { |
2772 mpctx->playtree_iter = play_tree_iter_new(mpctx->playtree,mconfig); | 2810 mpctx->playtree_iter = play_tree_iter_new(mpctx->playtree, mconfig); |
2773 if(mpctx->playtree_iter) { | 2811 if (mpctx->playtree_iter) { |
2774 if(play_tree_iter_step(mpctx->playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) { | 2812 if (play_tree_iter_step(mpctx->playtree_iter, 0, 0) != PLAY_TREE_ITER_ENTRY) { |
2775 play_tree_iter_free(mpctx->playtree_iter); | 2813 play_tree_iter_free(mpctx->playtree_iter); |
2776 mpctx->playtree_iter = NULL; | 2814 mpctx->playtree_iter = NULL; |
2777 } | 2815 } |
2778 filename = play_tree_iter_get_file(mpctx->playtree_iter,1); | 2816 filename = play_tree_iter_get_file(mpctx->playtree_iter, 1); |
2779 } | 2817 } |
2780 } | 2818 } |
2781 } | 2819 } |
2782 | 2820 |
2783 print_version("MPlayer"); | 2821 print_version("MPlayer"); |
2784 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_GUI) | 2822 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_GUI) |
2785 void *runningmplayer = FindWindow("MPlayer GUI for Windows", "MPlayer for Windows"); | 2823 void *runningmplayer = FindWindow("MPlayer GUI for Windows", "MPlayer for Windows"); |
2786 if (runningmplayer && filename && use_gui) { | 2824 if (runningmplayer && filename && use_gui) { |
2787 COPYDATASTRUCT csData; | 2825 COPYDATASTRUCT csData; |
2788 char file[MAX_PATH]; | 2826 char file[MAX_PATH]; |
2789 char *filepart = filename; | 2827 char *filepart = filename; |
2790 if (GetFullPathName(filename, MAX_PATH, file, &filepart)) { | 2828 if (GetFullPathName(filename, MAX_PATH, file, &filepart)) { |
2791 csData.dwData = 0; | 2829 csData.dwData = 0; |
2792 csData.cbData = strlen(file)*2; | 2830 csData.cbData = strlen(file) * 2; |
2793 csData.lpData = file; | 2831 csData.lpData = file; |
2794 SendMessage(runningmplayer, WM_COPYDATA, (WPARAM)runningmplayer, (LPARAM)&csData); | 2832 SendMessage(runningmplayer, WM_COPYDATA, (WPARAM)runningmplayer, (LPARAM)&csData); |
2795 } | 2833 } |
2796 } | 2834 } |
2797 #endif | 2835 #endif |
2798 if (!common_init()) | 2836 if (!common_init()) |
2799 exit_player_with_rc(EXIT_NONE, 0); | 2837 exit_player_with_rc(EXIT_NONE, 0); |
2800 | 2838 |
2801 #ifndef CONFIG_GUI | 2839 #ifndef CONFIG_GUI |
2802 if(use_gui){ | 2840 if (use_gui) { |
2803 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui); | 2841 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_NoGui); |
2804 use_gui=0; | 2842 use_gui = 0; |
2805 } | 2843 } |
2806 #else | 2844 #else |
2807 #if !defined(__MINGW32__) && !defined(__CYGWIN__) | 2845 #if !defined(__MINGW32__) && !defined(__CYGWIN__) |
2808 if(use_gui && !vo_init()){ | 2846 if (use_gui && !vo_init()) { |
2809 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX); | 2847 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_GuiNeedsX); |
2810 use_gui=0; | 2848 use_gui = 0; |
2811 } | 2849 } |
2812 #endif | 2850 #endif |
2813 if (use_gui && mpctx->playtree_iter){ | 2851 if (use_gui && mpctx->playtree_iter) { |
2814 char cwd[PATH_MAX+2]; | 2852 char cwd[PATH_MAX + 2]; |
2815 // Free Playtree and Playtree-Iter as it's not used by the GUI. | 2853 // Free Playtree and Playtree-Iter as it's not used by the GUI. |
2816 play_tree_iter_free(mpctx->playtree_iter); | 2854 play_tree_iter_free(mpctx->playtree_iter); |
2817 mpctx->playtree_iter=NULL; | 2855 mpctx->playtree_iter = NULL; |
2818 | 2856 |
2819 if (getcwd(cwd, PATH_MAX) != (char *)NULL) | 2857 if (getcwd(cwd, PATH_MAX) != (char *)NULL) { |
2820 { | 2858 strcat(cwd, "/"); |
2821 strcat(cwd, "/"); | 2859 // Prefix relative paths with current working directory |
2822 // Prefix relative paths with current working directory | 2860 play_tree_add_bpf(mpctx->playtree, cwd); |
2823 play_tree_add_bpf(mpctx->playtree, cwd); | 2861 } |
2824 } | 2862 // Import initital playtree into GUI. |
2825 // Import initital playtree into GUI. | 2863 import_initial_playtree_into_gui(mpctx->playtree, mconfig, enqueue); |
2826 import_initial_playtree_into_gui(mpctx->playtree, mconfig, enqueue); | |
2827 } | 2864 } |
2828 #endif /* CONFIG_GUI */ | 2865 #endif /* CONFIG_GUI */ |
2829 | 2866 |
2830 if(video_driver_list && strcmp(video_driver_list[0],"help")==0){ | 2867 if (video_driver_list && strcmp(video_driver_list[0], "help") == 0) { |
2831 list_video_out(); | 2868 list_video_out(); |
2832 opt_exit = 1; | 2869 opt_exit = 1; |
2833 } | 2870 } |
2834 | 2871 |
2835 if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){ | 2872 if (audio_driver_list && strcmp(audio_driver_list[0], "help") == 0) { |
2836 list_audio_out(); | 2873 list_audio_out(); |
2837 opt_exit = 1; | 2874 opt_exit = 1; |
2838 } | 2875 } |
2839 | 2876 |
2840 if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){ | 2877 if (audio_codec_list && strcmp(audio_codec_list[0], "help") == 0) { |
2841 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs); | 2878 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs); |
2842 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_CODECS\n"); | 2879 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_CODECS\n"); |
2843 list_codecs(1); | 2880 list_codecs(1); |
2844 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); | 2881 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); |
2845 opt_exit = 1; | 2882 opt_exit = 1; |
2846 } | 2883 } |
2847 if(video_codec_list && strcmp(video_codec_list[0],"help")==0){ | 2884 if (video_codec_list && strcmp(video_codec_list[0], "help") == 0) { |
2848 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs); | 2885 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoCodecs); |
2849 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_CODECS\n"); | 2886 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_CODECS\n"); |
2850 list_codecs(0); | 2887 list_codecs(0); |
2851 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); | 2888 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); |
2852 opt_exit = 1; | 2889 opt_exit = 1; |
2853 } | 2890 } |
2854 if(video_fm_list && strcmp(video_fm_list[0],"help")==0){ | 2891 if (video_fm_list && strcmp(video_fm_list[0], "help") == 0) { |
2855 vfm_help(); | 2892 vfm_help(); |
2856 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); | 2893 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); |
2857 opt_exit = 1; | 2894 opt_exit = 1; |
2858 } | 2895 } |
2859 if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){ | 2896 if (audio_fm_list && strcmp(audio_fm_list[0], "help") == 0) { |
2860 afm_help(); | 2897 afm_help(); |
2861 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); | 2898 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); |
2862 opt_exit = 1; | 2899 opt_exit = 1; |
2863 } | 2900 } |
2864 if(af_cfg.list && strcmp(af_cfg.list[0],"help")==0){ | 2901 if (af_cfg.list && strcmp(af_cfg.list[0], "help") == 0) { |
2865 af_help(); | 2902 af_help(); |
2866 printf("\n"); | 2903 printf("\n"); |
2867 opt_exit = 1; | 2904 opt_exit = 1; |
2868 } | 2905 } |
2869 #ifdef CONFIG_X11 | 2906 #ifdef CONFIG_X11 |
2870 if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){ | 2907 if (vo_fstype_list && strcmp(vo_fstype_list[0], "help") == 0) { |
2871 fstype_help(); | 2908 fstype_help(); |
2872 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); | 2909 mp_msg(MSGT_FIXME, MSGL_FIXME, "\n"); |
2873 opt_exit = 1; | 2910 opt_exit = 1; |
2874 } | 2911 } |
2875 #endif | 2912 #endif |
2876 if((demuxer_name && strcmp(demuxer_name,"help")==0) || | 2913 if ((demuxer_name && strcmp(demuxer_name, "help") == 0) || |
2877 (audio_demuxer_name && strcmp(audio_demuxer_name,"help")==0) || | 2914 (audio_demuxer_name && strcmp(audio_demuxer_name, "help") == 0) || |
2878 (sub_demuxer_name && strcmp(sub_demuxer_name,"help")==0)){ | 2915 (sub_demuxer_name && strcmp(sub_demuxer_name, "help") == 0)) { |
2879 demuxer_help(); | 2916 demuxer_help(); |
2880 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n"); | 2917 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n"); |
2881 opt_exit = 1; | 2918 opt_exit = 1; |
2882 } | 2919 } |
2883 if(list_properties) { | 2920 if (list_properties) { |
2884 property_print_help(); | 2921 property_print_help(); |
2885 opt_exit = 1; | 2922 opt_exit = 1; |
2886 } | 2923 } |
2887 | 2924 |
2888 if(opt_exit) | 2925 if (opt_exit) |
2889 exit_player(EXIT_NONE); | 2926 exit_player(EXIT_NONE); |
2890 | 2927 |
2891 if (player_idle_mode && use_gui) { | 2928 if (player_idle_mode && use_gui) { |
2892 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_NoIdleAndGui); | 2929 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_NoIdleAndGui); |
2893 exit_player_with_rc(EXIT_NONE, 1); | 2930 exit_player_with_rc(EXIT_NONE, 1); |
2894 } | 2931 } |
2895 | 2932 |
2896 if(!filename && !player_idle_mode){ | 2933 if (!filename && !player_idle_mode) { |
2897 if(!use_gui){ | 2934 if (!use_gui) { |
2898 // no file/vcd/dvd -> show HELP: | 2935 // no file/vcd/dvd -> show HELP: |
2899 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text); | 2936 mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text); |
2900 exit_player_with_rc(EXIT_NONE, 0); | 2937 exit_player_with_rc(EXIT_NONE, 0); |
2901 } else gui_no_filename=1; | 2938 } else |
2939 gui_no_filename = 1; | |
2902 } | 2940 } |
2903 | 2941 |
2904 /* Display what configure line was used */ | 2942 /* Display what configure line was used */ |
2905 mp_msg(MSGT_CPLAYER, MSGL_V, "Configuration: " CONFIGURATION "\n"); | 2943 mp_msg(MSGT_CPLAYER, MSGL_V, "Configuration: " CONFIGURATION "\n"); |
2906 | 2944 |
2907 // Many users forget to include command line in bugreports... | 2945 // Many users forget to include command line in bugreports... |
2908 if( mp_msg_test(MSGT_CPLAYER,MSGL_V) ){ | 2946 if (mp_msg_test(MSGT_CPLAYER, MSGL_V)) { |
2909 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CommandLine); | 2947 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CommandLine); |
2910 for(i=1;i<argc;i++)mp_msg(MSGT_CPLAYER, MSGL_INFO," '%s'",argv[i]); | 2948 for (i = 1; i < argc; i++) |
2911 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n"); | 2949 mp_msg(MSGT_CPLAYER, MSGL_INFO, " '%s'", argv[i]); |
2950 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n"); | |
2912 } | 2951 } |
2913 | 2952 |
2914 //------ load global data first ------ | 2953 //------ load global data first ------ |
2915 | 2954 |
2916 #ifdef HAVE_RTC | 2955 #ifdef HAVE_RTC |
2917 if(!nortc) | 2956 if (!nortc) { |
2918 { | 2957 // seteuid(0); /* Can't hurt to try to get root here */ |
2919 // seteuid(0); /* Can't hurt to try to get root here */ | 2958 if ((rtc_fd = open(rtc_device ? rtc_device : "/dev/rtc", O_RDONLY)) < 0) |
2920 if ((rtc_fd = open(rtc_device ? rtc_device : "/dev/rtc", O_RDONLY)) < 0) | 2959 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_RTCDeviceNotOpenable, |
2921 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_RTCDeviceNotOpenable, | 2960 rtc_device ? rtc_device : "/dev/rtc", strerror(errno)); |
2922 rtc_device ? rtc_device : "/dev/rtc", strerror(errno)); | 2961 else { |
2923 else { | 2962 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */ |
2924 unsigned long irqp = 1024; /* 512 seemed OK. 128 is jerky. */ | 2963 |
2925 | 2964 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) { |
2926 if (ioctl(rtc_fd, RTC_IRQP_SET, irqp) < 0) { | 2965 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_LinuxRTCInitErrorIrqpSet, irqp, strerror(errno)); |
2927 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_LinuxRTCInitErrorIrqpSet, irqp, strerror(errno)); | 2966 mp_msg(MSGT_CPLAYER, MSGL_HINT, MSGTR_IncreaseRTCMaxUserFreq, irqp); |
2928 mp_msg(MSGT_CPLAYER, MSGL_HINT, MSGTR_IncreaseRTCMaxUserFreq, irqp); | 2967 close(rtc_fd); |
2929 close (rtc_fd); | 2968 rtc_fd = -1; |
2930 rtc_fd = -1; | 2969 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) { |
2931 } else if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) { | 2970 /* variable only by the root */ |
2932 /* variable only by the root */ | 2971 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCInitErrorPieOn, strerror(errno)); |
2933 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_LinuxRTCInitErrorPieOn, strerror(errno)); | 2972 close(rtc_fd); |
2934 close (rtc_fd); | 2973 rtc_fd = -1; |
2935 rtc_fd = -1; | 2974 } else |
2936 } else | 2975 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_UsingRTCTiming, irqp); |
2937 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_UsingRTCTiming, irqp); | 2976 } |
2938 } | 2977 } |
2939 } | |
2940 #ifdef CONFIG_GUI | 2978 #ifdef CONFIG_GUI |
2941 // breaks DGA and SVGAlib and VESA drivers: --A'rpi | 2979 // breaks DGA and SVGAlib and VESA drivers: --A'rpi |
2942 // and now ? -- Pontscho | 2980 // and now ? -- Pontscho |
2943 if(use_gui) setuid( getuid() ); // strongly test, please check this. | 2981 if (use_gui) |
2944 #endif | 2982 setuid(getuid()); // strongly test, please check this. |
2945 if(rtc_fd<0) | 2983 #endif |
2984 if (rtc_fd < 0) | |
2946 #endif /* HAVE_RTC */ | 2985 #endif /* HAVE_RTC */ |
2947 mp_msg(MSGT_CPLAYER, MSGL_V, "Using %s timing\n", | 2986 mp_msg(MSGT_CPLAYER, MSGL_V, "Using %s timing\n", |
2948 softsleep?"software":timer_name); | 2987 softsleep ? "software" : timer_name); |
2949 | 2988 |
2950 #ifdef HAVE_TERMCAP | 2989 #ifdef HAVE_TERMCAP |
2951 if ( !use_gui ) load_termcap(NULL); // load key-codes | 2990 if (!use_gui) |
2991 load_termcap(NULL); // load key-codes | |
2952 #endif | 2992 #endif |
2953 | 2993 |
2954 // ========== Init keyboard FIFO (connection to libvo) ============ | 2994 // ========== Init keyboard FIFO (connection to libvo) ============ |
2955 | 2995 |
2956 // Init input system | 2996 // Init input system |
2957 current_module = "init_input"; | 2997 current_module = "init_input"; |
2958 mp_input_init(); | 2998 mp_input_init(); |
2959 mp_input_add_key_fd(-1,0,mplayer_get_key,NULL); | 2999 mp_input_add_key_fd(-1, 0, mplayer_get_key, NULL); |
2960 if(slave_mode) | 3000 if (slave_mode) |
2961 mp_input_add_cmd_fd(0,USE_SELECT,MP_INPUT_SLAVE_CMD_FUNC,NULL); | 3001 mp_input_add_cmd_fd(0, USE_SELECT, MP_INPUT_SLAVE_CMD_FUNC, NULL); |
2962 else if(!noconsolecontrols) | 3002 else if (!noconsolecontrols) |
2963 mp_input_add_event_fd(0, getch2); | 3003 mp_input_add_event_fd(0, getch2); |
2964 // Set the libstream interrupt callback | 3004 // Set the libstream interrupt callback |
2965 stream_set_interrupt_callback(mp_input_check_interrupt); | 3005 stream_set_interrupt_callback(mp_input_check_interrupt); |
2966 | 3006 |
2967 #ifdef CONFIG_MENU | 3007 #ifdef CONFIG_MENU |
2968 if(use_menu) { | 3008 if (use_menu) { |
2969 if(menu_cfg && menu_init(mpctx, menu_cfg)) | 3009 if (menu_cfg && menu_init(mpctx, menu_cfg)) |
2970 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_MenuInitialized, menu_cfg); | 3010 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_MenuInitialized, menu_cfg); |
2971 else { | 3011 else { |
2972 menu_cfg = get_path("menu.conf"); | 3012 menu_cfg = get_path("menu.conf"); |
2973 if(menu_init(mpctx, menu_cfg)) | 3013 if (menu_init(mpctx, menu_cfg)) |
2974 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_MenuInitialized, menu_cfg); | 3014 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_MenuInitialized, menu_cfg); |
2975 else { | 3015 else { |
2976 if(menu_init(mpctx, MPLAYER_CONFDIR "/menu.conf")) | 3016 if (menu_init(mpctx, MPLAYER_CONFDIR "/menu.conf")) |
2977 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_MenuInitialized, MPLAYER_CONFDIR"/menu.conf"); | 3017 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_MenuInitialized, MPLAYER_CONFDIR "/menu.conf"); |
2978 else { | 3018 else { |
2979 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_MenuInitFailed); | 3019 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_MenuInitFailed); |
2980 use_menu = 0; | 3020 use_menu = 0; |
2981 } | 3021 } |
2982 } | 3022 } |
2983 } | 3023 } |
2984 } | 3024 } |
2985 #endif | 3025 #endif |
2986 | 3026 |
2987 initialized_flags|=INITIALIZED_INPUT; | 3027 initialized_flags |= INITIALIZED_INPUT; |
2988 current_module = NULL; | 3028 current_module = NULL; |
2989 | 3029 |
2990 // Catch signals | 3030 // Catch signals |
2991 #ifndef __MINGW32__ | 3031 #ifndef __MINGW32__ |
2992 signal(SIGCHLD,child_sighandler); | 3032 signal(SIGCHLD, child_sighandler); |
2993 #endif | 3033 #endif |
2994 | 3034 |
2995 #ifdef CONFIG_CRASH_DEBUG | 3035 #ifdef CONFIG_CRASH_DEBUG |
2996 prog_path = argv[0]; | 3036 prog_path = argv[0]; |
2997 #endif | 3037 #endif |
2998 //========= Catch terminate signals: ================ | 3038 //========= Catch terminate signals: ================ |
2999 // terminate requests: | 3039 // terminate requests: |
3000 signal(SIGTERM,exit_sighandler); // kill | 3040 signal(SIGTERM, exit_sighandler); // kill |
3001 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed | 3041 signal(SIGHUP, exit_sighandler); // kill -HUP / xterm closed |
3002 | 3042 |
3003 signal(SIGINT,exit_sighandler); // Interrupt from keyboard | 3043 signal(SIGINT, exit_sighandler); // Interrupt from keyboard |
3004 | 3044 |
3005 signal(SIGQUIT,exit_sighandler); // Quit from keyboard | 3045 signal(SIGQUIT, exit_sighandler); // Quit from keyboard |
3006 signal(SIGPIPE,exit_sighandler); // Some window managers cause this | 3046 signal(SIGPIPE, exit_sighandler); // Some window managers cause this |
3007 #ifdef CONFIG_SIGHANDLER | 3047 #ifdef CONFIG_SIGHANDLER |
3008 // fatal errors: | 3048 // fatal errors: |
3009 signal(SIGBUS,exit_sighandler); // bus error | 3049 signal(SIGBUS, exit_sighandler); // bus error |
3010 signal(SIGSEGV,exit_sighandler); // segfault | 3050 signal(SIGSEGV, exit_sighandler); // segfault |
3011 signal(SIGILL,exit_sighandler); // illegal instruction | 3051 signal(SIGILL, exit_sighandler); // illegal instruction |
3012 signal(SIGFPE,exit_sighandler); // floating point exc. | 3052 signal(SIGFPE, exit_sighandler); // floating point exc. |
3013 signal(SIGABRT,exit_sighandler); // abort() | 3053 signal(SIGABRT, exit_sighandler); // abort() |
3014 #ifdef CONFIG_CRASH_DEBUG | 3054 #ifdef CONFIG_CRASH_DEBUG |
3015 if (crash_debug) | 3055 if (crash_debug) |
3016 signal(SIGTRAP,exit_sighandler); | 3056 signal(SIGTRAP, exit_sighandler); |
3017 #endif | 3057 #endif |
3018 #endif | 3058 #endif |
3019 | 3059 |
3020 #ifdef CONFIG_GUI | 3060 #ifdef CONFIG_GUI |
3021 if(use_gui){ | 3061 if (use_gui) { |
3022 guiInit(); | 3062 guiInit(); |
3023 guiGetEvent(guiSetContext, mpctx); | 3063 guiGetEvent(guiSetContext, mpctx); |
3024 guiGetEvent( guiCEvent,(char *)((gui_no_filename) ? 0 : 1) ); | 3064 guiGetEvent(guiCEvent, (char *)((gui_no_filename) ? 0 : 1)); |
3025 } | 3065 } |
3026 #endif | 3066 #endif |
3027 | 3067 |
3028 // ******************* Now, let's see the per-file stuff ******************** | 3068 // ******************* Now, let's see the per-file stuff ******************** |
3029 | 3069 |
3030 play_next_file: | 3070 play_next_file: |
3031 | 3071 |
3032 // init global sub numbers | 3072 // init global sub numbers |
3033 mpctx->global_sub_size = 0; | 3073 mpctx->global_sub_size = 0; |
3034 memset(mpctx->sub_counts, 0, sizeof(mpctx->sub_counts)); | 3074 memset(mpctx->sub_counts, 0, sizeof(mpctx->sub_counts)); |
3035 | 3075 |
3036 if (filename) { | 3076 if (filename) { |
3037 load_per_protocol_config (mconfig, filename); | 3077 load_per_protocol_config(mconfig, filename); |
3038 load_per_extension_config (mconfig, filename); | 3078 load_per_extension_config(mconfig, filename); |
3039 load_per_file_config (mconfig, filename); | 3079 load_per_file_config(mconfig, filename); |
3040 } | 3080 } |
3041 | 3081 |
3042 if (video_driver_list) | 3082 if (video_driver_list) |
3043 load_per_output_config (mconfig, PROFILE_CFG_VO, video_driver_list[0]); | 3083 load_per_output_config(mconfig, PROFILE_CFG_VO, video_driver_list[0]); |
3044 if (audio_driver_list) | 3084 if (audio_driver_list) |
3045 load_per_output_config (mconfig, PROFILE_CFG_AO, audio_driver_list[0]); | 3085 load_per_output_config(mconfig, PROFILE_CFG_AO, audio_driver_list[0]); |
3046 | 3086 |
3047 // We must enable getch2 here to be able to interrupt network connection | 3087 // We must enable getch2 here to be able to interrupt network connection |
3048 // or cache filling | 3088 // or cache filling |
3049 if(!noconsolecontrols && !slave_mode){ | 3089 if (!noconsolecontrols && !slave_mode) { |
3050 if(initialized_flags&INITIALIZED_GETCH2) | 3090 if (initialized_flags & INITIALIZED_GETCH2) |
3051 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_Getch2InitializedTwice); | 3091 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_Getch2InitializedTwice); |
3052 else | 3092 else |
3053 getch2_enable(); // prepare stdin for hotkeys... | 3093 getch2_enable(); // prepare stdin for hotkeys... |
3054 initialized_flags|=INITIALIZED_GETCH2; | 3094 initialized_flags |= INITIALIZED_GETCH2; |
3055 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[init getch2]]]\n"); | 3095 mp_msg(MSGT_CPLAYER, MSGL_DBG2, "\n[[[init getch2]]]\n"); |
3056 } | 3096 } |
3057 | 3097 |
3058 // =================== GUI idle loop (STOP state) =========================== | 3098 // =================== GUI idle loop (STOP state) =========================== |
3059 #ifdef CONFIG_GUI | 3099 #ifdef CONFIG_GUI |
3060 if ( use_gui ) { | 3100 if (use_gui) { |
3061 mpctx->file_format=DEMUXER_TYPE_UNKNOWN; | 3101 mpctx->file_format = DEMUXER_TYPE_UNKNOWN; |
3062 guiGetEvent( guiSetDefaults,0 ); | 3102 guiGetEvent(guiSetDefaults, 0); |
3063 while ( guiIntfStruct.Playing != 1 ) | 3103 while (guiIntfStruct.Playing != 1) { |
3064 { | 3104 mp_cmd_t *cmd; |
3065 mp_cmd_t* cmd; | 3105 usec_sleep(20000); |
3066 usec_sleep(20000); | 3106 guiEventHandling(); |
3067 guiEventHandling(); | 3107 guiGetEvent(guiReDraw, NULL); |
3068 guiGetEvent( guiReDraw,NULL ); | 3108 if ((cmd = mp_input_get_cmd(0, 0, 0)) != NULL) { |
3069 if ( (cmd = mp_input_get_cmd(0,0,0)) != NULL) { | 3109 guiGetEvent(guiIEvent, (char *)cmd->id); |
3070 guiGetEvent(guiIEvent, (char *)cmd->id); | 3110 mp_cmd_free(cmd); |
3071 mp_cmd_free(cmd); | 3111 } |
3072 } | 3112 } |
3073 } | 3113 guiGetEvent(guiSetParameters, NULL); |
3074 guiGetEvent( guiSetParameters,NULL ); | 3114 if (guiIntfStruct.StreamType == STREAMTYPE_STREAM) { |
3075 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM ) | 3115 play_tree_t *entry = play_tree_new(); |
3076 { | 3116 play_tree_add_file(entry, guiIntfStruct.Filename); |
3077 play_tree_t * entry = play_tree_new(); | 3117 if (mpctx->playtree) |
3078 play_tree_add_file( entry,guiIntfStruct.Filename ); | 3118 play_tree_free_list(mpctx->playtree->child, 1); |
3079 if ( mpctx->playtree ) play_tree_free_list( mpctx->playtree->child,1 ); | 3119 else |
3080 else mpctx->playtree=play_tree_new(); | 3120 mpctx->playtree = play_tree_new(); |
3081 play_tree_set_child( mpctx->playtree,entry ); | 3121 play_tree_set_child(mpctx->playtree, entry); |
3082 if(mpctx->playtree) | 3122 if (mpctx->playtree) { |
3083 { | 3123 mpctx->playtree_iter = play_tree_iter_new(mpctx->playtree, mconfig); |
3084 mpctx->playtree_iter = play_tree_iter_new(mpctx->playtree,mconfig); | 3124 if (mpctx->playtree_iter) { |
3085 if(mpctx->playtree_iter) | 3125 if (play_tree_iter_step(mpctx->playtree_iter, 0, 0) != PLAY_TREE_ITER_ENTRY) { |
3086 { | 3126 play_tree_iter_free(mpctx->playtree_iter); |
3087 if(play_tree_iter_step(mpctx->playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) | 3127 mpctx->playtree_iter = NULL; |
3088 { | 3128 } |
3089 play_tree_iter_free(mpctx->playtree_iter); | 3129 filename = play_tree_iter_get_file(mpctx->playtree_iter, 1); |
3090 mpctx->playtree_iter = NULL; | 3130 } |
3091 } | 3131 } |
3092 filename = play_tree_iter_get_file(mpctx->playtree_iter,1); | 3132 } |
3093 } | |
3094 } | |
3095 } | |
3096 } | 3133 } |
3097 #endif /* CONFIG_GUI */ | 3134 #endif /* CONFIG_GUI */ |
3098 | 3135 |
3099 while (player_idle_mode && !filename) { | 3136 while (player_idle_mode && !filename) { |
3100 play_tree_t * entry = NULL; | 3137 play_tree_t *entry = NULL; |
3101 mp_cmd_t * cmd; | 3138 mp_cmd_t *cmd; |
3102 if (mpctx->video_out && vo_config_count) | 3139 if (mpctx->video_out && vo_config_count) |
3103 mpctx->video_out->control(VOCTRL_PAUSE, NULL); | 3140 mpctx->video_out->control(VOCTRL_PAUSE, NULL); |
3104 while (!(cmd = mp_input_get_cmd(0,1,0))) { // wait for command | 3141 while (!(cmd = mp_input_get_cmd(0, 1, 0))) { // wait for command |
3105 if (mpctx->video_out && vo_config_count) mpctx->video_out->check_events(); | 3142 if (mpctx->video_out && vo_config_count) |
3106 usec_sleep(20000); | 3143 mpctx->video_out->check_events(); |
3107 } | 3144 usec_sleep(20000); |
3108 switch (cmd->id) { | 3145 } |
3146 switch (cmd->id) { | |
3109 case MP_CMD_LOADFILE: | 3147 case MP_CMD_LOADFILE: |
3110 // prepare a tree entry with the new filename | 3148 // prepare a tree entry with the new filename |
3111 entry = play_tree_new(); | 3149 entry = play_tree_new(); |
3112 play_tree_add_file(entry, cmd->args[0].v.s); | 3150 play_tree_add_file(entry, cmd->args[0].v.s); |
3113 // The entry is added to the main playtree after the switch(). | 3151 // The entry is added to the main playtree after the switch(). |
3114 break; | 3152 break; |
3115 case MP_CMD_LOADLIST: | 3153 case MP_CMD_LOADLIST: |
3116 entry = parse_playlist_file(cmd->args[0].v.s); | 3154 entry = parse_playlist_file(cmd->args[0].v.s); |
3117 break; | 3155 break; |
3118 case MP_CMD_QUIT: | 3156 case MP_CMD_QUIT: |
3119 exit_player_with_rc(EXIT_QUIT, (cmd->nargs > 0)? cmd->args[0].v.i : 0); | 3157 exit_player_with_rc(EXIT_QUIT, (cmd->nargs > 0) ? cmd->args[0].v.i : 0); |
3120 break; | 3158 break; |
3121 case MP_CMD_VO_FULLSCREEN: | 3159 case MP_CMD_VO_FULLSCREEN: |
3122 case MP_CMD_GET_PROPERTY: | 3160 case MP_CMD_GET_PROPERTY: |
3123 case MP_CMD_SET_PROPERTY: | 3161 case MP_CMD_SET_PROPERTY: |
3124 case MP_CMD_STEP_PROPERTY: | 3162 case MP_CMD_STEP_PROPERTY: |
3125 run_command(mpctx, cmd); | 3163 run_command(mpctx, cmd); |
3126 break; | 3164 break; |
3127 } | 3165 } |
3128 | 3166 |
3129 mp_cmd_free(cmd); | 3167 mp_cmd_free(cmd); |
3130 | 3168 |
3131 if (entry) { // user entered a command that gave a valid entry | 3169 if (entry) { // user entered a command that gave a valid entry |
3132 if (mpctx->playtree) // the playtree is always a node with one child. let's clear it | 3170 if (mpctx->playtree) // the playtree is always a node with one child. let's clear it |
3133 play_tree_free_list(mpctx->playtree->child, 1); | 3171 play_tree_free_list(mpctx->playtree->child, 1); |
3134 else mpctx->playtree=play_tree_new(); // .. or make a brand new playtree | 3172 else |
3135 | 3173 mpctx->playtree = play_tree_new(); // .. or make a brand new playtree |
3136 if (!mpctx->playtree) continue; // couldn't make playtree! wait for next command | 3174 |
3137 | 3175 if (!mpctx->playtree) |
3138 play_tree_set_child(mpctx->playtree, entry); | 3176 continue; // couldn't make playtree! wait for next command |
3139 | 3177 |
3140 /* Make iterator start at the top the of tree. */ | 3178 play_tree_set_child(mpctx->playtree, entry); |
3141 mpctx->playtree_iter = play_tree_iter_new(mpctx->playtree, mconfig); | 3179 |
3142 if (!mpctx->playtree_iter) continue; | 3180 /* Make iterator start at the top the of tree. */ |
3143 | 3181 mpctx->playtree_iter = play_tree_iter_new(mpctx->playtree, mconfig); |
3144 // find the first real item in the tree | 3182 if (!mpctx->playtree_iter) |
3145 if (play_tree_iter_step(mpctx->playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) { | 3183 continue; |
3146 // no items! | 3184 |
3147 play_tree_iter_free(mpctx->playtree_iter); | 3185 // find the first real item in the tree |
3148 mpctx->playtree_iter = NULL; | 3186 if (play_tree_iter_step(mpctx->playtree_iter, 0, 0) != PLAY_TREE_ITER_ENTRY) { |
3149 continue; // wait for next command | 3187 // no items! |
3150 } | 3188 play_tree_iter_free(mpctx->playtree_iter); |
3151 filename = play_tree_iter_get_file(mpctx->playtree_iter, 1); | 3189 mpctx->playtree_iter = NULL; |
3152 } | 3190 continue; // wait for next command |
3153 } | 3191 } |
3192 filename = play_tree_iter_get_file(mpctx->playtree_iter, 1); | |
3193 } | |
3194 } | |
3154 //--------------------------------------------------------------------------- | 3195 //--------------------------------------------------------------------------- |
3155 | 3196 |
3156 if (mpctx->video_out && vo_config_count) | 3197 if (mpctx->video_out && vo_config_count) |
3157 mpctx->video_out->control(VOCTRL_RESUME, NULL); | 3198 mpctx->video_out->control(VOCTRL_RESUME, NULL); |
3158 | 3199 |
3159 if(filename) { | 3200 if (filename) { |
3160 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, | 3201 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_Playing, |
3161 filename_recode(filename)); | 3202 filename_recode(filename)); |
3162 if(use_filename_title && vo_wintitle == NULL) | 3203 if (use_filename_title && vo_wintitle == NULL) |
3163 vo_wintitle = strdup(mp_basename(filename)); | 3204 vo_wintitle = strdup(mp_basename(filename)); |
3164 } | 3205 } |
3165 | 3206 |
3166 edl_loadfile(); | 3207 edl_loadfile(); |
3167 | 3208 |
3174 } | 3215 } |
3175 } | 3216 } |
3176 | 3217 |
3177 //==================== Open VOB-Sub ============================ | 3218 //==================== Open VOB-Sub ============================ |
3178 | 3219 |
3179 current_module="vobsub"; | 3220 current_module = "vobsub"; |
3180 load_vob_subtitle(filename, spudec_ifo, &vo_spudec, add_vob_subtitle); | 3221 load_vob_subtitle(filename, spudec_ifo, &vo_spudec, add_vob_subtitle); |
3181 if(vo_vobsub){ | 3222 if (vo_vobsub) { |
3182 initialized_flags|=INITIALIZED_VOBSUB; | 3223 initialized_flags |= INITIALIZED_VOBSUB; |
3183 vobsub_set_from_lang(vo_vobsub, dvdsub_lang); | 3224 vobsub_set_from_lang(vo_vobsub, dvdsub_lang); |
3184 mp_property_do("sub_forced_only", M_PROPERTY_SET, &forced_subs_only, mpctx); | 3225 mp_property_do("sub_forced_only", M_PROPERTY_SET, &forced_subs_only, mpctx); |
3185 | 3226 |
3186 // setup global sub numbering | 3227 // setup global sub numbering |
3187 mpctx->sub_counts[SUB_SOURCE_VOBSUB] = vobsub_get_indexes_count(vo_vobsub); | 3228 mpctx->sub_counts[SUB_SOURCE_VOBSUB] = vobsub_get_indexes_count(vo_vobsub); |
3188 } | 3229 } |
3189 | 3230 |
3190 //============ Open & Sync STREAM --- fork cache2 ==================== | 3231 //============ Open & Sync STREAM --- fork cache2 ==================== |
3191 | 3232 |
3192 mpctx->stream=NULL; | 3233 mpctx->stream = NULL; |
3193 mpctx->demuxer=NULL; | 3234 mpctx->demuxer = NULL; |
3194 if (mpctx->d_audio) { | 3235 if (mpctx->d_audio) { |
3195 //free_demuxer_stream(mpctx->d_audio); | 3236 //free_demuxer_stream(mpctx->d_audio); |
3196 mpctx->d_audio=NULL; | 3237 mpctx->d_audio = NULL; |
3197 } | 3238 } |
3198 if (mpctx->d_video) { | 3239 if (mpctx->d_video) { |
3199 //free_demuxer_stream(d_video); | 3240 //free_demuxer_stream(d_video); |
3200 mpctx->d_video=NULL; | 3241 mpctx->d_video = NULL; |
3201 } | 3242 } |
3202 mpctx->sh_audio=NULL; | 3243 mpctx->sh_audio = NULL; |
3203 mpctx->sh_video=NULL; | 3244 mpctx->sh_video = NULL; |
3204 | 3245 |
3205 current_module="open_stream"; | 3246 current_module = "open_stream"; |
3206 mpctx->stream=open_stream(filename,0,&mpctx->file_format); | 3247 mpctx->stream = open_stream(filename, 0, &mpctx->file_format); |
3207 if(!mpctx->stream) { // error... | 3248 if (!mpctx->stream) { // error... |
3208 mpctx->eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY); | 3249 mpctx->eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY); |
3209 goto goto_next_file; | 3250 goto goto_next_file; |
3210 } | 3251 } |
3211 initialized_flags|=INITIALIZED_STREAM; | 3252 initialized_flags |= INITIALIZED_STREAM; |
3212 | 3253 |
3213 #ifdef CONFIG_GUI | 3254 #ifdef CONFIG_GUI |
3214 if ( use_gui ) guiGetEvent( guiSetStream,(char *)mpctx->stream ); | 3255 if (use_gui) |
3215 #endif | 3256 guiGetEvent(guiSetStream, (char *)mpctx->stream); |
3216 | 3257 #endif |
3217 if(mpctx->file_format == DEMUXER_TYPE_PLAYLIST) { | 3258 |
3218 play_tree_t* entry; | 3259 if (mpctx->file_format == DEMUXER_TYPE_PLAYLIST) { |
3219 // Handle playlist | 3260 play_tree_t *entry; |
3220 current_module="handle_playlist"; | 3261 // Handle playlist |
3221 mp_msg(MSGT_CPLAYER,MSGL_V,"Parsing playlist %s...\n", | 3262 current_module = "handle_playlist"; |
3222 filename_recode(filename)); | 3263 mp_msg(MSGT_CPLAYER, MSGL_V, "Parsing playlist %s...\n", |
3223 entry = parse_playtree(mpctx->stream,0); | 3264 filename_recode(filename)); |
3224 mpctx->eof=playtree_add_playlist(entry); | 3265 entry = parse_playtree(mpctx->stream, 0); |
3225 goto goto_next_file; | 3266 mpctx->eof = playtree_add_playlist(entry); |
3226 } | 3267 goto goto_next_file; |
3227 mpctx->stream->start_pos+=seek_to_byte; | 3268 } |
3228 | 3269 mpctx->stream->start_pos += seek_to_byte; |
3229 if(stream_dump_type==5){ | 3270 |
3230 unsigned char buf[4096]; | 3271 if (stream_dump_type == 5) { |
3231 int len; | 3272 unsigned char buf[4096]; |
3232 FILE *f; | 3273 int len; |
3233 current_module="dumpstream"; | 3274 FILE *f; |
3234 stream_reset(mpctx->stream); | 3275 current_module = "dumpstream"; |
3235 stream_seek(mpctx->stream,mpctx->stream->start_pos); | 3276 stream_reset(mpctx->stream); |
3236 f=fopen(stream_dump_name,"wb"); | 3277 stream_seek(mpctx->stream, mpctx->stream->start_pos); |
3237 if(!f){ | 3278 f = fopen(stream_dump_name, "wb"); |
3238 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile); | 3279 if (!f) { |
3239 exit_player(EXIT_ERROR); | 3280 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_CantOpenDumpfile); |
3240 } | 3281 exit_player(EXIT_ERROR); |
3241 if (dvd_chapter > 1) { | 3282 } |
3242 int chapter = dvd_chapter - 1; | 3283 if (dvd_chapter > 1) { |
3243 stream_control(mpctx->stream, STREAM_CTRL_SEEK_TO_CHAPTER, &chapter); | 3284 int chapter = dvd_chapter - 1; |
3244 } | 3285 stream_control(mpctx->stream, STREAM_CTRL_SEEK_TO_CHAPTER, &chapter); |
3245 while(!mpctx->stream->eof && !async_quit_request){ | 3286 } |
3246 len=stream_read(mpctx->stream,buf,4096); | 3287 while (!mpctx->stream->eof && !async_quit_request) { |
3247 if(len>0) { | 3288 len = stream_read(mpctx->stream, buf, 4096); |
3248 if(fwrite(buf,len,1,f) != 1) { | 3289 if (len > 0) { |
3249 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name); | 3290 if (fwrite(buf, len, 1, f) != 1) { |
3250 exit_player(EXIT_ERROR); | 3291 mp_msg(MSGT_MENCODER, MSGL_FATAL, MSGTR_ErrorWritingFile, stream_dump_name); |
3251 } | 3292 exit_player(EXIT_ERROR); |
3252 } | 3293 } |
3253 if(dvd_last_chapter > 0) { | 3294 } |
3254 int chapter = -1; | 3295 if (dvd_last_chapter > 0) { |
3255 if (stream_control(mpctx->stream, STREAM_CTRL_GET_CURRENT_CHAPTER, | 3296 int chapter = -1; |
3256 &chapter) == STREAM_OK && chapter + 1 > dvd_last_chapter) | 3297 if (stream_control(mpctx->stream, STREAM_CTRL_GET_CURRENT_CHAPTER, |
3257 break; | 3298 &chapter) == STREAM_OK && chapter + 1 > dvd_last_chapter) |
3258 } | 3299 break; |
3259 } | 3300 } |
3260 if(fclose(f)) { | 3301 } |
3261 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile,stream_dump_name); | 3302 if (fclose(f)) { |
3262 exit_player(EXIT_ERROR); | 3303 mp_msg(MSGT_MENCODER, MSGL_FATAL, MSGTR_ErrorWritingFile, stream_dump_name); |
3263 } | 3304 exit_player(EXIT_ERROR); |
3264 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped); | 3305 } |
3265 exit_player_with_rc(EXIT_EOF, 0); | 3306 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CoreDumped); |
3266 } | 3307 exit_player_with_rc(EXIT_EOF, 0); |
3267 | 3308 } |
3268 if(mpctx->stream->type==STREAMTYPE_BD){ | 3309 |
3269 if(audio_lang && audio_id==-1) audio_id=bd_aid_from_lang(mpctx->stream,audio_lang); | 3310 if (mpctx->stream->type == STREAMTYPE_BD) { |
3270 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=bd_sid_from_lang(mpctx->stream,dvdsub_lang); | 3311 if (audio_lang && audio_id == -1) |
3271 } | 3312 audio_id = bd_aid_from_lang(mpctx->stream, audio_lang); |
3313 if (dvdsub_lang && dvdsub_id == -1) | |
3314 dvdsub_id = bd_sid_from_lang(mpctx->stream, dvdsub_lang); | |
3315 } | |
3272 | 3316 |
3273 #ifdef CONFIG_DVDREAD | 3317 #ifdef CONFIG_DVDREAD |
3274 if(mpctx->stream->type==STREAMTYPE_DVD){ | 3318 if (mpctx->stream->type == STREAMTYPE_DVD) { |
3275 current_module="dvd lang->id"; | 3319 current_module = "dvd lang->id"; |
3276 if(audio_lang && audio_id==-1) audio_id=dvd_aid_from_lang(mpctx->stream,audio_lang); | 3320 if (audio_lang && audio_id == -1) |
3277 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(mpctx->stream,dvdsub_lang); | 3321 audio_id = dvd_aid_from_lang(mpctx->stream, audio_lang); |
3278 // setup global sub numbering | 3322 if (dvdsub_lang && dvdsub_id == -1) |
3279 mpctx->sub_counts[SUB_SOURCE_DEMUX] = dvd_number_of_subs(mpctx->stream); | 3323 dvdsub_id = dvd_sid_from_lang(mpctx->stream, dvdsub_lang); |
3280 current_module=NULL; | 3324 // setup global sub numbering |
3281 } | 3325 mpctx->sub_counts[SUB_SOURCE_DEMUX] = dvd_number_of_subs(mpctx->stream); |
3326 current_module = NULL; | |
3327 } | |
3282 #endif | 3328 #endif |
3283 | 3329 |
3284 #ifdef CONFIG_DVDNAV | 3330 #ifdef CONFIG_DVDNAV |
3285 if(mpctx->stream->type==STREAMTYPE_DVDNAV){ | 3331 if (mpctx->stream->type == STREAMTYPE_DVDNAV) { |
3286 current_module="dvdnav lang->id"; | 3332 current_module = "dvdnav lang->id"; |
3287 if(audio_lang && audio_id==-1) audio_id=mp_dvdnav_aid_from_lang(mpctx->stream,audio_lang); | 3333 if (audio_lang && audio_id == -1) |
3288 dvdsub_lang_id = -3; | 3334 audio_id = mp_dvdnav_aid_from_lang(mpctx->stream, audio_lang); |
3289 if(dvdsub_lang && dvdsub_id==-1) | 3335 dvdsub_lang_id = -3; |
3290 dvdsub_lang_id=dvdsub_id=mp_dvdnav_sid_from_lang(mpctx->stream,dvdsub_lang); | 3336 if (dvdsub_lang && dvdsub_id == -1) |
3291 // setup global sub numbering | 3337 dvdsub_lang_id = dvdsub_id = mp_dvdnav_sid_from_lang(mpctx->stream, dvdsub_lang); |
3292 mpctx->sub_counts[SUB_SOURCE_DEMUX] = mp_dvdnav_number_of_subs(mpctx->stream); | 3338 // setup global sub numbering |
3293 current_module=NULL; | 3339 mpctx->sub_counts[SUB_SOURCE_DEMUX] = mp_dvdnav_number_of_subs(mpctx->stream); |
3294 } | 3340 current_module = NULL; |
3341 } | |
3295 #endif | 3342 #endif |
3296 | 3343 |
3297 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts) | 3344 // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts) |
3298 goto_enable_cache: | 3345 goto_enable_cache: |
3299 if(stream_cache_size>0){ | 3346 if (stream_cache_size > 0) { |
3300 int res; | 3347 int res; |
3301 current_module="enable_cache"; | 3348 current_module = "enable_cache"; |
3302 res = stream_enable_cache(mpctx->stream,stream_cache_size*1024, | 3349 res = stream_enable_cache(mpctx->stream, stream_cache_size * 1024, |
3303 stream_cache_size*1024*(stream_cache_min_percent / 100.0), | 3350 stream_cache_size * 1024 * (stream_cache_min_percent / 100.0), |
3304 stream_cache_size*1024*(stream_cache_seek_min_percent / 100.0)); | 3351 stream_cache_size * 1024 * (stream_cache_seek_min_percent / 100.0)); |
3305 if(res == 0) | 3352 if (res == 0) |
3306 if((mpctx->eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) goto goto_next_file; | 3353 if ((mpctx->eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY))) |
3307 } | 3354 goto goto_next_file; |
3355 } | |
3308 | 3356 |
3309 //============ Open DEMUXERS --- DETECT file type ======================= | 3357 //============ Open DEMUXERS --- DETECT file type ======================= |
3310 current_module="demux_open"; | 3358 current_module = "demux_open"; |
3311 | 3359 |
3312 mpctx->demuxer=demux_open(mpctx->stream,mpctx->file_format,audio_id,video_id,dvdsub_id,filename); | 3360 mpctx->demuxer = demux_open(mpctx->stream, mpctx->file_format, audio_id, video_id, dvdsub_id, filename); |
3313 | 3361 |
3314 // HACK to get MOV Reference Files working | 3362 // HACK to get MOV Reference Files working |
3315 | 3363 |
3316 if (mpctx->demuxer && mpctx->demuxer->type==DEMUXER_TYPE_PLAYLIST) | 3364 if (mpctx->demuxer && mpctx->demuxer->type == DEMUXER_TYPE_PLAYLIST) { |
3317 { | 3365 unsigned char *playlist_entry; |
3318 unsigned char* playlist_entry; | 3366 play_tree_t *list = NULL, *entry = NULL; |
3319 play_tree_t *list = NULL, *entry = NULL; | 3367 |
3320 | 3368 current_module = "handle_demux_playlist"; |
3321 current_module="handle_demux_playlist"; | 3369 while (ds_get_packet(mpctx->demuxer->video, &playlist_entry) > 0) { |
3322 while (ds_get_packet(mpctx->demuxer->video,&playlist_entry)>0) | 3370 char *temp; |
3323 { | 3371 const char *bname; |
3324 char *temp; | 3372 |
3325 const char *bname; | 3373 mp_msg(MSGT_CPLAYER, MSGL_V, "Adding file %s to element entry.\n", |
3326 | 3374 filename_recode(playlist_entry)); |
3327 mp_msg(MSGT_CPLAYER,MSGL_V,"Adding file %s to element entry.\n", | 3375 |
3328 filename_recode(playlist_entry)); | 3376 bname = mp_basename(playlist_entry); |
3329 | 3377 if ((strlen(bname) > 10) && !strncmp(bname, "qt", 2) && !strncmp(bname + 3, "gateQT", 6)) |
3330 bname=mp_basename(playlist_entry); | 3378 continue; |
3331 if ((strlen(bname)>10) && !strncmp(bname,"qt",2) && !strncmp(bname+3,"gateQT",6)) | 3379 |
3332 continue; | 3380 if (!strcmp(playlist_entry, filename)) // ignoring self-reference |
3333 | 3381 continue; |
3334 if (!strcmp(playlist_entry,filename)) // ignoring self-reference | 3382 |
3335 continue; | 3383 entry = play_tree_new(); |
3336 | 3384 |
3337 entry = play_tree_new(); | 3385 if (filename && !strcmp(mp_basename(playlist_entry), playlist_entry)) { // add reference path of current file |
3338 | 3386 temp = malloc((strlen(filename) - strlen(mp_basename(filename)) + strlen(playlist_entry) + 1)); |
3339 if (filename && !strcmp(mp_basename(playlist_entry),playlist_entry)) // add reference path of current file | 3387 if (temp) { |
3340 { | 3388 strncpy(temp, filename, strlen(filename) - strlen(mp_basename(filename))); |
3341 temp=malloc((strlen(filename)-strlen(mp_basename(filename))+strlen(playlist_entry)+1)); | 3389 temp[strlen(filename) - strlen(mp_basename(filename))] = '\0'; |
3342 if (temp) | 3390 strcat(temp, playlist_entry); |
3343 { | 3391 if (!strcmp(temp, filename)) { |
3344 strncpy(temp, filename, strlen(filename)-strlen(mp_basename(filename))); | 3392 free(temp); |
3345 temp[strlen(filename)-strlen(mp_basename(filename))]='\0'; | 3393 continue; |
3346 strcat(temp, playlist_entry); | 3394 } |
3347 if (!strcmp(temp, filename)) { | 3395 play_tree_add_file(entry, temp); |
3348 free(temp); | 3396 mp_msg(MSGT_CPLAYER, MSGL_V, "Resolving reference to %s.\n", temp); |
3349 continue; | 3397 free(temp); |
3350 } | 3398 } |
3351 play_tree_add_file(entry,temp); | 3399 } else |
3352 mp_msg(MSGT_CPLAYER,MSGL_V,"Resolving reference to %s.\n",temp); | 3400 play_tree_add_file(entry, playlist_entry); |
3353 free(temp); | 3401 |
3354 } | 3402 if (!list) |
3355 } | 3403 list = entry; |
3356 else | 3404 else |
3357 play_tree_add_file(entry,playlist_entry); | 3405 play_tree_append_entry(list, entry); |
3358 | 3406 } |
3359 if(!list) | 3407 free_demuxer(mpctx->demuxer); |
3360 list = entry; | 3408 mpctx->demuxer = NULL; |
3361 else | 3409 |
3362 play_tree_append_entry(list,entry); | 3410 if (list) { |
3363 } | 3411 entry = play_tree_new(); |
3364 free_demuxer(mpctx->demuxer); | 3412 play_tree_set_child(entry, list); |
3365 mpctx->demuxer = NULL; | 3413 mpctx->eof = playtree_add_playlist(entry); |
3366 | 3414 goto goto_next_file; |
3367 if (list) | 3415 } |
3368 { | 3416 } |
3369 entry = play_tree_new(); | 3417 |
3370 play_tree_set_child(entry,list); | 3418 if (!mpctx->demuxer) |
3371 mpctx->eof=playtree_add_playlist(entry); | 3419 goto goto_next_file; |
3372 goto goto_next_file; | 3420 if (dvd_chapter > 1) { |
3373 } | 3421 float pts; |
3374 } | 3422 if (demuxer_seek_chapter(mpctx->demuxer, dvd_chapter - 1, 1, &pts, NULL, NULL) >= 0 && pts > -1.0) |
3375 | 3423 seek(mpctx, pts, SEEK_ABSOLUTE); |
3376 if(!mpctx->demuxer) | 3424 } |
3377 goto goto_next_file; | 3425 |
3378 if(dvd_chapter>1) { | 3426 initialized_flags |= INITIALIZED_DEMUXER; |
3379 float pts; | |
3380 if (demuxer_seek_chapter(mpctx->demuxer, dvd_chapter-1, 1, &pts, NULL, NULL) >= 0 && pts > -1.0) | |
3381 seek(mpctx, pts, SEEK_ABSOLUTE); | |
3382 } | |
3383 | |
3384 initialized_flags|=INITIALIZED_DEMUXER; | |
3385 | 3427 |
3386 #ifdef CONFIG_ASS | 3428 #ifdef CONFIG_ASS |
3387 if (ass_enabled && ass_library) { | 3429 if (ass_enabled && ass_library) { |
3388 for (i = 0; i < mpctx->demuxer->num_attachments; ++i) { | 3430 for (i = 0; i < mpctx->demuxer->num_attachments; ++i) { |
3389 demux_attachment_t* att = mpctx->demuxer->attachments + i; | 3431 demux_attachment_t *att = mpctx->demuxer->attachments + i; |
3390 if (extract_embedded_fonts && | 3432 if (extract_embedded_fonts && |
3391 att->name && att->type && att->data && att->data_size && | 3433 att->name && att->type && att->data && att->data_size && |
3392 (strcmp(att->type, "application/x-truetype-font") == 0 || | 3434 (strcmp(att->type, "application/x-truetype-font") == 0 || |
3393 strcmp(att->type, "application/x-font") == 0)) | 3435 strcmp(att->type, "application/x-font") == 0)) |
3394 ass_add_font(ass_library, att->name, att->data, att->data_size); | 3436 ass_add_font(ass_library, att->name, att->data, att->data_size); |
3395 } | 3437 } |
3396 } | 3438 } |
3397 #endif | 3439 #endif |
3398 | 3440 |
3399 current_module="demux_open2"; | 3441 current_module = "demux_open2"; |
3400 | 3442 |
3401 mpctx->d_audio=mpctx->demuxer->audio; | 3443 mpctx->d_audio = mpctx->demuxer->audio; |
3402 mpctx->d_video=mpctx->demuxer->video; | 3444 mpctx->d_video = mpctx->demuxer->video; |
3403 mpctx->d_sub=mpctx->demuxer->sub; | 3445 mpctx->d_sub = mpctx->demuxer->sub; |
3404 | 3446 |
3405 if (ts_prog) { | 3447 if (ts_prog) { |
3406 int tmp = ts_prog; | 3448 int tmp = ts_prog; |
3407 mp_property_do("switch_program", M_PROPERTY_SET, &tmp, mpctx); | 3449 mp_property_do("switch_program", M_PROPERTY_SET, &tmp, mpctx); |
3408 } | 3450 } |
3409 // select audio stream | 3451 // select audio stream |
3410 select_audio(mpctx->demuxer, audio_id, audio_lang); | 3452 select_audio(mpctx->demuxer, audio_id, audio_lang); |
3411 | 3453 |
3412 // DUMP STREAMS: | 3454 // DUMP STREAMS: |
3413 if((stream_dump_type)&&(stream_dump_type<4)){ | 3455 if ((stream_dump_type) && (stream_dump_type < 4)) { |
3414 FILE *f; | 3456 FILE *f; |
3415 demux_stream_t *ds=NULL; | 3457 demux_stream_t *ds = NULL; |
3416 current_module="dump"; | 3458 current_module = "dump"; |
3417 // select stream to dump | 3459 // select stream to dump |
3418 switch(stream_dump_type){ | 3460 switch (stream_dump_type) { |
3419 case 1: ds=mpctx->d_audio;break; | 3461 case 1: ds = mpctx->d_audio; |
3420 case 2: ds=mpctx->d_video;break; | 3462 break; |
3421 case 3: ds=mpctx->d_sub;break; | 3463 case 2: ds = mpctx->d_video; |
3422 } | 3464 break; |
3423 if(!ds){ | 3465 case 3: ds = mpctx->d_sub; |
3424 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedStreamMissing); | 3466 break; |
3425 exit_player(EXIT_ERROR); | 3467 } |
3426 } | 3468 if (!ds) { |
3427 // disable other streams: | 3469 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_DumpSelectedStreamMissing); |
3428 if(mpctx->d_audio && mpctx->d_audio!=ds) {ds_free_packs(mpctx->d_audio); mpctx->d_audio->id=-2; } | 3470 exit_player(EXIT_ERROR); |
3429 if(mpctx->d_video && mpctx->d_video!=ds) {ds_free_packs(mpctx->d_video); mpctx->d_video->id=-2; } | 3471 } |
3430 if(mpctx->d_sub && mpctx->d_sub!=ds) {ds_free_packs(mpctx->d_sub); mpctx->d_sub->id=-2; } | 3472 // disable other streams: |
3431 // let's dump it! | 3473 if (mpctx->d_audio && mpctx->d_audio != ds) { |
3432 f=fopen(stream_dump_name,"wb"); | 3474 ds_free_packs(mpctx->d_audio); |
3433 if(!f){ | 3475 mpctx->d_audio->id = -2; |
3434 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CantOpenDumpfile); | 3476 } |
3435 exit_player(EXIT_ERROR); | 3477 if (mpctx->d_video && mpctx->d_video != ds) { |
3436 } | 3478 ds_free_packs(mpctx->d_video); |
3437 while(!ds->eof){ | 3479 mpctx->d_video->id = -2; |
3438 unsigned char* start; | 3480 } |
3439 int in_size=ds_get_packet(ds,&start); | 3481 if (mpctx->d_sub && mpctx->d_sub != ds) { |
3440 if( (mpctx->demuxer->file_format==DEMUXER_TYPE_AVI || mpctx->demuxer->file_format==DEMUXER_TYPE_ASF || mpctx->demuxer->file_format==DEMUXER_TYPE_MOV) | 3482 ds_free_packs(mpctx->d_sub); |
3441 && stream_dump_type==2) fwrite(&in_size,1,4,f); | 3483 mpctx->d_sub->id = -2; |
3442 if(in_size>0) fwrite(start,in_size,1,f); | 3484 } |
3443 if(dvd_last_chapter>0) { | 3485 // let's dump it! |
3444 int cur_chapter = demuxer_get_current_chapter(mpctx->demuxer); | 3486 f = fopen(stream_dump_name, "wb"); |
3445 if(cur_chapter!=-1 && cur_chapter+1>dvd_last_chapter) | 3487 if (!f) { |
3446 break; | 3488 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_CantOpenDumpfile); |
3447 } | 3489 exit_player(EXIT_ERROR); |
3448 } | 3490 } |
3449 fclose(f); | 3491 while (!ds->eof) { |
3450 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CoreDumped); | 3492 unsigned char *start; |
3451 exit_player_with_rc(EXIT_EOF, 0); | 3493 int in_size = ds_get_packet(ds, &start); |
3452 } | 3494 if ((mpctx->demuxer->file_format == DEMUXER_TYPE_AVI || mpctx->demuxer->file_format == DEMUXER_TYPE_ASF || mpctx->demuxer->file_format == DEMUXER_TYPE_MOV) |
3453 | 3495 && stream_dump_type == 2) |
3454 mpctx->sh_audio=mpctx->d_audio->sh; | 3496 fwrite(&in_size, 1, 4, f); |
3455 mpctx->sh_video=mpctx->d_video->sh; | 3497 if (in_size > 0) |
3456 | 3498 fwrite(start, in_size, 1, f); |
3457 if(mpctx->sh_video){ | 3499 if (dvd_last_chapter > 0) { |
3458 | 3500 int cur_chapter = demuxer_get_current_chapter(mpctx->demuxer); |
3459 current_module="video_read_properties"; | 3501 if (cur_chapter != -1 && cur_chapter + 1 > dvd_last_chapter) |
3460 if(!video_read_properties(mpctx->sh_video)) { | 3502 break; |
3461 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotReadVideoProperties); | 3503 } |
3462 mpctx->sh_video=mpctx->d_video->sh=NULL; | 3504 } |
3463 } else { | 3505 fclose(f); |
3464 mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_FilefmtFourccSizeFpsFtime, | 3506 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CoreDumped); |
3465 mpctx->demuxer->file_format,mpctx->sh_video->format, mpctx->sh_video->disp_w,mpctx->sh_video->disp_h, | 3507 exit_player_with_rc(EXIT_EOF, 0); |
3466 mpctx->sh_video->fps,mpctx->sh_video->frametime | 3508 } |
3467 ); | 3509 |
3468 | 3510 mpctx->sh_audio = mpctx->d_audio->sh; |
3469 /* need to set fps here for output encoders to pick it up in their init */ | 3511 mpctx->sh_video = mpctx->d_video->sh; |
3470 if(force_fps){ | 3512 |
3471 mpctx->sh_video->fps=force_fps; | 3513 if (mpctx->sh_video) { |
3472 mpctx->sh_video->frametime=1.0f/mpctx->sh_video->fps; | 3514 current_module = "video_read_properties"; |
3473 } | 3515 if (!video_read_properties(mpctx->sh_video)) { |
3474 vo_fps = mpctx->sh_video->fps; | 3516 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CannotReadVideoProperties); |
3475 | 3517 mpctx->sh_video = mpctx->d_video->sh = NULL; |
3476 if(!mpctx->sh_video->fps && !force_fps && !correct_pts){ | 3518 } else { |
3477 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_FPSnotspecified); | 3519 mp_msg(MSGT_CPLAYER, MSGL_V, MSGTR_FilefmtFourccSizeFpsFtime, |
3478 correct_pts = 1; | 3520 mpctx->demuxer->file_format, mpctx->sh_video->format, mpctx->sh_video->disp_w, mpctx->sh_video->disp_h, |
3479 } | 3521 mpctx->sh_video->fps, mpctx->sh_video->frametime |
3480 } | 3522 ); |
3481 | 3523 |
3482 } | 3524 /* need to set fps here for output encoders to pick it up in their init */ |
3483 | 3525 if (force_fps) { |
3484 if(!mpctx->sh_video && !mpctx->sh_audio){ | 3526 mpctx->sh_video->fps = force_fps; |
3485 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NoStreamFound); | 3527 mpctx->sh_video->frametime = 1.0f / mpctx->sh_video->fps; |
3528 } | |
3529 vo_fps = mpctx->sh_video->fps; | |
3530 | |
3531 if (!mpctx->sh_video->fps && !force_fps && !correct_pts) { | |
3532 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_FPSnotspecified); | |
3533 correct_pts = 1; | |
3534 } | |
3535 } | |
3536 } | |
3537 | |
3538 if (!mpctx->sh_video && !mpctx->sh_audio) { | |
3539 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_NoStreamFound); | |
3486 #ifdef CONFIG_DVBIN | 3540 #ifdef CONFIG_DVBIN |
3487 if(mpctx->stream->type == STREAMTYPE_DVB) | 3541 if (mpctx->stream->type == STREAMTYPE_DVB) { |
3488 { | 3542 int dir; |
3489 int dir; | 3543 int v = mpctx->last_dvb_step; |
3490 int v = mpctx->last_dvb_step; | 3544 if (v > 0) |
3491 if(v > 0) | 3545 dir = DVB_CHANNEL_HIGHER; |
3492 dir = DVB_CHANNEL_HIGHER; | 3546 else |
3493 else | 3547 dir = DVB_CHANNEL_LOWER; |
3494 dir = DVB_CHANNEL_LOWER; | 3548 |
3495 | 3549 if (dvb_step_channel(mpctx->stream, dir)) |
3496 if(dvb_step_channel(mpctx->stream, dir)) | 3550 mpctx->eof = mpctx->dvbin_reopen = 1; |
3497 mpctx->eof = mpctx->dvbin_reopen = 1; | 3551 } |
3498 } | 3552 #endif |
3499 #endif | 3553 goto goto_next_file; // exit_player(MSGTR_Exit_error); |
3500 goto goto_next_file; // exit_player(MSGTR_Exit_error); | 3554 } |
3501 } | |
3502 | 3555 |
3503 /* display clip info */ | 3556 /* display clip info */ |
3504 demux_info_print(mpctx->demuxer); | 3557 demux_info_print(mpctx->demuxer); |
3505 | 3558 |
3506 //================== Read SUBTITLES (DVD & TEXT) ========================== | 3559 //================== Read SUBTITLES (DVD & TEXT) ========================== |
3507 if(vo_spudec==NULL && | 3560 if (vo_spudec == NULL && |
3508 (mpctx->stream->type==STREAMTYPE_DVD || mpctx->stream->type == STREAMTYPE_DVDNAV)){ | 3561 (mpctx->stream->type == STREAMTYPE_DVD || mpctx->stream->type == STREAMTYPE_DVDNAV)) { |
3509 init_vo_spudec(); | 3562 init_vo_spudec(); |
3510 } | 3563 } |
3511 | 3564 |
3512 if(1 || mpctx->sh_video) { | 3565 if (1 || mpctx->sh_video) { |
3513 // after reading video params we should load subtitles because | 3566 // after reading video params we should load subtitles because |
3514 // we know fps so now we can adjust subtitle time to ~6 seconds AST | 3567 // we know fps so now we can adjust subtitle time to ~6 seconds AST |
3515 // check .sub | 3568 // check .sub |
3516 double fps = mpctx->sh_video ? mpctx->sh_video->fps : 25; | 3569 double fps = mpctx->sh_video ? mpctx->sh_video->fps : 25; |
3517 current_module="read_subtitles_file"; | 3570 current_module = "read_subtitles_file"; |
3518 load_subtitles(filename, fps, add_subtitles); | 3571 load_subtitles(filename, fps, add_subtitles); |
3519 if (mpctx->set_of_sub_size > 0) | 3572 if (mpctx->set_of_sub_size > 0) |
3520 mpctx->sub_counts[SUB_SOURCE_SUBS] = mpctx->set_of_sub_size; | 3573 mpctx->sub_counts[SUB_SOURCE_SUBS] = mpctx->set_of_sub_size; |
3521 // set even if we have no subs yet, they may be added later | 3574 // set even if we have no subs yet, they may be added later |
3522 initialized_flags |= INITIALIZED_SUBS; | 3575 initialized_flags |= INITIALIZED_SUBS; |
3523 } | 3576 } |
3524 | 3577 |
3525 if (select_subtitle(mpctx)) { | 3578 if (select_subtitle(mpctx)) { |
3526 if(subdata) | 3579 if (subdata) |
3527 switch (stream_dump_type) { | 3580 switch (stream_dump_type) { |
3528 case 3: list_sub_file(subdata); break; | 3581 case 3: list_sub_file(subdata); |
3529 case 4: dump_mpsub(subdata, mpctx->sh_video->fps); break; | 3582 break; |
3530 case 6: dump_srt(subdata, mpctx->sh_video->fps); break; | 3583 case 4: dump_mpsub(subdata, mpctx->sh_video->fps); |
3531 case 7: dump_microdvd(subdata, mpctx->sh_video->fps); break; | 3584 break; |
3532 case 8: dump_jacosub(subdata, mpctx->sh_video->fps); break; | 3585 case 6: dump_srt(subdata, mpctx->sh_video->fps); |
3533 case 9: dump_sami(subdata, mpctx->sh_video->fps); break; | 3586 break; |
3534 } | 3587 case 7: dump_microdvd(subdata, mpctx->sh_video->fps); |
3535 } | 3588 break; |
3536 | 3589 case 8: dump_jacosub(subdata, mpctx->sh_video->fps); |
3537 print_file_properties(mpctx, filename); | 3590 break; |
3538 | 3591 case 9: dump_sami(subdata, mpctx->sh_video->fps); |
3539 // Adjust EDL positions with start_pts | 3592 break; |
3540 if (edl_start_pts && start_pts) { | 3593 } |
3541 edl_record_ptr edl = edl_records; | 3594 } |
3542 while (edl) { | 3595 |
3543 edl->start_sec += start_pts; | 3596 print_file_properties(mpctx, filename); |
3544 edl->stop_sec += start_pts; | 3597 |
3545 edl = edl->next; | 3598 // Adjust EDL positions with start_pts |
3546 } | 3599 if (edl_start_pts && start_pts) { |
3547 } | 3600 edl_record_ptr edl = edl_records; |
3548 | 3601 while (edl) { |
3549 if (mpctx->sh_video) | 3602 edl->start_sec += start_pts; |
3550 reinit_video_chain(); | 3603 edl->stop_sec += start_pts; |
3551 | 3604 edl = edl->next; |
3552 if (mpctx->sh_video) { | 3605 } |
3553 if (vo_flags & 0x08 && vo_spudec) | 3606 } |
3554 spudec_set_hw_spu(vo_spudec, mpctx->video_out); | 3607 |
3608 if (mpctx->sh_video) | |
3609 reinit_video_chain(); | |
3610 | |
3611 if (mpctx->sh_video) { | |
3612 if (vo_flags & 0x08 && vo_spudec) | |
3613 spudec_set_hw_spu(vo_spudec, mpctx->video_out); | |
3555 | 3614 |
3556 #ifdef CONFIG_FREETYPE | 3615 #ifdef CONFIG_FREETYPE |
3557 force_load_font = 1; | 3616 force_load_font = 1; |
3558 #endif | 3617 #endif |
3559 } else if (!mpctx->sh_audio) | 3618 } else if (!mpctx->sh_audio) |
3560 goto goto_next_file; | 3619 goto goto_next_file; |
3561 | 3620 |
3562 //================== MAIN: ========================== | 3621 //================== MAIN: ========================== |
3563 current_module="main"; | 3622 current_module = "main"; |
3564 | 3623 |
3565 if(playing_msg) { | 3624 if (playing_msg) { |
3566 char* msg = property_expand_string(mpctx, playing_msg); | 3625 char *msg = property_expand_string(mpctx, playing_msg); |
3567 mp_msg(MSGT_CPLAYER,MSGL_INFO,"%s",msg); | 3626 mp_msg(MSGT_CPLAYER, MSGL_INFO, "%s", msg); |
3568 free(msg); | 3627 free(msg); |
3569 } | 3628 } |
3570 | 3629 |
3571 | |
3572 // Disable the term OSD in verbose mode | 3630 // Disable the term OSD in verbose mode |
3573 if(verbose) term_osd = 0; | 3631 if (verbose) |
3574 | 3632 term_osd = 0; |
3575 { | 3633 |
3576 mpctx->num_buffered_frames=0; | 3634 { |
3577 mpctx->framestep_found=0; | 3635 mpctx->num_buffered_frames = 0; |
3636 mpctx->framestep_found = 0; | |
3578 | 3637 |
3579 // Make sure old OSD does not stay around, | 3638 // Make sure old OSD does not stay around, |
3580 // e.g. with -fixed-vo and same-resolution files | 3639 // e.g. with -fixed-vo and same-resolution files |
3581 clear_osd_msgs(); | 3640 clear_osd_msgs(); |
3582 update_osd_msg(); | 3641 update_osd_msg(); |
3583 | 3642 |
3584 //================ SETUP AUDIO ========================== | 3643 //================ SETUP AUDIO ========================== |
3585 | 3644 |
3586 if(mpctx->sh_audio){ | 3645 if (mpctx->sh_audio) { |
3587 reinit_audio_chain(); | 3646 reinit_audio_chain(); |
3588 if (mpctx->sh_audio && mpctx->sh_audio->codec) | 3647 if (mpctx->sh_audio && mpctx->sh_audio->codec) |
3589 mp_msg(MSGT_IDENTIFY,MSGL_INFO, "ID_AUDIO_CODEC=%s\n", mpctx->sh_audio->codec->name); | 3648 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_CODEC=%s\n", mpctx->sh_audio->codec->name); |
3590 } | 3649 } |
3591 | 3650 |
3592 current_module="av_init"; | 3651 current_module = "av_init"; |
3593 | 3652 |
3594 if(mpctx->sh_video){ | 3653 if (mpctx->sh_video) { |
3595 mpctx->sh_video->timer=0; | 3654 mpctx->sh_video->timer = 0; |
3596 if (! ignore_start) | 3655 if (!ignore_start) |
3597 audio_delay += mpctx->sh_video->stream_delay; | 3656 audio_delay += mpctx->sh_video->stream_delay; |
3598 } | 3657 } |
3599 if(mpctx->sh_audio){ | 3658 if (mpctx->sh_audio) { |
3600 if (start_volume >= 0) | 3659 if (start_volume >= 0) |
3601 mixer_setvolume(&mpctx->mixer, start_volume, start_volume); | 3660 mixer_setvolume(&mpctx->mixer, start_volume, start_volume); |
3602 if (! ignore_start) | 3661 if (!ignore_start) |
3603 audio_delay -= mpctx->sh_audio->stream_delay; | 3662 audio_delay -= mpctx->sh_audio->stream_delay; |
3604 mpctx->delay=-audio_delay; | 3663 mpctx->delay = -audio_delay; |
3605 } | 3664 } |
3606 | 3665 |
3607 if(!mpctx->sh_audio){ | 3666 if (!mpctx->sh_audio) { |
3608 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound); | 3667 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_NoSound); |
3609 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused audio chunks.\n",mpctx->d_audio->packs); | 3668 mp_msg(MSGT_CPLAYER, MSGL_V, "Freeing %d unused audio chunks.\n", mpctx->d_audio->packs); |
3610 ds_free_packs(mpctx->d_audio); // free buffered chunks | 3669 ds_free_packs(mpctx->d_audio); // free buffered chunks |
3611 //mpctx->d_audio->id=-2; // do not read audio chunks | 3670 //mpctx->d_audio->id=-2; // do not read audio chunks |
3612 //uninit_player(INITIALIZED_AO); // close device | 3671 //uninit_player(INITIALIZED_AO); // close device |
3613 } | 3672 } |
3614 if(!mpctx->sh_video){ | 3673 if (!mpctx->sh_video) { |
3615 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Video_NoVideo); | 3674 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_Video_NoVideo); |
3616 mp_msg(MSGT_CPLAYER,MSGL_V,"Freeing %d unused video chunks.\n",mpctx->d_video->packs); | 3675 mp_msg(MSGT_CPLAYER, MSGL_V, "Freeing %d unused video chunks.\n", mpctx->d_video->packs); |
3617 ds_free_packs(mpctx->d_video); | 3676 ds_free_packs(mpctx->d_video); |
3618 mpctx->d_video->id=-2; | 3677 mpctx->d_video->id = -2; |
3619 //if(!fixed_vo) uninit_player(INITIALIZED_VO); | 3678 //if(!fixed_vo) uninit_player(INITIALIZED_VO); |
3620 } | 3679 } |
3621 | 3680 |
3622 if (!mpctx->sh_video && !mpctx->sh_audio) | 3681 if (!mpctx->sh_video && !mpctx->sh_audio) |
3623 goto goto_next_file; | 3682 goto goto_next_file; |
3624 | 3683 |
3625 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf! | 3684 //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf! |
3626 if(force_fps && mpctx->sh_video){ | 3685 if (force_fps && mpctx->sh_video) { |
3627 vo_fps = mpctx->sh_video->fps=force_fps; | 3686 vo_fps = mpctx->sh_video->fps = force_fps; |
3628 mpctx->sh_video->frametime=1.0f/mpctx->sh_video->fps; | 3687 mpctx->sh_video->frametime = 1.0f / mpctx->sh_video->fps; |
3629 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_FPSforced,mpctx->sh_video->fps,mpctx->sh_video->frametime); | 3688 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_FPSforced, mpctx->sh_video->fps, mpctx->sh_video->frametime); |
3630 } | 3689 } |
3631 | 3690 |
3632 #ifdef CONFIG_GUI | 3691 #ifdef CONFIG_GUI |
3633 if ( use_gui ) { | 3692 if (use_gui) { |
3634 if ( mpctx->sh_audio ) guiIntfStruct.AudioType=mpctx->sh_audio->channels; else guiIntfStruct.AudioType=0; | 3693 if (mpctx->sh_audio) |
3635 if ( !mpctx->sh_video && mpctx->sh_audio ) guiGetEvent( guiSetAudioOnly,(char *)1 ); else guiGetEvent( guiSetAudioOnly,(char *)0 ); | 3694 guiIntfStruct.AudioType = mpctx->sh_audio->channels; |
3636 guiGetEvent( guiSetFileFormat,(char *)mpctx->demuxer->file_format ); | 3695 else |
3637 if ( guiGetEvent( guiSetValues,(char *)mpctx->sh_video ) ) goto goto_next_file; | 3696 guiIntfStruct.AudioType = 0; |
3638 guiGetEvent( guiSetDemuxer,(char *)mpctx->demuxer ); | 3697 if (!mpctx->sh_video && mpctx->sh_audio) |
3639 } | 3698 guiGetEvent(guiSetAudioOnly, (char *)1); |
3640 #endif | 3699 else |
3641 | 3700 guiGetEvent(guiSetAudioOnly, (char *)0); |
3642 mp_input_set_section(NULL); | 3701 guiGetEvent(guiSetFileFormat, (char *)mpctx->demuxer->file_format); |
3702 if (guiGetEvent(guiSetValues, (char *)mpctx->sh_video)) | |
3703 goto goto_next_file; | |
3704 guiGetEvent(guiSetDemuxer, (char *)mpctx->demuxer); | |
3705 } | |
3706 #endif | |
3707 | |
3708 mp_input_set_section(NULL); | |
3643 //TODO: add desired (stream-based) sections here | 3709 //TODO: add desired (stream-based) sections here |
3644 if (mpctx->stream->type==STREAMTYPE_TV) mp_input_set_section("tv"); | 3710 if (mpctx->stream->type == STREAMTYPE_TV) |
3645 if (mpctx->stream->type==STREAMTYPE_DVDNAV) mp_input_set_section("dvdnav"); | 3711 mp_input_set_section("tv"); |
3712 if (mpctx->stream->type == STREAMTYPE_DVDNAV) | |
3713 mp_input_set_section("dvdnav"); | |
3646 | 3714 |
3647 //==================== START PLAYING ======================= | 3715 //==================== START PLAYING ======================= |
3648 | 3716 |
3649 if(mpctx->loop_times>1) mpctx->loop_times--; else | 3717 if (mpctx->loop_times > 1) |
3650 if(mpctx->loop_times==1) mpctx->loop_times = -1; | 3718 mpctx->loop_times--; |
3651 | 3719 else if (mpctx->loop_times == 1) |
3652 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_StartPlaying); | 3720 mpctx->loop_times = -1; |
3653 | 3721 |
3654 total_time_usage_start=GetTimer(); | 3722 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_StartPlaying); |
3655 audio_time_usage=0; video_time_usage=0; vout_time_usage=0; | 3723 |
3656 total_frame_cnt=0; drop_frame_cnt=0; // fix for multifile fps benchmark | 3724 total_time_usage_start = GetTimer(); |
3657 play_n_frames=play_n_frames_mf; | 3725 audio_time_usage = 0; |
3658 mpctx->startup_decode_retry = DEFAULT_STARTUP_DECODE_RETRY; | 3726 video_time_usage = 0; |
3659 | 3727 vout_time_usage = 0; |
3660 if(play_n_frames==0){ | 3728 total_frame_cnt = 0; |
3661 mpctx->eof=PT_NEXT_ENTRY; goto goto_next_file; | 3729 drop_frame_cnt = 0; // fix for multifile fps benchmark |
3662 } | 3730 play_n_frames = play_n_frames_mf; |
3663 | 3731 mpctx->startup_decode_retry = DEFAULT_STARTUP_DECODE_RETRY; |
3664 if (seek_to_sec) { | 3732 |
3665 seek(mpctx, seek_to_sec, SEEK_ABSOLUTE); | 3733 if (play_n_frames == 0) { |
3666 end_at.pos += seek_to_sec; | 3734 mpctx->eof = PT_NEXT_ENTRY; |
3667 } | 3735 goto goto_next_file; |
3736 } | |
3737 | |
3738 if (seek_to_sec) { | |
3739 seek(mpctx, seek_to_sec, SEEK_ABSOLUTE); | |
3740 end_at.pos += seek_to_sec; | |
3741 } | |
3668 | 3742 |
3669 #ifdef CONFIG_DVDNAV | 3743 #ifdef CONFIG_DVDNAV |
3670 mp_dvdnav_context_free(mpctx); | 3744 mp_dvdnav_context_free(mpctx); |
3671 if (mpctx->stream->type == STREAMTYPE_DVDNAV) { | 3745 if (mpctx->stream->type == STREAMTYPE_DVDNAV) { |
3672 mp_dvdnav_read_wait(mpctx->stream, 0, 1); | 3746 mp_dvdnav_read_wait(mpctx->stream, 0, 1); |
3673 mp_dvdnav_cell_has_changed(mpctx->stream,1); | 3747 mp_dvdnav_cell_has_changed(mpctx->stream, 1); |
3674 } | 3748 } |
3675 #endif | 3749 #endif |
3676 | 3750 |
3677 while(!mpctx->eof){ | 3751 while (!mpctx->eof) { |
3678 float aq_sleep_time=0; | 3752 float aq_sleep_time = 0; |
3679 | 3753 |
3680 if(dvd_last_chapter>0) { | 3754 if (dvd_last_chapter > 0) { |
3681 int cur_chapter = demuxer_get_current_chapter(mpctx->demuxer); | 3755 int cur_chapter = demuxer_get_current_chapter(mpctx->demuxer); |
3682 if(cur_chapter!=-1 && cur_chapter+1>dvd_last_chapter) | 3756 if (cur_chapter != -1 && cur_chapter + 1 > dvd_last_chapter) |
3683 goto goto_next_file; | 3757 goto goto_next_file; |
3684 } | 3758 } |
3685 | 3759 |
3686 if(!mpctx->sh_audio && mpctx->d_audio->sh) { | 3760 if (!mpctx->sh_audio && mpctx->d_audio->sh) { |
3687 mpctx->sh_audio = mpctx->d_audio->sh; | 3761 mpctx->sh_audio = mpctx->d_audio->sh; |
3688 mpctx->sh_audio->ds = mpctx->d_audio; | 3762 mpctx->sh_audio->ds = mpctx->d_audio; |
3689 reinit_audio_chain(); | 3763 reinit_audio_chain(); |
3690 } | 3764 } |
3691 | 3765 |
3692 /*========================== PLAY AUDIO ============================*/ | 3766 /*========================== PLAY AUDIO ============================*/ |
3693 | 3767 |
3694 if (mpctx->sh_audio) | 3768 if (mpctx->sh_audio) |
3695 if (!fill_audio_out_buffers()) | 3769 if (!fill_audio_out_buffers()) |
3696 // at eof, all audio at least written to ao | 3770 // at eof, all audio at least written to ao |
3697 if (!mpctx->sh_video) | 3771 if (!mpctx->sh_video) |
3698 mpctx->eof = PT_NEXT_ENTRY; | 3772 mpctx->eof = PT_NEXT_ENTRY; |
3699 | 3773 |
3700 | 3774 if (!mpctx->sh_video) { |
3701 if(!mpctx->sh_video) { | 3775 // handle audio-only case: |
3702 // handle audio-only case: | 3776 double a_pos = 0; |
3703 double a_pos=0; | 3777 // sh_audio can be NULL due to video stream switching |
3704 // sh_audio can be NULL due to video stream switching | 3778 // TODO: handle this better |
3705 // TODO: handle this better | 3779 if ((!quiet || end_at.type == END_AT_TIME) && mpctx->sh_audio) |
3706 if((!quiet || end_at.type == END_AT_TIME) && mpctx->sh_audio) | 3780 a_pos = playing_audio_pts(mpctx->sh_audio, mpctx->d_audio, mpctx->audio_out); |
3707 a_pos = playing_audio_pts(mpctx->sh_audio, mpctx->d_audio, mpctx->audio_out); | 3781 |
3708 | 3782 if (!quiet) |
3709 if(!quiet) | 3783 print_status(a_pos, 0, 0); |
3710 print_status(a_pos, 0, 0); | 3784 |
3711 | 3785 if (end_at.type == END_AT_TIME && end_at.pos < a_pos || |
3712 if(end_at.type == END_AT_TIME && end_at.pos < a_pos || | 3786 end_at.type == END_AT_SIZE && end_at.pos < stream_tell(mpctx->stream)) |
3713 end_at.type == END_AT_SIZE && end_at.pos < stream_tell(mpctx->stream)) | 3787 mpctx->eof = PT_NEXT_ENTRY; |
3714 mpctx->eof = PT_NEXT_ENTRY; | 3788 update_subtitles(NULL, a_pos, mpctx->d_sub, 0); |
3715 update_subtitles(NULL, a_pos, mpctx->d_sub, 0); | 3789 update_osd_msg(); |
3716 update_osd_msg(); | 3790 } else { |
3717 | 3791 int frame_time_remaining = 0; |
3718 } else { | 3792 int blit_frame = 1; |
3719 int frame_time_remaining = 0; | 3793 // skip timing after seek |
3720 int blit_frame = 1; | 3794 int skip_timing = mpctx->startup_decode_retry > 0; |
3721 // skip timing after seek | |
3722 int skip_timing = mpctx->startup_decode_retry > 0; | |
3723 | 3795 |
3724 /*========================== PLAY VIDEO ============================*/ | 3796 /*========================== PLAY VIDEO ============================*/ |
3725 | 3797 |
3726 vo_pts=mpctx->sh_video->timer*90000.0; | 3798 vo_pts = mpctx->sh_video->timer * 90000.0; |
3727 vo_fps=mpctx->sh_video->fps; | 3799 vo_fps = mpctx->sh_video->fps; |
3728 | 3800 |
3729 if (!mpctx->num_buffered_frames) { | 3801 if (!mpctx->num_buffered_frames) { |
3730 double frame_time = update_video(&blit_frame); | 3802 double frame_time = update_video(&blit_frame); |
3731 while (!blit_frame && mpctx->startup_decode_retry > 0) { | 3803 while (!blit_frame && mpctx->startup_decode_retry > 0) { |
3732 double delay = mpctx->delay; | 3804 double delay = mpctx->delay; |
3733 // these initial decode failures are probably due to codec delay, | 3805 // these initial decode failures are probably due to codec delay, |
3734 // ignore them and also their probably nonsense durations | 3806 // ignore them and also their probably nonsense durations |
3735 update_video(&blit_frame); | 3807 update_video(&blit_frame); |
3736 mpctx->delay = delay; | 3808 mpctx->delay = delay; |
3737 mpctx->startup_decode_retry--; | 3809 mpctx->startup_decode_retry--; |
3738 } | 3810 } |
3739 mpctx->startup_decode_retry = 0; | 3811 mpctx->startup_decode_retry = 0; |
3740 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time); | 3812 mp_dbg(MSGT_AVSYNC, MSGL_DBG2, "*** ftime=%5.3f ***\n", frame_time); |
3741 if (mpctx->sh_video->vf_initialized < 0) { | 3813 if (mpctx->sh_video->vf_initialized < 0) { |
3742 mp_msg(MSGT_CPLAYER,MSGL_FATAL, MSGTR_NotInitializeVOPorVO); | 3814 mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_NotInitializeVOPorVO); |
3743 mpctx->eof = 1; goto goto_next_file; | 3815 mpctx->eof = 1; |
3744 } | 3816 goto goto_next_file; |
3745 if (frame_time < 0) { | 3817 } |
3746 // if we have no more video, sleep some arbitrary time | 3818 if (frame_time < 0) { |
3747 frame_time = 1.0/20.0; | 3819 // if we have no more video, sleep some arbitrary time |
3748 // only stop playing when audio is at end as well | 3820 frame_time = 1.0 / 20.0; |
3749 if (!mpctx->sh_audio || mpctx->d_audio->eof) | 3821 // only stop playing when audio is at end as well |
3750 mpctx->eof = 1; | 3822 if (!mpctx->sh_audio || mpctx->d_audio->eof) |
3751 } else { | 3823 mpctx->eof = 1; |
3752 // might return with !eof && !blit_frame if !correct_pts | 3824 } else { |
3753 mpctx->num_buffered_frames += blit_frame; | 3825 // might return with !eof && !blit_frame if !correct_pts |
3754 mpctx->time_frame += frame_time / playback_speed; // for nosound | 3826 mpctx->num_buffered_frames += blit_frame; |
3755 } | 3827 mpctx->time_frame += frame_time / playback_speed; // for nosound |
3756 } | 3828 } |
3829 } | |
3757 | 3830 |
3758 // ========================================================================== | 3831 // ========================================================================== |
3759 | 3832 |
3760 // current_module="draw_osd"; | 3833 // current_module="draw_osd"; |
3761 // if(vo_config_count) mpctx->video_out->draw_osd(); | 3834 // if(vo_config_count) mpctx->video_out->draw_osd(); |
3762 | 3835 |
3763 #ifdef CONFIG_GUI | 3836 #ifdef CONFIG_GUI |
3764 if(use_gui) guiEventHandling(); | 3837 if (use_gui) |
3765 #endif | 3838 guiEventHandling(); |
3766 | 3839 #endif |
3767 current_module="vo_check_events"; | 3840 |
3768 if (vo_config_count) mpctx->video_out->check_events(); | 3841 current_module = "vo_check_events"; |
3842 if (vo_config_count) | |
3843 mpctx->video_out->check_events(); | |
3769 | 3844 |
3770 #ifdef CONFIG_X11 | 3845 #ifdef CONFIG_X11 |
3771 if (stop_xscreensaver) { | 3846 if (stop_xscreensaver) { |
3772 current_module = "stop_xscreensaver"; | 3847 current_module = "stop_xscreensaver"; |
3773 xscreensaver_heartbeat(); | 3848 xscreensaver_heartbeat(); |
3774 } | 3849 } |
3775 #endif | 3850 #endif |
3776 if (heartbeat_cmd) { | 3851 if (heartbeat_cmd) { |
3777 static unsigned last_heartbeat; | 3852 static unsigned last_heartbeat; |
3778 unsigned now = GetTimerMS(); | 3853 unsigned now = GetTimerMS(); |
3779 if (now - last_heartbeat > 30000) { | 3854 if (now - last_heartbeat > 30000) { |
3780 last_heartbeat = now; | 3855 last_heartbeat = now; |
3781 system(heartbeat_cmd); | 3856 system(heartbeat_cmd); |
3782 } | 3857 } |
3783 } | 3858 } |
3784 | 3859 |
3785 if (!skip_timing) | 3860 if (!skip_timing) |
3786 frame_time_remaining = sleep_until_update(&mpctx->time_frame, &aq_sleep_time); | 3861 frame_time_remaining = sleep_until_update(&mpctx->time_frame, &aq_sleep_time); |
3787 | 3862 |
3788 //====================== FLIP PAGE (VIDEO BLT): ========================= | 3863 //====================== FLIP PAGE (VIDEO BLT): ========================= |
3789 | 3864 |
3790 if (!edl_needs_reset) { | 3865 if (!edl_needs_reset) { |
3791 current_module="flip_page"; | 3866 current_module = "flip_page"; |
3792 if (!frame_time_remaining && blit_frame) { | 3867 if (!frame_time_remaining && blit_frame) { |
3793 unsigned int t2=GetTimer(); | 3868 unsigned int t2 = GetTimer(); |
3794 | 3869 |
3795 if(vo_config_count) mpctx->video_out->flip_page(); | 3870 if (vo_config_count) |
3796 mpctx->num_buffered_frames--; | 3871 mpctx->video_out->flip_page(); |
3797 | 3872 mpctx->num_buffered_frames--; |
3798 vout_time_usage += (GetTimer() - t2) * 0.000001; | 3873 |
3799 } | 3874 vout_time_usage += (GetTimer() - t2) * 0.000001; |
3800 } | 3875 } |
3876 } | |
3801 //====================== A-V TIMESTAMP CORRECTION: ========================= | 3877 //====================== A-V TIMESTAMP CORRECTION: ========================= |
3802 | 3878 |
3803 adjust_sync_and_print_status(frame_time_remaining, mpctx->time_frame); | 3879 adjust_sync_and_print_status(frame_time_remaining, mpctx->time_frame); |
3804 | 3880 |
3805 //============================ Auto QUALITY ============================ | 3881 //============================ Auto QUALITY ============================ |
3806 | 3882 |
3807 /*Output quality adjustments:*/ | 3883 /*Output quality adjustments:*/ |
3808 if(auto_quality>0){ | 3884 if (auto_quality > 0) { |
3809 current_module="autoq"; | 3885 current_module = "autoq"; |
3810 // float total=0.000001f * (GetTimer()-aq_total_time); | 3886 // float total=0.000001f * (GetTimer()-aq_total_time); |
3811 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total) | 3887 // if(output_quality<auto_quality && aq_sleep_time>0.05f*total) |
3812 if(output_quality<auto_quality && aq_sleep_time>0) | 3888 if (output_quality < auto_quality && aq_sleep_time > 0) |
3813 ++output_quality; | 3889 ++output_quality; |
3814 else | 3890 else |
3815 // if(output_quality>0 && aq_sleep_time<-0.05f*total) | 3891 // if(output_quality>0 && aq_sleep_time<-0.05f*total) |
3816 if(output_quality>1 && aq_sleep_time<0) | 3892 if (output_quality > 1 && aq_sleep_time < 0) |
3817 --output_quality; | 3893 --output_quality; |
3818 else | 3894 else if (output_quality > 0 && aq_sleep_time < -0.050f) // 50ms |
3819 if(output_quality>0 && aq_sleep_time<-0.050f) // 50ms | 3895 output_quality = 0; |
3820 output_quality=0; | |
3821 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality); | 3896 // printf("total: %8.6f sleep: %8.6f q: %d\n",(0.000001f*aq_total_time),aq_sleep_time,output_quality); |
3822 set_video_quality(mpctx->sh_video,output_quality); | 3897 set_video_quality(mpctx->sh_video, output_quality); |
3823 } | 3898 } |
3824 | 3899 |
3825 if (play_n_frames >= 0 && !frame_time_remaining && blit_frame) { | 3900 if (play_n_frames >= 0 && !frame_time_remaining && blit_frame) { |
3826 --play_n_frames; | 3901 --play_n_frames; |
3827 if (play_n_frames <= 0) mpctx->eof = PT_NEXT_ENTRY; | 3902 if (play_n_frames <= 0) |
3828 } | 3903 mpctx->eof = PT_NEXT_ENTRY; |
3829 | 3904 } |
3830 if (!frame_time_remaining && | 3905 |
3831 ((end_at.type == END_AT_TIME && mpctx->sh_video->pts >= end_at.pos) || | 3906 if (!frame_time_remaining && |
3832 (end_at.type == END_AT_SIZE && stream_tell(mpctx->stream) >= end_at.pos))) | 3907 ((end_at.type == END_AT_TIME && mpctx->sh_video->pts >= end_at.pos) || |
3833 mpctx->eof = PT_NEXT_ENTRY; | 3908 (end_at.type == END_AT_SIZE && stream_tell(mpctx->stream) >= end_at.pos))) |
3834 | 3909 mpctx->eof = PT_NEXT_ENTRY; |
3835 } // end if(mpctx->sh_video) | 3910 } // end if(mpctx->sh_video) |
3836 | 3911 |
3837 #ifdef CONFIG_DVDNAV | 3912 #ifdef CONFIG_DVDNAV |
3838 if (mpctx->stream->type == STREAMTYPE_DVDNAV) { | 3913 if (mpctx->stream->type == STREAMTYPE_DVDNAV) { |
3839 nav_highlight_t hl; | 3914 nav_highlight_t hl; |
3840 mp_dvdnav_get_highlight (mpctx->stream, &hl); | 3915 mp_dvdnav_get_highlight(mpctx->stream, &hl); |
3841 if (!vo_spudec || !spudec_apply_palette_crop(vo_spudec, hl.palette, hl.sx, hl.sy, hl.ex, hl.ey)) { | 3916 if (!vo_spudec || !spudec_apply_palette_crop(vo_spudec, hl.palette, hl.sx, hl.sy, hl.ex, hl.ey)) { |
3842 osd_set_nav_box (hl.sx, hl.sy, hl.ex, hl.ey); | 3917 osd_set_nav_box(hl.sx, hl.sy, hl.ex, hl.ey); |
3843 vo_osd_changed (OSDTYPE_DVDNAV); | 3918 vo_osd_changed(OSDTYPE_DVDNAV); |
3844 } else { | 3919 } else { |
3845 osd_set_nav_box(0, 0, 0, 0); | 3920 osd_set_nav_box(0, 0, 0, 0); |
3846 vo_osd_changed(OSDTYPE_DVDNAV); | 3921 vo_osd_changed(OSDTYPE_DVDNAV); |
3847 vo_osd_changed(OSDTYPE_SPU); | 3922 vo_osd_changed(OSDTYPE_SPU); |
3848 } | 3923 } |
3849 | 3924 |
3850 if (mp_dvdnav_stream_has_changed(mpctx->stream)) { | 3925 if (mp_dvdnav_stream_has_changed(mpctx->stream)) { |
3851 double ar = -1.0; | 3926 double ar = -1.0; |
3852 if (mpctx->sh_video && | 3927 if (mpctx->sh_video && |
3853 stream_control (mpctx->demuxer->stream, | 3928 stream_control(mpctx->demuxer->stream, |
3854 STREAM_CTRL_GET_ASPECT_RATIO, &ar) | 3929 STREAM_CTRL_GET_ASPECT_RATIO, &ar) |
3855 != STREAM_UNSUPPORTED) | 3930 != STREAM_UNSUPPORTED) |
3856 mpctx->sh_video->stream_aspect = ar; | 3931 mpctx->sh_video->stream_aspect = ar; |
3857 } | 3932 } |
3858 } | 3933 } |
3859 #endif | 3934 #endif |
3860 | 3935 |
3861 //============================ Handle PAUSE =============================== | 3936 //============================ Handle PAUSE =============================== |
3862 | 3937 |
3863 current_module="pause"; | 3938 current_module = "pause"; |
3864 | 3939 |
3865 if (mpctx->osd_function == OSD_PAUSE) { | 3940 if (mpctx->osd_function == OSD_PAUSE) { |
3866 mpctx->was_paused = 1; | 3941 mpctx->was_paused = 1; |
3867 pause_loop(); | 3942 pause_loop(); |
3868 } | 3943 } |
3869 | 3944 |
3870 // handle -sstep | 3945 // handle -sstep |
3871 if(step_sec>0) { | 3946 if (step_sec > 0) { |
3872 mpctx->osd_function=OSD_FFW; | 3947 mpctx->osd_function = OSD_FFW; |
3873 rel_seek_secs+=step_sec; | 3948 rel_seek_secs += step_sec; |
3874 } | 3949 } |
3875 | 3950 |
3876 edl_update(mpctx); | 3951 edl_update(mpctx); |
3877 | 3952 |
3878 //================= Keyboard events, SEEKing ==================== | 3953 //================= Keyboard events, SEEKing ==================== |
3879 | 3954 |
3880 current_module="key_events"; | 3955 current_module = "key_events"; |
3881 | 3956 |
3882 { | 3957 { |
3883 mp_cmd_t* cmd; | 3958 mp_cmd_t *cmd; |
3884 int brk_cmd = 0; | 3959 int brk_cmd = 0; |
3885 while( !brk_cmd && (cmd = mp_input_get_cmd(0,0,0)) != NULL) { | 3960 while (!brk_cmd && (cmd = mp_input_get_cmd(0, 0, 0)) != NULL) { |
3886 brk_cmd = run_command(mpctx, cmd); | 3961 brk_cmd = run_command(mpctx, cmd); |
3887 if (cmd->id == MP_CMD_EDL_LOADFILE) { | 3962 if (cmd->id == MP_CMD_EDL_LOADFILE) { |
3888 free(edl_filename); | 3963 free(edl_filename); |
3889 edl_filename = strdup(cmd->args[0].v.s); | 3964 edl_filename = strdup(cmd->args[0].v.s); |
3890 if (edl_filename) | 3965 if (edl_filename) |
3891 edl_loadfile(); | 3966 edl_loadfile(); |
3892 else | 3967 else |
3893 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlOutOfMemFile, | 3968 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlOutOfMemFile, |
3894 cmd->args[0].v.s); | 3969 cmd->args[0].v.s); |
3895 } | 3970 } |
3896 mp_cmd_free(cmd); | 3971 mp_cmd_free(cmd); |
3897 if (brk_cmd == 2) | 3972 if (brk_cmd == 2) |
3898 goto goto_enable_cache; | 3973 goto goto_enable_cache; |
3899 } | 3974 } |
3900 } | 3975 } |
3901 mpctx->was_paused = 0; | 3976 mpctx->was_paused = 0; |
3902 | 3977 |
3903 /* Looping. */ | 3978 /* Looping. */ |
3904 if(mpctx->eof==1 && mpctx->loop_times>=0) { | 3979 if (mpctx->eof == 1 && mpctx->loop_times >= 0) { |
3905 mp_msg(MSGT_CPLAYER,MSGL_V,"loop_times = %d, eof = %d\n", mpctx->loop_times,mpctx->eof); | 3980 mp_msg(MSGT_CPLAYER, MSGL_V, "loop_times = %d, eof = %d\n", mpctx->loop_times, mpctx->eof); |
3906 | 3981 |
3907 if(mpctx->loop_times>1) mpctx->loop_times--; else | 3982 if (mpctx->loop_times > 1) |
3908 if(mpctx->loop_times==1) mpctx->loop_times=-1; | 3983 mpctx->loop_times--; |
3909 play_n_frames=play_n_frames_mf; | 3984 else if (mpctx->loop_times == 1) |
3910 mpctx->eof=0; | 3985 mpctx->loop_times = -1; |
3911 abs_seek_pos=SEEK_ABSOLUTE; rel_seek_secs=seek_to_sec; | 3986 play_n_frames = play_n_frames_mf; |
3912 loop_seek = 1; | 3987 mpctx->eof = 0; |
3913 } | 3988 abs_seek_pos = SEEK_ABSOLUTE; |
3914 | 3989 rel_seek_secs = seek_to_sec; |
3915 if(rel_seek_secs || abs_seek_pos){ | 3990 loop_seek = 1; |
3916 if (seek(mpctx, rel_seek_secs, abs_seek_pos) >= 0) { | 3991 } |
3917 // Set OSD: | 3992 |
3918 if(!loop_seek){ | 3993 if (rel_seek_secs || abs_seek_pos) { |
3919 if( !edl_decision ) | 3994 if (seek(mpctx, rel_seek_secs, abs_seek_pos) >= 0) { |
3920 set_osd_bar(0,"Position",0,100,demuxer_get_percent_pos(mpctx->demuxer)); | 3995 // Set OSD: |
3921 } | 3996 if (!loop_seek) { |
3922 } | 3997 if (!edl_decision) |
3923 | 3998 set_osd_bar(0, "Position", 0, 100, demuxer_get_percent_pos(mpctx->demuxer)); |
3924 rel_seek_secs=0; | 3999 } |
3925 abs_seek_pos=0; | 4000 } |
3926 loop_seek=0; | 4001 |
3927 edl_decision = 0; | 4002 rel_seek_secs = 0; |
3928 } | 4003 abs_seek_pos = 0; |
4004 loop_seek = 0; | |
4005 edl_decision = 0; | |
4006 } | |
3929 | 4007 |
3930 #ifdef CONFIG_GUI | 4008 #ifdef CONFIG_GUI |
3931 if(use_gui){ | 4009 if (use_gui) { |
3932 guiEventHandling(); | 4010 guiEventHandling(); |
3933 if(mpctx->demuxer->file_format==DEMUXER_TYPE_AVI && mpctx->sh_video && mpctx->sh_video->video.dwLength>2){ | 4011 if (mpctx->demuxer->file_format == DEMUXER_TYPE_AVI && mpctx->sh_video && mpctx->sh_video->video.dwLength > 2) { |
3934 // get pos from frame number / total frames | 4012 // get pos from frame number / total frames |
3935 guiIntfStruct.Position=(float)mpctx->d_video->pack_no*100.0f/mpctx->sh_video->video.dwLength; | 4013 guiIntfStruct.Position = (float)mpctx->d_video->pack_no * 100.0f / mpctx->sh_video->video.dwLength; |
3936 } else { | 4014 } else { |
3937 guiIntfStruct.Position=demuxer_get_percent_pos(mpctx->demuxer); | 4015 guiIntfStruct.Position = demuxer_get_percent_pos(mpctx->demuxer); |
3938 } | 4016 } |
3939 if ( mpctx->sh_video ) guiIntfStruct.TimeSec=mpctx->sh_video->pts; | 4017 if (mpctx->sh_video) |
3940 else if ( mpctx->sh_audio ) guiIntfStruct.TimeSec=playing_audio_pts(mpctx->sh_audio, mpctx->d_audio, mpctx->audio_out); | 4018 guiIntfStruct.TimeSec = mpctx->sh_video->pts; |
3941 guiIntfStruct.LengthInSec=demuxer_get_time_length(mpctx->demuxer); | 4019 else if (mpctx->sh_audio) |
3942 guiGetEvent( guiReDraw,NULL ); | 4020 guiIntfStruct.TimeSec = playing_audio_pts(mpctx->sh_audio, mpctx->d_audio, mpctx->audio_out); |
3943 guiGetEvent( guiSetVolume,NULL ); | 4021 guiIntfStruct.LengthInSec = demuxer_get_time_length(mpctx->demuxer); |
3944 if(guiIntfStruct.Playing==0) break; // STOP | 4022 guiGetEvent(guiReDraw, NULL); |
3945 if(guiIntfStruct.Playing==2) mpctx->osd_function=OSD_PAUSE; | 4023 guiGetEvent(guiSetVolume, NULL); |
3946 if ( guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay ) goto goto_next_file; | 4024 if (guiIntfStruct.Playing == 0) |
4025 break; // STOP | |
4026 if (guiIntfStruct.Playing == 2) | |
4027 mpctx->osd_function = OSD_PAUSE; | |
4028 if (guiIntfStruct.DiskChanged || guiIntfStruct.NewPlay) | |
4029 goto goto_next_file; | |
3947 #ifdef CONFIG_DVDREAD | 4030 #ifdef CONFIG_DVDREAD |
3948 if ( mpctx->stream->type == STREAMTYPE_DVD ) | 4031 if (mpctx->stream->type == STREAMTYPE_DVD) { |
3949 { | 4032 dvd_priv_t *dvdp = mpctx->stream->priv; |
3950 dvd_priv_t * dvdp = mpctx->stream->priv; | 4033 guiIntfStruct.DVD.current_chapter = dvd_chapter_from_cell(dvdp, guiIntfStruct.DVD.current_title - 1, dvdp->cur_cell) + 1; |
3951 guiIntfStruct.DVD.current_chapter=dvd_chapter_from_cell(dvdp,guiIntfStruct.DVD.current_title-1, dvdp->cur_cell)+1; | 4034 } |
3952 } | 4035 #endif |
3953 #endif | 4036 } |
3954 } | |
3955 #endif /* CONFIG_GUI */ | 4037 #endif /* CONFIG_GUI */ |
3956 | 4038 } // while(!mpctx->eof) |
3957 } // while(!mpctx->eof) | 4039 |
3958 | 4040 mp_msg(MSGT_GLOBAL, MSGL_V, "EOF code: %d \n", mpctx->eof); |
3959 mp_msg(MSGT_GLOBAL,MSGL_V,"EOF code: %d \n",mpctx->eof); | |
3960 | 4041 |
3961 #ifdef CONFIG_DVBIN | 4042 #ifdef CONFIG_DVBIN |
3962 if(mpctx->dvbin_reopen) | 4043 if (mpctx->dvbin_reopen) { |
3963 { | 4044 mpctx->eof = 0; |
3964 mpctx->eof = 0; | 4045 uninit_player(INITIALIZED_ALL - (INITIALIZED_GUI | INITIALIZED_STREAM | INITIALIZED_INPUT | INITIALIZED_GETCH2 | (fixed_vo ? INITIALIZED_VO : 0))); |
3965 uninit_player(INITIALIZED_ALL-(INITIALIZED_GUI|INITIALIZED_STREAM|INITIALIZED_INPUT|INITIALIZED_GETCH2|(fixed_vo?INITIALIZED_VO:0))); | 4046 cache_uninit(mpctx->stream); |
3966 cache_uninit(mpctx->stream); | 4047 mpctx->dvbin_reopen = 0; |
3967 mpctx->dvbin_reopen = 0; | 4048 goto goto_enable_cache; |
3968 goto goto_enable_cache; | 4049 } |
3969 } | 4050 #endif |
3970 #endif | 4051 } |
3971 } | |
3972 | 4052 |
3973 goto_next_file: // don't jump here after ao/vo/getch initialization! | 4053 goto_next_file: // don't jump here after ao/vo/getch initialization! |
3974 | 4054 |
3975 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n"); | 4055 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n"); |
3976 | 4056 |
3977 if(benchmark){ | 4057 if (benchmark) { |
3978 double tot=video_time_usage+vout_time_usage+audio_time_usage; | 4058 double tot = video_time_usage + vout_time_usage + audio_time_usage; |
3979 double total_time_usage; | 4059 double total_time_usage; |
3980 total_time_usage_start=GetTimer()-total_time_usage_start; | 4060 total_time_usage_start = GetTimer() - total_time_usage_start; |
3981 total_time_usage = (float)total_time_usage_start*0.000001; | 4061 total_time_usage = (float)total_time_usage_start * 0.000001; |
3982 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n", | 4062 mp_msg(MSGT_CPLAYER, MSGL_INFO, "\nBENCHMARKs: VC:%8.3fs VO:%8.3fs A:%8.3fs Sys:%8.3fs = %8.3fs\n", |
3983 video_time_usage,vout_time_usage,audio_time_usage, | 4063 video_time_usage, vout_time_usage, audio_time_usage, |
3984 total_time_usage-tot,total_time_usage); | 4064 total_time_usage - tot, total_time_usage); |
3985 if(total_time_usage>0.0) | 4065 if (total_time_usage > 0.0) |
3986 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n", | 4066 mp_msg(MSGT_CPLAYER, MSGL_INFO, "BENCHMARK%%: VC:%8.4f%% VO:%8.4f%% A:%8.4f%% Sys:%8.4f%% = %8.4f%%\n", |
3987 100.0*video_time_usage/total_time_usage, | 4067 100.0 * video_time_usage / total_time_usage, |
3988 100.0*vout_time_usage/total_time_usage, | 4068 100.0 * vout_time_usage / total_time_usage, |
3989 100.0*audio_time_usage/total_time_usage, | 4069 100.0 * audio_time_usage / total_time_usage, |
3990 100.0*(total_time_usage-tot)/total_time_usage, | 4070 100.0 * (total_time_usage - tot) / total_time_usage, |
3991 100.0); | 4071 100.0); |
3992 if(total_frame_cnt && frame_dropping) | 4072 if (total_frame_cnt && frame_dropping) |
3993 mp_msg(MSGT_CPLAYER,MSGL_INFO,"BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n", | 4073 mp_msg(MSGT_CPLAYER, MSGL_INFO, "BENCHMARKn: disp: %d (%3.2f fps) drop: %d (%d%%) total: %d (%3.2f fps)\n", |
3994 total_frame_cnt-drop_frame_cnt, | 4074 total_frame_cnt - drop_frame_cnt, |
3995 (total_time_usage>0.5)?((total_frame_cnt-drop_frame_cnt)/total_time_usage):0, | 4075 (total_time_usage > 0.5) ? ((total_frame_cnt - drop_frame_cnt) / total_time_usage) : 0, |
3996 drop_frame_cnt, | 4076 drop_frame_cnt, |
3997 100*drop_frame_cnt/total_frame_cnt, | 4077 100 * drop_frame_cnt / total_frame_cnt, |
3998 total_frame_cnt, | 4078 total_frame_cnt, |
3999 (total_time_usage>0.5)?(total_frame_cnt/total_time_usage):0); | 4079 (total_time_usage > 0.5) ? (total_frame_cnt / total_time_usage) : 0); |
4000 } | 4080 } |
4001 | 4081 |
4002 // time to uninit all, except global stuff: | 4082 // time to uninit all, except global stuff: |
4003 uninit_player(INITIALIZED_ALL-(INITIALIZED_GUI+INITIALIZED_INPUT+(fixed_vo?INITIALIZED_VO:0))); | 4083 uninit_player(INITIALIZED_ALL - (INITIALIZED_GUI + INITIALIZED_INPUT + (fixed_vo ? INITIALIZED_VO : 0))); |
4004 | 4084 |
4005 if(mpctx->eof == PT_NEXT_ENTRY || mpctx->eof == PT_PREV_ENTRY) { | 4085 if (mpctx->eof == PT_NEXT_ENTRY || mpctx->eof == PT_PREV_ENTRY) { |
4006 mpctx->eof = mpctx->eof == PT_NEXT_ENTRY ? 1 : -1; | 4086 mpctx->eof = mpctx->eof == PT_NEXT_ENTRY ? 1 : -1; |
4007 if(play_tree_iter_step(mpctx->playtree_iter,mpctx->play_tree_step,0) == PLAY_TREE_ITER_ENTRY) { | 4087 if (play_tree_iter_step(mpctx->playtree_iter, mpctx->play_tree_step, 0) == PLAY_TREE_ITER_ENTRY) { |
4008 mpctx->eof = 1; | |
4009 } else { | |
4010 play_tree_iter_free(mpctx->playtree_iter); | |
4011 mpctx->playtree_iter = NULL; | |
4012 } | |
4013 mpctx->play_tree_step = 1; | |
4014 } else if(mpctx->eof == PT_UP_NEXT || mpctx->eof == PT_UP_PREV) { | |
4015 mpctx->eof = mpctx->eof == PT_UP_NEXT ? 1 : -1; | |
4016 if(mpctx->playtree_iter) { | |
4017 if(play_tree_iter_up_step(mpctx->playtree_iter,mpctx->eof,0) == PLAY_TREE_ITER_ENTRY) { | |
4018 mpctx->eof = 1; | 4088 mpctx->eof = 1; |
4019 } else { | 4089 } else { |
4020 play_tree_iter_free(mpctx->playtree_iter); | 4090 play_tree_iter_free(mpctx->playtree_iter); |
4021 mpctx->playtree_iter = NULL; | 4091 mpctx->playtree_iter = NULL; |
4022 } | 4092 } |
4023 } | 4093 mpctx->play_tree_step = 1; |
4024 } else if (mpctx->eof == PT_STOP) { | 4094 } else if (mpctx->eof == PT_UP_NEXT || mpctx->eof == PT_UP_PREV) { |
4025 play_tree_iter_free(mpctx->playtree_iter); | 4095 mpctx->eof = mpctx->eof == PT_UP_NEXT ? 1 : -1; |
4026 mpctx->playtree_iter = NULL; | 4096 if (mpctx->playtree_iter) { |
4027 } else { // NEXT PREV SRC | 4097 if (play_tree_iter_up_step(mpctx->playtree_iter, mpctx->eof, 0) == PLAY_TREE_ITER_ENTRY) { |
4028 mpctx->eof = mpctx->eof == PT_PREV_SRC ? -1 : 1; | 4098 mpctx->eof = 1; |
4029 } | 4099 } else { |
4030 | 4100 play_tree_iter_free(mpctx->playtree_iter); |
4031 if(mpctx->eof == 0) mpctx->eof = 1; | 4101 mpctx->playtree_iter = NULL; |
4032 | 4102 } |
4033 while(mpctx->playtree_iter != NULL) { | 4103 } |
4034 filename = play_tree_iter_get_file(mpctx->playtree_iter,mpctx->eof); | 4104 } else if (mpctx->eof == PT_STOP) { |
4035 if(filename == NULL) { | 4105 play_tree_iter_free(mpctx->playtree_iter); |
4036 if(play_tree_iter_step(mpctx->playtree_iter,mpctx->eof,0) != PLAY_TREE_ITER_ENTRY) { | 4106 mpctx->playtree_iter = NULL; |
4037 play_tree_iter_free(mpctx->playtree_iter); | 4107 } else { // NEXT PREV SRC |
4038 mpctx->playtree_iter = NULL; | 4108 mpctx->eof = mpctx->eof == PT_PREV_SRC ? -1 : 1; |
4039 } | 4109 } |
4040 } else | 4110 |
4041 break; | 4111 if (mpctx->eof == 0) |
4042 } | 4112 mpctx->eof = 1; |
4113 | |
4114 while (mpctx->playtree_iter != NULL) { | |
4115 filename = play_tree_iter_get_file(mpctx->playtree_iter, mpctx->eof); | |
4116 if (filename == NULL) { | |
4117 if (play_tree_iter_step(mpctx->playtree_iter, mpctx->eof, 0) != PLAY_TREE_ITER_ENTRY) { | |
4118 play_tree_iter_free(mpctx->playtree_iter); | |
4119 mpctx->playtree_iter = NULL; | |
4120 } | |
4121 } else | |
4122 break; | |
4123 } | |
4043 | 4124 |
4044 #ifdef CONFIG_GUI | 4125 #ifdef CONFIG_GUI |
4045 if(use_gui && !mpctx->playtree_iter) { | 4126 if (use_gui && !mpctx->playtree_iter) { |
4046 #ifdef CONFIG_DVDREAD | 4127 #ifdef CONFIG_DVDREAD |
4047 if(!guiIntfStruct.DiskChanged) | 4128 if (!guiIntfStruct.DiskChanged) |
4048 #endif | 4129 #endif |
4049 mplEnd(); | 4130 mplEnd(); |
4050 } | 4131 } |
4051 #endif | 4132 #endif |
4052 | 4133 |
4053 if(use_gui || mpctx->playtree_iter != NULL || player_idle_mode){ | 4134 if (use_gui || mpctx->playtree_iter != NULL || player_idle_mode) { |
4054 if(!mpctx->playtree_iter) filename = NULL; | 4135 if (!mpctx->playtree_iter) |
4055 mpctx->eof = 0; | 4136 filename = NULL; |
4056 goto play_next_file; | 4137 mpctx->eof = 0; |
4057 } | 4138 goto play_next_file; |
4058 | 4139 } |
4059 | 4140 |
4060 exit_player_with_rc(EXIT_EOF, 0); | 4141 exit_player_with_rc(EXIT_EOF, 0); |
4061 | 4142 |
4062 return 1; | 4143 return 1; |
4063 } | 4144 } |
4145 | |
4064 #endif /* DISABLE_MAIN */ | 4146 #endif /* DISABLE_MAIN */ |