Add af_eq_set_bands slave command support
[mplayer/kovensky.git] / command.c
blob6d44fa046c510cbc3803c89a6ab88d78e01ab375
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 "talloc.h"
9 #include "command.h"
10 #include "input/input.h"
11 #include "stream/stream.h"
12 #include "libmpdemux/demuxer.h"
13 #include "libmpdemux/stheader.h"
14 #include "codec-cfg.h"
15 #include "mplayer.h"
16 #include "libvo/sub.h"
17 #include "m_option.h"
18 #include "m_property.h"
19 #include "help_mp.h"
20 #include "metadata.h"
21 #include "libmpcodecs/vf.h"
22 #include "libmpcodecs/vd.h"
23 #include "mp_osd.h"
24 #include "libvo/video_out.h"
25 #include "libvo/font_load.h"
26 #include "playtree.h"
27 #include "libao2/audio_out.h"
28 #include "mpcommon.h"
29 #include "mixer.h"
30 #include "libmpcodecs/dec_video.h"
31 #include "vobsub.h"
32 #include "spudec.h"
33 #include "get_path.h"
34 #ifdef CONFIG_TV
35 #include "stream/tv.h"
36 #endif
37 #ifdef CONFIG_RADIO
38 #include "stream/stream_radio.h"
39 #endif
40 #ifdef CONFIG_PVR
41 #include "stream/pvr.h"
42 #endif
43 #ifdef CONFIG_DVBIN
44 #include "stream/dvbin.h"
45 #endif
46 #ifdef CONFIG_DVDREAD
47 #include "stream/stream_dvd.h"
48 #endif
49 #ifdef CONFIG_DVDNAV
50 #include "stream/stream_dvdnav.h"
51 #endif
52 #ifdef CONFIG_ASS
53 #include "libass/ass.h"
54 #include "libass/ass_mp.h"
55 #endif
56 #ifdef CONFIG_MENU
57 #include "m_struct.h"
58 #include "libmenu/menu.h"
59 #endif
61 #include "mp_core.h"
62 #include "mp_fifo.h"
63 #include "libavutil/avstring.h"
65 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
67 extern int use_menu;
69 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
70 double *dx, double *dy)
72 struct MPOpts *opts = &mpctx->opts;
73 struct vo *vo = mpctx->video_out;
74 //remove the borders, if any, and rescale to the range [0,1],[0,1]
75 if (vo_fs) { //we are in full-screen mode
76 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
77 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
78 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
79 iy -= (opts->vo_screenheight - vo->dheight) / 2;
81 if (ix < 0 || ix > vo->dwidth) {
82 *dx = *dy = -1.0;
83 return;
84 } //we are on one of the borders
85 if (iy < 0 || iy > vo->dheight) {
86 *dx = *dy = -1.0;
87 return;
88 } //we are on one of the borders
91 *dx = (double) ix / (double) vo->dwidth;
92 *dy = (double) iy / (double) vo->dheight;
94 mp_msg(MSGT_CPLAYER, MSGL_V,
95 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
96 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
97 vo->dheight, vo_fs);
100 static int sub_source_by_pos(MPContext *mpctx, int pos)
102 int source = -1;
103 int top = -1;
104 int i;
105 for (i = 0; i < SUB_SOURCES; i++) {
106 int j = mpctx->global_sub_indices[i];
107 if ((j >= 0) && (j > top) && (pos >= j)) {
108 source = i;
109 top = j;
112 return source;
115 static int sub_source(MPContext *mpctx)
117 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
121 * \brief Log the currently displayed subtitle to a file
123 * Logs the current or last displayed subtitle together with filename
124 * and time information to ~/.mplayer/subtitle_log
126 * Intended purpose is to allow convenient marking of bogus subtitles
127 * which need to be fixed while watching the movie.
130 static void log_sub(struct MPContext *mpctx)
132 char *fname;
133 FILE *f;
134 int i;
136 if (subdata == NULL || vo_sub_last == NULL)
137 return;
138 fname = get_path("subtitle_log");
139 f = fopen(fname, "a");
140 if (!f)
141 return;
142 fprintf(f, "----------------------------------------------------------\n");
143 if (subdata->sub_uses_time) {
144 fprintf(f,
145 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
146 mpctx->filename, vo_sub_last->start / 360000,
147 (vo_sub_last->start / 6000) % 60,
148 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
149 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
150 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
151 } else {
152 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
153 vo_sub_last->start, vo_sub_last->end);
155 for (i = 0; i < vo_sub_last->lines; i++) {
156 fprintf(f, "%s\n", vo_sub_last->text[i]);
158 fclose(f);
162 /// \defgroup Properties
163 ///@{
165 /// \defgroup GeneralProperties General properties
166 /// \ingroup Properties
167 ///@{
169 /// OSD level (RW)
170 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
171 MPContext *mpctx)
173 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
176 /// Loop (RW)
177 static int mp_property_loop(m_option_t *prop, int action, void *arg,
178 MPContext *mpctx)
180 struct MPOpts *opts = &mpctx->opts;
181 switch (action) {
182 case M_PROPERTY_PRINT:
183 if (!arg) return M_PROPERTY_ERROR;
184 if (opts->loop_times < 0)
185 *(char**)arg = strdup("off");
186 else if (opts->loop_times == 0)
187 *(char**)arg = strdup("inf");
188 else
189 break;
190 return M_PROPERTY_OK;
192 return m_property_int_range(prop, action, arg, &opts->loop_times);
195 /// Playback speed (RW)
196 static int mp_property_playback_speed(m_option_t *prop, int action,
197 void *arg, MPContext *mpctx)
199 struct MPOpts *opts = &mpctx->opts;
200 switch (action) {
201 case M_PROPERTY_SET:
202 if (!arg)
203 return M_PROPERTY_ERROR;
204 M_PROPERTY_CLAMP(prop, *(float *) arg);
205 opts->playback_speed = *(float *) arg;
206 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
207 return M_PROPERTY_OK;
208 case M_PROPERTY_STEP_UP:
209 case M_PROPERTY_STEP_DOWN:
210 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
211 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
212 M_PROPERTY_CLAMP(prop, opts->playback_speed);
213 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
214 return M_PROPERTY_OK;
216 return m_property_float_range(prop, action, arg, &opts->playback_speed);
219 /// filename with path (RO)
220 static int mp_property_path(m_option_t *prop, int action, void *arg,
221 MPContext *mpctx)
223 return m_property_string_ro(prop, action, arg, mpctx->filename);
226 /// filename without path (RO)
227 static int mp_property_filename(m_option_t *prop, int action, void *arg,
228 MPContext *mpctx)
230 char *f;
231 if (!mpctx->filename)
232 return M_PROPERTY_UNAVAILABLE;
233 if (((f = strrchr(mpctx->filename, '/'))
234 || (f = strrchr(mpctx->filename, '\\'))) && f[1])
235 f++;
236 else
237 f = mpctx->filename;
238 return m_property_string_ro(prop, action, arg, f);
241 /// Demuxer name (RO)
242 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
243 MPContext *mpctx)
245 if (!mpctx->demuxer)
246 return M_PROPERTY_UNAVAILABLE;
247 return m_property_string_ro(prop, action, arg,
248 (char *) mpctx->demuxer->desc->name);
251 /// Position in the stream (RW)
252 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
253 MPContext *mpctx)
255 if (!mpctx->demuxer || !mpctx->demuxer->stream)
256 return M_PROPERTY_UNAVAILABLE;
257 if (!arg)
258 return M_PROPERTY_ERROR;
259 switch (action) {
260 case M_PROPERTY_GET:
261 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
262 return M_PROPERTY_OK;
263 case M_PROPERTY_SET:
264 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
265 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
266 return M_PROPERTY_OK;
268 return M_PROPERTY_NOT_IMPLEMENTED;
271 /// Stream start offset (RO)
272 static int mp_property_stream_start(m_option_t *prop, int action,
273 void *arg, MPContext *mpctx)
275 if (!mpctx->demuxer || !mpctx->demuxer->stream)
276 return M_PROPERTY_UNAVAILABLE;
277 switch (action) {
278 case M_PROPERTY_GET:
279 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
280 return M_PROPERTY_OK;
282 return M_PROPERTY_NOT_IMPLEMENTED;
285 /// Stream end offset (RO)
286 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
287 MPContext *mpctx)
289 if (!mpctx->demuxer || !mpctx->demuxer->stream)
290 return M_PROPERTY_UNAVAILABLE;
291 switch (action) {
292 case M_PROPERTY_GET:
293 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
294 return M_PROPERTY_OK;
296 return M_PROPERTY_NOT_IMPLEMENTED;
299 /// Stream length (RO)
300 static int mp_property_stream_length(m_option_t *prop, int action,
301 void *arg, MPContext *mpctx)
303 if (!mpctx->demuxer || !mpctx->demuxer->stream)
304 return M_PROPERTY_UNAVAILABLE;
305 switch (action) {
306 case M_PROPERTY_GET:
307 *(off_t *) arg =
308 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
309 return M_PROPERTY_OK;
311 return M_PROPERTY_NOT_IMPLEMENTED;
314 /// Media length in seconds (RO)
315 static int mp_property_length(m_option_t *prop, int action, void *arg,
316 MPContext *mpctx)
318 double len;
320 if (!mpctx->demuxer ||
321 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
322 return M_PROPERTY_UNAVAILABLE;
324 return m_property_time_ro(prop, action, arg, len);
327 /// Current position in percent (RW)
328 static int mp_property_percent_pos(m_option_t *prop, int action,
329 void *arg, MPContext *mpctx) {
330 int pos;
332 if (!mpctx->demuxer)
333 return M_PROPERTY_UNAVAILABLE;
335 switch(action) {
336 case M_PROPERTY_SET:
337 if(!arg) return M_PROPERTY_ERROR;
338 M_PROPERTY_CLAMP(prop, *(int*)arg);
339 pos = *(int*)arg;
340 break;
341 case M_PROPERTY_STEP_UP:
342 case M_PROPERTY_STEP_DOWN:
343 pos = demuxer_get_percent_pos(mpctx->demuxer);
344 pos += (arg ? *(int*)arg : 10) *
345 (action == M_PROPERTY_STEP_UP ? 1 : -1);
346 M_PROPERTY_CLAMP(prop, pos);
347 break;
348 default:
349 return m_property_int_ro(prop, action, arg,
350 demuxer_get_percent_pos(mpctx->demuxer));
353 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
354 mpctx->rel_seek_secs = pos / 100.0;
355 return M_PROPERTY_OK;
358 /// Current position in seconds (RW)
359 static int mp_property_time_pos(m_option_t *prop, int action,
360 void *arg, MPContext *mpctx) {
361 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
362 return M_PROPERTY_UNAVAILABLE;
364 switch(action) {
365 case M_PROPERTY_SET:
366 if(!arg) return M_PROPERTY_ERROR;
367 M_PROPERTY_CLAMP(prop, *(double*)arg);
368 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
369 mpctx->rel_seek_secs = *(double*)arg;
370 return M_PROPERTY_OK;
371 case M_PROPERTY_STEP_UP:
372 case M_PROPERTY_STEP_DOWN:
373 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
374 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
375 return M_PROPERTY_OK;
377 return m_property_time_ro(prop, action, arg,
378 mpctx->sh_video ? mpctx->sh_video->pts :
379 playing_audio_pts(mpctx));
382 /// Current chapter (RW)
383 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
384 MPContext *mpctx)
386 struct MPOpts *opts = &mpctx->opts;
387 int chapter = -1;
388 int step_all;
389 char *chapter_name = NULL;
391 if (mpctx->demuxer)
392 chapter = get_current_chapter(mpctx);
393 if (chapter < 0)
394 return M_PROPERTY_UNAVAILABLE;
396 switch (action) {
397 case M_PROPERTY_GET:
398 if (!arg)
399 return M_PROPERTY_ERROR;
400 *(int *) arg = chapter;
401 return M_PROPERTY_OK;
402 case M_PROPERTY_PRINT: {
403 if (!arg)
404 return M_PROPERTY_ERROR;
405 chapter_name = chapter_display_name(mpctx, chapter);
406 if (!chapter_name)
407 return M_PROPERTY_UNAVAILABLE;
408 *(char **) arg = chapter_name;
409 return M_PROPERTY_OK;
411 case M_PROPERTY_SET:
412 if (!arg)
413 return M_PROPERTY_ERROR;
414 M_PROPERTY_CLAMP(prop, *(int*)arg);
415 step_all = *(int *)arg - chapter;
416 chapter += step_all;
417 break;
418 case M_PROPERTY_STEP_UP:
419 case M_PROPERTY_STEP_DOWN: {
420 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
421 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
422 chapter += step_all;
423 if (chapter < 0)
424 chapter = 0;
425 break;
427 default:
428 return M_PROPERTY_NOT_IMPLEMENTED;
431 double next_pts = 0;
432 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
433 mpctx->rel_seek_secs = 0;
434 mpctx->abs_seek_pos = 0;
435 if (chapter >= 0) {
436 if (next_pts > -1.0) {
437 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
438 mpctx->rel_seek_secs = next_pts;
440 if (chapter_name)
441 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
442 _("Chapter: (%d) %s"), chapter + 1, chapter_name);
444 else if (step_all > 0)
445 mpctx->rel_seek_secs = 1000000000.;
446 else
447 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
448 _("Chapter: (%d) %s"), 0, _("unknown"));
449 if (chapter_name)
450 talloc_free(chapter_name);
451 return M_PROPERTY_OK;
454 /// Number of chapters in file
455 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
456 MPContext *mpctx)
458 if (!mpctx->demuxer)
459 return M_PROPERTY_UNAVAILABLE;
460 if (mpctx->demuxer->num_chapters == 0)
461 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
462 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
465 /// Current dvd angle (RW)
466 static int mp_property_angle(m_option_t *prop, int action, void *arg,
467 MPContext *mpctx)
469 struct MPOpts *opts = &mpctx->opts;
470 int angle = -1;
471 int angles;
472 char *angle_name = NULL;
474 if (mpctx->demuxer)
475 angle = demuxer_get_current_angle(mpctx->demuxer);
476 if (angle < 0)
477 return M_PROPERTY_UNAVAILABLE;
478 angles = demuxer_angles_count(mpctx->demuxer);
479 if (angles <= 1)
480 return M_PROPERTY_UNAVAILABLE;
482 switch (action) {
483 case M_PROPERTY_GET:
484 if (!arg)
485 return M_PROPERTY_ERROR;
486 *(int *) arg = angle;
487 return M_PROPERTY_OK;
488 case M_PROPERTY_PRINT: {
489 if (!arg)
490 return M_PROPERTY_ERROR;
491 angle_name = calloc(1, 64);
492 if (!angle_name)
493 return M_PROPERTY_UNAVAILABLE;
494 snprintf(angle_name, 64, "%d/%d", angle, angles);
495 *(char **) arg = angle_name;
496 return M_PROPERTY_OK;
498 case M_PROPERTY_SET:
499 if (!arg)
500 return M_PROPERTY_ERROR;
501 angle = *(int *)arg;
502 M_PROPERTY_CLAMP(prop, angle);
503 break;
504 case M_PROPERTY_STEP_UP:
505 case M_PROPERTY_STEP_DOWN: {
506 int step = 0;
507 if(arg)
508 step = *(int*)arg;
509 if(!step)
510 step = 1;
511 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
512 angle += step;
513 if (angle < 1) //cycle
514 angle = angles;
515 break;
517 default:
518 return M_PROPERTY_NOT_IMPLEMENTED;
520 angle = demuxer_set_angle(mpctx->demuxer, angle);
521 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
522 _("Angle: %d/%d"), angle, angles);
523 if (angle_name)
524 free(angle_name);
525 return M_PROPERTY_OK;
528 /// Demuxer meta data
529 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
530 MPContext *mpctx) {
531 m_property_action_t* ka;
532 char* meta;
533 static const m_option_t key_type =
534 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
535 if (!mpctx->demuxer)
536 return M_PROPERTY_UNAVAILABLE;
538 switch(action) {
539 case M_PROPERTY_GET:
540 if(!arg) return M_PROPERTY_ERROR;
541 *(char***)arg = mpctx->demuxer->info;
542 return M_PROPERTY_OK;
543 case M_PROPERTY_KEY_ACTION:
544 if(!arg) return M_PROPERTY_ERROR;
545 ka = arg;
546 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
547 return M_PROPERTY_UNKNOWN;
548 switch(ka->action) {
549 case M_PROPERTY_GET:
550 if(!ka->arg) return M_PROPERTY_ERROR;
551 *(char**)ka->arg = meta;
552 return M_PROPERTY_OK;
553 case M_PROPERTY_GET_TYPE:
554 if(!ka->arg) return M_PROPERTY_ERROR;
555 *(m_option_t**)ka->arg = &key_type;
556 return M_PROPERTY_OK;
559 return M_PROPERTY_NOT_IMPLEMENTED;
562 static int mp_property_pause(m_option_t *prop, int action, void *arg,
563 void *ctx)
565 MPContext *mpctx = ctx;
567 switch (action) {
568 case M_PROPERTY_SET:
569 if (!arg)
570 return M_PROPERTY_ERROR;
571 if (mpctx->paused == (bool)*(int *) arg)
572 return M_PROPERTY_OK;
573 case M_PROPERTY_STEP_UP:
574 case M_PROPERTY_STEP_DOWN:
575 if (mpctx->paused) {
576 unpause_player(mpctx);
577 mpctx->osd_function = OSD_PLAY;
579 else {
580 pause_player(mpctx);
581 mpctx->osd_function = OSD_PAUSE;
583 return M_PROPERTY_OK;
584 default:
585 return m_property_flag(prop, action, arg, &mpctx->paused);
590 ///@}
592 /// \defgroup AudioProperties Audio properties
593 /// \ingroup Properties
594 ///@{
596 /// Volume (RW)
597 static int mp_property_volume(m_option_t *prop, int action, void *arg,
598 MPContext *mpctx)
601 if (!mpctx->sh_audio)
602 return M_PROPERTY_UNAVAILABLE;
604 switch (action) {
605 case M_PROPERTY_GET:
606 if (!arg)
607 return M_PROPERTY_ERROR;
608 mixer_getbothvolume(&mpctx->mixer, arg);
609 return M_PROPERTY_OK;
610 case M_PROPERTY_PRINT:{
611 float vol;
612 if (!arg)
613 return M_PROPERTY_ERROR;
614 mixer_getbothvolume(&mpctx->mixer, &vol);
615 return m_property_float_range(prop, action, arg, &vol);
617 case M_PROPERTY_STEP_UP:
618 case M_PROPERTY_STEP_DOWN:
619 case M_PROPERTY_SET:
620 break;
621 default:
622 return M_PROPERTY_NOT_IMPLEMENTED;
625 if (mpctx->edl_muted)
626 return M_PROPERTY_DISABLED;
627 mpctx->user_muted = 0;
629 switch (action) {
630 case M_PROPERTY_SET:
631 if (!arg)
632 return M_PROPERTY_ERROR;
633 M_PROPERTY_CLAMP(prop, *(float *) arg);
634 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
635 return M_PROPERTY_OK;
636 case M_PROPERTY_STEP_UP:
637 if (arg && *(float *) arg <= 0)
638 mixer_decvolume(&mpctx->mixer);
639 else
640 mixer_incvolume(&mpctx->mixer);
641 return M_PROPERTY_OK;
642 case M_PROPERTY_STEP_DOWN:
643 if (arg && *(float *) arg <= 0)
644 mixer_incvolume(&mpctx->mixer);
645 else
646 mixer_decvolume(&mpctx->mixer);
647 return M_PROPERTY_OK;
649 return M_PROPERTY_NOT_IMPLEMENTED;
652 /// Mute (RW)
653 static int mp_property_mute(m_option_t *prop, int action, void *arg,
654 MPContext *mpctx)
657 if (!mpctx->sh_audio)
658 return M_PROPERTY_UNAVAILABLE;
660 switch (action) {
661 case M_PROPERTY_SET:
662 if (mpctx->edl_muted)
663 return M_PROPERTY_DISABLED;
664 if (!arg)
665 return M_PROPERTY_ERROR;
666 if ((!!*(int *) arg) != mpctx->mixer.muted)
667 mixer_mute(&mpctx->mixer);
668 mpctx->user_muted = mpctx->mixer.muted;
669 return M_PROPERTY_OK;
670 case M_PROPERTY_STEP_UP:
671 case M_PROPERTY_STEP_DOWN:
672 if (mpctx->edl_muted)
673 return M_PROPERTY_DISABLED;
674 mixer_mute(&mpctx->mixer);
675 mpctx->user_muted = mpctx->mixer.muted;
676 return M_PROPERTY_OK;
677 case M_PROPERTY_PRINT:
678 if (!arg)
679 return M_PROPERTY_ERROR;
680 if (mpctx->edl_muted) {
681 *(char **) arg = strdup(_("enabled (EDL)"));
682 return M_PROPERTY_OK;
684 default:
685 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
690 /// Audio delay (RW)
691 static int mp_property_audio_delay(m_option_t *prop, int action,
692 void *arg, MPContext *mpctx)
694 if (!(mpctx->sh_audio && mpctx->sh_video))
695 return M_PROPERTY_UNAVAILABLE;
696 switch (action) {
697 case M_PROPERTY_SET:
698 case M_PROPERTY_STEP_UP:
699 case M_PROPERTY_STEP_DOWN: {
700 int ret;
701 float delay = audio_delay;
702 ret = m_property_delay(prop, action, arg, &audio_delay);
703 if (ret != M_PROPERTY_OK)
704 return ret;
705 if (mpctx->sh_audio)
706 mpctx->delay -= audio_delay - delay;
708 return M_PROPERTY_OK;
709 default:
710 return m_property_delay(prop, action, arg, &audio_delay);
714 /// Audio codec tag (RO)
715 static int mp_property_audio_format(m_option_t *prop, int action,
716 void *arg, MPContext *mpctx)
718 if (!mpctx->sh_audio)
719 return M_PROPERTY_UNAVAILABLE;
720 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
723 /// Audio codec name (RO)
724 static int mp_property_audio_codec(m_option_t *prop, int action,
725 void *arg, MPContext *mpctx)
727 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
728 return M_PROPERTY_UNAVAILABLE;
729 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
732 /// Audio bitrate (RO)
733 static int mp_property_audio_bitrate(m_option_t *prop, int action,
734 void *arg, MPContext *mpctx)
736 if (!mpctx->sh_audio)
737 return M_PROPERTY_UNAVAILABLE;
738 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
741 /// Samplerate (RO)
742 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
743 MPContext *mpctx)
745 if (!mpctx->sh_audio)
746 return M_PROPERTY_UNAVAILABLE;
747 switch(action) {
748 case M_PROPERTY_PRINT:
749 if(!arg) return M_PROPERTY_ERROR;
750 *(char**)arg = malloc(16);
751 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
752 return M_PROPERTY_OK;
754 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
757 /// Number of channels (RO)
758 static int mp_property_channels(m_option_t *prop, int action, void *arg,
759 MPContext *mpctx)
761 if (!mpctx->sh_audio)
762 return M_PROPERTY_UNAVAILABLE;
763 switch (action) {
764 case M_PROPERTY_PRINT:
765 if (!arg)
766 return M_PROPERTY_ERROR;
767 switch (mpctx->sh_audio->channels) {
768 case 1:
769 *(char **) arg = strdup("mono");
770 break;
771 case 2:
772 *(char **) arg = strdup("stereo");
773 break;
774 default:
775 *(char **) arg = malloc(32);
776 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
778 return M_PROPERTY_OK;
780 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
783 /// Balance (RW)
784 static int mp_property_balance(m_option_t *prop, int action, void *arg,
785 MPContext *mpctx)
787 float bal;
789 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
790 return M_PROPERTY_UNAVAILABLE;
792 switch (action) {
793 case M_PROPERTY_GET:
794 if (!arg)
795 return M_PROPERTY_ERROR;
796 mixer_getbalance(&mpctx->mixer, arg);
797 return M_PROPERTY_OK;
798 case M_PROPERTY_PRINT: {
799 char** str = arg;
800 if (!arg)
801 return M_PROPERTY_ERROR;
802 mixer_getbalance(&mpctx->mixer, &bal);
803 if (bal == 0.f)
804 *str = strdup("center");
805 else if (bal == -1.f)
806 *str = strdup("left only");
807 else if (bal == 1.f)
808 *str = strdup("right only");
809 else {
810 unsigned right = (bal + 1.f) / 2.f * 100.f;
811 *str = malloc(sizeof("left xxx%, right xxx%"));
812 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
814 return M_PROPERTY_OK;
816 case M_PROPERTY_STEP_UP:
817 case M_PROPERTY_STEP_DOWN:
818 mixer_getbalance(&mpctx->mixer, &bal);
819 bal += (arg ? *(float*)arg : .1f) *
820 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
821 M_PROPERTY_CLAMP(prop, bal);
822 mixer_setbalance(&mpctx->mixer, bal);
823 return M_PROPERTY_OK;
824 case M_PROPERTY_SET:
825 if (!arg)
826 return M_PROPERTY_ERROR;
827 M_PROPERTY_CLAMP(prop, *(float*)arg);
828 mixer_setbalance(&mpctx->mixer, *(float*)arg);
829 return M_PROPERTY_OK;
831 return M_PROPERTY_NOT_IMPLEMENTED;
834 /// Selected audio id (RW)
835 static int mp_property_audio(m_option_t *prop, int action, void *arg,
836 MPContext *mpctx)
838 struct MPOpts *opts = &mpctx->opts;
839 int current_id = -1, tmp;
841 switch (action) {
842 case M_PROPERTY_GET:
843 if (!mpctx->sh_audio)
844 return M_PROPERTY_UNAVAILABLE;
845 if (!arg)
846 return M_PROPERTY_ERROR;
847 *(int *) arg = opts->audio_id;
848 return M_PROPERTY_OK;
849 case M_PROPERTY_PRINT:
850 if (!mpctx->sh_audio)
851 return M_PROPERTY_UNAVAILABLE;
852 if (!arg)
853 return M_PROPERTY_ERROR;
855 if (opts->audio_id < 0)
856 *(char **) arg = strdup(_("disabled"));
857 else {
858 char lang[40] = _("unknown");
859 sh_audio_t* sh = mpctx->sh_audio;
860 if (sh && sh->lang)
861 av_strlcpy(lang, sh->lang, 40);
862 #ifdef CONFIG_DVDREAD
863 else if (mpctx->stream->type == STREAMTYPE_DVD) {
864 int code = dvd_lang_from_aid(mpctx->stream, opts->audio_id);
865 if (code) {
866 lang[0] = code >> 8;
867 lang[1] = code;
868 lang[2] = 0;
871 #endif
873 #ifdef CONFIG_DVDNAV
874 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
875 mp_dvdnav_lang_from_aid(mpctx->stream, opts->audio_id, lang);
876 #endif
877 *(char **) arg = malloc(64);
878 snprintf(*(char **) arg, 64, "(%d) %s", opts->audio_id, lang);
880 return M_PROPERTY_OK;
882 case M_PROPERTY_STEP_UP:
883 case M_PROPERTY_SET:
884 if (!mpctx->demuxer)
885 return M_PROPERTY_UNAVAILABLE;
886 if (action == M_PROPERTY_SET && arg)
887 tmp = *((int *) arg);
888 else
889 tmp = -1;
890 current_id = mpctx->demuxer->audio->id;
891 opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
892 if (opts->audio_id == -2
893 || (opts->audio_id > -1
894 && mpctx->demuxer->audio->id != current_id && current_id != -2))
895 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
896 if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
897 sh_audio_t *sh2;
898 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
899 if (sh2) {
900 sh2->ds = mpctx->demuxer->audio;
901 mpctx->sh_audio = sh2;
902 reinit_audio_chain(mpctx);
905 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id);
906 return M_PROPERTY_OK;
907 default:
908 return M_PROPERTY_NOT_IMPLEMENTED;
913 /// Selected video id (RW)
914 static int mp_property_video(m_option_t *prop, int action, void *arg,
915 MPContext *mpctx)
917 struct MPOpts *opts = &mpctx->opts;
918 int current_id = -1, tmp;
920 switch (action) {
921 case M_PROPERTY_GET:
922 if (!mpctx->sh_video)
923 return M_PROPERTY_UNAVAILABLE;
924 if (!arg)
925 return M_PROPERTY_ERROR;
926 *(int *) arg = opts->video_id;
927 return M_PROPERTY_OK;
928 case M_PROPERTY_PRINT:
929 if (!mpctx->sh_video)
930 return M_PROPERTY_UNAVAILABLE;
931 if (!arg)
932 return M_PROPERTY_ERROR;
934 if (opts->video_id < 0)
935 *(char **) arg = strdup(_("disabled"));
936 else {
937 char lang[40] = _("unknown");
938 *(char **) arg = malloc(64);
939 snprintf(*(char **) arg, 64, "(%d) %s", opts->video_id, lang);
941 return M_PROPERTY_OK;
943 case M_PROPERTY_STEP_UP:
944 case M_PROPERTY_SET:
945 current_id = mpctx->demuxer->video->id;
946 if (action == M_PROPERTY_SET && arg)
947 tmp = *((int *) arg);
948 else
949 tmp = -1;
950 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
951 if (opts->video_id == -2
952 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
953 && current_id != -2))
954 uninit_player(mpctx, INITIALIZED_VCODEC |
955 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
956 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
957 sh_video_t *sh2;
958 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
959 if (sh2) {
960 sh2->ds = mpctx->demuxer->video;
961 mpctx->sh_video = sh2;
962 reinit_video_chain(mpctx);
965 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
966 return M_PROPERTY_OK;
968 default:
969 return M_PROPERTY_NOT_IMPLEMENTED;
973 static int mp_property_program(m_option_t *prop, int action, void *arg,
974 MPContext *mpctx)
976 demux_program_t prog;
978 switch (action) {
979 case M_PROPERTY_STEP_UP:
980 case M_PROPERTY_SET:
981 if (action == M_PROPERTY_SET && arg)
982 prog.progid = *((int *) arg);
983 else
984 prog.progid = -1;
985 if (demux_control
986 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
987 &prog) == DEMUXER_CTRL_NOTIMPL)
988 return M_PROPERTY_ERROR;
990 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
991 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
992 return M_PROPERTY_OK;
994 default:
995 return M_PROPERTY_NOT_IMPLEMENTED;
999 ///@}
1001 /// \defgroup VideoProperties Video properties
1002 /// \ingroup Properties
1003 ///@{
1005 /// Fullscreen state (RW)
1006 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1007 MPContext *mpctx)
1010 if (!mpctx->video_out)
1011 return M_PROPERTY_UNAVAILABLE;
1013 switch (action) {
1014 case M_PROPERTY_SET:
1015 if (!arg)
1016 return M_PROPERTY_ERROR;
1017 M_PROPERTY_CLAMP(prop, *(int *) arg);
1018 if (vo_fs == !!*(int *) arg)
1019 return M_PROPERTY_OK;
1020 case M_PROPERTY_STEP_UP:
1021 case M_PROPERTY_STEP_DOWN:
1022 if (mpctx->video_out->config_ok)
1023 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1024 mpctx->opts.fullscreen = vo_fs;
1025 return M_PROPERTY_OK;
1026 default:
1027 return m_property_flag(prop, action, arg, &vo_fs);
1031 static int mp_property_deinterlace(m_option_t *prop, int action,
1032 void *arg, MPContext *mpctx)
1034 int deinterlace;
1035 vf_instance_t *vf;
1036 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1037 return M_PROPERTY_UNAVAILABLE;
1038 vf = mpctx->sh_video->vfilter;
1039 switch (action) {
1040 case M_PROPERTY_GET:
1041 if (!arg)
1042 return M_PROPERTY_ERROR;
1043 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1044 return M_PROPERTY_OK;
1045 case M_PROPERTY_SET:
1046 if (!arg)
1047 return M_PROPERTY_ERROR;
1048 M_PROPERTY_CLAMP(prop, *(int *) arg);
1049 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1050 return M_PROPERTY_OK;
1051 case M_PROPERTY_STEP_UP:
1052 case M_PROPERTY_STEP_DOWN:
1053 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1054 deinterlace = !deinterlace;
1055 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1056 return M_PROPERTY_OK;
1058 return M_PROPERTY_NOT_IMPLEMENTED;
1061 /// Panscan (RW)
1062 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1063 MPContext *mpctx)
1066 if (!mpctx->video_out
1067 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1068 return M_PROPERTY_UNAVAILABLE;
1070 switch (action) {
1071 case M_PROPERTY_SET:
1072 if (!arg)
1073 return M_PROPERTY_ERROR;
1074 M_PROPERTY_CLAMP(prop, *(float *) arg);
1075 vo_panscan = *(float *) arg;
1076 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1077 return M_PROPERTY_OK;
1078 case M_PROPERTY_STEP_UP:
1079 case M_PROPERTY_STEP_DOWN:
1080 vo_panscan += (arg ? *(float *) arg : 0.1) *
1081 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1082 if (vo_panscan > 1)
1083 vo_panscan = 1;
1084 else if (vo_panscan < 0)
1085 vo_panscan = 0;
1086 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1087 return M_PROPERTY_OK;
1088 default:
1089 return m_property_float_range(prop, action, arg, &vo_panscan);
1093 /// Helper to set vo flags.
1094 /** \ingroup PropertyImplHelper
1096 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1097 int vo_ctrl, int *vo_var, MPContext *mpctx)
1100 if (!mpctx->video_out)
1101 return M_PROPERTY_UNAVAILABLE;
1103 switch (action) {
1104 case M_PROPERTY_SET:
1105 if (!arg)
1106 return M_PROPERTY_ERROR;
1107 M_PROPERTY_CLAMP(prop, *(int *) arg);
1108 if (*vo_var == !!*(int *) arg)
1109 return M_PROPERTY_OK;
1110 case M_PROPERTY_STEP_UP:
1111 case M_PROPERTY_STEP_DOWN:
1112 if (mpctx->video_out->config_ok)
1113 vo_control(mpctx->video_out, vo_ctrl, 0);
1114 return M_PROPERTY_OK;
1115 default:
1116 return m_property_flag(prop, action, arg, vo_var);
1120 /// Window always on top (RW)
1121 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1122 MPContext *mpctx)
1124 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1125 &mpctx->opts.vo_ontop, mpctx);
1128 /// Display in the root window (RW)
1129 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1130 MPContext *mpctx)
1132 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1133 &vo_rootwin, mpctx);
1136 /// Show window borders (RW)
1137 static int mp_property_border(m_option_t *prop, int action, void *arg,
1138 MPContext *mpctx)
1140 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1141 &vo_border, mpctx);
1144 /// Framedropping state (RW)
1145 static int mp_property_framedropping(m_option_t *prop, int action,
1146 void *arg, MPContext *mpctx)
1149 if (!mpctx->sh_video)
1150 return M_PROPERTY_UNAVAILABLE;
1152 switch (action) {
1153 case M_PROPERTY_PRINT:
1154 if (!arg)
1155 return M_PROPERTY_ERROR;
1156 *(char **) arg = strdup(frame_dropping == 1 ? _("enabled") :
1157 (frame_dropping == 2 ? _("hard") :
1158 _("disabled")));
1159 return M_PROPERTY_OK;
1160 default:
1161 return m_property_choice(prop, action, arg, &frame_dropping);
1165 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1166 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1167 MPContext *mpctx)
1169 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1170 int r, val;
1172 if (!mpctx->sh_video)
1173 return M_PROPERTY_UNAVAILABLE;
1175 if (gamma[0] == 1000) {
1176 gamma[0] = 0;
1177 get_video_colors(mpctx->sh_video, prop->name, gamma);
1180 switch (action) {
1181 case M_PROPERTY_SET:
1182 if (!arg)
1183 return M_PROPERTY_ERROR;
1184 M_PROPERTY_CLAMP(prop, *(int *) arg);
1185 *gamma = *(int *) arg;
1186 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1187 if (r <= 0)
1188 break;
1189 return r;
1190 case M_PROPERTY_GET:
1191 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1192 if (!arg)
1193 return M_PROPERTY_ERROR;
1194 *(int *)arg = val;
1195 return M_PROPERTY_OK;
1197 break;
1198 case M_PROPERTY_STEP_UP:
1199 case M_PROPERTY_STEP_DOWN:
1200 *gamma += (arg ? *(int *) arg : 1) *
1201 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1202 M_PROPERTY_CLAMP(prop, *gamma);
1203 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1204 if (r <= 0)
1205 break;
1206 return r;
1207 default:
1208 return M_PROPERTY_NOT_IMPLEMENTED;
1211 #ifdef CONFIG_TV
1212 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1213 int l = strlen(prop->name);
1214 char tv_prop[3 + l + 1];
1215 sprintf(tv_prop, "tv_%s", prop->name);
1216 return mp_property_do(tv_prop, action, arg, mpctx);
1218 #endif
1220 return M_PROPERTY_UNAVAILABLE;
1223 /// VSync (RW)
1224 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1225 MPContext *mpctx)
1227 return m_property_flag(prop, action, arg, &vo_vsync);
1230 /// Video codec tag (RO)
1231 static int mp_property_video_format(m_option_t *prop, int action,
1232 void *arg, MPContext *mpctx)
1234 char* meta;
1235 if (!mpctx->sh_video)
1236 return M_PROPERTY_UNAVAILABLE;
1237 switch(action) {
1238 case M_PROPERTY_PRINT:
1239 if (!arg)
1240 return M_PROPERTY_ERROR;
1241 switch(mpctx->sh_video->format) {
1242 case 0x10000001:
1243 meta = strdup ("mpeg1"); break;
1244 case 0x10000002:
1245 meta = strdup ("mpeg2"); break;
1246 case 0x10000004:
1247 meta = strdup ("mpeg4"); break;
1248 case 0x10000005:
1249 meta = strdup ("h264"); break;
1250 default:
1251 if(mpctx->sh_video->format >= 0x20202020) {
1252 meta = malloc(5);
1253 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1254 } else {
1255 meta = malloc(20);
1256 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1259 *(char**)arg = meta;
1260 return M_PROPERTY_OK;
1262 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1265 /// Video codec name (RO)
1266 static int mp_property_video_codec(m_option_t *prop, int action,
1267 void *arg, MPContext *mpctx)
1269 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1270 return M_PROPERTY_UNAVAILABLE;
1271 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1275 /// Video bitrate (RO)
1276 static int mp_property_video_bitrate(m_option_t *prop, int action,
1277 void *arg, MPContext *mpctx)
1279 if (!mpctx->sh_video)
1280 return M_PROPERTY_UNAVAILABLE;
1281 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1284 /// Video display width (RO)
1285 static int mp_property_width(m_option_t *prop, int action, void *arg,
1286 MPContext *mpctx)
1288 if (!mpctx->sh_video)
1289 return M_PROPERTY_UNAVAILABLE;
1290 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1293 /// Video display height (RO)
1294 static int mp_property_height(m_option_t *prop, int action, void *arg,
1295 MPContext *mpctx)
1297 if (!mpctx->sh_video)
1298 return M_PROPERTY_UNAVAILABLE;
1299 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1302 /// Video fps (RO)
1303 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1304 MPContext *mpctx)
1306 if (!mpctx->sh_video)
1307 return M_PROPERTY_UNAVAILABLE;
1308 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1311 /// Video aspect (RO)
1312 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1313 MPContext *mpctx)
1315 if (!mpctx->sh_video)
1316 return M_PROPERTY_UNAVAILABLE;
1317 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1320 ///@}
1322 /// \defgroup SubProprties Subtitles properties
1323 /// \ingroup Properties
1324 ///@{
1326 /// Text subtitle position (RW)
1327 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1328 MPContext *mpctx)
1330 if (!mpctx->sh_video)
1331 return M_PROPERTY_UNAVAILABLE;
1333 switch (action) {
1334 case M_PROPERTY_SET:
1335 if (!arg)
1336 return M_PROPERTY_ERROR;
1337 case M_PROPERTY_STEP_UP:
1338 case M_PROPERTY_STEP_DOWN:
1339 vo_osd_changed(OSDTYPE_SUBTITLE);
1340 default:
1341 return m_property_int_range(prop, action, arg, &sub_pos);
1345 /// Selected subtitles (RW)
1346 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1347 MPContext *mpctx)
1349 struct MPOpts *opts = &mpctx->opts;
1350 demux_stream_t *const d_sub = mpctx->d_sub;
1351 const int global_sub_size = mpctx->global_sub_size;
1352 int source = -1, reset_spu = 0;
1353 char *sub_name;
1355 if (!mpctx->sh_video || global_sub_size <= 0)
1356 return M_PROPERTY_UNAVAILABLE;
1358 switch (action) {
1359 case M_PROPERTY_GET:
1360 if (!arg)
1361 return M_PROPERTY_ERROR;
1362 *(int *) arg = mpctx->global_sub_pos;
1363 return M_PROPERTY_OK;
1364 case M_PROPERTY_PRINT:
1365 if (!arg)
1366 return M_PROPERTY_ERROR;
1367 *(char **) arg = malloc(64);
1368 (*(char **) arg)[63] = 0;
1369 sub_name = 0;
1370 if (subdata)
1371 sub_name = subdata->filename;
1372 #ifdef CONFIG_ASS
1373 if (ass_track && ass_track->name)
1374 sub_name = ass_track->name;
1375 #endif
1376 if (sub_name) {
1377 char *tmp, *tmp2;
1378 tmp = sub_name;
1379 if ((tmp2 = strrchr(tmp, '/')))
1380 tmp = tmp2 + 1;
1382 snprintf(*(char **) arg, 63, "(%d) %s%s",
1383 mpctx->set_of_sub_pos + 1,
1384 strlen(tmp) < 20 ? "" : "...",
1385 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1386 return M_PROPERTY_OK;
1388 #ifdef CONFIG_DVDNAV
1389 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1390 if (vo_spudec && opts->sub_id >= 0) {
1391 unsigned char lang[3];
1392 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1393 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1394 return M_PROPERTY_OK;
1398 #endif
1400 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1401 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1402 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1403 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1404 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1405 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1406 if (!lang) lang = _("unknown");
1407 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1408 return M_PROPERTY_OK;
1411 if (vo_vobsub && vobsub_id >= 0) {
1412 const char *language = _("unknown");
1413 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1414 snprintf(*(char **) arg, 63, "(%d) %s",
1415 vobsub_id, language ? language : _("unknown"));
1416 return M_PROPERTY_OK;
1418 #ifdef CONFIG_DVDREAD
1419 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1420 && opts->sub_id >= 0) {
1421 char lang[3];
1422 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1423 lang[0] = code >> 8;
1424 lang[1] = code;
1425 lang[2] = 0;
1426 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1427 return M_PROPERTY_OK;
1429 #endif
1430 if (opts->sub_id >= 0) {
1431 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, _("unknown"));
1432 return M_PROPERTY_OK;
1434 snprintf(*(char **) arg, 63, _("disabled"));
1435 return M_PROPERTY_OK;
1437 case M_PROPERTY_SET:
1438 if (!arg)
1439 return M_PROPERTY_ERROR;
1440 if (*(int *) arg < -1)
1441 *(int *) arg = -1;
1442 else if (*(int *) arg >= global_sub_size)
1443 *(int *) arg = global_sub_size - 1;
1444 mpctx->global_sub_pos = *(int *) arg;
1445 break;
1446 case M_PROPERTY_STEP_UP:
1447 mpctx->global_sub_pos += 2;
1448 mpctx->global_sub_pos =
1449 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1450 break;
1451 case M_PROPERTY_STEP_DOWN:
1452 mpctx->global_sub_pos += global_sub_size + 1;
1453 mpctx->global_sub_pos =
1454 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1455 break;
1456 default:
1457 return M_PROPERTY_NOT_IMPLEMENTED;
1460 if (mpctx->global_sub_pos >= 0)
1461 source = sub_source(mpctx);
1463 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1464 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1465 global_sub_size,
1466 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1467 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1468 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1469 mpctx->global_sub_pos, source);
1471 mpctx->set_of_sub_pos = -1;
1472 subdata = NULL;
1474 vobsub_id = -1;
1475 opts->sub_id = -1;
1476 if (d_sub) {
1477 if (d_sub->id > -2)
1478 reset_spu = 1;
1479 d_sub->id = -2;
1481 #ifdef CONFIG_ASS
1482 ass_track = 0;
1483 #endif
1485 if (source == SUB_SOURCE_VOBSUB) {
1486 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1487 } else if (source == SUB_SOURCE_SUBS) {
1488 mpctx->set_of_sub_pos =
1489 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1490 #ifdef CONFIG_ASS
1491 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1492 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1493 else
1494 #endif
1496 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1497 vo_osd_changed(OSDTYPE_SUBTITLE);
1499 } else if (source == SUB_SOURCE_DEMUX) {
1500 opts->sub_id =
1501 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1502 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1503 int i = 0;
1504 // default: assume 1:1 mapping of sid and stream id
1505 d_sub->id = opts->sub_id;
1506 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1507 ds_free_packs(d_sub);
1508 for (i = 0; i < MAX_S_STREAMS; i++) {
1509 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1510 if (sh && sh->sid == opts->sub_id) {
1511 d_sub->id = i;
1512 d_sub->sh = sh;
1513 break;
1516 if (d_sub->sh && d_sub->id >= 0) {
1517 sh_sub_t *sh = d_sub->sh;
1518 if (sh->type == 'v')
1519 init_vo_spudec(mpctx);
1520 #ifdef CONFIG_ASS
1521 else if (ass_enabled)
1522 ass_track = sh->ass_track;
1523 #endif
1524 } else {
1525 d_sub->id = -2;
1526 d_sub->sh = NULL;
1530 #ifdef CONFIG_DVDREAD
1531 if (vo_spudec
1532 && (mpctx->stream->type == STREAMTYPE_DVD
1533 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1534 && opts->sub_id < 0 && reset_spu) {
1535 opts->sub_id = -2;
1536 d_sub->id = opts->sub_id;
1538 #endif
1539 update_subtitles(mpctx->sh_video, d_sub, 0, 1);
1541 return M_PROPERTY_OK;
1544 /// Selected sub source (RW)
1545 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1546 MPContext *mpctx)
1548 int source;
1549 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1550 return M_PROPERTY_UNAVAILABLE;
1552 switch (action) {
1553 case M_PROPERTY_GET:
1554 if (!arg)
1555 return M_PROPERTY_ERROR;
1556 *(int *) arg = sub_source(mpctx);
1557 return M_PROPERTY_OK;
1558 case M_PROPERTY_PRINT:
1559 if (!arg)
1560 return M_PROPERTY_ERROR;
1561 *(char **) arg = malloc(64);
1562 (*(char **) arg)[63] = 0;
1563 switch (sub_source(mpctx))
1565 case SUB_SOURCE_SUBS:
1566 snprintf(*(char **) arg, 63, _("file"));
1567 break;
1568 case SUB_SOURCE_VOBSUB:
1569 snprintf(*(char **) arg, 63, _("vobsub"));
1570 break;
1571 case SUB_SOURCE_DEMUX:
1572 snprintf(*(char **) arg, 63, _("embedded"));
1573 break;
1574 default:
1575 snprintf(*(char **) arg, 63, _("disabled"));
1577 return M_PROPERTY_OK;
1578 case M_PROPERTY_SET:
1579 if (!arg)
1580 return M_PROPERTY_ERROR;
1581 M_PROPERTY_CLAMP(prop, *(int*)arg);
1582 if (*(int *) arg < 0)
1583 mpctx->global_sub_pos = -1;
1584 else if (*(int *) arg != sub_source(mpctx)) {
1585 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1586 return M_PROPERTY_UNAVAILABLE;
1587 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1589 break;
1590 case M_PROPERTY_STEP_UP:
1591 case M_PROPERTY_STEP_DOWN: {
1592 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1593 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1594 int step = (step_all > 0) ? 1 : -1;
1595 int cur_source = sub_source(mpctx);
1596 source = cur_source;
1597 while (step_all) {
1598 source += step;
1599 if (source >= SUB_SOURCES)
1600 source = -1;
1601 else if (source < -1)
1602 source = SUB_SOURCES - 1;
1603 if (source == cur_source || source == -1 ||
1604 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1605 step_all -= step;
1607 if (source == cur_source)
1608 return M_PROPERTY_OK;
1609 if (source == -1)
1610 mpctx->global_sub_pos = -1;
1611 else
1612 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1613 break;
1615 default:
1616 return M_PROPERTY_NOT_IMPLEMENTED;
1618 --mpctx->global_sub_pos;
1619 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1622 /// Selected subtitles from specific source (RW)
1623 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1624 MPContext *mpctx)
1626 int source, is_cur_source, offset;
1627 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1628 return M_PROPERTY_UNAVAILABLE;
1630 if (!strcmp(prop->name, "sub_file"))
1631 source = SUB_SOURCE_SUBS;
1632 else if (!strcmp(prop->name, "sub_vob"))
1633 source = SUB_SOURCE_VOBSUB;
1634 else if (!strcmp(prop->name, "sub_demux"))
1635 source = SUB_SOURCE_DEMUX;
1636 else
1637 return M_PROPERTY_ERROR;
1639 offset = mpctx->global_sub_indices[source];
1640 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1641 return M_PROPERTY_UNAVAILABLE;
1643 is_cur_source = sub_source(mpctx) == source;
1644 switch (action) {
1645 case M_PROPERTY_GET:
1646 if (!arg)
1647 return M_PROPERTY_ERROR;
1648 if (is_cur_source) {
1649 *(int *) arg = mpctx->global_sub_pos - offset;
1650 if (source == SUB_SOURCE_VOBSUB)
1651 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1653 else
1654 *(int *) arg = -1;
1655 return M_PROPERTY_OK;
1656 case M_PROPERTY_PRINT:
1657 if (!arg)
1658 return M_PROPERTY_ERROR;
1659 if (is_cur_source)
1660 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1661 *(char **) arg = malloc(64);
1662 (*(char **) arg)[63] = 0;
1663 snprintf(*(char **) arg, 63, _("disabled"));
1664 return M_PROPERTY_OK;
1665 case M_PROPERTY_SET:
1666 if (!arg)
1667 return M_PROPERTY_ERROR;
1668 if (*(int *) arg >= 0) {
1669 int index = *(int *)arg;
1670 if (source == SUB_SOURCE_VOBSUB)
1671 index = vobsub_get_index_by_id(vo_vobsub, index);
1672 mpctx->global_sub_pos = offset + index;
1673 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1674 || sub_source(mpctx) != source) {
1675 mpctx->global_sub_pos = -1;
1676 *(int *) arg = -1;
1679 else
1680 mpctx->global_sub_pos = -1;
1681 break;
1682 case M_PROPERTY_STEP_UP:
1683 case M_PROPERTY_STEP_DOWN: {
1684 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1685 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1686 int step = (step_all > 0) ? 1 : -1;
1687 int max_sub_pos_for_source = -1;
1688 if (!is_cur_source)
1689 mpctx->global_sub_pos = -1;
1690 while (step_all) {
1691 if (mpctx->global_sub_pos == -1) {
1692 if (step > 0)
1693 mpctx->global_sub_pos = offset;
1694 else if (max_sub_pos_for_source == -1) {
1695 // Find max pos for specific source
1696 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1697 while (mpctx->global_sub_pos >= 0
1698 && sub_source(mpctx) != source)
1699 --mpctx->global_sub_pos;
1701 else
1702 mpctx->global_sub_pos = max_sub_pos_for_source;
1704 else {
1705 mpctx->global_sub_pos += step;
1706 if (mpctx->global_sub_pos < offset ||
1707 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1708 sub_source(mpctx) != source)
1709 mpctx->global_sub_pos = -1;
1711 step_all -= step;
1713 break;
1715 default:
1716 return M_PROPERTY_NOT_IMPLEMENTED;
1718 --mpctx->global_sub_pos;
1719 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1722 /// Subtitle delay (RW)
1723 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1724 MPContext *mpctx)
1726 if (!mpctx->sh_video)
1727 return M_PROPERTY_UNAVAILABLE;
1728 return m_property_delay(prop, action, arg, &sub_delay);
1731 /// Alignment of text subtitles (RW)
1732 static int mp_property_sub_alignment(m_option_t *prop, int action,
1733 void *arg, MPContext *mpctx)
1735 char *name[] = { _("top"), _("center"), _("bottom") };
1737 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1738 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1739 return M_PROPERTY_UNAVAILABLE;
1741 switch (action) {
1742 case M_PROPERTY_PRINT:
1743 if (!arg)
1744 return M_PROPERTY_ERROR;
1745 M_PROPERTY_CLAMP(prop, sub_alignment);
1746 *(char **) arg = strdup(name[sub_alignment]);
1747 return M_PROPERTY_OK;
1748 case M_PROPERTY_SET:
1749 if (!arg)
1750 return M_PROPERTY_ERROR;
1751 case M_PROPERTY_STEP_UP:
1752 case M_PROPERTY_STEP_DOWN:
1753 vo_osd_changed(OSDTYPE_SUBTITLE);
1754 default:
1755 return m_property_choice(prop, action, arg, &sub_alignment);
1759 /// Subtitle visibility (RW)
1760 static int mp_property_sub_visibility(m_option_t *prop, int action,
1761 void *arg, MPContext *mpctx)
1763 if (!mpctx->sh_video)
1764 return M_PROPERTY_UNAVAILABLE;
1766 switch (action) {
1767 case M_PROPERTY_SET:
1768 if (!arg)
1769 return M_PROPERTY_ERROR;
1770 case M_PROPERTY_STEP_UP:
1771 case M_PROPERTY_STEP_DOWN:
1772 vo_osd_changed(OSDTYPE_SUBTITLE);
1773 if (vo_spudec)
1774 vo_osd_changed(OSDTYPE_SPU);
1775 default:
1776 return m_property_flag(prop, action, arg, &sub_visibility);
1780 #ifdef CONFIG_ASS
1781 /// Use margins for libass subtitles (RW)
1782 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1783 void *arg, MPContext *mpctx)
1785 if (!mpctx->sh_video)
1786 return M_PROPERTY_UNAVAILABLE;
1788 switch (action) {
1789 case M_PROPERTY_SET:
1790 if (!arg)
1791 return M_PROPERTY_ERROR;
1792 case M_PROPERTY_STEP_UP:
1793 case M_PROPERTY_STEP_DOWN:
1794 ass_force_reload = 1;
1795 default:
1796 return m_property_flag(prop, action, arg, &ass_use_margins);
1799 #endif
1801 /// Show only forced subtitles (RW)
1802 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1803 void *arg, MPContext *mpctx)
1805 if (!vo_spudec)
1806 return M_PROPERTY_UNAVAILABLE;
1808 switch (action) {
1809 case M_PROPERTY_SET:
1810 if (!arg)
1811 return M_PROPERTY_ERROR;
1812 case M_PROPERTY_STEP_UP:
1813 case M_PROPERTY_STEP_DOWN:
1814 m_property_flag(prop, action, arg, &forced_subs_only);
1815 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1816 return M_PROPERTY_OK;
1817 default:
1818 return m_property_flag(prop, action, arg, &forced_subs_only);
1823 #ifdef CONFIG_FREETYPE
1824 /// Subtitle scale (RW)
1825 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1826 MPContext *mpctx)
1829 switch (action) {
1830 case M_PROPERTY_SET:
1831 if (!arg)
1832 return M_PROPERTY_ERROR;
1833 M_PROPERTY_CLAMP(prop, *(float *) arg);
1834 #ifdef CONFIG_ASS
1835 if (ass_enabled) {
1836 ass_font_scale = *(float *) arg;
1837 ass_force_reload = 1;
1839 #endif
1840 text_font_scale_factor = *(float *) arg;
1841 force_load_font = 1;
1842 return M_PROPERTY_OK;
1843 case M_PROPERTY_STEP_UP:
1844 case M_PROPERTY_STEP_DOWN:
1845 #ifdef CONFIG_ASS
1846 if (ass_enabled) {
1847 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1848 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1849 M_PROPERTY_CLAMP(prop, ass_font_scale);
1850 ass_force_reload = 1;
1852 #endif
1853 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1854 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1855 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1856 force_load_font = 1;
1857 return M_PROPERTY_OK;
1858 default:
1859 #ifdef CONFIG_ASS
1860 if (ass_enabled)
1861 return m_property_float_ro(prop, action, arg, ass_font_scale);
1862 else
1863 #endif
1864 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1867 #endif
1869 ///@}
1871 /// \defgroup TVProperties TV properties
1872 /// \ingroup Properties
1873 ///@{
1875 #ifdef CONFIG_TV
1877 /// TV color settings (RW)
1878 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1879 MPContext *mpctx)
1881 int r, val;
1882 tvi_handle_t *tvh = mpctx->demuxer->priv;
1883 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1884 return M_PROPERTY_UNAVAILABLE;
1886 switch (action) {
1887 case M_PROPERTY_SET:
1888 if (!arg)
1889 return M_PROPERTY_ERROR;
1890 M_PROPERTY_CLAMP(prop, *(int *) arg);
1891 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1892 case M_PROPERTY_GET:
1893 return tv_get_color_options(tvh, (int) prop->priv, arg);
1894 case M_PROPERTY_STEP_UP:
1895 case M_PROPERTY_STEP_DOWN:
1896 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1897 if (!r)
1898 return M_PROPERTY_ERROR;
1899 val += (arg ? *(int *) arg : 1) *
1900 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1901 M_PROPERTY_CLAMP(prop, val);
1902 return tv_set_color_options(tvh, (int) prop->priv, val);
1904 return M_PROPERTY_ERROR;
1906 return M_PROPERTY_NOT_IMPLEMENTED;
1909 #endif
1911 #ifdef CONFIG_TV_TELETEXT
1912 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1913 MPContext *mpctx)
1915 int val,result;
1916 int base_ioctl=(int)prop->priv;
1918 for teletext's GET,SET,STEP ioctls this is not 0
1919 SET is GET+1
1920 STEP is GET+2
1922 tvi_handle_t *tvh = mpctx->demuxer->priv;
1923 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1924 return M_PROPERTY_UNAVAILABLE;
1925 if(!base_ioctl)
1926 return M_PROPERTY_ERROR;
1928 switch (action) {
1929 case M_PROPERTY_GET:
1930 if (!arg)
1931 return M_PROPERTY_ERROR;
1932 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1933 break;
1934 case M_PROPERTY_SET:
1935 if (!arg)
1936 return M_PROPERTY_ERROR;
1937 M_PROPERTY_CLAMP(prop, *(int *) arg);
1938 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1939 break;
1940 case M_PROPERTY_STEP_UP:
1941 case M_PROPERTY_STEP_DOWN:
1942 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1943 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1944 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1945 break;
1946 default:
1947 return M_PROPERTY_NOT_IMPLEMENTED;
1950 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1953 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
1954 MPContext *mpctx)
1956 tvi_handle_t *tvh = mpctx->demuxer->priv;
1957 int result;
1958 int val;
1960 //with tvh==NULL will fail too
1961 result=mp_property_teletext_common(prop,action,arg,mpctx);
1962 if(result!=M_PROPERTY_OK)
1963 return result;
1965 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1966 mp_input_set_section(mpctx->input, "teletext");
1967 else
1968 mp_input_set_section(mpctx->input, "tv");
1969 return M_PROPERTY_OK;
1972 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
1973 MPContext *mpctx)
1975 tvi_handle_t *tvh = mpctx->demuxer->priv;
1976 int result;
1977 int val;
1978 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1979 return M_PROPERTY_UNAVAILABLE;
1980 switch(action){
1981 case M_PROPERTY_STEP_UP:
1982 case M_PROPERTY_STEP_DOWN:
1983 //This should be handled separately
1984 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1985 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1986 break;
1987 default:
1988 result=mp_property_teletext_common(prop,action,arg,mpctx);
1990 return result;
1994 #endif /* CONFIG_TV_TELETEXT */
1996 ///@}
1998 /// All properties available in MPlayer.
1999 /** \ingroup Properties
2001 static const m_option_t mp_properties[] = {
2002 // General
2003 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2004 M_OPT_RANGE, 0, 3, NULL },
2005 { "loop", mp_property_loop, CONF_TYPE_INT,
2006 M_OPT_MIN, -1, 0, NULL },
2007 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2008 M_OPT_RANGE, 0.01, 100.0, NULL },
2009 { "filename", mp_property_filename, CONF_TYPE_STRING,
2010 0, 0, 0, NULL },
2011 { "path", mp_property_path, CONF_TYPE_STRING,
2012 0, 0, 0, NULL },
2013 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2014 0, 0, 0, NULL },
2015 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2016 M_OPT_MIN, 0, 0, NULL },
2017 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2018 M_OPT_MIN, 0, 0, NULL },
2019 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2020 M_OPT_MIN, 0, 0, NULL },
2021 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2022 M_OPT_MIN, 0, 0, NULL },
2023 { "length", mp_property_length, CONF_TYPE_TIME,
2024 M_OPT_MIN, 0, 0, NULL },
2025 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2026 M_OPT_RANGE, 0, 100, NULL },
2027 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2028 M_OPT_MIN, 0, 0, NULL },
2029 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2030 M_OPT_MIN, 0, 0, NULL },
2031 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2032 0, 0, 0, NULL },
2033 { "angle", mp_property_angle, CONF_TYPE_INT,
2034 CONF_RANGE, -2, 10, NULL },
2035 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2036 0, 0, 0, NULL },
2037 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2038 M_OPT_RANGE, 0, 1, NULL },
2040 // Audio
2041 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2042 M_OPT_RANGE, 0, 100, NULL },
2043 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2044 M_OPT_RANGE, 0, 1, NULL },
2045 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2046 M_OPT_RANGE, -100, 100, NULL },
2047 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2048 0, 0, 0, NULL },
2049 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2050 0, 0, 0, NULL },
2051 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2052 0, 0, 0, NULL },
2053 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2054 0, 0, 0, NULL },
2055 { "channels", mp_property_channels, CONF_TYPE_INT,
2056 0, 0, 0, NULL },
2057 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2058 CONF_RANGE, -2, 65535, NULL },
2059 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2060 M_OPT_RANGE, -1, 1, NULL },
2062 // Video
2063 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2064 M_OPT_RANGE, 0, 1, NULL },
2065 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2066 M_OPT_RANGE, 0, 1, NULL },
2067 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2068 M_OPT_RANGE, 0, 1, NULL },
2069 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2070 M_OPT_RANGE, 0, 1, NULL },
2071 { "border", mp_property_border, CONF_TYPE_FLAG,
2072 M_OPT_RANGE, 0, 1, NULL },
2073 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2074 M_OPT_RANGE, 0, 2, NULL },
2075 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2076 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2077 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2078 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2079 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2080 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2081 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2082 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2083 { "hue", mp_property_gamma, CONF_TYPE_INT,
2084 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2085 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2086 M_OPT_RANGE, 0, 1, NULL },
2087 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2088 M_OPT_RANGE, 0, 1, NULL },
2089 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2090 0, 0, 0, NULL },
2091 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2092 0, 0, 0, NULL },
2093 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2094 0, 0, 0, NULL },
2095 { "width", mp_property_width, CONF_TYPE_INT,
2096 0, 0, 0, NULL },
2097 { "height", mp_property_height, CONF_TYPE_INT,
2098 0, 0, 0, NULL },
2099 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2100 0, 0, 0, NULL },
2101 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2102 0, 0, 0, NULL },
2103 { "switch_video", mp_property_video, CONF_TYPE_INT,
2104 CONF_RANGE, -2, 65535, NULL },
2105 { "switch_program", mp_property_program, CONF_TYPE_INT,
2106 CONF_RANGE, -1, 65535, NULL },
2108 // Subs
2109 { "sub", mp_property_sub, CONF_TYPE_INT,
2110 M_OPT_MIN, -1, 0, NULL },
2111 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2112 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2113 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2114 M_OPT_MIN, -1, 0, NULL },
2115 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2116 M_OPT_MIN, -1, 0, NULL },
2117 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2118 M_OPT_MIN, -1, 0, NULL },
2119 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2120 0, 0, 0, NULL },
2121 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2122 M_OPT_RANGE, 0, 100, NULL },
2123 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2124 M_OPT_RANGE, 0, 2, NULL },
2125 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2126 M_OPT_RANGE, 0, 1, NULL },
2127 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2128 M_OPT_RANGE, 0, 1, NULL },
2129 #ifdef CONFIG_FREETYPE
2130 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2131 M_OPT_RANGE, 0, 100, NULL },
2132 #endif
2133 #ifdef CONFIG_ASS
2134 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2135 M_OPT_RANGE, 0, 1, NULL },
2136 #endif
2138 #ifdef CONFIG_TV
2139 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2140 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2141 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2142 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2143 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2144 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2145 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2146 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2147 #endif
2149 #ifdef CONFIG_TV_TELETEXT
2150 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2151 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2152 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2153 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2154 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2155 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2156 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2157 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2158 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2159 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2160 #endif
2162 { NULL, NULL, NULL, 0, 0, 0, NULL }
2166 int mp_property_do(const char *name, int action, void *val, void *ctx)
2168 return m_property_do(mp_properties, name, action, val, ctx);
2171 char* mp_property_print(const char *name, void* ctx)
2173 char* ret = NULL;
2174 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2175 return NULL;
2176 return ret;
2179 char *property_expand_string(MPContext *mpctx, char *str)
2181 return m_properties_expand_string(mp_properties, str, mpctx);
2184 void property_print_help(void)
2186 m_properties_print_help_list(mp_properties);
2190 ///@}
2191 // Properties group
2195 * \defgroup Command2Property Command to property bridge
2197 * It is used to handle most commands that just set a property
2198 * and optionally display something on the OSD.
2199 * Two kinds of commands are handled: adjust or toggle.
2201 * Adjust commands take 1 or 2 parameters: <value> <abs>
2202 * If <abs> is non-zero the property is set to the given value
2203 * otherwise it is adjusted.
2205 * Toggle commands take 0 or 1 parameters. With no parameter
2206 * or a value less than the property minimum it just steps the
2207 * property to its next value. Otherwise it sets it to the given
2208 * value.
2213 /// List of the commands that can be handled by setting a property.
2214 static struct {
2215 /// property name
2216 const char *name;
2217 /// cmd id
2218 int cmd;
2219 /// set/adjust or toggle command
2220 int toggle;
2221 /// progressbar type
2222 int osd_progbar; // -1 is special value for seek indicators
2223 /// osd msg id if it must be shared
2224 int osd_id;
2225 /// osd msg template
2226 const char *osd_msg;
2227 } set_prop_cmd[] = {
2228 // general
2229 { "loop", MP_CMD_LOOP, 0, 0, -1, _("Loop: %s") },
2230 { "chapter", MP_CMD_SEEK_CHAPTER, 0, -1, -1, NULL },
2231 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2232 { "pause", MP_CMD_PAUSE, 0, 0, -1, NULL },
2233 // audio
2234 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, _("Volume") },
2235 { "mute", MP_CMD_MUTE, 1, 0, -1, _("Mute: %s") },
2236 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, _("A-V delay: %s") },
2237 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, _("Audio: %s") },
2238 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, _("Balance") },
2239 // video
2240 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2241 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, _("Panscan") },
2242 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, _("Stay on top: %s") },
2243 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, _("Rootwin: %s") },
2244 { "border", MP_CMD_VO_BORDER, 1, 0, -1, _("Border: %s") },
2245 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, _("Framedropping: %s") },
2246 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, _("Gamma") },
2247 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, _("Brightness") },
2248 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, _("Contrast") },
2249 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, _("Saturation") },
2250 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, _("Hue") },
2251 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, _("VSync: %s") },
2252 // subs
2253 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, _("Subtitles: %s") },
2254 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, _("Sub source: %s") },
2255 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, _("Subtitles: %s") },
2256 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, _("Subtitles: %s") },
2257 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, _("Subtitles: %s") },
2258 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, _("Sub position: %s/100") },
2259 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, _("Sub alignment: %s") },
2260 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2261 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, _("Subtitles: %s") },
2262 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, _("Forced sub only: %s") },
2263 #ifdef CONFIG_FREETYPE
2264 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, _("Sub Scale: %s")},
2265 #endif
2266 #ifdef CONFIG_ASS
2267 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2268 #endif
2269 #ifdef CONFIG_TV
2270 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, _("Brightness") },
2271 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, _("Hue") },
2272 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, _("Saturation") },
2273 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, _("Contrast") },
2274 #endif
2275 { NULL, 0, 0, 0, -1, NULL }
2279 /// Handle commands that set a property.
2280 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2282 struct MPOpts *opts = &mpctx->opts;
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 == -1)
2313 mpctx->add_osd_seek_info = true;
2314 else if (set_prop_cmd[i].osd_progbar) {
2315 if (prop->type == CONF_TYPE_INT) {
2316 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2317 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2318 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2319 } else if (prop->type == CONF_TYPE_FLOAT) {
2320 float f;
2321 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2322 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2323 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2324 } else
2325 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2326 "Property use an unsupported type.\n");
2327 return 1;
2330 if (set_prop_cmd[i].osd_msg) {
2331 char *val = mp_property_print(pname, mpctx);
2332 if (val) {
2333 set_osd_msg(set_prop_cmd[i].osd_id >=
2334 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2335 1, opts->osd_duration, set_prop_cmd[i].osd_msg, val);
2336 free(val);
2339 return 1;
2342 #ifdef CONFIG_DVDNAV
2343 static const struct {
2344 const char *name;
2345 const mp_command_type cmd;
2346 } mp_dvdnav_bindings[] = {
2347 { "up", MP_CMD_DVDNAV_UP },
2348 { "down", MP_CMD_DVDNAV_DOWN },
2349 { "left", MP_CMD_DVDNAV_LEFT },
2350 { "right", MP_CMD_DVDNAV_RIGHT },
2351 { "menu", MP_CMD_DVDNAV_MENU },
2352 { "select", MP_CMD_DVDNAV_SELECT },
2353 { "prev", MP_CMD_DVDNAV_PREVMENU },
2354 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2357 * keep old dvdnav sub-command options for a while in order not to
2358 * break slave-mode API too suddenly.
2360 { "1", MP_CMD_DVDNAV_UP },
2361 { "2", MP_CMD_DVDNAV_DOWN },
2362 { "3", MP_CMD_DVDNAV_LEFT },
2363 { "4", MP_CMD_DVDNAV_RIGHT },
2364 { "5", MP_CMD_DVDNAV_MENU },
2365 { "6", MP_CMD_DVDNAV_SELECT },
2366 { "7", MP_CMD_DVDNAV_PREVMENU },
2367 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2368 { NULL, 0 }
2370 #endif
2372 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2374 struct MPOpts *opts = &mpctx->opts;
2375 sh_audio_t * const sh_audio = mpctx->sh_audio;
2376 sh_video_t * const sh_video = mpctx->sh_video;
2377 int osd_duration = opts->osd_duration;
2378 if (!set_property_command(mpctx, cmd))
2379 switch (cmd->id) {
2380 case MP_CMD_SEEK:{
2381 float v;
2382 int abs;
2383 mpctx->add_osd_seek_info = true;
2384 v = cmd->args[0].v.f;
2385 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2386 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2387 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2388 if (sh_video)
2389 mpctx->osd_function =
2390 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2391 mpctx->rel_seek_secs = v;
2392 } else if (abs) { /* Absolute seek by percentage */
2393 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2394 if (sh_video)
2395 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2396 mpctx->rel_seek_secs = v / 100.0;
2397 } else {
2398 mpctx->rel_seek_secs += v;
2399 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2402 break;
2404 case MP_CMD_SET_PROPERTY:{
2405 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2406 cmd->args[1].v.s, mpctx);
2407 if (r == M_PROPERTY_UNKNOWN)
2408 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2409 "Unknown property: '%s'\n", cmd->args[0].v.s);
2410 else if (r <= 0)
2411 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2412 "Failed to set property '%s' to '%s'.\n",
2413 cmd->args[0].v.s, cmd->args[1].v.s);
2415 break;
2417 case MP_CMD_STEP_PROPERTY:{
2418 void* arg = NULL;
2419 int r,i;
2420 double d;
2421 off_t o;
2422 if (cmd->args[1].v.f) {
2423 m_option_t* prop;
2424 if((r = mp_property_do(cmd->args[0].v.s,
2425 M_PROPERTY_GET_TYPE,
2426 &prop, mpctx)) <= 0)
2427 goto step_prop_err;
2428 if(prop->type == CONF_TYPE_INT ||
2429 prop->type == CONF_TYPE_FLAG)
2430 i = cmd->args[1].v.f, arg = &i;
2431 else if(prop->type == CONF_TYPE_FLOAT)
2432 arg = &cmd->args[1].v.f;
2433 else if(prop->type == CONF_TYPE_DOUBLE ||
2434 prop->type == CONF_TYPE_TIME)
2435 d = cmd->args[1].v.f, arg = &d;
2436 else if(prop->type == CONF_TYPE_POSITION)
2437 o = cmd->args[1].v.f, arg = &o;
2438 else
2439 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2440 "Ignoring step size stepping property '%s'.\n",
2441 cmd->args[0].v.s);
2443 r = mp_property_do(cmd->args[0].v.s,
2444 cmd->args[2].v.i < 0 ?
2445 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2446 arg, mpctx);
2447 step_prop_err:
2448 if (r == M_PROPERTY_UNKNOWN)
2449 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2450 "Unknown property: '%s'\n", cmd->args[0].v.s);
2451 else if (r <= 0)
2452 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2453 "Failed to increment property '%s' by %f.\n",
2454 cmd->args[0].v.s, cmd->args[1].v.f);
2456 break;
2458 case MP_CMD_GET_PROPERTY:{
2459 char *tmp;
2460 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2461 &tmp, mpctx) <= 0) {
2462 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2463 "Failed to get value of property '%s'.\n",
2464 cmd->args[0].v.s);
2465 break;
2467 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2468 cmd->args[0].v.s, tmp);
2469 free(tmp);
2471 break;
2473 case MP_CMD_EDL_MARK:
2474 if (edl_fd) {
2475 float v = sh_video ? sh_video->pts :
2476 playing_audio_pts(mpctx);
2477 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2478 mpctx->begin_skip = v;
2479 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2480 } else {
2481 if (mpctx->begin_skip > v)
2482 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2483 else {
2484 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2485 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2487 mpctx->begin_skip = MP_NOPTS_VALUE;
2490 break;
2492 case MP_CMD_SWITCH_RATIO:
2493 if (!sh_video)
2494 break;
2495 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2496 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2497 else
2498 opts->movie_aspect = cmd->args[0].v.f;
2499 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2500 break;
2502 case MP_CMD_SPEED_INCR:{
2503 float v = cmd->args[0].v.f;
2504 opts->playback_speed += v;
2505 build_afilter_chain(mpctx, sh_audio, &ao_data);
2506 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2507 opts->playback_speed);
2508 } break;
2510 case MP_CMD_SPEED_MULT:{
2511 float v = cmd->args[0].v.f;
2512 opts->playback_speed *= v;
2513 build_afilter_chain(mpctx, sh_audio, &ao_data);
2514 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2515 opts->playback_speed);
2516 } break;
2518 case MP_CMD_SPEED_SET:{
2519 float v = cmd->args[0].v.f;
2520 opts->playback_speed = v;
2521 build_afilter_chain(mpctx, sh_audio, &ao_data);
2522 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2523 opts->playback_speed);
2524 } break;
2526 case MP_CMD_FRAME_STEP:
2527 add_step_frame(mpctx);
2528 break;
2530 case MP_CMD_FILE_FILTER:
2531 file_filter = cmd->args[0].v.i;
2532 break;
2534 case MP_CMD_QUIT:
2535 exit_player_with_rc(mpctx, EXIT_QUIT,
2536 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2538 case MP_CMD_PLAY_TREE_STEP:{
2539 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2540 int force = cmd->args[1].v.i;
2543 if (!force && mpctx->playtree_iter) {
2544 play_tree_iter_t *i =
2545 play_tree_iter_new_copy(mpctx->playtree_iter);
2546 if (play_tree_iter_step(i, n, 0) ==
2547 PLAY_TREE_ITER_ENTRY)
2548 mpctx->stop_play =
2549 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2550 play_tree_iter_free(i);
2551 } else
2552 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2553 if (mpctx->stop_play)
2554 mpctx->play_tree_step = n;
2557 break;
2559 case MP_CMD_PLAY_TREE_UP_STEP:{
2560 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2561 int force = cmd->args[1].v.i;
2563 if (!force && mpctx->playtree_iter) {
2564 play_tree_iter_t *i =
2565 play_tree_iter_new_copy(mpctx->playtree_iter);
2566 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2567 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2568 play_tree_iter_free(i);
2569 } else
2570 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2572 break;
2574 case MP_CMD_PLAY_ALT_SRC_STEP:
2575 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2576 int v = cmd->args[0].v.i;
2577 if (v > 0
2578 && mpctx->playtree_iter->file <
2579 mpctx->playtree_iter->num_files)
2580 mpctx->stop_play = PT_NEXT_SRC;
2581 else if (v < 0 && mpctx->playtree_iter->file > 1)
2582 mpctx->stop_play = PT_PREV_SRC;
2584 break;
2586 case MP_CMD_SUB_STEP:
2587 if (sh_video) {
2588 int movement = cmd->args[0].v.i;
2589 step_sub(subdata, sh_video->pts, movement);
2590 #ifdef CONFIG_ASS
2591 if (ass_track)
2592 sub_delay +=
2593 ass_step_sub(ass_track,
2594 (sh_video->pts +
2595 sub_delay) * 1000 + .5, movement) / 1000.;
2596 #endif
2597 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2598 _("Sub delay: %d ms"), ROUND(sub_delay * 1000));
2600 break;
2602 case MP_CMD_SUB_LOG:
2603 log_sub(mpctx);
2604 break;
2606 case MP_CMD_OSD:{
2607 int v = cmd->args[0].v.i;
2608 int max = (term_osd
2609 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2610 if (opts->osd_level > max)
2611 opts->osd_level = max;
2612 if (v < 0)
2613 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2614 else
2615 opts->osd_level = v > max ? max : v;
2616 /* Show OSD state when disabled, but not when an explicit
2617 argument is given to the OSD command, i.e. in slave mode. */
2618 if (v == -1 && opts->osd_level <= 1)
2619 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2620 _("OSD: %s"),
2621 opts->osd_level ? _("enabled") :
2622 _("disabled"));
2623 else
2624 rm_osd_msg(OSD_MSG_OSD_STATUS);
2626 break;
2628 case MP_CMD_OSD_SHOW_TEXT:
2629 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2630 (cmd->args[1].v.i <
2631 0 ? osd_duration : cmd->args[1].v.i),
2632 "%-.63s", cmd->args[0].v.s);
2633 break;
2635 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2636 char *txt = m_properties_expand_string(mp_properties,
2637 cmd->args[0].v.s,
2638 mpctx);
2639 /* if no argument supplied take default osd_duration, else <arg> ms. */
2640 if (txt) {
2641 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2642 (cmd->args[1].v.i <
2643 0 ? osd_duration : cmd->args[1].v.i),
2644 "%-.63s", txt);
2645 free(txt);
2648 break;
2650 case MP_CMD_LOADFILE:{
2651 play_tree_t *e = play_tree_new();
2652 play_tree_add_file(e, cmd->args[0].v.s);
2654 if (cmd->args[1].v.i) // append
2655 play_tree_append_entry(mpctx->playtree->child, e);
2656 else {
2657 // Go back to the starting point.
2658 while (play_tree_iter_up_step
2659 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2660 /* NOP */ ;
2661 play_tree_free_list(mpctx->playtree->child, 1);
2662 play_tree_set_child(mpctx->playtree, e);
2663 pt_iter_goto_head(mpctx->playtree_iter);
2664 mpctx->stop_play = PT_NEXT_SRC;
2667 break;
2669 case MP_CMD_LOADLIST:{
2670 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2671 if (!e)
2672 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2673 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2674 else {
2675 if (cmd->args[1].v.i) // append
2676 play_tree_append_entry(mpctx->playtree->child, e);
2677 else {
2678 // Go back to the starting point.
2679 while (play_tree_iter_up_step
2680 (mpctx->playtree_iter, 0, 1)
2681 != PLAY_TREE_ITER_END)
2682 /* NOP */ ;
2683 play_tree_free_list(mpctx->playtree->child, 1);
2684 play_tree_set_child(mpctx->playtree, e);
2685 pt_iter_goto_head(mpctx->playtree_iter);
2686 mpctx->stop_play = PT_NEXT_SRC;
2690 break;
2692 case MP_CMD_STOP:
2693 // Go back to the starting point.
2694 while (play_tree_iter_up_step
2695 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2696 /* NOP */ ;
2697 mpctx->stop_play = PT_STOP;
2698 break;
2700 #ifdef CONFIG_RADIO
2701 case MP_CMD_RADIO_STEP_CHANNEL:
2702 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2703 int v = cmd->args[0].v.i;
2704 if (v > 0)
2705 radio_step_channel(mpctx->demuxer->stream,
2706 RADIO_CHANNEL_HIGHER);
2707 else
2708 radio_step_channel(mpctx->demuxer->stream,
2709 RADIO_CHANNEL_LOWER);
2710 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2711 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2712 _("Channel: %s"),
2713 radio_get_channel_name(mpctx->demuxer->stream));
2716 break;
2718 case MP_CMD_RADIO_SET_CHANNEL:
2719 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2720 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2721 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2722 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2723 _("Channel: %s"),
2724 radio_get_channel_name(mpctx->demuxer->stream));
2727 break;
2729 case MP_CMD_RADIO_SET_FREQ:
2730 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2731 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2732 break;
2734 case MP_CMD_RADIO_STEP_FREQ:
2735 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2736 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2737 break;
2738 #endif
2740 #ifdef CONFIG_TV
2741 case MP_CMD_TV_START_SCAN:
2742 if (mpctx->file_format == DEMUXER_TYPE_TV)
2743 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2744 break;
2745 case MP_CMD_TV_SET_FREQ:
2746 if (mpctx->file_format == DEMUXER_TYPE_TV)
2747 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2748 cmd->args[0].v.f * 16.0);
2749 #ifdef CONFIG_PVR
2750 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2751 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2752 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2753 pvr_get_current_channelname (mpctx->stream),
2754 pvr_get_current_stationname (mpctx->stream));
2756 #endif /* CONFIG_PVR */
2757 break;
2759 case MP_CMD_TV_STEP_FREQ:
2760 if (mpctx->file_format == DEMUXER_TYPE_TV)
2761 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2762 cmd->args[0].v.f * 16.0);
2763 #ifdef CONFIG_PVR
2764 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2765 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2766 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2767 pvr_get_current_channelname (mpctx->stream),
2768 pvr_get_current_frequency (mpctx->stream));
2770 #endif /* CONFIG_PVR */
2771 break;
2773 case MP_CMD_TV_SET_NORM:
2774 if (mpctx->file_format == DEMUXER_TYPE_TV)
2775 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2776 cmd->args[0].v.s);
2777 break;
2779 case MP_CMD_TV_STEP_CHANNEL:{
2780 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2781 int v = cmd->args[0].v.i;
2782 if (v > 0) {
2783 tv_step_channel((tvi_handle_t *) (mpctx->
2784 demuxer->priv),
2785 TV_CHANNEL_HIGHER);
2786 } else {
2787 tv_step_channel((tvi_handle_t *) (mpctx->
2788 demuxer->priv),
2789 TV_CHANNEL_LOWER);
2791 if (tv_channel_list) {
2792 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2793 _("Channel: %s"), tv_channel_current->name);
2794 //vo_osd_changed(OSDTYPE_SUBTITLE);
2797 #ifdef CONFIG_PVR
2798 else if (mpctx->stream &&
2799 mpctx->stream->type == STREAMTYPE_PVR) {
2800 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2801 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2802 pvr_get_current_channelname (mpctx->stream),
2803 pvr_get_current_stationname (mpctx->stream));
2805 #endif /* CONFIG_PVR */
2807 #ifdef CONFIG_DVBIN
2808 if (mpctx->stream->type == STREAMTYPE_DVB) {
2809 int dir;
2810 int v = cmd->args[0].v.i;
2812 mpctx->last_dvb_step = v;
2813 if (v > 0)
2814 dir = DVB_CHANNEL_HIGHER;
2815 else
2816 dir = DVB_CHANNEL_LOWER;
2819 if (dvb_step_channel(mpctx->stream, dir)) {
2820 mpctx->stop_play = PT_NEXT_ENTRY;
2821 mpctx->dvbin_reopen = 1;
2824 #endif /* CONFIG_DVBIN */
2825 break;
2827 case MP_CMD_TV_SET_CHANNEL:
2828 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2829 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2830 cmd->args[0].v.s);
2831 if (tv_channel_list) {
2832 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2833 _("Channel: %s"), tv_channel_current->name);
2834 //vo_osd_changed(OSDTYPE_SUBTITLE);
2837 #ifdef CONFIG_PVR
2838 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2839 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2840 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2841 pvr_get_current_channelname (mpctx->stream),
2842 pvr_get_current_stationname (mpctx->stream));
2844 #endif /* CONFIG_PVR */
2845 break;
2847 #ifdef CONFIG_DVBIN
2848 case MP_CMD_DVB_SET_CHANNEL:
2849 if (mpctx->stream->type == STREAMTYPE_DVB) {
2850 mpctx->last_dvb_step = 1;
2852 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
2853 cmd->args[0].v.i)) {
2854 mpctx->stop_play = PT_NEXT_ENTRY;
2855 mpctx->dvbin_reopen = 1;
2858 break;
2859 #endif /* CONFIG_DVBIN */
2861 case MP_CMD_TV_LAST_CHANNEL:
2862 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2863 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2864 if (tv_channel_list) {
2865 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2866 _("Channel: %s"), tv_channel_current->name);
2867 //vo_osd_changed(OSDTYPE_SUBTITLE);
2870 #ifdef CONFIG_PVR
2871 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2872 pvr_set_lastchannel (mpctx->stream);
2873 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2874 pvr_get_current_channelname (mpctx->stream),
2875 pvr_get_current_stationname (mpctx->stream));
2877 #endif /* CONFIG_PVR */
2878 break;
2880 case MP_CMD_TV_STEP_NORM:
2881 if (mpctx->file_format == DEMUXER_TYPE_TV)
2882 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2883 break;
2885 case MP_CMD_TV_STEP_CHANNEL_LIST:
2886 if (mpctx->file_format == DEMUXER_TYPE_TV)
2887 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2888 break;
2889 #ifdef CONFIG_TV_TELETEXT
2890 case MP_CMD_TV_TELETEXT_ADD_DEC:
2892 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2893 if (mpctx->file_format == DEMUXER_TYPE_TV)
2894 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2895 break;
2897 case MP_CMD_TV_TELETEXT_GO_LINK:
2899 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2900 if (mpctx->file_format == DEMUXER_TYPE_TV)
2901 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2902 break;
2904 #endif /* CONFIG_TV_TELETEXT */
2905 #endif /* CONFIG_TV */
2907 case MP_CMD_SUB_LOAD:
2908 if (sh_video) {
2909 int n = mpctx->set_of_sub_size;
2910 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
2911 if (n != mpctx->set_of_sub_size) {
2912 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2913 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2914 mpctx->global_sub_size;
2915 ++mpctx->global_sub_size;
2918 break;
2920 case MP_CMD_SUB_REMOVE:
2921 if (sh_video) {
2922 int v = cmd->args[0].v.i;
2923 sub_data *subd;
2924 if (v < 0) {
2925 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2926 subd = mpctx->set_of_subtitles[v];
2927 mp_tmsg(MSGT_CPLAYER, MSGL_STATUS,
2928 "SUB: Removed subtitle file (%d): %s\n", v + 1,
2929 filename_recode(subd->filename));
2930 sub_free(subd);
2931 mpctx->set_of_subtitles[v] = NULL;
2933 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2934 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2935 mpctx->set_of_sub_size = 0;
2936 if (mpctx->set_of_sub_pos >= 0) {
2937 mpctx->global_sub_pos = -2;
2938 subdata = NULL;
2939 mp_input_queue_cmd(mpctx->input,
2940 mp_input_parse_cmd("sub_select"));
2942 } else if (v < mpctx->set_of_sub_size) {
2943 subd = mpctx->set_of_subtitles[v];
2944 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2945 "SUB: Removed subtitle file (%d): %s\n", v + 1,
2946 filename_recode(subd->filename));
2947 sub_free(subd);
2948 if (mpctx->set_of_sub_pos == v) {
2949 mpctx->global_sub_pos = -2;
2950 subdata = NULL;
2951 mp_input_queue_cmd(mpctx->input,
2952 mp_input_parse_cmd("sub_select"));
2953 } else if (mpctx->set_of_sub_pos > v) {
2954 --mpctx->set_of_sub_pos;
2955 --mpctx->global_sub_pos;
2957 while (++v < mpctx->set_of_sub_size)
2958 mpctx->set_of_subtitles[v - 1] =
2959 mpctx->set_of_subtitles[v];
2960 --mpctx->set_of_sub_size;
2961 --mpctx->global_sub_size;
2962 if (mpctx->set_of_sub_size <= 0)
2963 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2964 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2967 break;
2969 case MP_CMD_GET_SUB_VISIBILITY:
2970 if (sh_video) {
2971 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2972 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2974 break;
2976 case MP_CMD_SCREENSHOT:
2977 if (mpctx->video_out && mpctx->video_out->config_ok) {
2978 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2979 if (CONTROL_OK !=
2980 ((vf_instance_t *) sh_video->vfilter)->
2981 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2982 &cmd->args[0].v.i))
2983 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2985 break;
2987 case MP_CMD_AF_EQ_SET:{
2988 af_instance_t* m1=af_get(sh_audio->afilter, "equalizer");
2989 if (m1) m1->control( m1, AF_CONTROL_COMMAND_LINE, cmd->args[0].v.s);
2990 else mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -af equalizer=0:0 ?)\n");
2992 break;
2994 case MP_CMD_VF_CHANGE_RECTANGLE:
2995 if (!sh_video)
2996 break;
2997 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2998 break;
3000 case MP_CMD_GET_TIME_LENGTH:{
3001 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
3002 demuxer_get_time_length(mpctx->demuxer));
3004 break;
3006 case MP_CMD_GET_FILENAME:{
3007 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3008 get_metadata(mpctx, META_NAME));
3010 break;
3012 case MP_CMD_GET_VIDEO_CODEC:{
3013 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3014 if (!inf)
3015 inf = strdup("");
3016 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3017 free(inf);
3019 break;
3021 case MP_CMD_GET_VIDEO_BITRATE:{
3022 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3023 if (!inf)
3024 inf = strdup("");
3025 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3026 free(inf);
3028 break;
3030 case MP_CMD_GET_VIDEO_RESOLUTION:{
3031 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3032 if (!inf)
3033 inf = strdup("");
3034 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3035 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3036 free(inf);
3038 break;
3040 case MP_CMD_GET_AUDIO_CODEC:{
3041 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3042 if (!inf)
3043 inf = strdup("");
3044 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3045 free(inf);
3047 break;
3049 case MP_CMD_GET_AUDIO_BITRATE:{
3050 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3051 if (!inf)
3052 inf = strdup("");
3053 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3054 free(inf);
3056 break;
3058 case MP_CMD_GET_AUDIO_SAMPLES:{
3059 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3060 if (!inf)
3061 inf = strdup("");
3062 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3063 free(inf);
3065 break;
3067 case MP_CMD_GET_META_TITLE:{
3068 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3069 if (!inf)
3070 inf = strdup("");
3071 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3072 free(inf);
3074 break;
3076 case MP_CMD_GET_META_ARTIST:{
3077 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3078 if (!inf)
3079 inf = strdup("");
3080 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3081 free(inf);
3083 break;
3085 case MP_CMD_GET_META_ALBUM:{
3086 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3087 if (!inf)
3088 inf = strdup("");
3089 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3090 free(inf);
3092 break;
3094 case MP_CMD_GET_META_YEAR:{
3095 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3096 if (!inf)
3097 inf = strdup("");
3098 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3099 free(inf);
3101 break;
3103 case MP_CMD_GET_META_COMMENT:{
3104 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3105 if (!inf)
3106 inf = strdup("");
3107 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3108 free(inf);
3110 break;
3112 case MP_CMD_GET_META_TRACK:{
3113 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3114 if (!inf)
3115 inf = strdup("");
3116 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3117 free(inf);
3119 break;
3121 case MP_CMD_GET_META_GENRE:{
3122 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3123 if (!inf)
3124 inf = strdup("");
3125 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3126 free(inf);
3128 break;
3130 case MP_CMD_GET_VO_FULLSCREEN:
3131 if (mpctx->video_out && mpctx->video_out->config_ok)
3132 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3133 break;
3135 case MP_CMD_GET_PERCENT_POS:
3136 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3137 demuxer_get_percent_pos(mpctx->demuxer));
3138 break;
3140 case MP_CMD_GET_TIME_POS:{
3141 float pos = 0;
3142 if (sh_video)
3143 pos = sh_video->pts;
3144 else if (sh_audio && mpctx->audio_out)
3145 pos = playing_audio_pts(mpctx);
3146 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3148 break;
3150 case MP_CMD_RUN:
3151 #ifndef __MINGW32__
3152 if (!fork()) {
3153 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3154 exit(0);
3156 #endif
3157 break;
3159 case MP_CMD_KEYDOWN_EVENTS:
3160 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3161 break;
3163 case MP_CMD_SET_MOUSE_POS:{
3164 int pointer_x, pointer_y;
3165 double dx, dy;
3166 pointer_x = cmd->args[0].v.i;
3167 pointer_y = cmd->args[1].v.i;
3168 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3169 #ifdef CONFIG_DVDNAV
3170 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3171 && dx > 0.0 && dy > 0.0) {
3172 int button = -1;
3173 pointer_x = (int) (dx * (double) sh_video->disp_w);
3174 pointer_y = (int) (dy * (double) sh_video->disp_h);
3175 mp_dvdnav_update_mouse_pos(mpctx->stream,
3176 pointer_x, pointer_y, &button);
3177 if (opts->osd_level > 1 && button > 0)
3178 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3179 "Selected button number %d", button);
3181 #endif
3182 #ifdef CONFIG_MENU
3183 if (use_menu && dx >= 0.0 && dy >= 0.0)
3184 menu_update_mouse_pos(dx, dy);
3185 #endif
3187 break;
3189 #ifdef CONFIG_DVDNAV
3190 case MP_CMD_DVDNAV:{
3191 int button = -1;
3192 int i;
3193 mp_command_type command = 0;
3194 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3195 break;
3197 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3198 if (cmd->args[0].v.s &&
3199 !strcasecmp (cmd->args[0].v.s,
3200 mp_dvdnav_bindings[i].name))
3201 command = mp_dvdnav_bindings[i].cmd;
3203 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3204 if (opts->osd_level > 1 && button > 0)
3205 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3206 "Selected button number %d", button);
3208 break;
3210 case MP_CMD_SWITCH_TITLE:
3211 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3212 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3213 break;
3215 #endif
3217 default:
3218 mp_msg(MSGT_CPLAYER, MSGL_V,
3219 "Received unknown cmd %s\n", cmd->name);
3222 switch (cmd->pausing) {
3223 case 1: // "pausing"
3224 pause_player(mpctx);
3225 break;
3226 case 3: // "pausing_toggle"
3227 if (mpctx->paused)
3228 unpause_player(mpctx);
3229 else
3230 pause_player(mpctx);
3231 break;