cosmetics: reformatting
[mplayer/greg.git] / command.c
blob68b30b9503a3320968fe9ebb4282bc951e001c10
1 #include <stdlib.h>
2 #include <inttypes.h>
3 #include <unistd.h>
4 #include <string.h>
6 #include "config.h"
7 #include "input/input.h"
8 #include "stream/stream.h"
9 #include "libmpdemux/demuxer.h"
10 #include "libmpdemux/stheader.h"
11 #include "codec-cfg.h"
12 #include "mplayer.h"
13 #include "libvo/sub.h"
14 #include "m_option.h"
15 #include "m_property.h"
16 #include "help_mp.h"
17 #include "metadata.h"
18 #include "libmpcodecs/mp_image.h"
19 #include "libmpcodecs/vf.h"
20 #include "libmpcodecs/vd.h"
21 #include "libvo/video_out.h"
22 #include "libvo/font_load.h"
23 #include "playtree.h"
24 #include "libao2/audio_out.h"
25 #include "mpcommon.h"
26 #include "mixer.h"
27 #include "libmpdemux/matroska.h"
28 #include "libmpcodecs/dec_video.h"
29 #include "vobsub.h"
30 #include "spudec.h"
31 #include "get_path.h"
32 #ifdef USE_TV
33 #include "stream/tv.h"
34 #endif
35 #ifdef USE_RADIO
36 #include "stream/stream_radio.h"
37 #endif
38 #ifdef HAVE_PVR
39 #include "stream/pvr.h"
40 #endif
41 #ifdef HAS_DVBIN_SUPPORT
42 #include "stream/dvbin.h"
43 #endif
44 #ifdef USE_DVDREAD
45 #include "stream/stream_dvd.h"
46 #endif
47 #ifdef USE_DVDNAV
48 #include "stream/stream_dvdnav.h"
49 #endif
50 #ifdef USE_ASS
51 #include "libass/ass.h"
52 #include "libass/ass_mp.h"
53 #endif
54 #ifdef HAVE_NEW_GUI
55 #include "gui/interface.h"
56 #endif
58 #include "mp_core.h"
59 #include "mp_fifo.h"
61 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
63 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy)
65 //remove the borders, if any, and rescale to the range [0,1],[0,1]
66 if (vo_fs) { //we are in full-screen mode
67 if (vo_screenwidth > vo_dwidth) //there are borders along the x axis
68 ix -= (vo_screenwidth - vo_dwidth) / 2;
69 if (vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
70 iy -= (vo_screenheight - vo_dheight) / 2;
72 if (ix < 0 || ix > vo_dwidth) {
73 *dx = *dy = -1.0;
74 return;
75 } //we are on one of the borders
76 if (iy < 0 || iy > vo_dheight) {
77 *dx = *dy = -1.0;
78 return;
79 } //we are on one of the borders
82 *dx = (double) ix / (double) vo_dwidth;
83 *dy = (double) iy / (double) vo_dheight;
85 mp_msg(MSGT_CPLAYER, MSGL_V,
86 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
87 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth,
88 vo_dheight, vo_fs);
91 static int sub_source_by_pos(MPContext * mpctx, int pos)
93 int source = -1;
94 int top = -1;
95 int i;
96 for (i = 0; i < SUB_SOURCES; i++) {
97 int j = mpctx->global_sub_indices[i];
98 if ((j >= 0) && (j > top) && (pos >= j)) {
99 source = i;
100 top = j;
103 return source;
106 static int sub_source(MPContext * mpctx)
108 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
112 * \brief Log the currently displayed subtitle to a file
114 * Logs the current or last displayed subtitle together with filename
115 * and time information to ~/.mplayer/subtitle_log
117 * Intended purpose is to allow convenient marking of bogus subtitles
118 * which need to be fixed while watching the movie.
121 static void log_sub(void)
123 char *fname;
124 FILE *f;
125 int i;
127 if (subdata == NULL || vo_sub_last == NULL)
128 return;
129 fname = get_path("subtitle_log");
130 f = fopen(fname, "a");
131 if (!f)
132 return;
133 fprintf(f, "----------------------------------------------------------\n");
134 if (subdata->sub_uses_time) {
135 fprintf(f,
136 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
137 filename, vo_sub_last->start / 360000,
138 (vo_sub_last->start / 6000) % 60,
139 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
140 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
141 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
142 } else {
143 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start,
144 vo_sub_last->end);
146 for (i = 0; i < vo_sub_last->lines; i++) {
147 fprintf(f, "%s\n", vo_sub_last->text[i]);
149 fclose(f);
153 /// \defgroup Properties
154 ///@{
156 /// \defgroup GeneralProperties General properties
157 /// \ingroup Properties
158 ///@{
160 /// OSD level (RW)
161 static int mp_property_osdlevel(m_option_t * prop, int action, void *arg,
162 MPContext * mpctx)
164 return m_property_choice(prop, action, arg, &osd_level);
167 /// Loop (RW)
168 static int mp_property_loop(m_option_t * prop, int action, void *arg,
169 MPContext * mpctx)
171 switch (action) {
172 case M_PROPERTY_PRINT:
173 if (!arg) return M_PROPERTY_ERROR;
174 if (mpctx->loop_times < 0)
175 *(char**)arg = strdup("off");
176 else if (mpctx->loop_times == 0)
177 *(char**)arg = strdup("inf");
178 else
179 break;
180 return M_PROPERTY_OK;
182 return m_property_int_range(prop, action, arg, &mpctx->loop_times);
185 /// Playback speed (RW)
186 static int mp_property_playback_speed(m_option_t * prop, int action,
187 void *arg, MPContext * mpctx)
189 switch (action) {
190 case M_PROPERTY_SET:
191 if (!arg)
192 return M_PROPERTY_ERROR;
193 M_PROPERTY_CLAMP(prop, *(float *) arg);
194 playback_speed = *(float *) arg;
195 build_afilter_chain(mpctx->sh_audio, &ao_data);
196 return M_PROPERTY_OK;
197 case M_PROPERTY_STEP_UP:
198 case M_PROPERTY_STEP_DOWN:
199 playback_speed += (arg ? *(float *) arg : 0.1) *
200 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
201 M_PROPERTY_CLAMP(prop, playback_speed);
202 build_afilter_chain(mpctx->sh_audio, &ao_data);
203 return M_PROPERTY_OK;
205 return m_property_float_range(prop, action, arg, &playback_speed);
208 /// filename with path (RO)
209 static int mp_property_path(m_option_t * prop, int action, void *arg,
210 MPContext * mpctx)
212 return m_property_string_ro(prop, action, arg, filename);
215 /// filename without path (RO)
216 static int mp_property_filename(m_option_t * prop, int action, void *arg,
217 MPContext * mpctx)
219 char *f;
220 if (!filename)
221 return M_PROPERTY_UNAVAILABLE;
222 if (((f = strrchr(filename, '/')) || (f = strrchr(filename, '\\'))) && f[1])
223 f++;
224 else
225 f = filename;
226 return m_property_string_ro(prop, action, arg, f);
229 /// Demuxer name (RO)
230 static int mp_property_demuxer(m_option_t * prop, int action, void *arg,
231 MPContext * mpctx)
233 if (!mpctx->demuxer)
234 return M_PROPERTY_UNAVAILABLE;
235 return m_property_string_ro(prop, action, arg,
236 (char *) mpctx->demuxer->desc->name);
239 /// Position in the stream (RW)
240 static int mp_property_stream_pos(m_option_t * prop, int action, void *arg,
241 MPContext * mpctx)
243 if (!mpctx->demuxer || !mpctx->demuxer->stream)
244 return M_PROPERTY_UNAVAILABLE;
245 if (!arg)
246 return M_PROPERTY_ERROR;
247 switch (action) {
248 case M_PROPERTY_GET:
249 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
250 return M_PROPERTY_OK;
251 case M_PROPERTY_SET:
252 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
253 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
254 return M_PROPERTY_OK;
256 return M_PROPERTY_NOT_IMPLEMENTED;
259 /// Stream start offset (RO)
260 static int mp_property_stream_start(m_option_t * prop, int action,
261 void *arg, MPContext * mpctx)
263 if (!mpctx->demuxer || !mpctx->demuxer->stream)
264 return M_PROPERTY_UNAVAILABLE;
265 switch (action) {
266 case M_PROPERTY_GET:
267 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
268 return M_PROPERTY_OK;
270 return M_PROPERTY_NOT_IMPLEMENTED;
273 /// Stream end offset (RO)
274 static int mp_property_stream_end(m_option_t * prop, int action, void *arg,
275 MPContext * mpctx)
277 if (!mpctx->demuxer || !mpctx->demuxer->stream)
278 return M_PROPERTY_UNAVAILABLE;
279 switch (action) {
280 case M_PROPERTY_GET:
281 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
282 return M_PROPERTY_OK;
284 return M_PROPERTY_NOT_IMPLEMENTED;
287 /// Stream length (RO)
288 static int mp_property_stream_length(m_option_t * prop, int action,
289 void *arg, MPContext * mpctx)
291 if (!mpctx->demuxer || !mpctx->demuxer->stream)
292 return M_PROPERTY_UNAVAILABLE;
293 switch (action) {
294 case M_PROPERTY_GET:
295 *(off_t *) arg =
296 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
297 return M_PROPERTY_OK;
299 return M_PROPERTY_NOT_IMPLEMENTED;
302 /// Media length in seconds (RO)
303 static int mp_property_length(m_option_t * prop, int action, void *arg,
304 MPContext * mpctx)
306 double len;
308 if (!mpctx->demuxer ||
309 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
310 return M_PROPERTY_UNAVAILABLE;
312 return m_property_time_ro(prop, action, arg, len);
315 /// Current position in percent (RW)
316 static int mp_property_percent_pos(m_option_t * prop, int action,
317 void *arg, MPContext * mpctx) {
318 int pos;
320 if (!mpctx->demuxer)
321 return M_PROPERTY_UNAVAILABLE;
323 switch(action) {
324 case M_PROPERTY_SET:
325 if(!arg) return M_PROPERTY_ERROR;
326 M_PROPERTY_CLAMP(prop, *(int*)arg);
327 pos = *(int*)arg;
328 break;
329 case M_PROPERTY_STEP_UP:
330 case M_PROPERTY_STEP_DOWN:
331 pos = demuxer_get_percent_pos(mpctx->demuxer);
332 pos += (arg ? *(int*)arg : 10) *
333 (action == M_PROPERTY_STEP_UP ? 1 : -1);
334 M_PROPERTY_CLAMP(prop, pos);
335 break;
336 default:
337 return m_property_int_ro(prop, action, arg,
338 demuxer_get_percent_pos(mpctx->demuxer));
341 abs_seek_pos = 3;
342 rel_seek_secs = pos / 100.0;
343 return M_PROPERTY_OK;
346 /// Current position in seconds (RW)
347 static int mp_property_time_pos(m_option_t * prop, int action,
348 void *arg, MPContext * mpctx) {
349 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
350 return M_PROPERTY_UNAVAILABLE;
352 switch(action) {
353 case M_PROPERTY_SET:
354 if(!arg) return M_PROPERTY_ERROR;
355 M_PROPERTY_CLAMP(prop, *(double*)arg);
356 abs_seek_pos = 1;
357 rel_seek_secs = *(double*)arg;
358 return M_PROPERTY_OK;
359 case M_PROPERTY_STEP_UP:
360 case M_PROPERTY_STEP_DOWN:
361 rel_seek_secs += (arg ? *(double*)arg : 10.0) *
362 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
363 return M_PROPERTY_OK;
365 return m_property_time_ro(prop, action, arg,
366 mpctx->sh_video ? mpctx->sh_video->pts :
367 playing_audio_pts(mpctx->sh_audio,
368 mpctx->d_audio,
369 mpctx->audio_out));
372 /// Current chapter (RW)
373 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
374 MPContext *mpctx)
376 int chapter;
377 float next_pts = 0;
378 int chapter_num;
379 int step_all;
380 char *chapter_name = NULL;
382 switch (action) {
383 case M_PROPERTY_GET:
384 if (!arg)
385 return M_PROPERTY_ERROR;
386 *(int *) arg = demuxer_get_current_chapter(mpctx->demuxer);
387 return M_PROPERTY_OK;
388 case M_PROPERTY_PRINT: {
389 if (!arg)
390 return M_PROPERTY_ERROR;
391 chapter = demuxer_get_current_chapter(mpctx->demuxer);
392 if (chapter < 0)
393 return M_PROPERTY_UNAVAILABLE;
394 chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter);
395 if (!chapter_name)
396 return M_PROPERTY_UNAVAILABLE;
397 *(char **) arg = chapter_name;
398 return M_PROPERTY_OK;
400 case M_PROPERTY_SET:
401 if (!arg)
402 return M_PROPERTY_ERROR;
403 M_PROPERTY_CLAMP(prop, *(int*)arg);
404 chapter = demuxer_get_current_chapter(mpctx->demuxer);
405 if (chapter < 0)
406 return M_PROPERTY_UNAVAILABLE;
407 step_all = *(int *)arg - (chapter + 1);
408 chapter += step_all;
409 break;
410 case M_PROPERTY_STEP_UP:
411 case M_PROPERTY_STEP_DOWN: {
412 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
413 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
414 chapter = demuxer_get_current_chapter(mpctx->demuxer);
415 if (chapter < 0)
416 return M_PROPERTY_UNAVAILABLE;
417 chapter += step_all;
418 if (chapter < 0)
419 chapter = 0;
420 break;
422 default:
423 return M_PROPERTY_NOT_IMPLEMENTED;
425 rel_seek_secs = 0;
426 abs_seek_pos = 0;
427 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
428 &next_pts, &chapter_num, &chapter_name);
429 if (chapter >= 0) {
430 if (next_pts > -1.0) {
431 abs_seek_pos = 1;
432 rel_seek_secs = next_pts;
434 if (chapter_name)
435 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
436 MSGTR_OSDChapter, chapter + 1, chapter_name);
438 else if (step_all > 0)
439 rel_seek_secs = 1000000000.;
440 else
441 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
442 MSGTR_OSDChapter, 0, MSGTR_Unknown);
443 if (chapter_name)
444 free(chapter_name);
445 return M_PROPERTY_OK;
448 /// Demuxer meta data
449 static int mp_property_metadata(m_option_t * prop, int action, void *arg,
450 MPContext * mpctx) {
451 m_property_action_t* ka;
452 char* meta;
453 static m_option_t key_type =
454 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
455 if (!mpctx->demuxer)
456 return M_PROPERTY_UNAVAILABLE;
458 switch(action) {
459 case M_PROPERTY_GET:
460 if(!arg) return M_PROPERTY_ERROR;
461 *(char***)arg = mpctx->demuxer->info;
462 return M_PROPERTY_OK;
463 case M_PROPERTY_KEY_ACTION:
464 if(!arg) return M_PROPERTY_ERROR;
465 ka = arg;
466 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
467 return M_PROPERTY_UNKNOWN;
468 switch(ka->action) {
469 case M_PROPERTY_GET:
470 if(!ka->arg) return M_PROPERTY_ERROR;
471 *(char**)ka->arg = meta;
472 return M_PROPERTY_OK;
473 case M_PROPERTY_GET_TYPE:
474 if(!ka->arg) return M_PROPERTY_ERROR;
475 *(m_option_t**)ka->arg = &key_type;
476 return M_PROPERTY_OK;
479 return M_PROPERTY_NOT_IMPLEMENTED;
483 ///@}
485 /// \defgroup AudioProperties Audio properties
486 /// \ingroup Properties
487 ///@{
489 /// Volume (RW)
490 static int mp_property_volume(m_option_t * prop, int action, void *arg,
491 MPContext * mpctx)
494 if (!mpctx->sh_audio)
495 return M_PROPERTY_UNAVAILABLE;
497 switch (action) {
498 case M_PROPERTY_GET:
499 if (!arg)
500 return M_PROPERTY_ERROR;
501 mixer_getbothvolume(&mpctx->mixer, arg);
502 return M_PROPERTY_OK;
503 case M_PROPERTY_PRINT:{
504 float vol;
505 if (!arg)
506 return M_PROPERTY_ERROR;
507 mixer_getbothvolume(&mpctx->mixer, &vol);
508 return m_property_float_range(prop, action, arg, &vol);
510 case M_PROPERTY_STEP_UP:
511 case M_PROPERTY_STEP_DOWN:
512 case M_PROPERTY_SET:
513 break;
514 default:
515 return M_PROPERTY_NOT_IMPLEMENTED;
518 if (mpctx->edl_muted)
519 return M_PROPERTY_DISABLED;
520 mpctx->user_muted = 0;
522 switch (action) {
523 case M_PROPERTY_SET:
524 if (!arg)
525 return M_PROPERTY_ERROR;
526 M_PROPERTY_CLAMP(prop, *(float *) arg);
527 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
528 return M_PROPERTY_OK;
529 case M_PROPERTY_STEP_UP:
530 if (arg && *(float *) arg <= 0)
531 mixer_decvolume(&mpctx->mixer);
532 else
533 mixer_incvolume(&mpctx->mixer);
534 return M_PROPERTY_OK;
535 case M_PROPERTY_STEP_DOWN:
536 if (arg && *(float *) arg <= 0)
537 mixer_incvolume(&mpctx->mixer);
538 else
539 mixer_decvolume(&mpctx->mixer);
540 return M_PROPERTY_OK;
542 return M_PROPERTY_NOT_IMPLEMENTED;
545 /// Mute (RW)
546 static int mp_property_mute(m_option_t * prop, int action, void *arg,
547 MPContext * mpctx)
550 if (!mpctx->sh_audio)
551 return M_PROPERTY_UNAVAILABLE;
553 switch (action) {
554 case M_PROPERTY_SET:
555 if (mpctx->edl_muted)
556 return M_PROPERTY_DISABLED;
557 if (!arg)
558 return M_PROPERTY_ERROR;
559 if ((!!*(int *) arg) != mpctx->mixer.muted)
560 mixer_mute(&mpctx->mixer);
561 mpctx->user_muted = mpctx->mixer.muted;
562 return M_PROPERTY_OK;
563 case M_PROPERTY_STEP_UP:
564 case M_PROPERTY_STEP_DOWN:
565 if (mpctx->edl_muted)
566 return M_PROPERTY_DISABLED;
567 mixer_mute(&mpctx->mixer);
568 mpctx->user_muted = mpctx->mixer.muted;
569 return M_PROPERTY_OK;
570 case M_PROPERTY_PRINT:
571 if (!arg)
572 return M_PROPERTY_ERROR;
573 if (mpctx->edl_muted) {
574 *(char **) arg = strdup(MSGTR_EnabledEdl);
575 return M_PROPERTY_OK;
577 default:
578 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
583 /// Audio delay (RW)
584 static int mp_property_audio_delay(m_option_t * prop, int action,
585 void *arg, MPContext * mpctx)
587 if (!(mpctx->sh_audio && mpctx->sh_video))
588 return M_PROPERTY_UNAVAILABLE;
589 switch (action) {
590 case M_PROPERTY_SET:
591 case M_PROPERTY_STEP_UP:
592 case M_PROPERTY_STEP_DOWN:
593 if (!arg)
594 return M_PROPERTY_ERROR;
595 else {
596 float delay = audio_delay;
597 m_property_delay(prop, action, arg, &audio_delay);
598 if (mpctx->sh_audio)
599 mpctx->delay -= audio_delay - delay;
601 return M_PROPERTY_OK;
602 default:
603 return m_property_delay(prop, action, arg, &audio_delay);
607 /// Audio codec tag (RO)
608 static int mp_property_audio_format(m_option_t * prop, int action,
609 void *arg, MPContext * mpctx)
611 if (!mpctx->sh_audio)
612 return M_PROPERTY_UNAVAILABLE;
613 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
616 /// Audio codec name (RO)
617 static int mp_property_audio_codec(m_option_t * prop, int action,
618 void *arg, MPContext * mpctx)
620 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
621 return M_PROPERTY_UNAVAILABLE;
622 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
625 /// Audio bitrate (RO)
626 static int mp_property_audio_bitrate(m_option_t * prop, int action,
627 void *arg, MPContext * mpctx)
629 if (!mpctx->sh_audio)
630 return M_PROPERTY_UNAVAILABLE;
631 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
634 /// Samplerate (RO)
635 static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
636 MPContext * mpctx)
638 if (!mpctx->sh_audio)
639 return M_PROPERTY_UNAVAILABLE;
640 switch(action) {
641 case M_PROPERTY_PRINT:
642 if(!arg) return M_PROPERTY_ERROR;
643 *(char**)arg = malloc(16);
644 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
645 return M_PROPERTY_OK;
647 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
650 /// Number of channels (RO)
651 static int mp_property_channels(m_option_t * prop, int action, void *arg,
652 MPContext * mpctx)
654 if (!mpctx->sh_audio)
655 return M_PROPERTY_UNAVAILABLE;
656 switch (action) {
657 case M_PROPERTY_PRINT:
658 if (!arg)
659 return M_PROPERTY_ERROR;
660 switch (mpctx->sh_audio->channels) {
661 case 1:
662 *(char **) arg = strdup("mono");
663 break;
664 case 2:
665 *(char **) arg = strdup("stereo");
666 break;
667 default:
668 *(char **) arg = malloc(32);
669 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
671 return M_PROPERTY_OK;
673 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
676 /// Balance (RW)
677 static int mp_property_balance(m_option_t * prop, int action, void *arg,
678 MPContext * mpctx)
680 float bal;
682 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
683 return M_PROPERTY_UNAVAILABLE;
685 switch (action) {
686 case M_PROPERTY_GET:
687 if (!arg)
688 return M_PROPERTY_ERROR;
689 mixer_getbalance(&mpctx->mixer, arg);
690 return M_PROPERTY_OK;
691 case M_PROPERTY_PRINT: {
692 char** str = arg;
693 if (!arg)
694 return M_PROPERTY_ERROR;
695 mixer_getbalance(&mpctx->mixer, &bal);
696 if (bal == 0.f)
697 *str = strdup("center");
698 else if (bal == -1.f)
699 *str = strdup("left only");
700 else if (bal == 1.f)
701 *str = strdup("right only");
702 else {
703 unsigned right = (bal + 1.f) / 2.f * 100.f;
704 *str = malloc(sizeof("left xxx%, right xxx%"));
705 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
707 return M_PROPERTY_OK;
709 case M_PROPERTY_STEP_UP:
710 case M_PROPERTY_STEP_DOWN:
711 mixer_getbalance(&mpctx->mixer, &bal);
712 bal += (arg ? *(float*)arg : .1f) *
713 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
714 M_PROPERTY_CLAMP(prop, bal);
715 mixer_setbalance(&mpctx->mixer, bal);
716 return M_PROPERTY_OK;
717 case M_PROPERTY_SET:
718 if (!arg)
719 return M_PROPERTY_ERROR;
720 M_PROPERTY_CLAMP(prop, *(float*)arg);
721 mixer_setbalance(&mpctx->mixer, *(float*)arg);
722 return M_PROPERTY_OK;
724 return M_PROPERTY_NOT_IMPLEMENTED;
727 /// Selected audio id (RW)
728 static int mp_property_audio(m_option_t * prop, int action, void *arg,
729 MPContext * mpctx)
731 int current_id = -1, tmp;
733 switch (action) {
734 case M_PROPERTY_GET:
735 if (!mpctx->sh_audio)
736 return M_PROPERTY_UNAVAILABLE;
737 if (!arg)
738 return M_PROPERTY_ERROR;
739 *(int *) arg = audio_id;
740 return M_PROPERTY_OK;
741 case M_PROPERTY_PRINT:
742 if (!mpctx->sh_audio)
743 return M_PROPERTY_UNAVAILABLE;
744 if (!arg)
745 return M_PROPERTY_ERROR;
747 if (audio_id < 0)
748 *(char **) arg = strdup(MSGTR_Disabled);
749 else {
750 char lang[40] = MSGTR_Unknown;
751 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA)
752 demux_mkv_get_audio_lang(mpctx->demuxer, audio_id, lang, 9);
753 #ifdef USE_DVDREAD
754 else if (mpctx->stream->type == STREAMTYPE_DVD) {
755 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
756 if (code) {
757 lang[0] = code >> 8;
758 lang[1] = code;
759 lang[2] = 0;
762 #endif
764 #ifdef USE_DVDNAV
765 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
766 dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
767 #endif
768 *(char **) arg = malloc(64);
769 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
771 return M_PROPERTY_OK;
773 case M_PROPERTY_STEP_UP:
774 case M_PROPERTY_SET:
775 if (action == M_PROPERTY_SET && arg)
776 tmp = *((int *) arg);
777 else
778 tmp = -1;
779 current_id = mpctx->demuxer->audio->id;
780 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
781 if (audio_id == -2
782 || (audio_id > -1
783 && mpctx->demuxer->audio->id != current_id && current_id != -2))
784 uninit_player(INITED_AO | INITED_ACODEC);
785 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
786 sh_audio_t *sh2;
787 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
788 if (sh2) {
789 sh2->ds = mpctx->demuxer->audio;
790 mpctx->sh_audio = sh2;
791 reinit_audio_chain();
794 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
795 return M_PROPERTY_OK;
796 default:
797 return M_PROPERTY_NOT_IMPLEMENTED;
802 /// Selected video id (RW)
803 static int mp_property_video(m_option_t * prop, int action, void *arg,
804 MPContext * mpctx)
806 int current_id = -1, tmp;
808 switch (action) {
809 case M_PROPERTY_GET:
810 if (!mpctx->sh_video)
811 return M_PROPERTY_UNAVAILABLE;
812 if (!arg)
813 return M_PROPERTY_ERROR;
814 *(int *) arg = video_id;
815 return M_PROPERTY_OK;
816 case M_PROPERTY_PRINT:
817 if (!mpctx->sh_video)
818 return M_PROPERTY_UNAVAILABLE;
819 if (!arg)
820 return M_PROPERTY_ERROR;
822 if (video_id < 0)
823 *(char **) arg = strdup(MSGTR_Disabled);
824 else {
825 char lang[40] = MSGTR_Unknown;
826 *(char **) arg = malloc(64);
827 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
829 return M_PROPERTY_OK;
831 case M_PROPERTY_STEP_UP:
832 case M_PROPERTY_SET:
833 current_id = mpctx->demuxer->video->id;
834 if (action == M_PROPERTY_SET && arg)
835 tmp = *((int *) arg);
836 else
837 tmp = -1;
838 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
839 if (video_id == -2
840 || (video_id > -1 && mpctx->demuxer->video->id != current_id
841 && current_id != -2))
842 uninit_player(INITED_VCODEC |
843 (fixed_vo && video_id != -2 ? 0 : INITED_VO));
844 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
845 sh_video_t *sh2;
846 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
847 if (sh2) {
848 sh2->ds = mpctx->demuxer->video;
849 mpctx->sh_video = sh2;
850 reinit_video_chain();
853 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
854 return M_PROPERTY_OK;
856 default:
857 return M_PROPERTY_NOT_IMPLEMENTED;
861 static int mp_property_program(m_option_t * prop, int action, void *arg,
862 MPContext * mpctx)
864 demux_program_t prog;
866 switch (action) {
867 case M_PROPERTY_STEP_UP:
868 case M_PROPERTY_SET:
869 if (action == M_PROPERTY_SET && arg)
870 prog.progid = *((int *) arg);
871 else
872 prog.progid = -1;
873 if (demux_control
874 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
875 &prog) == DEMUXER_CTRL_NOTIMPL)
876 return M_PROPERTY_ERROR;
878 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
879 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
880 return M_PROPERTY_OK;
882 default:
883 return M_PROPERTY_NOT_IMPLEMENTED;
887 ///@}
889 /// \defgroup VideoProperties Video properties
890 /// \ingroup Properties
891 ///@{
893 /// Fullscreen state (RW)
894 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
895 MPContext * mpctx)
898 if (!mpctx->video_out)
899 return M_PROPERTY_UNAVAILABLE;
901 switch (action) {
902 case M_PROPERTY_SET:
903 if (!arg)
904 return M_PROPERTY_ERROR;
905 M_PROPERTY_CLAMP(prop, *(int *) arg);
906 if (vo_fs == !!*(int *) arg)
907 return M_PROPERTY_OK;
908 case M_PROPERTY_STEP_UP:
909 case M_PROPERTY_STEP_DOWN:
910 #ifdef HAVE_NEW_GUI
911 if (use_gui)
912 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
913 else
914 #endif
915 if (vo_config_count)
916 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
917 return M_PROPERTY_OK;
918 default:
919 return m_property_flag(prop, action, arg, &vo_fs);
923 static int mp_property_deinterlace(m_option_t * prop, int action,
924 void *arg, MPContext * mpctx)
926 int deinterlace;
927 vf_instance_t *vf;
928 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
929 return M_PROPERTY_UNAVAILABLE;
930 vf = mpctx->sh_video->vfilter;
931 switch (action) {
932 case M_PROPERTY_GET:
933 if (!arg)
934 return M_PROPERTY_ERROR;
935 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
936 return M_PROPERTY_OK;
937 case M_PROPERTY_SET:
938 if (!arg)
939 return M_PROPERTY_ERROR;
940 M_PROPERTY_CLAMP(prop, *(int *) arg);
941 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
942 return M_PROPERTY_OK;
943 case M_PROPERTY_STEP_UP:
944 case M_PROPERTY_STEP_DOWN:
945 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
946 deinterlace = !deinterlace;
947 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
948 return M_PROPERTY_OK;
950 return M_PROPERTY_NOT_IMPLEMENTED;
953 /// Panscan (RW)
954 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
955 MPContext * mpctx)
958 if (!mpctx->video_out
959 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
960 return M_PROPERTY_UNAVAILABLE;
962 switch (action) {
963 case M_PROPERTY_SET:
964 if (!arg)
965 return M_PROPERTY_ERROR;
966 M_PROPERTY_CLAMP(prop, *(float *) arg);
967 vo_panscan = *(float *) arg;
968 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
969 return M_PROPERTY_OK;
970 case M_PROPERTY_STEP_UP:
971 case M_PROPERTY_STEP_DOWN:
972 vo_panscan += (arg ? *(float *) arg : 0.1) *
973 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
974 if (vo_panscan > 1)
975 vo_panscan = 1;
976 else if (vo_panscan < 0)
977 vo_panscan = 0;
978 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
979 return M_PROPERTY_OK;
980 default:
981 return m_property_float_range(prop, action, arg, &vo_panscan);
985 /// Helper to set vo flags.
986 /** \ingroup PropertyImplHelper
988 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
989 int vo_ctrl, int *vo_var, MPContext * mpctx)
992 if (!mpctx->video_out)
993 return M_PROPERTY_UNAVAILABLE;
995 switch (action) {
996 case M_PROPERTY_SET:
997 if (!arg)
998 return M_PROPERTY_ERROR;
999 M_PROPERTY_CLAMP(prop, *(int *) arg);
1000 if (*vo_var == !!*(int *) arg)
1001 return M_PROPERTY_OK;
1002 case M_PROPERTY_STEP_UP:
1003 case M_PROPERTY_STEP_DOWN:
1004 if (vo_config_count)
1005 mpctx->video_out->control(vo_ctrl, 0);
1006 return M_PROPERTY_OK;
1007 default:
1008 return m_property_flag(prop, action, arg, vo_var);
1012 /// Window always on top (RW)
1013 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
1014 MPContext * mpctx)
1016 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
1017 mpctx);
1020 /// Display in the root window (RW)
1021 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
1022 MPContext * mpctx)
1024 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1025 &vo_rootwin, mpctx);
1028 /// Show window borders (RW)
1029 static int mp_property_border(m_option_t * prop, int action, void *arg,
1030 MPContext * mpctx)
1032 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1033 &vo_border, mpctx);
1036 /// Framedropping state (RW)
1037 static int mp_property_framedropping(m_option_t * prop, int action,
1038 void *arg, MPContext * mpctx)
1041 if (!mpctx->sh_video)
1042 return M_PROPERTY_UNAVAILABLE;
1044 switch (action) {
1045 case M_PROPERTY_PRINT:
1046 if (!arg)
1047 return M_PROPERTY_ERROR;
1048 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1049 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1050 MSGTR_Disabled));
1051 return M_PROPERTY_OK;
1052 default:
1053 return m_property_choice(prop, action, arg, &frame_dropping);
1057 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1058 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
1059 MPContext * mpctx)
1061 int *gamma = prop->priv, r;
1063 if (!mpctx->sh_video)
1064 return M_PROPERTY_UNAVAILABLE;
1066 if (gamma[0] == 1000) {
1067 gamma[0] = 0;
1068 get_video_colors(mpctx->sh_video, prop->name, gamma);
1071 switch (action) {
1072 case M_PROPERTY_SET:
1073 if (!arg)
1074 return M_PROPERTY_ERROR;
1075 M_PROPERTY_CLAMP(prop, *(int *) arg);
1076 *gamma = *(int *) arg;
1077 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1078 if (r <= 0)
1079 break;
1080 return r;
1081 case M_PROPERTY_GET:
1082 if (!arg)
1083 return M_PROPERTY_ERROR;
1084 r = get_video_colors(mpctx->sh_video, prop->name, arg);
1085 if (r <= 0)
1086 break;
1087 return r;
1088 case M_PROPERTY_STEP_UP:
1089 case M_PROPERTY_STEP_DOWN:
1090 *gamma += (arg ? *(int *) arg : 1) *
1091 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1092 M_PROPERTY_CLAMP(prop, *gamma);
1093 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1094 if (r <= 0)
1095 break;
1096 return r;
1097 default:
1098 return M_PROPERTY_NOT_IMPLEMENTED;
1101 #ifdef USE_TV
1102 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1103 int l = strlen(prop->name);
1104 char tv_prop[3 + l + 1];
1105 sprintf(tv_prop, "tv_%s", prop->name);
1106 return mp_property_do(tv_prop, action, arg, mpctx);
1108 #endif
1110 return M_PROPERTY_UNAVAILABLE;
1113 /// VSync (RW)
1114 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1115 MPContext * mpctx)
1117 return m_property_flag(prop, action, arg, &vo_vsync);
1120 /// Video codec tag (RO)
1121 static int mp_property_video_format(m_option_t * prop, int action,
1122 void *arg, MPContext * mpctx)
1124 char* meta;
1125 if (!mpctx->sh_video)
1126 return M_PROPERTY_UNAVAILABLE;
1127 switch(action) {
1128 case M_PROPERTY_PRINT:
1129 if (!arg)
1130 return M_PROPERTY_ERROR;
1131 switch(mpctx->sh_video->format) {
1132 case 0x10000001:
1133 meta = strdup ("mpeg1"); break;
1134 case 0x10000002:
1135 meta = strdup ("mpeg2"); break;
1136 case 0x10000004:
1137 meta = strdup ("mpeg4"); break;
1138 case 0x10000005:
1139 meta = strdup ("h264"); break;
1140 default:
1141 if(mpctx->sh_video->format >= 0x20202020) {
1142 meta = malloc(5);
1143 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1144 } else {
1145 meta = malloc(20);
1146 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1149 *(char**)arg = meta;
1150 return M_PROPERTY_OK;
1152 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1155 /// Video codec name (RO)
1156 static int mp_property_video_codec(m_option_t * prop, int action,
1157 void *arg, MPContext * mpctx)
1159 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1160 return M_PROPERTY_UNAVAILABLE;
1161 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1165 /// Video bitrate (RO)
1166 static int mp_property_video_bitrate(m_option_t * prop, int action,
1167 void *arg, MPContext * mpctx)
1169 if (!mpctx->sh_video)
1170 return M_PROPERTY_UNAVAILABLE;
1171 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1174 /// Video display width (RO)
1175 static int mp_property_width(m_option_t * prop, int action, void *arg,
1176 MPContext * mpctx)
1178 if (!mpctx->sh_video)
1179 return M_PROPERTY_UNAVAILABLE;
1180 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1183 /// Video display height (RO)
1184 static int mp_property_height(m_option_t * prop, int action, void *arg,
1185 MPContext * mpctx)
1187 if (!mpctx->sh_video)
1188 return M_PROPERTY_UNAVAILABLE;
1189 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1192 /// Video fps (RO)
1193 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1194 MPContext * mpctx)
1196 if (!mpctx->sh_video)
1197 return M_PROPERTY_UNAVAILABLE;
1198 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1201 /// Video aspect (RO)
1202 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1203 MPContext * mpctx)
1205 if (!mpctx->sh_video)
1206 return M_PROPERTY_UNAVAILABLE;
1207 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1210 ///@}
1212 /// \defgroup SubProprties Subtitles properties
1213 /// \ingroup Properties
1214 ///@{
1216 /// Text subtitle position (RW)
1217 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1218 MPContext * mpctx)
1220 if (!mpctx->sh_video)
1221 return M_PROPERTY_UNAVAILABLE;
1223 switch (action) {
1224 case M_PROPERTY_SET:
1225 if (!arg)
1226 return M_PROPERTY_ERROR;
1227 case M_PROPERTY_STEP_UP:
1228 case M_PROPERTY_STEP_DOWN:
1229 vo_osd_changed(OSDTYPE_SUBTITLE);
1230 default:
1231 return m_property_int_range(prop, action, arg, &sub_pos);
1235 char *demux_lavf_sub_lang(demuxer_t *demuxer, int track_num);
1237 /// Selected subtitles (RW)
1238 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1239 MPContext * mpctx)
1241 demux_stream_t *const d_sub = mpctx->d_sub;
1242 const int global_sub_size = mpctx->global_sub_size;
1243 int source = -1, reset_spu = 0;
1244 char *sub_name;
1246 if (global_sub_size <= 0)
1247 return M_PROPERTY_UNAVAILABLE;
1249 switch (action) {
1250 case M_PROPERTY_GET:
1251 if (!arg)
1252 return M_PROPERTY_ERROR;
1253 *(int *) arg = mpctx->global_sub_pos;
1254 return M_PROPERTY_OK;
1255 case M_PROPERTY_PRINT:
1256 if (!arg)
1257 return M_PROPERTY_ERROR;
1258 *(char **) arg = malloc(64);
1259 (*(char **) arg)[63] = 0;
1260 sub_name = 0;
1261 if (subdata)
1262 sub_name = subdata->filename;
1263 #ifdef USE_ASS
1264 if (ass_track && ass_track->name)
1265 sub_name = ass_track->name;
1266 #endif
1267 if (sub_name) {
1268 char *tmp, *tmp2;
1269 tmp = sub_name;
1270 if ((tmp2 = strrchr(tmp, '/')))
1271 tmp = tmp2 + 1;
1273 snprintf(*(char **) arg, 63, "(%d) %s%s",
1274 mpctx->set_of_sub_pos + 1,
1275 strlen(tmp) < 20 ? "" : "...",
1276 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1277 return M_PROPERTY_OK;
1279 #ifdef USE_DVDNAV
1280 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1281 if (vo_spudec && dvdsub_id >= 0) {
1282 unsigned char lang[3];
1283 if (dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1284 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1285 return M_PROPERTY_OK;
1289 #endif
1291 #ifdef USE_LIBAVFORMAT
1292 if (mpctx->demuxer->type == DEMUXER_TYPE_LAVF && dvdsub_id >= 0) {
1293 char *lang = demux_lavf_sub_lang(mpctx->demuxer, dvdsub_id);
1294 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1295 return M_PROPERTY_OK;
1297 #endif
1298 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
1299 char lang[40] = MSGTR_Unknown;
1300 demux_mkv_get_sub_lang(mpctx->demuxer, dvdsub_id, lang, 9);
1301 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1302 return M_PROPERTY_OK;
1304 #ifdef HAVE_OGGVORBIS
1305 if (mpctx->demuxer->type == DEMUXER_TYPE_OGG && d_sub && dvdsub_id >= 0) {
1306 char *lang = demux_ogg_sub_lang(mpctx->demuxer, dvdsub_id);
1307 if (!lang)
1308 lang = MSGTR_Unknown;
1309 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1310 return M_PROPERTY_OK;
1312 #endif
1313 if (vo_vobsub && vobsub_id >= 0) {
1314 const char *language = MSGTR_Unknown;
1315 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1316 snprintf(*(char **) arg, 63, "(%d) %s",
1317 vobsub_id, language ? language : MSGTR_Unknown);
1318 return M_PROPERTY_OK;
1320 #ifdef USE_DVDREAD
1321 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1322 && dvdsub_id >= 0) {
1323 char lang[3];
1324 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1325 lang[0] = code >> 8;
1326 lang[1] = code;
1327 lang[2] = 0;
1328 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1329 return M_PROPERTY_OK;
1331 #endif
1332 if (dvdsub_id >= 0) {
1333 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1334 return M_PROPERTY_OK;
1336 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1337 return M_PROPERTY_OK;
1339 case M_PROPERTY_SET:
1340 if (!arg)
1341 return M_PROPERTY_ERROR;
1342 if (*(int *) arg < -1)
1343 *(int *) arg = -1;
1344 else if (*(int *) arg >= global_sub_size)
1345 *(int *) arg = global_sub_size - 1;
1346 mpctx->global_sub_pos = *(int *) arg;
1347 break;
1348 case M_PROPERTY_STEP_UP:
1349 mpctx->global_sub_pos += 2;
1350 mpctx->global_sub_pos =
1351 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1352 break;
1353 case M_PROPERTY_STEP_DOWN:
1354 mpctx->global_sub_pos += global_sub_size + 1;
1355 mpctx->global_sub_pos =
1356 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1357 break;
1358 default:
1359 return M_PROPERTY_NOT_IMPLEMENTED;
1362 if (mpctx->global_sub_pos >= 0)
1363 source = sub_source(mpctx);
1365 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1366 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1367 global_sub_size,
1368 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1369 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1370 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1371 mpctx->global_sub_pos, source);
1373 mpctx->set_of_sub_pos = -1;
1374 subdata = NULL;
1376 vobsub_id = -1;
1377 dvdsub_id = -1;
1378 if (d_sub) {
1379 if (d_sub->id > -2)
1380 reset_spu = 1;
1381 d_sub->id = -2;
1383 #ifdef USE_ASS
1384 ass_track = 0;
1385 #endif
1387 if (source == SUB_SOURCE_VOBSUB) {
1388 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1389 } else if (source == SUB_SOURCE_SUBS) {
1390 mpctx->set_of_sub_pos =
1391 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1392 #ifdef USE_ASS
1393 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1394 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1395 else
1396 #endif
1398 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1399 vo_osd_changed(OSDTYPE_SUBTITLE);
1401 } else if (source == SUB_SOURCE_DEMUX) {
1402 dvdsub_id =
1403 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1404 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1405 int i = 0;
1406 // default: assume 1:1 mapping of sid and stream id
1407 d_sub->id = dvdsub_id;
1408 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1409 for (i = 0; i < MAX_S_STREAMS; i++) {
1410 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1411 if (sh && sh->sid == dvdsub_id) {
1412 d_sub->id = i;
1413 d_sub->sh = sh;
1414 break;
1417 if (d_sub->sh && d_sub->id >= 0) {
1418 sh_sub_t *sh = d_sub->sh;
1419 if (sh->type == 'v')
1420 init_vo_spudec();
1421 #ifdef USE_ASS
1422 else if (ass_enabled && sh->type == 'a')
1423 ass_track = sh->ass_track;
1424 #endif
1425 } else {
1426 d_sub->id = -2;
1427 d_sub->sh = NULL;
1431 #ifdef USE_DVDREAD
1432 if (vo_spudec
1433 && (mpctx->stream->type == STREAMTYPE_DVD
1434 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1435 && dvdsub_id < 0 && reset_spu) {
1436 dvdsub_id = -2;
1437 d_sub->id = dvdsub_id;
1439 #endif
1440 update_subtitles(mpctx->sh_video, d_sub, 1);
1442 return M_PROPERTY_OK;
1445 /// Selected sub source (RW)
1446 static int mp_property_sub_source(m_option_t * prop, int action, void *arg,
1447 MPContext * mpctx)
1449 int source;
1450 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1451 return M_PROPERTY_UNAVAILABLE;
1453 switch (action) {
1454 case M_PROPERTY_GET:
1455 if (!arg)
1456 return M_PROPERTY_ERROR;
1457 *(int *) arg = sub_source(mpctx);
1458 return M_PROPERTY_OK;
1459 case M_PROPERTY_PRINT:
1460 if (!arg)
1461 return M_PROPERTY_ERROR;
1462 *(char **) arg = malloc(64);
1463 (*(char **) arg)[63] = 0;
1464 switch (sub_source(mpctx))
1466 case SUB_SOURCE_SUBS:
1467 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1468 break;
1469 case SUB_SOURCE_VOBSUB:
1470 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1471 break;
1472 case SUB_SOURCE_DEMUX:
1473 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1474 break;
1475 default:
1476 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1478 return M_PROPERTY_OK;
1479 case M_PROPERTY_SET:
1480 if (!arg)
1481 return M_PROPERTY_ERROR;
1482 M_PROPERTY_CLAMP(prop, *(int*)arg);
1483 if (*(int *) arg < 0)
1484 mpctx->global_sub_pos = -1;
1485 else if (*(int *) arg != sub_source(mpctx)) {
1486 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1487 return M_PROPERTY_UNAVAILABLE;
1488 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1490 break;
1491 case M_PROPERTY_STEP_UP:
1492 case M_PROPERTY_STEP_DOWN: {
1493 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1494 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1495 int step = (step_all > 0) ? 1 : -1;
1496 int cur_source = sub_source(mpctx);
1497 source = cur_source;
1498 while (step_all) {
1499 source += step;
1500 if (source >= SUB_SOURCES)
1501 source = -1;
1502 else if (source < -1)
1503 source = SUB_SOURCES - 1;
1504 if (source == cur_source || source == -1 ||
1505 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1506 step_all -= step;
1508 if (source == cur_source)
1509 return M_PROPERTY_OK;
1510 if (source == -1)
1511 mpctx->global_sub_pos = -1;
1512 else
1513 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1514 break;
1516 default:
1517 return M_PROPERTY_NOT_IMPLEMENTED;
1519 --mpctx->global_sub_pos;
1520 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1523 /// Selected subtitles from specific source (RW)
1524 static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg,
1525 MPContext * mpctx)
1527 int source, is_cur_source, offset;
1528 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1529 return M_PROPERTY_UNAVAILABLE;
1531 if (!strcmp(prop->name, "sub_file"))
1532 source = SUB_SOURCE_SUBS;
1533 else if (!strcmp(prop->name, "sub_vob"))
1534 source = SUB_SOURCE_VOBSUB;
1535 else if (!strcmp(prop->name, "sub_demux"))
1536 source = SUB_SOURCE_DEMUX;
1537 else
1538 return M_PROPERTY_ERROR;
1540 offset = mpctx->global_sub_indices[source];
1541 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1542 return M_PROPERTY_UNAVAILABLE;
1544 is_cur_source = sub_source(mpctx) == source;
1545 switch (action) {
1546 case M_PROPERTY_GET:
1547 if (!arg)
1548 return M_PROPERTY_ERROR;
1549 if (is_cur_source) {
1550 *(int *) arg = mpctx->global_sub_pos - offset;
1551 if (source == SUB_SOURCE_VOBSUB)
1552 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1554 else
1555 *(int *) arg = -1;
1556 return M_PROPERTY_OK;
1557 case M_PROPERTY_PRINT:
1558 if (!arg)
1559 return M_PROPERTY_ERROR;
1560 if (is_cur_source)
1561 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1562 *(char **) arg = malloc(64);
1563 (*(char **) arg)[63] = 0;
1564 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1565 return M_PROPERTY_OK;
1566 case M_PROPERTY_SET:
1567 if (!arg)
1568 return M_PROPERTY_ERROR;
1569 if (*(int *) arg >= 0) {
1570 int index = *(int *)arg;
1571 if (source == SUB_SOURCE_VOBSUB)
1572 index = vobsub_get_index_by_id(vo_vobsub, index);
1573 mpctx->global_sub_pos = offset + index;
1574 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1575 || sub_source(mpctx) != source) {
1576 mpctx->global_sub_pos = -1;
1577 *(int *) arg = -1;
1580 else
1581 mpctx->global_sub_pos = -1;
1582 break;
1583 case M_PROPERTY_STEP_UP:
1584 case M_PROPERTY_STEP_DOWN: {
1585 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1586 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1587 int step = (step_all > 0) ? 1 : -1;
1588 int max_sub_pos_for_source = -1;
1589 if (!is_cur_source)
1590 mpctx->global_sub_pos = -1;
1591 while (step_all) {
1592 if (mpctx->global_sub_pos == -1) {
1593 if (step > 0)
1594 mpctx->global_sub_pos = offset;
1595 else if (max_sub_pos_for_source == -1) {
1596 // Find max pos for specific source
1597 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1598 while (mpctx->global_sub_pos >= 0
1599 && sub_source(mpctx) != source)
1600 --mpctx->global_sub_pos;
1602 else
1603 mpctx->global_sub_pos = max_sub_pos_for_source;
1605 else {
1606 mpctx->global_sub_pos += step;
1607 if (mpctx->global_sub_pos < offset ||
1608 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1609 sub_source(mpctx) != source)
1610 mpctx->global_sub_pos = -1;
1612 step_all -= step;
1614 break;
1616 default:
1617 return M_PROPERTY_NOT_IMPLEMENTED;
1619 --mpctx->global_sub_pos;
1620 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1623 /// Subtitle delay (RW)
1624 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1625 MPContext * mpctx)
1627 if (!mpctx->sh_video)
1628 return M_PROPERTY_UNAVAILABLE;
1629 return m_property_delay(prop, action, arg, &sub_delay);
1632 /// Alignment of text subtitles (RW)
1633 static int mp_property_sub_alignment(m_option_t * prop, int action,
1634 void *arg, MPContext * mpctx)
1636 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1638 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1639 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1640 return M_PROPERTY_UNAVAILABLE;
1642 switch (action) {
1643 case M_PROPERTY_PRINT:
1644 if (!arg)
1645 return M_PROPERTY_ERROR;
1646 M_PROPERTY_CLAMP(prop, sub_alignment);
1647 *(char **) arg = strdup(name[sub_alignment]);
1648 return M_PROPERTY_OK;
1649 case M_PROPERTY_SET:
1650 if (!arg)
1651 return M_PROPERTY_ERROR;
1652 case M_PROPERTY_STEP_UP:
1653 case M_PROPERTY_STEP_DOWN:
1654 vo_osd_changed(OSDTYPE_SUBTITLE);
1655 default:
1656 return m_property_choice(prop, action, arg, &sub_alignment);
1660 /// Subtitle visibility (RW)
1661 static int mp_property_sub_visibility(m_option_t * prop, int action,
1662 void *arg, MPContext * mpctx)
1664 if (!mpctx->sh_video)
1665 return M_PROPERTY_UNAVAILABLE;
1667 switch (action) {
1668 case M_PROPERTY_SET:
1669 if (!arg)
1670 return M_PROPERTY_ERROR;
1671 case M_PROPERTY_STEP_UP:
1672 case M_PROPERTY_STEP_DOWN:
1673 vo_osd_changed(OSDTYPE_SUBTITLE);
1674 if (vo_spudec)
1675 vo_osd_changed(OSDTYPE_SPU);
1676 default:
1677 return m_property_flag(prop, action, arg, &sub_visibility);
1681 /// Show only forced subtitles (RW)
1682 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1683 void *arg, MPContext * mpctx)
1685 if (!vo_spudec)
1686 return M_PROPERTY_UNAVAILABLE;
1688 switch (action) {
1689 case M_PROPERTY_SET:
1690 if (!arg)
1691 return M_PROPERTY_ERROR;
1692 case M_PROPERTY_STEP_UP:
1693 case M_PROPERTY_STEP_DOWN:
1694 m_property_flag(prop, action, arg, &forced_subs_only);
1695 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1696 return M_PROPERTY_OK;
1697 default:
1698 return m_property_flag(prop, action, arg, &forced_subs_only);
1703 #ifdef HAVE_FREETYPE
1704 /// Subtitle scale (RW)
1705 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1706 MPContext * mpctx)
1709 switch (action) {
1710 case M_PROPERTY_SET:
1711 if (!arg)
1712 return M_PROPERTY_ERROR;
1713 M_PROPERTY_CLAMP(prop, *(float *) arg);
1714 text_font_scale_factor = *(float *) arg;
1715 force_load_font = 1;
1716 return M_PROPERTY_OK;
1717 case M_PROPERTY_STEP_UP:
1718 case M_PROPERTY_STEP_DOWN:
1719 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1720 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1721 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1722 force_load_font = 1;
1723 return M_PROPERTY_OK;
1724 default:
1725 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1728 #endif
1730 ///@}
1732 /// \defgroup TVProperties TV properties
1733 /// \ingroup Properties
1734 ///@{
1736 #ifdef USE_TV
1738 /// TV color settings (RW)
1739 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1740 MPContext * mpctx)
1742 int r, val;
1743 tvi_handle_t *tvh = mpctx->demuxer->priv;
1744 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1745 return M_PROPERTY_UNAVAILABLE;
1747 switch (action) {
1748 case M_PROPERTY_SET:
1749 if (!arg)
1750 return M_PROPERTY_ERROR;
1751 M_PROPERTY_CLAMP(prop, *(int *) arg);
1752 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1753 case M_PROPERTY_GET:
1754 return tv_get_color_options(tvh, (int) prop->priv, arg);
1755 case M_PROPERTY_STEP_UP:
1756 case M_PROPERTY_STEP_DOWN:
1757 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1758 if (!r)
1759 return M_PROPERTY_ERROR;
1760 val += (arg ? *(int *) arg : 1) *
1761 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1762 M_PROPERTY_CLAMP(prop, val);
1763 return tv_set_color_options(tvh, (int) prop->priv, val);
1765 return M_PROPERTY_ERROR;
1767 return M_PROPERTY_NOT_IMPLEMENTED;
1770 #endif
1772 #ifdef HAVE_TV_TELETEXT
1773 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1774 MPContext * mpctx)
1776 int val,result;
1777 int base_ioctl=(int)prop->priv;
1779 for teletext's GET,SET,STEP ioctls this is not 0
1780 SET is GET+1
1781 STEP is GET+2
1783 tvi_handle_t *tvh = mpctx->demuxer->priv;
1784 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1785 return M_PROPERTY_UNAVAILABLE;
1786 if(!base_ioctl)
1787 return M_PROPERTY_ERROR;
1789 switch (action) {
1790 case M_PROPERTY_GET:
1791 if (!arg)
1792 return M_PROPERTY_ERROR;
1793 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1794 break;
1795 case M_PROPERTY_SET:
1796 if (!arg)
1797 return M_PROPERTY_ERROR;
1798 M_PROPERTY_CLAMP(prop, *(int *) arg);
1799 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1800 break;
1801 case M_PROPERTY_STEP_UP:
1802 case M_PROPERTY_STEP_DOWN:
1803 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1804 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1805 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1806 break;
1807 default:
1808 return M_PROPERTY_NOT_IMPLEMENTED;
1811 return (result==TVI_CONTROL_TRUE?M_PROPERTY_OK:M_PROPERTY_ERROR);
1814 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1815 MPContext * mpctx)
1817 tvi_handle_t *tvh = mpctx->demuxer->priv;
1818 int result;
1819 int val;
1821 //with tvh==NULL will fail too
1822 result=mp_property_teletext_common(prop,action,arg,mpctx);
1823 if(result!=M_PROPERTY_OK)
1824 return result;
1826 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1827 mp_input_set_section("teletext");
1828 else
1829 mp_input_set_section("tv");
1830 return M_PROPERTY_OK;
1833 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1834 MPContext * mpctx)
1836 tvi_handle_t *tvh = mpctx->demuxer->priv;
1837 int result;
1838 int val;
1839 switch(action){
1840 case M_PROPERTY_STEP_UP:
1841 case M_PROPERTY_STEP_DOWN:
1842 //This should be handled separately
1843 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1844 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1845 break;
1846 default:
1847 result=mp_property_teletext_common(prop,action,arg,mpctx);
1849 return result;
1853 #endif /* HAVE_TV_TELETEXT */
1855 ///@}
1857 /// All properties available in MPlayer.
1858 /** \ingroup Properties
1860 static m_option_t mp_properties[] = {
1861 // General
1862 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1863 M_OPT_RANGE, 0, 3, NULL },
1864 { "loop", mp_property_loop, CONF_TYPE_INT,
1865 M_OPT_MIN, -1, 0, NULL },
1866 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1867 M_OPT_RANGE, 0.01, 100.0, NULL },
1868 { "filename", mp_property_filename, CONF_TYPE_STRING,
1869 0, 0, 0, NULL },
1870 { "path", mp_property_path, CONF_TYPE_STRING,
1871 0, 0, 0, NULL },
1872 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1873 0, 0, 0, NULL },
1874 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1875 M_OPT_MIN, 0, 0, NULL },
1876 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1877 M_OPT_MIN, 0, 0, NULL },
1878 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1879 M_OPT_MIN, 0, 0, NULL },
1880 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1881 M_OPT_MIN, 0, 0, NULL },
1882 { "length", mp_property_length, CONF_TYPE_TIME,
1883 M_OPT_MIN, 0, 0, NULL },
1884 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1885 M_OPT_RANGE, 0, 100, NULL },
1886 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1887 M_OPT_MIN, 0, 0, NULL },
1888 { "chapter", mp_property_chapter, CONF_TYPE_INT,
1889 M_OPT_MIN, 1, 0, NULL },
1890 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
1891 0, 0, 0, NULL },
1893 // Audio
1894 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
1895 M_OPT_RANGE, 0, 100, NULL },
1896 { "mute", mp_property_mute, CONF_TYPE_FLAG,
1897 M_OPT_RANGE, 0, 1, NULL },
1898 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
1899 M_OPT_RANGE, -100, 100, NULL },
1900 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
1901 0, 0, 0, NULL },
1902 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
1903 0, 0, 0, NULL },
1904 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
1905 0, 0, 0, NULL },
1906 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
1907 0, 0, 0, NULL },
1908 { "channels", mp_property_channels, CONF_TYPE_INT,
1909 0, 0, 0, NULL },
1910 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
1911 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
1912 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
1913 M_OPT_RANGE, -1, 1, NULL },
1915 // Video
1916 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
1917 M_OPT_RANGE, 0, 1, NULL },
1918 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
1919 M_OPT_RANGE, 0, 1, NULL },
1920 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
1921 M_OPT_RANGE, 0, 1, NULL },
1922 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
1923 M_OPT_RANGE, 0, 1, NULL },
1924 { "border", mp_property_border, CONF_TYPE_FLAG,
1925 M_OPT_RANGE, 0, 1, NULL },
1926 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
1927 M_OPT_RANGE, 0, 2, NULL },
1928 { "gamma", mp_property_gamma, CONF_TYPE_INT,
1929 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
1930 { "brightness", mp_property_gamma, CONF_TYPE_INT,
1931 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
1932 { "contrast", mp_property_gamma, CONF_TYPE_INT,
1933 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
1934 { "saturation", mp_property_gamma, CONF_TYPE_INT,
1935 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
1936 { "hue", mp_property_gamma, CONF_TYPE_INT,
1937 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
1938 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
1939 M_OPT_RANGE, 0, 1, NULL },
1940 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
1941 M_OPT_RANGE, 0, 1, NULL },
1942 { "video_format", mp_property_video_format, CONF_TYPE_INT,
1943 0, 0, 0, NULL },
1944 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
1945 0, 0, 0, NULL },
1946 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
1947 0, 0, 0, NULL },
1948 { "width", mp_property_width, CONF_TYPE_INT,
1949 0, 0, 0, NULL },
1950 { "height", mp_property_height, CONF_TYPE_INT,
1951 0, 0, 0, NULL },
1952 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
1953 0, 0, 0, NULL },
1954 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
1955 0, 0, 0, NULL },
1956 { "switch_video", mp_property_video, CONF_TYPE_INT,
1957 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
1958 { "switch_program", mp_property_program, CONF_TYPE_INT,
1959 CONF_RANGE, -1, 65535, NULL },
1961 // Subs
1962 { "sub", mp_property_sub, CONF_TYPE_INT,
1963 M_OPT_MIN, -1, 0, NULL },
1964 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
1965 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
1966 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
1967 M_OPT_MIN, -1, 0, NULL },
1968 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
1969 M_OPT_MIN, -1, 0, NULL },
1970 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
1971 M_OPT_MIN, -1, 0, NULL },
1972 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
1973 0, 0, 0, NULL },
1974 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
1975 M_OPT_RANGE, 0, 100, NULL },
1976 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
1977 M_OPT_RANGE, 0, 2, NULL },
1978 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
1979 M_OPT_RANGE, 0, 1, NULL },
1980 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
1981 M_OPT_RANGE, 0, 1, NULL },
1982 #ifdef HAVE_FREETYPE
1983 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
1984 M_OPT_RANGE, 0, 100, NULL },
1985 #endif
1987 #ifdef USE_TV
1988 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
1989 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
1990 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
1991 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
1992 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
1993 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
1994 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
1995 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
1996 #endif
1998 #ifdef HAVE_TV_TELETEXT
1999 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2000 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2001 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2002 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2003 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2004 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2005 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2006 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2007 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2008 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2009 #endif
2011 { NULL, NULL, NULL, 0, 0, 0, NULL }
2015 int mp_property_do(const char *name, int action, void *val, void *ctx)
2017 return m_property_do(mp_properties, name, action, val, ctx);
2020 char* mp_property_print(const char *name, void* ctx)
2022 char* ret = NULL;
2023 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2024 return NULL;
2025 return ret;
2028 char *property_expand_string(MPContext * mpctx, char *str)
2030 return m_properties_expand_string(mp_properties, str, mpctx);
2033 void property_print_help(void)
2035 m_properties_print_help_list(mp_properties);
2039 ///@}
2040 // Properties group
2044 * \defgroup Command2Property Command to property bridge
2046 * It is used to handle most commands that just set a property
2047 * and optionally display something on the OSD.
2048 * Two kinds of commands are handled: adjust or toggle.
2050 * Adjust commands take 1 or 2 parameters: <value> <abs>
2051 * If <abs> is non-zero the property is set to the given value
2052 * otherwise it is adjusted.
2054 * Toggle commands take 0 or 1 parameters. With no parameter
2055 * or a value less than the property minimum it just steps the
2056 * property to its next value. Otherwise it sets it to the given
2057 * value.
2062 /// List of the commands that can be handled by setting a property.
2063 static struct {
2064 /// property name
2065 const char *name;
2066 /// cmd id
2067 int cmd;
2068 /// set/adjust or toggle command
2069 int toggle;
2070 /// progressbar type
2071 int osd_progbar;
2072 /// osd msg id if it must be shared
2073 int osd_id;
2074 /// osd msg template
2075 const char *osd_msg;
2076 } set_prop_cmd[] = {
2077 // general
2078 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2079 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2080 // audio
2081 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2082 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2083 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2084 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2085 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2086 // video
2087 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2088 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2089 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2090 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2091 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2092 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2093 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2094 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2095 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2096 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2097 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2098 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2099 // subs
2100 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2101 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2102 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2103 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2104 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2105 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2106 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2107 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2108 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2109 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2110 #ifdef HAVE_FREETYPE
2111 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2112 #endif
2113 #ifdef USE_TV
2114 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2115 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2116 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2117 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2118 #endif
2119 { NULL, 0, 0, 0, -1, NULL }
2123 /// Handle commands that set a property.
2124 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
2126 int i, r;
2127 m_option_t* prop;
2128 const char *pname;
2130 // look for the command
2131 for (i = 0; set_prop_cmd[i].name; i++)
2132 if (set_prop_cmd[i].cmd == cmd->id)
2133 break;
2134 if (!(pname = set_prop_cmd[i].name))
2135 return 0;
2137 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2138 return 0;
2140 // toggle command
2141 if (set_prop_cmd[i].toggle) {
2142 // set to value
2143 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2144 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2145 else
2146 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2147 } else if (cmd->args[1].v.i) //set
2148 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2149 else // adjust
2150 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2152 if (r <= 0)
2153 return 1;
2155 if (set_prop_cmd[i].osd_progbar) {
2156 if (prop->type == CONF_TYPE_INT) {
2157 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2158 set_osd_bar(set_prop_cmd[i].osd_progbar,
2159 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2160 } else if (prop->type == CONF_TYPE_FLOAT) {
2161 float f;
2162 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2163 set_osd_bar(set_prop_cmd[i].osd_progbar,
2164 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2165 } else
2166 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2167 "Property use an unsupported type.\n");
2168 return 1;
2171 if (set_prop_cmd[i].osd_msg) {
2172 char *val = mp_property_print(pname, mpctx);
2173 if (val) {
2174 set_osd_msg(set_prop_cmd[i].osd_id >=
2175 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2176 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2177 free(val);
2180 return 1;
2184 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
2186 sh_audio_t * const sh_audio = mpctx->sh_audio;
2187 sh_video_t * const sh_video = mpctx->sh_video;
2188 int brk_cmd = 0;
2189 if (!set_property_command(mpctx, cmd))
2190 switch (cmd->id) {
2191 case MP_CMD_SEEK:{
2192 float v;
2193 int abs;
2194 if (sh_video)
2195 mpctx->osd_show_percentage = sh_video->fps;
2196 v = cmd->args[0].v.f;
2197 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2198 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2199 abs_seek_pos = 1;
2200 if (sh_video)
2201 mpctx->osd_function =
2202 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2203 rel_seek_secs = v;
2204 } else if (abs) { /* Absolute seek by percentage */
2205 abs_seek_pos = 3;
2206 if (sh_video)
2207 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2208 rel_seek_secs = v / 100.0;
2209 } else {
2210 rel_seek_secs += v;
2211 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2213 brk_cmd = 1;
2215 break;
2217 case MP_CMD_SET_PROPERTY:{
2218 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2219 cmd->args[1].v.s, mpctx);
2220 if (r == M_PROPERTY_UNKNOWN)
2221 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2222 "Unknown property: '%s'\n", cmd->args[0].v.s);
2223 else if (r <= 0)
2224 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2225 "Failed to set property '%s' to '%s'.\n",
2226 cmd->args[0].v.s, cmd->args[1].v.s);
2228 break;
2230 case MP_CMD_STEP_PROPERTY:{
2231 void* arg = NULL;
2232 int r,i;
2233 double d;
2234 off_t o;
2235 if (cmd->args[1].v.f) {
2236 m_option_t* prop;
2237 if((r = mp_property_do(cmd->args[0].v.s,
2238 M_PROPERTY_GET_TYPE,
2239 &prop, mpctx)) <= 0)
2240 goto step_prop_err;
2241 if(prop->type == CONF_TYPE_INT ||
2242 prop->type == CONF_TYPE_FLAG)
2243 i = cmd->args[1].v.f, arg = &i;
2244 else if(prop->type == CONF_TYPE_FLOAT)
2245 arg = &cmd->args[1].v.f;
2246 else if(prop->type == CONF_TYPE_DOUBLE ||
2247 prop->type == CONF_TYPE_TIME)
2248 d = cmd->args[1].v.f, arg = &d;
2249 else if(prop->type == CONF_TYPE_POSITION)
2250 o = cmd->args[1].v.f, arg = &o;
2251 else
2252 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2253 "Ignoring step size stepping property '%s'.\n",
2254 cmd->args[0].v.s);
2256 r = mp_property_do(cmd->args[0].v.s,
2257 cmd->args[2].v.i < 0 ?
2258 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2259 arg, mpctx);
2260 step_prop_err:
2261 if (r == M_PROPERTY_UNKNOWN)
2262 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2263 "Unknown property: '%s'\n", cmd->args[0].v.s);
2264 else if (r <= 0)
2265 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2266 "Failed to increment property '%s' by %f.\n",
2267 cmd->args[0].v.s, cmd->args[1].v.f);
2269 break;
2271 case MP_CMD_GET_PROPERTY:{
2272 char *tmp;
2273 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2274 &tmp, mpctx) <= 0) {
2275 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2276 "Failed to get value of property '%s'.\n",
2277 cmd->args[0].v.s);
2278 break;
2280 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2281 cmd->args[0].v.s, tmp);
2282 free(tmp);
2284 break;
2286 case MP_CMD_EDL_MARK:
2287 if (edl_fd) {
2288 float v = sh_video ? sh_video->pts :
2289 playing_audio_pts(sh_audio, mpctx->d_audio,
2290 mpctx->audio_out);
2292 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2293 mpctx->begin_skip = v;
2294 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2295 } else {
2296 if (mpctx->begin_skip > v)
2297 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2298 else {
2299 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2300 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2302 mpctx->begin_skip = MP_NOPTS_VALUE;
2305 break;
2307 case MP_CMD_SWITCH_RATIO:
2308 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2309 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2310 else
2311 movie_aspect = cmd->args[0].v.f;
2312 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2313 break;
2315 case MP_CMD_SPEED_INCR:{
2316 float v = cmd->args[0].v.f;
2317 playback_speed += v;
2318 build_afilter_chain(sh_audio, &ao_data);
2319 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2320 playback_speed);
2321 } break;
2323 case MP_CMD_SPEED_MULT:{
2324 float v = cmd->args[0].v.f;
2325 playback_speed *= v;
2326 build_afilter_chain(sh_audio, &ao_data);
2327 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2328 playback_speed);
2329 } break;
2331 case MP_CMD_SPEED_SET:{
2332 float v = cmd->args[0].v.f;
2333 playback_speed = v;
2334 build_afilter_chain(sh_audio, &ao_data);
2335 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2336 playback_speed);
2337 } break;
2339 case MP_CMD_FRAME_STEP:
2340 case MP_CMD_PAUSE:
2341 cmd->pausing = 1;
2342 brk_cmd = 1;
2343 break;
2345 case MP_CMD_FILE_FILTER:
2346 file_filter = cmd->args[0].v.i;
2347 break;
2349 case MP_CMD_QUIT:
2350 exit_player_with_rc(MSGTR_Exit_quit,
2351 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2353 case MP_CMD_PLAY_TREE_STEP:{
2354 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2355 int force = cmd->args[1].v.i;
2357 #ifdef HAVE_NEW_GUI
2358 if (use_gui) {
2359 int i = 0;
2360 if (n > 0)
2361 for (i = 0; i < n; i++)
2362 mplNext();
2363 else
2364 for (i = 0; i < -1 * n; i++)
2365 mplPrev();
2366 } else
2367 #endif
2369 if (!force && mpctx->playtree_iter) {
2370 play_tree_iter_t *i =
2371 play_tree_iter_new_copy(mpctx->playtree_iter);
2372 if (play_tree_iter_step(i, n, 0) ==
2373 PLAY_TREE_ITER_ENTRY)
2374 mpctx->eof =
2375 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2376 play_tree_iter_free(i);
2377 } else
2378 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2379 if (mpctx->eof)
2380 mpctx->play_tree_step = n;
2381 brk_cmd = 1;
2384 break;
2386 case MP_CMD_PLAY_TREE_UP_STEP:{
2387 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2388 int force = cmd->args[1].v.i;
2390 if (!force && mpctx->playtree_iter) {
2391 play_tree_iter_t *i =
2392 play_tree_iter_new_copy(mpctx->playtree_iter);
2393 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2394 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2395 play_tree_iter_free(i);
2396 } else
2397 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2398 brk_cmd = 1;
2400 break;
2402 case MP_CMD_PLAY_ALT_SRC_STEP:
2403 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2404 int v = cmd->args[0].v.i;
2405 if (v > 0
2406 && mpctx->playtree_iter->file <
2407 mpctx->playtree_iter->num_files)
2408 mpctx->eof = PT_NEXT_SRC;
2409 else if (v < 0 && mpctx->playtree_iter->file > 1)
2410 mpctx->eof = PT_PREV_SRC;
2412 brk_cmd = 1;
2413 break;
2415 case MP_CMD_SUB_STEP:
2416 if (sh_video) {
2417 int movement = cmd->args[0].v.i;
2418 step_sub(subdata, sh_video->pts, movement);
2419 #ifdef USE_ASS
2420 if (ass_track)
2421 sub_delay +=
2422 ass_step_sub(ass_track,
2423 (sh_video->pts +
2424 sub_delay) * 1000 + .5, movement) / 1000.;
2425 #endif
2426 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2427 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2429 break;
2431 case MP_CMD_SUB_LOG:
2432 log_sub();
2433 break;
2435 case MP_CMD_OSD:{
2436 int v = cmd->args[0].v.i;
2437 int max = (term_osd
2438 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2439 if (osd_level > max)
2440 osd_level = max;
2441 if (v < 0)
2442 osd_level = (osd_level + 1) % (max + 1);
2443 else
2444 osd_level = v > max ? max : v;
2445 /* Show OSD state when disabled, but not when an explicit
2446 argument is given to the OSD command, i.e. in slave mode. */
2447 if (v == -1 && osd_level <= 1)
2448 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2449 MSGTR_OSDosd,
2450 osd_level ? MSGTR_OSDenabled :
2451 MSGTR_OSDdisabled);
2452 else
2453 rm_osd_msg(OSD_MSG_OSD_STATUS);
2455 break;
2457 case MP_CMD_OSD_SHOW_TEXT:
2458 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2459 (cmd->args[1].v.i <
2460 0 ? osd_duration : cmd->args[1].v.i),
2461 "%-.63s", cmd->args[0].v.s);
2462 break;
2464 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2465 char *txt = m_properties_expand_string(mp_properties,
2466 cmd->args[0].v.s,
2467 mpctx);
2468 /* if no argument supplied take default osd_duration, else <arg> ms. */
2469 if (txt) {
2470 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2471 (cmd->args[1].v.i <
2472 0 ? osd_duration : cmd->args[1].v.i),
2473 "%-.63s", txt);
2474 free(txt);
2477 break;
2479 case MP_CMD_LOADFILE:{
2480 play_tree_t *e = play_tree_new();
2481 play_tree_add_file(e, cmd->args[0].v.s);
2483 if (cmd->args[1].v.i) // append
2484 play_tree_append_entry(mpctx->playtree, e);
2485 else {
2486 // Go back to the starting point.
2487 while (play_tree_iter_up_step
2488 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2489 /* NOP */ ;
2490 play_tree_free_list(mpctx->playtree->child, 1);
2491 play_tree_set_child(mpctx->playtree, e);
2492 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2493 mpctx->eof = PT_NEXT_SRC;
2495 brk_cmd = 1;
2497 break;
2499 case MP_CMD_LOADLIST:{
2500 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2501 if (!e)
2502 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2503 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2504 else {
2505 if (cmd->args[1].v.i) // append
2506 play_tree_append_entry(mpctx->playtree, e);
2507 else {
2508 // Go back to the starting point.
2509 while (play_tree_iter_up_step
2510 (mpctx->playtree_iter, 0, 1)
2511 != PLAY_TREE_ITER_END)
2512 /* NOP */ ;
2513 play_tree_free_list(mpctx->playtree->child, 1);
2514 play_tree_set_child(mpctx->playtree, e);
2515 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2516 mpctx->eof = PT_NEXT_SRC;
2519 brk_cmd = 1;
2521 break;
2523 #ifdef USE_RADIO
2524 case MP_CMD_RADIO_STEP_CHANNEL:
2525 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2526 int v = cmd->args[0].v.i;
2527 if (v > 0)
2528 radio_step_channel(mpctx->demuxer->stream,
2529 RADIO_CHANNEL_HIGHER);
2530 else
2531 radio_step_channel(mpctx->demuxer->stream,
2532 RADIO_CHANNEL_LOWER);
2533 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2534 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2535 MSGTR_OSDChannel,
2536 radio_get_channel_name(mpctx->demuxer->stream));
2539 break;
2541 case MP_CMD_RADIO_SET_CHANNEL:
2542 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2543 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2544 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2545 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2546 MSGTR_OSDChannel,
2547 radio_get_channel_name(mpctx->demuxer->stream));
2550 break;
2552 case MP_CMD_RADIO_SET_FREQ:
2553 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2554 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2555 break;
2557 case MP_CMD_RADIO_STEP_FREQ:
2558 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2559 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2560 break;
2561 #endif
2563 #ifdef USE_TV
2564 case MP_CMD_TV_START_SCAN:
2565 if (mpctx->file_format == DEMUXER_TYPE_TV)
2566 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2567 break;
2568 case MP_CMD_TV_SET_FREQ:
2569 if (mpctx->file_format == DEMUXER_TYPE_TV)
2570 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2571 cmd->args[0].v.f * 16.0);
2572 #ifdef HAVE_PVR
2573 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2574 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2575 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2576 pvr_get_current_channelname (mpctx->stream),
2577 pvr_get_current_stationname (mpctx->stream));
2579 #endif /* HAVE_PVR */
2580 break;
2582 case MP_CMD_TV_STEP_FREQ:
2583 if (mpctx->file_format == DEMUXER_TYPE_TV)
2584 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2585 cmd->args[0].v.f * 16.0);
2586 #ifdef HAVE_PVR
2587 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2588 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2589 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2590 pvr_get_current_channelname (mpctx->stream),
2591 pvr_get_current_frequency (mpctx->stream));
2593 #endif /* HAVE_PVR */
2594 break;
2596 case MP_CMD_TV_SET_NORM:
2597 if (mpctx->file_format == DEMUXER_TYPE_TV)
2598 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2599 cmd->args[0].v.s);
2600 break;
2602 case MP_CMD_TV_STEP_CHANNEL:{
2603 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2604 int v = cmd->args[0].v.i;
2605 if (v > 0) {
2606 tv_step_channel((tvi_handle_t *) (mpctx->
2607 demuxer->priv),
2608 TV_CHANNEL_HIGHER);
2609 } else {
2610 tv_step_channel((tvi_handle_t *) (mpctx->
2611 demuxer->priv),
2612 TV_CHANNEL_LOWER);
2614 if (tv_channel_list) {
2615 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2616 MSGTR_OSDChannel, tv_channel_current->name);
2617 //vo_osd_changed(OSDTYPE_SUBTITLE);
2620 #ifdef HAVE_PVR
2621 else if (mpctx->stream &&
2622 mpctx->stream->type == STREAMTYPE_PVR) {
2623 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2624 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2625 pvr_get_current_channelname (mpctx->stream),
2626 pvr_get_current_stationname (mpctx->stream));
2628 #endif /* HAVE_PVR */
2630 #ifdef HAS_DVBIN_SUPPORT
2631 if (mpctx->stream->type == STREAMTYPE_DVB) {
2632 int dir;
2633 int v = cmd->args[0].v.i;
2635 mpctx->last_dvb_step = v;
2636 if (v > 0)
2637 dir = DVB_CHANNEL_HIGHER;
2638 else
2639 dir = DVB_CHANNEL_LOWER;
2642 if (dvb_step_channel(mpctx->stream, dir))
2643 mpctx->eof = mpctx->dvbin_reopen = 1;
2645 #endif /* HAS_DVBIN_SUPPORT */
2646 break;
2648 case MP_CMD_TV_SET_CHANNEL:
2649 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2650 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2651 cmd->args[0].v.s);
2652 if (tv_channel_list) {
2653 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2654 MSGTR_OSDChannel, tv_channel_current->name);
2655 //vo_osd_changed(OSDTYPE_SUBTITLE);
2658 #ifdef HAVE_PVR
2659 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2660 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2661 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2662 pvr_get_current_channelname (mpctx->stream),
2663 pvr_get_current_stationname (mpctx->stream));
2665 #endif /* HAVE_PVR */
2666 break;
2668 #ifdef HAS_DVBIN_SUPPORT
2669 case MP_CMD_DVB_SET_CHANNEL:
2670 if (mpctx->stream->type == STREAMTYPE_DVB) {
2671 mpctx->last_dvb_step = 1;
2673 if (dvb_set_channel
2674 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2675 mpctx->eof = mpctx->dvbin_reopen = 1;
2677 break;
2678 #endif /* HAS_DVBIN_SUPPORT */
2680 case MP_CMD_TV_LAST_CHANNEL:
2681 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2682 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2683 if (tv_channel_list) {
2684 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2685 MSGTR_OSDChannel, tv_channel_current->name);
2686 //vo_osd_changed(OSDTYPE_SUBTITLE);
2689 #ifdef HAVE_PVR
2690 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2691 pvr_set_lastchannel (mpctx->stream);
2692 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2693 pvr_get_current_channelname (mpctx->stream),
2694 pvr_get_current_stationname (mpctx->stream));
2696 #endif /* HAVE_PVR */
2697 break;
2699 case MP_CMD_TV_STEP_NORM:
2700 if (mpctx->file_format == DEMUXER_TYPE_TV)
2701 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2702 break;
2704 case MP_CMD_TV_STEP_CHANNEL_LIST:
2705 if (mpctx->file_format == DEMUXER_TYPE_TV)
2706 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2707 break;
2708 #ifdef HAVE_TV_TELETEXT
2709 case MP_CMD_TV_TELETEXT_ADD_DEC:
2711 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2712 if (mpctx->file_format == DEMUXER_TYPE_TV)
2713 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2714 break;
2716 case MP_CMD_TV_TELETEXT_GO_LINK:
2718 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2719 if (mpctx->file_format == DEMUXER_TYPE_TV)
2720 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2721 break;
2723 #endif /* HAVE_TV_TELETEXT */
2724 #endif /* USE_TV */
2726 case MP_CMD_SUB_LOAD:
2727 if (sh_video) {
2728 int n = mpctx->set_of_sub_size;
2729 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2730 if (n != mpctx->set_of_sub_size) {
2731 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2732 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2733 mpctx->global_sub_size;
2734 ++mpctx->global_sub_size;
2737 break;
2739 case MP_CMD_SUB_REMOVE:
2740 if (sh_video) {
2741 int v = cmd->args[0].v.i;
2742 sub_data *subd;
2743 if (v < 0) {
2744 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2745 subd = mpctx->set_of_subtitles[v];
2746 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2747 MSGTR_RemovedSubtitleFile, v + 1,
2748 filename_recode(subd->filename));
2749 sub_free(subd);
2750 mpctx->set_of_subtitles[v] = NULL;
2752 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2753 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2754 mpctx->set_of_sub_size = 0;
2755 if (mpctx->set_of_sub_pos >= 0) {
2756 mpctx->global_sub_pos = -2;
2757 subdata = NULL;
2758 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2760 } else if (v < mpctx->set_of_sub_size) {
2761 subd = mpctx->set_of_subtitles[v];
2762 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2763 MSGTR_RemovedSubtitleFile, v + 1,
2764 filename_recode(subd->filename));
2765 sub_free(subd);
2766 if (mpctx->set_of_sub_pos == v) {
2767 mpctx->global_sub_pos = -2;
2768 subdata = NULL;
2769 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2770 } else if (mpctx->set_of_sub_pos > v) {
2771 --mpctx->set_of_sub_pos;
2772 --mpctx->global_sub_pos;
2774 while (++v < mpctx->set_of_sub_size)
2775 mpctx->set_of_subtitles[v - 1] =
2776 mpctx->set_of_subtitles[v];
2777 --mpctx->set_of_sub_size;
2778 --mpctx->global_sub_size;
2779 if (mpctx->set_of_sub_size <= 0)
2780 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2781 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2784 break;
2786 case MP_CMD_GET_SUB_VISIBILITY:
2787 if (sh_video) {
2788 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2789 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2791 break;
2793 case MP_CMD_SCREENSHOT:
2794 if (vo_config_count) {
2795 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2796 if (CONTROL_OK !=
2797 ((vf_instance_t *) sh_video->vfilter)->
2798 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2799 &cmd->args[0].v.i))
2800 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2802 break;
2804 case MP_CMD_VF_CHANGE_RECTANGLE:
2805 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2806 break;
2808 case MP_CMD_GET_TIME_LENGTH:{
2809 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2810 demuxer_get_time_length(mpctx->demuxer));
2812 break;
2814 case MP_CMD_GET_FILENAME:{
2815 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2816 get_metadata(META_NAME));
2818 break;
2820 case MP_CMD_GET_VIDEO_CODEC:{
2821 char *inf = get_metadata(META_VIDEO_CODEC);
2822 if (!inf)
2823 inf = strdup("");
2824 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2825 free(inf);
2827 break;
2829 case MP_CMD_GET_VIDEO_BITRATE:{
2830 char *inf = get_metadata(META_VIDEO_BITRATE);
2831 if (!inf)
2832 inf = strdup("");
2833 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2834 free(inf);
2836 break;
2838 case MP_CMD_GET_VIDEO_RESOLUTION:{
2839 char *inf = get_metadata(META_VIDEO_RESOLUTION);
2840 if (!inf)
2841 inf = strdup("");
2842 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2843 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
2844 free(inf);
2846 break;
2848 case MP_CMD_GET_AUDIO_CODEC:{
2849 char *inf = get_metadata(META_AUDIO_CODEC);
2850 if (!inf)
2851 inf = strdup("");
2852 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
2853 free(inf);
2855 break;
2857 case MP_CMD_GET_AUDIO_BITRATE:{
2858 char *inf = get_metadata(META_AUDIO_BITRATE);
2859 if (!inf)
2860 inf = strdup("");
2861 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
2862 free(inf);
2864 break;
2866 case MP_CMD_GET_AUDIO_SAMPLES:{
2867 char *inf = get_metadata(META_AUDIO_SAMPLES);
2868 if (!inf)
2869 inf = strdup("");
2870 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
2871 free(inf);
2873 break;
2875 case MP_CMD_GET_META_TITLE:{
2876 char *inf = get_metadata(META_INFO_TITLE);
2877 if (!inf)
2878 inf = strdup("");
2879 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
2880 free(inf);
2882 break;
2884 case MP_CMD_GET_META_ARTIST:{
2885 char *inf = get_metadata(META_INFO_ARTIST);
2886 if (!inf)
2887 inf = strdup("");
2888 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
2889 free(inf);
2891 break;
2893 case MP_CMD_GET_META_ALBUM:{
2894 char *inf = get_metadata(META_INFO_ALBUM);
2895 if (!inf)
2896 inf = strdup("");
2897 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
2898 free(inf);
2900 break;
2902 case MP_CMD_GET_META_YEAR:{
2903 char *inf = get_metadata(META_INFO_YEAR);
2904 if (!inf)
2905 inf = strdup("");
2906 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
2907 free(inf);
2909 break;
2911 case MP_CMD_GET_META_COMMENT:{
2912 char *inf = get_metadata(META_INFO_COMMENT);
2913 if (!inf)
2914 inf = strdup("");
2915 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
2916 free(inf);
2918 break;
2920 case MP_CMD_GET_META_TRACK:{
2921 char *inf = get_metadata(META_INFO_TRACK);
2922 if (!inf)
2923 inf = strdup("");
2924 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
2925 free(inf);
2927 break;
2929 case MP_CMD_GET_META_GENRE:{
2930 char *inf = get_metadata(META_INFO_GENRE);
2931 if (!inf)
2932 inf = strdup("");
2933 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
2934 free(inf);
2936 break;
2938 case MP_CMD_GET_VO_FULLSCREEN:
2939 if (mpctx->video_out && vo_config_count)
2940 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
2941 break;
2943 case MP_CMD_GET_PERCENT_POS:
2944 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
2945 demuxer_get_percent_pos(mpctx->demuxer));
2946 break;
2948 case MP_CMD_GET_TIME_POS:{
2949 float pos = 0;
2950 if (sh_video)
2951 pos = sh_video->pts;
2952 else if (sh_audio && mpctx->audio_out)
2953 pos =
2954 playing_audio_pts(sh_audio, mpctx->d_audio,
2955 mpctx->audio_out);
2956 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
2958 break;
2960 case MP_CMD_RUN:
2961 #ifndef __MINGW32__
2962 if (!fork()) {
2963 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
2964 exit(0);
2966 #endif
2967 break;
2969 case MP_CMD_KEYDOWN_EVENTS:
2970 mplayer_put_key(cmd->args[0].v.i);
2971 break;
2973 case MP_CMD_SET_MOUSE_POS:{
2974 int pointer_x, pointer_y;
2975 double dx, dy;
2976 pointer_x = cmd->args[0].v.i;
2977 pointer_y = cmd->args[1].v.i;
2978 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
2979 #ifdef USE_DVDNAV
2980 if (mpctx->stream->type == STREAMTYPE_DVDNAV
2981 && dx > 0.0 && dy > 0.0) {
2982 int button = -1;
2983 pointer_x = (int) (dx * (double) sh_video->disp_w);
2984 pointer_y = (int) (dy * (double) sh_video->disp_h);
2985 mp_dvdnav_update_mouse_pos(mpctx->stream,
2986 pointer_x, pointer_y, &button);
2987 if (button > 0)
2988 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2989 "Selected button number %d", button);
2991 #endif
2993 break;
2995 #ifdef USE_DVDNAV
2996 case MP_CMD_DVDNAV:{
2997 int button = -1;
2998 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
2999 break;
3001 if (mp_dvdnav_handle_input
3002 (mpctx->stream, cmd->args[0].v.i, &button)) {
3003 uninit_player(INITED_ALL - (INITED_STREAM | INITED_INPUT |
3004 (fixed_vo ? INITED_VO : 0)));
3005 brk_cmd = 2;
3006 } else if (button > 0)
3007 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3008 "Selected button number %d", button);
3010 break;
3011 #endif
3013 default:
3014 #ifdef HAVE_NEW_GUI
3015 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3016 guiGetEvent(guiIEvent, (char *) cmd->id);
3017 else
3018 #endif
3019 mp_msg(MSGT_CPLAYER, MSGL_V,
3020 "Received unknown cmd %s\n", cmd->name);
3023 switch (cmd->pausing) {
3024 case 1: // "pausing"
3025 mpctx->osd_function = OSD_PAUSE;
3026 break;
3027 case 3: // "pausing_toggle"
3028 mpctx->was_paused = !mpctx->was_paused;
3029 if (mpctx->was_paused)
3030 mpctx->osd_function = OSD_PAUSE;
3031 else if (mpctx->osd_function == OSD_PAUSE)
3032 mpctx->osd_function = OSD_PLAY;
3033 break;
3034 case 2: // "pausing_keep"
3035 if (mpctx->was_paused)
3036 mpctx->osd_function = OSD_PAUSE;
3038 return brk_cmd;