example.conf: Disambiguate remarks about profiles
[mplayer.git] / command.c
blobbc6aa3c8184df2fe4583470a48e82043516347e4
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 "sub/vobsub.h"
53 #include "sub/spudec.h"
54 #include "path.h"
55 #include "sub/ass_mp.h"
56 #include "stream/tv.h"
57 #include "stream/stream_radio.h"
58 #include "stream/pvr.h"
59 #ifdef CONFIG_DVBIN
60 #include "stream/dvbin.h"
61 #endif
62 #ifdef CONFIG_DVDREAD
63 #include "stream/stream_dvd.h"
64 #endif
65 #include "stream/stream_dvdnav.h"
66 #include "m_struct.h"
67 #include "libmenu/menu.h"
69 #include "mp_core.h"
70 #include "mp_fifo.h"
71 #include "libavutil/avstring.h"
73 extern int use_menu;
75 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
76 double *dx, double *dy)
78 struct MPOpts *opts = &mpctx->opts;
79 struct vo *vo = mpctx->video_out;
80 //remove the borders, if any, and rescale to the range [0,1],[0,1]
81 if (vo_fs) { //we are in full-screen mode
82 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
83 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
84 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
85 iy -= (opts->vo_screenheight - vo->dheight) / 2;
87 if (ix < 0 || ix > vo->dwidth) {
88 *dx = *dy = -1.0;
89 return;
90 } //we are on one of the borders
91 if (iy < 0 || iy > vo->dheight) {
92 *dx = *dy = -1.0;
93 return;
94 } //we are on one of the borders
97 *dx = (double) ix / (double) vo->dwidth;
98 *dy = (double) iy / (double) vo->dheight;
100 mp_msg(MSGT_CPLAYER, MSGL_V,
101 "\r\nrescaled coordinates: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
102 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
103 vo->dheight, vo_fs);
106 static int sub_pos_by_source(MPContext *mpctx, int src)
108 int i, cnt = 0;
109 if (src >= SUB_SOURCES || mpctx->sub_counts[src] == 0)
110 return -1;
111 for (i = 0; i < src; i++)
112 cnt += mpctx->sub_counts[i];
113 return cnt;
116 static int sub_source_and_index_by_pos(MPContext *mpctx, int *pos)
118 int start = 0;
119 int i;
120 for (i = 0; i < SUB_SOURCES; i++) {
121 int cnt = mpctx->sub_counts[i];
122 if (*pos >= start && *pos < start + cnt) {
123 *pos -= start;
124 return i;
126 start += cnt;
128 *pos = -1;
129 return -1;
132 static int sub_source_by_pos(MPContext *mpctx, int pos)
134 return sub_source_and_index_by_pos(mpctx, &pos);
137 static int sub_source_pos(MPContext *mpctx)
139 int pos = mpctx->global_sub_pos;
140 sub_source_and_index_by_pos(mpctx, &pos);
141 return pos;
144 static int sub_source(MPContext *mpctx)
146 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
149 static void update_global_sub_size(MPContext *mpctx)
151 struct MPOpts *opts = &mpctx->opts;
152 int i;
153 int cnt = 0;
155 // update number of demuxer sub streams
156 for (i = 0; i < MAX_S_STREAMS; i++)
157 if (mpctx->d_sub->demuxer->s_streams[i])
158 cnt++;
159 if (cnt > mpctx->sub_counts[SUB_SOURCE_DEMUX])
160 mpctx->sub_counts[SUB_SOURCE_DEMUX] = cnt;
162 // update global size
163 mpctx->global_sub_size = 0;
164 for (i = 0; i < SUB_SOURCES; i++)
165 mpctx->global_sub_size += mpctx->sub_counts[i];
167 // update global_sub_pos if we auto-detected a demuxer sub
168 if (mpctx->global_sub_pos == -1) {
169 int sub_id = -1;
170 if (mpctx->demuxer->sub)
171 sub_id = mpctx->demuxer->sub->id;
172 if (sub_id < 0)
173 sub_id = opts->sub_id;
174 if (sub_id >= 0 && sub_id < mpctx->sub_counts[SUB_SOURCE_DEMUX])
175 mpctx->global_sub_pos = sub_pos_by_source(mpctx, SUB_SOURCE_DEMUX) +
176 sub_id;
181 * \brief Log the currently displayed subtitle to a file
183 * Logs the current or last displayed subtitle together with filename
184 * and time information to ~/.mplayer/subtitle_log
186 * Intended purpose is to allow convenient marking of bogus subtitles
187 * which need to be fixed while watching the movie.
190 static void log_sub(struct MPContext *mpctx)
192 char *fname;
193 FILE *f;
194 int i;
195 struct subtitle *vo_sub_last = mpctx->vo_sub_last;
197 if (mpctx->subdata == NULL || vo_sub_last == NULL)
198 return;
199 fname = get_path("subtitle_log");
200 f = fopen(fname, "a");
201 if (!f)
202 return;
203 fprintf(f, "----------------------------------------------------------\n");
204 if (mpctx->subdata->sub_uses_time) {
205 fprintf(f,
206 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
207 mpctx->filename, vo_sub_last->start / 360000,
208 (vo_sub_last->start / 6000) % 60,
209 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
210 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
211 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
212 } else {
213 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
214 vo_sub_last->start, vo_sub_last->end);
216 for (i = 0; i < vo_sub_last->lines; i++) {
217 fprintf(f, "%s\n", vo_sub_last->text[i]);
219 fclose(f);
223 /// \defgroup Properties
224 ///@{
226 /// \defgroup GeneralProperties General properties
227 /// \ingroup Properties
228 ///@{
230 static int mp_property_generic_option(struct m_option *prop, int action,
231 void *arg, MPContext *mpctx)
233 char *optname = prop->priv;
234 const struct m_option *opt = m_config_get_option(mpctx->mconfig, optname);
235 void *valptr = m_option_get_ptr(opt, &mpctx->opts);
237 switch (action) {
238 case M_PROPERTY_GET_TYPE:
239 *(const struct m_option **)arg = opt;
240 return M_PROPERTY_OK;
241 case M_PROPERTY_GET:
242 m_option_copy(opt, arg, valptr);
243 return M_PROPERTY_OK;
244 case M_PROPERTY_SET:
245 m_option_copy(opt, valptr, arg);
246 return M_PROPERTY_OK;
247 case M_PROPERTY_STEP_UP:
248 if (opt->type == &m_option_type_choice) {
249 int v = *(int *) valptr;
250 int best = v;
251 struct m_opt_choice_alternatives *alt;
252 for (alt = opt->priv; alt->name; alt++)
253 if ((unsigned) alt->value - v - 1 < (unsigned) best - v - 1)
254 best = alt->value;
255 *(int *) valptr = best;
256 return M_PROPERTY_OK;
258 break;
260 return M_PROPERTY_NOT_IMPLEMENTED;
263 /// OSD level (RW)
264 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
265 MPContext *mpctx)
267 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
270 /// Loop (RW)
271 static int mp_property_loop(m_option_t *prop, int action, void *arg,
272 MPContext *mpctx)
274 struct MPOpts *opts = &mpctx->opts;
275 switch (action) {
276 case M_PROPERTY_PRINT:
277 if (!arg) return M_PROPERTY_ERROR;
278 if (opts->loop_times < 0)
279 *(char**)arg = strdup("off");
280 else if (opts->loop_times == 0)
281 *(char**)arg = strdup("inf");
282 else
283 break;
284 return M_PROPERTY_OK;
286 return m_property_int_range(prop, action, arg, &opts->loop_times);
289 /// Playback speed (RW)
290 static int mp_property_playback_speed(m_option_t *prop, int action,
291 void *arg, MPContext *mpctx)
293 struct MPOpts *opts = &mpctx->opts;
294 switch (action) {
295 case M_PROPERTY_SET:
296 if (!arg)
297 return M_PROPERTY_ERROR;
298 M_PROPERTY_CLAMP(prop, *(float *) arg);
299 opts->playback_speed = *(float *) arg;
300 reinit_audio_chain(mpctx);
301 return M_PROPERTY_OK;
302 case M_PROPERTY_STEP_UP:
303 case M_PROPERTY_STEP_DOWN:
304 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
305 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
306 M_PROPERTY_CLAMP(prop, opts->playback_speed);
307 reinit_audio_chain(mpctx);
308 return M_PROPERTY_OK;
310 return m_property_float_range(prop, action, arg, &opts->playback_speed);
313 /// filename with path (RO)
314 static int mp_property_path(m_option_t *prop, int action, void *arg,
315 MPContext *mpctx)
317 return m_property_string_ro(prop, action, arg, mpctx->filename);
320 /// filename without path (RO)
321 static int mp_property_filename(m_option_t *prop, int action, void *arg,
322 MPContext *mpctx)
324 char *f;
325 if (!mpctx->filename)
326 return M_PROPERTY_UNAVAILABLE;
327 f = (char *)mp_basename(mpctx->filename);
328 if (!*f)
329 f = mpctx->filename;
330 return m_property_string_ro(prop, action, arg, f);
333 /// Demuxer name (RO)
334 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
335 MPContext *mpctx)
337 if (!mpctx->demuxer)
338 return M_PROPERTY_UNAVAILABLE;
339 return m_property_string_ro(prop, action, arg,
340 (char *) mpctx->demuxer->desc->name);
343 /// Position in the stream (RW)
344 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
345 MPContext *mpctx)
347 if (!mpctx->demuxer || !mpctx->demuxer->stream)
348 return M_PROPERTY_UNAVAILABLE;
349 if (!arg)
350 return M_PROPERTY_ERROR;
351 switch (action) {
352 case M_PROPERTY_GET:
353 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
354 return M_PROPERTY_OK;
355 case M_PROPERTY_SET:
356 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
357 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
358 return M_PROPERTY_OK;
360 return M_PROPERTY_NOT_IMPLEMENTED;
363 /// Stream start offset (RO)
364 static int mp_property_stream_start(m_option_t *prop, int action,
365 void *arg, MPContext *mpctx)
367 if (!mpctx->demuxer || !mpctx->demuxer->stream)
368 return M_PROPERTY_UNAVAILABLE;
369 switch (action) {
370 case M_PROPERTY_GET:
371 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
372 return M_PROPERTY_OK;
374 return M_PROPERTY_NOT_IMPLEMENTED;
377 /// Stream end offset (RO)
378 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
379 MPContext *mpctx)
381 if (!mpctx->demuxer || !mpctx->demuxer->stream)
382 return M_PROPERTY_UNAVAILABLE;
383 switch (action) {
384 case M_PROPERTY_GET:
385 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
386 return M_PROPERTY_OK;
388 return M_PROPERTY_NOT_IMPLEMENTED;
391 /// Stream length (RO)
392 static int mp_property_stream_length(m_option_t *prop, int action,
393 void *arg, MPContext *mpctx)
395 if (!mpctx->demuxer || !mpctx->demuxer->stream)
396 return M_PROPERTY_UNAVAILABLE;
397 switch (action) {
398 case M_PROPERTY_GET:
399 *(off_t *) arg =
400 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
401 return M_PROPERTY_OK;
403 return M_PROPERTY_NOT_IMPLEMENTED;
406 /// Current stream position in seconds (RO)
407 static int mp_property_stream_time_pos(m_option_t *prop, int action,
408 void *arg, MPContext *mpctx)
410 if (!mpctx->demuxer || mpctx->demuxer->stream_pts == MP_NOPTS_VALUE)
411 return M_PROPERTY_UNAVAILABLE;
413 return m_property_time_ro(prop, action, arg, mpctx->demuxer->stream_pts);
417 /// Media length in seconds (RO)
418 static int mp_property_length(m_option_t *prop, int action, void *arg,
419 MPContext *mpctx)
421 double len;
423 if (!mpctx->demuxer ||
424 !(int) (len = get_time_length(mpctx)))
425 return M_PROPERTY_UNAVAILABLE;
427 return m_property_time_ro(prop, action, arg, len);
430 /// Current position in percent (RW)
431 static int mp_property_percent_pos(m_option_t *prop, int action,
432 void *arg, MPContext *mpctx) {
433 int pos;
435 if (!mpctx->demuxer)
436 return M_PROPERTY_UNAVAILABLE;
438 switch(action) {
439 case M_PROPERTY_SET:
440 if(!arg) return M_PROPERTY_ERROR;
441 M_PROPERTY_CLAMP(prop, *(int*)arg);
442 pos = *(int*)arg;
443 break;
444 case M_PROPERTY_STEP_UP:
445 case M_PROPERTY_STEP_DOWN:
446 pos = get_percent_pos(mpctx);
447 pos += (arg ? *(int*)arg : 10) *
448 (action == M_PROPERTY_STEP_UP ? 1 : -1);
449 M_PROPERTY_CLAMP(prop, pos);
450 break;
451 default:
452 return m_property_int_ro(prop, action, arg, get_percent_pos(mpctx));
455 queue_seek(mpctx, MPSEEK_FACTOR, pos / 100.0, 0);
456 return M_PROPERTY_OK;
459 /// Current position in seconds (RW)
460 static int mp_property_time_pos(m_option_t *prop, int action,
461 void *arg, MPContext *mpctx) {
462 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
463 return M_PROPERTY_UNAVAILABLE;
465 switch(action) {
466 case M_PROPERTY_SET:
467 if(!arg) return M_PROPERTY_ERROR;
468 M_PROPERTY_CLAMP(prop, *(double*)arg);
469 queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double*)arg, 0);
470 return M_PROPERTY_OK;
471 case M_PROPERTY_STEP_UP:
472 case M_PROPERTY_STEP_DOWN:
473 queue_seek(mpctx, MPSEEK_RELATIVE, (arg ? *(double*)arg : 10.0) *
474 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0), 0);
475 return M_PROPERTY_OK;
477 return m_property_time_ro(prop, action, arg, get_current_time(mpctx));
480 /// Current chapter (RW)
481 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
482 MPContext *mpctx)
484 struct MPOpts *opts = &mpctx->opts;
485 int chapter = -1;
486 int step_all;
487 char *chapter_name = NULL;
489 if (mpctx->demuxer)
490 chapter = get_current_chapter(mpctx);
491 if (chapter < -1)
492 return M_PROPERTY_UNAVAILABLE;
494 switch (action) {
495 case M_PROPERTY_GET:
496 if (!arg)
497 return M_PROPERTY_ERROR;
498 *(int *) arg = chapter;
499 return M_PROPERTY_OK;
500 case M_PROPERTY_PRINT: {
501 if (!arg)
502 return M_PROPERTY_ERROR;
503 chapter_name = chapter_display_name(mpctx, chapter);
504 if (!chapter_name)
505 return M_PROPERTY_UNAVAILABLE;
506 *(char **) arg = chapter_name;
507 return M_PROPERTY_OK;
509 case M_PROPERTY_SET:
510 if (!arg)
511 return M_PROPERTY_ERROR;
512 M_PROPERTY_CLAMP(prop, *(int*)arg);
513 step_all = *(int *)arg - chapter;
514 chapter += step_all;
515 break;
516 case M_PROPERTY_STEP_UP:
517 case M_PROPERTY_STEP_DOWN: {
518 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
519 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
520 chapter += step_all;
521 if (chapter < 0)
522 chapter = 0;
523 break;
525 default:
526 return M_PROPERTY_NOT_IMPLEMENTED;
529 double next_pts = 0;
530 queue_seek(mpctx, MPSEEK_NONE, 0, 0);
531 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
532 if (chapter >= 0) {
533 if (next_pts > -1.0)
534 queue_seek(mpctx, MPSEEK_ABSOLUTE, next_pts, 0);
535 if (chapter_name)
536 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
537 "Chapter: (%d) %s", chapter + 1, chapter_name);
538 } else if (step_all > 0)
539 queue_seek(mpctx, MPSEEK_RELATIVE, 1000000000, 0);
540 else
541 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
542 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
543 talloc_free(chapter_name);
544 return M_PROPERTY_OK;
547 /// Number of chapters in file
548 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
549 MPContext *mpctx)
551 if (!mpctx->demuxer)
552 return M_PROPERTY_UNAVAILABLE;
553 if (mpctx->demuxer->num_chapters == 0)
554 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
555 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
558 /// Current dvd angle (RW)
559 static int mp_property_angle(m_option_t *prop, int action, void *arg,
560 MPContext *mpctx)
562 struct MPOpts *opts = &mpctx->opts;
563 int angle = -1;
564 int angles;
565 char *angle_name = NULL;
567 if (mpctx->demuxer)
568 angle = demuxer_get_current_angle(mpctx->demuxer);
569 if (angle < 0)
570 return M_PROPERTY_UNAVAILABLE;
571 angles = demuxer_angles_count(mpctx->demuxer);
572 if (angles <= 1)
573 return M_PROPERTY_UNAVAILABLE;
575 switch (action) {
576 case M_PROPERTY_GET:
577 if (!arg)
578 return M_PROPERTY_ERROR;
579 *(int *) arg = angle;
580 return M_PROPERTY_OK;
581 case M_PROPERTY_PRINT: {
582 if (!arg)
583 return M_PROPERTY_ERROR;
584 angle_name = calloc(1, 64);
585 if (!angle_name)
586 return M_PROPERTY_UNAVAILABLE;
587 snprintf(angle_name, 64, "%d/%d", angle, angles);
588 *(char **) arg = angle_name;
589 return M_PROPERTY_OK;
591 case M_PROPERTY_SET:
592 if (!arg)
593 return M_PROPERTY_ERROR;
594 angle = *(int *)arg;
595 M_PROPERTY_CLAMP(prop, angle);
596 break;
597 case M_PROPERTY_STEP_UP:
598 case M_PROPERTY_STEP_DOWN: {
599 int step = 0;
600 if(arg)
601 step = *(int*)arg;
602 if(!step)
603 step = 1;
604 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
605 angle += step;
606 if (angle < 1) //cycle
607 angle = angles;
608 break;
610 default:
611 return M_PROPERTY_NOT_IMPLEMENTED;
613 angle = demuxer_set_angle(mpctx->demuxer, angle);
614 if (angle >= 0) {
615 struct sh_video *sh_video = mpctx->demuxer->video->sh;
616 if (sh_video)
617 resync_video_stream(sh_video);
619 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
620 if (sh_audio)
621 resync_audio_stream(sh_audio);
624 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
625 "Angle: %d/%d", angle, angles);
626 free(angle_name);
627 return M_PROPERTY_OK;
630 /// Demuxer meta data
631 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
632 MPContext *mpctx) {
633 m_property_action_t* ka;
634 char* meta;
635 static const m_option_t key_type =
636 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
637 if (!mpctx->demuxer)
638 return M_PROPERTY_UNAVAILABLE;
640 switch(action) {
641 case M_PROPERTY_GET:
642 if(!arg) return M_PROPERTY_ERROR;
643 *(char***)arg = mpctx->demuxer->info;
644 return M_PROPERTY_OK;
645 case M_PROPERTY_KEY_ACTION:
646 if(!arg) return M_PROPERTY_ERROR;
647 ka = arg;
648 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
649 return M_PROPERTY_UNKNOWN;
650 switch(ka->action) {
651 case M_PROPERTY_GET:
652 if(!ka->arg) return M_PROPERTY_ERROR;
653 *(char**)ka->arg = meta;
654 return M_PROPERTY_OK;
655 case M_PROPERTY_GET_TYPE:
656 if(!ka->arg) return M_PROPERTY_ERROR;
657 *(const m_option_t**)ka->arg = &key_type;
658 return M_PROPERTY_OK;
661 return M_PROPERTY_NOT_IMPLEMENTED;
664 static int mp_property_pause(m_option_t *prop, int action, void *arg,
665 void *ctx)
667 MPContext *mpctx = ctx;
669 switch (action) {
670 case M_PROPERTY_SET:
671 if (!arg)
672 return M_PROPERTY_ERROR;
673 if (mpctx->paused == (bool)*(int *) arg)
674 return M_PROPERTY_OK;
675 case M_PROPERTY_STEP_UP:
676 case M_PROPERTY_STEP_DOWN:
677 if (mpctx->paused) {
678 unpause_player(mpctx);
679 mpctx->osd_function = OSD_PLAY;
681 else {
682 pause_player(mpctx);
683 mpctx->osd_function = OSD_PAUSE;
685 return M_PROPERTY_OK;
686 default:
687 return m_property_flag(prop, action, arg, &mpctx->paused);
692 ///@}
694 /// \defgroup AudioProperties Audio properties
695 /// \ingroup Properties
696 ///@{
698 /// Volume (RW)
699 static int mp_property_volume(m_option_t *prop, int action, void *arg,
700 MPContext *mpctx)
703 if (!mpctx->sh_audio)
704 return M_PROPERTY_UNAVAILABLE;
706 switch (action) {
707 case M_PROPERTY_GET:
708 if (!arg)
709 return M_PROPERTY_ERROR;
710 mixer_getbothvolume(&mpctx->mixer, arg);
711 return M_PROPERTY_OK;
712 case M_PROPERTY_PRINT:{
713 float vol;
714 if (!arg)
715 return M_PROPERTY_ERROR;
716 mixer_getbothvolume(&mpctx->mixer, &vol);
717 return m_property_float_range(prop, action, arg, &vol);
719 case M_PROPERTY_STEP_UP:
720 case M_PROPERTY_STEP_DOWN:
721 case M_PROPERTY_SET:
722 break;
723 default:
724 return M_PROPERTY_NOT_IMPLEMENTED;
727 if (mpctx->edl_muted)
728 return M_PROPERTY_DISABLED;
729 mpctx->user_muted = 0;
731 switch (action) {
732 case M_PROPERTY_SET:
733 if (!arg)
734 return M_PROPERTY_ERROR;
735 M_PROPERTY_CLAMP(prop, *(float *) arg);
736 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
737 return M_PROPERTY_OK;
738 case M_PROPERTY_STEP_UP:
739 if (arg && *(float *) arg <= 0)
740 mixer_decvolume(&mpctx->mixer);
741 else
742 mixer_incvolume(&mpctx->mixer);
743 return M_PROPERTY_OK;
744 case M_PROPERTY_STEP_DOWN:
745 if (arg && *(float *) arg <= 0)
746 mixer_incvolume(&mpctx->mixer);
747 else
748 mixer_decvolume(&mpctx->mixer);
749 return M_PROPERTY_OK;
751 return M_PROPERTY_NOT_IMPLEMENTED;
754 /// Mute (RW)
755 static int mp_property_mute(m_option_t *prop, int action, void *arg,
756 MPContext *mpctx)
759 if (!mpctx->sh_audio)
760 return M_PROPERTY_UNAVAILABLE;
762 switch (action) {
763 case M_PROPERTY_SET:
764 if (mpctx->edl_muted)
765 return M_PROPERTY_DISABLED;
766 if (!arg)
767 return M_PROPERTY_ERROR;
768 if ((!!*(int *) arg) != mpctx->mixer.muted)
769 mixer_mute(&mpctx->mixer);
770 mpctx->user_muted = mpctx->mixer.muted;
771 return M_PROPERTY_OK;
772 case M_PROPERTY_STEP_UP:
773 case M_PROPERTY_STEP_DOWN:
774 if (mpctx->edl_muted)
775 return M_PROPERTY_DISABLED;
776 mixer_mute(&mpctx->mixer);
777 mpctx->user_muted = mpctx->mixer.muted;
778 return M_PROPERTY_OK;
779 case M_PROPERTY_PRINT:
780 if (!arg)
781 return M_PROPERTY_ERROR;
782 if (mpctx->edl_muted) {
783 *(char **) arg = strdup(mp_gtext("enabled (EDL)"));
784 return M_PROPERTY_OK;
786 default:
787 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
792 /// Audio delay (RW)
793 static int mp_property_audio_delay(m_option_t *prop, int action,
794 void *arg, MPContext *mpctx)
796 if (!(mpctx->sh_audio && mpctx->sh_video))
797 return M_PROPERTY_UNAVAILABLE;
798 switch (action) {
799 case M_PROPERTY_SET:
800 case M_PROPERTY_STEP_UP:
801 case M_PROPERTY_STEP_DOWN: {
802 int ret;
803 float delay = audio_delay;
804 ret = m_property_delay(prop, action, arg, &audio_delay);
805 if (ret != M_PROPERTY_OK)
806 return ret;
807 if (mpctx->sh_audio)
808 mpctx->delay -= audio_delay - delay;
810 return M_PROPERTY_OK;
811 default:
812 return m_property_delay(prop, action, arg, &audio_delay);
816 /// Audio codec tag (RO)
817 static int mp_property_audio_format(m_option_t *prop, int action,
818 void *arg, MPContext *mpctx)
820 if (!mpctx->sh_audio)
821 return M_PROPERTY_UNAVAILABLE;
822 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
825 /// Audio codec name (RO)
826 static int mp_property_audio_codec(m_option_t *prop, int action,
827 void *arg, MPContext *mpctx)
829 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
830 return M_PROPERTY_UNAVAILABLE;
831 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
834 /// Audio bitrate (RO)
835 static int mp_property_audio_bitrate(m_option_t *prop, int action,
836 void *arg, MPContext *mpctx)
838 if (!mpctx->sh_audio)
839 return M_PROPERTY_UNAVAILABLE;
840 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
843 /// Samplerate (RO)
844 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
845 MPContext *mpctx)
847 if (!mpctx->sh_audio)
848 return M_PROPERTY_UNAVAILABLE;
849 switch(action) {
850 case M_PROPERTY_PRINT:
851 if(!arg) return M_PROPERTY_ERROR;
852 *(char**)arg = malloc(16);
853 sprintf(*(char**)arg,"%d kHz",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 = strdup("mono");
872 break;
873 case 2:
874 *(char **) arg = strdup("stereo");
875 break;
876 default:
877 *(char **) arg = malloc(32);
878 sprintf(*(char **) arg, "%d channels", 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 = strdup("center");
907 else if (bal == -1.f)
908 *str = strdup("left only");
909 else if (bal == 1.f)
910 *str = strdup("right only");
911 else {
912 unsigned right = (bal + 1.f) / 2.f * 100.f;
913 *str = malloc(sizeof("left xxx%, right xxx%"));
914 sprintf(*str, "left %d%%, right %d%%", 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 current_id = mpctx->sh_audio ? mpctx->sh_audio->aid : -2;
945 switch (action) {
946 case M_PROPERTY_GET:
947 if (!arg)
948 return M_PROPERTY_ERROR;
949 *(int *) arg = current_id;
950 return M_PROPERTY_OK;
951 case M_PROPERTY_PRINT:
952 if (!arg)
953 return M_PROPERTY_ERROR;
955 if (current_id < 0)
956 *(char **) arg = strdup(mp_gtext("disabled"));
957 else {
958 char lang[40];
959 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
960 sh_audio_t* sh = mpctx->sh_audio;
961 if (sh && sh->lang)
962 av_strlcpy(lang, sh->lang, 40);
963 #ifdef CONFIG_DVDREAD
964 else if (mpctx->stream->type == STREAMTYPE_DVD) {
965 int code = dvd_lang_from_aid(mpctx->stream, current_id);
966 if (code) {
967 lang[0] = code >> 8;
968 lang[1] = code;
969 lang[2] = 0;
972 #endif
974 #ifdef CONFIG_DVDNAV
975 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
976 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
977 #endif
978 *(char **) arg = malloc(64);
979 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
981 return M_PROPERTY_OK;
983 case M_PROPERTY_STEP_UP:
984 case M_PROPERTY_SET:
985 if (action == M_PROPERTY_SET && arg)
986 tmp = *((int *) arg);
987 else
988 tmp = -1;
989 int new_id = demuxer_switch_audio(mpctx->d_audio->demuxer, tmp);
990 if (new_id != current_id)
991 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
992 if (new_id != current_id && new_id >= 0) {
993 sh_audio_t *sh2;
994 sh2 = mpctx->d_audio->demuxer->a_streams[mpctx->demuxer->audio->id];
995 sh2->ds = mpctx->demuxer->audio;
996 mpctx->sh_audio = sh2;
997 reinit_audio_chain(mpctx);
999 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
1000 return M_PROPERTY_OK;
1001 default:
1002 return M_PROPERTY_NOT_IMPLEMENTED;
1007 /// Selected video id (RW)
1008 static int mp_property_video(m_option_t *prop, int action, void *arg,
1009 MPContext *mpctx)
1011 struct MPOpts *opts = &mpctx->opts;
1012 int current_id, tmp;
1013 if (!mpctx->demuxer || !mpctx->d_video)
1014 return M_PROPERTY_UNAVAILABLE;
1015 current_id = mpctx->d_video->id;
1017 switch (action) {
1018 case M_PROPERTY_GET:
1019 if (!arg)
1020 return M_PROPERTY_ERROR;
1021 *(int *) arg = current_id;
1022 return M_PROPERTY_OK;
1023 case M_PROPERTY_PRINT:
1024 if (!arg)
1025 return M_PROPERTY_ERROR;
1027 if (current_id < 0)
1028 *(char **) arg = strdup(mp_gtext("disabled"));
1029 else {
1030 char lang[40];
1031 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
1032 *(char **) arg = malloc(64);
1033 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
1035 return M_PROPERTY_OK;
1037 case M_PROPERTY_STEP_UP:
1038 case M_PROPERTY_SET:
1039 if (action == M_PROPERTY_SET && arg)
1040 tmp = *((int *) arg);
1041 else
1042 tmp = -1;
1043 opts->video_id = demuxer_switch_video(mpctx->d_video->demuxer, tmp);
1044 if (opts->video_id == -2
1045 || (opts->video_id > -1 && mpctx->d_video->id != current_id
1046 && current_id != -2))
1047 uninit_player(mpctx, INITIALIZED_VCODEC |
1048 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
1049 if (opts->video_id > -1 && mpctx->d_video->id != current_id) {
1050 sh_video_t *sh2;
1051 sh2 = mpctx->d_video->demuxer->v_streams[mpctx->d_video->id];
1052 if (sh2) {
1053 sh2->ds = mpctx->d_video;
1054 mpctx->sh_video = sh2;
1055 reinit_video_chain(mpctx);
1058 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_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
1079 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1080 &prog) == DEMUXER_CTRL_NOTIMPL)
1081 return M_PROPERTY_ERROR;
1083 if (prog.aid < 0 && prog.vid < 0) {
1084 mp_msg(MSGT_CPLAYER, MSGL_ERR, "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;
1096 ///@}
1098 /// \defgroup VideoProperties Video properties
1099 /// \ingroup Properties
1100 ///@{
1102 /// Fullscreen state (RW)
1103 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1104 MPContext *mpctx)
1107 if (!mpctx->video_out)
1108 return M_PROPERTY_UNAVAILABLE;
1110 switch (action) {
1111 case M_PROPERTY_SET:
1112 if (!arg)
1113 return M_PROPERTY_ERROR;
1114 M_PROPERTY_CLAMP(prop, *(int *) arg);
1115 if (vo_fs == !!*(int *) arg)
1116 return M_PROPERTY_OK;
1117 case M_PROPERTY_STEP_UP:
1118 case M_PROPERTY_STEP_DOWN:
1119 if (mpctx->video_out->config_ok)
1120 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1121 mpctx->opts.fullscreen = vo_fs;
1122 return M_PROPERTY_OK;
1123 default:
1124 return m_property_flag(prop, action, arg, &vo_fs);
1128 static int mp_property_deinterlace(m_option_t *prop, int action,
1129 void *arg, MPContext *mpctx)
1131 int deinterlace;
1132 vf_instance_t *vf;
1133 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1134 return M_PROPERTY_UNAVAILABLE;
1135 vf = mpctx->sh_video->vfilter;
1136 switch (action) {
1137 case M_PROPERTY_GET:
1138 if (!arg)
1139 return M_PROPERTY_ERROR;
1140 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1141 return M_PROPERTY_OK;
1142 case M_PROPERTY_SET:
1143 if (!arg)
1144 return M_PROPERTY_ERROR;
1145 M_PROPERTY_CLAMP(prop, *(int *) arg);
1146 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1147 return M_PROPERTY_OK;
1148 case M_PROPERTY_STEP_UP:
1149 case M_PROPERTY_STEP_DOWN:
1150 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1151 deinterlace = !deinterlace;
1152 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1153 return M_PROPERTY_OK;
1155 int value = 0;
1156 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1157 return m_property_flag_ro(prop, action, arg, value);
1160 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1161 void *arg, MPContext *mpctx)
1163 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1164 return M_PROPERTY_UNAVAILABLE;
1166 struct vf_instance *vf = mpctx->sh_video->vfilter;
1167 int colorspace;
1168 switch (action) {
1169 case M_PROPERTY_GET:
1170 if (!arg)
1171 return M_PROPERTY_ERROR;
1172 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1173 return M_PROPERTY_UNAVAILABLE;
1174 return M_PROPERTY_OK;
1175 case M_PROPERTY_PRINT:
1176 if (!arg)
1177 return M_PROPERTY_ERROR;
1178 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1179 return M_PROPERTY_UNAVAILABLE;
1180 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1181 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1182 *(char **)arg = strdup("Unknown");
1183 else
1184 *(char**)arg = strdup(names[colorspace]);
1185 return M_PROPERTY_OK;
1186 case M_PROPERTY_SET:
1187 if (!arg)
1188 return M_PROPERTY_ERROR;
1189 M_PROPERTY_CLAMP(prop, *(int *) arg);
1190 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1191 return M_PROPERTY_OK;
1192 case M_PROPERTY_STEP_UP:;
1193 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1194 return M_PROPERTY_UNAVAILABLE;
1195 colorspace += 1;
1196 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1197 return M_PROPERTY_OK;
1199 return M_PROPERTY_NOT_IMPLEMENTED;
1202 static int mp_property_capture(m_option_t *prop, int action,
1203 void *arg, MPContext *mpctx)
1205 struct MPOpts *opts = &mpctx->opts;
1207 if (!mpctx->stream)
1208 return M_PROPERTY_UNAVAILABLE;
1210 if (!opts->capture_dump) {
1211 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1212 "Capturing not enabled (forgot -capture parameter?)\n");
1213 return M_PROPERTY_ERROR;
1216 int capturing = !!mpctx->stream->capture_file;
1218 int ret = m_property_flag(prop, action, arg, &capturing);
1219 if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
1220 if (capturing) {
1221 mpctx->stream->capture_file = fopen(opts->stream_dump_name, "wb");
1222 if (!mpctx->stream->capture_file) {
1223 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1224 "Error opening capture file: %s\n", strerror(errno));
1225 ret = M_PROPERTY_ERROR;
1227 } else {
1228 fclose(mpctx->stream->capture_file);
1229 mpctx->stream->capture_file = NULL;
1233 return ret;
1236 /// Panscan (RW)
1237 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1238 MPContext *mpctx)
1241 if (!mpctx->video_out
1242 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1243 return M_PROPERTY_UNAVAILABLE;
1245 switch (action) {
1246 case M_PROPERTY_SET:
1247 if (!arg)
1248 return M_PROPERTY_ERROR;
1249 M_PROPERTY_CLAMP(prop, *(float *) arg);
1250 vo_panscan = *(float *) arg;
1251 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1252 return M_PROPERTY_OK;
1253 case M_PROPERTY_STEP_UP:
1254 case M_PROPERTY_STEP_DOWN:
1255 vo_panscan += (arg ? *(float *) arg : 0.1) *
1256 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1257 if (vo_panscan > 1)
1258 vo_panscan = 1;
1259 else if (vo_panscan < 0)
1260 vo_panscan = 0;
1261 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1262 return M_PROPERTY_OK;
1263 default:
1264 return m_property_float_range(prop, action, arg, &vo_panscan);
1268 /// Helper to set vo flags.
1269 /** \ingroup PropertyImplHelper
1271 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1272 int vo_ctrl, int *vo_var, MPContext *mpctx)
1275 if (!mpctx->video_out)
1276 return M_PROPERTY_UNAVAILABLE;
1278 switch (action) {
1279 case M_PROPERTY_SET:
1280 if (!arg)
1281 return M_PROPERTY_ERROR;
1282 M_PROPERTY_CLAMP(prop, *(int *) arg);
1283 if (*vo_var == !!*(int *) arg)
1284 return M_PROPERTY_OK;
1285 case M_PROPERTY_STEP_UP:
1286 case M_PROPERTY_STEP_DOWN:
1287 if (mpctx->video_out->config_ok)
1288 vo_control(mpctx->video_out, vo_ctrl, 0);
1289 return M_PROPERTY_OK;
1290 default:
1291 return m_property_flag(prop, action, arg, vo_var);
1295 /// Window always on top (RW)
1296 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1297 MPContext *mpctx)
1299 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1300 &mpctx->opts.vo_ontop, mpctx);
1303 /// Display in the root window (RW)
1304 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1305 MPContext *mpctx)
1307 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1308 &vo_rootwin, mpctx);
1311 /// Show window borders (RW)
1312 static int mp_property_border(m_option_t *prop, int action, void *arg,
1313 MPContext *mpctx)
1315 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1316 &vo_border, mpctx);
1319 /// Framedropping state (RW)
1320 static int mp_property_framedropping(m_option_t *prop, int action,
1321 void *arg, MPContext *mpctx)
1324 if (!mpctx->sh_video)
1325 return M_PROPERTY_UNAVAILABLE;
1327 switch (action) {
1328 case M_PROPERTY_PRINT:
1329 if (!arg)
1330 return M_PROPERTY_ERROR;
1331 *(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
1332 (frame_dropping == 2 ? mp_gtext("hard") :
1333 mp_gtext("disabled")));
1334 return M_PROPERTY_OK;
1335 default:
1336 return m_property_choice(prop, action, arg, &frame_dropping);
1340 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1341 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1342 MPContext *mpctx)
1344 int *gamma = (int *)((char *)&mpctx->opts + prop->offset);
1345 int r, val;
1347 if (!mpctx->sh_video)
1348 return M_PROPERTY_UNAVAILABLE;
1350 if (gamma[0] == 1000) {
1351 gamma[0] = 0;
1352 get_video_colors(mpctx->sh_video, prop->name, gamma);
1355 switch (action) {
1356 case M_PROPERTY_SET:
1357 if (!arg)
1358 return M_PROPERTY_ERROR;
1359 M_PROPERTY_CLAMP(prop, *(int *) arg);
1360 *gamma = *(int *) arg;
1361 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1362 if (r <= 0)
1363 break;
1364 return r;
1365 case M_PROPERTY_GET:
1366 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1367 if (!arg)
1368 return M_PROPERTY_ERROR;
1369 *(int *)arg = val;
1370 return M_PROPERTY_OK;
1372 break;
1373 case M_PROPERTY_STEP_UP:
1374 case M_PROPERTY_STEP_DOWN:
1375 *gamma += (arg ? *(int *) arg : 1) *
1376 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1377 M_PROPERTY_CLAMP(prop, *gamma);
1378 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1379 if (r <= 0)
1380 break;
1381 return r;
1382 default:
1383 return M_PROPERTY_NOT_IMPLEMENTED;
1386 #ifdef CONFIG_TV
1387 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1388 int l = strlen(prop->name);
1389 char tv_prop[3 + l + 1];
1390 sprintf(tv_prop, "tv_%s", prop->name);
1391 return mp_property_do(tv_prop, action, arg, mpctx);
1393 #endif
1395 return M_PROPERTY_UNAVAILABLE;
1398 /// VSync (RW)
1399 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1400 MPContext *mpctx)
1402 return m_property_flag(prop, action, arg, &vo_vsync);
1405 /// Video codec tag (RO)
1406 static int mp_property_video_format(m_option_t *prop, int action,
1407 void *arg, MPContext *mpctx)
1409 char* meta;
1410 if (!mpctx->sh_video)
1411 return M_PROPERTY_UNAVAILABLE;
1412 switch(action) {
1413 case M_PROPERTY_PRINT:
1414 if (!arg)
1415 return M_PROPERTY_ERROR;
1416 switch(mpctx->sh_video->format) {
1417 case 0x10000001:
1418 meta = strdup ("mpeg1"); break;
1419 case 0x10000002:
1420 meta = strdup ("mpeg2"); break;
1421 case 0x10000004:
1422 meta = strdup ("mpeg4"); break;
1423 case 0x10000005:
1424 meta = strdup ("h264"); break;
1425 default:
1426 if(mpctx->sh_video->format >= 0x20202020) {
1427 meta = malloc(5);
1428 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1429 } else {
1430 meta = malloc(20);
1431 sprintf (meta, "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, mpctx->sh_video->codec->name);
1450 /// Video bitrate (RO)
1451 static int mp_property_video_bitrate(m_option_t *prop, int action,
1452 void *arg, MPContext *mpctx)
1454 if (!mpctx->sh_video)
1455 return M_PROPERTY_UNAVAILABLE;
1456 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1459 /// Video display width (RO)
1460 static int mp_property_width(m_option_t *prop, int action, void *arg,
1461 MPContext *mpctx)
1463 if (!mpctx->sh_video)
1464 return M_PROPERTY_UNAVAILABLE;
1465 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1468 /// Video display height (RO)
1469 static int mp_property_height(m_option_t *prop, int action, void *arg,
1470 MPContext *mpctx)
1472 if (!mpctx->sh_video)
1473 return M_PROPERTY_UNAVAILABLE;
1474 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1477 /// Video fps (RO)
1478 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1479 MPContext *mpctx)
1481 if (!mpctx->sh_video)
1482 return M_PROPERTY_UNAVAILABLE;
1483 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1486 /// Video aspect (RO)
1487 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1488 MPContext *mpctx)
1490 if (!mpctx->sh_video)
1491 return M_PROPERTY_UNAVAILABLE;
1492 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1495 ///@}
1497 /// \defgroup SubProprties Subtitles properties
1498 /// \ingroup Properties
1499 ///@{
1501 /// Text subtitle position (RW)
1502 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1503 MPContext *mpctx)
1505 switch (action) {
1506 case M_PROPERTY_SET:
1507 if (!arg)
1508 return M_PROPERTY_ERROR;
1509 case M_PROPERTY_STEP_UP:
1510 case M_PROPERTY_STEP_DOWN:
1511 vo_osd_changed(OSDTYPE_SUBTITLE);
1512 default:
1513 return m_property_int_range(prop, action, arg, &sub_pos);
1517 /// Selected subtitles (RW)
1518 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1519 MPContext *mpctx)
1521 struct MPOpts *opts = &mpctx->opts;
1522 demux_stream_t *const d_sub = mpctx->d_sub;
1523 int source = -1, reset_spu = 0;
1524 int source_pos = -1;
1526 update_global_sub_size(mpctx);
1527 const int global_sub_size = mpctx->global_sub_size;
1529 if (global_sub_size <= 0)
1530 return M_PROPERTY_UNAVAILABLE;
1532 switch (action) {
1533 case M_PROPERTY_GET:
1534 if (!arg)
1535 return M_PROPERTY_ERROR;
1536 *(int *) arg = mpctx->global_sub_pos;
1537 return M_PROPERTY_OK;
1538 case M_PROPERTY_PRINT:
1539 if (!arg)
1540 return M_PROPERTY_ERROR;
1541 *(char **) arg = malloc(64);
1542 (*(char **) arg)[63] = 0;
1543 char *sub_name = NULL;
1544 if (mpctx->subdata)
1545 sub_name = mpctx->subdata->filename;
1546 #ifdef CONFIG_ASS
1547 if (mpctx->osd->ass_track)
1548 sub_name = mpctx->osd->ass_track->name;
1549 #endif
1550 if (!sub_name && mpctx->subdata)
1551 sub_name = mpctx->subdata->filename;
1552 if (sub_name) {
1553 const char *tmp = mp_basename(sub_name);
1555 snprintf(*(char **) arg, 63, "(%d) %s%s",
1556 mpctx->set_of_sub_pos + 1,
1557 strlen(tmp) < 20 ? "" : "...",
1558 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1559 return M_PROPERTY_OK;
1561 #ifdef CONFIG_DVDNAV
1562 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1563 if (vo_spudec && opts->sub_id >= 0) {
1564 unsigned char lang[3];
1565 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1566 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1567 return M_PROPERTY_OK;
1571 #endif
1573 if ((d_sub->demuxer->type == DEMUXER_TYPE_MATROSKA
1574 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF
1575 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1576 || d_sub->demuxer->type == DEMUXER_TYPE_OGG)
1577 && d_sub->sh && opts->sub_id >= 0) {
1578 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1579 if (!lang) lang = mp_gtext("unknown");
1580 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1581 return M_PROPERTY_OK;
1584 if (vo_vobsub && vobsub_id >= 0) {
1585 const char *language = mp_gtext("unknown");
1586 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1587 snprintf(*(char **) arg, 63, "(%d) %s",
1588 vobsub_id, language ? language : mp_gtext("unknown"));
1589 return M_PROPERTY_OK;
1591 #ifdef CONFIG_DVDREAD
1592 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1593 && opts->sub_id >= 0) {
1594 char lang[3];
1595 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1596 lang[0] = code >> 8;
1597 lang[1] = code;
1598 lang[2] = 0;
1599 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1600 return M_PROPERTY_OK;
1602 #endif
1603 if (opts->sub_id >= 0) {
1604 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
1605 mp_gtext("unknown"));
1606 return M_PROPERTY_OK;
1608 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1609 return M_PROPERTY_OK;
1611 case M_PROPERTY_SET:
1612 if (!arg)
1613 return M_PROPERTY_ERROR;
1614 if (*(int *) arg < -1)
1615 *(int *) arg = -1;
1616 else if (*(int *) arg >= global_sub_size)
1617 *(int *) arg = global_sub_size - 1;
1618 mpctx->global_sub_pos = *(int *) arg;
1619 break;
1620 case M_PROPERTY_STEP_UP:
1621 mpctx->global_sub_pos += 2;
1622 mpctx->global_sub_pos =
1623 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1624 break;
1625 case M_PROPERTY_STEP_DOWN:
1626 mpctx->global_sub_pos += global_sub_size + 1;
1627 mpctx->global_sub_pos =
1628 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1629 break;
1630 default:
1631 return M_PROPERTY_NOT_IMPLEMENTED;
1634 if (mpctx->global_sub_pos >= 0) {
1635 source = sub_source(mpctx);
1636 source_pos = sub_source_pos(mpctx);
1639 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1640 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1641 global_sub_size,
1642 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1643 mpctx->sub_counts[SUB_SOURCE_SUBS],
1644 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1645 mpctx->global_sub_pos, source);
1647 mpctx->set_of_sub_pos = -1;
1648 mpctx->subdata = NULL;
1650 vobsub_id = -1;
1651 opts->sub_id = -1;
1652 if (d_sub) {
1653 if (d_sub->id > -2)
1654 reset_spu = 1;
1655 d_sub->id = -2;
1657 mpctx->osd->ass_track = NULL;
1658 uninit_player(mpctx, INITIALIZED_SUB);
1660 if (source == SUB_SOURCE_VOBSUB) {
1661 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1662 } else if (source == SUB_SOURCE_SUBS) {
1663 mpctx->set_of_sub_pos = source_pos;
1664 #ifdef CONFIG_ASS
1665 if (opts->ass_enabled
1666 && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]) {
1667 mpctx->osd->ass_track =
1668 mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1669 mpctx->osd->ass_track_changed = true;
1670 mpctx->osd->vsfilter_aspect =
1671 mpctx->track_was_native_ass[mpctx->set_of_sub_pos];
1672 } else
1673 #endif
1675 mpctx->subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1676 vo_osd_changed(OSDTYPE_SUBTITLE);
1678 } else if (source == SUB_SOURCE_DEMUX) {
1679 opts->sub_id = source_pos;
1680 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1681 int i = 0;
1682 // default: assume 1:1 mapping of sid and stream id
1683 d_sub->id = opts->sub_id;
1684 d_sub->sh = mpctx->d_sub->demuxer->s_streams[d_sub->id];
1685 ds_free_packs(d_sub);
1686 for (i = 0; i < MAX_S_STREAMS; i++) {
1687 sh_sub_t *sh = mpctx->d_sub->demuxer->s_streams[i];
1688 if (sh && sh->sid == opts->sub_id) {
1689 d_sub->id = i;
1690 d_sub->sh = sh;
1691 break;
1694 if (d_sub->sh && d_sub->id >= 0) {
1695 sh_sub_t *sh = d_sub->sh;
1696 if (sh->type == 'v')
1697 init_vo_spudec(mpctx);
1698 else {
1699 sub_init(sh, mpctx->osd);
1700 mpctx->initialized_flags |= INITIALIZED_SUB;
1702 } else {
1703 d_sub->id = -2;
1704 d_sub->sh = NULL;
1708 #ifdef CONFIG_DVDREAD
1709 if (vo_spudec
1710 && (mpctx->stream->type == STREAMTYPE_DVD
1711 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1712 && opts->sub_id < 0 && reset_spu) {
1713 d_sub->id = -2;
1714 d_sub->sh = NULL;
1716 #endif
1718 update_subtitles(mpctx, 0, 0, true);
1720 return M_PROPERTY_OK;
1723 /// Selected sub source (RW)
1724 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1725 MPContext *mpctx)
1727 int source;
1728 update_global_sub_size(mpctx);
1729 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1730 return M_PROPERTY_UNAVAILABLE;
1732 switch (action) {
1733 case M_PROPERTY_GET:
1734 if (!arg)
1735 return M_PROPERTY_ERROR;
1736 *(int *) arg = sub_source(mpctx);
1737 return M_PROPERTY_OK;
1738 case M_PROPERTY_PRINT:
1739 if (!arg)
1740 return M_PROPERTY_ERROR;
1741 *(char **) arg = malloc(64);
1742 (*(char **) arg)[63] = 0;
1743 switch (sub_source(mpctx))
1745 case SUB_SOURCE_SUBS:
1746 snprintf(*(char **) arg, 63, mp_gtext("file"));
1747 break;
1748 case SUB_SOURCE_VOBSUB:
1749 snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
1750 break;
1751 case SUB_SOURCE_DEMUX:
1752 snprintf(*(char **) arg, 63, mp_gtext("embedded"));
1753 break;
1754 default:
1755 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1757 return M_PROPERTY_OK;
1758 case M_PROPERTY_SET:
1759 if (!arg)
1760 return M_PROPERTY_ERROR;
1761 M_PROPERTY_CLAMP(prop, *(int*)arg);
1762 if (*(int *) arg < 0)
1763 mpctx->global_sub_pos = -1;
1764 else if (*(int *) arg != sub_source(mpctx)) {
1765 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1766 if (new_pos == -1)
1767 return M_PROPERTY_UNAVAILABLE;
1768 mpctx->global_sub_pos = new_pos;
1770 break;
1771 case M_PROPERTY_STEP_UP:
1772 case M_PROPERTY_STEP_DOWN: {
1773 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1774 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1775 int step = (step_all > 0) ? 1 : -1;
1776 int cur_source = sub_source(mpctx);
1777 source = cur_source;
1778 while (step_all) {
1779 source += step;
1780 if (source >= SUB_SOURCES)
1781 source = -1;
1782 else if (source < -1)
1783 source = SUB_SOURCES - 1;
1784 if (source == cur_source || source == -1 ||
1785 mpctx->sub_counts[source])
1786 step_all -= step;
1788 if (source == cur_source)
1789 return M_PROPERTY_OK;
1790 if (source == -1)
1791 mpctx->global_sub_pos = -1;
1792 else
1793 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1794 break;
1796 default:
1797 return M_PROPERTY_NOT_IMPLEMENTED;
1799 --mpctx->global_sub_pos;
1800 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1803 /// Selected subtitles from specific source (RW)
1804 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1805 MPContext *mpctx)
1807 int source, is_cur_source, offset, new_pos;
1808 update_global_sub_size(mpctx);
1809 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1810 return M_PROPERTY_UNAVAILABLE;
1812 if (!strcmp(prop->name, "sub_file"))
1813 source = SUB_SOURCE_SUBS;
1814 else if (!strcmp(prop->name, "sub_vob"))
1815 source = SUB_SOURCE_VOBSUB;
1816 else if (!strcmp(prop->name, "sub_demux"))
1817 source = SUB_SOURCE_DEMUX;
1818 else
1819 return M_PROPERTY_ERROR;
1821 offset = sub_pos_by_source(mpctx, source);
1822 if (offset < 0)
1823 return M_PROPERTY_UNAVAILABLE;
1825 is_cur_source = sub_source(mpctx) == source;
1826 new_pos = mpctx->global_sub_pos;
1827 switch (action) {
1828 case M_PROPERTY_GET:
1829 if (!arg)
1830 return M_PROPERTY_ERROR;
1831 if (is_cur_source) {
1832 *(int *) arg = sub_source_pos(mpctx);
1833 if (source == SUB_SOURCE_VOBSUB)
1834 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
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 = malloc(64);
1845 (*(char **) arg)[63] = 0;
1846 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1847 return M_PROPERTY_OK;
1848 case M_PROPERTY_SET:
1849 if (!arg)
1850 return M_PROPERTY_ERROR;
1851 if (*(int *) arg >= 0) {
1852 int index = *(int *)arg;
1853 if (source == SUB_SOURCE_VOBSUB)
1854 index = vobsub_get_index_by_id(vo_vobsub, index);
1855 new_pos = offset + index;
1856 if (index < 0 || index > mpctx->sub_counts[source]) {
1857 new_pos = -1;
1858 *(int *) arg = -1;
1861 else
1862 new_pos = -1;
1863 break;
1864 case M_PROPERTY_STEP_UP:
1865 case M_PROPERTY_STEP_DOWN: {
1866 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1867 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1868 int step = (step_all > 0) ? 1 : -1;
1869 int max_sub_pos_for_source = -1;
1870 if (!is_cur_source)
1871 new_pos = -1;
1872 while (step_all) {
1873 if (new_pos == -1) {
1874 if (step > 0)
1875 new_pos = offset;
1876 else if (max_sub_pos_for_source == -1) {
1877 // Find max pos for specific source
1878 new_pos = mpctx->global_sub_size - 1;
1879 while (new_pos >= 0
1880 && sub_source(mpctx) != source)
1881 new_pos--;
1883 else
1884 new_pos = max_sub_pos_for_source;
1886 else {
1887 new_pos += step;
1888 if (new_pos < offset ||
1889 new_pos >= mpctx->global_sub_size ||
1890 sub_source(mpctx) != source)
1891 new_pos = -1;
1893 step_all -= step;
1895 break;
1897 default:
1898 return M_PROPERTY_NOT_IMPLEMENTED;
1900 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1903 /// Subtitle delay (RW)
1904 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1905 MPContext *mpctx)
1907 if (!mpctx->sh_video)
1908 return M_PROPERTY_UNAVAILABLE;
1909 return m_property_delay(prop, action, arg, &sub_delay);
1912 /// Alignment of text subtitles (RW)
1913 static int mp_property_sub_alignment(m_option_t *prop, int action,
1914 void *arg, MPContext *mpctx)
1916 char *name[] = { _("top"), _("center"), _("bottom") };
1918 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1919 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1920 return M_PROPERTY_UNAVAILABLE;
1922 switch (action) {
1923 case M_PROPERTY_PRINT:
1924 if (!arg)
1925 return M_PROPERTY_ERROR;
1926 M_PROPERTY_CLAMP(prop, sub_alignment);
1927 *(char **) arg = strdup(mp_gtext(name[sub_alignment]));
1928 return M_PROPERTY_OK;
1929 case M_PROPERTY_SET:
1930 if (!arg)
1931 return M_PROPERTY_ERROR;
1932 case M_PROPERTY_STEP_UP:
1933 case M_PROPERTY_STEP_DOWN:
1934 vo_osd_changed(OSDTYPE_SUBTITLE);
1935 default:
1936 return m_property_choice(prop, action, arg, &sub_alignment);
1940 /// Subtitle visibility (RW)
1941 static int mp_property_sub_visibility(m_option_t *prop, int action,
1942 void *arg, MPContext *mpctx)
1944 if (!mpctx->sh_video)
1945 return M_PROPERTY_UNAVAILABLE;
1947 switch (action) {
1948 case M_PROPERTY_SET:
1949 if (!arg)
1950 return M_PROPERTY_ERROR;
1951 case M_PROPERTY_STEP_UP:
1952 case M_PROPERTY_STEP_DOWN:
1953 vo_osd_changed(OSDTYPE_SUBTITLE);
1954 if (vo_spudec)
1955 vo_osd_changed(OSDTYPE_SPU);
1956 default:
1957 return m_property_flag(prop, action, arg, &sub_visibility);
1961 #ifdef CONFIG_ASS
1962 /// Use margins for libass subtitles (RW)
1963 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1964 void *arg, MPContext *mpctx)
1966 if (!mpctx->sh_video)
1967 return M_PROPERTY_UNAVAILABLE;
1969 switch (action) {
1970 case M_PROPERTY_SET:
1971 if (!arg)
1972 return M_PROPERTY_ERROR;
1973 case M_PROPERTY_STEP_UP:
1974 case M_PROPERTY_STEP_DOWN:
1975 ass_force_reload = 1;
1976 default:
1977 return m_property_flag(prop, action, arg, &ass_use_margins);
1980 #endif
1982 /// Show only forced subtitles (RW)
1983 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1984 void *arg, MPContext *mpctx)
1986 if (!vo_spudec)
1987 return M_PROPERTY_UNAVAILABLE;
1989 switch (action) {
1990 case M_PROPERTY_SET:
1991 if (!arg)
1992 return M_PROPERTY_ERROR;
1993 case M_PROPERTY_STEP_UP:
1994 case M_PROPERTY_STEP_DOWN:
1995 m_property_flag(prop, action, arg, &forced_subs_only);
1996 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1997 return M_PROPERTY_OK;
1998 default:
1999 return m_property_flag(prop, action, arg, &forced_subs_only);
2004 #ifdef CONFIG_FREETYPE
2005 /// Subtitle scale (RW)
2006 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
2007 MPContext *mpctx)
2009 struct MPOpts *opts = &mpctx->opts;
2011 switch (action) {
2012 case M_PROPERTY_SET:
2013 if (!arg)
2014 return M_PROPERTY_ERROR;
2015 M_PROPERTY_CLAMP(prop, *(float *) arg);
2016 #ifdef CONFIG_ASS
2017 if (opts->ass_enabled) {
2018 ass_font_scale = *(float *) arg;
2019 ass_force_reload = 1;
2021 #endif
2022 text_font_scale_factor = *(float *) arg;
2023 force_load_font = 1;
2024 return M_PROPERTY_OK;
2025 case M_PROPERTY_STEP_UP:
2026 case M_PROPERTY_STEP_DOWN:
2027 #ifdef CONFIG_ASS
2028 if (opts->ass_enabled) {
2029 ass_font_scale += (arg ? *(float *) arg : 0.1)*
2030 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2031 M_PROPERTY_CLAMP(prop, ass_font_scale);
2032 ass_force_reload = 1;
2034 #endif
2035 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
2036 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2037 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
2038 force_load_font = 1;
2039 return M_PROPERTY_OK;
2040 default:
2041 #ifdef CONFIG_ASS
2042 if (opts->ass_enabled)
2043 return m_property_float_ro(prop, action, arg, ass_font_scale);
2044 else
2045 #endif
2046 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
2049 #endif
2051 ///@}
2053 /// \defgroup TVProperties TV properties
2054 /// \ingroup Properties
2055 ///@{
2057 #ifdef CONFIG_TV
2059 /// TV color settings (RW)
2060 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2061 MPContext *mpctx)
2063 int r, val;
2064 tvi_handle_t *tvh = mpctx->demuxer->priv;
2065 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2066 return M_PROPERTY_UNAVAILABLE;
2068 switch (action) {
2069 case M_PROPERTY_SET:
2070 if (!arg)
2071 return M_PROPERTY_ERROR;
2072 M_PROPERTY_CLAMP(prop, *(int *) arg);
2073 return tv_set_color_options(tvh, prop->offset, *(int *) arg);
2074 case M_PROPERTY_GET:
2075 return tv_get_color_options(tvh, prop->offset, arg);
2076 case M_PROPERTY_STEP_UP:
2077 case M_PROPERTY_STEP_DOWN:
2078 if ((r = tv_get_color_options(tvh, prop->offset, &val)) >= 0) {
2079 if (!r)
2080 return M_PROPERTY_ERROR;
2081 val += (arg ? *(int *) arg : 1) *
2082 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2083 M_PROPERTY_CLAMP(prop, val);
2084 return tv_set_color_options(tvh, prop->offset, val);
2086 return M_PROPERTY_ERROR;
2088 return M_PROPERTY_NOT_IMPLEMENTED;
2091 #endif
2093 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2094 MPContext *mpctx)
2096 int val,result;
2097 int base_ioctl = prop->offset;
2099 for teletext's GET,SET,STEP ioctls this is not 0
2100 SET is GET+1
2101 STEP is GET+2
2103 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2104 return M_PROPERTY_UNAVAILABLE;
2105 if(!base_ioctl)
2106 return M_PROPERTY_ERROR;
2108 switch (action) {
2109 case M_PROPERTY_GET:
2110 if (!arg)
2111 return M_PROPERTY_ERROR;
2112 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2113 break;
2114 case M_PROPERTY_SET:
2115 if (!arg)
2116 return M_PROPERTY_ERROR;
2117 M_PROPERTY_CLAMP(prop, *(int *) arg);
2118 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
2119 break;
2120 case M_PROPERTY_STEP_UP:
2121 case M_PROPERTY_STEP_DOWN:
2122 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2123 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2124 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
2125 break;
2126 default:
2127 return M_PROPERTY_NOT_IMPLEMENTED;
2130 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2133 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2134 MPContext *mpctx)
2136 int result;
2137 int val;
2139 //with tvh==NULL will fail too
2140 result=mp_property_teletext_common(prop,action,arg,mpctx);
2141 if(result!=M_PROPERTY_OK)
2142 return result;
2144 if(teletext_control(mpctx->demuxer->teletext,
2145 prop->offset, &val)==VBI_CONTROL_TRUE && val)
2146 mp_input_set_section(mpctx->input, "teletext");
2147 else
2148 mp_input_set_section(mpctx->input, "tv");
2149 return M_PROPERTY_OK;
2152 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2153 MPContext *mpctx)
2155 int result;
2156 int val;
2157 if (!mpctx->demuxer->teletext)
2158 return M_PROPERTY_UNAVAILABLE;
2159 switch(action){
2160 case M_PROPERTY_STEP_UP:
2161 case M_PROPERTY_STEP_DOWN:
2162 //This should be handled separately
2163 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2164 result=teletext_control(mpctx->demuxer->teletext,
2165 TV_VBI_CONTROL_STEP_PAGE, &val);
2166 break;
2167 default:
2168 result=mp_property_teletext_common(prop,action,arg,mpctx);
2170 return result;
2173 ///@}
2175 /// All properties available in MPlayer.
2176 /** \ingroup Properties
2178 static const m_option_t mp_properties[] = {
2179 // General
2180 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2181 M_OPT_RANGE, 0, 3, NULL },
2182 { "loop", mp_property_loop, CONF_TYPE_INT,
2183 M_OPT_MIN, -1, 0, NULL },
2184 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2185 M_OPT_RANGE, 0.01, 100.0, NULL },
2186 { "filename", mp_property_filename, CONF_TYPE_STRING,
2187 0, 0, 0, NULL },
2188 { "path", mp_property_path, CONF_TYPE_STRING,
2189 0, 0, 0, NULL },
2190 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2191 0, 0, 0, NULL },
2192 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2193 M_OPT_MIN, 0, 0, NULL },
2194 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2195 M_OPT_MIN, 0, 0, NULL },
2196 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2197 M_OPT_MIN, 0, 0, NULL },
2198 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2199 M_OPT_MIN, 0, 0, NULL },
2200 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2201 M_OPT_MIN, 0, 0, NULL },
2202 { "length", mp_property_length, CONF_TYPE_TIME,
2203 M_OPT_MIN, 0, 0, NULL },
2204 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2205 M_OPT_RANGE, 0, 100, NULL },
2206 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2207 M_OPT_MIN, 0, 0, NULL },
2208 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2209 M_OPT_MIN, 0, 0, NULL },
2210 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2211 0, 0, 0, NULL },
2212 { "angle", mp_property_angle, CONF_TYPE_INT,
2213 CONF_RANGE, -2, 10, NULL },
2214 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2215 0, 0, 0, NULL },
2216 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2217 M_OPT_RANGE, 0, 1, NULL },
2218 { "capturing", mp_property_capture, CONF_TYPE_FLAG,
2219 M_OPT_RANGE, 0, 1, NULL },
2220 { "pts_association_mode", mp_property_generic_option, &m_option_type_choice,
2221 0, 0, 0, "pts-association-mode" },
2222 { "hr_seek", mp_property_generic_option, &m_option_type_choice,
2223 0, 0, 0, "hr-seek" },
2225 // Audio
2226 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2227 M_OPT_RANGE, 0, 100, NULL },
2228 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2229 M_OPT_RANGE, 0, 1, NULL },
2230 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2231 M_OPT_RANGE, -100, 100, NULL },
2232 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2233 0, 0, 0, NULL },
2234 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2235 0, 0, 0, NULL },
2236 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2237 0, 0, 0, NULL },
2238 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2239 0, 0, 0, NULL },
2240 { "channels", mp_property_channels, CONF_TYPE_INT,
2241 0, 0, 0, NULL },
2242 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2243 CONF_RANGE, -2, 65535, NULL },
2244 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2245 M_OPT_RANGE, -1, 1, NULL },
2247 // Video
2248 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2249 M_OPT_RANGE, 0, 1, NULL },
2250 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2251 M_OPT_RANGE, 0, 1, NULL },
2252 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2253 M_OPT_RANGE, 0, 2, NULL },
2254 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2255 M_OPT_RANGE, 0, 1, NULL },
2256 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2257 M_OPT_RANGE, 0, 1, NULL },
2258 { "border", mp_property_border, CONF_TYPE_FLAG,
2259 M_OPT_RANGE, 0, 1, NULL },
2260 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2261 M_OPT_RANGE, 0, 2, NULL },
2262 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2263 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_gamma)},
2264 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2265 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_brightness) },
2266 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2267 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_contrast) },
2268 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2269 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_saturation) },
2270 { "hue", mp_property_gamma, CONF_TYPE_INT,
2271 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_hue) },
2272 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2273 M_OPT_RANGE, 0, 1, NULL },
2274 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2275 M_OPT_RANGE, 0, 1, NULL },
2276 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2277 0, 0, 0, NULL },
2278 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2279 0, 0, 0, NULL },
2280 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2281 0, 0, 0, NULL },
2282 { "width", mp_property_width, CONF_TYPE_INT,
2283 0, 0, 0, NULL },
2284 { "height", mp_property_height, CONF_TYPE_INT,
2285 0, 0, 0, NULL },
2286 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2287 0, 0, 0, NULL },
2288 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2289 0, 0, 0, NULL },
2290 { "switch_video", mp_property_video, CONF_TYPE_INT,
2291 CONF_RANGE, -2, 65535, NULL },
2292 { "switch_program", mp_property_program, CONF_TYPE_INT,
2293 CONF_RANGE, -1, 65535, NULL },
2295 // Subs
2296 { "sub", mp_property_sub, CONF_TYPE_INT,
2297 M_OPT_MIN, -1, 0, NULL },
2298 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2299 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2300 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2301 M_OPT_MIN, -1, 0, NULL },
2302 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2303 M_OPT_MIN, -1, 0, NULL },
2304 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2305 M_OPT_MIN, -1, 0, NULL },
2306 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2307 0, 0, 0, NULL },
2308 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2309 M_OPT_RANGE, 0, 100, NULL },
2310 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2311 M_OPT_RANGE, 0, 2, NULL },
2312 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2313 M_OPT_RANGE, 0, 1, NULL },
2314 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2315 M_OPT_RANGE, 0, 1, NULL },
2316 #ifdef CONFIG_FREETYPE
2317 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2318 M_OPT_RANGE, 0, 100, NULL },
2319 #endif
2320 #ifdef CONFIG_ASS
2321 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2322 M_OPT_RANGE, 0, 1, NULL },
2323 #endif
2325 #ifdef CONFIG_TV
2326 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2327 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_BRIGHTNESS },
2328 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2329 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_CONTRAST },
2330 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2331 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_SATURATION },
2332 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2333 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_HUE },
2334 #endif
2335 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2336 M_OPT_RANGE, 100, 899, .offset=TV_VBI_CONTROL_GET_PAGE },
2337 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2338 M_OPT_RANGE, 0, 64, .offset=TV_VBI_CONTROL_GET_SUBPAGE },
2339 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2340 M_OPT_RANGE, 0, 1, .offset=TV_VBI_CONTROL_GET_MODE },
2341 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2342 M_OPT_RANGE, 0, 3, .offset=TV_VBI_CONTROL_GET_FORMAT },
2343 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2344 M_OPT_RANGE, 0, 2, .offset=TV_VBI_CONTROL_GET_HALF_PAGE },
2345 { NULL, NULL, NULL, 0, 0, 0, NULL }
2349 int mp_property_do(const char *name, int action, void *val, void *ctx)
2351 return m_property_do(mp_properties, name, action, val, ctx);
2354 char* mp_property_print(const char *name, void* ctx)
2356 char* ret = NULL;
2357 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2358 return NULL;
2359 return ret;
2362 char *property_expand_string(MPContext *mpctx, char *str)
2364 return m_properties_expand_string(mp_properties, str, mpctx);
2367 void property_print_help(void)
2369 m_properties_print_help_list(mp_properties);
2373 /* List of default ways to show a property on OSD.
2375 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2376 * a bar showing the current position between min/max values of the
2377 * property. In this case osd_msg is only used for terminal output
2378 * if there is no video; it'll be a label shown together with percentage.
2380 * Otherwise setting osd_msg will show the string on OSD, formatted with
2381 * the text value of the property as argument.
2383 static struct property_osd_display {
2384 /// property name
2385 const char *name;
2386 /// progressbar type
2387 int osd_progbar; // -1 is special value for seek indicators
2388 /// osd msg id if it must be shared
2389 int osd_id;
2390 /// osd msg template
2391 const char *osd_msg;
2392 } property_osd_display[] = {
2393 // general
2394 { "loop", 0, -1, _("Loop: %s") },
2395 { "chapter", -1, -1, NULL },
2396 { "capturing", 0, -1, _("Capturing: %s") },
2397 { "pts_association_mode", 0, -1, "PTS association mode: %s" },
2398 { "hr_seek", 0, -1, "hr-seek: %s" },
2399 { "speed", 0, -1, _("Speed: x %6s") },
2400 // audio
2401 { "volume", OSD_VOLUME, -1, _("Volume") },
2402 { "mute", 0, -1, _("Mute: %s") },
2403 { "audio_delay", 0, -1, _("A-V delay: %s") },
2404 { "switch_audio", 0, -1, _("Audio: %s") },
2405 { "balance", OSD_BALANCE, -1, _("Balance") },
2406 // video
2407 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2408 { "ontop", 0, -1, _("Stay on top: %s") },
2409 { "rootwin", 0, -1, _("Rootwin: %s") },
2410 { "border", 0, -1, _("Border: %s") },
2411 { "framedropping", 0, -1, _("Framedropping: %s") },
2412 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2413 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2414 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2415 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2416 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2417 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2418 { "hue", OSD_HUE, -1, _("Hue") },
2419 { "vsync", 0, -1, _("VSync: %s") },
2420 // subs
2421 { "sub", 0, -1, _("Subtitles: %s") },
2422 { "sub_source", 0, -1, _("Sub source: %s") },
2423 { "sub_vob", 0, -1, _("Subtitles: %s") },
2424 { "sub_demux", 0, -1, _("Subtitles: %s") },
2425 { "sub_file", 0, -1, _("Subtitles: %s") },
2426 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2427 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2428 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2429 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2430 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2431 #ifdef CONFIG_FREETYPE
2432 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2433 #endif
2434 #ifdef CONFIG_TV
2435 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2436 { "tv_hue", OSD_HUE, -1, _("Hue") },
2437 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2438 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2439 #endif
2443 static int show_property_osd(MPContext *mpctx, const char *pname)
2445 struct MPOpts *opts = &mpctx->opts;
2446 int r;
2447 m_option_t* prop;
2448 struct property_osd_display *p;
2450 // look for the command
2451 for (p = property_osd_display; p->name; p++)
2452 if (!strcmp(p->name, pname))
2453 break;
2454 if (!p->name)
2455 return -1;
2457 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2458 return -1;
2460 if (p->osd_progbar == -1)
2461 mpctx->add_osd_seek_info = true;
2462 else if (p->osd_progbar) {
2463 if (prop->type == CONF_TYPE_INT) {
2464 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2465 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2466 prop->min, prop->max, r);
2467 } else if (prop->type == CONF_TYPE_FLOAT) {
2468 float f;
2469 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2470 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2471 prop->min, prop->max, f);
2472 } else {
2473 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2474 "Property use an unsupported type.\n");
2475 return -1;
2477 return 0;
2480 if (p->osd_msg) {
2481 char *val = mp_property_print(pname, mpctx);
2482 if (val) {
2483 int index = p - property_osd_display;
2484 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2485 1, opts->osd_duration, p->osd_msg, val);
2486 free(val);
2489 return 0;
2494 * \defgroup Command2Property Command to property bridge
2496 * It is used to handle most commands that just set a property
2497 * and optionally display something on the OSD.
2498 * Two kinds of commands are handled: adjust or toggle.
2500 * Adjust commands take 1 or 2 parameters: <value> <abs>
2501 * If <abs> is non-zero the property is set to the given value
2502 * otherwise it is adjusted.
2504 * Toggle commands take 0 or 1 parameters. With no parameter
2505 * or a value less than the property minimum it just steps the
2506 * property to its next or previous value respectively.
2507 * Otherwise it sets it to the given value.
2512 /// List of the commands that can be handled by setting a property.
2513 static struct {
2514 /// property name
2515 const char *name;
2516 /// cmd id
2517 int cmd;
2518 /// set/adjust or toggle command
2519 int toggle;
2520 } set_prop_cmd[] = {
2521 // general
2522 { "loop", MP_CMD_LOOP, 0},
2523 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2524 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2525 { "pause", MP_CMD_PAUSE, 0},
2526 { "capturing", MP_CMD_CAPTURING, 1},
2527 // audio
2528 { "volume", MP_CMD_VOLUME, 0},
2529 { "mute", MP_CMD_MUTE, 1},
2530 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2531 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2532 { "balance", MP_CMD_BALANCE, 0},
2533 // video
2534 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2535 { "panscan", MP_CMD_PANSCAN, 0},
2536 { "ontop", MP_CMD_VO_ONTOP, 1},
2537 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2538 { "border", MP_CMD_VO_BORDER, 1},
2539 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2540 { "gamma", MP_CMD_GAMMA, 0},
2541 { "brightness", MP_CMD_BRIGHTNESS, 0},
2542 { "contrast", MP_CMD_CONTRAST, 0},
2543 { "saturation", MP_CMD_SATURATION, 0},
2544 { "hue", MP_CMD_HUE, 0},
2545 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2546 // subs
2547 { "sub", MP_CMD_SUB_SELECT, 1},
2548 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2549 { "sub_vob", MP_CMD_SUB_VOB, 1},
2550 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2551 { "sub_file", MP_CMD_SUB_FILE, 1},
2552 { "sub_pos", MP_CMD_SUB_POS, 0},
2553 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2554 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2555 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2556 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2557 #ifdef CONFIG_FREETYPE
2558 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2559 #endif
2560 #ifdef CONFIG_ASS
2561 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2562 #endif
2563 #ifdef CONFIG_TV
2564 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2565 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2566 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2567 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2568 #endif
2572 /// Handle commands that set a property.
2573 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2575 int i, r;
2576 m_option_t *prop;
2577 const char *pname;
2579 // look for the command
2580 for (i = 0; set_prop_cmd[i].name; i++)
2581 if (set_prop_cmd[i].cmd == cmd->id)
2582 break;
2583 if (!(pname = set_prop_cmd[i].name))
2584 return 0;
2586 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2587 return 0;
2589 // toggle command
2590 if (set_prop_cmd[i].toggle) {
2591 // set to value
2592 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2593 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2594 else if (cmd->nargs > 0)
2595 r = mp_property_do(pname, M_PROPERTY_STEP_DOWN, NULL, mpctx);
2596 else
2597 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2598 } else if (cmd->args[1].v.i) //set
2599 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2600 else // adjust
2601 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2603 if (r <= 0)
2604 return 1;
2606 show_property_osd(mpctx, pname);
2608 return 1;
2611 #ifdef CONFIG_DVDNAV
2612 static const struct {
2613 const char *name;
2614 const mp_command_type cmd;
2615 } mp_dvdnav_bindings[] = {
2616 { "up", MP_CMD_DVDNAV_UP },
2617 { "down", MP_CMD_DVDNAV_DOWN },
2618 { "left", MP_CMD_DVDNAV_LEFT },
2619 { "right", MP_CMD_DVDNAV_RIGHT },
2620 { "menu", MP_CMD_DVDNAV_MENU },
2621 { "select", MP_CMD_DVDNAV_SELECT },
2622 { "prev", MP_CMD_DVDNAV_PREVMENU },
2623 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2626 * keep old dvdnav sub-command options for a while in order not to
2627 * break slave-mode API too suddenly.
2629 { "1", MP_CMD_DVDNAV_UP },
2630 { "2", MP_CMD_DVDNAV_DOWN },
2631 { "3", MP_CMD_DVDNAV_LEFT },
2632 { "4", MP_CMD_DVDNAV_RIGHT },
2633 { "5", MP_CMD_DVDNAV_MENU },
2634 { "6", MP_CMD_DVDNAV_SELECT },
2635 { "7", MP_CMD_DVDNAV_PREVMENU },
2636 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2637 { NULL, 0 }
2639 #endif
2641 static const char *property_error_string(int error_value)
2643 switch (error_value) {
2644 case M_PROPERTY_ERROR:
2645 return "ERROR";
2646 case M_PROPERTY_UNAVAILABLE:
2647 return "PROPERTY_UNAVAILABLE";
2648 case M_PROPERTY_NOT_IMPLEMENTED:
2649 return "NOT_IMPLEMENTED";
2650 case M_PROPERTY_UNKNOWN:
2651 return "PROPERTY_UNKNOWN";
2652 case M_PROPERTY_DISABLED:
2653 return "DISABLED";
2655 return "UNKNOWN";
2658 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2660 int idx;
2661 int end = start + count;
2662 int after = mpctx->set_of_sub_size - end;
2663 sub_data **subs = mpctx->set_of_subtitles;
2664 #ifdef CONFIG_ASS
2665 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2666 #endif
2667 if (count < 0 || count > mpctx->set_of_sub_size ||
2668 start < 0 || start > mpctx->set_of_sub_size - count) {
2669 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2670 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2671 return;
2673 for (idx = start; idx < end; idx++) {
2674 sub_data *subd = subs[idx];
2675 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2676 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2677 filename_recode(subd->filename));
2678 sub_free(subd);
2679 subs[idx] = NULL;
2680 #ifdef CONFIG_ASS
2681 if (ass_tracks[idx])
2682 ass_free_track(ass_tracks[idx]);
2683 ass_tracks[idx] = NULL;
2684 #endif
2687 mpctx->global_sub_size -= count;
2688 mpctx->set_of_sub_size -= count;
2689 if (mpctx->set_of_sub_size <= 0)
2690 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2692 memmove(subs + start, subs + end, after * sizeof(*subs));
2693 memset(subs + start + after, 0, count * sizeof(*subs));
2694 #ifdef CONFIG_ASS
2695 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2696 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2697 #endif
2699 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2700 mpctx->global_sub_pos = -2;
2701 mpctx->subdata = NULL;
2702 mpctx->osd->ass_track = NULL;
2703 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2704 } else if (mpctx->set_of_sub_pos >= end) {
2705 mpctx->set_of_sub_pos -= count;
2706 mpctx->global_sub_pos -= count;
2710 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2712 struct MPOpts *opts = &mpctx->opts;
2713 sh_audio_t * const sh_audio = mpctx->sh_audio;
2714 sh_video_t * const sh_video = mpctx->sh_video;
2715 int osd_duration = opts->osd_duration;
2716 int case_fallthrough_hack = 0;
2717 if (!set_property_command(mpctx, cmd))
2718 switch (cmd->id) {
2719 case MP_CMD_SEEK:{
2720 mpctx->add_osd_seek_info = true;
2721 float v = cmd->args[0].v.f;
2722 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2723 int exact = (cmd->nargs > 2) ? cmd->args[2].v.i : 0;
2724 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2725 queue_seek(mpctx, MPSEEK_ABSOLUTE, v, exact);
2726 mpctx->osd_function = v > get_current_time(mpctx) ?
2727 OSD_FFW : OSD_REW;
2728 } else if (abs) { /* Absolute seek by percentage */
2729 queue_seek(mpctx, MPSEEK_FACTOR, v / 100.0, exact);
2730 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2731 } else {
2732 queue_seek(mpctx, MPSEEK_RELATIVE, v, exact);
2733 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2736 break;
2738 case MP_CMD_SET_PROPERTY_OSD:
2739 case_fallthrough_hack = 1;
2741 case MP_CMD_SET_PROPERTY:{
2742 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2743 cmd->args[1].v.s, mpctx);
2744 if (r == M_PROPERTY_UNKNOWN)
2745 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2746 "Unknown property: '%s'\n", cmd->args[0].v.s);
2747 else if (r <= 0)
2748 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2749 "Failed to set property '%s' to '%s'.\n",
2750 cmd->args[0].v.s, cmd->args[1].v.s);
2751 else if (case_fallthrough_hack)
2752 show_property_osd(mpctx, cmd->args[0].v.s);
2753 if (r <= 0)
2754 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2756 break;
2758 case MP_CMD_STEP_PROPERTY_OSD:
2759 case_fallthrough_hack = 1;
2761 case MP_CMD_STEP_PROPERTY:{
2762 void* arg = NULL;
2763 int r,i;
2764 double d;
2765 off_t o;
2766 if (cmd->args[1].v.f) {
2767 m_option_t* prop;
2768 if((r = mp_property_do(cmd->args[0].v.s,
2769 M_PROPERTY_GET_TYPE,
2770 &prop, mpctx)) <= 0)
2771 goto step_prop_err;
2772 if(prop->type == CONF_TYPE_INT ||
2773 prop->type == CONF_TYPE_FLAG)
2774 i = cmd->args[1].v.f, arg = &i;
2775 else if(prop->type == CONF_TYPE_FLOAT)
2776 arg = &cmd->args[1].v.f;
2777 else if(prop->type == CONF_TYPE_DOUBLE ||
2778 prop->type == CONF_TYPE_TIME)
2779 d = cmd->args[1].v.f, arg = &d;
2780 else if(prop->type == CONF_TYPE_POSITION)
2781 o = cmd->args[1].v.f, arg = &o;
2782 else
2783 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2784 "Ignoring step size stepping property '%s'.\n",
2785 cmd->args[0].v.s);
2787 r = mp_property_do(cmd->args[0].v.s,
2788 cmd->args[2].v.i < 0 ?
2789 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2790 arg, mpctx);
2791 step_prop_err:
2792 if (r == M_PROPERTY_UNKNOWN)
2793 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2794 "Unknown property: '%s'\n", cmd->args[0].v.s);
2795 else if (r <= 0)
2796 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2797 "Failed to increment property '%s' by %f.\n",
2798 cmd->args[0].v.s, cmd->args[1].v.f);
2799 else if (case_fallthrough_hack)
2800 show_property_osd(mpctx, cmd->args[0].v.s);
2801 if (r <= 0)
2802 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2804 break;
2806 case MP_CMD_GET_PROPERTY:{
2807 char *tmp;
2808 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2809 &tmp, mpctx);
2810 if (r <= 0) {
2811 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2812 "Failed to get value of property '%s'.\n",
2813 cmd->args[0].v.s);
2814 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2815 break;
2817 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2818 cmd->args[0].v.s, tmp);
2819 free(tmp);
2821 break;
2823 case MP_CMD_EDL_MARK:
2824 if (edl_fd) {
2825 float v = get_current_time(mpctx);
2826 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2827 mpctx->begin_skip = v;
2828 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2829 } else {
2830 if (mpctx->begin_skip > v)
2831 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2832 else {
2833 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2834 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2836 mpctx->begin_skip = MP_NOPTS_VALUE;
2839 break;
2841 case MP_CMD_SWITCH_RATIO:
2842 if (!sh_video)
2843 break;
2844 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2845 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2846 else
2847 opts->movie_aspect = cmd->args[0].v.f;
2848 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2849 break;
2851 case MP_CMD_SPEED_INCR:{
2852 float v = cmd->args[0].v.f;
2853 mp_property_do("speed", M_PROPERTY_STEP_UP, &v, mpctx);
2854 show_property_osd(mpctx, "speed");
2855 break;
2858 case MP_CMD_SPEED_MULT:
2859 case_fallthrough_hack = true;
2861 case MP_CMD_SPEED_SET:{
2862 float v = cmd->args[0].v.f;
2863 if (case_fallthrough_hack)
2864 v *= mpctx->opts.playback_speed;
2865 mp_property_do("speed", M_PROPERTY_SET, &v, mpctx);
2866 show_property_osd(mpctx, "speed");
2867 break;
2870 case MP_CMD_FRAME_STEP:
2871 add_step_frame(mpctx);
2872 break;
2874 case MP_CMD_FILE_FILTER:
2875 file_filter = cmd->args[0].v.i;
2876 break;
2878 case MP_CMD_QUIT:
2879 exit_player_with_rc(mpctx, EXIT_QUIT,
2880 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2882 case MP_CMD_PLAY_TREE_STEP:{
2883 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2884 int force = cmd->args[1].v.i;
2887 if (!force && mpctx->playtree_iter) {
2888 play_tree_iter_t *i =
2889 play_tree_iter_new_copy(mpctx->playtree_iter);
2890 if (play_tree_iter_step(i, n, 0) ==
2891 PLAY_TREE_ITER_ENTRY)
2892 mpctx->stop_play =
2893 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2894 play_tree_iter_free(i);
2895 } else
2896 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2897 if (mpctx->stop_play)
2898 mpctx->play_tree_step = n;
2901 break;
2903 case MP_CMD_PLAY_TREE_UP_STEP:{
2904 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2905 int force = cmd->args[1].v.i;
2907 if (!force && mpctx->playtree_iter) {
2908 play_tree_iter_t *i =
2909 play_tree_iter_new_copy(mpctx->playtree_iter);
2910 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2911 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2912 play_tree_iter_free(i);
2913 } else
2914 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2916 break;
2918 case MP_CMD_PLAY_ALT_SRC_STEP:
2919 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2920 int v = cmd->args[0].v.i;
2921 if (v > 0
2922 && mpctx->playtree_iter->file <
2923 mpctx->playtree_iter->num_files)
2924 mpctx->stop_play = PT_NEXT_SRC;
2925 else if (v < 0 && mpctx->playtree_iter->file > 1)
2926 mpctx->stop_play = PT_PREV_SRC;
2928 break;
2930 case MP_CMD_SUB_STEP:
2931 if (sh_video) {
2932 int movement = cmd->args[0].v.i;
2933 step_sub(mpctx->subdata, mpctx->video_pts, movement);
2934 #ifdef CONFIG_ASS
2935 if (mpctx->osd->ass_track)
2936 sub_delay +=
2937 ass_step_sub(mpctx->osd->ass_track,
2938 (mpctx->video_pts +
2939 sub_delay) * 1000 + .5, movement) / 1000.;
2940 #endif
2941 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2942 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2944 break;
2946 case MP_CMD_SUB_LOG:
2947 log_sub(mpctx);
2948 break;
2950 case MP_CMD_OSD:{
2951 int v = cmd->args[0].v.i;
2952 int max = (opts->term_osd
2953 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2954 if (opts->osd_level > max)
2955 opts->osd_level = max;
2956 if (v < 0)
2957 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2958 else
2959 opts->osd_level = v > max ? max : v;
2960 /* Show OSD state when disabled, but not when an explicit
2961 argument is given to the OSD command, i.e. in slave mode. */
2962 if (v == -1 && opts->osd_level <= 1)
2963 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2964 "OSD: %s",
2965 opts->osd_level ? mp_gtext("enabled") :
2966 mp_gtext("disabled"));
2967 else
2968 rm_osd_msg(OSD_MSG_OSD_STATUS);
2970 break;
2972 case MP_CMD_OSD_SHOW_TEXT:
2973 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2974 (cmd->args[1].v.i <
2975 0 ? osd_duration : cmd->args[1].v.i),
2976 "%-.63s", cmd->args[0].v.s);
2977 break;
2979 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2980 char *txt = m_properties_expand_string(mp_properties,
2981 cmd->args[0].v.s,
2982 mpctx);
2983 /* if no argument supplied take default osd_duration, else <arg> ms. */
2984 if (txt) {
2985 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2986 (cmd->args[1].v.i <
2987 0 ? osd_duration : cmd->args[1].v.i),
2988 "%-.63s", txt);
2989 free(txt);
2992 break;
2994 case MP_CMD_LOADFILE:{
2995 play_tree_t *e = play_tree_new();
2996 play_tree_add_file(e, cmd->args[0].v.s);
2998 if (cmd->args[1].v.i) // append
2999 play_tree_append_entry(mpctx->playtree->child, e);
3000 else {
3001 // Go back to the starting point.
3002 while (play_tree_iter_up_step
3003 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3004 /* NOP */ ;
3005 play_tree_free_list(mpctx->playtree->child, 1);
3006 play_tree_set_child(mpctx->playtree, e);
3007 pt_iter_goto_head(mpctx->playtree_iter);
3008 mpctx->stop_play = PT_NEXT_SRC;
3011 break;
3013 case MP_CMD_LOADLIST:{
3014 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
3015 if (!e)
3016 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
3017 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
3018 else {
3019 if (cmd->args[1].v.i) // append
3020 play_tree_append_entry(mpctx->playtree->child, e);
3021 else {
3022 // Go back to the starting point.
3023 while (play_tree_iter_up_step
3024 (mpctx->playtree_iter, 0, 1)
3025 != PLAY_TREE_ITER_END)
3026 /* NOP */ ;
3027 play_tree_free_list(mpctx->playtree->child, 1);
3028 play_tree_set_child(mpctx->playtree, e);
3029 pt_iter_goto_head(mpctx->playtree_iter);
3030 mpctx->stop_play = PT_NEXT_SRC;
3034 break;
3036 case MP_CMD_STOP:
3037 // Go back to the starting point.
3038 while (play_tree_iter_up_step
3039 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3040 /* NOP */ ;
3041 mpctx->stop_play = PT_STOP;
3042 break;
3044 case MP_CMD_OSD_SHOW_PROGRESSION:{
3045 int len = get_time_length(mpctx);
3046 int pts = get_current_time(mpctx);
3047 set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3048 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3049 "%c %02d:%02d:%02d / %02d:%02d:%02d",
3050 mpctx->osd_function, pts/3600, (pts/60)%60, pts%60,
3051 len/3600, (len/60)%60, len%60);
3053 break;
3055 #ifdef CONFIG_RADIO
3056 case MP_CMD_RADIO_STEP_CHANNEL:
3057 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3058 int v = cmd->args[0].v.i;
3059 if (v > 0)
3060 radio_step_channel(mpctx->demuxer->stream,
3061 RADIO_CHANNEL_HIGHER);
3062 else
3063 radio_step_channel(mpctx->demuxer->stream,
3064 RADIO_CHANNEL_LOWER);
3065 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3066 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3067 "Channel: %s",
3068 radio_get_channel_name(mpctx->demuxer->stream));
3071 break;
3073 case MP_CMD_RADIO_SET_CHANNEL:
3074 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3075 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3076 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3077 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3078 "Channel: %s",
3079 radio_get_channel_name(mpctx->demuxer->stream));
3082 break;
3084 case MP_CMD_RADIO_SET_FREQ:
3085 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3086 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3087 break;
3089 case MP_CMD_RADIO_STEP_FREQ:
3090 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3091 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3092 break;
3093 #endif
3095 #ifdef CONFIG_TV
3096 case MP_CMD_TV_START_SCAN:
3097 if (mpctx->file_format == DEMUXER_TYPE_TV)
3098 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
3099 break;
3100 case MP_CMD_TV_SET_FREQ:
3101 if (mpctx->file_format == DEMUXER_TYPE_TV)
3102 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3103 cmd->args[0].v.f * 16.0);
3104 #ifdef CONFIG_PVR
3105 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3106 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
3107 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3108 pvr_get_current_channelname (mpctx->stream),
3109 pvr_get_current_stationname (mpctx->stream));
3111 #endif /* CONFIG_PVR */
3112 break;
3114 case MP_CMD_TV_STEP_FREQ:
3115 if (mpctx->file_format == DEMUXER_TYPE_TV)
3116 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3117 cmd->args[0].v.f * 16.0);
3118 #ifdef CONFIG_PVR
3119 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3120 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
3121 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3122 pvr_get_current_channelname (mpctx->stream),
3123 pvr_get_current_frequency (mpctx->stream));
3125 #endif /* CONFIG_PVR */
3126 break;
3128 case MP_CMD_TV_SET_NORM:
3129 if (mpctx->file_format == DEMUXER_TYPE_TV)
3130 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3131 cmd->args[0].v.s);
3132 break;
3134 case MP_CMD_TV_STEP_CHANNEL:{
3135 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3136 int v = cmd->args[0].v.i;
3137 if (v > 0) {
3138 tv_step_channel((tvi_handle_t *) (mpctx->
3139 demuxer->priv),
3140 TV_CHANNEL_HIGHER);
3141 } else {
3142 tv_step_channel((tvi_handle_t *) (mpctx->
3143 demuxer->priv),
3144 TV_CHANNEL_LOWER);
3146 if (tv_channel_list) {
3147 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3148 "Channel: %s", tv_channel_current->name);
3149 //vo_osd_changed(OSDTYPE_SUBTITLE);
3152 #ifdef CONFIG_PVR
3153 else if (mpctx->stream &&
3154 mpctx->stream->type == STREAMTYPE_PVR) {
3155 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3156 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3157 pvr_get_current_channelname (mpctx->stream),
3158 pvr_get_current_stationname (mpctx->stream));
3160 #endif /* CONFIG_PVR */
3162 #ifdef CONFIG_DVBIN
3163 if (mpctx->stream->type == STREAMTYPE_DVB) {
3164 int dir;
3165 int v = cmd->args[0].v.i;
3167 mpctx->last_dvb_step = v;
3168 if (v > 0)
3169 dir = DVB_CHANNEL_HIGHER;
3170 else
3171 dir = DVB_CHANNEL_LOWER;
3174 if (dvb_step_channel(mpctx->stream, dir)) {
3175 mpctx->stop_play = PT_NEXT_ENTRY;
3176 mpctx->dvbin_reopen = 1;
3179 #endif /* CONFIG_DVBIN */
3180 break;
3182 case MP_CMD_TV_SET_CHANNEL:
3183 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3184 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3185 cmd->args[0].v.s);
3186 if (tv_channel_list) {
3187 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3188 "Channel: %s", tv_channel_current->name);
3189 //vo_osd_changed(OSDTYPE_SUBTITLE);
3192 #ifdef CONFIG_PVR
3193 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3194 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3195 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3196 pvr_get_current_channelname (mpctx->stream),
3197 pvr_get_current_stationname (mpctx->stream));
3199 #endif /* CONFIG_PVR */
3200 break;
3202 #ifdef CONFIG_DVBIN
3203 case MP_CMD_DVB_SET_CHANNEL:
3204 if (mpctx->stream->type == STREAMTYPE_DVB) {
3205 mpctx->last_dvb_step = 1;
3207 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3208 cmd->args[0].v.i)) {
3209 mpctx->stop_play = PT_NEXT_ENTRY;
3210 mpctx->dvbin_reopen = 1;
3213 break;
3214 #endif /* CONFIG_DVBIN */
3216 case MP_CMD_TV_LAST_CHANNEL:
3217 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3218 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3219 if (tv_channel_list) {
3220 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3221 "Channel: %s", tv_channel_current->name);
3222 //vo_osd_changed(OSDTYPE_SUBTITLE);
3225 #ifdef CONFIG_PVR
3226 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3227 pvr_set_lastchannel (mpctx->stream);
3228 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3229 pvr_get_current_channelname (mpctx->stream),
3230 pvr_get_current_stationname (mpctx->stream));
3232 #endif /* CONFIG_PVR */
3233 break;
3235 case MP_CMD_TV_STEP_NORM:
3236 if (mpctx->file_format == DEMUXER_TYPE_TV)
3237 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3238 break;
3240 case MP_CMD_TV_STEP_CHANNEL_LIST:
3241 if (mpctx->file_format == DEMUXER_TYPE_TV)
3242 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3243 break;
3244 #endif /* CONFIG_TV */
3245 case MP_CMD_TV_TELETEXT_ADD_DEC:
3246 if (mpctx->demuxer->teletext)
3247 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3248 &(cmd->args[0].v.s));
3249 break;
3250 case MP_CMD_TV_TELETEXT_GO_LINK:
3251 if (mpctx->demuxer->teletext)
3252 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3253 &(cmd->args[0].v.i));
3254 break;
3256 case MP_CMD_SUB_LOAD:
3257 if (sh_video) {
3258 int n = mpctx->set_of_sub_size;
3259 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3260 if (n != mpctx->set_of_sub_size) {
3261 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3262 ++mpctx->global_sub_size;
3265 break;
3267 case MP_CMD_SUB_REMOVE:
3268 if (sh_video) {
3269 int v = cmd->args[0].v.i;
3270 if (v < 0) {
3271 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3272 } else if (v < mpctx->set_of_sub_size) {
3273 remove_subtitle_range(mpctx, v, 1);
3276 break;
3278 case MP_CMD_GET_SUB_VISIBILITY:
3279 if (sh_video) {
3280 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3281 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3283 break;
3285 case MP_CMD_SCREENSHOT:
3286 if (mpctx->video_out && mpctx->video_out->config_ok) {
3287 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3288 if (CONTROL_OK !=
3289 ((vf_instance_t *) sh_video->vfilter)->
3290 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3291 &cmd->args[0].v.i))
3292 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3294 break;
3296 case MP_CMD_VF_CHANGE_RECTANGLE:
3297 if (!sh_video)
3298 break;
3299 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3300 break;
3302 case MP_CMD_GET_TIME_LENGTH:{
3303 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3304 get_time_length(mpctx));
3306 break;
3308 case MP_CMD_GET_FILENAME:{
3309 char *inf = get_metadata(mpctx, META_NAME);
3310 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n", inf);
3311 talloc_free(inf);
3313 break;
3315 case MP_CMD_GET_VIDEO_CODEC:{
3316 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3317 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3318 talloc_free(inf);
3320 break;
3322 case MP_CMD_GET_VIDEO_BITRATE:{
3323 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3324 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3325 talloc_free(inf);
3327 break;
3329 case MP_CMD_GET_VIDEO_RESOLUTION:{
3330 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3331 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3332 talloc_free(inf);
3334 break;
3336 case MP_CMD_GET_AUDIO_CODEC:{
3337 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3338 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3339 talloc_free(inf);
3341 break;
3343 case MP_CMD_GET_AUDIO_BITRATE:{
3344 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3345 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3346 talloc_free(inf);
3348 break;
3350 case MP_CMD_GET_AUDIO_SAMPLES:{
3351 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3352 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3353 talloc_free(inf);
3355 break;
3357 case MP_CMD_GET_META_TITLE:{
3358 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3359 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3360 talloc_free(inf);
3362 break;
3364 case MP_CMD_GET_META_ARTIST:{
3365 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3366 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3367 talloc_free(inf);
3369 break;
3371 case MP_CMD_GET_META_ALBUM:{
3372 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3373 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3374 talloc_free(inf);
3376 break;
3378 case MP_CMD_GET_META_YEAR:{
3379 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3380 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3381 talloc_free(inf);
3383 break;
3385 case MP_CMD_GET_META_COMMENT:{
3386 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3387 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3388 talloc_free(inf);
3390 break;
3392 case MP_CMD_GET_META_TRACK:{
3393 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3394 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3395 talloc_free(inf);
3397 break;
3399 case MP_CMD_GET_META_GENRE:{
3400 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3401 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3402 talloc_free(inf);
3404 break;
3406 case MP_CMD_GET_VO_FULLSCREEN:
3407 if (mpctx->video_out && mpctx->video_out->config_ok)
3408 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3409 break;
3411 case MP_CMD_GET_PERCENT_POS:
3412 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3413 get_percent_pos(mpctx));
3414 break;
3416 case MP_CMD_GET_TIME_POS:{
3417 float pos = get_current_time(mpctx);
3418 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3420 break;
3422 case MP_CMD_RUN:
3423 #ifndef __MINGW32__
3424 if (!fork()) {
3425 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3426 exit(0);
3428 #endif
3429 break;
3431 case MP_CMD_KEYDOWN_EVENTS:
3432 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3433 break;
3435 case MP_CMD_SET_MOUSE_POS:{
3436 int pointer_x, pointer_y;
3437 double dx, dy;
3438 pointer_x = cmd->args[0].v.i;
3439 pointer_y = cmd->args[1].v.i;
3440 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3441 #ifdef CONFIG_DVDNAV
3442 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3443 && dx > 0.0 && dy > 0.0) {
3444 int button = -1;
3445 pointer_x = (int) (dx * (double) sh_video->disp_w);
3446 pointer_y = (int) (dy * (double) sh_video->disp_h);
3447 mp_dvdnav_update_mouse_pos(mpctx->stream,
3448 pointer_x, pointer_y, &button);
3449 if (opts->osd_level > 1 && button > 0)
3450 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3451 "Selected button number %d", button);
3453 #endif
3454 #ifdef CONFIG_MENU
3455 if (use_menu && dx >= 0.0 && dy >= 0.0)
3456 menu_update_mouse_pos(dx, dy);
3457 #endif
3459 break;
3461 #ifdef CONFIG_DVDNAV
3462 case MP_CMD_DVDNAV:{
3463 int button = -1;
3464 int i;
3465 mp_command_type command = 0;
3466 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3467 break;
3469 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3470 if (cmd->args[0].v.s &&
3471 !strcasecmp (cmd->args[0].v.s,
3472 mp_dvdnav_bindings[i].name))
3473 command = mp_dvdnav_bindings[i].cmd;
3475 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3476 if (opts->osd_level > 1 && button > 0)
3477 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3478 "Selected button number %d", button);
3480 break;
3482 case MP_CMD_SWITCH_TITLE:
3483 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3484 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3485 break;
3487 #endif
3489 case MP_CMD_AF_SWITCH:
3490 if (sh_audio)
3492 af_uninit(mpctx->mixer.afilter);
3493 af_init(mpctx->mixer.afilter);
3495 case MP_CMD_AF_ADD:
3496 case MP_CMD_AF_DEL:
3497 if (!sh_audio)
3498 break;
3500 char* af_args = strdup(cmd->args[0].v.s);
3501 char* af_commands = af_args;
3502 char* af_command;
3503 af_instance_t* af;
3504 while ((af_command = strsep(&af_commands, ",")) != NULL)
3506 if (cmd->id == MP_CMD_AF_DEL)
3508 af = af_get(mpctx->mixer.afilter, af_command);
3509 if (af != NULL)
3510 af_remove(mpctx->mixer.afilter, af);
3512 else
3513 af_add(mpctx->mixer.afilter, af_command);
3515 reinit_audio_chain(mpctx);
3516 free(af_args);
3518 break;
3519 case MP_CMD_AF_CLR:
3520 if (!sh_audio)
3521 break;
3522 af_uninit(mpctx->mixer.afilter);
3523 af_init(mpctx->mixer.afilter);
3524 reinit_audio_chain(mpctx);
3525 break;
3526 case MP_CMD_AF_CMDLINE:
3527 if (sh_audio) {
3528 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3529 if (!af) {
3530 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3531 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3532 break;
3534 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3535 af_reinit(sh_audio->afilter, af);
3537 break;
3539 default:
3540 mp_msg(MSGT_CPLAYER, MSGL_V,
3541 "Received unknown cmd %s\n", cmd->name);
3544 switch (cmd->pausing) {
3545 case 1: // "pausing"
3546 pause_player(mpctx);
3547 break;
3548 case 3: // "pausing_toggle"
3549 if (mpctx->paused)
3550 unpause_player(mpctx);
3551 else
3552 pause_player(mpctx);
3553 break;