Merge svn changes up to r27374
[mplayer.git] / command.c
blob78564d6755dd7677e05f40d301ffb94b936711db
1 #include <stdlib.h>
2 #include <inttypes.h>
3 #include <unistd.h>
4 #include <string.h>
6 #include "config.h"
7 #include "command.h"
8 #include "input/input.h"
9 #include "stream/stream.h"
10 #include "libmpdemux/demuxer.h"
11 #include "libmpdemux/stheader.h"
12 #include "codec-cfg.h"
13 #include "mplayer.h"
14 #include "libvo/sub.h"
15 #include "m_option.h"
16 #include "m_property.h"
17 #include "help_mp.h"
18 #include "metadata.h"
19 #include "libmpcodecs/vf.h"
20 #include "libmpcodecs/vd.h"
21 #include "mp_osd.h"
22 #include "libvo/video_out.h"
23 #include "libvo/font_load.h"
24 #include "playtree.h"
25 #include "libao2/audio_out.h"
26 #include "mpcommon.h"
27 #include "mixer.h"
28 #include "libmpcodecs/dec_video.h"
29 #include "vobsub.h"
30 #include "spudec.h"
31 #include "get_path.h"
32 #ifdef CONFIG_TV
33 #include "stream/tv.h"
34 #endif
35 #ifdef CONFIG_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 CONFIG_DVDREAD
45 #include "stream/stream_dvd.h"
46 #endif
47 #ifdef CONFIG_DVDNAV
48 #include "stream/stream_dvdnav.h"
49 #endif
50 #ifdef CONFIG_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"
64 #include "libavutil/avstring.h"
66 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
68 extern int use_menu;
70 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
71 double *dx, double *dy)
73 struct MPOpts *opts = &mpctx->opts;
74 struct vo *vo = mpctx->video_out;
75 //remove the borders, if any, and rescale to the range [0,1],[0,1]
76 if (vo_fs) { //we are in full-screen mode
77 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
78 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
79 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
80 iy -= (opts->vo_screenheight - vo->dheight) / 2;
82 if (ix < 0 || ix > vo->dwidth) {
83 *dx = *dy = -1.0;
84 return;
85 } //we are on one of the borders
86 if (iy < 0 || iy > vo->dheight) {
87 *dx = *dy = -1.0;
88 return;
89 } //we are on one of the borders
92 *dx = (double) ix / (double) vo->dwidth;
93 *dy = (double) iy / (double) vo->dheight;
95 mp_msg(MSGT_CPLAYER, MSGL_V,
96 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
97 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
98 vo->dheight, vo_fs);
101 static int sub_source_by_pos(MPContext *mpctx, int pos)
103 int source = -1;
104 int top = -1;
105 int i;
106 for (i = 0; i < SUB_SOURCES; i++) {
107 int j = mpctx->global_sub_indices[i];
108 if ((j >= 0) && (j > top) && (pos >= j)) {
109 source = i;
110 top = j;
113 return source;
116 static int sub_source(MPContext *mpctx)
118 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
122 * \brief Log the currently displayed subtitle to a file
124 * Logs the current or last displayed subtitle together with filename
125 * and time information to ~/.mplayer/subtitle_log
127 * Intended purpose is to allow convenient marking of bogus subtitles
128 * which need to be fixed while watching the movie.
131 static void log_sub(struct MPContext *mpctx)
133 char *fname;
134 FILE *f;
135 int i;
137 if (subdata == NULL || vo_sub_last == NULL)
138 return;
139 fname = get_path("subtitle_log");
140 f = fopen(fname, "a");
141 if (!f)
142 return;
143 fprintf(f, "----------------------------------------------------------\n");
144 if (subdata->sub_uses_time) {
145 fprintf(f,
146 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
147 mpctx->filename, vo_sub_last->start / 360000,
148 (vo_sub_last->start / 6000) % 60,
149 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
150 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
151 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
152 } else {
153 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
154 vo_sub_last->start, vo_sub_last->end);
156 for (i = 0; i < vo_sub_last->lines; i++) {
157 fprintf(f, "%s\n", vo_sub_last->text[i]);
159 fclose(f);
163 /// \defgroup Properties
164 ///@{
166 /// \defgroup GeneralProperties General properties
167 /// \ingroup Properties
168 ///@{
170 /// OSD level (RW)
171 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
172 MPContext *mpctx)
174 return m_property_choice(prop, action, arg, &osd_level);
177 /// Loop (RW)
178 static int mp_property_loop(m_option_t *prop, int action, void *arg,
179 MPContext *mpctx)
181 struct MPOpts *opts = &mpctx->opts;
182 switch (action) {
183 case M_PROPERTY_PRINT:
184 if (!arg) return M_PROPERTY_ERROR;
185 if (opts->loop_times < 0)
186 *(char**)arg = strdup("off");
187 else if (opts->loop_times == 0)
188 *(char**)arg = strdup("inf");
189 else
190 break;
191 return M_PROPERTY_OK;
193 return m_property_int_range(prop, action, arg, &opts->loop_times);
196 /// Playback speed (RW)
197 static int mp_property_playback_speed(m_option_t *prop, int action,
198 void *arg, MPContext *mpctx)
200 struct MPOpts *opts = &mpctx->opts;
201 switch (action) {
202 case M_PROPERTY_SET:
203 if (!arg)
204 return M_PROPERTY_ERROR;
205 M_PROPERTY_CLAMP(prop, *(float *) arg);
206 opts->playback_speed = *(float *) arg;
207 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
208 return M_PROPERTY_OK;
209 case M_PROPERTY_STEP_UP:
210 case M_PROPERTY_STEP_DOWN:
211 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
212 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
213 M_PROPERTY_CLAMP(prop, opts->playback_speed);
214 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
215 return M_PROPERTY_OK;
217 return m_property_float_range(prop, action, arg, &opts->playback_speed);
220 /// filename with path (RO)
221 static int mp_property_path(m_option_t *prop, int action, void *arg,
222 MPContext *mpctx)
224 return m_property_string_ro(prop, action, arg, mpctx->filename);
227 /// filename without path (RO)
228 static int mp_property_filename(m_option_t *prop, int action, void *arg,
229 MPContext *mpctx)
231 char *f;
232 if (!mpctx->filename)
233 return M_PROPERTY_UNAVAILABLE;
234 if (((f = strrchr(mpctx->filename, '/'))
235 || (f = strrchr(mpctx->filename, '\\'))) && f[1])
236 f++;
237 else
238 f = mpctx->filename;
239 return m_property_string_ro(prop, action, arg, f);
242 /// Demuxer name (RO)
243 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
244 MPContext *mpctx)
246 if (!mpctx->demuxer)
247 return M_PROPERTY_UNAVAILABLE;
248 return m_property_string_ro(prop, action, arg,
249 (char *) mpctx->demuxer->desc->name);
252 /// Position in the stream (RW)
253 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
254 MPContext *mpctx)
256 if (!mpctx->demuxer || !mpctx->demuxer->stream)
257 return M_PROPERTY_UNAVAILABLE;
258 if (!arg)
259 return M_PROPERTY_ERROR;
260 switch (action) {
261 case M_PROPERTY_GET:
262 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
263 return M_PROPERTY_OK;
264 case M_PROPERTY_SET:
265 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
266 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
267 return M_PROPERTY_OK;
269 return M_PROPERTY_NOT_IMPLEMENTED;
272 /// Stream start offset (RO)
273 static int mp_property_stream_start(m_option_t *prop, int action,
274 void *arg, MPContext *mpctx)
276 if (!mpctx->demuxer || !mpctx->demuxer->stream)
277 return M_PROPERTY_UNAVAILABLE;
278 switch (action) {
279 case M_PROPERTY_GET:
280 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
281 return M_PROPERTY_OK;
283 return M_PROPERTY_NOT_IMPLEMENTED;
286 /// Stream end offset (RO)
287 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
288 MPContext *mpctx)
290 if (!mpctx->demuxer || !mpctx->demuxer->stream)
291 return M_PROPERTY_UNAVAILABLE;
292 switch (action) {
293 case M_PROPERTY_GET:
294 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
295 return M_PROPERTY_OK;
297 return M_PROPERTY_NOT_IMPLEMENTED;
300 /// Stream length (RO)
301 static int mp_property_stream_length(m_option_t *prop, int action,
302 void *arg, MPContext *mpctx)
304 if (!mpctx->demuxer || !mpctx->demuxer->stream)
305 return M_PROPERTY_UNAVAILABLE;
306 switch (action) {
307 case M_PROPERTY_GET:
308 *(off_t *) arg =
309 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
310 return M_PROPERTY_OK;
312 return M_PROPERTY_NOT_IMPLEMENTED;
315 /// Media length in seconds (RO)
316 static int mp_property_length(m_option_t *prop, int action, void *arg,
317 MPContext *mpctx)
319 double len;
321 if (!mpctx->demuxer ||
322 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
323 return M_PROPERTY_UNAVAILABLE;
325 return m_property_time_ro(prop, action, arg, len);
328 /// Current position in percent (RW)
329 static int mp_property_percent_pos(m_option_t *prop, int action,
330 void *arg, MPContext *mpctx) {
331 int pos;
333 if (!mpctx->demuxer)
334 return M_PROPERTY_UNAVAILABLE;
336 switch(action) {
337 case M_PROPERTY_SET:
338 if(!arg) return M_PROPERTY_ERROR;
339 M_PROPERTY_CLAMP(prop, *(int*)arg);
340 pos = *(int*)arg;
341 break;
342 case M_PROPERTY_STEP_UP:
343 case M_PROPERTY_STEP_DOWN:
344 pos = demuxer_get_percent_pos(mpctx->demuxer);
345 pos += (arg ? *(int*)arg : 10) *
346 (action == M_PROPERTY_STEP_UP ? 1 : -1);
347 M_PROPERTY_CLAMP(prop, pos);
348 break;
349 default:
350 return m_property_int_ro(prop, action, arg,
351 demuxer_get_percent_pos(mpctx->demuxer));
354 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
355 mpctx->rel_seek_secs = pos / 100.0;
356 return M_PROPERTY_OK;
359 /// Current position in seconds (RW)
360 static int mp_property_time_pos(m_option_t *prop, int action,
361 void *arg, MPContext *mpctx) {
362 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
363 return M_PROPERTY_UNAVAILABLE;
365 switch(action) {
366 case M_PROPERTY_SET:
367 if(!arg) return M_PROPERTY_ERROR;
368 M_PROPERTY_CLAMP(prop, *(double*)arg);
369 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
370 mpctx->rel_seek_secs = *(double*)arg;
371 return M_PROPERTY_OK;
372 case M_PROPERTY_STEP_UP:
373 case M_PROPERTY_STEP_DOWN:
374 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
375 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
376 return M_PROPERTY_OK;
378 return m_property_time_ro(prop, action, arg,
379 mpctx->sh_video ? mpctx->sh_video->pts :
380 playing_audio_pts(mpctx));
383 /// Current chapter (RW)
384 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
385 MPContext *mpctx)
387 int chapter;
388 float next_pts = 0;
389 int chapter_num;
390 int step_all;
391 char *chapter_name = NULL;
393 chapter = demuxer_get_current_chapter(mpctx->demuxer);
394 if (chapter < 0)
395 return M_PROPERTY_UNAVAILABLE;
397 switch (action) {
398 case M_PROPERTY_GET:
399 if (!arg)
400 return M_PROPERTY_ERROR;
401 *(int *) arg = chapter;
402 return M_PROPERTY_OK;
403 case M_PROPERTY_PRINT: {
404 if (!arg)
405 return M_PROPERTY_ERROR;
406 chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter);
407 if (!chapter_name)
408 return M_PROPERTY_UNAVAILABLE;
409 *(char **) arg = chapter_name;
410 return M_PROPERTY_OK;
412 case M_PROPERTY_SET:
413 if (!arg)
414 return M_PROPERTY_ERROR;
415 M_PROPERTY_CLAMP(prop, *(int*)arg);
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 += step_all;
424 if (chapter < 0)
425 chapter = 0;
426 break;
428 default:
429 return M_PROPERTY_NOT_IMPLEMENTED;
431 mpctx->rel_seek_secs = 0;
432 mpctx->abs_seek_pos = 0;
433 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
434 &next_pts, &chapter_num, &chapter_name);
435 if (chapter >= 0) {
436 if (next_pts > -1.0) {
437 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
438 mpctx->rel_seek_secs = next_pts;
440 if (chapter_name)
441 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
442 MSGTR_OSDChapter, chapter + 1, chapter_name);
444 else if (step_all > 0)
445 mpctx->rel_seek_secs = 1000000000.;
446 else
447 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
448 MSGTR_OSDChapter, 0, MSGTR_Unknown);
449 if (chapter_name)
450 free(chapter_name);
451 return M_PROPERTY_OK;
454 /// Current dvd angle (RW)
455 static int mp_property_angle(m_option_t *prop, int action, void *arg,
456 MPContext *mpctx)
458 int angle;
459 int angles;
460 char *angle_name = NULL;
462 angle = demuxer_get_current_angle(mpctx->demuxer);
463 if (angle < 0)
464 return M_PROPERTY_UNAVAILABLE;
465 angles = demuxer_angles_count(mpctx->demuxer);
466 if (angles <= 1)
467 return M_PROPERTY_UNAVAILABLE;
469 switch (action) {
470 case M_PROPERTY_GET:
471 if (!arg)
472 return M_PROPERTY_ERROR;
473 *(int *) arg = angle;
474 return M_PROPERTY_OK;
475 case M_PROPERTY_PRINT: {
476 if (!arg)
477 return M_PROPERTY_ERROR;
478 angle_name = calloc(1, 64);
479 if (!angle_name)
480 return M_PROPERTY_UNAVAILABLE;
481 snprintf(angle_name, 64, "%d/%d", angle, angles);
482 *(char **) arg = angle_name;
483 return M_PROPERTY_OK;
485 case M_PROPERTY_SET:
486 if (!arg)
487 return M_PROPERTY_ERROR;
488 angle = *(int *)arg;
489 M_PROPERTY_CLAMP(prop, angle);
490 break;
491 case M_PROPERTY_STEP_UP:
492 case M_PROPERTY_STEP_DOWN: {
493 int step = 0;
494 if(arg)
495 step = *(int*)arg;
496 if(!step)
497 step = 1;
498 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
499 angle += step;
500 if (angle < 1) //cycle
501 angle = angles;
502 break;
504 default:
505 return M_PROPERTY_NOT_IMPLEMENTED;
507 angle = demuxer_set_angle(mpctx->demuxer, angle);
508 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
509 MSGTR_OSDAngle, angle, angles);
510 if (angle_name)
511 free(angle_name);
512 return M_PROPERTY_OK;
515 /// Demuxer meta data
516 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
517 MPContext *mpctx) {
518 m_property_action_t* ka;
519 char* meta;
520 static const m_option_t key_type =
521 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
522 if (!mpctx->demuxer)
523 return M_PROPERTY_UNAVAILABLE;
525 switch(action) {
526 case M_PROPERTY_GET:
527 if(!arg) return M_PROPERTY_ERROR;
528 *(char***)arg = mpctx->demuxer->info;
529 return M_PROPERTY_OK;
530 case M_PROPERTY_KEY_ACTION:
531 if(!arg) return M_PROPERTY_ERROR;
532 ka = arg;
533 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
534 return M_PROPERTY_UNKNOWN;
535 switch(ka->action) {
536 case M_PROPERTY_GET:
537 if(!ka->arg) return M_PROPERTY_ERROR;
538 *(char**)ka->arg = meta;
539 return M_PROPERTY_OK;
540 case M_PROPERTY_GET_TYPE:
541 if(!ka->arg) return M_PROPERTY_ERROR;
542 *(m_option_t**)ka->arg = &key_type;
543 return M_PROPERTY_OK;
546 return M_PROPERTY_NOT_IMPLEMENTED;
550 ///@}
552 /// \defgroup AudioProperties Audio properties
553 /// \ingroup Properties
554 ///@{
556 /// Volume (RW)
557 static int mp_property_volume(m_option_t *prop, int action, void *arg,
558 MPContext *mpctx)
561 if (!mpctx->sh_audio)
562 return M_PROPERTY_UNAVAILABLE;
564 switch (action) {
565 case M_PROPERTY_GET:
566 if (!arg)
567 return M_PROPERTY_ERROR;
568 mixer_getbothvolume(&mpctx->mixer, arg);
569 return M_PROPERTY_OK;
570 case M_PROPERTY_PRINT:{
571 float vol;
572 if (!arg)
573 return M_PROPERTY_ERROR;
574 mixer_getbothvolume(&mpctx->mixer, &vol);
575 return m_property_float_range(prop, action, arg, &vol);
577 case M_PROPERTY_STEP_UP:
578 case M_PROPERTY_STEP_DOWN:
579 case M_PROPERTY_SET:
580 break;
581 default:
582 return M_PROPERTY_NOT_IMPLEMENTED;
585 if (mpctx->edl_muted)
586 return M_PROPERTY_DISABLED;
587 mpctx->user_muted = 0;
589 switch (action) {
590 case M_PROPERTY_SET:
591 if (!arg)
592 return M_PROPERTY_ERROR;
593 M_PROPERTY_CLAMP(prop, *(float *) arg);
594 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
595 return M_PROPERTY_OK;
596 case M_PROPERTY_STEP_UP:
597 if (arg && *(float *) arg <= 0)
598 mixer_decvolume(&mpctx->mixer);
599 else
600 mixer_incvolume(&mpctx->mixer);
601 return M_PROPERTY_OK;
602 case M_PROPERTY_STEP_DOWN:
603 if (arg && *(float *) arg <= 0)
604 mixer_incvolume(&mpctx->mixer);
605 else
606 mixer_decvolume(&mpctx->mixer);
607 return M_PROPERTY_OK;
609 return M_PROPERTY_NOT_IMPLEMENTED;
612 /// Mute (RW)
613 static int mp_property_mute(m_option_t *prop, int action, void *arg,
614 MPContext *mpctx)
617 if (!mpctx->sh_audio)
618 return M_PROPERTY_UNAVAILABLE;
620 switch (action) {
621 case M_PROPERTY_SET:
622 if (mpctx->edl_muted)
623 return M_PROPERTY_DISABLED;
624 if (!arg)
625 return M_PROPERTY_ERROR;
626 if ((!!*(int *) arg) != mpctx->mixer.muted)
627 mixer_mute(&mpctx->mixer);
628 mpctx->user_muted = mpctx->mixer.muted;
629 return M_PROPERTY_OK;
630 case M_PROPERTY_STEP_UP:
631 case M_PROPERTY_STEP_DOWN:
632 if (mpctx->edl_muted)
633 return M_PROPERTY_DISABLED;
634 mixer_mute(&mpctx->mixer);
635 mpctx->user_muted = mpctx->mixer.muted;
636 return M_PROPERTY_OK;
637 case M_PROPERTY_PRINT:
638 if (!arg)
639 return M_PROPERTY_ERROR;
640 if (mpctx->edl_muted) {
641 *(char **) arg = strdup(MSGTR_EnabledEdl);
642 return M_PROPERTY_OK;
644 default:
645 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
650 /// Audio delay (RW)
651 static int mp_property_audio_delay(m_option_t *prop, int action,
652 void *arg, MPContext *mpctx)
654 if (!(mpctx->sh_audio && mpctx->sh_video))
655 return M_PROPERTY_UNAVAILABLE;
656 switch (action) {
657 case M_PROPERTY_SET:
658 case M_PROPERTY_STEP_UP:
659 case M_PROPERTY_STEP_DOWN: {
660 int ret;
661 float delay = audio_delay;
662 ret = m_property_delay(prop, action, arg, &audio_delay);
663 if (ret != M_PROPERTY_OK)
664 return ret;
665 if (mpctx->sh_audio)
666 mpctx->delay -= audio_delay - delay;
668 return M_PROPERTY_OK;
669 default:
670 return m_property_delay(prop, action, arg, &audio_delay);
674 /// Audio codec tag (RO)
675 static int mp_property_audio_format(m_option_t *prop, int action,
676 void *arg, MPContext *mpctx)
678 if (!mpctx->sh_audio)
679 return M_PROPERTY_UNAVAILABLE;
680 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
683 /// Audio codec name (RO)
684 static int mp_property_audio_codec(m_option_t *prop, int action,
685 void *arg, MPContext *mpctx)
687 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
688 return M_PROPERTY_UNAVAILABLE;
689 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
692 /// Audio bitrate (RO)
693 static int mp_property_audio_bitrate(m_option_t *prop, int action,
694 void *arg, MPContext *mpctx)
696 if (!mpctx->sh_audio)
697 return M_PROPERTY_UNAVAILABLE;
698 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
701 /// Samplerate (RO)
702 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
703 MPContext *mpctx)
705 if (!mpctx->sh_audio)
706 return M_PROPERTY_UNAVAILABLE;
707 switch(action) {
708 case M_PROPERTY_PRINT:
709 if(!arg) return M_PROPERTY_ERROR;
710 *(char**)arg = malloc(16);
711 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
712 return M_PROPERTY_OK;
714 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
717 /// Number of channels (RO)
718 static int mp_property_channels(m_option_t *prop, int action, void *arg,
719 MPContext *mpctx)
721 if (!mpctx->sh_audio)
722 return M_PROPERTY_UNAVAILABLE;
723 switch (action) {
724 case M_PROPERTY_PRINT:
725 if (!arg)
726 return M_PROPERTY_ERROR;
727 switch (mpctx->sh_audio->channels) {
728 case 1:
729 *(char **) arg = strdup("mono");
730 break;
731 case 2:
732 *(char **) arg = strdup("stereo");
733 break;
734 default:
735 *(char **) arg = malloc(32);
736 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
738 return M_PROPERTY_OK;
740 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
743 /// Balance (RW)
744 static int mp_property_balance(m_option_t *prop, int action, void *arg,
745 MPContext *mpctx)
747 float bal;
749 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
750 return M_PROPERTY_UNAVAILABLE;
752 switch (action) {
753 case M_PROPERTY_GET:
754 if (!arg)
755 return M_PROPERTY_ERROR;
756 mixer_getbalance(&mpctx->mixer, arg);
757 return M_PROPERTY_OK;
758 case M_PROPERTY_PRINT: {
759 char** str = arg;
760 if (!arg)
761 return M_PROPERTY_ERROR;
762 mixer_getbalance(&mpctx->mixer, &bal);
763 if (bal == 0.f)
764 *str = strdup("center");
765 else if (bal == -1.f)
766 *str = strdup("left only");
767 else if (bal == 1.f)
768 *str = strdup("right only");
769 else {
770 unsigned right = (bal + 1.f) / 2.f * 100.f;
771 *str = malloc(sizeof("left xxx%, right xxx%"));
772 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
774 return M_PROPERTY_OK;
776 case M_PROPERTY_STEP_UP:
777 case M_PROPERTY_STEP_DOWN:
778 mixer_getbalance(&mpctx->mixer, &bal);
779 bal += (arg ? *(float*)arg : .1f) *
780 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
781 M_PROPERTY_CLAMP(prop, bal);
782 mixer_setbalance(&mpctx->mixer, bal);
783 return M_PROPERTY_OK;
784 case M_PROPERTY_SET:
785 if (!arg)
786 return M_PROPERTY_ERROR;
787 M_PROPERTY_CLAMP(prop, *(float*)arg);
788 mixer_setbalance(&mpctx->mixer, *(float*)arg);
789 return M_PROPERTY_OK;
791 return M_PROPERTY_NOT_IMPLEMENTED;
794 /// Selected audio id (RW)
795 static int mp_property_audio(m_option_t *prop, int action, void *arg,
796 MPContext *mpctx)
798 struct MPOpts *opts = &mpctx->opts;
799 int current_id = -1, tmp;
801 switch (action) {
802 case M_PROPERTY_GET:
803 if (!mpctx->sh_audio)
804 return M_PROPERTY_UNAVAILABLE;
805 if (!arg)
806 return M_PROPERTY_ERROR;
807 *(int *) arg = opts->audio_id;
808 return M_PROPERTY_OK;
809 case M_PROPERTY_PRINT:
810 if (!mpctx->sh_audio)
811 return M_PROPERTY_UNAVAILABLE;
812 if (!arg)
813 return M_PROPERTY_ERROR;
815 if (opts->audio_id < 0)
816 *(char **) arg = strdup(MSGTR_Disabled);
817 else {
818 char lang[40] = MSGTR_Unknown;
819 sh_audio_t* sh = mpctx->sh_audio;
820 if (sh && sh->lang)
821 av_strlcpy(lang, sh->lang, 40);
822 #ifdef CONFIG_DVDREAD
823 else if (mpctx->stream->type == STREAMTYPE_DVD) {
824 int code = dvd_lang_from_aid(mpctx->stream, opts->audio_id);
825 if (code) {
826 lang[0] = code >> 8;
827 lang[1] = code;
828 lang[2] = 0;
831 #endif
833 #ifdef CONFIG_DVDNAV
834 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
835 mp_dvdnav_lang_from_aid(mpctx->stream, opts->audio_id, lang);
836 #endif
837 *(char **) arg = malloc(64);
838 snprintf(*(char **) arg, 64, "(%d) %s", opts->audio_id, lang);
840 return M_PROPERTY_OK;
842 case M_PROPERTY_STEP_UP:
843 case M_PROPERTY_SET:
844 if (action == M_PROPERTY_SET && arg)
845 tmp = *((int *) arg);
846 else
847 tmp = -1;
848 current_id = mpctx->demuxer->audio->id;
849 opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
850 if (opts->audio_id == -2
851 || (opts->audio_id > -1
852 && mpctx->demuxer->audio->id != current_id && current_id != -2))
853 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
854 if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
855 sh_audio_t *sh2;
856 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
857 if (sh2) {
858 sh2->ds = mpctx->demuxer->audio;
859 mpctx->sh_audio = sh2;
860 reinit_audio_chain(mpctx);
863 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id);
864 return M_PROPERTY_OK;
865 default:
866 return M_PROPERTY_NOT_IMPLEMENTED;
871 /// Selected video id (RW)
872 static int mp_property_video(m_option_t *prop, int action, void *arg,
873 MPContext *mpctx)
875 struct MPOpts *opts = &mpctx->opts;
876 int current_id = -1, tmp;
878 switch (action) {
879 case M_PROPERTY_GET:
880 if (!mpctx->sh_video)
881 return M_PROPERTY_UNAVAILABLE;
882 if (!arg)
883 return M_PROPERTY_ERROR;
884 *(int *) arg = opts->video_id;
885 return M_PROPERTY_OK;
886 case M_PROPERTY_PRINT:
887 if (!mpctx->sh_video)
888 return M_PROPERTY_UNAVAILABLE;
889 if (!arg)
890 return M_PROPERTY_ERROR;
892 if (opts->video_id < 0)
893 *(char **) arg = strdup(MSGTR_Disabled);
894 else {
895 char lang[40] = MSGTR_Unknown;
896 *(char **) arg = malloc(64);
897 snprintf(*(char **) arg, 64, "(%d) %s", opts->video_id, lang);
899 return M_PROPERTY_OK;
901 case M_PROPERTY_STEP_UP:
902 case M_PROPERTY_SET:
903 current_id = mpctx->demuxer->video->id;
904 if (action == M_PROPERTY_SET && arg)
905 tmp = *((int *) arg);
906 else
907 tmp = -1;
908 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
909 if (opts->video_id == -2
910 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
911 && current_id != -2))
912 uninit_player(mpctx, INITIALIZED_VCODEC |
913 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
914 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
915 sh_video_t *sh2;
916 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
917 if (sh2) {
918 sh2->ds = mpctx->demuxer->video;
919 mpctx->sh_video = sh2;
920 reinit_video_chain(mpctx);
923 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
924 return M_PROPERTY_OK;
926 default:
927 return M_PROPERTY_NOT_IMPLEMENTED;
931 static int mp_property_program(m_option_t *prop, int action, void *arg,
932 MPContext *mpctx)
934 demux_program_t prog;
936 switch (action) {
937 case M_PROPERTY_STEP_UP:
938 case M_PROPERTY_SET:
939 if (action == M_PROPERTY_SET && arg)
940 prog.progid = *((int *) arg);
941 else
942 prog.progid = -1;
943 if (demux_control
944 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
945 &prog) == DEMUXER_CTRL_NOTIMPL)
946 return M_PROPERTY_ERROR;
948 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
949 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
950 return M_PROPERTY_OK;
952 default:
953 return M_PROPERTY_NOT_IMPLEMENTED;
957 ///@}
959 /// \defgroup VideoProperties Video properties
960 /// \ingroup Properties
961 ///@{
963 /// Fullscreen state (RW)
964 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
965 MPContext *mpctx)
968 if (!mpctx->video_out)
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, *(int *) arg);
976 if (vo_fs == !!*(int *) arg)
977 return M_PROPERTY_OK;
978 case M_PROPERTY_STEP_UP:
979 case M_PROPERTY_STEP_DOWN:
980 #ifdef HAVE_NEW_GUI
981 if (use_gui)
982 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
983 else
984 #endif
985 if (mpctx->video_out->config_ok)
986 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
987 return M_PROPERTY_OK;
988 default:
989 return m_property_flag(prop, action, arg, &vo_fs);
993 static int mp_property_deinterlace(m_option_t *prop, int action,
994 void *arg, MPContext *mpctx)
996 int deinterlace;
997 vf_instance_t *vf;
998 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
999 return M_PROPERTY_UNAVAILABLE;
1000 vf = mpctx->sh_video->vfilter;
1001 switch (action) {
1002 case M_PROPERTY_GET:
1003 if (!arg)
1004 return M_PROPERTY_ERROR;
1005 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1006 return M_PROPERTY_OK;
1007 case M_PROPERTY_SET:
1008 if (!arg)
1009 return M_PROPERTY_ERROR;
1010 M_PROPERTY_CLAMP(prop, *(int *) arg);
1011 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1012 return M_PROPERTY_OK;
1013 case M_PROPERTY_STEP_UP:
1014 case M_PROPERTY_STEP_DOWN:
1015 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1016 deinterlace = !deinterlace;
1017 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1018 return M_PROPERTY_OK;
1020 return M_PROPERTY_NOT_IMPLEMENTED;
1023 /// Panscan (RW)
1024 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1025 MPContext *mpctx)
1028 if (!mpctx->video_out
1029 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1030 return M_PROPERTY_UNAVAILABLE;
1032 switch (action) {
1033 case M_PROPERTY_SET:
1034 if (!arg)
1035 return M_PROPERTY_ERROR;
1036 M_PROPERTY_CLAMP(prop, *(float *) arg);
1037 vo_panscan = *(float *) arg;
1038 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1039 return M_PROPERTY_OK;
1040 case M_PROPERTY_STEP_UP:
1041 case M_PROPERTY_STEP_DOWN:
1042 vo_panscan += (arg ? *(float *) arg : 0.1) *
1043 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1044 if (vo_panscan > 1)
1045 vo_panscan = 1;
1046 else if (vo_panscan < 0)
1047 vo_panscan = 0;
1048 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1049 return M_PROPERTY_OK;
1050 default:
1051 return m_property_float_range(prop, action, arg, &vo_panscan);
1055 /// Helper to set vo flags.
1056 /** \ingroup PropertyImplHelper
1058 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1059 int vo_ctrl, int *vo_var, MPContext *mpctx)
1062 if (!mpctx->video_out)
1063 return M_PROPERTY_UNAVAILABLE;
1065 switch (action) {
1066 case M_PROPERTY_SET:
1067 if (!arg)
1068 return M_PROPERTY_ERROR;
1069 M_PROPERTY_CLAMP(prop, *(int *) arg);
1070 if (*vo_var == !!*(int *) arg)
1071 return M_PROPERTY_OK;
1072 case M_PROPERTY_STEP_UP:
1073 case M_PROPERTY_STEP_DOWN:
1074 if (mpctx->video_out->config_ok)
1075 vo_control(mpctx->video_out, vo_ctrl, 0);
1076 return M_PROPERTY_OK;
1077 default:
1078 return m_property_flag(prop, action, arg, vo_var);
1082 /// Window always on top (RW)
1083 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1084 MPContext *mpctx)
1086 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1087 &mpctx->opts.vo_ontop, mpctx);
1090 /// Display in the root window (RW)
1091 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1092 MPContext *mpctx)
1094 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1095 &vo_rootwin, mpctx);
1098 /// Show window borders (RW)
1099 static int mp_property_border(m_option_t *prop, int action, void *arg,
1100 MPContext *mpctx)
1102 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1103 &vo_border, mpctx);
1106 /// Framedropping state (RW)
1107 static int mp_property_framedropping(m_option_t *prop, int action,
1108 void *arg, MPContext *mpctx)
1111 if (!mpctx->sh_video)
1112 return M_PROPERTY_UNAVAILABLE;
1114 switch (action) {
1115 case M_PROPERTY_PRINT:
1116 if (!arg)
1117 return M_PROPERTY_ERROR;
1118 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1119 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1120 MSGTR_Disabled));
1121 return M_PROPERTY_OK;
1122 default:
1123 return m_property_choice(prop, action, arg, &frame_dropping);
1127 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1128 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1129 MPContext *mpctx)
1131 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1132 int r, val;
1134 if (!mpctx->sh_video)
1135 return M_PROPERTY_UNAVAILABLE;
1137 if (gamma[0] == 1000) {
1138 gamma[0] = 0;
1139 get_video_colors(mpctx->sh_video, prop->name, gamma);
1142 switch (action) {
1143 case M_PROPERTY_SET:
1144 if (!arg)
1145 return M_PROPERTY_ERROR;
1146 M_PROPERTY_CLAMP(prop, *(int *) arg);
1147 *gamma = *(int *) arg;
1148 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1149 if (r <= 0)
1150 break;
1151 return r;
1152 case M_PROPERTY_GET:
1153 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1154 if (!arg)
1155 return M_PROPERTY_ERROR;
1156 *(int *)arg = val;
1157 return M_PROPERTY_OK;
1159 break;
1160 case M_PROPERTY_STEP_UP:
1161 case M_PROPERTY_STEP_DOWN:
1162 *gamma += (arg ? *(int *) arg : 1) *
1163 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1164 M_PROPERTY_CLAMP(prop, *gamma);
1165 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1166 if (r <= 0)
1167 break;
1168 return r;
1169 default:
1170 return M_PROPERTY_NOT_IMPLEMENTED;
1173 #ifdef CONFIG_TV
1174 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1175 int l = strlen(prop->name);
1176 char tv_prop[3 + l + 1];
1177 sprintf(tv_prop, "tv_%s", prop->name);
1178 return mp_property_do(tv_prop, action, arg, mpctx);
1180 #endif
1182 return M_PROPERTY_UNAVAILABLE;
1185 /// VSync (RW)
1186 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1187 MPContext *mpctx)
1189 return m_property_flag(prop, action, arg, &vo_vsync);
1192 /// Video codec tag (RO)
1193 static int mp_property_video_format(m_option_t *prop, int action,
1194 void *arg, MPContext *mpctx)
1196 char* meta;
1197 if (!mpctx->sh_video)
1198 return M_PROPERTY_UNAVAILABLE;
1199 switch(action) {
1200 case M_PROPERTY_PRINT:
1201 if (!arg)
1202 return M_PROPERTY_ERROR;
1203 switch(mpctx->sh_video->format) {
1204 case 0x10000001:
1205 meta = strdup ("mpeg1"); break;
1206 case 0x10000002:
1207 meta = strdup ("mpeg2"); break;
1208 case 0x10000004:
1209 meta = strdup ("mpeg4"); break;
1210 case 0x10000005:
1211 meta = strdup ("h264"); break;
1212 default:
1213 if(mpctx->sh_video->format >= 0x20202020) {
1214 meta = malloc(5);
1215 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1216 } else {
1217 meta = malloc(20);
1218 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1221 *(char**)arg = meta;
1222 return M_PROPERTY_OK;
1224 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1227 /// Video codec name (RO)
1228 static int mp_property_video_codec(m_option_t *prop, int action,
1229 void *arg, MPContext *mpctx)
1231 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1232 return M_PROPERTY_UNAVAILABLE;
1233 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1237 /// Video bitrate (RO)
1238 static int mp_property_video_bitrate(m_option_t *prop, int action,
1239 void *arg, MPContext *mpctx)
1241 if (!mpctx->sh_video)
1242 return M_PROPERTY_UNAVAILABLE;
1243 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1246 /// Video display width (RO)
1247 static int mp_property_width(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_w);
1255 /// Video display height (RO)
1256 static int mp_property_height(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_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1264 /// Video fps (RO)
1265 static int mp_property_fps(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->fps);
1273 /// Video aspect (RO)
1274 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1275 MPContext *mpctx)
1277 if (!mpctx->sh_video)
1278 return M_PROPERTY_UNAVAILABLE;
1279 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1282 ///@}
1284 /// \defgroup SubProprties Subtitles properties
1285 /// \ingroup Properties
1286 ///@{
1288 /// Text subtitle position (RW)
1289 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1290 MPContext *mpctx)
1292 if (!mpctx->sh_video)
1293 return M_PROPERTY_UNAVAILABLE;
1295 switch (action) {
1296 case M_PROPERTY_SET:
1297 if (!arg)
1298 return M_PROPERTY_ERROR;
1299 case M_PROPERTY_STEP_UP:
1300 case M_PROPERTY_STEP_DOWN:
1301 vo_osd_changed(OSDTYPE_SUBTITLE);
1302 default:
1303 return m_property_int_range(prop, action, arg, &sub_pos);
1307 /// Selected subtitles (RW)
1308 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1309 MPContext *mpctx)
1311 struct MPOpts *opts = &mpctx->opts;
1312 demux_stream_t *const d_sub = mpctx->d_sub;
1313 const int global_sub_size = mpctx->global_sub_size;
1314 int source = -1, reset_spu = 0;
1315 char *sub_name;
1317 if (global_sub_size <= 0)
1318 return M_PROPERTY_UNAVAILABLE;
1320 switch (action) {
1321 case M_PROPERTY_GET:
1322 if (!arg)
1323 return M_PROPERTY_ERROR;
1324 *(int *) arg = mpctx->global_sub_pos;
1325 return M_PROPERTY_OK;
1326 case M_PROPERTY_PRINT:
1327 if (!arg)
1328 return M_PROPERTY_ERROR;
1329 *(char **) arg = malloc(64);
1330 (*(char **) arg)[63] = 0;
1331 sub_name = 0;
1332 if (subdata)
1333 sub_name = subdata->filename;
1334 #ifdef CONFIG_ASS
1335 if (ass_track && ass_track->name)
1336 sub_name = ass_track->name;
1337 #endif
1338 if (sub_name) {
1339 char *tmp, *tmp2;
1340 tmp = sub_name;
1341 if ((tmp2 = strrchr(tmp, '/')))
1342 tmp = tmp2 + 1;
1344 snprintf(*(char **) arg, 63, "(%d) %s%s",
1345 mpctx->set_of_sub_pos + 1,
1346 strlen(tmp) < 20 ? "" : "...",
1347 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1348 return M_PROPERTY_OK;
1350 #ifdef CONFIG_DVDNAV
1351 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1352 if (vo_spudec && opts->sub_id >= 0) {
1353 unsigned char lang[3];
1354 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1355 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1356 return M_PROPERTY_OK;
1360 #endif
1362 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1363 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1364 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1365 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1366 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1367 if (!lang) lang = MSGTR_Unknown;
1368 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1369 return M_PROPERTY_OK;
1372 if (vo_vobsub && vobsub_id >= 0) {
1373 const char *language = MSGTR_Unknown;
1374 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1375 snprintf(*(char **) arg, 63, "(%d) %s",
1376 vobsub_id, language ? language : MSGTR_Unknown);
1377 return M_PROPERTY_OK;
1379 #ifdef CONFIG_DVDREAD
1380 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1381 && opts->sub_id >= 0) {
1382 char lang[3];
1383 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1384 lang[0] = code >> 8;
1385 lang[1] = code;
1386 lang[2] = 0;
1387 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1388 return M_PROPERTY_OK;
1390 #endif
1391 if (opts->sub_id >= 0) {
1392 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, MSGTR_Unknown);
1393 return M_PROPERTY_OK;
1395 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1396 return M_PROPERTY_OK;
1398 case M_PROPERTY_SET:
1399 if (!arg)
1400 return M_PROPERTY_ERROR;
1401 if (*(int *) arg < -1)
1402 *(int *) arg = -1;
1403 else if (*(int *) arg >= global_sub_size)
1404 *(int *) arg = global_sub_size - 1;
1405 mpctx->global_sub_pos = *(int *) arg;
1406 break;
1407 case M_PROPERTY_STEP_UP:
1408 mpctx->global_sub_pos += 2;
1409 mpctx->global_sub_pos =
1410 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1411 break;
1412 case M_PROPERTY_STEP_DOWN:
1413 mpctx->global_sub_pos += global_sub_size + 1;
1414 mpctx->global_sub_pos =
1415 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1416 break;
1417 default:
1418 return M_PROPERTY_NOT_IMPLEMENTED;
1421 if (mpctx->global_sub_pos >= 0)
1422 source = sub_source(mpctx);
1424 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1425 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1426 global_sub_size,
1427 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1428 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1429 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1430 mpctx->global_sub_pos, source);
1432 mpctx->set_of_sub_pos = -1;
1433 subdata = NULL;
1435 vobsub_id = -1;
1436 opts->sub_id = -1;
1437 if (d_sub) {
1438 if (d_sub->id > -2)
1439 reset_spu = 1;
1440 d_sub->id = -2;
1442 #ifdef CONFIG_ASS
1443 ass_track = 0;
1444 #endif
1446 if (source == SUB_SOURCE_VOBSUB) {
1447 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1448 } else if (source == SUB_SOURCE_SUBS) {
1449 mpctx->set_of_sub_pos =
1450 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1451 #ifdef CONFIG_ASS
1452 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1453 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1454 else
1455 #endif
1457 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1458 vo_osd_changed(OSDTYPE_SUBTITLE);
1460 } else if (source == SUB_SOURCE_DEMUX) {
1461 opts->sub_id =
1462 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1463 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1464 int i = 0;
1465 // default: assume 1:1 mapping of sid and stream id
1466 d_sub->id = opts->sub_id;
1467 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1468 ds_free_packs(d_sub);
1469 for (i = 0; i < MAX_S_STREAMS; i++) {
1470 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1471 if (sh && sh->sid == opts->sub_id) {
1472 d_sub->id = i;
1473 d_sub->sh = sh;
1474 break;
1477 if (d_sub->sh && d_sub->id >= 0) {
1478 sh_sub_t *sh = d_sub->sh;
1479 if (sh->type == 'v')
1480 init_vo_spudec(mpctx);
1481 #ifdef CONFIG_ASS
1482 else if (ass_enabled)
1483 ass_track = sh->ass_track;
1484 #endif
1485 } else {
1486 d_sub->id = -2;
1487 d_sub->sh = NULL;
1491 #ifdef CONFIG_DVDREAD
1492 if (vo_spudec
1493 && (mpctx->stream->type == STREAMTYPE_DVD
1494 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1495 && opts->sub_id < 0 && reset_spu) {
1496 opts->sub_id = -2;
1497 d_sub->id = opts->sub_id;
1499 #endif
1500 update_subtitles(mpctx->sh_video, d_sub, 1);
1502 return M_PROPERTY_OK;
1505 /// Selected sub source (RW)
1506 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1507 MPContext *mpctx)
1509 int source;
1510 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1511 return M_PROPERTY_UNAVAILABLE;
1513 switch (action) {
1514 case M_PROPERTY_GET:
1515 if (!arg)
1516 return M_PROPERTY_ERROR;
1517 *(int *) arg = sub_source(mpctx);
1518 return M_PROPERTY_OK;
1519 case M_PROPERTY_PRINT:
1520 if (!arg)
1521 return M_PROPERTY_ERROR;
1522 *(char **) arg = malloc(64);
1523 (*(char **) arg)[63] = 0;
1524 switch (sub_source(mpctx))
1526 case SUB_SOURCE_SUBS:
1527 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1528 break;
1529 case SUB_SOURCE_VOBSUB:
1530 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1531 break;
1532 case SUB_SOURCE_DEMUX:
1533 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1534 break;
1535 default:
1536 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1538 return M_PROPERTY_OK;
1539 case M_PROPERTY_SET:
1540 if (!arg)
1541 return M_PROPERTY_ERROR;
1542 M_PROPERTY_CLAMP(prop, *(int*)arg);
1543 if (*(int *) arg < 0)
1544 mpctx->global_sub_pos = -1;
1545 else if (*(int *) arg != sub_source(mpctx)) {
1546 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1547 return M_PROPERTY_UNAVAILABLE;
1548 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1550 break;
1551 case M_PROPERTY_STEP_UP:
1552 case M_PROPERTY_STEP_DOWN: {
1553 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1554 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1555 int step = (step_all > 0) ? 1 : -1;
1556 int cur_source = sub_source(mpctx);
1557 source = cur_source;
1558 while (step_all) {
1559 source += step;
1560 if (source >= SUB_SOURCES)
1561 source = -1;
1562 else if (source < -1)
1563 source = SUB_SOURCES - 1;
1564 if (source == cur_source || source == -1 ||
1565 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1566 step_all -= step;
1568 if (source == cur_source)
1569 return M_PROPERTY_OK;
1570 if (source == -1)
1571 mpctx->global_sub_pos = -1;
1572 else
1573 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1574 break;
1576 default:
1577 return M_PROPERTY_NOT_IMPLEMENTED;
1579 --mpctx->global_sub_pos;
1580 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1583 /// Selected subtitles from specific source (RW)
1584 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1585 MPContext *mpctx)
1587 int source, is_cur_source, offset;
1588 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1589 return M_PROPERTY_UNAVAILABLE;
1591 if (!strcmp(prop->name, "sub_file"))
1592 source = SUB_SOURCE_SUBS;
1593 else if (!strcmp(prop->name, "sub_vob"))
1594 source = SUB_SOURCE_VOBSUB;
1595 else if (!strcmp(prop->name, "sub_demux"))
1596 source = SUB_SOURCE_DEMUX;
1597 else
1598 return M_PROPERTY_ERROR;
1600 offset = mpctx->global_sub_indices[source];
1601 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1602 return M_PROPERTY_UNAVAILABLE;
1604 is_cur_source = sub_source(mpctx) == source;
1605 switch (action) {
1606 case M_PROPERTY_GET:
1607 if (!arg)
1608 return M_PROPERTY_ERROR;
1609 if (is_cur_source) {
1610 *(int *) arg = mpctx->global_sub_pos - offset;
1611 if (source == SUB_SOURCE_VOBSUB)
1612 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1614 else
1615 *(int *) arg = -1;
1616 return M_PROPERTY_OK;
1617 case M_PROPERTY_PRINT:
1618 if (!arg)
1619 return M_PROPERTY_ERROR;
1620 if (is_cur_source)
1621 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1622 *(char **) arg = malloc(64);
1623 (*(char **) arg)[63] = 0;
1624 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1625 return M_PROPERTY_OK;
1626 case M_PROPERTY_SET:
1627 if (!arg)
1628 return M_PROPERTY_ERROR;
1629 if (*(int *) arg >= 0) {
1630 int index = *(int *)arg;
1631 if (source == SUB_SOURCE_VOBSUB)
1632 index = vobsub_get_index_by_id(vo_vobsub, index);
1633 mpctx->global_sub_pos = offset + index;
1634 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1635 || sub_source(mpctx) != source) {
1636 mpctx->global_sub_pos = -1;
1637 *(int *) arg = -1;
1640 else
1641 mpctx->global_sub_pos = -1;
1642 break;
1643 case M_PROPERTY_STEP_UP:
1644 case M_PROPERTY_STEP_DOWN: {
1645 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1646 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1647 int step = (step_all > 0) ? 1 : -1;
1648 int max_sub_pos_for_source = -1;
1649 if (!is_cur_source)
1650 mpctx->global_sub_pos = -1;
1651 while (step_all) {
1652 if (mpctx->global_sub_pos == -1) {
1653 if (step > 0)
1654 mpctx->global_sub_pos = offset;
1655 else if (max_sub_pos_for_source == -1) {
1656 // Find max pos for specific source
1657 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1658 while (mpctx->global_sub_pos >= 0
1659 && sub_source(mpctx) != source)
1660 --mpctx->global_sub_pos;
1662 else
1663 mpctx->global_sub_pos = max_sub_pos_for_source;
1665 else {
1666 mpctx->global_sub_pos += step;
1667 if (mpctx->global_sub_pos < offset ||
1668 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1669 sub_source(mpctx) != source)
1670 mpctx->global_sub_pos = -1;
1672 step_all -= step;
1674 break;
1676 default:
1677 return M_PROPERTY_NOT_IMPLEMENTED;
1679 --mpctx->global_sub_pos;
1680 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1683 /// Subtitle delay (RW)
1684 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1685 MPContext *mpctx)
1687 if (!mpctx->sh_video)
1688 return M_PROPERTY_UNAVAILABLE;
1689 return m_property_delay(prop, action, arg, &sub_delay);
1692 /// Alignment of text subtitles (RW)
1693 static int mp_property_sub_alignment(m_option_t *prop, int action,
1694 void *arg, MPContext *mpctx)
1696 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1698 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1699 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1700 return M_PROPERTY_UNAVAILABLE;
1702 switch (action) {
1703 case M_PROPERTY_PRINT:
1704 if (!arg)
1705 return M_PROPERTY_ERROR;
1706 M_PROPERTY_CLAMP(prop, sub_alignment);
1707 *(char **) arg = strdup(name[sub_alignment]);
1708 return M_PROPERTY_OK;
1709 case M_PROPERTY_SET:
1710 if (!arg)
1711 return M_PROPERTY_ERROR;
1712 case M_PROPERTY_STEP_UP:
1713 case M_PROPERTY_STEP_DOWN:
1714 vo_osd_changed(OSDTYPE_SUBTITLE);
1715 default:
1716 return m_property_choice(prop, action, arg, &sub_alignment);
1720 /// Subtitle visibility (RW)
1721 static int mp_property_sub_visibility(m_option_t *prop, int action,
1722 void *arg, MPContext *mpctx)
1724 if (!mpctx->sh_video)
1725 return M_PROPERTY_UNAVAILABLE;
1727 switch (action) {
1728 case M_PROPERTY_SET:
1729 if (!arg)
1730 return M_PROPERTY_ERROR;
1731 case M_PROPERTY_STEP_UP:
1732 case M_PROPERTY_STEP_DOWN:
1733 vo_osd_changed(OSDTYPE_SUBTITLE);
1734 if (vo_spudec)
1735 vo_osd_changed(OSDTYPE_SPU);
1736 default:
1737 return m_property_flag(prop, action, arg, &sub_visibility);
1741 #ifdef CONFIG_ASS
1742 /// Use margins for libass subtitles (RW)
1743 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1744 void *arg, MPContext *mpctx)
1746 if (!mpctx->sh_video)
1747 return M_PROPERTY_UNAVAILABLE;
1749 switch (action) {
1750 case M_PROPERTY_SET:
1751 if (!arg)
1752 return M_PROPERTY_ERROR;
1753 case M_PROPERTY_STEP_UP:
1754 case M_PROPERTY_STEP_DOWN:
1755 ass_force_reload = 1;
1756 default:
1757 return m_property_flag(prop, action, arg, &ass_use_margins);
1760 #endif
1762 /// Show only forced subtitles (RW)
1763 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1764 void *arg, MPContext *mpctx)
1766 if (!vo_spudec)
1767 return M_PROPERTY_UNAVAILABLE;
1769 switch (action) {
1770 case M_PROPERTY_SET:
1771 if (!arg)
1772 return M_PROPERTY_ERROR;
1773 case M_PROPERTY_STEP_UP:
1774 case M_PROPERTY_STEP_DOWN:
1775 m_property_flag(prop, action, arg, &forced_subs_only);
1776 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1777 return M_PROPERTY_OK;
1778 default:
1779 return m_property_flag(prop, action, arg, &forced_subs_only);
1784 #ifdef HAVE_FREETYPE
1785 /// Subtitle scale (RW)
1786 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1787 MPContext *mpctx)
1790 switch (action) {
1791 case M_PROPERTY_SET:
1792 if (!arg)
1793 return M_PROPERTY_ERROR;
1794 M_PROPERTY_CLAMP(prop, *(float *) arg);
1795 #ifdef CONFIG_ASS
1796 if (ass_enabled) {
1797 ass_font_scale = *(float *) arg;
1798 ass_force_reload = 1;
1800 #endif
1801 text_font_scale_factor = *(float *) arg;
1802 force_load_font = 1;
1803 return M_PROPERTY_OK;
1804 case M_PROPERTY_STEP_UP:
1805 case M_PROPERTY_STEP_DOWN:
1806 #ifdef CONFIG_ASS
1807 if (ass_enabled) {
1808 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1809 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1810 M_PROPERTY_CLAMP(prop, ass_font_scale);
1811 ass_force_reload = 1;
1813 #endif
1814 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1815 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1816 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1817 force_load_font = 1;
1818 return M_PROPERTY_OK;
1819 default:
1820 #ifdef CONFIG_ASS
1821 if (ass_enabled)
1822 return m_property_float_ro(prop, action, arg, ass_font_scale);
1823 else
1824 #endif
1825 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1828 #endif
1830 ///@}
1832 /// \defgroup TVProperties TV properties
1833 /// \ingroup Properties
1834 ///@{
1836 #ifdef CONFIG_TV
1838 /// TV color settings (RW)
1839 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1840 MPContext *mpctx)
1842 int r, val;
1843 tvi_handle_t *tvh = mpctx->demuxer->priv;
1844 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1845 return M_PROPERTY_UNAVAILABLE;
1847 switch (action) {
1848 case M_PROPERTY_SET:
1849 if (!arg)
1850 return M_PROPERTY_ERROR;
1851 M_PROPERTY_CLAMP(prop, *(int *) arg);
1852 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1853 case M_PROPERTY_GET:
1854 return tv_get_color_options(tvh, (int) prop->priv, arg);
1855 case M_PROPERTY_STEP_UP:
1856 case M_PROPERTY_STEP_DOWN:
1857 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1858 if (!r)
1859 return M_PROPERTY_ERROR;
1860 val += (arg ? *(int *) arg : 1) *
1861 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1862 M_PROPERTY_CLAMP(prop, val);
1863 return tv_set_color_options(tvh, (int) prop->priv, val);
1865 return M_PROPERTY_ERROR;
1867 return M_PROPERTY_NOT_IMPLEMENTED;
1870 #endif
1872 #ifdef HAVE_TV_TELETEXT
1873 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1874 MPContext *mpctx)
1876 int val,result;
1877 int base_ioctl=(int)prop->priv;
1879 for teletext's GET,SET,STEP ioctls this is not 0
1880 SET is GET+1
1881 STEP is GET+2
1883 tvi_handle_t *tvh = mpctx->demuxer->priv;
1884 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1885 return M_PROPERTY_UNAVAILABLE;
1886 if(!base_ioctl)
1887 return M_PROPERTY_ERROR;
1889 switch (action) {
1890 case M_PROPERTY_GET:
1891 if (!arg)
1892 return M_PROPERTY_ERROR;
1893 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1894 break;
1895 case M_PROPERTY_SET:
1896 if (!arg)
1897 return M_PROPERTY_ERROR;
1898 M_PROPERTY_CLAMP(prop, *(int *) arg);
1899 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1900 break;
1901 case M_PROPERTY_STEP_UP:
1902 case M_PROPERTY_STEP_DOWN:
1903 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1904 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1905 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1906 break;
1907 default:
1908 return M_PROPERTY_NOT_IMPLEMENTED;
1911 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1914 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
1915 MPContext *mpctx)
1917 tvi_handle_t *tvh = mpctx->demuxer->priv;
1918 int result;
1919 int val;
1921 //with tvh==NULL will fail too
1922 result=mp_property_teletext_common(prop,action,arg,mpctx);
1923 if(result!=M_PROPERTY_OK)
1924 return result;
1926 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1927 mp_input_set_section(mpctx->input, "teletext");
1928 else
1929 mp_input_set_section(mpctx->input, "tv");
1930 return M_PROPERTY_OK;
1933 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
1934 MPContext *mpctx)
1936 tvi_handle_t *tvh = mpctx->demuxer->priv;
1937 int result;
1938 int val;
1939 switch(action){
1940 case M_PROPERTY_STEP_UP:
1941 case M_PROPERTY_STEP_DOWN:
1942 //This should be handled separately
1943 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1944 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1945 break;
1946 default:
1947 result=mp_property_teletext_common(prop,action,arg,mpctx);
1949 return result;
1953 #endif /* HAVE_TV_TELETEXT */
1955 ///@}
1957 /// All properties available in MPlayer.
1958 /** \ingroup Properties
1960 static const m_option_t mp_properties[] = {
1961 // General
1962 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1963 M_OPT_RANGE, 0, 3, NULL },
1964 { "loop", mp_property_loop, CONF_TYPE_INT,
1965 M_OPT_MIN, -1, 0, NULL },
1966 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1967 M_OPT_RANGE, 0.01, 100.0, NULL },
1968 { "filename", mp_property_filename, CONF_TYPE_STRING,
1969 0, 0, 0, NULL },
1970 { "path", mp_property_path, CONF_TYPE_STRING,
1971 0, 0, 0, NULL },
1972 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1973 0, 0, 0, NULL },
1974 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1975 M_OPT_MIN, 0, 0, NULL },
1976 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1977 M_OPT_MIN, 0, 0, NULL },
1978 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1979 M_OPT_MIN, 0, 0, NULL },
1980 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1981 M_OPT_MIN, 0, 0, NULL },
1982 { "length", mp_property_length, CONF_TYPE_TIME,
1983 M_OPT_MIN, 0, 0, NULL },
1984 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1985 M_OPT_RANGE, 0, 100, NULL },
1986 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1987 M_OPT_MIN, 0, 0, NULL },
1988 { "chapter", mp_property_chapter, CONF_TYPE_INT,
1989 M_OPT_MIN, 1, 0, NULL },
1990 { "angle", mp_property_angle, CONF_TYPE_INT,
1991 CONF_RANGE, -2, 10, NULL },
1992 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
1993 0, 0, 0, NULL },
1995 // Audio
1996 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
1997 M_OPT_RANGE, 0, 100, NULL },
1998 { "mute", mp_property_mute, CONF_TYPE_FLAG,
1999 M_OPT_RANGE, 0, 1, NULL },
2000 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2001 M_OPT_RANGE, -100, 100, NULL },
2002 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2003 0, 0, 0, NULL },
2004 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2005 0, 0, 0, NULL },
2006 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2007 0, 0, 0, NULL },
2008 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2009 0, 0, 0, NULL },
2010 { "channels", mp_property_channels, CONF_TYPE_INT,
2011 0, 0, 0, NULL },
2012 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2013 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
2014 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2015 M_OPT_RANGE, -1, 1, NULL },
2017 // Video
2018 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2019 M_OPT_RANGE, 0, 1, NULL },
2020 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2021 M_OPT_RANGE, 0, 1, NULL },
2022 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2023 M_OPT_RANGE, 0, 1, NULL },
2024 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2025 M_OPT_RANGE, 0, 1, NULL },
2026 { "border", mp_property_border, CONF_TYPE_FLAG,
2027 M_OPT_RANGE, 0, 1, NULL },
2028 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2029 M_OPT_RANGE, 0, 2, NULL },
2030 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2031 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2032 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2033 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2034 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2035 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2036 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2037 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2038 { "hue", mp_property_gamma, CONF_TYPE_INT,
2039 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2040 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2041 M_OPT_RANGE, 0, 1, NULL },
2042 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2043 M_OPT_RANGE, 0, 1, NULL },
2044 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2045 0, 0, 0, NULL },
2046 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2047 0, 0, 0, NULL },
2048 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2049 0, 0, 0, NULL },
2050 { "width", mp_property_width, CONF_TYPE_INT,
2051 0, 0, 0, NULL },
2052 { "height", mp_property_height, CONF_TYPE_INT,
2053 0, 0, 0, NULL },
2054 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2055 0, 0, 0, NULL },
2056 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2057 0, 0, 0, NULL },
2058 { "switch_video", mp_property_video, CONF_TYPE_INT,
2059 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
2060 { "switch_program", mp_property_program, CONF_TYPE_INT,
2061 CONF_RANGE, -1, 65535, NULL },
2063 // Subs
2064 { "sub", mp_property_sub, CONF_TYPE_INT,
2065 M_OPT_MIN, -1, 0, NULL },
2066 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2067 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2068 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2069 M_OPT_MIN, -1, 0, NULL },
2070 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2071 M_OPT_MIN, -1, 0, NULL },
2072 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2073 M_OPT_MIN, -1, 0, NULL },
2074 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2075 0, 0, 0, NULL },
2076 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2077 M_OPT_RANGE, 0, 100, NULL },
2078 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2079 M_OPT_RANGE, 0, 2, NULL },
2080 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2081 M_OPT_RANGE, 0, 1, NULL },
2082 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2083 M_OPT_RANGE, 0, 1, NULL },
2084 #ifdef HAVE_FREETYPE
2085 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2086 M_OPT_RANGE, 0, 100, NULL },
2087 #endif
2088 #ifdef CONFIG_ASS
2089 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2090 M_OPT_RANGE, 0, 1, NULL },
2091 #endif
2093 #ifdef CONFIG_TV
2094 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2095 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2096 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2097 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2098 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2099 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2100 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2101 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2102 #endif
2104 #ifdef HAVE_TV_TELETEXT
2105 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2106 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2107 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2108 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2109 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2110 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2111 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2112 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2113 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2114 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2115 #endif
2117 { NULL, NULL, NULL, 0, 0, 0, NULL }
2121 int mp_property_do(const char *name, int action, void *val, void *ctx)
2123 return m_property_do(mp_properties, name, action, val, ctx);
2126 char* mp_property_print(const char *name, void* ctx)
2128 char* ret = NULL;
2129 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2130 return NULL;
2131 return ret;
2134 char *property_expand_string(MPContext *mpctx, char *str)
2136 return m_properties_expand_string(mp_properties, str, mpctx);
2139 void property_print_help(void)
2141 m_properties_print_help_list(mp_properties);
2145 ///@}
2146 // Properties group
2150 * \defgroup Command2Property Command to property bridge
2152 * It is used to handle most commands that just set a property
2153 * and optionally display something on the OSD.
2154 * Two kinds of commands are handled: adjust or toggle.
2156 * Adjust commands take 1 or 2 parameters: <value> <abs>
2157 * If <abs> is non-zero the property is set to the given value
2158 * otherwise it is adjusted.
2160 * Toggle commands take 0 or 1 parameters. With no parameter
2161 * or a value less than the property minimum it just steps the
2162 * property to its next value. Otherwise it sets it to the given
2163 * value.
2168 /// List of the commands that can be handled by setting a property.
2169 static struct {
2170 /// property name
2171 const char *name;
2172 /// cmd id
2173 int cmd;
2174 /// set/adjust or toggle command
2175 int toggle;
2176 /// progressbar type
2177 int osd_progbar;
2178 /// osd msg id if it must be shared
2179 int osd_id;
2180 /// osd msg template
2181 const char *osd_msg;
2182 } set_prop_cmd[] = {
2183 // general
2184 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2185 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2186 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2187 // audio
2188 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2189 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2190 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2191 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2192 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2193 // video
2194 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2195 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2196 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2197 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2198 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2199 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2200 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2201 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2202 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2203 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2204 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2205 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2206 // subs
2207 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2208 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2209 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2210 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2211 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2212 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2213 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2214 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2215 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2216 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2217 #ifdef HAVE_FREETYPE
2218 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2219 #endif
2220 #ifdef CONFIG_ASS
2221 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2222 #endif
2223 #ifdef CONFIG_TV
2224 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2225 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2226 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2227 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2228 #endif
2229 { NULL, 0, 0, 0, -1, NULL }
2233 /// Handle commands that set a property.
2234 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2236 int i, r;
2237 m_option_t* prop;
2238 const char *pname;
2240 // look for the command
2241 for (i = 0; set_prop_cmd[i].name; i++)
2242 if (set_prop_cmd[i].cmd == cmd->id)
2243 break;
2244 if (!(pname = set_prop_cmd[i].name))
2245 return 0;
2247 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2248 return 0;
2250 // toggle command
2251 if (set_prop_cmd[i].toggle) {
2252 // set to value
2253 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2254 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2255 else
2256 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2257 } else if (cmd->args[1].v.i) //set
2258 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2259 else // adjust
2260 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2262 if (r <= 0)
2263 return 1;
2265 if (set_prop_cmd[i].osd_progbar) {
2266 if (prop->type == CONF_TYPE_INT) {
2267 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2268 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2269 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2270 } else if (prop->type == CONF_TYPE_FLOAT) {
2271 float f;
2272 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2273 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2274 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2275 } else
2276 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2277 "Property use an unsupported type.\n");
2278 return 1;
2281 if (set_prop_cmd[i].osd_msg) {
2282 char *val = mp_property_print(pname, mpctx);
2283 if (val) {
2284 set_osd_msg(set_prop_cmd[i].osd_id >=
2285 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2286 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2287 free(val);
2290 return 1;
2293 #ifdef CONFIG_DVDNAV
2294 static const struct {
2295 const char *name;
2296 const mp_command_type cmd;
2297 } mp_dvdnav_bindings[] = {
2298 { "up", MP_CMD_DVDNAV_UP },
2299 { "down", MP_CMD_DVDNAV_DOWN },
2300 { "left", MP_CMD_DVDNAV_LEFT },
2301 { "right", MP_CMD_DVDNAV_RIGHT },
2302 { "menu", MP_CMD_DVDNAV_MENU },
2303 { "select", MP_CMD_DVDNAV_SELECT },
2304 { "prev", MP_CMD_DVDNAV_PREVMENU },
2305 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2308 * keep old dvdnav sub-command options for a while in order not to
2309 * break slave-mode API too suddenly.
2311 { "1", MP_CMD_DVDNAV_UP },
2312 { "2", MP_CMD_DVDNAV_DOWN },
2313 { "3", MP_CMD_DVDNAV_LEFT },
2314 { "4", MP_CMD_DVDNAV_RIGHT },
2315 { "5", MP_CMD_DVDNAV_MENU },
2316 { "6", MP_CMD_DVDNAV_SELECT },
2317 { "7", MP_CMD_DVDNAV_PREVMENU },
2318 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2319 { NULL, 0 }
2321 #endif
2323 int run_command(MPContext *mpctx, mp_cmd_t *cmd)
2325 struct MPOpts *opts = &mpctx->opts;
2326 sh_audio_t * const sh_audio = mpctx->sh_audio;
2327 sh_video_t * const sh_video = mpctx->sh_video;
2328 int brk_cmd = 0;
2329 if (!set_property_command(mpctx, cmd))
2330 switch (cmd->id) {
2331 case MP_CMD_SEEK:{
2332 float v;
2333 int abs;
2334 if (sh_video)
2335 mpctx->osd_show_percentage = sh_video->fps;
2336 v = cmd->args[0].v.f;
2337 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2338 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2339 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2340 if (sh_video)
2341 mpctx->osd_function =
2342 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2343 mpctx->rel_seek_secs = v;
2344 } else if (abs) { /* Absolute seek by percentage */
2345 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2346 if (sh_video)
2347 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2348 mpctx->rel_seek_secs = v / 100.0;
2349 } else {
2350 mpctx->rel_seek_secs += v;
2351 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2353 brk_cmd = 1;
2355 break;
2357 case MP_CMD_SET_PROPERTY:{
2358 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2359 cmd->args[1].v.s, mpctx);
2360 if (r == M_PROPERTY_UNKNOWN)
2361 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2362 "Unknown property: '%s'\n", cmd->args[0].v.s);
2363 else if (r <= 0)
2364 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2365 "Failed to set property '%s' to '%s'.\n",
2366 cmd->args[0].v.s, cmd->args[1].v.s);
2368 break;
2370 case MP_CMD_STEP_PROPERTY:{
2371 void* arg = NULL;
2372 int r,i;
2373 double d;
2374 off_t o;
2375 if (cmd->args[1].v.f) {
2376 m_option_t* prop;
2377 if((r = mp_property_do(cmd->args[0].v.s,
2378 M_PROPERTY_GET_TYPE,
2379 &prop, mpctx)) <= 0)
2380 goto step_prop_err;
2381 if(prop->type == CONF_TYPE_INT ||
2382 prop->type == CONF_TYPE_FLAG)
2383 i = cmd->args[1].v.f, arg = &i;
2384 else if(prop->type == CONF_TYPE_FLOAT)
2385 arg = &cmd->args[1].v.f;
2386 else if(prop->type == CONF_TYPE_DOUBLE ||
2387 prop->type == CONF_TYPE_TIME)
2388 d = cmd->args[1].v.f, arg = &d;
2389 else if(prop->type == CONF_TYPE_POSITION)
2390 o = cmd->args[1].v.f, arg = &o;
2391 else
2392 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2393 "Ignoring step size stepping property '%s'.\n",
2394 cmd->args[0].v.s);
2396 r = mp_property_do(cmd->args[0].v.s,
2397 cmd->args[2].v.i < 0 ?
2398 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2399 arg, mpctx);
2400 step_prop_err:
2401 if (r == M_PROPERTY_UNKNOWN)
2402 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2403 "Unknown property: '%s'\n", cmd->args[0].v.s);
2404 else if (r <= 0)
2405 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2406 "Failed to increment property '%s' by %f.\n",
2407 cmd->args[0].v.s, cmd->args[1].v.f);
2409 break;
2411 case MP_CMD_GET_PROPERTY:{
2412 char *tmp;
2413 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2414 &tmp, mpctx) <= 0) {
2415 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2416 "Failed to get value of property '%s'.\n",
2417 cmd->args[0].v.s);
2418 break;
2420 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2421 cmd->args[0].v.s, tmp);
2422 free(tmp);
2424 break;
2426 case MP_CMD_EDL_MARK:
2427 if (edl_fd) {
2428 float v = sh_video ? sh_video->pts :
2429 playing_audio_pts(mpctx);
2430 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2431 mpctx->begin_skip = v;
2432 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2433 } else {
2434 if (mpctx->begin_skip > v)
2435 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2436 else {
2437 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2438 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2440 mpctx->begin_skip = MP_NOPTS_VALUE;
2443 break;
2445 case MP_CMD_SWITCH_RATIO:
2446 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2447 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2448 else
2449 opts->movie_aspect = cmd->args[0].v.f;
2450 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2451 break;
2453 case MP_CMD_SPEED_INCR:{
2454 float v = cmd->args[0].v.f;
2455 opts->playback_speed += v;
2456 build_afilter_chain(mpctx, sh_audio, &ao_data);
2457 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2458 opts->playback_speed);
2459 } break;
2461 case MP_CMD_SPEED_MULT:{
2462 float v = cmd->args[0].v.f;
2463 opts->playback_speed *= v;
2464 build_afilter_chain(mpctx, sh_audio, &ao_data);
2465 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2466 opts->playback_speed);
2467 } break;
2469 case MP_CMD_SPEED_SET:{
2470 float v = cmd->args[0].v.f;
2471 opts->playback_speed = v;
2472 build_afilter_chain(mpctx, sh_audio, &ao_data);
2473 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2474 opts->playback_speed);
2475 } break;
2477 case MP_CMD_FRAME_STEP:
2478 case MP_CMD_PAUSE:
2479 cmd->pausing = 1;
2480 brk_cmd = 1;
2481 break;
2483 case MP_CMD_FILE_FILTER:
2484 file_filter = cmd->args[0].v.i;
2485 break;
2487 case MP_CMD_QUIT:
2488 exit_player_with_rc(mpctx, MSGTR_Exit_quit,
2489 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2491 case MP_CMD_PLAY_TREE_STEP:{
2492 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2493 int force = cmd->args[1].v.i;
2495 #ifdef HAVE_NEW_GUI
2496 if (use_gui) {
2497 int i = 0;
2498 if (n > 0)
2499 for (i = 0; i < n; i++)
2500 mplNext();
2501 else
2502 for (i = 0; i < -1 * n; i++)
2503 mplPrev();
2504 } else
2505 #endif
2507 if (!force && mpctx->playtree_iter) {
2508 play_tree_iter_t *i =
2509 play_tree_iter_new_copy(mpctx->playtree_iter);
2510 if (play_tree_iter_step(i, n, 0) ==
2511 PLAY_TREE_ITER_ENTRY)
2512 mpctx->eof =
2513 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2514 play_tree_iter_free(i);
2515 } else
2516 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2517 if (mpctx->eof)
2518 mpctx->play_tree_step = n;
2519 brk_cmd = 1;
2522 break;
2524 case MP_CMD_PLAY_TREE_UP_STEP:{
2525 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2526 int force = cmd->args[1].v.i;
2528 if (!force && mpctx->playtree_iter) {
2529 play_tree_iter_t *i =
2530 play_tree_iter_new_copy(mpctx->playtree_iter);
2531 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2532 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2533 play_tree_iter_free(i);
2534 } else
2535 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2536 brk_cmd = 1;
2538 break;
2540 case MP_CMD_PLAY_ALT_SRC_STEP:
2541 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2542 int v = cmd->args[0].v.i;
2543 if (v > 0
2544 && mpctx->playtree_iter->file <
2545 mpctx->playtree_iter->num_files)
2546 mpctx->eof = PT_NEXT_SRC;
2547 else if (v < 0 && mpctx->playtree_iter->file > 1)
2548 mpctx->eof = PT_PREV_SRC;
2550 brk_cmd = 1;
2551 break;
2553 case MP_CMD_SUB_STEP:
2554 if (sh_video) {
2555 int movement = cmd->args[0].v.i;
2556 step_sub(subdata, sh_video->pts, movement);
2557 #ifdef CONFIG_ASS
2558 if (ass_track)
2559 sub_delay +=
2560 ass_step_sub(ass_track,
2561 (sh_video->pts +
2562 sub_delay) * 1000 + .5, movement) / 1000.;
2563 #endif
2564 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2565 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2567 break;
2569 case MP_CMD_SUB_LOG:
2570 log_sub(mpctx);
2571 break;
2573 case MP_CMD_OSD:{
2574 int v = cmd->args[0].v.i;
2575 int max = (term_osd
2576 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2577 if (osd_level > max)
2578 osd_level = max;
2579 if (v < 0)
2580 osd_level = (osd_level + 1) % (max + 1);
2581 else
2582 osd_level = v > max ? max : v;
2583 /* Show OSD state when disabled, but not when an explicit
2584 argument is given to the OSD command, i.e. in slave mode. */
2585 if (v == -1 && osd_level <= 1)
2586 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2587 MSGTR_OSDosd,
2588 osd_level ? MSGTR_OSDenabled :
2589 MSGTR_OSDdisabled);
2590 else
2591 rm_osd_msg(OSD_MSG_OSD_STATUS);
2593 break;
2595 case MP_CMD_OSD_SHOW_TEXT:
2596 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2597 (cmd->args[1].v.i <
2598 0 ? osd_duration : cmd->args[1].v.i),
2599 "%-.63s", cmd->args[0].v.s);
2600 break;
2602 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2603 char *txt = m_properties_expand_string(mp_properties,
2604 cmd->args[0].v.s,
2605 mpctx);
2606 /* if no argument supplied take default osd_duration, else <arg> ms. */
2607 if (txt) {
2608 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2609 (cmd->args[1].v.i <
2610 0 ? osd_duration : cmd->args[1].v.i),
2611 "%-.63s", txt);
2612 free(txt);
2615 break;
2617 case MP_CMD_LOADFILE:{
2618 play_tree_t *e = play_tree_new();
2619 play_tree_add_file(e, cmd->args[0].v.s);
2621 if (cmd->args[1].v.i) // append
2622 play_tree_append_entry(mpctx->playtree, e);
2623 else {
2624 // Go back to the starting point.
2625 while (play_tree_iter_up_step
2626 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2627 /* NOP */ ;
2628 play_tree_free_list(mpctx->playtree->child, 1);
2629 play_tree_set_child(mpctx->playtree, e);
2630 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2631 mpctx->eof = PT_NEXT_SRC;
2633 brk_cmd = 1;
2635 break;
2637 case MP_CMD_LOADLIST:{
2638 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2639 if (!e)
2640 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2641 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2642 else {
2643 if (cmd->args[1].v.i) // append
2644 play_tree_append_entry(mpctx->playtree, e);
2645 else {
2646 // Go back to the starting point.
2647 while (play_tree_iter_up_step
2648 (mpctx->playtree_iter, 0, 1)
2649 != PLAY_TREE_ITER_END)
2650 /* NOP */ ;
2651 play_tree_free_list(mpctx->playtree->child, 1);
2652 play_tree_set_child(mpctx->playtree, e);
2653 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2654 mpctx->eof = PT_NEXT_SRC;
2657 brk_cmd = 1;
2659 break;
2661 case MP_CMD_STOP:
2662 mpctx->eof = PT_STOP;
2663 brk_cmd = 1;
2664 break;
2666 #ifdef CONFIG_RADIO
2667 case MP_CMD_RADIO_STEP_CHANNEL:
2668 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2669 int v = cmd->args[0].v.i;
2670 if (v > 0)
2671 radio_step_channel(mpctx->demuxer->stream,
2672 RADIO_CHANNEL_HIGHER);
2673 else
2674 radio_step_channel(mpctx->demuxer->stream,
2675 RADIO_CHANNEL_LOWER);
2676 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2677 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2678 MSGTR_OSDChannel,
2679 radio_get_channel_name(mpctx->demuxer->stream));
2682 break;
2684 case MP_CMD_RADIO_SET_CHANNEL:
2685 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2686 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2687 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2688 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2689 MSGTR_OSDChannel,
2690 radio_get_channel_name(mpctx->demuxer->stream));
2693 break;
2695 case MP_CMD_RADIO_SET_FREQ:
2696 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2697 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2698 break;
2700 case MP_CMD_RADIO_STEP_FREQ:
2701 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2702 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2703 break;
2704 #endif
2706 #ifdef CONFIG_TV
2707 case MP_CMD_TV_START_SCAN:
2708 if (mpctx->file_format == DEMUXER_TYPE_TV)
2709 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2710 break;
2711 case MP_CMD_TV_SET_FREQ:
2712 if (mpctx->file_format == DEMUXER_TYPE_TV)
2713 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2714 cmd->args[0].v.f * 16.0);
2715 #ifdef HAVE_PVR
2716 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2717 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2718 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2719 pvr_get_current_channelname (mpctx->stream),
2720 pvr_get_current_stationname (mpctx->stream));
2722 #endif /* HAVE_PVR */
2723 break;
2725 case MP_CMD_TV_STEP_FREQ:
2726 if (mpctx->file_format == DEMUXER_TYPE_TV)
2727 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2728 cmd->args[0].v.f * 16.0);
2729 #ifdef HAVE_PVR
2730 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2731 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2732 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2733 pvr_get_current_channelname (mpctx->stream),
2734 pvr_get_current_frequency (mpctx->stream));
2736 #endif /* HAVE_PVR */
2737 break;
2739 case MP_CMD_TV_SET_NORM:
2740 if (mpctx->file_format == DEMUXER_TYPE_TV)
2741 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2742 cmd->args[0].v.s);
2743 break;
2745 case MP_CMD_TV_STEP_CHANNEL:{
2746 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2747 int v = cmd->args[0].v.i;
2748 if (v > 0) {
2749 tv_step_channel((tvi_handle_t *) (mpctx->
2750 demuxer->priv),
2751 TV_CHANNEL_HIGHER);
2752 } else {
2753 tv_step_channel((tvi_handle_t *) (mpctx->
2754 demuxer->priv),
2755 TV_CHANNEL_LOWER);
2757 if (tv_channel_list) {
2758 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2759 MSGTR_OSDChannel, tv_channel_current->name);
2760 //vo_osd_changed(OSDTYPE_SUBTITLE);
2763 #ifdef HAVE_PVR
2764 else if (mpctx->stream &&
2765 mpctx->stream->type == STREAMTYPE_PVR) {
2766 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2767 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2768 pvr_get_current_channelname (mpctx->stream),
2769 pvr_get_current_stationname (mpctx->stream));
2771 #endif /* HAVE_PVR */
2773 #ifdef HAS_DVBIN_SUPPORT
2774 if (mpctx->stream->type == STREAMTYPE_DVB) {
2775 int dir;
2776 int v = cmd->args[0].v.i;
2778 mpctx->last_dvb_step = v;
2779 if (v > 0)
2780 dir = DVB_CHANNEL_HIGHER;
2781 else
2782 dir = DVB_CHANNEL_LOWER;
2785 if (dvb_step_channel(mpctx->stream, dir))
2786 mpctx->eof = mpctx->dvbin_reopen = 1;
2788 #endif /* HAS_DVBIN_SUPPORT */
2789 break;
2791 case MP_CMD_TV_SET_CHANNEL:
2792 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2793 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2794 cmd->args[0].v.s);
2795 if (tv_channel_list) {
2796 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2797 MSGTR_OSDChannel, tv_channel_current->name);
2798 //vo_osd_changed(OSDTYPE_SUBTITLE);
2801 #ifdef HAVE_PVR
2802 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2803 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2804 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2805 pvr_get_current_channelname (mpctx->stream),
2806 pvr_get_current_stationname (mpctx->stream));
2808 #endif /* HAVE_PVR */
2809 break;
2811 #ifdef HAS_DVBIN_SUPPORT
2812 case MP_CMD_DVB_SET_CHANNEL:
2813 if (mpctx->stream->type == STREAMTYPE_DVB) {
2814 mpctx->last_dvb_step = 1;
2816 if (dvb_set_channel
2817 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2818 mpctx->eof = mpctx->dvbin_reopen = 1;
2820 break;
2821 #endif /* HAS_DVBIN_SUPPORT */
2823 case MP_CMD_TV_LAST_CHANNEL:
2824 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2825 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2826 if (tv_channel_list) {
2827 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2828 MSGTR_OSDChannel, tv_channel_current->name);
2829 //vo_osd_changed(OSDTYPE_SUBTITLE);
2832 #ifdef HAVE_PVR
2833 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2834 pvr_set_lastchannel (mpctx->stream);
2835 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2836 pvr_get_current_channelname (mpctx->stream),
2837 pvr_get_current_stationname (mpctx->stream));
2839 #endif /* HAVE_PVR */
2840 break;
2842 case MP_CMD_TV_STEP_NORM:
2843 if (mpctx->file_format == DEMUXER_TYPE_TV)
2844 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2845 break;
2847 case MP_CMD_TV_STEP_CHANNEL_LIST:
2848 if (mpctx->file_format == DEMUXER_TYPE_TV)
2849 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2850 break;
2851 #ifdef HAVE_TV_TELETEXT
2852 case MP_CMD_TV_TELETEXT_ADD_DEC:
2854 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2855 if (mpctx->file_format == DEMUXER_TYPE_TV)
2856 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2857 break;
2859 case MP_CMD_TV_TELETEXT_GO_LINK:
2861 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2862 if (mpctx->file_format == DEMUXER_TYPE_TV)
2863 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2864 break;
2866 #endif /* HAVE_TV_TELETEXT */
2867 #endif /* CONFIG_TV */
2869 case MP_CMD_SUB_LOAD:
2870 if (sh_video) {
2871 int n = mpctx->set_of_sub_size;
2872 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
2873 if (n != mpctx->set_of_sub_size) {
2874 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2875 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2876 mpctx->global_sub_size;
2877 ++mpctx->global_sub_size;
2880 break;
2882 case MP_CMD_SUB_REMOVE:
2883 if (sh_video) {
2884 int v = cmd->args[0].v.i;
2885 sub_data *subd;
2886 if (v < 0) {
2887 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2888 subd = mpctx->set_of_subtitles[v];
2889 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2890 MSGTR_RemovedSubtitleFile, v + 1,
2891 filename_recode(subd->filename));
2892 sub_free(subd);
2893 mpctx->set_of_subtitles[v] = NULL;
2895 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2896 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2897 mpctx->set_of_sub_size = 0;
2898 if (mpctx->set_of_sub_pos >= 0) {
2899 mpctx->global_sub_pos = -2;
2900 subdata = NULL;
2901 mp_input_queue_cmd(mpctx->input,
2902 mp_input_parse_cmd("sub_select"));
2904 } else if (v < mpctx->set_of_sub_size) {
2905 subd = mpctx->set_of_subtitles[v];
2906 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2907 MSGTR_RemovedSubtitleFile, v + 1,
2908 filename_recode(subd->filename));
2909 sub_free(subd);
2910 if (mpctx->set_of_sub_pos == v) {
2911 mpctx->global_sub_pos = -2;
2912 subdata = NULL;
2913 mp_input_queue_cmd(mpctx->input,
2914 mp_input_parse_cmd("sub_select"));
2915 } else if (mpctx->set_of_sub_pos > v) {
2916 --mpctx->set_of_sub_pos;
2917 --mpctx->global_sub_pos;
2919 while (++v < mpctx->set_of_sub_size)
2920 mpctx->set_of_subtitles[v - 1] =
2921 mpctx->set_of_subtitles[v];
2922 --mpctx->set_of_sub_size;
2923 --mpctx->global_sub_size;
2924 if (mpctx->set_of_sub_size <= 0)
2925 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2926 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2929 break;
2931 case MP_CMD_GET_SUB_VISIBILITY:
2932 if (sh_video) {
2933 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2934 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2936 break;
2938 case MP_CMD_SCREENSHOT:
2939 if (mpctx->video_out && mpctx->video_out->config_ok) {
2940 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2941 if (CONTROL_OK !=
2942 ((vf_instance_t *) sh_video->vfilter)->
2943 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2944 &cmd->args[0].v.i))
2945 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2947 break;
2949 case MP_CMD_VF_CHANGE_RECTANGLE:
2950 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2951 break;
2953 case MP_CMD_GET_TIME_LENGTH:{
2954 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2955 demuxer_get_time_length(mpctx->demuxer));
2957 break;
2959 case MP_CMD_GET_FILENAME:{
2960 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2961 get_metadata(mpctx, META_NAME));
2963 break;
2965 case MP_CMD_GET_VIDEO_CODEC:{
2966 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
2967 if (!inf)
2968 inf = strdup("");
2969 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2970 free(inf);
2972 break;
2974 case MP_CMD_GET_VIDEO_BITRATE:{
2975 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
2976 if (!inf)
2977 inf = strdup("");
2978 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2979 free(inf);
2981 break;
2983 case MP_CMD_GET_VIDEO_RESOLUTION:{
2984 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
2985 if (!inf)
2986 inf = strdup("");
2987 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2988 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
2989 free(inf);
2991 break;
2993 case MP_CMD_GET_AUDIO_CODEC:{
2994 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
2995 if (!inf)
2996 inf = strdup("");
2997 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
2998 free(inf);
3000 break;
3002 case MP_CMD_GET_AUDIO_BITRATE:{
3003 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3004 if (!inf)
3005 inf = strdup("");
3006 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3007 free(inf);
3009 break;
3011 case MP_CMD_GET_AUDIO_SAMPLES:{
3012 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3013 if (!inf)
3014 inf = strdup("");
3015 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3016 free(inf);
3018 break;
3020 case MP_CMD_GET_META_TITLE:{
3021 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3022 if (!inf)
3023 inf = strdup("");
3024 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3025 free(inf);
3027 break;
3029 case MP_CMD_GET_META_ARTIST:{
3030 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3031 if (!inf)
3032 inf = strdup("");
3033 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3034 free(inf);
3036 break;
3038 case MP_CMD_GET_META_ALBUM:{
3039 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3040 if (!inf)
3041 inf = strdup("");
3042 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3043 free(inf);
3045 break;
3047 case MP_CMD_GET_META_YEAR:{
3048 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3049 if (!inf)
3050 inf = strdup("");
3051 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3052 free(inf);
3054 break;
3056 case MP_CMD_GET_META_COMMENT:{
3057 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3058 if (!inf)
3059 inf = strdup("");
3060 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3061 free(inf);
3063 break;
3065 case MP_CMD_GET_META_TRACK:{
3066 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3067 if (!inf)
3068 inf = strdup("");
3069 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3070 free(inf);
3072 break;
3074 case MP_CMD_GET_META_GENRE:{
3075 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3076 if (!inf)
3077 inf = strdup("");
3078 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3079 free(inf);
3081 break;
3083 case MP_CMD_GET_VO_FULLSCREEN:
3084 if (mpctx->video_out && mpctx->video_out->config_ok)
3085 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3086 break;
3088 case MP_CMD_GET_PERCENT_POS:
3089 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3090 demuxer_get_percent_pos(mpctx->demuxer));
3091 break;
3093 case MP_CMD_GET_TIME_POS:{
3094 float pos = 0;
3095 if (sh_video)
3096 pos = sh_video->pts;
3097 else if (sh_audio && mpctx->audio_out)
3098 pos = playing_audio_pts(mpctx);
3099 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3101 break;
3103 case MP_CMD_RUN:
3104 #ifndef __MINGW32__
3105 if (!fork()) {
3106 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3107 exit(0);
3109 #endif
3110 break;
3112 case MP_CMD_KEYDOWN_EVENTS:
3113 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3114 break;
3116 case MP_CMD_SET_MOUSE_POS:{
3117 int pointer_x, pointer_y;
3118 double dx, dy;
3119 pointer_x = cmd->args[0].v.i;
3120 pointer_y = cmd->args[1].v.i;
3121 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3122 #ifdef CONFIG_DVDNAV
3123 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3124 && dx > 0.0 && dy > 0.0) {
3125 int button = -1;
3126 pointer_x = (int) (dx * (double) sh_video->disp_w);
3127 pointer_y = (int) (dy * (double) sh_video->disp_h);
3128 mp_dvdnav_update_mouse_pos(mpctx->stream,
3129 pointer_x, pointer_y, &button);
3130 if (osd_level > 1 && button > 0)
3131 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3132 "Selected button number %d", button);
3134 #endif
3135 #ifdef HAVE_MENU
3136 if (use_menu && dx >= 0.0 && dy >= 0.0)
3137 menu_update_mouse_pos(dx, dy);
3138 #endif
3140 break;
3142 #ifdef CONFIG_DVDNAV
3143 case MP_CMD_DVDNAV:{
3144 int button = -1;
3145 int i;
3146 mp_command_type command = 0;
3147 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3148 break;
3150 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3151 if (cmd->args[0].v.s &&
3152 !strcasecmp (cmd->args[0].v.s,
3153 mp_dvdnav_bindings[i].name))
3154 command = mp_dvdnav_bindings[i].cmd;
3156 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3157 if (osd_level > 1 && button > 0)
3158 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3159 "Selected button number %d", button);
3161 break;
3163 case MP_CMD_SWITCH_TITLE:
3164 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3165 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3166 break;
3168 #endif
3170 default:
3171 #ifdef HAVE_NEW_GUI
3172 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3173 guiGetEvent(guiIEvent, (char *) cmd->id);
3174 else
3175 #endif
3176 mp_msg(MSGT_CPLAYER, MSGL_V,
3177 "Received unknown cmd %s\n", cmd->name);
3180 switch (cmd->pausing) {
3181 case 1: // "pausing"
3182 mpctx->osd_function = OSD_PAUSE;
3183 break;
3184 case 3: // "pausing_toggle"
3185 mpctx->was_paused = !mpctx->was_paused;
3186 if (mpctx->was_paused)
3187 mpctx->osd_function = OSD_PAUSE;
3188 else if (mpctx->osd_function == OSD_PAUSE)
3189 mpctx->osd_function = OSD_PLAY;
3190 break;
3191 case 2: // "pausing_keep"
3192 if (mpctx->was_paused)
3193 mpctx->osd_function = OSD_PAUSE;
3195 return brk_cmd;