mixer: fix lowering hw volume while muted
[mplayer.git] / command.c
blob0f13ed691cd6d72ae4ddc25f3c3507aab5d129fa
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdlib.h>
20 #include <inttypes.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <stdbool.h>
25 #include "config.h"
26 #include "talloc.h"
27 #include "command.h"
28 #include "input/input.h"
29 #include "stream/stream.h"
30 #include "libmpdemux/demuxer.h"
31 #include "libmpdemux/stheader.h"
32 #include "codec-cfg.h"
33 #include "mplayer.h"
34 #include "sub/sub.h"
35 #include "sub/dec_sub.h"
36 #include "m_option.h"
37 #include "m_property.h"
38 #include "m_config.h"
39 #include "metadata.h"
40 #include "libmpcodecs/vf.h"
41 #include "libmpcodecs/vd.h"
42 #include "mp_osd.h"
43 #include "libvo/video_out.h"
44 #include "libvo/csputils.h"
45 #include "playtree.h"
46 #include "libao2/audio_out.h"
47 #include "mpcommon.h"
48 #include "mixer.h"
49 #include "libmpcodecs/dec_video.h"
50 #include "libmpcodecs/dec_audio.h"
51 #include "libmpcodecs/dec_teletext.h"
52 #include "osdep/strsep.h"
53 #include "sub/vobsub.h"
54 #include "sub/spudec.h"
55 #include "path.h"
56 #include "sub/ass_mp.h"
57 #include "stream/tv.h"
58 #include "stream/stream_radio.h"
59 #include "stream/pvr.h"
60 #ifdef CONFIG_DVBIN
61 #include "stream/dvbin.h"
62 #endif
63 #ifdef CONFIG_DVDREAD
64 #include "stream/stream_dvd.h"
65 #endif
66 #include "stream/stream_dvdnav.h"
67 #include "m_struct.h"
68 #include "screenshot.h"
70 #include "mp_core.h"
71 #include "mp_fifo.h"
72 #include "libavutil/avstring.h"
74 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
75 double *dx, double *dy)
77 struct MPOpts *opts = &mpctx->opts;
78 struct vo *vo = mpctx->video_out;
79 //remove the borders, if any, and rescale to the range [0,1],[0,1]
80 if (vo_fs) { //we are in full-screen mode
81 if (opts->vo_screenwidth > vo->dwidth)
82 // there are borders along the x axis
83 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
84 if (opts->vo_screenheight > vo->dheight)
85 // there are borders along the y axis (usual way)
86 iy -= (opts->vo_screenheight - vo->dheight) / 2;
88 if (ix < 0 || ix > vo->dwidth) {
89 *dx = *dy = -1.0;
90 return;
91 } //we are on one of the borders
92 if (iy < 0 || iy > vo->dheight) {
93 *dx = *dy = -1.0;
94 return;
95 } //we are on one of the borders
98 *dx = (double) ix / (double) vo->dwidth;
99 *dy = (double) iy / (double) vo->dheight;
101 mp_msg(MSGT_CPLAYER, MSGL_V,
102 "\r\nrescaled coordinates: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
103 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
104 vo->dheight, vo_fs);
107 static int sub_pos_by_source(MPContext *mpctx, int src)
109 int i, cnt = 0;
110 if (src >= SUB_SOURCES || mpctx->sub_counts[src] == 0)
111 return -1;
112 for (i = 0; i < src; i++)
113 cnt += mpctx->sub_counts[i];
114 return cnt;
117 static int sub_source_and_index_by_pos(MPContext *mpctx, int *pos)
119 int start = 0;
120 int i;
121 for (i = 0; i < SUB_SOURCES; i++) {
122 int cnt = mpctx->sub_counts[i];
123 if (*pos >= start && *pos < start + cnt) {
124 *pos -= start;
125 return i;
127 start += cnt;
129 *pos = -1;
130 return -1;
133 static int sub_source_by_pos(MPContext *mpctx, int pos)
135 return sub_source_and_index_by_pos(mpctx, &pos);
138 static int sub_source_pos(MPContext *mpctx)
140 int pos = mpctx->global_sub_pos;
141 sub_source_and_index_by_pos(mpctx, &pos);
142 return pos;
145 static int sub_source(MPContext *mpctx)
147 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
150 static void update_global_sub_size(MPContext *mpctx)
152 struct MPOpts *opts = &mpctx->opts;
153 int i;
154 int cnt = 0;
156 // update number of demuxer sub streams
157 for (i = 0; i < MAX_S_STREAMS; i++)
158 if (mpctx->d_sub->demuxer->s_streams[i])
159 cnt++;
160 if (cnt > mpctx->sub_counts[SUB_SOURCE_DEMUX])
161 mpctx->sub_counts[SUB_SOURCE_DEMUX] = cnt;
163 // update global size
164 mpctx->global_sub_size = 0;
165 for (i = 0; i < SUB_SOURCES; i++)
166 mpctx->global_sub_size += mpctx->sub_counts[i];
168 // update global_sub_pos if we auto-detected a demuxer sub
169 if (mpctx->global_sub_pos == -1) {
170 int sub_id = -1;
171 if (mpctx->demuxer->sub)
172 sub_id = mpctx->demuxer->sub->id;
173 if (sub_id < 0)
174 sub_id = opts->sub_id;
175 if (sub_id >= 0 && sub_id < mpctx->sub_counts[SUB_SOURCE_DEMUX])
176 mpctx->global_sub_pos = sub_pos_by_source(mpctx, SUB_SOURCE_DEMUX) +
177 sub_id;
182 * \brief Log the currently displayed subtitle to a file
184 * Logs the current or last displayed subtitle together with filename
185 * and time information to ~/.mplayer/subtitle_log
187 * Intended purpose is to allow convenient marking of bogus subtitles
188 * which need to be fixed while watching the movie.
191 static void log_sub(struct MPContext *mpctx)
193 char *fname;
194 FILE *f;
195 int i;
196 struct subtitle *vo_sub_last = mpctx->vo_sub_last;
198 if (mpctx->subdata == NULL || vo_sub_last == NULL)
199 return;
200 fname = get_path("subtitle_log");
201 f = fopen(fname, "a");
202 if (!f)
203 return;
204 fprintf(f, "----------------------------------------------------------\n");
205 if (mpctx->subdata->sub_uses_time) {
206 fprintf(f,
207 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
208 mpctx->filename, vo_sub_last->start / 360000,
209 (vo_sub_last->start / 6000) % 60,
210 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
211 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
212 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
213 } else {
214 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
215 vo_sub_last->start, vo_sub_last->end);
217 for (i = 0; i < vo_sub_last->lines; i++)
218 fprintf(f, "%s\n", vo_sub_last->text[i]);
219 fclose(f);
223 static int mp_property_generic_option(struct m_option *prop, int action,
224 void *arg, MPContext *mpctx)
226 char *optname = prop->priv;
227 const struct m_option *opt = m_config_get_option(mpctx->mconfig,
228 bstr(optname));
229 void *valptr = m_option_get_ptr(opt, &mpctx->opts);
231 switch (action) {
232 case M_PROPERTY_GET_TYPE:
233 *(const struct m_option **)arg = opt;
234 return M_PROPERTY_OK;
235 case M_PROPERTY_GET:
236 m_option_copy(opt, arg, valptr);
237 return M_PROPERTY_OK;
238 case M_PROPERTY_SET:
239 m_option_copy(opt, valptr, arg);
240 return M_PROPERTY_OK;
241 case M_PROPERTY_STEP:
242 if (opt->type == &m_option_type_choice) {
243 int v = *(int *) valptr;
244 int best = v;
245 struct m_opt_choice_alternatives *alt;
246 for (alt = opt->priv; alt->name; alt++)
247 if ((unsigned) alt->value - v - 1 < (unsigned) best - v - 1)
248 best = alt->value;
249 *(int *) valptr = best;
250 return M_PROPERTY_OK;
252 break;
254 return M_PROPERTY_NOT_IMPLEMENTED;
257 /// OSD level (RW)
258 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
259 MPContext *mpctx)
261 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
264 /// Loop (RW)
265 static int mp_property_loop(m_option_t *prop, int action, void *arg,
266 MPContext *mpctx)
268 struct MPOpts *opts = &mpctx->opts;
269 switch (action) {
270 case M_PROPERTY_PRINT:
271 if (!arg)
272 return M_PROPERTY_ERROR;
273 if (opts->loop_times < 0)
274 *(char **)arg = talloc_strdup(NULL, "off");
275 else if (opts->loop_times == 0)
276 *(char **)arg = talloc_strdup(NULL, "inf");
277 else
278 break;
279 return M_PROPERTY_OK;
281 return m_property_int_range(prop, action, arg, &opts->loop_times);
284 /// Playback speed (RW)
285 static int mp_property_playback_speed(m_option_t *prop, int action,
286 void *arg, MPContext *mpctx)
288 struct MPOpts *opts = &mpctx->opts;
289 double orig_speed = opts->playback_speed;
290 switch (action) {
291 case M_PROPERTY_SET:
292 if (!arg)
293 return M_PROPERTY_ERROR;
294 opts->playback_speed = *(float *) arg;
295 goto set;
296 case M_PROPERTY_STEP:
297 opts->playback_speed += (arg ? *(float *) arg : 0.1);
298 set:
299 M_PROPERTY_CLAMP(prop, opts->playback_speed);
300 if (opts->playback_speed == orig_speed)
301 return M_PROPERTY_OK;
302 // Adjust time until next frame flip for nosound mode
303 mpctx->time_frame *= orig_speed / opts->playback_speed;
304 if (mpctx->sh_audio) {
305 double a = ao_get_delay(mpctx->ao);
306 mpctx->delay += (opts->playback_speed - orig_speed) * a;
308 reinit_audio_chain(mpctx);
309 return M_PROPERTY_OK;
311 return m_property_float_range(prop, action, arg, &opts->playback_speed);
314 /// filename with path (RO)
315 static int mp_property_path(m_option_t *prop, int action, void *arg,
316 MPContext *mpctx)
318 return m_property_string_ro(prop, action, arg, mpctx->filename);
321 /// filename without path (RO)
322 static int mp_property_filename(m_option_t *prop, int action, void *arg,
323 MPContext *mpctx)
325 char *f;
326 if (!mpctx->filename)
327 return M_PROPERTY_UNAVAILABLE;
328 f = (char *)mp_basename(mpctx->filename);
329 if (!*f)
330 f = mpctx->filename;
331 return m_property_string_ro(prop, action, arg, f);
334 /// Demuxer name (RO)
335 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
336 MPContext *mpctx)
338 if (!mpctx->demuxer)
339 return M_PROPERTY_UNAVAILABLE;
340 return m_property_string_ro(prop, action, arg,
341 (char *) mpctx->demuxer->desc->name);
344 /// Position in the stream (RW)
345 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
346 MPContext *mpctx)
348 if (!mpctx->demuxer || !mpctx->demuxer->stream)
349 return M_PROPERTY_UNAVAILABLE;
350 if (!arg)
351 return M_PROPERTY_ERROR;
352 switch (action) {
353 case M_PROPERTY_GET:
354 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
355 return M_PROPERTY_OK;
356 case M_PROPERTY_SET:
357 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
358 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
359 return M_PROPERTY_OK;
361 return M_PROPERTY_NOT_IMPLEMENTED;
364 /// Stream start offset (RO)
365 static int mp_property_stream_start(m_option_t *prop, int action,
366 void *arg, MPContext *mpctx)
368 if (!mpctx->demuxer || !mpctx->demuxer->stream)
369 return M_PROPERTY_UNAVAILABLE;
370 switch (action) {
371 case M_PROPERTY_GET:
372 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
373 return M_PROPERTY_OK;
375 return M_PROPERTY_NOT_IMPLEMENTED;
378 /// Stream end offset (RO)
379 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
380 MPContext *mpctx)
382 if (!mpctx->demuxer || !mpctx->demuxer->stream)
383 return M_PROPERTY_UNAVAILABLE;
384 switch (action) {
385 case M_PROPERTY_GET:
386 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
387 return M_PROPERTY_OK;
389 return M_PROPERTY_NOT_IMPLEMENTED;
392 /// Stream length (RO)
393 static int mp_property_stream_length(m_option_t *prop, int action,
394 void *arg, MPContext *mpctx)
396 if (!mpctx->demuxer || !mpctx->demuxer->stream)
397 return M_PROPERTY_UNAVAILABLE;
398 switch (action) {
399 case M_PROPERTY_GET:
400 *(off_t *) arg =
401 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
402 return M_PROPERTY_OK;
404 return M_PROPERTY_NOT_IMPLEMENTED;
407 /// Current stream position in seconds (RO)
408 static int mp_property_stream_time_pos(m_option_t *prop, int action,
409 void *arg, MPContext *mpctx)
411 if (!mpctx->demuxer || mpctx->demuxer->stream_pts == MP_NOPTS_VALUE)
412 return M_PROPERTY_UNAVAILABLE;
414 return m_property_time_ro(prop, action, arg, mpctx->demuxer->stream_pts);
418 /// Media length in seconds (RO)
419 static int mp_property_length(m_option_t *prop, int action, void *arg,
420 MPContext *mpctx)
422 double len;
424 if (!mpctx->demuxer ||
425 !(int) (len = get_time_length(mpctx)))
426 return M_PROPERTY_UNAVAILABLE;
428 return m_property_time_ro(prop, action, arg, len);
431 /// Current position in percent (RW)
432 static int mp_property_percent_pos(m_option_t *prop, int action,
433 void *arg, MPContext *mpctx)
435 int pos;
437 if (!mpctx->demuxer)
438 return M_PROPERTY_UNAVAILABLE;
440 switch (action) {
441 case M_PROPERTY_SET:
442 if (!arg)
443 return M_PROPERTY_ERROR;
444 M_PROPERTY_CLAMP(prop, *(int *)arg);
445 pos = *(int *)arg;
446 break;
447 case M_PROPERTY_STEP:
448 pos = get_percent_pos(mpctx);
449 pos += (arg ? *(int *)arg : 10);
450 M_PROPERTY_CLAMP(prop, pos);
451 break;
452 default:
453 return m_property_int_ro(prop, action, arg, get_percent_pos(mpctx));
456 queue_seek(mpctx, MPSEEK_FACTOR, pos / 100.0, 0);
457 return M_PROPERTY_OK;
460 /// Current position in seconds (RW)
461 static int mp_property_time_pos(m_option_t *prop, int action,
462 void *arg, MPContext *mpctx)
464 if (!(mpctx->sh_video || mpctx->sh_audio))
465 return M_PROPERTY_UNAVAILABLE;
467 switch (action) {
468 case M_PROPERTY_SET:
469 if (!arg)
470 return M_PROPERTY_ERROR;
471 M_PROPERTY_CLAMP(prop, *(double *)arg);
472 queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double *)arg, 0);
473 return M_PROPERTY_OK;
474 case M_PROPERTY_STEP:
475 queue_seek(mpctx, MPSEEK_RELATIVE, (arg ? *(double *)arg : 10.0), 0);
476 return M_PROPERTY_OK;
478 return m_property_time_ro(prop, action, arg, get_current_time(mpctx));
481 /// Current chapter (RW)
482 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
483 MPContext *mpctx)
485 struct MPOpts *opts = &mpctx->opts;
486 int chapter = -1;
487 int step_all;
488 char *chapter_name = NULL;
490 if (mpctx->demuxer)
491 chapter = get_current_chapter(mpctx);
492 if (chapter < -1)
493 return M_PROPERTY_UNAVAILABLE;
495 switch (action) {
496 case M_PROPERTY_GET:
497 if (!arg)
498 return M_PROPERTY_ERROR;
499 *(int *) arg = chapter;
500 return M_PROPERTY_OK;
501 case M_PROPERTY_PRINT: {
502 if (!arg)
503 return M_PROPERTY_ERROR;
504 chapter_name = chapter_display_name(mpctx, chapter);
505 if (!chapter_name)
506 return M_PROPERTY_UNAVAILABLE;
507 *(char **) arg = chapter_name;
508 return M_PROPERTY_OK;
510 case M_PROPERTY_SET:
511 if (!arg)
512 return M_PROPERTY_ERROR;
513 M_PROPERTY_CLAMP(prop, *(int *)arg);
514 step_all = *(int *)arg - chapter;
515 chapter += step_all;
516 break;
517 case M_PROPERTY_STEP: {
518 step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1);
519 chapter += step_all;
520 if (chapter < 0)
521 chapter = 0;
522 break;
524 default:
525 return M_PROPERTY_NOT_IMPLEMENTED;
528 double next_pts = 0;
529 queue_seek(mpctx, MPSEEK_NONE, 0, 0);
530 chapter = seek_chapter(mpctx, chapter, &next_pts);
531 if (chapter >= 0) {
532 if (next_pts > -1.0)
533 queue_seek(mpctx, MPSEEK_ABSOLUTE, next_pts, 0);
534 chapter_name = chapter_display_name(mpctx, chapter);
535 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
536 "Chapter: %s", chapter_name);
537 } else if (step_all > 0)
538 queue_seek(mpctx, MPSEEK_RELATIVE, 1000000000, 0);
539 else
540 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
541 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
542 talloc_free(chapter_name);
543 return M_PROPERTY_OK;
546 /// Number of chapters in file
547 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
548 MPContext *mpctx)
550 if (!mpctx->demuxer)
551 return M_PROPERTY_UNAVAILABLE;
552 int count = get_chapter_count(mpctx);
553 return m_property_int_ro(prop, action, arg, count);
556 /// Current dvd angle (RW)
557 static int mp_property_angle(m_option_t *prop, int action, void *arg,
558 MPContext *mpctx)
560 struct MPOpts *opts = &mpctx->opts;
561 int angle = -1;
562 int angles;
564 if (mpctx->demuxer)
565 angle = demuxer_get_current_angle(mpctx->demuxer);
566 if (angle < 0)
567 return M_PROPERTY_UNAVAILABLE;
568 angles = demuxer_angles_count(mpctx->demuxer);
569 if (angles <= 1)
570 return M_PROPERTY_UNAVAILABLE;
572 switch (action) {
573 case M_PROPERTY_GET:
574 if (!arg)
575 return M_PROPERTY_ERROR;
576 *(int *) arg = angle;
577 return M_PROPERTY_OK;
578 case M_PROPERTY_PRINT: {
579 if (!arg)
580 return M_PROPERTY_ERROR;
581 *(char **) arg = talloc_asprintf(NULL, "%d/%d", angle, angles);
582 return M_PROPERTY_OK;
584 case M_PROPERTY_SET:
585 if (!arg)
586 return M_PROPERTY_ERROR;
587 angle = *(int *)arg;
588 M_PROPERTY_CLAMP(prop, angle);
589 break;
590 case M_PROPERTY_STEP: {
591 int step = 0;
592 if (arg)
593 step = *(int *)arg;
594 if (!step)
595 step = 1;
596 angle += step;
597 if (angle < 1) //cycle
598 angle = angles;
599 else if (angle > angles)
600 angle = 1;
601 break;
603 default:
604 return M_PROPERTY_NOT_IMPLEMENTED;
606 angle = demuxer_set_angle(mpctx->demuxer, angle);
607 if (angle >= 0) {
608 struct sh_video *sh_video = mpctx->demuxer->video->sh;
609 if (sh_video)
610 resync_video_stream(sh_video);
612 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
613 if (sh_audio)
614 resync_audio_stream(sh_audio);
617 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
618 "Angle: %d/%d", angle, angles);
619 return M_PROPERTY_OK;
622 /// Demuxer meta data
623 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
624 MPContext *mpctx)
626 m_property_action_t *ka;
627 char *meta;
628 static const m_option_t key_type =
630 "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL
632 if (!mpctx->demuxer)
633 return M_PROPERTY_UNAVAILABLE;
635 switch (action) {
636 case M_PROPERTY_GET:
637 if (!arg)
638 return M_PROPERTY_ERROR;
639 *(char ***)arg = mpctx->demuxer->info;
640 return M_PROPERTY_OK;
641 case M_PROPERTY_KEY_ACTION:
642 if (!arg)
643 return M_PROPERTY_ERROR;
644 ka = arg;
645 if (!(meta = demux_info_get(mpctx->demuxer, ka->key)))
646 return M_PROPERTY_UNKNOWN;
647 switch (ka->action) {
648 case M_PROPERTY_GET:
649 if (!ka->arg)
650 return M_PROPERTY_ERROR;
651 *(char **)ka->arg = meta;
652 return M_PROPERTY_OK;
653 case M_PROPERTY_GET_TYPE:
654 if (!ka->arg)
655 return M_PROPERTY_ERROR;
656 *(const m_option_t **)ka->arg = &key_type;
657 return M_PROPERTY_OK;
660 return M_PROPERTY_NOT_IMPLEMENTED;
663 static int mp_property_pause(m_option_t *prop, int action, void *arg,
664 void *ctx)
666 MPContext *mpctx = ctx;
668 switch (action) {
669 case M_PROPERTY_SET:
670 if (!arg)
671 return M_PROPERTY_ERROR;
672 if (mpctx->paused == (bool) * (int *)arg)
673 return M_PROPERTY_OK;
674 case M_PROPERTY_STEP:
675 if (mpctx->paused) {
676 unpause_player(mpctx);
677 } else {
678 pause_player(mpctx);
680 return M_PROPERTY_OK;
681 default:
682 return m_property_flag(prop, action, arg, &mpctx->paused);
687 /// Volume (RW)
688 static int mp_property_volume(m_option_t *prop, int action, void *arg,
689 MPContext *mpctx)
692 if (!mpctx->sh_audio)
693 return M_PROPERTY_UNAVAILABLE;
695 switch (action) {
696 case M_PROPERTY_GET:
697 if (!arg)
698 return M_PROPERTY_ERROR;
699 mixer_getbothvolume(&mpctx->mixer, arg);
700 return M_PROPERTY_OK;
701 case M_PROPERTY_PRINT: {
702 float vol;
703 if (!arg)
704 return M_PROPERTY_ERROR;
705 mixer_getbothvolume(&mpctx->mixer, &vol);
706 return m_property_float_range(prop, action, arg, &vol);
708 case M_PROPERTY_SET:
709 if (!arg)
710 return M_PROPERTY_ERROR;
711 M_PROPERTY_CLAMP(prop, *(float *) arg);
712 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
713 return M_PROPERTY_OK;
714 case M_PROPERTY_STEP:
715 if (arg && *(float *) arg <= 0)
716 mixer_decvolume(&mpctx->mixer);
717 else
718 mixer_incvolume(&mpctx->mixer);
719 return M_PROPERTY_OK;
720 default:
721 return M_PROPERTY_NOT_IMPLEMENTED;
725 /// Mute (RW)
726 static int mp_property_mute(m_option_t *prop, int action, void *arg,
727 MPContext *mpctx)
730 if (!mpctx->sh_audio)
731 return M_PROPERTY_UNAVAILABLE;
733 switch (action) {
734 case M_PROPERTY_SET:
735 if (!arg)
736 return M_PROPERTY_ERROR;
737 mixer_setmute(&mpctx->mixer, *(int *) arg);
738 return M_PROPERTY_OK;
739 case M_PROPERTY_STEP:
740 mixer_setmute(&mpctx->mixer, !mixer_getmute(&mpctx->mixer));
741 return M_PROPERTY_OK;
742 default:
743 return m_property_flag_ro(prop, action, arg,
744 mixer_getmute(&mpctx->mixer));
748 /// Audio delay (RW)
749 static int mp_property_audio_delay(m_option_t *prop, int action,
750 void *arg, MPContext *mpctx)
752 if (!(mpctx->sh_audio && mpctx->sh_video))
753 return M_PROPERTY_UNAVAILABLE;
754 switch (action) {
755 case M_PROPERTY_SET:
756 case M_PROPERTY_STEP: {
757 int ret;
758 float delay = audio_delay;
759 ret = m_property_delay(prop, action, arg, &audio_delay);
760 if (ret != M_PROPERTY_OK)
761 return ret;
762 if (mpctx->sh_audio)
763 mpctx->delay -= audio_delay - delay;
765 return M_PROPERTY_OK;
766 default:
767 return m_property_delay(prop, action, arg, &audio_delay);
771 /// Audio codec tag (RO)
772 static int mp_property_audio_format(m_option_t *prop, int action,
773 void *arg, MPContext *mpctx)
775 if (!mpctx->sh_audio)
776 return M_PROPERTY_UNAVAILABLE;
777 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
780 /// Audio codec name (RO)
781 static int mp_property_audio_codec(m_option_t *prop, int action,
782 void *arg, MPContext *mpctx)
784 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
785 return M_PROPERTY_UNAVAILABLE;
786 return m_property_string_ro(prop, action, arg,
787 mpctx->sh_audio->codec->name);
790 /// Audio bitrate (RO)
791 static int mp_property_audio_bitrate(m_option_t *prop, int action,
792 void *arg, MPContext *mpctx)
794 if (!mpctx->sh_audio)
795 return M_PROPERTY_UNAVAILABLE;
796 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
799 /// Samplerate (RO)
800 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
801 MPContext *mpctx)
803 if (!mpctx->sh_audio)
804 return M_PROPERTY_UNAVAILABLE;
805 switch (action) {
806 case M_PROPERTY_PRINT:
807 if (!arg)
808 return M_PROPERTY_ERROR;
809 *(char **)arg = talloc_asprintf(NULL, "%d kHz",
810 mpctx->sh_audio->samplerate / 1000);
811 return M_PROPERTY_OK;
813 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
816 /// Number of channels (RO)
817 static int mp_property_channels(m_option_t *prop, int action, void *arg,
818 MPContext *mpctx)
820 if (!mpctx->sh_audio)
821 return M_PROPERTY_UNAVAILABLE;
822 switch (action) {
823 case M_PROPERTY_PRINT:
824 if (!arg)
825 return M_PROPERTY_ERROR;
826 switch (mpctx->sh_audio->channels) {
827 case 1:
828 *(char **) arg = talloc_strdup(NULL, "mono");
829 break;
830 case 2:
831 *(char **) arg = talloc_strdup(NULL, "stereo");
832 break;
833 default:
834 *(char **) arg = talloc_asprintf(NULL, "%d channels",
835 mpctx->sh_audio->channels);
837 return M_PROPERTY_OK;
839 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
842 /// Balance (RW)
843 static int mp_property_balance(m_option_t *prop, int action, void *arg,
844 MPContext *mpctx)
846 float bal;
848 switch (action) {
849 case M_PROPERTY_GET:
850 if (!arg)
851 return M_PROPERTY_ERROR;
852 mixer_getbalance(&mpctx->mixer, arg);
853 return M_PROPERTY_OK;
854 case M_PROPERTY_PRINT: {
855 char **str = arg;
856 if (!arg)
857 return M_PROPERTY_ERROR;
858 mixer_getbalance(&mpctx->mixer, &bal);
859 if (bal == 0.f)
860 *str = talloc_strdup(NULL, "center");
861 else if (bal == -1.f)
862 *str = talloc_strdup(NULL, "left only");
863 else if (bal == 1.f)
864 *str = talloc_strdup(NULL, "right only");
865 else {
866 unsigned right = (bal + 1.f) / 2.f * 100.f;
867 *str = talloc_asprintf(NULL, "left %d%%, right %d%%",
868 100 - right, right);
870 return M_PROPERTY_OK;
872 case M_PROPERTY_STEP:
873 mixer_getbalance(&mpctx->mixer, &bal);
874 bal += (arg ? *(float *)arg : .1f);
875 M_PROPERTY_CLAMP(prop, bal);
876 mixer_setbalance(&mpctx->mixer, bal);
877 return M_PROPERTY_OK;
878 case M_PROPERTY_SET:
879 if (!arg)
880 return M_PROPERTY_ERROR;
881 M_PROPERTY_CLAMP(prop, *(float *)arg);
882 mixer_setbalance(&mpctx->mixer, *(float *)arg);
883 return M_PROPERTY_OK;
885 return M_PROPERTY_NOT_IMPLEMENTED;
888 /// Selected audio id (RW)
889 static int mp_property_audio(m_option_t *prop, int action, void *arg,
890 MPContext *mpctx)
892 int current_id, tmp;
893 if (!mpctx->demuxer || !mpctx->d_audio)
894 return M_PROPERTY_UNAVAILABLE;
895 struct sh_audio *sh = mpctx->sh_audio;
896 current_id = sh ? sh->aid : -2;
898 switch (action) {
899 case M_PROPERTY_GET:
900 if (!arg)
901 return M_PROPERTY_ERROR;
902 *(int *) arg = current_id;
903 return M_PROPERTY_OK;
904 case M_PROPERTY_PRINT:
905 if (!arg)
906 return M_PROPERTY_ERROR;
908 if (current_id < 0)
909 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
910 else if (sh && (sh->lang || sh->title)) {
911 char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
912 if (sh->title)
913 *(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
914 current_id, lang, sh->title);
915 else
916 *(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id,
917 lang);
918 } else {
919 char lang[40];
920 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
921 if (0) ;
922 #ifdef CONFIG_DVDREAD
923 else if (mpctx->stream->type == STREAMTYPE_DVD) {
924 int code = dvd_lang_from_aid(mpctx->stream, current_id);
925 if (code) {
926 lang[0] = code >> 8;
927 lang[1] = code;
928 lang[2] = 0;
931 #endif
933 #ifdef CONFIG_DVDNAV
934 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
935 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
936 #endif
937 *(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id, lang);
939 return M_PROPERTY_OK;
941 case M_PROPERTY_STEP:
942 case M_PROPERTY_SET:
943 if (action == M_PROPERTY_SET && arg)
944 tmp = *((int *) arg);
945 else
946 tmp = -1;
947 int new_id = demuxer_switch_audio(mpctx->d_audio->demuxer, tmp);
948 if (new_id != current_id)
949 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
950 if (new_id != current_id && new_id >= 0) {
951 sh_audio_t *sh2;
952 sh2 = mpctx->d_audio->demuxer->a_streams[mpctx->d_audio->id];
953 sh2->ds = mpctx->d_audio;
954 mpctx->sh_audio = sh2;
955 reinit_audio_chain(mpctx);
957 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
958 return M_PROPERTY_OK;
959 default:
960 return M_PROPERTY_NOT_IMPLEMENTED;
965 /// Selected video id (RW)
966 static int mp_property_video(m_option_t *prop, int action, void *arg,
967 MPContext *mpctx)
969 struct MPOpts *opts = &mpctx->opts;
970 int current_id, tmp;
971 if (!mpctx->demuxer || !mpctx->d_video)
972 return M_PROPERTY_UNAVAILABLE;
973 current_id = mpctx->sh_video ? mpctx->sh_video->vid : -2;
975 switch (action) {
976 case M_PROPERTY_GET:
977 if (!arg)
978 return M_PROPERTY_ERROR;
979 *(int *) arg = current_id;
980 return M_PROPERTY_OK;
981 case M_PROPERTY_PRINT:
982 if (!arg)
983 return M_PROPERTY_ERROR;
985 if (current_id < 0)
986 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
987 else {
988 *(char **) arg = talloc_asprintf(NULL, "(%d) %s", current_id,
989 mp_gtext("unknown"));
991 return M_PROPERTY_OK;
993 case M_PROPERTY_STEP:
994 case M_PROPERTY_SET:
995 if (action == M_PROPERTY_SET && arg)
996 tmp = *((int *) arg);
997 else
998 tmp = -1;
999 int new_id = demuxer_switch_video(mpctx->d_video->demuxer, tmp);
1000 if (new_id != current_id)
1001 uninit_player(mpctx, INITIALIZED_VCODEC |
1002 (opts->fixed_vo && new_id >= 0 ? 0 : INITIALIZED_VO));
1003 if (new_id != current_id && new_id >= 0) {
1004 sh_video_t *sh2;
1005 sh2 = mpctx->d_video->demuxer->v_streams[mpctx->d_video->id];
1006 sh2->ds = mpctx->d_video;
1007 mpctx->sh_video = sh2;
1008 reinit_video_chain(mpctx);
1010 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", new_id);
1011 return M_PROPERTY_OK;
1013 default:
1014 return M_PROPERTY_NOT_IMPLEMENTED;
1018 static int mp_property_program(m_option_t *prop, int action, void *arg,
1019 MPContext *mpctx)
1021 demux_program_t prog;
1023 switch (action) {
1024 case M_PROPERTY_STEP:
1025 case M_PROPERTY_SET:
1026 if (action == M_PROPERTY_SET && arg)
1027 prog.progid = *((int *) arg);
1028 else
1029 prog.progid = -1;
1030 if (demux_control(mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1031 &prog) == DEMUXER_CTRL_NOTIMPL)
1032 return M_PROPERTY_ERROR;
1034 if (prog.aid < 0 && prog.vid < 0) {
1035 mp_msg(MSGT_CPLAYER, MSGL_ERR,
1036 "Selected program contains no audio or video streams!\n");
1037 return M_PROPERTY_ERROR;
1039 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1040 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1041 return M_PROPERTY_OK;
1043 default:
1044 return M_PROPERTY_NOT_IMPLEMENTED;
1049 /// Fullscreen state (RW)
1050 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1051 MPContext *mpctx)
1054 if (!mpctx->video_out)
1055 return M_PROPERTY_UNAVAILABLE;
1057 switch (action) {
1058 case M_PROPERTY_SET:
1059 if (!arg)
1060 return M_PROPERTY_ERROR;
1061 M_PROPERTY_CLAMP(prop, *(int *) arg);
1062 if (vo_fs == !!*(int *) arg)
1063 return M_PROPERTY_OK;
1064 case M_PROPERTY_STEP:
1065 if (mpctx->video_out->config_ok)
1066 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1067 mpctx->opts.fullscreen = vo_fs;
1068 return M_PROPERTY_OK;
1069 default:
1070 return m_property_flag(prop, action, arg, &vo_fs);
1074 static int mp_property_deinterlace(m_option_t *prop, int action,
1075 void *arg, MPContext *mpctx)
1077 int deinterlace;
1078 vf_instance_t *vf;
1079 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1080 return M_PROPERTY_UNAVAILABLE;
1081 vf = mpctx->sh_video->vfilter;
1082 switch (action) {
1083 case M_PROPERTY_GET:
1084 if (!arg)
1085 return M_PROPERTY_ERROR;
1086 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1087 return M_PROPERTY_OK;
1088 case M_PROPERTY_SET:
1089 if (!arg)
1090 return M_PROPERTY_ERROR;
1091 M_PROPERTY_CLAMP(prop, *(int *) arg);
1092 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1093 return M_PROPERTY_OK;
1094 case M_PROPERTY_STEP:
1095 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1096 deinterlace = !deinterlace;
1097 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1098 return M_PROPERTY_OK;
1100 int value = 0;
1101 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1102 return m_property_flag_ro(prop, action, arg, value);
1105 static int colormatrix_property_helper(m_option_t *prop, int action,
1106 void *arg, MPContext *mpctx)
1108 int r = mp_property_generic_option(prop, action, arg, mpctx);
1109 // testing for an actual change is too much effort
1110 switch (action) {
1111 case M_PROPERTY_SET:
1112 case M_PROPERTY_STEP:
1113 if (mpctx->sh_video)
1114 set_video_colorspace(mpctx->sh_video);
1115 break;
1117 return r;
1120 static int mp_property_colormatrix(m_option_t *prop, int action, void *arg,
1121 MPContext *mpctx)
1123 struct MPOpts *opts = &mpctx->opts;
1124 switch (action) {
1125 case M_PROPERTY_PRINT:
1126 if (!arg)
1127 return M_PROPERTY_ERROR;
1128 struct mp_csp_details actual = { .format = -1 };
1129 char *req_csp = mp_csp_names[opts->requested_colorspace];
1130 char *real_csp = NULL;
1131 if (mpctx->sh_video) {
1132 struct vf_instance *vf = mpctx->sh_video->vfilter;
1133 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &actual) == true) {
1134 real_csp = mp_csp_names[actual.format];
1135 } else {
1136 real_csp = "Unknown";
1139 char *res;
1140 if (opts->requested_colorspace == MP_CSP_AUTO && real_csp) {
1141 // Caveat: doesn't handle the case when the autodetected colorspace
1142 // is different from the actual colorspace as used by the
1143 // VO - the OSD will display the VO colorspace without
1144 // indication that it doesn't match the requested colorspace.
1145 res = talloc_asprintf(NULL, "Auto (%s)", real_csp);
1146 } else if (opts->requested_colorspace == actual.format || !real_csp) {
1147 res = talloc_strdup(NULL, req_csp);
1148 } else
1149 res = talloc_asprintf(NULL, mp_gtext("%s, but %s used"),
1150 req_csp, real_csp);
1151 *(char **)arg = res;
1152 return M_PROPERTY_OK;
1153 default:;
1154 return colormatrix_property_helper(prop, action, arg, mpctx);
1158 static int levels_property_helper(int offset, m_option_t *prop, int action,
1159 void *arg, MPContext *mpctx)
1161 char *optname = prop->priv;
1162 const struct m_option *opt = m_config_get_option(mpctx->mconfig,
1163 bstr(optname));
1164 int *valptr = (int *)m_option_get_ptr(opt, &mpctx->opts);
1166 switch (action) {
1167 case M_PROPERTY_PRINT:
1168 if (!arg)
1169 return M_PROPERTY_ERROR;
1170 struct mp_csp_details actual = {0};
1171 int actual_level = -1;
1172 char *req_level = m_option_print(opt, valptr);
1173 char *real_level = NULL;
1174 if (mpctx->sh_video) {
1175 struct vf_instance *vf = mpctx->sh_video->vfilter;
1176 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &actual) == true) {
1177 actual_level = *(enum mp_csp_levels *)(((char *)&actual) + offset);
1178 real_level = m_option_print(opt, &actual_level);
1179 } else {
1180 real_level = talloc_strdup(NULL, "Unknown");
1183 char *res;
1184 if (*valptr == MP_CSP_LEVELS_AUTO && real_level) {
1185 res = talloc_asprintf(NULL, "Auto (%s)", real_level);
1186 } else if (*valptr == actual_level || !real_level) {
1187 res = talloc_strdup(NULL, real_level);
1188 } else
1189 res = talloc_asprintf(NULL, mp_gtext("%s, but %s used"),
1190 req_level, real_level);
1191 talloc_free(req_level);
1192 talloc_free(real_level);
1193 *(char **)arg = res;
1194 return M_PROPERTY_OK;
1195 default:;
1196 return colormatrix_property_helper(prop, action, arg, mpctx);
1200 static int mp_property_colormatrix_input_range(m_option_t *prop, int action,
1201 void *arg, MPContext *mpctx)
1203 return levels_property_helper(offsetof(struct mp_csp_details, levels_in),
1204 prop, action, arg, mpctx);
1207 static int mp_property_colormatrix_output_range(m_option_t *prop, int action,
1208 void *arg, MPContext *mpctx)
1210 return levels_property_helper(offsetof(struct mp_csp_details, levels_out),
1211 prop, action, arg, mpctx);
1214 static int mp_property_capture(m_option_t *prop, int action,
1215 void *arg, MPContext *mpctx)
1217 struct MPOpts *opts = &mpctx->opts;
1219 if (!mpctx->stream)
1220 return M_PROPERTY_UNAVAILABLE;
1222 if (!opts->capture_dump) {
1223 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1224 "Capturing not enabled (forgot -capture parameter?)\n");
1225 return M_PROPERTY_ERROR;
1228 int capturing = !!mpctx->stream->capture_file;
1230 int ret = m_property_flag(prop, action, arg, &capturing);
1231 if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
1232 if (capturing) {
1233 mpctx->stream->capture_file = fopen(opts->stream_dump_name, "wb");
1234 if (!mpctx->stream->capture_file) {
1235 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1236 "Error opening capture file: %s\n", strerror(errno));
1237 ret = M_PROPERTY_ERROR;
1239 } else {
1240 fclose(mpctx->stream->capture_file);
1241 mpctx->stream->capture_file = NULL;
1245 return ret;
1248 /// Panscan (RW)
1249 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1250 MPContext *mpctx)
1253 if (!mpctx->video_out
1254 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1255 return M_PROPERTY_UNAVAILABLE;
1257 switch (action) {
1258 case M_PROPERTY_SET:
1259 if (!arg)
1260 return M_PROPERTY_ERROR;
1261 M_PROPERTY_CLAMP(prop, *(float *) arg);
1262 vo_panscan = *(float *) arg;
1263 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1264 return M_PROPERTY_OK;
1265 case M_PROPERTY_STEP:
1266 vo_panscan += (arg ? *(float *) arg : 0.1);
1267 if (vo_panscan > 1)
1268 vo_panscan = 1;
1269 else if (vo_panscan < 0)
1270 vo_panscan = 0;
1271 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1272 return M_PROPERTY_OK;
1273 default:
1274 return m_property_float_range(prop, action, arg, &vo_panscan);
1278 /// Helper to set vo flags.
1279 /** \ingroup PropertyImplHelper
1281 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1282 int vo_ctrl, int *vo_var, MPContext *mpctx)
1285 if (!mpctx->video_out)
1286 return M_PROPERTY_UNAVAILABLE;
1288 switch (action) {
1289 case M_PROPERTY_SET:
1290 if (!arg)
1291 return M_PROPERTY_ERROR;
1292 M_PROPERTY_CLAMP(prop, *(int *) arg);
1293 if (*vo_var == !!*(int *) arg)
1294 return M_PROPERTY_OK;
1295 case M_PROPERTY_STEP:
1296 if (mpctx->video_out->config_ok)
1297 vo_control(mpctx->video_out, vo_ctrl, 0);
1298 return M_PROPERTY_OK;
1299 default:
1300 return m_property_flag(prop, action, arg, vo_var);
1304 /// Window always on top (RW)
1305 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1306 MPContext *mpctx)
1308 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1309 &mpctx->opts.vo_ontop, mpctx);
1312 /// Display in the root window (RW)
1313 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1314 MPContext *mpctx)
1316 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1317 &vo_rootwin, mpctx);
1320 /// Show window borders (RW)
1321 static int mp_property_border(m_option_t *prop, int action, void *arg,
1322 MPContext *mpctx)
1324 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1325 &vo_border, mpctx);
1328 /// Framedropping state (RW)
1329 static int mp_property_framedropping(m_option_t *prop, int action,
1330 void *arg, MPContext *mpctx)
1333 if (!mpctx->sh_video)
1334 return M_PROPERTY_UNAVAILABLE;
1336 switch (action) {
1337 case M_PROPERTY_PRINT:
1338 if (!arg)
1339 return M_PROPERTY_ERROR;
1340 *(char **) arg = talloc_strdup(NULL, frame_dropping == 1 ?
1341 mp_gtext("enabled") :
1342 (frame_dropping == 2 ? mp_gtext("hard") :
1343 mp_gtext("disabled")));
1344 return M_PROPERTY_OK;
1345 default:
1346 return m_property_choice(prop, action, arg, &frame_dropping);
1350 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1351 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1352 MPContext *mpctx)
1354 int *gamma = (int *)((char *)&mpctx->opts + prop->offset);
1355 int r, val;
1357 if (!mpctx->sh_video)
1358 return M_PROPERTY_UNAVAILABLE;
1360 if (gamma[0] == 1000) {
1361 gamma[0] = 0;
1362 get_video_colors(mpctx->sh_video, prop->name, gamma);
1365 switch (action) {
1366 case M_PROPERTY_SET:
1367 if (!arg)
1368 return M_PROPERTY_ERROR;
1369 M_PROPERTY_CLAMP(prop, *(int *) arg);
1370 *gamma = *(int *) arg;
1371 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1372 if (r <= 0)
1373 break;
1374 return r;
1375 case M_PROPERTY_GET:
1376 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1377 if (!arg)
1378 return M_PROPERTY_ERROR;
1379 *(int *)arg = val;
1380 return M_PROPERTY_OK;
1382 break;
1383 case M_PROPERTY_STEP:
1384 *gamma += (arg ? *(int *) arg : 1);
1385 M_PROPERTY_CLAMP(prop, *gamma);
1386 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1387 if (r <= 0)
1388 break;
1389 return r;
1390 default:
1391 return M_PROPERTY_NOT_IMPLEMENTED;
1394 #ifdef CONFIG_TV
1395 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1396 int l = strlen(prop->name);
1397 char tv_prop[3 + l + 1];
1398 sprintf(tv_prop, "tv_%s", prop->name);
1399 return mp_property_do(tv_prop, action, arg, mpctx);
1401 #endif
1403 return M_PROPERTY_UNAVAILABLE;
1406 /// VSync (RW)
1407 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1408 MPContext *mpctx)
1410 return m_property_flag(prop, action, arg, &vo_vsync);
1413 /// Video codec tag (RO)
1414 static int mp_property_video_format(m_option_t *prop, int action,
1415 void *arg, MPContext *mpctx)
1417 char *meta;
1418 if (!mpctx->sh_video)
1419 return M_PROPERTY_UNAVAILABLE;
1420 switch (action) {
1421 case M_PROPERTY_PRINT:
1422 if (!arg)
1423 return M_PROPERTY_ERROR;
1424 switch (mpctx->sh_video->format) {
1425 case 0x10000001:
1426 meta = talloc_strdup(NULL, "mpeg1");
1427 break;
1428 case 0x10000002:
1429 meta = talloc_strdup(NULL, "mpeg2");
1430 break;
1431 case 0x10000004:
1432 meta = talloc_strdup(NULL, "mpeg4");
1433 break;
1434 case 0x10000005:
1435 meta = talloc_strdup(NULL, "h264");
1436 break;
1437 default:
1438 if (mpctx->sh_video->format >= 0x20202020) {
1439 meta = talloc_asprintf(NULL, "%.4s",
1440 (char *) &mpctx->sh_video->format);
1441 } else
1442 meta = talloc_asprintf(NULL, "0x%08X", mpctx->sh_video->format);
1444 *(char **)arg = meta;
1445 return M_PROPERTY_OK;
1447 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1450 /// Video codec name (RO)
1451 static int mp_property_video_codec(m_option_t *prop, int action,
1452 void *arg, MPContext *mpctx)
1454 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1455 return M_PROPERTY_UNAVAILABLE;
1456 return m_property_string_ro(prop, action, arg,
1457 mpctx->sh_video->codec->name);
1461 /// Video bitrate (RO)
1462 static int mp_property_video_bitrate(m_option_t *prop, int action,
1463 void *arg, MPContext *mpctx)
1465 if (!mpctx->sh_video)
1466 return M_PROPERTY_UNAVAILABLE;
1467 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1470 /// Video display width (RO)
1471 static int mp_property_width(m_option_t *prop, int action, void *arg,
1472 MPContext *mpctx)
1474 if (!mpctx->sh_video)
1475 return M_PROPERTY_UNAVAILABLE;
1476 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1479 /// Video display height (RO)
1480 static int mp_property_height(m_option_t *prop, int action, void *arg,
1481 MPContext *mpctx)
1483 if (!mpctx->sh_video)
1484 return M_PROPERTY_UNAVAILABLE;
1485 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1488 /// Video fps (RO)
1489 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1490 MPContext *mpctx)
1492 if (!mpctx->sh_video)
1493 return M_PROPERTY_UNAVAILABLE;
1494 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1497 /// Video aspect (RO)
1498 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1499 MPContext *mpctx)
1501 if (!mpctx->sh_video)
1502 return M_PROPERTY_UNAVAILABLE;
1503 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1507 /// Text subtitle position (RW)
1508 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1509 MPContext *mpctx)
1511 switch (action) {
1512 case M_PROPERTY_SET:
1513 if (!arg)
1514 return M_PROPERTY_ERROR;
1515 case M_PROPERTY_STEP:
1516 vo_osd_changed(OSDTYPE_SUBTITLE);
1517 default:
1518 return m_property_int_range(prop, action, arg, &sub_pos);
1522 /// Selected subtitles (RW)
1523 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1524 MPContext *mpctx)
1526 struct MPOpts *opts = &mpctx->opts;
1527 demux_stream_t *const d_sub = mpctx->d_sub;
1528 int source = -1, reset_spu av_unused = 0; // used under CONFIG_DVDREAD
1529 int source_pos = -1;
1531 update_global_sub_size(mpctx);
1532 const int global_sub_size = mpctx->global_sub_size;
1534 if (global_sub_size <= 0)
1535 return M_PROPERTY_UNAVAILABLE;
1537 switch (action) {
1538 case M_PROPERTY_GET:
1539 if (!arg)
1540 return M_PROPERTY_ERROR;
1541 *(int *) arg = mpctx->global_sub_pos;
1542 return M_PROPERTY_OK;
1543 case M_PROPERTY_PRINT:
1544 if (!arg)
1545 return M_PROPERTY_ERROR;
1546 char *sub_name = NULL;
1547 if (mpctx->subdata)
1548 sub_name = mpctx->subdata->filename;
1549 if (sub_source(mpctx) == SUB_SOURCE_SUBS && mpctx->osd->sh_sub)
1550 sub_name = mpctx->osd->sh_sub->title;
1551 if (!sub_name && mpctx->subdata)
1552 sub_name = mpctx->subdata->filename;
1553 if (sub_name) {
1554 const char *tmp = mp_basename(sub_name);
1556 *(char **) arg = talloc_asprintf(NULL, "(%d) %s%s",
1557 mpctx->set_of_sub_pos + 1,
1558 strlen(tmp) < 20 ? "" : "...",
1559 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1560 return M_PROPERTY_OK;
1562 #ifdef CONFIG_DVDNAV
1563 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1564 if (vo_spudec && opts->sub_id >= 0) {
1565 unsigned char lang[3];
1566 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id,
1567 lang)) {
1568 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1569 opts->sub_id, lang);
1570 return M_PROPERTY_OK;
1574 #endif
1576 if ((d_sub->demuxer->type == DEMUXER_TYPE_MATROSKA
1577 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF
1578 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1579 || d_sub->demuxer->type == DEMUXER_TYPE_OGG)
1580 && d_sub->sh && opts->sub_id >= 0) {
1581 struct sh_sub *sh = d_sub->sh;
1582 char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
1583 if (sh->title)
1584 *(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
1585 opts->sub_id, lang, sh->title);
1586 else
1587 *(char **)arg = talloc_asprintf(NULL, "(%d) %s",
1588 opts->sub_id, lang);
1589 return M_PROPERTY_OK;
1592 if (vo_vobsub && vobsub_id >= 0) {
1593 const char *language = mp_gtext("unknown");
1594 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1595 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1596 vobsub_id, language ? language : mp_gtext("unknown"));
1597 return M_PROPERTY_OK;
1599 #ifdef CONFIG_DVDREAD
1600 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1601 && opts->sub_id >= 0) {
1602 char lang[3];
1603 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1604 lang[0] = code >> 8;
1605 lang[1] = code;
1606 lang[2] = 0;
1607 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1608 opts->sub_id, lang);
1609 return M_PROPERTY_OK;
1611 #endif
1612 if (opts->sub_id >= 0) {
1613 *(char **) arg = talloc_asprintf(NULL, "(%d) %s", opts->sub_id,
1614 mp_gtext("unknown"));
1615 return M_PROPERTY_OK;
1617 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1618 return M_PROPERTY_OK;
1620 case M_PROPERTY_SET:
1621 if (!arg)
1622 return M_PROPERTY_ERROR;
1623 if (*(int *) arg < -1)
1624 *(int *) arg = -1;
1625 else if (*(int *) arg >= global_sub_size)
1626 *(int *) arg = global_sub_size - 1;
1627 mpctx->global_sub_pos = *(int *) arg;
1628 break;
1629 case M_PROPERTY_STEP:
1630 if (!arg || *(int *)arg >= 0) {
1631 mpctx->global_sub_pos += 2;
1632 mpctx->global_sub_pos =
1633 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1634 } else {
1635 mpctx->global_sub_pos += global_sub_size + 1;
1636 mpctx->global_sub_pos =
1637 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1639 break;
1640 default:
1641 return M_PROPERTY_NOT_IMPLEMENTED;
1644 if (mpctx->global_sub_pos >= 0) {
1645 source = sub_source(mpctx);
1646 source_pos = sub_source_pos(mpctx);
1649 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1650 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1651 global_sub_size,
1652 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1653 mpctx->sub_counts[SUB_SOURCE_SUBS],
1654 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1655 mpctx->global_sub_pos, source);
1657 mpctx->set_of_sub_pos = -1;
1658 mpctx->subdata = NULL;
1660 vobsub_id = -1;
1661 opts->sub_id = -1;
1662 if (d_sub) {
1663 if (d_sub->id > -2)
1664 reset_spu = 1;
1665 d_sub->id = -2;
1667 uninit_player(mpctx, INITIALIZED_SUB);
1669 if (source == SUB_SOURCE_VOBSUB)
1670 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1671 else if (source == SUB_SOURCE_SUBS) {
1672 mpctx->set_of_sub_pos = source_pos;
1673 if (opts->ass_enabled
1674 && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]) {
1675 sub_init(mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos],
1676 mpctx->osd);
1677 mpctx->initialized_flags |= INITIALIZED_SUB;
1678 } else
1679 mpctx->subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1680 vo_osd_changed(OSDTYPE_SUBTITLE);
1681 } else if (source == SUB_SOURCE_DEMUX) {
1682 opts->sub_id = source_pos;
1683 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1684 int i = 0;
1685 // default: assume 1:1 mapping of sid and stream id
1686 d_sub->id = opts->sub_id;
1687 d_sub->sh = mpctx->d_sub->demuxer->s_streams[d_sub->id];
1688 ds_free_packs(d_sub);
1689 for (i = 0; i < MAX_S_STREAMS; i++) {
1690 sh_sub_t *sh = mpctx->d_sub->demuxer->s_streams[i];
1691 if (sh && sh->sid == opts->sub_id) {
1692 d_sub->id = i;
1693 d_sub->sh = sh;
1694 break;
1697 if (d_sub->sh && d_sub->id >= 0) {
1698 sh_sub_t *sh = d_sub->sh;
1699 if (sh->type == 'v')
1700 init_vo_spudec(mpctx);
1701 else {
1702 sub_init(sh, mpctx->osd);
1703 mpctx->initialized_flags |= INITIALIZED_SUB;
1705 } else {
1706 d_sub->id = -2;
1707 d_sub->sh = NULL;
1711 #ifdef CONFIG_DVDREAD
1712 if (vo_spudec
1713 && (mpctx->stream->type == STREAMTYPE_DVD
1714 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1715 && opts->sub_id < 0 && reset_spu) {
1716 d_sub->id = -2;
1717 d_sub->sh = NULL;
1719 #endif
1721 update_subtitles(mpctx, 0, true);
1723 return M_PROPERTY_OK;
1726 /// Selected sub source (RW)
1727 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1728 MPContext *mpctx)
1730 int source;
1731 update_global_sub_size(mpctx);
1732 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1733 return M_PROPERTY_UNAVAILABLE;
1735 switch (action) {
1736 case M_PROPERTY_GET:
1737 if (!arg)
1738 return M_PROPERTY_ERROR;
1739 *(int *) arg = sub_source(mpctx);
1740 return M_PROPERTY_OK;
1741 case M_PROPERTY_PRINT:
1742 if (!arg)
1743 return M_PROPERTY_ERROR;
1744 char *sourcename;
1745 switch (sub_source(mpctx)) {
1746 case SUB_SOURCE_SUBS:
1747 sourcename = mp_gtext("file");
1748 break;
1749 case SUB_SOURCE_VOBSUB:
1750 sourcename = mp_gtext("vobsub");
1751 break;
1752 case SUB_SOURCE_DEMUX:
1753 sourcename = mp_gtext("embedded");
1754 break;
1755 default:
1756 sourcename = mp_gtext("disabled");
1758 *(char **)arg = talloc_strdup(NULL, sourcename);
1759 return M_PROPERTY_OK;
1760 case M_PROPERTY_SET:
1761 if (!arg)
1762 return M_PROPERTY_ERROR;
1763 M_PROPERTY_CLAMP(prop, *(int *)arg);
1764 if (*(int *) arg < 0)
1765 mpctx->global_sub_pos = -1;
1766 else if (*(int *) arg != sub_source(mpctx)) {
1767 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1768 if (new_pos == -1)
1769 return M_PROPERTY_UNAVAILABLE;
1770 mpctx->global_sub_pos = new_pos;
1772 break;
1773 case M_PROPERTY_STEP: {
1774 int step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1);
1775 int step = (step_all > 0) ? 1 : -1;
1776 int cur_source = sub_source(mpctx);
1777 source = cur_source;
1778 while (step_all) {
1779 source += step;
1780 if (source >= SUB_SOURCES)
1781 source = -1;
1782 else if (source < -1)
1783 source = SUB_SOURCES - 1;
1784 if (source == cur_source || source == -1 ||
1785 mpctx->sub_counts[source])
1786 step_all -= step;
1788 if (source == cur_source)
1789 return M_PROPERTY_OK;
1790 if (source == -1)
1791 mpctx->global_sub_pos = -1;
1792 else
1793 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1794 break;
1796 default:
1797 return M_PROPERTY_NOT_IMPLEMENTED;
1799 --mpctx->global_sub_pos;
1800 return mp_property_sub(prop, M_PROPERTY_STEP, NULL, mpctx);
1803 /// Selected subtitles from specific source (RW)
1804 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1805 MPContext *mpctx)
1807 int source, is_cur_source, offset, new_pos;
1808 update_global_sub_size(mpctx);
1809 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1810 return M_PROPERTY_UNAVAILABLE;
1812 if (!strcmp(prop->name, "sub_file"))
1813 source = SUB_SOURCE_SUBS;
1814 else if (!strcmp(prop->name, "sub_vob"))
1815 source = SUB_SOURCE_VOBSUB;
1816 else if (!strcmp(prop->name, "sub_demux"))
1817 source = SUB_SOURCE_DEMUX;
1818 else
1819 return M_PROPERTY_ERROR;
1821 offset = sub_pos_by_source(mpctx, source);
1822 if (offset < 0)
1823 return M_PROPERTY_UNAVAILABLE;
1825 is_cur_source = sub_source(mpctx) == source;
1826 new_pos = mpctx->global_sub_pos;
1827 switch (action) {
1828 case M_PROPERTY_GET:
1829 if (!arg)
1830 return M_PROPERTY_ERROR;
1831 if (is_cur_source) {
1832 *(int *) arg = sub_source_pos(mpctx);
1833 if (source == SUB_SOURCE_VOBSUB)
1834 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1835 } else
1836 *(int *) arg = -1;
1837 return M_PROPERTY_OK;
1838 case M_PROPERTY_PRINT:
1839 if (!arg)
1840 return M_PROPERTY_ERROR;
1841 if (is_cur_source)
1842 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1843 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1844 return M_PROPERTY_OK;
1845 case M_PROPERTY_SET:
1846 if (!arg)
1847 return M_PROPERTY_ERROR;
1848 if (*(int *) arg >= 0) {
1849 int index = *(int *)arg;
1850 if (source == SUB_SOURCE_VOBSUB)
1851 index = vobsub_get_index_by_id(vo_vobsub, index);
1852 new_pos = offset + index;
1853 if (index < 0 || index > mpctx->sub_counts[source]) {
1854 new_pos = -1;
1855 *(int *) arg = -1;
1857 } else
1858 new_pos = -1;
1859 break;
1860 case M_PROPERTY_STEP: {
1861 int step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1);
1862 int step = (step_all > 0) ? 1 : -1;
1863 int max_sub_pos_for_source = -1;
1864 if (!is_cur_source)
1865 new_pos = -1;
1866 while (step_all) {
1867 if (new_pos == -1) {
1868 if (step > 0)
1869 new_pos = offset;
1870 else if (max_sub_pos_for_source == -1) {
1871 // Find max pos for specific source
1872 new_pos = mpctx->global_sub_size - 1;
1873 while (new_pos >= 0 && sub_source(mpctx) != source)
1874 new_pos--;
1875 } else
1876 new_pos = max_sub_pos_for_source;
1877 } else {
1878 new_pos += step;
1879 if (new_pos < offset ||
1880 new_pos >= mpctx->global_sub_size ||
1881 sub_source(mpctx) != source)
1882 new_pos = -1;
1884 step_all -= step;
1886 break;
1888 default:
1889 return M_PROPERTY_NOT_IMPLEMENTED;
1891 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1894 /// Subtitle delay (RW)
1895 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1896 MPContext *mpctx)
1898 if (!mpctx->sh_video)
1899 return M_PROPERTY_UNAVAILABLE;
1900 return m_property_delay(prop, action, arg, &sub_delay);
1903 /// Alignment of text subtitles (RW)
1904 static int mp_property_sub_alignment(m_option_t *prop, int action,
1905 void *arg, MPContext *mpctx)
1907 char *name[] = {
1908 _("top"), _("center"), _("bottom")
1911 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1912 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1913 return M_PROPERTY_UNAVAILABLE;
1915 switch (action) {
1916 case M_PROPERTY_PRINT:
1917 if (!arg)
1918 return M_PROPERTY_ERROR;
1919 M_PROPERTY_CLAMP(prop, sub_alignment);
1920 *(char **) arg = talloc_strdup(NULL, mp_gtext(name[sub_alignment]));
1921 return M_PROPERTY_OK;
1922 case M_PROPERTY_SET:
1923 if (!arg)
1924 return M_PROPERTY_ERROR;
1925 case M_PROPERTY_STEP:
1926 vo_osd_changed(OSDTYPE_SUBTITLE);
1927 default:
1928 return m_property_choice(prop, action, arg, &sub_alignment);
1932 /// Subtitle visibility (RW)
1933 static int mp_property_sub_visibility(m_option_t *prop, int action,
1934 void *arg, MPContext *mpctx)
1936 struct MPOpts *opts = &mpctx->opts;
1938 if (!mpctx->sh_video)
1939 return M_PROPERTY_UNAVAILABLE;
1941 switch (action) {
1942 case M_PROPERTY_SET:
1943 if (!arg)
1944 return M_PROPERTY_ERROR;
1945 case M_PROPERTY_STEP:
1946 vo_osd_changed(OSDTYPE_SUBTITLE);
1947 if (vo_spudec)
1948 vo_osd_changed(OSDTYPE_SPU);
1949 default:
1950 return m_property_flag(prop, action, arg, &opts->sub_visibility);
1954 #ifdef CONFIG_ASS
1955 /// Use margins for libass subtitles (RW)
1956 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1957 void *arg, MPContext *mpctx)
1959 struct MPOpts *opts = &mpctx->opts;
1960 if (!mpctx->sh_video)
1961 return M_PROPERTY_UNAVAILABLE;
1963 switch (action) {
1964 case M_PROPERTY_SET:
1965 if (!arg)
1966 return M_PROPERTY_ERROR;
1967 case M_PROPERTY_STEP:
1968 vo_osd_changed(OSDTYPE_SUBTITLE);
1969 default:
1970 return m_property_flag(prop, action, arg, &opts->ass_use_margins);
1974 static int mp_property_ass_vsfilter_aspect_compat(m_option_t *prop, int action,
1975 void *arg, MPContext *mpctx)
1977 if (!mpctx->sh_video)
1978 return M_PROPERTY_UNAVAILABLE;
1980 switch (action) {
1981 case M_PROPERTY_SET:
1982 if (!arg)
1983 return M_PROPERTY_ERROR;
1984 case M_PROPERTY_STEP:
1985 vo_osd_changed(OSDTYPE_SUBTITLE);
1986 default:
1987 return m_property_flag(prop, action, arg,
1988 &mpctx->opts.ass_vsfilter_aspect_compat);
1992 #endif
1994 /// Show only forced subtitles (RW)
1995 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1996 void *arg, MPContext *mpctx)
1998 if (!vo_spudec)
1999 return M_PROPERTY_UNAVAILABLE;
2001 switch (action) {
2002 case M_PROPERTY_SET:
2003 if (!arg)
2004 return M_PROPERTY_ERROR;
2005 case M_PROPERTY_STEP:
2006 m_property_flag(prop, action, arg, &forced_subs_only);
2007 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
2008 return M_PROPERTY_OK;
2009 default:
2010 return m_property_flag(prop, action, arg, &forced_subs_only);
2015 /// Subtitle scale (RW)
2016 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
2017 MPContext *mpctx)
2019 struct MPOpts *opts = &mpctx->opts;
2021 switch (action) {
2022 case M_PROPERTY_SET:
2023 if (!arg)
2024 return M_PROPERTY_ERROR;
2025 M_PROPERTY_CLAMP(prop, *(float *) arg);
2026 if (opts->ass_enabled)
2027 opts->ass_font_scale = *(float *) arg;
2028 text_font_scale_factor = *(float *) arg;
2029 vo_osd_changed(OSDTYPE_SUBTITLE);
2030 return M_PROPERTY_OK;
2031 case M_PROPERTY_STEP:
2032 if (opts->ass_enabled) {
2033 opts->ass_font_scale += (arg ? *(float *) arg : 0.1);
2034 M_PROPERTY_CLAMP(prop, opts->ass_font_scale);
2036 text_font_scale_factor += (arg ? *(float *) arg : 0.1);
2037 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
2038 vo_osd_changed(OSDTYPE_SUBTITLE);
2039 return M_PROPERTY_OK;
2040 default:
2041 if (opts->ass_enabled)
2042 return m_property_float_ro(prop, action, arg, opts->ass_font_scale);
2043 else
2044 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
2049 #ifdef CONFIG_TV
2051 /// TV color settings (RW)
2052 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2053 MPContext *mpctx)
2055 int r, val;
2056 tvi_handle_t *tvh = mpctx->demuxer->priv;
2057 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2058 return M_PROPERTY_UNAVAILABLE;
2060 switch (action) {
2061 case M_PROPERTY_SET:
2062 if (!arg)
2063 return M_PROPERTY_ERROR;
2064 M_PROPERTY_CLAMP(prop, *(int *) arg);
2065 return tv_set_color_options(tvh, prop->offset, *(int *) arg);
2066 case M_PROPERTY_GET:
2067 return tv_get_color_options(tvh, prop->offset, arg);
2068 case M_PROPERTY_STEP:
2069 if ((r = tv_get_color_options(tvh, prop->offset, &val)) >= 0) {
2070 if (!r)
2071 return M_PROPERTY_ERROR;
2072 val += (arg ? *(int *) arg : 1);
2073 M_PROPERTY_CLAMP(prop, val);
2074 return tv_set_color_options(tvh, prop->offset, val);
2076 return M_PROPERTY_ERROR;
2078 return M_PROPERTY_NOT_IMPLEMENTED;
2081 #endif
2083 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2084 MPContext *mpctx)
2086 int val, result;
2087 int base_ioctl = prop->offset;
2089 for teletext's GET,SET,STEP ioctls this is not 0
2090 SET is GET+1
2091 STEP is GET+2
2093 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2094 return M_PROPERTY_UNAVAILABLE;
2095 if (!base_ioctl)
2096 return M_PROPERTY_ERROR;
2098 switch (action) {
2099 case M_PROPERTY_GET:
2100 if (!arg)
2101 return M_PROPERTY_ERROR;
2102 result = teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2103 break;
2104 case M_PROPERTY_SET:
2105 if (!arg)
2106 return M_PROPERTY_ERROR;
2107 M_PROPERTY_CLAMP(prop, *(int *) arg);
2108 result = teletext_control(mpctx->demuxer->teletext, base_ioctl + 1,
2109 arg);
2110 break;
2111 case M_PROPERTY_STEP:
2112 result = teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2113 val += (arg ? *(int *) arg : 1);
2114 result = teletext_control(mpctx->demuxer->teletext, base_ioctl + 1,
2115 &val);
2116 break;
2117 default:
2118 return M_PROPERTY_NOT_IMPLEMENTED;
2121 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2124 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2125 MPContext *mpctx)
2127 int result;
2128 int val;
2130 //with tvh==NULL will fail too
2131 result = mp_property_teletext_common(prop, action, arg, mpctx);
2132 if (result != M_PROPERTY_OK)
2133 return result;
2135 if (teletext_control(mpctx->demuxer->teletext,
2136 prop->offset, &val) == VBI_CONTROL_TRUE && val)
2137 mp_input_set_section(mpctx->input, "teletext");
2138 else
2139 mp_input_set_section(mpctx->input, "tv");
2140 return M_PROPERTY_OK;
2143 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2144 MPContext *mpctx)
2146 int result;
2147 int val;
2148 if (!mpctx->demuxer->teletext)
2149 return M_PROPERTY_UNAVAILABLE;
2150 switch (action) {
2151 case M_PROPERTY_STEP:
2152 //This should be handled separately
2153 val = (arg ? *(int *) arg : 1);
2154 result = teletext_control(mpctx->demuxer->teletext,
2155 TV_VBI_CONTROL_STEP_PAGE, &val);
2156 break;
2157 default:
2158 result = mp_property_teletext_common(prop, action, arg, mpctx);
2160 return result;
2164 /// All properties available in MPlayer.
2165 /** \ingroup Properties
2167 static const m_option_t mp_properties[] = {
2168 // General
2169 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2170 M_OPT_RANGE, 0, 3, NULL },
2171 { "loop", mp_property_loop, CONF_TYPE_INT,
2172 M_OPT_MIN, -1, 0, NULL },
2173 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2174 M_OPT_RANGE, 0.01, 100.0, NULL },
2175 { "filename", mp_property_filename, CONF_TYPE_STRING,
2176 0, 0, 0, NULL },
2177 { "path", mp_property_path, CONF_TYPE_STRING,
2178 0, 0, 0, NULL },
2179 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2180 0, 0, 0, NULL },
2181 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2182 M_OPT_MIN, 0, 0, NULL },
2183 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2184 M_OPT_MIN, 0, 0, NULL },
2185 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2186 M_OPT_MIN, 0, 0, NULL },
2187 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2188 M_OPT_MIN, 0, 0, NULL },
2189 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2190 M_OPT_MIN, 0, 0, NULL },
2191 { "length", mp_property_length, CONF_TYPE_TIME,
2192 M_OPT_MIN, 0, 0, NULL },
2193 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2194 M_OPT_RANGE, 0, 100, NULL },
2195 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2196 M_OPT_MIN, 0, 0, NULL },
2197 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2198 M_OPT_MIN, 0, 0, NULL },
2199 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2200 0, 0, 0, NULL },
2201 { "angle", mp_property_angle, CONF_TYPE_INT,
2202 CONF_RANGE, -2, 10, NULL },
2203 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2204 0, 0, 0, NULL },
2205 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2206 M_OPT_RANGE, 0, 1, NULL },
2207 { "capturing", mp_property_capture, CONF_TYPE_FLAG,
2208 M_OPT_RANGE, 0, 1, NULL },
2209 { "pts_association_mode", mp_property_generic_option, &m_option_type_choice,
2210 0, 0, 0, "pts-association-mode" },
2211 { "hr_seek", mp_property_generic_option, &m_option_type_choice,
2212 0, 0, 0, "hr-seek" },
2214 // Audio
2215 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2216 M_OPT_RANGE, 0, 100, NULL },
2217 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2218 M_OPT_RANGE, 0, 1, NULL },
2219 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2220 M_OPT_RANGE, -100, 100, NULL },
2221 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2222 0, 0, 0, NULL },
2223 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2224 0, 0, 0, NULL },
2225 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2226 0, 0, 0, NULL },
2227 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2228 0, 0, 0, NULL },
2229 { "channels", mp_property_channels, CONF_TYPE_INT,
2230 0, 0, 0, NULL },
2231 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2232 CONF_RANGE, -2, 65535, NULL },
2233 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2234 M_OPT_RANGE, -1, 1, NULL },
2236 // Video
2237 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2238 M_OPT_RANGE, 0, 1, NULL },
2239 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2240 M_OPT_RANGE, 0, 1, NULL },
2241 { "colormatrix", mp_property_colormatrix, &m_option_type_choice,
2242 0, 0, 0, "colormatrix" },
2243 { "colormatrix_input_range", mp_property_colormatrix_input_range, &m_option_type_choice,
2244 0, 0, 0, "colormatrix-input-range" },
2245 { "colormatrix_output_range", mp_property_colormatrix_output_range, &m_option_type_choice,
2246 0, 0, 0, "colormatrix-output-range" },
2247 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2248 M_OPT_RANGE, 0, 1, NULL },
2249 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2250 M_OPT_RANGE, 0, 1, NULL },
2251 { "border", mp_property_border, CONF_TYPE_FLAG,
2252 M_OPT_RANGE, 0, 1, NULL },
2253 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2254 M_OPT_RANGE, 0, 2, NULL },
2255 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2256 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_gamma)},
2257 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2258 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_brightness) },
2259 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2260 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_contrast) },
2261 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2262 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_saturation) },
2263 { "hue", mp_property_gamma, CONF_TYPE_INT,
2264 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_hue) },
2265 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2266 M_OPT_RANGE, 0, 1, NULL },
2267 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2268 M_OPT_RANGE, 0, 1, NULL },
2269 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2270 0, 0, 0, NULL },
2271 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2272 0, 0, 0, NULL },
2273 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2274 0, 0, 0, NULL },
2275 { "width", mp_property_width, CONF_TYPE_INT,
2276 0, 0, 0, NULL },
2277 { "height", mp_property_height, CONF_TYPE_INT,
2278 0, 0, 0, NULL },
2279 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2280 0, 0, 0, NULL },
2281 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2282 0, 0, 0, NULL },
2283 { "switch_video", mp_property_video, CONF_TYPE_INT,
2284 CONF_RANGE, -2, 65535, NULL },
2285 { "switch_program", mp_property_program, CONF_TYPE_INT,
2286 CONF_RANGE, -1, 65535, NULL },
2288 // Subs
2289 { "sub", mp_property_sub, CONF_TYPE_INT,
2290 M_OPT_MIN, -1, 0, NULL },
2291 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2292 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2293 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2294 M_OPT_MIN, -1, 0, NULL },
2295 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2296 M_OPT_MIN, -1, 0, NULL },
2297 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2298 M_OPT_MIN, -1, 0, NULL },
2299 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2300 0, 0, 0, NULL },
2301 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2302 M_OPT_RANGE, 0, 100, NULL },
2303 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2304 M_OPT_RANGE, 0, 2, NULL },
2305 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2306 M_OPT_RANGE, 0, 1, NULL },
2307 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2308 M_OPT_RANGE, 0, 1, NULL },
2309 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2310 M_OPT_RANGE, 0, 100, NULL },
2311 #ifdef CONFIG_ASS
2312 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2313 M_OPT_RANGE, 0, 1, NULL },
2314 { "ass_vsfilter_aspect_compat", mp_property_ass_vsfilter_aspect_compat,
2315 CONF_TYPE_FLAG, M_OPT_RANGE, 0, 1, NULL },
2316 #endif
2318 #ifdef CONFIG_TV
2319 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2320 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_BRIGHTNESS },
2321 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2322 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_CONTRAST },
2323 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2324 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_SATURATION },
2325 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2326 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_HUE },
2327 #endif
2328 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2329 M_OPT_RANGE, 100, 899, .offset = TV_VBI_CONTROL_GET_PAGE },
2330 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2331 M_OPT_RANGE, 0, 64, .offset = TV_VBI_CONTROL_GET_SUBPAGE },
2332 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2333 M_OPT_RANGE, 0, 1, .offset = TV_VBI_CONTROL_GET_MODE },
2334 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2335 M_OPT_RANGE, 0, 3, .offset = TV_VBI_CONTROL_GET_FORMAT },
2336 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2337 M_OPT_RANGE, 0, 2, .offset = TV_VBI_CONTROL_GET_HALF_PAGE },
2338 { NULL, NULL, NULL, 0, 0, 0, NULL }
2342 int mp_property_do(const char *name, int action, void *val, void *ctx)
2344 return m_property_do(mp_properties, name, action, val, ctx);
2347 char *mp_property_print(const char *name, void *ctx)
2349 char *ret = NULL;
2350 if (mp_property_do(name, M_PROPERTY_PRINT, &ret, ctx) <= 0)
2351 return NULL;
2352 return ret;
2355 char *property_expand_string(MPContext *mpctx, char *str)
2357 return m_properties_expand_string(mp_properties, str, mpctx);
2360 void property_print_help(void)
2362 m_properties_print_help_list(mp_properties);
2366 /* List of default ways to show a property on OSD.
2368 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2369 * a bar showing the current position between min/max values of the
2370 * property. In this case osd_msg is only used for terminal output
2371 * if there is no video; it'll be a label shown together with percentage.
2373 * Otherwise setting osd_msg will show the string on OSD, formatted with
2374 * the text value of the property as argument.
2376 static struct property_osd_display {
2377 /// property name
2378 const char *name;
2379 /// progressbar type
2380 int osd_progbar; // -1 is special value for seek indicators
2381 /// osd msg id if it must be shared
2382 int osd_id;
2383 /// osd msg template
2384 const char *osd_msg;
2385 } property_osd_display[] = {
2386 // general
2387 { "loop", 0, -1, _("Loop: %s") },
2388 { "chapter", -1, -1, NULL },
2389 { "capturing", 0, -1, _("Capturing: %s") },
2390 { "pts_association_mode", 0, -1, "PTS association mode: %s" },
2391 { "hr_seek", 0, -1, "hr-seek: %s" },
2392 { "speed", 0, -1, _("Speed: x %6s") },
2393 // audio
2394 { "volume", OSD_VOLUME, -1, _("Volume") },
2395 { "mute", 0, -1, _("Mute: %s") },
2396 { "audio_delay", 0, -1, _("A-V delay: %s") },
2397 { "switch_audio", 0, -1, _("Audio: %s") },
2398 { "balance", OSD_BALANCE, -1, _("Balance") },
2399 // video
2400 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2401 { "ontop", 0, -1, _("Stay on top: %s") },
2402 { "rootwin", 0, -1, _("Rootwin: %s") },
2403 { "border", 0, -1, _("Border: %s") },
2404 { "framedropping", 0, -1, _("Framedropping: %s") },
2405 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2406 { "colormatrix", 0, -1, _("YUV colormatrix: %s") },
2407 { "colormatrix_input_range", 0, -1, _("YUV input range: %s") },
2408 { "colormatrix_output_range", 0, -1, _("RGB output range: %s") },
2409 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2410 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2411 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2412 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2413 { "hue", OSD_HUE, -1, _("Hue") },
2414 { "vsync", 0, -1, _("VSync: %s") },
2415 // subs
2416 { "sub", 0, -1, _("Subtitles: %s") },
2417 { "sub_source", 0, -1, _("Sub source: %s") },
2418 { "sub_vob", 0, -1, _("Subtitles: %s") },
2419 { "sub_demux", 0, -1, _("Subtitles: %s") },
2420 { "sub_file", 0, -1, _("Subtitles: %s") },
2421 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2422 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2423 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2424 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2425 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2426 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2427 { "ass_vsfilter_aspect_compat", 0, -1,
2428 _("Subtitle VSFilter aspect compat: %s")},
2429 #ifdef CONFIG_TV
2430 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2431 { "tv_hue", OSD_HUE, -1, _("Hue") },
2432 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2433 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2434 #endif
2438 static int show_property_osd(MPContext *mpctx, const char *pname)
2440 struct MPOpts *opts = &mpctx->opts;
2441 int r;
2442 m_option_t *prop;
2443 struct property_osd_display *p;
2445 // look for the command
2446 for (p = property_osd_display; p->name; p++)
2447 if (!strcmp(p->name, pname))
2448 break;
2450 if (!p->name)
2451 return -1;
2453 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2454 return -1;
2456 if (p->osd_progbar == -1)
2457 mpctx->add_osd_seek_info = true;
2458 else if (p->osd_progbar) {
2459 if (prop->type == CONF_TYPE_INT) {
2460 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2461 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2462 prop->min, prop->max, r);
2463 } else if (prop->type == CONF_TYPE_FLOAT) {
2464 float f;
2465 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2466 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2467 prop->min, prop->max, f);
2468 } else {
2469 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2470 "Property use an unsupported type.\n");
2471 return -1;
2473 return 0;
2476 if (p->osd_msg) {
2477 char *val = mp_property_print(pname, mpctx);
2478 if (val) {
2479 int index = p - property_osd_display;
2480 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2481 1, opts->osd_duration, p->osd_msg, val);
2482 talloc_free(val);
2485 return 0;
2490 * Command to property bridge
2492 * It is used to handle most commands that just set a property
2493 * and optionally display something on the OSD.
2494 * Two kinds of commands are handled: adjust or toggle.
2496 * Adjust commands take 1 or 2 parameters: <value> <abs>
2497 * If <abs> is non-zero the property is set to the given value
2498 * otherwise it is adjusted.
2500 * Toggle commands take 0 or 1 parameters. With no parameter
2501 * or a value less than the property minimum it just steps the
2502 * property to its next or previous value respectively.
2503 * Otherwise it sets it to the given value.
2506 /// List of the commands that can be handled by setting a property.
2507 static struct {
2508 /// property name
2509 const char *name;
2510 /// cmd id
2511 int cmd;
2512 /// set/adjust or toggle command
2513 int toggle;
2514 } set_prop_cmd[] = {
2515 // general
2516 { "loop", MP_CMD_LOOP, 0},
2517 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2518 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2519 { "pause", MP_CMD_PAUSE, 0},
2520 { "capturing", MP_CMD_CAPTURING, 1},
2521 // audio
2522 { "volume", MP_CMD_VOLUME, 0},
2523 { "mute", MP_CMD_MUTE, 1},
2524 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2525 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2526 { "balance", MP_CMD_BALANCE, 0},
2527 // video
2528 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2529 { "panscan", MP_CMD_PANSCAN, 0},
2530 { "ontop", MP_CMD_VO_ONTOP, 1},
2531 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2532 { "border", MP_CMD_VO_BORDER, 1},
2533 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2534 { "gamma", MP_CMD_GAMMA, 0},
2535 { "brightness", MP_CMD_BRIGHTNESS, 0},
2536 { "contrast", MP_CMD_CONTRAST, 0},
2537 { "saturation", MP_CMD_SATURATION, 0},
2538 { "hue", MP_CMD_HUE, 0},
2539 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2540 // subs
2541 { "sub", MP_CMD_SUB_SELECT, 1},
2542 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2543 { "sub_vob", MP_CMD_SUB_VOB, 1},
2544 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2545 { "sub_file", MP_CMD_SUB_FILE, 1},
2546 { "sub_pos", MP_CMD_SUB_POS, 0},
2547 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2548 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2549 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2550 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2551 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2552 #ifdef CONFIG_ASS
2553 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2554 #endif
2555 #ifdef CONFIG_TV
2556 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2557 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2558 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2559 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2560 #endif
2564 /// Handle commands that set a property.
2565 static bool set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2567 int i, r;
2568 m_option_t *prop;
2569 const char *pname;
2571 // look for the command
2572 for (i = 0; set_prop_cmd[i].name; i++)
2573 if (set_prop_cmd[i].cmd == cmd->id)
2574 break;
2575 if (!(pname = set_prop_cmd[i].name))
2576 return 0;
2578 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2579 return 0;
2581 // toggle command
2582 if (set_prop_cmd[i].toggle) {
2583 // set to value
2584 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2585 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2586 else {
2587 int dir = 1;
2588 if (cmd->nargs > 0)
2589 dir = -1;
2590 r = mp_property_do(pname, M_PROPERTY_STEP, &dir, mpctx);
2592 } else if (cmd->args[1].v.i) //set
2593 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2594 else // adjust
2595 r = mp_property_do(pname, M_PROPERTY_STEP, &cmd->args[0].v, mpctx);
2597 if (r <= 0)
2598 return 1;
2600 show_property_osd(mpctx, pname);
2602 return 1;
2605 #ifdef CONFIG_DVDNAV
2606 static const struct {
2607 const char *name;
2608 const enum mp_command_type cmd;
2609 } mp_dvdnav_bindings[] = {
2610 { "up", MP_CMD_DVDNAV_UP },
2611 { "down", MP_CMD_DVDNAV_DOWN },
2612 { "left", MP_CMD_DVDNAV_LEFT },
2613 { "right", MP_CMD_DVDNAV_RIGHT },
2614 { "menu", MP_CMD_DVDNAV_MENU },
2615 { "select", MP_CMD_DVDNAV_SELECT },
2616 { "prev", MP_CMD_DVDNAV_PREVMENU },
2617 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2620 * keep old dvdnav sub-command options for a while in order not to
2621 * break slave-mode API too suddenly.
2623 { "1", MP_CMD_DVDNAV_UP },
2624 { "2", MP_CMD_DVDNAV_DOWN },
2625 { "3", MP_CMD_DVDNAV_LEFT },
2626 { "4", MP_CMD_DVDNAV_RIGHT },
2627 { "5", MP_CMD_DVDNAV_MENU },
2628 { "6", MP_CMD_DVDNAV_SELECT },
2629 { "7", MP_CMD_DVDNAV_PREVMENU },
2630 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2631 { NULL, 0 }
2633 #endif
2635 static const char *property_error_string(int error_value)
2637 switch (error_value) {
2638 case M_PROPERTY_ERROR:
2639 return "ERROR";
2640 case M_PROPERTY_UNAVAILABLE:
2641 return "PROPERTY_UNAVAILABLE";
2642 case M_PROPERTY_NOT_IMPLEMENTED:
2643 return "NOT_IMPLEMENTED";
2644 case M_PROPERTY_UNKNOWN:
2645 return "PROPERTY_UNKNOWN";
2646 case M_PROPERTY_DISABLED:
2647 return "DISABLED";
2649 return "UNKNOWN";
2652 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2654 int idx;
2655 int end = start + count;
2656 int after = mpctx->set_of_sub_size - end;
2657 sub_data **subs = mpctx->set_of_subtitles;
2658 struct sh_sub **ass_tracks = mpctx->set_of_ass_tracks;
2659 if (count < 0 || count > mpctx->set_of_sub_size ||
2660 start < 0 || start > mpctx->set_of_sub_size - count) {
2661 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2662 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2663 return;
2665 for (idx = start; idx < end; idx++) {
2666 sub_data *subd = subs[idx];
2667 char *filename = "";
2668 if (subd)
2669 filename = subd->filename;
2670 if (!subd)
2671 filename = ass_tracks[idx]->title;
2672 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2673 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2674 filename_recode(filename));
2675 sub_free(subd);
2676 subs[idx] = NULL;
2677 if (ass_tracks[idx]) {
2678 sub_switchoff(ass_tracks[idx], mpctx->osd);
2679 sub_uninit(ass_tracks[idx]);
2681 talloc_free(ass_tracks[idx]);
2682 ass_tracks[idx] = NULL;
2685 mpctx->global_sub_size -= count;
2686 mpctx->set_of_sub_size -= count;
2687 if (mpctx->set_of_sub_size <= 0)
2688 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2690 memmove(subs + start, subs + end, after * sizeof(*subs));
2691 memset(subs + start + after, 0, count * sizeof(*subs));
2692 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2693 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2695 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2696 mpctx->global_sub_pos = -2;
2697 mpctx->subdata = NULL;
2698 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2699 } else if (mpctx->set_of_sub_pos >= end) {
2700 mpctx->set_of_sub_pos -= count;
2701 mpctx->global_sub_pos -= count;
2705 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2707 struct MPOpts *opts = &mpctx->opts;
2708 sh_audio_t *const sh_audio = mpctx->sh_audio;
2709 sh_video_t *const sh_video = mpctx->sh_video;
2710 int osd_duration = opts->osd_duration;
2711 int case_fallthrough_hack = 0;
2712 if (set_property_command(mpctx, cmd))
2713 goto old_pause_hack; // was handled already
2714 switch (cmd->id) {
2715 case MP_CMD_SEEK: {
2716 mpctx->add_osd_seek_info = true;
2717 float v = cmd->args[0].v.f;
2718 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2719 int exact = (cmd->nargs > 2) ? cmd->args[2].v.i : 0;
2720 if (abs == 2) { // Absolute seek to a timestamp in seconds
2721 queue_seek(mpctx, MPSEEK_ABSOLUTE, v, exact);
2722 mpctx->osd_function = v > get_current_time(mpctx) ?
2723 OSD_FFW : OSD_REW;
2724 } else if (abs) { /* Absolute seek by percentage */
2725 queue_seek(mpctx, MPSEEK_FACTOR, v / 100.0, exact);
2726 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2727 } else {
2728 queue_seek(mpctx, MPSEEK_RELATIVE, v, exact);
2729 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2731 break;
2734 case MP_CMD_SET_PROPERTY_OSD:
2735 case_fallthrough_hack = 1;
2737 case MP_CMD_SET_PROPERTY: {
2738 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2739 cmd->args[1].v.s, mpctx);
2740 if (r == M_PROPERTY_UNKNOWN)
2741 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2742 "Unknown property: '%s'\n", cmd->args[0].v.s);
2743 else if (r <= 0)
2744 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2745 "Failed to set property '%s' to '%s'.\n",
2746 cmd->args[0].v.s, cmd->args[1].v.s);
2747 else if (case_fallthrough_hack)
2748 show_property_osd(mpctx, cmd->args[0].v.s);
2749 if (r <= 0)
2750 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2751 "ANS_ERROR=%s\n", property_error_string(r));
2752 break;
2755 case MP_CMD_STEP_PROPERTY_OSD:
2756 case_fallthrough_hack = 1;
2758 case MP_CMD_STEP_PROPERTY: {
2759 void *arg = NULL;
2760 int r, i;
2761 double d;
2762 off_t o;
2763 if (cmd->args[1].v.f) {
2764 m_option_t *prop;
2765 if ((r = mp_property_do(cmd->args[0].v.s,
2766 M_PROPERTY_GET_TYPE,
2767 &prop, mpctx)) <= 0)
2768 goto step_prop_err;
2769 if (prop->type == CONF_TYPE_INT ||
2770 prop->type == CONF_TYPE_FLAG)
2771 i = cmd->args[1].v.f, arg = &i;
2772 else if (prop->type == CONF_TYPE_FLOAT)
2773 arg = &cmd->args[1].v.f;
2774 else if (prop->type == CONF_TYPE_DOUBLE ||
2775 prop->type == CONF_TYPE_TIME)
2776 d = cmd->args[1].v.f, arg = &d;
2777 else if (prop->type == CONF_TYPE_POSITION)
2778 o = cmd->args[1].v.f, arg = &o;
2779 else
2780 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2781 "Ignoring step size stepping property '%s'.\n",
2782 cmd->args[0].v.s);
2784 r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_STEP,
2785 arg, mpctx);
2786 step_prop_err:
2787 if (r == M_PROPERTY_UNKNOWN)
2788 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2789 "Unknown property: '%s'\n", cmd->args[0].v.s);
2790 else if (r <= 0)
2791 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2792 "Failed to increment property '%s' by %f.\n",
2793 cmd->args[0].v.s, cmd->args[1].v.f);
2794 else if (case_fallthrough_hack)
2795 show_property_osd(mpctx, cmd->args[0].v.s);
2796 if (r <= 0)
2797 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n",
2798 property_error_string(r));
2799 break;
2802 case MP_CMD_GET_PROPERTY: {
2803 char *tmp;
2804 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2805 &tmp, mpctx);
2806 if (r <= 0) {
2807 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2808 "Failed to get value of property '%s'.\n",
2809 cmd->args[0].v.s);
2810 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n",
2811 property_error_string(r));
2812 break;
2814 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2815 cmd->args[0].v.s, tmp);
2816 talloc_free(tmp);
2817 break;
2820 case MP_CMD_EDL_MARK:
2821 if (edl_fd) {
2822 float v = get_current_time(mpctx);
2823 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2824 mpctx->begin_skip = v;
2825 mp_tmsg(MSGT_CPLAYER, MSGL_INFO,
2826 "EDL skip start, press 'i' again to end block.\n");
2827 } else {
2828 if (mpctx->begin_skip > v)
2829 mp_tmsg(MSGT_CPLAYER, MSGL_WARN,
2830 "EDL skip canceled, last start > stop\n");
2831 else {
2832 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2833 mp_tmsg(MSGT_CPLAYER, MSGL_INFO,
2834 "EDL skip end, line written.\n");
2836 mpctx->begin_skip = MP_NOPTS_VALUE;
2839 break;
2841 case MP_CMD_SWITCH_RATIO:
2842 if (!sh_video)
2843 break;
2844 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2845 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2846 else
2847 opts->movie_aspect = cmd->args[0].v.f;
2848 video_reset_aspect(sh_video);
2849 break;
2851 case MP_CMD_SPEED_INCR: {
2852 float v = cmd->args[0].v.f;
2853 mp_property_do("speed", M_PROPERTY_STEP, &v, mpctx);
2854 show_property_osd(mpctx, "speed");
2855 break;
2858 case MP_CMD_SPEED_MULT:
2859 case_fallthrough_hack = true;
2861 case MP_CMD_SPEED_SET: {
2862 float v = cmd->args[0].v.f;
2863 if (case_fallthrough_hack)
2864 v *= mpctx->opts.playback_speed;
2865 mp_property_do("speed", M_PROPERTY_SET, &v, mpctx);
2866 show_property_osd(mpctx, "speed");
2867 break;
2870 case MP_CMD_FRAME_STEP:
2871 add_step_frame(mpctx);
2872 break;
2874 case MP_CMD_QUIT:
2875 exit_player_with_rc(mpctx, EXIT_QUIT,
2876 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2878 case MP_CMD_PLAY_TREE_STEP: {
2879 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2880 int force = cmd->args[1].v.i;
2883 if (!force && mpctx->playtree_iter) {
2884 play_tree_iter_t *i =
2885 play_tree_iter_new_copy(mpctx->playtree_iter);
2886 if (play_tree_iter_step(i, n, 0) ==
2887 PLAY_TREE_ITER_ENTRY)
2888 mpctx->stop_play =
2889 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2890 play_tree_iter_free(i);
2891 } else
2892 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2893 if (mpctx->stop_play)
2894 mpctx->play_tree_step = n;
2896 break;
2899 case MP_CMD_PLAY_TREE_UP_STEP: {
2900 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2901 int force = cmd->args[1].v.i;
2903 if (!force && mpctx->playtree_iter) {
2904 play_tree_iter_t *i =
2905 play_tree_iter_new_copy(mpctx->playtree_iter);
2906 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2907 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2908 play_tree_iter_free(i);
2909 } else
2910 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2911 break;
2914 case MP_CMD_PLAY_ALT_SRC_STEP:
2915 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2916 int v = cmd->args[0].v.i;
2917 if (v > 0
2918 && mpctx->playtree_iter->file <
2919 mpctx->playtree_iter->num_files)
2920 mpctx->stop_play = PT_NEXT_SRC;
2921 else if (v < 0 && mpctx->playtree_iter->file > 1)
2922 mpctx->stop_play = PT_PREV_SRC;
2924 break;
2926 case MP_CMD_SUB_STEP:
2927 if (sh_video) {
2928 int movement = cmd->args[0].v.i;
2929 step_sub(mpctx->subdata, mpctx->video_pts, movement);
2930 #if 0
2931 // currently not implemented with libass
2932 if (mpctx->osd->ass_track)
2933 sub_delay +=
2934 ass_step_sub(mpctx->osd->ass_track,
2935 (mpctx->video_pts +
2936 sub_delay) * 1000 + .5, movement) / 1000.;
2937 #endif
2938 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2939 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2941 break;
2943 case MP_CMD_SUB_LOG:
2944 log_sub(mpctx);
2945 break;
2947 case MP_CMD_OSD: {
2948 int v = cmd->args[0].v.i;
2949 int max = (opts->term_osd
2950 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2951 if (opts->osd_level > max)
2952 opts->osd_level = max;
2953 if (v < 0)
2954 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2955 else
2956 opts->osd_level = v > max ? max : v;
2957 /* Show OSD state when disabled, but not when an explicit
2958 argument is given to the OSD command, i.e. in slave mode. */
2959 if (v == -1 && opts->osd_level <= 1)
2960 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2961 "OSD: %s",
2962 opts->osd_level ? mp_gtext("enabled") :
2963 mp_gtext("disabled"));
2964 else
2965 rm_osd_msg(OSD_MSG_OSD_STATUS);
2966 break;
2969 case MP_CMD_OSD_SHOW_TEXT:
2970 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2971 (cmd->args[1].v.i <
2972 0 ? osd_duration : cmd->args[1].v.i),
2973 "%s", cmd->args[0].v.s);
2974 break;
2976 case MP_CMD_OSD_SHOW_PROPERTY_TEXT: {
2977 char *txt = m_properties_expand_string(mp_properties,
2978 cmd->args[0].v.s,
2979 mpctx);
2980 // if no argument supplied use default osd_duration, else <arg> ms.
2981 if (txt) {
2982 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2983 (cmd->args[1].v.i <
2984 0 ? osd_duration : cmd->args[1].v.i),
2985 "%s", txt);
2986 free(txt);
2988 break;
2991 case MP_CMD_LOADFILE: {
2992 play_tree_t *e = play_tree_new();
2993 play_tree_add_file(e, cmd->args[0].v.s);
2995 if (cmd->args[1].v.i) // append
2996 play_tree_append_entry(mpctx->playtree->child, e);
2997 else {
2998 // Go back to the starting point.
2999 while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1)
3000 != PLAY_TREE_ITER_END)
3001 /* NOP */;
3002 play_tree_free_list(mpctx->playtree->child, 1);
3003 play_tree_set_child(mpctx->playtree, e);
3004 pt_iter_goto_head(mpctx->playtree_iter);
3005 mpctx->stop_play = PT_NEXT_SRC;
3007 break;
3010 case MP_CMD_LOADLIST: {
3011 play_tree_t *e = parse_playlist_file(mpctx->mconfig,
3012 bstr(cmd->args[0].v.s));
3013 if (!e)
3014 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
3015 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
3016 else {
3017 if (cmd->args[1].v.i) // append
3018 play_tree_append_entry(mpctx->playtree->child, e);
3019 else {
3020 // Go back to the starting point.
3021 while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1)
3022 != PLAY_TREE_ITER_END)
3023 /* NOP */;
3024 play_tree_free_list(mpctx->playtree->child, 1);
3025 play_tree_set_child(mpctx->playtree, e);
3026 pt_iter_goto_head(mpctx->playtree_iter);
3027 mpctx->stop_play = PT_NEXT_SRC;
3030 break;
3033 case MP_CMD_STOP:
3034 // Go back to the starting point.
3035 while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1) !=
3036 PLAY_TREE_ITER_END)
3037 /* NOP */;
3038 mpctx->stop_play = PT_STOP;
3039 break;
3041 case MP_CMD_OSD_SHOW_PROGRESSION: {
3042 set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3043 set_osd_progressmsg(OSD_MSG_TEXT, 1, osd_duration);
3044 break;
3047 #ifdef CONFIG_RADIO
3048 case MP_CMD_RADIO_STEP_CHANNEL:
3049 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3050 int v = cmd->args[0].v.i;
3051 if (v > 0)
3052 radio_step_channel(mpctx->demuxer->stream,
3053 RADIO_CHANNEL_HIGHER);
3054 else
3055 radio_step_channel(mpctx->demuxer->stream,
3056 RADIO_CHANNEL_LOWER);
3057 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3058 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3059 "Channel: %s",
3060 radio_get_channel_name(mpctx->demuxer->stream));
3063 break;
3065 case MP_CMD_RADIO_SET_CHANNEL:
3066 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3067 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3068 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3069 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3070 "Channel: %s",
3071 radio_get_channel_name(mpctx->demuxer->stream));
3074 break;
3076 case MP_CMD_RADIO_SET_FREQ:
3077 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3078 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3079 break;
3081 case MP_CMD_RADIO_STEP_FREQ:
3082 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3083 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3084 break;
3085 #endif
3087 #ifdef CONFIG_TV
3088 case MP_CMD_TV_START_SCAN:
3089 if (mpctx->file_format == DEMUXER_TYPE_TV)
3090 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv), 1);
3091 break;
3092 case MP_CMD_TV_SET_FREQ:
3093 if (mpctx->file_format == DEMUXER_TYPE_TV)
3094 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3095 cmd->args[0].v.f * 16.0);
3096 #ifdef CONFIG_PVR
3097 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3098 pvr_set_freq(mpctx->stream, ROUND(cmd->args[0].v.f));
3099 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3100 pvr_get_current_channelname(mpctx->stream),
3101 pvr_get_current_stationname(mpctx->stream));
3103 #endif /* CONFIG_PVR */
3104 break;
3106 case MP_CMD_TV_STEP_FREQ:
3107 if (mpctx->file_format == DEMUXER_TYPE_TV)
3108 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3109 cmd->args[0].v.f * 16.0);
3110 #ifdef CONFIG_PVR
3111 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3112 pvr_force_freq_step(mpctx->stream, ROUND(cmd->args[0].v.f));
3113 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3114 pvr_get_current_channelname(mpctx->stream),
3115 pvr_get_current_frequency(mpctx->stream));
3117 #endif /* CONFIG_PVR */
3118 break;
3120 case MP_CMD_TV_SET_NORM:
3121 if (mpctx->file_format == DEMUXER_TYPE_TV)
3122 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3123 cmd->args[0].v.s);
3124 break;
3126 case MP_CMD_TV_STEP_CHANNEL:
3127 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3128 int v = cmd->args[0].v.i;
3129 if (v > 0) {
3130 tv_step_channel((tvi_handle_t *) (mpctx->
3131 demuxer->priv),
3132 TV_CHANNEL_HIGHER);
3133 } else {
3134 tv_step_channel((tvi_handle_t *) (mpctx->
3135 demuxer->priv),
3136 TV_CHANNEL_LOWER);
3138 if (tv_channel_list) {
3139 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3140 "Channel: %s", tv_channel_current->name);
3141 //vo_osd_changed(OSDTYPE_SUBTITLE);
3144 #ifdef CONFIG_PVR
3145 else if (mpctx->stream &&
3146 mpctx->stream->type == STREAMTYPE_PVR) {
3147 pvr_set_channel_step(mpctx->stream, cmd->args[0].v.i);
3148 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3149 pvr_get_current_channelname(mpctx->stream),
3150 pvr_get_current_stationname(mpctx->stream));
3152 #endif /* CONFIG_PVR */
3153 #ifdef CONFIG_DVBIN
3154 if (mpctx->stream->type == STREAMTYPE_DVB) {
3155 int dir;
3156 int v = cmd->args[0].v.i;
3158 mpctx->last_dvb_step = v;
3159 if (v > 0)
3160 dir = DVB_CHANNEL_HIGHER;
3161 else
3162 dir = DVB_CHANNEL_LOWER;
3165 if (dvb_step_channel(mpctx->stream, dir)) {
3166 mpctx->stop_play = PT_NEXT_ENTRY;
3167 mpctx->dvbin_reopen = 1;
3170 #endif /* CONFIG_DVBIN */
3171 break;
3173 case MP_CMD_TV_SET_CHANNEL:
3174 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3175 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3176 cmd->args[0].v.s);
3177 if (tv_channel_list) {
3178 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3179 "Channel: %s", tv_channel_current->name);
3180 //vo_osd_changed(OSDTYPE_SUBTITLE);
3183 #ifdef CONFIG_PVR
3184 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3185 pvr_set_channel(mpctx->stream, cmd->args[0].v.s);
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 #ifdef CONFIG_DVBIN
3194 case MP_CMD_DVB_SET_CHANNEL:
3195 if (mpctx->stream->type == STREAMTYPE_DVB) {
3196 mpctx->last_dvb_step = 1;
3198 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3199 cmd->args[0].v.i)) {
3200 mpctx->stop_play = PT_NEXT_ENTRY;
3201 mpctx->dvbin_reopen = 1;
3204 break;
3205 #endif /* CONFIG_DVBIN */
3207 case MP_CMD_TV_LAST_CHANNEL:
3208 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3209 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3210 if (tv_channel_list) {
3211 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3212 "Channel: %s", tv_channel_current->name);
3213 //vo_osd_changed(OSDTYPE_SUBTITLE);
3216 #ifdef CONFIG_PVR
3217 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3218 pvr_set_lastchannel(mpctx->stream);
3219 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3220 pvr_get_current_channelname(mpctx->stream),
3221 pvr_get_current_stationname(mpctx->stream));
3223 #endif /* CONFIG_PVR */
3224 break;
3226 case MP_CMD_TV_STEP_NORM:
3227 if (mpctx->file_format == DEMUXER_TYPE_TV)
3228 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3229 break;
3231 case MP_CMD_TV_STEP_CHANNEL_LIST:
3232 if (mpctx->file_format == DEMUXER_TYPE_TV)
3233 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3234 break;
3235 #endif /* CONFIG_TV */
3236 case MP_CMD_TV_TELETEXT_ADD_DEC:
3237 if (mpctx->demuxer->teletext)
3238 teletext_control(mpctx->demuxer->teletext, TV_VBI_CONTROL_ADD_DEC,
3239 &(cmd->args[0].v.s));
3240 break;
3241 case MP_CMD_TV_TELETEXT_GO_LINK:
3242 if (mpctx->demuxer->teletext)
3243 teletext_control(mpctx->demuxer->teletext, TV_VBI_CONTROL_GO_LINK,
3244 &(cmd->args[0].v.i));
3245 break;
3247 case MP_CMD_SUB_LOAD:
3248 if (sh_video) {
3249 int n = mpctx->set_of_sub_size;
3250 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3251 if (n != mpctx->set_of_sub_size) {
3252 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3253 ++mpctx->global_sub_size;
3256 break;
3258 case MP_CMD_SUB_REMOVE:
3259 if (sh_video) {
3260 int v = cmd->args[0].v.i;
3261 if (v < 0)
3262 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3263 else if (v < mpctx->set_of_sub_size)
3264 remove_subtitle_range(mpctx, v, 1);
3266 break;
3268 case MP_CMD_GET_SUB_VISIBILITY:
3269 if (sh_video) {
3270 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3271 "ANS_SUB_VISIBILITY=%d\n", opts->sub_visibility);
3273 break;
3275 case MP_CMD_SCREENSHOT:
3276 screenshot_request(mpctx, cmd->args[0].v.i, cmd->args[1].v.i);
3277 break;
3279 case MP_CMD_VF_CHANGE_RECTANGLE:
3280 if (!sh_video)
3281 break;
3282 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3283 break;
3285 case MP_CMD_GET_TIME_LENGTH:
3286 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3287 get_time_length(mpctx));
3288 break;
3290 case MP_CMD_GET_FILENAME: {
3291 char *inf = get_metadata(mpctx, META_NAME);
3292 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n", inf);
3293 talloc_free(inf);
3294 break;
3297 case MP_CMD_GET_VIDEO_CODEC: {
3298 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3299 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3300 talloc_free(inf);
3301 break;
3304 case MP_CMD_GET_VIDEO_BITRATE: {
3305 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3306 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3307 talloc_free(inf);
3308 break;
3311 case MP_CMD_GET_VIDEO_RESOLUTION: {
3312 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3313 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3314 talloc_free(inf);
3315 break;
3318 case MP_CMD_GET_AUDIO_CODEC: {
3319 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3320 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3321 talloc_free(inf);
3322 break;
3325 case MP_CMD_GET_AUDIO_BITRATE: {
3326 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3327 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3328 talloc_free(inf);
3329 break;
3332 case MP_CMD_GET_AUDIO_SAMPLES: {
3333 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3334 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3335 talloc_free(inf);
3336 break;
3339 case MP_CMD_GET_META_TITLE: {
3340 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3341 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3342 talloc_free(inf);
3343 break;
3346 case MP_CMD_GET_META_ARTIST: {
3347 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3348 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3349 talloc_free(inf);
3350 break;
3353 case MP_CMD_GET_META_ALBUM: {
3354 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3355 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3356 talloc_free(inf);
3357 break;
3360 case MP_CMD_GET_META_YEAR: {
3361 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3362 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3363 talloc_free(inf);
3364 break;
3367 case MP_CMD_GET_META_COMMENT: {
3368 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3369 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3370 talloc_free(inf);
3371 break;
3374 case MP_CMD_GET_META_TRACK: {
3375 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3376 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3377 talloc_free(inf);
3378 break;
3381 case MP_CMD_GET_META_GENRE: {
3382 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3383 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3384 talloc_free(inf);
3385 break;
3388 case MP_CMD_GET_VO_FULLSCREEN:
3389 if (mpctx->video_out && mpctx->video_out->config_ok)
3390 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3391 break;
3393 case MP_CMD_GET_PERCENT_POS:
3394 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3395 get_percent_pos(mpctx));
3396 break;
3398 case MP_CMD_GET_TIME_POS: {
3399 float pos = get_current_time(mpctx);
3400 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3401 break;
3404 case MP_CMD_RUN:
3405 #ifndef __MINGW32__
3406 if (!fork()) {
3407 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3408 exit(0);
3410 #endif
3411 break;
3413 case MP_CMD_KEYDOWN_EVENTS:
3414 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3415 break;
3417 case MP_CMD_SET_MOUSE_POS: {
3418 int pointer_x, pointer_y;
3419 double dx, dy;
3420 pointer_x = cmd->args[0].v.i;
3421 pointer_y = cmd->args[1].v.i;
3422 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3423 #ifdef CONFIG_DVDNAV
3424 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3425 && dx > 0.0 && dy > 0.0) {
3426 int button = -1;
3427 pointer_x = (int) (dx * (double) sh_video->disp_w);
3428 pointer_y = (int) (dy * (double) sh_video->disp_h);
3429 mp_dvdnav_update_mouse_pos(mpctx->stream,
3430 pointer_x, pointer_y, &button);
3431 if (opts->osd_level > 1 && button > 0)
3432 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3433 "Selected button number %d", button);
3435 #endif
3436 break;
3439 #ifdef CONFIG_DVDNAV
3440 case MP_CMD_DVDNAV: {
3441 int button = -1;
3442 int i;
3443 enum mp_command_type command = 0;
3444 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3445 break;
3447 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3448 if (cmd->args[0].v.s &&
3449 !strcasecmp(cmd->args[0].v.s,
3450 mp_dvdnav_bindings[i].name))
3451 command = mp_dvdnav_bindings[i].cmd;
3453 mp_dvdnav_handle_input(mpctx->stream, command, &button);
3454 if (opts->osd_level > 1 && button > 0)
3455 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3456 "Selected button number %d", button);
3457 break;
3460 case MP_CMD_SWITCH_TITLE:
3461 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3462 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3463 break;
3465 #endif
3467 case MP_CMD_AF_SWITCH:
3468 if (sh_audio) {
3469 af_uninit(mpctx->mixer.afilter);
3470 af_init(mpctx->mixer.afilter);
3472 case MP_CMD_AF_ADD:
3473 case MP_CMD_AF_DEL: {
3474 if (!sh_audio)
3475 break;
3476 char *af_args = strdup(cmd->args[0].v.s);
3477 char *af_commands = af_args;
3478 char *af_command;
3479 af_instance_t *af;
3480 while ((af_command = strsep(&af_commands, ",")) != NULL) {
3481 if (cmd->id == MP_CMD_AF_DEL) {
3482 af = af_get(mpctx->mixer.afilter, af_command);
3483 if (af != NULL)
3484 af_remove(mpctx->mixer.afilter, af);
3485 } else
3486 af_add(mpctx->mixer.afilter, af_command);
3488 reinit_audio_chain(mpctx);
3489 free(af_args);
3490 break;
3492 case MP_CMD_AF_CLR:
3493 if (!sh_audio)
3494 break;
3495 af_uninit(mpctx->mixer.afilter);
3496 af_init(mpctx->mixer.afilter);
3497 reinit_audio_chain(mpctx);
3498 break;
3499 case MP_CMD_AF_CMDLINE:
3500 if (sh_audio) {
3501 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3502 if (!af) {
3503 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3504 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3505 break;
3507 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3508 af_reinit(sh_audio->afilter, af);
3510 break;
3512 default:
3513 mp_msg(MSGT_CPLAYER, MSGL_V,
3514 "Received unknown cmd %s\n", cmd->name);
3517 old_pause_hack:
3518 switch (cmd->pausing) {
3519 case 1: // "pausing"
3520 pause_player(mpctx);
3521 break;
3522 case 3: // "pausing_toggle"
3523 if (mpctx->paused)
3524 unpause_player(mpctx);
3525 else
3526 pause_player(mpctx);
3527 break;