osd: rewrite OSD rendering to use libass
[mplayer.git] / command.c
blob2fd3f1e604224edc09b5c1557e61cb22145e02b8
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdlib.h>
20 #include <inttypes.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <stdbool.h>
25 #include "config.h"
26 #include "talloc.h"
27 #include "command.h"
28 #include "input/input.h"
29 #include "stream/stream.h"
30 #include "libmpdemux/demuxer.h"
31 #include "libmpdemux/stheader.h"
32 #include "codec-cfg.h"
33 #include "mplayer.h"
34 #include "sub/sub.h"
35 #include "sub/dec_sub.h"
36 #include "m_option.h"
37 #include "m_property.h"
38 #include "m_config.h"
39 #include "metadata.h"
40 #include "libmpcodecs/vf.h"
41 #include "libmpcodecs/vd.h"
42 #include "mp_osd.h"
43 #include "libvo/video_out.h"
44 #include "libvo/csputils.h"
45 #include "playtree.h"
46 #include "libao2/audio_out.h"
47 #include "mpcommon.h"
48 #include "mixer.h"
49 #include "libmpcodecs/dec_video.h"
50 #include "libmpcodecs/dec_audio.h"
51 #include "libmpcodecs/dec_teletext.h"
52 #include "osdep/strsep.h"
53 #include "sub/vobsub.h"
54 #include "sub/spudec.h"
55 #include "path.h"
56 #include "sub/ass_mp.h"
57 #include "stream/tv.h"
58 #include "stream/stream_radio.h"
59 #include "stream/pvr.h"
60 #ifdef CONFIG_DVBIN
61 #include "stream/dvbin.h"
62 #endif
63 #ifdef CONFIG_DVDREAD
64 #include "stream/stream_dvd.h"
65 #endif
66 #include "stream/stream_dvdnav.h"
67 #include "m_struct.h"
68 #include "screenshot.h"
70 #include "mp_core.h"
71 #include "mp_fifo.h"
72 #include "libavutil/avstring.h"
74 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
75 double *dx, double *dy)
77 struct MPOpts *opts = &mpctx->opts;
78 struct vo *vo = mpctx->video_out;
79 //remove the borders, if any, and rescale to the range [0,1],[0,1]
80 if (vo_fs) { //we are in full-screen mode
81 if (opts->vo_screenwidth > vo->dwidth)
82 // there are borders along the x axis
83 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
84 if (opts->vo_screenheight > vo->dheight)
85 // there are borders along the y axis (usual way)
86 iy -= (opts->vo_screenheight - vo->dheight) / 2;
88 if (ix < 0 || ix > vo->dwidth) {
89 *dx = *dy = -1.0;
90 return;
91 } //we are on one of the borders
92 if (iy < 0 || iy > vo->dheight) {
93 *dx = *dy = -1.0;
94 return;
95 } //we are on one of the borders
98 *dx = (double) ix / (double) vo->dwidth;
99 *dy = (double) iy / (double) vo->dheight;
101 mp_msg(MSGT_CPLAYER, MSGL_V,
102 "\r\nrescaled coordinates: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
103 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
104 vo->dheight, vo_fs);
107 static int sub_pos_by_source(MPContext *mpctx, int src)
109 int i, cnt = 0;
110 if (src >= SUB_SOURCES || mpctx->sub_counts[src] == 0)
111 return -1;
112 for (i = 0; i < src; i++)
113 cnt += mpctx->sub_counts[i];
114 return cnt;
117 static int sub_source_and_index_by_pos(MPContext *mpctx, int *pos)
119 int start = 0;
120 int i;
121 for (i = 0; i < SUB_SOURCES; i++) {
122 int cnt = mpctx->sub_counts[i];
123 if (*pos >= start && *pos < start + cnt) {
124 *pos -= start;
125 return i;
127 start += cnt;
129 *pos = -1;
130 return -1;
133 static int sub_source_by_pos(MPContext *mpctx, int pos)
135 return sub_source_and_index_by_pos(mpctx, &pos);
138 static int sub_source_pos(MPContext *mpctx)
140 int pos = mpctx->global_sub_pos;
141 sub_source_and_index_by_pos(mpctx, &pos);
142 return pos;
145 static int sub_source(MPContext *mpctx)
147 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
150 static void update_global_sub_size(MPContext *mpctx)
152 struct MPOpts *opts = &mpctx->opts;
153 int i;
154 int cnt = 0;
156 // update number of demuxer sub streams
157 for (i = 0; i < MAX_S_STREAMS; i++)
158 if (mpctx->d_sub->demuxer->s_streams[i])
159 cnt++;
160 if (cnt > mpctx->sub_counts[SUB_SOURCE_DEMUX])
161 mpctx->sub_counts[SUB_SOURCE_DEMUX] = cnt;
163 // update global size
164 mpctx->global_sub_size = 0;
165 for (i = 0; i < SUB_SOURCES; i++)
166 mpctx->global_sub_size += mpctx->sub_counts[i];
168 // update global_sub_pos if we auto-detected a demuxer sub
169 if (mpctx->global_sub_pos == -1) {
170 int sub_id = -1;
171 if (mpctx->demuxer->sub)
172 sub_id = mpctx->demuxer->sub->id;
173 if (sub_id < 0)
174 sub_id = opts->sub_id;
175 if (sub_id >= 0 && sub_id < mpctx->sub_counts[SUB_SOURCE_DEMUX])
176 mpctx->global_sub_pos = sub_pos_by_source(mpctx, SUB_SOURCE_DEMUX) +
177 sub_id;
182 * \brief Log the currently displayed subtitle to a file
184 * Logs the current or last displayed subtitle together with filename
185 * and time information to ~/.mplayer/subtitle_log
187 * Intended purpose is to allow convenient marking of bogus subtitles
188 * which need to be fixed while watching the movie.
191 static void log_sub(struct MPContext *mpctx)
193 char *fname;
194 FILE *f;
195 int i;
196 struct subtitle *vo_sub_last = mpctx->vo_sub_last;
198 if (mpctx->subdata == NULL || vo_sub_last == NULL)
199 return;
200 fname = get_path("subtitle_log");
201 f = fopen(fname, "a");
202 if (!f)
203 return;
204 fprintf(f, "----------------------------------------------------------\n");
205 if (mpctx->subdata->sub_uses_time) {
206 fprintf(f,
207 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
208 mpctx->filename, vo_sub_last->start / 360000,
209 (vo_sub_last->start / 6000) % 60,
210 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
211 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
212 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
213 } else {
214 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
215 vo_sub_last->start, vo_sub_last->end);
217 for (i = 0; i < vo_sub_last->lines; i++)
218 fprintf(f, "%s\n", vo_sub_last->text[i]);
219 fclose(f);
223 static int mp_property_generic_option(struct m_option *prop, int action,
224 void *arg, MPContext *mpctx)
226 char *optname = prop->priv;
227 const struct m_option *opt = m_config_get_option(mpctx->mconfig,
228 bstr(optname));
229 void *valptr = m_option_get_ptr(opt, &mpctx->opts);
231 switch (action) {
232 case M_PROPERTY_GET_TYPE:
233 *(const struct m_option **)arg = opt;
234 return M_PROPERTY_OK;
235 case M_PROPERTY_GET:
236 m_option_copy(opt, arg, valptr);
237 return M_PROPERTY_OK;
238 case M_PROPERTY_SET:
239 m_option_copy(opt, valptr, arg);
240 return M_PROPERTY_OK;
241 case M_PROPERTY_STEP_UP:
242 if (opt->type == &m_option_type_choice) {
243 int v = *(int *) valptr;
244 int best = v;
245 struct m_opt_choice_alternatives *alt;
246 for (alt = opt->priv; alt->name; alt++)
247 if ((unsigned) alt->value - v - 1 < (unsigned) best - v - 1)
248 best = alt->value;
249 *(int *) valptr = best;
250 return M_PROPERTY_OK;
252 break;
254 return M_PROPERTY_NOT_IMPLEMENTED;
257 /// OSD level (RW)
258 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
259 MPContext *mpctx)
261 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
264 /// Loop (RW)
265 static int mp_property_loop(m_option_t *prop, int action, void *arg,
266 MPContext *mpctx)
268 struct MPOpts *opts = &mpctx->opts;
269 switch (action) {
270 case M_PROPERTY_PRINT:
271 if (!arg)
272 return M_PROPERTY_ERROR;
273 if (opts->loop_times < 0)
274 *(char **)arg = talloc_strdup(NULL, "off");
275 else if (opts->loop_times == 0)
276 *(char **)arg = talloc_strdup(NULL, "inf");
277 else
278 break;
279 return M_PROPERTY_OK;
281 return m_property_int_range(prop, action, arg, &opts->loop_times);
284 /// Playback speed (RW)
285 static int mp_property_playback_speed(m_option_t *prop, int action,
286 void *arg, MPContext *mpctx)
288 struct MPOpts *opts = &mpctx->opts;
289 double orig_speed = opts->playback_speed;
290 switch (action) {
291 case M_PROPERTY_SET:
292 if (!arg)
293 return M_PROPERTY_ERROR;
294 opts->playback_speed = *(float *) arg;
295 goto set;
296 case M_PROPERTY_STEP_UP:
297 case M_PROPERTY_STEP_DOWN:
298 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
299 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
300 set:
301 M_PROPERTY_CLAMP(prop, opts->playback_speed);
302 // Adjust time until next frame flip for nosound mode
303 mpctx->time_frame *= orig_speed / opts->playback_speed;
304 reinit_audio_chain(mpctx);
305 return M_PROPERTY_OK;
307 return m_property_float_range(prop, action, arg, &opts->playback_speed);
310 /// filename with path (RO)
311 static int mp_property_path(m_option_t *prop, int action, void *arg,
312 MPContext *mpctx)
314 return m_property_string_ro(prop, action, arg, mpctx->filename);
317 /// filename without path (RO)
318 static int mp_property_filename(m_option_t *prop, int action, void *arg,
319 MPContext *mpctx)
321 char *f;
322 if (!mpctx->filename)
323 return M_PROPERTY_UNAVAILABLE;
324 f = (char *)mp_basename(mpctx->filename);
325 if (!*f)
326 f = mpctx->filename;
327 return m_property_string_ro(prop, action, arg, f);
330 /// Demuxer name (RO)
331 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
332 MPContext *mpctx)
334 if (!mpctx->demuxer)
335 return M_PROPERTY_UNAVAILABLE;
336 return m_property_string_ro(prop, action, arg,
337 (char *) mpctx->demuxer->desc->name);
340 /// Position in the stream (RW)
341 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
342 MPContext *mpctx)
344 if (!mpctx->demuxer || !mpctx->demuxer->stream)
345 return M_PROPERTY_UNAVAILABLE;
346 if (!arg)
347 return M_PROPERTY_ERROR;
348 switch (action) {
349 case M_PROPERTY_GET:
350 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
351 return M_PROPERTY_OK;
352 case M_PROPERTY_SET:
353 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
354 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
355 return M_PROPERTY_OK;
357 return M_PROPERTY_NOT_IMPLEMENTED;
360 /// Stream start offset (RO)
361 static int mp_property_stream_start(m_option_t *prop, int action,
362 void *arg, MPContext *mpctx)
364 if (!mpctx->demuxer || !mpctx->demuxer->stream)
365 return M_PROPERTY_UNAVAILABLE;
366 switch (action) {
367 case M_PROPERTY_GET:
368 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
369 return M_PROPERTY_OK;
371 return M_PROPERTY_NOT_IMPLEMENTED;
374 /// Stream end offset (RO)
375 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
376 MPContext *mpctx)
378 if (!mpctx->demuxer || !mpctx->demuxer->stream)
379 return M_PROPERTY_UNAVAILABLE;
380 switch (action) {
381 case M_PROPERTY_GET:
382 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
383 return M_PROPERTY_OK;
385 return M_PROPERTY_NOT_IMPLEMENTED;
388 /// Stream length (RO)
389 static int mp_property_stream_length(m_option_t *prop, int action,
390 void *arg, MPContext *mpctx)
392 if (!mpctx->demuxer || !mpctx->demuxer->stream)
393 return M_PROPERTY_UNAVAILABLE;
394 switch (action) {
395 case M_PROPERTY_GET:
396 *(off_t *) arg =
397 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
398 return M_PROPERTY_OK;
400 return M_PROPERTY_NOT_IMPLEMENTED;
403 /// Current stream position in seconds (RO)
404 static int mp_property_stream_time_pos(m_option_t *prop, int action,
405 void *arg, MPContext *mpctx)
407 if (!mpctx->demuxer || mpctx->demuxer->stream_pts == MP_NOPTS_VALUE)
408 return M_PROPERTY_UNAVAILABLE;
410 return m_property_time_ro(prop, action, arg, mpctx->demuxer->stream_pts);
414 /// Media length in seconds (RO)
415 static int mp_property_length(m_option_t *prop, int action, void *arg,
416 MPContext *mpctx)
418 double len;
420 if (!mpctx->demuxer ||
421 !(int) (len = get_time_length(mpctx)))
422 return M_PROPERTY_UNAVAILABLE;
424 return m_property_time_ro(prop, action, arg, len);
427 /// Current position in percent (RW)
428 static int mp_property_percent_pos(m_option_t *prop, int action,
429 void *arg, MPContext *mpctx)
431 int pos;
433 if (!mpctx->demuxer)
434 return M_PROPERTY_UNAVAILABLE;
436 switch (action) {
437 case M_PROPERTY_SET:
438 if (!arg)
439 return M_PROPERTY_ERROR;
440 M_PROPERTY_CLAMP(prop, *(int *)arg);
441 pos = *(int *)arg;
442 break;
443 case M_PROPERTY_STEP_UP:
444 case M_PROPERTY_STEP_DOWN:
445 pos = get_percent_pos(mpctx);
446 pos += (arg ? *(int *)arg : 10) *
447 (action == M_PROPERTY_STEP_UP ? 1 : -1);
448 M_PROPERTY_CLAMP(prop, pos);
449 break;
450 default:
451 return m_property_int_ro(prop, action, arg, get_percent_pos(mpctx));
454 queue_seek(mpctx, MPSEEK_FACTOR, pos / 100.0, 0);
455 return M_PROPERTY_OK;
458 /// Current position in seconds (RW)
459 static int mp_property_time_pos(m_option_t *prop, int action,
460 void *arg, MPContext *mpctx)
462 if (!(mpctx->sh_video || mpctx->sh_audio))
463 return M_PROPERTY_UNAVAILABLE;
465 switch (action) {
466 case M_PROPERTY_SET:
467 if (!arg)
468 return M_PROPERTY_ERROR;
469 M_PROPERTY_CLAMP(prop, *(double *)arg);
470 queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double *)arg, 0);
471 return M_PROPERTY_OK;
472 case M_PROPERTY_STEP_UP:
473 case M_PROPERTY_STEP_DOWN:
474 queue_seek(mpctx, MPSEEK_RELATIVE, (arg ? *(double *)arg : 10.0) *
475 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0), 0);
476 return M_PROPERTY_OK;
478 return m_property_time_ro(prop, action, arg, get_current_time(mpctx));
481 /// Current chapter (RW)
482 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
483 MPContext *mpctx)
485 struct MPOpts *opts = &mpctx->opts;
486 int chapter = -1;
487 int step_all;
488 char *chapter_name = NULL;
490 if (mpctx->demuxer)
491 chapter = get_current_chapter(mpctx);
492 if (chapter < -1)
493 return M_PROPERTY_UNAVAILABLE;
495 switch (action) {
496 case M_PROPERTY_GET:
497 if (!arg)
498 return M_PROPERTY_ERROR;
499 *(int *) arg = chapter;
500 return M_PROPERTY_OK;
501 case M_PROPERTY_PRINT: {
502 if (!arg)
503 return M_PROPERTY_ERROR;
504 chapter_name = chapter_display_name(mpctx, chapter);
505 if (!chapter_name)
506 return M_PROPERTY_UNAVAILABLE;
507 *(char **) arg = chapter_name;
508 return M_PROPERTY_OK;
510 case M_PROPERTY_SET:
511 if (!arg)
512 return M_PROPERTY_ERROR;
513 M_PROPERTY_CLAMP(prop, *(int *)arg);
514 step_all = *(int *)arg - chapter;
515 chapter += step_all;
516 break;
517 case M_PROPERTY_STEP_UP:
518 case M_PROPERTY_STEP_DOWN: {
519 step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1)
520 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
521 chapter += step_all;
522 if (chapter < 0)
523 chapter = 0;
524 break;
526 default:
527 return M_PROPERTY_NOT_IMPLEMENTED;
530 double next_pts = 0;
531 queue_seek(mpctx, MPSEEK_NONE, 0, 0);
532 chapter = seek_chapter(mpctx, chapter, &next_pts);
533 if (chapter >= 0) {
534 if (next_pts > -1.0)
535 queue_seek(mpctx, MPSEEK_ABSOLUTE, next_pts, 0);
536 chapter_name = chapter_display_name(mpctx, chapter);
537 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
538 "Chapter: %s", chapter_name);
539 } else if (step_all > 0)
540 queue_seek(mpctx, MPSEEK_RELATIVE, 1000000000, 0);
541 else
542 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
543 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
544 talloc_free(chapter_name);
545 return M_PROPERTY_OK;
548 /// Number of chapters in file
549 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
550 MPContext *mpctx)
552 if (!mpctx->demuxer)
553 return M_PROPERTY_UNAVAILABLE;
554 int count = get_chapter_count(mpctx);
555 return m_property_int_ro(prop, action, arg, count);
558 /// Current dvd angle (RW)
559 static int mp_property_angle(m_option_t *prop, int action, void *arg,
560 MPContext *mpctx)
562 struct MPOpts *opts = &mpctx->opts;
563 int angle = -1;
564 int angles;
566 if (mpctx->demuxer)
567 angle = demuxer_get_current_angle(mpctx->demuxer);
568 if (angle < 0)
569 return M_PROPERTY_UNAVAILABLE;
570 angles = demuxer_angles_count(mpctx->demuxer);
571 if (angles <= 1)
572 return M_PROPERTY_UNAVAILABLE;
574 switch (action) {
575 case M_PROPERTY_GET:
576 if (!arg)
577 return M_PROPERTY_ERROR;
578 *(int *) arg = angle;
579 return M_PROPERTY_OK;
580 case M_PROPERTY_PRINT: {
581 if (!arg)
582 return M_PROPERTY_ERROR;
583 *(char **) arg = talloc_asprintf(NULL, "%d/%d", angle, angles);
584 return M_PROPERTY_OK;
586 case M_PROPERTY_SET:
587 if (!arg)
588 return M_PROPERTY_ERROR;
589 angle = *(int *)arg;
590 M_PROPERTY_CLAMP(prop, angle);
591 break;
592 case M_PROPERTY_STEP_UP:
593 case M_PROPERTY_STEP_DOWN: {
594 int step = 0;
595 if (arg)
596 step = *(int *)arg;
597 if (!step)
598 step = 1;
599 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
600 angle += step;
601 if (angle < 1) //cycle
602 angle = angles;
603 else if (angle > angles)
604 angle = 1;
605 break;
607 default:
608 return M_PROPERTY_NOT_IMPLEMENTED;
610 angle = demuxer_set_angle(mpctx->demuxer, angle);
611 if (angle >= 0) {
612 struct sh_video *sh_video = mpctx->demuxer->video->sh;
613 if (sh_video)
614 resync_video_stream(sh_video);
616 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
617 if (sh_audio)
618 resync_audio_stream(sh_audio);
621 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
622 "Angle: %d/%d", angle, angles);
623 return M_PROPERTY_OK;
626 /// Demuxer meta data
627 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
628 MPContext *mpctx)
630 m_property_action_t *ka;
631 char *meta;
632 static const m_option_t key_type =
634 "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL
636 if (!mpctx->demuxer)
637 return M_PROPERTY_UNAVAILABLE;
639 switch (action) {
640 case M_PROPERTY_GET:
641 if (!arg)
642 return M_PROPERTY_ERROR;
643 *(char ***)arg = mpctx->demuxer->info;
644 return M_PROPERTY_OK;
645 case M_PROPERTY_KEY_ACTION:
646 if (!arg)
647 return M_PROPERTY_ERROR;
648 ka = arg;
649 if (!(meta = demux_info_get(mpctx->demuxer, ka->key)))
650 return M_PROPERTY_UNKNOWN;
651 switch (ka->action) {
652 case M_PROPERTY_GET:
653 if (!ka->arg)
654 return M_PROPERTY_ERROR;
655 *(char **)ka->arg = meta;
656 return M_PROPERTY_OK;
657 case M_PROPERTY_GET_TYPE:
658 if (!ka->arg)
659 return M_PROPERTY_ERROR;
660 *(const m_option_t **)ka->arg = &key_type;
661 return M_PROPERTY_OK;
664 return M_PROPERTY_NOT_IMPLEMENTED;
667 static int mp_property_pause(m_option_t *prop, int action, void *arg,
668 void *ctx)
670 MPContext *mpctx = ctx;
672 switch (action) {
673 case M_PROPERTY_SET:
674 if (!arg)
675 return M_PROPERTY_ERROR;
676 if (mpctx->paused == (bool) * (int *)arg)
677 return M_PROPERTY_OK;
678 case M_PROPERTY_STEP_UP:
679 case M_PROPERTY_STEP_DOWN:
680 if (mpctx->paused) {
681 unpause_player(mpctx);
682 } else {
683 pause_player(mpctx);
685 return M_PROPERTY_OK;
686 default:
687 return m_property_flag(prop, action, arg, &mpctx->paused);
692 /// Volume (RW)
693 static int mp_property_volume(m_option_t *prop, int action, void *arg,
694 MPContext *mpctx)
697 if (!mpctx->sh_audio)
698 return M_PROPERTY_UNAVAILABLE;
700 switch (action) {
701 case M_PROPERTY_GET:
702 if (!arg)
703 return M_PROPERTY_ERROR;
704 mixer_getbothvolume(&mpctx->mixer, arg);
705 return M_PROPERTY_OK;
706 case M_PROPERTY_PRINT: {
707 float vol;
708 if (!arg)
709 return M_PROPERTY_ERROR;
710 mixer_getbothvolume(&mpctx->mixer, &vol);
711 return m_property_float_range(prop, action, arg, &vol);
713 case M_PROPERTY_STEP_UP:
714 case M_PROPERTY_STEP_DOWN:
715 case M_PROPERTY_SET:
716 break;
717 default:
718 return M_PROPERTY_NOT_IMPLEMENTED;
721 switch (action) {
722 case M_PROPERTY_SET:
723 if (!arg)
724 return M_PROPERTY_ERROR;
725 M_PROPERTY_CLAMP(prop, *(float *) arg);
726 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
727 return M_PROPERTY_OK;
728 case M_PROPERTY_STEP_UP:
729 if (arg && *(float *) arg <= 0)
730 mixer_decvolume(&mpctx->mixer);
731 else
732 mixer_incvolume(&mpctx->mixer);
733 return M_PROPERTY_OK;
734 case M_PROPERTY_STEP_DOWN:
735 if (arg && *(float *) arg <= 0)
736 mixer_incvolume(&mpctx->mixer);
737 else
738 mixer_decvolume(&mpctx->mixer);
739 return M_PROPERTY_OK;
741 return M_PROPERTY_NOT_IMPLEMENTED;
744 /// Mute (RW)
745 static int mp_property_mute(m_option_t *prop, int action, void *arg,
746 MPContext *mpctx)
749 if (!mpctx->sh_audio)
750 return M_PROPERTY_UNAVAILABLE;
752 switch (action) {
753 case M_PROPERTY_SET:
754 if (!arg)
755 return M_PROPERTY_ERROR;
756 mixer_setmute(&mpctx->mixer, *(int *) arg);
757 return M_PROPERTY_OK;
758 case M_PROPERTY_STEP_UP:
759 case M_PROPERTY_STEP_DOWN:
760 mixer_setmute(&mpctx->mixer, !mixer_getmute(&mpctx->mixer));
761 return M_PROPERTY_OK;
762 default:
763 return m_property_flag_ro(prop, action, arg,
764 mixer_getmute(&mpctx->mixer));
768 /// Audio delay (RW)
769 static int mp_property_audio_delay(m_option_t *prop, int action,
770 void *arg, MPContext *mpctx)
772 if (!(mpctx->sh_audio && mpctx->sh_video))
773 return M_PROPERTY_UNAVAILABLE;
774 switch (action) {
775 case M_PROPERTY_SET:
776 case M_PROPERTY_STEP_UP:
777 case M_PROPERTY_STEP_DOWN: {
778 int ret;
779 float delay = audio_delay;
780 ret = m_property_delay(prop, action, arg, &audio_delay);
781 if (ret != M_PROPERTY_OK)
782 return ret;
783 if (mpctx->sh_audio)
784 mpctx->delay -= audio_delay - delay;
786 return M_PROPERTY_OK;
787 default:
788 return m_property_delay(prop, action, arg, &audio_delay);
792 /// Audio codec tag (RO)
793 static int mp_property_audio_format(m_option_t *prop, int action,
794 void *arg, MPContext *mpctx)
796 if (!mpctx->sh_audio)
797 return M_PROPERTY_UNAVAILABLE;
798 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
801 /// Audio codec name (RO)
802 static int mp_property_audio_codec(m_option_t *prop, int action,
803 void *arg, MPContext *mpctx)
805 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
806 return M_PROPERTY_UNAVAILABLE;
807 return m_property_string_ro(prop, action, arg,
808 mpctx->sh_audio->codec->name);
811 /// Audio bitrate (RO)
812 static int mp_property_audio_bitrate(m_option_t *prop, int action,
813 void *arg, MPContext *mpctx)
815 if (!mpctx->sh_audio)
816 return M_PROPERTY_UNAVAILABLE;
817 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
820 /// Samplerate (RO)
821 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
822 MPContext *mpctx)
824 if (!mpctx->sh_audio)
825 return M_PROPERTY_UNAVAILABLE;
826 switch (action) {
827 case M_PROPERTY_PRINT:
828 if (!arg)
829 return M_PROPERTY_ERROR;
830 *(char **)arg = talloc_asprintf(NULL, "%d kHz",
831 mpctx->sh_audio->samplerate / 1000);
832 return M_PROPERTY_OK;
834 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
837 /// Number of channels (RO)
838 static int mp_property_channels(m_option_t *prop, int action, void *arg,
839 MPContext *mpctx)
841 if (!mpctx->sh_audio)
842 return M_PROPERTY_UNAVAILABLE;
843 switch (action) {
844 case M_PROPERTY_PRINT:
845 if (!arg)
846 return M_PROPERTY_ERROR;
847 switch (mpctx->sh_audio->channels) {
848 case 1:
849 *(char **) arg = talloc_strdup(NULL, "mono");
850 break;
851 case 2:
852 *(char **) arg = talloc_strdup(NULL, "stereo");
853 break;
854 default:
855 *(char **) arg = talloc_asprintf(NULL, "%d channels",
856 mpctx->sh_audio->channels);
858 return M_PROPERTY_OK;
860 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
863 /// Balance (RW)
864 static int mp_property_balance(m_option_t *prop, int action, void *arg,
865 MPContext *mpctx)
867 float bal;
869 switch (action) {
870 case M_PROPERTY_GET:
871 if (!arg)
872 return M_PROPERTY_ERROR;
873 mixer_getbalance(&mpctx->mixer, arg);
874 return M_PROPERTY_OK;
875 case M_PROPERTY_PRINT: {
876 char **str = arg;
877 if (!arg)
878 return M_PROPERTY_ERROR;
879 mixer_getbalance(&mpctx->mixer, &bal);
880 if (bal == 0.f)
881 *str = talloc_strdup(NULL, "center");
882 else if (bal == -1.f)
883 *str = talloc_strdup(NULL, "left only");
884 else if (bal == 1.f)
885 *str = talloc_strdup(NULL, "right only");
886 else {
887 unsigned right = (bal + 1.f) / 2.f * 100.f;
888 *str = talloc_asprintf(NULL, "left %d%%, right %d%%",
889 100 - right, right);
891 return M_PROPERTY_OK;
893 case M_PROPERTY_STEP_UP:
894 case M_PROPERTY_STEP_DOWN:
895 mixer_getbalance(&mpctx->mixer, &bal);
896 bal += (arg ? *(float *)arg : .1f) *
897 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
898 M_PROPERTY_CLAMP(prop, bal);
899 mixer_setbalance(&mpctx->mixer, bal);
900 return M_PROPERTY_OK;
901 case M_PROPERTY_SET:
902 if (!arg)
903 return M_PROPERTY_ERROR;
904 M_PROPERTY_CLAMP(prop, *(float *)arg);
905 mixer_setbalance(&mpctx->mixer, *(float *)arg);
906 return M_PROPERTY_OK;
908 return M_PROPERTY_NOT_IMPLEMENTED;
911 /// Selected audio id (RW)
912 static int mp_property_audio(m_option_t *prop, int action, void *arg,
913 MPContext *mpctx)
915 int current_id, tmp;
916 if (!mpctx->demuxer || !mpctx->d_audio)
917 return M_PROPERTY_UNAVAILABLE;
918 struct sh_audio *sh = mpctx->sh_audio;
919 current_id = sh ? sh->aid : -2;
921 switch (action) {
922 case M_PROPERTY_GET:
923 if (!arg)
924 return M_PROPERTY_ERROR;
925 *(int *) arg = current_id;
926 return M_PROPERTY_OK;
927 case M_PROPERTY_PRINT:
928 if (!arg)
929 return M_PROPERTY_ERROR;
931 if (current_id < 0)
932 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
933 else if (sh && (sh->lang || sh->title)) {
934 char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
935 if (sh->title)
936 *(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
937 current_id, lang, sh->title);
938 else
939 *(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id,
940 lang);
941 } else {
942 char lang[40];
943 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
944 if (0) ;
945 #ifdef CONFIG_DVDREAD
946 else if (mpctx->stream->type == STREAMTYPE_DVD) {
947 int code = dvd_lang_from_aid(mpctx->stream, current_id);
948 if (code) {
949 lang[0] = code >> 8;
950 lang[1] = code;
951 lang[2] = 0;
954 #endif
956 #ifdef CONFIG_DVDNAV
957 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
958 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
959 #endif
960 *(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id, lang);
962 return M_PROPERTY_OK;
964 case M_PROPERTY_STEP_UP:
965 case M_PROPERTY_SET:
966 if (action == M_PROPERTY_SET && arg)
967 tmp = *((int *) arg);
968 else
969 tmp = -1;
970 int new_id = demuxer_switch_audio(mpctx->d_audio->demuxer, tmp);
971 if (new_id != current_id)
972 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
973 if (new_id != current_id && new_id >= 0) {
974 sh_audio_t *sh2;
975 sh2 = mpctx->d_audio->demuxer->a_streams[mpctx->d_audio->id];
976 sh2->ds = mpctx->d_audio;
977 mpctx->sh_audio = sh2;
978 reinit_audio_chain(mpctx);
980 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
981 return M_PROPERTY_OK;
982 default:
983 return M_PROPERTY_NOT_IMPLEMENTED;
988 /// Selected video id (RW)
989 static int mp_property_video(m_option_t *prop, int action, void *arg,
990 MPContext *mpctx)
992 struct MPOpts *opts = &mpctx->opts;
993 int current_id, tmp;
994 if (!mpctx->demuxer || !mpctx->d_video)
995 return M_PROPERTY_UNAVAILABLE;
996 current_id = mpctx->sh_video ? mpctx->sh_video->vid : -2;
998 switch (action) {
999 case M_PROPERTY_GET:
1000 if (!arg)
1001 return M_PROPERTY_ERROR;
1002 *(int *) arg = current_id;
1003 return M_PROPERTY_OK;
1004 case M_PROPERTY_PRINT:
1005 if (!arg)
1006 return M_PROPERTY_ERROR;
1008 if (current_id < 0)
1009 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1010 else {
1011 *(char **) arg = talloc_asprintf(NULL, "(%d) %s", current_id,
1012 mp_gtext("unknown"));
1014 return M_PROPERTY_OK;
1016 case M_PROPERTY_STEP_UP:
1017 case M_PROPERTY_SET:
1018 if (action == M_PROPERTY_SET && arg)
1019 tmp = *((int *) arg);
1020 else
1021 tmp = -1;
1022 int new_id = demuxer_switch_video(mpctx->d_video->demuxer, tmp);
1023 if (new_id != current_id)
1024 uninit_player(mpctx, INITIALIZED_VCODEC |
1025 (opts->fixed_vo && new_id >= 0 ? 0 : INITIALIZED_VO));
1026 if (new_id != current_id && new_id >= 0) {
1027 sh_video_t *sh2;
1028 sh2 = mpctx->d_video->demuxer->v_streams[mpctx->d_video->id];
1029 sh2->ds = mpctx->d_video;
1030 mpctx->sh_video = sh2;
1031 reinit_video_chain(mpctx);
1033 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", new_id);
1034 return M_PROPERTY_OK;
1036 default:
1037 return M_PROPERTY_NOT_IMPLEMENTED;
1041 static int mp_property_program(m_option_t *prop, int action, void *arg,
1042 MPContext *mpctx)
1044 demux_program_t prog;
1046 switch (action) {
1047 case M_PROPERTY_STEP_UP:
1048 case M_PROPERTY_SET:
1049 if (action == M_PROPERTY_SET && arg)
1050 prog.progid = *((int *) arg);
1051 else
1052 prog.progid = -1;
1053 if (demux_control(mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1054 &prog) == DEMUXER_CTRL_NOTIMPL)
1055 return M_PROPERTY_ERROR;
1057 if (prog.aid < 0 && prog.vid < 0) {
1058 mp_msg(MSGT_CPLAYER, MSGL_ERR,
1059 "Selected program contains no audio or video streams!\n");
1060 return M_PROPERTY_ERROR;
1062 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1063 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1064 return M_PROPERTY_OK;
1066 default:
1067 return M_PROPERTY_NOT_IMPLEMENTED;
1072 /// Fullscreen state (RW)
1073 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1074 MPContext *mpctx)
1077 if (!mpctx->video_out)
1078 return M_PROPERTY_UNAVAILABLE;
1080 switch (action) {
1081 case M_PROPERTY_SET:
1082 if (!arg)
1083 return M_PROPERTY_ERROR;
1084 M_PROPERTY_CLAMP(prop, *(int *) arg);
1085 if (vo_fs == !!*(int *) arg)
1086 return M_PROPERTY_OK;
1087 case M_PROPERTY_STEP_UP:
1088 case M_PROPERTY_STEP_DOWN:
1089 if (mpctx->video_out->config_ok)
1090 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1091 mpctx->opts.fullscreen = vo_fs;
1092 return M_PROPERTY_OK;
1093 default:
1094 return m_property_flag(prop, action, arg, &vo_fs);
1098 static int mp_property_deinterlace(m_option_t *prop, int action,
1099 void *arg, MPContext *mpctx)
1101 int deinterlace;
1102 vf_instance_t *vf;
1103 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1104 return M_PROPERTY_UNAVAILABLE;
1105 vf = mpctx->sh_video->vfilter;
1106 switch (action) {
1107 case M_PROPERTY_GET:
1108 if (!arg)
1109 return M_PROPERTY_ERROR;
1110 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1111 return M_PROPERTY_OK;
1112 case M_PROPERTY_SET:
1113 if (!arg)
1114 return M_PROPERTY_ERROR;
1115 M_PROPERTY_CLAMP(prop, *(int *) arg);
1116 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1117 return M_PROPERTY_OK;
1118 case M_PROPERTY_STEP_UP:
1119 case M_PROPERTY_STEP_DOWN:
1120 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1121 deinterlace = !deinterlace;
1122 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1123 return M_PROPERTY_OK;
1125 int value = 0;
1126 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1127 return m_property_flag_ro(prop, action, arg, value);
1130 static int colormatrix_property_helper(m_option_t *prop, int action,
1131 void *arg, MPContext *mpctx)
1133 int r = mp_property_generic_option(prop, action, arg, mpctx);
1134 // testing for an actual change is too much effort
1135 switch (action) {
1136 case M_PROPERTY_SET:
1137 case M_PROPERTY_STEP_UP:
1138 case M_PROPERTY_STEP_DOWN:
1139 if (mpctx->sh_video)
1140 set_video_colorspace(mpctx->sh_video);
1141 break;
1143 return r;
1146 static int mp_property_colormatrix(m_option_t *prop, int action, void *arg,
1147 MPContext *mpctx)
1149 struct MPOpts *opts = &mpctx->opts;
1150 switch (action) {
1151 case M_PROPERTY_PRINT:
1152 if (!arg)
1153 return M_PROPERTY_ERROR;
1154 struct mp_csp_details actual = { .format = -1 };
1155 char *req_csp = mp_csp_names[opts->requested_colorspace];
1156 char *real_csp = NULL;
1157 if (mpctx->sh_video) {
1158 struct vf_instance *vf = mpctx->sh_video->vfilter;
1159 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &actual) == true) {
1160 real_csp = mp_csp_names[actual.format];
1161 } else {
1162 real_csp = "Unknown";
1165 char *res;
1166 if (opts->requested_colorspace == MP_CSP_AUTO && real_csp) {
1167 // Caveat: doesn't handle the case when the autodetected colorspace
1168 // is different from the actual colorspace as used by the
1169 // VO - the OSD will display the VO colorspace without
1170 // indication that it doesn't match the requested colorspace.
1171 res = talloc_asprintf(NULL, "Auto (%s)", real_csp);
1172 } else if (opts->requested_colorspace == actual.format || !real_csp) {
1173 res = talloc_strdup(NULL, req_csp);
1174 } else
1175 res = talloc_asprintf(NULL, mp_gtext("%s, but %s used"),
1176 req_csp, real_csp);
1177 *(char **)arg = res;
1178 return M_PROPERTY_OK;
1179 default:;
1180 return colormatrix_property_helper(prop, action, arg, mpctx);
1184 static int levels_property_helper(int offset, m_option_t *prop, int action,
1185 void *arg, MPContext *mpctx)
1187 char *optname = prop->priv;
1188 const struct m_option *opt = m_config_get_option(mpctx->mconfig,
1189 bstr(optname));
1190 int *valptr = (int *)m_option_get_ptr(opt, &mpctx->opts);
1192 switch (action) {
1193 case M_PROPERTY_PRINT:
1194 if (!arg)
1195 return M_PROPERTY_ERROR;
1196 struct mp_csp_details actual = {0};
1197 int actual_level = -1;
1198 char *req_level = m_option_print(opt, valptr);
1199 char *real_level = NULL;
1200 if (mpctx->sh_video) {
1201 struct vf_instance *vf = mpctx->sh_video->vfilter;
1202 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &actual) == true) {
1203 actual_level = *(enum mp_csp_levels *)(((char *)&actual) + offset);
1204 real_level = m_option_print(opt, &actual_level);
1205 } else {
1206 real_level = talloc_strdup(NULL, "Unknown");
1209 char *res;
1210 if (*valptr == MP_CSP_LEVELS_AUTO && real_level) {
1211 res = talloc_asprintf(NULL, "Auto (%s)", real_level);
1212 } else if (*valptr == actual_level || !real_level) {
1213 res = talloc_strdup(NULL, real_level);
1214 } else
1215 res = talloc_asprintf(NULL, mp_gtext("%s, but %s used"),
1216 req_level, real_level);
1217 talloc_free(req_level);
1218 talloc_free(real_level);
1219 *(char **)arg = res;
1220 return M_PROPERTY_OK;
1221 default:;
1222 return colormatrix_property_helper(prop, action, arg, mpctx);
1226 static int mp_property_colormatrix_input_range(m_option_t *prop, int action,
1227 void *arg, MPContext *mpctx)
1229 return levels_property_helper(offsetof(struct mp_csp_details, levels_in),
1230 prop, action, arg, mpctx);
1233 static int mp_property_colormatrix_output_range(m_option_t *prop, int action,
1234 void *arg, MPContext *mpctx)
1236 return levels_property_helper(offsetof(struct mp_csp_details, levels_out),
1237 prop, action, arg, mpctx);
1240 static int mp_property_capture(m_option_t *prop, int action,
1241 void *arg, MPContext *mpctx)
1243 struct MPOpts *opts = &mpctx->opts;
1245 if (!mpctx->stream)
1246 return M_PROPERTY_UNAVAILABLE;
1248 if (!opts->capture_dump) {
1249 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1250 "Capturing not enabled (forgot -capture parameter?)\n");
1251 return M_PROPERTY_ERROR;
1254 int capturing = !!mpctx->stream->capture_file;
1256 int ret = m_property_flag(prop, action, arg, &capturing);
1257 if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
1258 if (capturing) {
1259 mpctx->stream->capture_file = fopen(opts->stream_dump_name, "wb");
1260 if (!mpctx->stream->capture_file) {
1261 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1262 "Error opening capture file: %s\n", strerror(errno));
1263 ret = M_PROPERTY_ERROR;
1265 } else {
1266 fclose(mpctx->stream->capture_file);
1267 mpctx->stream->capture_file = NULL;
1271 return ret;
1274 /// Panscan (RW)
1275 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1276 MPContext *mpctx)
1279 if (!mpctx->video_out
1280 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1281 return M_PROPERTY_UNAVAILABLE;
1283 switch (action) {
1284 case M_PROPERTY_SET:
1285 if (!arg)
1286 return M_PROPERTY_ERROR;
1287 M_PROPERTY_CLAMP(prop, *(float *) arg);
1288 vo_panscan = *(float *) arg;
1289 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1290 return M_PROPERTY_OK;
1291 case M_PROPERTY_STEP_UP:
1292 case M_PROPERTY_STEP_DOWN:
1293 vo_panscan += (arg ? *(float *) arg : 0.1) *
1294 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1295 if (vo_panscan > 1)
1296 vo_panscan = 1;
1297 else if (vo_panscan < 0)
1298 vo_panscan = 0;
1299 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1300 return M_PROPERTY_OK;
1301 default:
1302 return m_property_float_range(prop, action, arg, &vo_panscan);
1306 /// Helper to set vo flags.
1307 /** \ingroup PropertyImplHelper
1309 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1310 int vo_ctrl, int *vo_var, MPContext *mpctx)
1313 if (!mpctx->video_out)
1314 return M_PROPERTY_UNAVAILABLE;
1316 switch (action) {
1317 case M_PROPERTY_SET:
1318 if (!arg)
1319 return M_PROPERTY_ERROR;
1320 M_PROPERTY_CLAMP(prop, *(int *) arg);
1321 if (*vo_var == !!*(int *) arg)
1322 return M_PROPERTY_OK;
1323 case M_PROPERTY_STEP_UP:
1324 case M_PROPERTY_STEP_DOWN:
1325 if (mpctx->video_out->config_ok)
1326 vo_control(mpctx->video_out, vo_ctrl, 0);
1327 return M_PROPERTY_OK;
1328 default:
1329 return m_property_flag(prop, action, arg, vo_var);
1333 /// Window always on top (RW)
1334 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1335 MPContext *mpctx)
1337 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1338 &mpctx->opts.vo_ontop, mpctx);
1341 /// Display in the root window (RW)
1342 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1343 MPContext *mpctx)
1345 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1346 &vo_rootwin, mpctx);
1349 /// Show window borders (RW)
1350 static int mp_property_border(m_option_t *prop, int action, void *arg,
1351 MPContext *mpctx)
1353 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1354 &vo_border, mpctx);
1357 /// Framedropping state (RW)
1358 static int mp_property_framedropping(m_option_t *prop, int action,
1359 void *arg, MPContext *mpctx)
1362 if (!mpctx->sh_video)
1363 return M_PROPERTY_UNAVAILABLE;
1365 switch (action) {
1366 case M_PROPERTY_PRINT:
1367 if (!arg)
1368 return M_PROPERTY_ERROR;
1369 *(char **) arg = talloc_strdup(NULL, frame_dropping == 1 ?
1370 mp_gtext("enabled") :
1371 (frame_dropping == 2 ? mp_gtext("hard") :
1372 mp_gtext("disabled")));
1373 return M_PROPERTY_OK;
1374 default:
1375 return m_property_choice(prop, action, arg, &frame_dropping);
1379 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1380 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1381 MPContext *mpctx)
1383 int *gamma = (int *)((char *)&mpctx->opts + prop->offset);
1384 int r, val;
1386 if (!mpctx->sh_video)
1387 return M_PROPERTY_UNAVAILABLE;
1389 if (gamma[0] == 1000) {
1390 gamma[0] = 0;
1391 get_video_colors(mpctx->sh_video, prop->name, gamma);
1394 switch (action) {
1395 case M_PROPERTY_SET:
1396 if (!arg)
1397 return M_PROPERTY_ERROR;
1398 M_PROPERTY_CLAMP(prop, *(int *) arg);
1399 *gamma = *(int *) arg;
1400 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1401 if (r <= 0)
1402 break;
1403 return r;
1404 case M_PROPERTY_GET:
1405 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1406 if (!arg)
1407 return M_PROPERTY_ERROR;
1408 *(int *)arg = val;
1409 return M_PROPERTY_OK;
1411 break;
1412 case M_PROPERTY_STEP_UP:
1413 case M_PROPERTY_STEP_DOWN:
1414 *gamma += (arg ? *(int *) arg : 1) *
1415 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1416 M_PROPERTY_CLAMP(prop, *gamma);
1417 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1418 if (r <= 0)
1419 break;
1420 return r;
1421 default:
1422 return M_PROPERTY_NOT_IMPLEMENTED;
1425 #ifdef CONFIG_TV
1426 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1427 int l = strlen(prop->name);
1428 char tv_prop[3 + l + 1];
1429 sprintf(tv_prop, "tv_%s", prop->name);
1430 return mp_property_do(tv_prop, action, arg, mpctx);
1432 #endif
1434 return M_PROPERTY_UNAVAILABLE;
1437 /// VSync (RW)
1438 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1439 MPContext *mpctx)
1441 return m_property_flag(prop, action, arg, &vo_vsync);
1444 /// Video codec tag (RO)
1445 static int mp_property_video_format(m_option_t *prop, int action,
1446 void *arg, MPContext *mpctx)
1448 char *meta;
1449 if (!mpctx->sh_video)
1450 return M_PROPERTY_UNAVAILABLE;
1451 switch (action) {
1452 case M_PROPERTY_PRINT:
1453 if (!arg)
1454 return M_PROPERTY_ERROR;
1455 switch (mpctx->sh_video->format) {
1456 case 0x10000001:
1457 meta = talloc_strdup(NULL, "mpeg1");
1458 break;
1459 case 0x10000002:
1460 meta = talloc_strdup(NULL, "mpeg2");
1461 break;
1462 case 0x10000004:
1463 meta = talloc_strdup(NULL, "mpeg4");
1464 break;
1465 case 0x10000005:
1466 meta = talloc_strdup(NULL, "h264");
1467 break;
1468 default:
1469 if (mpctx->sh_video->format >= 0x20202020) {
1470 meta = talloc_asprintf(NULL, "%.4s",
1471 (char *) &mpctx->sh_video->format);
1472 } else
1473 meta = talloc_asprintf(NULL, "0x%08X", mpctx->sh_video->format);
1475 *(char **)arg = meta;
1476 return M_PROPERTY_OK;
1478 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1481 /// Video codec name (RO)
1482 static int mp_property_video_codec(m_option_t *prop, int action,
1483 void *arg, MPContext *mpctx)
1485 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1486 return M_PROPERTY_UNAVAILABLE;
1487 return m_property_string_ro(prop, action, arg,
1488 mpctx->sh_video->codec->name);
1492 /// Video bitrate (RO)
1493 static int mp_property_video_bitrate(m_option_t *prop, int action,
1494 void *arg, MPContext *mpctx)
1496 if (!mpctx->sh_video)
1497 return M_PROPERTY_UNAVAILABLE;
1498 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1501 /// Video display width (RO)
1502 static int mp_property_width(m_option_t *prop, int action, void *arg,
1503 MPContext *mpctx)
1505 if (!mpctx->sh_video)
1506 return M_PROPERTY_UNAVAILABLE;
1507 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1510 /// Video display height (RO)
1511 static int mp_property_height(m_option_t *prop, int action, void *arg,
1512 MPContext *mpctx)
1514 if (!mpctx->sh_video)
1515 return M_PROPERTY_UNAVAILABLE;
1516 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1519 /// Video fps (RO)
1520 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1521 MPContext *mpctx)
1523 if (!mpctx->sh_video)
1524 return M_PROPERTY_UNAVAILABLE;
1525 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1528 /// Video aspect (RO)
1529 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1530 MPContext *mpctx)
1532 if (!mpctx->sh_video)
1533 return M_PROPERTY_UNAVAILABLE;
1534 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1538 /// Text subtitle position (RW)
1539 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1540 MPContext *mpctx)
1542 switch (action) {
1543 case M_PROPERTY_SET:
1544 if (!arg)
1545 return M_PROPERTY_ERROR;
1546 case M_PROPERTY_STEP_UP:
1547 case M_PROPERTY_STEP_DOWN:
1548 vo_osd_changed(OSDTYPE_SUBTITLE);
1549 default:
1550 return m_property_int_range(prop, action, arg, &sub_pos);
1554 /// Selected subtitles (RW)
1555 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1556 MPContext *mpctx)
1558 struct MPOpts *opts = &mpctx->opts;
1559 demux_stream_t *const d_sub = mpctx->d_sub;
1560 int source = -1, reset_spu av_unused = 0; // used under CONFIG_DVDREAD
1561 int source_pos = -1;
1563 update_global_sub_size(mpctx);
1564 const int global_sub_size = mpctx->global_sub_size;
1566 if (global_sub_size <= 0)
1567 return M_PROPERTY_UNAVAILABLE;
1569 switch (action) {
1570 case M_PROPERTY_GET:
1571 if (!arg)
1572 return M_PROPERTY_ERROR;
1573 *(int *) arg = mpctx->global_sub_pos;
1574 return M_PROPERTY_OK;
1575 case M_PROPERTY_PRINT:
1576 if (!arg)
1577 return M_PROPERTY_ERROR;
1578 char *sub_name = NULL;
1579 if (mpctx->subdata)
1580 sub_name = mpctx->subdata->filename;
1581 #ifdef CONFIG_ASS
1582 if (mpctx->osd->ass_track)
1583 sub_name = mpctx->osd->ass_track->name;
1584 #endif
1585 if (!sub_name && mpctx->subdata)
1586 sub_name = mpctx->subdata->filename;
1587 if (sub_name) {
1588 const char *tmp = mp_basename(sub_name);
1590 *(char **) arg = talloc_asprintf(NULL, "(%d) %s%s",
1591 mpctx->set_of_sub_pos + 1,
1592 strlen(tmp) < 20 ? "" : "...",
1593 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1594 return M_PROPERTY_OK;
1596 #ifdef CONFIG_DVDNAV
1597 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1598 if (vo_spudec && opts->sub_id >= 0) {
1599 unsigned char lang[3];
1600 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id,
1601 lang)) {
1602 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1603 opts->sub_id, lang);
1604 return M_PROPERTY_OK;
1608 #endif
1610 if ((d_sub->demuxer->type == DEMUXER_TYPE_MATROSKA
1611 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF
1612 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1613 || d_sub->demuxer->type == DEMUXER_TYPE_OGG)
1614 && d_sub->sh && opts->sub_id >= 0) {
1615 struct sh_sub *sh = d_sub->sh;
1616 char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
1617 if (sh->title)
1618 *(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
1619 opts->sub_id, lang, sh->title);
1620 else
1621 *(char **)arg = talloc_asprintf(NULL, "(%d) %s",
1622 opts->sub_id, lang);
1623 return M_PROPERTY_OK;
1626 if (vo_vobsub && vobsub_id >= 0) {
1627 const char *language = mp_gtext("unknown");
1628 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1629 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1630 vobsub_id, language ? language : mp_gtext("unknown"));
1631 return M_PROPERTY_OK;
1633 #ifdef CONFIG_DVDREAD
1634 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1635 && opts->sub_id >= 0) {
1636 char lang[3];
1637 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1638 lang[0] = code >> 8;
1639 lang[1] = code;
1640 lang[2] = 0;
1641 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1642 opts->sub_id, lang);
1643 return M_PROPERTY_OK;
1645 #endif
1646 if (opts->sub_id >= 0) {
1647 *(char **) arg = talloc_asprintf(NULL, "(%d) %s", opts->sub_id,
1648 mp_gtext("unknown"));
1649 return M_PROPERTY_OK;
1651 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1652 return M_PROPERTY_OK;
1654 case M_PROPERTY_SET:
1655 if (!arg)
1656 return M_PROPERTY_ERROR;
1657 if (*(int *) arg < -1)
1658 *(int *) arg = -1;
1659 else if (*(int *) arg >= global_sub_size)
1660 *(int *) arg = global_sub_size - 1;
1661 mpctx->global_sub_pos = *(int *) arg;
1662 break;
1663 case M_PROPERTY_STEP_UP:
1664 mpctx->global_sub_pos += 2;
1665 mpctx->global_sub_pos =
1666 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1667 break;
1668 case M_PROPERTY_STEP_DOWN:
1669 mpctx->global_sub_pos += global_sub_size + 1;
1670 mpctx->global_sub_pos =
1671 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1672 break;
1673 default:
1674 return M_PROPERTY_NOT_IMPLEMENTED;
1677 if (mpctx->global_sub_pos >= 0) {
1678 source = sub_source(mpctx);
1679 source_pos = sub_source_pos(mpctx);
1682 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1683 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1684 global_sub_size,
1685 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1686 mpctx->sub_counts[SUB_SOURCE_SUBS],
1687 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1688 mpctx->global_sub_pos, source);
1690 mpctx->set_of_sub_pos = -1;
1691 mpctx->subdata = NULL;
1693 vobsub_id = -1;
1694 opts->sub_id = -1;
1695 if (d_sub) {
1696 if (d_sub->id > -2)
1697 reset_spu = 1;
1698 d_sub->id = -2;
1700 mpctx->osd->ass_track = NULL;
1701 uninit_player(mpctx, INITIALIZED_SUB);
1703 if (source == SUB_SOURCE_VOBSUB)
1704 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1705 else if (source == SUB_SOURCE_SUBS) {
1706 mpctx->set_of_sub_pos = source_pos;
1707 #ifdef CONFIG_ASS
1708 if (opts->ass_enabled
1709 && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]) {
1710 mpctx->osd->ass_track =
1711 mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1712 mpctx->osd->ass_track_changed = true;
1713 mpctx->osd->vsfilter_aspect =
1714 mpctx->track_was_native_ass[mpctx->set_of_sub_pos];
1715 } else
1716 #endif
1718 mpctx->subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1719 vo_osd_changed(OSDTYPE_SUBTITLE);
1721 } else if (source == SUB_SOURCE_DEMUX) {
1722 opts->sub_id = source_pos;
1723 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1724 int i = 0;
1725 // default: assume 1:1 mapping of sid and stream id
1726 d_sub->id = opts->sub_id;
1727 d_sub->sh = mpctx->d_sub->demuxer->s_streams[d_sub->id];
1728 ds_free_packs(d_sub);
1729 for (i = 0; i < MAX_S_STREAMS; i++) {
1730 sh_sub_t *sh = mpctx->d_sub->demuxer->s_streams[i];
1731 if (sh && sh->sid == opts->sub_id) {
1732 d_sub->id = i;
1733 d_sub->sh = sh;
1734 break;
1737 if (d_sub->sh && d_sub->id >= 0) {
1738 sh_sub_t *sh = d_sub->sh;
1739 if (sh->type == 'v')
1740 init_vo_spudec(mpctx);
1741 else {
1742 sub_init(sh, mpctx->osd);
1743 mpctx->initialized_flags |= INITIALIZED_SUB;
1745 } else {
1746 d_sub->id = -2;
1747 d_sub->sh = NULL;
1751 #ifdef CONFIG_DVDREAD
1752 if (vo_spudec
1753 && (mpctx->stream->type == STREAMTYPE_DVD
1754 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1755 && opts->sub_id < 0 && reset_spu) {
1756 d_sub->id = -2;
1757 d_sub->sh = NULL;
1759 #endif
1761 update_subtitles(mpctx, 0, true);
1763 return M_PROPERTY_OK;
1766 /// Selected sub source (RW)
1767 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1768 MPContext *mpctx)
1770 int source;
1771 update_global_sub_size(mpctx);
1772 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1773 return M_PROPERTY_UNAVAILABLE;
1775 switch (action) {
1776 case M_PROPERTY_GET:
1777 if (!arg)
1778 return M_PROPERTY_ERROR;
1779 *(int *) arg = sub_source(mpctx);
1780 return M_PROPERTY_OK;
1781 case M_PROPERTY_PRINT:
1782 if (!arg)
1783 return M_PROPERTY_ERROR;
1784 char *sourcename;
1785 switch (sub_source(mpctx)) {
1786 case SUB_SOURCE_SUBS:
1787 sourcename = mp_gtext("file");
1788 break;
1789 case SUB_SOURCE_VOBSUB:
1790 sourcename = mp_gtext("vobsub");
1791 break;
1792 case SUB_SOURCE_DEMUX:
1793 sourcename = mp_gtext("embedded");
1794 break;
1795 default:
1796 sourcename = mp_gtext("disabled");
1798 *(char **)arg = talloc_strdup(NULL, sourcename);
1799 return M_PROPERTY_OK;
1800 case M_PROPERTY_SET:
1801 if (!arg)
1802 return M_PROPERTY_ERROR;
1803 M_PROPERTY_CLAMP(prop, *(int *)arg);
1804 if (*(int *) arg < 0)
1805 mpctx->global_sub_pos = -1;
1806 else if (*(int *) arg != sub_source(mpctx)) {
1807 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1808 if (new_pos == -1)
1809 return M_PROPERTY_UNAVAILABLE;
1810 mpctx->global_sub_pos = new_pos;
1812 break;
1813 case M_PROPERTY_STEP_UP:
1814 case M_PROPERTY_STEP_DOWN: {
1815 int step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1)
1816 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1817 int step = (step_all > 0) ? 1 : -1;
1818 int cur_source = sub_source(mpctx);
1819 source = cur_source;
1820 while (step_all) {
1821 source += step;
1822 if (source >= SUB_SOURCES)
1823 source = -1;
1824 else if (source < -1)
1825 source = SUB_SOURCES - 1;
1826 if (source == cur_source || source == -1 ||
1827 mpctx->sub_counts[source])
1828 step_all -= step;
1830 if (source == cur_source)
1831 return M_PROPERTY_OK;
1832 if (source == -1)
1833 mpctx->global_sub_pos = -1;
1834 else
1835 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1836 break;
1838 default:
1839 return M_PROPERTY_NOT_IMPLEMENTED;
1841 --mpctx->global_sub_pos;
1842 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1845 /// Selected subtitles from specific source (RW)
1846 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1847 MPContext *mpctx)
1849 int source, is_cur_source, offset, new_pos;
1850 update_global_sub_size(mpctx);
1851 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1852 return M_PROPERTY_UNAVAILABLE;
1854 if (!strcmp(prop->name, "sub_file"))
1855 source = SUB_SOURCE_SUBS;
1856 else if (!strcmp(prop->name, "sub_vob"))
1857 source = SUB_SOURCE_VOBSUB;
1858 else if (!strcmp(prop->name, "sub_demux"))
1859 source = SUB_SOURCE_DEMUX;
1860 else
1861 return M_PROPERTY_ERROR;
1863 offset = sub_pos_by_source(mpctx, source);
1864 if (offset < 0)
1865 return M_PROPERTY_UNAVAILABLE;
1867 is_cur_source = sub_source(mpctx) == source;
1868 new_pos = mpctx->global_sub_pos;
1869 switch (action) {
1870 case M_PROPERTY_GET:
1871 if (!arg)
1872 return M_PROPERTY_ERROR;
1873 if (is_cur_source) {
1874 *(int *) arg = sub_source_pos(mpctx);
1875 if (source == SUB_SOURCE_VOBSUB)
1876 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1877 } else
1878 *(int *) arg = -1;
1879 return M_PROPERTY_OK;
1880 case M_PROPERTY_PRINT:
1881 if (!arg)
1882 return M_PROPERTY_ERROR;
1883 if (is_cur_source)
1884 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1885 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1886 return M_PROPERTY_OK;
1887 case M_PROPERTY_SET:
1888 if (!arg)
1889 return M_PROPERTY_ERROR;
1890 if (*(int *) arg >= 0) {
1891 int index = *(int *)arg;
1892 if (source == SUB_SOURCE_VOBSUB)
1893 index = vobsub_get_index_by_id(vo_vobsub, index);
1894 new_pos = offset + index;
1895 if (index < 0 || index > mpctx->sub_counts[source]) {
1896 new_pos = -1;
1897 *(int *) arg = -1;
1899 } else
1900 new_pos = -1;
1901 break;
1902 case M_PROPERTY_STEP_UP:
1903 case M_PROPERTY_STEP_DOWN: {
1904 int step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1)
1905 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1906 int step = (step_all > 0) ? 1 : -1;
1907 int max_sub_pos_for_source = -1;
1908 if (!is_cur_source)
1909 new_pos = -1;
1910 while (step_all) {
1911 if (new_pos == -1) {
1912 if (step > 0)
1913 new_pos = offset;
1914 else if (max_sub_pos_for_source == -1) {
1915 // Find max pos for specific source
1916 new_pos = mpctx->global_sub_size - 1;
1917 while (new_pos >= 0 && sub_source(mpctx) != source)
1918 new_pos--;
1919 } else
1920 new_pos = max_sub_pos_for_source;
1921 } else {
1922 new_pos += step;
1923 if (new_pos < offset ||
1924 new_pos >= mpctx->global_sub_size ||
1925 sub_source(mpctx) != source)
1926 new_pos = -1;
1928 step_all -= step;
1930 break;
1932 default:
1933 return M_PROPERTY_NOT_IMPLEMENTED;
1935 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1938 /// Subtitle delay (RW)
1939 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1940 MPContext *mpctx)
1942 if (!mpctx->sh_video)
1943 return M_PROPERTY_UNAVAILABLE;
1944 return m_property_delay(prop, action, arg, &sub_delay);
1947 /// Alignment of text subtitles (RW)
1948 static int mp_property_sub_alignment(m_option_t *prop, int action,
1949 void *arg, MPContext *mpctx)
1951 char *name[] = {
1952 _("top"), _("center"), _("bottom")
1955 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1956 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1957 return M_PROPERTY_UNAVAILABLE;
1959 switch (action) {
1960 case M_PROPERTY_PRINT:
1961 if (!arg)
1962 return M_PROPERTY_ERROR;
1963 M_PROPERTY_CLAMP(prop, sub_alignment);
1964 *(char **) arg = talloc_strdup(NULL, mp_gtext(name[sub_alignment]));
1965 return M_PROPERTY_OK;
1966 case M_PROPERTY_SET:
1967 if (!arg)
1968 return M_PROPERTY_ERROR;
1969 case M_PROPERTY_STEP_UP:
1970 case M_PROPERTY_STEP_DOWN:
1971 vo_osd_changed(OSDTYPE_SUBTITLE);
1972 default:
1973 return m_property_choice(prop, action, arg, &sub_alignment);
1977 /// Subtitle visibility (RW)
1978 static int mp_property_sub_visibility(m_option_t *prop, int action,
1979 void *arg, MPContext *mpctx)
1981 if (!mpctx->sh_video)
1982 return M_PROPERTY_UNAVAILABLE;
1984 switch (action) {
1985 case M_PROPERTY_SET:
1986 if (!arg)
1987 return M_PROPERTY_ERROR;
1988 case M_PROPERTY_STEP_UP:
1989 case M_PROPERTY_STEP_DOWN:
1990 vo_osd_changed(OSDTYPE_SUBTITLE);
1991 if (vo_spudec)
1992 vo_osd_changed(OSDTYPE_SPU);
1993 default:
1994 return m_property_flag(prop, action, arg, &sub_visibility);
1998 #ifdef CONFIG_ASS
1999 /// Use margins for libass subtitles (RW)
2000 static int mp_property_ass_use_margins(m_option_t *prop, int action,
2001 void *arg, MPContext *mpctx)
2003 struct MPOpts *opts = &mpctx->opts;
2004 if (!mpctx->sh_video)
2005 return M_PROPERTY_UNAVAILABLE;
2007 switch (action) {
2008 case M_PROPERTY_SET:
2009 if (!arg)
2010 return M_PROPERTY_ERROR;
2011 case M_PROPERTY_STEP_UP:
2012 case M_PROPERTY_STEP_DOWN:
2013 mpctx->osd->ass_force_reload = true;
2014 default:
2015 return m_property_flag(prop, action, arg, &opts->ass_use_margins);
2019 static int mp_property_ass_vsfilter_aspect_compat(m_option_t *prop, int action,
2020 void *arg, MPContext *mpctx)
2022 if (!mpctx->sh_video)
2023 return M_PROPERTY_UNAVAILABLE;
2025 switch (action) {
2026 case M_PROPERTY_SET:
2027 if (!arg)
2028 return M_PROPERTY_ERROR;
2029 case M_PROPERTY_STEP_UP:
2030 case M_PROPERTY_STEP_DOWN:
2031 //has to re-render subs with new aspect ratio
2032 mpctx->osd->ass_force_reload = 1;
2033 default:
2034 return m_property_flag(prop, action, arg,
2035 &mpctx->opts.ass_vsfilter_aspect_compat);
2039 #endif
2041 /// Show only forced subtitles (RW)
2042 static int mp_property_sub_forced_only(m_option_t *prop, int action,
2043 void *arg, MPContext *mpctx)
2045 if (!vo_spudec)
2046 return M_PROPERTY_UNAVAILABLE;
2048 switch (action) {
2049 case M_PROPERTY_SET:
2050 if (!arg)
2051 return M_PROPERTY_ERROR;
2052 case M_PROPERTY_STEP_UP:
2053 case M_PROPERTY_STEP_DOWN:
2054 m_property_flag(prop, action, arg, &forced_subs_only);
2055 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
2056 return M_PROPERTY_OK;
2057 default:
2058 return m_property_flag(prop, action, arg, &forced_subs_only);
2063 /// Subtitle scale (RW)
2064 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
2065 MPContext *mpctx)
2067 struct MPOpts *opts = &mpctx->opts;
2069 switch (action) {
2070 case M_PROPERTY_SET:
2071 if (!arg)
2072 return M_PROPERTY_ERROR;
2073 M_PROPERTY_CLAMP(prop, *(float *) arg);
2074 #ifdef CONFIG_ASS
2075 if (opts->ass_enabled) {
2076 opts->ass_font_scale = *(float *) arg;
2077 mpctx->osd->ass_force_reload = true;
2079 #endif
2080 text_font_scale_factor = *(float *) arg;
2081 vo_osd_changed(OSDTYPE_SUBTITLE);
2082 return M_PROPERTY_OK;
2083 case M_PROPERTY_STEP_UP:
2084 case M_PROPERTY_STEP_DOWN:
2085 #ifdef CONFIG_ASS
2086 if (opts->ass_enabled) {
2087 opts->ass_font_scale += (arg ? *(float *) arg : 0.1) *
2088 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2089 M_PROPERTY_CLAMP(prop, opts->ass_font_scale);
2090 mpctx->osd->ass_force_reload = true;
2092 #endif
2093 text_font_scale_factor += (arg ? *(float *) arg : 0.1) *
2094 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2095 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
2096 vo_osd_changed(OSDTYPE_SUBTITLE);
2097 return M_PROPERTY_OK;
2098 default:
2099 #ifdef CONFIG_ASS
2100 if (opts->ass_enabled)
2101 return m_property_float_ro(prop, action, arg, opts->ass_font_scale);
2102 else
2103 #endif
2104 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
2109 #ifdef CONFIG_TV
2111 /// TV color settings (RW)
2112 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2113 MPContext *mpctx)
2115 int r, val;
2116 tvi_handle_t *tvh = mpctx->demuxer->priv;
2117 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2118 return M_PROPERTY_UNAVAILABLE;
2120 switch (action) {
2121 case M_PROPERTY_SET:
2122 if (!arg)
2123 return M_PROPERTY_ERROR;
2124 M_PROPERTY_CLAMP(prop, *(int *) arg);
2125 return tv_set_color_options(tvh, prop->offset, *(int *) arg);
2126 case M_PROPERTY_GET:
2127 return tv_get_color_options(tvh, prop->offset, arg);
2128 case M_PROPERTY_STEP_UP:
2129 case M_PROPERTY_STEP_DOWN:
2130 if ((r = tv_get_color_options(tvh, prop->offset, &val)) >= 0) {
2131 if (!r)
2132 return M_PROPERTY_ERROR;
2133 val += (arg ? *(int *) arg : 1) *
2134 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2135 M_PROPERTY_CLAMP(prop, val);
2136 return tv_set_color_options(tvh, prop->offset, val);
2138 return M_PROPERTY_ERROR;
2140 return M_PROPERTY_NOT_IMPLEMENTED;
2143 #endif
2145 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2146 MPContext *mpctx)
2148 int val, result;
2149 int base_ioctl = prop->offset;
2151 for teletext's GET,SET,STEP ioctls this is not 0
2152 SET is GET+1
2153 STEP is GET+2
2155 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2156 return M_PROPERTY_UNAVAILABLE;
2157 if (!base_ioctl)
2158 return M_PROPERTY_ERROR;
2160 switch (action) {
2161 case M_PROPERTY_GET:
2162 if (!arg)
2163 return M_PROPERTY_ERROR;
2164 result = teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2165 break;
2166 case M_PROPERTY_SET:
2167 if (!arg)
2168 return M_PROPERTY_ERROR;
2169 M_PROPERTY_CLAMP(prop, *(int *) arg);
2170 result = teletext_control(mpctx->demuxer->teletext, base_ioctl + 1,
2171 arg);
2172 break;
2173 case M_PROPERTY_STEP_UP:
2174 case M_PROPERTY_STEP_DOWN:
2175 result = teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2176 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ?
2177 -1 : 1);
2178 result = teletext_control(mpctx->demuxer->teletext, base_ioctl + 1,
2179 &val);
2180 break;
2181 default:
2182 return M_PROPERTY_NOT_IMPLEMENTED;
2185 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2188 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2189 MPContext *mpctx)
2191 int result;
2192 int val;
2194 //with tvh==NULL will fail too
2195 result = mp_property_teletext_common(prop, action, arg, mpctx);
2196 if (result != M_PROPERTY_OK)
2197 return result;
2199 if (teletext_control(mpctx->demuxer->teletext,
2200 prop->offset, &val) == VBI_CONTROL_TRUE && val)
2201 mp_input_set_section(mpctx->input, "teletext");
2202 else
2203 mp_input_set_section(mpctx->input, "tv");
2204 return M_PROPERTY_OK;
2207 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2208 MPContext *mpctx)
2210 int result;
2211 int val;
2212 if (!mpctx->demuxer->teletext)
2213 return M_PROPERTY_UNAVAILABLE;
2214 switch (action) {
2215 case M_PROPERTY_STEP_UP:
2216 case M_PROPERTY_STEP_DOWN:
2217 //This should be handled separately
2218 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ?
2219 -1 : 1);
2220 result = teletext_control(mpctx->demuxer->teletext,
2221 TV_VBI_CONTROL_STEP_PAGE, &val);
2222 break;
2223 default:
2224 result = mp_property_teletext_common(prop, action, arg, mpctx);
2226 return result;
2230 /// All properties available in MPlayer.
2231 /** \ingroup Properties
2233 static const m_option_t mp_properties[] = {
2234 // General
2235 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2236 M_OPT_RANGE, 0, 3, NULL },
2237 { "loop", mp_property_loop, CONF_TYPE_INT,
2238 M_OPT_MIN, -1, 0, NULL },
2239 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2240 M_OPT_RANGE, 0.01, 100.0, NULL },
2241 { "filename", mp_property_filename, CONF_TYPE_STRING,
2242 0, 0, 0, NULL },
2243 { "path", mp_property_path, CONF_TYPE_STRING,
2244 0, 0, 0, NULL },
2245 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2246 0, 0, 0, NULL },
2247 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2248 M_OPT_MIN, 0, 0, NULL },
2249 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2250 M_OPT_MIN, 0, 0, NULL },
2251 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2252 M_OPT_MIN, 0, 0, NULL },
2253 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2254 M_OPT_MIN, 0, 0, NULL },
2255 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2256 M_OPT_MIN, 0, 0, NULL },
2257 { "length", mp_property_length, CONF_TYPE_TIME,
2258 M_OPT_MIN, 0, 0, NULL },
2259 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2260 M_OPT_RANGE, 0, 100, NULL },
2261 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2262 M_OPT_MIN, 0, 0, NULL },
2263 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2264 M_OPT_MIN, 0, 0, NULL },
2265 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2266 0, 0, 0, NULL },
2267 { "angle", mp_property_angle, CONF_TYPE_INT,
2268 CONF_RANGE, -2, 10, NULL },
2269 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2270 0, 0, 0, NULL },
2271 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2272 M_OPT_RANGE, 0, 1, NULL },
2273 { "capturing", mp_property_capture, CONF_TYPE_FLAG,
2274 M_OPT_RANGE, 0, 1, NULL },
2275 { "pts_association_mode", mp_property_generic_option, &m_option_type_choice,
2276 0, 0, 0, "pts-association-mode" },
2277 { "hr_seek", mp_property_generic_option, &m_option_type_choice,
2278 0, 0, 0, "hr-seek" },
2280 // Audio
2281 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2282 M_OPT_RANGE, 0, 100, NULL },
2283 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2284 M_OPT_RANGE, 0, 1, NULL },
2285 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2286 M_OPT_RANGE, -100, 100, NULL },
2287 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2288 0, 0, 0, NULL },
2289 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2290 0, 0, 0, NULL },
2291 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2292 0, 0, 0, NULL },
2293 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2294 0, 0, 0, NULL },
2295 { "channels", mp_property_channels, CONF_TYPE_INT,
2296 0, 0, 0, NULL },
2297 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2298 CONF_RANGE, -2, 65535, NULL },
2299 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2300 M_OPT_RANGE, -1, 1, NULL },
2302 // Video
2303 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2304 M_OPT_RANGE, 0, 1, NULL },
2305 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2306 M_OPT_RANGE, 0, 1, NULL },
2307 { "colormatrix", mp_property_colormatrix, &m_option_type_choice,
2308 0, 0, 0, "colormatrix" },
2309 { "colormatrix_input_range", mp_property_colormatrix_input_range, &m_option_type_choice,
2310 0, 0, 0, "colormatrix-input-range" },
2311 { "colormatrix_output_range", mp_property_colormatrix_output_range, &m_option_type_choice,
2312 0, 0, 0, "colormatrix-output-range" },
2313 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2314 M_OPT_RANGE, 0, 1, NULL },
2315 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2316 M_OPT_RANGE, 0, 1, NULL },
2317 { "border", mp_property_border, CONF_TYPE_FLAG,
2318 M_OPT_RANGE, 0, 1, NULL },
2319 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2320 M_OPT_RANGE, 0, 2, NULL },
2321 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2322 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_gamma)},
2323 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2324 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_brightness) },
2325 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2326 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_contrast) },
2327 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2328 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_saturation) },
2329 { "hue", mp_property_gamma, CONF_TYPE_INT,
2330 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_hue) },
2331 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2332 M_OPT_RANGE, 0, 1, NULL },
2333 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2334 M_OPT_RANGE, 0, 1, NULL },
2335 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2336 0, 0, 0, NULL },
2337 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2338 0, 0, 0, NULL },
2339 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2340 0, 0, 0, NULL },
2341 { "width", mp_property_width, CONF_TYPE_INT,
2342 0, 0, 0, NULL },
2343 { "height", mp_property_height, CONF_TYPE_INT,
2344 0, 0, 0, NULL },
2345 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2346 0, 0, 0, NULL },
2347 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2348 0, 0, 0, NULL },
2349 { "switch_video", mp_property_video, CONF_TYPE_INT,
2350 CONF_RANGE, -2, 65535, NULL },
2351 { "switch_program", mp_property_program, CONF_TYPE_INT,
2352 CONF_RANGE, -1, 65535, NULL },
2354 // Subs
2355 { "sub", mp_property_sub, CONF_TYPE_INT,
2356 M_OPT_MIN, -1, 0, NULL },
2357 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2358 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2359 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2360 M_OPT_MIN, -1, 0, NULL },
2361 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2362 M_OPT_MIN, -1, 0, NULL },
2363 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2364 M_OPT_MIN, -1, 0, NULL },
2365 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2366 0, 0, 0, NULL },
2367 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2368 M_OPT_RANGE, 0, 100, NULL },
2369 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2370 M_OPT_RANGE, 0, 2, NULL },
2371 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2372 M_OPT_RANGE, 0, 1, NULL },
2373 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2374 M_OPT_RANGE, 0, 1, NULL },
2375 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2376 M_OPT_RANGE, 0, 100, NULL },
2377 #ifdef CONFIG_ASS
2378 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2379 M_OPT_RANGE, 0, 1, NULL },
2380 { "ass_vsfilter_aspect_compat", mp_property_ass_vsfilter_aspect_compat,
2381 CONF_TYPE_FLAG, M_OPT_RANGE, 0, 1, NULL },
2382 #endif
2384 #ifdef CONFIG_TV
2385 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2386 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_BRIGHTNESS },
2387 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2388 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_CONTRAST },
2389 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2390 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_SATURATION },
2391 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2392 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_HUE },
2393 #endif
2394 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2395 M_OPT_RANGE, 100, 899, .offset = TV_VBI_CONTROL_GET_PAGE },
2396 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2397 M_OPT_RANGE, 0, 64, .offset = TV_VBI_CONTROL_GET_SUBPAGE },
2398 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2399 M_OPT_RANGE, 0, 1, .offset = TV_VBI_CONTROL_GET_MODE },
2400 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2401 M_OPT_RANGE, 0, 3, .offset = TV_VBI_CONTROL_GET_FORMAT },
2402 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2403 M_OPT_RANGE, 0, 2, .offset = TV_VBI_CONTROL_GET_HALF_PAGE },
2404 { NULL, NULL, NULL, 0, 0, 0, NULL }
2408 int mp_property_do(const char *name, int action, void *val, void *ctx)
2410 return m_property_do(mp_properties, name, action, val, ctx);
2413 char *mp_property_print(const char *name, void *ctx)
2415 char *ret = NULL;
2416 if (mp_property_do(name, M_PROPERTY_PRINT, &ret, ctx) <= 0)
2417 return NULL;
2418 return ret;
2421 char *property_expand_string(MPContext *mpctx, char *str)
2423 return m_properties_expand_string(mp_properties, str, mpctx);
2426 void property_print_help(void)
2428 m_properties_print_help_list(mp_properties);
2432 /* List of default ways to show a property on OSD.
2434 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2435 * a bar showing the current position between min/max values of the
2436 * property. In this case osd_msg is only used for terminal output
2437 * if there is no video; it'll be a label shown together with percentage.
2439 * Otherwise setting osd_msg will show the string on OSD, formatted with
2440 * the text value of the property as argument.
2442 static struct property_osd_display {
2443 /// property name
2444 const char *name;
2445 /// progressbar type
2446 int osd_progbar; // -1 is special value for seek indicators
2447 /// osd msg id if it must be shared
2448 int osd_id;
2449 /// osd msg template
2450 const char *osd_msg;
2451 } property_osd_display[] = {
2452 // general
2453 { "loop", 0, -1, _("Loop: %s") },
2454 { "chapter", -1, -1, NULL },
2455 { "capturing", 0, -1, _("Capturing: %s") },
2456 { "pts_association_mode", 0, -1, "PTS association mode: %s" },
2457 { "hr_seek", 0, -1, "hr-seek: %s" },
2458 { "speed", 0, -1, _("Speed: x %6s") },
2459 // audio
2460 { "volume", OSD_VOLUME, -1, _("Volume") },
2461 { "mute", 0, -1, _("Mute: %s") },
2462 { "audio_delay", 0, -1, _("A-V delay: %s") },
2463 { "switch_audio", 0, -1, _("Audio: %s") },
2464 { "balance", OSD_BALANCE, -1, _("Balance") },
2465 // video
2466 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2467 { "ontop", 0, -1, _("Stay on top: %s") },
2468 { "rootwin", 0, -1, _("Rootwin: %s") },
2469 { "border", 0, -1, _("Border: %s") },
2470 { "framedropping", 0, -1, _("Framedropping: %s") },
2471 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2472 { "colormatrix", 0, -1, _("YUV colormatrix: %s") },
2473 { "colormatrix_input_range", 0, -1, _("YUV input range: %s") },
2474 { "colormatrix_output_range", 0, -1, _("RGB output range: %s") },
2475 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2476 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2477 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2478 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2479 { "hue", OSD_HUE, -1, _("Hue") },
2480 { "vsync", 0, -1, _("VSync: %s") },
2481 // subs
2482 { "sub", 0, -1, _("Subtitles: %s") },
2483 { "sub_source", 0, -1, _("Sub source: %s") },
2484 { "sub_vob", 0, -1, _("Subtitles: %s") },
2485 { "sub_demux", 0, -1, _("Subtitles: %s") },
2486 { "sub_file", 0, -1, _("Subtitles: %s") },
2487 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2488 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2489 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2490 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2491 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2492 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2493 { "ass_vsfilter_aspect_compat", 0, -1,
2494 _("Subtitle VSFilter aspect compat: %s")},
2495 #ifdef CONFIG_TV
2496 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2497 { "tv_hue", OSD_HUE, -1, _("Hue") },
2498 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2499 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2500 #endif
2504 static int show_property_osd(MPContext *mpctx, const char *pname)
2506 struct MPOpts *opts = &mpctx->opts;
2507 int r;
2508 m_option_t *prop;
2509 struct property_osd_display *p;
2511 // look for the command
2512 for (p = property_osd_display; p->name; p++)
2513 if (!strcmp(p->name, pname))
2514 break;
2516 if (!p->name)
2517 return -1;
2519 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2520 return -1;
2522 if (p->osd_progbar == -1)
2523 mpctx->add_osd_seek_info = true;
2524 else if (p->osd_progbar) {
2525 if (prop->type == CONF_TYPE_INT) {
2526 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2527 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2528 prop->min, prop->max, r);
2529 } else if (prop->type == CONF_TYPE_FLOAT) {
2530 float f;
2531 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2532 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2533 prop->min, prop->max, f);
2534 } else {
2535 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2536 "Property use an unsupported type.\n");
2537 return -1;
2539 return 0;
2542 if (p->osd_msg) {
2543 char *val = mp_property_print(pname, mpctx);
2544 if (val) {
2545 int index = p - property_osd_display;
2546 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2547 1, opts->osd_duration, p->osd_msg, val);
2548 talloc_free(val);
2551 return 0;
2556 * Command to property bridge
2558 * It is used to handle most commands that just set a property
2559 * and optionally display something on the OSD.
2560 * Two kinds of commands are handled: adjust or toggle.
2562 * Adjust commands take 1 or 2 parameters: <value> <abs>
2563 * If <abs> is non-zero the property is set to the given value
2564 * otherwise it is adjusted.
2566 * Toggle commands take 0 or 1 parameters. With no parameter
2567 * or a value less than the property minimum it just steps the
2568 * property to its next or previous value respectively.
2569 * Otherwise it sets it to the given value.
2572 /// List of the commands that can be handled by setting a property.
2573 static struct {
2574 /// property name
2575 const char *name;
2576 /// cmd id
2577 int cmd;
2578 /// set/adjust or toggle command
2579 int toggle;
2580 } set_prop_cmd[] = {
2581 // general
2582 { "loop", MP_CMD_LOOP, 0},
2583 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2584 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2585 { "pause", MP_CMD_PAUSE, 0},
2586 { "capturing", MP_CMD_CAPTURING, 1},
2587 // audio
2588 { "volume", MP_CMD_VOLUME, 0},
2589 { "mute", MP_CMD_MUTE, 1},
2590 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2591 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2592 { "balance", MP_CMD_BALANCE, 0},
2593 // video
2594 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2595 { "panscan", MP_CMD_PANSCAN, 0},
2596 { "ontop", MP_CMD_VO_ONTOP, 1},
2597 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2598 { "border", MP_CMD_VO_BORDER, 1},
2599 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2600 { "gamma", MP_CMD_GAMMA, 0},
2601 { "brightness", MP_CMD_BRIGHTNESS, 0},
2602 { "contrast", MP_CMD_CONTRAST, 0},
2603 { "saturation", MP_CMD_SATURATION, 0},
2604 { "hue", MP_CMD_HUE, 0},
2605 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2606 // subs
2607 { "sub", MP_CMD_SUB_SELECT, 1},
2608 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2609 { "sub_vob", MP_CMD_SUB_VOB, 1},
2610 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2611 { "sub_file", MP_CMD_SUB_FILE, 1},
2612 { "sub_pos", MP_CMD_SUB_POS, 0},
2613 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2614 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2615 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2616 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2617 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2618 #ifdef CONFIG_ASS
2619 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2620 #endif
2621 #ifdef CONFIG_TV
2622 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2623 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2624 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2625 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2626 #endif
2630 /// Handle commands that set a property.
2631 static bool set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2633 int i, r;
2634 m_option_t *prop;
2635 const char *pname;
2637 // look for the command
2638 for (i = 0; set_prop_cmd[i].name; i++)
2639 if (set_prop_cmd[i].cmd == cmd->id)
2640 break;
2641 if (!(pname = set_prop_cmd[i].name))
2642 return 0;
2644 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2645 return 0;
2647 // toggle command
2648 if (set_prop_cmd[i].toggle) {
2649 // set to value
2650 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2651 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2652 else if (cmd->nargs > 0)
2653 r = mp_property_do(pname, M_PROPERTY_STEP_DOWN, NULL, mpctx);
2654 else
2655 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2656 } else if (cmd->args[1].v.i) //set
2657 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2658 else // adjust
2659 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2661 if (r <= 0)
2662 return 1;
2664 show_property_osd(mpctx, pname);
2666 return 1;
2669 #ifdef CONFIG_DVDNAV
2670 static const struct {
2671 const char *name;
2672 const enum mp_command_type cmd;
2673 } mp_dvdnav_bindings[] = {
2674 { "up", MP_CMD_DVDNAV_UP },
2675 { "down", MP_CMD_DVDNAV_DOWN },
2676 { "left", MP_CMD_DVDNAV_LEFT },
2677 { "right", MP_CMD_DVDNAV_RIGHT },
2678 { "menu", MP_CMD_DVDNAV_MENU },
2679 { "select", MP_CMD_DVDNAV_SELECT },
2680 { "prev", MP_CMD_DVDNAV_PREVMENU },
2681 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2684 * keep old dvdnav sub-command options for a while in order not to
2685 * break slave-mode API too suddenly.
2687 { "1", MP_CMD_DVDNAV_UP },
2688 { "2", MP_CMD_DVDNAV_DOWN },
2689 { "3", MP_CMD_DVDNAV_LEFT },
2690 { "4", MP_CMD_DVDNAV_RIGHT },
2691 { "5", MP_CMD_DVDNAV_MENU },
2692 { "6", MP_CMD_DVDNAV_SELECT },
2693 { "7", MP_CMD_DVDNAV_PREVMENU },
2694 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2695 { NULL, 0 }
2697 #endif
2699 static const char *property_error_string(int error_value)
2701 switch (error_value) {
2702 case M_PROPERTY_ERROR:
2703 return "ERROR";
2704 case M_PROPERTY_UNAVAILABLE:
2705 return "PROPERTY_UNAVAILABLE";
2706 case M_PROPERTY_NOT_IMPLEMENTED:
2707 return "NOT_IMPLEMENTED";
2708 case M_PROPERTY_UNKNOWN:
2709 return "PROPERTY_UNKNOWN";
2710 case M_PROPERTY_DISABLED:
2711 return "DISABLED";
2713 return "UNKNOWN";
2716 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2718 int idx;
2719 int end = start + count;
2720 int after = mpctx->set_of_sub_size - end;
2721 sub_data **subs = mpctx->set_of_subtitles;
2722 #ifdef CONFIG_ASS
2723 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2724 #endif
2725 if (count < 0 || count > mpctx->set_of_sub_size ||
2726 start < 0 || start > mpctx->set_of_sub_size - count) {
2727 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2728 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2729 return;
2731 for (idx = start; idx < end; idx++) {
2732 sub_data *subd = subs[idx];
2733 char *filename = "";
2734 if (subd)
2735 filename = subd->filename;
2736 #ifdef CONFIG_ASS
2737 if (!subd)
2738 filename = ass_tracks[idx]->name;
2739 #endif
2740 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2741 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2742 filename_recode(filename));
2743 sub_free(subd);
2744 subs[idx] = NULL;
2745 #ifdef CONFIG_ASS
2746 if (ass_tracks[idx])
2747 ass_free_track(ass_tracks[idx]);
2748 ass_tracks[idx] = NULL;
2749 #endif
2752 mpctx->global_sub_size -= count;
2753 mpctx->set_of_sub_size -= count;
2754 if (mpctx->set_of_sub_size <= 0)
2755 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2757 memmove(subs + start, subs + end, after * sizeof(*subs));
2758 memset(subs + start + after, 0, count * sizeof(*subs));
2759 #ifdef CONFIG_ASS
2760 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2761 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2762 #endif
2764 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2765 mpctx->global_sub_pos = -2;
2766 mpctx->subdata = NULL;
2767 mpctx->osd->ass_track = NULL;
2768 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2769 } else if (mpctx->set_of_sub_pos >= end) {
2770 mpctx->set_of_sub_pos -= count;
2771 mpctx->global_sub_pos -= count;
2775 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2777 struct MPOpts *opts = &mpctx->opts;
2778 sh_audio_t *const sh_audio = mpctx->sh_audio;
2779 sh_video_t *const sh_video = mpctx->sh_video;
2780 int osd_duration = opts->osd_duration;
2781 int case_fallthrough_hack = 0;
2782 if (set_property_command(mpctx, cmd))
2783 goto old_pause_hack; // was handled already
2784 switch (cmd->id) {
2785 case MP_CMD_SEEK: {
2786 mpctx->add_osd_seek_info = true;
2787 float v = cmd->args[0].v.f;
2788 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2789 int exact = (cmd->nargs > 2) ? cmd->args[2].v.i : 0;
2790 if (abs == 2) { // Absolute seek to a timestamp in seconds
2791 queue_seek(mpctx, MPSEEK_ABSOLUTE, v, exact);
2792 mpctx->osd_function = v > get_current_time(mpctx) ?
2793 OSD_FFW : OSD_REW;
2794 } else if (abs) { /* Absolute seek by percentage */
2795 queue_seek(mpctx, MPSEEK_FACTOR, v / 100.0, exact);
2796 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2797 } else {
2798 queue_seek(mpctx, MPSEEK_RELATIVE, v, exact);
2799 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2801 break;
2804 case MP_CMD_SET_PROPERTY_OSD:
2805 case_fallthrough_hack = 1;
2807 case MP_CMD_SET_PROPERTY: {
2808 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2809 cmd->args[1].v.s, mpctx);
2810 if (r == M_PROPERTY_UNKNOWN)
2811 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2812 "Unknown property: '%s'\n", cmd->args[0].v.s);
2813 else if (r <= 0)
2814 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2815 "Failed to set property '%s' to '%s'.\n",
2816 cmd->args[0].v.s, cmd->args[1].v.s);
2817 else if (case_fallthrough_hack)
2818 show_property_osd(mpctx, cmd->args[0].v.s);
2819 if (r <= 0)
2820 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2821 "ANS_ERROR=%s\n", property_error_string(r));
2822 break;
2825 case MP_CMD_STEP_PROPERTY_OSD:
2826 case_fallthrough_hack = 1;
2828 case MP_CMD_STEP_PROPERTY: {
2829 void *arg = NULL;
2830 int r, i;
2831 double d;
2832 off_t o;
2833 if (cmd->args[1].v.f) {
2834 m_option_t *prop;
2835 if ((r = mp_property_do(cmd->args[0].v.s,
2836 M_PROPERTY_GET_TYPE,
2837 &prop, mpctx)) <= 0)
2838 goto step_prop_err;
2839 if (prop->type == CONF_TYPE_INT ||
2840 prop->type == CONF_TYPE_FLAG)
2841 i = cmd->args[1].v.f, arg = &i;
2842 else if (prop->type == CONF_TYPE_FLOAT)
2843 arg = &cmd->args[1].v.f;
2844 else if (prop->type == CONF_TYPE_DOUBLE ||
2845 prop->type == CONF_TYPE_TIME)
2846 d = cmd->args[1].v.f, arg = &d;
2847 else if (prop->type == CONF_TYPE_POSITION)
2848 o = cmd->args[1].v.f, arg = &o;
2849 else
2850 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2851 "Ignoring step size stepping property '%s'.\n",
2852 cmd->args[0].v.s);
2854 r = mp_property_do(cmd->args[0].v.s,
2855 cmd->args[2].v.i < 0 ?
2856 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2857 arg, mpctx);
2858 step_prop_err:
2859 if (r == M_PROPERTY_UNKNOWN)
2860 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2861 "Unknown property: '%s'\n", cmd->args[0].v.s);
2862 else if (r <= 0)
2863 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2864 "Failed to increment property '%s' by %f.\n",
2865 cmd->args[0].v.s, cmd->args[1].v.f);
2866 else if (case_fallthrough_hack)
2867 show_property_osd(mpctx, cmd->args[0].v.s);
2868 if (r <= 0)
2869 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n",
2870 property_error_string(r));
2871 break;
2874 case MP_CMD_GET_PROPERTY: {
2875 char *tmp;
2876 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2877 &tmp, mpctx);
2878 if (r <= 0) {
2879 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2880 "Failed to get value of property '%s'.\n",
2881 cmd->args[0].v.s);
2882 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n",
2883 property_error_string(r));
2884 break;
2886 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2887 cmd->args[0].v.s, tmp);
2888 talloc_free(tmp);
2889 break;
2892 case MP_CMD_EDL_MARK:
2893 if (edl_fd) {
2894 float v = get_current_time(mpctx);
2895 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2896 mpctx->begin_skip = v;
2897 mp_tmsg(MSGT_CPLAYER, MSGL_INFO,
2898 "EDL skip start, press 'i' again to end block.\n");
2899 } else {
2900 if (mpctx->begin_skip > v)
2901 mp_tmsg(MSGT_CPLAYER, MSGL_WARN,
2902 "EDL skip canceled, last start > stop\n");
2903 else {
2904 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2905 mp_tmsg(MSGT_CPLAYER, MSGL_INFO,
2906 "EDL skip end, line written.\n");
2908 mpctx->begin_skip = MP_NOPTS_VALUE;
2911 break;
2913 case MP_CMD_SWITCH_RATIO:
2914 if (!sh_video)
2915 break;
2916 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2917 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2918 else
2919 opts->movie_aspect = cmd->args[0].v.f;
2920 video_reset_aspect(sh_video);
2921 break;
2923 case MP_CMD_SPEED_INCR: {
2924 float v = cmd->args[0].v.f;
2925 mp_property_do("speed", M_PROPERTY_STEP_UP, &v, mpctx);
2926 show_property_osd(mpctx, "speed");
2927 break;
2930 case MP_CMD_SPEED_MULT:
2931 case_fallthrough_hack = true;
2933 case MP_CMD_SPEED_SET: {
2934 float v = cmd->args[0].v.f;
2935 if (case_fallthrough_hack)
2936 v *= mpctx->opts.playback_speed;
2937 mp_property_do("speed", M_PROPERTY_SET, &v, mpctx);
2938 show_property_osd(mpctx, "speed");
2939 break;
2942 case MP_CMD_FRAME_STEP:
2943 add_step_frame(mpctx);
2944 break;
2946 case MP_CMD_QUIT:
2947 exit_player_with_rc(mpctx, EXIT_QUIT,
2948 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2950 case MP_CMD_PLAY_TREE_STEP: {
2951 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2952 int force = cmd->args[1].v.i;
2955 if (!force && mpctx->playtree_iter) {
2956 play_tree_iter_t *i =
2957 play_tree_iter_new_copy(mpctx->playtree_iter);
2958 if (play_tree_iter_step(i, n, 0) ==
2959 PLAY_TREE_ITER_ENTRY)
2960 mpctx->stop_play =
2961 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2962 play_tree_iter_free(i);
2963 } else
2964 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2965 if (mpctx->stop_play)
2966 mpctx->play_tree_step = n;
2968 break;
2971 case MP_CMD_PLAY_TREE_UP_STEP: {
2972 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2973 int force = cmd->args[1].v.i;
2975 if (!force && mpctx->playtree_iter) {
2976 play_tree_iter_t *i =
2977 play_tree_iter_new_copy(mpctx->playtree_iter);
2978 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2979 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2980 play_tree_iter_free(i);
2981 } else
2982 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2983 break;
2986 case MP_CMD_PLAY_ALT_SRC_STEP:
2987 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2988 int v = cmd->args[0].v.i;
2989 if (v > 0
2990 && mpctx->playtree_iter->file <
2991 mpctx->playtree_iter->num_files)
2992 mpctx->stop_play = PT_NEXT_SRC;
2993 else if (v < 0 && mpctx->playtree_iter->file > 1)
2994 mpctx->stop_play = PT_PREV_SRC;
2996 break;
2998 case MP_CMD_SUB_STEP:
2999 if (sh_video) {
3000 int movement = cmd->args[0].v.i;
3001 step_sub(mpctx->subdata, mpctx->video_pts, movement);
3002 #ifdef CONFIG_ASS
3003 if (mpctx->osd->ass_track)
3004 sub_delay +=
3005 ass_step_sub(mpctx->osd->ass_track,
3006 (mpctx->video_pts +
3007 sub_delay) * 1000 + .5, movement) / 1000.;
3008 #endif
3009 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
3010 "Sub delay: %d ms", ROUND(sub_delay * 1000));
3012 break;
3014 case MP_CMD_SUB_LOG:
3015 log_sub(mpctx);
3016 break;
3018 case MP_CMD_OSD: {
3019 int v = cmd->args[0].v.i;
3020 int max = (opts->term_osd
3021 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
3022 if (opts->osd_level > max)
3023 opts->osd_level = max;
3024 if (v < 0)
3025 opts->osd_level = (opts->osd_level + 1) % (max + 1);
3026 else
3027 opts->osd_level = v > max ? max : v;
3028 /* Show OSD state when disabled, but not when an explicit
3029 argument is given to the OSD command, i.e. in slave mode. */
3030 if (v == -1 && opts->osd_level <= 1)
3031 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
3032 "OSD: %s",
3033 opts->osd_level ? mp_gtext("enabled") :
3034 mp_gtext("disabled"));
3035 else
3036 rm_osd_msg(OSD_MSG_OSD_STATUS);
3037 break;
3040 case MP_CMD_OSD_SHOW_TEXT:
3041 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
3042 (cmd->args[1].v.i <
3043 0 ? osd_duration : cmd->args[1].v.i),
3044 "%s", cmd->args[0].v.s);
3045 break;
3047 case MP_CMD_OSD_SHOW_PROPERTY_TEXT: {
3048 char *txt = m_properties_expand_string(mp_properties,
3049 cmd->args[0].v.s,
3050 mpctx);
3051 // if no argument supplied use default osd_duration, else <arg> ms.
3052 if (txt) {
3053 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
3054 (cmd->args[1].v.i <
3055 0 ? osd_duration : cmd->args[1].v.i),
3056 "%s", txt);
3057 free(txt);
3059 break;
3062 case MP_CMD_LOADFILE: {
3063 play_tree_t *e = play_tree_new();
3064 play_tree_add_file(e, cmd->args[0].v.s);
3066 if (cmd->args[1].v.i) // append
3067 play_tree_append_entry(mpctx->playtree->child, e);
3068 else {
3069 // Go back to the starting point.
3070 while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1)
3071 != PLAY_TREE_ITER_END)
3072 /* NOP */;
3073 play_tree_free_list(mpctx->playtree->child, 1);
3074 play_tree_set_child(mpctx->playtree, e);
3075 pt_iter_goto_head(mpctx->playtree_iter);
3076 mpctx->stop_play = PT_NEXT_SRC;
3078 break;
3081 case MP_CMD_LOADLIST: {
3082 play_tree_t *e = parse_playlist_file(mpctx->mconfig,
3083 bstr(cmd->args[0].v.s));
3084 if (!e)
3085 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
3086 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
3087 else {
3088 if (cmd->args[1].v.i) // append
3089 play_tree_append_entry(mpctx->playtree->child, e);
3090 else {
3091 // Go back to the starting point.
3092 while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1)
3093 != PLAY_TREE_ITER_END)
3094 /* NOP */;
3095 play_tree_free_list(mpctx->playtree->child, 1);
3096 play_tree_set_child(mpctx->playtree, e);
3097 pt_iter_goto_head(mpctx->playtree_iter);
3098 mpctx->stop_play = PT_NEXT_SRC;
3101 break;
3104 case MP_CMD_STOP:
3105 // Go back to the starting point.
3106 while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1) !=
3107 PLAY_TREE_ITER_END)
3108 /* NOP */;
3109 mpctx->stop_play = PT_STOP;
3110 break;
3112 case MP_CMD_OSD_SHOW_PROGRESSION: {
3113 set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3114 set_osd_progressmsg(OSD_MSG_TEXT, 1, osd_duration);
3115 break;
3118 #ifdef CONFIG_RADIO
3119 case MP_CMD_RADIO_STEP_CHANNEL:
3120 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3121 int v = cmd->args[0].v.i;
3122 if (v > 0)
3123 radio_step_channel(mpctx->demuxer->stream,
3124 RADIO_CHANNEL_HIGHER);
3125 else
3126 radio_step_channel(mpctx->demuxer->stream,
3127 RADIO_CHANNEL_LOWER);
3128 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3129 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3130 "Channel: %s",
3131 radio_get_channel_name(mpctx->demuxer->stream));
3134 break;
3136 case MP_CMD_RADIO_SET_CHANNEL:
3137 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3138 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3139 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3140 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3141 "Channel: %s",
3142 radio_get_channel_name(mpctx->demuxer->stream));
3145 break;
3147 case MP_CMD_RADIO_SET_FREQ:
3148 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3149 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3150 break;
3152 case MP_CMD_RADIO_STEP_FREQ:
3153 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3154 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3155 break;
3156 #endif
3158 #ifdef CONFIG_TV
3159 case MP_CMD_TV_START_SCAN:
3160 if (mpctx->file_format == DEMUXER_TYPE_TV)
3161 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv), 1);
3162 break;
3163 case MP_CMD_TV_SET_FREQ:
3164 if (mpctx->file_format == DEMUXER_TYPE_TV)
3165 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3166 cmd->args[0].v.f * 16.0);
3167 #ifdef CONFIG_PVR
3168 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3169 pvr_set_freq(mpctx->stream, ROUND(cmd->args[0].v.f));
3170 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3171 pvr_get_current_channelname(mpctx->stream),
3172 pvr_get_current_stationname(mpctx->stream));
3174 #endif /* CONFIG_PVR */
3175 break;
3177 case MP_CMD_TV_STEP_FREQ:
3178 if (mpctx->file_format == DEMUXER_TYPE_TV)
3179 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3180 cmd->args[0].v.f * 16.0);
3181 #ifdef CONFIG_PVR
3182 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3183 pvr_force_freq_step(mpctx->stream, ROUND(cmd->args[0].v.f));
3184 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3185 pvr_get_current_channelname(mpctx->stream),
3186 pvr_get_current_frequency(mpctx->stream));
3188 #endif /* CONFIG_PVR */
3189 break;
3191 case MP_CMD_TV_SET_NORM:
3192 if (mpctx->file_format == DEMUXER_TYPE_TV)
3193 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3194 cmd->args[0].v.s);
3195 break;
3197 case MP_CMD_TV_STEP_CHANNEL:
3198 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3199 int v = cmd->args[0].v.i;
3200 if (v > 0) {
3201 tv_step_channel((tvi_handle_t *) (mpctx->
3202 demuxer->priv),
3203 TV_CHANNEL_HIGHER);
3204 } else {
3205 tv_step_channel((tvi_handle_t *) (mpctx->
3206 demuxer->priv),
3207 TV_CHANNEL_LOWER);
3209 if (tv_channel_list) {
3210 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3211 "Channel: %s", tv_channel_current->name);
3212 //vo_osd_changed(OSDTYPE_SUBTITLE);
3215 #ifdef CONFIG_PVR
3216 else if (mpctx->stream &&
3217 mpctx->stream->type == STREAMTYPE_PVR) {
3218 pvr_set_channel_step(mpctx->stream, cmd->args[0].v.i);
3219 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3220 pvr_get_current_channelname(mpctx->stream),
3221 pvr_get_current_stationname(mpctx->stream));
3223 #endif /* CONFIG_PVR */
3224 #ifdef CONFIG_DVBIN
3225 if (mpctx->stream->type == STREAMTYPE_DVB) {
3226 int dir;
3227 int v = cmd->args[0].v.i;
3229 mpctx->last_dvb_step = v;
3230 if (v > 0)
3231 dir = DVB_CHANNEL_HIGHER;
3232 else
3233 dir = DVB_CHANNEL_LOWER;
3236 if (dvb_step_channel(mpctx->stream, dir)) {
3237 mpctx->stop_play = PT_NEXT_ENTRY;
3238 mpctx->dvbin_reopen = 1;
3241 #endif /* CONFIG_DVBIN */
3242 break;
3244 case MP_CMD_TV_SET_CHANNEL:
3245 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3246 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3247 cmd->args[0].v.s);
3248 if (tv_channel_list) {
3249 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3250 "Channel: %s", tv_channel_current->name);
3251 //vo_osd_changed(OSDTYPE_SUBTITLE);
3254 #ifdef CONFIG_PVR
3255 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3256 pvr_set_channel(mpctx->stream, cmd->args[0].v.s);
3257 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3258 pvr_get_current_channelname(mpctx->stream),
3259 pvr_get_current_stationname(mpctx->stream));
3261 #endif /* CONFIG_PVR */
3262 break;
3264 #ifdef CONFIG_DVBIN
3265 case MP_CMD_DVB_SET_CHANNEL:
3266 if (mpctx->stream->type == STREAMTYPE_DVB) {
3267 mpctx->last_dvb_step = 1;
3269 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3270 cmd->args[0].v.i)) {
3271 mpctx->stop_play = PT_NEXT_ENTRY;
3272 mpctx->dvbin_reopen = 1;
3275 break;
3276 #endif /* CONFIG_DVBIN */
3278 case MP_CMD_TV_LAST_CHANNEL:
3279 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3280 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3281 if (tv_channel_list) {
3282 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3283 "Channel: %s", tv_channel_current->name);
3284 //vo_osd_changed(OSDTYPE_SUBTITLE);
3287 #ifdef CONFIG_PVR
3288 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3289 pvr_set_lastchannel(mpctx->stream);
3290 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3291 pvr_get_current_channelname(mpctx->stream),
3292 pvr_get_current_stationname(mpctx->stream));
3294 #endif /* CONFIG_PVR */
3295 break;
3297 case MP_CMD_TV_STEP_NORM:
3298 if (mpctx->file_format == DEMUXER_TYPE_TV)
3299 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3300 break;
3302 case MP_CMD_TV_STEP_CHANNEL_LIST:
3303 if (mpctx->file_format == DEMUXER_TYPE_TV)
3304 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3305 break;
3306 #endif /* CONFIG_TV */
3307 case MP_CMD_TV_TELETEXT_ADD_DEC:
3308 if (mpctx->demuxer->teletext)
3309 teletext_control(mpctx->demuxer->teletext, TV_VBI_CONTROL_ADD_DEC,
3310 &(cmd->args[0].v.s));
3311 break;
3312 case MP_CMD_TV_TELETEXT_GO_LINK:
3313 if (mpctx->demuxer->teletext)
3314 teletext_control(mpctx->demuxer->teletext, TV_VBI_CONTROL_GO_LINK,
3315 &(cmd->args[0].v.i));
3316 break;
3318 case MP_CMD_SUB_LOAD:
3319 if (sh_video) {
3320 int n = mpctx->set_of_sub_size;
3321 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3322 if (n != mpctx->set_of_sub_size) {
3323 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3324 ++mpctx->global_sub_size;
3327 break;
3329 case MP_CMD_SUB_REMOVE:
3330 if (sh_video) {
3331 int v = cmd->args[0].v.i;
3332 if (v < 0)
3333 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3334 else if (v < mpctx->set_of_sub_size)
3335 remove_subtitle_range(mpctx, v, 1);
3337 break;
3339 case MP_CMD_GET_SUB_VISIBILITY:
3340 if (sh_video) {
3341 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3342 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3344 break;
3346 case MP_CMD_SCREENSHOT:
3347 screenshot_request(mpctx, cmd->args[0].v.i, cmd->args[1].v.i);
3348 break;
3350 case MP_CMD_VF_CHANGE_RECTANGLE:
3351 if (!sh_video)
3352 break;
3353 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3354 break;
3356 case MP_CMD_GET_TIME_LENGTH:
3357 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3358 get_time_length(mpctx));
3359 break;
3361 case MP_CMD_GET_FILENAME: {
3362 char *inf = get_metadata(mpctx, META_NAME);
3363 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n", inf);
3364 talloc_free(inf);
3365 break;
3368 case MP_CMD_GET_VIDEO_CODEC: {
3369 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3370 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3371 talloc_free(inf);
3372 break;
3375 case MP_CMD_GET_VIDEO_BITRATE: {
3376 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3377 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3378 talloc_free(inf);
3379 break;
3382 case MP_CMD_GET_VIDEO_RESOLUTION: {
3383 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3384 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3385 talloc_free(inf);
3386 break;
3389 case MP_CMD_GET_AUDIO_CODEC: {
3390 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3391 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3392 talloc_free(inf);
3393 break;
3396 case MP_CMD_GET_AUDIO_BITRATE: {
3397 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3398 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3399 talloc_free(inf);
3400 break;
3403 case MP_CMD_GET_AUDIO_SAMPLES: {
3404 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3405 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3406 talloc_free(inf);
3407 break;
3410 case MP_CMD_GET_META_TITLE: {
3411 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3412 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3413 talloc_free(inf);
3414 break;
3417 case MP_CMD_GET_META_ARTIST: {
3418 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3419 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3420 talloc_free(inf);
3421 break;
3424 case MP_CMD_GET_META_ALBUM: {
3425 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3426 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3427 talloc_free(inf);
3428 break;
3431 case MP_CMD_GET_META_YEAR: {
3432 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3433 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3434 talloc_free(inf);
3435 break;
3438 case MP_CMD_GET_META_COMMENT: {
3439 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3440 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3441 talloc_free(inf);
3442 break;
3445 case MP_CMD_GET_META_TRACK: {
3446 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3447 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3448 talloc_free(inf);
3449 break;
3452 case MP_CMD_GET_META_GENRE: {
3453 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3454 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3455 talloc_free(inf);
3456 break;
3459 case MP_CMD_GET_VO_FULLSCREEN:
3460 if (mpctx->video_out && mpctx->video_out->config_ok)
3461 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3462 break;
3464 case MP_CMD_GET_PERCENT_POS:
3465 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3466 get_percent_pos(mpctx));
3467 break;
3469 case MP_CMD_GET_TIME_POS: {
3470 float pos = get_current_time(mpctx);
3471 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3472 break;
3475 case MP_CMD_RUN:
3476 #ifndef __MINGW32__
3477 if (!fork()) {
3478 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3479 exit(0);
3481 #endif
3482 break;
3484 case MP_CMD_KEYDOWN_EVENTS:
3485 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3486 break;
3488 case MP_CMD_SET_MOUSE_POS: {
3489 int pointer_x, pointer_y;
3490 double dx, dy;
3491 pointer_x = cmd->args[0].v.i;
3492 pointer_y = cmd->args[1].v.i;
3493 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3494 #ifdef CONFIG_DVDNAV
3495 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3496 && dx > 0.0 && dy > 0.0) {
3497 int button = -1;
3498 pointer_x = (int) (dx * (double) sh_video->disp_w);
3499 pointer_y = (int) (dy * (double) sh_video->disp_h);
3500 mp_dvdnav_update_mouse_pos(mpctx->stream,
3501 pointer_x, pointer_y, &button);
3502 if (opts->osd_level > 1 && button > 0)
3503 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3504 "Selected button number %d", button);
3506 #endif
3507 break;
3510 #ifdef CONFIG_DVDNAV
3511 case MP_CMD_DVDNAV: {
3512 int button = -1;
3513 int i;
3514 enum mp_command_type command = 0;
3515 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3516 break;
3518 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3519 if (cmd->args[0].v.s &&
3520 !strcasecmp(cmd->args[0].v.s,
3521 mp_dvdnav_bindings[i].name))
3522 command = mp_dvdnav_bindings[i].cmd;
3524 mp_dvdnav_handle_input(mpctx->stream, command, &button);
3525 if (opts->osd_level > 1 && button > 0)
3526 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3527 "Selected button number %d", button);
3528 break;
3531 case MP_CMD_SWITCH_TITLE:
3532 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3533 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3534 break;
3536 #endif
3538 case MP_CMD_AF_SWITCH:
3539 if (sh_audio) {
3540 af_uninit(mpctx->mixer.afilter);
3541 af_init(mpctx->mixer.afilter);
3543 case MP_CMD_AF_ADD:
3544 case MP_CMD_AF_DEL: {
3545 if (!sh_audio)
3546 break;
3547 char *af_args = strdup(cmd->args[0].v.s);
3548 char *af_commands = af_args;
3549 char *af_command;
3550 af_instance_t *af;
3551 while ((af_command = strsep(&af_commands, ",")) != NULL) {
3552 if (cmd->id == MP_CMD_AF_DEL) {
3553 af = af_get(mpctx->mixer.afilter, af_command);
3554 if (af != NULL)
3555 af_remove(mpctx->mixer.afilter, af);
3556 } else
3557 af_add(mpctx->mixer.afilter, af_command);
3559 reinit_audio_chain(mpctx);
3560 free(af_args);
3561 break;
3563 case MP_CMD_AF_CLR:
3564 if (!sh_audio)
3565 break;
3566 af_uninit(mpctx->mixer.afilter);
3567 af_init(mpctx->mixer.afilter);
3568 reinit_audio_chain(mpctx);
3569 break;
3570 case MP_CMD_AF_CMDLINE:
3571 if (sh_audio) {
3572 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3573 if (!af) {
3574 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3575 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3576 break;
3578 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3579 af_reinit(sh_audio->afilter, af);
3581 break;
3583 default:
3584 mp_msg(MSGT_CPLAYER, MSGL_V,
3585 "Received unknown cmd %s\n", cmd->name);
3588 old_pause_hack:
3589 switch (cmd->pausing) {
3590 case 1: // "pausing"
3591 pause_player(mpctx);
3592 break;
3593 case 3: // "pausing_toggle"
3594 if (mpctx->paused)
3595 unpause_player(mpctx);
3596 else
3597 pause_player(mpctx);
3598 break;