OSD menu support mouse selection.
[mplayer/greg.git] / command.c
blobd6da090f4567129326400e16192c6ca7c8792c2a
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_MENU
55 #include "m_struct.h"
56 #include "libmenu/menu.h"
57 #endif
58 #ifdef HAVE_NEW_GUI
59 #include "gui/interface.h"
60 #endif
62 #include "mp_core.h"
63 #include "mp_fifo.h"
65 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
67 extern int use_menu;
69 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy)
71 //remove the borders, if any, and rescale to the range [0,1],[0,1]
72 if (vo_fs) { //we are in full-screen mode
73 if (vo_screenwidth > vo_dwidth) //there are borders along the x axis
74 ix -= (vo_screenwidth - vo_dwidth) / 2;
75 if (vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
76 iy -= (vo_screenheight - vo_dheight) / 2;
78 if (ix < 0 || ix > vo_dwidth) {
79 *dx = *dy = -1.0;
80 return;
81 } //we are on one of the borders
82 if (iy < 0 || iy > vo_dheight) {
83 *dx = *dy = -1.0;
84 return;
85 } //we are on one of the borders
88 *dx = (double) ix / (double) vo_dwidth;
89 *dy = (double) iy / (double) vo_dheight;
91 mp_msg(MSGT_CPLAYER, MSGL_V,
92 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
93 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth,
94 vo_dheight, vo_fs);
97 static int sub_source_by_pos(MPContext * mpctx, int pos)
99 int source = -1;
100 int top = -1;
101 int i;
102 for (i = 0; i < SUB_SOURCES; i++) {
103 int j = mpctx->global_sub_indices[i];
104 if ((j >= 0) && (j > top) && (pos >= j)) {
105 source = i;
106 top = j;
109 return source;
112 static int sub_source(MPContext * mpctx)
114 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
118 * \brief Log the currently displayed subtitle to a file
120 * Logs the current or last displayed subtitle together with filename
121 * and time information to ~/.mplayer/subtitle_log
123 * Intended purpose is to allow convenient marking of bogus subtitles
124 * which need to be fixed while watching the movie.
127 static void log_sub(void)
129 char *fname;
130 FILE *f;
131 int i;
133 if (subdata == NULL || vo_sub_last == NULL)
134 return;
135 fname = get_path("subtitle_log");
136 f = fopen(fname, "a");
137 if (!f)
138 return;
139 fprintf(f, "----------------------------------------------------------\n");
140 if (subdata->sub_uses_time) {
141 fprintf(f,
142 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
143 filename, vo_sub_last->start / 360000,
144 (vo_sub_last->start / 6000) % 60,
145 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
146 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
147 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
148 } else {
149 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start,
150 vo_sub_last->end);
152 for (i = 0; i < vo_sub_last->lines; i++) {
153 fprintf(f, "%s\n", vo_sub_last->text[i]);
155 fclose(f);
159 /// \defgroup Properties
160 ///@{
162 /// \defgroup GeneralProperties General properties
163 /// \ingroup Properties
164 ///@{
166 /// OSD level (RW)
167 static int mp_property_osdlevel(m_option_t * prop, int action, void *arg,
168 MPContext * mpctx)
170 return m_property_choice(prop, action, arg, &osd_level);
173 /// Loop (RW)
174 static int mp_property_loop(m_option_t * prop, int action, void *arg,
175 MPContext * mpctx)
177 switch (action) {
178 case M_PROPERTY_PRINT:
179 if (!arg) return M_PROPERTY_ERROR;
180 if (mpctx->loop_times < 0)
181 *(char**)arg = strdup("off");
182 else if (mpctx->loop_times == 0)
183 *(char**)arg = strdup("inf");
184 else
185 break;
186 return M_PROPERTY_OK;
188 return m_property_int_range(prop, action, arg, &mpctx->loop_times);
191 /// Playback speed (RW)
192 static int mp_property_playback_speed(m_option_t * prop, int action,
193 void *arg, MPContext * mpctx)
195 switch (action) {
196 case M_PROPERTY_SET:
197 if (!arg)
198 return M_PROPERTY_ERROR;
199 M_PROPERTY_CLAMP(prop, *(float *) arg);
200 playback_speed = *(float *) arg;
201 build_afilter_chain(mpctx->sh_audio, &ao_data);
202 return M_PROPERTY_OK;
203 case M_PROPERTY_STEP_UP:
204 case M_PROPERTY_STEP_DOWN:
205 playback_speed += (arg ? *(float *) arg : 0.1) *
206 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
207 M_PROPERTY_CLAMP(prop, playback_speed);
208 build_afilter_chain(mpctx->sh_audio, &ao_data);
209 return M_PROPERTY_OK;
211 return m_property_float_range(prop, action, arg, &playback_speed);
214 /// filename with path (RO)
215 static int mp_property_path(m_option_t * prop, int action, void *arg,
216 MPContext * mpctx)
218 return m_property_string_ro(prop, action, arg, filename);
221 /// filename without path (RO)
222 static int mp_property_filename(m_option_t * prop, int action, void *arg,
223 MPContext * mpctx)
225 char *f;
226 if (!filename)
227 return M_PROPERTY_UNAVAILABLE;
228 if (((f = strrchr(filename, '/')) || (f = strrchr(filename, '\\'))) && f[1])
229 f++;
230 else
231 f = filename;
232 return m_property_string_ro(prop, action, arg, f);
235 /// Demuxer name (RO)
236 static int mp_property_demuxer(m_option_t * prop, int action, void *arg,
237 MPContext * mpctx)
239 if (!mpctx->demuxer)
240 return M_PROPERTY_UNAVAILABLE;
241 return m_property_string_ro(prop, action, arg,
242 (char *) mpctx->demuxer->desc->name);
245 /// Position in the stream (RW)
246 static int mp_property_stream_pos(m_option_t * prop, int action, void *arg,
247 MPContext * mpctx)
249 if (!mpctx->demuxer || !mpctx->demuxer->stream)
250 return M_PROPERTY_UNAVAILABLE;
251 if (!arg)
252 return M_PROPERTY_ERROR;
253 switch (action) {
254 case M_PROPERTY_GET:
255 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
256 return M_PROPERTY_OK;
257 case M_PROPERTY_SET:
258 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
259 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
260 return M_PROPERTY_OK;
262 return M_PROPERTY_NOT_IMPLEMENTED;
265 /// Stream start offset (RO)
266 static int mp_property_stream_start(m_option_t * prop, int action,
267 void *arg, MPContext * mpctx)
269 if (!mpctx->demuxer || !mpctx->demuxer->stream)
270 return M_PROPERTY_UNAVAILABLE;
271 switch (action) {
272 case M_PROPERTY_GET:
273 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
274 return M_PROPERTY_OK;
276 return M_PROPERTY_NOT_IMPLEMENTED;
279 /// Stream end offset (RO)
280 static int mp_property_stream_end(m_option_t * prop, int action, void *arg,
281 MPContext * mpctx)
283 if (!mpctx->demuxer || !mpctx->demuxer->stream)
284 return M_PROPERTY_UNAVAILABLE;
285 switch (action) {
286 case M_PROPERTY_GET:
287 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
288 return M_PROPERTY_OK;
290 return M_PROPERTY_NOT_IMPLEMENTED;
293 /// Stream length (RO)
294 static int mp_property_stream_length(m_option_t * prop, int action,
295 void *arg, MPContext * mpctx)
297 if (!mpctx->demuxer || !mpctx->demuxer->stream)
298 return M_PROPERTY_UNAVAILABLE;
299 switch (action) {
300 case M_PROPERTY_GET:
301 *(off_t *) arg =
302 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
303 return M_PROPERTY_OK;
305 return M_PROPERTY_NOT_IMPLEMENTED;
308 /// Media length in seconds (RO)
309 static int mp_property_length(m_option_t * prop, int action, void *arg,
310 MPContext * mpctx)
312 double len;
314 if (!mpctx->demuxer ||
315 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
316 return M_PROPERTY_UNAVAILABLE;
318 return m_property_time_ro(prop, action, arg, len);
321 /// Current position in percent (RW)
322 static int mp_property_percent_pos(m_option_t * prop, int action,
323 void *arg, MPContext * mpctx) {
324 int pos;
326 if (!mpctx->demuxer)
327 return M_PROPERTY_UNAVAILABLE;
329 switch(action) {
330 case M_PROPERTY_SET:
331 if(!arg) return M_PROPERTY_ERROR;
332 M_PROPERTY_CLAMP(prop, *(int*)arg);
333 pos = *(int*)arg;
334 break;
335 case M_PROPERTY_STEP_UP:
336 case M_PROPERTY_STEP_DOWN:
337 pos = demuxer_get_percent_pos(mpctx->demuxer);
338 pos += (arg ? *(int*)arg : 10) *
339 (action == M_PROPERTY_STEP_UP ? 1 : -1);
340 M_PROPERTY_CLAMP(prop, pos);
341 break;
342 default:
343 return m_property_int_ro(prop, action, arg,
344 demuxer_get_percent_pos(mpctx->demuxer));
347 abs_seek_pos = 3;
348 rel_seek_secs = pos / 100.0;
349 return M_PROPERTY_OK;
352 /// Current position in seconds (RW)
353 static int mp_property_time_pos(m_option_t * prop, int action,
354 void *arg, MPContext * mpctx) {
355 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
356 return M_PROPERTY_UNAVAILABLE;
358 switch(action) {
359 case M_PROPERTY_SET:
360 if(!arg) return M_PROPERTY_ERROR;
361 M_PROPERTY_CLAMP(prop, *(double*)arg);
362 abs_seek_pos = 1;
363 rel_seek_secs = *(double*)arg;
364 return M_PROPERTY_OK;
365 case M_PROPERTY_STEP_UP:
366 case M_PROPERTY_STEP_DOWN:
367 rel_seek_secs += (arg ? *(double*)arg : 10.0) *
368 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
369 return M_PROPERTY_OK;
371 return m_property_time_ro(prop, action, arg,
372 mpctx->sh_video ? mpctx->sh_video->pts :
373 playing_audio_pts(mpctx->sh_audio,
374 mpctx->d_audio,
375 mpctx->audio_out));
378 /// Current chapter (RW)
379 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
380 MPContext *mpctx)
382 int chapter;
383 float next_pts = 0;
384 int chapter_num;
385 int step_all;
386 char *chapter_name = NULL;
388 switch (action) {
389 case M_PROPERTY_GET:
390 chapter = demuxer_get_current_chapter(mpctx->demuxer);
391 if (chapter < 0)
392 return M_PROPERTY_UNAVAILABLE;
393 if (!arg)
394 return M_PROPERTY_ERROR;
395 *(int *) arg = chapter;
396 return M_PROPERTY_OK;
397 case M_PROPERTY_PRINT: {
398 if (!arg)
399 return M_PROPERTY_ERROR;
400 chapter = demuxer_get_current_chapter(mpctx->demuxer);
401 if (chapter < 0)
402 return M_PROPERTY_UNAVAILABLE;
403 chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter);
404 if (!chapter_name)
405 return M_PROPERTY_UNAVAILABLE;
406 *(char **) arg = chapter_name;
407 return M_PROPERTY_OK;
409 case M_PROPERTY_SET:
410 if (!arg)
411 return M_PROPERTY_ERROR;
412 M_PROPERTY_CLAMP(prop, *(int*)arg);
413 chapter = demuxer_get_current_chapter(mpctx->demuxer);
414 if (chapter < 0)
415 return M_PROPERTY_UNAVAILABLE;
416 step_all = *(int *)arg - (chapter + 1);
417 chapter += step_all;
418 break;
419 case M_PROPERTY_STEP_UP:
420 case M_PROPERTY_STEP_DOWN: {
421 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
422 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
423 chapter = demuxer_get_current_chapter(mpctx->demuxer);
424 if (chapter < 0)
425 return M_PROPERTY_UNAVAILABLE;
426 chapter += step_all;
427 if (chapter < 0)
428 chapter = 0;
429 break;
431 default:
432 return M_PROPERTY_NOT_IMPLEMENTED;
434 rel_seek_secs = 0;
435 abs_seek_pos = 0;
436 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
437 &next_pts, &chapter_num, &chapter_name);
438 if (chapter >= 0) {
439 if (next_pts > -1.0) {
440 abs_seek_pos = 1;
441 rel_seek_secs = next_pts;
443 if (chapter_name)
444 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
445 MSGTR_OSDChapter, chapter + 1, chapter_name);
447 else if (step_all > 0)
448 rel_seek_secs = 1000000000.;
449 else
450 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
451 MSGTR_OSDChapter, 0, MSGTR_Unknown);
452 if (chapter_name)
453 free(chapter_name);
454 return M_PROPERTY_OK;
457 /// Demuxer meta data
458 static int mp_property_metadata(m_option_t * prop, int action, void *arg,
459 MPContext * mpctx) {
460 m_property_action_t* ka;
461 char* meta;
462 static m_option_t key_type =
463 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
464 if (!mpctx->demuxer)
465 return M_PROPERTY_UNAVAILABLE;
467 switch(action) {
468 case M_PROPERTY_GET:
469 if(!arg) return M_PROPERTY_ERROR;
470 *(char***)arg = mpctx->demuxer->info;
471 return M_PROPERTY_OK;
472 case M_PROPERTY_KEY_ACTION:
473 if(!arg) return M_PROPERTY_ERROR;
474 ka = arg;
475 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
476 return M_PROPERTY_UNKNOWN;
477 switch(ka->action) {
478 case M_PROPERTY_GET:
479 if(!ka->arg) return M_PROPERTY_ERROR;
480 *(char**)ka->arg = meta;
481 return M_PROPERTY_OK;
482 case M_PROPERTY_GET_TYPE:
483 if(!ka->arg) return M_PROPERTY_ERROR;
484 *(m_option_t**)ka->arg = &key_type;
485 return M_PROPERTY_OK;
488 return M_PROPERTY_NOT_IMPLEMENTED;
492 ///@}
494 /// \defgroup AudioProperties Audio properties
495 /// \ingroup Properties
496 ///@{
498 /// Volume (RW)
499 static int mp_property_volume(m_option_t * prop, int action, void *arg,
500 MPContext * mpctx)
503 if (!mpctx->sh_audio)
504 return M_PROPERTY_UNAVAILABLE;
506 switch (action) {
507 case M_PROPERTY_GET:
508 if (!arg)
509 return M_PROPERTY_ERROR;
510 mixer_getbothvolume(&mpctx->mixer, arg);
511 return M_PROPERTY_OK;
512 case M_PROPERTY_PRINT:{
513 float vol;
514 if (!arg)
515 return M_PROPERTY_ERROR;
516 mixer_getbothvolume(&mpctx->mixer, &vol);
517 return m_property_float_range(prop, action, arg, &vol);
519 case M_PROPERTY_STEP_UP:
520 case M_PROPERTY_STEP_DOWN:
521 case M_PROPERTY_SET:
522 break;
523 default:
524 return M_PROPERTY_NOT_IMPLEMENTED;
527 if (mpctx->edl_muted)
528 return M_PROPERTY_DISABLED;
529 mpctx->user_muted = 0;
531 switch (action) {
532 case M_PROPERTY_SET:
533 if (!arg)
534 return M_PROPERTY_ERROR;
535 M_PROPERTY_CLAMP(prop, *(float *) arg);
536 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
537 return M_PROPERTY_OK;
538 case M_PROPERTY_STEP_UP:
539 if (arg && *(float *) arg <= 0)
540 mixer_decvolume(&mpctx->mixer);
541 else
542 mixer_incvolume(&mpctx->mixer);
543 return M_PROPERTY_OK;
544 case M_PROPERTY_STEP_DOWN:
545 if (arg && *(float *) arg <= 0)
546 mixer_incvolume(&mpctx->mixer);
547 else
548 mixer_decvolume(&mpctx->mixer);
549 return M_PROPERTY_OK;
551 return M_PROPERTY_NOT_IMPLEMENTED;
554 /// Mute (RW)
555 static int mp_property_mute(m_option_t * prop, int action, void *arg,
556 MPContext * mpctx)
559 if (!mpctx->sh_audio)
560 return M_PROPERTY_UNAVAILABLE;
562 switch (action) {
563 case M_PROPERTY_SET:
564 if (mpctx->edl_muted)
565 return M_PROPERTY_DISABLED;
566 if (!arg)
567 return M_PROPERTY_ERROR;
568 if ((!!*(int *) arg) != mpctx->mixer.muted)
569 mixer_mute(&mpctx->mixer);
570 mpctx->user_muted = mpctx->mixer.muted;
571 return M_PROPERTY_OK;
572 case M_PROPERTY_STEP_UP:
573 case M_PROPERTY_STEP_DOWN:
574 if (mpctx->edl_muted)
575 return M_PROPERTY_DISABLED;
576 mixer_mute(&mpctx->mixer);
577 mpctx->user_muted = mpctx->mixer.muted;
578 return M_PROPERTY_OK;
579 case M_PROPERTY_PRINT:
580 if (!arg)
581 return M_PROPERTY_ERROR;
582 if (mpctx->edl_muted) {
583 *(char **) arg = strdup(MSGTR_EnabledEdl);
584 return M_PROPERTY_OK;
586 default:
587 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
592 /// Audio delay (RW)
593 static int mp_property_audio_delay(m_option_t * prop, int action,
594 void *arg, MPContext * mpctx)
596 if (!(mpctx->sh_audio && mpctx->sh_video))
597 return M_PROPERTY_UNAVAILABLE;
598 switch (action) {
599 case M_PROPERTY_SET:
600 case M_PROPERTY_STEP_UP:
601 case M_PROPERTY_STEP_DOWN:
602 if (!arg)
603 return M_PROPERTY_ERROR;
604 else {
605 float delay = audio_delay;
606 m_property_delay(prop, action, arg, &audio_delay);
607 if (mpctx->sh_audio)
608 mpctx->delay -= audio_delay - delay;
610 return M_PROPERTY_OK;
611 default:
612 return m_property_delay(prop, action, arg, &audio_delay);
616 /// Audio codec tag (RO)
617 static int mp_property_audio_format(m_option_t * prop, int action,
618 void *arg, MPContext * mpctx)
620 if (!mpctx->sh_audio)
621 return M_PROPERTY_UNAVAILABLE;
622 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
625 /// Audio codec name (RO)
626 static int mp_property_audio_codec(m_option_t * prop, int action,
627 void *arg, MPContext * mpctx)
629 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
630 return M_PROPERTY_UNAVAILABLE;
631 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
634 /// Audio bitrate (RO)
635 static int mp_property_audio_bitrate(m_option_t * prop, int action,
636 void *arg, MPContext * mpctx)
638 if (!mpctx->sh_audio)
639 return M_PROPERTY_UNAVAILABLE;
640 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
643 /// Samplerate (RO)
644 static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
645 MPContext * mpctx)
647 if (!mpctx->sh_audio)
648 return M_PROPERTY_UNAVAILABLE;
649 switch(action) {
650 case M_PROPERTY_PRINT:
651 if(!arg) return M_PROPERTY_ERROR;
652 *(char**)arg = malloc(16);
653 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
654 return M_PROPERTY_OK;
656 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
659 /// Number of channels (RO)
660 static int mp_property_channels(m_option_t * prop, int action, void *arg,
661 MPContext * mpctx)
663 if (!mpctx->sh_audio)
664 return M_PROPERTY_UNAVAILABLE;
665 switch (action) {
666 case M_PROPERTY_PRINT:
667 if (!arg)
668 return M_PROPERTY_ERROR;
669 switch (mpctx->sh_audio->channels) {
670 case 1:
671 *(char **) arg = strdup("mono");
672 break;
673 case 2:
674 *(char **) arg = strdup("stereo");
675 break;
676 default:
677 *(char **) arg = malloc(32);
678 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
680 return M_PROPERTY_OK;
682 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
685 /// Balance (RW)
686 static int mp_property_balance(m_option_t * prop, int action, void *arg,
687 MPContext * mpctx)
689 float bal;
691 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
692 return M_PROPERTY_UNAVAILABLE;
694 switch (action) {
695 case M_PROPERTY_GET:
696 if (!arg)
697 return M_PROPERTY_ERROR;
698 mixer_getbalance(&mpctx->mixer, arg);
699 return M_PROPERTY_OK;
700 case M_PROPERTY_PRINT: {
701 char** str = arg;
702 if (!arg)
703 return M_PROPERTY_ERROR;
704 mixer_getbalance(&mpctx->mixer, &bal);
705 if (bal == 0.f)
706 *str = strdup("center");
707 else if (bal == -1.f)
708 *str = strdup("left only");
709 else if (bal == 1.f)
710 *str = strdup("right only");
711 else {
712 unsigned right = (bal + 1.f) / 2.f * 100.f;
713 *str = malloc(sizeof("left xxx%, right xxx%"));
714 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
716 return M_PROPERTY_OK;
718 case M_PROPERTY_STEP_UP:
719 case M_PROPERTY_STEP_DOWN:
720 mixer_getbalance(&mpctx->mixer, &bal);
721 bal += (arg ? *(float*)arg : .1f) *
722 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
723 M_PROPERTY_CLAMP(prop, bal);
724 mixer_setbalance(&mpctx->mixer, bal);
725 return M_PROPERTY_OK;
726 case M_PROPERTY_SET:
727 if (!arg)
728 return M_PROPERTY_ERROR;
729 M_PROPERTY_CLAMP(prop, *(float*)arg);
730 mixer_setbalance(&mpctx->mixer, *(float*)arg);
731 return M_PROPERTY_OK;
733 return M_PROPERTY_NOT_IMPLEMENTED;
736 /// Selected audio id (RW)
737 static int mp_property_audio(m_option_t * prop, int action, void *arg,
738 MPContext * mpctx)
740 int current_id = -1, tmp;
742 switch (action) {
743 case M_PROPERTY_GET:
744 if (!mpctx->sh_audio)
745 return M_PROPERTY_UNAVAILABLE;
746 if (!arg)
747 return M_PROPERTY_ERROR;
748 *(int *) arg = audio_id;
749 return M_PROPERTY_OK;
750 case M_PROPERTY_PRINT:
751 if (!mpctx->sh_audio)
752 return M_PROPERTY_UNAVAILABLE;
753 if (!arg)
754 return M_PROPERTY_ERROR;
756 if (audio_id < 0)
757 *(char **) arg = strdup(MSGTR_Disabled);
758 else {
759 char lang[40] = MSGTR_Unknown;
760 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA)
761 demux_mkv_get_audio_lang(mpctx->demuxer, audio_id, lang, 9);
762 #ifdef USE_DVDREAD
763 else if (mpctx->stream->type == STREAMTYPE_DVD) {
764 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
765 if (code) {
766 lang[0] = code >> 8;
767 lang[1] = code;
768 lang[2] = 0;
771 #endif
773 #ifdef USE_DVDNAV
774 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
775 dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
776 #endif
777 *(char **) arg = malloc(64);
778 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
780 return M_PROPERTY_OK;
782 case M_PROPERTY_STEP_UP:
783 case M_PROPERTY_SET:
784 if (action == M_PROPERTY_SET && arg)
785 tmp = *((int *) arg);
786 else
787 tmp = -1;
788 current_id = mpctx->demuxer->audio->id;
789 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
790 if (audio_id == -2
791 || (audio_id > -1
792 && mpctx->demuxer->audio->id != current_id && current_id != -2))
793 uninit_player(INITED_AO | INITED_ACODEC);
794 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
795 sh_audio_t *sh2;
796 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
797 if (sh2) {
798 sh2->ds = mpctx->demuxer->audio;
799 mpctx->sh_audio = sh2;
800 reinit_audio_chain();
803 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
804 return M_PROPERTY_OK;
805 default:
806 return M_PROPERTY_NOT_IMPLEMENTED;
811 /// Selected video id (RW)
812 static int mp_property_video(m_option_t * prop, int action, void *arg,
813 MPContext * mpctx)
815 int current_id = -1, tmp;
817 switch (action) {
818 case M_PROPERTY_GET:
819 if (!mpctx->sh_video)
820 return M_PROPERTY_UNAVAILABLE;
821 if (!arg)
822 return M_PROPERTY_ERROR;
823 *(int *) arg = video_id;
824 return M_PROPERTY_OK;
825 case M_PROPERTY_PRINT:
826 if (!mpctx->sh_video)
827 return M_PROPERTY_UNAVAILABLE;
828 if (!arg)
829 return M_PROPERTY_ERROR;
831 if (video_id < 0)
832 *(char **) arg = strdup(MSGTR_Disabled);
833 else {
834 char lang[40] = MSGTR_Unknown;
835 *(char **) arg = malloc(64);
836 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
838 return M_PROPERTY_OK;
840 case M_PROPERTY_STEP_UP:
841 case M_PROPERTY_SET:
842 current_id = mpctx->demuxer->video->id;
843 if (action == M_PROPERTY_SET && arg)
844 tmp = *((int *) arg);
845 else
846 tmp = -1;
847 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
848 if (video_id == -2
849 || (video_id > -1 && mpctx->demuxer->video->id != current_id
850 && current_id != -2))
851 uninit_player(INITED_VCODEC |
852 (fixed_vo && video_id != -2 ? 0 : INITED_VO));
853 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
854 sh_video_t *sh2;
855 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
856 if (sh2) {
857 sh2->ds = mpctx->demuxer->video;
858 mpctx->sh_video = sh2;
859 reinit_video_chain();
862 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
863 return M_PROPERTY_OK;
865 default:
866 return M_PROPERTY_NOT_IMPLEMENTED;
870 static int mp_property_program(m_option_t * prop, int action, void *arg,
871 MPContext * mpctx)
873 demux_program_t prog;
875 switch (action) {
876 case M_PROPERTY_STEP_UP:
877 case M_PROPERTY_SET:
878 if (action == M_PROPERTY_SET && arg)
879 prog.progid = *((int *) arg);
880 else
881 prog.progid = -1;
882 if (demux_control
883 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
884 &prog) == DEMUXER_CTRL_NOTIMPL)
885 return M_PROPERTY_ERROR;
887 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
888 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
889 return M_PROPERTY_OK;
891 default:
892 return M_PROPERTY_NOT_IMPLEMENTED;
896 ///@}
898 /// \defgroup VideoProperties Video properties
899 /// \ingroup Properties
900 ///@{
902 /// Fullscreen state (RW)
903 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
904 MPContext * mpctx)
907 if (!mpctx->video_out)
908 return M_PROPERTY_UNAVAILABLE;
910 switch (action) {
911 case M_PROPERTY_SET:
912 if (!arg)
913 return M_PROPERTY_ERROR;
914 M_PROPERTY_CLAMP(prop, *(int *) arg);
915 if (vo_fs == !!*(int *) arg)
916 return M_PROPERTY_OK;
917 case M_PROPERTY_STEP_UP:
918 case M_PROPERTY_STEP_DOWN:
919 #ifdef HAVE_NEW_GUI
920 if (use_gui)
921 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
922 else
923 #endif
924 if (vo_config_count)
925 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
926 return M_PROPERTY_OK;
927 default:
928 return m_property_flag(prop, action, arg, &vo_fs);
932 static int mp_property_deinterlace(m_option_t * prop, int action,
933 void *arg, MPContext * mpctx)
935 int deinterlace;
936 vf_instance_t *vf;
937 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
938 return M_PROPERTY_UNAVAILABLE;
939 vf = mpctx->sh_video->vfilter;
940 switch (action) {
941 case M_PROPERTY_GET:
942 if (!arg)
943 return M_PROPERTY_ERROR;
944 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
945 return M_PROPERTY_OK;
946 case M_PROPERTY_SET:
947 if (!arg)
948 return M_PROPERTY_ERROR;
949 M_PROPERTY_CLAMP(prop, *(int *) arg);
950 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
951 return M_PROPERTY_OK;
952 case M_PROPERTY_STEP_UP:
953 case M_PROPERTY_STEP_DOWN:
954 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
955 deinterlace = !deinterlace;
956 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
957 return M_PROPERTY_OK;
959 return M_PROPERTY_NOT_IMPLEMENTED;
962 /// Panscan (RW)
963 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
964 MPContext * mpctx)
967 if (!mpctx->video_out
968 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
969 return M_PROPERTY_UNAVAILABLE;
971 switch (action) {
972 case M_PROPERTY_SET:
973 if (!arg)
974 return M_PROPERTY_ERROR;
975 M_PROPERTY_CLAMP(prop, *(float *) arg);
976 vo_panscan = *(float *) arg;
977 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
978 return M_PROPERTY_OK;
979 case M_PROPERTY_STEP_UP:
980 case M_PROPERTY_STEP_DOWN:
981 vo_panscan += (arg ? *(float *) arg : 0.1) *
982 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
983 if (vo_panscan > 1)
984 vo_panscan = 1;
985 else if (vo_panscan < 0)
986 vo_panscan = 0;
987 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
988 return M_PROPERTY_OK;
989 default:
990 return m_property_float_range(prop, action, arg, &vo_panscan);
994 /// Helper to set vo flags.
995 /** \ingroup PropertyImplHelper
997 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
998 int vo_ctrl, int *vo_var, MPContext * mpctx)
1001 if (!mpctx->video_out)
1002 return M_PROPERTY_UNAVAILABLE;
1004 switch (action) {
1005 case M_PROPERTY_SET:
1006 if (!arg)
1007 return M_PROPERTY_ERROR;
1008 M_PROPERTY_CLAMP(prop, *(int *) arg);
1009 if (*vo_var == !!*(int *) arg)
1010 return M_PROPERTY_OK;
1011 case M_PROPERTY_STEP_UP:
1012 case M_PROPERTY_STEP_DOWN:
1013 if (vo_config_count)
1014 mpctx->video_out->control(vo_ctrl, 0);
1015 return M_PROPERTY_OK;
1016 default:
1017 return m_property_flag(prop, action, arg, vo_var);
1021 /// Window always on top (RW)
1022 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
1023 MPContext * mpctx)
1025 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
1026 mpctx);
1029 /// Display in the root window (RW)
1030 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
1031 MPContext * mpctx)
1033 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1034 &vo_rootwin, mpctx);
1037 /// Show window borders (RW)
1038 static int mp_property_border(m_option_t * prop, int action, void *arg,
1039 MPContext * mpctx)
1041 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1042 &vo_border, mpctx);
1045 /// Framedropping state (RW)
1046 static int mp_property_framedropping(m_option_t * prop, int action,
1047 void *arg, MPContext * mpctx)
1050 if (!mpctx->sh_video)
1051 return M_PROPERTY_UNAVAILABLE;
1053 switch (action) {
1054 case M_PROPERTY_PRINT:
1055 if (!arg)
1056 return M_PROPERTY_ERROR;
1057 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1058 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1059 MSGTR_Disabled));
1060 return M_PROPERTY_OK;
1061 default:
1062 return m_property_choice(prop, action, arg, &frame_dropping);
1066 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1067 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
1068 MPContext * mpctx)
1070 int *gamma = prop->priv, r;
1072 if (!mpctx->sh_video)
1073 return M_PROPERTY_UNAVAILABLE;
1075 if (gamma[0] == 1000) {
1076 gamma[0] = 0;
1077 get_video_colors(mpctx->sh_video, prop->name, gamma);
1080 switch (action) {
1081 case M_PROPERTY_SET:
1082 if (!arg)
1083 return M_PROPERTY_ERROR;
1084 M_PROPERTY_CLAMP(prop, *(int *) arg);
1085 *gamma = *(int *) arg;
1086 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1087 if (r <= 0)
1088 break;
1089 return r;
1090 case M_PROPERTY_GET:
1091 if (!arg)
1092 return M_PROPERTY_ERROR;
1093 r = get_video_colors(mpctx->sh_video, prop->name, arg);
1094 if (r <= 0)
1095 break;
1096 return r;
1097 case M_PROPERTY_STEP_UP:
1098 case M_PROPERTY_STEP_DOWN:
1099 *gamma += (arg ? *(int *) arg : 1) *
1100 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1101 M_PROPERTY_CLAMP(prop, *gamma);
1102 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1103 if (r <= 0)
1104 break;
1105 return r;
1106 default:
1107 return M_PROPERTY_NOT_IMPLEMENTED;
1110 #ifdef USE_TV
1111 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1112 int l = strlen(prop->name);
1113 char tv_prop[3 + l + 1];
1114 sprintf(tv_prop, "tv_%s", prop->name);
1115 return mp_property_do(tv_prop, action, arg, mpctx);
1117 #endif
1119 return M_PROPERTY_UNAVAILABLE;
1122 /// VSync (RW)
1123 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1124 MPContext * mpctx)
1126 return m_property_flag(prop, action, arg, &vo_vsync);
1129 /// Video codec tag (RO)
1130 static int mp_property_video_format(m_option_t * prop, int action,
1131 void *arg, MPContext * mpctx)
1133 char* meta;
1134 if (!mpctx->sh_video)
1135 return M_PROPERTY_UNAVAILABLE;
1136 switch(action) {
1137 case M_PROPERTY_PRINT:
1138 if (!arg)
1139 return M_PROPERTY_ERROR;
1140 switch(mpctx->sh_video->format) {
1141 case 0x10000001:
1142 meta = strdup ("mpeg1"); break;
1143 case 0x10000002:
1144 meta = strdup ("mpeg2"); break;
1145 case 0x10000004:
1146 meta = strdup ("mpeg4"); break;
1147 case 0x10000005:
1148 meta = strdup ("h264"); break;
1149 default:
1150 if(mpctx->sh_video->format >= 0x20202020) {
1151 meta = malloc(5);
1152 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1153 } else {
1154 meta = malloc(20);
1155 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1158 *(char**)arg = meta;
1159 return M_PROPERTY_OK;
1161 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1164 /// Video codec name (RO)
1165 static int mp_property_video_codec(m_option_t * prop, int action,
1166 void *arg, MPContext * mpctx)
1168 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1169 return M_PROPERTY_UNAVAILABLE;
1170 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1174 /// Video bitrate (RO)
1175 static int mp_property_video_bitrate(m_option_t * prop, int action,
1176 void *arg, MPContext * mpctx)
1178 if (!mpctx->sh_video)
1179 return M_PROPERTY_UNAVAILABLE;
1180 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1183 /// Video display width (RO)
1184 static int mp_property_width(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_w);
1192 /// Video display height (RO)
1193 static int mp_property_height(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_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1201 /// Video fps (RO)
1202 static int mp_property_fps(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->fps);
1210 /// Video aspect (RO)
1211 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1212 MPContext * mpctx)
1214 if (!mpctx->sh_video)
1215 return M_PROPERTY_UNAVAILABLE;
1216 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1219 ///@}
1221 /// \defgroup SubProprties Subtitles properties
1222 /// \ingroup Properties
1223 ///@{
1225 /// Text subtitle position (RW)
1226 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1227 MPContext * mpctx)
1229 if (!mpctx->sh_video)
1230 return M_PROPERTY_UNAVAILABLE;
1232 switch (action) {
1233 case M_PROPERTY_SET:
1234 if (!arg)
1235 return M_PROPERTY_ERROR;
1236 case M_PROPERTY_STEP_UP:
1237 case M_PROPERTY_STEP_DOWN:
1238 vo_osd_changed(OSDTYPE_SUBTITLE);
1239 default:
1240 return m_property_int_range(prop, action, arg, &sub_pos);
1244 char *demux_lavf_sub_lang(demuxer_t *demuxer, int track_num);
1246 /// Selected subtitles (RW)
1247 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1248 MPContext * mpctx)
1250 demux_stream_t *const d_sub = mpctx->d_sub;
1251 const int global_sub_size = mpctx->global_sub_size;
1252 int source = -1, reset_spu = 0;
1253 char *sub_name;
1255 if (global_sub_size <= 0)
1256 return M_PROPERTY_UNAVAILABLE;
1258 switch (action) {
1259 case M_PROPERTY_GET:
1260 if (!arg)
1261 return M_PROPERTY_ERROR;
1262 *(int *) arg = mpctx->global_sub_pos;
1263 return M_PROPERTY_OK;
1264 case M_PROPERTY_PRINT:
1265 if (!arg)
1266 return M_PROPERTY_ERROR;
1267 *(char **) arg = malloc(64);
1268 (*(char **) arg)[63] = 0;
1269 sub_name = 0;
1270 if (subdata)
1271 sub_name = subdata->filename;
1272 #ifdef USE_ASS
1273 if (ass_track && ass_track->name)
1274 sub_name = ass_track->name;
1275 #endif
1276 if (sub_name) {
1277 char *tmp, *tmp2;
1278 tmp = sub_name;
1279 if ((tmp2 = strrchr(tmp, '/')))
1280 tmp = tmp2 + 1;
1282 snprintf(*(char **) arg, 63, "(%d) %s%s",
1283 mpctx->set_of_sub_pos + 1,
1284 strlen(tmp) < 20 ? "" : "...",
1285 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1286 return M_PROPERTY_OK;
1288 #ifdef USE_DVDNAV
1289 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1290 if (vo_spudec && dvdsub_id >= 0) {
1291 unsigned char lang[3];
1292 if (dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1293 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1294 return M_PROPERTY_OK;
1298 #endif
1300 #ifdef USE_LIBAVFORMAT
1301 if (mpctx->demuxer->type == DEMUXER_TYPE_LAVF && dvdsub_id >= 0) {
1302 char *lang = demux_lavf_sub_lang(mpctx->demuxer, dvdsub_id);
1303 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1304 return M_PROPERTY_OK;
1306 #endif
1307 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
1308 char lang[40] = MSGTR_Unknown;
1309 demux_mkv_get_sub_lang(mpctx->demuxer, dvdsub_id, lang, 9);
1310 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1311 return M_PROPERTY_OK;
1313 #ifdef HAVE_OGGVORBIS
1314 if (mpctx->demuxer->type == DEMUXER_TYPE_OGG && d_sub && dvdsub_id >= 0) {
1315 char *lang = demux_ogg_sub_lang(mpctx->demuxer, dvdsub_id);
1316 if (!lang)
1317 lang = MSGTR_Unknown;
1318 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1319 return M_PROPERTY_OK;
1321 #endif
1322 if (vo_vobsub && vobsub_id >= 0) {
1323 const char *language = MSGTR_Unknown;
1324 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1325 snprintf(*(char **) arg, 63, "(%d) %s",
1326 vobsub_id, language ? language : MSGTR_Unknown);
1327 return M_PROPERTY_OK;
1329 #ifdef USE_DVDREAD
1330 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1331 && dvdsub_id >= 0) {
1332 char lang[3];
1333 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1334 lang[0] = code >> 8;
1335 lang[1] = code;
1336 lang[2] = 0;
1337 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1338 return M_PROPERTY_OK;
1340 #endif
1341 if (dvdsub_id >= 0) {
1342 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1343 return M_PROPERTY_OK;
1345 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1346 return M_PROPERTY_OK;
1348 case M_PROPERTY_SET:
1349 if (!arg)
1350 return M_PROPERTY_ERROR;
1351 if (*(int *) arg < -1)
1352 *(int *) arg = -1;
1353 else if (*(int *) arg >= global_sub_size)
1354 *(int *) arg = global_sub_size - 1;
1355 mpctx->global_sub_pos = *(int *) arg;
1356 break;
1357 case M_PROPERTY_STEP_UP:
1358 mpctx->global_sub_pos += 2;
1359 mpctx->global_sub_pos =
1360 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1361 break;
1362 case M_PROPERTY_STEP_DOWN:
1363 mpctx->global_sub_pos += global_sub_size + 1;
1364 mpctx->global_sub_pos =
1365 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1366 break;
1367 default:
1368 return M_PROPERTY_NOT_IMPLEMENTED;
1371 if (mpctx->global_sub_pos >= 0)
1372 source = sub_source(mpctx);
1374 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1375 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1376 global_sub_size,
1377 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1378 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1379 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1380 mpctx->global_sub_pos, source);
1382 mpctx->set_of_sub_pos = -1;
1383 subdata = NULL;
1385 vobsub_id = -1;
1386 dvdsub_id = -1;
1387 if (d_sub) {
1388 if (d_sub->id > -2)
1389 reset_spu = 1;
1390 d_sub->id = -2;
1392 #ifdef USE_ASS
1393 ass_track = 0;
1394 #endif
1396 if (source == SUB_SOURCE_VOBSUB) {
1397 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1398 } else if (source == SUB_SOURCE_SUBS) {
1399 mpctx->set_of_sub_pos =
1400 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1401 #ifdef USE_ASS
1402 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1403 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1404 else
1405 #endif
1407 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1408 vo_osd_changed(OSDTYPE_SUBTITLE);
1410 } else if (source == SUB_SOURCE_DEMUX) {
1411 dvdsub_id =
1412 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1413 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1414 int i = 0;
1415 // default: assume 1:1 mapping of sid and stream id
1416 d_sub->id = dvdsub_id;
1417 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1418 for (i = 0; i < MAX_S_STREAMS; i++) {
1419 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1420 if (sh && sh->sid == dvdsub_id) {
1421 d_sub->id = i;
1422 d_sub->sh = sh;
1423 break;
1426 if (d_sub->sh && d_sub->id >= 0) {
1427 sh_sub_t *sh = d_sub->sh;
1428 if (sh->type == 'v')
1429 init_vo_spudec();
1430 #ifdef USE_ASS
1431 else if (ass_enabled && sh->type == 'a')
1432 ass_track = sh->ass_track;
1433 #endif
1434 } else {
1435 d_sub->id = -2;
1436 d_sub->sh = NULL;
1440 #ifdef USE_DVDREAD
1441 if (vo_spudec
1442 && (mpctx->stream->type == STREAMTYPE_DVD
1443 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1444 && dvdsub_id < 0 && reset_spu) {
1445 dvdsub_id = -2;
1446 d_sub->id = dvdsub_id;
1448 #endif
1449 update_subtitles(mpctx->sh_video, d_sub, 1);
1451 return M_PROPERTY_OK;
1454 /// Selected sub source (RW)
1455 static int mp_property_sub_source(m_option_t * prop, int action, void *arg,
1456 MPContext * mpctx)
1458 int source;
1459 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1460 return M_PROPERTY_UNAVAILABLE;
1462 switch (action) {
1463 case M_PROPERTY_GET:
1464 if (!arg)
1465 return M_PROPERTY_ERROR;
1466 *(int *) arg = sub_source(mpctx);
1467 return M_PROPERTY_OK;
1468 case M_PROPERTY_PRINT:
1469 if (!arg)
1470 return M_PROPERTY_ERROR;
1471 *(char **) arg = malloc(64);
1472 (*(char **) arg)[63] = 0;
1473 switch (sub_source(mpctx))
1475 case SUB_SOURCE_SUBS:
1476 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1477 break;
1478 case SUB_SOURCE_VOBSUB:
1479 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1480 break;
1481 case SUB_SOURCE_DEMUX:
1482 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1483 break;
1484 default:
1485 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1487 return M_PROPERTY_OK;
1488 case M_PROPERTY_SET:
1489 if (!arg)
1490 return M_PROPERTY_ERROR;
1491 M_PROPERTY_CLAMP(prop, *(int*)arg);
1492 if (*(int *) arg < 0)
1493 mpctx->global_sub_pos = -1;
1494 else if (*(int *) arg != sub_source(mpctx)) {
1495 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1496 return M_PROPERTY_UNAVAILABLE;
1497 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1499 break;
1500 case M_PROPERTY_STEP_UP:
1501 case M_PROPERTY_STEP_DOWN: {
1502 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1503 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1504 int step = (step_all > 0) ? 1 : -1;
1505 int cur_source = sub_source(mpctx);
1506 source = cur_source;
1507 while (step_all) {
1508 source += step;
1509 if (source >= SUB_SOURCES)
1510 source = -1;
1511 else if (source < -1)
1512 source = SUB_SOURCES - 1;
1513 if (source == cur_source || source == -1 ||
1514 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1515 step_all -= step;
1517 if (source == cur_source)
1518 return M_PROPERTY_OK;
1519 if (source == -1)
1520 mpctx->global_sub_pos = -1;
1521 else
1522 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1523 break;
1525 default:
1526 return M_PROPERTY_NOT_IMPLEMENTED;
1528 --mpctx->global_sub_pos;
1529 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1532 /// Selected subtitles from specific source (RW)
1533 static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg,
1534 MPContext * mpctx)
1536 int source, is_cur_source, offset;
1537 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1538 return M_PROPERTY_UNAVAILABLE;
1540 if (!strcmp(prop->name, "sub_file"))
1541 source = SUB_SOURCE_SUBS;
1542 else if (!strcmp(prop->name, "sub_vob"))
1543 source = SUB_SOURCE_VOBSUB;
1544 else if (!strcmp(prop->name, "sub_demux"))
1545 source = SUB_SOURCE_DEMUX;
1546 else
1547 return M_PROPERTY_ERROR;
1549 offset = mpctx->global_sub_indices[source];
1550 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1551 return M_PROPERTY_UNAVAILABLE;
1553 is_cur_source = sub_source(mpctx) == source;
1554 switch (action) {
1555 case M_PROPERTY_GET:
1556 if (!arg)
1557 return M_PROPERTY_ERROR;
1558 if (is_cur_source) {
1559 *(int *) arg = mpctx->global_sub_pos - offset;
1560 if (source == SUB_SOURCE_VOBSUB)
1561 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1563 else
1564 *(int *) arg = -1;
1565 return M_PROPERTY_OK;
1566 case M_PROPERTY_PRINT:
1567 if (!arg)
1568 return M_PROPERTY_ERROR;
1569 if (is_cur_source)
1570 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1571 *(char **) arg = malloc(64);
1572 (*(char **) arg)[63] = 0;
1573 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1574 return M_PROPERTY_OK;
1575 case M_PROPERTY_SET:
1576 if (!arg)
1577 return M_PROPERTY_ERROR;
1578 if (*(int *) arg >= 0) {
1579 int index = *(int *)arg;
1580 if (source == SUB_SOURCE_VOBSUB)
1581 index = vobsub_get_index_by_id(vo_vobsub, index);
1582 mpctx->global_sub_pos = offset + index;
1583 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1584 || sub_source(mpctx) != source) {
1585 mpctx->global_sub_pos = -1;
1586 *(int *) arg = -1;
1589 else
1590 mpctx->global_sub_pos = -1;
1591 break;
1592 case M_PROPERTY_STEP_UP:
1593 case M_PROPERTY_STEP_DOWN: {
1594 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1595 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1596 int step = (step_all > 0) ? 1 : -1;
1597 int max_sub_pos_for_source = -1;
1598 if (!is_cur_source)
1599 mpctx->global_sub_pos = -1;
1600 while (step_all) {
1601 if (mpctx->global_sub_pos == -1) {
1602 if (step > 0)
1603 mpctx->global_sub_pos = offset;
1604 else if (max_sub_pos_for_source == -1) {
1605 // Find max pos for specific source
1606 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1607 while (mpctx->global_sub_pos >= 0
1608 && sub_source(mpctx) != source)
1609 --mpctx->global_sub_pos;
1611 else
1612 mpctx->global_sub_pos = max_sub_pos_for_source;
1614 else {
1615 mpctx->global_sub_pos += step;
1616 if (mpctx->global_sub_pos < offset ||
1617 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1618 sub_source(mpctx) != source)
1619 mpctx->global_sub_pos = -1;
1621 step_all -= step;
1623 break;
1625 default:
1626 return M_PROPERTY_NOT_IMPLEMENTED;
1628 --mpctx->global_sub_pos;
1629 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1632 /// Subtitle delay (RW)
1633 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1634 MPContext * mpctx)
1636 if (!mpctx->sh_video)
1637 return M_PROPERTY_UNAVAILABLE;
1638 return m_property_delay(prop, action, arg, &sub_delay);
1641 /// Alignment of text subtitles (RW)
1642 static int mp_property_sub_alignment(m_option_t * prop, int action,
1643 void *arg, MPContext * mpctx)
1645 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1647 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1648 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1649 return M_PROPERTY_UNAVAILABLE;
1651 switch (action) {
1652 case M_PROPERTY_PRINT:
1653 if (!arg)
1654 return M_PROPERTY_ERROR;
1655 M_PROPERTY_CLAMP(prop, sub_alignment);
1656 *(char **) arg = strdup(name[sub_alignment]);
1657 return M_PROPERTY_OK;
1658 case M_PROPERTY_SET:
1659 if (!arg)
1660 return M_PROPERTY_ERROR;
1661 case M_PROPERTY_STEP_UP:
1662 case M_PROPERTY_STEP_DOWN:
1663 vo_osd_changed(OSDTYPE_SUBTITLE);
1664 default:
1665 return m_property_choice(prop, action, arg, &sub_alignment);
1669 /// Subtitle visibility (RW)
1670 static int mp_property_sub_visibility(m_option_t * prop, int action,
1671 void *arg, MPContext * mpctx)
1673 if (!mpctx->sh_video)
1674 return M_PROPERTY_UNAVAILABLE;
1676 switch (action) {
1677 case M_PROPERTY_SET:
1678 if (!arg)
1679 return M_PROPERTY_ERROR;
1680 case M_PROPERTY_STEP_UP:
1681 case M_PROPERTY_STEP_DOWN:
1682 vo_osd_changed(OSDTYPE_SUBTITLE);
1683 if (vo_spudec)
1684 vo_osd_changed(OSDTYPE_SPU);
1685 default:
1686 return m_property_flag(prop, action, arg, &sub_visibility);
1690 /// Show only forced subtitles (RW)
1691 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1692 void *arg, MPContext * mpctx)
1694 if (!vo_spudec)
1695 return M_PROPERTY_UNAVAILABLE;
1697 switch (action) {
1698 case M_PROPERTY_SET:
1699 if (!arg)
1700 return M_PROPERTY_ERROR;
1701 case M_PROPERTY_STEP_UP:
1702 case M_PROPERTY_STEP_DOWN:
1703 m_property_flag(prop, action, arg, &forced_subs_only);
1704 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1705 return M_PROPERTY_OK;
1706 default:
1707 return m_property_flag(prop, action, arg, &forced_subs_only);
1712 #ifdef HAVE_FREETYPE
1713 /// Subtitle scale (RW)
1714 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1715 MPContext * mpctx)
1718 switch (action) {
1719 case M_PROPERTY_SET:
1720 if (!arg)
1721 return M_PROPERTY_ERROR;
1722 M_PROPERTY_CLAMP(prop, *(float *) arg);
1723 text_font_scale_factor = *(float *) arg;
1724 force_load_font = 1;
1725 return M_PROPERTY_OK;
1726 case M_PROPERTY_STEP_UP:
1727 case M_PROPERTY_STEP_DOWN:
1728 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1729 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1730 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1731 force_load_font = 1;
1732 return M_PROPERTY_OK;
1733 default:
1734 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1737 #endif
1739 ///@}
1741 /// \defgroup TVProperties TV properties
1742 /// \ingroup Properties
1743 ///@{
1745 #ifdef USE_TV
1747 /// TV color settings (RW)
1748 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1749 MPContext * mpctx)
1751 int r, val;
1752 tvi_handle_t *tvh = mpctx->demuxer->priv;
1753 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1754 return M_PROPERTY_UNAVAILABLE;
1756 switch (action) {
1757 case M_PROPERTY_SET:
1758 if (!arg)
1759 return M_PROPERTY_ERROR;
1760 M_PROPERTY_CLAMP(prop, *(int *) arg);
1761 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1762 case M_PROPERTY_GET:
1763 return tv_get_color_options(tvh, (int) prop->priv, arg);
1764 case M_PROPERTY_STEP_UP:
1765 case M_PROPERTY_STEP_DOWN:
1766 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1767 if (!r)
1768 return M_PROPERTY_ERROR;
1769 val += (arg ? *(int *) arg : 1) *
1770 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1771 M_PROPERTY_CLAMP(prop, val);
1772 return tv_set_color_options(tvh, (int) prop->priv, val);
1774 return M_PROPERTY_ERROR;
1776 return M_PROPERTY_NOT_IMPLEMENTED;
1779 #endif
1781 #ifdef HAVE_TV_TELETEXT
1782 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1783 MPContext * mpctx)
1785 int val,result;
1786 int base_ioctl=(int)prop->priv;
1788 for teletext's GET,SET,STEP ioctls this is not 0
1789 SET is GET+1
1790 STEP is GET+2
1792 tvi_handle_t *tvh = mpctx->demuxer->priv;
1793 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1794 return M_PROPERTY_UNAVAILABLE;
1795 if(!base_ioctl)
1796 return M_PROPERTY_ERROR;
1798 switch (action) {
1799 case M_PROPERTY_GET:
1800 if (!arg)
1801 return M_PROPERTY_ERROR;
1802 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1803 break;
1804 case M_PROPERTY_SET:
1805 if (!arg)
1806 return M_PROPERTY_ERROR;
1807 M_PROPERTY_CLAMP(prop, *(int *) arg);
1808 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1809 break;
1810 case M_PROPERTY_STEP_UP:
1811 case M_PROPERTY_STEP_DOWN:
1812 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1813 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1814 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1815 break;
1816 default:
1817 return M_PROPERTY_NOT_IMPLEMENTED;
1820 return (result==TVI_CONTROL_TRUE?M_PROPERTY_OK:M_PROPERTY_ERROR);
1823 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1824 MPContext * mpctx)
1826 tvi_handle_t *tvh = mpctx->demuxer->priv;
1827 int result;
1828 int val;
1830 //with tvh==NULL will fail too
1831 result=mp_property_teletext_common(prop,action,arg,mpctx);
1832 if(result!=M_PROPERTY_OK)
1833 return result;
1835 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1836 mp_input_set_section("teletext");
1837 else
1838 mp_input_set_section("tv");
1839 return M_PROPERTY_OK;
1842 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1843 MPContext * mpctx)
1845 tvi_handle_t *tvh = mpctx->demuxer->priv;
1846 int result;
1847 int val;
1848 switch(action){
1849 case M_PROPERTY_STEP_UP:
1850 case M_PROPERTY_STEP_DOWN:
1851 //This should be handled separately
1852 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1853 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1854 break;
1855 default:
1856 result=mp_property_teletext_common(prop,action,arg,mpctx);
1858 return result;
1862 #endif /* HAVE_TV_TELETEXT */
1864 ///@}
1866 /// All properties available in MPlayer.
1867 /** \ingroup Properties
1869 static m_option_t mp_properties[] = {
1870 // General
1871 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1872 M_OPT_RANGE, 0, 3, NULL },
1873 { "loop", mp_property_loop, CONF_TYPE_INT,
1874 M_OPT_MIN, -1, 0, NULL },
1875 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1876 M_OPT_RANGE, 0.01, 100.0, NULL },
1877 { "filename", mp_property_filename, CONF_TYPE_STRING,
1878 0, 0, 0, NULL },
1879 { "path", mp_property_path, CONF_TYPE_STRING,
1880 0, 0, 0, NULL },
1881 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1882 0, 0, 0, NULL },
1883 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1884 M_OPT_MIN, 0, 0, NULL },
1885 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1886 M_OPT_MIN, 0, 0, NULL },
1887 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1888 M_OPT_MIN, 0, 0, NULL },
1889 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1890 M_OPT_MIN, 0, 0, NULL },
1891 { "length", mp_property_length, CONF_TYPE_TIME,
1892 M_OPT_MIN, 0, 0, NULL },
1893 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1894 M_OPT_RANGE, 0, 100, NULL },
1895 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1896 M_OPT_MIN, 0, 0, NULL },
1897 { "chapter", mp_property_chapter, CONF_TYPE_INT,
1898 M_OPT_MIN, 1, 0, NULL },
1899 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
1900 0, 0, 0, NULL },
1902 // Audio
1903 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
1904 M_OPT_RANGE, 0, 100, NULL },
1905 { "mute", mp_property_mute, CONF_TYPE_FLAG,
1906 M_OPT_RANGE, 0, 1, NULL },
1907 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
1908 M_OPT_RANGE, -100, 100, NULL },
1909 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
1910 0, 0, 0, NULL },
1911 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
1912 0, 0, 0, NULL },
1913 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
1914 0, 0, 0, NULL },
1915 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
1916 0, 0, 0, NULL },
1917 { "channels", mp_property_channels, CONF_TYPE_INT,
1918 0, 0, 0, NULL },
1919 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
1920 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
1921 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
1922 M_OPT_RANGE, -1, 1, NULL },
1924 // Video
1925 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
1926 M_OPT_RANGE, 0, 1, NULL },
1927 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
1928 M_OPT_RANGE, 0, 1, NULL },
1929 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
1930 M_OPT_RANGE, 0, 1, NULL },
1931 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
1932 M_OPT_RANGE, 0, 1, NULL },
1933 { "border", mp_property_border, CONF_TYPE_FLAG,
1934 M_OPT_RANGE, 0, 1, NULL },
1935 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
1936 M_OPT_RANGE, 0, 2, NULL },
1937 { "gamma", mp_property_gamma, CONF_TYPE_INT,
1938 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
1939 { "brightness", mp_property_gamma, CONF_TYPE_INT,
1940 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
1941 { "contrast", mp_property_gamma, CONF_TYPE_INT,
1942 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
1943 { "saturation", mp_property_gamma, CONF_TYPE_INT,
1944 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
1945 { "hue", mp_property_gamma, CONF_TYPE_INT,
1946 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
1947 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
1948 M_OPT_RANGE, 0, 1, NULL },
1949 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
1950 M_OPT_RANGE, 0, 1, NULL },
1951 { "video_format", mp_property_video_format, CONF_TYPE_INT,
1952 0, 0, 0, NULL },
1953 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
1954 0, 0, 0, NULL },
1955 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
1956 0, 0, 0, NULL },
1957 { "width", mp_property_width, CONF_TYPE_INT,
1958 0, 0, 0, NULL },
1959 { "height", mp_property_height, CONF_TYPE_INT,
1960 0, 0, 0, NULL },
1961 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
1962 0, 0, 0, NULL },
1963 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
1964 0, 0, 0, NULL },
1965 { "switch_video", mp_property_video, CONF_TYPE_INT,
1966 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
1967 { "switch_program", mp_property_program, CONF_TYPE_INT,
1968 CONF_RANGE, -1, 65535, NULL },
1970 // Subs
1971 { "sub", mp_property_sub, CONF_TYPE_INT,
1972 M_OPT_MIN, -1, 0, NULL },
1973 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
1974 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
1975 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
1976 M_OPT_MIN, -1, 0, NULL },
1977 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
1978 M_OPT_MIN, -1, 0, NULL },
1979 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
1980 M_OPT_MIN, -1, 0, NULL },
1981 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
1982 0, 0, 0, NULL },
1983 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
1984 M_OPT_RANGE, 0, 100, NULL },
1985 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
1986 M_OPT_RANGE, 0, 2, NULL },
1987 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
1988 M_OPT_RANGE, 0, 1, NULL },
1989 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
1990 M_OPT_RANGE, 0, 1, NULL },
1991 #ifdef HAVE_FREETYPE
1992 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
1993 M_OPT_RANGE, 0, 100, NULL },
1994 #endif
1996 #ifdef USE_TV
1997 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
1998 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
1999 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2000 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2001 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2002 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2003 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2004 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2005 #endif
2007 #ifdef HAVE_TV_TELETEXT
2008 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2009 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2010 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2011 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2012 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2013 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2014 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2015 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2016 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2017 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2018 #endif
2020 { NULL, NULL, NULL, 0, 0, 0, NULL }
2024 int mp_property_do(const char *name, int action, void *val, void *ctx)
2026 return m_property_do(mp_properties, name, action, val, ctx);
2029 char* mp_property_print(const char *name, void* ctx)
2031 char* ret = NULL;
2032 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2033 return NULL;
2034 return ret;
2037 char *property_expand_string(MPContext * mpctx, char *str)
2039 return m_properties_expand_string(mp_properties, str, mpctx);
2042 void property_print_help(void)
2044 m_properties_print_help_list(mp_properties);
2048 ///@}
2049 // Properties group
2053 * \defgroup Command2Property Command to property bridge
2055 * It is used to handle most commands that just set a property
2056 * and optionally display something on the OSD.
2057 * Two kinds of commands are handled: adjust or toggle.
2059 * Adjust commands take 1 or 2 parameters: <value> <abs>
2060 * If <abs> is non-zero the property is set to the given value
2061 * otherwise it is adjusted.
2063 * Toggle commands take 0 or 1 parameters. With no parameter
2064 * or a value less than the property minimum it just steps the
2065 * property to its next value. Otherwise it sets it to the given
2066 * value.
2071 /// List of the commands that can be handled by setting a property.
2072 static struct {
2073 /// property name
2074 const char *name;
2075 /// cmd id
2076 int cmd;
2077 /// set/adjust or toggle command
2078 int toggle;
2079 /// progressbar type
2080 int osd_progbar;
2081 /// osd msg id if it must be shared
2082 int osd_id;
2083 /// osd msg template
2084 const char *osd_msg;
2085 } set_prop_cmd[] = {
2086 // general
2087 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2088 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2089 // audio
2090 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2091 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2092 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2093 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2094 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2095 // video
2096 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2097 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2098 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2099 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2100 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2101 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2102 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2103 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2104 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2105 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2106 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2107 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2108 // subs
2109 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2110 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2111 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2112 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2113 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2114 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2115 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2116 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2117 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2118 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2119 #ifdef HAVE_FREETYPE
2120 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2121 #endif
2122 #ifdef USE_TV
2123 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2124 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2125 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2126 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2127 #endif
2128 { NULL, 0, 0, 0, -1, NULL }
2132 /// Handle commands that set a property.
2133 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
2135 int i, r;
2136 m_option_t* prop;
2137 const char *pname;
2139 // look for the command
2140 for (i = 0; set_prop_cmd[i].name; i++)
2141 if (set_prop_cmd[i].cmd == cmd->id)
2142 break;
2143 if (!(pname = set_prop_cmd[i].name))
2144 return 0;
2146 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2147 return 0;
2149 // toggle command
2150 if (set_prop_cmd[i].toggle) {
2151 // set to value
2152 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2153 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2154 else
2155 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2156 } else if (cmd->args[1].v.i) //set
2157 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2158 else // adjust
2159 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2161 if (r <= 0)
2162 return 1;
2164 if (set_prop_cmd[i].osd_progbar) {
2165 if (prop->type == CONF_TYPE_INT) {
2166 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2167 set_osd_bar(set_prop_cmd[i].osd_progbar,
2168 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2169 } else if (prop->type == CONF_TYPE_FLOAT) {
2170 float f;
2171 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2172 set_osd_bar(set_prop_cmd[i].osd_progbar,
2173 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2174 } else
2175 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2176 "Property use an unsupported type.\n");
2177 return 1;
2180 if (set_prop_cmd[i].osd_msg) {
2181 char *val = mp_property_print(pname, mpctx);
2182 if (val) {
2183 set_osd_msg(set_prop_cmd[i].osd_id >=
2184 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2185 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2186 free(val);
2189 return 1;
2193 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
2195 sh_audio_t * const sh_audio = mpctx->sh_audio;
2196 sh_video_t * const sh_video = mpctx->sh_video;
2197 int brk_cmd = 0;
2198 if (!set_property_command(mpctx, cmd))
2199 switch (cmd->id) {
2200 case MP_CMD_SEEK:{
2201 float v;
2202 int abs;
2203 if (sh_video)
2204 mpctx->osd_show_percentage = sh_video->fps;
2205 v = cmd->args[0].v.f;
2206 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2207 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2208 abs_seek_pos = 1;
2209 if (sh_video)
2210 mpctx->osd_function =
2211 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2212 rel_seek_secs = v;
2213 } else if (abs) { /* Absolute seek by percentage */
2214 abs_seek_pos = 3;
2215 if (sh_video)
2216 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2217 rel_seek_secs = v / 100.0;
2218 } else {
2219 rel_seek_secs += v;
2220 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2222 brk_cmd = 1;
2224 break;
2226 case MP_CMD_SET_PROPERTY:{
2227 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2228 cmd->args[1].v.s, mpctx);
2229 if (r == M_PROPERTY_UNKNOWN)
2230 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2231 "Unknown property: '%s'\n", cmd->args[0].v.s);
2232 else if (r <= 0)
2233 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2234 "Failed to set property '%s' to '%s'.\n",
2235 cmd->args[0].v.s, cmd->args[1].v.s);
2237 break;
2239 case MP_CMD_STEP_PROPERTY:{
2240 void* arg = NULL;
2241 int r,i;
2242 double d;
2243 off_t o;
2244 if (cmd->args[1].v.f) {
2245 m_option_t* prop;
2246 if((r = mp_property_do(cmd->args[0].v.s,
2247 M_PROPERTY_GET_TYPE,
2248 &prop, mpctx)) <= 0)
2249 goto step_prop_err;
2250 if(prop->type == CONF_TYPE_INT ||
2251 prop->type == CONF_TYPE_FLAG)
2252 i = cmd->args[1].v.f, arg = &i;
2253 else if(prop->type == CONF_TYPE_FLOAT)
2254 arg = &cmd->args[1].v.f;
2255 else if(prop->type == CONF_TYPE_DOUBLE ||
2256 prop->type == CONF_TYPE_TIME)
2257 d = cmd->args[1].v.f, arg = &d;
2258 else if(prop->type == CONF_TYPE_POSITION)
2259 o = cmd->args[1].v.f, arg = &o;
2260 else
2261 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2262 "Ignoring step size stepping property '%s'.\n",
2263 cmd->args[0].v.s);
2265 r = mp_property_do(cmd->args[0].v.s,
2266 cmd->args[2].v.i < 0 ?
2267 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2268 arg, mpctx);
2269 step_prop_err:
2270 if (r == M_PROPERTY_UNKNOWN)
2271 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2272 "Unknown property: '%s'\n", cmd->args[0].v.s);
2273 else if (r <= 0)
2274 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2275 "Failed to increment property '%s' by %f.\n",
2276 cmd->args[0].v.s, cmd->args[1].v.f);
2278 break;
2280 case MP_CMD_GET_PROPERTY:{
2281 char *tmp;
2282 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2283 &tmp, mpctx) <= 0) {
2284 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2285 "Failed to get value of property '%s'.\n",
2286 cmd->args[0].v.s);
2287 break;
2289 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2290 cmd->args[0].v.s, tmp);
2291 free(tmp);
2293 break;
2295 case MP_CMD_EDL_MARK:
2296 if (edl_fd) {
2297 float v = sh_video ? sh_video->pts :
2298 playing_audio_pts(sh_audio, mpctx->d_audio,
2299 mpctx->audio_out);
2301 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2302 mpctx->begin_skip = v;
2303 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2304 } else {
2305 if (mpctx->begin_skip > v)
2306 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2307 else {
2308 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2309 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2311 mpctx->begin_skip = MP_NOPTS_VALUE;
2314 break;
2316 case MP_CMD_SWITCH_RATIO:
2317 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2318 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2319 else
2320 movie_aspect = cmd->args[0].v.f;
2321 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2322 break;
2324 case MP_CMD_SPEED_INCR:{
2325 float v = cmd->args[0].v.f;
2326 playback_speed += v;
2327 build_afilter_chain(sh_audio, &ao_data);
2328 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2329 playback_speed);
2330 } break;
2332 case MP_CMD_SPEED_MULT:{
2333 float v = cmd->args[0].v.f;
2334 playback_speed *= v;
2335 build_afilter_chain(sh_audio, &ao_data);
2336 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2337 playback_speed);
2338 } break;
2340 case MP_CMD_SPEED_SET:{
2341 float v = cmd->args[0].v.f;
2342 playback_speed = v;
2343 build_afilter_chain(sh_audio, &ao_data);
2344 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2345 playback_speed);
2346 } break;
2348 case MP_CMD_FRAME_STEP:
2349 case MP_CMD_PAUSE:
2350 cmd->pausing = 1;
2351 brk_cmd = 1;
2352 break;
2354 case MP_CMD_FILE_FILTER:
2355 file_filter = cmd->args[0].v.i;
2356 break;
2358 case MP_CMD_QUIT:
2359 exit_player_with_rc(MSGTR_Exit_quit,
2360 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2362 case MP_CMD_PLAY_TREE_STEP:{
2363 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2364 int force = cmd->args[1].v.i;
2366 #ifdef HAVE_NEW_GUI
2367 if (use_gui) {
2368 int i = 0;
2369 if (n > 0)
2370 for (i = 0; i < n; i++)
2371 mplNext();
2372 else
2373 for (i = 0; i < -1 * n; i++)
2374 mplPrev();
2375 } else
2376 #endif
2378 if (!force && mpctx->playtree_iter) {
2379 play_tree_iter_t *i =
2380 play_tree_iter_new_copy(mpctx->playtree_iter);
2381 if (play_tree_iter_step(i, n, 0) ==
2382 PLAY_TREE_ITER_ENTRY)
2383 mpctx->eof =
2384 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2385 play_tree_iter_free(i);
2386 } else
2387 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2388 if (mpctx->eof)
2389 mpctx->play_tree_step = n;
2390 brk_cmd = 1;
2393 break;
2395 case MP_CMD_PLAY_TREE_UP_STEP:{
2396 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2397 int force = cmd->args[1].v.i;
2399 if (!force && mpctx->playtree_iter) {
2400 play_tree_iter_t *i =
2401 play_tree_iter_new_copy(mpctx->playtree_iter);
2402 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2403 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2404 play_tree_iter_free(i);
2405 } else
2406 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2407 brk_cmd = 1;
2409 break;
2411 case MP_CMD_PLAY_ALT_SRC_STEP:
2412 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2413 int v = cmd->args[0].v.i;
2414 if (v > 0
2415 && mpctx->playtree_iter->file <
2416 mpctx->playtree_iter->num_files)
2417 mpctx->eof = PT_NEXT_SRC;
2418 else if (v < 0 && mpctx->playtree_iter->file > 1)
2419 mpctx->eof = PT_PREV_SRC;
2421 brk_cmd = 1;
2422 break;
2424 case MP_CMD_SUB_STEP:
2425 if (sh_video) {
2426 int movement = cmd->args[0].v.i;
2427 step_sub(subdata, sh_video->pts, movement);
2428 #ifdef USE_ASS
2429 if (ass_track)
2430 sub_delay +=
2431 ass_step_sub(ass_track,
2432 (sh_video->pts +
2433 sub_delay) * 1000 + .5, movement) / 1000.;
2434 #endif
2435 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2436 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2438 break;
2440 case MP_CMD_SUB_LOG:
2441 log_sub();
2442 break;
2444 case MP_CMD_OSD:{
2445 int v = cmd->args[0].v.i;
2446 int max = (term_osd
2447 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2448 if (osd_level > max)
2449 osd_level = max;
2450 if (v < 0)
2451 osd_level = (osd_level + 1) % (max + 1);
2452 else
2453 osd_level = v > max ? max : v;
2454 /* Show OSD state when disabled, but not when an explicit
2455 argument is given to the OSD command, i.e. in slave mode. */
2456 if (v == -1 && osd_level <= 1)
2457 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2458 MSGTR_OSDosd,
2459 osd_level ? MSGTR_OSDenabled :
2460 MSGTR_OSDdisabled);
2461 else
2462 rm_osd_msg(OSD_MSG_OSD_STATUS);
2464 break;
2466 case MP_CMD_OSD_SHOW_TEXT:
2467 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2468 (cmd->args[1].v.i <
2469 0 ? osd_duration : cmd->args[1].v.i),
2470 "%-.63s", cmd->args[0].v.s);
2471 break;
2473 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2474 char *txt = m_properties_expand_string(mp_properties,
2475 cmd->args[0].v.s,
2476 mpctx);
2477 /* if no argument supplied take default osd_duration, else <arg> ms. */
2478 if (txt) {
2479 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2480 (cmd->args[1].v.i <
2481 0 ? osd_duration : cmd->args[1].v.i),
2482 "%-.63s", txt);
2483 free(txt);
2486 break;
2488 case MP_CMD_LOADFILE:{
2489 play_tree_t *e = play_tree_new();
2490 play_tree_add_file(e, cmd->args[0].v.s);
2492 if (cmd->args[1].v.i) // append
2493 play_tree_append_entry(mpctx->playtree, e);
2494 else {
2495 // Go back to the starting point.
2496 while (play_tree_iter_up_step
2497 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2498 /* NOP */ ;
2499 play_tree_free_list(mpctx->playtree->child, 1);
2500 play_tree_set_child(mpctx->playtree, e);
2501 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2502 mpctx->eof = PT_NEXT_SRC;
2504 brk_cmd = 1;
2506 break;
2508 case MP_CMD_LOADLIST:{
2509 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2510 if (!e)
2511 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2512 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2513 else {
2514 if (cmd->args[1].v.i) // append
2515 play_tree_append_entry(mpctx->playtree, e);
2516 else {
2517 // Go back to the starting point.
2518 while (play_tree_iter_up_step
2519 (mpctx->playtree_iter, 0, 1)
2520 != PLAY_TREE_ITER_END)
2521 /* NOP */ ;
2522 play_tree_free_list(mpctx->playtree->child, 1);
2523 play_tree_set_child(mpctx->playtree, e);
2524 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2525 mpctx->eof = PT_NEXT_SRC;
2528 brk_cmd = 1;
2530 break;
2532 #ifdef USE_RADIO
2533 case MP_CMD_RADIO_STEP_CHANNEL:
2534 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2535 int v = cmd->args[0].v.i;
2536 if (v > 0)
2537 radio_step_channel(mpctx->demuxer->stream,
2538 RADIO_CHANNEL_HIGHER);
2539 else
2540 radio_step_channel(mpctx->demuxer->stream,
2541 RADIO_CHANNEL_LOWER);
2542 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2543 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2544 MSGTR_OSDChannel,
2545 radio_get_channel_name(mpctx->demuxer->stream));
2548 break;
2550 case MP_CMD_RADIO_SET_CHANNEL:
2551 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2552 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2553 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2554 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2555 MSGTR_OSDChannel,
2556 radio_get_channel_name(mpctx->demuxer->stream));
2559 break;
2561 case MP_CMD_RADIO_SET_FREQ:
2562 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2563 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2564 break;
2566 case MP_CMD_RADIO_STEP_FREQ:
2567 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2568 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2569 break;
2570 #endif
2572 #ifdef USE_TV
2573 case MP_CMD_TV_START_SCAN:
2574 if (mpctx->file_format == DEMUXER_TYPE_TV)
2575 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2576 break;
2577 case MP_CMD_TV_SET_FREQ:
2578 if (mpctx->file_format == DEMUXER_TYPE_TV)
2579 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2580 cmd->args[0].v.f * 16.0);
2581 #ifdef HAVE_PVR
2582 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2583 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2584 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2585 pvr_get_current_channelname (mpctx->stream),
2586 pvr_get_current_stationname (mpctx->stream));
2588 #endif /* HAVE_PVR */
2589 break;
2591 case MP_CMD_TV_STEP_FREQ:
2592 if (mpctx->file_format == DEMUXER_TYPE_TV)
2593 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2594 cmd->args[0].v.f * 16.0);
2595 #ifdef HAVE_PVR
2596 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2597 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2598 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2599 pvr_get_current_channelname (mpctx->stream),
2600 pvr_get_current_frequency (mpctx->stream));
2602 #endif /* HAVE_PVR */
2603 break;
2605 case MP_CMD_TV_SET_NORM:
2606 if (mpctx->file_format == DEMUXER_TYPE_TV)
2607 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2608 cmd->args[0].v.s);
2609 break;
2611 case MP_CMD_TV_STEP_CHANNEL:{
2612 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2613 int v = cmd->args[0].v.i;
2614 if (v > 0) {
2615 tv_step_channel((tvi_handle_t *) (mpctx->
2616 demuxer->priv),
2617 TV_CHANNEL_HIGHER);
2618 } else {
2619 tv_step_channel((tvi_handle_t *) (mpctx->
2620 demuxer->priv),
2621 TV_CHANNEL_LOWER);
2623 if (tv_channel_list) {
2624 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2625 MSGTR_OSDChannel, tv_channel_current->name);
2626 //vo_osd_changed(OSDTYPE_SUBTITLE);
2629 #ifdef HAVE_PVR
2630 else if (mpctx->stream &&
2631 mpctx->stream->type == STREAMTYPE_PVR) {
2632 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2633 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2634 pvr_get_current_channelname (mpctx->stream),
2635 pvr_get_current_stationname (mpctx->stream));
2637 #endif /* HAVE_PVR */
2639 #ifdef HAS_DVBIN_SUPPORT
2640 if (mpctx->stream->type == STREAMTYPE_DVB) {
2641 int dir;
2642 int v = cmd->args[0].v.i;
2644 mpctx->last_dvb_step = v;
2645 if (v > 0)
2646 dir = DVB_CHANNEL_HIGHER;
2647 else
2648 dir = DVB_CHANNEL_LOWER;
2651 if (dvb_step_channel(mpctx->stream, dir))
2652 mpctx->eof = mpctx->dvbin_reopen = 1;
2654 #endif /* HAS_DVBIN_SUPPORT */
2655 break;
2657 case MP_CMD_TV_SET_CHANNEL:
2658 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2659 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2660 cmd->args[0].v.s);
2661 if (tv_channel_list) {
2662 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2663 MSGTR_OSDChannel, tv_channel_current->name);
2664 //vo_osd_changed(OSDTYPE_SUBTITLE);
2667 #ifdef HAVE_PVR
2668 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2669 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2670 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2671 pvr_get_current_channelname (mpctx->stream),
2672 pvr_get_current_stationname (mpctx->stream));
2674 #endif /* HAVE_PVR */
2675 break;
2677 #ifdef HAS_DVBIN_SUPPORT
2678 case MP_CMD_DVB_SET_CHANNEL:
2679 if (mpctx->stream->type == STREAMTYPE_DVB) {
2680 mpctx->last_dvb_step = 1;
2682 if (dvb_set_channel
2683 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2684 mpctx->eof = mpctx->dvbin_reopen = 1;
2686 break;
2687 #endif /* HAS_DVBIN_SUPPORT */
2689 case MP_CMD_TV_LAST_CHANNEL:
2690 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2691 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2692 if (tv_channel_list) {
2693 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2694 MSGTR_OSDChannel, tv_channel_current->name);
2695 //vo_osd_changed(OSDTYPE_SUBTITLE);
2698 #ifdef HAVE_PVR
2699 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2700 pvr_set_lastchannel (mpctx->stream);
2701 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2702 pvr_get_current_channelname (mpctx->stream),
2703 pvr_get_current_stationname (mpctx->stream));
2705 #endif /* HAVE_PVR */
2706 break;
2708 case MP_CMD_TV_STEP_NORM:
2709 if (mpctx->file_format == DEMUXER_TYPE_TV)
2710 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2711 break;
2713 case MP_CMD_TV_STEP_CHANNEL_LIST:
2714 if (mpctx->file_format == DEMUXER_TYPE_TV)
2715 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2716 break;
2717 #ifdef HAVE_TV_TELETEXT
2718 case MP_CMD_TV_TELETEXT_ADD_DEC:
2720 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2721 if (mpctx->file_format == DEMUXER_TYPE_TV)
2722 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2723 break;
2725 case MP_CMD_TV_TELETEXT_GO_LINK:
2727 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2728 if (mpctx->file_format == DEMUXER_TYPE_TV)
2729 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2730 break;
2732 #endif /* HAVE_TV_TELETEXT */
2733 #endif /* USE_TV */
2735 case MP_CMD_SUB_LOAD:
2736 if (sh_video) {
2737 int n = mpctx->set_of_sub_size;
2738 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2739 if (n != mpctx->set_of_sub_size) {
2740 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2741 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2742 mpctx->global_sub_size;
2743 ++mpctx->global_sub_size;
2746 break;
2748 case MP_CMD_SUB_REMOVE:
2749 if (sh_video) {
2750 int v = cmd->args[0].v.i;
2751 sub_data *subd;
2752 if (v < 0) {
2753 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2754 subd = mpctx->set_of_subtitles[v];
2755 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2756 MSGTR_RemovedSubtitleFile, v + 1,
2757 filename_recode(subd->filename));
2758 sub_free(subd);
2759 mpctx->set_of_subtitles[v] = NULL;
2761 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2762 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2763 mpctx->set_of_sub_size = 0;
2764 if (mpctx->set_of_sub_pos >= 0) {
2765 mpctx->global_sub_pos = -2;
2766 subdata = NULL;
2767 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2769 } else if (v < mpctx->set_of_sub_size) {
2770 subd = mpctx->set_of_subtitles[v];
2771 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2772 MSGTR_RemovedSubtitleFile, v + 1,
2773 filename_recode(subd->filename));
2774 sub_free(subd);
2775 if (mpctx->set_of_sub_pos == v) {
2776 mpctx->global_sub_pos = -2;
2777 subdata = NULL;
2778 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2779 } else if (mpctx->set_of_sub_pos > v) {
2780 --mpctx->set_of_sub_pos;
2781 --mpctx->global_sub_pos;
2783 while (++v < mpctx->set_of_sub_size)
2784 mpctx->set_of_subtitles[v - 1] =
2785 mpctx->set_of_subtitles[v];
2786 --mpctx->set_of_sub_size;
2787 --mpctx->global_sub_size;
2788 if (mpctx->set_of_sub_size <= 0)
2789 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2790 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2793 break;
2795 case MP_CMD_GET_SUB_VISIBILITY:
2796 if (sh_video) {
2797 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2798 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2800 break;
2802 case MP_CMD_SCREENSHOT:
2803 if (vo_config_count) {
2804 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2805 if (CONTROL_OK !=
2806 ((vf_instance_t *) sh_video->vfilter)->
2807 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2808 &cmd->args[0].v.i))
2809 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2811 break;
2813 case MP_CMD_VF_CHANGE_RECTANGLE:
2814 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2815 break;
2817 case MP_CMD_GET_TIME_LENGTH:{
2818 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2819 demuxer_get_time_length(mpctx->demuxer));
2821 break;
2823 case MP_CMD_GET_FILENAME:{
2824 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2825 get_metadata(META_NAME));
2827 break;
2829 case MP_CMD_GET_VIDEO_CODEC:{
2830 char *inf = get_metadata(META_VIDEO_CODEC);
2831 if (!inf)
2832 inf = strdup("");
2833 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2834 free(inf);
2836 break;
2838 case MP_CMD_GET_VIDEO_BITRATE:{
2839 char *inf = get_metadata(META_VIDEO_BITRATE);
2840 if (!inf)
2841 inf = strdup("");
2842 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2843 free(inf);
2845 break;
2847 case MP_CMD_GET_VIDEO_RESOLUTION:{
2848 char *inf = get_metadata(META_VIDEO_RESOLUTION);
2849 if (!inf)
2850 inf = strdup("");
2851 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2852 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
2853 free(inf);
2855 break;
2857 case MP_CMD_GET_AUDIO_CODEC:{
2858 char *inf = get_metadata(META_AUDIO_CODEC);
2859 if (!inf)
2860 inf = strdup("");
2861 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
2862 free(inf);
2864 break;
2866 case MP_CMD_GET_AUDIO_BITRATE:{
2867 char *inf = get_metadata(META_AUDIO_BITRATE);
2868 if (!inf)
2869 inf = strdup("");
2870 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
2871 free(inf);
2873 break;
2875 case MP_CMD_GET_AUDIO_SAMPLES:{
2876 char *inf = get_metadata(META_AUDIO_SAMPLES);
2877 if (!inf)
2878 inf = strdup("");
2879 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
2880 free(inf);
2882 break;
2884 case MP_CMD_GET_META_TITLE:{
2885 char *inf = get_metadata(META_INFO_TITLE);
2886 if (!inf)
2887 inf = strdup("");
2888 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
2889 free(inf);
2891 break;
2893 case MP_CMD_GET_META_ARTIST:{
2894 char *inf = get_metadata(META_INFO_ARTIST);
2895 if (!inf)
2896 inf = strdup("");
2897 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
2898 free(inf);
2900 break;
2902 case MP_CMD_GET_META_ALBUM:{
2903 char *inf = get_metadata(META_INFO_ALBUM);
2904 if (!inf)
2905 inf = strdup("");
2906 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
2907 free(inf);
2909 break;
2911 case MP_CMD_GET_META_YEAR:{
2912 char *inf = get_metadata(META_INFO_YEAR);
2913 if (!inf)
2914 inf = strdup("");
2915 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
2916 free(inf);
2918 break;
2920 case MP_CMD_GET_META_COMMENT:{
2921 char *inf = get_metadata(META_INFO_COMMENT);
2922 if (!inf)
2923 inf = strdup("");
2924 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
2925 free(inf);
2927 break;
2929 case MP_CMD_GET_META_TRACK:{
2930 char *inf = get_metadata(META_INFO_TRACK);
2931 if (!inf)
2932 inf = strdup("");
2933 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
2934 free(inf);
2936 break;
2938 case MP_CMD_GET_META_GENRE:{
2939 char *inf = get_metadata(META_INFO_GENRE);
2940 if (!inf)
2941 inf = strdup("");
2942 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
2943 free(inf);
2945 break;
2947 case MP_CMD_GET_VO_FULLSCREEN:
2948 if (mpctx->video_out && vo_config_count)
2949 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
2950 break;
2952 case MP_CMD_GET_PERCENT_POS:
2953 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
2954 demuxer_get_percent_pos(mpctx->demuxer));
2955 break;
2957 case MP_CMD_GET_TIME_POS:{
2958 float pos = 0;
2959 if (sh_video)
2960 pos = sh_video->pts;
2961 else if (sh_audio && mpctx->audio_out)
2962 pos =
2963 playing_audio_pts(sh_audio, mpctx->d_audio,
2964 mpctx->audio_out);
2965 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
2967 break;
2969 case MP_CMD_RUN:
2970 #ifndef __MINGW32__
2971 if (!fork()) {
2972 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
2973 exit(0);
2975 #endif
2976 break;
2978 case MP_CMD_KEYDOWN_EVENTS:
2979 mplayer_put_key(cmd->args[0].v.i);
2980 break;
2982 case MP_CMD_SET_MOUSE_POS:{
2983 int pointer_x, pointer_y;
2984 double dx, dy;
2985 pointer_x = cmd->args[0].v.i;
2986 pointer_y = cmd->args[1].v.i;
2987 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
2988 #ifdef USE_DVDNAV
2989 if (mpctx->stream->type == STREAMTYPE_DVDNAV
2990 && dx > 0.0 && dy > 0.0) {
2991 int button = -1;
2992 pointer_x = (int) (dx * (double) sh_video->disp_w);
2993 pointer_y = (int) (dy * (double) sh_video->disp_h);
2994 mp_dvdnav_update_mouse_pos(mpctx->stream,
2995 pointer_x, pointer_y, &button);
2996 if (button > 0)
2997 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2998 "Selected button number %d", button);
3000 #endif
3001 #ifdef HAVE_MENU
3002 if (use_menu && dx >= 0.0 && dy >= 0.0)
3003 menu_update_mouse_pos(dx, dy);
3004 #endif
3006 break;
3008 #ifdef USE_DVDNAV
3009 case MP_CMD_DVDNAV:{
3010 int button = -1;
3011 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3012 break;
3014 if (mp_dvdnav_handle_input
3015 (mpctx->stream, cmd->args[0].v.i, &button)) {
3016 uninit_player(INITED_ALL - (INITED_STREAM | INITED_INPUT |
3017 (fixed_vo ? INITED_VO : 0)));
3018 brk_cmd = 2;
3019 } else if (button > 0)
3020 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3021 "Selected button number %d", button);
3023 break;
3024 #endif
3026 default:
3027 #ifdef HAVE_NEW_GUI
3028 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3029 guiGetEvent(guiIEvent, (char *) cmd->id);
3030 else
3031 #endif
3032 mp_msg(MSGT_CPLAYER, MSGL_V,
3033 "Received unknown cmd %s\n", cmd->name);
3036 switch (cmd->pausing) {
3037 case 1: // "pausing"
3038 mpctx->osd_function = OSD_PAUSE;
3039 break;
3040 case 3: // "pausing_toggle"
3041 mpctx->was_paused = !mpctx->was_paused;
3042 if (mpctx->was_paused)
3043 mpctx->osd_function = OSD_PAUSE;
3044 else if (mpctx->osd_function == OSD_PAUSE)
3045 mpctx->osd_function = OSD_PLAY;
3046 break;
3047 case 2: // "pausing_keep"
3048 if (mpctx->was_paused)
3049 mpctx->osd_function = OSD_PAUSE;
3051 return brk_cmd;