configure: disable live555 by default
[mplayer.git] / command.c
blob48f0ecb013540924d08b4da06f4a343ebbbb7828
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 "sub/font_load.h"
46 #include "playtree.h"
47 #include "libao2/audio_out.h"
48 #include "mpcommon.h"
49 #include "mixer.h"
50 #include "libmpcodecs/dec_video.h"
51 #include "libmpcodecs/dec_audio.h"
52 #include "libmpcodecs/dec_teletext.h"
53 #include "osdep/strsep.h"
54 #include "sub/vobsub.h"
55 #include "sub/spudec.h"
56 #include "path.h"
57 #include "sub/ass_mp.h"
58 #include "stream/tv.h"
59 #include "stream/stream_radio.h"
60 #include "stream/pvr.h"
61 #ifdef CONFIG_DVBIN
62 #include "stream/dvbin.h"
63 #endif
64 #ifdef CONFIG_DVDREAD
65 #include "stream/stream_dvd.h"
66 #endif
67 #include "stream/stream_dvdnav.h"
68 #include "m_struct.h"
69 #include "screenshot.h"
71 #include "mp_core.h"
72 #include "mp_fifo.h"
73 #include "libavutil/avstring.h"
75 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
76 double *dx, double *dy)
78 struct MPOpts *opts = &mpctx->opts;
79 struct vo *vo = mpctx->video_out;
80 //remove the borders, if any, and rescale to the range [0,1],[0,1]
81 if (vo_fs) { //we are in full-screen mode
82 if (opts->vo_screenwidth > vo->dwidth)
83 // there are borders along the x axis
84 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
85 if (opts->vo_screenheight > vo->dheight)
86 // there are borders along the y axis (usual way)
87 iy -= (opts->vo_screenheight - vo->dheight) / 2;
89 if (ix < 0 || ix > vo->dwidth) {
90 *dx = *dy = -1.0;
91 return;
92 } //we are on one of the borders
93 if (iy < 0 || iy > vo->dheight) {
94 *dx = *dy = -1.0;
95 return;
96 } //we are on one of the borders
99 *dx = (double) ix / (double) vo->dwidth;
100 *dy = (double) iy / (double) vo->dheight;
102 mp_msg(MSGT_CPLAYER, MSGL_V,
103 "\r\nrescaled coordinates: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
104 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
105 vo->dheight, vo_fs);
108 static int sub_pos_by_source(MPContext *mpctx, int src)
110 int i, cnt = 0;
111 if (src >= SUB_SOURCES || mpctx->sub_counts[src] == 0)
112 return -1;
113 for (i = 0; i < src; i++)
114 cnt += mpctx->sub_counts[i];
115 return cnt;
118 static int sub_source_and_index_by_pos(MPContext *mpctx, int *pos)
120 int start = 0;
121 int i;
122 for (i = 0; i < SUB_SOURCES; i++) {
123 int cnt = mpctx->sub_counts[i];
124 if (*pos >= start && *pos < start + cnt) {
125 *pos -= start;
126 return i;
128 start += cnt;
130 *pos = -1;
131 return -1;
134 static int sub_source_by_pos(MPContext *mpctx, int pos)
136 return sub_source_and_index_by_pos(mpctx, &pos);
139 static int sub_source_pos(MPContext *mpctx)
141 int pos = mpctx->global_sub_pos;
142 sub_source_and_index_by_pos(mpctx, &pos);
143 return pos;
146 static int sub_source(MPContext *mpctx)
148 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
151 static void update_global_sub_size(MPContext *mpctx)
153 struct MPOpts *opts = &mpctx->opts;
154 int i;
155 int cnt = 0;
157 // update number of demuxer sub streams
158 for (i = 0; i < MAX_S_STREAMS; i++)
159 if (mpctx->d_sub->demuxer->s_streams[i])
160 cnt++;
161 if (cnt > mpctx->sub_counts[SUB_SOURCE_DEMUX])
162 mpctx->sub_counts[SUB_SOURCE_DEMUX] = cnt;
164 // update global size
165 mpctx->global_sub_size = 0;
166 for (i = 0; i < SUB_SOURCES; i++)
167 mpctx->global_sub_size += mpctx->sub_counts[i];
169 // update global_sub_pos if we auto-detected a demuxer sub
170 if (mpctx->global_sub_pos == -1) {
171 int sub_id = -1;
172 if (mpctx->demuxer->sub)
173 sub_id = mpctx->demuxer->sub->id;
174 if (sub_id < 0)
175 sub_id = opts->sub_id;
176 if (sub_id >= 0 && sub_id < mpctx->sub_counts[SUB_SOURCE_DEMUX])
177 mpctx->global_sub_pos = sub_pos_by_source(mpctx, SUB_SOURCE_DEMUX) +
178 sub_id;
183 * \brief Log the currently displayed subtitle to a file
185 * Logs the current or last displayed subtitle together with filename
186 * and time information to ~/.mplayer/subtitle_log
188 * Intended purpose is to allow convenient marking of bogus subtitles
189 * which need to be fixed while watching the movie.
192 static void log_sub(struct MPContext *mpctx)
194 char *fname;
195 FILE *f;
196 int i;
197 struct subtitle *vo_sub_last = mpctx->vo_sub_last;
199 if (mpctx->subdata == NULL || vo_sub_last == NULL)
200 return;
201 fname = get_path("subtitle_log");
202 f = fopen(fname, "a");
203 if (!f)
204 return;
205 fprintf(f, "----------------------------------------------------------\n");
206 if (mpctx->subdata->sub_uses_time) {
207 fprintf(f,
208 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
209 mpctx->filename, vo_sub_last->start / 360000,
210 (vo_sub_last->start / 6000) % 60,
211 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
212 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
213 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
214 } else {
215 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
216 vo_sub_last->start, vo_sub_last->end);
218 for (i = 0; i < vo_sub_last->lines; i++)
219 fprintf(f, "%s\n", vo_sub_last->text[i]);
220 fclose(f);
224 static int mp_property_generic_option(struct m_option *prop, int action,
225 void *arg, MPContext *mpctx)
227 char *optname = prop->priv;
228 const struct m_option *opt = m_config_get_option(mpctx->mconfig,
229 bstr(optname));
230 void *valptr = m_option_get_ptr(opt, &mpctx->opts);
232 switch (action) {
233 case M_PROPERTY_GET_TYPE:
234 *(const struct m_option **)arg = opt;
235 return M_PROPERTY_OK;
236 case M_PROPERTY_GET:
237 m_option_copy(opt, arg, valptr);
238 return M_PROPERTY_OK;
239 case M_PROPERTY_SET:
240 m_option_copy(opt, valptr, arg);
241 return M_PROPERTY_OK;
242 case M_PROPERTY_STEP_UP:
243 if (opt->type == &m_option_type_choice) {
244 int v = *(int *) valptr;
245 int best = v;
246 struct m_opt_choice_alternatives *alt;
247 for (alt = opt->priv; alt->name; alt++)
248 if ((unsigned) alt->value - v - 1 < (unsigned) best - v - 1)
249 best = alt->value;
250 *(int *) valptr = best;
251 return M_PROPERTY_OK;
253 break;
255 return M_PROPERTY_NOT_IMPLEMENTED;
258 /// OSD level (RW)
259 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
260 MPContext *mpctx)
262 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
265 /// Loop (RW)
266 static int mp_property_loop(m_option_t *prop, int action, void *arg,
267 MPContext *mpctx)
269 struct MPOpts *opts = &mpctx->opts;
270 switch (action) {
271 case M_PROPERTY_PRINT:
272 if (!arg)
273 return M_PROPERTY_ERROR;
274 if (opts->loop_times < 0)
275 *(char **)arg = talloc_strdup(NULL, "off");
276 else if (opts->loop_times == 0)
277 *(char **)arg = talloc_strdup(NULL, "inf");
278 else
279 break;
280 return M_PROPERTY_OK;
282 return m_property_int_range(prop, action, arg, &opts->loop_times);
285 /// Playback speed (RW)
286 static int mp_property_playback_speed(m_option_t *prop, int action,
287 void *arg, MPContext *mpctx)
289 struct MPOpts *opts = &mpctx->opts;
290 double orig_speed = opts->playback_speed;
291 switch (action) {
292 case M_PROPERTY_SET:
293 if (!arg)
294 return M_PROPERTY_ERROR;
295 opts->playback_speed = *(float *) arg;
296 goto set;
297 case M_PROPERTY_STEP_UP:
298 case M_PROPERTY_STEP_DOWN:
299 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
300 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
301 set:
302 M_PROPERTY_CLAMP(prop, opts->playback_speed);
303 // Adjust time until next frame flip for nosound mode
304 mpctx->time_frame *= orig_speed / opts->playback_speed;
305 reinit_audio_chain(mpctx);
306 return M_PROPERTY_OK;
308 return m_property_float_range(prop, action, arg, &opts->playback_speed);
311 /// filename with path (RO)
312 static int mp_property_path(m_option_t *prop, int action, void *arg,
313 MPContext *mpctx)
315 return m_property_string_ro(prop, action, arg, mpctx->filename);
318 /// filename without path (RO)
319 static int mp_property_filename(m_option_t *prop, int action, void *arg,
320 MPContext *mpctx)
322 char *f;
323 if (!mpctx->filename)
324 return M_PROPERTY_UNAVAILABLE;
325 f = (char *)mp_basename(mpctx->filename);
326 if (!*f)
327 f = mpctx->filename;
328 return m_property_string_ro(prop, action, arg, f);
331 /// Demuxer name (RO)
332 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
333 MPContext *mpctx)
335 if (!mpctx->demuxer)
336 return M_PROPERTY_UNAVAILABLE;
337 return m_property_string_ro(prop, action, arg,
338 (char *) mpctx->demuxer->desc->name);
341 /// Position in the stream (RW)
342 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
343 MPContext *mpctx)
345 if (!mpctx->demuxer || !mpctx->demuxer->stream)
346 return M_PROPERTY_UNAVAILABLE;
347 if (!arg)
348 return M_PROPERTY_ERROR;
349 switch (action) {
350 case M_PROPERTY_GET:
351 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
352 return M_PROPERTY_OK;
353 case M_PROPERTY_SET:
354 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
355 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
356 return M_PROPERTY_OK;
358 return M_PROPERTY_NOT_IMPLEMENTED;
361 /// Stream start offset (RO)
362 static int mp_property_stream_start(m_option_t *prop, int action,
363 void *arg, MPContext *mpctx)
365 if (!mpctx->demuxer || !mpctx->demuxer->stream)
366 return M_PROPERTY_UNAVAILABLE;
367 switch (action) {
368 case M_PROPERTY_GET:
369 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
370 return M_PROPERTY_OK;
372 return M_PROPERTY_NOT_IMPLEMENTED;
375 /// Stream end offset (RO)
376 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
377 MPContext *mpctx)
379 if (!mpctx->demuxer || !mpctx->demuxer->stream)
380 return M_PROPERTY_UNAVAILABLE;
381 switch (action) {
382 case M_PROPERTY_GET:
383 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
384 return M_PROPERTY_OK;
386 return M_PROPERTY_NOT_IMPLEMENTED;
389 /// Stream length (RO)
390 static int mp_property_stream_length(m_option_t *prop, int action,
391 void *arg, MPContext *mpctx)
393 if (!mpctx->demuxer || !mpctx->demuxer->stream)
394 return M_PROPERTY_UNAVAILABLE;
395 switch (action) {
396 case M_PROPERTY_GET:
397 *(off_t *) arg =
398 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
399 return M_PROPERTY_OK;
401 return M_PROPERTY_NOT_IMPLEMENTED;
404 /// Current stream position in seconds (RO)
405 static int mp_property_stream_time_pos(m_option_t *prop, int action,
406 void *arg, MPContext *mpctx)
408 if (!mpctx->demuxer || mpctx->demuxer->stream_pts == MP_NOPTS_VALUE)
409 return M_PROPERTY_UNAVAILABLE;
411 return m_property_time_ro(prop, action, arg, mpctx->demuxer->stream_pts);
415 /// Media length in seconds (RO)
416 static int mp_property_length(m_option_t *prop, int action, void *arg,
417 MPContext *mpctx)
419 double len;
421 if (!mpctx->demuxer ||
422 !(int) (len = get_time_length(mpctx)))
423 return M_PROPERTY_UNAVAILABLE;
425 return m_property_time_ro(prop, action, arg, len);
428 /// Current position in percent (RW)
429 static int mp_property_percent_pos(m_option_t *prop, int action,
430 void *arg, MPContext *mpctx)
432 int pos;
434 if (!mpctx->demuxer)
435 return M_PROPERTY_UNAVAILABLE;
437 switch (action) {
438 case M_PROPERTY_SET:
439 if (!arg)
440 return M_PROPERTY_ERROR;
441 M_PROPERTY_CLAMP(prop, *(int *)arg);
442 pos = *(int *)arg;
443 break;
444 case M_PROPERTY_STEP_UP:
445 case M_PROPERTY_STEP_DOWN:
446 pos = get_percent_pos(mpctx);
447 pos += (arg ? *(int *)arg : 10) *
448 (action == M_PROPERTY_STEP_UP ? 1 : -1);
449 M_PROPERTY_CLAMP(prop, pos);
450 break;
451 default:
452 return m_property_int_ro(prop, action, arg, get_percent_pos(mpctx));
455 queue_seek(mpctx, MPSEEK_FACTOR, pos / 100.0, 0);
456 return M_PROPERTY_OK;
459 /// Current position in seconds (RW)
460 static int mp_property_time_pos(m_option_t *prop, int action,
461 void *arg, MPContext *mpctx)
463 if (!(mpctx->sh_video || mpctx->sh_audio))
464 return M_PROPERTY_UNAVAILABLE;
466 switch (action) {
467 case M_PROPERTY_SET:
468 if (!arg)
469 return M_PROPERTY_ERROR;
470 M_PROPERTY_CLAMP(prop, *(double *)arg);
471 queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double *)arg, 0);
472 return M_PROPERTY_OK;
473 case M_PROPERTY_STEP_UP:
474 case M_PROPERTY_STEP_DOWN:
475 queue_seek(mpctx, MPSEEK_RELATIVE, (arg ? *(double *)arg : 10.0) *
476 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0), 0);
477 return M_PROPERTY_OK;
479 return m_property_time_ro(prop, action, arg, get_current_time(mpctx));
482 /// Current chapter (RW)
483 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
484 MPContext *mpctx)
486 struct MPOpts *opts = &mpctx->opts;
487 int chapter = -1;
488 int step_all;
489 char *chapter_name = NULL;
491 if (mpctx->demuxer)
492 chapter = get_current_chapter(mpctx);
493 if (chapter < -1)
494 return M_PROPERTY_UNAVAILABLE;
496 switch (action) {
497 case M_PROPERTY_GET:
498 if (!arg)
499 return M_PROPERTY_ERROR;
500 *(int *) arg = chapter;
501 return M_PROPERTY_OK;
502 case M_PROPERTY_PRINT: {
503 if (!arg)
504 return M_PROPERTY_ERROR;
505 chapter_name = chapter_display_name(mpctx, chapter);
506 if (!chapter_name)
507 return M_PROPERTY_UNAVAILABLE;
508 *(char **) arg = chapter_name;
509 return M_PROPERTY_OK;
511 case M_PROPERTY_SET:
512 if (!arg)
513 return M_PROPERTY_ERROR;
514 M_PROPERTY_CLAMP(prop, *(int *)arg);
515 step_all = *(int *)arg - chapter;
516 chapter += step_all;
517 break;
518 case M_PROPERTY_STEP_UP:
519 case M_PROPERTY_STEP_DOWN: {
520 step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1)
521 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
522 chapter += step_all;
523 if (chapter < 0)
524 chapter = 0;
525 break;
527 default:
528 return M_PROPERTY_NOT_IMPLEMENTED;
531 double next_pts = 0;
532 queue_seek(mpctx, MPSEEK_NONE, 0, 0);
533 chapter = seek_chapter(mpctx, chapter, &next_pts);
534 if (chapter >= 0) {
535 if (next_pts > -1.0)
536 queue_seek(mpctx, MPSEEK_ABSOLUTE, next_pts, 0);
537 chapter_name = chapter_display_name(mpctx, chapter);
538 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
539 "Chapter: %s", chapter_name);
540 } else if (step_all > 0)
541 queue_seek(mpctx, MPSEEK_RELATIVE, 1000000000, 0);
542 else
543 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
544 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
545 talloc_free(chapter_name);
546 return M_PROPERTY_OK;
549 /// Number of chapters in file
550 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
551 MPContext *mpctx)
553 if (!mpctx->demuxer)
554 return M_PROPERTY_UNAVAILABLE;
555 int count = get_chapter_count(mpctx);
556 return m_property_int_ro(prop, action, arg, count);
559 /// Current dvd angle (RW)
560 static int mp_property_angle(m_option_t *prop, int action, void *arg,
561 MPContext *mpctx)
563 struct MPOpts *opts = &mpctx->opts;
564 int angle = -1;
565 int angles;
567 if (mpctx->demuxer)
568 angle = demuxer_get_current_angle(mpctx->demuxer);
569 if (angle < 0)
570 return M_PROPERTY_UNAVAILABLE;
571 angles = demuxer_angles_count(mpctx->demuxer);
572 if (angles <= 1)
573 return M_PROPERTY_UNAVAILABLE;
575 switch (action) {
576 case M_PROPERTY_GET:
577 if (!arg)
578 return M_PROPERTY_ERROR;
579 *(int *) arg = angle;
580 return M_PROPERTY_OK;
581 case M_PROPERTY_PRINT: {
582 if (!arg)
583 return M_PROPERTY_ERROR;
584 *(char **) arg = talloc_asprintf(NULL, "%d/%d", angle, angles);
585 return M_PROPERTY_OK;
587 case M_PROPERTY_SET:
588 if (!arg)
589 return M_PROPERTY_ERROR;
590 angle = *(int *)arg;
591 M_PROPERTY_CLAMP(prop, angle);
592 break;
593 case M_PROPERTY_STEP_UP:
594 case M_PROPERTY_STEP_DOWN: {
595 int step = 0;
596 if (arg)
597 step = *(int *)arg;
598 if (!step)
599 step = 1;
600 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
601 angle += step;
602 if (angle < 1) //cycle
603 angle = angles;
604 else if (angle > angles)
605 angle = 1;
606 break;
608 default:
609 return M_PROPERTY_NOT_IMPLEMENTED;
611 angle = demuxer_set_angle(mpctx->demuxer, angle);
612 if (angle >= 0) {
613 struct sh_video *sh_video = mpctx->demuxer->video->sh;
614 if (sh_video)
615 resync_video_stream(sh_video);
617 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
618 if (sh_audio)
619 resync_audio_stream(sh_audio);
622 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
623 "Angle: %d/%d", angle, angles);
624 return M_PROPERTY_OK;
627 /// Demuxer meta data
628 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
629 MPContext *mpctx)
631 m_property_action_t *ka;
632 char *meta;
633 static const m_option_t key_type =
635 "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL
637 if (!mpctx->demuxer)
638 return M_PROPERTY_UNAVAILABLE;
640 switch (action) {
641 case M_PROPERTY_GET:
642 if (!arg)
643 return M_PROPERTY_ERROR;
644 *(char ***)arg = mpctx->demuxer->info;
645 return M_PROPERTY_OK;
646 case M_PROPERTY_KEY_ACTION:
647 if (!arg)
648 return M_PROPERTY_ERROR;
649 ka = arg;
650 if (!(meta = demux_info_get(mpctx->demuxer, ka->key)))
651 return M_PROPERTY_UNKNOWN;
652 switch (ka->action) {
653 case M_PROPERTY_GET:
654 if (!ka->arg)
655 return M_PROPERTY_ERROR;
656 *(char **)ka->arg = meta;
657 return M_PROPERTY_OK;
658 case M_PROPERTY_GET_TYPE:
659 if (!ka->arg)
660 return M_PROPERTY_ERROR;
661 *(const m_option_t **)ka->arg = &key_type;
662 return M_PROPERTY_OK;
665 return M_PROPERTY_NOT_IMPLEMENTED;
668 static int mp_property_pause(m_option_t *prop, int action, void *arg,
669 void *ctx)
671 MPContext *mpctx = ctx;
673 switch (action) {
674 case M_PROPERTY_SET:
675 if (!arg)
676 return M_PROPERTY_ERROR;
677 if (mpctx->paused == (bool) * (int *)arg)
678 return M_PROPERTY_OK;
679 case M_PROPERTY_STEP_UP:
680 case M_PROPERTY_STEP_DOWN:
681 if (mpctx->paused) {
682 unpause_player(mpctx);
683 } else {
684 pause_player(mpctx);
686 return M_PROPERTY_OK;
687 default:
688 return m_property_flag(prop, action, arg, &mpctx->paused);
693 /// Volume (RW)
694 static int mp_property_volume(m_option_t *prop, int action, void *arg,
695 MPContext *mpctx)
698 if (!mpctx->sh_audio)
699 return M_PROPERTY_UNAVAILABLE;
701 switch (action) {
702 case M_PROPERTY_GET:
703 if (!arg)
704 return M_PROPERTY_ERROR;
705 mixer_getbothvolume(&mpctx->mixer, arg);
706 return M_PROPERTY_OK;
707 case M_PROPERTY_PRINT: {
708 float vol;
709 if (!arg)
710 return M_PROPERTY_ERROR;
711 mixer_getbothvolume(&mpctx->mixer, &vol);
712 return m_property_float_range(prop, action, arg, &vol);
714 case M_PROPERTY_STEP_UP:
715 case M_PROPERTY_STEP_DOWN:
716 case M_PROPERTY_SET:
717 break;
718 default:
719 return M_PROPERTY_NOT_IMPLEMENTED;
722 mpctx->user_muted = 0;
724 switch (action) {
725 case M_PROPERTY_SET:
726 if (!arg)
727 return M_PROPERTY_ERROR;
728 M_PROPERTY_CLAMP(prop, *(float *) arg);
729 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
730 return M_PROPERTY_OK;
731 case M_PROPERTY_STEP_UP:
732 if (arg && *(float *) arg <= 0)
733 mixer_decvolume(&mpctx->mixer);
734 else
735 mixer_incvolume(&mpctx->mixer);
736 return M_PROPERTY_OK;
737 case M_PROPERTY_STEP_DOWN:
738 if (arg && *(float *) arg <= 0)
739 mixer_incvolume(&mpctx->mixer);
740 else
741 mixer_decvolume(&mpctx->mixer);
742 return M_PROPERTY_OK;
744 return M_PROPERTY_NOT_IMPLEMENTED;
747 /// Mute (RW)
748 static int mp_property_mute(m_option_t *prop, int action, void *arg,
749 MPContext *mpctx)
752 if (!mpctx->sh_audio)
753 return M_PROPERTY_UNAVAILABLE;
755 switch (action) {
756 case M_PROPERTY_SET:
757 if (!arg)
758 return M_PROPERTY_ERROR;
759 if ((!!*(int *) arg) != mpctx->mixer.muted)
760 mixer_mute(&mpctx->mixer);
761 mpctx->user_muted = mpctx->mixer.muted;
762 return M_PROPERTY_OK;
763 case M_PROPERTY_STEP_UP:
764 case M_PROPERTY_STEP_DOWN:
765 mixer_mute(&mpctx->mixer);
766 mpctx->user_muted = mpctx->mixer.muted;
767 return M_PROPERTY_OK;
768 default:
769 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
774 /// Audio delay (RW)
775 static int mp_property_audio_delay(m_option_t *prop, int action,
776 void *arg, MPContext *mpctx)
778 if (!(mpctx->sh_audio && mpctx->sh_video))
779 return M_PROPERTY_UNAVAILABLE;
780 switch (action) {
781 case M_PROPERTY_SET:
782 case M_PROPERTY_STEP_UP:
783 case M_PROPERTY_STEP_DOWN: {
784 int ret;
785 float delay = audio_delay;
786 ret = m_property_delay(prop, action, arg, &audio_delay);
787 if (ret != M_PROPERTY_OK)
788 return ret;
789 if (mpctx->sh_audio)
790 mpctx->delay -= audio_delay - delay;
792 return M_PROPERTY_OK;
793 default:
794 return m_property_delay(prop, action, arg, &audio_delay);
798 /// Audio codec tag (RO)
799 static int mp_property_audio_format(m_option_t *prop, int action,
800 void *arg, MPContext *mpctx)
802 if (!mpctx->sh_audio)
803 return M_PROPERTY_UNAVAILABLE;
804 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
807 /// Audio codec name (RO)
808 static int mp_property_audio_codec(m_option_t *prop, int action,
809 void *arg, MPContext *mpctx)
811 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
812 return M_PROPERTY_UNAVAILABLE;
813 return m_property_string_ro(prop, action, arg,
814 mpctx->sh_audio->codec->name);
817 /// Audio bitrate (RO)
818 static int mp_property_audio_bitrate(m_option_t *prop, int action,
819 void *arg, MPContext *mpctx)
821 if (!mpctx->sh_audio)
822 return M_PROPERTY_UNAVAILABLE;
823 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
826 /// Samplerate (RO)
827 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
828 MPContext *mpctx)
830 if (!mpctx->sh_audio)
831 return M_PROPERTY_UNAVAILABLE;
832 switch (action) {
833 case M_PROPERTY_PRINT:
834 if (!arg)
835 return M_PROPERTY_ERROR;
836 *(char **)arg = talloc_asprintf(NULL, "%d kHz",
837 mpctx->sh_audio->samplerate / 1000);
838 return M_PROPERTY_OK;
840 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
843 /// Number of channels (RO)
844 static int mp_property_channels(m_option_t *prop, int action, void *arg,
845 MPContext *mpctx)
847 if (!mpctx->sh_audio)
848 return M_PROPERTY_UNAVAILABLE;
849 switch (action) {
850 case M_PROPERTY_PRINT:
851 if (!arg)
852 return M_PROPERTY_ERROR;
853 switch (mpctx->sh_audio->channels) {
854 case 1:
855 *(char **) arg = talloc_strdup(NULL, "mono");
856 break;
857 case 2:
858 *(char **) arg = talloc_strdup(NULL, "stereo");
859 break;
860 default:
861 *(char **) arg = talloc_asprintf(NULL, "%d channels",
862 mpctx->sh_audio->channels);
864 return M_PROPERTY_OK;
866 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
869 /// Balance (RW)
870 static int mp_property_balance(m_option_t *prop, int action, void *arg,
871 MPContext *mpctx)
873 float bal;
875 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
876 return M_PROPERTY_UNAVAILABLE;
878 switch (action) {
879 case M_PROPERTY_GET:
880 if (!arg)
881 return M_PROPERTY_ERROR;
882 mixer_getbalance(&mpctx->mixer, arg);
883 return M_PROPERTY_OK;
884 case M_PROPERTY_PRINT: {
885 char **str = arg;
886 if (!arg)
887 return M_PROPERTY_ERROR;
888 mixer_getbalance(&mpctx->mixer, &bal);
889 if (bal == 0.f)
890 *str = talloc_strdup(NULL, "center");
891 else if (bal == -1.f)
892 *str = talloc_strdup(NULL, "left only");
893 else if (bal == 1.f)
894 *str = talloc_strdup(NULL, "right only");
895 else {
896 unsigned right = (bal + 1.f) / 2.f * 100.f;
897 *str = talloc_asprintf(NULL, "left %d%%, right %d%%",
898 100 - right, right);
900 return M_PROPERTY_OK;
902 case M_PROPERTY_STEP_UP:
903 case M_PROPERTY_STEP_DOWN:
904 mixer_getbalance(&mpctx->mixer, &bal);
905 bal += (arg ? *(float *)arg : .1f) *
906 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
907 M_PROPERTY_CLAMP(prop, bal);
908 mixer_setbalance(&mpctx->mixer, bal);
909 return M_PROPERTY_OK;
910 case M_PROPERTY_SET:
911 if (!arg)
912 return M_PROPERTY_ERROR;
913 M_PROPERTY_CLAMP(prop, *(float *)arg);
914 mixer_setbalance(&mpctx->mixer, *(float *)arg);
915 return M_PROPERTY_OK;
917 return M_PROPERTY_NOT_IMPLEMENTED;
920 /// Selected audio id (RW)
921 static int mp_property_audio(m_option_t *prop, int action, void *arg,
922 MPContext *mpctx)
924 int current_id, tmp;
925 if (!mpctx->demuxer || !mpctx->d_audio)
926 return M_PROPERTY_UNAVAILABLE;
927 struct sh_audio *sh = mpctx->sh_audio;
928 current_id = sh ? sh->aid : -2;
930 switch (action) {
931 case M_PROPERTY_GET:
932 if (!arg)
933 return M_PROPERTY_ERROR;
934 *(int *) arg = current_id;
935 return M_PROPERTY_OK;
936 case M_PROPERTY_PRINT:
937 if (!arg)
938 return M_PROPERTY_ERROR;
940 if (current_id < 0)
941 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
942 else if (sh && (sh->lang || sh->title)) {
943 char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
944 if (sh->title)
945 *(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
946 current_id, lang, sh->title);
947 else
948 *(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id,
949 lang);
950 } else {
951 char lang[40];
952 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
953 if (0) ;
954 #ifdef CONFIG_DVDREAD
955 else if (mpctx->stream->type == STREAMTYPE_DVD) {
956 int code = dvd_lang_from_aid(mpctx->stream, current_id);
957 if (code) {
958 lang[0] = code >> 8;
959 lang[1] = code;
960 lang[2] = 0;
963 #endif
965 #ifdef CONFIG_DVDNAV
966 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
967 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
968 #endif
969 *(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id, lang);
971 return M_PROPERTY_OK;
973 case M_PROPERTY_STEP_UP:
974 case M_PROPERTY_SET:
975 if (action == M_PROPERTY_SET && arg)
976 tmp = *((int *) arg);
977 else
978 tmp = -1;
979 int new_id = demuxer_switch_audio(mpctx->d_audio->demuxer, tmp);
980 if (new_id != current_id)
981 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
982 if (new_id != current_id && new_id >= 0) {
983 sh_audio_t *sh2;
984 sh2 = mpctx->d_audio->demuxer->a_streams[mpctx->d_audio->id];
985 sh2->ds = mpctx->d_audio;
986 mpctx->sh_audio = sh2;
987 reinit_audio_chain(mpctx);
989 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
990 return M_PROPERTY_OK;
991 default:
992 return M_PROPERTY_NOT_IMPLEMENTED;
997 /// Selected video id (RW)
998 static int mp_property_video(m_option_t *prop, int action, void *arg,
999 MPContext *mpctx)
1001 struct MPOpts *opts = &mpctx->opts;
1002 int current_id, tmp;
1003 if (!mpctx->demuxer || !mpctx->d_video)
1004 return M_PROPERTY_UNAVAILABLE;
1005 current_id = mpctx->sh_video ? mpctx->sh_video->vid : -2;
1007 switch (action) {
1008 case M_PROPERTY_GET:
1009 if (!arg)
1010 return M_PROPERTY_ERROR;
1011 *(int *) arg = current_id;
1012 return M_PROPERTY_OK;
1013 case M_PROPERTY_PRINT:
1014 if (!arg)
1015 return M_PROPERTY_ERROR;
1017 if (current_id < 0)
1018 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1019 else {
1020 *(char **) arg = talloc_asprintf(NULL, "(%d) %s", current_id,
1021 mp_gtext("unknown"));
1023 return M_PROPERTY_OK;
1025 case M_PROPERTY_STEP_UP:
1026 case M_PROPERTY_SET:
1027 if (action == M_PROPERTY_SET && arg)
1028 tmp = *((int *) arg);
1029 else
1030 tmp = -1;
1031 int new_id = demuxer_switch_video(mpctx->d_video->demuxer, tmp);
1032 if (new_id != current_id)
1033 uninit_player(mpctx, INITIALIZED_VCODEC |
1034 (opts->fixed_vo && new_id >= 0 ? 0 : INITIALIZED_VO));
1035 if (new_id != current_id && new_id >= 0) {
1036 sh_video_t *sh2;
1037 sh2 = mpctx->d_video->demuxer->v_streams[mpctx->d_video->id];
1038 sh2->ds = mpctx->d_video;
1039 mpctx->sh_video = sh2;
1040 reinit_video_chain(mpctx);
1042 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", new_id);
1043 return M_PROPERTY_OK;
1045 default:
1046 return M_PROPERTY_NOT_IMPLEMENTED;
1050 static int mp_property_program(m_option_t *prop, int action, void *arg,
1051 MPContext *mpctx)
1053 demux_program_t prog;
1055 switch (action) {
1056 case M_PROPERTY_STEP_UP:
1057 case M_PROPERTY_SET:
1058 if (action == M_PROPERTY_SET && arg)
1059 prog.progid = *((int *) arg);
1060 else
1061 prog.progid = -1;
1062 if (demux_control(mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1063 &prog) == DEMUXER_CTRL_NOTIMPL)
1064 return M_PROPERTY_ERROR;
1066 if (prog.aid < 0 && prog.vid < 0) {
1067 mp_msg(MSGT_CPLAYER, MSGL_ERR,
1068 "Selected program contains no audio or video streams!\n");
1069 return M_PROPERTY_ERROR;
1071 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1072 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1073 return M_PROPERTY_OK;
1075 default:
1076 return M_PROPERTY_NOT_IMPLEMENTED;
1081 /// Fullscreen state (RW)
1082 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1083 MPContext *mpctx)
1086 if (!mpctx->video_out)
1087 return M_PROPERTY_UNAVAILABLE;
1089 switch (action) {
1090 case M_PROPERTY_SET:
1091 if (!arg)
1092 return M_PROPERTY_ERROR;
1093 M_PROPERTY_CLAMP(prop, *(int *) arg);
1094 if (vo_fs == !!*(int *) arg)
1095 return M_PROPERTY_OK;
1096 case M_PROPERTY_STEP_UP:
1097 case M_PROPERTY_STEP_DOWN:
1098 if (mpctx->video_out->config_ok)
1099 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1100 mpctx->opts.fullscreen = vo_fs;
1101 return M_PROPERTY_OK;
1102 default:
1103 return m_property_flag(prop, action, arg, &vo_fs);
1107 static int mp_property_deinterlace(m_option_t *prop, int action,
1108 void *arg, MPContext *mpctx)
1110 int deinterlace;
1111 vf_instance_t *vf;
1112 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1113 return M_PROPERTY_UNAVAILABLE;
1114 vf = mpctx->sh_video->vfilter;
1115 switch (action) {
1116 case M_PROPERTY_GET:
1117 if (!arg)
1118 return M_PROPERTY_ERROR;
1119 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1120 return M_PROPERTY_OK;
1121 case M_PROPERTY_SET:
1122 if (!arg)
1123 return M_PROPERTY_ERROR;
1124 M_PROPERTY_CLAMP(prop, *(int *) arg);
1125 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1126 return M_PROPERTY_OK;
1127 case M_PROPERTY_STEP_UP:
1128 case M_PROPERTY_STEP_DOWN:
1129 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1130 deinterlace = !deinterlace;
1131 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1132 return M_PROPERTY_OK;
1134 int value = 0;
1135 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1136 return m_property_flag_ro(prop, action, arg, value);
1139 static int colormatrix_property_helper(m_option_t *prop, int action,
1140 void *arg, MPContext *mpctx)
1142 int r = mp_property_generic_option(prop, action, arg, mpctx);
1143 // testing for an actual change is too much effort
1144 switch (action) {
1145 case M_PROPERTY_SET:
1146 case M_PROPERTY_STEP_UP:
1147 case M_PROPERTY_STEP_DOWN:
1148 if (mpctx->sh_video)
1149 set_video_colorspace(mpctx->sh_video);
1150 break;
1152 return r;
1155 static int mp_property_colormatrix(m_option_t *prop, int action, void *arg,
1156 MPContext *mpctx)
1158 struct MPOpts *opts = &mpctx->opts;
1159 switch (action) {
1160 case M_PROPERTY_PRINT:
1161 if (!arg)
1162 return M_PROPERTY_ERROR;
1163 struct mp_csp_details actual = { .format = -1 };
1164 char *req_csp = mp_csp_names[opts->requested_colorspace];
1165 char *real_csp = NULL;
1166 if (mpctx->sh_video) {
1167 struct vf_instance *vf = mpctx->sh_video->vfilter;
1168 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &actual) == true) {
1169 real_csp = mp_csp_names[actual.format];
1170 } else {
1171 real_csp = "Unknown";
1174 char *res;
1175 if (opts->requested_colorspace == MP_CSP_AUTO && real_csp) {
1176 // Caveat: doesn't handle the case when the autodetected colorspace
1177 // is different from the actual colorspace as used by the
1178 // VO - the OSD will display the VO colorspace without
1179 // indication that it doesn't match the requested colorspace.
1180 res = talloc_asprintf(NULL, "Auto (%s)", real_csp);
1181 } else if (opts->requested_colorspace == actual.format || !real_csp) {
1182 res = talloc_strdup(NULL, req_csp);
1183 } else
1184 res = talloc_asprintf(NULL, mp_gtext("%s, but %s used"),
1185 req_csp, real_csp);
1186 *(char **)arg = res;
1187 return M_PROPERTY_OK;
1188 default:;
1189 return colormatrix_property_helper(prop, action, arg, mpctx);
1193 static int levels_property_helper(int offset, m_option_t *prop, int action,
1194 void *arg, MPContext *mpctx)
1196 char *optname = prop->priv;
1197 const struct m_option *opt = m_config_get_option(mpctx->mconfig,
1198 bstr(optname));
1199 int *valptr = (int *)m_option_get_ptr(opt, &mpctx->opts);
1201 switch (action) {
1202 case M_PROPERTY_PRINT:
1203 if (!arg)
1204 return M_PROPERTY_ERROR;
1205 struct mp_csp_details actual = {0};
1206 int actual_level = -1;
1207 char *req_level = m_option_print(opt, valptr);
1208 char *real_level = NULL;
1209 if (mpctx->sh_video) {
1210 struct vf_instance *vf = mpctx->sh_video->vfilter;
1211 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &actual) == true) {
1212 actual_level = *(enum mp_csp_levels *)(((char *)&actual) + offset);
1213 real_level = m_option_print(opt, &actual_level);
1214 } else {
1215 real_level = talloc_strdup(NULL, "Unknown");
1218 char *res;
1219 if (*valptr == MP_CSP_LEVELS_AUTO && real_level) {
1220 res = talloc_asprintf(NULL, "Auto (%s)", real_level);
1221 } else if (*valptr == actual_level || !real_level) {
1222 res = talloc_strdup(NULL, real_level);
1223 } else
1224 res = talloc_asprintf(NULL, mp_gtext("%s, but %s used"),
1225 req_level, real_level);
1226 talloc_free(req_level);
1227 talloc_free(real_level);
1228 *(char **)arg = res;
1229 return M_PROPERTY_OK;
1230 default:;
1231 return colormatrix_property_helper(prop, action, arg, mpctx);
1235 static int mp_property_colormatrix_input_range(m_option_t *prop, int action,
1236 void *arg, MPContext *mpctx)
1238 return levels_property_helper(offsetof(struct mp_csp_details, levels_in),
1239 prop, action, arg, mpctx);
1242 static int mp_property_colormatrix_output_range(m_option_t *prop, int action,
1243 void *arg, MPContext *mpctx)
1245 return levels_property_helper(offsetof(struct mp_csp_details, levels_out),
1246 prop, action, arg, mpctx);
1249 static int mp_property_capture(m_option_t *prop, int action,
1250 void *arg, MPContext *mpctx)
1252 struct MPOpts *opts = &mpctx->opts;
1254 if (!mpctx->stream)
1255 return M_PROPERTY_UNAVAILABLE;
1257 if (!opts->capture_dump) {
1258 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1259 "Capturing not enabled (forgot -capture parameter?)\n");
1260 return M_PROPERTY_ERROR;
1263 int capturing = !!mpctx->stream->capture_file;
1265 int ret = m_property_flag(prop, action, arg, &capturing);
1266 if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
1267 if (capturing) {
1268 mpctx->stream->capture_file = fopen(opts->stream_dump_name, "wb");
1269 if (!mpctx->stream->capture_file) {
1270 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1271 "Error opening capture file: %s\n", strerror(errno));
1272 ret = M_PROPERTY_ERROR;
1274 } else {
1275 fclose(mpctx->stream->capture_file);
1276 mpctx->stream->capture_file = NULL;
1280 return ret;
1283 /// Panscan (RW)
1284 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1285 MPContext *mpctx)
1288 if (!mpctx->video_out
1289 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1290 return M_PROPERTY_UNAVAILABLE;
1292 switch (action) {
1293 case M_PROPERTY_SET:
1294 if (!arg)
1295 return M_PROPERTY_ERROR;
1296 M_PROPERTY_CLAMP(prop, *(float *) arg);
1297 vo_panscan = *(float *) arg;
1298 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1299 return M_PROPERTY_OK;
1300 case M_PROPERTY_STEP_UP:
1301 case M_PROPERTY_STEP_DOWN:
1302 vo_panscan += (arg ? *(float *) arg : 0.1) *
1303 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1304 if (vo_panscan > 1)
1305 vo_panscan = 1;
1306 else if (vo_panscan < 0)
1307 vo_panscan = 0;
1308 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1309 return M_PROPERTY_OK;
1310 default:
1311 return m_property_float_range(prop, action, arg, &vo_panscan);
1315 /// Helper to set vo flags.
1316 /** \ingroup PropertyImplHelper
1318 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1319 int vo_ctrl, int *vo_var, MPContext *mpctx)
1322 if (!mpctx->video_out)
1323 return M_PROPERTY_UNAVAILABLE;
1325 switch (action) {
1326 case M_PROPERTY_SET:
1327 if (!arg)
1328 return M_PROPERTY_ERROR;
1329 M_PROPERTY_CLAMP(prop, *(int *) arg);
1330 if (*vo_var == !!*(int *) arg)
1331 return M_PROPERTY_OK;
1332 case M_PROPERTY_STEP_UP:
1333 case M_PROPERTY_STEP_DOWN:
1334 if (mpctx->video_out->config_ok)
1335 vo_control(mpctx->video_out, vo_ctrl, 0);
1336 return M_PROPERTY_OK;
1337 default:
1338 return m_property_flag(prop, action, arg, vo_var);
1342 /// Window always on top (RW)
1343 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1344 MPContext *mpctx)
1346 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1347 &mpctx->opts.vo_ontop, mpctx);
1350 /// Display in the root window (RW)
1351 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1352 MPContext *mpctx)
1354 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1355 &vo_rootwin, mpctx);
1358 /// Show window borders (RW)
1359 static int mp_property_border(m_option_t *prop, int action, void *arg,
1360 MPContext *mpctx)
1362 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1363 &vo_border, mpctx);
1366 /// Framedropping state (RW)
1367 static int mp_property_framedropping(m_option_t *prop, int action,
1368 void *arg, MPContext *mpctx)
1371 if (!mpctx->sh_video)
1372 return M_PROPERTY_UNAVAILABLE;
1374 switch (action) {
1375 case M_PROPERTY_PRINT:
1376 if (!arg)
1377 return M_PROPERTY_ERROR;
1378 *(char **) arg = talloc_strdup(NULL, frame_dropping == 1 ?
1379 mp_gtext("enabled") :
1380 (frame_dropping == 2 ? mp_gtext("hard") :
1381 mp_gtext("disabled")));
1382 return M_PROPERTY_OK;
1383 default:
1384 return m_property_choice(prop, action, arg, &frame_dropping);
1388 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1389 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1390 MPContext *mpctx)
1392 int *gamma = (int *)((char *)&mpctx->opts + prop->offset);
1393 int r, val;
1395 if (!mpctx->sh_video)
1396 return M_PROPERTY_UNAVAILABLE;
1398 if (gamma[0] == 1000) {
1399 gamma[0] = 0;
1400 get_video_colors(mpctx->sh_video, prop->name, gamma);
1403 switch (action) {
1404 case M_PROPERTY_SET:
1405 if (!arg)
1406 return M_PROPERTY_ERROR;
1407 M_PROPERTY_CLAMP(prop, *(int *) arg);
1408 *gamma = *(int *) arg;
1409 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1410 if (r <= 0)
1411 break;
1412 return r;
1413 case M_PROPERTY_GET:
1414 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1415 if (!arg)
1416 return M_PROPERTY_ERROR;
1417 *(int *)arg = val;
1418 return M_PROPERTY_OK;
1420 break;
1421 case M_PROPERTY_STEP_UP:
1422 case M_PROPERTY_STEP_DOWN:
1423 *gamma += (arg ? *(int *) arg : 1) *
1424 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1425 M_PROPERTY_CLAMP(prop, *gamma);
1426 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1427 if (r <= 0)
1428 break;
1429 return r;
1430 default:
1431 return M_PROPERTY_NOT_IMPLEMENTED;
1434 #ifdef CONFIG_TV
1435 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1436 int l = strlen(prop->name);
1437 char tv_prop[3 + l + 1];
1438 sprintf(tv_prop, "tv_%s", prop->name);
1439 return mp_property_do(tv_prop, action, arg, mpctx);
1441 #endif
1443 return M_PROPERTY_UNAVAILABLE;
1446 /// VSync (RW)
1447 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1448 MPContext *mpctx)
1450 return m_property_flag(prop, action, arg, &vo_vsync);
1453 /// Video codec tag (RO)
1454 static int mp_property_video_format(m_option_t *prop, int action,
1455 void *arg, MPContext *mpctx)
1457 char *meta;
1458 if (!mpctx->sh_video)
1459 return M_PROPERTY_UNAVAILABLE;
1460 switch (action) {
1461 case M_PROPERTY_PRINT:
1462 if (!arg)
1463 return M_PROPERTY_ERROR;
1464 switch (mpctx->sh_video->format) {
1465 case 0x10000001:
1466 meta = talloc_strdup(NULL, "mpeg1");
1467 break;
1468 case 0x10000002:
1469 meta = talloc_strdup(NULL, "mpeg2");
1470 break;
1471 case 0x10000004:
1472 meta = talloc_strdup(NULL, "mpeg4");
1473 break;
1474 case 0x10000005:
1475 meta = talloc_strdup(NULL, "h264");
1476 break;
1477 default:
1478 if (mpctx->sh_video->format >= 0x20202020) {
1479 meta = talloc_asprintf(NULL, "%.4s",
1480 (char *) &mpctx->sh_video->format);
1481 } else
1482 meta = talloc_asprintf(NULL, "0x%08X", mpctx->sh_video->format);
1484 *(char **)arg = meta;
1485 return M_PROPERTY_OK;
1487 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1490 /// Video codec name (RO)
1491 static int mp_property_video_codec(m_option_t *prop, int action,
1492 void *arg, MPContext *mpctx)
1494 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1495 return M_PROPERTY_UNAVAILABLE;
1496 return m_property_string_ro(prop, action, arg,
1497 mpctx->sh_video->codec->name);
1501 /// Video bitrate (RO)
1502 static int mp_property_video_bitrate(m_option_t *prop, int action,
1503 void *arg, MPContext *mpctx)
1505 if (!mpctx->sh_video)
1506 return M_PROPERTY_UNAVAILABLE;
1507 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1510 /// Video display width (RO)
1511 static int mp_property_width(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_w);
1519 /// Video display height (RO)
1520 static int mp_property_height(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_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1528 /// Video fps (RO)
1529 static int mp_property_fps(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->fps);
1537 /// Video aspect (RO)
1538 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1539 MPContext *mpctx)
1541 if (!mpctx->sh_video)
1542 return M_PROPERTY_UNAVAILABLE;
1543 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1547 /// Text subtitle position (RW)
1548 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1549 MPContext *mpctx)
1551 switch (action) {
1552 case M_PROPERTY_SET:
1553 if (!arg)
1554 return M_PROPERTY_ERROR;
1555 case M_PROPERTY_STEP_UP:
1556 case M_PROPERTY_STEP_DOWN:
1557 vo_osd_changed(OSDTYPE_SUBTITLE);
1558 default:
1559 return m_property_int_range(prop, action, arg, &sub_pos);
1563 /// Selected subtitles (RW)
1564 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1565 MPContext *mpctx)
1567 struct MPOpts *opts = &mpctx->opts;
1568 demux_stream_t *const d_sub = mpctx->d_sub;
1569 int source = -1, reset_spu av_unused = 0; // used under CONFIG_DVDREAD
1570 int source_pos = -1;
1572 update_global_sub_size(mpctx);
1573 const int global_sub_size = mpctx->global_sub_size;
1575 if (global_sub_size <= 0)
1576 return M_PROPERTY_UNAVAILABLE;
1578 switch (action) {
1579 case M_PROPERTY_GET:
1580 if (!arg)
1581 return M_PROPERTY_ERROR;
1582 *(int *) arg = mpctx->global_sub_pos;
1583 return M_PROPERTY_OK;
1584 case M_PROPERTY_PRINT:
1585 if (!arg)
1586 return M_PROPERTY_ERROR;
1587 char *sub_name = NULL;
1588 if (mpctx->subdata)
1589 sub_name = mpctx->subdata->filename;
1590 #ifdef CONFIG_ASS
1591 if (mpctx->osd->ass_track)
1592 sub_name = mpctx->osd->ass_track->name;
1593 #endif
1594 if (!sub_name && mpctx->subdata)
1595 sub_name = mpctx->subdata->filename;
1596 if (sub_name) {
1597 const char *tmp = mp_basename(sub_name);
1599 *(char **) arg = talloc_asprintf(NULL, "(%d) %s%s",
1600 mpctx->set_of_sub_pos + 1,
1601 strlen(tmp) < 20 ? "" : "...",
1602 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1603 return M_PROPERTY_OK;
1605 #ifdef CONFIG_DVDNAV
1606 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1607 if (vo_spudec && opts->sub_id >= 0) {
1608 unsigned char lang[3];
1609 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id,
1610 lang)) {
1611 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1612 opts->sub_id, lang);
1613 return M_PROPERTY_OK;
1617 #endif
1619 if ((d_sub->demuxer->type == DEMUXER_TYPE_MATROSKA
1620 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF
1621 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1622 || d_sub->demuxer->type == DEMUXER_TYPE_OGG)
1623 && d_sub->sh && opts->sub_id >= 0) {
1624 struct sh_sub *sh = d_sub->sh;
1625 char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
1626 if (sh->title)
1627 *(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
1628 opts->sub_id, lang, sh->title);
1629 else
1630 *(char **)arg = talloc_asprintf(NULL, "(%d) %s",
1631 opts->sub_id, lang);
1632 return M_PROPERTY_OK;
1635 if (vo_vobsub && vobsub_id >= 0) {
1636 const char *language = mp_gtext("unknown");
1637 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1638 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1639 vobsub_id, language ? language : mp_gtext("unknown"));
1640 return M_PROPERTY_OK;
1642 #ifdef CONFIG_DVDREAD
1643 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1644 && opts->sub_id >= 0) {
1645 char lang[3];
1646 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1647 lang[0] = code >> 8;
1648 lang[1] = code;
1649 lang[2] = 0;
1650 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1651 opts->sub_id, lang);
1652 return M_PROPERTY_OK;
1654 #endif
1655 if (opts->sub_id >= 0) {
1656 *(char **) arg = talloc_asprintf(NULL, "(%d) %s", opts->sub_id,
1657 mp_gtext("unknown"));
1658 return M_PROPERTY_OK;
1660 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1661 return M_PROPERTY_OK;
1663 case M_PROPERTY_SET:
1664 if (!arg)
1665 return M_PROPERTY_ERROR;
1666 if (*(int *) arg < -1)
1667 *(int *) arg = -1;
1668 else if (*(int *) arg >= global_sub_size)
1669 *(int *) arg = global_sub_size - 1;
1670 mpctx->global_sub_pos = *(int *) arg;
1671 break;
1672 case M_PROPERTY_STEP_UP:
1673 mpctx->global_sub_pos += 2;
1674 mpctx->global_sub_pos =
1675 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1676 break;
1677 case M_PROPERTY_STEP_DOWN:
1678 mpctx->global_sub_pos += global_sub_size + 1;
1679 mpctx->global_sub_pos =
1680 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1681 break;
1682 default:
1683 return M_PROPERTY_NOT_IMPLEMENTED;
1686 if (mpctx->global_sub_pos >= 0) {
1687 source = sub_source(mpctx);
1688 source_pos = sub_source_pos(mpctx);
1691 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1692 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1693 global_sub_size,
1694 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1695 mpctx->sub_counts[SUB_SOURCE_SUBS],
1696 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1697 mpctx->global_sub_pos, source);
1699 mpctx->set_of_sub_pos = -1;
1700 mpctx->subdata = NULL;
1702 vobsub_id = -1;
1703 opts->sub_id = -1;
1704 if (d_sub) {
1705 if (d_sub->id > -2)
1706 reset_spu = 1;
1707 d_sub->id = -2;
1709 mpctx->osd->ass_track = NULL;
1710 uninit_player(mpctx, INITIALIZED_SUB);
1712 if (source == SUB_SOURCE_VOBSUB)
1713 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1714 else if (source == SUB_SOURCE_SUBS) {
1715 mpctx->set_of_sub_pos = source_pos;
1716 #ifdef CONFIG_ASS
1717 if (opts->ass_enabled
1718 && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]) {
1719 mpctx->osd->ass_track =
1720 mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1721 mpctx->osd->ass_track_changed = true;
1722 mpctx->osd->vsfilter_aspect =
1723 mpctx->track_was_native_ass[mpctx->set_of_sub_pos];
1724 } else
1725 #endif
1727 mpctx->subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1728 vo_osd_changed(OSDTYPE_SUBTITLE);
1730 } else if (source == SUB_SOURCE_DEMUX) {
1731 opts->sub_id = source_pos;
1732 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1733 int i = 0;
1734 // default: assume 1:1 mapping of sid and stream id
1735 d_sub->id = opts->sub_id;
1736 d_sub->sh = mpctx->d_sub->demuxer->s_streams[d_sub->id];
1737 ds_free_packs(d_sub);
1738 for (i = 0; i < MAX_S_STREAMS; i++) {
1739 sh_sub_t *sh = mpctx->d_sub->demuxer->s_streams[i];
1740 if (sh && sh->sid == opts->sub_id) {
1741 d_sub->id = i;
1742 d_sub->sh = sh;
1743 break;
1746 if (d_sub->sh && d_sub->id >= 0) {
1747 sh_sub_t *sh = d_sub->sh;
1748 if (sh->type == 'v')
1749 init_vo_spudec(mpctx);
1750 else {
1751 sub_init(sh, mpctx->osd);
1752 mpctx->initialized_flags |= INITIALIZED_SUB;
1754 } else {
1755 d_sub->id = -2;
1756 d_sub->sh = NULL;
1760 #ifdef CONFIG_DVDREAD
1761 if (vo_spudec
1762 && (mpctx->stream->type == STREAMTYPE_DVD
1763 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1764 && opts->sub_id < 0 && reset_spu) {
1765 d_sub->id = -2;
1766 d_sub->sh = NULL;
1768 #endif
1770 update_subtitles(mpctx, 0, 0, true);
1772 return M_PROPERTY_OK;
1775 /// Selected sub source (RW)
1776 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1777 MPContext *mpctx)
1779 int source;
1780 update_global_sub_size(mpctx);
1781 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1782 return M_PROPERTY_UNAVAILABLE;
1784 switch (action) {
1785 case M_PROPERTY_GET:
1786 if (!arg)
1787 return M_PROPERTY_ERROR;
1788 *(int *) arg = sub_source(mpctx);
1789 return M_PROPERTY_OK;
1790 case M_PROPERTY_PRINT:
1791 if (!arg)
1792 return M_PROPERTY_ERROR;
1793 char *sourcename;
1794 switch (sub_source(mpctx)) {
1795 case SUB_SOURCE_SUBS:
1796 sourcename = mp_gtext("file");
1797 break;
1798 case SUB_SOURCE_VOBSUB:
1799 sourcename = mp_gtext("vobsub");
1800 break;
1801 case SUB_SOURCE_DEMUX:
1802 sourcename = mp_gtext("embedded");
1803 break;
1804 default:
1805 sourcename = mp_gtext("disabled");
1807 *(char **)arg = talloc_strdup(NULL, sourcename);
1808 return M_PROPERTY_OK;
1809 case M_PROPERTY_SET:
1810 if (!arg)
1811 return M_PROPERTY_ERROR;
1812 M_PROPERTY_CLAMP(prop, *(int *)arg);
1813 if (*(int *) arg < 0)
1814 mpctx->global_sub_pos = -1;
1815 else if (*(int *) arg != sub_source(mpctx)) {
1816 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1817 if (new_pos == -1)
1818 return M_PROPERTY_UNAVAILABLE;
1819 mpctx->global_sub_pos = new_pos;
1821 break;
1822 case M_PROPERTY_STEP_UP:
1823 case M_PROPERTY_STEP_DOWN: {
1824 int step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1)
1825 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1826 int step = (step_all > 0) ? 1 : -1;
1827 int cur_source = sub_source(mpctx);
1828 source = cur_source;
1829 while (step_all) {
1830 source += step;
1831 if (source >= SUB_SOURCES)
1832 source = -1;
1833 else if (source < -1)
1834 source = SUB_SOURCES - 1;
1835 if (source == cur_source || source == -1 ||
1836 mpctx->sub_counts[source])
1837 step_all -= step;
1839 if (source == cur_source)
1840 return M_PROPERTY_OK;
1841 if (source == -1)
1842 mpctx->global_sub_pos = -1;
1843 else
1844 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1845 break;
1847 default:
1848 return M_PROPERTY_NOT_IMPLEMENTED;
1850 --mpctx->global_sub_pos;
1851 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1854 /// Selected subtitles from specific source (RW)
1855 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1856 MPContext *mpctx)
1858 int source, is_cur_source, offset, new_pos;
1859 update_global_sub_size(mpctx);
1860 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1861 return M_PROPERTY_UNAVAILABLE;
1863 if (!strcmp(prop->name, "sub_file"))
1864 source = SUB_SOURCE_SUBS;
1865 else if (!strcmp(prop->name, "sub_vob"))
1866 source = SUB_SOURCE_VOBSUB;
1867 else if (!strcmp(prop->name, "sub_demux"))
1868 source = SUB_SOURCE_DEMUX;
1869 else
1870 return M_PROPERTY_ERROR;
1872 offset = sub_pos_by_source(mpctx, source);
1873 if (offset < 0)
1874 return M_PROPERTY_UNAVAILABLE;
1876 is_cur_source = sub_source(mpctx) == source;
1877 new_pos = mpctx->global_sub_pos;
1878 switch (action) {
1879 case M_PROPERTY_GET:
1880 if (!arg)
1881 return M_PROPERTY_ERROR;
1882 if (is_cur_source) {
1883 *(int *) arg = sub_source_pos(mpctx);
1884 if (source == SUB_SOURCE_VOBSUB)
1885 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1886 } else
1887 *(int *) arg = -1;
1888 return M_PROPERTY_OK;
1889 case M_PROPERTY_PRINT:
1890 if (!arg)
1891 return M_PROPERTY_ERROR;
1892 if (is_cur_source)
1893 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1894 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1895 return M_PROPERTY_OK;
1896 case M_PROPERTY_SET:
1897 if (!arg)
1898 return M_PROPERTY_ERROR;
1899 if (*(int *) arg >= 0) {
1900 int index = *(int *)arg;
1901 if (source == SUB_SOURCE_VOBSUB)
1902 index = vobsub_get_index_by_id(vo_vobsub, index);
1903 new_pos = offset + index;
1904 if (index < 0 || index > mpctx->sub_counts[source]) {
1905 new_pos = -1;
1906 *(int *) arg = -1;
1908 } else
1909 new_pos = -1;
1910 break;
1911 case M_PROPERTY_STEP_UP:
1912 case M_PROPERTY_STEP_DOWN: {
1913 int step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1)
1914 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1915 int step = (step_all > 0) ? 1 : -1;
1916 int max_sub_pos_for_source = -1;
1917 if (!is_cur_source)
1918 new_pos = -1;
1919 while (step_all) {
1920 if (new_pos == -1) {
1921 if (step > 0)
1922 new_pos = offset;
1923 else if (max_sub_pos_for_source == -1) {
1924 // Find max pos for specific source
1925 new_pos = mpctx->global_sub_size - 1;
1926 while (new_pos >= 0 && sub_source(mpctx) != source)
1927 new_pos--;
1928 } else
1929 new_pos = max_sub_pos_for_source;
1930 } else {
1931 new_pos += step;
1932 if (new_pos < offset ||
1933 new_pos >= mpctx->global_sub_size ||
1934 sub_source(mpctx) != source)
1935 new_pos = -1;
1937 step_all -= step;
1939 break;
1941 default:
1942 return M_PROPERTY_NOT_IMPLEMENTED;
1944 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1947 /// Subtitle delay (RW)
1948 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1949 MPContext *mpctx)
1951 if (!mpctx->sh_video)
1952 return M_PROPERTY_UNAVAILABLE;
1953 return m_property_delay(prop, action, arg, &sub_delay);
1956 /// Alignment of text subtitles (RW)
1957 static int mp_property_sub_alignment(m_option_t *prop, int action,
1958 void *arg, MPContext *mpctx)
1960 char *name[] = {
1961 _("top"), _("center"), _("bottom")
1964 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1965 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1966 return M_PROPERTY_UNAVAILABLE;
1968 switch (action) {
1969 case M_PROPERTY_PRINT:
1970 if (!arg)
1971 return M_PROPERTY_ERROR;
1972 M_PROPERTY_CLAMP(prop, sub_alignment);
1973 *(char **) arg = talloc_strdup(NULL, mp_gtext(name[sub_alignment]));
1974 return M_PROPERTY_OK;
1975 case M_PROPERTY_SET:
1976 if (!arg)
1977 return M_PROPERTY_ERROR;
1978 case M_PROPERTY_STEP_UP:
1979 case M_PROPERTY_STEP_DOWN:
1980 vo_osd_changed(OSDTYPE_SUBTITLE);
1981 default:
1982 return m_property_choice(prop, action, arg, &sub_alignment);
1986 /// Subtitle visibility (RW)
1987 static int mp_property_sub_visibility(m_option_t *prop, int action,
1988 void *arg, MPContext *mpctx)
1990 if (!mpctx->sh_video)
1991 return M_PROPERTY_UNAVAILABLE;
1993 switch (action) {
1994 case M_PROPERTY_SET:
1995 if (!arg)
1996 return M_PROPERTY_ERROR;
1997 case M_PROPERTY_STEP_UP:
1998 case M_PROPERTY_STEP_DOWN:
1999 vo_osd_changed(OSDTYPE_SUBTITLE);
2000 if (vo_spudec)
2001 vo_osd_changed(OSDTYPE_SPU);
2002 default:
2003 return m_property_flag(prop, action, arg, &sub_visibility);
2007 #ifdef CONFIG_ASS
2008 /// Use margins for libass subtitles (RW)
2009 static int mp_property_ass_use_margins(m_option_t *prop, int action,
2010 void *arg, MPContext *mpctx)
2012 struct MPOpts *opts = &mpctx->opts;
2013 if (!mpctx->sh_video)
2014 return M_PROPERTY_UNAVAILABLE;
2016 switch (action) {
2017 case M_PROPERTY_SET:
2018 if (!arg)
2019 return M_PROPERTY_ERROR;
2020 case M_PROPERTY_STEP_UP:
2021 case M_PROPERTY_STEP_DOWN:
2022 mpctx->osd->ass_force_reload = true;
2023 default:
2024 return m_property_flag(prop, action, arg, &opts->ass_use_margins);
2028 static int mp_property_ass_vsfilter_aspect_compat(m_option_t *prop, int action,
2029 void *arg, MPContext *mpctx)
2031 if (!mpctx->sh_video)
2032 return M_PROPERTY_UNAVAILABLE;
2034 switch (action) {
2035 case M_PROPERTY_SET:
2036 if (!arg)
2037 return M_PROPERTY_ERROR;
2038 case M_PROPERTY_STEP_UP:
2039 case M_PROPERTY_STEP_DOWN:
2040 //has to re-render subs with new aspect ratio
2041 mpctx->osd->ass_force_reload = 1;
2042 default:
2043 return m_property_flag(prop, action, arg,
2044 &mpctx->opts.ass_vsfilter_aspect_compat);
2048 #endif
2050 /// Show only forced subtitles (RW)
2051 static int mp_property_sub_forced_only(m_option_t *prop, int action,
2052 void *arg, MPContext *mpctx)
2054 if (!vo_spudec)
2055 return M_PROPERTY_UNAVAILABLE;
2057 switch (action) {
2058 case M_PROPERTY_SET:
2059 if (!arg)
2060 return M_PROPERTY_ERROR;
2061 case M_PROPERTY_STEP_UP:
2062 case M_PROPERTY_STEP_DOWN:
2063 m_property_flag(prop, action, arg, &forced_subs_only);
2064 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
2065 return M_PROPERTY_OK;
2066 default:
2067 return m_property_flag(prop, action, arg, &forced_subs_only);
2072 #ifdef CONFIG_FREETYPE
2073 /// Subtitle scale (RW)
2074 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
2075 MPContext *mpctx)
2077 struct MPOpts *opts = &mpctx->opts;
2079 switch (action) {
2080 case M_PROPERTY_SET:
2081 if (!arg)
2082 return M_PROPERTY_ERROR;
2083 M_PROPERTY_CLAMP(prop, *(float *) arg);
2084 #ifdef CONFIG_ASS
2085 if (opts->ass_enabled) {
2086 opts->ass_font_scale = *(float *) arg;
2087 mpctx->osd->ass_force_reload = true;
2089 #endif
2090 text_font_scale_factor = *(float *) arg;
2091 force_load_font = 1;
2092 vo_osd_changed(OSDTYPE_SUBTITLE);
2093 return M_PROPERTY_OK;
2094 case M_PROPERTY_STEP_UP:
2095 case M_PROPERTY_STEP_DOWN:
2096 #ifdef CONFIG_ASS
2097 if (opts->ass_enabled) {
2098 opts->ass_font_scale += (arg ? *(float *) arg : 0.1) *
2099 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2100 M_PROPERTY_CLAMP(prop, opts->ass_font_scale);
2101 mpctx->osd->ass_force_reload = true;
2103 #endif
2104 text_font_scale_factor += (arg ? *(float *) arg : 0.1) *
2105 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2106 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
2107 force_load_font = 1;
2108 vo_osd_changed(OSDTYPE_SUBTITLE);
2109 return M_PROPERTY_OK;
2110 default:
2111 #ifdef CONFIG_ASS
2112 if (opts->ass_enabled)
2113 return m_property_float_ro(prop, action, arg, opts->ass_font_scale);
2114 else
2115 #endif
2116 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
2119 #endif
2122 #ifdef CONFIG_TV
2124 /// TV color settings (RW)
2125 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2126 MPContext *mpctx)
2128 int r, val;
2129 tvi_handle_t *tvh = mpctx->demuxer->priv;
2130 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2131 return M_PROPERTY_UNAVAILABLE;
2133 switch (action) {
2134 case M_PROPERTY_SET:
2135 if (!arg)
2136 return M_PROPERTY_ERROR;
2137 M_PROPERTY_CLAMP(prop, *(int *) arg);
2138 return tv_set_color_options(tvh, prop->offset, *(int *) arg);
2139 case M_PROPERTY_GET:
2140 return tv_get_color_options(tvh, prop->offset, arg);
2141 case M_PROPERTY_STEP_UP:
2142 case M_PROPERTY_STEP_DOWN:
2143 if ((r = tv_get_color_options(tvh, prop->offset, &val)) >= 0) {
2144 if (!r)
2145 return M_PROPERTY_ERROR;
2146 val += (arg ? *(int *) arg : 1) *
2147 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2148 M_PROPERTY_CLAMP(prop, val);
2149 return tv_set_color_options(tvh, prop->offset, val);
2151 return M_PROPERTY_ERROR;
2153 return M_PROPERTY_NOT_IMPLEMENTED;
2156 #endif
2158 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2159 MPContext *mpctx)
2161 int val, result;
2162 int base_ioctl = prop->offset;
2164 for teletext's GET,SET,STEP ioctls this is not 0
2165 SET is GET+1
2166 STEP is GET+2
2168 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2169 return M_PROPERTY_UNAVAILABLE;
2170 if (!base_ioctl)
2171 return M_PROPERTY_ERROR;
2173 switch (action) {
2174 case M_PROPERTY_GET:
2175 if (!arg)
2176 return M_PROPERTY_ERROR;
2177 result = teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2178 break;
2179 case M_PROPERTY_SET:
2180 if (!arg)
2181 return M_PROPERTY_ERROR;
2182 M_PROPERTY_CLAMP(prop, *(int *) arg);
2183 result = teletext_control(mpctx->demuxer->teletext, base_ioctl + 1,
2184 arg);
2185 break;
2186 case M_PROPERTY_STEP_UP:
2187 case M_PROPERTY_STEP_DOWN:
2188 result = teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2189 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ?
2190 -1 : 1);
2191 result = teletext_control(mpctx->demuxer->teletext, base_ioctl + 1,
2192 &val);
2193 break;
2194 default:
2195 return M_PROPERTY_NOT_IMPLEMENTED;
2198 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2201 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2202 MPContext *mpctx)
2204 int result;
2205 int val;
2207 //with tvh==NULL will fail too
2208 result = mp_property_teletext_common(prop, action, arg, mpctx);
2209 if (result != M_PROPERTY_OK)
2210 return result;
2212 if (teletext_control(mpctx->demuxer->teletext,
2213 prop->offset, &val) == VBI_CONTROL_TRUE && val)
2214 mp_input_set_section(mpctx->input, "teletext");
2215 else
2216 mp_input_set_section(mpctx->input, "tv");
2217 return M_PROPERTY_OK;
2220 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2221 MPContext *mpctx)
2223 int result;
2224 int val;
2225 if (!mpctx->demuxer->teletext)
2226 return M_PROPERTY_UNAVAILABLE;
2227 switch (action) {
2228 case M_PROPERTY_STEP_UP:
2229 case M_PROPERTY_STEP_DOWN:
2230 //This should be handled separately
2231 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ?
2232 -1 : 1);
2233 result = teletext_control(mpctx->demuxer->teletext,
2234 TV_VBI_CONTROL_STEP_PAGE, &val);
2235 break;
2236 default:
2237 result = mp_property_teletext_common(prop, action, arg, mpctx);
2239 return result;
2243 /// All properties available in MPlayer.
2244 /** \ingroup Properties
2246 static const m_option_t mp_properties[] = {
2247 // General
2248 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2249 M_OPT_RANGE, 0, 3, NULL },
2250 { "loop", mp_property_loop, CONF_TYPE_INT,
2251 M_OPT_MIN, -1, 0, NULL },
2252 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2253 M_OPT_RANGE, 0.01, 100.0, NULL },
2254 { "filename", mp_property_filename, CONF_TYPE_STRING,
2255 0, 0, 0, NULL },
2256 { "path", mp_property_path, CONF_TYPE_STRING,
2257 0, 0, 0, NULL },
2258 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2259 0, 0, 0, NULL },
2260 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2261 M_OPT_MIN, 0, 0, NULL },
2262 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2263 M_OPT_MIN, 0, 0, NULL },
2264 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2265 M_OPT_MIN, 0, 0, NULL },
2266 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2267 M_OPT_MIN, 0, 0, NULL },
2268 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2269 M_OPT_MIN, 0, 0, NULL },
2270 { "length", mp_property_length, CONF_TYPE_TIME,
2271 M_OPT_MIN, 0, 0, NULL },
2272 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2273 M_OPT_RANGE, 0, 100, NULL },
2274 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2275 M_OPT_MIN, 0, 0, NULL },
2276 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2277 M_OPT_MIN, 0, 0, NULL },
2278 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2279 0, 0, 0, NULL },
2280 { "angle", mp_property_angle, CONF_TYPE_INT,
2281 CONF_RANGE, -2, 10, NULL },
2282 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2283 0, 0, 0, NULL },
2284 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2285 M_OPT_RANGE, 0, 1, NULL },
2286 { "capturing", mp_property_capture, CONF_TYPE_FLAG,
2287 M_OPT_RANGE, 0, 1, NULL },
2288 { "pts_association_mode", mp_property_generic_option, &m_option_type_choice,
2289 0, 0, 0, "pts-association-mode" },
2290 { "hr_seek", mp_property_generic_option, &m_option_type_choice,
2291 0, 0, 0, "hr-seek" },
2293 // Audio
2294 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2295 M_OPT_RANGE, 0, 100, NULL },
2296 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2297 M_OPT_RANGE, 0, 1, NULL },
2298 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2299 M_OPT_RANGE, -100, 100, NULL },
2300 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2301 0, 0, 0, NULL },
2302 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2303 0, 0, 0, NULL },
2304 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2305 0, 0, 0, NULL },
2306 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2307 0, 0, 0, NULL },
2308 { "channels", mp_property_channels, CONF_TYPE_INT,
2309 0, 0, 0, NULL },
2310 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2311 CONF_RANGE, -2, 65535, NULL },
2312 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2313 M_OPT_RANGE, -1, 1, NULL },
2315 // Video
2316 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2317 M_OPT_RANGE, 0, 1, NULL },
2318 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2319 M_OPT_RANGE, 0, 1, NULL },
2320 { "colormatrix", mp_property_colormatrix, &m_option_type_choice,
2321 0, 0, 0, "colormatrix" },
2322 { "colormatrix_input_range", mp_property_colormatrix_input_range, &m_option_type_choice,
2323 0, 0, 0, "colormatrix-input-range" },
2324 { "colormatrix_output_range", mp_property_colormatrix_output_range, &m_option_type_choice,
2325 0, 0, 0, "colormatrix-output-range" },
2326 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2327 M_OPT_RANGE, 0, 1, NULL },
2328 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2329 M_OPT_RANGE, 0, 1, NULL },
2330 { "border", mp_property_border, CONF_TYPE_FLAG,
2331 M_OPT_RANGE, 0, 1, NULL },
2332 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2333 M_OPT_RANGE, 0, 2, NULL },
2334 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2335 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_gamma)},
2336 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2337 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_brightness) },
2338 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2339 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_contrast) },
2340 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2341 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_saturation) },
2342 { "hue", mp_property_gamma, CONF_TYPE_INT,
2343 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_hue) },
2344 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2345 M_OPT_RANGE, 0, 1, NULL },
2346 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2347 M_OPT_RANGE, 0, 1, NULL },
2348 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2349 0, 0, 0, NULL },
2350 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2351 0, 0, 0, NULL },
2352 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2353 0, 0, 0, NULL },
2354 { "width", mp_property_width, CONF_TYPE_INT,
2355 0, 0, 0, NULL },
2356 { "height", mp_property_height, CONF_TYPE_INT,
2357 0, 0, 0, NULL },
2358 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2359 0, 0, 0, NULL },
2360 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2361 0, 0, 0, NULL },
2362 { "switch_video", mp_property_video, CONF_TYPE_INT,
2363 CONF_RANGE, -2, 65535, NULL },
2364 { "switch_program", mp_property_program, CONF_TYPE_INT,
2365 CONF_RANGE, -1, 65535, NULL },
2367 // Subs
2368 { "sub", mp_property_sub, CONF_TYPE_INT,
2369 M_OPT_MIN, -1, 0, NULL },
2370 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2371 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2372 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2373 M_OPT_MIN, -1, 0, NULL },
2374 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2375 M_OPT_MIN, -1, 0, NULL },
2376 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2377 M_OPT_MIN, -1, 0, NULL },
2378 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2379 0, 0, 0, NULL },
2380 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2381 M_OPT_RANGE, 0, 100, NULL },
2382 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2383 M_OPT_RANGE, 0, 2, NULL },
2384 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2385 M_OPT_RANGE, 0, 1, NULL },
2386 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2387 M_OPT_RANGE, 0, 1, NULL },
2388 #ifdef CONFIG_FREETYPE
2389 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2390 M_OPT_RANGE, 0, 100, NULL },
2391 #endif
2392 #ifdef CONFIG_ASS
2393 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2394 M_OPT_RANGE, 0, 1, NULL },
2395 { "ass_vsfilter_aspect_compat", mp_property_ass_vsfilter_aspect_compat,
2396 CONF_TYPE_FLAG, M_OPT_RANGE, 0, 1, NULL },
2397 #endif
2399 #ifdef CONFIG_TV
2400 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2401 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_BRIGHTNESS },
2402 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2403 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_CONTRAST },
2404 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2405 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_SATURATION },
2406 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2407 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_HUE },
2408 #endif
2409 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2410 M_OPT_RANGE, 100, 899, .offset = TV_VBI_CONTROL_GET_PAGE },
2411 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2412 M_OPT_RANGE, 0, 64, .offset = TV_VBI_CONTROL_GET_SUBPAGE },
2413 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2414 M_OPT_RANGE, 0, 1, .offset = TV_VBI_CONTROL_GET_MODE },
2415 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2416 M_OPT_RANGE, 0, 3, .offset = TV_VBI_CONTROL_GET_FORMAT },
2417 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2418 M_OPT_RANGE, 0, 2, .offset = TV_VBI_CONTROL_GET_HALF_PAGE },
2419 { NULL, NULL, NULL, 0, 0, 0, NULL }
2423 int mp_property_do(const char *name, int action, void *val, void *ctx)
2425 return m_property_do(mp_properties, name, action, val, ctx);
2428 char *mp_property_print(const char *name, void *ctx)
2430 char *ret = NULL;
2431 if (mp_property_do(name, M_PROPERTY_PRINT, &ret, ctx) <= 0)
2432 return NULL;
2433 return ret;
2436 char *property_expand_string(MPContext *mpctx, char *str)
2438 return m_properties_expand_string(mp_properties, str, mpctx);
2441 void property_print_help(void)
2443 m_properties_print_help_list(mp_properties);
2447 /* List of default ways to show a property on OSD.
2449 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2450 * a bar showing the current position between min/max values of the
2451 * property. In this case osd_msg is only used for terminal output
2452 * if there is no video; it'll be a label shown together with percentage.
2454 * Otherwise setting osd_msg will show the string on OSD, formatted with
2455 * the text value of the property as argument.
2457 static struct property_osd_display {
2458 /// property name
2459 const char *name;
2460 /// progressbar type
2461 int osd_progbar; // -1 is special value for seek indicators
2462 /// osd msg id if it must be shared
2463 int osd_id;
2464 /// osd msg template
2465 const char *osd_msg;
2466 } property_osd_display[] = {
2467 // general
2468 { "loop", 0, -1, _("Loop: %s") },
2469 { "chapter", -1, -1, NULL },
2470 { "capturing", 0, -1, _("Capturing: %s") },
2471 { "pts_association_mode", 0, -1, "PTS association mode: %s" },
2472 { "hr_seek", 0, -1, "hr-seek: %s" },
2473 { "speed", 0, -1, _("Speed: x %6s") },
2474 // audio
2475 { "volume", OSD_VOLUME, -1, _("Volume") },
2476 { "mute", 0, -1, _("Mute: %s") },
2477 { "audio_delay", 0, -1, _("A-V delay: %s") },
2478 { "switch_audio", 0, -1, _("Audio: %s") },
2479 { "balance", OSD_BALANCE, -1, _("Balance") },
2480 // video
2481 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2482 { "ontop", 0, -1, _("Stay on top: %s") },
2483 { "rootwin", 0, -1, _("Rootwin: %s") },
2484 { "border", 0, -1, _("Border: %s") },
2485 { "framedropping", 0, -1, _("Framedropping: %s") },
2486 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2487 { "colormatrix", 0, -1, _("YUV colormatrix: %s") },
2488 { "colormatrix_input_range", 0, -1, _("YUV input range: %s") },
2489 { "colormatrix_output_range", 0, -1, _("RGB output range: %s") },
2490 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2491 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2492 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2493 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2494 { "hue", OSD_HUE, -1, _("Hue") },
2495 { "vsync", 0, -1, _("VSync: %s") },
2496 // subs
2497 { "sub", 0, -1, _("Subtitles: %s") },
2498 { "sub_source", 0, -1, _("Sub source: %s") },
2499 { "sub_vob", 0, -1, _("Subtitles: %s") },
2500 { "sub_demux", 0, -1, _("Subtitles: %s") },
2501 { "sub_file", 0, -1, _("Subtitles: %s") },
2502 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2503 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2504 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2505 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2506 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2507 #ifdef CONFIG_FREETYPE
2508 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2509 #endif
2510 { "ass_vsfilter_aspect_compat", 0, -1,
2511 _("Subtitle VSFilter aspect compat: %s")},
2512 #ifdef CONFIG_TV
2513 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2514 { "tv_hue", OSD_HUE, -1, _("Hue") },
2515 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2516 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2517 #endif
2521 static int show_property_osd(MPContext *mpctx, const char *pname)
2523 struct MPOpts *opts = &mpctx->opts;
2524 int r;
2525 m_option_t *prop;
2526 struct property_osd_display *p;
2528 // look for the command
2529 for (p = property_osd_display; p->name; p++)
2530 if (!strcmp(p->name, pname))
2531 break;
2533 if (!p->name)
2534 return -1;
2536 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2537 return -1;
2539 if (p->osd_progbar == -1)
2540 mpctx->add_osd_seek_info = true;
2541 else if (p->osd_progbar) {
2542 if (prop->type == CONF_TYPE_INT) {
2543 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2544 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2545 prop->min, prop->max, r);
2546 } else if (prop->type == CONF_TYPE_FLOAT) {
2547 float f;
2548 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2549 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2550 prop->min, prop->max, f);
2551 } else {
2552 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2553 "Property use an unsupported type.\n");
2554 return -1;
2556 return 0;
2559 if (p->osd_msg) {
2560 char *val = mp_property_print(pname, mpctx);
2561 if (val) {
2562 int index = p - property_osd_display;
2563 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2564 1, opts->osd_duration, p->osd_msg, val);
2565 talloc_free(val);
2568 return 0;
2573 * Command to property bridge
2575 * It is used to handle most commands that just set a property
2576 * and optionally display something on the OSD.
2577 * Two kinds of commands are handled: adjust or toggle.
2579 * Adjust commands take 1 or 2 parameters: <value> <abs>
2580 * If <abs> is non-zero the property is set to the given value
2581 * otherwise it is adjusted.
2583 * Toggle commands take 0 or 1 parameters. With no parameter
2584 * or a value less than the property minimum it just steps the
2585 * property to its next or previous value respectively.
2586 * Otherwise it sets it to the given value.
2589 /// List of the commands that can be handled by setting a property.
2590 static struct {
2591 /// property name
2592 const char *name;
2593 /// cmd id
2594 int cmd;
2595 /// set/adjust or toggle command
2596 int toggle;
2597 } set_prop_cmd[] = {
2598 // general
2599 { "loop", MP_CMD_LOOP, 0},
2600 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2601 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2602 { "pause", MP_CMD_PAUSE, 0},
2603 { "capturing", MP_CMD_CAPTURING, 1},
2604 // audio
2605 { "volume", MP_CMD_VOLUME, 0},
2606 { "mute", MP_CMD_MUTE, 1},
2607 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2608 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2609 { "balance", MP_CMD_BALANCE, 0},
2610 // video
2611 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2612 { "panscan", MP_CMD_PANSCAN, 0},
2613 { "ontop", MP_CMD_VO_ONTOP, 1},
2614 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2615 { "border", MP_CMD_VO_BORDER, 1},
2616 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2617 { "gamma", MP_CMD_GAMMA, 0},
2618 { "brightness", MP_CMD_BRIGHTNESS, 0},
2619 { "contrast", MP_CMD_CONTRAST, 0},
2620 { "saturation", MP_CMD_SATURATION, 0},
2621 { "hue", MP_CMD_HUE, 0},
2622 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2623 // subs
2624 { "sub", MP_CMD_SUB_SELECT, 1},
2625 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2626 { "sub_vob", MP_CMD_SUB_VOB, 1},
2627 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2628 { "sub_file", MP_CMD_SUB_FILE, 1},
2629 { "sub_pos", MP_CMD_SUB_POS, 0},
2630 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2631 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2632 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2633 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2634 #ifdef CONFIG_FREETYPE
2635 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2636 #endif
2637 #ifdef CONFIG_ASS
2638 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2639 #endif
2640 #ifdef CONFIG_TV
2641 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2642 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2643 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2644 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2645 #endif
2649 /// Handle commands that set a property.
2650 static bool set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2652 int i, r;
2653 m_option_t *prop;
2654 const char *pname;
2656 // look for the command
2657 for (i = 0; set_prop_cmd[i].name; i++)
2658 if (set_prop_cmd[i].cmd == cmd->id)
2659 break;
2660 if (!(pname = set_prop_cmd[i].name))
2661 return 0;
2663 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2664 return 0;
2666 // toggle command
2667 if (set_prop_cmd[i].toggle) {
2668 // set to value
2669 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2670 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2671 else if (cmd->nargs > 0)
2672 r = mp_property_do(pname, M_PROPERTY_STEP_DOWN, NULL, mpctx);
2673 else
2674 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2675 } else if (cmd->args[1].v.i) //set
2676 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2677 else // adjust
2678 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2680 if (r <= 0)
2681 return 1;
2683 show_property_osd(mpctx, pname);
2685 return 1;
2688 #ifdef CONFIG_DVDNAV
2689 static const struct {
2690 const char *name;
2691 const enum mp_command_type cmd;
2692 } mp_dvdnav_bindings[] = {
2693 { "up", MP_CMD_DVDNAV_UP },
2694 { "down", MP_CMD_DVDNAV_DOWN },
2695 { "left", MP_CMD_DVDNAV_LEFT },
2696 { "right", MP_CMD_DVDNAV_RIGHT },
2697 { "menu", MP_CMD_DVDNAV_MENU },
2698 { "select", MP_CMD_DVDNAV_SELECT },
2699 { "prev", MP_CMD_DVDNAV_PREVMENU },
2700 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2703 * keep old dvdnav sub-command options for a while in order not to
2704 * break slave-mode API too suddenly.
2706 { "1", MP_CMD_DVDNAV_UP },
2707 { "2", MP_CMD_DVDNAV_DOWN },
2708 { "3", MP_CMD_DVDNAV_LEFT },
2709 { "4", MP_CMD_DVDNAV_RIGHT },
2710 { "5", MP_CMD_DVDNAV_MENU },
2711 { "6", MP_CMD_DVDNAV_SELECT },
2712 { "7", MP_CMD_DVDNAV_PREVMENU },
2713 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2714 { NULL, 0 }
2716 #endif
2718 static const char *property_error_string(int error_value)
2720 switch (error_value) {
2721 case M_PROPERTY_ERROR:
2722 return "ERROR";
2723 case M_PROPERTY_UNAVAILABLE:
2724 return "PROPERTY_UNAVAILABLE";
2725 case M_PROPERTY_NOT_IMPLEMENTED:
2726 return "NOT_IMPLEMENTED";
2727 case M_PROPERTY_UNKNOWN:
2728 return "PROPERTY_UNKNOWN";
2729 case M_PROPERTY_DISABLED:
2730 return "DISABLED";
2732 return "UNKNOWN";
2735 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2737 int idx;
2738 int end = start + count;
2739 int after = mpctx->set_of_sub_size - end;
2740 sub_data **subs = mpctx->set_of_subtitles;
2741 #ifdef CONFIG_ASS
2742 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2743 #endif
2744 if (count < 0 || count > mpctx->set_of_sub_size ||
2745 start < 0 || start > mpctx->set_of_sub_size - count) {
2746 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2747 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2748 return;
2750 for (idx = start; idx < end; idx++) {
2751 sub_data *subd = subs[idx];
2752 char *filename = "";
2753 if (subd)
2754 filename = subd->filename;
2755 #ifdef CONFIG_ASS
2756 if (!subd)
2757 filename = ass_tracks[idx]->name;
2758 #endif
2759 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2760 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2761 filename_recode(filename));
2762 sub_free(subd);
2763 subs[idx] = NULL;
2764 #ifdef CONFIG_ASS
2765 if (ass_tracks[idx])
2766 ass_free_track(ass_tracks[idx]);
2767 ass_tracks[idx] = NULL;
2768 #endif
2771 mpctx->global_sub_size -= count;
2772 mpctx->set_of_sub_size -= count;
2773 if (mpctx->set_of_sub_size <= 0)
2774 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2776 memmove(subs + start, subs + end, after * sizeof(*subs));
2777 memset(subs + start + after, 0, count * sizeof(*subs));
2778 #ifdef CONFIG_ASS
2779 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2780 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2781 #endif
2783 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2784 mpctx->global_sub_pos = -2;
2785 mpctx->subdata = NULL;
2786 mpctx->osd->ass_track = NULL;
2787 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2788 } else if (mpctx->set_of_sub_pos >= end) {
2789 mpctx->set_of_sub_pos -= count;
2790 mpctx->global_sub_pos -= count;
2794 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2796 struct MPOpts *opts = &mpctx->opts;
2797 sh_audio_t *const sh_audio = mpctx->sh_audio;
2798 sh_video_t *const sh_video = mpctx->sh_video;
2799 int osd_duration = opts->osd_duration;
2800 int case_fallthrough_hack = 0;
2801 if (set_property_command(mpctx, cmd))
2802 goto old_pause_hack; // was handled already
2803 switch (cmd->id) {
2804 case MP_CMD_SEEK: {
2805 mpctx->add_osd_seek_info = true;
2806 float v = cmd->args[0].v.f;
2807 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2808 int exact = (cmd->nargs > 2) ? cmd->args[2].v.i : 0;
2809 if (abs == 2) { // Absolute seek to a timestamp in seconds
2810 queue_seek(mpctx, MPSEEK_ABSOLUTE, v, exact);
2811 mpctx->osd_function = v > get_current_time(mpctx) ?
2812 OSD_FFW : OSD_REW;
2813 } else if (abs) { /* Absolute seek by percentage */
2814 queue_seek(mpctx, MPSEEK_FACTOR, v / 100.0, exact);
2815 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2816 } else {
2817 queue_seek(mpctx, MPSEEK_RELATIVE, v, exact);
2818 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2820 break;
2823 case MP_CMD_SET_PROPERTY_OSD:
2824 case_fallthrough_hack = 1;
2826 case MP_CMD_SET_PROPERTY: {
2827 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2828 cmd->args[1].v.s, mpctx);
2829 if (r == M_PROPERTY_UNKNOWN)
2830 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2831 "Unknown property: '%s'\n", cmd->args[0].v.s);
2832 else if (r <= 0)
2833 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2834 "Failed to set property '%s' to '%s'.\n",
2835 cmd->args[0].v.s, cmd->args[1].v.s);
2836 else if (case_fallthrough_hack)
2837 show_property_osd(mpctx, cmd->args[0].v.s);
2838 if (r <= 0)
2839 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2840 "ANS_ERROR=%s\n", property_error_string(r));
2841 break;
2844 case MP_CMD_STEP_PROPERTY_OSD:
2845 case_fallthrough_hack = 1;
2847 case MP_CMD_STEP_PROPERTY: {
2848 void *arg = NULL;
2849 int r, i;
2850 double d;
2851 off_t o;
2852 if (cmd->args[1].v.f) {
2853 m_option_t *prop;
2854 if ((r = mp_property_do(cmd->args[0].v.s,
2855 M_PROPERTY_GET_TYPE,
2856 &prop, mpctx)) <= 0)
2857 goto step_prop_err;
2858 if (prop->type == CONF_TYPE_INT ||
2859 prop->type == CONF_TYPE_FLAG)
2860 i = cmd->args[1].v.f, arg = &i;
2861 else if (prop->type == CONF_TYPE_FLOAT)
2862 arg = &cmd->args[1].v.f;
2863 else if (prop->type == CONF_TYPE_DOUBLE ||
2864 prop->type == CONF_TYPE_TIME)
2865 d = cmd->args[1].v.f, arg = &d;
2866 else if (prop->type == CONF_TYPE_POSITION)
2867 o = cmd->args[1].v.f, arg = &o;
2868 else
2869 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2870 "Ignoring step size stepping property '%s'.\n",
2871 cmd->args[0].v.s);
2873 r = mp_property_do(cmd->args[0].v.s,
2874 cmd->args[2].v.i < 0 ?
2875 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2876 arg, mpctx);
2877 step_prop_err:
2878 if (r == M_PROPERTY_UNKNOWN)
2879 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2880 "Unknown property: '%s'\n", cmd->args[0].v.s);
2881 else if (r <= 0)
2882 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2883 "Failed to increment property '%s' by %f.\n",
2884 cmd->args[0].v.s, cmd->args[1].v.f);
2885 else if (case_fallthrough_hack)
2886 show_property_osd(mpctx, cmd->args[0].v.s);
2887 if (r <= 0)
2888 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n",
2889 property_error_string(r));
2890 break;
2893 case MP_CMD_GET_PROPERTY: {
2894 char *tmp;
2895 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2896 &tmp, mpctx);
2897 if (r <= 0) {
2898 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2899 "Failed to get value of property '%s'.\n",
2900 cmd->args[0].v.s);
2901 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n",
2902 property_error_string(r));
2903 break;
2905 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2906 cmd->args[0].v.s, tmp);
2907 talloc_free(tmp);
2908 break;
2911 case MP_CMD_EDL_MARK:
2912 if (edl_fd) {
2913 float v = get_current_time(mpctx);
2914 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2915 mpctx->begin_skip = v;
2916 mp_tmsg(MSGT_CPLAYER, MSGL_INFO,
2917 "EDL skip start, press 'i' again to end block.\n");
2918 } else {
2919 if (mpctx->begin_skip > v)
2920 mp_tmsg(MSGT_CPLAYER, MSGL_WARN,
2921 "EDL skip canceled, last start > stop\n");
2922 else {
2923 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2924 mp_tmsg(MSGT_CPLAYER, MSGL_INFO,
2925 "EDL skip end, line written.\n");
2927 mpctx->begin_skip = MP_NOPTS_VALUE;
2930 break;
2932 case MP_CMD_SWITCH_RATIO:
2933 if (!sh_video)
2934 break;
2935 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2936 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2937 else
2938 opts->movie_aspect = cmd->args[0].v.f;
2939 video_reset_aspect(sh_video);
2940 break;
2942 case MP_CMD_SPEED_INCR: {
2943 float v = cmd->args[0].v.f;
2944 mp_property_do("speed", M_PROPERTY_STEP_UP, &v, mpctx);
2945 show_property_osd(mpctx, "speed");
2946 break;
2949 case MP_CMD_SPEED_MULT:
2950 case_fallthrough_hack = true;
2952 case MP_CMD_SPEED_SET: {
2953 float v = cmd->args[0].v.f;
2954 if (case_fallthrough_hack)
2955 v *= mpctx->opts.playback_speed;
2956 mp_property_do("speed", M_PROPERTY_SET, &v, mpctx);
2957 show_property_osd(mpctx, "speed");
2958 break;
2961 case MP_CMD_FRAME_STEP:
2962 add_step_frame(mpctx);
2963 break;
2965 case MP_CMD_QUIT:
2966 exit_player_with_rc(mpctx, EXIT_QUIT,
2967 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2969 case MP_CMD_PLAY_TREE_STEP: {
2970 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2971 int force = cmd->args[1].v.i;
2974 if (!force && mpctx->playtree_iter) {
2975 play_tree_iter_t *i =
2976 play_tree_iter_new_copy(mpctx->playtree_iter);
2977 if (play_tree_iter_step(i, n, 0) ==
2978 PLAY_TREE_ITER_ENTRY)
2979 mpctx->stop_play =
2980 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2981 play_tree_iter_free(i);
2982 } else
2983 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2984 if (mpctx->stop_play)
2985 mpctx->play_tree_step = n;
2987 break;
2990 case MP_CMD_PLAY_TREE_UP_STEP: {
2991 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2992 int force = cmd->args[1].v.i;
2994 if (!force && mpctx->playtree_iter) {
2995 play_tree_iter_t *i =
2996 play_tree_iter_new_copy(mpctx->playtree_iter);
2997 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2998 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2999 play_tree_iter_free(i);
3000 } else
3001 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
3002 break;
3005 case MP_CMD_PLAY_ALT_SRC_STEP:
3006 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
3007 int v = cmd->args[0].v.i;
3008 if (v > 0
3009 && mpctx->playtree_iter->file <
3010 mpctx->playtree_iter->num_files)
3011 mpctx->stop_play = PT_NEXT_SRC;
3012 else if (v < 0 && mpctx->playtree_iter->file > 1)
3013 mpctx->stop_play = PT_PREV_SRC;
3015 break;
3017 case MP_CMD_SUB_STEP:
3018 if (sh_video) {
3019 int movement = cmd->args[0].v.i;
3020 step_sub(mpctx->subdata, mpctx->video_pts, movement);
3021 #ifdef CONFIG_ASS
3022 if (mpctx->osd->ass_track)
3023 sub_delay +=
3024 ass_step_sub(mpctx->osd->ass_track,
3025 (mpctx->video_pts +
3026 sub_delay) * 1000 + .5, movement) / 1000.;
3027 #endif
3028 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
3029 "Sub delay: %d ms", ROUND(sub_delay * 1000));
3031 break;
3033 case MP_CMD_SUB_LOG:
3034 log_sub(mpctx);
3035 break;
3037 case MP_CMD_OSD: {
3038 int v = cmd->args[0].v.i;
3039 int max = (opts->term_osd
3040 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
3041 if (opts->osd_level > max)
3042 opts->osd_level = max;
3043 if (v < 0)
3044 opts->osd_level = (opts->osd_level + 1) % (max + 1);
3045 else
3046 opts->osd_level = v > max ? max : v;
3047 /* Show OSD state when disabled, but not when an explicit
3048 argument is given to the OSD command, i.e. in slave mode. */
3049 if (v == -1 && opts->osd_level <= 1)
3050 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
3051 "OSD: %s",
3052 opts->osd_level ? mp_gtext("enabled") :
3053 mp_gtext("disabled"));
3054 else
3055 rm_osd_msg(OSD_MSG_OSD_STATUS);
3056 break;
3059 case MP_CMD_OSD_SHOW_TEXT:
3060 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
3061 (cmd->args[1].v.i <
3062 0 ? osd_duration : cmd->args[1].v.i),
3063 "%s", cmd->args[0].v.s);
3064 break;
3066 case MP_CMD_OSD_SHOW_PROPERTY_TEXT: {
3067 char *txt = m_properties_expand_string(mp_properties,
3068 cmd->args[0].v.s,
3069 mpctx);
3070 // if no argument supplied use default osd_duration, else <arg> ms.
3071 if (txt) {
3072 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
3073 (cmd->args[1].v.i <
3074 0 ? osd_duration : cmd->args[1].v.i),
3075 "%s", txt);
3076 free(txt);
3078 break;
3081 case MP_CMD_LOADFILE: {
3082 play_tree_t *e = play_tree_new();
3083 play_tree_add_file(e, cmd->args[0].v.s);
3085 if (cmd->args[1].v.i) // append
3086 play_tree_append_entry(mpctx->playtree->child, e);
3087 else {
3088 // Go back to the starting point.
3089 while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1)
3090 != PLAY_TREE_ITER_END)
3091 /* NOP */;
3092 play_tree_free_list(mpctx->playtree->child, 1);
3093 play_tree_set_child(mpctx->playtree, e);
3094 pt_iter_goto_head(mpctx->playtree_iter);
3095 mpctx->stop_play = PT_NEXT_SRC;
3097 break;
3100 case MP_CMD_LOADLIST: {
3101 play_tree_t *e = parse_playlist_file(mpctx->mconfig,
3102 bstr(cmd->args[0].v.s));
3103 if (!e)
3104 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
3105 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
3106 else {
3107 if (cmd->args[1].v.i) // append
3108 play_tree_append_entry(mpctx->playtree->child, e);
3109 else {
3110 // Go back to the starting point.
3111 while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1)
3112 != PLAY_TREE_ITER_END)
3113 /* NOP */;
3114 play_tree_free_list(mpctx->playtree->child, 1);
3115 play_tree_set_child(mpctx->playtree, e);
3116 pt_iter_goto_head(mpctx->playtree_iter);
3117 mpctx->stop_play = PT_NEXT_SRC;
3120 break;
3123 case MP_CMD_STOP:
3124 // Go back to the starting point.
3125 while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1) !=
3126 PLAY_TREE_ITER_END)
3127 /* NOP */;
3128 mpctx->stop_play = PT_STOP;
3129 break;
3131 case MP_CMD_OSD_SHOW_PROGRESSION: {
3132 int len = get_time_length(mpctx);
3133 int pts = get_current_time(mpctx);
3134 set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3135 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3136 "%c %02d:%02d:%02d / %02d:%02d:%02d",
3137 mpctx->osd_function, pts / 3600, (pts / 60) % 60, pts % 60,
3138 len / 3600, (len / 60) % 60, len % 60);
3139 break;
3142 #ifdef CONFIG_RADIO
3143 case MP_CMD_RADIO_STEP_CHANNEL:
3144 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3145 int v = cmd->args[0].v.i;
3146 if (v > 0)
3147 radio_step_channel(mpctx->demuxer->stream,
3148 RADIO_CHANNEL_HIGHER);
3149 else
3150 radio_step_channel(mpctx->demuxer->stream,
3151 RADIO_CHANNEL_LOWER);
3152 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3153 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3154 "Channel: %s",
3155 radio_get_channel_name(mpctx->demuxer->stream));
3158 break;
3160 case MP_CMD_RADIO_SET_CHANNEL:
3161 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3162 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3163 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3164 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3165 "Channel: %s",
3166 radio_get_channel_name(mpctx->demuxer->stream));
3169 break;
3171 case MP_CMD_RADIO_SET_FREQ:
3172 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3173 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3174 break;
3176 case MP_CMD_RADIO_STEP_FREQ:
3177 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3178 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3179 break;
3180 #endif
3182 #ifdef CONFIG_TV
3183 case MP_CMD_TV_START_SCAN:
3184 if (mpctx->file_format == DEMUXER_TYPE_TV)
3185 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv), 1);
3186 break;
3187 case MP_CMD_TV_SET_FREQ:
3188 if (mpctx->file_format == DEMUXER_TYPE_TV)
3189 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3190 cmd->args[0].v.f * 16.0);
3191 #ifdef CONFIG_PVR
3192 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3193 pvr_set_freq(mpctx->stream, ROUND(cmd->args[0].v.f));
3194 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3195 pvr_get_current_channelname(mpctx->stream),
3196 pvr_get_current_stationname(mpctx->stream));
3198 #endif /* CONFIG_PVR */
3199 break;
3201 case MP_CMD_TV_STEP_FREQ:
3202 if (mpctx->file_format == DEMUXER_TYPE_TV)
3203 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3204 cmd->args[0].v.f * 16.0);
3205 #ifdef CONFIG_PVR
3206 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3207 pvr_force_freq_step(mpctx->stream, ROUND(cmd->args[0].v.f));
3208 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3209 pvr_get_current_channelname(mpctx->stream),
3210 pvr_get_current_frequency(mpctx->stream));
3212 #endif /* CONFIG_PVR */
3213 break;
3215 case MP_CMD_TV_SET_NORM:
3216 if (mpctx->file_format == DEMUXER_TYPE_TV)
3217 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3218 cmd->args[0].v.s);
3219 break;
3221 case MP_CMD_TV_STEP_CHANNEL:
3222 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3223 int v = cmd->args[0].v.i;
3224 if (v > 0) {
3225 tv_step_channel((tvi_handle_t *) (mpctx->
3226 demuxer->priv),
3227 TV_CHANNEL_HIGHER);
3228 } else {
3229 tv_step_channel((tvi_handle_t *) (mpctx->
3230 demuxer->priv),
3231 TV_CHANNEL_LOWER);
3233 if (tv_channel_list) {
3234 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3235 "Channel: %s", tv_channel_current->name);
3236 //vo_osd_changed(OSDTYPE_SUBTITLE);
3239 #ifdef CONFIG_PVR
3240 else if (mpctx->stream &&
3241 mpctx->stream->type == STREAMTYPE_PVR) {
3242 pvr_set_channel_step(mpctx->stream, cmd->args[0].v.i);
3243 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3244 pvr_get_current_channelname(mpctx->stream),
3245 pvr_get_current_stationname(mpctx->stream));
3247 #endif /* CONFIG_PVR */
3248 #ifdef CONFIG_DVBIN
3249 if (mpctx->stream->type == STREAMTYPE_DVB) {
3250 int dir;
3251 int v = cmd->args[0].v.i;
3253 mpctx->last_dvb_step = v;
3254 if (v > 0)
3255 dir = DVB_CHANNEL_HIGHER;
3256 else
3257 dir = DVB_CHANNEL_LOWER;
3260 if (dvb_step_channel(mpctx->stream, dir)) {
3261 mpctx->stop_play = PT_NEXT_ENTRY;
3262 mpctx->dvbin_reopen = 1;
3265 #endif /* CONFIG_DVBIN */
3266 break;
3268 case MP_CMD_TV_SET_CHANNEL:
3269 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3270 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3271 cmd->args[0].v.s);
3272 if (tv_channel_list) {
3273 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3274 "Channel: %s", tv_channel_current->name);
3275 //vo_osd_changed(OSDTYPE_SUBTITLE);
3278 #ifdef CONFIG_PVR
3279 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3280 pvr_set_channel(mpctx->stream, cmd->args[0].v.s);
3281 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3282 pvr_get_current_channelname(mpctx->stream),
3283 pvr_get_current_stationname(mpctx->stream));
3285 #endif /* CONFIG_PVR */
3286 break;
3288 #ifdef CONFIG_DVBIN
3289 case MP_CMD_DVB_SET_CHANNEL:
3290 if (mpctx->stream->type == STREAMTYPE_DVB) {
3291 mpctx->last_dvb_step = 1;
3293 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3294 cmd->args[0].v.i)) {
3295 mpctx->stop_play = PT_NEXT_ENTRY;
3296 mpctx->dvbin_reopen = 1;
3299 break;
3300 #endif /* CONFIG_DVBIN */
3302 case MP_CMD_TV_LAST_CHANNEL:
3303 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3304 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3305 if (tv_channel_list) {
3306 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3307 "Channel: %s", tv_channel_current->name);
3308 //vo_osd_changed(OSDTYPE_SUBTITLE);
3311 #ifdef CONFIG_PVR
3312 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3313 pvr_set_lastchannel(mpctx->stream);
3314 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3315 pvr_get_current_channelname(mpctx->stream),
3316 pvr_get_current_stationname(mpctx->stream));
3318 #endif /* CONFIG_PVR */
3319 break;
3321 case MP_CMD_TV_STEP_NORM:
3322 if (mpctx->file_format == DEMUXER_TYPE_TV)
3323 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3324 break;
3326 case MP_CMD_TV_STEP_CHANNEL_LIST:
3327 if (mpctx->file_format == DEMUXER_TYPE_TV)
3328 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3329 break;
3330 #endif /* CONFIG_TV */
3331 case MP_CMD_TV_TELETEXT_ADD_DEC:
3332 if (mpctx->demuxer->teletext)
3333 teletext_control(mpctx->demuxer->teletext, TV_VBI_CONTROL_ADD_DEC,
3334 &(cmd->args[0].v.s));
3335 break;
3336 case MP_CMD_TV_TELETEXT_GO_LINK:
3337 if (mpctx->demuxer->teletext)
3338 teletext_control(mpctx->demuxer->teletext, TV_VBI_CONTROL_GO_LINK,
3339 &(cmd->args[0].v.i));
3340 break;
3342 case MP_CMD_SUB_LOAD:
3343 if (sh_video) {
3344 int n = mpctx->set_of_sub_size;
3345 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3346 if (n != mpctx->set_of_sub_size) {
3347 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3348 ++mpctx->global_sub_size;
3351 break;
3353 case MP_CMD_SUB_REMOVE:
3354 if (sh_video) {
3355 int v = cmd->args[0].v.i;
3356 if (v < 0)
3357 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3358 else if (v < mpctx->set_of_sub_size)
3359 remove_subtitle_range(mpctx, v, 1);
3361 break;
3363 case MP_CMD_GET_SUB_VISIBILITY:
3364 if (sh_video) {
3365 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3366 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3368 break;
3370 case MP_CMD_SCREENSHOT:
3371 screenshot_request(mpctx, cmd->args[0].v.i, cmd->args[1].v.i);
3372 break;
3374 case MP_CMD_VF_CHANGE_RECTANGLE:
3375 if (!sh_video)
3376 break;
3377 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3378 break;
3380 case MP_CMD_GET_TIME_LENGTH:
3381 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3382 get_time_length(mpctx));
3383 break;
3385 case MP_CMD_GET_FILENAME: {
3386 char *inf = get_metadata(mpctx, META_NAME);
3387 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n", inf);
3388 talloc_free(inf);
3389 break;
3392 case MP_CMD_GET_VIDEO_CODEC: {
3393 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3394 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3395 talloc_free(inf);
3396 break;
3399 case MP_CMD_GET_VIDEO_BITRATE: {
3400 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3401 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3402 talloc_free(inf);
3403 break;
3406 case MP_CMD_GET_VIDEO_RESOLUTION: {
3407 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3408 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3409 talloc_free(inf);
3410 break;
3413 case MP_CMD_GET_AUDIO_CODEC: {
3414 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3415 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3416 talloc_free(inf);
3417 break;
3420 case MP_CMD_GET_AUDIO_BITRATE: {
3421 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3422 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3423 talloc_free(inf);
3424 break;
3427 case MP_CMD_GET_AUDIO_SAMPLES: {
3428 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3429 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3430 talloc_free(inf);
3431 break;
3434 case MP_CMD_GET_META_TITLE: {
3435 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3436 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3437 talloc_free(inf);
3438 break;
3441 case MP_CMD_GET_META_ARTIST: {
3442 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3443 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3444 talloc_free(inf);
3445 break;
3448 case MP_CMD_GET_META_ALBUM: {
3449 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3450 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3451 talloc_free(inf);
3452 break;
3455 case MP_CMD_GET_META_YEAR: {
3456 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3457 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3458 talloc_free(inf);
3459 break;
3462 case MP_CMD_GET_META_COMMENT: {
3463 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3464 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3465 talloc_free(inf);
3466 break;
3469 case MP_CMD_GET_META_TRACK: {
3470 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3471 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3472 talloc_free(inf);
3473 break;
3476 case MP_CMD_GET_META_GENRE: {
3477 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3478 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3479 talloc_free(inf);
3480 break;
3483 case MP_CMD_GET_VO_FULLSCREEN:
3484 if (mpctx->video_out && mpctx->video_out->config_ok)
3485 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3486 break;
3488 case MP_CMD_GET_PERCENT_POS:
3489 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3490 get_percent_pos(mpctx));
3491 break;
3493 case MP_CMD_GET_TIME_POS: {
3494 float pos = get_current_time(mpctx);
3495 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3496 break;
3499 case MP_CMD_RUN:
3500 #ifndef __MINGW32__
3501 if (!fork()) {
3502 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3503 exit(0);
3505 #endif
3506 break;
3508 case MP_CMD_KEYDOWN_EVENTS:
3509 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3510 break;
3512 case MP_CMD_SET_MOUSE_POS: {
3513 int pointer_x, pointer_y;
3514 double dx, dy;
3515 pointer_x = cmd->args[0].v.i;
3516 pointer_y = cmd->args[1].v.i;
3517 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3518 #ifdef CONFIG_DVDNAV
3519 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3520 && dx > 0.0 && dy > 0.0) {
3521 int button = -1;
3522 pointer_x = (int) (dx * (double) sh_video->disp_w);
3523 pointer_y = (int) (dy * (double) sh_video->disp_h);
3524 mp_dvdnav_update_mouse_pos(mpctx->stream,
3525 pointer_x, pointer_y, &button);
3526 if (opts->osd_level > 1 && button > 0)
3527 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3528 "Selected button number %d", button);
3530 #endif
3531 break;
3534 #ifdef CONFIG_DVDNAV
3535 case MP_CMD_DVDNAV: {
3536 int button = -1;
3537 int i;
3538 enum mp_command_type command = 0;
3539 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3540 break;
3542 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3543 if (cmd->args[0].v.s &&
3544 !strcasecmp(cmd->args[0].v.s,
3545 mp_dvdnav_bindings[i].name))
3546 command = mp_dvdnav_bindings[i].cmd;
3548 mp_dvdnav_handle_input(mpctx->stream, command, &button);
3549 if (opts->osd_level > 1 && button > 0)
3550 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3551 "Selected button number %d", button);
3552 break;
3555 case MP_CMD_SWITCH_TITLE:
3556 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3557 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3558 break;
3560 #endif
3562 case MP_CMD_AF_SWITCH:
3563 if (sh_audio) {
3564 af_uninit(mpctx->mixer.afilter);
3565 af_init(mpctx->mixer.afilter);
3567 case MP_CMD_AF_ADD:
3568 case MP_CMD_AF_DEL: {
3569 if (!sh_audio)
3570 break;
3571 char *af_args = strdup(cmd->args[0].v.s);
3572 char *af_commands = af_args;
3573 char *af_command;
3574 af_instance_t *af;
3575 while ((af_command = strsep(&af_commands, ",")) != NULL) {
3576 if (cmd->id == MP_CMD_AF_DEL) {
3577 af = af_get(mpctx->mixer.afilter, af_command);
3578 if (af != NULL)
3579 af_remove(mpctx->mixer.afilter, af);
3580 } else
3581 af_add(mpctx->mixer.afilter, af_command);
3583 reinit_audio_chain(mpctx);
3584 free(af_args);
3585 break;
3587 case MP_CMD_AF_CLR:
3588 if (!sh_audio)
3589 break;
3590 af_uninit(mpctx->mixer.afilter);
3591 af_init(mpctx->mixer.afilter);
3592 reinit_audio_chain(mpctx);
3593 break;
3594 case MP_CMD_AF_CMDLINE:
3595 if (sh_audio) {
3596 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3597 if (!af) {
3598 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3599 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3600 break;
3602 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3603 af_reinit(sh_audio->afilter, af);
3605 break;
3607 default:
3608 mp_msg(MSGT_CPLAYER, MSGL_V,
3609 "Received unknown cmd %s\n", cmd->name);
3612 old_pause_hack:
3613 switch (cmd->pausing) {
3614 case 1: // "pausing"
3615 pause_player(mpctx);
3616 break;
3617 case 3: // "pausing_toggle"
3618 if (mpctx->paused)
3619 unpause_player(mpctx);
3620 else
3621 pause_player(mpctx);
3622 break;