Makefile: Don't use "install -d" on existing directories
[mplayer.git] / command.c
blob9d4c38726b7246a3d035d87cd19d71558d0b0785
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 CONFIG_PVR
39 #include "stream/pvr.h"
40 #endif
41 #ifdef CONFIG_DVBIN
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 CONFIG_MENU
55 #include "m_struct.h"
56 #include "libmenu/menu.h"
57 #endif
58 #ifdef CONFIG_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 = -1;
388 float next_pts = 0;
389 int chapter_num;
390 int step_all;
391 char *chapter_name = NULL;
393 if (mpctx->demuxer)
394 chapter = demuxer_get_current_chapter(mpctx->demuxer);
395 if (chapter < 0)
396 return M_PROPERTY_UNAVAILABLE;
398 switch (action) {
399 case M_PROPERTY_GET:
400 if (!arg)
401 return M_PROPERTY_ERROR;
402 *(int *) arg = chapter;
403 return M_PROPERTY_OK;
404 case M_PROPERTY_PRINT: {
405 if (!arg)
406 return M_PROPERTY_ERROR;
407 chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter);
408 if (!chapter_name)
409 return M_PROPERTY_UNAVAILABLE;
410 *(char **) arg = chapter_name;
411 return M_PROPERTY_OK;
413 case M_PROPERTY_SET:
414 if (!arg)
415 return M_PROPERTY_ERROR;
416 M_PROPERTY_CLAMP(prop, *(int*)arg);
417 step_all = *(int *)arg - (chapter + 1);
418 chapter += step_all;
419 break;
420 case M_PROPERTY_STEP_UP:
421 case M_PROPERTY_STEP_DOWN: {
422 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
423 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
424 chapter += step_all;
425 if (chapter < 0)
426 chapter = 0;
427 break;
429 default:
430 return M_PROPERTY_NOT_IMPLEMENTED;
432 mpctx->rel_seek_secs = 0;
433 mpctx->abs_seek_pos = 0;
434 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
435 &next_pts, &chapter_num, &chapter_name);
436 if (chapter >= 0) {
437 if (next_pts > -1.0) {
438 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
439 mpctx->rel_seek_secs = next_pts;
441 if (chapter_name)
442 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
443 MSGTR_OSDChapter, chapter + 1, chapter_name);
445 else if (step_all > 0)
446 mpctx->rel_seek_secs = 1000000000.;
447 else
448 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
449 MSGTR_OSDChapter, 0, MSGTR_Unknown);
450 if (chapter_name)
451 free(chapter_name);
452 return M_PROPERTY_OK;
455 /// Number of chapters in file
456 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
457 MPContext *mpctx)
459 if (!mpctx->demuxer)
460 return M_PROPERTY_UNAVAILABLE;
461 if (mpctx->demuxer->num_chapters == 0)
462 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
463 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
466 /// Current dvd angle (RW)
467 static int mp_property_angle(m_option_t *prop, int action, void *arg,
468 MPContext *mpctx)
470 int angle = -1;
471 int angles;
472 char *angle_name = NULL;
474 if (mpctx->demuxer)
475 angle = demuxer_get_current_angle(mpctx->demuxer);
476 if (angle < 0)
477 return M_PROPERTY_UNAVAILABLE;
478 angles = demuxer_angles_count(mpctx->demuxer);
479 if (angles <= 1)
480 return M_PROPERTY_UNAVAILABLE;
482 switch (action) {
483 case M_PROPERTY_GET:
484 if (!arg)
485 return M_PROPERTY_ERROR;
486 *(int *) arg = angle;
487 return M_PROPERTY_OK;
488 case M_PROPERTY_PRINT: {
489 if (!arg)
490 return M_PROPERTY_ERROR;
491 angle_name = calloc(1, 64);
492 if (!angle_name)
493 return M_PROPERTY_UNAVAILABLE;
494 snprintf(angle_name, 64, "%d/%d", angle, angles);
495 *(char **) arg = angle_name;
496 return M_PROPERTY_OK;
498 case M_PROPERTY_SET:
499 if (!arg)
500 return M_PROPERTY_ERROR;
501 angle = *(int *)arg;
502 M_PROPERTY_CLAMP(prop, angle);
503 break;
504 case M_PROPERTY_STEP_UP:
505 case M_PROPERTY_STEP_DOWN: {
506 int step = 0;
507 if(arg)
508 step = *(int*)arg;
509 if(!step)
510 step = 1;
511 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
512 angle += step;
513 if (angle < 1) //cycle
514 angle = angles;
515 break;
517 default:
518 return M_PROPERTY_NOT_IMPLEMENTED;
520 angle = demuxer_set_angle(mpctx->demuxer, angle);
521 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
522 MSGTR_OSDAngle, angle, angles);
523 if (angle_name)
524 free(angle_name);
525 return M_PROPERTY_OK;
528 /// Demuxer meta data
529 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
530 MPContext *mpctx) {
531 m_property_action_t* ka;
532 char* meta;
533 static const m_option_t key_type =
534 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
535 if (!mpctx->demuxer)
536 return M_PROPERTY_UNAVAILABLE;
538 switch(action) {
539 case M_PROPERTY_GET:
540 if(!arg) return M_PROPERTY_ERROR;
541 *(char***)arg = mpctx->demuxer->info;
542 return M_PROPERTY_OK;
543 case M_PROPERTY_KEY_ACTION:
544 if(!arg) return M_PROPERTY_ERROR;
545 ka = arg;
546 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
547 return M_PROPERTY_UNKNOWN;
548 switch(ka->action) {
549 case M_PROPERTY_GET:
550 if(!ka->arg) return M_PROPERTY_ERROR;
551 *(char**)ka->arg = meta;
552 return M_PROPERTY_OK;
553 case M_PROPERTY_GET_TYPE:
554 if(!ka->arg) return M_PROPERTY_ERROR;
555 *(m_option_t**)ka->arg = &key_type;
556 return M_PROPERTY_OK;
559 return M_PROPERTY_NOT_IMPLEMENTED;
562 static int mp_property_pause(m_option_t * prop, int action, void *arg,
563 MPContext * mpctx)
565 return m_property_flag_ro(prop, action, arg, mpctx->osd_function == OSD_PAUSE);
569 ///@}
571 /// \defgroup AudioProperties Audio properties
572 /// \ingroup Properties
573 ///@{
575 /// Volume (RW)
576 static int mp_property_volume(m_option_t *prop, int action, void *arg,
577 MPContext *mpctx)
580 if (!mpctx->sh_audio)
581 return M_PROPERTY_UNAVAILABLE;
583 switch (action) {
584 case M_PROPERTY_GET:
585 if (!arg)
586 return M_PROPERTY_ERROR;
587 mixer_getbothvolume(&mpctx->mixer, arg);
588 return M_PROPERTY_OK;
589 case M_PROPERTY_PRINT:{
590 float vol;
591 if (!arg)
592 return M_PROPERTY_ERROR;
593 mixer_getbothvolume(&mpctx->mixer, &vol);
594 return m_property_float_range(prop, action, arg, &vol);
596 case M_PROPERTY_STEP_UP:
597 case M_PROPERTY_STEP_DOWN:
598 case M_PROPERTY_SET:
599 break;
600 default:
601 return M_PROPERTY_NOT_IMPLEMENTED;
604 if (mpctx->edl_muted)
605 return M_PROPERTY_DISABLED;
606 mpctx->user_muted = 0;
608 switch (action) {
609 case M_PROPERTY_SET:
610 if (!arg)
611 return M_PROPERTY_ERROR;
612 M_PROPERTY_CLAMP(prop, *(float *) arg);
613 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
614 return M_PROPERTY_OK;
615 case M_PROPERTY_STEP_UP:
616 if (arg && *(float *) arg <= 0)
617 mixer_decvolume(&mpctx->mixer);
618 else
619 mixer_incvolume(&mpctx->mixer);
620 return M_PROPERTY_OK;
621 case M_PROPERTY_STEP_DOWN:
622 if (arg && *(float *) arg <= 0)
623 mixer_incvolume(&mpctx->mixer);
624 else
625 mixer_decvolume(&mpctx->mixer);
626 return M_PROPERTY_OK;
628 return M_PROPERTY_NOT_IMPLEMENTED;
631 /// Mute (RW)
632 static int mp_property_mute(m_option_t *prop, int action, void *arg,
633 MPContext *mpctx)
636 if (!mpctx->sh_audio)
637 return M_PROPERTY_UNAVAILABLE;
639 switch (action) {
640 case M_PROPERTY_SET:
641 if (mpctx->edl_muted)
642 return M_PROPERTY_DISABLED;
643 if (!arg)
644 return M_PROPERTY_ERROR;
645 if ((!!*(int *) arg) != mpctx->mixer.muted)
646 mixer_mute(&mpctx->mixer);
647 mpctx->user_muted = mpctx->mixer.muted;
648 return M_PROPERTY_OK;
649 case M_PROPERTY_STEP_UP:
650 case M_PROPERTY_STEP_DOWN:
651 if (mpctx->edl_muted)
652 return M_PROPERTY_DISABLED;
653 mixer_mute(&mpctx->mixer);
654 mpctx->user_muted = mpctx->mixer.muted;
655 return M_PROPERTY_OK;
656 case M_PROPERTY_PRINT:
657 if (!arg)
658 return M_PROPERTY_ERROR;
659 if (mpctx->edl_muted) {
660 *(char **) arg = strdup(MSGTR_EnabledEdl);
661 return M_PROPERTY_OK;
663 default:
664 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
669 /// Audio delay (RW)
670 static int mp_property_audio_delay(m_option_t *prop, int action,
671 void *arg, MPContext *mpctx)
673 if (!(mpctx->sh_audio && mpctx->sh_video))
674 return M_PROPERTY_UNAVAILABLE;
675 switch (action) {
676 case M_PROPERTY_SET:
677 case M_PROPERTY_STEP_UP:
678 case M_PROPERTY_STEP_DOWN: {
679 int ret;
680 float delay = audio_delay;
681 ret = m_property_delay(prop, action, arg, &audio_delay);
682 if (ret != M_PROPERTY_OK)
683 return ret;
684 if (mpctx->sh_audio)
685 mpctx->delay -= audio_delay - delay;
687 return M_PROPERTY_OK;
688 default:
689 return m_property_delay(prop, action, arg, &audio_delay);
693 /// Audio codec tag (RO)
694 static int mp_property_audio_format(m_option_t *prop, int action,
695 void *arg, MPContext *mpctx)
697 if (!mpctx->sh_audio)
698 return M_PROPERTY_UNAVAILABLE;
699 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
702 /// Audio codec name (RO)
703 static int mp_property_audio_codec(m_option_t *prop, int action,
704 void *arg, MPContext *mpctx)
706 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
707 return M_PROPERTY_UNAVAILABLE;
708 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
711 /// Audio bitrate (RO)
712 static int mp_property_audio_bitrate(m_option_t *prop, int action,
713 void *arg, MPContext *mpctx)
715 if (!mpctx->sh_audio)
716 return M_PROPERTY_UNAVAILABLE;
717 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
720 /// Samplerate (RO)
721 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
722 MPContext *mpctx)
724 if (!mpctx->sh_audio)
725 return M_PROPERTY_UNAVAILABLE;
726 switch(action) {
727 case M_PROPERTY_PRINT:
728 if(!arg) return M_PROPERTY_ERROR;
729 *(char**)arg = malloc(16);
730 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
731 return M_PROPERTY_OK;
733 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
736 /// Number of channels (RO)
737 static int mp_property_channels(m_option_t *prop, int action, void *arg,
738 MPContext *mpctx)
740 if (!mpctx->sh_audio)
741 return M_PROPERTY_UNAVAILABLE;
742 switch (action) {
743 case M_PROPERTY_PRINT:
744 if (!arg)
745 return M_PROPERTY_ERROR;
746 switch (mpctx->sh_audio->channels) {
747 case 1:
748 *(char **) arg = strdup("mono");
749 break;
750 case 2:
751 *(char **) arg = strdup("stereo");
752 break;
753 default:
754 *(char **) arg = malloc(32);
755 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
757 return M_PROPERTY_OK;
759 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
762 /// Balance (RW)
763 static int mp_property_balance(m_option_t *prop, int action, void *arg,
764 MPContext *mpctx)
766 float bal;
768 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
769 return M_PROPERTY_UNAVAILABLE;
771 switch (action) {
772 case M_PROPERTY_GET:
773 if (!arg)
774 return M_PROPERTY_ERROR;
775 mixer_getbalance(&mpctx->mixer, arg);
776 return M_PROPERTY_OK;
777 case M_PROPERTY_PRINT: {
778 char** str = arg;
779 if (!arg)
780 return M_PROPERTY_ERROR;
781 mixer_getbalance(&mpctx->mixer, &bal);
782 if (bal == 0.f)
783 *str = strdup("center");
784 else if (bal == -1.f)
785 *str = strdup("left only");
786 else if (bal == 1.f)
787 *str = strdup("right only");
788 else {
789 unsigned right = (bal + 1.f) / 2.f * 100.f;
790 *str = malloc(sizeof("left xxx%, right xxx%"));
791 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
793 return M_PROPERTY_OK;
795 case M_PROPERTY_STEP_UP:
796 case M_PROPERTY_STEP_DOWN:
797 mixer_getbalance(&mpctx->mixer, &bal);
798 bal += (arg ? *(float*)arg : .1f) *
799 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
800 M_PROPERTY_CLAMP(prop, bal);
801 mixer_setbalance(&mpctx->mixer, bal);
802 return M_PROPERTY_OK;
803 case M_PROPERTY_SET:
804 if (!arg)
805 return M_PROPERTY_ERROR;
806 M_PROPERTY_CLAMP(prop, *(float*)arg);
807 mixer_setbalance(&mpctx->mixer, *(float*)arg);
808 return M_PROPERTY_OK;
810 return M_PROPERTY_NOT_IMPLEMENTED;
813 /// Selected audio id (RW)
814 static int mp_property_audio(m_option_t *prop, int action, void *arg,
815 MPContext *mpctx)
817 struct MPOpts *opts = &mpctx->opts;
818 int current_id = -1, tmp;
820 switch (action) {
821 case M_PROPERTY_GET:
822 if (!mpctx->sh_audio)
823 return M_PROPERTY_UNAVAILABLE;
824 if (!arg)
825 return M_PROPERTY_ERROR;
826 *(int *) arg = opts->audio_id;
827 return M_PROPERTY_OK;
828 case M_PROPERTY_PRINT:
829 if (!mpctx->sh_audio)
830 return M_PROPERTY_UNAVAILABLE;
831 if (!arg)
832 return M_PROPERTY_ERROR;
834 if (opts->audio_id < 0)
835 *(char **) arg = strdup(MSGTR_Disabled);
836 else {
837 char lang[40] = MSGTR_Unknown;
838 sh_audio_t* sh = mpctx->sh_audio;
839 if (sh && sh->lang)
840 av_strlcpy(lang, sh->lang, 40);
841 #ifdef CONFIG_DVDREAD
842 else if (mpctx->stream->type == STREAMTYPE_DVD) {
843 int code = dvd_lang_from_aid(mpctx->stream, opts->audio_id);
844 if (code) {
845 lang[0] = code >> 8;
846 lang[1] = code;
847 lang[2] = 0;
850 #endif
852 #ifdef CONFIG_DVDNAV
853 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
854 mp_dvdnav_lang_from_aid(mpctx->stream, opts->audio_id, lang);
855 #endif
856 *(char **) arg = malloc(64);
857 snprintf(*(char **) arg, 64, "(%d) %s", opts->audio_id, lang);
859 return M_PROPERTY_OK;
861 case M_PROPERTY_STEP_UP:
862 case M_PROPERTY_SET:
863 if (!mpctx->demuxer)
864 return M_PROPERTY_UNAVAILABLE;
865 if (action == M_PROPERTY_SET && arg)
866 tmp = *((int *) arg);
867 else
868 tmp = -1;
869 current_id = mpctx->demuxer->audio->id;
870 opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
871 if (opts->audio_id == -2
872 || (opts->audio_id > -1
873 && mpctx->demuxer->audio->id != current_id && current_id != -2))
874 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
875 if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
876 sh_audio_t *sh2;
877 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
878 if (sh2) {
879 sh2->ds = mpctx->demuxer->audio;
880 mpctx->sh_audio = sh2;
881 reinit_audio_chain(mpctx);
884 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id);
885 return M_PROPERTY_OK;
886 default:
887 return M_PROPERTY_NOT_IMPLEMENTED;
892 /// Selected video id (RW)
893 static int mp_property_video(m_option_t *prop, int action, void *arg,
894 MPContext *mpctx)
896 struct MPOpts *opts = &mpctx->opts;
897 int current_id = -1, tmp;
899 switch (action) {
900 case M_PROPERTY_GET:
901 if (!mpctx->sh_video)
902 return M_PROPERTY_UNAVAILABLE;
903 if (!arg)
904 return M_PROPERTY_ERROR;
905 *(int *) arg = opts->video_id;
906 return M_PROPERTY_OK;
907 case M_PROPERTY_PRINT:
908 if (!mpctx->sh_video)
909 return M_PROPERTY_UNAVAILABLE;
910 if (!arg)
911 return M_PROPERTY_ERROR;
913 if (opts->video_id < 0)
914 *(char **) arg = strdup(MSGTR_Disabled);
915 else {
916 char lang[40] = MSGTR_Unknown;
917 *(char **) arg = malloc(64);
918 snprintf(*(char **) arg, 64, "(%d) %s", opts->video_id, lang);
920 return M_PROPERTY_OK;
922 case M_PROPERTY_STEP_UP:
923 case M_PROPERTY_SET:
924 current_id = mpctx->demuxer->video->id;
925 if (action == M_PROPERTY_SET && arg)
926 tmp = *((int *) arg);
927 else
928 tmp = -1;
929 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
930 if (opts->video_id == -2
931 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
932 && current_id != -2))
933 uninit_player(mpctx, INITIALIZED_VCODEC |
934 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
935 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
936 sh_video_t *sh2;
937 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
938 if (sh2) {
939 sh2->ds = mpctx->demuxer->video;
940 mpctx->sh_video = sh2;
941 reinit_video_chain(mpctx);
944 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
945 return M_PROPERTY_OK;
947 default:
948 return M_PROPERTY_NOT_IMPLEMENTED;
952 static int mp_property_program(m_option_t *prop, int action, void *arg,
953 MPContext *mpctx)
955 demux_program_t prog;
957 switch (action) {
958 case M_PROPERTY_STEP_UP:
959 case M_PROPERTY_SET:
960 if (action == M_PROPERTY_SET && arg)
961 prog.progid = *((int *) arg);
962 else
963 prog.progid = -1;
964 if (demux_control
965 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
966 &prog) == DEMUXER_CTRL_NOTIMPL)
967 return M_PROPERTY_ERROR;
969 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
970 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
971 return M_PROPERTY_OK;
973 default:
974 return M_PROPERTY_NOT_IMPLEMENTED;
978 ///@}
980 /// \defgroup VideoProperties Video properties
981 /// \ingroup Properties
982 ///@{
984 /// Fullscreen state (RW)
985 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
986 MPContext *mpctx)
989 if (!mpctx->video_out)
990 return M_PROPERTY_UNAVAILABLE;
992 switch (action) {
993 case M_PROPERTY_SET:
994 if (!arg)
995 return M_PROPERTY_ERROR;
996 M_PROPERTY_CLAMP(prop, *(int *) arg);
997 if (vo_fs == !!*(int *) arg)
998 return M_PROPERTY_OK;
999 case M_PROPERTY_STEP_UP:
1000 case M_PROPERTY_STEP_DOWN:
1001 #ifdef CONFIG_GUI
1002 if (use_gui)
1003 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
1004 else
1005 #endif
1006 if (mpctx->video_out->config_ok)
1007 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1008 return M_PROPERTY_OK;
1009 default:
1010 return m_property_flag(prop, action, arg, &vo_fs);
1014 static int mp_property_deinterlace(m_option_t *prop, int action,
1015 void *arg, MPContext *mpctx)
1017 int deinterlace;
1018 vf_instance_t *vf;
1019 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1020 return M_PROPERTY_UNAVAILABLE;
1021 vf = mpctx->sh_video->vfilter;
1022 switch (action) {
1023 case M_PROPERTY_GET:
1024 if (!arg)
1025 return M_PROPERTY_ERROR;
1026 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1027 return M_PROPERTY_OK;
1028 case M_PROPERTY_SET:
1029 if (!arg)
1030 return M_PROPERTY_ERROR;
1031 M_PROPERTY_CLAMP(prop, *(int *) arg);
1032 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1033 return M_PROPERTY_OK;
1034 case M_PROPERTY_STEP_UP:
1035 case M_PROPERTY_STEP_DOWN:
1036 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1037 deinterlace = !deinterlace;
1038 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1039 return M_PROPERTY_OK;
1041 return M_PROPERTY_NOT_IMPLEMENTED;
1044 /// Panscan (RW)
1045 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1046 MPContext *mpctx)
1049 if (!mpctx->video_out
1050 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1051 return M_PROPERTY_UNAVAILABLE;
1053 switch (action) {
1054 case M_PROPERTY_SET:
1055 if (!arg)
1056 return M_PROPERTY_ERROR;
1057 M_PROPERTY_CLAMP(prop, *(float *) arg);
1058 vo_panscan = *(float *) arg;
1059 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1060 return M_PROPERTY_OK;
1061 case M_PROPERTY_STEP_UP:
1062 case M_PROPERTY_STEP_DOWN:
1063 vo_panscan += (arg ? *(float *) arg : 0.1) *
1064 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1065 if (vo_panscan > 1)
1066 vo_panscan = 1;
1067 else if (vo_panscan < 0)
1068 vo_panscan = 0;
1069 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1070 return M_PROPERTY_OK;
1071 default:
1072 return m_property_float_range(prop, action, arg, &vo_panscan);
1076 /// Helper to set vo flags.
1077 /** \ingroup PropertyImplHelper
1079 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1080 int vo_ctrl, int *vo_var, MPContext *mpctx)
1083 if (!mpctx->video_out)
1084 return M_PROPERTY_UNAVAILABLE;
1086 switch (action) {
1087 case M_PROPERTY_SET:
1088 if (!arg)
1089 return M_PROPERTY_ERROR;
1090 M_PROPERTY_CLAMP(prop, *(int *) arg);
1091 if (*vo_var == !!*(int *) arg)
1092 return M_PROPERTY_OK;
1093 case M_PROPERTY_STEP_UP:
1094 case M_PROPERTY_STEP_DOWN:
1095 if (mpctx->video_out->config_ok)
1096 vo_control(mpctx->video_out, vo_ctrl, 0);
1097 return M_PROPERTY_OK;
1098 default:
1099 return m_property_flag(prop, action, arg, vo_var);
1103 /// Window always on top (RW)
1104 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1105 MPContext *mpctx)
1107 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1108 &mpctx->opts.vo_ontop, mpctx);
1111 /// Display in the root window (RW)
1112 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1113 MPContext *mpctx)
1115 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1116 &vo_rootwin, mpctx);
1119 /// Show window borders (RW)
1120 static int mp_property_border(m_option_t *prop, int action, void *arg,
1121 MPContext *mpctx)
1123 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1124 &vo_border, mpctx);
1127 /// Framedropping state (RW)
1128 static int mp_property_framedropping(m_option_t *prop, int action,
1129 void *arg, MPContext *mpctx)
1132 if (!mpctx->sh_video)
1133 return M_PROPERTY_UNAVAILABLE;
1135 switch (action) {
1136 case M_PROPERTY_PRINT:
1137 if (!arg)
1138 return M_PROPERTY_ERROR;
1139 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1140 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1141 MSGTR_Disabled));
1142 return M_PROPERTY_OK;
1143 default:
1144 return m_property_choice(prop, action, arg, &frame_dropping);
1148 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1149 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1150 MPContext *mpctx)
1152 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1153 int r, val;
1155 if (!mpctx->sh_video)
1156 return M_PROPERTY_UNAVAILABLE;
1158 if (gamma[0] == 1000) {
1159 gamma[0] = 0;
1160 get_video_colors(mpctx->sh_video, prop->name, gamma);
1163 switch (action) {
1164 case M_PROPERTY_SET:
1165 if (!arg)
1166 return M_PROPERTY_ERROR;
1167 M_PROPERTY_CLAMP(prop, *(int *) arg);
1168 *gamma = *(int *) arg;
1169 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1170 if (r <= 0)
1171 break;
1172 return r;
1173 case M_PROPERTY_GET:
1174 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1175 if (!arg)
1176 return M_PROPERTY_ERROR;
1177 *(int *)arg = val;
1178 return M_PROPERTY_OK;
1180 break;
1181 case M_PROPERTY_STEP_UP:
1182 case M_PROPERTY_STEP_DOWN:
1183 *gamma += (arg ? *(int *) arg : 1) *
1184 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1185 M_PROPERTY_CLAMP(prop, *gamma);
1186 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1187 if (r <= 0)
1188 break;
1189 return r;
1190 default:
1191 return M_PROPERTY_NOT_IMPLEMENTED;
1194 #ifdef CONFIG_TV
1195 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1196 int l = strlen(prop->name);
1197 char tv_prop[3 + l + 1];
1198 sprintf(tv_prop, "tv_%s", prop->name);
1199 return mp_property_do(tv_prop, action, arg, mpctx);
1201 #endif
1203 return M_PROPERTY_UNAVAILABLE;
1206 /// VSync (RW)
1207 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1208 MPContext *mpctx)
1210 return m_property_flag(prop, action, arg, &vo_vsync);
1213 /// Video codec tag (RO)
1214 static int mp_property_video_format(m_option_t *prop, int action,
1215 void *arg, MPContext *mpctx)
1217 char* meta;
1218 if (!mpctx->sh_video)
1219 return M_PROPERTY_UNAVAILABLE;
1220 switch(action) {
1221 case M_PROPERTY_PRINT:
1222 if (!arg)
1223 return M_PROPERTY_ERROR;
1224 switch(mpctx->sh_video->format) {
1225 case 0x10000001:
1226 meta = strdup ("mpeg1"); break;
1227 case 0x10000002:
1228 meta = strdup ("mpeg2"); break;
1229 case 0x10000004:
1230 meta = strdup ("mpeg4"); break;
1231 case 0x10000005:
1232 meta = strdup ("h264"); break;
1233 default:
1234 if(mpctx->sh_video->format >= 0x20202020) {
1235 meta = malloc(5);
1236 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1237 } else {
1238 meta = malloc(20);
1239 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1242 *(char**)arg = meta;
1243 return M_PROPERTY_OK;
1245 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1248 /// Video codec name (RO)
1249 static int mp_property_video_codec(m_option_t *prop, int action,
1250 void *arg, MPContext *mpctx)
1252 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1253 return M_PROPERTY_UNAVAILABLE;
1254 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1258 /// Video bitrate (RO)
1259 static int mp_property_video_bitrate(m_option_t *prop, int action,
1260 void *arg, MPContext *mpctx)
1262 if (!mpctx->sh_video)
1263 return M_PROPERTY_UNAVAILABLE;
1264 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1267 /// Video display width (RO)
1268 static int mp_property_width(m_option_t *prop, int action, void *arg,
1269 MPContext *mpctx)
1271 if (!mpctx->sh_video)
1272 return M_PROPERTY_UNAVAILABLE;
1273 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1276 /// Video display height (RO)
1277 static int mp_property_height(m_option_t *prop, int action, void *arg,
1278 MPContext *mpctx)
1280 if (!mpctx->sh_video)
1281 return M_PROPERTY_UNAVAILABLE;
1282 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1285 /// Video fps (RO)
1286 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1287 MPContext *mpctx)
1289 if (!mpctx->sh_video)
1290 return M_PROPERTY_UNAVAILABLE;
1291 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1294 /// Video aspect (RO)
1295 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1296 MPContext *mpctx)
1298 if (!mpctx->sh_video)
1299 return M_PROPERTY_UNAVAILABLE;
1300 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1303 ///@}
1305 /// \defgroup SubProprties Subtitles properties
1306 /// \ingroup Properties
1307 ///@{
1309 /// Text subtitle position (RW)
1310 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1311 MPContext *mpctx)
1313 if (!mpctx->sh_video)
1314 return M_PROPERTY_UNAVAILABLE;
1316 switch (action) {
1317 case M_PROPERTY_SET:
1318 if (!arg)
1319 return M_PROPERTY_ERROR;
1320 case M_PROPERTY_STEP_UP:
1321 case M_PROPERTY_STEP_DOWN:
1322 vo_osd_changed(OSDTYPE_SUBTITLE);
1323 default:
1324 return m_property_int_range(prop, action, arg, &sub_pos);
1328 /// Selected subtitles (RW)
1329 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1330 MPContext *mpctx)
1332 struct MPOpts *opts = &mpctx->opts;
1333 demux_stream_t *const d_sub = mpctx->d_sub;
1334 const int global_sub_size = mpctx->global_sub_size;
1335 int source = -1, reset_spu = 0;
1336 char *sub_name;
1338 if (global_sub_size <= 0)
1339 return M_PROPERTY_UNAVAILABLE;
1341 switch (action) {
1342 case M_PROPERTY_GET:
1343 if (!arg)
1344 return M_PROPERTY_ERROR;
1345 *(int *) arg = mpctx->global_sub_pos;
1346 return M_PROPERTY_OK;
1347 case M_PROPERTY_PRINT:
1348 if (!arg)
1349 return M_PROPERTY_ERROR;
1350 *(char **) arg = malloc(64);
1351 (*(char **) arg)[63] = 0;
1352 sub_name = 0;
1353 if (subdata)
1354 sub_name = subdata->filename;
1355 #ifdef CONFIG_ASS
1356 if (ass_track && ass_track->name)
1357 sub_name = ass_track->name;
1358 #endif
1359 if (sub_name) {
1360 char *tmp, *tmp2;
1361 tmp = sub_name;
1362 if ((tmp2 = strrchr(tmp, '/')))
1363 tmp = tmp2 + 1;
1365 snprintf(*(char **) arg, 63, "(%d) %s%s",
1366 mpctx->set_of_sub_pos + 1,
1367 strlen(tmp) < 20 ? "" : "...",
1368 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1369 return M_PROPERTY_OK;
1371 #ifdef CONFIG_DVDNAV
1372 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1373 if (vo_spudec && opts->sub_id >= 0) {
1374 unsigned char lang[3];
1375 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1376 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1377 return M_PROPERTY_OK;
1381 #endif
1383 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1384 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1385 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1386 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1387 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1388 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1389 if (!lang) lang = MSGTR_Unknown;
1390 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1391 return M_PROPERTY_OK;
1394 if (vo_vobsub && vobsub_id >= 0) {
1395 const char *language = MSGTR_Unknown;
1396 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1397 snprintf(*(char **) arg, 63, "(%d) %s",
1398 vobsub_id, language ? language : MSGTR_Unknown);
1399 return M_PROPERTY_OK;
1401 #ifdef CONFIG_DVDREAD
1402 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1403 && opts->sub_id >= 0) {
1404 char lang[3];
1405 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1406 lang[0] = code >> 8;
1407 lang[1] = code;
1408 lang[2] = 0;
1409 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1410 return M_PROPERTY_OK;
1412 #endif
1413 if (opts->sub_id >= 0) {
1414 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, MSGTR_Unknown);
1415 return M_PROPERTY_OK;
1417 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1418 return M_PROPERTY_OK;
1420 case M_PROPERTY_SET:
1421 if (!arg)
1422 return M_PROPERTY_ERROR;
1423 if (*(int *) arg < -1)
1424 *(int *) arg = -1;
1425 else if (*(int *) arg >= global_sub_size)
1426 *(int *) arg = global_sub_size - 1;
1427 mpctx->global_sub_pos = *(int *) arg;
1428 break;
1429 case M_PROPERTY_STEP_UP:
1430 mpctx->global_sub_pos += 2;
1431 mpctx->global_sub_pos =
1432 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1433 break;
1434 case M_PROPERTY_STEP_DOWN:
1435 mpctx->global_sub_pos += global_sub_size + 1;
1436 mpctx->global_sub_pos =
1437 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1438 break;
1439 default:
1440 return M_PROPERTY_NOT_IMPLEMENTED;
1443 if (mpctx->global_sub_pos >= 0)
1444 source = sub_source(mpctx);
1446 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1447 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1448 global_sub_size,
1449 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1450 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1451 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1452 mpctx->global_sub_pos, source);
1454 mpctx->set_of_sub_pos = -1;
1455 subdata = NULL;
1457 vobsub_id = -1;
1458 opts->sub_id = -1;
1459 if (d_sub) {
1460 if (d_sub->id > -2)
1461 reset_spu = 1;
1462 d_sub->id = -2;
1464 #ifdef CONFIG_ASS
1465 ass_track = 0;
1466 #endif
1468 if (source == SUB_SOURCE_VOBSUB) {
1469 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1470 } else if (source == SUB_SOURCE_SUBS) {
1471 mpctx->set_of_sub_pos =
1472 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1473 #ifdef CONFIG_ASS
1474 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1475 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1476 else
1477 #endif
1479 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1480 vo_osd_changed(OSDTYPE_SUBTITLE);
1482 } else if (source == SUB_SOURCE_DEMUX) {
1483 opts->sub_id =
1484 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1485 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1486 int i = 0;
1487 // default: assume 1:1 mapping of sid and stream id
1488 d_sub->id = opts->sub_id;
1489 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1490 ds_free_packs(d_sub);
1491 for (i = 0; i < MAX_S_STREAMS; i++) {
1492 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1493 if (sh && sh->sid == opts->sub_id) {
1494 d_sub->id = i;
1495 d_sub->sh = sh;
1496 break;
1499 if (d_sub->sh && d_sub->id >= 0) {
1500 sh_sub_t *sh = d_sub->sh;
1501 if (sh->type == 'v')
1502 init_vo_spudec(mpctx);
1503 #ifdef CONFIG_ASS
1504 else if (ass_enabled)
1505 ass_track = sh->ass_track;
1506 #endif
1507 } else {
1508 d_sub->id = -2;
1509 d_sub->sh = NULL;
1513 #ifdef CONFIG_DVDREAD
1514 if (vo_spudec
1515 && (mpctx->stream->type == STREAMTYPE_DVD
1516 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1517 && opts->sub_id < 0 && reset_spu) {
1518 opts->sub_id = -2;
1519 d_sub->id = opts->sub_id;
1521 #endif
1522 update_subtitles(mpctx->sh_video, d_sub, 1);
1524 return M_PROPERTY_OK;
1527 /// Selected sub source (RW)
1528 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1529 MPContext *mpctx)
1531 int source;
1532 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1533 return M_PROPERTY_UNAVAILABLE;
1535 switch (action) {
1536 case M_PROPERTY_GET:
1537 if (!arg)
1538 return M_PROPERTY_ERROR;
1539 *(int *) arg = sub_source(mpctx);
1540 return M_PROPERTY_OK;
1541 case M_PROPERTY_PRINT:
1542 if (!arg)
1543 return M_PROPERTY_ERROR;
1544 *(char **) arg = malloc(64);
1545 (*(char **) arg)[63] = 0;
1546 switch (sub_source(mpctx))
1548 case SUB_SOURCE_SUBS:
1549 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1550 break;
1551 case SUB_SOURCE_VOBSUB:
1552 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1553 break;
1554 case SUB_SOURCE_DEMUX:
1555 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1556 break;
1557 default:
1558 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1560 return M_PROPERTY_OK;
1561 case M_PROPERTY_SET:
1562 if (!arg)
1563 return M_PROPERTY_ERROR;
1564 M_PROPERTY_CLAMP(prop, *(int*)arg);
1565 if (*(int *) arg < 0)
1566 mpctx->global_sub_pos = -1;
1567 else if (*(int *) arg != sub_source(mpctx)) {
1568 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1569 return M_PROPERTY_UNAVAILABLE;
1570 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1572 break;
1573 case M_PROPERTY_STEP_UP:
1574 case M_PROPERTY_STEP_DOWN: {
1575 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1576 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1577 int step = (step_all > 0) ? 1 : -1;
1578 int cur_source = sub_source(mpctx);
1579 source = cur_source;
1580 while (step_all) {
1581 source += step;
1582 if (source >= SUB_SOURCES)
1583 source = -1;
1584 else if (source < -1)
1585 source = SUB_SOURCES - 1;
1586 if (source == cur_source || source == -1 ||
1587 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1588 step_all -= step;
1590 if (source == cur_source)
1591 return M_PROPERTY_OK;
1592 if (source == -1)
1593 mpctx->global_sub_pos = -1;
1594 else
1595 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1596 break;
1598 default:
1599 return M_PROPERTY_NOT_IMPLEMENTED;
1601 --mpctx->global_sub_pos;
1602 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1605 /// Selected subtitles from specific source (RW)
1606 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1607 MPContext *mpctx)
1609 int source, is_cur_source, offset;
1610 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1611 return M_PROPERTY_UNAVAILABLE;
1613 if (!strcmp(prop->name, "sub_file"))
1614 source = SUB_SOURCE_SUBS;
1615 else if (!strcmp(prop->name, "sub_vob"))
1616 source = SUB_SOURCE_VOBSUB;
1617 else if (!strcmp(prop->name, "sub_demux"))
1618 source = SUB_SOURCE_DEMUX;
1619 else
1620 return M_PROPERTY_ERROR;
1622 offset = mpctx->global_sub_indices[source];
1623 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1624 return M_PROPERTY_UNAVAILABLE;
1626 is_cur_source = sub_source(mpctx) == source;
1627 switch (action) {
1628 case M_PROPERTY_GET:
1629 if (!arg)
1630 return M_PROPERTY_ERROR;
1631 if (is_cur_source) {
1632 *(int *) arg = mpctx->global_sub_pos - offset;
1633 if (source == SUB_SOURCE_VOBSUB)
1634 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1636 else
1637 *(int *) arg = -1;
1638 return M_PROPERTY_OK;
1639 case M_PROPERTY_PRINT:
1640 if (!arg)
1641 return M_PROPERTY_ERROR;
1642 if (is_cur_source)
1643 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1644 *(char **) arg = malloc(64);
1645 (*(char **) arg)[63] = 0;
1646 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1647 return M_PROPERTY_OK;
1648 case M_PROPERTY_SET:
1649 if (!arg)
1650 return M_PROPERTY_ERROR;
1651 if (*(int *) arg >= 0) {
1652 int index = *(int *)arg;
1653 if (source == SUB_SOURCE_VOBSUB)
1654 index = vobsub_get_index_by_id(vo_vobsub, index);
1655 mpctx->global_sub_pos = offset + index;
1656 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1657 || sub_source(mpctx) != source) {
1658 mpctx->global_sub_pos = -1;
1659 *(int *) arg = -1;
1662 else
1663 mpctx->global_sub_pos = -1;
1664 break;
1665 case M_PROPERTY_STEP_UP:
1666 case M_PROPERTY_STEP_DOWN: {
1667 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1668 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1669 int step = (step_all > 0) ? 1 : -1;
1670 int max_sub_pos_for_source = -1;
1671 if (!is_cur_source)
1672 mpctx->global_sub_pos = -1;
1673 while (step_all) {
1674 if (mpctx->global_sub_pos == -1) {
1675 if (step > 0)
1676 mpctx->global_sub_pos = offset;
1677 else if (max_sub_pos_for_source == -1) {
1678 // Find max pos for specific source
1679 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1680 while (mpctx->global_sub_pos >= 0
1681 && sub_source(mpctx) != source)
1682 --mpctx->global_sub_pos;
1684 else
1685 mpctx->global_sub_pos = max_sub_pos_for_source;
1687 else {
1688 mpctx->global_sub_pos += step;
1689 if (mpctx->global_sub_pos < offset ||
1690 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1691 sub_source(mpctx) != source)
1692 mpctx->global_sub_pos = -1;
1694 step_all -= step;
1696 break;
1698 default:
1699 return M_PROPERTY_NOT_IMPLEMENTED;
1701 --mpctx->global_sub_pos;
1702 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1705 /// Subtitle delay (RW)
1706 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1707 MPContext *mpctx)
1709 if (!mpctx->sh_video)
1710 return M_PROPERTY_UNAVAILABLE;
1711 return m_property_delay(prop, action, arg, &sub_delay);
1714 /// Alignment of text subtitles (RW)
1715 static int mp_property_sub_alignment(m_option_t *prop, int action,
1716 void *arg, MPContext *mpctx)
1718 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1720 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1721 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1722 return M_PROPERTY_UNAVAILABLE;
1724 switch (action) {
1725 case M_PROPERTY_PRINT:
1726 if (!arg)
1727 return M_PROPERTY_ERROR;
1728 M_PROPERTY_CLAMP(prop, sub_alignment);
1729 *(char **) arg = strdup(name[sub_alignment]);
1730 return M_PROPERTY_OK;
1731 case M_PROPERTY_SET:
1732 if (!arg)
1733 return M_PROPERTY_ERROR;
1734 case M_PROPERTY_STEP_UP:
1735 case M_PROPERTY_STEP_DOWN:
1736 vo_osd_changed(OSDTYPE_SUBTITLE);
1737 default:
1738 return m_property_choice(prop, action, arg, &sub_alignment);
1742 /// Subtitle visibility (RW)
1743 static int mp_property_sub_visibility(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 vo_osd_changed(OSDTYPE_SUBTITLE);
1756 if (vo_spudec)
1757 vo_osd_changed(OSDTYPE_SPU);
1758 default:
1759 return m_property_flag(prop, action, arg, &sub_visibility);
1763 #ifdef CONFIG_ASS
1764 /// Use margins for libass subtitles (RW)
1765 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1766 void *arg, MPContext *mpctx)
1768 if (!mpctx->sh_video)
1769 return M_PROPERTY_UNAVAILABLE;
1771 switch (action) {
1772 case M_PROPERTY_SET:
1773 if (!arg)
1774 return M_PROPERTY_ERROR;
1775 case M_PROPERTY_STEP_UP:
1776 case M_PROPERTY_STEP_DOWN:
1777 ass_force_reload = 1;
1778 default:
1779 return m_property_flag(prop, action, arg, &ass_use_margins);
1782 #endif
1784 /// Show only forced subtitles (RW)
1785 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1786 void *arg, MPContext *mpctx)
1788 if (!vo_spudec)
1789 return M_PROPERTY_UNAVAILABLE;
1791 switch (action) {
1792 case M_PROPERTY_SET:
1793 if (!arg)
1794 return M_PROPERTY_ERROR;
1795 case M_PROPERTY_STEP_UP:
1796 case M_PROPERTY_STEP_DOWN:
1797 m_property_flag(prop, action, arg, &forced_subs_only);
1798 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1799 return M_PROPERTY_OK;
1800 default:
1801 return m_property_flag(prop, action, arg, &forced_subs_only);
1806 #ifdef CONFIG_FREETYPE
1807 /// Subtitle scale (RW)
1808 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1809 MPContext *mpctx)
1812 switch (action) {
1813 case M_PROPERTY_SET:
1814 if (!arg)
1815 return M_PROPERTY_ERROR;
1816 M_PROPERTY_CLAMP(prop, *(float *) arg);
1817 #ifdef CONFIG_ASS
1818 if (ass_enabled) {
1819 ass_font_scale = *(float *) arg;
1820 ass_force_reload = 1;
1822 #endif
1823 text_font_scale_factor = *(float *) arg;
1824 force_load_font = 1;
1825 return M_PROPERTY_OK;
1826 case M_PROPERTY_STEP_UP:
1827 case M_PROPERTY_STEP_DOWN:
1828 #ifdef CONFIG_ASS
1829 if (ass_enabled) {
1830 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1831 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1832 M_PROPERTY_CLAMP(prop, ass_font_scale);
1833 ass_force_reload = 1;
1835 #endif
1836 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1837 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1838 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1839 force_load_font = 1;
1840 return M_PROPERTY_OK;
1841 default:
1842 #ifdef CONFIG_ASS
1843 if (ass_enabled)
1844 return m_property_float_ro(prop, action, arg, ass_font_scale);
1845 else
1846 #endif
1847 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1850 #endif
1852 ///@}
1854 /// \defgroup TVProperties TV properties
1855 /// \ingroup Properties
1856 ///@{
1858 #ifdef CONFIG_TV
1860 /// TV color settings (RW)
1861 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1862 MPContext *mpctx)
1864 int r, val;
1865 tvi_handle_t *tvh = mpctx->demuxer->priv;
1866 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1867 return M_PROPERTY_UNAVAILABLE;
1869 switch (action) {
1870 case M_PROPERTY_SET:
1871 if (!arg)
1872 return M_PROPERTY_ERROR;
1873 M_PROPERTY_CLAMP(prop, *(int *) arg);
1874 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1875 case M_PROPERTY_GET:
1876 return tv_get_color_options(tvh, (int) prop->priv, arg);
1877 case M_PROPERTY_STEP_UP:
1878 case M_PROPERTY_STEP_DOWN:
1879 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1880 if (!r)
1881 return M_PROPERTY_ERROR;
1882 val += (arg ? *(int *) arg : 1) *
1883 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1884 M_PROPERTY_CLAMP(prop, val);
1885 return tv_set_color_options(tvh, (int) prop->priv, val);
1887 return M_PROPERTY_ERROR;
1889 return M_PROPERTY_NOT_IMPLEMENTED;
1892 #endif
1894 #ifdef CONFIG_TV_TELETEXT
1895 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1896 MPContext *mpctx)
1898 int val,result;
1899 int base_ioctl=(int)prop->priv;
1901 for teletext's GET,SET,STEP ioctls this is not 0
1902 SET is GET+1
1903 STEP is GET+2
1905 tvi_handle_t *tvh = mpctx->demuxer->priv;
1906 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1907 return M_PROPERTY_UNAVAILABLE;
1908 if(!base_ioctl)
1909 return M_PROPERTY_ERROR;
1911 switch (action) {
1912 case M_PROPERTY_GET:
1913 if (!arg)
1914 return M_PROPERTY_ERROR;
1915 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1916 break;
1917 case M_PROPERTY_SET:
1918 if (!arg)
1919 return M_PROPERTY_ERROR;
1920 M_PROPERTY_CLAMP(prop, *(int *) arg);
1921 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1922 break;
1923 case M_PROPERTY_STEP_UP:
1924 case M_PROPERTY_STEP_DOWN:
1925 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1926 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1927 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1928 break;
1929 default:
1930 return M_PROPERTY_NOT_IMPLEMENTED;
1933 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1936 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
1937 MPContext *mpctx)
1939 tvi_handle_t *tvh = mpctx->demuxer->priv;
1940 int result;
1941 int val;
1943 //with tvh==NULL will fail too
1944 result=mp_property_teletext_common(prop,action,arg,mpctx);
1945 if(result!=M_PROPERTY_OK)
1946 return result;
1948 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1949 mp_input_set_section(mpctx->input, "teletext");
1950 else
1951 mp_input_set_section(mpctx->input, "tv");
1952 return M_PROPERTY_OK;
1955 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
1956 MPContext *mpctx)
1958 tvi_handle_t *tvh = mpctx->demuxer->priv;
1959 int result;
1960 int val;
1961 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1962 return M_PROPERTY_UNAVAILABLE;
1963 switch(action){
1964 case M_PROPERTY_STEP_UP:
1965 case M_PROPERTY_STEP_DOWN:
1966 //This should be handled separately
1967 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1968 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1969 break;
1970 default:
1971 result=mp_property_teletext_common(prop,action,arg,mpctx);
1973 return result;
1977 #endif /* CONFIG_TV_TELETEXT */
1979 ///@}
1981 /// All properties available in MPlayer.
1982 /** \ingroup Properties
1984 static const m_option_t mp_properties[] = {
1985 // General
1986 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1987 M_OPT_RANGE, 0, 3, NULL },
1988 { "loop", mp_property_loop, CONF_TYPE_INT,
1989 M_OPT_MIN, -1, 0, NULL },
1990 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1991 M_OPT_RANGE, 0.01, 100.0, NULL },
1992 { "filename", mp_property_filename, CONF_TYPE_STRING,
1993 0, 0, 0, NULL },
1994 { "path", mp_property_path, CONF_TYPE_STRING,
1995 0, 0, 0, NULL },
1996 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1997 0, 0, 0, NULL },
1998 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1999 M_OPT_MIN, 0, 0, NULL },
2000 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2001 M_OPT_MIN, 0, 0, NULL },
2002 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2003 M_OPT_MIN, 0, 0, NULL },
2004 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2005 M_OPT_MIN, 0, 0, NULL },
2006 { "length", mp_property_length, CONF_TYPE_TIME,
2007 M_OPT_MIN, 0, 0, NULL },
2008 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2009 M_OPT_RANGE, 0, 100, NULL },
2010 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2011 M_OPT_MIN, 0, 0, NULL },
2012 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2013 M_OPT_MIN, 1, 0, NULL },
2014 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2015 0, 0, 0, NULL },
2016 { "angle", mp_property_angle, CONF_TYPE_INT,
2017 CONF_RANGE, -2, 10, NULL },
2018 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2019 0, 0, 0, NULL },
2020 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2021 M_OPT_RANGE, 0, 1, NULL },
2023 // Audio
2024 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2025 M_OPT_RANGE, 0, 100, NULL },
2026 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2027 M_OPT_RANGE, 0, 1, NULL },
2028 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2029 M_OPT_RANGE, -100, 100, NULL },
2030 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2031 0, 0, 0, NULL },
2032 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2033 0, 0, 0, NULL },
2034 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2035 0, 0, 0, NULL },
2036 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2037 0, 0, 0, NULL },
2038 { "channels", mp_property_channels, CONF_TYPE_INT,
2039 0, 0, 0, NULL },
2040 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2041 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
2042 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2043 M_OPT_RANGE, -1, 1, NULL },
2045 // Video
2046 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2047 M_OPT_RANGE, 0, 1, NULL },
2048 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2049 M_OPT_RANGE, 0, 1, NULL },
2050 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2051 M_OPT_RANGE, 0, 1, NULL },
2052 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2053 M_OPT_RANGE, 0, 1, NULL },
2054 { "border", mp_property_border, CONF_TYPE_FLAG,
2055 M_OPT_RANGE, 0, 1, NULL },
2056 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2057 M_OPT_RANGE, 0, 2, NULL },
2058 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2059 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2060 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2061 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2062 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2063 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2064 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2065 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2066 { "hue", mp_property_gamma, CONF_TYPE_INT,
2067 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2068 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2069 M_OPT_RANGE, 0, 1, NULL },
2070 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2071 M_OPT_RANGE, 0, 1, NULL },
2072 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2073 0, 0, 0, NULL },
2074 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2075 0, 0, 0, NULL },
2076 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2077 0, 0, 0, NULL },
2078 { "width", mp_property_width, CONF_TYPE_INT,
2079 0, 0, 0, NULL },
2080 { "height", mp_property_height, CONF_TYPE_INT,
2081 0, 0, 0, NULL },
2082 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2083 0, 0, 0, NULL },
2084 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2085 0, 0, 0, NULL },
2086 { "switch_video", mp_property_video, CONF_TYPE_INT,
2087 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
2088 { "switch_program", mp_property_program, CONF_TYPE_INT,
2089 CONF_RANGE, -1, 65535, NULL },
2091 // Subs
2092 { "sub", mp_property_sub, CONF_TYPE_INT,
2093 M_OPT_MIN, -1, 0, NULL },
2094 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2095 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2096 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2097 M_OPT_MIN, -1, 0, NULL },
2098 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2099 M_OPT_MIN, -1, 0, NULL },
2100 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2101 M_OPT_MIN, -1, 0, NULL },
2102 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2103 0, 0, 0, NULL },
2104 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2105 M_OPT_RANGE, 0, 100, NULL },
2106 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2107 M_OPT_RANGE, 0, 2, NULL },
2108 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2109 M_OPT_RANGE, 0, 1, NULL },
2110 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2111 M_OPT_RANGE, 0, 1, NULL },
2112 #ifdef CONFIG_FREETYPE
2113 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2114 M_OPT_RANGE, 0, 100, NULL },
2115 #endif
2116 #ifdef CONFIG_ASS
2117 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2118 M_OPT_RANGE, 0, 1, NULL },
2119 #endif
2121 #ifdef CONFIG_TV
2122 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2123 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2124 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2125 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2126 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2127 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2128 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2129 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2130 #endif
2132 #ifdef CONFIG_TV_TELETEXT
2133 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2134 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2135 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2136 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2137 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2138 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2139 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2140 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2141 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2142 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2143 #endif
2145 { NULL, NULL, NULL, 0, 0, 0, NULL }
2149 int mp_property_do(const char *name, int action, void *val, void *ctx)
2151 return m_property_do(mp_properties, name, action, val, ctx);
2154 char* mp_property_print(const char *name, void* ctx)
2156 char* ret = NULL;
2157 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2158 return NULL;
2159 return ret;
2162 char *property_expand_string(MPContext *mpctx, char *str)
2164 return m_properties_expand_string(mp_properties, str, mpctx);
2167 void property_print_help(void)
2169 m_properties_print_help_list(mp_properties);
2173 ///@}
2174 // Properties group
2178 * \defgroup Command2Property Command to property bridge
2180 * It is used to handle most commands that just set a property
2181 * and optionally display something on the OSD.
2182 * Two kinds of commands are handled: adjust or toggle.
2184 * Adjust commands take 1 or 2 parameters: <value> <abs>
2185 * If <abs> is non-zero the property is set to the given value
2186 * otherwise it is adjusted.
2188 * Toggle commands take 0 or 1 parameters. With no parameter
2189 * or a value less than the property minimum it just steps the
2190 * property to its next value. Otherwise it sets it to the given
2191 * value.
2196 /// List of the commands that can be handled by setting a property.
2197 static struct {
2198 /// property name
2199 const char *name;
2200 /// cmd id
2201 int cmd;
2202 /// set/adjust or toggle command
2203 int toggle;
2204 /// progressbar type
2205 int osd_progbar;
2206 /// osd msg id if it must be shared
2207 int osd_id;
2208 /// osd msg template
2209 const char *osd_msg;
2210 } set_prop_cmd[] = {
2211 // general
2212 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2213 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2214 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2215 // audio
2216 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2217 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2218 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2219 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2220 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2221 // video
2222 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2223 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2224 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2225 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2226 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2227 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2228 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2229 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2230 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2231 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2232 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2233 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2234 // subs
2235 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2236 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2237 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2238 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2239 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2240 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2241 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2242 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2243 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2244 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2245 #ifdef CONFIG_FREETYPE
2246 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2247 #endif
2248 #ifdef CONFIG_ASS
2249 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2250 #endif
2251 #ifdef CONFIG_TV
2252 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2253 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2254 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2255 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2256 #endif
2257 { NULL, 0, 0, 0, -1, NULL }
2261 /// Handle commands that set a property.
2262 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2264 int i, r;
2265 m_option_t* prop;
2266 const char *pname;
2268 // look for the command
2269 for (i = 0; set_prop_cmd[i].name; i++)
2270 if (set_prop_cmd[i].cmd == cmd->id)
2271 break;
2272 if (!(pname = set_prop_cmd[i].name))
2273 return 0;
2275 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2276 return 0;
2278 // toggle command
2279 if (set_prop_cmd[i].toggle) {
2280 // set to value
2281 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2282 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2283 else
2284 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2285 } else if (cmd->args[1].v.i) //set
2286 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2287 else // adjust
2288 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2290 if (r <= 0)
2291 return 1;
2293 if (set_prop_cmd[i].osd_progbar) {
2294 if (prop->type == CONF_TYPE_INT) {
2295 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2296 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2297 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2298 } else if (prop->type == CONF_TYPE_FLOAT) {
2299 float f;
2300 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2301 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2302 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2303 } else
2304 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2305 "Property use an unsupported type.\n");
2306 return 1;
2309 if (set_prop_cmd[i].osd_msg) {
2310 char *val = mp_property_print(pname, mpctx);
2311 if (val) {
2312 set_osd_msg(set_prop_cmd[i].osd_id >=
2313 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2314 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2315 free(val);
2318 return 1;
2321 #ifdef CONFIG_DVDNAV
2322 static const struct {
2323 const char *name;
2324 const mp_command_type cmd;
2325 } mp_dvdnav_bindings[] = {
2326 { "up", MP_CMD_DVDNAV_UP },
2327 { "down", MP_CMD_DVDNAV_DOWN },
2328 { "left", MP_CMD_DVDNAV_LEFT },
2329 { "right", MP_CMD_DVDNAV_RIGHT },
2330 { "menu", MP_CMD_DVDNAV_MENU },
2331 { "select", MP_CMD_DVDNAV_SELECT },
2332 { "prev", MP_CMD_DVDNAV_PREVMENU },
2333 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2336 * keep old dvdnav sub-command options for a while in order not to
2337 * break slave-mode API too suddenly.
2339 { "1", MP_CMD_DVDNAV_UP },
2340 { "2", MP_CMD_DVDNAV_DOWN },
2341 { "3", MP_CMD_DVDNAV_LEFT },
2342 { "4", MP_CMD_DVDNAV_RIGHT },
2343 { "5", MP_CMD_DVDNAV_MENU },
2344 { "6", MP_CMD_DVDNAV_SELECT },
2345 { "7", MP_CMD_DVDNAV_PREVMENU },
2346 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2347 { NULL, 0 }
2349 #endif
2351 int run_command(MPContext *mpctx, mp_cmd_t *cmd)
2353 struct MPOpts *opts = &mpctx->opts;
2354 sh_audio_t * const sh_audio = mpctx->sh_audio;
2355 sh_video_t * const sh_video = mpctx->sh_video;
2356 int brk_cmd = 0;
2357 if (!set_property_command(mpctx, cmd))
2358 switch (cmd->id) {
2359 case MP_CMD_SEEK:{
2360 float v;
2361 int abs;
2362 if (sh_video)
2363 mpctx->osd_show_percentage = sh_video->fps;
2364 v = cmd->args[0].v.f;
2365 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2366 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2367 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2368 if (sh_video)
2369 mpctx->osd_function =
2370 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2371 mpctx->rel_seek_secs = v;
2372 } else if (abs) { /* Absolute seek by percentage */
2373 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2374 if (sh_video)
2375 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2376 mpctx->rel_seek_secs = v / 100.0;
2377 } else {
2378 mpctx->rel_seek_secs += v;
2379 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2381 brk_cmd = 1;
2383 break;
2385 case MP_CMD_SET_PROPERTY:{
2386 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2387 cmd->args[1].v.s, mpctx);
2388 if (r == M_PROPERTY_UNKNOWN)
2389 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2390 "Unknown property: '%s'\n", cmd->args[0].v.s);
2391 else if (r <= 0)
2392 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2393 "Failed to set property '%s' to '%s'.\n",
2394 cmd->args[0].v.s, cmd->args[1].v.s);
2396 break;
2398 case MP_CMD_STEP_PROPERTY:{
2399 void* arg = NULL;
2400 int r,i;
2401 double d;
2402 off_t o;
2403 if (cmd->args[1].v.f) {
2404 m_option_t* prop;
2405 if((r = mp_property_do(cmd->args[0].v.s,
2406 M_PROPERTY_GET_TYPE,
2407 &prop, mpctx)) <= 0)
2408 goto step_prop_err;
2409 if(prop->type == CONF_TYPE_INT ||
2410 prop->type == CONF_TYPE_FLAG)
2411 i = cmd->args[1].v.f, arg = &i;
2412 else if(prop->type == CONF_TYPE_FLOAT)
2413 arg = &cmd->args[1].v.f;
2414 else if(prop->type == CONF_TYPE_DOUBLE ||
2415 prop->type == CONF_TYPE_TIME)
2416 d = cmd->args[1].v.f, arg = &d;
2417 else if(prop->type == CONF_TYPE_POSITION)
2418 o = cmd->args[1].v.f, arg = &o;
2419 else
2420 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2421 "Ignoring step size stepping property '%s'.\n",
2422 cmd->args[0].v.s);
2424 r = mp_property_do(cmd->args[0].v.s,
2425 cmd->args[2].v.i < 0 ?
2426 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2427 arg, mpctx);
2428 step_prop_err:
2429 if (r == M_PROPERTY_UNKNOWN)
2430 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2431 "Unknown property: '%s'\n", cmd->args[0].v.s);
2432 else if (r <= 0)
2433 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2434 "Failed to increment property '%s' by %f.\n",
2435 cmd->args[0].v.s, cmd->args[1].v.f);
2437 break;
2439 case MP_CMD_GET_PROPERTY:{
2440 char *tmp;
2441 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2442 &tmp, mpctx) <= 0) {
2443 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2444 "Failed to get value of property '%s'.\n",
2445 cmd->args[0].v.s);
2446 break;
2448 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2449 cmd->args[0].v.s, tmp);
2450 free(tmp);
2452 break;
2454 case MP_CMD_EDL_MARK:
2455 if (edl_fd) {
2456 float v = sh_video ? sh_video->pts :
2457 playing_audio_pts(mpctx);
2458 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2459 mpctx->begin_skip = v;
2460 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2461 } else {
2462 if (mpctx->begin_skip > v)
2463 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2464 else {
2465 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2466 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2468 mpctx->begin_skip = MP_NOPTS_VALUE;
2471 break;
2473 case MP_CMD_SWITCH_RATIO:
2474 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2475 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2476 else
2477 opts->movie_aspect = cmd->args[0].v.f;
2478 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2479 break;
2481 case MP_CMD_SPEED_INCR:{
2482 float v = cmd->args[0].v.f;
2483 opts->playback_speed += v;
2484 build_afilter_chain(mpctx, sh_audio, &ao_data);
2485 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2486 opts->playback_speed);
2487 } break;
2489 case MP_CMD_SPEED_MULT:{
2490 float v = cmd->args[0].v.f;
2491 opts->playback_speed *= v;
2492 build_afilter_chain(mpctx, sh_audio, &ao_data);
2493 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2494 opts->playback_speed);
2495 } break;
2497 case MP_CMD_SPEED_SET:{
2498 float v = cmd->args[0].v.f;
2499 opts->playback_speed = v;
2500 build_afilter_chain(mpctx, sh_audio, &ao_data);
2501 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2502 opts->playback_speed);
2503 } break;
2505 case MP_CMD_FRAME_STEP:
2506 case MP_CMD_PAUSE:
2507 cmd->pausing = 1;
2508 brk_cmd = 1;
2509 break;
2511 case MP_CMD_FILE_FILTER:
2512 file_filter = cmd->args[0].v.i;
2513 break;
2515 case MP_CMD_QUIT:
2516 exit_player_with_rc(mpctx, EXIT_QUIT,
2517 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2519 case MP_CMD_PLAY_TREE_STEP:{
2520 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2521 int force = cmd->args[1].v.i;
2523 #ifdef CONFIG_GUI
2524 if (use_gui) {
2525 int i = 0;
2526 if (n > 0)
2527 for (i = 0; i < n; i++)
2528 mplNext();
2529 else
2530 for (i = 0; i < -1 * n; i++)
2531 mplPrev();
2532 } else
2533 #endif
2535 if (!force && mpctx->playtree_iter) {
2536 play_tree_iter_t *i =
2537 play_tree_iter_new_copy(mpctx->playtree_iter);
2538 if (play_tree_iter_step(i, n, 0) ==
2539 PLAY_TREE_ITER_ENTRY)
2540 mpctx->stop_play =
2541 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2542 play_tree_iter_free(i);
2543 } else
2544 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2545 if (mpctx->stop_play)
2546 mpctx->play_tree_step = n;
2547 brk_cmd = 1;
2550 break;
2552 case MP_CMD_PLAY_TREE_UP_STEP:{
2553 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2554 int force = cmd->args[1].v.i;
2556 if (!force && mpctx->playtree_iter) {
2557 play_tree_iter_t *i =
2558 play_tree_iter_new_copy(mpctx->playtree_iter);
2559 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2560 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2561 play_tree_iter_free(i);
2562 } else
2563 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2564 brk_cmd = 1;
2566 break;
2568 case MP_CMD_PLAY_ALT_SRC_STEP:
2569 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2570 int v = cmd->args[0].v.i;
2571 if (v > 0
2572 && mpctx->playtree_iter->file <
2573 mpctx->playtree_iter->num_files)
2574 mpctx->stop_play = PT_NEXT_SRC;
2575 else if (v < 0 && mpctx->playtree_iter->file > 1)
2576 mpctx->stop_play = PT_PREV_SRC;
2578 brk_cmd = 1;
2579 break;
2581 case MP_CMD_SUB_STEP:
2582 if (sh_video) {
2583 int movement = cmd->args[0].v.i;
2584 step_sub(subdata, sh_video->pts, movement);
2585 #ifdef CONFIG_ASS
2586 if (ass_track)
2587 sub_delay +=
2588 ass_step_sub(ass_track,
2589 (sh_video->pts +
2590 sub_delay) * 1000 + .5, movement) / 1000.;
2591 #endif
2592 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2593 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2595 break;
2597 case MP_CMD_SUB_LOG:
2598 log_sub(mpctx);
2599 break;
2601 case MP_CMD_OSD:{
2602 int v = cmd->args[0].v.i;
2603 int max = (term_osd
2604 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2605 if (osd_level > max)
2606 osd_level = max;
2607 if (v < 0)
2608 osd_level = (osd_level + 1) % (max + 1);
2609 else
2610 osd_level = v > max ? max : v;
2611 /* Show OSD state when disabled, but not when an explicit
2612 argument is given to the OSD command, i.e. in slave mode. */
2613 if (v == -1 && osd_level <= 1)
2614 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2615 MSGTR_OSDosd,
2616 osd_level ? MSGTR_OSDenabled :
2617 MSGTR_OSDdisabled);
2618 else
2619 rm_osd_msg(OSD_MSG_OSD_STATUS);
2621 break;
2623 case MP_CMD_OSD_SHOW_TEXT:
2624 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2625 (cmd->args[1].v.i <
2626 0 ? osd_duration : cmd->args[1].v.i),
2627 "%-.63s", cmd->args[0].v.s);
2628 break;
2630 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2631 char *txt = m_properties_expand_string(mp_properties,
2632 cmd->args[0].v.s,
2633 mpctx);
2634 /* if no argument supplied take default osd_duration, else <arg> ms. */
2635 if (txt) {
2636 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2637 (cmd->args[1].v.i <
2638 0 ? osd_duration : cmd->args[1].v.i),
2639 "%-.63s", txt);
2640 free(txt);
2643 break;
2645 case MP_CMD_LOADFILE:{
2646 play_tree_t *e = play_tree_new();
2647 play_tree_add_file(e, cmd->args[0].v.s);
2649 if (cmd->args[1].v.i) // append
2650 play_tree_append_entry(mpctx->playtree->child, e);
2651 else {
2652 // Go back to the starting point.
2653 while (play_tree_iter_up_step
2654 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2655 /* NOP */ ;
2656 play_tree_free_list(mpctx->playtree->child, 1);
2657 play_tree_set_child(mpctx->playtree, e);
2658 pt_iter_goto_head(mpctx->playtree_iter);
2659 mpctx->stop_play = PT_NEXT_SRC;
2661 brk_cmd = 1;
2663 break;
2665 case MP_CMD_LOADLIST:{
2666 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2667 if (!e)
2668 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2669 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2670 else {
2671 if (cmd->args[1].v.i) // append
2672 play_tree_append_entry(mpctx->playtree->child, e);
2673 else {
2674 // Go back to the starting point.
2675 while (play_tree_iter_up_step
2676 (mpctx->playtree_iter, 0, 1)
2677 != PLAY_TREE_ITER_END)
2678 /* NOP */ ;
2679 play_tree_free_list(mpctx->playtree->child, 1);
2680 play_tree_set_child(mpctx->playtree, e);
2681 pt_iter_goto_head(mpctx->playtree_iter);
2682 mpctx->stop_play = PT_NEXT_SRC;
2685 brk_cmd = 1;
2687 break;
2689 case MP_CMD_STOP:
2690 // Go back to the starting point.
2691 while (play_tree_iter_up_step
2692 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2693 /* NOP */ ;
2694 mpctx->stop_play = PT_STOP;
2695 brk_cmd = 1;
2696 break;
2698 #ifdef CONFIG_RADIO
2699 case MP_CMD_RADIO_STEP_CHANNEL:
2700 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2701 int v = cmd->args[0].v.i;
2702 if (v > 0)
2703 radio_step_channel(mpctx->demuxer->stream,
2704 RADIO_CHANNEL_HIGHER);
2705 else
2706 radio_step_channel(mpctx->demuxer->stream,
2707 RADIO_CHANNEL_LOWER);
2708 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2709 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2710 MSGTR_OSDChannel,
2711 radio_get_channel_name(mpctx->demuxer->stream));
2714 break;
2716 case MP_CMD_RADIO_SET_CHANNEL:
2717 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2718 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2719 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2720 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2721 MSGTR_OSDChannel,
2722 radio_get_channel_name(mpctx->demuxer->stream));
2725 break;
2727 case MP_CMD_RADIO_SET_FREQ:
2728 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2729 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2730 break;
2732 case MP_CMD_RADIO_STEP_FREQ:
2733 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2734 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2735 break;
2736 #endif
2738 #ifdef CONFIG_TV
2739 case MP_CMD_TV_START_SCAN:
2740 if (mpctx->file_format == DEMUXER_TYPE_TV)
2741 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2742 break;
2743 case MP_CMD_TV_SET_FREQ:
2744 if (mpctx->file_format == DEMUXER_TYPE_TV)
2745 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2746 cmd->args[0].v.f * 16.0);
2747 #ifdef CONFIG_PVR
2748 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2749 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2750 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2751 pvr_get_current_channelname (mpctx->stream),
2752 pvr_get_current_stationname (mpctx->stream));
2754 #endif /* CONFIG_PVR */
2755 break;
2757 case MP_CMD_TV_STEP_FREQ:
2758 if (mpctx->file_format == DEMUXER_TYPE_TV)
2759 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2760 cmd->args[0].v.f * 16.0);
2761 #ifdef CONFIG_PVR
2762 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2763 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2764 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2765 pvr_get_current_channelname (mpctx->stream),
2766 pvr_get_current_frequency (mpctx->stream));
2768 #endif /* CONFIG_PVR */
2769 break;
2771 case MP_CMD_TV_SET_NORM:
2772 if (mpctx->file_format == DEMUXER_TYPE_TV)
2773 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2774 cmd->args[0].v.s);
2775 break;
2777 case MP_CMD_TV_STEP_CHANNEL:{
2778 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2779 int v = cmd->args[0].v.i;
2780 if (v > 0) {
2781 tv_step_channel((tvi_handle_t *) (mpctx->
2782 demuxer->priv),
2783 TV_CHANNEL_HIGHER);
2784 } else {
2785 tv_step_channel((tvi_handle_t *) (mpctx->
2786 demuxer->priv),
2787 TV_CHANNEL_LOWER);
2789 if (tv_channel_list) {
2790 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2791 MSGTR_OSDChannel, tv_channel_current->name);
2792 //vo_osd_changed(OSDTYPE_SUBTITLE);
2795 #ifdef CONFIG_PVR
2796 else if (mpctx->stream &&
2797 mpctx->stream->type == STREAMTYPE_PVR) {
2798 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2799 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2800 pvr_get_current_channelname (mpctx->stream),
2801 pvr_get_current_stationname (mpctx->stream));
2803 #endif /* CONFIG_PVR */
2805 #ifdef CONFIG_DVBIN
2806 if (mpctx->stream->type == STREAMTYPE_DVB) {
2807 int dir;
2808 int v = cmd->args[0].v.i;
2810 mpctx->last_dvb_step = v;
2811 if (v > 0)
2812 dir = DVB_CHANNEL_HIGHER;
2813 else
2814 dir = DVB_CHANNEL_LOWER;
2817 if (dvb_step_channel(mpctx->stream, dir)) {
2818 mpctx->stop_play = PT_NEXT_ENTRY;
2819 mpctx->dvbin_reopen = 1;
2822 #endif /* CONFIG_DVBIN */
2823 break;
2825 case MP_CMD_TV_SET_CHANNEL:
2826 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2827 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2828 cmd->args[0].v.s);
2829 if (tv_channel_list) {
2830 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2831 MSGTR_OSDChannel, tv_channel_current->name);
2832 //vo_osd_changed(OSDTYPE_SUBTITLE);
2835 #ifdef CONFIG_PVR
2836 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2837 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2838 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2839 pvr_get_current_channelname (mpctx->stream),
2840 pvr_get_current_stationname (mpctx->stream));
2842 #endif /* CONFIG_PVR */
2843 break;
2845 #ifdef CONFIG_DVBIN
2846 case MP_CMD_DVB_SET_CHANNEL:
2847 if (mpctx->stream->type == STREAMTYPE_DVB) {
2848 mpctx->last_dvb_step = 1;
2850 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
2851 cmd->args[0].v.i)) {
2852 mpctx->stop_play = PT_NEXT_ENTRY;
2853 mpctx->dvbin_reopen = 1;
2856 break;
2857 #endif /* CONFIG_DVBIN */
2859 case MP_CMD_TV_LAST_CHANNEL:
2860 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2861 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2862 if (tv_channel_list) {
2863 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2864 MSGTR_OSDChannel, tv_channel_current->name);
2865 //vo_osd_changed(OSDTYPE_SUBTITLE);
2868 #ifdef CONFIG_PVR
2869 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2870 pvr_set_lastchannel (mpctx->stream);
2871 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2872 pvr_get_current_channelname (mpctx->stream),
2873 pvr_get_current_stationname (mpctx->stream));
2875 #endif /* CONFIG_PVR */
2876 break;
2878 case MP_CMD_TV_STEP_NORM:
2879 if (mpctx->file_format == DEMUXER_TYPE_TV)
2880 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2881 break;
2883 case MP_CMD_TV_STEP_CHANNEL_LIST:
2884 if (mpctx->file_format == DEMUXER_TYPE_TV)
2885 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2886 break;
2887 #ifdef CONFIG_TV_TELETEXT
2888 case MP_CMD_TV_TELETEXT_ADD_DEC:
2890 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2891 if (mpctx->file_format == DEMUXER_TYPE_TV)
2892 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2893 break;
2895 case MP_CMD_TV_TELETEXT_GO_LINK:
2897 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2898 if (mpctx->file_format == DEMUXER_TYPE_TV)
2899 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2900 break;
2902 #endif /* CONFIG_TV_TELETEXT */
2903 #endif /* CONFIG_TV */
2905 case MP_CMD_SUB_LOAD:
2906 if (sh_video) {
2907 int n = mpctx->set_of_sub_size;
2908 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
2909 if (n != mpctx->set_of_sub_size) {
2910 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2911 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2912 mpctx->global_sub_size;
2913 ++mpctx->global_sub_size;
2916 break;
2918 case MP_CMD_SUB_REMOVE:
2919 if (sh_video) {
2920 int v = cmd->args[0].v.i;
2921 sub_data *subd;
2922 if (v < 0) {
2923 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2924 subd = mpctx->set_of_subtitles[v];
2925 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2926 MSGTR_RemovedSubtitleFile, v + 1,
2927 filename_recode(subd->filename));
2928 sub_free(subd);
2929 mpctx->set_of_subtitles[v] = NULL;
2931 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2932 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2933 mpctx->set_of_sub_size = 0;
2934 if (mpctx->set_of_sub_pos >= 0) {
2935 mpctx->global_sub_pos = -2;
2936 subdata = NULL;
2937 mp_input_queue_cmd(mpctx->input,
2938 mp_input_parse_cmd("sub_select"));
2940 } else if (v < mpctx->set_of_sub_size) {
2941 subd = mpctx->set_of_subtitles[v];
2942 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2943 MSGTR_RemovedSubtitleFile, v + 1,
2944 filename_recode(subd->filename));
2945 sub_free(subd);
2946 if (mpctx->set_of_sub_pos == v) {
2947 mpctx->global_sub_pos = -2;
2948 subdata = NULL;
2949 mp_input_queue_cmd(mpctx->input,
2950 mp_input_parse_cmd("sub_select"));
2951 } else if (mpctx->set_of_sub_pos > v) {
2952 --mpctx->set_of_sub_pos;
2953 --mpctx->global_sub_pos;
2955 while (++v < mpctx->set_of_sub_size)
2956 mpctx->set_of_subtitles[v - 1] =
2957 mpctx->set_of_subtitles[v];
2958 --mpctx->set_of_sub_size;
2959 --mpctx->global_sub_size;
2960 if (mpctx->set_of_sub_size <= 0)
2961 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2962 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2965 break;
2967 case MP_CMD_GET_SUB_VISIBILITY:
2968 if (sh_video) {
2969 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2970 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2972 break;
2974 case MP_CMD_SCREENSHOT:
2975 if (mpctx->video_out && mpctx->video_out->config_ok) {
2976 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2977 if (CONTROL_OK !=
2978 ((vf_instance_t *) sh_video->vfilter)->
2979 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2980 &cmd->args[0].v.i))
2981 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2983 break;
2985 case MP_CMD_VF_CHANGE_RECTANGLE:
2986 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2987 break;
2989 case MP_CMD_GET_TIME_LENGTH:{
2990 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2991 demuxer_get_time_length(mpctx->demuxer));
2993 break;
2995 case MP_CMD_GET_FILENAME:{
2996 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2997 get_metadata(mpctx, META_NAME));
2999 break;
3001 case MP_CMD_GET_VIDEO_CODEC:{
3002 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3003 if (!inf)
3004 inf = strdup("");
3005 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3006 free(inf);
3008 break;
3010 case MP_CMD_GET_VIDEO_BITRATE:{
3011 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3012 if (!inf)
3013 inf = strdup("");
3014 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3015 free(inf);
3017 break;
3019 case MP_CMD_GET_VIDEO_RESOLUTION:{
3020 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3021 if (!inf)
3022 inf = strdup("");
3023 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3024 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3025 free(inf);
3027 break;
3029 case MP_CMD_GET_AUDIO_CODEC:{
3030 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3031 if (!inf)
3032 inf = strdup("");
3033 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3034 free(inf);
3036 break;
3038 case MP_CMD_GET_AUDIO_BITRATE:{
3039 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3040 if (!inf)
3041 inf = strdup("");
3042 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3043 free(inf);
3045 break;
3047 case MP_CMD_GET_AUDIO_SAMPLES:{
3048 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3049 if (!inf)
3050 inf = strdup("");
3051 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3052 free(inf);
3054 break;
3056 case MP_CMD_GET_META_TITLE:{
3057 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3058 if (!inf)
3059 inf = strdup("");
3060 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3061 free(inf);
3063 break;
3065 case MP_CMD_GET_META_ARTIST:{
3066 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3067 if (!inf)
3068 inf = strdup("");
3069 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3070 free(inf);
3072 break;
3074 case MP_CMD_GET_META_ALBUM:{
3075 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3076 if (!inf)
3077 inf = strdup("");
3078 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3079 free(inf);
3081 break;
3083 case MP_CMD_GET_META_YEAR:{
3084 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3085 if (!inf)
3086 inf = strdup("");
3087 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3088 free(inf);
3090 break;
3092 case MP_CMD_GET_META_COMMENT:{
3093 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3094 if (!inf)
3095 inf = strdup("");
3096 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3097 free(inf);
3099 break;
3101 case MP_CMD_GET_META_TRACK:{
3102 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3103 if (!inf)
3104 inf = strdup("");
3105 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3106 free(inf);
3108 break;
3110 case MP_CMD_GET_META_GENRE:{
3111 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3112 if (!inf)
3113 inf = strdup("");
3114 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3115 free(inf);
3117 break;
3119 case MP_CMD_GET_VO_FULLSCREEN:
3120 if (mpctx->video_out && mpctx->video_out->config_ok)
3121 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3122 break;
3124 case MP_CMD_GET_PERCENT_POS:
3125 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3126 demuxer_get_percent_pos(mpctx->demuxer));
3127 break;
3129 case MP_CMD_GET_TIME_POS:{
3130 float pos = 0;
3131 if (sh_video)
3132 pos = sh_video->pts;
3133 else if (sh_audio && mpctx->audio_out)
3134 pos = playing_audio_pts(mpctx);
3135 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3137 break;
3139 case MP_CMD_RUN:
3140 #ifndef __MINGW32__
3141 if (!fork()) {
3142 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3143 exit(0);
3145 #endif
3146 break;
3148 case MP_CMD_KEYDOWN_EVENTS:
3149 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3150 break;
3152 case MP_CMD_SET_MOUSE_POS:{
3153 int pointer_x, pointer_y;
3154 double dx, dy;
3155 pointer_x = cmd->args[0].v.i;
3156 pointer_y = cmd->args[1].v.i;
3157 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3158 #ifdef CONFIG_DVDNAV
3159 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3160 && dx > 0.0 && dy > 0.0) {
3161 int button = -1;
3162 pointer_x = (int) (dx * (double) sh_video->disp_w);
3163 pointer_y = (int) (dy * (double) sh_video->disp_h);
3164 mp_dvdnav_update_mouse_pos(mpctx->stream,
3165 pointer_x, pointer_y, &button);
3166 if (osd_level > 1 && button > 0)
3167 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3168 "Selected button number %d", button);
3170 #endif
3171 #ifdef CONFIG_MENU
3172 if (use_menu && dx >= 0.0 && dy >= 0.0)
3173 menu_update_mouse_pos(dx, dy);
3174 #endif
3176 break;
3178 #ifdef CONFIG_DVDNAV
3179 case MP_CMD_DVDNAV:{
3180 int button = -1;
3181 int i;
3182 mp_command_type command = 0;
3183 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3184 break;
3186 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3187 if (cmd->args[0].v.s &&
3188 !strcasecmp (cmd->args[0].v.s,
3189 mp_dvdnav_bindings[i].name))
3190 command = mp_dvdnav_bindings[i].cmd;
3192 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3193 if (osd_level > 1 && button > 0)
3194 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3195 "Selected button number %d", button);
3197 break;
3199 case MP_CMD_SWITCH_TITLE:
3200 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3201 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3202 break;
3204 #endif
3206 default:
3207 #ifdef CONFIG_GUI
3208 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3209 guiGetEvent(guiIEvent, (char *) cmd->id);
3210 else
3211 #endif
3212 mp_msg(MSGT_CPLAYER, MSGL_V,
3213 "Received unknown cmd %s\n", cmd->name);
3216 switch (cmd->pausing) {
3217 case 1: // "pausing"
3218 mpctx->osd_function = OSD_PAUSE;
3219 break;
3220 case 3: // "pausing_toggle"
3221 mpctx->was_paused = !mpctx->was_paused;
3222 if (mpctx->was_paused)
3223 mpctx->osd_function = OSD_PAUSE;
3224 else if (mpctx->osd_function == OSD_PAUSE)
3225 mpctx->osd_function = OSD_PLAY;
3226 break;
3227 case 2: // "pausing_keep"
3228 if (mpctx->was_paused)
3229 mpctx->osd_function = OSD_PAUSE;
3231 return brk_cmd;