vf_screenshot: better check for pixel format swscale support
[mplayer.git] / command.c
blob1dea8cfaab0ae9bb01da70924b8f05e0dde1b682
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 "sub/font_load.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 "libmenu/menu.h"
70 #include "mp_core.h"
71 #include "mp_fifo.h"
72 #include "libavutil/avstring.h"
74 extern int use_menu;
76 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
77 double *dx, double *dy)
79 struct MPOpts *opts = &mpctx->opts;
80 struct vo *vo = mpctx->video_out;
81 //remove the borders, if any, and rescale to the range [0,1],[0,1]
82 if (vo_fs) { //we are in full-screen mode
83 if (opts->vo_screenwidth > vo->dwidth)
84 // there are borders along the x axis
85 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
86 if (opts->vo_screenheight > vo->dheight)
87 // there are borders along the y axis (usual way)
88 iy -= (opts->vo_screenheight - vo->dheight) / 2;
90 if (ix < 0 || ix > vo->dwidth) {
91 *dx = *dy = -1.0;
92 return;
93 } //we are on one of the borders
94 if (iy < 0 || iy > vo->dheight) {
95 *dx = *dy = -1.0;
96 return;
97 } //we are on one of the borders
100 *dx = (double) ix / (double) vo->dwidth;
101 *dy = (double) iy / (double) vo->dheight;
103 mp_msg(MSGT_CPLAYER, MSGL_V,
104 "\r\nrescaled coordinates: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
105 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
106 vo->dheight, vo_fs);
109 static int sub_pos_by_source(MPContext *mpctx, int src)
111 int i, cnt = 0;
112 if (src >= SUB_SOURCES || mpctx->sub_counts[src] == 0)
113 return -1;
114 for (i = 0; i < src; i++)
115 cnt += mpctx->sub_counts[i];
116 return cnt;
119 static int sub_source_and_index_by_pos(MPContext *mpctx, int *pos)
121 int start = 0;
122 int i;
123 for (i = 0; i < SUB_SOURCES; i++) {
124 int cnt = mpctx->sub_counts[i];
125 if (*pos >= start && *pos < start + cnt) {
126 *pos -= start;
127 return i;
129 start += cnt;
131 *pos = -1;
132 return -1;
135 static int sub_source_by_pos(MPContext *mpctx, int pos)
137 return sub_source_and_index_by_pos(mpctx, &pos);
140 static int sub_source_pos(MPContext *mpctx)
142 int pos = mpctx->global_sub_pos;
143 sub_source_and_index_by_pos(mpctx, &pos);
144 return pos;
147 static int sub_source(MPContext *mpctx)
149 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
152 static void update_global_sub_size(MPContext *mpctx)
154 struct MPOpts *opts = &mpctx->opts;
155 int i;
156 int cnt = 0;
158 // update number of demuxer sub streams
159 for (i = 0; i < MAX_S_STREAMS; i++)
160 if (mpctx->d_sub->demuxer->s_streams[i])
161 cnt++;
162 if (cnt > mpctx->sub_counts[SUB_SOURCE_DEMUX])
163 mpctx->sub_counts[SUB_SOURCE_DEMUX] = cnt;
165 // update global size
166 mpctx->global_sub_size = 0;
167 for (i = 0; i < SUB_SOURCES; i++)
168 mpctx->global_sub_size += mpctx->sub_counts[i];
170 // update global_sub_pos if we auto-detected a demuxer sub
171 if (mpctx->global_sub_pos == -1) {
172 int sub_id = -1;
173 if (mpctx->demuxer->sub)
174 sub_id = mpctx->demuxer->sub->id;
175 if (sub_id < 0)
176 sub_id = opts->sub_id;
177 if (sub_id >= 0 && sub_id < mpctx->sub_counts[SUB_SOURCE_DEMUX])
178 mpctx->global_sub_pos = sub_pos_by_source(mpctx, SUB_SOURCE_DEMUX) +
179 sub_id;
184 * \brief Log the currently displayed subtitle to a file
186 * Logs the current or last displayed subtitle together with filename
187 * and time information to ~/.mplayer/subtitle_log
189 * Intended purpose is to allow convenient marking of bogus subtitles
190 * which need to be fixed while watching the movie.
193 static void log_sub(struct MPContext *mpctx)
195 char *fname;
196 FILE *f;
197 int i;
198 struct subtitle *vo_sub_last = mpctx->vo_sub_last;
200 if (mpctx->subdata == NULL || vo_sub_last == NULL)
201 return;
202 fname = get_path("subtitle_log");
203 f = fopen(fname, "a");
204 if (!f)
205 return;
206 fprintf(f, "----------------------------------------------------------\n");
207 if (mpctx->subdata->sub_uses_time) {
208 fprintf(f,
209 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
210 mpctx->filename, vo_sub_last->start / 360000,
211 (vo_sub_last->start / 6000) % 60,
212 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
213 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
214 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
215 } else {
216 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
217 vo_sub_last->start, vo_sub_last->end);
219 for (i = 0; i < vo_sub_last->lines; i++)
220 fprintf(f, "%s\n", vo_sub_last->text[i]);
221 fclose(f);
225 static int mp_property_generic_option(struct m_option *prop, int action,
226 void *arg, MPContext *mpctx)
228 char *optname = prop->priv;
229 const struct m_option *opt = m_config_get_option(mpctx->mconfig,
230 bstr(optname));
231 void *valptr = m_option_get_ptr(opt, &mpctx->opts);
233 switch (action) {
234 case M_PROPERTY_GET_TYPE:
235 *(const struct m_option **)arg = opt;
236 return M_PROPERTY_OK;
237 case M_PROPERTY_GET:
238 m_option_copy(opt, arg, valptr);
239 return M_PROPERTY_OK;
240 case M_PROPERTY_SET:
241 m_option_copy(opt, valptr, arg);
242 return M_PROPERTY_OK;
243 case M_PROPERTY_STEP_UP:
244 if (opt->type == &m_option_type_choice) {
245 int v = *(int *) valptr;
246 int best = v;
247 struct m_opt_choice_alternatives *alt;
248 for (alt = opt->priv; alt->name; alt++)
249 if ((unsigned) alt->value - v - 1 < (unsigned) best - v - 1)
250 best = alt->value;
251 *(int *) valptr = best;
252 return M_PROPERTY_OK;
254 break;
256 return M_PROPERTY_NOT_IMPLEMENTED;
259 /// OSD level (RW)
260 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
261 MPContext *mpctx)
263 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
266 /// Loop (RW)
267 static int mp_property_loop(m_option_t *prop, int action, void *arg,
268 MPContext *mpctx)
270 struct MPOpts *opts = &mpctx->opts;
271 switch (action) {
272 case M_PROPERTY_PRINT:
273 if (!arg)
274 return M_PROPERTY_ERROR;
275 if (opts->loop_times < 0)
276 *(char **)arg = talloc_strdup(NULL, "off");
277 else if (opts->loop_times == 0)
278 *(char **)arg = talloc_strdup(NULL, "inf");
279 else
280 break;
281 return M_PROPERTY_OK;
283 return m_property_int_range(prop, action, arg, &opts->loop_times);
286 /// Playback speed (RW)
287 static int mp_property_playback_speed(m_option_t *prop, int action,
288 void *arg, MPContext *mpctx)
290 struct MPOpts *opts = &mpctx->opts;
291 switch (action) {
292 case M_PROPERTY_SET:
293 if (!arg)
294 return M_PROPERTY_ERROR;
295 M_PROPERTY_CLAMP(prop, *(float *) arg);
296 opts->playback_speed = *(float *) arg;
297 reinit_audio_chain(mpctx);
298 return M_PROPERTY_OK;
299 case M_PROPERTY_STEP_UP:
300 case M_PROPERTY_STEP_DOWN:
301 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
302 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
303 M_PROPERTY_CLAMP(prop, opts->playback_speed);
304 reinit_audio_chain(mpctx);
305 return M_PROPERTY_OK;
307 return m_property_float_range(prop, action, arg, &opts->playback_speed);
310 /// filename with path (RO)
311 static int mp_property_path(m_option_t *prop, int action, void *arg,
312 MPContext *mpctx)
314 return m_property_string_ro(prop, action, arg, mpctx->filename);
317 /// filename without path (RO)
318 static int mp_property_filename(m_option_t *prop, int action, void *arg,
319 MPContext *mpctx)
321 char *f;
322 if (!mpctx->filename)
323 return M_PROPERTY_UNAVAILABLE;
324 f = (char *)mp_basename(mpctx->filename);
325 if (!*f)
326 f = mpctx->filename;
327 return m_property_string_ro(prop, action, arg, f);
330 /// Demuxer name (RO)
331 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
332 MPContext *mpctx)
334 if (!mpctx->demuxer)
335 return M_PROPERTY_UNAVAILABLE;
336 return m_property_string_ro(prop, action, arg,
337 (char *) mpctx->demuxer->desc->name);
340 /// Position in the stream (RW)
341 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
342 MPContext *mpctx)
344 if (!mpctx->demuxer || !mpctx->demuxer->stream)
345 return M_PROPERTY_UNAVAILABLE;
346 if (!arg)
347 return M_PROPERTY_ERROR;
348 switch (action) {
349 case M_PROPERTY_GET:
350 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
351 return M_PROPERTY_OK;
352 case M_PROPERTY_SET:
353 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
354 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
355 return M_PROPERTY_OK;
357 return M_PROPERTY_NOT_IMPLEMENTED;
360 /// Stream start offset (RO)
361 static int mp_property_stream_start(m_option_t *prop, int action,
362 void *arg, MPContext *mpctx)
364 if (!mpctx->demuxer || !mpctx->demuxer->stream)
365 return M_PROPERTY_UNAVAILABLE;
366 switch (action) {
367 case M_PROPERTY_GET:
368 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
369 return M_PROPERTY_OK;
371 return M_PROPERTY_NOT_IMPLEMENTED;
374 /// Stream end offset (RO)
375 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
376 MPContext *mpctx)
378 if (!mpctx->demuxer || !mpctx->demuxer->stream)
379 return M_PROPERTY_UNAVAILABLE;
380 switch (action) {
381 case M_PROPERTY_GET:
382 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
383 return M_PROPERTY_OK;
385 return M_PROPERTY_NOT_IMPLEMENTED;
388 /// Stream length (RO)
389 static int mp_property_stream_length(m_option_t *prop, int action,
390 void *arg, MPContext *mpctx)
392 if (!mpctx->demuxer || !mpctx->demuxer->stream)
393 return M_PROPERTY_UNAVAILABLE;
394 switch (action) {
395 case M_PROPERTY_GET:
396 *(off_t *) arg =
397 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
398 return M_PROPERTY_OK;
400 return M_PROPERTY_NOT_IMPLEMENTED;
403 /// Current stream position in seconds (RO)
404 static int mp_property_stream_time_pos(m_option_t *prop, int action,
405 void *arg, MPContext *mpctx)
407 if (!mpctx->demuxer || mpctx->demuxer->stream_pts == MP_NOPTS_VALUE)
408 return M_PROPERTY_UNAVAILABLE;
410 return m_property_time_ro(prop, action, arg, mpctx->demuxer->stream_pts);
414 /// Media length in seconds (RO)
415 static int mp_property_length(m_option_t *prop, int action, void *arg,
416 MPContext *mpctx)
418 double len;
420 if (!mpctx->demuxer ||
421 !(int) (len = get_time_length(mpctx)))
422 return M_PROPERTY_UNAVAILABLE;
424 return m_property_time_ro(prop, action, arg, len);
427 /// Current position in percent (RW)
428 static int mp_property_percent_pos(m_option_t *prop, int action,
429 void *arg, MPContext *mpctx)
431 int pos;
433 if (!mpctx->demuxer)
434 return M_PROPERTY_UNAVAILABLE;
436 switch (action) {
437 case M_PROPERTY_SET:
438 if (!arg)
439 return M_PROPERTY_ERROR;
440 M_PROPERTY_CLAMP(prop, *(int *)arg);
441 pos = *(int *)arg;
442 break;
443 case M_PROPERTY_STEP_UP:
444 case M_PROPERTY_STEP_DOWN:
445 pos = get_percent_pos(mpctx);
446 pos += (arg ? *(int *)arg : 10) *
447 (action == M_PROPERTY_STEP_UP ? 1 : -1);
448 M_PROPERTY_CLAMP(prop, pos);
449 break;
450 default:
451 return m_property_int_ro(prop, action, arg, get_percent_pos(mpctx));
454 queue_seek(mpctx, MPSEEK_FACTOR, pos / 100.0, 0);
455 return M_PROPERTY_OK;
458 /// Current position in seconds (RW)
459 static int mp_property_time_pos(m_option_t *prop, int action,
460 void *arg, MPContext *mpctx)
462 if (!(mpctx->sh_video || mpctx->sh_audio))
463 return M_PROPERTY_UNAVAILABLE;
465 switch (action) {
466 case M_PROPERTY_SET:
467 if (!arg)
468 return M_PROPERTY_ERROR;
469 M_PROPERTY_CLAMP(prop, *(double *)arg);
470 queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double *)arg, 0);
471 return M_PROPERTY_OK;
472 case M_PROPERTY_STEP_UP:
473 case M_PROPERTY_STEP_DOWN:
474 queue_seek(mpctx, MPSEEK_RELATIVE, (arg ? *(double *)arg : 10.0) *
475 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0), 0);
476 return M_PROPERTY_OK;
478 return m_property_time_ro(prop, action, arg, get_current_time(mpctx));
481 /// Current chapter (RW)
482 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
483 MPContext *mpctx)
485 struct MPOpts *opts = &mpctx->opts;
486 int chapter = -1;
487 int step_all;
488 char *chapter_name = NULL;
490 if (mpctx->demuxer)
491 chapter = get_current_chapter(mpctx);
492 if (chapter < -1)
493 return M_PROPERTY_UNAVAILABLE;
495 switch (action) {
496 case M_PROPERTY_GET:
497 if (!arg)
498 return M_PROPERTY_ERROR;
499 *(int *) arg = chapter;
500 return M_PROPERTY_OK;
501 case M_PROPERTY_PRINT: {
502 if (!arg)
503 return M_PROPERTY_ERROR;
504 chapter_name = chapter_display_name(mpctx, chapter);
505 if (!chapter_name)
506 return M_PROPERTY_UNAVAILABLE;
507 *(char **) arg = chapter_name;
508 return M_PROPERTY_OK;
510 case M_PROPERTY_SET:
511 if (!arg)
512 return M_PROPERTY_ERROR;
513 M_PROPERTY_CLAMP(prop, *(int *)arg);
514 step_all = *(int *)arg - chapter;
515 chapter += step_all;
516 break;
517 case M_PROPERTY_STEP_UP:
518 case M_PROPERTY_STEP_DOWN: {
519 step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1)
520 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
521 chapter += step_all;
522 if (chapter < 0)
523 chapter = 0;
524 break;
526 default:
527 return M_PROPERTY_NOT_IMPLEMENTED;
530 double next_pts = 0;
531 queue_seek(mpctx, MPSEEK_NONE, 0, 0);
532 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
533 if (chapter >= 0) {
534 if (next_pts > -1.0)
535 queue_seek(mpctx, MPSEEK_ABSOLUTE, next_pts, 0);
536 if (chapter_name)
537 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
538 "Chapter: (%d) %s", chapter + 1, chapter_name);
539 } else if (step_all > 0)
540 queue_seek(mpctx, MPSEEK_RELATIVE, 1000000000, 0);
541 else
542 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
543 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
544 talloc_free(chapter_name);
545 return M_PROPERTY_OK;
548 /// Number of chapters in file
549 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
550 MPContext *mpctx)
552 if (!mpctx->demuxer)
553 return M_PROPERTY_UNAVAILABLE;
554 if (mpctx->demuxer->num_chapters == 0)
555 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS,
556 &mpctx->demuxer->num_chapters);
557 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
560 /// Current dvd angle (RW)
561 static int mp_property_angle(m_option_t *prop, int action, void *arg,
562 MPContext *mpctx)
564 struct MPOpts *opts = &mpctx->opts;
565 int angle = -1;
566 int angles;
568 if (mpctx->demuxer)
569 angle = demuxer_get_current_angle(mpctx->demuxer);
570 if (angle < 0)
571 return M_PROPERTY_UNAVAILABLE;
572 angles = demuxer_angles_count(mpctx->demuxer);
573 if (angles <= 1)
574 return M_PROPERTY_UNAVAILABLE;
576 switch (action) {
577 case M_PROPERTY_GET:
578 if (!arg)
579 return M_PROPERTY_ERROR;
580 *(int *) arg = angle;
581 return M_PROPERTY_OK;
582 case M_PROPERTY_PRINT: {
583 if (!arg)
584 return M_PROPERTY_ERROR;
585 *(char **) arg = talloc_asprintf(NULL, "%d/%d", angle, angles);
586 return M_PROPERTY_OK;
588 case M_PROPERTY_SET:
589 if (!arg)
590 return M_PROPERTY_ERROR;
591 angle = *(int *)arg;
592 M_PROPERTY_CLAMP(prop, angle);
593 break;
594 case M_PROPERTY_STEP_UP:
595 case M_PROPERTY_STEP_DOWN: {
596 int step = 0;
597 if (arg)
598 step = *(int *)arg;
599 if (!step)
600 step = 1;
601 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
602 angle += step;
603 if (angle < 1) //cycle
604 angle = angles;
605 else if (angle > angles)
606 angle = 1;
607 break;
609 default:
610 return M_PROPERTY_NOT_IMPLEMENTED;
612 angle = demuxer_set_angle(mpctx->demuxer, angle);
613 if (angle >= 0) {
614 struct sh_video *sh_video = mpctx->demuxer->video->sh;
615 if (sh_video)
616 resync_video_stream(sh_video);
618 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
619 if (sh_audio)
620 resync_audio_stream(sh_audio);
623 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
624 "Angle: %d/%d", angle, angles);
625 return M_PROPERTY_OK;
628 /// Demuxer meta data
629 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
630 MPContext *mpctx)
632 m_property_action_t *ka;
633 char *meta;
634 static const m_option_t key_type =
636 "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL
638 if (!mpctx->demuxer)
639 return M_PROPERTY_UNAVAILABLE;
641 switch (action) {
642 case M_PROPERTY_GET:
643 if (!arg)
644 return M_PROPERTY_ERROR;
645 *(char ***)arg = mpctx->demuxer->info;
646 return M_PROPERTY_OK;
647 case M_PROPERTY_KEY_ACTION:
648 if (!arg)
649 return M_PROPERTY_ERROR;
650 ka = arg;
651 if (!(meta = demux_info_get(mpctx->demuxer, ka->key)))
652 return M_PROPERTY_UNKNOWN;
653 switch (ka->action) {
654 case M_PROPERTY_GET:
655 if (!ka->arg)
656 return M_PROPERTY_ERROR;
657 *(char **)ka->arg = meta;
658 return M_PROPERTY_OK;
659 case M_PROPERTY_GET_TYPE:
660 if (!ka->arg)
661 return M_PROPERTY_ERROR;
662 *(const m_option_t **)ka->arg = &key_type;
663 return M_PROPERTY_OK;
666 return M_PROPERTY_NOT_IMPLEMENTED;
669 static int mp_property_pause(m_option_t *prop, int action, void *arg,
670 void *ctx)
672 MPContext *mpctx = ctx;
674 switch (action) {
675 case M_PROPERTY_SET:
676 if (!arg)
677 return M_PROPERTY_ERROR;
678 if (mpctx->paused == (bool) * (int *)arg)
679 return M_PROPERTY_OK;
680 case M_PROPERTY_STEP_UP:
681 case M_PROPERTY_STEP_DOWN:
682 if (mpctx->paused) {
683 unpause_player(mpctx);
684 mpctx->osd_function = OSD_PLAY;
685 } else {
686 pause_player(mpctx);
687 mpctx->osd_function = OSD_PAUSE;
689 return M_PROPERTY_OK;
690 default:
691 return m_property_flag(prop, action, arg, &mpctx->paused);
696 /// Volume (RW)
697 static int mp_property_volume(m_option_t *prop, int action, void *arg,
698 MPContext *mpctx)
701 if (!mpctx->sh_audio)
702 return M_PROPERTY_UNAVAILABLE;
704 switch (action) {
705 case M_PROPERTY_GET:
706 if (!arg)
707 return M_PROPERTY_ERROR;
708 mixer_getbothvolume(&mpctx->mixer, arg);
709 return M_PROPERTY_OK;
710 case M_PROPERTY_PRINT: {
711 float vol;
712 if (!arg)
713 return M_PROPERTY_ERROR;
714 mixer_getbothvolume(&mpctx->mixer, &vol);
715 return m_property_float_range(prop, action, arg, &vol);
717 case M_PROPERTY_STEP_UP:
718 case M_PROPERTY_STEP_DOWN:
719 case M_PROPERTY_SET:
720 break;
721 default:
722 return M_PROPERTY_NOT_IMPLEMENTED;
725 if (mpctx->edl_muted)
726 return M_PROPERTY_DISABLED;
727 mpctx->user_muted = 0;
729 switch (action) {
730 case M_PROPERTY_SET:
731 if (!arg)
732 return M_PROPERTY_ERROR;
733 M_PROPERTY_CLAMP(prop, *(float *) arg);
734 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
735 return M_PROPERTY_OK;
736 case M_PROPERTY_STEP_UP:
737 if (arg && *(float *) arg <= 0)
738 mixer_decvolume(&mpctx->mixer);
739 else
740 mixer_incvolume(&mpctx->mixer);
741 return M_PROPERTY_OK;
742 case M_PROPERTY_STEP_DOWN:
743 if (arg && *(float *) arg <= 0)
744 mixer_incvolume(&mpctx->mixer);
745 else
746 mixer_decvolume(&mpctx->mixer);
747 return M_PROPERTY_OK;
749 return M_PROPERTY_NOT_IMPLEMENTED;
752 /// Mute (RW)
753 static int mp_property_mute(m_option_t *prop, int action, void *arg,
754 MPContext *mpctx)
757 if (!mpctx->sh_audio)
758 return M_PROPERTY_UNAVAILABLE;
760 switch (action) {
761 case M_PROPERTY_SET:
762 if (mpctx->edl_muted)
763 return M_PROPERTY_DISABLED;
764 if (!arg)
765 return M_PROPERTY_ERROR;
766 if ((!!*(int *) arg) != mpctx->mixer.muted)
767 mixer_mute(&mpctx->mixer);
768 mpctx->user_muted = mpctx->mixer.muted;
769 return M_PROPERTY_OK;
770 case M_PROPERTY_STEP_UP:
771 case M_PROPERTY_STEP_DOWN:
772 if (mpctx->edl_muted)
773 return M_PROPERTY_DISABLED;
774 mixer_mute(&mpctx->mixer);
775 mpctx->user_muted = mpctx->mixer.muted;
776 return M_PROPERTY_OK;
777 case M_PROPERTY_PRINT:
778 if (!arg)
779 return M_PROPERTY_ERROR;
780 if (mpctx->edl_muted) {
781 *(char **) arg = talloc_strdup(NULL, mp_gtext("enabled (EDL)"));
782 return M_PROPERTY_OK;
784 default:
785 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
790 /// Audio delay (RW)
791 static int mp_property_audio_delay(m_option_t *prop, int action,
792 void *arg, MPContext *mpctx)
794 if (!(mpctx->sh_audio && mpctx->sh_video))
795 return M_PROPERTY_UNAVAILABLE;
796 switch (action) {
797 case M_PROPERTY_SET:
798 case M_PROPERTY_STEP_UP:
799 case M_PROPERTY_STEP_DOWN: {
800 int ret;
801 float delay = audio_delay;
802 ret = m_property_delay(prop, action, arg, &audio_delay);
803 if (ret != M_PROPERTY_OK)
804 return ret;
805 if (mpctx->sh_audio)
806 mpctx->delay -= audio_delay - delay;
808 return M_PROPERTY_OK;
809 default:
810 return m_property_delay(prop, action, arg, &audio_delay);
814 /// Audio codec tag (RO)
815 static int mp_property_audio_format(m_option_t *prop, int action,
816 void *arg, MPContext *mpctx)
818 if (!mpctx->sh_audio)
819 return M_PROPERTY_UNAVAILABLE;
820 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
823 /// Audio codec name (RO)
824 static int mp_property_audio_codec(m_option_t *prop, int action,
825 void *arg, MPContext *mpctx)
827 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
828 return M_PROPERTY_UNAVAILABLE;
829 return m_property_string_ro(prop, action, arg,
830 mpctx->sh_audio->codec->name);
833 /// Audio bitrate (RO)
834 static int mp_property_audio_bitrate(m_option_t *prop, int action,
835 void *arg, MPContext *mpctx)
837 if (!mpctx->sh_audio)
838 return M_PROPERTY_UNAVAILABLE;
839 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
842 /// Samplerate (RO)
843 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
844 MPContext *mpctx)
846 if (!mpctx->sh_audio)
847 return M_PROPERTY_UNAVAILABLE;
848 switch (action) {
849 case M_PROPERTY_PRINT:
850 if (!arg)
851 return M_PROPERTY_ERROR;
852 *(char **)arg = talloc_asprintf(NULL, "%d kHz",
853 mpctx->sh_audio->samplerate / 1000);
854 return M_PROPERTY_OK;
856 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
859 /// Number of channels (RO)
860 static int mp_property_channels(m_option_t *prop, int action, void *arg,
861 MPContext *mpctx)
863 if (!mpctx->sh_audio)
864 return M_PROPERTY_UNAVAILABLE;
865 switch (action) {
866 case M_PROPERTY_PRINT:
867 if (!arg)
868 return M_PROPERTY_ERROR;
869 switch (mpctx->sh_audio->channels) {
870 case 1:
871 *(char **) arg = talloc_strdup(NULL, "mono");
872 break;
873 case 2:
874 *(char **) arg = talloc_strdup(NULL, "stereo");
875 break;
876 default:
877 *(char **) arg = talloc_asprintf(NULL, "%d channels",
878 mpctx->sh_audio->channels);
880 return M_PROPERTY_OK;
882 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
885 /// Balance (RW)
886 static int mp_property_balance(m_option_t *prop, int action, void *arg,
887 MPContext *mpctx)
889 float bal;
891 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
892 return M_PROPERTY_UNAVAILABLE;
894 switch (action) {
895 case M_PROPERTY_GET:
896 if (!arg)
897 return M_PROPERTY_ERROR;
898 mixer_getbalance(&mpctx->mixer, arg);
899 return M_PROPERTY_OK;
900 case M_PROPERTY_PRINT: {
901 char **str = arg;
902 if (!arg)
903 return M_PROPERTY_ERROR;
904 mixer_getbalance(&mpctx->mixer, &bal);
905 if (bal == 0.f)
906 *str = talloc_strdup(NULL, "center");
907 else if (bal == -1.f)
908 *str = talloc_strdup(NULL, "left only");
909 else if (bal == 1.f)
910 *str = talloc_strdup(NULL, "right only");
911 else {
912 unsigned right = (bal + 1.f) / 2.f * 100.f;
913 *str = talloc_asprintf(NULL, "left %d%%, right %d%%",
914 100 - right, right);
916 return M_PROPERTY_OK;
918 case M_PROPERTY_STEP_UP:
919 case M_PROPERTY_STEP_DOWN:
920 mixer_getbalance(&mpctx->mixer, &bal);
921 bal += (arg ? *(float *)arg : .1f) *
922 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
923 M_PROPERTY_CLAMP(prop, bal);
924 mixer_setbalance(&mpctx->mixer, bal);
925 return M_PROPERTY_OK;
926 case M_PROPERTY_SET:
927 if (!arg)
928 return M_PROPERTY_ERROR;
929 M_PROPERTY_CLAMP(prop, *(float *)arg);
930 mixer_setbalance(&mpctx->mixer, *(float *)arg);
931 return M_PROPERTY_OK;
933 return M_PROPERTY_NOT_IMPLEMENTED;
936 /// Selected audio id (RW)
937 static int mp_property_audio(m_option_t *prop, int action, void *arg,
938 MPContext *mpctx)
940 int current_id, tmp;
941 if (!mpctx->demuxer || !mpctx->d_audio)
942 return M_PROPERTY_UNAVAILABLE;
943 struct sh_audio *sh = mpctx->sh_audio;
944 current_id = sh ? sh->aid : -2;
946 switch (action) {
947 case M_PROPERTY_GET:
948 if (!arg)
949 return M_PROPERTY_ERROR;
950 *(int *) arg = current_id;
951 return M_PROPERTY_OK;
952 case M_PROPERTY_PRINT:
953 if (!arg)
954 return M_PROPERTY_ERROR;
956 if (current_id < 0)
957 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
958 else if (sh && (sh->lang || sh->title)) {
959 char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
960 if (sh->title)
961 *(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
962 current_id, lang, sh->title);
963 else
964 *(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id,
965 lang);
966 } else {
967 char lang[40];
968 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
969 if (0) ;
970 #ifdef CONFIG_DVDREAD
971 else if (mpctx->stream->type == STREAMTYPE_DVD) {
972 int code = dvd_lang_from_aid(mpctx->stream, current_id);
973 if (code) {
974 lang[0] = code >> 8;
975 lang[1] = code;
976 lang[2] = 0;
979 #endif
981 #ifdef CONFIG_DVDNAV
982 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
983 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
984 #endif
985 *(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id, lang);
987 return M_PROPERTY_OK;
989 case M_PROPERTY_STEP_UP:
990 case M_PROPERTY_SET:
991 if (action == M_PROPERTY_SET && arg)
992 tmp = *((int *) arg);
993 else
994 tmp = -1;
995 int new_id = demuxer_switch_audio(mpctx->d_audio->demuxer, tmp);
996 if (new_id != current_id)
997 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
998 if (new_id != current_id && new_id >= 0) {
999 sh_audio_t *sh2;
1000 sh2 = mpctx->d_audio->demuxer->a_streams[mpctx->d_audio->id];
1001 sh2->ds = mpctx->d_audio;
1002 mpctx->sh_audio = sh2;
1003 reinit_audio_chain(mpctx);
1005 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
1006 return M_PROPERTY_OK;
1007 default:
1008 return M_PROPERTY_NOT_IMPLEMENTED;
1013 /// Selected video id (RW)
1014 static int mp_property_video(m_option_t *prop, int action, void *arg,
1015 MPContext *mpctx)
1017 struct MPOpts *opts = &mpctx->opts;
1018 int current_id, tmp;
1019 if (!mpctx->demuxer || !mpctx->d_video)
1020 return M_PROPERTY_UNAVAILABLE;
1021 current_id = mpctx->sh_video ? mpctx->sh_video->vid : -2;
1023 switch (action) {
1024 case M_PROPERTY_GET:
1025 if (!arg)
1026 return M_PROPERTY_ERROR;
1027 *(int *) arg = current_id;
1028 return M_PROPERTY_OK;
1029 case M_PROPERTY_PRINT:
1030 if (!arg)
1031 return M_PROPERTY_ERROR;
1033 if (current_id < 0)
1034 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1035 else {
1036 *(char **) arg = talloc_asprintf(NULL, "(%d) %s", current_id,
1037 mp_gtext("unknown"));
1039 return M_PROPERTY_OK;
1041 case M_PROPERTY_STEP_UP:
1042 case M_PROPERTY_SET:
1043 if (action == M_PROPERTY_SET && arg)
1044 tmp = *((int *) arg);
1045 else
1046 tmp = -1;
1047 int new_id = demuxer_switch_video(mpctx->d_video->demuxer, tmp);
1048 if (new_id != current_id)
1049 uninit_player(mpctx, INITIALIZED_VCODEC |
1050 (opts->fixed_vo && new_id >= 0 ? 0 : INITIALIZED_VO));
1051 if (new_id != current_id && new_id >= 0) {
1052 sh_video_t *sh2;
1053 sh2 = mpctx->d_video->demuxer->v_streams[mpctx->d_video->id];
1054 sh2->ds = mpctx->d_video;
1055 mpctx->sh_video = sh2;
1056 reinit_video_chain(mpctx);
1058 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", new_id);
1059 return M_PROPERTY_OK;
1061 default:
1062 return M_PROPERTY_NOT_IMPLEMENTED;
1066 static int mp_property_program(m_option_t *prop, int action, void *arg,
1067 MPContext *mpctx)
1069 demux_program_t prog;
1071 switch (action) {
1072 case M_PROPERTY_STEP_UP:
1073 case M_PROPERTY_SET:
1074 if (action == M_PROPERTY_SET && arg)
1075 prog.progid = *((int *) arg);
1076 else
1077 prog.progid = -1;
1078 if (demux_control(mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1079 &prog) == DEMUXER_CTRL_NOTIMPL)
1080 return M_PROPERTY_ERROR;
1082 if (prog.aid < 0 && prog.vid < 0) {
1083 mp_msg(MSGT_CPLAYER, MSGL_ERR,
1084 "Selected program contains no audio or video streams!\n");
1085 return M_PROPERTY_ERROR;
1087 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1088 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1089 return M_PROPERTY_OK;
1091 default:
1092 return M_PROPERTY_NOT_IMPLEMENTED;
1097 /// Fullscreen state (RW)
1098 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1099 MPContext *mpctx)
1102 if (!mpctx->video_out)
1103 return M_PROPERTY_UNAVAILABLE;
1105 switch (action) {
1106 case M_PROPERTY_SET:
1107 if (!arg)
1108 return M_PROPERTY_ERROR;
1109 M_PROPERTY_CLAMP(prop, *(int *) arg);
1110 if (vo_fs == !!*(int *) arg)
1111 return M_PROPERTY_OK;
1112 case M_PROPERTY_STEP_UP:
1113 case M_PROPERTY_STEP_DOWN:
1114 if (mpctx->video_out->config_ok)
1115 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1116 mpctx->opts.fullscreen = vo_fs;
1117 return M_PROPERTY_OK;
1118 default:
1119 return m_property_flag(prop, action, arg, &vo_fs);
1123 static int mp_property_deinterlace(m_option_t *prop, int action,
1124 void *arg, MPContext *mpctx)
1126 int deinterlace;
1127 vf_instance_t *vf;
1128 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1129 return M_PROPERTY_UNAVAILABLE;
1130 vf = mpctx->sh_video->vfilter;
1131 switch (action) {
1132 case M_PROPERTY_GET:
1133 if (!arg)
1134 return M_PROPERTY_ERROR;
1135 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1136 return M_PROPERTY_OK;
1137 case M_PROPERTY_SET:
1138 if (!arg)
1139 return M_PROPERTY_ERROR;
1140 M_PROPERTY_CLAMP(prop, *(int *) arg);
1141 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1142 return M_PROPERTY_OK;
1143 case M_PROPERTY_STEP_UP:
1144 case M_PROPERTY_STEP_DOWN:
1145 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1146 deinterlace = !deinterlace;
1147 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1148 return M_PROPERTY_OK;
1150 int value = 0;
1151 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1152 return m_property_flag_ro(prop, action, arg, value);
1155 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1156 void *arg, MPContext *mpctx)
1158 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1159 return M_PROPERTY_UNAVAILABLE;
1161 struct vf_instance *vf = mpctx->sh_video->vfilter;
1162 int colorspace;
1163 switch (action) {
1164 case M_PROPERTY_GET:
1165 if (!arg)
1166 return M_PROPERTY_ERROR;
1167 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1168 return M_PROPERTY_UNAVAILABLE;
1169 return M_PROPERTY_OK;
1170 case M_PROPERTY_PRINT:
1171 if (!arg)
1172 return M_PROPERTY_ERROR;
1173 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1174 return M_PROPERTY_UNAVAILABLE;
1175 char *const names[] = {
1176 "BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"
1178 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1179 *(char **)arg = talloc_strdup(NULL, mp_gtext("unknown"));
1180 else
1181 *(char **)arg = talloc_strdup(NULL, names[colorspace]);
1182 return M_PROPERTY_OK;
1183 case M_PROPERTY_SET:
1184 if (!arg)
1185 return M_PROPERTY_ERROR;
1186 M_PROPERTY_CLAMP(prop, *(int *) arg);
1187 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1188 return M_PROPERTY_OK;
1189 case M_PROPERTY_STEP_UP:;
1190 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1191 return M_PROPERTY_UNAVAILABLE;
1192 colorspace += 1;
1193 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1194 return M_PROPERTY_OK;
1196 return M_PROPERTY_NOT_IMPLEMENTED;
1199 static int mp_property_capture(m_option_t *prop, int action,
1200 void *arg, MPContext *mpctx)
1202 struct MPOpts *opts = &mpctx->opts;
1204 if (!mpctx->stream)
1205 return M_PROPERTY_UNAVAILABLE;
1207 if (!opts->capture_dump) {
1208 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1209 "Capturing not enabled (forgot -capture parameter?)\n");
1210 return M_PROPERTY_ERROR;
1213 int capturing = !!mpctx->stream->capture_file;
1215 int ret = m_property_flag(prop, action, arg, &capturing);
1216 if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
1217 if (capturing) {
1218 mpctx->stream->capture_file = fopen(opts->stream_dump_name, "wb");
1219 if (!mpctx->stream->capture_file) {
1220 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1221 "Error opening capture file: %s\n", strerror(errno));
1222 ret = M_PROPERTY_ERROR;
1224 } else {
1225 fclose(mpctx->stream->capture_file);
1226 mpctx->stream->capture_file = NULL;
1230 return ret;
1233 /// Panscan (RW)
1234 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1235 MPContext *mpctx)
1238 if (!mpctx->video_out
1239 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1240 return M_PROPERTY_UNAVAILABLE;
1242 switch (action) {
1243 case M_PROPERTY_SET:
1244 if (!arg)
1245 return M_PROPERTY_ERROR;
1246 M_PROPERTY_CLAMP(prop, *(float *) arg);
1247 vo_panscan = *(float *) arg;
1248 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1249 return M_PROPERTY_OK;
1250 case M_PROPERTY_STEP_UP:
1251 case M_PROPERTY_STEP_DOWN:
1252 vo_panscan += (arg ? *(float *) arg : 0.1) *
1253 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1254 if (vo_panscan > 1)
1255 vo_panscan = 1;
1256 else if (vo_panscan < 0)
1257 vo_panscan = 0;
1258 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1259 return M_PROPERTY_OK;
1260 default:
1261 return m_property_float_range(prop, action, arg, &vo_panscan);
1265 /// Helper to set vo flags.
1266 /** \ingroup PropertyImplHelper
1268 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1269 int vo_ctrl, int *vo_var, MPContext *mpctx)
1272 if (!mpctx->video_out)
1273 return M_PROPERTY_UNAVAILABLE;
1275 switch (action) {
1276 case M_PROPERTY_SET:
1277 if (!arg)
1278 return M_PROPERTY_ERROR;
1279 M_PROPERTY_CLAMP(prop, *(int *) arg);
1280 if (*vo_var == !!*(int *) arg)
1281 return M_PROPERTY_OK;
1282 case M_PROPERTY_STEP_UP:
1283 case M_PROPERTY_STEP_DOWN:
1284 if (mpctx->video_out->config_ok)
1285 vo_control(mpctx->video_out, vo_ctrl, 0);
1286 return M_PROPERTY_OK;
1287 default:
1288 return m_property_flag(prop, action, arg, vo_var);
1292 /// Window always on top (RW)
1293 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1294 MPContext *mpctx)
1296 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1297 &mpctx->opts.vo_ontop, mpctx);
1300 /// Display in the root window (RW)
1301 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1302 MPContext *mpctx)
1304 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1305 &vo_rootwin, mpctx);
1308 /// Show window borders (RW)
1309 static int mp_property_border(m_option_t *prop, int action, void *arg,
1310 MPContext *mpctx)
1312 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1313 &vo_border, mpctx);
1316 /// Framedropping state (RW)
1317 static int mp_property_framedropping(m_option_t *prop, int action,
1318 void *arg, MPContext *mpctx)
1321 if (!mpctx->sh_video)
1322 return M_PROPERTY_UNAVAILABLE;
1324 switch (action) {
1325 case M_PROPERTY_PRINT:
1326 if (!arg)
1327 return M_PROPERTY_ERROR;
1328 *(char **) arg = talloc_strdup(NULL, frame_dropping == 1 ?
1329 mp_gtext("enabled") :
1330 (frame_dropping == 2 ? mp_gtext("hard") :
1331 mp_gtext("disabled")));
1332 return M_PROPERTY_OK;
1333 default:
1334 return m_property_choice(prop, action, arg, &frame_dropping);
1338 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1339 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1340 MPContext *mpctx)
1342 int *gamma = (int *)((char *)&mpctx->opts + prop->offset);
1343 int r, val;
1345 if (!mpctx->sh_video)
1346 return M_PROPERTY_UNAVAILABLE;
1348 if (gamma[0] == 1000) {
1349 gamma[0] = 0;
1350 get_video_colors(mpctx->sh_video, prop->name, gamma);
1353 switch (action) {
1354 case M_PROPERTY_SET:
1355 if (!arg)
1356 return M_PROPERTY_ERROR;
1357 M_PROPERTY_CLAMP(prop, *(int *) arg);
1358 *gamma = *(int *) arg;
1359 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1360 if (r <= 0)
1361 break;
1362 return r;
1363 case M_PROPERTY_GET:
1364 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1365 if (!arg)
1366 return M_PROPERTY_ERROR;
1367 *(int *)arg = val;
1368 return M_PROPERTY_OK;
1370 break;
1371 case M_PROPERTY_STEP_UP:
1372 case M_PROPERTY_STEP_DOWN:
1373 *gamma += (arg ? *(int *) arg : 1) *
1374 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1375 M_PROPERTY_CLAMP(prop, *gamma);
1376 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1377 if (r <= 0)
1378 break;
1379 return r;
1380 default:
1381 return M_PROPERTY_NOT_IMPLEMENTED;
1384 #ifdef CONFIG_TV
1385 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1386 int l = strlen(prop->name);
1387 char tv_prop[3 + l + 1];
1388 sprintf(tv_prop, "tv_%s", prop->name);
1389 return mp_property_do(tv_prop, action, arg, mpctx);
1391 #endif
1393 return M_PROPERTY_UNAVAILABLE;
1396 /// VSync (RW)
1397 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1398 MPContext *mpctx)
1400 return m_property_flag(prop, action, arg, &vo_vsync);
1403 /// Video codec tag (RO)
1404 static int mp_property_video_format(m_option_t *prop, int action,
1405 void *arg, MPContext *mpctx)
1407 char *meta;
1408 if (!mpctx->sh_video)
1409 return M_PROPERTY_UNAVAILABLE;
1410 switch (action) {
1411 case M_PROPERTY_PRINT:
1412 if (!arg)
1413 return M_PROPERTY_ERROR;
1414 switch (mpctx->sh_video->format) {
1415 case 0x10000001:
1416 meta = talloc_strdup(NULL, "mpeg1");
1417 break;
1418 case 0x10000002:
1419 meta = talloc_strdup(NULL, "mpeg2");
1420 break;
1421 case 0x10000004:
1422 meta = talloc_strdup(NULL, "mpeg4");
1423 break;
1424 case 0x10000005:
1425 meta = talloc_strdup(NULL, "h264");
1426 break;
1427 default:
1428 if (mpctx->sh_video->format >= 0x20202020) {
1429 meta = talloc_asprintf(NULL, "%.4s",
1430 (char *) &mpctx->sh_video->format);
1431 } else
1432 meta = talloc_asprintf(NULL, "0x%08X", mpctx->sh_video->format);
1434 *(char **)arg = meta;
1435 return M_PROPERTY_OK;
1437 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1440 /// Video codec name (RO)
1441 static int mp_property_video_codec(m_option_t *prop, int action,
1442 void *arg, MPContext *mpctx)
1444 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1445 return M_PROPERTY_UNAVAILABLE;
1446 return m_property_string_ro(prop, action, arg,
1447 mpctx->sh_video->codec->name);
1451 /// Video bitrate (RO)
1452 static int mp_property_video_bitrate(m_option_t *prop, int action,
1453 void *arg, MPContext *mpctx)
1455 if (!mpctx->sh_video)
1456 return M_PROPERTY_UNAVAILABLE;
1457 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1460 /// Video display width (RO)
1461 static int mp_property_width(m_option_t *prop, int action, void *arg,
1462 MPContext *mpctx)
1464 if (!mpctx->sh_video)
1465 return M_PROPERTY_UNAVAILABLE;
1466 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1469 /// Video display height (RO)
1470 static int mp_property_height(m_option_t *prop, int action, void *arg,
1471 MPContext *mpctx)
1473 if (!mpctx->sh_video)
1474 return M_PROPERTY_UNAVAILABLE;
1475 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1478 /// Video fps (RO)
1479 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1480 MPContext *mpctx)
1482 if (!mpctx->sh_video)
1483 return M_PROPERTY_UNAVAILABLE;
1484 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1487 /// Video aspect (RO)
1488 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1489 MPContext *mpctx)
1491 if (!mpctx->sh_video)
1492 return M_PROPERTY_UNAVAILABLE;
1493 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1497 /// Text subtitle position (RW)
1498 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1499 MPContext *mpctx)
1501 switch (action) {
1502 case M_PROPERTY_SET:
1503 if (!arg)
1504 return M_PROPERTY_ERROR;
1505 case M_PROPERTY_STEP_UP:
1506 case M_PROPERTY_STEP_DOWN:
1507 vo_osd_changed(OSDTYPE_SUBTITLE);
1508 default:
1509 return m_property_int_range(prop, action, arg, &sub_pos);
1513 /// Selected subtitles (RW)
1514 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1515 MPContext *mpctx)
1517 struct MPOpts *opts = &mpctx->opts;
1518 demux_stream_t *const d_sub = mpctx->d_sub;
1519 int source = -1, reset_spu = 0;
1520 int source_pos = -1;
1522 update_global_sub_size(mpctx);
1523 const int global_sub_size = mpctx->global_sub_size;
1525 if (global_sub_size <= 0)
1526 return M_PROPERTY_UNAVAILABLE;
1528 switch (action) {
1529 case M_PROPERTY_GET:
1530 if (!arg)
1531 return M_PROPERTY_ERROR;
1532 *(int *) arg = mpctx->global_sub_pos;
1533 return M_PROPERTY_OK;
1534 case M_PROPERTY_PRINT:
1535 if (!arg)
1536 return M_PROPERTY_ERROR;
1537 char *sub_name = NULL;
1538 if (mpctx->subdata)
1539 sub_name = mpctx->subdata->filename;
1540 #ifdef CONFIG_ASS
1541 if (mpctx->osd->ass_track)
1542 sub_name = mpctx->osd->ass_track->name;
1543 #endif
1544 if (!sub_name && mpctx->subdata)
1545 sub_name = mpctx->subdata->filename;
1546 if (sub_name) {
1547 const char *tmp = mp_basename(sub_name);
1549 *(char **) arg = talloc_asprintf(NULL, "(%d) %s%s",
1550 mpctx->set_of_sub_pos + 1,
1551 strlen(tmp) < 20 ? "" : "...",
1552 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1553 return M_PROPERTY_OK;
1555 #ifdef CONFIG_DVDNAV
1556 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1557 if (vo_spudec && opts->sub_id >= 0) {
1558 unsigned char lang[3];
1559 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id,
1560 lang)) {
1561 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1562 opts->sub_id, lang);
1563 return M_PROPERTY_OK;
1567 #endif
1569 if ((d_sub->demuxer->type == DEMUXER_TYPE_MATROSKA
1570 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF
1571 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1572 || d_sub->demuxer->type == DEMUXER_TYPE_OGG)
1573 && d_sub->sh && opts->sub_id >= 0) {
1574 struct sh_sub *sh = d_sub->sh;
1575 char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
1576 if (sh->title)
1577 *(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
1578 opts->sub_id, lang, sh->title);
1579 else
1580 *(char **)arg = talloc_asprintf(NULL, "(%d) %s",
1581 opts->sub_id, lang);
1582 return M_PROPERTY_OK;
1585 if (vo_vobsub && vobsub_id >= 0) {
1586 const char *language = mp_gtext("unknown");
1587 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1588 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1589 vobsub_id, language ? language : mp_gtext("unknown"));
1590 return M_PROPERTY_OK;
1592 #ifdef CONFIG_DVDREAD
1593 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1594 && opts->sub_id >= 0) {
1595 char lang[3];
1596 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1597 lang[0] = code >> 8;
1598 lang[1] = code;
1599 lang[2] = 0;
1600 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1601 opts->sub_id, lang);
1602 return M_PROPERTY_OK;
1604 #endif
1605 if (opts->sub_id >= 0) {
1606 *(char **) arg = talloc_asprintf(NULL, "(%d) %s", opts->sub_id,
1607 mp_gtext("unknown"));
1608 return M_PROPERTY_OK;
1610 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1611 return M_PROPERTY_OK;
1613 case M_PROPERTY_SET:
1614 if (!arg)
1615 return M_PROPERTY_ERROR;
1616 if (*(int *) arg < -1)
1617 *(int *) arg = -1;
1618 else if (*(int *) arg >= global_sub_size)
1619 *(int *) arg = global_sub_size - 1;
1620 mpctx->global_sub_pos = *(int *) arg;
1621 break;
1622 case M_PROPERTY_STEP_UP:
1623 mpctx->global_sub_pos += 2;
1624 mpctx->global_sub_pos =
1625 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1626 break;
1627 case M_PROPERTY_STEP_DOWN:
1628 mpctx->global_sub_pos += global_sub_size + 1;
1629 mpctx->global_sub_pos =
1630 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1631 break;
1632 default:
1633 return M_PROPERTY_NOT_IMPLEMENTED;
1636 if (mpctx->global_sub_pos >= 0) {
1637 source = sub_source(mpctx);
1638 source_pos = sub_source_pos(mpctx);
1641 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1642 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1643 global_sub_size,
1644 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1645 mpctx->sub_counts[SUB_SOURCE_SUBS],
1646 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1647 mpctx->global_sub_pos, source);
1649 mpctx->set_of_sub_pos = -1;
1650 mpctx->subdata = NULL;
1652 vobsub_id = -1;
1653 opts->sub_id = -1;
1654 if (d_sub) {
1655 if (d_sub->id > -2)
1656 reset_spu = 1;
1657 d_sub->id = -2;
1659 mpctx->osd->ass_track = NULL;
1660 uninit_player(mpctx, INITIALIZED_SUB);
1662 if (source == SUB_SOURCE_VOBSUB)
1663 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1664 else if (source == SUB_SOURCE_SUBS) {
1665 mpctx->set_of_sub_pos = source_pos;
1666 #ifdef CONFIG_ASS
1667 if (opts->ass_enabled
1668 && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]) {
1669 mpctx->osd->ass_track =
1670 mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1671 mpctx->osd->ass_track_changed = true;
1672 mpctx->osd->vsfilter_aspect =
1673 mpctx->track_was_native_ass[mpctx->set_of_sub_pos];
1674 } else
1675 #endif
1677 mpctx->subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1678 vo_osd_changed(OSDTYPE_SUBTITLE);
1680 } else if (source == SUB_SOURCE_DEMUX) {
1681 opts->sub_id = source_pos;
1682 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1683 int i = 0;
1684 // default: assume 1:1 mapping of sid and stream id
1685 d_sub->id = opts->sub_id;
1686 d_sub->sh = mpctx->d_sub->demuxer->s_streams[d_sub->id];
1687 ds_free_packs(d_sub);
1688 for (i = 0; i < MAX_S_STREAMS; i++) {
1689 sh_sub_t *sh = mpctx->d_sub->demuxer->s_streams[i];
1690 if (sh && sh->sid == opts->sub_id) {
1691 d_sub->id = i;
1692 d_sub->sh = sh;
1693 break;
1696 if (d_sub->sh && d_sub->id >= 0) {
1697 sh_sub_t *sh = d_sub->sh;
1698 if (sh->type == 'v')
1699 init_vo_spudec(mpctx);
1700 else {
1701 sub_init(sh, mpctx->osd);
1702 mpctx->initialized_flags |= INITIALIZED_SUB;
1704 } else {
1705 d_sub->id = -2;
1706 d_sub->sh = NULL;
1710 #ifdef CONFIG_DVDREAD
1711 if (vo_spudec
1712 && (mpctx->stream->type == STREAMTYPE_DVD
1713 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1714 && opts->sub_id < 0 && reset_spu) {
1715 d_sub->id = -2;
1716 d_sub->sh = NULL;
1718 #endif
1720 update_subtitles(mpctx, 0, 0, true);
1722 return M_PROPERTY_OK;
1725 /// Selected sub source (RW)
1726 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1727 MPContext *mpctx)
1729 int source;
1730 update_global_sub_size(mpctx);
1731 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1732 return M_PROPERTY_UNAVAILABLE;
1734 switch (action) {
1735 case M_PROPERTY_GET:
1736 if (!arg)
1737 return M_PROPERTY_ERROR;
1738 *(int *) arg = sub_source(mpctx);
1739 return M_PROPERTY_OK;
1740 case M_PROPERTY_PRINT:
1741 if (!arg)
1742 return M_PROPERTY_ERROR;
1743 char *sourcename;
1744 switch (sub_source(mpctx)) {
1745 case SUB_SOURCE_SUBS:
1746 sourcename = mp_gtext("file");
1747 break;
1748 case SUB_SOURCE_VOBSUB:
1749 sourcename = mp_gtext("vobsub");
1750 break;
1751 case SUB_SOURCE_DEMUX:
1752 sourcename = mp_gtext("embedded");
1753 break;
1754 default:
1755 sourcename = mp_gtext("disabled");
1757 *(char **)arg = talloc_strdup(NULL, sourcename);
1758 return M_PROPERTY_OK;
1759 case M_PROPERTY_SET:
1760 if (!arg)
1761 return M_PROPERTY_ERROR;
1762 M_PROPERTY_CLAMP(prop, *(int *)arg);
1763 if (*(int *) arg < 0)
1764 mpctx->global_sub_pos = -1;
1765 else if (*(int *) arg != sub_source(mpctx)) {
1766 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1767 if (new_pos == -1)
1768 return M_PROPERTY_UNAVAILABLE;
1769 mpctx->global_sub_pos = new_pos;
1771 break;
1772 case M_PROPERTY_STEP_UP:
1773 case M_PROPERTY_STEP_DOWN: {
1774 int step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1)
1775 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1776 int step = (step_all > 0) ? 1 : -1;
1777 int cur_source = sub_source(mpctx);
1778 source = cur_source;
1779 while (step_all) {
1780 source += step;
1781 if (source >= SUB_SOURCES)
1782 source = -1;
1783 else if (source < -1)
1784 source = SUB_SOURCES - 1;
1785 if (source == cur_source || source == -1 ||
1786 mpctx->sub_counts[source])
1787 step_all -= step;
1789 if (source == cur_source)
1790 return M_PROPERTY_OK;
1791 if (source == -1)
1792 mpctx->global_sub_pos = -1;
1793 else
1794 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1795 break;
1797 default:
1798 return M_PROPERTY_NOT_IMPLEMENTED;
1800 --mpctx->global_sub_pos;
1801 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1804 /// Selected subtitles from specific source (RW)
1805 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1806 MPContext *mpctx)
1808 int source, is_cur_source, offset, new_pos;
1809 update_global_sub_size(mpctx);
1810 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1811 return M_PROPERTY_UNAVAILABLE;
1813 if (!strcmp(prop->name, "sub_file"))
1814 source = SUB_SOURCE_SUBS;
1815 else if (!strcmp(prop->name, "sub_vob"))
1816 source = SUB_SOURCE_VOBSUB;
1817 else if (!strcmp(prop->name, "sub_demux"))
1818 source = SUB_SOURCE_DEMUX;
1819 else
1820 return M_PROPERTY_ERROR;
1822 offset = sub_pos_by_source(mpctx, source);
1823 if (offset < 0)
1824 return M_PROPERTY_UNAVAILABLE;
1826 is_cur_source = sub_source(mpctx) == source;
1827 new_pos = mpctx->global_sub_pos;
1828 switch (action) {
1829 case M_PROPERTY_GET:
1830 if (!arg)
1831 return M_PROPERTY_ERROR;
1832 if (is_cur_source) {
1833 *(int *) arg = sub_source_pos(mpctx);
1834 if (source == SUB_SOURCE_VOBSUB)
1835 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1836 } else
1837 *(int *) arg = -1;
1838 return M_PROPERTY_OK;
1839 case M_PROPERTY_PRINT:
1840 if (!arg)
1841 return M_PROPERTY_ERROR;
1842 if (is_cur_source)
1843 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1844 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1845 return M_PROPERTY_OK;
1846 case M_PROPERTY_SET:
1847 if (!arg)
1848 return M_PROPERTY_ERROR;
1849 if (*(int *) arg >= 0) {
1850 int index = *(int *)arg;
1851 if (source == SUB_SOURCE_VOBSUB)
1852 index = vobsub_get_index_by_id(vo_vobsub, index);
1853 new_pos = offset + index;
1854 if (index < 0 || index > mpctx->sub_counts[source]) {
1855 new_pos = -1;
1856 *(int *) arg = -1;
1858 } else
1859 new_pos = -1;
1860 break;
1861 case M_PROPERTY_STEP_UP:
1862 case M_PROPERTY_STEP_DOWN: {
1863 int step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1)
1864 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1865 int step = (step_all > 0) ? 1 : -1;
1866 int max_sub_pos_for_source = -1;
1867 if (!is_cur_source)
1868 new_pos = -1;
1869 while (step_all) {
1870 if (new_pos == -1) {
1871 if (step > 0)
1872 new_pos = offset;
1873 else if (max_sub_pos_for_source == -1) {
1874 // Find max pos for specific source
1875 new_pos = mpctx->global_sub_size - 1;
1876 while (new_pos >= 0 && sub_source(mpctx) != source)
1877 new_pos--;
1878 } else
1879 new_pos = max_sub_pos_for_source;
1880 } else {
1881 new_pos += step;
1882 if (new_pos < offset ||
1883 new_pos >= mpctx->global_sub_size ||
1884 sub_source(mpctx) != source)
1885 new_pos = -1;
1887 step_all -= step;
1889 break;
1891 default:
1892 return M_PROPERTY_NOT_IMPLEMENTED;
1894 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1897 /// Subtitle delay (RW)
1898 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1899 MPContext *mpctx)
1901 if (!mpctx->sh_video)
1902 return M_PROPERTY_UNAVAILABLE;
1903 return m_property_delay(prop, action, arg, &sub_delay);
1906 /// Alignment of text subtitles (RW)
1907 static int mp_property_sub_alignment(m_option_t *prop, int action,
1908 void *arg, MPContext *mpctx)
1910 char *name[] = {
1911 _("top"), _("center"), _("bottom")
1914 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1915 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1916 return M_PROPERTY_UNAVAILABLE;
1918 switch (action) {
1919 case M_PROPERTY_PRINT:
1920 if (!arg)
1921 return M_PROPERTY_ERROR;
1922 M_PROPERTY_CLAMP(prop, sub_alignment);
1923 *(char **) arg = talloc_strdup(NULL, mp_gtext(name[sub_alignment]));
1924 return M_PROPERTY_OK;
1925 case M_PROPERTY_SET:
1926 if (!arg)
1927 return M_PROPERTY_ERROR;
1928 case M_PROPERTY_STEP_UP:
1929 case M_PROPERTY_STEP_DOWN:
1930 vo_osd_changed(OSDTYPE_SUBTITLE);
1931 default:
1932 return m_property_choice(prop, action, arg, &sub_alignment);
1936 /// Subtitle visibility (RW)
1937 static int mp_property_sub_visibility(m_option_t *prop, int action,
1938 void *arg, MPContext *mpctx)
1940 if (!mpctx->sh_video)
1941 return M_PROPERTY_UNAVAILABLE;
1943 switch (action) {
1944 case M_PROPERTY_SET:
1945 if (!arg)
1946 return M_PROPERTY_ERROR;
1947 case M_PROPERTY_STEP_UP:
1948 case M_PROPERTY_STEP_DOWN:
1949 vo_osd_changed(OSDTYPE_SUBTITLE);
1950 if (vo_spudec)
1951 vo_osd_changed(OSDTYPE_SPU);
1952 default:
1953 return m_property_flag(prop, action, arg, &sub_visibility);
1957 #ifdef CONFIG_ASS
1958 /// Use margins for libass subtitles (RW)
1959 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1960 void *arg, MPContext *mpctx)
1962 if (!mpctx->sh_video)
1963 return M_PROPERTY_UNAVAILABLE;
1965 switch (action) {
1966 case M_PROPERTY_SET:
1967 if (!arg)
1968 return M_PROPERTY_ERROR;
1969 case M_PROPERTY_STEP_UP:
1970 case M_PROPERTY_STEP_DOWN:
1971 mpctx->osd->ass_force_reload = true;
1972 default:
1973 return m_property_flag(prop, action, arg, &ass_use_margins);
1977 static int mp_property_ass_vsfilter_aspect_compat(m_option_t *prop, int action,
1978 void *arg, MPContext *mpctx)
1980 if (!mpctx->sh_video)
1981 return M_PROPERTY_UNAVAILABLE;
1983 switch (action) {
1984 case M_PROPERTY_SET:
1985 if (!arg)
1986 return M_PROPERTY_ERROR;
1987 case M_PROPERTY_STEP_UP:
1988 case M_PROPERTY_STEP_DOWN:
1989 //has to re-render subs with new aspect ratio
1990 mpctx->osd->ass_force_reload = 1;
1991 default:
1992 return m_property_flag(prop, action, arg,
1993 &mpctx->opts.ass_vsfilter_aspect_compat);
1997 #endif
1999 /// Show only forced subtitles (RW)
2000 static int mp_property_sub_forced_only(m_option_t *prop, int action,
2001 void *arg, MPContext *mpctx)
2003 if (!vo_spudec)
2004 return M_PROPERTY_UNAVAILABLE;
2006 switch (action) {
2007 case M_PROPERTY_SET:
2008 if (!arg)
2009 return M_PROPERTY_ERROR;
2010 case M_PROPERTY_STEP_UP:
2011 case M_PROPERTY_STEP_DOWN:
2012 m_property_flag(prop, action, arg, &forced_subs_only);
2013 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
2014 return M_PROPERTY_OK;
2015 default:
2016 return m_property_flag(prop, action, arg, &forced_subs_only);
2021 #ifdef CONFIG_FREETYPE
2022 /// Subtitle scale (RW)
2023 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
2024 MPContext *mpctx)
2026 struct MPOpts *opts = &mpctx->opts;
2028 switch (action) {
2029 case M_PROPERTY_SET:
2030 if (!arg)
2031 return M_PROPERTY_ERROR;
2032 M_PROPERTY_CLAMP(prop, *(float *) arg);
2033 #ifdef CONFIG_ASS
2034 if (opts->ass_enabled) {
2035 ass_font_scale = *(float *) arg;
2036 mpctx->osd->ass_force_reload = true;
2038 #endif
2039 text_font_scale_factor = *(float *) arg;
2040 force_load_font = 1;
2041 vo_osd_changed(OSDTYPE_SUBTITLE);
2042 return M_PROPERTY_OK;
2043 case M_PROPERTY_STEP_UP:
2044 case M_PROPERTY_STEP_DOWN:
2045 #ifdef CONFIG_ASS
2046 if (opts->ass_enabled) {
2047 ass_font_scale += (arg ? *(float *) arg : 0.1) *
2048 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2049 M_PROPERTY_CLAMP(prop, ass_font_scale);
2050 mpctx->osd->ass_force_reload = true;
2052 #endif
2053 text_font_scale_factor += (arg ? *(float *) arg : 0.1) *
2054 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2055 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
2056 force_load_font = 1;
2057 vo_osd_changed(OSDTYPE_SUBTITLE);
2058 return M_PROPERTY_OK;
2059 default:
2060 #ifdef CONFIG_ASS
2061 if (opts->ass_enabled)
2062 return m_property_float_ro(prop, action, arg, ass_font_scale);
2063 else
2064 #endif
2065 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
2068 #endif
2071 #ifdef CONFIG_TV
2073 /// TV color settings (RW)
2074 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2075 MPContext *mpctx)
2077 int r, val;
2078 tvi_handle_t *tvh = mpctx->demuxer->priv;
2079 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2080 return M_PROPERTY_UNAVAILABLE;
2082 switch (action) {
2083 case M_PROPERTY_SET:
2084 if (!arg)
2085 return M_PROPERTY_ERROR;
2086 M_PROPERTY_CLAMP(prop, *(int *) arg);
2087 return tv_set_color_options(tvh, prop->offset, *(int *) arg);
2088 case M_PROPERTY_GET:
2089 return tv_get_color_options(tvh, prop->offset, arg);
2090 case M_PROPERTY_STEP_UP:
2091 case M_PROPERTY_STEP_DOWN:
2092 if ((r = tv_get_color_options(tvh, prop->offset, &val)) >= 0) {
2093 if (!r)
2094 return M_PROPERTY_ERROR;
2095 val += (arg ? *(int *) arg : 1) *
2096 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2097 M_PROPERTY_CLAMP(prop, val);
2098 return tv_set_color_options(tvh, prop->offset, val);
2100 return M_PROPERTY_ERROR;
2102 return M_PROPERTY_NOT_IMPLEMENTED;
2105 #endif
2107 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2108 MPContext *mpctx)
2110 int val, result;
2111 int base_ioctl = prop->offset;
2113 for teletext's GET,SET,STEP ioctls this is not 0
2114 SET is GET+1
2115 STEP is GET+2
2117 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2118 return M_PROPERTY_UNAVAILABLE;
2119 if (!base_ioctl)
2120 return M_PROPERTY_ERROR;
2122 switch (action) {
2123 case M_PROPERTY_GET:
2124 if (!arg)
2125 return M_PROPERTY_ERROR;
2126 result = teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2127 break;
2128 case M_PROPERTY_SET:
2129 if (!arg)
2130 return M_PROPERTY_ERROR;
2131 M_PROPERTY_CLAMP(prop, *(int *) arg);
2132 result = teletext_control(mpctx->demuxer->teletext, base_ioctl + 1,
2133 arg);
2134 break;
2135 case M_PROPERTY_STEP_UP:
2136 case M_PROPERTY_STEP_DOWN:
2137 result = teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2138 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ?
2139 -1 : 1);
2140 result = teletext_control(mpctx->demuxer->teletext, base_ioctl + 1,
2141 &val);
2142 break;
2143 default:
2144 return M_PROPERTY_NOT_IMPLEMENTED;
2147 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2150 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2151 MPContext *mpctx)
2153 int result;
2154 int val;
2156 //with tvh==NULL will fail too
2157 result = mp_property_teletext_common(prop, action, arg, mpctx);
2158 if (result != M_PROPERTY_OK)
2159 return result;
2161 if (teletext_control(mpctx->demuxer->teletext,
2162 prop->offset, &val) == VBI_CONTROL_TRUE && val)
2163 mp_input_set_section(mpctx->input, "teletext");
2164 else
2165 mp_input_set_section(mpctx->input, "tv");
2166 return M_PROPERTY_OK;
2169 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2170 MPContext *mpctx)
2172 int result;
2173 int val;
2174 if (!mpctx->demuxer->teletext)
2175 return M_PROPERTY_UNAVAILABLE;
2176 switch (action) {
2177 case M_PROPERTY_STEP_UP:
2178 case M_PROPERTY_STEP_DOWN:
2179 //This should be handled separately
2180 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ?
2181 -1 : 1);
2182 result = teletext_control(mpctx->demuxer->teletext,
2183 TV_VBI_CONTROL_STEP_PAGE, &val);
2184 break;
2185 default:
2186 result = mp_property_teletext_common(prop, action, arg, mpctx);
2188 return result;
2192 /// All properties available in MPlayer.
2193 /** \ingroup Properties
2195 static const m_option_t mp_properties[] = {
2196 // General
2197 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2198 M_OPT_RANGE, 0, 3, NULL },
2199 { "loop", mp_property_loop, CONF_TYPE_INT,
2200 M_OPT_MIN, -1, 0, NULL },
2201 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2202 M_OPT_RANGE, 0.01, 100.0, NULL },
2203 { "filename", mp_property_filename, CONF_TYPE_STRING,
2204 0, 0, 0, NULL },
2205 { "path", mp_property_path, CONF_TYPE_STRING,
2206 0, 0, 0, NULL },
2207 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2208 0, 0, 0, NULL },
2209 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2210 M_OPT_MIN, 0, 0, NULL },
2211 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2212 M_OPT_MIN, 0, 0, NULL },
2213 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2214 M_OPT_MIN, 0, 0, NULL },
2215 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2216 M_OPT_MIN, 0, 0, NULL },
2217 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2218 M_OPT_MIN, 0, 0, NULL },
2219 { "length", mp_property_length, CONF_TYPE_TIME,
2220 M_OPT_MIN, 0, 0, NULL },
2221 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2222 M_OPT_RANGE, 0, 100, NULL },
2223 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2224 M_OPT_MIN, 0, 0, NULL },
2225 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2226 M_OPT_MIN, 0, 0, NULL },
2227 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2228 0, 0, 0, NULL },
2229 { "angle", mp_property_angle, CONF_TYPE_INT,
2230 CONF_RANGE, -2, 10, NULL },
2231 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2232 0, 0, 0, NULL },
2233 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2234 M_OPT_RANGE, 0, 1, NULL },
2235 { "capturing", mp_property_capture, CONF_TYPE_FLAG,
2236 M_OPT_RANGE, 0, 1, NULL },
2237 { "pts_association_mode", mp_property_generic_option, &m_option_type_choice,
2238 0, 0, 0, "pts-association-mode" },
2239 { "hr_seek", mp_property_generic_option, &m_option_type_choice,
2240 0, 0, 0, "hr-seek" },
2242 // Audio
2243 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2244 M_OPT_RANGE, 0, 100, NULL },
2245 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2246 M_OPT_RANGE, 0, 1, NULL },
2247 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2248 M_OPT_RANGE, -100, 100, NULL },
2249 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2250 0, 0, 0, NULL },
2251 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2252 0, 0, 0, NULL },
2253 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2254 0, 0, 0, NULL },
2255 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2256 0, 0, 0, NULL },
2257 { "channels", mp_property_channels, CONF_TYPE_INT,
2258 0, 0, 0, NULL },
2259 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2260 CONF_RANGE, -2, 65535, NULL },
2261 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2262 M_OPT_RANGE, -1, 1, NULL },
2264 // Video
2265 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2266 M_OPT_RANGE, 0, 1, NULL },
2267 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2268 M_OPT_RANGE, 0, 1, NULL },
2269 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2270 M_OPT_RANGE, 0, 2, NULL },
2271 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2272 M_OPT_RANGE, 0, 1, NULL },
2273 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2274 M_OPT_RANGE, 0, 1, NULL },
2275 { "border", mp_property_border, CONF_TYPE_FLAG,
2276 M_OPT_RANGE, 0, 1, NULL },
2277 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2278 M_OPT_RANGE, 0, 2, NULL },
2279 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2280 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_gamma)},
2281 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2282 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_brightness) },
2283 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2284 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_contrast) },
2285 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2286 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_saturation) },
2287 { "hue", mp_property_gamma, CONF_TYPE_INT,
2288 M_OPT_RANGE, -100, 100, .offset = offsetof(struct MPOpts, vo_gamma_hue) },
2289 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2290 M_OPT_RANGE, 0, 1, NULL },
2291 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2292 M_OPT_RANGE, 0, 1, NULL },
2293 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2294 0, 0, 0, NULL },
2295 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2296 0, 0, 0, NULL },
2297 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2298 0, 0, 0, NULL },
2299 { "width", mp_property_width, CONF_TYPE_INT,
2300 0, 0, 0, NULL },
2301 { "height", mp_property_height, CONF_TYPE_INT,
2302 0, 0, 0, NULL },
2303 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2304 0, 0, 0, NULL },
2305 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2306 0, 0, 0, NULL },
2307 { "switch_video", mp_property_video, CONF_TYPE_INT,
2308 CONF_RANGE, -2, 65535, NULL },
2309 { "switch_program", mp_property_program, CONF_TYPE_INT,
2310 CONF_RANGE, -1, 65535, NULL },
2312 // Subs
2313 { "sub", mp_property_sub, CONF_TYPE_INT,
2314 M_OPT_MIN, -1, 0, NULL },
2315 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2316 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2317 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2318 M_OPT_MIN, -1, 0, NULL },
2319 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2320 M_OPT_MIN, -1, 0, NULL },
2321 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2322 M_OPT_MIN, -1, 0, NULL },
2323 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2324 0, 0, 0, NULL },
2325 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2326 M_OPT_RANGE, 0, 100, NULL },
2327 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2328 M_OPT_RANGE, 0, 2, NULL },
2329 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2330 M_OPT_RANGE, 0, 1, NULL },
2331 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2332 M_OPT_RANGE, 0, 1, NULL },
2333 #ifdef CONFIG_FREETYPE
2334 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2335 M_OPT_RANGE, 0, 100, NULL },
2336 #endif
2337 #ifdef CONFIG_ASS
2338 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2339 M_OPT_RANGE, 0, 1, NULL },
2340 { "ass_vsfilter_aspect_compat", mp_property_ass_vsfilter_aspect_compat,
2341 CONF_TYPE_FLAG, M_OPT_RANGE, 0, 1, NULL },
2342 #endif
2344 #ifdef CONFIG_TV
2345 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2346 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_BRIGHTNESS },
2347 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2348 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_CONTRAST },
2349 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2350 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_SATURATION },
2351 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2352 M_OPT_RANGE, -100, 100, .offset = TV_COLOR_HUE },
2353 #endif
2354 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2355 M_OPT_RANGE, 100, 899, .offset = TV_VBI_CONTROL_GET_PAGE },
2356 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2357 M_OPT_RANGE, 0, 64, .offset = TV_VBI_CONTROL_GET_SUBPAGE },
2358 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2359 M_OPT_RANGE, 0, 1, .offset = TV_VBI_CONTROL_GET_MODE },
2360 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2361 M_OPT_RANGE, 0, 3, .offset = TV_VBI_CONTROL_GET_FORMAT },
2362 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2363 M_OPT_RANGE, 0, 2, .offset = TV_VBI_CONTROL_GET_HALF_PAGE },
2364 { NULL, NULL, NULL, 0, 0, 0, NULL }
2368 int mp_property_do(const char *name, int action, void *val, void *ctx)
2370 return m_property_do(mp_properties, name, action, val, ctx);
2373 char *mp_property_print(const char *name, void *ctx)
2375 char *ret = NULL;
2376 if (mp_property_do(name, M_PROPERTY_PRINT, &ret, ctx) <= 0)
2377 return NULL;
2378 return ret;
2381 char *property_expand_string(MPContext *mpctx, char *str)
2383 return m_properties_expand_string(mp_properties, str, mpctx);
2386 void property_print_help(void)
2388 m_properties_print_help_list(mp_properties);
2392 /* List of default ways to show a property on OSD.
2394 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2395 * a bar showing the current position between min/max values of the
2396 * property. In this case osd_msg is only used for terminal output
2397 * if there is no video; it'll be a label shown together with percentage.
2399 * Otherwise setting osd_msg will show the string on OSD, formatted with
2400 * the text value of the property as argument.
2402 static struct property_osd_display {
2403 /// property name
2404 const char *name;
2405 /// progressbar type
2406 int osd_progbar; // -1 is special value for seek indicators
2407 /// osd msg id if it must be shared
2408 int osd_id;
2409 /// osd msg template
2410 const char *osd_msg;
2411 } property_osd_display[] = {
2412 // general
2413 { "loop", 0, -1, _("Loop: %s") },
2414 { "chapter", -1, -1, NULL },
2415 { "capturing", 0, -1, _("Capturing: %s") },
2416 { "pts_association_mode", 0, -1, "PTS association mode: %s" },
2417 { "hr_seek", 0, -1, "hr-seek: %s" },
2418 { "speed", 0, -1, _("Speed: x %6s") },
2419 // audio
2420 { "volume", OSD_VOLUME, -1, _("Volume") },
2421 { "mute", 0, -1, _("Mute: %s") },
2422 { "audio_delay", 0, -1, _("A-V delay: %s") },
2423 { "switch_audio", 0, -1, _("Audio: %s") },
2424 { "balance", OSD_BALANCE, -1, _("Balance") },
2425 // video
2426 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2427 { "ontop", 0, -1, _("Stay on top: %s") },
2428 { "rootwin", 0, -1, _("Rootwin: %s") },
2429 { "border", 0, -1, _("Border: %s") },
2430 { "framedropping", 0, -1, _("Framedropping: %s") },
2431 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2432 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2433 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2434 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2435 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2436 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2437 { "hue", OSD_HUE, -1, _("Hue") },
2438 { "vsync", 0, -1, _("VSync: %s") },
2439 // subs
2440 { "sub", 0, -1, _("Subtitles: %s") },
2441 { "sub_source", 0, -1, _("Sub source: %s") },
2442 { "sub_vob", 0, -1, _("Subtitles: %s") },
2443 { "sub_demux", 0, -1, _("Subtitles: %s") },
2444 { "sub_file", 0, -1, _("Subtitles: %s") },
2445 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2446 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2447 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2448 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2449 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2450 #ifdef CONFIG_FREETYPE
2451 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2452 #endif
2453 { "ass_vsfilter_aspect_compat", 0, -1,
2454 _("Subtitle VSFilter aspect compat: %s")},
2455 #ifdef CONFIG_TV
2456 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2457 { "tv_hue", OSD_HUE, -1, _("Hue") },
2458 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2459 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2460 #endif
2464 static int show_property_osd(MPContext *mpctx, const char *pname)
2466 struct MPOpts *opts = &mpctx->opts;
2467 int r;
2468 m_option_t *prop;
2469 struct property_osd_display *p;
2471 // look for the command
2472 for (p = property_osd_display; p->name; p++)
2473 if (!strcmp(p->name, pname))
2474 break;
2475 if (!p->name)
2476 return -1;
2478 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2479 return -1;
2481 if (p->osd_progbar == -1)
2482 mpctx->add_osd_seek_info = true;
2483 else if (p->osd_progbar) {
2484 if (prop->type == CONF_TYPE_INT) {
2485 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2486 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2487 prop->min, prop->max, r);
2488 } else if (prop->type == CONF_TYPE_FLOAT) {
2489 float f;
2490 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2491 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2492 prop->min, prop->max, f);
2493 } else {
2494 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2495 "Property use an unsupported type.\n");
2496 return -1;
2498 return 0;
2501 if (p->osd_msg) {
2502 char *val = mp_property_print(pname, mpctx);
2503 if (val) {
2504 int index = p - property_osd_display;
2505 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2506 1, opts->osd_duration, p->osd_msg, val);
2507 talloc_free(val);
2510 return 0;
2515 * Command to property bridge
2517 * It is used to handle most commands that just set a property
2518 * and optionally display something on the OSD.
2519 * Two kinds of commands are handled: adjust or toggle.
2521 * Adjust commands take 1 or 2 parameters: <value> <abs>
2522 * If <abs> is non-zero the property is set to the given value
2523 * otherwise it is adjusted.
2525 * Toggle commands take 0 or 1 parameters. With no parameter
2526 * or a value less than the property minimum it just steps the
2527 * property to its next or previous value respectively.
2528 * Otherwise it sets it to the given value.
2531 /// List of the commands that can be handled by setting a property.
2532 static struct {
2533 /// property name
2534 const char *name;
2535 /// cmd id
2536 int cmd;
2537 /// set/adjust or toggle command
2538 int toggle;
2539 } set_prop_cmd[] = {
2540 // general
2541 { "loop", MP_CMD_LOOP, 0},
2542 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2543 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2544 { "pause", MP_CMD_PAUSE, 0},
2545 { "capturing", MP_CMD_CAPTURING, 1},
2546 // audio
2547 { "volume", MP_CMD_VOLUME, 0},
2548 { "mute", MP_CMD_MUTE, 1},
2549 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2550 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2551 { "balance", MP_CMD_BALANCE, 0},
2552 // video
2553 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2554 { "panscan", MP_CMD_PANSCAN, 0},
2555 { "ontop", MP_CMD_VO_ONTOP, 1},
2556 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2557 { "border", MP_CMD_VO_BORDER, 1},
2558 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2559 { "gamma", MP_CMD_GAMMA, 0},
2560 { "brightness", MP_CMD_BRIGHTNESS, 0},
2561 { "contrast", MP_CMD_CONTRAST, 0},
2562 { "saturation", MP_CMD_SATURATION, 0},
2563 { "hue", MP_CMD_HUE, 0},
2564 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2565 // subs
2566 { "sub", MP_CMD_SUB_SELECT, 1},
2567 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2568 { "sub_vob", MP_CMD_SUB_VOB, 1},
2569 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2570 { "sub_file", MP_CMD_SUB_FILE, 1},
2571 { "sub_pos", MP_CMD_SUB_POS, 0},
2572 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2573 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2574 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2575 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2576 #ifdef CONFIG_FREETYPE
2577 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2578 #endif
2579 #ifdef CONFIG_ASS
2580 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2581 #endif
2582 #ifdef CONFIG_TV
2583 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2584 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2585 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2586 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2587 #endif
2591 /// Handle commands that set a property.
2592 static bool set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2594 int i, r;
2595 m_option_t *prop;
2596 const char *pname;
2598 // look for the command
2599 for (i = 0; set_prop_cmd[i].name; i++)
2600 if (set_prop_cmd[i].cmd == cmd->id)
2601 break;
2602 if (!(pname = set_prop_cmd[i].name))
2603 return 0;
2605 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2606 return 0;
2608 // toggle command
2609 if (set_prop_cmd[i].toggle) {
2610 // set to value
2611 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2612 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2613 else if (cmd->nargs > 0)
2614 r = mp_property_do(pname, M_PROPERTY_STEP_DOWN, NULL, mpctx);
2615 else
2616 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2617 } else if (cmd->args[1].v.i) //set
2618 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2619 else // adjust
2620 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2622 if (r <= 0)
2623 return 1;
2625 show_property_osd(mpctx, pname);
2627 return 1;
2630 #ifdef CONFIG_DVDNAV
2631 static const struct {
2632 const char *name;
2633 const enum mp_command_type cmd;
2634 } mp_dvdnav_bindings[] = {
2635 { "up", MP_CMD_DVDNAV_UP },
2636 { "down", MP_CMD_DVDNAV_DOWN },
2637 { "left", MP_CMD_DVDNAV_LEFT },
2638 { "right", MP_CMD_DVDNAV_RIGHT },
2639 { "menu", MP_CMD_DVDNAV_MENU },
2640 { "select", MP_CMD_DVDNAV_SELECT },
2641 { "prev", MP_CMD_DVDNAV_PREVMENU },
2642 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2645 * keep old dvdnav sub-command options for a while in order not to
2646 * break slave-mode API too suddenly.
2648 { "1", MP_CMD_DVDNAV_UP },
2649 { "2", MP_CMD_DVDNAV_DOWN },
2650 { "3", MP_CMD_DVDNAV_LEFT },
2651 { "4", MP_CMD_DVDNAV_RIGHT },
2652 { "5", MP_CMD_DVDNAV_MENU },
2653 { "6", MP_CMD_DVDNAV_SELECT },
2654 { "7", MP_CMD_DVDNAV_PREVMENU },
2655 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2656 { NULL, 0 }
2658 #endif
2660 static const char *property_error_string(int error_value)
2662 switch (error_value) {
2663 case M_PROPERTY_ERROR:
2664 return "ERROR";
2665 case M_PROPERTY_UNAVAILABLE:
2666 return "PROPERTY_UNAVAILABLE";
2667 case M_PROPERTY_NOT_IMPLEMENTED:
2668 return "NOT_IMPLEMENTED";
2669 case M_PROPERTY_UNKNOWN:
2670 return "PROPERTY_UNKNOWN";
2671 case M_PROPERTY_DISABLED:
2672 return "DISABLED";
2674 return "UNKNOWN";
2677 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2679 int idx;
2680 int end = start + count;
2681 int after = mpctx->set_of_sub_size - end;
2682 sub_data **subs = mpctx->set_of_subtitles;
2683 #ifdef CONFIG_ASS
2684 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2685 #endif
2686 if (count < 0 || count > mpctx->set_of_sub_size ||
2687 start < 0 || start > mpctx->set_of_sub_size - count) {
2688 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2689 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2690 return;
2692 for (idx = start; idx < end; idx++) {
2693 sub_data *subd = subs[idx];
2694 char *filename = "";
2695 if (subd)
2696 filename = subd->filename;
2697 #ifdef CONFIG_ASS
2698 if (!subd)
2699 filename = ass_tracks[idx]->name;
2700 #endif
2701 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2702 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2703 filename_recode(filename));
2704 sub_free(subd);
2705 subs[idx] = NULL;
2706 #ifdef CONFIG_ASS
2707 if (ass_tracks[idx])
2708 ass_free_track(ass_tracks[idx]);
2709 ass_tracks[idx] = NULL;
2710 #endif
2713 mpctx->global_sub_size -= count;
2714 mpctx->set_of_sub_size -= count;
2715 if (mpctx->set_of_sub_size <= 0)
2716 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2718 memmove(subs + start, subs + end, after * sizeof(*subs));
2719 memset(subs + start + after, 0, count * sizeof(*subs));
2720 #ifdef CONFIG_ASS
2721 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2722 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2723 #endif
2725 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2726 mpctx->global_sub_pos = -2;
2727 mpctx->subdata = NULL;
2728 mpctx->osd->ass_track = NULL;
2729 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2730 } else if (mpctx->set_of_sub_pos >= end) {
2731 mpctx->set_of_sub_pos -= count;
2732 mpctx->global_sub_pos -= count;
2736 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2738 struct MPOpts *opts = &mpctx->opts;
2739 sh_audio_t *const sh_audio = mpctx->sh_audio;
2740 sh_video_t *const sh_video = mpctx->sh_video;
2741 int osd_duration = opts->osd_duration;
2742 int case_fallthrough_hack = 0;
2743 if (set_property_command(mpctx, cmd))
2744 goto old_pause_hack; // was handled already
2745 switch (cmd->id) {
2746 case MP_CMD_SEEK: {
2747 mpctx->add_osd_seek_info = true;
2748 float v = cmd->args[0].v.f;
2749 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2750 int exact = (cmd->nargs > 2) ? cmd->args[2].v.i : 0;
2751 if (abs == 2) { // Absolute seek to a timestamp in seconds
2752 queue_seek(mpctx, MPSEEK_ABSOLUTE, v, exact);
2753 mpctx->osd_function = v > get_current_time(mpctx) ?
2754 OSD_FFW : OSD_REW;
2755 } else if (abs) { /* Absolute seek by percentage */
2756 queue_seek(mpctx, MPSEEK_FACTOR, v / 100.0, exact);
2757 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2758 } else {
2759 queue_seek(mpctx, MPSEEK_RELATIVE, v, exact);
2760 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2762 break;
2765 case MP_CMD_SET_PROPERTY_OSD:
2766 case_fallthrough_hack = 1;
2768 case MP_CMD_SET_PROPERTY: {
2769 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2770 cmd->args[1].v.s, mpctx);
2771 if (r == M_PROPERTY_UNKNOWN)
2772 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2773 "Unknown property: '%s'\n", cmd->args[0].v.s);
2774 else if (r <= 0)
2775 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2776 "Failed to set property '%s' to '%s'.\n",
2777 cmd->args[0].v.s, cmd->args[1].v.s);
2778 else if (case_fallthrough_hack)
2779 show_property_osd(mpctx, cmd->args[0].v.s);
2780 if (r <= 0)
2781 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2782 "ANS_ERROR=%s\n", property_error_string(r));
2783 break;
2786 case MP_CMD_STEP_PROPERTY_OSD:
2787 case_fallthrough_hack = 1;
2789 case MP_CMD_STEP_PROPERTY: {
2790 void *arg = NULL;
2791 int r, i;
2792 double d;
2793 off_t o;
2794 if (cmd->args[1].v.f) {
2795 m_option_t *prop;
2796 if ((r = mp_property_do(cmd->args[0].v.s,
2797 M_PROPERTY_GET_TYPE,
2798 &prop, mpctx)) <= 0)
2799 goto step_prop_err;
2800 if (prop->type == CONF_TYPE_INT ||
2801 prop->type == CONF_TYPE_FLAG)
2802 i = cmd->args[1].v.f, arg = &i;
2803 else if (prop->type == CONF_TYPE_FLOAT)
2804 arg = &cmd->args[1].v.f;
2805 else if (prop->type == CONF_TYPE_DOUBLE ||
2806 prop->type == CONF_TYPE_TIME)
2807 d = cmd->args[1].v.f, arg = &d;
2808 else if (prop->type == CONF_TYPE_POSITION)
2809 o = cmd->args[1].v.f, arg = &o;
2810 else
2811 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2812 "Ignoring step size stepping property '%s'.\n",
2813 cmd->args[0].v.s);
2815 r = mp_property_do(cmd->args[0].v.s,
2816 cmd->args[2].v.i < 0 ?
2817 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2818 arg, mpctx);
2819 step_prop_err:
2820 if (r == M_PROPERTY_UNKNOWN)
2821 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2822 "Unknown property: '%s'\n", cmd->args[0].v.s);
2823 else if (r <= 0)
2824 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2825 "Failed to increment property '%s' by %f.\n",
2826 cmd->args[0].v.s, cmd->args[1].v.f);
2827 else if (case_fallthrough_hack)
2828 show_property_osd(mpctx, cmd->args[0].v.s);
2829 if (r <= 0)
2830 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n",
2831 property_error_string(r));
2832 break;
2835 case MP_CMD_GET_PROPERTY: {
2836 char *tmp;
2837 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2838 &tmp, mpctx);
2839 if (r <= 0) {
2840 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2841 "Failed to get value of property '%s'.\n",
2842 cmd->args[0].v.s);
2843 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n",
2844 property_error_string(r));
2845 break;
2847 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2848 cmd->args[0].v.s, tmp);
2849 talloc_free(tmp);
2850 break;
2853 case MP_CMD_EDL_MARK:
2854 if (edl_fd) {
2855 float v = get_current_time(mpctx);
2856 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2857 mpctx->begin_skip = v;
2858 mp_tmsg(MSGT_CPLAYER, MSGL_INFO,
2859 "EDL skip start, press 'i' again to end block.\n");
2860 } else {
2861 if (mpctx->begin_skip > v)
2862 mp_tmsg(MSGT_CPLAYER, MSGL_WARN,
2863 "EDL skip canceled, last start > stop\n");
2864 else {
2865 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2866 mp_tmsg(MSGT_CPLAYER, MSGL_INFO,
2867 "EDL skip end, line written.\n");
2869 mpctx->begin_skip = MP_NOPTS_VALUE;
2872 break;
2874 case MP_CMD_SWITCH_RATIO:
2875 if (!sh_video)
2876 break;
2877 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2878 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2879 else
2880 opts->movie_aspect = cmd->args[0].v.f;
2881 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2882 break;
2884 case MP_CMD_SPEED_INCR: {
2885 float v = cmd->args[0].v.f;
2886 mp_property_do("speed", M_PROPERTY_STEP_UP, &v, mpctx);
2887 show_property_osd(mpctx, "speed");
2888 break;
2891 case MP_CMD_SPEED_MULT:
2892 case_fallthrough_hack = true;
2894 case MP_CMD_SPEED_SET: {
2895 float v = cmd->args[0].v.f;
2896 if (case_fallthrough_hack)
2897 v *= mpctx->opts.playback_speed;
2898 mp_property_do("speed", M_PROPERTY_SET, &v, mpctx);
2899 show_property_osd(mpctx, "speed");
2900 break;
2903 case MP_CMD_FRAME_STEP:
2904 add_step_frame(mpctx);
2905 break;
2907 case MP_CMD_FILE_FILTER:
2908 file_filter = cmd->args[0].v.i;
2909 break;
2911 case MP_CMD_QUIT:
2912 exit_player_with_rc(mpctx, EXIT_QUIT,
2913 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2915 case MP_CMD_PLAY_TREE_STEP: {
2916 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2917 int force = cmd->args[1].v.i;
2920 if (!force && mpctx->playtree_iter) {
2921 play_tree_iter_t *i =
2922 play_tree_iter_new_copy(mpctx->playtree_iter);
2923 if (play_tree_iter_step(i, n, 0) ==
2924 PLAY_TREE_ITER_ENTRY)
2925 mpctx->stop_play =
2926 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2927 play_tree_iter_free(i);
2928 } else
2929 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2930 if (mpctx->stop_play)
2931 mpctx->play_tree_step = n;
2933 break;
2936 case MP_CMD_PLAY_TREE_UP_STEP: {
2937 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2938 int force = cmd->args[1].v.i;
2940 if (!force && mpctx->playtree_iter) {
2941 play_tree_iter_t *i =
2942 play_tree_iter_new_copy(mpctx->playtree_iter);
2943 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2944 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2945 play_tree_iter_free(i);
2946 } else
2947 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2948 break;
2951 case MP_CMD_PLAY_ALT_SRC_STEP:
2952 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2953 int v = cmd->args[0].v.i;
2954 if (v > 0
2955 && mpctx->playtree_iter->file <
2956 mpctx->playtree_iter->num_files)
2957 mpctx->stop_play = PT_NEXT_SRC;
2958 else if (v < 0 && mpctx->playtree_iter->file > 1)
2959 mpctx->stop_play = PT_PREV_SRC;
2961 break;
2963 case MP_CMD_SUB_STEP:
2964 if (sh_video) {
2965 int movement = cmd->args[0].v.i;
2966 step_sub(mpctx->subdata, mpctx->video_pts, movement);
2967 #ifdef CONFIG_ASS
2968 if (mpctx->osd->ass_track)
2969 sub_delay +=
2970 ass_step_sub(mpctx->osd->ass_track,
2971 (mpctx->video_pts +
2972 sub_delay) * 1000 + .5, movement) / 1000.;
2973 #endif
2974 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2975 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2977 break;
2979 case MP_CMD_SUB_LOG:
2980 log_sub(mpctx);
2981 break;
2983 case MP_CMD_OSD: {
2984 int v = cmd->args[0].v.i;
2985 int max = (opts->term_osd
2986 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2987 if (opts->osd_level > max)
2988 opts->osd_level = max;
2989 if (v < 0)
2990 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2991 else
2992 opts->osd_level = v > max ? max : v;
2993 /* Show OSD state when disabled, but not when an explicit
2994 argument is given to the OSD command, i.e. in slave mode. */
2995 if (v == -1 && opts->osd_level <= 1)
2996 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2997 "OSD: %s",
2998 opts->osd_level ? mp_gtext("enabled") :
2999 mp_gtext("disabled"));
3000 else
3001 rm_osd_msg(OSD_MSG_OSD_STATUS);
3002 break;
3005 case MP_CMD_OSD_SHOW_TEXT:
3006 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
3007 (cmd->args[1].v.i <
3008 0 ? osd_duration : cmd->args[1].v.i),
3009 "%s", cmd->args[0].v.s);
3010 break;
3012 case MP_CMD_OSD_SHOW_PROPERTY_TEXT: {
3013 char *txt = m_properties_expand_string(mp_properties,
3014 cmd->args[0].v.s,
3015 mpctx);
3016 // if no argument supplied use default osd_duration, else <arg> ms.
3017 if (txt) {
3018 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
3019 (cmd->args[1].v.i <
3020 0 ? osd_duration : cmd->args[1].v.i),
3021 "%s", txt);
3022 free(txt);
3024 break;
3027 case MP_CMD_LOADFILE: {
3028 play_tree_t *e = play_tree_new();
3029 play_tree_add_file(e, cmd->args[0].v.s);
3031 if (cmd->args[1].v.i) // append
3032 play_tree_append_entry(mpctx->playtree->child, e);
3033 else {
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 play_tree_free_list(mpctx->playtree->child, 1);
3039 play_tree_set_child(mpctx->playtree, e);
3040 pt_iter_goto_head(mpctx->playtree_iter);
3041 mpctx->stop_play = PT_NEXT_SRC;
3043 break;
3046 case MP_CMD_LOADLIST: {
3047 play_tree_t *e = parse_playlist_file(mpctx->mconfig,
3048 bstr(cmd->args[0].v.s));
3049 if (!e)
3050 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
3051 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
3052 else {
3053 if (cmd->args[1].v.i) // append
3054 play_tree_append_entry(mpctx->playtree->child, e);
3055 else {
3056 // Go back to the starting point.
3057 while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1)
3058 != PLAY_TREE_ITER_END)
3059 /* NOP */;
3060 play_tree_free_list(mpctx->playtree->child, 1);
3061 play_tree_set_child(mpctx->playtree, e);
3062 pt_iter_goto_head(mpctx->playtree_iter);
3063 mpctx->stop_play = PT_NEXT_SRC;
3066 break;
3069 case MP_CMD_STOP:
3070 // Go back to the starting point.
3071 while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1) !=
3072 PLAY_TREE_ITER_END)
3073 /* NOP */;
3074 mpctx->stop_play = PT_STOP;
3075 break;
3077 case MP_CMD_OSD_SHOW_PROGRESSION: {
3078 int len = get_time_length(mpctx);
3079 int pts = get_current_time(mpctx);
3080 set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3081 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3082 "%c %02d:%02d:%02d / %02d:%02d:%02d",
3083 mpctx->osd_function, pts / 3600, (pts / 60) % 60, pts % 60,
3084 len / 3600, (len / 60) % 60, len % 60);
3085 break;
3088 #ifdef CONFIG_RADIO
3089 case MP_CMD_RADIO_STEP_CHANNEL:
3090 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3091 int v = cmd->args[0].v.i;
3092 if (v > 0)
3093 radio_step_channel(mpctx->demuxer->stream,
3094 RADIO_CHANNEL_HIGHER);
3095 else
3096 radio_step_channel(mpctx->demuxer->stream,
3097 RADIO_CHANNEL_LOWER);
3098 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3099 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3100 "Channel: %s",
3101 radio_get_channel_name(mpctx->demuxer->stream));
3104 break;
3106 case MP_CMD_RADIO_SET_CHANNEL:
3107 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3108 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3109 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3110 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3111 "Channel: %s",
3112 radio_get_channel_name(mpctx->demuxer->stream));
3115 break;
3117 case MP_CMD_RADIO_SET_FREQ:
3118 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3119 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3120 break;
3122 case MP_CMD_RADIO_STEP_FREQ:
3123 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3124 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3125 break;
3126 #endif
3128 #ifdef CONFIG_TV
3129 case MP_CMD_TV_START_SCAN:
3130 if (mpctx->file_format == DEMUXER_TYPE_TV)
3131 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv), 1);
3132 break;
3133 case MP_CMD_TV_SET_FREQ:
3134 if (mpctx->file_format == DEMUXER_TYPE_TV)
3135 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3136 cmd->args[0].v.f * 16.0);
3137 #ifdef CONFIG_PVR
3138 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3139 pvr_set_freq(mpctx->stream, ROUND(cmd->args[0].v.f));
3140 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3141 pvr_get_current_channelname(mpctx->stream),
3142 pvr_get_current_stationname(mpctx->stream));
3144 #endif /* CONFIG_PVR */
3145 break;
3147 case MP_CMD_TV_STEP_FREQ:
3148 if (mpctx->file_format == DEMUXER_TYPE_TV)
3149 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3150 cmd->args[0].v.f * 16.0);
3151 #ifdef CONFIG_PVR
3152 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3153 pvr_force_freq_step(mpctx->stream, ROUND(cmd->args[0].v.f));
3154 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3155 pvr_get_current_channelname(mpctx->stream),
3156 pvr_get_current_frequency(mpctx->stream));
3158 #endif /* CONFIG_PVR */
3159 break;
3161 case MP_CMD_TV_SET_NORM:
3162 if (mpctx->file_format == DEMUXER_TYPE_TV)
3163 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3164 cmd->args[0].v.s);
3165 break;
3167 case MP_CMD_TV_STEP_CHANNEL:
3168 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3169 int v = cmd->args[0].v.i;
3170 if (v > 0) {
3171 tv_step_channel((tvi_handle_t *) (mpctx->
3172 demuxer->priv),
3173 TV_CHANNEL_HIGHER);
3174 } else {
3175 tv_step_channel((tvi_handle_t *) (mpctx->
3176 demuxer->priv),
3177 TV_CHANNEL_LOWER);
3179 if (tv_channel_list) {
3180 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3181 "Channel: %s", tv_channel_current->name);
3182 //vo_osd_changed(OSDTYPE_SUBTITLE);
3185 #ifdef CONFIG_PVR
3186 else if (mpctx->stream &&
3187 mpctx->stream->type == STREAMTYPE_PVR) {
3188 pvr_set_channel_step(mpctx->stream, cmd->args[0].v.i);
3189 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3190 pvr_get_current_channelname(mpctx->stream),
3191 pvr_get_current_stationname(mpctx->stream));
3193 #endif /* CONFIG_PVR */
3194 #ifdef CONFIG_DVBIN
3195 if (mpctx->stream->type == STREAMTYPE_DVB) {
3196 int dir;
3197 int v = cmd->args[0].v.i;
3199 mpctx->last_dvb_step = v;
3200 if (v > 0)
3201 dir = DVB_CHANNEL_HIGHER;
3202 else
3203 dir = DVB_CHANNEL_LOWER;
3206 if (dvb_step_channel(mpctx->stream, dir)) {
3207 mpctx->stop_play = PT_NEXT_ENTRY;
3208 mpctx->dvbin_reopen = 1;
3211 #endif /* CONFIG_DVBIN */
3212 break;
3214 case MP_CMD_TV_SET_CHANNEL:
3215 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3216 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3217 cmd->args[0].v.s);
3218 if (tv_channel_list) {
3219 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3220 "Channel: %s", tv_channel_current->name);
3221 //vo_osd_changed(OSDTYPE_SUBTITLE);
3224 #ifdef CONFIG_PVR
3225 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3226 pvr_set_channel(mpctx->stream, cmd->args[0].v.s);
3227 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3228 pvr_get_current_channelname(mpctx->stream),
3229 pvr_get_current_stationname(mpctx->stream));
3231 #endif /* CONFIG_PVR */
3232 break;
3234 #ifdef CONFIG_DVBIN
3235 case MP_CMD_DVB_SET_CHANNEL:
3236 if (mpctx->stream->type == STREAMTYPE_DVB) {
3237 mpctx->last_dvb_step = 1;
3239 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3240 cmd->args[0].v.i)) {
3241 mpctx->stop_play = PT_NEXT_ENTRY;
3242 mpctx->dvbin_reopen = 1;
3245 break;
3246 #endif /* CONFIG_DVBIN */
3248 case MP_CMD_TV_LAST_CHANNEL:
3249 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3250 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3251 if (tv_channel_list) {
3252 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3253 "Channel: %s", tv_channel_current->name);
3254 //vo_osd_changed(OSDTYPE_SUBTITLE);
3257 #ifdef CONFIG_PVR
3258 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3259 pvr_set_lastchannel(mpctx->stream);
3260 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3261 pvr_get_current_channelname(mpctx->stream),
3262 pvr_get_current_stationname(mpctx->stream));
3264 #endif /* CONFIG_PVR */
3265 break;
3267 case MP_CMD_TV_STEP_NORM:
3268 if (mpctx->file_format == DEMUXER_TYPE_TV)
3269 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3270 break;
3272 case MP_CMD_TV_STEP_CHANNEL_LIST:
3273 if (mpctx->file_format == DEMUXER_TYPE_TV)
3274 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3275 break;
3276 #endif /* CONFIG_TV */
3277 case MP_CMD_TV_TELETEXT_ADD_DEC:
3278 if (mpctx->demuxer->teletext)
3279 teletext_control(mpctx->demuxer->teletext, TV_VBI_CONTROL_ADD_DEC,
3280 &(cmd->args[0].v.s));
3281 break;
3282 case MP_CMD_TV_TELETEXT_GO_LINK:
3283 if (mpctx->demuxer->teletext)
3284 teletext_control(mpctx->demuxer->teletext, TV_VBI_CONTROL_GO_LINK,
3285 &(cmd->args[0].v.i));
3286 break;
3288 case MP_CMD_SUB_LOAD:
3289 if (sh_video) {
3290 int n = mpctx->set_of_sub_size;
3291 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3292 if (n != mpctx->set_of_sub_size) {
3293 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3294 ++mpctx->global_sub_size;
3297 break;
3299 case MP_CMD_SUB_REMOVE:
3300 if (sh_video) {
3301 int v = cmd->args[0].v.i;
3302 if (v < 0)
3303 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3304 else if (v < mpctx->set_of_sub_size)
3305 remove_subtitle_range(mpctx, v, 1);
3307 break;
3309 case MP_CMD_GET_SUB_VISIBILITY:
3310 if (sh_video) {
3311 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3312 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3314 break;
3316 case MP_CMD_SCREENSHOT:
3317 if (mpctx->video_out && mpctx->video_out->config_ok) {
3318 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3319 if (CONTROL_OK !=
3320 ((vf_instance_t *) sh_video->vfilter)->
3321 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3322 &cmd->args[0].v.i))
3323 mp_msg(MSGT_CPLAYER, MSGL_INFO,
3324 "failed (forgot -vf screenshot?)\n");
3326 break;
3328 case MP_CMD_VF_CHANGE_RECTANGLE:
3329 if (!sh_video)
3330 break;
3331 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3332 break;
3334 case MP_CMD_GET_TIME_LENGTH:
3335 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3336 get_time_length(mpctx));
3337 break;
3339 case MP_CMD_GET_FILENAME: {
3340 char *inf = get_metadata(mpctx, META_NAME);
3341 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n", inf);
3342 talloc_free(inf);
3343 break;
3346 case MP_CMD_GET_VIDEO_CODEC: {
3347 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3348 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3349 talloc_free(inf);
3350 break;
3353 case MP_CMD_GET_VIDEO_BITRATE: {
3354 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3355 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3356 talloc_free(inf);
3357 break;
3360 case MP_CMD_GET_VIDEO_RESOLUTION: {
3361 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3362 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3363 talloc_free(inf);
3364 break;
3367 case MP_CMD_GET_AUDIO_CODEC: {
3368 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3369 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3370 talloc_free(inf);
3371 break;
3374 case MP_CMD_GET_AUDIO_BITRATE: {
3375 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3376 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3377 talloc_free(inf);
3378 break;
3381 case MP_CMD_GET_AUDIO_SAMPLES: {
3382 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3383 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3384 talloc_free(inf);
3385 break;
3388 case MP_CMD_GET_META_TITLE: {
3389 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3390 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3391 talloc_free(inf);
3392 break;
3395 case MP_CMD_GET_META_ARTIST: {
3396 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3397 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3398 talloc_free(inf);
3399 break;
3402 case MP_CMD_GET_META_ALBUM: {
3403 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3404 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3405 talloc_free(inf);
3406 break;
3409 case MP_CMD_GET_META_YEAR: {
3410 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3411 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3412 talloc_free(inf);
3413 break;
3416 case MP_CMD_GET_META_COMMENT: {
3417 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3418 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3419 talloc_free(inf);
3420 break;
3423 case MP_CMD_GET_META_TRACK: {
3424 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3425 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3426 talloc_free(inf);
3427 break;
3430 case MP_CMD_GET_META_GENRE: {
3431 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3432 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3433 talloc_free(inf);
3434 break;
3437 case MP_CMD_GET_VO_FULLSCREEN:
3438 if (mpctx->video_out && mpctx->video_out->config_ok)
3439 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3440 break;
3442 case MP_CMD_GET_PERCENT_POS:
3443 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3444 get_percent_pos(mpctx));
3445 break;
3447 case MP_CMD_GET_TIME_POS: {
3448 float pos = get_current_time(mpctx);
3449 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3450 break;
3453 case MP_CMD_RUN:
3454 #ifndef __MINGW32__
3455 if (!fork()) {
3456 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3457 exit(0);
3459 #endif
3460 break;
3462 case MP_CMD_KEYDOWN_EVENTS:
3463 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3464 break;
3466 case MP_CMD_SET_MOUSE_POS: {
3467 int pointer_x, pointer_y;
3468 double dx, dy;
3469 pointer_x = cmd->args[0].v.i;
3470 pointer_y = cmd->args[1].v.i;
3471 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3472 #ifdef CONFIG_DVDNAV
3473 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3474 && dx > 0.0 && dy > 0.0) {
3475 int button = -1;
3476 pointer_x = (int) (dx * (double) sh_video->disp_w);
3477 pointer_y = (int) (dy * (double) sh_video->disp_h);
3478 mp_dvdnav_update_mouse_pos(mpctx->stream,
3479 pointer_x, pointer_y, &button);
3480 if (opts->osd_level > 1 && button > 0)
3481 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3482 "Selected button number %d", button);
3484 #endif
3485 #ifdef CONFIG_MENU
3486 if (use_menu && dx >= 0.0 && dy >= 0.0)
3487 menu_update_mouse_pos(dx, dy);
3488 #endif
3489 break;
3492 #ifdef CONFIG_DVDNAV
3493 case MP_CMD_DVDNAV: {
3494 int button = -1;
3495 int i;
3496 enum mp_command_type command = 0;
3497 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3498 break;
3500 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3501 if (cmd->args[0].v.s &&
3502 !strcasecmp(cmd->args[0].v.s,
3503 mp_dvdnav_bindings[i].name))
3504 command = mp_dvdnav_bindings[i].cmd;
3506 mp_dvdnav_handle_input(mpctx->stream, command, &button);
3507 if (opts->osd_level > 1 && button > 0)
3508 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3509 "Selected button number %d", button);
3510 break;
3513 case MP_CMD_SWITCH_TITLE:
3514 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3515 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3516 break;
3518 #endif
3520 case MP_CMD_AF_SWITCH:
3521 if (sh_audio) {
3522 af_uninit(mpctx->mixer.afilter);
3523 af_init(mpctx->mixer.afilter);
3525 case MP_CMD_AF_ADD:
3526 case MP_CMD_AF_DEL: {
3527 if (!sh_audio)
3528 break;
3529 char *af_args = strdup(cmd->args[0].v.s);
3530 char *af_commands = af_args;
3531 char *af_command;
3532 af_instance_t *af;
3533 while ((af_command = strsep(&af_commands, ",")) != NULL) {
3534 if (cmd->id == MP_CMD_AF_DEL) {
3535 af = af_get(mpctx->mixer.afilter, af_command);
3536 if (af != NULL)
3537 af_remove(mpctx->mixer.afilter, af);
3538 } else
3539 af_add(mpctx->mixer.afilter, af_command);
3541 reinit_audio_chain(mpctx);
3542 free(af_args);
3543 break;
3545 case MP_CMD_AF_CLR:
3546 if (!sh_audio)
3547 break;
3548 af_uninit(mpctx->mixer.afilter);
3549 af_init(mpctx->mixer.afilter);
3550 reinit_audio_chain(mpctx);
3551 break;
3552 case MP_CMD_AF_CMDLINE:
3553 if (sh_audio) {
3554 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3555 if (!af) {
3556 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3557 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3558 break;
3560 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3561 af_reinit(sh_audio->afilter, af);
3563 break;
3565 default:
3566 mp_msg(MSGT_CPLAYER, MSGL_V,
3567 "Received unknown cmd %s\n", cmd->name);
3570 old_pause_hack:
3571 switch (cmd->pausing) {
3572 case 1: // "pausing"
3573 pause_player(mpctx);
3574 break;
3575 case 3: // "pausing_toggle"
3576 if (mpctx->paused)
3577 unpause_player(mpctx);
3578 else
3579 pause_player(mpctx);
3580 break;