Fix illegal identifier, names starting with _ and uppercase are reserved.
[mplayer/greg.git] / command.c
blob269eeac0877dce9f6528553452879eb99c8693f0
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 chapter = demuxer_get_current_chapter(mpctx->demuxer);
389 if (chapter < 0)
390 return M_PROPERTY_UNAVAILABLE;
392 switch (action) {
393 case M_PROPERTY_GET:
394 if (!arg)
395 return M_PROPERTY_ERROR;
396 *(int *) arg = chapter;
397 return M_PROPERTY_OK;
398 case M_PROPERTY_PRINT: {
399 if (!arg)
400 return M_PROPERTY_ERROR;
401 chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter);
402 if (!chapter_name)
403 return M_PROPERTY_UNAVAILABLE;
404 *(char **) arg = chapter_name;
405 return M_PROPERTY_OK;
407 case M_PROPERTY_SET:
408 if (!arg)
409 return M_PROPERTY_ERROR;
410 M_PROPERTY_CLAMP(prop, *(int*)arg);
411 step_all = *(int *)arg - (chapter + 1);
412 chapter += step_all;
413 break;
414 case M_PROPERTY_STEP_UP:
415 case M_PROPERTY_STEP_DOWN: {
416 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
417 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
418 chapter += step_all;
419 if (chapter < 0)
420 chapter = 0;
421 break;
423 default:
424 return M_PROPERTY_NOT_IMPLEMENTED;
426 rel_seek_secs = 0;
427 abs_seek_pos = 0;
428 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
429 &next_pts, &chapter_num, &chapter_name);
430 if (chapter >= 0) {
431 if (next_pts > -1.0) {
432 abs_seek_pos = 1;
433 rel_seek_secs = next_pts;
435 if (chapter_name)
436 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
437 MSGTR_OSDChapter, chapter + 1, chapter_name);
439 else if (step_all > 0)
440 rel_seek_secs = 1000000000.;
441 else
442 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
443 MSGTR_OSDChapter, 0, MSGTR_Unknown);
444 if (chapter_name)
445 free(chapter_name);
446 return M_PROPERTY_OK;
449 /// Current dvd angle (RW)
450 static int mp_property_angle(m_option_t *prop, int action, void *arg,
451 MPContext *mpctx)
453 int angle;
454 int angles;
455 char *angle_name = NULL;
457 angle = demuxer_get_current_angle(mpctx->demuxer);
458 if (angle < 0)
459 return M_PROPERTY_UNAVAILABLE;
460 angles = demuxer_angles_count(mpctx->demuxer);
461 if (angles <= 1)
462 return M_PROPERTY_UNAVAILABLE;
464 switch (action) {
465 case M_PROPERTY_GET:
466 if (!arg)
467 return M_PROPERTY_ERROR;
468 *(int *) arg = angle;
469 return M_PROPERTY_OK;
470 case M_PROPERTY_PRINT: {
471 if (!arg)
472 return M_PROPERTY_ERROR;
473 angle_name = calloc(1, 64);
474 if (!angle_name)
475 return M_PROPERTY_UNAVAILABLE;
476 snprintf(angle_name, 64, "%d/%d", angle, angles);
477 *(char **) arg = angle_name;
478 return M_PROPERTY_OK;
480 case M_PROPERTY_SET:
481 if (!arg)
482 return M_PROPERTY_ERROR;
483 angle = *(int *)arg;
484 M_PROPERTY_CLAMP(prop, angle);
485 break;
486 case M_PROPERTY_STEP_UP:
487 case M_PROPERTY_STEP_DOWN: {
488 int step = 0;
489 if(arg)
490 step = *(int*)arg;
491 if(!step)
492 step = 1;
493 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
494 angle += step;
495 if (angle < 1) //cycle
496 angle = angles;
497 break;
499 default:
500 return M_PROPERTY_NOT_IMPLEMENTED;
502 angle = demuxer_set_angle(mpctx->demuxer, angle);
503 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
504 MSGTR_OSDAngle, angle, angles);
505 if (angle_name)
506 free(angle_name);
507 return M_PROPERTY_OK;
510 /// Demuxer meta data
511 static int mp_property_metadata(m_option_t * prop, int action, void *arg,
512 MPContext * mpctx) {
513 m_property_action_t* ka;
514 char* meta;
515 static m_option_t key_type =
516 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
517 if (!mpctx->demuxer)
518 return M_PROPERTY_UNAVAILABLE;
520 switch(action) {
521 case M_PROPERTY_GET:
522 if(!arg) return M_PROPERTY_ERROR;
523 *(char***)arg = mpctx->demuxer->info;
524 return M_PROPERTY_OK;
525 case M_PROPERTY_KEY_ACTION:
526 if(!arg) return M_PROPERTY_ERROR;
527 ka = arg;
528 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
529 return M_PROPERTY_UNKNOWN;
530 switch(ka->action) {
531 case M_PROPERTY_GET:
532 if(!ka->arg) return M_PROPERTY_ERROR;
533 *(char**)ka->arg = meta;
534 return M_PROPERTY_OK;
535 case M_PROPERTY_GET_TYPE:
536 if(!ka->arg) return M_PROPERTY_ERROR;
537 *(m_option_t**)ka->arg = &key_type;
538 return M_PROPERTY_OK;
541 return M_PROPERTY_NOT_IMPLEMENTED;
545 ///@}
547 /// \defgroup AudioProperties Audio properties
548 /// \ingroup Properties
549 ///@{
551 /// Volume (RW)
552 static int mp_property_volume(m_option_t * prop, int action, void *arg,
553 MPContext * mpctx)
556 if (!mpctx->sh_audio)
557 return M_PROPERTY_UNAVAILABLE;
559 switch (action) {
560 case M_PROPERTY_GET:
561 if (!arg)
562 return M_PROPERTY_ERROR;
563 mixer_getbothvolume(&mpctx->mixer, arg);
564 return M_PROPERTY_OK;
565 case M_PROPERTY_PRINT:{
566 float vol;
567 if (!arg)
568 return M_PROPERTY_ERROR;
569 mixer_getbothvolume(&mpctx->mixer, &vol);
570 return m_property_float_range(prop, action, arg, &vol);
572 case M_PROPERTY_STEP_UP:
573 case M_PROPERTY_STEP_DOWN:
574 case M_PROPERTY_SET:
575 break;
576 default:
577 return M_PROPERTY_NOT_IMPLEMENTED;
580 if (mpctx->edl_muted)
581 return M_PROPERTY_DISABLED;
582 mpctx->user_muted = 0;
584 switch (action) {
585 case M_PROPERTY_SET:
586 if (!arg)
587 return M_PROPERTY_ERROR;
588 M_PROPERTY_CLAMP(prop, *(float *) arg);
589 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
590 return M_PROPERTY_OK;
591 case M_PROPERTY_STEP_UP:
592 if (arg && *(float *) arg <= 0)
593 mixer_decvolume(&mpctx->mixer);
594 else
595 mixer_incvolume(&mpctx->mixer);
596 return M_PROPERTY_OK;
597 case M_PROPERTY_STEP_DOWN:
598 if (arg && *(float *) arg <= 0)
599 mixer_incvolume(&mpctx->mixer);
600 else
601 mixer_decvolume(&mpctx->mixer);
602 return M_PROPERTY_OK;
604 return M_PROPERTY_NOT_IMPLEMENTED;
607 /// Mute (RW)
608 static int mp_property_mute(m_option_t * prop, int action, void *arg,
609 MPContext * mpctx)
612 if (!mpctx->sh_audio)
613 return M_PROPERTY_UNAVAILABLE;
615 switch (action) {
616 case M_PROPERTY_SET:
617 if (mpctx->edl_muted)
618 return M_PROPERTY_DISABLED;
619 if (!arg)
620 return M_PROPERTY_ERROR;
621 if ((!!*(int *) arg) != mpctx->mixer.muted)
622 mixer_mute(&mpctx->mixer);
623 mpctx->user_muted = mpctx->mixer.muted;
624 return M_PROPERTY_OK;
625 case M_PROPERTY_STEP_UP:
626 case M_PROPERTY_STEP_DOWN:
627 if (mpctx->edl_muted)
628 return M_PROPERTY_DISABLED;
629 mixer_mute(&mpctx->mixer);
630 mpctx->user_muted = mpctx->mixer.muted;
631 return M_PROPERTY_OK;
632 case M_PROPERTY_PRINT:
633 if (!arg)
634 return M_PROPERTY_ERROR;
635 if (mpctx->edl_muted) {
636 *(char **) arg = strdup(MSGTR_EnabledEdl);
637 return M_PROPERTY_OK;
639 default:
640 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
645 /// Audio delay (RW)
646 static int mp_property_audio_delay(m_option_t * prop, int action,
647 void *arg, MPContext * mpctx)
649 if (!(mpctx->sh_audio && mpctx->sh_video))
650 return M_PROPERTY_UNAVAILABLE;
651 switch (action) {
652 case M_PROPERTY_SET:
653 case M_PROPERTY_STEP_UP:
654 case M_PROPERTY_STEP_DOWN: {
655 int ret;
656 float delay = audio_delay;
657 ret = m_property_delay(prop, action, arg, &audio_delay);
658 if (ret != M_PROPERTY_OK)
659 return ret;
660 if (mpctx->sh_audio)
661 mpctx->delay -= audio_delay - delay;
663 return M_PROPERTY_OK;
664 default:
665 return m_property_delay(prop, action, arg, &audio_delay);
669 /// Audio codec tag (RO)
670 static int mp_property_audio_format(m_option_t * prop, int action,
671 void *arg, MPContext * mpctx)
673 if (!mpctx->sh_audio)
674 return M_PROPERTY_UNAVAILABLE;
675 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
678 /// Audio codec name (RO)
679 static int mp_property_audio_codec(m_option_t * prop, int action,
680 void *arg, MPContext * mpctx)
682 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
683 return M_PROPERTY_UNAVAILABLE;
684 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
687 /// Audio bitrate (RO)
688 static int mp_property_audio_bitrate(m_option_t * prop, int action,
689 void *arg, MPContext * mpctx)
691 if (!mpctx->sh_audio)
692 return M_PROPERTY_UNAVAILABLE;
693 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
696 /// Samplerate (RO)
697 static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
698 MPContext * mpctx)
700 if (!mpctx->sh_audio)
701 return M_PROPERTY_UNAVAILABLE;
702 switch(action) {
703 case M_PROPERTY_PRINT:
704 if(!arg) return M_PROPERTY_ERROR;
705 *(char**)arg = malloc(16);
706 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
707 return M_PROPERTY_OK;
709 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
712 /// Number of channels (RO)
713 static int mp_property_channels(m_option_t * prop, int action, void *arg,
714 MPContext * mpctx)
716 if (!mpctx->sh_audio)
717 return M_PROPERTY_UNAVAILABLE;
718 switch (action) {
719 case M_PROPERTY_PRINT:
720 if (!arg)
721 return M_PROPERTY_ERROR;
722 switch (mpctx->sh_audio->channels) {
723 case 1:
724 *(char **) arg = strdup("mono");
725 break;
726 case 2:
727 *(char **) arg = strdup("stereo");
728 break;
729 default:
730 *(char **) arg = malloc(32);
731 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
733 return M_PROPERTY_OK;
735 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
738 /// Balance (RW)
739 static int mp_property_balance(m_option_t * prop, int action, void *arg,
740 MPContext * mpctx)
742 float bal;
744 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
745 return M_PROPERTY_UNAVAILABLE;
747 switch (action) {
748 case M_PROPERTY_GET:
749 if (!arg)
750 return M_PROPERTY_ERROR;
751 mixer_getbalance(&mpctx->mixer, arg);
752 return M_PROPERTY_OK;
753 case M_PROPERTY_PRINT: {
754 char** str = arg;
755 if (!arg)
756 return M_PROPERTY_ERROR;
757 mixer_getbalance(&mpctx->mixer, &bal);
758 if (bal == 0.f)
759 *str = strdup("center");
760 else if (bal == -1.f)
761 *str = strdup("left only");
762 else if (bal == 1.f)
763 *str = strdup("right only");
764 else {
765 unsigned right = (bal + 1.f) / 2.f * 100.f;
766 *str = malloc(sizeof("left xxx%, right xxx%"));
767 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
769 return M_PROPERTY_OK;
771 case M_PROPERTY_STEP_UP:
772 case M_PROPERTY_STEP_DOWN:
773 mixer_getbalance(&mpctx->mixer, &bal);
774 bal += (arg ? *(float*)arg : .1f) *
775 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
776 M_PROPERTY_CLAMP(prop, bal);
777 mixer_setbalance(&mpctx->mixer, bal);
778 return M_PROPERTY_OK;
779 case M_PROPERTY_SET:
780 if (!arg)
781 return M_PROPERTY_ERROR;
782 M_PROPERTY_CLAMP(prop, *(float*)arg);
783 mixer_setbalance(&mpctx->mixer, *(float*)arg);
784 return M_PROPERTY_OK;
786 return M_PROPERTY_NOT_IMPLEMENTED;
789 /// Selected audio id (RW)
790 static int mp_property_audio(m_option_t * prop, int action, void *arg,
791 MPContext * mpctx)
793 int current_id = -1, tmp;
795 switch (action) {
796 case M_PROPERTY_GET:
797 if (!mpctx->sh_audio)
798 return M_PROPERTY_UNAVAILABLE;
799 if (!arg)
800 return M_PROPERTY_ERROR;
801 *(int *) arg = audio_id;
802 return M_PROPERTY_OK;
803 case M_PROPERTY_PRINT:
804 if (!mpctx->sh_audio)
805 return M_PROPERTY_UNAVAILABLE;
806 if (!arg)
807 return M_PROPERTY_ERROR;
809 if (audio_id < 0)
810 *(char **) arg = strdup(MSGTR_Disabled);
811 else {
812 char lang[40] = MSGTR_Unknown;
813 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA)
814 demux_mkv_get_audio_lang(mpctx->demuxer, audio_id, lang, 9);
815 #ifdef USE_DVDREAD
816 else if (mpctx->stream->type == STREAMTYPE_DVD) {
817 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
818 if (code) {
819 lang[0] = code >> 8;
820 lang[1] = code;
821 lang[2] = 0;
824 #endif
826 #ifdef USE_DVDNAV
827 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
828 dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
829 #endif
830 *(char **) arg = malloc(64);
831 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
833 return M_PROPERTY_OK;
835 case M_PROPERTY_STEP_UP:
836 case M_PROPERTY_SET:
837 if (action == M_PROPERTY_SET && arg)
838 tmp = *((int *) arg);
839 else
840 tmp = -1;
841 current_id = mpctx->demuxer->audio->id;
842 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
843 if (audio_id == -2
844 || (audio_id > -1
845 && mpctx->demuxer->audio->id != current_id && current_id != -2))
846 uninit_player(INITED_AO | INITED_ACODEC);
847 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
848 sh_audio_t *sh2;
849 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
850 if (sh2) {
851 sh2->ds = mpctx->demuxer->audio;
852 mpctx->sh_audio = sh2;
853 reinit_audio_chain();
856 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
857 return M_PROPERTY_OK;
858 default:
859 return M_PROPERTY_NOT_IMPLEMENTED;
864 /// Selected video id (RW)
865 static int mp_property_video(m_option_t * prop, int action, void *arg,
866 MPContext * mpctx)
868 int current_id = -1, tmp;
870 switch (action) {
871 case M_PROPERTY_GET:
872 if (!mpctx->sh_video)
873 return M_PROPERTY_UNAVAILABLE;
874 if (!arg)
875 return M_PROPERTY_ERROR;
876 *(int *) arg = video_id;
877 return M_PROPERTY_OK;
878 case M_PROPERTY_PRINT:
879 if (!mpctx->sh_video)
880 return M_PROPERTY_UNAVAILABLE;
881 if (!arg)
882 return M_PROPERTY_ERROR;
884 if (video_id < 0)
885 *(char **) arg = strdup(MSGTR_Disabled);
886 else {
887 char lang[40] = MSGTR_Unknown;
888 *(char **) arg = malloc(64);
889 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
891 return M_PROPERTY_OK;
893 case M_PROPERTY_STEP_UP:
894 case M_PROPERTY_SET:
895 current_id = mpctx->demuxer->video->id;
896 if (action == M_PROPERTY_SET && arg)
897 tmp = *((int *) arg);
898 else
899 tmp = -1;
900 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
901 if (video_id == -2
902 || (video_id > -1 && mpctx->demuxer->video->id != current_id
903 && current_id != -2))
904 uninit_player(INITED_VCODEC |
905 (fixed_vo && video_id != -2 ? 0 : INITED_VO));
906 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
907 sh_video_t *sh2;
908 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
909 if (sh2) {
910 sh2->ds = mpctx->demuxer->video;
911 mpctx->sh_video = sh2;
912 reinit_video_chain();
915 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
916 return M_PROPERTY_OK;
918 default:
919 return M_PROPERTY_NOT_IMPLEMENTED;
923 static int mp_property_program(m_option_t * prop, int action, void *arg,
924 MPContext * mpctx)
926 demux_program_t prog;
928 switch (action) {
929 case M_PROPERTY_STEP_UP:
930 case M_PROPERTY_SET:
931 if (action == M_PROPERTY_SET && arg)
932 prog.progid = *((int *) arg);
933 else
934 prog.progid = -1;
935 if (demux_control
936 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
937 &prog) == DEMUXER_CTRL_NOTIMPL)
938 return M_PROPERTY_ERROR;
940 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
941 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
942 return M_PROPERTY_OK;
944 default:
945 return M_PROPERTY_NOT_IMPLEMENTED;
949 ///@}
951 /// \defgroup VideoProperties Video properties
952 /// \ingroup Properties
953 ///@{
955 /// Fullscreen state (RW)
956 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
957 MPContext * mpctx)
960 if (!mpctx->video_out)
961 return M_PROPERTY_UNAVAILABLE;
963 switch (action) {
964 case M_PROPERTY_SET:
965 if (!arg)
966 return M_PROPERTY_ERROR;
967 M_PROPERTY_CLAMP(prop, *(int *) arg);
968 if (vo_fs == !!*(int *) arg)
969 return M_PROPERTY_OK;
970 case M_PROPERTY_STEP_UP:
971 case M_PROPERTY_STEP_DOWN:
972 #ifdef HAVE_NEW_GUI
973 if (use_gui)
974 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
975 else
976 #endif
977 if (vo_config_count)
978 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
979 return M_PROPERTY_OK;
980 default:
981 return m_property_flag(prop, action, arg, &vo_fs);
985 static int mp_property_deinterlace(m_option_t * prop, int action,
986 void *arg, MPContext * mpctx)
988 int deinterlace;
989 vf_instance_t *vf;
990 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
991 return M_PROPERTY_UNAVAILABLE;
992 vf = mpctx->sh_video->vfilter;
993 switch (action) {
994 case M_PROPERTY_GET:
995 if (!arg)
996 return M_PROPERTY_ERROR;
997 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
998 return M_PROPERTY_OK;
999 case M_PROPERTY_SET:
1000 if (!arg)
1001 return M_PROPERTY_ERROR;
1002 M_PROPERTY_CLAMP(prop, *(int *) arg);
1003 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1004 return M_PROPERTY_OK;
1005 case M_PROPERTY_STEP_UP:
1006 case M_PROPERTY_STEP_DOWN:
1007 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1008 deinterlace = !deinterlace;
1009 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1010 return M_PROPERTY_OK;
1012 return M_PROPERTY_NOT_IMPLEMENTED;
1015 /// Panscan (RW)
1016 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
1017 MPContext * mpctx)
1020 if (!mpctx->video_out
1021 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1022 return M_PROPERTY_UNAVAILABLE;
1024 switch (action) {
1025 case M_PROPERTY_SET:
1026 if (!arg)
1027 return M_PROPERTY_ERROR;
1028 M_PROPERTY_CLAMP(prop, *(float *) arg);
1029 vo_panscan = *(float *) arg;
1030 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1031 return M_PROPERTY_OK;
1032 case M_PROPERTY_STEP_UP:
1033 case M_PROPERTY_STEP_DOWN:
1034 vo_panscan += (arg ? *(float *) arg : 0.1) *
1035 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1036 if (vo_panscan > 1)
1037 vo_panscan = 1;
1038 else if (vo_panscan < 0)
1039 vo_panscan = 0;
1040 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1041 return M_PROPERTY_OK;
1042 default:
1043 return m_property_float_range(prop, action, arg, &vo_panscan);
1047 /// Helper to set vo flags.
1048 /** \ingroup PropertyImplHelper
1050 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
1051 int vo_ctrl, int *vo_var, MPContext * mpctx)
1054 if (!mpctx->video_out)
1055 return M_PROPERTY_UNAVAILABLE;
1057 switch (action) {
1058 case M_PROPERTY_SET:
1059 if (!arg)
1060 return M_PROPERTY_ERROR;
1061 M_PROPERTY_CLAMP(prop, *(int *) arg);
1062 if (*vo_var == !!*(int *) arg)
1063 return M_PROPERTY_OK;
1064 case M_PROPERTY_STEP_UP:
1065 case M_PROPERTY_STEP_DOWN:
1066 if (vo_config_count)
1067 mpctx->video_out->control(vo_ctrl, 0);
1068 return M_PROPERTY_OK;
1069 default:
1070 return m_property_flag(prop, action, arg, vo_var);
1074 /// Window always on top (RW)
1075 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
1076 MPContext * mpctx)
1078 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
1079 mpctx);
1082 /// Display in the root window (RW)
1083 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
1084 MPContext * mpctx)
1086 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1087 &vo_rootwin, mpctx);
1090 /// Show window borders (RW)
1091 static int mp_property_border(m_option_t * prop, int action, void *arg,
1092 MPContext * mpctx)
1094 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1095 &vo_border, mpctx);
1098 /// Framedropping state (RW)
1099 static int mp_property_framedropping(m_option_t * prop, int action,
1100 void *arg, MPContext * mpctx)
1103 if (!mpctx->sh_video)
1104 return M_PROPERTY_UNAVAILABLE;
1106 switch (action) {
1107 case M_PROPERTY_PRINT:
1108 if (!arg)
1109 return M_PROPERTY_ERROR;
1110 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1111 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1112 MSGTR_Disabled));
1113 return M_PROPERTY_OK;
1114 default:
1115 return m_property_choice(prop, action, arg, &frame_dropping);
1119 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1120 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
1121 MPContext * mpctx)
1123 int *gamma = prop->priv, r, val;
1125 if (!mpctx->sh_video)
1126 return M_PROPERTY_UNAVAILABLE;
1128 if (gamma[0] == 1000) {
1129 gamma[0] = 0;
1130 get_video_colors(mpctx->sh_video, prop->name, gamma);
1133 switch (action) {
1134 case M_PROPERTY_SET:
1135 if (!arg)
1136 return M_PROPERTY_ERROR;
1137 M_PROPERTY_CLAMP(prop, *(int *) arg);
1138 *gamma = *(int *) arg;
1139 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1140 if (r <= 0)
1141 break;
1142 return r;
1143 case M_PROPERTY_GET:
1144 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1145 if (!arg)
1146 return M_PROPERTY_ERROR;
1147 *(int *)arg = val;
1148 return M_PROPERTY_OK;
1150 break;
1151 case M_PROPERTY_STEP_UP:
1152 case M_PROPERTY_STEP_DOWN:
1153 *gamma += (arg ? *(int *) arg : 1) *
1154 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1155 M_PROPERTY_CLAMP(prop, *gamma);
1156 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1157 if (r <= 0)
1158 break;
1159 return r;
1160 default:
1161 return M_PROPERTY_NOT_IMPLEMENTED;
1164 #ifdef USE_TV
1165 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1166 int l = strlen(prop->name);
1167 char tv_prop[3 + l + 1];
1168 sprintf(tv_prop, "tv_%s", prop->name);
1169 return mp_property_do(tv_prop, action, arg, mpctx);
1171 #endif
1173 return M_PROPERTY_UNAVAILABLE;
1176 /// VSync (RW)
1177 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1178 MPContext * mpctx)
1180 return m_property_flag(prop, action, arg, &vo_vsync);
1183 /// Video codec tag (RO)
1184 static int mp_property_video_format(m_option_t * prop, int action,
1185 void *arg, MPContext * mpctx)
1187 char* meta;
1188 if (!mpctx->sh_video)
1189 return M_PROPERTY_UNAVAILABLE;
1190 switch(action) {
1191 case M_PROPERTY_PRINT:
1192 if (!arg)
1193 return M_PROPERTY_ERROR;
1194 switch(mpctx->sh_video->format) {
1195 case 0x10000001:
1196 meta = strdup ("mpeg1"); break;
1197 case 0x10000002:
1198 meta = strdup ("mpeg2"); break;
1199 case 0x10000004:
1200 meta = strdup ("mpeg4"); break;
1201 case 0x10000005:
1202 meta = strdup ("h264"); break;
1203 default:
1204 if(mpctx->sh_video->format >= 0x20202020) {
1205 meta = malloc(5);
1206 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1207 } else {
1208 meta = malloc(20);
1209 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1212 *(char**)arg = meta;
1213 return M_PROPERTY_OK;
1215 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1218 /// Video codec name (RO)
1219 static int mp_property_video_codec(m_option_t * prop, int action,
1220 void *arg, MPContext * mpctx)
1222 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1223 return M_PROPERTY_UNAVAILABLE;
1224 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1228 /// Video bitrate (RO)
1229 static int mp_property_video_bitrate(m_option_t * prop, int action,
1230 void *arg, MPContext * mpctx)
1232 if (!mpctx->sh_video)
1233 return M_PROPERTY_UNAVAILABLE;
1234 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1237 /// Video display width (RO)
1238 static int mp_property_width(m_option_t * prop, int action, void *arg,
1239 MPContext * mpctx)
1241 if (!mpctx->sh_video)
1242 return M_PROPERTY_UNAVAILABLE;
1243 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1246 /// Video display height (RO)
1247 static int mp_property_height(m_option_t * prop, int action, void *arg,
1248 MPContext * mpctx)
1250 if (!mpctx->sh_video)
1251 return M_PROPERTY_UNAVAILABLE;
1252 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1255 /// Video fps (RO)
1256 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1257 MPContext * mpctx)
1259 if (!mpctx->sh_video)
1260 return M_PROPERTY_UNAVAILABLE;
1261 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1264 /// Video aspect (RO)
1265 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1266 MPContext * mpctx)
1268 if (!mpctx->sh_video)
1269 return M_PROPERTY_UNAVAILABLE;
1270 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1273 ///@}
1275 /// \defgroup SubProprties Subtitles properties
1276 /// \ingroup Properties
1277 ///@{
1279 /// Text subtitle position (RW)
1280 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1281 MPContext * mpctx)
1283 if (!mpctx->sh_video)
1284 return M_PROPERTY_UNAVAILABLE;
1286 switch (action) {
1287 case M_PROPERTY_SET:
1288 if (!arg)
1289 return M_PROPERTY_ERROR;
1290 case M_PROPERTY_STEP_UP:
1291 case M_PROPERTY_STEP_DOWN:
1292 vo_osd_changed(OSDTYPE_SUBTITLE);
1293 default:
1294 return m_property_int_range(prop, action, arg, &sub_pos);
1298 char *demux_lavf_sub_lang(demuxer_t *demuxer, int track_num);
1300 /// Selected subtitles (RW)
1301 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1302 MPContext * mpctx)
1304 demux_stream_t *const d_sub = mpctx->d_sub;
1305 const int global_sub_size = mpctx->global_sub_size;
1306 int source = -1, reset_spu = 0;
1307 char *sub_name;
1309 if (global_sub_size <= 0)
1310 return M_PROPERTY_UNAVAILABLE;
1312 switch (action) {
1313 case M_PROPERTY_GET:
1314 if (!arg)
1315 return M_PROPERTY_ERROR;
1316 *(int *) arg = mpctx->global_sub_pos;
1317 return M_PROPERTY_OK;
1318 case M_PROPERTY_PRINT:
1319 if (!arg)
1320 return M_PROPERTY_ERROR;
1321 *(char **) arg = malloc(64);
1322 (*(char **) arg)[63] = 0;
1323 sub_name = 0;
1324 if (subdata)
1325 sub_name = subdata->filename;
1326 #ifdef USE_ASS
1327 if (ass_track && ass_track->name)
1328 sub_name = ass_track->name;
1329 #endif
1330 if (sub_name) {
1331 char *tmp, *tmp2;
1332 tmp = sub_name;
1333 if ((tmp2 = strrchr(tmp, '/')))
1334 tmp = tmp2 + 1;
1336 snprintf(*(char **) arg, 63, "(%d) %s%s",
1337 mpctx->set_of_sub_pos + 1,
1338 strlen(tmp) < 20 ? "" : "...",
1339 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1340 return M_PROPERTY_OK;
1342 #ifdef USE_DVDNAV
1343 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1344 if (vo_spudec && dvdsub_id >= 0) {
1345 unsigned char lang[3];
1346 if (dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1347 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1348 return M_PROPERTY_OK;
1352 #endif
1354 #ifdef USE_LIBAVFORMAT
1355 if (mpctx->demuxer->type == DEMUXER_TYPE_LAVF && dvdsub_id >= 0) {
1356 char *lang = demux_lavf_sub_lang(mpctx->demuxer, dvdsub_id);
1357 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1358 return M_PROPERTY_OK;
1360 #endif
1361 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
1362 char lang[40] = MSGTR_Unknown;
1363 demux_mkv_get_sub_lang(mpctx->demuxer, dvdsub_id, lang, 9);
1364 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1365 return M_PROPERTY_OK;
1367 #ifdef HAVE_OGGVORBIS
1368 if (mpctx->demuxer->type == DEMUXER_TYPE_OGG && d_sub && dvdsub_id >= 0) {
1369 const char *lang = demux_ogg_sub_lang(mpctx->demuxer, dvdsub_id);
1370 if (!lang)
1371 lang = MSGTR_Unknown;
1372 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1373 return M_PROPERTY_OK;
1375 #endif
1376 if (vo_vobsub && vobsub_id >= 0) {
1377 const char *language = MSGTR_Unknown;
1378 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1379 snprintf(*(char **) arg, 63, "(%d) %s",
1380 vobsub_id, language ? language : MSGTR_Unknown);
1381 return M_PROPERTY_OK;
1383 #ifdef USE_DVDREAD
1384 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1385 && dvdsub_id >= 0) {
1386 char lang[3];
1387 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1388 lang[0] = code >> 8;
1389 lang[1] = code;
1390 lang[2] = 0;
1391 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1392 return M_PROPERTY_OK;
1394 #endif
1395 if (dvdsub_id >= 0) {
1396 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1397 return M_PROPERTY_OK;
1399 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1400 return M_PROPERTY_OK;
1402 case M_PROPERTY_SET:
1403 if (!arg)
1404 return M_PROPERTY_ERROR;
1405 if (*(int *) arg < -1)
1406 *(int *) arg = -1;
1407 else if (*(int *) arg >= global_sub_size)
1408 *(int *) arg = global_sub_size - 1;
1409 mpctx->global_sub_pos = *(int *) arg;
1410 break;
1411 case M_PROPERTY_STEP_UP:
1412 mpctx->global_sub_pos += 2;
1413 mpctx->global_sub_pos =
1414 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1415 break;
1416 case M_PROPERTY_STEP_DOWN:
1417 mpctx->global_sub_pos += global_sub_size + 1;
1418 mpctx->global_sub_pos =
1419 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1420 break;
1421 default:
1422 return M_PROPERTY_NOT_IMPLEMENTED;
1425 if (mpctx->global_sub_pos >= 0)
1426 source = sub_source(mpctx);
1428 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1429 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1430 global_sub_size,
1431 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1432 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1433 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1434 mpctx->global_sub_pos, source);
1436 mpctx->set_of_sub_pos = -1;
1437 subdata = NULL;
1439 vobsub_id = -1;
1440 dvdsub_id = -1;
1441 if (d_sub) {
1442 if (d_sub->id > -2)
1443 reset_spu = 1;
1444 d_sub->id = -2;
1446 #ifdef USE_ASS
1447 ass_track = 0;
1448 #endif
1450 if (source == SUB_SOURCE_VOBSUB) {
1451 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1452 } else if (source == SUB_SOURCE_SUBS) {
1453 mpctx->set_of_sub_pos =
1454 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1455 #ifdef USE_ASS
1456 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1457 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1458 else
1459 #endif
1461 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1462 vo_osd_changed(OSDTYPE_SUBTITLE);
1464 } else if (source == SUB_SOURCE_DEMUX) {
1465 dvdsub_id =
1466 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1467 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1468 int i = 0;
1469 // default: assume 1:1 mapping of sid and stream id
1470 d_sub->id = dvdsub_id;
1471 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1472 for (i = 0; i < MAX_S_STREAMS; i++) {
1473 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1474 if (sh && sh->sid == dvdsub_id) {
1475 d_sub->id = i;
1476 d_sub->sh = sh;
1477 break;
1480 if (d_sub->sh && d_sub->id >= 0) {
1481 sh_sub_t *sh = d_sub->sh;
1482 if (sh->type == 'v')
1483 init_vo_spudec();
1484 #ifdef USE_ASS
1485 else if (ass_enabled && sh->type == 'a')
1486 ass_track = sh->ass_track;
1487 #endif
1488 } else {
1489 d_sub->id = -2;
1490 d_sub->sh = NULL;
1494 #ifdef USE_DVDREAD
1495 if (vo_spudec
1496 && (mpctx->stream->type == STREAMTYPE_DVD
1497 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1498 && dvdsub_id < 0 && reset_spu) {
1499 dvdsub_id = -2;
1500 d_sub->id = dvdsub_id;
1502 #endif
1503 update_subtitles(mpctx->sh_video, d_sub, 1);
1505 return M_PROPERTY_OK;
1508 /// Selected sub source (RW)
1509 static int mp_property_sub_source(m_option_t * prop, int action, void *arg,
1510 MPContext * mpctx)
1512 int source;
1513 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1514 return M_PROPERTY_UNAVAILABLE;
1516 switch (action) {
1517 case M_PROPERTY_GET:
1518 if (!arg)
1519 return M_PROPERTY_ERROR;
1520 *(int *) arg = sub_source(mpctx);
1521 return M_PROPERTY_OK;
1522 case M_PROPERTY_PRINT:
1523 if (!arg)
1524 return M_PROPERTY_ERROR;
1525 *(char **) arg = malloc(64);
1526 (*(char **) arg)[63] = 0;
1527 switch (sub_source(mpctx))
1529 case SUB_SOURCE_SUBS:
1530 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1531 break;
1532 case SUB_SOURCE_VOBSUB:
1533 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1534 break;
1535 case SUB_SOURCE_DEMUX:
1536 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1537 break;
1538 default:
1539 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1541 return M_PROPERTY_OK;
1542 case M_PROPERTY_SET:
1543 if (!arg)
1544 return M_PROPERTY_ERROR;
1545 M_PROPERTY_CLAMP(prop, *(int*)arg);
1546 if (*(int *) arg < 0)
1547 mpctx->global_sub_pos = -1;
1548 else if (*(int *) arg != sub_source(mpctx)) {
1549 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1550 return M_PROPERTY_UNAVAILABLE;
1551 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1553 break;
1554 case M_PROPERTY_STEP_UP:
1555 case M_PROPERTY_STEP_DOWN: {
1556 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1557 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1558 int step = (step_all > 0) ? 1 : -1;
1559 int cur_source = sub_source(mpctx);
1560 source = cur_source;
1561 while (step_all) {
1562 source += step;
1563 if (source >= SUB_SOURCES)
1564 source = -1;
1565 else if (source < -1)
1566 source = SUB_SOURCES - 1;
1567 if (source == cur_source || source == -1 ||
1568 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1569 step_all -= step;
1571 if (source == cur_source)
1572 return M_PROPERTY_OK;
1573 if (source == -1)
1574 mpctx->global_sub_pos = -1;
1575 else
1576 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1577 break;
1579 default:
1580 return M_PROPERTY_NOT_IMPLEMENTED;
1582 --mpctx->global_sub_pos;
1583 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1586 /// Selected subtitles from specific source (RW)
1587 static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg,
1588 MPContext * mpctx)
1590 int source, is_cur_source, offset;
1591 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1592 return M_PROPERTY_UNAVAILABLE;
1594 if (!strcmp(prop->name, "sub_file"))
1595 source = SUB_SOURCE_SUBS;
1596 else if (!strcmp(prop->name, "sub_vob"))
1597 source = SUB_SOURCE_VOBSUB;
1598 else if (!strcmp(prop->name, "sub_demux"))
1599 source = SUB_SOURCE_DEMUX;
1600 else
1601 return M_PROPERTY_ERROR;
1603 offset = mpctx->global_sub_indices[source];
1604 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1605 return M_PROPERTY_UNAVAILABLE;
1607 is_cur_source = sub_source(mpctx) == source;
1608 switch (action) {
1609 case M_PROPERTY_GET:
1610 if (!arg)
1611 return M_PROPERTY_ERROR;
1612 if (is_cur_source) {
1613 *(int *) arg = mpctx->global_sub_pos - offset;
1614 if (source == SUB_SOURCE_VOBSUB)
1615 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1617 else
1618 *(int *) arg = -1;
1619 return M_PROPERTY_OK;
1620 case M_PROPERTY_PRINT:
1621 if (!arg)
1622 return M_PROPERTY_ERROR;
1623 if (is_cur_source)
1624 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1625 *(char **) arg = malloc(64);
1626 (*(char **) arg)[63] = 0;
1627 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1628 return M_PROPERTY_OK;
1629 case M_PROPERTY_SET:
1630 if (!arg)
1631 return M_PROPERTY_ERROR;
1632 if (*(int *) arg >= 0) {
1633 int index = *(int *)arg;
1634 if (source == SUB_SOURCE_VOBSUB)
1635 index = vobsub_get_index_by_id(vo_vobsub, index);
1636 mpctx->global_sub_pos = offset + index;
1637 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1638 || sub_source(mpctx) != source) {
1639 mpctx->global_sub_pos = -1;
1640 *(int *) arg = -1;
1643 else
1644 mpctx->global_sub_pos = -1;
1645 break;
1646 case M_PROPERTY_STEP_UP:
1647 case M_PROPERTY_STEP_DOWN: {
1648 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1649 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1650 int step = (step_all > 0) ? 1 : -1;
1651 int max_sub_pos_for_source = -1;
1652 if (!is_cur_source)
1653 mpctx->global_sub_pos = -1;
1654 while (step_all) {
1655 if (mpctx->global_sub_pos == -1) {
1656 if (step > 0)
1657 mpctx->global_sub_pos = offset;
1658 else if (max_sub_pos_for_source == -1) {
1659 // Find max pos for specific source
1660 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1661 while (mpctx->global_sub_pos >= 0
1662 && sub_source(mpctx) != source)
1663 --mpctx->global_sub_pos;
1665 else
1666 mpctx->global_sub_pos = max_sub_pos_for_source;
1668 else {
1669 mpctx->global_sub_pos += step;
1670 if (mpctx->global_sub_pos < offset ||
1671 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1672 sub_source(mpctx) != source)
1673 mpctx->global_sub_pos = -1;
1675 step_all -= step;
1677 break;
1679 default:
1680 return M_PROPERTY_NOT_IMPLEMENTED;
1682 --mpctx->global_sub_pos;
1683 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1686 /// Subtitle delay (RW)
1687 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1688 MPContext * mpctx)
1690 if (!mpctx->sh_video)
1691 return M_PROPERTY_UNAVAILABLE;
1692 return m_property_delay(prop, action, arg, &sub_delay);
1695 /// Alignment of text subtitles (RW)
1696 static int mp_property_sub_alignment(m_option_t * prop, int action,
1697 void *arg, MPContext * mpctx)
1699 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1701 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1702 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1703 return M_PROPERTY_UNAVAILABLE;
1705 switch (action) {
1706 case M_PROPERTY_PRINT:
1707 if (!arg)
1708 return M_PROPERTY_ERROR;
1709 M_PROPERTY_CLAMP(prop, sub_alignment);
1710 *(char **) arg = strdup(name[sub_alignment]);
1711 return M_PROPERTY_OK;
1712 case M_PROPERTY_SET:
1713 if (!arg)
1714 return M_PROPERTY_ERROR;
1715 case M_PROPERTY_STEP_UP:
1716 case M_PROPERTY_STEP_DOWN:
1717 vo_osd_changed(OSDTYPE_SUBTITLE);
1718 default:
1719 return m_property_choice(prop, action, arg, &sub_alignment);
1723 /// Subtitle visibility (RW)
1724 static int mp_property_sub_visibility(m_option_t * prop, int action,
1725 void *arg, MPContext * mpctx)
1727 if (!mpctx->sh_video)
1728 return M_PROPERTY_UNAVAILABLE;
1730 switch (action) {
1731 case M_PROPERTY_SET:
1732 if (!arg)
1733 return M_PROPERTY_ERROR;
1734 case M_PROPERTY_STEP_UP:
1735 case M_PROPERTY_STEP_DOWN:
1736 vo_osd_changed(OSDTYPE_SUBTITLE);
1737 if (vo_spudec)
1738 vo_osd_changed(OSDTYPE_SPU);
1739 default:
1740 return m_property_flag(prop, action, arg, &sub_visibility);
1744 /// Show only forced subtitles (RW)
1745 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1746 void *arg, MPContext * mpctx)
1748 if (!vo_spudec)
1749 return M_PROPERTY_UNAVAILABLE;
1751 switch (action) {
1752 case M_PROPERTY_SET:
1753 if (!arg)
1754 return M_PROPERTY_ERROR;
1755 case M_PROPERTY_STEP_UP:
1756 case M_PROPERTY_STEP_DOWN:
1757 m_property_flag(prop, action, arg, &forced_subs_only);
1758 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1759 return M_PROPERTY_OK;
1760 default:
1761 return m_property_flag(prop, action, arg, &forced_subs_only);
1766 #ifdef HAVE_FREETYPE
1767 /// Subtitle scale (RW)
1768 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1769 MPContext * mpctx)
1772 switch (action) {
1773 case M_PROPERTY_SET:
1774 if (!arg)
1775 return M_PROPERTY_ERROR;
1776 M_PROPERTY_CLAMP(prop, *(float *) arg);
1777 text_font_scale_factor = *(float *) arg;
1778 force_load_font = 1;
1779 return M_PROPERTY_OK;
1780 case M_PROPERTY_STEP_UP:
1781 case M_PROPERTY_STEP_DOWN:
1782 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1783 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1784 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1785 force_load_font = 1;
1786 return M_PROPERTY_OK;
1787 default:
1788 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1791 #endif
1793 ///@}
1795 /// \defgroup TVProperties TV properties
1796 /// \ingroup Properties
1797 ///@{
1799 #ifdef USE_TV
1801 /// TV color settings (RW)
1802 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1803 MPContext * mpctx)
1805 int r, val;
1806 tvi_handle_t *tvh = mpctx->demuxer->priv;
1807 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1808 return M_PROPERTY_UNAVAILABLE;
1810 switch (action) {
1811 case M_PROPERTY_SET:
1812 if (!arg)
1813 return M_PROPERTY_ERROR;
1814 M_PROPERTY_CLAMP(prop, *(int *) arg);
1815 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1816 case M_PROPERTY_GET:
1817 return tv_get_color_options(tvh, (int) prop->priv, arg);
1818 case M_PROPERTY_STEP_UP:
1819 case M_PROPERTY_STEP_DOWN:
1820 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1821 if (!r)
1822 return M_PROPERTY_ERROR;
1823 val += (arg ? *(int *) arg : 1) *
1824 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1825 M_PROPERTY_CLAMP(prop, val);
1826 return tv_set_color_options(tvh, (int) prop->priv, val);
1828 return M_PROPERTY_ERROR;
1830 return M_PROPERTY_NOT_IMPLEMENTED;
1833 #endif
1835 #ifdef HAVE_TV_TELETEXT
1836 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1837 MPContext * mpctx)
1839 int val,result;
1840 int base_ioctl=(int)prop->priv;
1842 for teletext's GET,SET,STEP ioctls this is not 0
1843 SET is GET+1
1844 STEP is GET+2
1846 tvi_handle_t *tvh = mpctx->demuxer->priv;
1847 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1848 return M_PROPERTY_UNAVAILABLE;
1849 if(!base_ioctl)
1850 return M_PROPERTY_ERROR;
1852 switch (action) {
1853 case M_PROPERTY_GET:
1854 if (!arg)
1855 return M_PROPERTY_ERROR;
1856 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1857 break;
1858 case M_PROPERTY_SET:
1859 if (!arg)
1860 return M_PROPERTY_ERROR;
1861 M_PROPERTY_CLAMP(prop, *(int *) arg);
1862 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1863 break;
1864 case M_PROPERTY_STEP_UP:
1865 case M_PROPERTY_STEP_DOWN:
1866 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1867 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1868 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1869 break;
1870 default:
1871 return M_PROPERTY_NOT_IMPLEMENTED;
1874 return (result==TVI_CONTROL_TRUE?M_PROPERTY_OK:M_PROPERTY_ERROR);
1877 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1878 MPContext * mpctx)
1880 tvi_handle_t *tvh = mpctx->demuxer->priv;
1881 int result;
1882 int val;
1884 //with tvh==NULL will fail too
1885 result=mp_property_teletext_common(prop,action,arg,mpctx);
1886 if(result!=M_PROPERTY_OK)
1887 return result;
1889 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1890 mp_input_set_section("teletext");
1891 else
1892 mp_input_set_section("tv");
1893 return M_PROPERTY_OK;
1896 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1897 MPContext * mpctx)
1899 tvi_handle_t *tvh = mpctx->demuxer->priv;
1900 int result;
1901 int val;
1902 switch(action){
1903 case M_PROPERTY_STEP_UP:
1904 case M_PROPERTY_STEP_DOWN:
1905 //This should be handled separately
1906 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1907 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1908 break;
1909 default:
1910 result=mp_property_teletext_common(prop,action,arg,mpctx);
1912 return result;
1916 #endif /* HAVE_TV_TELETEXT */
1918 ///@}
1920 /// All properties available in MPlayer.
1921 /** \ingroup Properties
1923 static m_option_t mp_properties[] = {
1924 // General
1925 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1926 M_OPT_RANGE, 0, 3, NULL },
1927 { "loop", mp_property_loop, CONF_TYPE_INT,
1928 M_OPT_MIN, -1, 0, NULL },
1929 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1930 M_OPT_RANGE, 0.01, 100.0, NULL },
1931 { "filename", mp_property_filename, CONF_TYPE_STRING,
1932 0, 0, 0, NULL },
1933 { "path", mp_property_path, CONF_TYPE_STRING,
1934 0, 0, 0, NULL },
1935 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1936 0, 0, 0, NULL },
1937 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1938 M_OPT_MIN, 0, 0, NULL },
1939 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1940 M_OPT_MIN, 0, 0, NULL },
1941 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1942 M_OPT_MIN, 0, 0, NULL },
1943 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1944 M_OPT_MIN, 0, 0, NULL },
1945 { "length", mp_property_length, CONF_TYPE_TIME,
1946 M_OPT_MIN, 0, 0, NULL },
1947 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1948 M_OPT_RANGE, 0, 100, NULL },
1949 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1950 M_OPT_MIN, 0, 0, NULL },
1951 { "chapter", mp_property_chapter, CONF_TYPE_INT,
1952 M_OPT_MIN, 1, 0, NULL },
1953 { "angle", mp_property_angle, CONF_TYPE_INT,
1954 CONF_RANGE, -2, 10, NULL },
1955 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
1956 0, 0, 0, NULL },
1958 // Audio
1959 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
1960 M_OPT_RANGE, 0, 100, NULL },
1961 { "mute", mp_property_mute, CONF_TYPE_FLAG,
1962 M_OPT_RANGE, 0, 1, NULL },
1963 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
1964 M_OPT_RANGE, -100, 100, NULL },
1965 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
1966 0, 0, 0, NULL },
1967 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
1968 0, 0, 0, NULL },
1969 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
1970 0, 0, 0, NULL },
1971 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
1972 0, 0, 0, NULL },
1973 { "channels", mp_property_channels, CONF_TYPE_INT,
1974 0, 0, 0, NULL },
1975 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
1976 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
1977 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
1978 M_OPT_RANGE, -1, 1, NULL },
1980 // Video
1981 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
1982 M_OPT_RANGE, 0, 1, NULL },
1983 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
1984 M_OPT_RANGE, 0, 1, NULL },
1985 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
1986 M_OPT_RANGE, 0, 1, NULL },
1987 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
1988 M_OPT_RANGE, 0, 1, NULL },
1989 { "border", mp_property_border, CONF_TYPE_FLAG,
1990 M_OPT_RANGE, 0, 1, NULL },
1991 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
1992 M_OPT_RANGE, 0, 2, NULL },
1993 { "gamma", mp_property_gamma, CONF_TYPE_INT,
1994 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
1995 { "brightness", mp_property_gamma, CONF_TYPE_INT,
1996 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
1997 { "contrast", mp_property_gamma, CONF_TYPE_INT,
1998 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
1999 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2000 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2001 { "hue", mp_property_gamma, CONF_TYPE_INT,
2002 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2003 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2004 M_OPT_RANGE, 0, 1, NULL },
2005 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2006 M_OPT_RANGE, 0, 1, NULL },
2007 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2008 0, 0, 0, NULL },
2009 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2010 0, 0, 0, NULL },
2011 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2012 0, 0, 0, NULL },
2013 { "width", mp_property_width, CONF_TYPE_INT,
2014 0, 0, 0, NULL },
2015 { "height", mp_property_height, CONF_TYPE_INT,
2016 0, 0, 0, NULL },
2017 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2018 0, 0, 0, NULL },
2019 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2020 0, 0, 0, NULL },
2021 { "switch_video", mp_property_video, CONF_TYPE_INT,
2022 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
2023 { "switch_program", mp_property_program, CONF_TYPE_INT,
2024 CONF_RANGE, -1, 65535, NULL },
2026 // Subs
2027 { "sub", mp_property_sub, CONF_TYPE_INT,
2028 M_OPT_MIN, -1, 0, NULL },
2029 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2030 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2031 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2032 M_OPT_MIN, -1, 0, NULL },
2033 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2034 M_OPT_MIN, -1, 0, NULL },
2035 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2036 M_OPT_MIN, -1, 0, NULL },
2037 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2038 0, 0, 0, NULL },
2039 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2040 M_OPT_RANGE, 0, 100, NULL },
2041 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2042 M_OPT_RANGE, 0, 2, NULL },
2043 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2044 M_OPT_RANGE, 0, 1, NULL },
2045 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2046 M_OPT_RANGE, 0, 1, NULL },
2047 #ifdef HAVE_FREETYPE
2048 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2049 M_OPT_RANGE, 0, 100, NULL },
2050 #endif
2052 #ifdef USE_TV
2053 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2054 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2055 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2056 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2057 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2058 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2059 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2060 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2061 #endif
2063 #ifdef HAVE_TV_TELETEXT
2064 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2065 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2066 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2067 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2068 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2069 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2070 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2071 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2072 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2073 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2074 #endif
2076 { NULL, NULL, NULL, 0, 0, 0, NULL }
2080 int mp_property_do(const char *name, int action, void *val, void *ctx)
2082 return m_property_do(mp_properties, name, action, val, ctx);
2085 char* mp_property_print(const char *name, void* ctx)
2087 char* ret = NULL;
2088 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2089 return NULL;
2090 return ret;
2093 char *property_expand_string(MPContext * mpctx, char *str)
2095 return m_properties_expand_string(mp_properties, str, mpctx);
2098 void property_print_help(void)
2100 m_properties_print_help_list(mp_properties);
2104 ///@}
2105 // Properties group
2109 * \defgroup Command2Property Command to property bridge
2111 * It is used to handle most commands that just set a property
2112 * and optionally display something on the OSD.
2113 * Two kinds of commands are handled: adjust or toggle.
2115 * Adjust commands take 1 or 2 parameters: <value> <abs>
2116 * If <abs> is non-zero the property is set to the given value
2117 * otherwise it is adjusted.
2119 * Toggle commands take 0 or 1 parameters. With no parameter
2120 * or a value less than the property minimum it just steps the
2121 * property to its next value. Otherwise it sets it to the given
2122 * value.
2127 /// List of the commands that can be handled by setting a property.
2128 static struct {
2129 /// property name
2130 const char *name;
2131 /// cmd id
2132 int cmd;
2133 /// set/adjust or toggle command
2134 int toggle;
2135 /// progressbar type
2136 int osd_progbar;
2137 /// osd msg id if it must be shared
2138 int osd_id;
2139 /// osd msg template
2140 const char *osd_msg;
2141 } set_prop_cmd[] = {
2142 // general
2143 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2144 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2145 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2146 // audio
2147 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2148 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2149 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2150 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2151 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2152 // video
2153 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2154 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2155 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2156 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2157 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2158 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2159 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2160 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2161 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2162 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2163 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2164 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2165 // subs
2166 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2167 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2168 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2169 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2170 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2171 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2172 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2173 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2174 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2175 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2176 #ifdef HAVE_FREETYPE
2177 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2178 #endif
2179 #ifdef USE_TV
2180 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2181 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2182 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2183 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2184 #endif
2185 { NULL, 0, 0, 0, -1, NULL }
2189 /// Handle commands that set a property.
2190 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
2192 int i, r;
2193 m_option_t* prop;
2194 const char *pname;
2196 // look for the command
2197 for (i = 0; set_prop_cmd[i].name; i++)
2198 if (set_prop_cmd[i].cmd == cmd->id)
2199 break;
2200 if (!(pname = set_prop_cmd[i].name))
2201 return 0;
2203 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2204 return 0;
2206 // toggle command
2207 if (set_prop_cmd[i].toggle) {
2208 // set to value
2209 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2210 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2211 else
2212 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2213 } else if (cmd->args[1].v.i) //set
2214 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2215 else // adjust
2216 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2218 if (r <= 0)
2219 return 1;
2221 if (set_prop_cmd[i].osd_progbar) {
2222 if (prop->type == CONF_TYPE_INT) {
2223 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2224 set_osd_bar(set_prop_cmd[i].osd_progbar,
2225 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2226 } else if (prop->type == CONF_TYPE_FLOAT) {
2227 float f;
2228 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2229 set_osd_bar(set_prop_cmd[i].osd_progbar,
2230 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2231 } else
2232 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2233 "Property use an unsupported type.\n");
2234 return 1;
2237 if (set_prop_cmd[i].osd_msg) {
2238 char *val = mp_property_print(pname, mpctx);
2239 if (val) {
2240 set_osd_msg(set_prop_cmd[i].osd_id >=
2241 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2242 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2243 free(val);
2246 return 1;
2250 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
2252 sh_audio_t * const sh_audio = mpctx->sh_audio;
2253 sh_video_t * const sh_video = mpctx->sh_video;
2254 int brk_cmd = 0;
2255 if (!set_property_command(mpctx, cmd))
2256 switch (cmd->id) {
2257 case MP_CMD_SEEK:{
2258 float v;
2259 int abs;
2260 if (sh_video)
2261 mpctx->osd_show_percentage = sh_video->fps;
2262 v = cmd->args[0].v.f;
2263 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2264 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2265 abs_seek_pos = 1;
2266 if (sh_video)
2267 mpctx->osd_function =
2268 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2269 rel_seek_secs = v;
2270 } else if (abs) { /* Absolute seek by percentage */
2271 abs_seek_pos = 3;
2272 if (sh_video)
2273 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2274 rel_seek_secs = v / 100.0;
2275 } else {
2276 rel_seek_secs += v;
2277 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2279 brk_cmd = 1;
2281 break;
2283 case MP_CMD_SET_PROPERTY:{
2284 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2285 cmd->args[1].v.s, mpctx);
2286 if (r == M_PROPERTY_UNKNOWN)
2287 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2288 "Unknown property: '%s'\n", cmd->args[0].v.s);
2289 else if (r <= 0)
2290 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2291 "Failed to set property '%s' to '%s'.\n",
2292 cmd->args[0].v.s, cmd->args[1].v.s);
2294 break;
2296 case MP_CMD_STEP_PROPERTY:{
2297 void* arg = NULL;
2298 int r,i;
2299 double d;
2300 off_t o;
2301 if (cmd->args[1].v.f) {
2302 m_option_t* prop;
2303 if((r = mp_property_do(cmd->args[0].v.s,
2304 M_PROPERTY_GET_TYPE,
2305 &prop, mpctx)) <= 0)
2306 goto step_prop_err;
2307 if(prop->type == CONF_TYPE_INT ||
2308 prop->type == CONF_TYPE_FLAG)
2309 i = cmd->args[1].v.f, arg = &i;
2310 else if(prop->type == CONF_TYPE_FLOAT)
2311 arg = &cmd->args[1].v.f;
2312 else if(prop->type == CONF_TYPE_DOUBLE ||
2313 prop->type == CONF_TYPE_TIME)
2314 d = cmd->args[1].v.f, arg = &d;
2315 else if(prop->type == CONF_TYPE_POSITION)
2316 o = cmd->args[1].v.f, arg = &o;
2317 else
2318 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2319 "Ignoring step size stepping property '%s'.\n",
2320 cmd->args[0].v.s);
2322 r = mp_property_do(cmd->args[0].v.s,
2323 cmd->args[2].v.i < 0 ?
2324 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2325 arg, mpctx);
2326 step_prop_err:
2327 if (r == M_PROPERTY_UNKNOWN)
2328 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2329 "Unknown property: '%s'\n", cmd->args[0].v.s);
2330 else if (r <= 0)
2331 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2332 "Failed to increment property '%s' by %f.\n",
2333 cmd->args[0].v.s, cmd->args[1].v.f);
2335 break;
2337 case MP_CMD_GET_PROPERTY:{
2338 char *tmp;
2339 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2340 &tmp, mpctx) <= 0) {
2341 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2342 "Failed to get value of property '%s'.\n",
2343 cmd->args[0].v.s);
2344 break;
2346 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2347 cmd->args[0].v.s, tmp);
2348 free(tmp);
2350 break;
2352 case MP_CMD_EDL_MARK:
2353 if (edl_fd) {
2354 float v = sh_video ? sh_video->pts :
2355 playing_audio_pts(sh_audio, mpctx->d_audio,
2356 mpctx->audio_out);
2358 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2359 mpctx->begin_skip = v;
2360 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2361 } else {
2362 if (mpctx->begin_skip > v)
2363 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2364 else {
2365 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2366 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2368 mpctx->begin_skip = MP_NOPTS_VALUE;
2371 break;
2373 case MP_CMD_SWITCH_RATIO:
2374 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2375 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2376 else
2377 movie_aspect = cmd->args[0].v.f;
2378 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2379 break;
2381 case MP_CMD_SPEED_INCR:{
2382 float v = cmd->args[0].v.f;
2383 playback_speed += v;
2384 build_afilter_chain(sh_audio, &ao_data);
2385 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2386 playback_speed);
2387 } break;
2389 case MP_CMD_SPEED_MULT:{
2390 float v = cmd->args[0].v.f;
2391 playback_speed *= v;
2392 build_afilter_chain(sh_audio, &ao_data);
2393 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2394 playback_speed);
2395 } break;
2397 case MP_CMD_SPEED_SET:{
2398 float v = cmd->args[0].v.f;
2399 playback_speed = v;
2400 build_afilter_chain(sh_audio, &ao_data);
2401 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2402 playback_speed);
2403 } break;
2405 case MP_CMD_FRAME_STEP:
2406 case MP_CMD_PAUSE:
2407 cmd->pausing = 1;
2408 brk_cmd = 1;
2409 break;
2411 case MP_CMD_FILE_FILTER:
2412 file_filter = cmd->args[0].v.i;
2413 break;
2415 case MP_CMD_QUIT:
2416 exit_player_with_rc(MSGTR_Exit_quit,
2417 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2419 case MP_CMD_PLAY_TREE_STEP:{
2420 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2421 int force = cmd->args[1].v.i;
2423 #ifdef HAVE_NEW_GUI
2424 if (use_gui) {
2425 int i = 0;
2426 if (n > 0)
2427 for (i = 0; i < n; i++)
2428 mplNext();
2429 else
2430 for (i = 0; i < -1 * n; i++)
2431 mplPrev();
2432 } else
2433 #endif
2435 if (!force && mpctx->playtree_iter) {
2436 play_tree_iter_t *i =
2437 play_tree_iter_new_copy(mpctx->playtree_iter);
2438 if (play_tree_iter_step(i, n, 0) ==
2439 PLAY_TREE_ITER_ENTRY)
2440 mpctx->eof =
2441 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2442 play_tree_iter_free(i);
2443 } else
2444 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2445 if (mpctx->eof)
2446 mpctx->play_tree_step = n;
2447 brk_cmd = 1;
2450 break;
2452 case MP_CMD_PLAY_TREE_UP_STEP:{
2453 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2454 int force = cmd->args[1].v.i;
2456 if (!force && mpctx->playtree_iter) {
2457 play_tree_iter_t *i =
2458 play_tree_iter_new_copy(mpctx->playtree_iter);
2459 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2460 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2461 play_tree_iter_free(i);
2462 } else
2463 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2464 brk_cmd = 1;
2466 break;
2468 case MP_CMD_PLAY_ALT_SRC_STEP:
2469 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2470 int v = cmd->args[0].v.i;
2471 if (v > 0
2472 && mpctx->playtree_iter->file <
2473 mpctx->playtree_iter->num_files)
2474 mpctx->eof = PT_NEXT_SRC;
2475 else if (v < 0 && mpctx->playtree_iter->file > 1)
2476 mpctx->eof = PT_PREV_SRC;
2478 brk_cmd = 1;
2479 break;
2481 case MP_CMD_SUB_STEP:
2482 if (sh_video) {
2483 int movement = cmd->args[0].v.i;
2484 step_sub(subdata, sh_video->pts, movement);
2485 #ifdef USE_ASS
2486 if (ass_track)
2487 sub_delay +=
2488 ass_step_sub(ass_track,
2489 (sh_video->pts +
2490 sub_delay) * 1000 + .5, movement) / 1000.;
2491 #endif
2492 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2493 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2495 break;
2497 case MP_CMD_SUB_LOG:
2498 log_sub();
2499 break;
2501 case MP_CMD_OSD:{
2502 int v = cmd->args[0].v.i;
2503 int max = (term_osd
2504 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2505 if (osd_level > max)
2506 osd_level = max;
2507 if (v < 0)
2508 osd_level = (osd_level + 1) % (max + 1);
2509 else
2510 osd_level = v > max ? max : v;
2511 /* Show OSD state when disabled, but not when an explicit
2512 argument is given to the OSD command, i.e. in slave mode. */
2513 if (v == -1 && osd_level <= 1)
2514 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2515 MSGTR_OSDosd,
2516 osd_level ? MSGTR_OSDenabled :
2517 MSGTR_OSDdisabled);
2518 else
2519 rm_osd_msg(OSD_MSG_OSD_STATUS);
2521 break;
2523 case MP_CMD_OSD_SHOW_TEXT:
2524 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2525 (cmd->args[1].v.i <
2526 0 ? osd_duration : cmd->args[1].v.i),
2527 "%-.63s", cmd->args[0].v.s);
2528 break;
2530 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2531 char *txt = m_properties_expand_string(mp_properties,
2532 cmd->args[0].v.s,
2533 mpctx);
2534 /* if no argument supplied take default osd_duration, else <arg> ms. */
2535 if (txt) {
2536 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2537 (cmd->args[1].v.i <
2538 0 ? osd_duration : cmd->args[1].v.i),
2539 "%-.63s", txt);
2540 free(txt);
2543 break;
2545 case MP_CMD_LOADFILE:{
2546 play_tree_t *e = play_tree_new();
2547 play_tree_add_file(e, cmd->args[0].v.s);
2549 if (cmd->args[1].v.i) // append
2550 play_tree_append_entry(mpctx->playtree, e);
2551 else {
2552 // Go back to the starting point.
2553 while (play_tree_iter_up_step
2554 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2555 /* NOP */ ;
2556 play_tree_free_list(mpctx->playtree->child, 1);
2557 play_tree_set_child(mpctx->playtree, e);
2558 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2559 mpctx->eof = PT_NEXT_SRC;
2561 brk_cmd = 1;
2563 break;
2565 case MP_CMD_LOADLIST:{
2566 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2567 if (!e)
2568 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2569 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2570 else {
2571 if (cmd->args[1].v.i) // append
2572 play_tree_append_entry(mpctx->playtree, e);
2573 else {
2574 // Go back to the starting point.
2575 while (play_tree_iter_up_step
2576 (mpctx->playtree_iter, 0, 1)
2577 != PLAY_TREE_ITER_END)
2578 /* NOP */ ;
2579 play_tree_free_list(mpctx->playtree->child, 1);
2580 play_tree_set_child(mpctx->playtree, e);
2581 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2582 mpctx->eof = PT_NEXT_SRC;
2585 brk_cmd = 1;
2587 break;
2589 #ifdef USE_RADIO
2590 case MP_CMD_RADIO_STEP_CHANNEL:
2591 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2592 int v = cmd->args[0].v.i;
2593 if (v > 0)
2594 radio_step_channel(mpctx->demuxer->stream,
2595 RADIO_CHANNEL_HIGHER);
2596 else
2597 radio_step_channel(mpctx->demuxer->stream,
2598 RADIO_CHANNEL_LOWER);
2599 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2600 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2601 MSGTR_OSDChannel,
2602 radio_get_channel_name(mpctx->demuxer->stream));
2605 break;
2607 case MP_CMD_RADIO_SET_CHANNEL:
2608 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2609 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2610 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2611 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2612 MSGTR_OSDChannel,
2613 radio_get_channel_name(mpctx->demuxer->stream));
2616 break;
2618 case MP_CMD_RADIO_SET_FREQ:
2619 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2620 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2621 break;
2623 case MP_CMD_RADIO_STEP_FREQ:
2624 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2625 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2626 break;
2627 #endif
2629 #ifdef USE_TV
2630 case MP_CMD_TV_START_SCAN:
2631 if (mpctx->file_format == DEMUXER_TYPE_TV)
2632 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2633 break;
2634 case MP_CMD_TV_SET_FREQ:
2635 if (mpctx->file_format == DEMUXER_TYPE_TV)
2636 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2637 cmd->args[0].v.f * 16.0);
2638 #ifdef HAVE_PVR
2639 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2640 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2641 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2642 pvr_get_current_channelname (mpctx->stream),
2643 pvr_get_current_stationname (mpctx->stream));
2645 #endif /* HAVE_PVR */
2646 break;
2648 case MP_CMD_TV_STEP_FREQ:
2649 if (mpctx->file_format == DEMUXER_TYPE_TV)
2650 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2651 cmd->args[0].v.f * 16.0);
2652 #ifdef HAVE_PVR
2653 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2654 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2655 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2656 pvr_get_current_channelname (mpctx->stream),
2657 pvr_get_current_frequency (mpctx->stream));
2659 #endif /* HAVE_PVR */
2660 break;
2662 case MP_CMD_TV_SET_NORM:
2663 if (mpctx->file_format == DEMUXER_TYPE_TV)
2664 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2665 cmd->args[0].v.s);
2666 break;
2668 case MP_CMD_TV_STEP_CHANNEL:{
2669 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2670 int v = cmd->args[0].v.i;
2671 if (v > 0) {
2672 tv_step_channel((tvi_handle_t *) (mpctx->
2673 demuxer->priv),
2674 TV_CHANNEL_HIGHER);
2675 } else {
2676 tv_step_channel((tvi_handle_t *) (mpctx->
2677 demuxer->priv),
2678 TV_CHANNEL_LOWER);
2680 if (tv_channel_list) {
2681 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2682 MSGTR_OSDChannel, tv_channel_current->name);
2683 //vo_osd_changed(OSDTYPE_SUBTITLE);
2686 #ifdef HAVE_PVR
2687 else if (mpctx->stream &&
2688 mpctx->stream->type == STREAMTYPE_PVR) {
2689 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2690 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2691 pvr_get_current_channelname (mpctx->stream),
2692 pvr_get_current_stationname (mpctx->stream));
2694 #endif /* HAVE_PVR */
2696 #ifdef HAS_DVBIN_SUPPORT
2697 if (mpctx->stream->type == STREAMTYPE_DVB) {
2698 int dir;
2699 int v = cmd->args[0].v.i;
2701 mpctx->last_dvb_step = v;
2702 if (v > 0)
2703 dir = DVB_CHANNEL_HIGHER;
2704 else
2705 dir = DVB_CHANNEL_LOWER;
2708 if (dvb_step_channel(mpctx->stream, dir))
2709 mpctx->eof = mpctx->dvbin_reopen = 1;
2711 #endif /* HAS_DVBIN_SUPPORT */
2712 break;
2714 case MP_CMD_TV_SET_CHANNEL:
2715 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2716 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2717 cmd->args[0].v.s);
2718 if (tv_channel_list) {
2719 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2720 MSGTR_OSDChannel, tv_channel_current->name);
2721 //vo_osd_changed(OSDTYPE_SUBTITLE);
2724 #ifdef HAVE_PVR
2725 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2726 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2727 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2728 pvr_get_current_channelname (mpctx->stream),
2729 pvr_get_current_stationname (mpctx->stream));
2731 #endif /* HAVE_PVR */
2732 break;
2734 #ifdef HAS_DVBIN_SUPPORT
2735 case MP_CMD_DVB_SET_CHANNEL:
2736 if (mpctx->stream->type == STREAMTYPE_DVB) {
2737 mpctx->last_dvb_step = 1;
2739 if (dvb_set_channel
2740 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2741 mpctx->eof = mpctx->dvbin_reopen = 1;
2743 break;
2744 #endif /* HAS_DVBIN_SUPPORT */
2746 case MP_CMD_TV_LAST_CHANNEL:
2747 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2748 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2749 if (tv_channel_list) {
2750 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2751 MSGTR_OSDChannel, tv_channel_current->name);
2752 //vo_osd_changed(OSDTYPE_SUBTITLE);
2755 #ifdef HAVE_PVR
2756 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2757 pvr_set_lastchannel (mpctx->stream);
2758 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2759 pvr_get_current_channelname (mpctx->stream),
2760 pvr_get_current_stationname (mpctx->stream));
2762 #endif /* HAVE_PVR */
2763 break;
2765 case MP_CMD_TV_STEP_NORM:
2766 if (mpctx->file_format == DEMUXER_TYPE_TV)
2767 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2768 break;
2770 case MP_CMD_TV_STEP_CHANNEL_LIST:
2771 if (mpctx->file_format == DEMUXER_TYPE_TV)
2772 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2773 break;
2774 #ifdef HAVE_TV_TELETEXT
2775 case MP_CMD_TV_TELETEXT_ADD_DEC:
2777 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2778 if (mpctx->file_format == DEMUXER_TYPE_TV)
2779 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2780 break;
2782 case MP_CMD_TV_TELETEXT_GO_LINK:
2784 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2785 if (mpctx->file_format == DEMUXER_TYPE_TV)
2786 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2787 break;
2789 #endif /* HAVE_TV_TELETEXT */
2790 #endif /* USE_TV */
2792 case MP_CMD_SUB_LOAD:
2793 if (sh_video) {
2794 int n = mpctx->set_of_sub_size;
2795 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2796 if (n != mpctx->set_of_sub_size) {
2797 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2798 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2799 mpctx->global_sub_size;
2800 ++mpctx->global_sub_size;
2803 break;
2805 case MP_CMD_SUB_REMOVE:
2806 if (sh_video) {
2807 int v = cmd->args[0].v.i;
2808 sub_data *subd;
2809 if (v < 0) {
2810 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2811 subd = mpctx->set_of_subtitles[v];
2812 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2813 MSGTR_RemovedSubtitleFile, v + 1,
2814 filename_recode(subd->filename));
2815 sub_free(subd);
2816 mpctx->set_of_subtitles[v] = NULL;
2818 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2819 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2820 mpctx->set_of_sub_size = 0;
2821 if (mpctx->set_of_sub_pos >= 0) {
2822 mpctx->global_sub_pos = -2;
2823 subdata = NULL;
2824 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2826 } else if (v < mpctx->set_of_sub_size) {
2827 subd = mpctx->set_of_subtitles[v];
2828 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2829 MSGTR_RemovedSubtitleFile, v + 1,
2830 filename_recode(subd->filename));
2831 sub_free(subd);
2832 if (mpctx->set_of_sub_pos == v) {
2833 mpctx->global_sub_pos = -2;
2834 subdata = NULL;
2835 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2836 } else if (mpctx->set_of_sub_pos > v) {
2837 --mpctx->set_of_sub_pos;
2838 --mpctx->global_sub_pos;
2840 while (++v < mpctx->set_of_sub_size)
2841 mpctx->set_of_subtitles[v - 1] =
2842 mpctx->set_of_subtitles[v];
2843 --mpctx->set_of_sub_size;
2844 --mpctx->global_sub_size;
2845 if (mpctx->set_of_sub_size <= 0)
2846 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2847 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2850 break;
2852 case MP_CMD_GET_SUB_VISIBILITY:
2853 if (sh_video) {
2854 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2855 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2857 break;
2859 case MP_CMD_SCREENSHOT:
2860 if (vo_config_count) {
2861 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2862 if (CONTROL_OK !=
2863 ((vf_instance_t *) sh_video->vfilter)->
2864 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2865 &cmd->args[0].v.i))
2866 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2868 break;
2870 case MP_CMD_VF_CHANGE_RECTANGLE:
2871 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2872 break;
2874 case MP_CMD_GET_TIME_LENGTH:{
2875 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2876 demuxer_get_time_length(mpctx->demuxer));
2878 break;
2880 case MP_CMD_GET_FILENAME:{
2881 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2882 get_metadata(META_NAME));
2884 break;
2886 case MP_CMD_GET_VIDEO_CODEC:{
2887 char *inf = get_metadata(META_VIDEO_CODEC);
2888 if (!inf)
2889 inf = strdup("");
2890 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2891 free(inf);
2893 break;
2895 case MP_CMD_GET_VIDEO_BITRATE:{
2896 char *inf = get_metadata(META_VIDEO_BITRATE);
2897 if (!inf)
2898 inf = strdup("");
2899 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2900 free(inf);
2902 break;
2904 case MP_CMD_GET_VIDEO_RESOLUTION:{
2905 char *inf = get_metadata(META_VIDEO_RESOLUTION);
2906 if (!inf)
2907 inf = strdup("");
2908 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2909 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
2910 free(inf);
2912 break;
2914 case MP_CMD_GET_AUDIO_CODEC:{
2915 char *inf = get_metadata(META_AUDIO_CODEC);
2916 if (!inf)
2917 inf = strdup("");
2918 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
2919 free(inf);
2921 break;
2923 case MP_CMD_GET_AUDIO_BITRATE:{
2924 char *inf = get_metadata(META_AUDIO_BITRATE);
2925 if (!inf)
2926 inf = strdup("");
2927 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
2928 free(inf);
2930 break;
2932 case MP_CMD_GET_AUDIO_SAMPLES:{
2933 char *inf = get_metadata(META_AUDIO_SAMPLES);
2934 if (!inf)
2935 inf = strdup("");
2936 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
2937 free(inf);
2939 break;
2941 case MP_CMD_GET_META_TITLE:{
2942 char *inf = get_metadata(META_INFO_TITLE);
2943 if (!inf)
2944 inf = strdup("");
2945 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
2946 free(inf);
2948 break;
2950 case MP_CMD_GET_META_ARTIST:{
2951 char *inf = get_metadata(META_INFO_ARTIST);
2952 if (!inf)
2953 inf = strdup("");
2954 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
2955 free(inf);
2957 break;
2959 case MP_CMD_GET_META_ALBUM:{
2960 char *inf = get_metadata(META_INFO_ALBUM);
2961 if (!inf)
2962 inf = strdup("");
2963 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
2964 free(inf);
2966 break;
2968 case MP_CMD_GET_META_YEAR:{
2969 char *inf = get_metadata(META_INFO_YEAR);
2970 if (!inf)
2971 inf = strdup("");
2972 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
2973 free(inf);
2975 break;
2977 case MP_CMD_GET_META_COMMENT:{
2978 char *inf = get_metadata(META_INFO_COMMENT);
2979 if (!inf)
2980 inf = strdup("");
2981 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
2982 free(inf);
2984 break;
2986 case MP_CMD_GET_META_TRACK:{
2987 char *inf = get_metadata(META_INFO_TRACK);
2988 if (!inf)
2989 inf = strdup("");
2990 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
2991 free(inf);
2993 break;
2995 case MP_CMD_GET_META_GENRE:{
2996 char *inf = get_metadata(META_INFO_GENRE);
2997 if (!inf)
2998 inf = strdup("");
2999 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3000 free(inf);
3002 break;
3004 case MP_CMD_GET_VO_FULLSCREEN:
3005 if (mpctx->video_out && vo_config_count)
3006 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3007 break;
3009 case MP_CMD_GET_PERCENT_POS:
3010 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3011 demuxer_get_percent_pos(mpctx->demuxer));
3012 break;
3014 case MP_CMD_GET_TIME_POS:{
3015 float pos = 0;
3016 if (sh_video)
3017 pos = sh_video->pts;
3018 else if (sh_audio && mpctx->audio_out)
3019 pos =
3020 playing_audio_pts(sh_audio, mpctx->d_audio,
3021 mpctx->audio_out);
3022 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3024 break;
3026 case MP_CMD_RUN:
3027 #ifndef __MINGW32__
3028 if (!fork()) {
3029 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3030 exit(0);
3032 #endif
3033 break;
3035 case MP_CMD_KEYDOWN_EVENTS:
3036 mplayer_put_key(cmd->args[0].v.i);
3037 break;
3039 case MP_CMD_SET_MOUSE_POS:{
3040 int pointer_x, pointer_y;
3041 double dx, dy;
3042 pointer_x = cmd->args[0].v.i;
3043 pointer_y = cmd->args[1].v.i;
3044 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
3045 #ifdef USE_DVDNAV
3046 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3047 && dx > 0.0 && dy > 0.0) {
3048 int button = -1;
3049 pointer_x = (int) (dx * (double) sh_video->disp_w);
3050 pointer_y = (int) (dy * (double) sh_video->disp_h);
3051 mp_dvdnav_update_mouse_pos(mpctx->stream,
3052 pointer_x, pointer_y, &button);
3053 if (button > 0)
3054 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3055 "Selected button number %d", button);
3057 #endif
3058 #ifdef HAVE_MENU
3059 if (use_menu && dx >= 0.0 && dy >= 0.0)
3060 menu_update_mouse_pos(dx, dy);
3061 #endif
3063 break;
3065 #ifdef USE_DVDNAV
3066 case MP_CMD_DVDNAV:{
3067 int button = -1;
3068 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3069 break;
3071 if (mp_dvdnav_handle_input
3072 (mpctx->stream, cmd->args[0].v.i, &button)) {
3073 uninit_player(INITED_ALL - (INITED_STREAM | INITED_INPUT |
3074 (fixed_vo ? INITED_VO : 0)));
3075 brk_cmd = 2;
3076 } else if (button > 0)
3077 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3078 "Selected button number %d", button);
3080 break;
3081 #endif
3083 default:
3084 #ifdef HAVE_NEW_GUI
3085 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3086 guiGetEvent(guiIEvent, (char *) cmd->id);
3087 else
3088 #endif
3089 mp_msg(MSGT_CPLAYER, MSGL_V,
3090 "Received unknown cmd %s\n", cmd->name);
3093 switch (cmd->pausing) {
3094 case 1: // "pausing"
3095 mpctx->osd_function = OSD_PAUSE;
3096 break;
3097 case 3: // "pausing_toggle"
3098 mpctx->was_paused = !mpctx->was_paused;
3099 if (mpctx->was_paused)
3100 mpctx->osd_function = OSD_PAUSE;
3101 else if (mpctx->osd_function == OSD_PAUSE)
3102 mpctx->osd_function = OSD_PLAY;
3103 break;
3104 case 2: // "pausing_keep"
3105 if (mpctx->was_paused)
3106 mpctx->osd_function = OSD_PAUSE;
3108 return brk_cmd;