ao_pulse: support native mute control
[mplayer.git] / command.c
blobd511e52c4afd3169a6effa37492497542b19e2b2
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 switch (action) {
723 case M_PROPERTY_SET:
724 if (!arg)
725 return M_PROPERTY_ERROR;
726 M_PROPERTY_CLAMP(prop, *(float *) arg);
727 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
728 return M_PROPERTY_OK;
729 case M_PROPERTY_STEP_UP:
730 if (arg && *(float *) arg <= 0)
731 mixer_decvolume(&mpctx->mixer);
732 else
733 mixer_incvolume(&mpctx->mixer);
734 return M_PROPERTY_OK;
735 case M_PROPERTY_STEP_DOWN:
736 if (arg && *(float *) arg <= 0)
737 mixer_incvolume(&mpctx->mixer);
738 else
739 mixer_decvolume(&mpctx->mixer);
740 return M_PROPERTY_OK;
742 return M_PROPERTY_NOT_IMPLEMENTED;
745 /// Mute (RW)
746 static int mp_property_mute(m_option_t *prop, int action, void *arg,
747 MPContext *mpctx)
750 if (!mpctx->sh_audio)
751 return M_PROPERTY_UNAVAILABLE;
753 switch (action) {
754 case M_PROPERTY_SET:
755 if (!arg)
756 return M_PROPERTY_ERROR;
757 mixer_setmute(&mpctx->mixer, *(int *) arg);
758 return M_PROPERTY_OK;
759 case M_PROPERTY_STEP_UP:
760 case M_PROPERTY_STEP_DOWN:
761 mixer_setmute(&mpctx->mixer, !mixer_getmute(&mpctx->mixer));
762 return M_PROPERTY_OK;
763 default:
764 return m_property_flag_ro(prop, action, arg,
765 mixer_getmute(&mpctx->mixer));
769 /// Audio delay (RW)
770 static int mp_property_audio_delay(m_option_t *prop, int action,
771 void *arg, MPContext *mpctx)
773 if (!(mpctx->sh_audio && mpctx->sh_video))
774 return M_PROPERTY_UNAVAILABLE;
775 switch (action) {
776 case M_PROPERTY_SET:
777 case M_PROPERTY_STEP_UP:
778 case M_PROPERTY_STEP_DOWN: {
779 int ret;
780 float delay = audio_delay;
781 ret = m_property_delay(prop, action, arg, &audio_delay);
782 if (ret != M_PROPERTY_OK)
783 return ret;
784 if (mpctx->sh_audio)
785 mpctx->delay -= audio_delay - delay;
787 return M_PROPERTY_OK;
788 default:
789 return m_property_delay(prop, action, arg, &audio_delay);
793 /// Audio codec tag (RO)
794 static int mp_property_audio_format(m_option_t *prop, int action,
795 void *arg, MPContext *mpctx)
797 if (!mpctx->sh_audio)
798 return M_PROPERTY_UNAVAILABLE;
799 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
802 /// Audio codec name (RO)
803 static int mp_property_audio_codec(m_option_t *prop, int action,
804 void *arg, MPContext *mpctx)
806 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
807 return M_PROPERTY_UNAVAILABLE;
808 return m_property_string_ro(prop, action, arg,
809 mpctx->sh_audio->codec->name);
812 /// Audio bitrate (RO)
813 static int mp_property_audio_bitrate(m_option_t *prop, int action,
814 void *arg, MPContext *mpctx)
816 if (!mpctx->sh_audio)
817 return M_PROPERTY_UNAVAILABLE;
818 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
821 /// Samplerate (RO)
822 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
823 MPContext *mpctx)
825 if (!mpctx->sh_audio)
826 return M_PROPERTY_UNAVAILABLE;
827 switch (action) {
828 case M_PROPERTY_PRINT:
829 if (!arg)
830 return M_PROPERTY_ERROR;
831 *(char **)arg = talloc_asprintf(NULL, "%d kHz",
832 mpctx->sh_audio->samplerate / 1000);
833 return M_PROPERTY_OK;
835 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
838 /// Number of channels (RO)
839 static int mp_property_channels(m_option_t *prop, int action, void *arg,
840 MPContext *mpctx)
842 if (!mpctx->sh_audio)
843 return M_PROPERTY_UNAVAILABLE;
844 switch (action) {
845 case M_PROPERTY_PRINT:
846 if (!arg)
847 return M_PROPERTY_ERROR;
848 switch (mpctx->sh_audio->channels) {
849 case 1:
850 *(char **) arg = talloc_strdup(NULL, "mono");
851 break;
852 case 2:
853 *(char **) arg = talloc_strdup(NULL, "stereo");
854 break;
855 default:
856 *(char **) arg = talloc_asprintf(NULL, "%d channels",
857 mpctx->sh_audio->channels);
859 return M_PROPERTY_OK;
861 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
864 /// Balance (RW)
865 static int mp_property_balance(m_option_t *prop, int action, void *arg,
866 MPContext *mpctx)
868 float bal;
870 switch (action) {
871 case M_PROPERTY_GET:
872 if (!arg)
873 return M_PROPERTY_ERROR;
874 mixer_getbalance(&mpctx->mixer, arg);
875 return M_PROPERTY_OK;
876 case M_PROPERTY_PRINT: {
877 char **str = arg;
878 if (!arg)
879 return M_PROPERTY_ERROR;
880 mixer_getbalance(&mpctx->mixer, &bal);
881 if (bal == 0.f)
882 *str = talloc_strdup(NULL, "center");
883 else if (bal == -1.f)
884 *str = talloc_strdup(NULL, "left only");
885 else if (bal == 1.f)
886 *str = talloc_strdup(NULL, "right only");
887 else {
888 unsigned right = (bal + 1.f) / 2.f * 100.f;
889 *str = talloc_asprintf(NULL, "left %d%%, right %d%%",
890 100 - right, right);
892 return M_PROPERTY_OK;
894 case M_PROPERTY_STEP_UP:
895 case M_PROPERTY_STEP_DOWN:
896 mixer_getbalance(&mpctx->mixer, &bal);
897 bal += (arg ? *(float *)arg : .1f) *
898 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
899 M_PROPERTY_CLAMP(prop, bal);
900 mixer_setbalance(&mpctx->mixer, bal);
901 return M_PROPERTY_OK;
902 case M_PROPERTY_SET:
903 if (!arg)
904 return M_PROPERTY_ERROR;
905 M_PROPERTY_CLAMP(prop, *(float *)arg);
906 mixer_setbalance(&mpctx->mixer, *(float *)arg);
907 return M_PROPERTY_OK;
909 return M_PROPERTY_NOT_IMPLEMENTED;
912 /// Selected audio id (RW)
913 static int mp_property_audio(m_option_t *prop, int action, void *arg,
914 MPContext *mpctx)
916 int current_id, tmp;
917 if (!mpctx->demuxer || !mpctx->d_audio)
918 return M_PROPERTY_UNAVAILABLE;
919 struct sh_audio *sh = mpctx->sh_audio;
920 current_id = sh ? sh->aid : -2;
922 switch (action) {
923 case M_PROPERTY_GET:
924 if (!arg)
925 return M_PROPERTY_ERROR;
926 *(int *) arg = current_id;
927 return M_PROPERTY_OK;
928 case M_PROPERTY_PRINT:
929 if (!arg)
930 return M_PROPERTY_ERROR;
932 if (current_id < 0)
933 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
934 else if (sh && (sh->lang || sh->title)) {
935 char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
936 if (sh->title)
937 *(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
938 current_id, lang, sh->title);
939 else
940 *(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id,
941 lang);
942 } else {
943 char lang[40];
944 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
945 if (0) ;
946 #ifdef CONFIG_DVDREAD
947 else if (mpctx->stream->type == STREAMTYPE_DVD) {
948 int code = dvd_lang_from_aid(mpctx->stream, current_id);
949 if (code) {
950 lang[0] = code >> 8;
951 lang[1] = code;
952 lang[2] = 0;
955 #endif
957 #ifdef CONFIG_DVDNAV
958 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
959 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
960 #endif
961 *(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id, lang);
963 return M_PROPERTY_OK;
965 case M_PROPERTY_STEP_UP:
966 case M_PROPERTY_SET:
967 if (action == M_PROPERTY_SET && arg)
968 tmp = *((int *) arg);
969 else
970 tmp = -1;
971 int new_id = demuxer_switch_audio(mpctx->d_audio->demuxer, tmp);
972 if (new_id != current_id)
973 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
974 if (new_id != current_id && new_id >= 0) {
975 sh_audio_t *sh2;
976 sh2 = mpctx->d_audio->demuxer->a_streams[mpctx->d_audio->id];
977 sh2->ds = mpctx->d_audio;
978 mpctx->sh_audio = sh2;
979 reinit_audio_chain(mpctx);
981 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
982 return M_PROPERTY_OK;
983 default:
984 return M_PROPERTY_NOT_IMPLEMENTED;
989 /// Selected video id (RW)
990 static int mp_property_video(m_option_t *prop, int action, void *arg,
991 MPContext *mpctx)
993 struct MPOpts *opts = &mpctx->opts;
994 int current_id, tmp;
995 if (!mpctx->demuxer || !mpctx->d_video)
996 return M_PROPERTY_UNAVAILABLE;
997 current_id = mpctx->sh_video ? mpctx->sh_video->vid : -2;
999 switch (action) {
1000 case M_PROPERTY_GET:
1001 if (!arg)
1002 return M_PROPERTY_ERROR;
1003 *(int *) arg = current_id;
1004 return M_PROPERTY_OK;
1005 case M_PROPERTY_PRINT:
1006 if (!arg)
1007 return M_PROPERTY_ERROR;
1009 if (current_id < 0)
1010 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1011 else {
1012 *(char **) arg = talloc_asprintf(NULL, "(%d) %s", current_id,
1013 mp_gtext("unknown"));
1015 return M_PROPERTY_OK;
1017 case M_PROPERTY_STEP_UP:
1018 case M_PROPERTY_SET:
1019 if (action == M_PROPERTY_SET && arg)
1020 tmp = *((int *) arg);
1021 else
1022 tmp = -1;
1023 int new_id = demuxer_switch_video(mpctx->d_video->demuxer, tmp);
1024 if (new_id != current_id)
1025 uninit_player(mpctx, INITIALIZED_VCODEC |
1026 (opts->fixed_vo && new_id >= 0 ? 0 : INITIALIZED_VO));
1027 if (new_id != current_id && new_id >= 0) {
1028 sh_video_t *sh2;
1029 sh2 = mpctx->d_video->demuxer->v_streams[mpctx->d_video->id];
1030 sh2->ds = mpctx->d_video;
1031 mpctx->sh_video = sh2;
1032 reinit_video_chain(mpctx);
1034 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", new_id);
1035 return M_PROPERTY_OK;
1037 default:
1038 return M_PROPERTY_NOT_IMPLEMENTED;
1042 static int mp_property_program(m_option_t *prop, int action, void *arg,
1043 MPContext *mpctx)
1045 demux_program_t prog;
1047 switch (action) {
1048 case M_PROPERTY_STEP_UP:
1049 case M_PROPERTY_SET:
1050 if (action == M_PROPERTY_SET && arg)
1051 prog.progid = *((int *) arg);
1052 else
1053 prog.progid = -1;
1054 if (demux_control(mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1055 &prog) == DEMUXER_CTRL_NOTIMPL)
1056 return M_PROPERTY_ERROR;
1058 if (prog.aid < 0 && prog.vid < 0) {
1059 mp_msg(MSGT_CPLAYER, MSGL_ERR,
1060 "Selected program contains no audio or video streams!\n");
1061 return M_PROPERTY_ERROR;
1063 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1064 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1065 return M_PROPERTY_OK;
1067 default:
1068 return M_PROPERTY_NOT_IMPLEMENTED;
1073 /// Fullscreen state (RW)
1074 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1075 MPContext *mpctx)
1078 if (!mpctx->video_out)
1079 return M_PROPERTY_UNAVAILABLE;
1081 switch (action) {
1082 case M_PROPERTY_SET:
1083 if (!arg)
1084 return M_PROPERTY_ERROR;
1085 M_PROPERTY_CLAMP(prop, *(int *) arg);
1086 if (vo_fs == !!*(int *) arg)
1087 return M_PROPERTY_OK;
1088 case M_PROPERTY_STEP_UP:
1089 case M_PROPERTY_STEP_DOWN:
1090 if (mpctx->video_out->config_ok)
1091 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1092 mpctx->opts.fullscreen = vo_fs;
1093 return M_PROPERTY_OK;
1094 default:
1095 return m_property_flag(prop, action, arg, &vo_fs);
1099 static int mp_property_deinterlace(m_option_t *prop, int action,
1100 void *arg, MPContext *mpctx)
1102 int deinterlace;
1103 vf_instance_t *vf;
1104 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1105 return M_PROPERTY_UNAVAILABLE;
1106 vf = mpctx->sh_video->vfilter;
1107 switch (action) {
1108 case M_PROPERTY_GET:
1109 if (!arg)
1110 return M_PROPERTY_ERROR;
1111 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1112 return M_PROPERTY_OK;
1113 case M_PROPERTY_SET:
1114 if (!arg)
1115 return M_PROPERTY_ERROR;
1116 M_PROPERTY_CLAMP(prop, *(int *) arg);
1117 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1118 return M_PROPERTY_OK;
1119 case M_PROPERTY_STEP_UP:
1120 case M_PROPERTY_STEP_DOWN:
1121 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1122 deinterlace = !deinterlace;
1123 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1124 return M_PROPERTY_OK;
1126 int value = 0;
1127 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1128 return m_property_flag_ro(prop, action, arg, value);
1131 static int colormatrix_property_helper(m_option_t *prop, int action,
1132 void *arg, MPContext *mpctx)
1134 int r = mp_property_generic_option(prop, action, arg, mpctx);
1135 // testing for an actual change is too much effort
1136 switch (action) {
1137 case M_PROPERTY_SET:
1138 case M_PROPERTY_STEP_UP:
1139 case M_PROPERTY_STEP_DOWN:
1140 if (mpctx->sh_video)
1141 set_video_colorspace(mpctx->sh_video);
1142 break;
1144 return r;
1147 static int mp_property_colormatrix(m_option_t *prop, int action, void *arg,
1148 MPContext *mpctx)
1150 struct MPOpts *opts = &mpctx->opts;
1151 switch (action) {
1152 case M_PROPERTY_PRINT:
1153 if (!arg)
1154 return M_PROPERTY_ERROR;
1155 struct mp_csp_details actual = { .format = -1 };
1156 char *req_csp = mp_csp_names[opts->requested_colorspace];
1157 char *real_csp = NULL;
1158 if (mpctx->sh_video) {
1159 struct vf_instance *vf = mpctx->sh_video->vfilter;
1160 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &actual) == true) {
1161 real_csp = mp_csp_names[actual.format];
1162 } else {
1163 real_csp = "Unknown";
1166 char *res;
1167 if (opts->requested_colorspace == MP_CSP_AUTO && real_csp) {
1168 // Caveat: doesn't handle the case when the autodetected colorspace
1169 // is different from the actual colorspace as used by the
1170 // VO - the OSD will display the VO colorspace without
1171 // indication that it doesn't match the requested colorspace.
1172 res = talloc_asprintf(NULL, "Auto (%s)", real_csp);
1173 } else if (opts->requested_colorspace == actual.format || !real_csp) {
1174 res = talloc_strdup(NULL, req_csp);
1175 } else
1176 res = talloc_asprintf(NULL, mp_gtext("%s, but %s used"),
1177 req_csp, real_csp);
1178 *(char **)arg = res;
1179 return M_PROPERTY_OK;
1180 default:;
1181 return colormatrix_property_helper(prop, action, arg, mpctx);
1185 static int levels_property_helper(int offset, m_option_t *prop, int action,
1186 void *arg, MPContext *mpctx)
1188 char *optname = prop->priv;
1189 const struct m_option *opt = m_config_get_option(mpctx->mconfig,
1190 bstr(optname));
1191 int *valptr = (int *)m_option_get_ptr(opt, &mpctx->opts);
1193 switch (action) {
1194 case M_PROPERTY_PRINT:
1195 if (!arg)
1196 return M_PROPERTY_ERROR;
1197 struct mp_csp_details actual = {0};
1198 int actual_level = -1;
1199 char *req_level = m_option_print(opt, valptr);
1200 char *real_level = NULL;
1201 if (mpctx->sh_video) {
1202 struct vf_instance *vf = mpctx->sh_video->vfilter;
1203 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &actual) == true) {
1204 actual_level = *(enum mp_csp_levels *)(((char *)&actual) + offset);
1205 real_level = m_option_print(opt, &actual_level);
1206 } else {
1207 real_level = talloc_strdup(NULL, "Unknown");
1210 char *res;
1211 if (*valptr == MP_CSP_LEVELS_AUTO && real_level) {
1212 res = talloc_asprintf(NULL, "Auto (%s)", real_level);
1213 } else if (*valptr == actual_level || !real_level) {
1214 res = talloc_strdup(NULL, real_level);
1215 } else
1216 res = talloc_asprintf(NULL, mp_gtext("%s, but %s used"),
1217 req_level, real_level);
1218 talloc_free(req_level);
1219 talloc_free(real_level);
1220 *(char **)arg = res;
1221 return M_PROPERTY_OK;
1222 default:;
1223 return colormatrix_property_helper(prop, action, arg, mpctx);
1227 static int mp_property_colormatrix_input_range(m_option_t *prop, int action,
1228 void *arg, MPContext *mpctx)
1230 return levels_property_helper(offsetof(struct mp_csp_details, levels_in),
1231 prop, action, arg, mpctx);
1234 static int mp_property_colormatrix_output_range(m_option_t *prop, int action,
1235 void *arg, MPContext *mpctx)
1237 return levels_property_helper(offsetof(struct mp_csp_details, levels_out),
1238 prop, action, arg, mpctx);
1241 static int mp_property_capture(m_option_t *prop, int action,
1242 void *arg, MPContext *mpctx)
1244 struct MPOpts *opts = &mpctx->opts;
1246 if (!mpctx->stream)
1247 return M_PROPERTY_UNAVAILABLE;
1249 if (!opts->capture_dump) {
1250 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1251 "Capturing not enabled (forgot -capture parameter?)\n");
1252 return M_PROPERTY_ERROR;
1255 int capturing = !!mpctx->stream->capture_file;
1257 int ret = m_property_flag(prop, action, arg, &capturing);
1258 if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
1259 if (capturing) {
1260 mpctx->stream->capture_file = fopen(opts->stream_dump_name, "wb");
1261 if (!mpctx->stream->capture_file) {
1262 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1263 "Error opening capture file: %s\n", strerror(errno));
1264 ret = M_PROPERTY_ERROR;
1266 } else {
1267 fclose(mpctx->stream->capture_file);
1268 mpctx->stream->capture_file = NULL;
1272 return ret;
1275 /// Panscan (RW)
1276 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1277 MPContext *mpctx)
1280 if (!mpctx->video_out
1281 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1282 return M_PROPERTY_UNAVAILABLE;
1284 switch (action) {
1285 case M_PROPERTY_SET:
1286 if (!arg)
1287 return M_PROPERTY_ERROR;
1288 M_PROPERTY_CLAMP(prop, *(float *) arg);
1289 vo_panscan = *(float *) arg;
1290 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1291 return M_PROPERTY_OK;
1292 case M_PROPERTY_STEP_UP:
1293 case M_PROPERTY_STEP_DOWN:
1294 vo_panscan += (arg ? *(float *) arg : 0.1) *
1295 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1296 if (vo_panscan > 1)
1297 vo_panscan = 1;
1298 else if (vo_panscan < 0)
1299 vo_panscan = 0;
1300 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1301 return M_PROPERTY_OK;
1302 default:
1303 return m_property_float_range(prop, action, arg, &vo_panscan);
1307 /// Helper to set vo flags.
1308 /** \ingroup PropertyImplHelper
1310 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1311 int vo_ctrl, int *vo_var, MPContext *mpctx)
1314 if (!mpctx->video_out)
1315 return M_PROPERTY_UNAVAILABLE;
1317 switch (action) {
1318 case M_PROPERTY_SET:
1319 if (!arg)
1320 return M_PROPERTY_ERROR;
1321 M_PROPERTY_CLAMP(prop, *(int *) arg);
1322 if (*vo_var == !!*(int *) arg)
1323 return M_PROPERTY_OK;
1324 case M_PROPERTY_STEP_UP:
1325 case M_PROPERTY_STEP_DOWN:
1326 if (mpctx->video_out->config_ok)
1327 vo_control(mpctx->video_out, vo_ctrl, 0);
1328 return M_PROPERTY_OK;
1329 default:
1330 return m_property_flag(prop, action, arg, vo_var);
1334 /// Window always on top (RW)
1335 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1336 MPContext *mpctx)
1338 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1339 &mpctx->opts.vo_ontop, mpctx);
1342 /// Display in the root window (RW)
1343 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1344 MPContext *mpctx)
1346 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1347 &vo_rootwin, mpctx);
1350 /// Show window borders (RW)
1351 static int mp_property_border(m_option_t *prop, int action, void *arg,
1352 MPContext *mpctx)
1354 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1355 &vo_border, mpctx);
1358 /// Framedropping state (RW)
1359 static int mp_property_framedropping(m_option_t *prop, int action,
1360 void *arg, MPContext *mpctx)
1363 if (!mpctx->sh_video)
1364 return M_PROPERTY_UNAVAILABLE;
1366 switch (action) {
1367 case M_PROPERTY_PRINT:
1368 if (!arg)
1369 return M_PROPERTY_ERROR;
1370 *(char **) arg = talloc_strdup(NULL, frame_dropping == 1 ?
1371 mp_gtext("enabled") :
1372 (frame_dropping == 2 ? mp_gtext("hard") :
1373 mp_gtext("disabled")));
1374 return M_PROPERTY_OK;
1375 default:
1376 return m_property_choice(prop, action, arg, &frame_dropping);
1380 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1381 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1382 MPContext *mpctx)
1384 int *gamma = (int *)((char *)&mpctx->opts + prop->offset);
1385 int r, val;
1387 if (!mpctx->sh_video)
1388 return M_PROPERTY_UNAVAILABLE;
1390 if (gamma[0] == 1000) {
1391 gamma[0] = 0;
1392 get_video_colors(mpctx->sh_video, prop->name, gamma);
1395 switch (action) {
1396 case M_PROPERTY_SET:
1397 if (!arg)
1398 return M_PROPERTY_ERROR;
1399 M_PROPERTY_CLAMP(prop, *(int *) arg);
1400 *gamma = *(int *) arg;
1401 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1402 if (r <= 0)
1403 break;
1404 return r;
1405 case M_PROPERTY_GET:
1406 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1407 if (!arg)
1408 return M_PROPERTY_ERROR;
1409 *(int *)arg = val;
1410 return M_PROPERTY_OK;
1412 break;
1413 case M_PROPERTY_STEP_UP:
1414 case M_PROPERTY_STEP_DOWN:
1415 *gamma += (arg ? *(int *) arg : 1) *
1416 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1417 M_PROPERTY_CLAMP(prop, *gamma);
1418 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1419 if (r <= 0)
1420 break;
1421 return r;
1422 default:
1423 return M_PROPERTY_NOT_IMPLEMENTED;
1426 #ifdef CONFIG_TV
1427 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1428 int l = strlen(prop->name);
1429 char tv_prop[3 + l + 1];
1430 sprintf(tv_prop, "tv_%s", prop->name);
1431 return mp_property_do(tv_prop, action, arg, mpctx);
1433 #endif
1435 return M_PROPERTY_UNAVAILABLE;
1438 /// VSync (RW)
1439 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1440 MPContext *mpctx)
1442 return m_property_flag(prop, action, arg, &vo_vsync);
1445 /// Video codec tag (RO)
1446 static int mp_property_video_format(m_option_t *prop, int action,
1447 void *arg, MPContext *mpctx)
1449 char *meta;
1450 if (!mpctx->sh_video)
1451 return M_PROPERTY_UNAVAILABLE;
1452 switch (action) {
1453 case M_PROPERTY_PRINT:
1454 if (!arg)
1455 return M_PROPERTY_ERROR;
1456 switch (mpctx->sh_video->format) {
1457 case 0x10000001:
1458 meta = talloc_strdup(NULL, "mpeg1");
1459 break;
1460 case 0x10000002:
1461 meta = talloc_strdup(NULL, "mpeg2");
1462 break;
1463 case 0x10000004:
1464 meta = talloc_strdup(NULL, "mpeg4");
1465 break;
1466 case 0x10000005:
1467 meta = talloc_strdup(NULL, "h264");
1468 break;
1469 default:
1470 if (mpctx->sh_video->format >= 0x20202020) {
1471 meta = talloc_asprintf(NULL, "%.4s",
1472 (char *) &mpctx->sh_video->format);
1473 } else
1474 meta = talloc_asprintf(NULL, "0x%08X", mpctx->sh_video->format);
1476 *(char **)arg = meta;
1477 return M_PROPERTY_OK;
1479 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1482 /// Video codec name (RO)
1483 static int mp_property_video_codec(m_option_t *prop, int action,
1484 void *arg, MPContext *mpctx)
1486 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1487 return M_PROPERTY_UNAVAILABLE;
1488 return m_property_string_ro(prop, action, arg,
1489 mpctx->sh_video->codec->name);
1493 /// Video bitrate (RO)
1494 static int mp_property_video_bitrate(m_option_t *prop, int action,
1495 void *arg, MPContext *mpctx)
1497 if (!mpctx->sh_video)
1498 return M_PROPERTY_UNAVAILABLE;
1499 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1502 /// Video display width (RO)
1503 static int mp_property_width(m_option_t *prop, int action, void *arg,
1504 MPContext *mpctx)
1506 if (!mpctx->sh_video)
1507 return M_PROPERTY_UNAVAILABLE;
1508 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1511 /// Video display height (RO)
1512 static int mp_property_height(m_option_t *prop, int action, void *arg,
1513 MPContext *mpctx)
1515 if (!mpctx->sh_video)
1516 return M_PROPERTY_UNAVAILABLE;
1517 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1520 /// Video fps (RO)
1521 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1522 MPContext *mpctx)
1524 if (!mpctx->sh_video)
1525 return M_PROPERTY_UNAVAILABLE;
1526 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1529 /// Video aspect (RO)
1530 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1531 MPContext *mpctx)
1533 if (!mpctx->sh_video)
1534 return M_PROPERTY_UNAVAILABLE;
1535 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1539 /// Text subtitle position (RW)
1540 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1541 MPContext *mpctx)
1543 switch (action) {
1544 case M_PROPERTY_SET:
1545 if (!arg)
1546 return M_PROPERTY_ERROR;
1547 case M_PROPERTY_STEP_UP:
1548 case M_PROPERTY_STEP_DOWN:
1549 vo_osd_changed(OSDTYPE_SUBTITLE);
1550 default:
1551 return m_property_int_range(prop, action, arg, &sub_pos);
1555 /// Selected subtitles (RW)
1556 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1557 MPContext *mpctx)
1559 struct MPOpts *opts = &mpctx->opts;
1560 demux_stream_t *const d_sub = mpctx->d_sub;
1561 int source = -1, reset_spu av_unused = 0; // used under CONFIG_DVDREAD
1562 int source_pos = -1;
1564 update_global_sub_size(mpctx);
1565 const int global_sub_size = mpctx->global_sub_size;
1567 if (global_sub_size <= 0)
1568 return M_PROPERTY_UNAVAILABLE;
1570 switch (action) {
1571 case M_PROPERTY_GET:
1572 if (!arg)
1573 return M_PROPERTY_ERROR;
1574 *(int *) arg = mpctx->global_sub_pos;
1575 return M_PROPERTY_OK;
1576 case M_PROPERTY_PRINT:
1577 if (!arg)
1578 return M_PROPERTY_ERROR;
1579 char *sub_name = NULL;
1580 if (mpctx->subdata)
1581 sub_name = mpctx->subdata->filename;
1582 #ifdef CONFIG_ASS
1583 if (mpctx->osd->ass_track)
1584 sub_name = mpctx->osd->ass_track->name;
1585 #endif
1586 if (!sub_name && mpctx->subdata)
1587 sub_name = mpctx->subdata->filename;
1588 if (sub_name) {
1589 const char *tmp = mp_basename(sub_name);
1591 *(char **) arg = talloc_asprintf(NULL, "(%d) %s%s",
1592 mpctx->set_of_sub_pos + 1,
1593 strlen(tmp) < 20 ? "" : "...",
1594 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1595 return M_PROPERTY_OK;
1597 #ifdef CONFIG_DVDNAV
1598 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1599 if (vo_spudec && opts->sub_id >= 0) {
1600 unsigned char lang[3];
1601 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id,
1602 lang)) {
1603 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1604 opts->sub_id, lang);
1605 return M_PROPERTY_OK;
1609 #endif
1611 if ((d_sub->demuxer->type == DEMUXER_TYPE_MATROSKA
1612 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF
1613 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1614 || d_sub->demuxer->type == DEMUXER_TYPE_OGG)
1615 && d_sub->sh && opts->sub_id >= 0) {
1616 struct sh_sub *sh = d_sub->sh;
1617 char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
1618 if (sh->title)
1619 *(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
1620 opts->sub_id, lang, sh->title);
1621 else
1622 *(char **)arg = talloc_asprintf(NULL, "(%d) %s",
1623 opts->sub_id, lang);
1624 return M_PROPERTY_OK;
1627 if (vo_vobsub && vobsub_id >= 0) {
1628 const char *language = mp_gtext("unknown");
1629 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1630 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1631 vobsub_id, language ? language : mp_gtext("unknown"));
1632 return M_PROPERTY_OK;
1634 #ifdef CONFIG_DVDREAD
1635 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1636 && opts->sub_id >= 0) {
1637 char lang[3];
1638 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1639 lang[0] = code >> 8;
1640 lang[1] = code;
1641 lang[2] = 0;
1642 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1643 opts->sub_id, lang);
1644 return M_PROPERTY_OK;
1646 #endif
1647 if (opts->sub_id >= 0) {
1648 *(char **) arg = talloc_asprintf(NULL, "(%d) %s", opts->sub_id,
1649 mp_gtext("unknown"));
1650 return M_PROPERTY_OK;
1652 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1653 return M_PROPERTY_OK;
1655 case M_PROPERTY_SET:
1656 if (!arg)
1657 return M_PROPERTY_ERROR;
1658 if (*(int *) arg < -1)
1659 *(int *) arg = -1;
1660 else if (*(int *) arg >= global_sub_size)
1661 *(int *) arg = global_sub_size - 1;
1662 mpctx->global_sub_pos = *(int *) arg;
1663 break;
1664 case M_PROPERTY_STEP_UP:
1665 mpctx->global_sub_pos += 2;
1666 mpctx->global_sub_pos =
1667 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1668 break;
1669 case M_PROPERTY_STEP_DOWN:
1670 mpctx->global_sub_pos += global_sub_size + 1;
1671 mpctx->global_sub_pos =
1672 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1673 break;
1674 default:
1675 return M_PROPERTY_NOT_IMPLEMENTED;
1678 if (mpctx->global_sub_pos >= 0) {
1679 source = sub_source(mpctx);
1680 source_pos = sub_source_pos(mpctx);
1683 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1684 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1685 global_sub_size,
1686 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1687 mpctx->sub_counts[SUB_SOURCE_SUBS],
1688 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1689 mpctx->global_sub_pos, source);
1691 mpctx->set_of_sub_pos = -1;
1692 mpctx->subdata = NULL;
1694 vobsub_id = -1;
1695 opts->sub_id = -1;
1696 if (d_sub) {
1697 if (d_sub->id > -2)
1698 reset_spu = 1;
1699 d_sub->id = -2;
1701 mpctx->osd->ass_track = NULL;
1702 uninit_player(mpctx, INITIALIZED_SUB);
1704 if (source == SUB_SOURCE_VOBSUB)
1705 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1706 else if (source == SUB_SOURCE_SUBS) {
1707 mpctx->set_of_sub_pos = source_pos;
1708 #ifdef CONFIG_ASS
1709 if (opts->ass_enabled
1710 && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]) {
1711 mpctx->osd->ass_track =
1712 mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1713 mpctx->osd->ass_track_changed = true;
1714 mpctx->osd->vsfilter_aspect =
1715 mpctx->track_was_native_ass[mpctx->set_of_sub_pos];
1716 } else
1717 #endif
1719 mpctx->subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1720 vo_osd_changed(OSDTYPE_SUBTITLE);
1722 } else if (source == SUB_SOURCE_DEMUX) {
1723 opts->sub_id = source_pos;
1724 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1725 int i = 0;
1726 // default: assume 1:1 mapping of sid and stream id
1727 d_sub->id = opts->sub_id;
1728 d_sub->sh = mpctx->d_sub->demuxer->s_streams[d_sub->id];
1729 ds_free_packs(d_sub);
1730 for (i = 0; i < MAX_S_STREAMS; i++) {
1731 sh_sub_t *sh = mpctx->d_sub->demuxer->s_streams[i];
1732 if (sh && sh->sid == opts->sub_id) {
1733 d_sub->id = i;
1734 d_sub->sh = sh;
1735 break;
1738 if (d_sub->sh && d_sub->id >= 0) {
1739 sh_sub_t *sh = d_sub->sh;
1740 if (sh->type == 'v')
1741 init_vo_spudec(mpctx);
1742 else {
1743 sub_init(sh, mpctx->osd);
1744 mpctx->initialized_flags |= INITIALIZED_SUB;
1746 } else {
1747 d_sub->id = -2;
1748 d_sub->sh = NULL;
1752 #ifdef CONFIG_DVDREAD
1753 if (vo_spudec
1754 && (mpctx->stream->type == STREAMTYPE_DVD
1755 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1756 && opts->sub_id < 0 && reset_spu) {
1757 d_sub->id = -2;
1758 d_sub->sh = NULL;
1760 #endif
1762 update_subtitles(mpctx, 0, true);
1764 return M_PROPERTY_OK;
1767 /// Selected sub source (RW)
1768 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1769 MPContext *mpctx)
1771 int source;
1772 update_global_sub_size(mpctx);
1773 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1774 return M_PROPERTY_UNAVAILABLE;
1776 switch (action) {
1777 case M_PROPERTY_GET:
1778 if (!arg)
1779 return M_PROPERTY_ERROR;
1780 *(int *) arg = sub_source(mpctx);
1781 return M_PROPERTY_OK;
1782 case M_PROPERTY_PRINT:
1783 if (!arg)
1784 return M_PROPERTY_ERROR;
1785 char *sourcename;
1786 switch (sub_source(mpctx)) {
1787 case SUB_SOURCE_SUBS:
1788 sourcename = mp_gtext("file");
1789 break;
1790 case SUB_SOURCE_VOBSUB:
1791 sourcename = mp_gtext("vobsub");
1792 break;
1793 case SUB_SOURCE_DEMUX:
1794 sourcename = mp_gtext("embedded");
1795 break;
1796 default:
1797 sourcename = mp_gtext("disabled");
1799 *(char **)arg = talloc_strdup(NULL, sourcename);
1800 return M_PROPERTY_OK;
1801 case M_PROPERTY_SET:
1802 if (!arg)
1803 return M_PROPERTY_ERROR;
1804 M_PROPERTY_CLAMP(prop, *(int *)arg);
1805 if (*(int *) arg < 0)
1806 mpctx->global_sub_pos = -1;
1807 else if (*(int *) arg != sub_source(mpctx)) {
1808 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1809 if (new_pos == -1)
1810 return M_PROPERTY_UNAVAILABLE;
1811 mpctx->global_sub_pos = new_pos;
1813 break;
1814 case M_PROPERTY_STEP_UP:
1815 case M_PROPERTY_STEP_DOWN: {
1816 int step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1)
1817 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1818 int step = (step_all > 0) ? 1 : -1;
1819 int cur_source = sub_source(mpctx);
1820 source = cur_source;
1821 while (step_all) {
1822 source += step;
1823 if (source >= SUB_SOURCES)
1824 source = -1;
1825 else if (source < -1)
1826 source = SUB_SOURCES - 1;
1827 if (source == cur_source || source == -1 ||
1828 mpctx->sub_counts[source])
1829 step_all -= step;
1831 if (source == cur_source)
1832 return M_PROPERTY_OK;
1833 if (source == -1)
1834 mpctx->global_sub_pos = -1;
1835 else
1836 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1837 break;
1839 default:
1840 return M_PROPERTY_NOT_IMPLEMENTED;
1842 --mpctx->global_sub_pos;
1843 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1846 /// Selected subtitles from specific source (RW)
1847 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1848 MPContext *mpctx)
1850 int source, is_cur_source, offset, new_pos;
1851 update_global_sub_size(mpctx);
1852 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1853 return M_PROPERTY_UNAVAILABLE;
1855 if (!strcmp(prop->name, "sub_file"))
1856 source = SUB_SOURCE_SUBS;
1857 else if (!strcmp(prop->name, "sub_vob"))
1858 source = SUB_SOURCE_VOBSUB;
1859 else if (!strcmp(prop->name, "sub_demux"))
1860 source = SUB_SOURCE_DEMUX;
1861 else
1862 return M_PROPERTY_ERROR;
1864 offset = sub_pos_by_source(mpctx, source);
1865 if (offset < 0)
1866 return M_PROPERTY_UNAVAILABLE;
1868 is_cur_source = sub_source(mpctx) == source;
1869 new_pos = mpctx->global_sub_pos;
1870 switch (action) {
1871 case M_PROPERTY_GET:
1872 if (!arg)
1873 return M_PROPERTY_ERROR;
1874 if (is_cur_source) {
1875 *(int *) arg = sub_source_pos(mpctx);
1876 if (source == SUB_SOURCE_VOBSUB)
1877 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1878 } else
1879 *(int *) arg = -1;
1880 return M_PROPERTY_OK;
1881 case M_PROPERTY_PRINT:
1882 if (!arg)
1883 return M_PROPERTY_ERROR;
1884 if (is_cur_source)
1885 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1886 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1887 return M_PROPERTY_OK;
1888 case M_PROPERTY_SET:
1889 if (!arg)
1890 return M_PROPERTY_ERROR;
1891 if (*(int *) arg >= 0) {
1892 int index = *(int *)arg;
1893 if (source == SUB_SOURCE_VOBSUB)
1894 index = vobsub_get_index_by_id(vo_vobsub, index);
1895 new_pos = offset + index;
1896 if (index < 0 || index > mpctx->sub_counts[source]) {
1897 new_pos = -1;
1898 *(int *) arg = -1;
1900 } else
1901 new_pos = -1;
1902 break;
1903 case M_PROPERTY_STEP_UP:
1904 case M_PROPERTY_STEP_DOWN: {
1905 int step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1)
1906 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1907 int step = (step_all > 0) ? 1 : -1;
1908 int max_sub_pos_for_source = -1;
1909 if (!is_cur_source)
1910 new_pos = -1;
1911 while (step_all) {
1912 if (new_pos == -1) {
1913 if (step > 0)
1914 new_pos = offset;
1915 else if (max_sub_pos_for_source == -1) {
1916 // Find max pos for specific source
1917 new_pos = mpctx->global_sub_size - 1;
1918 while (new_pos >= 0 && sub_source(mpctx) != source)
1919 new_pos--;
1920 } else
1921 new_pos = max_sub_pos_for_source;
1922 } else {
1923 new_pos += step;
1924 if (new_pos < offset ||
1925 new_pos >= mpctx->global_sub_size ||
1926 sub_source(mpctx) != source)
1927 new_pos = -1;
1929 step_all -= step;
1931 break;
1933 default:
1934 return M_PROPERTY_NOT_IMPLEMENTED;
1936 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1939 /// Subtitle delay (RW)
1940 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1941 MPContext *mpctx)
1943 if (!mpctx->sh_video)
1944 return M_PROPERTY_UNAVAILABLE;
1945 return m_property_delay(prop, action, arg, &sub_delay);
1948 /// Alignment of text subtitles (RW)
1949 static int mp_property_sub_alignment(m_option_t *prop, int action,
1950 void *arg, MPContext *mpctx)
1952 char *name[] = {
1953 _("top"), _("center"), _("bottom")
1956 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1957 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1958 return M_PROPERTY_UNAVAILABLE;
1960 switch (action) {
1961 case M_PROPERTY_PRINT:
1962 if (!arg)
1963 return M_PROPERTY_ERROR;
1964 M_PROPERTY_CLAMP(prop, sub_alignment);
1965 *(char **) arg = talloc_strdup(NULL, mp_gtext(name[sub_alignment]));
1966 return M_PROPERTY_OK;
1967 case M_PROPERTY_SET:
1968 if (!arg)
1969 return M_PROPERTY_ERROR;
1970 case M_PROPERTY_STEP_UP:
1971 case M_PROPERTY_STEP_DOWN:
1972 vo_osd_changed(OSDTYPE_SUBTITLE);
1973 default:
1974 return m_property_choice(prop, action, arg, &sub_alignment);
1978 /// Subtitle visibility (RW)
1979 static int mp_property_sub_visibility(m_option_t *prop, int action,
1980 void *arg, MPContext *mpctx)
1982 if (!mpctx->sh_video)
1983 return M_PROPERTY_UNAVAILABLE;
1985 switch (action) {
1986 case M_PROPERTY_SET:
1987 if (!arg)
1988 return M_PROPERTY_ERROR;
1989 case M_PROPERTY_STEP_UP:
1990 case M_PROPERTY_STEP_DOWN:
1991 vo_osd_changed(OSDTYPE_SUBTITLE);
1992 if (vo_spudec)
1993 vo_osd_changed(OSDTYPE_SPU);
1994 default:
1995 return m_property_flag(prop, action, arg, &sub_visibility);
1999 #ifdef CONFIG_ASS
2000 /// Use margins for libass subtitles (RW)
2001 static int mp_property_ass_use_margins(m_option_t *prop, int action,
2002 void *arg, MPContext *mpctx)
2004 struct MPOpts *opts = &mpctx->opts;
2005 if (!mpctx->sh_video)
2006 return M_PROPERTY_UNAVAILABLE;
2008 switch (action) {
2009 case M_PROPERTY_SET:
2010 if (!arg)
2011 return M_PROPERTY_ERROR;
2012 case M_PROPERTY_STEP_UP:
2013 case M_PROPERTY_STEP_DOWN:
2014 mpctx->osd->ass_force_reload = true;
2015 default:
2016 return m_property_flag(prop, action, arg, &opts->ass_use_margins);
2020 static int mp_property_ass_vsfilter_aspect_compat(m_option_t *prop, int action,
2021 void *arg, MPContext *mpctx)
2023 if (!mpctx->sh_video)
2024 return M_PROPERTY_UNAVAILABLE;
2026 switch (action) {
2027 case M_PROPERTY_SET:
2028 if (!arg)
2029 return M_PROPERTY_ERROR;
2030 case M_PROPERTY_STEP_UP:
2031 case M_PROPERTY_STEP_DOWN:
2032 //has to re-render subs with new aspect ratio
2033 mpctx->osd->ass_force_reload = 1;
2034 default:
2035 return m_property_flag(prop, action, arg,
2036 &mpctx->opts.ass_vsfilter_aspect_compat);
2040 #endif
2042 /// Show only forced subtitles (RW)
2043 static int mp_property_sub_forced_only(m_option_t *prop, int action,
2044 void *arg, MPContext *mpctx)
2046 if (!vo_spudec)
2047 return M_PROPERTY_UNAVAILABLE;
2049 switch (action) {
2050 case M_PROPERTY_SET:
2051 if (!arg)
2052 return M_PROPERTY_ERROR;
2053 case M_PROPERTY_STEP_UP:
2054 case M_PROPERTY_STEP_DOWN:
2055 m_property_flag(prop, action, arg, &forced_subs_only);
2056 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
2057 return M_PROPERTY_OK;
2058 default:
2059 return m_property_flag(prop, action, arg, &forced_subs_only);
2064 #ifdef CONFIG_FREETYPE
2065 /// Subtitle scale (RW)
2066 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
2067 MPContext *mpctx)
2069 struct MPOpts *opts = &mpctx->opts;
2071 switch (action) {
2072 case M_PROPERTY_SET:
2073 if (!arg)
2074 return M_PROPERTY_ERROR;
2075 M_PROPERTY_CLAMP(prop, *(float *) arg);
2076 #ifdef CONFIG_ASS
2077 if (opts->ass_enabled) {
2078 opts->ass_font_scale = *(float *) arg;
2079 mpctx->osd->ass_force_reload = true;
2081 #endif
2082 text_font_scale_factor = *(float *) arg;
2083 force_load_font = 1;
2084 vo_osd_changed(OSDTYPE_SUBTITLE);
2085 return M_PROPERTY_OK;
2086 case M_PROPERTY_STEP_UP:
2087 case M_PROPERTY_STEP_DOWN:
2088 #ifdef CONFIG_ASS
2089 if (opts->ass_enabled) {
2090 opts->ass_font_scale += (arg ? *(float *) arg : 0.1) *
2091 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2092 M_PROPERTY_CLAMP(prop, opts->ass_font_scale);
2093 mpctx->osd->ass_force_reload = true;
2095 #endif
2096 text_font_scale_factor += (arg ? *(float *) arg : 0.1) *
2097 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2098 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
2099 force_load_font = 1;
2100 vo_osd_changed(OSDTYPE_SUBTITLE);
2101 return M_PROPERTY_OK;
2102 default:
2103 #ifdef CONFIG_ASS
2104 if (opts->ass_enabled)
2105 return m_property_float_ro(prop, action, arg, opts->ass_font_scale);
2106 else
2107 #endif
2108 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
2111 #endif
2114 #ifdef CONFIG_TV
2116 /// TV color settings (RW)
2117 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2118 MPContext *mpctx)
2120 int r, val;
2121 tvi_handle_t *tvh = mpctx->demuxer->priv;
2122 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2123 return M_PROPERTY_UNAVAILABLE;
2125 switch (action) {
2126 case M_PROPERTY_SET:
2127 if (!arg)
2128 return M_PROPERTY_ERROR;
2129 M_PROPERTY_CLAMP(prop, *(int *) arg);
2130 return tv_set_color_options(tvh, prop->offset, *(int *) arg);
2131 case M_PROPERTY_GET:
2132 return tv_get_color_options(tvh, prop->offset, arg);
2133 case M_PROPERTY_STEP_UP:
2134 case M_PROPERTY_STEP_DOWN:
2135 if ((r = tv_get_color_options(tvh, prop->offset, &val)) >= 0) {
2136 if (!r)
2137 return M_PROPERTY_ERROR;
2138 val += (arg ? *(int *) arg : 1) *
2139 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2140 M_PROPERTY_CLAMP(prop, val);
2141 return tv_set_color_options(tvh, prop->offset, val);
2143 return M_PROPERTY_ERROR;
2145 return M_PROPERTY_NOT_IMPLEMENTED;
2148 #endif
2150 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2151 MPContext *mpctx)
2153 int val, result;
2154 int base_ioctl = prop->offset;
2156 for teletext's GET,SET,STEP ioctls this is not 0
2157 SET is GET+1
2158 STEP is GET+2
2160 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2161 return M_PROPERTY_UNAVAILABLE;
2162 if (!base_ioctl)
2163 return M_PROPERTY_ERROR;
2165 switch (action) {
2166 case M_PROPERTY_GET:
2167 if (!arg)
2168 return M_PROPERTY_ERROR;
2169 result = teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2170 break;
2171 case M_PROPERTY_SET:
2172 if (!arg)
2173 return M_PROPERTY_ERROR;
2174 M_PROPERTY_CLAMP(prop, *(int *) arg);
2175 result = teletext_control(mpctx->demuxer->teletext, base_ioctl + 1,
2176 arg);
2177 break;
2178 case M_PROPERTY_STEP_UP:
2179 case M_PROPERTY_STEP_DOWN:
2180 result = teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2181 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ?
2182 -1 : 1);
2183 result = teletext_control(mpctx->demuxer->teletext, base_ioctl + 1,
2184 &val);
2185 break;
2186 default:
2187 return M_PROPERTY_NOT_IMPLEMENTED;
2190 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2193 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2194 MPContext *mpctx)
2196 int result;
2197 int val;
2199 //with tvh==NULL will fail too
2200 result = mp_property_teletext_common(prop, action, arg, mpctx);
2201 if (result != M_PROPERTY_OK)
2202 return result;
2204 if (teletext_control(mpctx->demuxer->teletext,
2205 prop->offset, &val) == VBI_CONTROL_TRUE && val)
2206 mp_input_set_section(mpctx->input, "teletext");
2207 else
2208 mp_input_set_section(mpctx->input, "tv");
2209 return M_PROPERTY_OK;
2212 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2213 MPContext *mpctx)
2215 int result;
2216 int val;
2217 if (!mpctx->demuxer->teletext)
2218 return M_PROPERTY_UNAVAILABLE;
2219 switch (action) {
2220 case M_PROPERTY_STEP_UP:
2221 case M_PROPERTY_STEP_DOWN:
2222 //This should be handled separately
2223 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ?
2224 -1 : 1);
2225 result = teletext_control(mpctx->demuxer->teletext,
2226 TV_VBI_CONTROL_STEP_PAGE, &val);
2227 break;
2228 default:
2229 result = mp_property_teletext_common(prop, action, arg, mpctx);
2231 return result;
2235 /// All properties available in MPlayer.
2236 /** \ingroup Properties
2238 static const m_option_t mp_properties[] = {
2239 // General
2240 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2241 M_OPT_RANGE, 0, 3, NULL },
2242 { "loop", mp_property_loop, CONF_TYPE_INT,
2243 M_OPT_MIN, -1, 0, NULL },
2244 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2245 M_OPT_RANGE, 0.01, 100.0, NULL },
2246 { "filename", mp_property_filename, CONF_TYPE_STRING,
2247 0, 0, 0, NULL },
2248 { "path", mp_property_path, CONF_TYPE_STRING,
2249 0, 0, 0, NULL },
2250 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2251 0, 0, 0, NULL },
2252 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2253 M_OPT_MIN, 0, 0, NULL },
2254 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2255 M_OPT_MIN, 0, 0, NULL },
2256 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2257 M_OPT_MIN, 0, 0, NULL },
2258 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2259 M_OPT_MIN, 0, 0, NULL },
2260 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2261 M_OPT_MIN, 0, 0, NULL },
2262 { "length", mp_property_length, CONF_TYPE_TIME,
2263 M_OPT_MIN, 0, 0, NULL },
2264 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2265 M_OPT_RANGE, 0, 100, NULL },
2266 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2267 M_OPT_MIN, 0, 0, NULL },
2268 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2269 M_OPT_MIN, 0, 0, NULL },
2270 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2271 0, 0, 0, NULL },
2272 { "angle", mp_property_angle, CONF_TYPE_INT,
2273 CONF_RANGE, -2, 10, NULL },
2274 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2275 0, 0, 0, NULL },
2276 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2277 M_OPT_RANGE, 0, 1, NULL },
2278 { "capturing", mp_property_capture, CONF_TYPE_FLAG,
2279 M_OPT_RANGE, 0, 1, NULL },
2280 { "pts_association_mode", mp_property_generic_option, &m_option_type_choice,
2281 0, 0, 0, "pts-association-mode" },
2282 { "hr_seek", mp_property_generic_option, &m_option_type_choice,
2283 0, 0, 0, "hr-seek" },
2285 // Audio
2286 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2287 M_OPT_RANGE, 0, 100, NULL },
2288 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2289 M_OPT_RANGE, 0, 1, NULL },
2290 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2291 M_OPT_RANGE, -100, 100, NULL },
2292 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2293 0, 0, 0, NULL },
2294 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2295 0, 0, 0, NULL },
2296 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2297 0, 0, 0, NULL },
2298 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2299 0, 0, 0, NULL },
2300 { "channels", mp_property_channels, CONF_TYPE_INT,
2301 0, 0, 0, NULL },
2302 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2303 CONF_RANGE, -2, 65535, NULL },
2304 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2305 M_OPT_RANGE, -1, 1, NULL },
2307 // Video
2308 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2309 M_OPT_RANGE, 0, 1, NULL },
2310 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2311 M_OPT_RANGE, 0, 1, NULL },
2312 { "colormatrix", mp_property_colormatrix, &m_option_type_choice,
2313 0, 0, 0, "colormatrix" },
2314 { "colormatrix_input_range", mp_property_colormatrix_input_range, &m_option_type_choice,
2315 0, 0, 0, "colormatrix-input-range" },
2316 { "colormatrix_output_range", mp_property_colormatrix_output_range, &m_option_type_choice,
2317 0, 0, 0, "colormatrix-output-range" },
2318 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2319 M_OPT_RANGE, 0, 1, NULL },
2320 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2321 M_OPT_RANGE, 0, 1, NULL },
2322 { "border", mp_property_border, CONF_TYPE_FLAG,
2323 M_OPT_RANGE, 0, 1, NULL },
2324 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2325 M_OPT_RANGE, 0, 2, NULL },
2326 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2327 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_gamma)},
2328 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2329 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_brightness) },
2330 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2331 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_contrast) },
2332 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2333 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_saturation) },
2334 { "hue", mp_property_gamma, CONF_TYPE_INT,
2335 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_hue) },
2336 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2337 M_OPT_RANGE, 0, 1, NULL },
2338 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2339 M_OPT_RANGE, 0, 1, NULL },
2340 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2341 0, 0, 0, NULL },
2342 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2343 0, 0, 0, NULL },
2344 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2345 0, 0, 0, NULL },
2346 { "width", mp_property_width, CONF_TYPE_INT,
2347 0, 0, 0, NULL },
2348 { "height", mp_property_height, CONF_TYPE_INT,
2349 0, 0, 0, NULL },
2350 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2351 0, 0, 0, NULL },
2352 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2353 0, 0, 0, NULL },
2354 { "switch_video", mp_property_video, CONF_TYPE_INT,
2355 CONF_RANGE, -2, 65535, NULL },
2356 { "switch_program", mp_property_program, CONF_TYPE_INT,
2357 CONF_RANGE, -1, 65535, NULL },
2359 // Subs
2360 { "sub", mp_property_sub, CONF_TYPE_INT,
2361 M_OPT_MIN, -1, 0, NULL },
2362 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2363 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2364 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2365 M_OPT_MIN, -1, 0, NULL },
2366 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2367 M_OPT_MIN, -1, 0, NULL },
2368 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2369 M_OPT_MIN, -1, 0, NULL },
2370 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2371 0, 0, 0, NULL },
2372 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2373 M_OPT_RANGE, 0, 100, NULL },
2374 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2375 M_OPT_RANGE, 0, 2, NULL },
2376 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2377 M_OPT_RANGE, 0, 1, NULL },
2378 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2379 M_OPT_RANGE, 0, 1, NULL },
2380 #ifdef CONFIG_FREETYPE
2381 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2382 M_OPT_RANGE, 0, 100, NULL },
2383 #endif
2384 #ifdef CONFIG_ASS
2385 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2386 M_OPT_RANGE, 0, 1, NULL },
2387 { "ass_vsfilter_aspect_compat", mp_property_ass_vsfilter_aspect_compat,
2388 CONF_TYPE_FLAG, M_OPT_RANGE, 0, 1, NULL },
2389 #endif
2391 #ifdef CONFIG_TV
2392 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2393 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_BRIGHTNESS },
2394 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2395 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_CONTRAST },
2396 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2397 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_SATURATION },
2398 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2399 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_HUE },
2400 #endif
2401 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2402 M_OPT_RANGE, 100, 899, .offset = TV_VBI_CONTROL_GET_PAGE },
2403 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2404 M_OPT_RANGE, 0, 64, .offset = TV_VBI_CONTROL_GET_SUBPAGE },
2405 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2406 M_OPT_RANGE, 0, 1, .offset = TV_VBI_CONTROL_GET_MODE },
2407 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2408 M_OPT_RANGE, 0, 3, .offset = TV_VBI_CONTROL_GET_FORMAT },
2409 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2410 M_OPT_RANGE, 0, 2, .offset = TV_VBI_CONTROL_GET_HALF_PAGE },
2411 { NULL, NULL, NULL, 0, 0, 0, NULL }
2415 int mp_property_do(const char *name, int action, void *val, void *ctx)
2417 return m_property_do(mp_properties, name, action, val, ctx);
2420 char *mp_property_print(const char *name, void *ctx)
2422 char *ret = NULL;
2423 if (mp_property_do(name, M_PROPERTY_PRINT, &ret, ctx) <= 0)
2424 return NULL;
2425 return ret;
2428 char *property_expand_string(MPContext *mpctx, char *str)
2430 return m_properties_expand_string(mp_properties, str, mpctx);
2433 void property_print_help(void)
2435 m_properties_print_help_list(mp_properties);
2439 /* List of default ways to show a property on OSD.
2441 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2442 * a bar showing the current position between min/max values of the
2443 * property. In this case osd_msg is only used for terminal output
2444 * if there is no video; it'll be a label shown together with percentage.
2446 * Otherwise setting osd_msg will show the string on OSD, formatted with
2447 * the text value of the property as argument.
2449 static struct property_osd_display {
2450 /// property name
2451 const char *name;
2452 /// progressbar type
2453 int osd_progbar; // -1 is special value for seek indicators
2454 /// osd msg id if it must be shared
2455 int osd_id;
2456 /// osd msg template
2457 const char *osd_msg;
2458 } property_osd_display[] = {
2459 // general
2460 { "loop", 0, -1, _("Loop: %s") },
2461 { "chapter", -1, -1, NULL },
2462 { "capturing", 0, -1, _("Capturing: %s") },
2463 { "pts_association_mode", 0, -1, "PTS association mode: %s" },
2464 { "hr_seek", 0, -1, "hr-seek: %s" },
2465 { "speed", 0, -1, _("Speed: x %6s") },
2466 // audio
2467 { "volume", OSD_VOLUME, -1, _("Volume") },
2468 { "mute", 0, -1, _("Mute: %s") },
2469 { "audio_delay", 0, -1, _("A-V delay: %s") },
2470 { "switch_audio", 0, -1, _("Audio: %s") },
2471 { "balance", OSD_BALANCE, -1, _("Balance") },
2472 // video
2473 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2474 { "ontop", 0, -1, _("Stay on top: %s") },
2475 { "rootwin", 0, -1, _("Rootwin: %s") },
2476 { "border", 0, -1, _("Border: %s") },
2477 { "framedropping", 0, -1, _("Framedropping: %s") },
2478 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2479 { "colormatrix", 0, -1, _("YUV colormatrix: %s") },
2480 { "colormatrix_input_range", 0, -1, _("YUV input range: %s") },
2481 { "colormatrix_output_range", 0, -1, _("RGB output range: %s") },
2482 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2483 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2484 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2485 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2486 { "hue", OSD_HUE, -1, _("Hue") },
2487 { "vsync", 0, -1, _("VSync: %s") },
2488 // subs
2489 { "sub", 0, -1, _("Subtitles: %s") },
2490 { "sub_source", 0, -1, _("Sub source: %s") },
2491 { "sub_vob", 0, -1, _("Subtitles: %s") },
2492 { "sub_demux", 0, -1, _("Subtitles: %s") },
2493 { "sub_file", 0, -1, _("Subtitles: %s") },
2494 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2495 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2496 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2497 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2498 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2499 #ifdef CONFIG_FREETYPE
2500 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2501 #endif
2502 { "ass_vsfilter_aspect_compat", 0, -1,
2503 _("Subtitle VSFilter aspect compat: %s")},
2504 #ifdef CONFIG_TV
2505 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2506 { "tv_hue", OSD_HUE, -1, _("Hue") },
2507 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2508 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2509 #endif
2513 static int show_property_osd(MPContext *mpctx, const char *pname)
2515 struct MPOpts *opts = &mpctx->opts;
2516 int r;
2517 m_option_t *prop;
2518 struct property_osd_display *p;
2520 // look for the command
2521 for (p = property_osd_display; p->name; p++)
2522 if (!strcmp(p->name, pname))
2523 break;
2525 if (!p->name)
2526 return -1;
2528 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2529 return -1;
2531 if (p->osd_progbar == -1)
2532 mpctx->add_osd_seek_info = true;
2533 else if (p->osd_progbar) {
2534 if (prop->type == CONF_TYPE_INT) {
2535 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2536 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2537 prop->min, prop->max, r);
2538 } else if (prop->type == CONF_TYPE_FLOAT) {
2539 float f;
2540 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2541 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2542 prop->min, prop->max, f);
2543 } else {
2544 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2545 "Property use an unsupported type.\n");
2546 return -1;
2548 return 0;
2551 if (p->osd_msg) {
2552 char *val = mp_property_print(pname, mpctx);
2553 if (val) {
2554 int index = p - property_osd_display;
2555 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2556 1, opts->osd_duration, p->osd_msg, val);
2557 talloc_free(val);
2560 return 0;
2565 * Command to property bridge
2567 * It is used to handle most commands that just set a property
2568 * and optionally display something on the OSD.
2569 * Two kinds of commands are handled: adjust or toggle.
2571 * Adjust commands take 1 or 2 parameters: <value> <abs>
2572 * If <abs> is non-zero the property is set to the given value
2573 * otherwise it is adjusted.
2575 * Toggle commands take 0 or 1 parameters. With no parameter
2576 * or a value less than the property minimum it just steps the
2577 * property to its next or previous value respectively.
2578 * Otherwise it sets it to the given value.
2581 /// List of the commands that can be handled by setting a property.
2582 static struct {
2583 /// property name
2584 const char *name;
2585 /// cmd id
2586 int cmd;
2587 /// set/adjust or toggle command
2588 int toggle;
2589 } set_prop_cmd[] = {
2590 // general
2591 { "loop", MP_CMD_LOOP, 0},
2592 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2593 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2594 { "pause", MP_CMD_PAUSE, 0},
2595 { "capturing", MP_CMD_CAPTURING, 1},
2596 // audio
2597 { "volume", MP_CMD_VOLUME, 0},
2598 { "mute", MP_CMD_MUTE, 1},
2599 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2600 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2601 { "balance", MP_CMD_BALANCE, 0},
2602 // video
2603 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2604 { "panscan", MP_CMD_PANSCAN, 0},
2605 { "ontop", MP_CMD_VO_ONTOP, 1},
2606 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2607 { "border", MP_CMD_VO_BORDER, 1},
2608 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2609 { "gamma", MP_CMD_GAMMA, 0},
2610 { "brightness", MP_CMD_BRIGHTNESS, 0},
2611 { "contrast", MP_CMD_CONTRAST, 0},
2612 { "saturation", MP_CMD_SATURATION, 0},
2613 { "hue", MP_CMD_HUE, 0},
2614 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2615 // subs
2616 { "sub", MP_CMD_SUB_SELECT, 1},
2617 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2618 { "sub_vob", MP_CMD_SUB_VOB, 1},
2619 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2620 { "sub_file", MP_CMD_SUB_FILE, 1},
2621 { "sub_pos", MP_CMD_SUB_POS, 0},
2622 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2623 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2624 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2625 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2626 #ifdef CONFIG_FREETYPE
2627 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2628 #endif
2629 #ifdef CONFIG_ASS
2630 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2631 #endif
2632 #ifdef CONFIG_TV
2633 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2634 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2635 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2636 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2637 #endif
2641 /// Handle commands that set a property.
2642 static bool set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2644 int i, r;
2645 m_option_t *prop;
2646 const char *pname;
2648 // look for the command
2649 for (i = 0; set_prop_cmd[i].name; i++)
2650 if (set_prop_cmd[i].cmd == cmd->id)
2651 break;
2652 if (!(pname = set_prop_cmd[i].name))
2653 return 0;
2655 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2656 return 0;
2658 // toggle command
2659 if (set_prop_cmd[i].toggle) {
2660 // set to value
2661 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2662 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2663 else if (cmd->nargs > 0)
2664 r = mp_property_do(pname, M_PROPERTY_STEP_DOWN, NULL, mpctx);
2665 else
2666 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2667 } else if (cmd->args[1].v.i) //set
2668 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2669 else // adjust
2670 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2672 if (r <= 0)
2673 return 1;
2675 show_property_osd(mpctx, pname);
2677 return 1;
2680 #ifdef CONFIG_DVDNAV
2681 static const struct {
2682 const char *name;
2683 const enum mp_command_type cmd;
2684 } mp_dvdnav_bindings[] = {
2685 { "up", MP_CMD_DVDNAV_UP },
2686 { "down", MP_CMD_DVDNAV_DOWN },
2687 { "left", MP_CMD_DVDNAV_LEFT },
2688 { "right", MP_CMD_DVDNAV_RIGHT },
2689 { "menu", MP_CMD_DVDNAV_MENU },
2690 { "select", MP_CMD_DVDNAV_SELECT },
2691 { "prev", MP_CMD_DVDNAV_PREVMENU },
2692 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2695 * keep old dvdnav sub-command options for a while in order not to
2696 * break slave-mode API too suddenly.
2698 { "1", MP_CMD_DVDNAV_UP },
2699 { "2", MP_CMD_DVDNAV_DOWN },
2700 { "3", MP_CMD_DVDNAV_LEFT },
2701 { "4", MP_CMD_DVDNAV_RIGHT },
2702 { "5", MP_CMD_DVDNAV_MENU },
2703 { "6", MP_CMD_DVDNAV_SELECT },
2704 { "7", MP_CMD_DVDNAV_PREVMENU },
2705 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2706 { NULL, 0 }
2708 #endif
2710 static const char *property_error_string(int error_value)
2712 switch (error_value) {
2713 case M_PROPERTY_ERROR:
2714 return "ERROR";
2715 case M_PROPERTY_UNAVAILABLE:
2716 return "PROPERTY_UNAVAILABLE";
2717 case M_PROPERTY_NOT_IMPLEMENTED:
2718 return "NOT_IMPLEMENTED";
2719 case M_PROPERTY_UNKNOWN:
2720 return "PROPERTY_UNKNOWN";
2721 case M_PROPERTY_DISABLED:
2722 return "DISABLED";
2724 return "UNKNOWN";
2727 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2729 int idx;
2730 int end = start + count;
2731 int after = mpctx->set_of_sub_size - end;
2732 sub_data **subs = mpctx->set_of_subtitles;
2733 #ifdef CONFIG_ASS
2734 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2735 #endif
2736 if (count < 0 || count > mpctx->set_of_sub_size ||
2737 start < 0 || start > mpctx->set_of_sub_size - count) {
2738 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2739 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2740 return;
2742 for (idx = start; idx < end; idx++) {
2743 sub_data *subd = subs[idx];
2744 char *filename = "";
2745 if (subd)
2746 filename = subd->filename;
2747 #ifdef CONFIG_ASS
2748 if (!subd)
2749 filename = ass_tracks[idx]->name;
2750 #endif
2751 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2752 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2753 filename_recode(filename));
2754 sub_free(subd);
2755 subs[idx] = NULL;
2756 #ifdef CONFIG_ASS
2757 if (ass_tracks[idx])
2758 ass_free_track(ass_tracks[idx]);
2759 ass_tracks[idx] = NULL;
2760 #endif
2763 mpctx->global_sub_size -= count;
2764 mpctx->set_of_sub_size -= count;
2765 if (mpctx->set_of_sub_size <= 0)
2766 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2768 memmove(subs + start, subs + end, after * sizeof(*subs));
2769 memset(subs + start + after, 0, count * sizeof(*subs));
2770 #ifdef CONFIG_ASS
2771 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2772 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2773 #endif
2775 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2776 mpctx->global_sub_pos = -2;
2777 mpctx->subdata = NULL;
2778 mpctx->osd->ass_track = NULL;
2779 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2780 } else if (mpctx->set_of_sub_pos >= end) {
2781 mpctx->set_of_sub_pos -= count;
2782 mpctx->global_sub_pos -= count;
2786 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2788 struct MPOpts *opts = &mpctx->opts;
2789 sh_audio_t *const sh_audio = mpctx->sh_audio;
2790 sh_video_t *const sh_video = mpctx->sh_video;
2791 int osd_duration = opts->osd_duration;
2792 int case_fallthrough_hack = 0;
2793 if (set_property_command(mpctx, cmd))
2794 goto old_pause_hack; // was handled already
2795 switch (cmd->id) {
2796 case MP_CMD_SEEK: {
2797 mpctx->add_osd_seek_info = true;
2798 float v = cmd->args[0].v.f;
2799 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2800 int exact = (cmd->nargs > 2) ? cmd->args[2].v.i : 0;
2801 if (abs == 2) { // Absolute seek to a timestamp in seconds
2802 queue_seek(mpctx, MPSEEK_ABSOLUTE, v, exact);
2803 mpctx->osd_function = v > get_current_time(mpctx) ?
2804 OSD_FFW : OSD_REW;
2805 } else if (abs) { /* Absolute seek by percentage */
2806 queue_seek(mpctx, MPSEEK_FACTOR, v / 100.0, exact);
2807 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2808 } else {
2809 queue_seek(mpctx, MPSEEK_RELATIVE, v, exact);
2810 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2812 break;
2815 case MP_CMD_SET_PROPERTY_OSD:
2816 case_fallthrough_hack = 1;
2818 case MP_CMD_SET_PROPERTY: {
2819 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2820 cmd->args[1].v.s, mpctx);
2821 if (r == M_PROPERTY_UNKNOWN)
2822 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2823 "Unknown property: '%s'\n", cmd->args[0].v.s);
2824 else if (r <= 0)
2825 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2826 "Failed to set property '%s' to '%s'.\n",
2827 cmd->args[0].v.s, cmd->args[1].v.s);
2828 else if (case_fallthrough_hack)
2829 show_property_osd(mpctx, cmd->args[0].v.s);
2830 if (r <= 0)
2831 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2832 "ANS_ERROR=%s\n", property_error_string(r));
2833 break;
2836 case MP_CMD_STEP_PROPERTY_OSD:
2837 case_fallthrough_hack = 1;
2839 case MP_CMD_STEP_PROPERTY: {
2840 void *arg = NULL;
2841 int r, i;
2842 double d;
2843 off_t o;
2844 if (cmd->args[1].v.f) {
2845 m_option_t *prop;
2846 if ((r = mp_property_do(cmd->args[0].v.s,
2847 M_PROPERTY_GET_TYPE,
2848 &prop, mpctx)) <= 0)
2849 goto step_prop_err;
2850 if (prop->type == CONF_TYPE_INT ||
2851 prop->type == CONF_TYPE_FLAG)
2852 i = cmd->args[1].v.f, arg = &i;
2853 else if (prop->type == CONF_TYPE_FLOAT)
2854 arg = &cmd->args[1].v.f;
2855 else if (prop->type == CONF_TYPE_DOUBLE ||
2856 prop->type == CONF_TYPE_TIME)
2857 d = cmd->args[1].v.f, arg = &d;
2858 else if (prop->type == CONF_TYPE_POSITION)
2859 o = cmd->args[1].v.f, arg = &o;
2860 else
2861 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2862 "Ignoring step size stepping property '%s'.\n",
2863 cmd->args[0].v.s);
2865 r = mp_property_do(cmd->args[0].v.s,
2866 cmd->args[2].v.i < 0 ?
2867 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2868 arg, mpctx);
2869 step_prop_err:
2870 if (r == M_PROPERTY_UNKNOWN)
2871 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2872 "Unknown property: '%s'\n", cmd->args[0].v.s);
2873 else if (r <= 0)
2874 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2875 "Failed to increment property '%s' by %f.\n",
2876 cmd->args[0].v.s, cmd->args[1].v.f);
2877 else if (case_fallthrough_hack)
2878 show_property_osd(mpctx, cmd->args[0].v.s);
2879 if (r <= 0)
2880 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n",
2881 property_error_string(r));
2882 break;
2885 case MP_CMD_GET_PROPERTY: {
2886 char *tmp;
2887 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2888 &tmp, mpctx);
2889 if (r <= 0) {
2890 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2891 "Failed to get value of property '%s'.\n",
2892 cmd->args[0].v.s);
2893 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n",
2894 property_error_string(r));
2895 break;
2897 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2898 cmd->args[0].v.s, tmp);
2899 talloc_free(tmp);
2900 break;
2903 case MP_CMD_EDL_MARK:
2904 if (edl_fd) {
2905 float v = get_current_time(mpctx);
2906 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2907 mpctx->begin_skip = v;
2908 mp_tmsg(MSGT_CPLAYER, MSGL_INFO,
2909 "EDL skip start, press 'i' again to end block.\n");
2910 } else {
2911 if (mpctx->begin_skip > v)
2912 mp_tmsg(MSGT_CPLAYER, MSGL_WARN,
2913 "EDL skip canceled, last start > stop\n");
2914 else {
2915 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2916 mp_tmsg(MSGT_CPLAYER, MSGL_INFO,
2917 "EDL skip end, line written.\n");
2919 mpctx->begin_skip = MP_NOPTS_VALUE;
2922 break;
2924 case MP_CMD_SWITCH_RATIO:
2925 if (!sh_video)
2926 break;
2927 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2928 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2929 else
2930 opts->movie_aspect = cmd->args[0].v.f;
2931 video_reset_aspect(sh_video);
2932 break;
2934 case MP_CMD_SPEED_INCR: {
2935 float v = cmd->args[0].v.f;
2936 mp_property_do("speed", M_PROPERTY_STEP_UP, &v, mpctx);
2937 show_property_osd(mpctx, "speed");
2938 break;
2941 case MP_CMD_SPEED_MULT:
2942 case_fallthrough_hack = true;
2944 case MP_CMD_SPEED_SET: {
2945 float v = cmd->args[0].v.f;
2946 if (case_fallthrough_hack)
2947 v *= mpctx->opts.playback_speed;
2948 mp_property_do("speed", M_PROPERTY_SET, &v, mpctx);
2949 show_property_osd(mpctx, "speed");
2950 break;
2953 case MP_CMD_FRAME_STEP:
2954 add_step_frame(mpctx);
2955 break;
2957 case MP_CMD_QUIT:
2958 exit_player_with_rc(mpctx, EXIT_QUIT,
2959 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2961 case MP_CMD_PLAY_TREE_STEP: {
2962 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2963 int force = cmd->args[1].v.i;
2966 if (!force && mpctx->playtree_iter) {
2967 play_tree_iter_t *i =
2968 play_tree_iter_new_copy(mpctx->playtree_iter);
2969 if (play_tree_iter_step(i, n, 0) ==
2970 PLAY_TREE_ITER_ENTRY)
2971 mpctx->stop_play =
2972 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2973 play_tree_iter_free(i);
2974 } else
2975 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2976 if (mpctx->stop_play)
2977 mpctx->play_tree_step = n;
2979 break;
2982 case MP_CMD_PLAY_TREE_UP_STEP: {
2983 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2984 int force = cmd->args[1].v.i;
2986 if (!force && mpctx->playtree_iter) {
2987 play_tree_iter_t *i =
2988 play_tree_iter_new_copy(mpctx->playtree_iter);
2989 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2990 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2991 play_tree_iter_free(i);
2992 } else
2993 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2994 break;
2997 case MP_CMD_PLAY_ALT_SRC_STEP:
2998 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2999 int v = cmd->args[0].v.i;
3000 if (v > 0
3001 && mpctx->playtree_iter->file <
3002 mpctx->playtree_iter->num_files)
3003 mpctx->stop_play = PT_NEXT_SRC;
3004 else if (v < 0 && mpctx->playtree_iter->file > 1)
3005 mpctx->stop_play = PT_PREV_SRC;
3007 break;
3009 case MP_CMD_SUB_STEP:
3010 if (sh_video) {
3011 int movement = cmd->args[0].v.i;
3012 step_sub(mpctx->subdata, mpctx->video_pts, movement);
3013 #ifdef CONFIG_ASS
3014 if (mpctx->osd->ass_track)
3015 sub_delay +=
3016 ass_step_sub(mpctx->osd->ass_track,
3017 (mpctx->video_pts +
3018 sub_delay) * 1000 + .5, movement) / 1000.;
3019 #endif
3020 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
3021 "Sub delay: %d ms", ROUND(sub_delay * 1000));
3023 break;
3025 case MP_CMD_SUB_LOG:
3026 log_sub(mpctx);
3027 break;
3029 case MP_CMD_OSD: {
3030 int v = cmd->args[0].v.i;
3031 int max = (opts->term_osd
3032 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
3033 if (opts->osd_level > max)
3034 opts->osd_level = max;
3035 if (v < 0)
3036 opts->osd_level = (opts->osd_level + 1) % (max + 1);
3037 else
3038 opts->osd_level = v > max ? max : v;
3039 /* Show OSD state when disabled, but not when an explicit
3040 argument is given to the OSD command, i.e. in slave mode. */
3041 if (v == -1 && opts->osd_level <= 1)
3042 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
3043 "OSD: %s",
3044 opts->osd_level ? mp_gtext("enabled") :
3045 mp_gtext("disabled"));
3046 else
3047 rm_osd_msg(OSD_MSG_OSD_STATUS);
3048 break;
3051 case MP_CMD_OSD_SHOW_TEXT:
3052 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
3053 (cmd->args[1].v.i <
3054 0 ? osd_duration : cmd->args[1].v.i),
3055 "%s", cmd->args[0].v.s);
3056 break;
3058 case MP_CMD_OSD_SHOW_PROPERTY_TEXT: {
3059 char *txt = m_properties_expand_string(mp_properties,
3060 cmd->args[0].v.s,
3061 mpctx);
3062 // if no argument supplied use default osd_duration, else <arg> ms.
3063 if (txt) {
3064 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
3065 (cmd->args[1].v.i <
3066 0 ? osd_duration : cmd->args[1].v.i),
3067 "%s", txt);
3068 free(txt);
3070 break;
3073 case MP_CMD_LOADFILE: {
3074 play_tree_t *e = play_tree_new();
3075 play_tree_add_file(e, cmd->args[0].v.s);
3077 if (cmd->args[1].v.i) // append
3078 play_tree_append_entry(mpctx->playtree->child, e);
3079 else {
3080 // Go back to the starting point.
3081 while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1)
3082 != PLAY_TREE_ITER_END)
3083 /* NOP */;
3084 play_tree_free_list(mpctx->playtree->child, 1);
3085 play_tree_set_child(mpctx->playtree, e);
3086 pt_iter_goto_head(mpctx->playtree_iter);
3087 mpctx->stop_play = PT_NEXT_SRC;
3089 break;
3092 case MP_CMD_LOADLIST: {
3093 play_tree_t *e = parse_playlist_file(mpctx->mconfig,
3094 bstr(cmd->args[0].v.s));
3095 if (!e)
3096 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
3097 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
3098 else {
3099 if (cmd->args[1].v.i) // append
3100 play_tree_append_entry(mpctx->playtree->child, e);
3101 else {
3102 // Go back to the starting point.
3103 while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1)
3104 != PLAY_TREE_ITER_END)
3105 /* NOP */;
3106 play_tree_free_list(mpctx->playtree->child, 1);
3107 play_tree_set_child(mpctx->playtree, e);
3108 pt_iter_goto_head(mpctx->playtree_iter);
3109 mpctx->stop_play = PT_NEXT_SRC;
3112 break;
3115 case MP_CMD_STOP:
3116 // Go back to the starting point.
3117 while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1) !=
3118 PLAY_TREE_ITER_END)
3119 /* NOP */;
3120 mpctx->stop_play = PT_STOP;
3121 break;
3123 case MP_CMD_OSD_SHOW_PROGRESSION: {
3124 int len = get_time_length(mpctx);
3125 int pts = get_current_time(mpctx);
3126 set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3127 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3128 "%c %02d:%02d:%02d / %02d:%02d:%02d",
3129 mpctx->osd_function, pts / 3600, (pts / 60) % 60, pts % 60,
3130 len / 3600, (len / 60) % 60, len % 60);
3131 break;
3134 #ifdef CONFIG_RADIO
3135 case MP_CMD_RADIO_STEP_CHANNEL:
3136 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3137 int v = cmd->args[0].v.i;
3138 if (v > 0)
3139 radio_step_channel(mpctx->demuxer->stream,
3140 RADIO_CHANNEL_HIGHER);
3141 else
3142 radio_step_channel(mpctx->demuxer->stream,
3143 RADIO_CHANNEL_LOWER);
3144 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3145 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3146 "Channel: %s",
3147 radio_get_channel_name(mpctx->demuxer->stream));
3150 break;
3152 case MP_CMD_RADIO_SET_CHANNEL:
3153 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3154 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3155 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3156 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3157 "Channel: %s",
3158 radio_get_channel_name(mpctx->demuxer->stream));
3161 break;
3163 case MP_CMD_RADIO_SET_FREQ:
3164 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3165 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3166 break;
3168 case MP_CMD_RADIO_STEP_FREQ:
3169 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3170 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3171 break;
3172 #endif
3174 #ifdef CONFIG_TV
3175 case MP_CMD_TV_START_SCAN:
3176 if (mpctx->file_format == DEMUXER_TYPE_TV)
3177 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv), 1);
3178 break;
3179 case MP_CMD_TV_SET_FREQ:
3180 if (mpctx->file_format == DEMUXER_TYPE_TV)
3181 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3182 cmd->args[0].v.f * 16.0);
3183 #ifdef CONFIG_PVR
3184 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3185 pvr_set_freq(mpctx->stream, ROUND(cmd->args[0].v.f));
3186 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3187 pvr_get_current_channelname(mpctx->stream),
3188 pvr_get_current_stationname(mpctx->stream));
3190 #endif /* CONFIG_PVR */
3191 break;
3193 case MP_CMD_TV_STEP_FREQ:
3194 if (mpctx->file_format == DEMUXER_TYPE_TV)
3195 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3196 cmd->args[0].v.f * 16.0);
3197 #ifdef CONFIG_PVR
3198 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3199 pvr_force_freq_step(mpctx->stream, ROUND(cmd->args[0].v.f));
3200 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3201 pvr_get_current_channelname(mpctx->stream),
3202 pvr_get_current_frequency(mpctx->stream));
3204 #endif /* CONFIG_PVR */
3205 break;
3207 case MP_CMD_TV_SET_NORM:
3208 if (mpctx->file_format == DEMUXER_TYPE_TV)
3209 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3210 cmd->args[0].v.s);
3211 break;
3213 case MP_CMD_TV_STEP_CHANNEL:
3214 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3215 int v = cmd->args[0].v.i;
3216 if (v > 0) {
3217 tv_step_channel((tvi_handle_t *) (mpctx->
3218 demuxer->priv),
3219 TV_CHANNEL_HIGHER);
3220 } else {
3221 tv_step_channel((tvi_handle_t *) (mpctx->
3222 demuxer->priv),
3223 TV_CHANNEL_LOWER);
3225 if (tv_channel_list) {
3226 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3227 "Channel: %s", tv_channel_current->name);
3228 //vo_osd_changed(OSDTYPE_SUBTITLE);
3231 #ifdef CONFIG_PVR
3232 else if (mpctx->stream &&
3233 mpctx->stream->type == STREAMTYPE_PVR) {
3234 pvr_set_channel_step(mpctx->stream, cmd->args[0].v.i);
3235 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3236 pvr_get_current_channelname(mpctx->stream),
3237 pvr_get_current_stationname(mpctx->stream));
3239 #endif /* CONFIG_PVR */
3240 #ifdef CONFIG_DVBIN
3241 if (mpctx->stream->type == STREAMTYPE_DVB) {
3242 int dir;
3243 int v = cmd->args[0].v.i;
3245 mpctx->last_dvb_step = v;
3246 if (v > 0)
3247 dir = DVB_CHANNEL_HIGHER;
3248 else
3249 dir = DVB_CHANNEL_LOWER;
3252 if (dvb_step_channel(mpctx->stream, dir)) {
3253 mpctx->stop_play = PT_NEXT_ENTRY;
3254 mpctx->dvbin_reopen = 1;
3257 #endif /* CONFIG_DVBIN */
3258 break;
3260 case MP_CMD_TV_SET_CHANNEL:
3261 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3262 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3263 cmd->args[0].v.s);
3264 if (tv_channel_list) {
3265 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3266 "Channel: %s", tv_channel_current->name);
3267 //vo_osd_changed(OSDTYPE_SUBTITLE);
3270 #ifdef CONFIG_PVR
3271 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3272 pvr_set_channel(mpctx->stream, cmd->args[0].v.s);
3273 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3274 pvr_get_current_channelname(mpctx->stream),
3275 pvr_get_current_stationname(mpctx->stream));
3277 #endif /* CONFIG_PVR */
3278 break;
3280 #ifdef CONFIG_DVBIN
3281 case MP_CMD_DVB_SET_CHANNEL:
3282 if (mpctx->stream->type == STREAMTYPE_DVB) {
3283 mpctx->last_dvb_step = 1;
3285 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3286 cmd->args[0].v.i)) {
3287 mpctx->stop_play = PT_NEXT_ENTRY;
3288 mpctx->dvbin_reopen = 1;
3291 break;
3292 #endif /* CONFIG_DVBIN */
3294 case MP_CMD_TV_LAST_CHANNEL:
3295 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3296 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3297 if (tv_channel_list) {
3298 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3299 "Channel: %s", tv_channel_current->name);
3300 //vo_osd_changed(OSDTYPE_SUBTITLE);
3303 #ifdef CONFIG_PVR
3304 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3305 pvr_set_lastchannel(mpctx->stream);
3306 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3307 pvr_get_current_channelname(mpctx->stream),
3308 pvr_get_current_stationname(mpctx->stream));
3310 #endif /* CONFIG_PVR */
3311 break;
3313 case MP_CMD_TV_STEP_NORM:
3314 if (mpctx->file_format == DEMUXER_TYPE_TV)
3315 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3316 break;
3318 case MP_CMD_TV_STEP_CHANNEL_LIST:
3319 if (mpctx->file_format == DEMUXER_TYPE_TV)
3320 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3321 break;
3322 #endif /* CONFIG_TV */
3323 case MP_CMD_TV_TELETEXT_ADD_DEC:
3324 if (mpctx->demuxer->teletext)
3325 teletext_control(mpctx->demuxer->teletext, TV_VBI_CONTROL_ADD_DEC,
3326 &(cmd->args[0].v.s));
3327 break;
3328 case MP_CMD_TV_TELETEXT_GO_LINK:
3329 if (mpctx->demuxer->teletext)
3330 teletext_control(mpctx->demuxer->teletext, TV_VBI_CONTROL_GO_LINK,
3331 &(cmd->args[0].v.i));
3332 break;
3334 case MP_CMD_SUB_LOAD:
3335 if (sh_video) {
3336 int n = mpctx->set_of_sub_size;
3337 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3338 if (n != mpctx->set_of_sub_size) {
3339 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3340 ++mpctx->global_sub_size;
3343 break;
3345 case MP_CMD_SUB_REMOVE:
3346 if (sh_video) {
3347 int v = cmd->args[0].v.i;
3348 if (v < 0)
3349 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3350 else if (v < mpctx->set_of_sub_size)
3351 remove_subtitle_range(mpctx, v, 1);
3353 break;
3355 case MP_CMD_GET_SUB_VISIBILITY:
3356 if (sh_video) {
3357 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3358 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3360 break;
3362 case MP_CMD_SCREENSHOT:
3363 screenshot_request(mpctx, cmd->args[0].v.i, cmd->args[1].v.i);
3364 break;
3366 case MP_CMD_VF_CHANGE_RECTANGLE:
3367 if (!sh_video)
3368 break;
3369 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3370 break;
3372 case MP_CMD_GET_TIME_LENGTH:
3373 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3374 get_time_length(mpctx));
3375 break;
3377 case MP_CMD_GET_FILENAME: {
3378 char *inf = get_metadata(mpctx, META_NAME);
3379 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n", inf);
3380 talloc_free(inf);
3381 break;
3384 case MP_CMD_GET_VIDEO_CODEC: {
3385 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3386 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3387 talloc_free(inf);
3388 break;
3391 case MP_CMD_GET_VIDEO_BITRATE: {
3392 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3393 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3394 talloc_free(inf);
3395 break;
3398 case MP_CMD_GET_VIDEO_RESOLUTION: {
3399 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3400 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3401 talloc_free(inf);
3402 break;
3405 case MP_CMD_GET_AUDIO_CODEC: {
3406 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3407 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3408 talloc_free(inf);
3409 break;
3412 case MP_CMD_GET_AUDIO_BITRATE: {
3413 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3414 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3415 talloc_free(inf);
3416 break;
3419 case MP_CMD_GET_AUDIO_SAMPLES: {
3420 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3421 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3422 talloc_free(inf);
3423 break;
3426 case MP_CMD_GET_META_TITLE: {
3427 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3428 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3429 talloc_free(inf);
3430 break;
3433 case MP_CMD_GET_META_ARTIST: {
3434 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3435 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3436 talloc_free(inf);
3437 break;
3440 case MP_CMD_GET_META_ALBUM: {
3441 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3442 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3443 talloc_free(inf);
3444 break;
3447 case MP_CMD_GET_META_YEAR: {
3448 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3449 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3450 talloc_free(inf);
3451 break;
3454 case MP_CMD_GET_META_COMMENT: {
3455 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3456 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3457 talloc_free(inf);
3458 break;
3461 case MP_CMD_GET_META_TRACK: {
3462 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3463 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3464 talloc_free(inf);
3465 break;
3468 case MP_CMD_GET_META_GENRE: {
3469 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3470 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3471 talloc_free(inf);
3472 break;
3475 case MP_CMD_GET_VO_FULLSCREEN:
3476 if (mpctx->video_out && mpctx->video_out->config_ok)
3477 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3478 break;
3480 case MP_CMD_GET_PERCENT_POS:
3481 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3482 get_percent_pos(mpctx));
3483 break;
3485 case MP_CMD_GET_TIME_POS: {
3486 float pos = get_current_time(mpctx);
3487 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3488 break;
3491 case MP_CMD_RUN:
3492 #ifndef __MINGW32__
3493 if (!fork()) {
3494 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3495 exit(0);
3497 #endif
3498 break;
3500 case MP_CMD_KEYDOWN_EVENTS:
3501 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3502 break;
3504 case MP_CMD_SET_MOUSE_POS: {
3505 int pointer_x, pointer_y;
3506 double dx, dy;
3507 pointer_x = cmd->args[0].v.i;
3508 pointer_y = cmd->args[1].v.i;
3509 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3510 #ifdef CONFIG_DVDNAV
3511 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3512 && dx > 0.0 && dy > 0.0) {
3513 int button = -1;
3514 pointer_x = (int) (dx * (double) sh_video->disp_w);
3515 pointer_y = (int) (dy * (double) sh_video->disp_h);
3516 mp_dvdnav_update_mouse_pos(mpctx->stream,
3517 pointer_x, pointer_y, &button);
3518 if (opts->osd_level > 1 && button > 0)
3519 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3520 "Selected button number %d", button);
3522 #endif
3523 break;
3526 #ifdef CONFIG_DVDNAV
3527 case MP_CMD_DVDNAV: {
3528 int button = -1;
3529 int i;
3530 enum mp_command_type command = 0;
3531 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3532 break;
3534 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3535 if (cmd->args[0].v.s &&
3536 !strcasecmp(cmd->args[0].v.s,
3537 mp_dvdnav_bindings[i].name))
3538 command = mp_dvdnav_bindings[i].cmd;
3540 mp_dvdnav_handle_input(mpctx->stream, command, &button);
3541 if (opts->osd_level > 1 && button > 0)
3542 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3543 "Selected button number %d", button);
3544 break;
3547 case MP_CMD_SWITCH_TITLE:
3548 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3549 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3550 break;
3552 #endif
3554 case MP_CMD_AF_SWITCH:
3555 if (sh_audio) {
3556 af_uninit(mpctx->mixer.afilter);
3557 af_init(mpctx->mixer.afilter);
3559 case MP_CMD_AF_ADD:
3560 case MP_CMD_AF_DEL: {
3561 if (!sh_audio)
3562 break;
3563 char *af_args = strdup(cmd->args[0].v.s);
3564 char *af_commands = af_args;
3565 char *af_command;
3566 af_instance_t *af;
3567 while ((af_command = strsep(&af_commands, ",")) != NULL) {
3568 if (cmd->id == MP_CMD_AF_DEL) {
3569 af = af_get(mpctx->mixer.afilter, af_command);
3570 if (af != NULL)
3571 af_remove(mpctx->mixer.afilter, af);
3572 } else
3573 af_add(mpctx->mixer.afilter, af_command);
3575 reinit_audio_chain(mpctx);
3576 free(af_args);
3577 break;
3579 case MP_CMD_AF_CLR:
3580 if (!sh_audio)
3581 break;
3582 af_uninit(mpctx->mixer.afilter);
3583 af_init(mpctx->mixer.afilter);
3584 reinit_audio_chain(mpctx);
3585 break;
3586 case MP_CMD_AF_CMDLINE:
3587 if (sh_audio) {
3588 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3589 if (!af) {
3590 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3591 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3592 break;
3594 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3595 af_reinit(sh_audio->afilter, af);
3597 break;
3599 default:
3600 mp_msg(MSGT_CPLAYER, MSGL_V,
3601 "Received unknown cmd %s\n", cmd->name);
3604 old_pause_hack:
3605 switch (cmd->pausing) {
3606 case 1: // "pausing"
3607 pause_player(mpctx);
3608 break;
3609 case 3: // "pausing_toggle"
3610 if (mpctx->paused)
3611 unpause_player(mpctx);
3612 else
3613 pause_player(mpctx);
3614 break;