vo_xv: Reformat code
[mplayer.git] / command.c
blob72fe83c2e71ca09e9f39482d86162edf0dea27c1
1 #include <stdlib.h>
2 #include <inttypes.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <stdbool.h>
7 #include "config.h"
8 #include "command.h"
9 #include "input/input.h"
10 #include "stream/stream.h"
11 #include "libmpdemux/demuxer.h"
12 #include "libmpdemux/stheader.h"
13 #include "codec-cfg.h"
14 #include "mplayer.h"
15 #include "libvo/sub.h"
16 #include "m_option.h"
17 #include "m_property.h"
18 #include "help_mp.h"
19 #include "metadata.h"
20 #include "libmpcodecs/vf.h"
21 #include "libmpcodecs/vd.h"
22 #include "mp_osd.h"
23 #include "libvo/video_out.h"
24 #include "libvo/font_load.h"
25 #include "playtree.h"
26 #include "libao2/audio_out.h"
27 #include "mpcommon.h"
28 #include "mixer.h"
29 #include "libmpcodecs/dec_video.h"
30 #include "vobsub.h"
31 #include "spudec.h"
32 #include "get_path.h"
33 #ifdef CONFIG_TV
34 #include "stream/tv.h"
35 #endif
36 #ifdef CONFIG_RADIO
37 #include "stream/stream_radio.h"
38 #endif
39 #ifdef CONFIG_PVR
40 #include "stream/pvr.h"
41 #endif
42 #ifdef CONFIG_DVBIN
43 #include "stream/dvbin.h"
44 #endif
45 #ifdef CONFIG_DVDREAD
46 #include "stream/stream_dvd.h"
47 #endif
48 #ifdef CONFIG_DVDNAV
49 #include "stream/stream_dvdnav.h"
50 #endif
51 #ifdef CONFIG_ASS
52 #include "libass/ass.h"
53 #include "libass/ass_mp.h"
54 #endif
55 #ifdef CONFIG_MENU
56 #include "m_struct.h"
57 #include "libmenu/menu.h"
58 #endif
59 #ifdef CONFIG_GUI
60 #include "gui/interface.h"
61 #endif
63 #include "mp_core.h"
64 #include "mp_fifo.h"
65 #include "libavutil/avstring.h"
67 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
69 extern int use_menu;
71 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
72 double *dx, double *dy)
74 struct MPOpts *opts = &mpctx->opts;
75 struct vo *vo = mpctx->video_out;
76 //remove the borders, if any, and rescale to the range [0,1],[0,1]
77 if (vo_fs) { //we are in full-screen mode
78 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
79 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
80 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
81 iy -= (opts->vo_screenheight - vo->dheight) / 2;
83 if (ix < 0 || ix > vo->dwidth) {
84 *dx = *dy = -1.0;
85 return;
86 } //we are on one of the borders
87 if (iy < 0 || iy > vo->dheight) {
88 *dx = *dy = -1.0;
89 return;
90 } //we are on one of the borders
93 *dx = (double) ix / (double) vo->dwidth;
94 *dy = (double) iy / (double) vo->dheight;
96 mp_msg(MSGT_CPLAYER, MSGL_V,
97 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
98 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
99 vo->dheight, vo_fs);
102 static int sub_source_by_pos(MPContext *mpctx, int pos)
104 int source = -1;
105 int top = -1;
106 int i;
107 for (i = 0; i < SUB_SOURCES; i++) {
108 int j = mpctx->global_sub_indices[i];
109 if ((j >= 0) && (j > top) && (pos >= j)) {
110 source = i;
111 top = j;
114 return source;
117 static int sub_source(MPContext *mpctx)
119 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
123 * \brief Log the currently displayed subtitle to a file
125 * Logs the current or last displayed subtitle together with filename
126 * and time information to ~/.mplayer/subtitle_log
128 * Intended purpose is to allow convenient marking of bogus subtitles
129 * which need to be fixed while watching the movie.
132 static void log_sub(struct MPContext *mpctx)
134 char *fname;
135 FILE *f;
136 int i;
138 if (subdata == NULL || vo_sub_last == NULL)
139 return;
140 fname = get_path("subtitle_log");
141 f = fopen(fname, "a");
142 if (!f)
143 return;
144 fprintf(f, "----------------------------------------------------------\n");
145 if (subdata->sub_uses_time) {
146 fprintf(f,
147 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
148 mpctx->filename, vo_sub_last->start / 360000,
149 (vo_sub_last->start / 6000) % 60,
150 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
151 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
152 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
153 } else {
154 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
155 vo_sub_last->start, vo_sub_last->end);
157 for (i = 0; i < vo_sub_last->lines; i++) {
158 fprintf(f, "%s\n", vo_sub_last->text[i]);
160 fclose(f);
164 /// \defgroup Properties
165 ///@{
167 /// \defgroup GeneralProperties General properties
168 /// \ingroup Properties
169 ///@{
171 /// OSD level (RW)
172 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
173 MPContext *mpctx)
175 return m_property_choice(prop, action, arg, &osd_level);
178 /// Loop (RW)
179 static int mp_property_loop(m_option_t *prop, int action, void *arg,
180 MPContext *mpctx)
182 struct MPOpts *opts = &mpctx->opts;
183 switch (action) {
184 case M_PROPERTY_PRINT:
185 if (!arg) return M_PROPERTY_ERROR;
186 if (opts->loop_times < 0)
187 *(char**)arg = strdup("off");
188 else if (opts->loop_times == 0)
189 *(char**)arg = strdup("inf");
190 else
191 break;
192 return M_PROPERTY_OK;
194 return m_property_int_range(prop, action, arg, &opts->loop_times);
197 /// Playback speed (RW)
198 static int mp_property_playback_speed(m_option_t *prop, int action,
199 void *arg, MPContext *mpctx)
201 struct MPOpts *opts = &mpctx->opts;
202 switch (action) {
203 case M_PROPERTY_SET:
204 if (!arg)
205 return M_PROPERTY_ERROR;
206 M_PROPERTY_CLAMP(prop, *(float *) arg);
207 opts->playback_speed = *(float *) arg;
208 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
209 return M_PROPERTY_OK;
210 case M_PROPERTY_STEP_UP:
211 case M_PROPERTY_STEP_DOWN:
212 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
213 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
214 M_PROPERTY_CLAMP(prop, opts->playback_speed);
215 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
216 return M_PROPERTY_OK;
218 return m_property_float_range(prop, action, arg, &opts->playback_speed);
221 /// filename with path (RO)
222 static int mp_property_path(m_option_t *prop, int action, void *arg,
223 MPContext *mpctx)
225 return m_property_string_ro(prop, action, arg, mpctx->filename);
228 /// filename without path (RO)
229 static int mp_property_filename(m_option_t *prop, int action, void *arg,
230 MPContext *mpctx)
232 char *f;
233 if (!mpctx->filename)
234 return M_PROPERTY_UNAVAILABLE;
235 if (((f = strrchr(mpctx->filename, '/'))
236 || (f = strrchr(mpctx->filename, '\\'))) && f[1])
237 f++;
238 else
239 f = mpctx->filename;
240 return m_property_string_ro(prop, action, arg, f);
243 /// Demuxer name (RO)
244 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
245 MPContext *mpctx)
247 if (!mpctx->demuxer)
248 return M_PROPERTY_UNAVAILABLE;
249 return m_property_string_ro(prop, action, arg,
250 (char *) mpctx->demuxer->desc->name);
253 /// Position in the stream (RW)
254 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
255 MPContext *mpctx)
257 if (!mpctx->demuxer || !mpctx->demuxer->stream)
258 return M_PROPERTY_UNAVAILABLE;
259 if (!arg)
260 return M_PROPERTY_ERROR;
261 switch (action) {
262 case M_PROPERTY_GET:
263 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
264 return M_PROPERTY_OK;
265 case M_PROPERTY_SET:
266 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
267 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
268 return M_PROPERTY_OK;
270 return M_PROPERTY_NOT_IMPLEMENTED;
273 /// Stream start offset (RO)
274 static int mp_property_stream_start(m_option_t *prop, int action,
275 void *arg, MPContext *mpctx)
277 if (!mpctx->demuxer || !mpctx->demuxer->stream)
278 return M_PROPERTY_UNAVAILABLE;
279 switch (action) {
280 case M_PROPERTY_GET:
281 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
282 return M_PROPERTY_OK;
284 return M_PROPERTY_NOT_IMPLEMENTED;
287 /// Stream end offset (RO)
288 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
289 MPContext *mpctx)
291 if (!mpctx->demuxer || !mpctx->demuxer->stream)
292 return M_PROPERTY_UNAVAILABLE;
293 switch (action) {
294 case M_PROPERTY_GET:
295 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
296 return M_PROPERTY_OK;
298 return M_PROPERTY_NOT_IMPLEMENTED;
301 /// Stream length (RO)
302 static int mp_property_stream_length(m_option_t *prop, int action,
303 void *arg, MPContext *mpctx)
305 if (!mpctx->demuxer || !mpctx->demuxer->stream)
306 return M_PROPERTY_UNAVAILABLE;
307 switch (action) {
308 case M_PROPERTY_GET:
309 *(off_t *) arg =
310 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
311 return M_PROPERTY_OK;
313 return M_PROPERTY_NOT_IMPLEMENTED;
316 /// Media length in seconds (RO)
317 static int mp_property_length(m_option_t *prop, int action, void *arg,
318 MPContext *mpctx)
320 double len;
322 if (!mpctx->demuxer ||
323 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
324 return M_PROPERTY_UNAVAILABLE;
326 return m_property_time_ro(prop, action, arg, len);
329 /// Current position in percent (RW)
330 static int mp_property_percent_pos(m_option_t *prop, int action,
331 void *arg, MPContext *mpctx) {
332 int pos;
334 if (!mpctx->demuxer)
335 return M_PROPERTY_UNAVAILABLE;
337 switch(action) {
338 case M_PROPERTY_SET:
339 if(!arg) return M_PROPERTY_ERROR;
340 M_PROPERTY_CLAMP(prop, *(int*)arg);
341 pos = *(int*)arg;
342 break;
343 case M_PROPERTY_STEP_UP:
344 case M_PROPERTY_STEP_DOWN:
345 pos = demuxer_get_percent_pos(mpctx->demuxer);
346 pos += (arg ? *(int*)arg : 10) *
347 (action == M_PROPERTY_STEP_UP ? 1 : -1);
348 M_PROPERTY_CLAMP(prop, pos);
349 break;
350 default:
351 return m_property_int_ro(prop, action, arg,
352 demuxer_get_percent_pos(mpctx->demuxer));
355 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
356 mpctx->rel_seek_secs = pos / 100.0;
357 return M_PROPERTY_OK;
360 /// Current position in seconds (RW)
361 static int mp_property_time_pos(m_option_t *prop, int action,
362 void *arg, MPContext *mpctx) {
363 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
364 return M_PROPERTY_UNAVAILABLE;
366 switch(action) {
367 case M_PROPERTY_SET:
368 if(!arg) return M_PROPERTY_ERROR;
369 M_PROPERTY_CLAMP(prop, *(double*)arg);
370 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
371 mpctx->rel_seek_secs = *(double*)arg;
372 return M_PROPERTY_OK;
373 case M_PROPERTY_STEP_UP:
374 case M_PROPERTY_STEP_DOWN:
375 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
376 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
377 return M_PROPERTY_OK;
379 return m_property_time_ro(prop, action, arg,
380 mpctx->sh_video ? mpctx->sh_video->pts :
381 playing_audio_pts(mpctx));
384 /// Current chapter (RW)
385 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
386 MPContext *mpctx)
388 int chapter = -1;
389 float next_pts = 0;
390 int chapter_num;
391 int step_all;
392 char *chapter_name = NULL;
394 if (mpctx->demuxer)
395 chapter = demuxer_get_current_chapter(mpctx->demuxer);
396 if (chapter < 0)
397 return M_PROPERTY_UNAVAILABLE;
399 switch (action) {
400 case M_PROPERTY_GET:
401 if (!arg)
402 return M_PROPERTY_ERROR;
403 *(int *) arg = chapter;
404 return M_PROPERTY_OK;
405 case M_PROPERTY_PRINT: {
406 if (!arg)
407 return M_PROPERTY_ERROR;
408 chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter);
409 if (!chapter_name)
410 return M_PROPERTY_UNAVAILABLE;
411 *(char **) arg = chapter_name;
412 return M_PROPERTY_OK;
414 case M_PROPERTY_SET:
415 if (!arg)
416 return M_PROPERTY_ERROR;
417 M_PROPERTY_CLAMP(prop, *(int*)arg);
418 step_all = *(int *)arg - (chapter + 1);
419 chapter += step_all;
420 break;
421 case M_PROPERTY_STEP_UP:
422 case M_PROPERTY_STEP_DOWN: {
423 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
424 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
425 chapter += step_all;
426 if (chapter < 0)
427 chapter = 0;
428 break;
430 default:
431 return M_PROPERTY_NOT_IMPLEMENTED;
433 mpctx->rel_seek_secs = 0;
434 mpctx->abs_seek_pos = 0;
435 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
436 &next_pts, &chapter_num, &chapter_name);
437 if (chapter >= 0) {
438 if (next_pts > -1.0) {
439 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
440 mpctx->rel_seek_secs = next_pts;
442 if (chapter_name)
443 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
444 MSGTR_OSDChapter, chapter + 1, chapter_name);
446 else if (step_all > 0)
447 mpctx->rel_seek_secs = 1000000000.;
448 else
449 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
450 MSGTR_OSDChapter, 0, MSGTR_Unknown);
451 if (chapter_name)
452 free(chapter_name);
453 return M_PROPERTY_OK;
456 /// Number of chapters in file
457 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
458 MPContext *mpctx)
460 if (!mpctx->demuxer)
461 return M_PROPERTY_UNAVAILABLE;
462 if (mpctx->demuxer->num_chapters == 0)
463 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
464 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
467 /// Current dvd angle (RW)
468 static int mp_property_angle(m_option_t *prop, int action, void *arg,
469 MPContext *mpctx)
471 int angle = -1;
472 int angles;
473 char *angle_name = NULL;
475 if (mpctx->demuxer)
476 angle = demuxer_get_current_angle(mpctx->demuxer);
477 if (angle < 0)
478 return M_PROPERTY_UNAVAILABLE;
479 angles = demuxer_angles_count(mpctx->demuxer);
480 if (angles <= 1)
481 return M_PROPERTY_UNAVAILABLE;
483 switch (action) {
484 case M_PROPERTY_GET:
485 if (!arg)
486 return M_PROPERTY_ERROR;
487 *(int *) arg = angle;
488 return M_PROPERTY_OK;
489 case M_PROPERTY_PRINT: {
490 if (!arg)
491 return M_PROPERTY_ERROR;
492 angle_name = calloc(1, 64);
493 if (!angle_name)
494 return M_PROPERTY_UNAVAILABLE;
495 snprintf(angle_name, 64, "%d/%d", angle, angles);
496 *(char **) arg = angle_name;
497 return M_PROPERTY_OK;
499 case M_PROPERTY_SET:
500 if (!arg)
501 return M_PROPERTY_ERROR;
502 angle = *(int *)arg;
503 M_PROPERTY_CLAMP(prop, angle);
504 break;
505 case M_PROPERTY_STEP_UP:
506 case M_PROPERTY_STEP_DOWN: {
507 int step = 0;
508 if(arg)
509 step = *(int*)arg;
510 if(!step)
511 step = 1;
512 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
513 angle += step;
514 if (angle < 1) //cycle
515 angle = angles;
516 break;
518 default:
519 return M_PROPERTY_NOT_IMPLEMENTED;
521 angle = demuxer_set_angle(mpctx->demuxer, angle);
522 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
523 MSGTR_OSDAngle, angle, angles);
524 if (angle_name)
525 free(angle_name);
526 return M_PROPERTY_OK;
529 /// Demuxer meta data
530 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
531 MPContext *mpctx) {
532 m_property_action_t* ka;
533 char* meta;
534 static const m_option_t key_type =
535 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
536 if (!mpctx->demuxer)
537 return M_PROPERTY_UNAVAILABLE;
539 switch(action) {
540 case M_PROPERTY_GET:
541 if(!arg) return M_PROPERTY_ERROR;
542 *(char***)arg = mpctx->demuxer->info;
543 return M_PROPERTY_OK;
544 case M_PROPERTY_KEY_ACTION:
545 if(!arg) return M_PROPERTY_ERROR;
546 ka = arg;
547 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
548 return M_PROPERTY_UNKNOWN;
549 switch(ka->action) {
550 case M_PROPERTY_GET:
551 if(!ka->arg) return M_PROPERTY_ERROR;
552 *(char**)ka->arg = meta;
553 return M_PROPERTY_OK;
554 case M_PROPERTY_GET_TYPE:
555 if(!ka->arg) return M_PROPERTY_ERROR;
556 *(m_option_t**)ka->arg = &key_type;
557 return M_PROPERTY_OK;
560 return M_PROPERTY_NOT_IMPLEMENTED;
563 static int mp_property_pause(m_option_t *prop, int action, void *arg,
564 void *ctx)
566 MPContext *mpctx = ctx;
568 switch (action) {
569 case M_PROPERTY_SET:
570 if (!arg)
571 return M_PROPERTY_ERROR;
572 if (mpctx->paused == (bool)*(int *) arg)
573 return M_PROPERTY_OK;
574 case M_PROPERTY_STEP_UP:
575 case M_PROPERTY_STEP_DOWN:
576 if (mpctx->paused)
577 unpause_player(mpctx);
578 else
579 pause_player(mpctx);
580 return M_PROPERTY_OK;
581 default:
582 return m_property_flag(prop, action, arg, &mpctx->paused);
587 ///@}
589 /// \defgroup AudioProperties Audio properties
590 /// \ingroup Properties
591 ///@{
593 /// Volume (RW)
594 static int mp_property_volume(m_option_t *prop, int action, void *arg,
595 MPContext *mpctx)
598 if (!mpctx->sh_audio)
599 return M_PROPERTY_UNAVAILABLE;
601 switch (action) {
602 case M_PROPERTY_GET:
603 if (!arg)
604 return M_PROPERTY_ERROR;
605 mixer_getbothvolume(&mpctx->mixer, arg);
606 return M_PROPERTY_OK;
607 case M_PROPERTY_PRINT:{
608 float vol;
609 if (!arg)
610 return M_PROPERTY_ERROR;
611 mixer_getbothvolume(&mpctx->mixer, &vol);
612 return m_property_float_range(prop, action, arg, &vol);
614 case M_PROPERTY_STEP_UP:
615 case M_PROPERTY_STEP_DOWN:
616 case M_PROPERTY_SET:
617 break;
618 default:
619 return M_PROPERTY_NOT_IMPLEMENTED;
622 if (mpctx->edl_muted)
623 return M_PROPERTY_DISABLED;
624 mpctx->user_muted = 0;
626 switch (action) {
627 case M_PROPERTY_SET:
628 if (!arg)
629 return M_PROPERTY_ERROR;
630 M_PROPERTY_CLAMP(prop, *(float *) arg);
631 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
632 return M_PROPERTY_OK;
633 case M_PROPERTY_STEP_UP:
634 if (arg && *(float *) arg <= 0)
635 mixer_decvolume(&mpctx->mixer);
636 else
637 mixer_incvolume(&mpctx->mixer);
638 return M_PROPERTY_OK;
639 case M_PROPERTY_STEP_DOWN:
640 if (arg && *(float *) arg <= 0)
641 mixer_incvolume(&mpctx->mixer);
642 else
643 mixer_decvolume(&mpctx->mixer);
644 return M_PROPERTY_OK;
646 return M_PROPERTY_NOT_IMPLEMENTED;
649 /// Mute (RW)
650 static int mp_property_mute(m_option_t *prop, int action, void *arg,
651 MPContext *mpctx)
654 if (!mpctx->sh_audio)
655 return M_PROPERTY_UNAVAILABLE;
657 switch (action) {
658 case M_PROPERTY_SET:
659 if (mpctx->edl_muted)
660 return M_PROPERTY_DISABLED;
661 if (!arg)
662 return M_PROPERTY_ERROR;
663 if ((!!*(int *) arg) != mpctx->mixer.muted)
664 mixer_mute(&mpctx->mixer);
665 mpctx->user_muted = mpctx->mixer.muted;
666 return M_PROPERTY_OK;
667 case M_PROPERTY_STEP_UP:
668 case M_PROPERTY_STEP_DOWN:
669 if (mpctx->edl_muted)
670 return M_PROPERTY_DISABLED;
671 mixer_mute(&mpctx->mixer);
672 mpctx->user_muted = mpctx->mixer.muted;
673 return M_PROPERTY_OK;
674 case M_PROPERTY_PRINT:
675 if (!arg)
676 return M_PROPERTY_ERROR;
677 if (mpctx->edl_muted) {
678 *(char **) arg = strdup(MSGTR_EnabledEdl);
679 return M_PROPERTY_OK;
681 default:
682 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
687 /// Audio delay (RW)
688 static int mp_property_audio_delay(m_option_t *prop, int action,
689 void *arg, MPContext *mpctx)
691 if (!(mpctx->sh_audio && mpctx->sh_video))
692 return M_PROPERTY_UNAVAILABLE;
693 switch (action) {
694 case M_PROPERTY_SET:
695 case M_PROPERTY_STEP_UP:
696 case M_PROPERTY_STEP_DOWN: {
697 int ret;
698 float delay = audio_delay;
699 ret = m_property_delay(prop, action, arg, &audio_delay);
700 if (ret != M_PROPERTY_OK)
701 return ret;
702 if (mpctx->sh_audio)
703 mpctx->delay -= audio_delay - delay;
705 return M_PROPERTY_OK;
706 default:
707 return m_property_delay(prop, action, arg, &audio_delay);
711 /// Audio codec tag (RO)
712 static int mp_property_audio_format(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_int_ro(prop, action, arg, mpctx->sh_audio->format);
720 /// Audio codec name (RO)
721 static int mp_property_audio_codec(m_option_t *prop, int action,
722 void *arg, MPContext *mpctx)
724 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
725 return M_PROPERTY_UNAVAILABLE;
726 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
729 /// Audio bitrate (RO)
730 static int mp_property_audio_bitrate(m_option_t *prop, int action,
731 void *arg, MPContext *mpctx)
733 if (!mpctx->sh_audio)
734 return M_PROPERTY_UNAVAILABLE;
735 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
738 /// Samplerate (RO)
739 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
740 MPContext *mpctx)
742 if (!mpctx->sh_audio)
743 return M_PROPERTY_UNAVAILABLE;
744 switch(action) {
745 case M_PROPERTY_PRINT:
746 if(!arg) return M_PROPERTY_ERROR;
747 *(char**)arg = malloc(16);
748 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
749 return M_PROPERTY_OK;
751 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
754 /// Number of channels (RO)
755 static int mp_property_channels(m_option_t *prop, int action, void *arg,
756 MPContext *mpctx)
758 if (!mpctx->sh_audio)
759 return M_PROPERTY_UNAVAILABLE;
760 switch (action) {
761 case M_PROPERTY_PRINT:
762 if (!arg)
763 return M_PROPERTY_ERROR;
764 switch (mpctx->sh_audio->channels) {
765 case 1:
766 *(char **) arg = strdup("mono");
767 break;
768 case 2:
769 *(char **) arg = strdup("stereo");
770 break;
771 default:
772 *(char **) arg = malloc(32);
773 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
775 return M_PROPERTY_OK;
777 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
780 /// Balance (RW)
781 static int mp_property_balance(m_option_t *prop, int action, void *arg,
782 MPContext *mpctx)
784 float bal;
786 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
787 return M_PROPERTY_UNAVAILABLE;
789 switch (action) {
790 case M_PROPERTY_GET:
791 if (!arg)
792 return M_PROPERTY_ERROR;
793 mixer_getbalance(&mpctx->mixer, arg);
794 return M_PROPERTY_OK;
795 case M_PROPERTY_PRINT: {
796 char** str = arg;
797 if (!arg)
798 return M_PROPERTY_ERROR;
799 mixer_getbalance(&mpctx->mixer, &bal);
800 if (bal == 0.f)
801 *str = strdup("center");
802 else if (bal == -1.f)
803 *str = strdup("left only");
804 else if (bal == 1.f)
805 *str = strdup("right only");
806 else {
807 unsigned right = (bal + 1.f) / 2.f * 100.f;
808 *str = malloc(sizeof("left xxx%, right xxx%"));
809 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
811 return M_PROPERTY_OK;
813 case M_PROPERTY_STEP_UP:
814 case M_PROPERTY_STEP_DOWN:
815 mixer_getbalance(&mpctx->mixer, &bal);
816 bal += (arg ? *(float*)arg : .1f) *
817 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
818 M_PROPERTY_CLAMP(prop, bal);
819 mixer_setbalance(&mpctx->mixer, bal);
820 return M_PROPERTY_OK;
821 case M_PROPERTY_SET:
822 if (!arg)
823 return M_PROPERTY_ERROR;
824 M_PROPERTY_CLAMP(prop, *(float*)arg);
825 mixer_setbalance(&mpctx->mixer, *(float*)arg);
826 return M_PROPERTY_OK;
828 return M_PROPERTY_NOT_IMPLEMENTED;
831 /// Selected audio id (RW)
832 static int mp_property_audio(m_option_t *prop, int action, void *arg,
833 MPContext *mpctx)
835 struct MPOpts *opts = &mpctx->opts;
836 int current_id = -1, tmp;
838 switch (action) {
839 case M_PROPERTY_GET:
840 if (!mpctx->sh_audio)
841 return M_PROPERTY_UNAVAILABLE;
842 if (!arg)
843 return M_PROPERTY_ERROR;
844 *(int *) arg = opts->audio_id;
845 return M_PROPERTY_OK;
846 case M_PROPERTY_PRINT:
847 if (!mpctx->sh_audio)
848 return M_PROPERTY_UNAVAILABLE;
849 if (!arg)
850 return M_PROPERTY_ERROR;
852 if (opts->audio_id < 0)
853 *(char **) arg = strdup(MSGTR_Disabled);
854 else {
855 char lang[40] = MSGTR_Unknown;
856 sh_audio_t* sh = mpctx->sh_audio;
857 if (sh && sh->lang)
858 av_strlcpy(lang, sh->lang, 40);
859 #ifdef CONFIG_DVDREAD
860 else if (mpctx->stream->type == STREAMTYPE_DVD) {
861 int code = dvd_lang_from_aid(mpctx->stream, opts->audio_id);
862 if (code) {
863 lang[0] = code >> 8;
864 lang[1] = code;
865 lang[2] = 0;
868 #endif
870 #ifdef CONFIG_DVDNAV
871 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
872 mp_dvdnav_lang_from_aid(mpctx->stream, opts->audio_id, lang);
873 #endif
874 *(char **) arg = malloc(64);
875 snprintf(*(char **) arg, 64, "(%d) %s", opts->audio_id, lang);
877 return M_PROPERTY_OK;
879 case M_PROPERTY_STEP_UP:
880 case M_PROPERTY_SET:
881 if (!mpctx->demuxer)
882 return M_PROPERTY_UNAVAILABLE;
883 if (action == M_PROPERTY_SET && arg)
884 tmp = *((int *) arg);
885 else
886 tmp = -1;
887 current_id = mpctx->demuxer->audio->id;
888 opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
889 if (opts->audio_id == -2
890 || (opts->audio_id > -1
891 && mpctx->demuxer->audio->id != current_id && current_id != -2))
892 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
893 if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
894 sh_audio_t *sh2;
895 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
896 if (sh2) {
897 sh2->ds = mpctx->demuxer->audio;
898 mpctx->sh_audio = sh2;
899 reinit_audio_chain(mpctx);
902 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id);
903 return M_PROPERTY_OK;
904 default:
905 return M_PROPERTY_NOT_IMPLEMENTED;
910 /// Selected video id (RW)
911 static int mp_property_video(m_option_t *prop, int action, void *arg,
912 MPContext *mpctx)
914 struct MPOpts *opts = &mpctx->opts;
915 int current_id = -1, tmp;
917 switch (action) {
918 case M_PROPERTY_GET:
919 if (!mpctx->sh_video)
920 return M_PROPERTY_UNAVAILABLE;
921 if (!arg)
922 return M_PROPERTY_ERROR;
923 *(int *) arg = opts->video_id;
924 return M_PROPERTY_OK;
925 case M_PROPERTY_PRINT:
926 if (!mpctx->sh_video)
927 return M_PROPERTY_UNAVAILABLE;
928 if (!arg)
929 return M_PROPERTY_ERROR;
931 if (opts->video_id < 0)
932 *(char **) arg = strdup(MSGTR_Disabled);
933 else {
934 char lang[40] = MSGTR_Unknown;
935 *(char **) arg = malloc(64);
936 snprintf(*(char **) arg, 64, "(%d) %s", opts->video_id, lang);
938 return M_PROPERTY_OK;
940 case M_PROPERTY_STEP_UP:
941 case M_PROPERTY_SET:
942 current_id = mpctx->demuxer->video->id;
943 if (action == M_PROPERTY_SET && arg)
944 tmp = *((int *) arg);
945 else
946 tmp = -1;
947 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
948 if (opts->video_id == -2
949 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
950 && current_id != -2))
951 uninit_player(mpctx, INITIALIZED_VCODEC |
952 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
953 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
954 sh_video_t *sh2;
955 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
956 if (sh2) {
957 sh2->ds = mpctx->demuxer->video;
958 mpctx->sh_video = sh2;
959 reinit_video_chain(mpctx);
962 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
963 return M_PROPERTY_OK;
965 default:
966 return M_PROPERTY_NOT_IMPLEMENTED;
970 static int mp_property_program(m_option_t *prop, int action, void *arg,
971 MPContext *mpctx)
973 demux_program_t prog;
975 switch (action) {
976 case M_PROPERTY_STEP_UP:
977 case M_PROPERTY_SET:
978 if (action == M_PROPERTY_SET && arg)
979 prog.progid = *((int *) arg);
980 else
981 prog.progid = -1;
982 if (demux_control
983 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
984 &prog) == DEMUXER_CTRL_NOTIMPL)
985 return M_PROPERTY_ERROR;
987 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
988 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
989 return M_PROPERTY_OK;
991 default:
992 return M_PROPERTY_NOT_IMPLEMENTED;
996 ///@}
998 /// \defgroup VideoProperties Video properties
999 /// \ingroup Properties
1000 ///@{
1002 /// Fullscreen state (RW)
1003 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1004 MPContext *mpctx)
1007 if (!mpctx->video_out)
1008 return M_PROPERTY_UNAVAILABLE;
1010 switch (action) {
1011 case M_PROPERTY_SET:
1012 if (!arg)
1013 return M_PROPERTY_ERROR;
1014 M_PROPERTY_CLAMP(prop, *(int *) arg);
1015 if (vo_fs == !!*(int *) arg)
1016 return M_PROPERTY_OK;
1017 case M_PROPERTY_STEP_UP:
1018 case M_PROPERTY_STEP_DOWN:
1019 #ifdef CONFIG_GUI
1020 if (use_gui)
1021 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
1022 else
1023 #endif
1024 if (mpctx->video_out->config_ok)
1025 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1026 return M_PROPERTY_OK;
1027 default:
1028 return m_property_flag(prop, action, arg, &vo_fs);
1032 static int mp_property_deinterlace(m_option_t *prop, int action,
1033 void *arg, MPContext *mpctx)
1035 int deinterlace;
1036 vf_instance_t *vf;
1037 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1038 return M_PROPERTY_UNAVAILABLE;
1039 vf = mpctx->sh_video->vfilter;
1040 switch (action) {
1041 case M_PROPERTY_GET:
1042 if (!arg)
1043 return M_PROPERTY_ERROR;
1044 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1045 return M_PROPERTY_OK;
1046 case M_PROPERTY_SET:
1047 if (!arg)
1048 return M_PROPERTY_ERROR;
1049 M_PROPERTY_CLAMP(prop, *(int *) arg);
1050 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1051 return M_PROPERTY_OK;
1052 case M_PROPERTY_STEP_UP:
1053 case M_PROPERTY_STEP_DOWN:
1054 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1055 deinterlace = !deinterlace;
1056 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1057 return M_PROPERTY_OK;
1059 return M_PROPERTY_NOT_IMPLEMENTED;
1062 /// Panscan (RW)
1063 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1064 MPContext *mpctx)
1067 if (!mpctx->video_out
1068 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1069 return M_PROPERTY_UNAVAILABLE;
1071 switch (action) {
1072 case M_PROPERTY_SET:
1073 if (!arg)
1074 return M_PROPERTY_ERROR;
1075 M_PROPERTY_CLAMP(prop, *(float *) arg);
1076 vo_panscan = *(float *) arg;
1077 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1078 return M_PROPERTY_OK;
1079 case M_PROPERTY_STEP_UP:
1080 case M_PROPERTY_STEP_DOWN:
1081 vo_panscan += (arg ? *(float *) arg : 0.1) *
1082 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1083 if (vo_panscan > 1)
1084 vo_panscan = 1;
1085 else if (vo_panscan < 0)
1086 vo_panscan = 0;
1087 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1088 return M_PROPERTY_OK;
1089 default:
1090 return m_property_float_range(prop, action, arg, &vo_panscan);
1094 /// Helper to set vo flags.
1095 /** \ingroup PropertyImplHelper
1097 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1098 int vo_ctrl, int *vo_var, MPContext *mpctx)
1101 if (!mpctx->video_out)
1102 return M_PROPERTY_UNAVAILABLE;
1104 switch (action) {
1105 case M_PROPERTY_SET:
1106 if (!arg)
1107 return M_PROPERTY_ERROR;
1108 M_PROPERTY_CLAMP(prop, *(int *) arg);
1109 if (*vo_var == !!*(int *) arg)
1110 return M_PROPERTY_OK;
1111 case M_PROPERTY_STEP_UP:
1112 case M_PROPERTY_STEP_DOWN:
1113 if (mpctx->video_out->config_ok)
1114 vo_control(mpctx->video_out, vo_ctrl, 0);
1115 return M_PROPERTY_OK;
1116 default:
1117 return m_property_flag(prop, action, arg, vo_var);
1121 /// Window always on top (RW)
1122 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1123 MPContext *mpctx)
1125 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1126 &mpctx->opts.vo_ontop, mpctx);
1129 /// Display in the root window (RW)
1130 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1131 MPContext *mpctx)
1133 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1134 &vo_rootwin, mpctx);
1137 /// Show window borders (RW)
1138 static int mp_property_border(m_option_t *prop, int action, void *arg,
1139 MPContext *mpctx)
1141 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1142 &vo_border, mpctx);
1145 /// Framedropping state (RW)
1146 static int mp_property_framedropping(m_option_t *prop, int action,
1147 void *arg, MPContext *mpctx)
1150 if (!mpctx->sh_video)
1151 return M_PROPERTY_UNAVAILABLE;
1153 switch (action) {
1154 case M_PROPERTY_PRINT:
1155 if (!arg)
1156 return M_PROPERTY_ERROR;
1157 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1158 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1159 MSGTR_Disabled));
1160 return M_PROPERTY_OK;
1161 default:
1162 return m_property_choice(prop, action, arg, &frame_dropping);
1166 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1167 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1168 MPContext *mpctx)
1170 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1171 int r, val;
1173 if (!mpctx->sh_video)
1174 return M_PROPERTY_UNAVAILABLE;
1176 if (gamma[0] == 1000) {
1177 gamma[0] = 0;
1178 get_video_colors(mpctx->sh_video, prop->name, gamma);
1181 switch (action) {
1182 case M_PROPERTY_SET:
1183 if (!arg)
1184 return M_PROPERTY_ERROR;
1185 M_PROPERTY_CLAMP(prop, *(int *) arg);
1186 *gamma = *(int *) arg;
1187 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1188 if (r <= 0)
1189 break;
1190 return r;
1191 case M_PROPERTY_GET:
1192 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1193 if (!arg)
1194 return M_PROPERTY_ERROR;
1195 *(int *)arg = val;
1196 return M_PROPERTY_OK;
1198 break;
1199 case M_PROPERTY_STEP_UP:
1200 case M_PROPERTY_STEP_DOWN:
1201 *gamma += (arg ? *(int *) arg : 1) *
1202 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1203 M_PROPERTY_CLAMP(prop, *gamma);
1204 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1205 if (r <= 0)
1206 break;
1207 return r;
1208 default:
1209 return M_PROPERTY_NOT_IMPLEMENTED;
1212 #ifdef CONFIG_TV
1213 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1214 int l = strlen(prop->name);
1215 char tv_prop[3 + l + 1];
1216 sprintf(tv_prop, "tv_%s", prop->name);
1217 return mp_property_do(tv_prop, action, arg, mpctx);
1219 #endif
1221 return M_PROPERTY_UNAVAILABLE;
1224 /// VSync (RW)
1225 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1226 MPContext *mpctx)
1228 return m_property_flag(prop, action, arg, &vo_vsync);
1231 /// Video codec tag (RO)
1232 static int mp_property_video_format(m_option_t *prop, int action,
1233 void *arg, MPContext *mpctx)
1235 char* meta;
1236 if (!mpctx->sh_video)
1237 return M_PROPERTY_UNAVAILABLE;
1238 switch(action) {
1239 case M_PROPERTY_PRINT:
1240 if (!arg)
1241 return M_PROPERTY_ERROR;
1242 switch(mpctx->sh_video->format) {
1243 case 0x10000001:
1244 meta = strdup ("mpeg1"); break;
1245 case 0x10000002:
1246 meta = strdup ("mpeg2"); break;
1247 case 0x10000004:
1248 meta = strdup ("mpeg4"); break;
1249 case 0x10000005:
1250 meta = strdup ("h264"); break;
1251 default:
1252 if(mpctx->sh_video->format >= 0x20202020) {
1253 meta = malloc(5);
1254 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1255 } else {
1256 meta = malloc(20);
1257 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1260 *(char**)arg = meta;
1261 return M_PROPERTY_OK;
1263 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1266 /// Video codec name (RO)
1267 static int mp_property_video_codec(m_option_t *prop, int action,
1268 void *arg, MPContext *mpctx)
1270 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1271 return M_PROPERTY_UNAVAILABLE;
1272 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1276 /// Video bitrate (RO)
1277 static int mp_property_video_bitrate(m_option_t *prop, int action,
1278 void *arg, MPContext *mpctx)
1280 if (!mpctx->sh_video)
1281 return M_PROPERTY_UNAVAILABLE;
1282 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1285 /// Video display width (RO)
1286 static int mp_property_width(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_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1294 /// Video display height (RO)
1295 static int mp_property_height(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_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1303 /// Video fps (RO)
1304 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1305 MPContext *mpctx)
1307 if (!mpctx->sh_video)
1308 return M_PROPERTY_UNAVAILABLE;
1309 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1312 /// Video aspect (RO)
1313 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1314 MPContext *mpctx)
1316 if (!mpctx->sh_video)
1317 return M_PROPERTY_UNAVAILABLE;
1318 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1321 ///@}
1323 /// \defgroup SubProprties Subtitles properties
1324 /// \ingroup Properties
1325 ///@{
1327 /// Text subtitle position (RW)
1328 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1329 MPContext *mpctx)
1331 if (!mpctx->sh_video)
1332 return M_PROPERTY_UNAVAILABLE;
1334 switch (action) {
1335 case M_PROPERTY_SET:
1336 if (!arg)
1337 return M_PROPERTY_ERROR;
1338 case M_PROPERTY_STEP_UP:
1339 case M_PROPERTY_STEP_DOWN:
1340 vo_osd_changed(OSDTYPE_SUBTITLE);
1341 default:
1342 return m_property_int_range(prop, action, arg, &sub_pos);
1346 /// Selected subtitles (RW)
1347 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1348 MPContext *mpctx)
1350 struct MPOpts *opts = &mpctx->opts;
1351 demux_stream_t *const d_sub = mpctx->d_sub;
1352 const int global_sub_size = mpctx->global_sub_size;
1353 int source = -1, reset_spu = 0;
1354 char *sub_name;
1356 if (global_sub_size <= 0)
1357 return M_PROPERTY_UNAVAILABLE;
1359 switch (action) {
1360 case M_PROPERTY_GET:
1361 if (!arg)
1362 return M_PROPERTY_ERROR;
1363 *(int *) arg = mpctx->global_sub_pos;
1364 return M_PROPERTY_OK;
1365 case M_PROPERTY_PRINT:
1366 if (!arg)
1367 return M_PROPERTY_ERROR;
1368 *(char **) arg = malloc(64);
1369 (*(char **) arg)[63] = 0;
1370 sub_name = 0;
1371 if (subdata)
1372 sub_name = subdata->filename;
1373 #ifdef CONFIG_ASS
1374 if (ass_track && ass_track->name)
1375 sub_name = ass_track->name;
1376 #endif
1377 if (sub_name) {
1378 char *tmp, *tmp2;
1379 tmp = sub_name;
1380 if ((tmp2 = strrchr(tmp, '/')))
1381 tmp = tmp2 + 1;
1383 snprintf(*(char **) arg, 63, "(%d) %s%s",
1384 mpctx->set_of_sub_pos + 1,
1385 strlen(tmp) < 20 ? "" : "...",
1386 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1387 return M_PROPERTY_OK;
1389 #ifdef CONFIG_DVDNAV
1390 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1391 if (vo_spudec && opts->sub_id >= 0) {
1392 unsigned char lang[3];
1393 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1394 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1395 return M_PROPERTY_OK;
1399 #endif
1401 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1402 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1403 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1404 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1405 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1406 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1407 if (!lang) lang = MSGTR_Unknown;
1408 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1409 return M_PROPERTY_OK;
1412 if (vo_vobsub && vobsub_id >= 0) {
1413 const char *language = MSGTR_Unknown;
1414 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1415 snprintf(*(char **) arg, 63, "(%d) %s",
1416 vobsub_id, language ? language : MSGTR_Unknown);
1417 return M_PROPERTY_OK;
1419 #ifdef CONFIG_DVDREAD
1420 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1421 && opts->sub_id >= 0) {
1422 char lang[3];
1423 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1424 lang[0] = code >> 8;
1425 lang[1] = code;
1426 lang[2] = 0;
1427 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1428 return M_PROPERTY_OK;
1430 #endif
1431 if (opts->sub_id >= 0) {
1432 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, MSGTR_Unknown);
1433 return M_PROPERTY_OK;
1435 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1436 return M_PROPERTY_OK;
1438 case M_PROPERTY_SET:
1439 if (!arg)
1440 return M_PROPERTY_ERROR;
1441 if (*(int *) arg < -1)
1442 *(int *) arg = -1;
1443 else if (*(int *) arg >= global_sub_size)
1444 *(int *) arg = global_sub_size - 1;
1445 mpctx->global_sub_pos = *(int *) arg;
1446 break;
1447 case M_PROPERTY_STEP_UP:
1448 mpctx->global_sub_pos += 2;
1449 mpctx->global_sub_pos =
1450 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1451 break;
1452 case M_PROPERTY_STEP_DOWN:
1453 mpctx->global_sub_pos += global_sub_size + 1;
1454 mpctx->global_sub_pos =
1455 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1456 break;
1457 default:
1458 return M_PROPERTY_NOT_IMPLEMENTED;
1461 if (mpctx->global_sub_pos >= 0)
1462 source = sub_source(mpctx);
1464 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1465 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1466 global_sub_size,
1467 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1468 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1469 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1470 mpctx->global_sub_pos, source);
1472 mpctx->set_of_sub_pos = -1;
1473 subdata = NULL;
1475 vobsub_id = -1;
1476 opts->sub_id = -1;
1477 if (d_sub) {
1478 if (d_sub->id > -2)
1479 reset_spu = 1;
1480 d_sub->id = -2;
1482 #ifdef CONFIG_ASS
1483 ass_track = 0;
1484 #endif
1486 if (source == SUB_SOURCE_VOBSUB) {
1487 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1488 } else if (source == SUB_SOURCE_SUBS) {
1489 mpctx->set_of_sub_pos =
1490 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1491 #ifdef CONFIG_ASS
1492 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1493 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1494 else
1495 #endif
1497 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1498 vo_osd_changed(OSDTYPE_SUBTITLE);
1500 } else if (source == SUB_SOURCE_DEMUX) {
1501 opts->sub_id =
1502 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1503 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1504 int i = 0;
1505 // default: assume 1:1 mapping of sid and stream id
1506 d_sub->id = opts->sub_id;
1507 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1508 ds_free_packs(d_sub);
1509 for (i = 0; i < MAX_S_STREAMS; i++) {
1510 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1511 if (sh && sh->sid == opts->sub_id) {
1512 d_sub->id = i;
1513 d_sub->sh = sh;
1514 break;
1517 if (d_sub->sh && d_sub->id >= 0) {
1518 sh_sub_t *sh = d_sub->sh;
1519 if (sh->type == 'v')
1520 init_vo_spudec(mpctx);
1521 #ifdef CONFIG_ASS
1522 else if (ass_enabled)
1523 ass_track = sh->ass_track;
1524 #endif
1525 } else {
1526 d_sub->id = -2;
1527 d_sub->sh = NULL;
1531 #ifdef CONFIG_DVDREAD
1532 if (vo_spudec
1533 && (mpctx->stream->type == STREAMTYPE_DVD
1534 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1535 && opts->sub_id < 0 && reset_spu) {
1536 opts->sub_id = -2;
1537 d_sub->id = opts->sub_id;
1539 #endif
1540 update_subtitles(mpctx->sh_video, d_sub, 1);
1542 return M_PROPERTY_OK;
1545 /// Selected sub source (RW)
1546 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1547 MPContext *mpctx)
1549 int source;
1550 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1551 return M_PROPERTY_UNAVAILABLE;
1553 switch (action) {
1554 case M_PROPERTY_GET:
1555 if (!arg)
1556 return M_PROPERTY_ERROR;
1557 *(int *) arg = sub_source(mpctx);
1558 return M_PROPERTY_OK;
1559 case M_PROPERTY_PRINT:
1560 if (!arg)
1561 return M_PROPERTY_ERROR;
1562 *(char **) arg = malloc(64);
1563 (*(char **) arg)[63] = 0;
1564 switch (sub_source(mpctx))
1566 case SUB_SOURCE_SUBS:
1567 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1568 break;
1569 case SUB_SOURCE_VOBSUB:
1570 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1571 break;
1572 case SUB_SOURCE_DEMUX:
1573 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1574 break;
1575 default:
1576 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1578 return M_PROPERTY_OK;
1579 case M_PROPERTY_SET:
1580 if (!arg)
1581 return M_PROPERTY_ERROR;
1582 M_PROPERTY_CLAMP(prop, *(int*)arg);
1583 if (*(int *) arg < 0)
1584 mpctx->global_sub_pos = -1;
1585 else if (*(int *) arg != sub_source(mpctx)) {
1586 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1587 return M_PROPERTY_UNAVAILABLE;
1588 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1590 break;
1591 case M_PROPERTY_STEP_UP:
1592 case M_PROPERTY_STEP_DOWN: {
1593 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1594 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1595 int step = (step_all > 0) ? 1 : -1;
1596 int cur_source = sub_source(mpctx);
1597 source = cur_source;
1598 while (step_all) {
1599 source += step;
1600 if (source >= SUB_SOURCES)
1601 source = -1;
1602 else if (source < -1)
1603 source = SUB_SOURCES - 1;
1604 if (source == cur_source || source == -1 ||
1605 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1606 step_all -= step;
1608 if (source == cur_source)
1609 return M_PROPERTY_OK;
1610 if (source == -1)
1611 mpctx->global_sub_pos = -1;
1612 else
1613 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1614 break;
1616 default:
1617 return M_PROPERTY_NOT_IMPLEMENTED;
1619 --mpctx->global_sub_pos;
1620 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1623 /// Selected subtitles from specific source (RW)
1624 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1625 MPContext *mpctx)
1627 int source, is_cur_source, offset;
1628 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1629 return M_PROPERTY_UNAVAILABLE;
1631 if (!strcmp(prop->name, "sub_file"))
1632 source = SUB_SOURCE_SUBS;
1633 else if (!strcmp(prop->name, "sub_vob"))
1634 source = SUB_SOURCE_VOBSUB;
1635 else if (!strcmp(prop->name, "sub_demux"))
1636 source = SUB_SOURCE_DEMUX;
1637 else
1638 return M_PROPERTY_ERROR;
1640 offset = mpctx->global_sub_indices[source];
1641 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1642 return M_PROPERTY_UNAVAILABLE;
1644 is_cur_source = sub_source(mpctx) == source;
1645 switch (action) {
1646 case M_PROPERTY_GET:
1647 if (!arg)
1648 return M_PROPERTY_ERROR;
1649 if (is_cur_source) {
1650 *(int *) arg = mpctx->global_sub_pos - offset;
1651 if (source == SUB_SOURCE_VOBSUB)
1652 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1654 else
1655 *(int *) arg = -1;
1656 return M_PROPERTY_OK;
1657 case M_PROPERTY_PRINT:
1658 if (!arg)
1659 return M_PROPERTY_ERROR;
1660 if (is_cur_source)
1661 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1662 *(char **) arg = malloc(64);
1663 (*(char **) arg)[63] = 0;
1664 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1665 return M_PROPERTY_OK;
1666 case M_PROPERTY_SET:
1667 if (!arg)
1668 return M_PROPERTY_ERROR;
1669 if (*(int *) arg >= 0) {
1670 int index = *(int *)arg;
1671 if (source == SUB_SOURCE_VOBSUB)
1672 index = vobsub_get_index_by_id(vo_vobsub, index);
1673 mpctx->global_sub_pos = offset + index;
1674 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1675 || sub_source(mpctx) != source) {
1676 mpctx->global_sub_pos = -1;
1677 *(int *) arg = -1;
1680 else
1681 mpctx->global_sub_pos = -1;
1682 break;
1683 case M_PROPERTY_STEP_UP:
1684 case M_PROPERTY_STEP_DOWN: {
1685 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1686 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1687 int step = (step_all > 0) ? 1 : -1;
1688 int max_sub_pos_for_source = -1;
1689 if (!is_cur_source)
1690 mpctx->global_sub_pos = -1;
1691 while (step_all) {
1692 if (mpctx->global_sub_pos == -1) {
1693 if (step > 0)
1694 mpctx->global_sub_pos = offset;
1695 else if (max_sub_pos_for_source == -1) {
1696 // Find max pos for specific source
1697 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1698 while (mpctx->global_sub_pos >= 0
1699 && sub_source(mpctx) != source)
1700 --mpctx->global_sub_pos;
1702 else
1703 mpctx->global_sub_pos = max_sub_pos_for_source;
1705 else {
1706 mpctx->global_sub_pos += step;
1707 if (mpctx->global_sub_pos < offset ||
1708 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1709 sub_source(mpctx) != source)
1710 mpctx->global_sub_pos = -1;
1712 step_all -= step;
1714 break;
1716 default:
1717 return M_PROPERTY_NOT_IMPLEMENTED;
1719 --mpctx->global_sub_pos;
1720 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1723 /// Subtitle delay (RW)
1724 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1725 MPContext *mpctx)
1727 if (!mpctx->sh_video)
1728 return M_PROPERTY_UNAVAILABLE;
1729 return m_property_delay(prop, action, arg, &sub_delay);
1732 /// Alignment of text subtitles (RW)
1733 static int mp_property_sub_alignment(m_option_t *prop, int action,
1734 void *arg, MPContext *mpctx)
1736 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1738 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1739 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1740 return M_PROPERTY_UNAVAILABLE;
1742 switch (action) {
1743 case M_PROPERTY_PRINT:
1744 if (!arg)
1745 return M_PROPERTY_ERROR;
1746 M_PROPERTY_CLAMP(prop, sub_alignment);
1747 *(char **) arg = strdup(name[sub_alignment]);
1748 return M_PROPERTY_OK;
1749 case M_PROPERTY_SET:
1750 if (!arg)
1751 return M_PROPERTY_ERROR;
1752 case M_PROPERTY_STEP_UP:
1753 case M_PROPERTY_STEP_DOWN:
1754 vo_osd_changed(OSDTYPE_SUBTITLE);
1755 default:
1756 return m_property_choice(prop, action, arg, &sub_alignment);
1760 /// Subtitle visibility (RW)
1761 static int mp_property_sub_visibility(m_option_t *prop, int action,
1762 void *arg, MPContext *mpctx)
1764 if (!mpctx->sh_video)
1765 return M_PROPERTY_UNAVAILABLE;
1767 switch (action) {
1768 case M_PROPERTY_SET:
1769 if (!arg)
1770 return M_PROPERTY_ERROR;
1771 case M_PROPERTY_STEP_UP:
1772 case M_PROPERTY_STEP_DOWN:
1773 vo_osd_changed(OSDTYPE_SUBTITLE);
1774 if (vo_spudec)
1775 vo_osd_changed(OSDTYPE_SPU);
1776 default:
1777 return m_property_flag(prop, action, arg, &sub_visibility);
1781 #ifdef CONFIG_ASS
1782 /// Use margins for libass subtitles (RW)
1783 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1784 void *arg, MPContext *mpctx)
1786 if (!mpctx->sh_video)
1787 return M_PROPERTY_UNAVAILABLE;
1789 switch (action) {
1790 case M_PROPERTY_SET:
1791 if (!arg)
1792 return M_PROPERTY_ERROR;
1793 case M_PROPERTY_STEP_UP:
1794 case M_PROPERTY_STEP_DOWN:
1795 ass_force_reload = 1;
1796 default:
1797 return m_property_flag(prop, action, arg, &ass_use_margins);
1800 #endif
1802 /// Show only forced subtitles (RW)
1803 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1804 void *arg, MPContext *mpctx)
1806 if (!vo_spudec)
1807 return M_PROPERTY_UNAVAILABLE;
1809 switch (action) {
1810 case M_PROPERTY_SET:
1811 if (!arg)
1812 return M_PROPERTY_ERROR;
1813 case M_PROPERTY_STEP_UP:
1814 case M_PROPERTY_STEP_DOWN:
1815 m_property_flag(prop, action, arg, &forced_subs_only);
1816 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1817 return M_PROPERTY_OK;
1818 default:
1819 return m_property_flag(prop, action, arg, &forced_subs_only);
1824 #ifdef CONFIG_FREETYPE
1825 /// Subtitle scale (RW)
1826 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1827 MPContext *mpctx)
1830 switch (action) {
1831 case M_PROPERTY_SET:
1832 if (!arg)
1833 return M_PROPERTY_ERROR;
1834 M_PROPERTY_CLAMP(prop, *(float *) arg);
1835 #ifdef CONFIG_ASS
1836 if (ass_enabled) {
1837 ass_font_scale = *(float *) arg;
1838 ass_force_reload = 1;
1840 #endif
1841 text_font_scale_factor = *(float *) arg;
1842 force_load_font = 1;
1843 return M_PROPERTY_OK;
1844 case M_PROPERTY_STEP_UP:
1845 case M_PROPERTY_STEP_DOWN:
1846 #ifdef CONFIG_ASS
1847 if (ass_enabled) {
1848 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1849 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1850 M_PROPERTY_CLAMP(prop, ass_font_scale);
1851 ass_force_reload = 1;
1853 #endif
1854 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1855 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1856 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1857 force_load_font = 1;
1858 return M_PROPERTY_OK;
1859 default:
1860 #ifdef CONFIG_ASS
1861 if (ass_enabled)
1862 return m_property_float_ro(prop, action, arg, ass_font_scale);
1863 else
1864 #endif
1865 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1868 #endif
1870 ///@}
1872 /// \defgroup TVProperties TV properties
1873 /// \ingroup Properties
1874 ///@{
1876 #ifdef CONFIG_TV
1878 /// TV color settings (RW)
1879 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1880 MPContext *mpctx)
1882 int r, val;
1883 tvi_handle_t *tvh = mpctx->demuxer->priv;
1884 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1885 return M_PROPERTY_UNAVAILABLE;
1887 switch (action) {
1888 case M_PROPERTY_SET:
1889 if (!arg)
1890 return M_PROPERTY_ERROR;
1891 M_PROPERTY_CLAMP(prop, *(int *) arg);
1892 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1893 case M_PROPERTY_GET:
1894 return tv_get_color_options(tvh, (int) prop->priv, arg);
1895 case M_PROPERTY_STEP_UP:
1896 case M_PROPERTY_STEP_DOWN:
1897 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1898 if (!r)
1899 return M_PROPERTY_ERROR;
1900 val += (arg ? *(int *) arg : 1) *
1901 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1902 M_PROPERTY_CLAMP(prop, val);
1903 return tv_set_color_options(tvh, (int) prop->priv, val);
1905 return M_PROPERTY_ERROR;
1907 return M_PROPERTY_NOT_IMPLEMENTED;
1910 #endif
1912 #ifdef CONFIG_TV_TELETEXT
1913 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1914 MPContext *mpctx)
1916 int val,result;
1917 int base_ioctl=(int)prop->priv;
1919 for teletext's GET,SET,STEP ioctls this is not 0
1920 SET is GET+1
1921 STEP is GET+2
1923 tvi_handle_t *tvh = mpctx->demuxer->priv;
1924 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1925 return M_PROPERTY_UNAVAILABLE;
1926 if(!base_ioctl)
1927 return M_PROPERTY_ERROR;
1929 switch (action) {
1930 case M_PROPERTY_GET:
1931 if (!arg)
1932 return M_PROPERTY_ERROR;
1933 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1934 break;
1935 case M_PROPERTY_SET:
1936 if (!arg)
1937 return M_PROPERTY_ERROR;
1938 M_PROPERTY_CLAMP(prop, *(int *) arg);
1939 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1940 break;
1941 case M_PROPERTY_STEP_UP:
1942 case M_PROPERTY_STEP_DOWN:
1943 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1944 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1945 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1946 break;
1947 default:
1948 return M_PROPERTY_NOT_IMPLEMENTED;
1951 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1954 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
1955 MPContext *mpctx)
1957 tvi_handle_t *tvh = mpctx->demuxer->priv;
1958 int result;
1959 int val;
1961 //with tvh==NULL will fail too
1962 result=mp_property_teletext_common(prop,action,arg,mpctx);
1963 if(result!=M_PROPERTY_OK)
1964 return result;
1966 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1967 mp_input_set_section(mpctx->input, "teletext");
1968 else
1969 mp_input_set_section(mpctx->input, "tv");
1970 return M_PROPERTY_OK;
1973 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
1974 MPContext *mpctx)
1976 tvi_handle_t *tvh = mpctx->demuxer->priv;
1977 int result;
1978 int val;
1979 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1980 return M_PROPERTY_UNAVAILABLE;
1981 switch(action){
1982 case M_PROPERTY_STEP_UP:
1983 case M_PROPERTY_STEP_DOWN:
1984 //This should be handled separately
1985 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1986 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1987 break;
1988 default:
1989 result=mp_property_teletext_common(prop,action,arg,mpctx);
1991 return result;
1995 #endif /* CONFIG_TV_TELETEXT */
1997 ///@}
1999 /// All properties available in MPlayer.
2000 /** \ingroup Properties
2002 static const m_option_t mp_properties[] = {
2003 // General
2004 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2005 M_OPT_RANGE, 0, 3, NULL },
2006 { "loop", mp_property_loop, CONF_TYPE_INT,
2007 M_OPT_MIN, -1, 0, NULL },
2008 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2009 M_OPT_RANGE, 0.01, 100.0, NULL },
2010 { "filename", mp_property_filename, CONF_TYPE_STRING,
2011 0, 0, 0, NULL },
2012 { "path", mp_property_path, CONF_TYPE_STRING,
2013 0, 0, 0, NULL },
2014 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2015 0, 0, 0, NULL },
2016 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2017 M_OPT_MIN, 0, 0, NULL },
2018 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2019 M_OPT_MIN, 0, 0, NULL },
2020 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2021 M_OPT_MIN, 0, 0, NULL },
2022 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2023 M_OPT_MIN, 0, 0, NULL },
2024 { "length", mp_property_length, CONF_TYPE_TIME,
2025 M_OPT_MIN, 0, 0, NULL },
2026 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2027 M_OPT_RANGE, 0, 100, NULL },
2028 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2029 M_OPT_MIN, 0, 0, NULL },
2030 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2031 M_OPT_MIN, 1, 0, NULL },
2032 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2033 0, 0, 0, NULL },
2034 { "angle", mp_property_angle, CONF_TYPE_INT,
2035 CONF_RANGE, -2, 10, NULL },
2036 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2037 0, 0, 0, NULL },
2038 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2039 M_OPT_RANGE, 0, 1, NULL },
2041 // Audio
2042 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2043 M_OPT_RANGE, 0, 100, NULL },
2044 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2045 M_OPT_RANGE, 0, 1, NULL },
2046 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2047 M_OPT_RANGE, -100, 100, NULL },
2048 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2049 0, 0, 0, NULL },
2050 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2051 0, 0, 0, NULL },
2052 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2053 0, 0, 0, NULL },
2054 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2055 0, 0, 0, NULL },
2056 { "channels", mp_property_channels, CONF_TYPE_INT,
2057 0, 0, 0, NULL },
2058 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2059 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
2060 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2061 M_OPT_RANGE, -1, 1, NULL },
2063 // Video
2064 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2065 M_OPT_RANGE, 0, 1, NULL },
2066 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2067 M_OPT_RANGE, 0, 1, NULL },
2068 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2069 M_OPT_RANGE, 0, 1, NULL },
2070 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2071 M_OPT_RANGE, 0, 1, NULL },
2072 { "border", mp_property_border, CONF_TYPE_FLAG,
2073 M_OPT_RANGE, 0, 1, NULL },
2074 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2075 M_OPT_RANGE, 0, 2, NULL },
2076 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2077 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2078 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2079 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2080 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2081 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2082 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2083 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2084 { "hue", mp_property_gamma, CONF_TYPE_INT,
2085 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2086 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2087 M_OPT_RANGE, 0, 1, NULL },
2088 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2089 M_OPT_RANGE, 0, 1, NULL },
2090 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2091 0, 0, 0, NULL },
2092 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2093 0, 0, 0, NULL },
2094 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2095 0, 0, 0, NULL },
2096 { "width", mp_property_width, CONF_TYPE_INT,
2097 0, 0, 0, NULL },
2098 { "height", mp_property_height, CONF_TYPE_INT,
2099 0, 0, 0, NULL },
2100 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2101 0, 0, 0, NULL },
2102 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2103 0, 0, 0, NULL },
2104 { "switch_video", mp_property_video, CONF_TYPE_INT,
2105 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
2106 { "switch_program", mp_property_program, CONF_TYPE_INT,
2107 CONF_RANGE, -1, 65535, NULL },
2109 // Subs
2110 { "sub", mp_property_sub, CONF_TYPE_INT,
2111 M_OPT_MIN, -1, 0, NULL },
2112 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2113 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2114 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2115 M_OPT_MIN, -1, 0, NULL },
2116 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2117 M_OPT_MIN, -1, 0, NULL },
2118 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2119 M_OPT_MIN, -1, 0, NULL },
2120 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2121 0, 0, 0, NULL },
2122 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2123 M_OPT_RANGE, 0, 100, NULL },
2124 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2125 M_OPT_RANGE, 0, 2, NULL },
2126 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2127 M_OPT_RANGE, 0, 1, NULL },
2128 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2129 M_OPT_RANGE, 0, 1, NULL },
2130 #ifdef CONFIG_FREETYPE
2131 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2132 M_OPT_RANGE, 0, 100, NULL },
2133 #endif
2134 #ifdef CONFIG_ASS
2135 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2136 M_OPT_RANGE, 0, 1, NULL },
2137 #endif
2139 #ifdef CONFIG_TV
2140 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2141 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2142 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2143 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2144 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2145 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2146 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2147 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2148 #endif
2150 #ifdef CONFIG_TV_TELETEXT
2151 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2152 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2153 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2154 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2155 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2156 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2157 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2158 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2159 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2160 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2161 #endif
2163 { NULL, NULL, NULL, 0, 0, 0, NULL }
2167 int mp_property_do(const char *name, int action, void *val, void *ctx)
2169 return m_property_do(mp_properties, name, action, val, ctx);
2172 char* mp_property_print(const char *name, void* ctx)
2174 char* ret = NULL;
2175 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2176 return NULL;
2177 return ret;
2180 char *property_expand_string(MPContext *mpctx, char *str)
2182 return m_properties_expand_string(mp_properties, str, mpctx);
2185 void property_print_help(void)
2187 m_properties_print_help_list(mp_properties);
2191 ///@}
2192 // Properties group
2196 * \defgroup Command2Property Command to property bridge
2198 * It is used to handle most commands that just set a property
2199 * and optionally display something on the OSD.
2200 * Two kinds of commands are handled: adjust or toggle.
2202 * Adjust commands take 1 or 2 parameters: <value> <abs>
2203 * If <abs> is non-zero the property is set to the given value
2204 * otherwise it is adjusted.
2206 * Toggle commands take 0 or 1 parameters. With no parameter
2207 * or a value less than the property minimum it just steps the
2208 * property to its next value. Otherwise it sets it to the given
2209 * value.
2214 /// List of the commands that can be handled by setting a property.
2215 static struct {
2216 /// property name
2217 const char *name;
2218 /// cmd id
2219 int cmd;
2220 /// set/adjust or toggle command
2221 int toggle;
2222 /// progressbar type
2223 int osd_progbar;
2224 /// osd msg id if it must be shared
2225 int osd_id;
2226 /// osd msg template
2227 const char *osd_msg;
2228 } set_prop_cmd[] = {
2229 // general
2230 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2231 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2232 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2233 { "pause", MP_CMD_PAUSE, 0, 0, -1, NULL },
2234 // audio
2235 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2236 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2237 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2238 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2239 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2240 // video
2241 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2242 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2243 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2244 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2245 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2246 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2247 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2248 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2249 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2250 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2251 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2252 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2253 // subs
2254 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2255 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2256 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2257 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2258 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2259 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2260 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2261 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2262 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2263 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2264 #ifdef CONFIG_FREETYPE
2265 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2266 #endif
2267 #ifdef CONFIG_ASS
2268 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2269 #endif
2270 #ifdef CONFIG_TV
2271 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2272 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2273 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2274 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2275 #endif
2276 { NULL, 0, 0, 0, -1, NULL }
2280 /// Handle commands that set a property.
2281 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2283 int i, r;
2284 m_option_t* prop;
2285 const char *pname;
2287 // look for the command
2288 for (i = 0; set_prop_cmd[i].name; i++)
2289 if (set_prop_cmd[i].cmd == cmd->id)
2290 break;
2291 if (!(pname = set_prop_cmd[i].name))
2292 return 0;
2294 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2295 return 0;
2297 // toggle command
2298 if (set_prop_cmd[i].toggle) {
2299 // set to value
2300 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2301 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2302 else
2303 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2304 } else if (cmd->args[1].v.i) //set
2305 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2306 else // adjust
2307 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2309 if (r <= 0)
2310 return 1;
2312 if (set_prop_cmd[i].osd_progbar) {
2313 if (prop->type == CONF_TYPE_INT) {
2314 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2315 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2316 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2317 } else if (prop->type == CONF_TYPE_FLOAT) {
2318 float f;
2319 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2320 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2321 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2322 } else
2323 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2324 "Property use an unsupported type.\n");
2325 return 1;
2328 if (set_prop_cmd[i].osd_msg) {
2329 char *val = mp_property_print(pname, mpctx);
2330 if (val) {
2331 set_osd_msg(set_prop_cmd[i].osd_id >=
2332 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2333 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2334 free(val);
2337 return 1;
2340 #ifdef CONFIG_DVDNAV
2341 static const struct {
2342 const char *name;
2343 const mp_command_type cmd;
2344 } mp_dvdnav_bindings[] = {
2345 { "up", MP_CMD_DVDNAV_UP },
2346 { "down", MP_CMD_DVDNAV_DOWN },
2347 { "left", MP_CMD_DVDNAV_LEFT },
2348 { "right", MP_CMD_DVDNAV_RIGHT },
2349 { "menu", MP_CMD_DVDNAV_MENU },
2350 { "select", MP_CMD_DVDNAV_SELECT },
2351 { "prev", MP_CMD_DVDNAV_PREVMENU },
2352 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2355 * keep old dvdnav sub-command options for a while in order not to
2356 * break slave-mode API too suddenly.
2358 { "1", MP_CMD_DVDNAV_UP },
2359 { "2", MP_CMD_DVDNAV_DOWN },
2360 { "3", MP_CMD_DVDNAV_LEFT },
2361 { "4", MP_CMD_DVDNAV_RIGHT },
2362 { "5", MP_CMD_DVDNAV_MENU },
2363 { "6", MP_CMD_DVDNAV_SELECT },
2364 { "7", MP_CMD_DVDNAV_PREVMENU },
2365 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2366 { NULL, 0 }
2368 #endif
2370 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2372 struct MPOpts *opts = &mpctx->opts;
2373 sh_audio_t * const sh_audio = mpctx->sh_audio;
2374 sh_video_t * const sh_video = mpctx->sh_video;
2375 if (!set_property_command(mpctx, cmd))
2376 switch (cmd->id) {
2377 case MP_CMD_SEEK:{
2378 float v;
2379 int abs;
2380 if (sh_video)
2381 mpctx->osd_show_percentage = sh_video->fps;
2382 v = cmd->args[0].v.f;
2383 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2384 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2385 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2386 if (sh_video)
2387 mpctx->osd_function =
2388 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2389 mpctx->rel_seek_secs = v;
2390 } else if (abs) { /* Absolute seek by percentage */
2391 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2392 if (sh_video)
2393 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2394 mpctx->rel_seek_secs = v / 100.0;
2395 } else {
2396 mpctx->rel_seek_secs += v;
2397 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2400 break;
2402 case MP_CMD_SET_PROPERTY:{
2403 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2404 cmd->args[1].v.s, mpctx);
2405 if (r == M_PROPERTY_UNKNOWN)
2406 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2407 "Unknown property: '%s'\n", cmd->args[0].v.s);
2408 else if (r <= 0)
2409 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2410 "Failed to set property '%s' to '%s'.\n",
2411 cmd->args[0].v.s, cmd->args[1].v.s);
2413 break;
2415 case MP_CMD_STEP_PROPERTY:{
2416 void* arg = NULL;
2417 int r,i;
2418 double d;
2419 off_t o;
2420 if (cmd->args[1].v.f) {
2421 m_option_t* prop;
2422 if((r = mp_property_do(cmd->args[0].v.s,
2423 M_PROPERTY_GET_TYPE,
2424 &prop, mpctx)) <= 0)
2425 goto step_prop_err;
2426 if(prop->type == CONF_TYPE_INT ||
2427 prop->type == CONF_TYPE_FLAG)
2428 i = cmd->args[1].v.f, arg = &i;
2429 else if(prop->type == CONF_TYPE_FLOAT)
2430 arg = &cmd->args[1].v.f;
2431 else if(prop->type == CONF_TYPE_DOUBLE ||
2432 prop->type == CONF_TYPE_TIME)
2433 d = cmd->args[1].v.f, arg = &d;
2434 else if(prop->type == CONF_TYPE_POSITION)
2435 o = cmd->args[1].v.f, arg = &o;
2436 else
2437 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2438 "Ignoring step size stepping property '%s'.\n",
2439 cmd->args[0].v.s);
2441 r = mp_property_do(cmd->args[0].v.s,
2442 cmd->args[2].v.i < 0 ?
2443 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2444 arg, mpctx);
2445 step_prop_err:
2446 if (r == M_PROPERTY_UNKNOWN)
2447 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2448 "Unknown property: '%s'\n", cmd->args[0].v.s);
2449 else if (r <= 0)
2450 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2451 "Failed to increment property '%s' by %f.\n",
2452 cmd->args[0].v.s, cmd->args[1].v.f);
2454 break;
2456 case MP_CMD_GET_PROPERTY:{
2457 char *tmp;
2458 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2459 &tmp, mpctx) <= 0) {
2460 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2461 "Failed to get value of property '%s'.\n",
2462 cmd->args[0].v.s);
2463 break;
2465 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2466 cmd->args[0].v.s, tmp);
2467 free(tmp);
2469 break;
2471 case MP_CMD_EDL_MARK:
2472 if (edl_fd) {
2473 float v = sh_video ? sh_video->pts :
2474 playing_audio_pts(mpctx);
2475 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2476 mpctx->begin_skip = v;
2477 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2478 } else {
2479 if (mpctx->begin_skip > v)
2480 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2481 else {
2482 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2483 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2485 mpctx->begin_skip = MP_NOPTS_VALUE;
2488 break;
2490 case MP_CMD_SWITCH_RATIO:
2491 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2492 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2493 else
2494 opts->movie_aspect = cmd->args[0].v.f;
2495 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2496 break;
2498 case MP_CMD_SPEED_INCR:{
2499 float v = cmd->args[0].v.f;
2500 opts->playback_speed += v;
2501 build_afilter_chain(mpctx, sh_audio, &ao_data);
2502 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2503 opts->playback_speed);
2504 } break;
2506 case MP_CMD_SPEED_MULT:{
2507 float v = cmd->args[0].v.f;
2508 opts->playback_speed *= v;
2509 build_afilter_chain(mpctx, sh_audio, &ao_data);
2510 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2511 opts->playback_speed);
2512 } break;
2514 case MP_CMD_SPEED_SET:{
2515 float v = cmd->args[0].v.f;
2516 opts->playback_speed = v;
2517 build_afilter_chain(mpctx, sh_audio, &ao_data);
2518 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2519 opts->playback_speed);
2520 } break;
2522 case MP_CMD_FRAME_STEP:
2523 mpctx->step_frames++;
2524 unpause_player(mpctx);
2525 break;
2527 case MP_CMD_FILE_FILTER:
2528 file_filter = cmd->args[0].v.i;
2529 break;
2531 case MP_CMD_QUIT:
2532 exit_player_with_rc(mpctx, EXIT_QUIT,
2533 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2535 case MP_CMD_PLAY_TREE_STEP:{
2536 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2537 int force = cmd->args[1].v.i;
2539 #ifdef CONFIG_GUI
2540 if (use_gui) {
2541 int i = 0;
2542 if (n > 0)
2543 for (i = 0; i < n; i++)
2544 mplNext();
2545 else
2546 for (i = 0; i < -1 * n; i++)
2547 mplPrev();
2548 } else
2549 #endif
2551 if (!force && mpctx->playtree_iter) {
2552 play_tree_iter_t *i =
2553 play_tree_iter_new_copy(mpctx->playtree_iter);
2554 if (play_tree_iter_step(i, n, 0) ==
2555 PLAY_TREE_ITER_ENTRY)
2556 mpctx->stop_play =
2557 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2558 play_tree_iter_free(i);
2559 } else
2560 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2561 if (mpctx->stop_play)
2562 mpctx->play_tree_step = n;
2565 break;
2567 case MP_CMD_PLAY_TREE_UP_STEP:{
2568 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2569 int force = cmd->args[1].v.i;
2571 if (!force && mpctx->playtree_iter) {
2572 play_tree_iter_t *i =
2573 play_tree_iter_new_copy(mpctx->playtree_iter);
2574 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2575 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2576 play_tree_iter_free(i);
2577 } else
2578 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2580 break;
2582 case MP_CMD_PLAY_ALT_SRC_STEP:
2583 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2584 int v = cmd->args[0].v.i;
2585 if (v > 0
2586 && mpctx->playtree_iter->file <
2587 mpctx->playtree_iter->num_files)
2588 mpctx->stop_play = PT_NEXT_SRC;
2589 else if (v < 0 && mpctx->playtree_iter->file > 1)
2590 mpctx->stop_play = PT_PREV_SRC;
2592 break;
2594 case MP_CMD_SUB_STEP:
2595 if (sh_video) {
2596 int movement = cmd->args[0].v.i;
2597 step_sub(subdata, sh_video->pts, movement);
2598 #ifdef CONFIG_ASS
2599 if (ass_track)
2600 sub_delay +=
2601 ass_step_sub(ass_track,
2602 (sh_video->pts +
2603 sub_delay) * 1000 + .5, movement) / 1000.;
2604 #endif
2605 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2606 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2608 break;
2610 case MP_CMD_SUB_LOG:
2611 log_sub(mpctx);
2612 break;
2614 case MP_CMD_OSD:{
2615 int v = cmd->args[0].v.i;
2616 int max = (term_osd
2617 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2618 if (osd_level > max)
2619 osd_level = max;
2620 if (v < 0)
2621 osd_level = (osd_level + 1) % (max + 1);
2622 else
2623 osd_level = v > max ? max : v;
2624 /* Show OSD state when disabled, but not when an explicit
2625 argument is given to the OSD command, i.e. in slave mode. */
2626 if (v == -1 && osd_level <= 1)
2627 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2628 MSGTR_OSDosd,
2629 osd_level ? MSGTR_OSDenabled :
2630 MSGTR_OSDdisabled);
2631 else
2632 rm_osd_msg(OSD_MSG_OSD_STATUS);
2634 break;
2636 case MP_CMD_OSD_SHOW_TEXT:
2637 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2638 (cmd->args[1].v.i <
2639 0 ? osd_duration : cmd->args[1].v.i),
2640 "%-.63s", cmd->args[0].v.s);
2641 break;
2643 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2644 char *txt = m_properties_expand_string(mp_properties,
2645 cmd->args[0].v.s,
2646 mpctx);
2647 /* if no argument supplied take default osd_duration, else <arg> ms. */
2648 if (txt) {
2649 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2650 (cmd->args[1].v.i <
2651 0 ? osd_duration : cmd->args[1].v.i),
2652 "%-.63s", txt);
2653 free(txt);
2656 break;
2658 case MP_CMD_LOADFILE:{
2659 play_tree_t *e = play_tree_new();
2660 play_tree_add_file(e, cmd->args[0].v.s);
2662 if (cmd->args[1].v.i) // append
2663 play_tree_append_entry(mpctx->playtree->child, e);
2664 else {
2665 // Go back to the starting point.
2666 while (play_tree_iter_up_step
2667 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2668 /* NOP */ ;
2669 play_tree_free_list(mpctx->playtree->child, 1);
2670 play_tree_set_child(mpctx->playtree, e);
2671 pt_iter_goto_head(mpctx->playtree_iter);
2672 mpctx->stop_play = PT_NEXT_SRC;
2675 break;
2677 case MP_CMD_LOADLIST:{
2678 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2679 if (!e)
2680 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2681 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2682 else {
2683 if (cmd->args[1].v.i) // append
2684 play_tree_append_entry(mpctx->playtree->child, e);
2685 else {
2686 // Go back to the starting point.
2687 while (play_tree_iter_up_step
2688 (mpctx->playtree_iter, 0, 1)
2689 != PLAY_TREE_ITER_END)
2690 /* NOP */ ;
2691 play_tree_free_list(mpctx->playtree->child, 1);
2692 play_tree_set_child(mpctx->playtree, e);
2693 pt_iter_goto_head(mpctx->playtree_iter);
2694 mpctx->stop_play = PT_NEXT_SRC;
2698 break;
2700 case MP_CMD_STOP:
2701 // Go back to the starting point.
2702 while (play_tree_iter_up_step
2703 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2704 /* NOP */ ;
2705 mpctx->stop_play = PT_STOP;
2706 break;
2708 #ifdef CONFIG_RADIO
2709 case MP_CMD_RADIO_STEP_CHANNEL:
2710 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2711 int v = cmd->args[0].v.i;
2712 if (v > 0)
2713 radio_step_channel(mpctx->demuxer->stream,
2714 RADIO_CHANNEL_HIGHER);
2715 else
2716 radio_step_channel(mpctx->demuxer->stream,
2717 RADIO_CHANNEL_LOWER);
2718 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2719 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2720 MSGTR_OSDChannel,
2721 radio_get_channel_name(mpctx->demuxer->stream));
2724 break;
2726 case MP_CMD_RADIO_SET_CHANNEL:
2727 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2728 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2729 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2730 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2731 MSGTR_OSDChannel,
2732 radio_get_channel_name(mpctx->demuxer->stream));
2735 break;
2737 case MP_CMD_RADIO_SET_FREQ:
2738 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2739 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2740 break;
2742 case MP_CMD_RADIO_STEP_FREQ:
2743 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2744 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2745 break;
2746 #endif
2748 #ifdef CONFIG_TV
2749 case MP_CMD_TV_START_SCAN:
2750 if (mpctx->file_format == DEMUXER_TYPE_TV)
2751 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2752 break;
2753 case MP_CMD_TV_SET_FREQ:
2754 if (mpctx->file_format == DEMUXER_TYPE_TV)
2755 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2756 cmd->args[0].v.f * 16.0);
2757 #ifdef CONFIG_PVR
2758 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2759 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2760 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2761 pvr_get_current_channelname (mpctx->stream),
2762 pvr_get_current_stationname (mpctx->stream));
2764 #endif /* CONFIG_PVR */
2765 break;
2767 case MP_CMD_TV_STEP_FREQ:
2768 if (mpctx->file_format == DEMUXER_TYPE_TV)
2769 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2770 cmd->args[0].v.f * 16.0);
2771 #ifdef CONFIG_PVR
2772 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2773 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2774 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2775 pvr_get_current_channelname (mpctx->stream),
2776 pvr_get_current_frequency (mpctx->stream));
2778 #endif /* CONFIG_PVR */
2779 break;
2781 case MP_CMD_TV_SET_NORM:
2782 if (mpctx->file_format == DEMUXER_TYPE_TV)
2783 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2784 cmd->args[0].v.s);
2785 break;
2787 case MP_CMD_TV_STEP_CHANNEL:{
2788 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2789 int v = cmd->args[0].v.i;
2790 if (v > 0) {
2791 tv_step_channel((tvi_handle_t *) (mpctx->
2792 demuxer->priv),
2793 TV_CHANNEL_HIGHER);
2794 } else {
2795 tv_step_channel((tvi_handle_t *) (mpctx->
2796 demuxer->priv),
2797 TV_CHANNEL_LOWER);
2799 if (tv_channel_list) {
2800 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2801 MSGTR_OSDChannel, tv_channel_current->name);
2802 //vo_osd_changed(OSDTYPE_SUBTITLE);
2805 #ifdef CONFIG_PVR
2806 else if (mpctx->stream &&
2807 mpctx->stream->type == STREAMTYPE_PVR) {
2808 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2809 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2810 pvr_get_current_channelname (mpctx->stream),
2811 pvr_get_current_stationname (mpctx->stream));
2813 #endif /* CONFIG_PVR */
2815 #ifdef CONFIG_DVBIN
2816 if (mpctx->stream->type == STREAMTYPE_DVB) {
2817 int dir;
2818 int v = cmd->args[0].v.i;
2820 mpctx->last_dvb_step = v;
2821 if (v > 0)
2822 dir = DVB_CHANNEL_HIGHER;
2823 else
2824 dir = DVB_CHANNEL_LOWER;
2827 if (dvb_step_channel(mpctx->stream, dir)) {
2828 mpctx->stop_play = PT_NEXT_ENTRY;
2829 mpctx->dvbin_reopen = 1;
2832 #endif /* CONFIG_DVBIN */
2833 break;
2835 case MP_CMD_TV_SET_CHANNEL:
2836 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2837 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2838 cmd->args[0].v.s);
2839 if (tv_channel_list) {
2840 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2841 MSGTR_OSDChannel, tv_channel_current->name);
2842 //vo_osd_changed(OSDTYPE_SUBTITLE);
2845 #ifdef CONFIG_PVR
2846 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2847 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2848 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2849 pvr_get_current_channelname (mpctx->stream),
2850 pvr_get_current_stationname (mpctx->stream));
2852 #endif /* CONFIG_PVR */
2853 break;
2855 #ifdef CONFIG_DVBIN
2856 case MP_CMD_DVB_SET_CHANNEL:
2857 if (mpctx->stream->type == STREAMTYPE_DVB) {
2858 mpctx->last_dvb_step = 1;
2860 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
2861 cmd->args[0].v.i)) {
2862 mpctx->stop_play = PT_NEXT_ENTRY;
2863 mpctx->dvbin_reopen = 1;
2866 break;
2867 #endif /* CONFIG_DVBIN */
2869 case MP_CMD_TV_LAST_CHANNEL:
2870 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2871 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2872 if (tv_channel_list) {
2873 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2874 MSGTR_OSDChannel, tv_channel_current->name);
2875 //vo_osd_changed(OSDTYPE_SUBTITLE);
2878 #ifdef CONFIG_PVR
2879 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2880 pvr_set_lastchannel (mpctx->stream);
2881 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2882 pvr_get_current_channelname (mpctx->stream),
2883 pvr_get_current_stationname (mpctx->stream));
2885 #endif /* CONFIG_PVR */
2886 break;
2888 case MP_CMD_TV_STEP_NORM:
2889 if (mpctx->file_format == DEMUXER_TYPE_TV)
2890 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2891 break;
2893 case MP_CMD_TV_STEP_CHANNEL_LIST:
2894 if (mpctx->file_format == DEMUXER_TYPE_TV)
2895 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2896 break;
2897 #ifdef CONFIG_TV_TELETEXT
2898 case MP_CMD_TV_TELETEXT_ADD_DEC:
2900 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2901 if (mpctx->file_format == DEMUXER_TYPE_TV)
2902 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2903 break;
2905 case MP_CMD_TV_TELETEXT_GO_LINK:
2907 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2908 if (mpctx->file_format == DEMUXER_TYPE_TV)
2909 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2910 break;
2912 #endif /* CONFIG_TV_TELETEXT */
2913 #endif /* CONFIG_TV */
2915 case MP_CMD_SUB_LOAD:
2916 if (sh_video) {
2917 int n = mpctx->set_of_sub_size;
2918 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
2919 if (n != mpctx->set_of_sub_size) {
2920 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2921 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2922 mpctx->global_sub_size;
2923 ++mpctx->global_sub_size;
2926 break;
2928 case MP_CMD_SUB_REMOVE:
2929 if (sh_video) {
2930 int v = cmd->args[0].v.i;
2931 sub_data *subd;
2932 if (v < 0) {
2933 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2934 subd = mpctx->set_of_subtitles[v];
2935 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2936 MSGTR_RemovedSubtitleFile, v + 1,
2937 filename_recode(subd->filename));
2938 sub_free(subd);
2939 mpctx->set_of_subtitles[v] = NULL;
2941 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2942 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2943 mpctx->set_of_sub_size = 0;
2944 if (mpctx->set_of_sub_pos >= 0) {
2945 mpctx->global_sub_pos = -2;
2946 subdata = NULL;
2947 mp_input_queue_cmd(mpctx->input,
2948 mp_input_parse_cmd("sub_select"));
2950 } else if (v < mpctx->set_of_sub_size) {
2951 subd = mpctx->set_of_subtitles[v];
2952 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2953 MSGTR_RemovedSubtitleFile, v + 1,
2954 filename_recode(subd->filename));
2955 sub_free(subd);
2956 if (mpctx->set_of_sub_pos == v) {
2957 mpctx->global_sub_pos = -2;
2958 subdata = NULL;
2959 mp_input_queue_cmd(mpctx->input,
2960 mp_input_parse_cmd("sub_select"));
2961 } else if (mpctx->set_of_sub_pos > v) {
2962 --mpctx->set_of_sub_pos;
2963 --mpctx->global_sub_pos;
2965 while (++v < mpctx->set_of_sub_size)
2966 mpctx->set_of_subtitles[v - 1] =
2967 mpctx->set_of_subtitles[v];
2968 --mpctx->set_of_sub_size;
2969 --mpctx->global_sub_size;
2970 if (mpctx->set_of_sub_size <= 0)
2971 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2972 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2975 break;
2977 case MP_CMD_GET_SUB_VISIBILITY:
2978 if (sh_video) {
2979 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2980 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2982 break;
2984 case MP_CMD_SCREENSHOT:
2985 if (mpctx->video_out && mpctx->video_out->config_ok) {
2986 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2987 if (CONTROL_OK !=
2988 ((vf_instance_t *) sh_video->vfilter)->
2989 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2990 &cmd->args[0].v.i))
2991 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2993 break;
2995 case MP_CMD_VF_CHANGE_RECTANGLE:
2996 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2997 break;
2999 case MP_CMD_GET_TIME_LENGTH:{
3000 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
3001 demuxer_get_time_length(mpctx->demuxer));
3003 break;
3005 case MP_CMD_GET_FILENAME:{
3006 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3007 get_metadata(mpctx, META_NAME));
3009 break;
3011 case MP_CMD_GET_VIDEO_CODEC:{
3012 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3013 if (!inf)
3014 inf = strdup("");
3015 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3016 free(inf);
3018 break;
3020 case MP_CMD_GET_VIDEO_BITRATE:{
3021 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3022 if (!inf)
3023 inf = strdup("");
3024 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3025 free(inf);
3027 break;
3029 case MP_CMD_GET_VIDEO_RESOLUTION:{
3030 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3031 if (!inf)
3032 inf = strdup("");
3033 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3034 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3035 free(inf);
3037 break;
3039 case MP_CMD_GET_AUDIO_CODEC:{
3040 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3041 if (!inf)
3042 inf = strdup("");
3043 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3044 free(inf);
3046 break;
3048 case MP_CMD_GET_AUDIO_BITRATE:{
3049 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3050 if (!inf)
3051 inf = strdup("");
3052 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3053 free(inf);
3055 break;
3057 case MP_CMD_GET_AUDIO_SAMPLES:{
3058 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3059 if (!inf)
3060 inf = strdup("");
3061 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3062 free(inf);
3064 break;
3066 case MP_CMD_GET_META_TITLE:{
3067 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3068 if (!inf)
3069 inf = strdup("");
3070 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3071 free(inf);
3073 break;
3075 case MP_CMD_GET_META_ARTIST:{
3076 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3077 if (!inf)
3078 inf = strdup("");
3079 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3080 free(inf);
3082 break;
3084 case MP_CMD_GET_META_ALBUM:{
3085 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3086 if (!inf)
3087 inf = strdup("");
3088 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3089 free(inf);
3091 break;
3093 case MP_CMD_GET_META_YEAR:{
3094 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3095 if (!inf)
3096 inf = strdup("");
3097 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3098 free(inf);
3100 break;
3102 case MP_CMD_GET_META_COMMENT:{
3103 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3104 if (!inf)
3105 inf = strdup("");
3106 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3107 free(inf);
3109 break;
3111 case MP_CMD_GET_META_TRACK:{
3112 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3113 if (!inf)
3114 inf = strdup("");
3115 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3116 free(inf);
3118 break;
3120 case MP_CMD_GET_META_GENRE:{
3121 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3122 if (!inf)
3123 inf = strdup("");
3124 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3125 free(inf);
3127 break;
3129 case MP_CMD_GET_VO_FULLSCREEN:
3130 if (mpctx->video_out && mpctx->video_out->config_ok)
3131 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3132 break;
3134 case MP_CMD_GET_PERCENT_POS:
3135 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3136 demuxer_get_percent_pos(mpctx->demuxer));
3137 break;
3139 case MP_CMD_GET_TIME_POS:{
3140 float pos = 0;
3141 if (sh_video)
3142 pos = sh_video->pts;
3143 else if (sh_audio && mpctx->audio_out)
3144 pos = playing_audio_pts(mpctx);
3145 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3147 break;
3149 case MP_CMD_RUN:
3150 #ifndef __MINGW32__
3151 if (!fork()) {
3152 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3153 exit(0);
3155 #endif
3156 break;
3158 case MP_CMD_KEYDOWN_EVENTS:
3159 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3160 break;
3162 case MP_CMD_SET_MOUSE_POS:{
3163 int pointer_x, pointer_y;
3164 double dx, dy;
3165 pointer_x = cmd->args[0].v.i;
3166 pointer_y = cmd->args[1].v.i;
3167 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3168 #ifdef CONFIG_DVDNAV
3169 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3170 && dx > 0.0 && dy > 0.0) {
3171 int button = -1;
3172 pointer_x = (int) (dx * (double) sh_video->disp_w);
3173 pointer_y = (int) (dy * (double) sh_video->disp_h);
3174 mp_dvdnav_update_mouse_pos(mpctx->stream,
3175 pointer_x, pointer_y, &button);
3176 if (osd_level > 1 && button > 0)
3177 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3178 "Selected button number %d", button);
3180 #endif
3181 #ifdef CONFIG_MENU
3182 if (use_menu && dx >= 0.0 && dy >= 0.0)
3183 menu_update_mouse_pos(dx, dy);
3184 #endif
3186 break;
3188 #ifdef CONFIG_DVDNAV
3189 case MP_CMD_DVDNAV:{
3190 int button = -1;
3191 int i;
3192 mp_command_type command = 0;
3193 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3194 break;
3196 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3197 if (cmd->args[0].v.s &&
3198 !strcasecmp (cmd->args[0].v.s,
3199 mp_dvdnav_bindings[i].name))
3200 command = mp_dvdnav_bindings[i].cmd;
3202 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3203 if (osd_level > 1 && button > 0)
3204 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3205 "Selected button number %d", button);
3207 break;
3209 case MP_CMD_SWITCH_TITLE:
3210 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3211 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3212 break;
3214 #endif
3216 default:
3217 #ifdef CONFIG_GUI
3218 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3219 guiGetEvent(guiIEvent, (char *) cmd->id);
3220 else
3221 #endif
3222 mp_msg(MSGT_CPLAYER, MSGL_V,
3223 "Received unknown cmd %s\n", cmd->name);
3226 switch (cmd->pausing) {
3227 case 1: // "pausing"
3228 pause_player(mpctx);
3229 break;
3230 case 3: // "pausing_toggle"
3231 if (mpctx->paused)
3232 unpause_player(mpctx);
3233 else
3234 pause_player(mpctx);
3235 break;