stream_cue: fix multiple bugs
[mplayer.git] / command.c
blob817becad0fdb1fc148e094a0791415efed095f3e
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdlib.h>
20 #include <inttypes.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <stdbool.h>
25 #include "config.h"
26 #include "talloc.h"
27 #include "command.h"
28 #include "input/input.h"
29 #include "stream/stream.h"
30 #include "libmpdemux/demuxer.h"
31 #include "libmpdemux/stheader.h"
32 #include "codec-cfg.h"
33 #include "mplayer.h"
34 #include "sub/sub.h"
35 #include "sub/dec_sub.h"
36 #include "m_option.h"
37 #include "m_property.h"
38 #include "m_config.h"
39 #include "metadata.h"
40 #include "libmpcodecs/vf.h"
41 #include "libmpcodecs/vd.h"
42 #include "mp_osd.h"
43 #include "libvo/video_out.h"
44 #include "sub/font_load.h"
45 #include "playtree.h"
46 #include "libao2/audio_out.h"
47 #include "mpcommon.h"
48 #include "mixer.h"
49 #include "libmpcodecs/dec_video.h"
50 #include "libmpcodecs/dec_audio.h"
51 #include "libmpcodecs/dec_teletext.h"
52 #include "osdep/strsep.h"
53 #include "sub/vobsub.h"
54 #include "sub/spudec.h"
55 #include "path.h"
56 #include "sub/ass_mp.h"
57 #include "stream/tv.h"
58 #include "stream/stream_radio.h"
59 #include "stream/pvr.h"
60 #ifdef CONFIG_DVBIN
61 #include "stream/dvbin.h"
62 #endif
63 #ifdef CONFIG_DVDREAD
64 #include "stream/stream_dvd.h"
65 #endif
66 #include "stream/stream_dvdnav.h"
67 #include "m_struct.h"
68 #include "libmenu/menu.h"
70 #include "mp_core.h"
71 #include "mp_fifo.h"
72 #include "libavutil/avstring.h"
74 extern int use_menu;
76 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
77 double *dx, double *dy)
79 struct MPOpts *opts = &mpctx->opts;
80 struct vo *vo = mpctx->video_out;
81 //remove the borders, if any, and rescale to the range [0,1],[0,1]
82 if (vo_fs) { //we are in full-screen mode
83 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
84 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
85 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
86 iy -= (opts->vo_screenheight - vo->dheight) / 2;
88 if (ix < 0 || ix > vo->dwidth) {
89 *dx = *dy = -1.0;
90 return;
91 } //we are on one of the borders
92 if (iy < 0 || iy > vo->dheight) {
93 *dx = *dy = -1.0;
94 return;
95 } //we are on one of the borders
98 *dx = (double) ix / (double) vo->dwidth;
99 *dy = (double) iy / (double) vo->dheight;
101 mp_msg(MSGT_CPLAYER, MSGL_V,
102 "\r\nrescaled coordinates: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
103 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
104 vo->dheight, vo_fs);
107 static int sub_pos_by_source(MPContext *mpctx, int src)
109 int i, cnt = 0;
110 if (src >= SUB_SOURCES || mpctx->sub_counts[src] == 0)
111 return -1;
112 for (i = 0; i < src; i++)
113 cnt += mpctx->sub_counts[i];
114 return cnt;
117 static int sub_source_and_index_by_pos(MPContext *mpctx, int *pos)
119 int start = 0;
120 int i;
121 for (i = 0; i < SUB_SOURCES; i++) {
122 int cnt = mpctx->sub_counts[i];
123 if (*pos >= start && *pos < start + cnt) {
124 *pos -= start;
125 return i;
127 start += cnt;
129 *pos = -1;
130 return -1;
133 static int sub_source_by_pos(MPContext *mpctx, int pos)
135 return sub_source_and_index_by_pos(mpctx, &pos);
138 static int sub_source_pos(MPContext *mpctx)
140 int pos = mpctx->global_sub_pos;
141 sub_source_and_index_by_pos(mpctx, &pos);
142 return pos;
145 static int sub_source(MPContext *mpctx)
147 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
150 static void update_global_sub_size(MPContext *mpctx)
152 struct MPOpts *opts = &mpctx->opts;
153 int i;
154 int cnt = 0;
156 // update number of demuxer sub streams
157 for (i = 0; i < MAX_S_STREAMS; i++)
158 if (mpctx->d_sub->demuxer->s_streams[i])
159 cnt++;
160 if (cnt > mpctx->sub_counts[SUB_SOURCE_DEMUX])
161 mpctx->sub_counts[SUB_SOURCE_DEMUX] = cnt;
163 // update global size
164 mpctx->global_sub_size = 0;
165 for (i = 0; i < SUB_SOURCES; i++)
166 mpctx->global_sub_size += mpctx->sub_counts[i];
168 // update global_sub_pos if we auto-detected a demuxer sub
169 if (mpctx->global_sub_pos == -1) {
170 int sub_id = -1;
171 if (mpctx->demuxer->sub)
172 sub_id = mpctx->demuxer->sub->id;
173 if (sub_id < 0)
174 sub_id = opts->sub_id;
175 if (sub_id >= 0 && sub_id < mpctx->sub_counts[SUB_SOURCE_DEMUX])
176 mpctx->global_sub_pos = sub_pos_by_source(mpctx, SUB_SOURCE_DEMUX) +
177 sub_id;
182 * \brief Log the currently displayed subtitle to a file
184 * Logs the current or last displayed subtitle together with filename
185 * and time information to ~/.mplayer/subtitle_log
187 * Intended purpose is to allow convenient marking of bogus subtitles
188 * which need to be fixed while watching the movie.
191 static void log_sub(struct MPContext *mpctx)
193 char *fname;
194 FILE *f;
195 int i;
196 struct subtitle *vo_sub_last = mpctx->vo_sub_last;
198 if (mpctx->subdata == NULL || vo_sub_last == NULL)
199 return;
200 fname = get_path("subtitle_log");
201 f = fopen(fname, "a");
202 if (!f)
203 return;
204 fprintf(f, "----------------------------------------------------------\n");
205 if (mpctx->subdata->sub_uses_time) {
206 fprintf(f,
207 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
208 mpctx->filename, vo_sub_last->start / 360000,
209 (vo_sub_last->start / 6000) % 60,
210 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
211 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
212 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
213 } else {
214 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
215 vo_sub_last->start, vo_sub_last->end);
217 for (i = 0; i < vo_sub_last->lines; i++) {
218 fprintf(f, "%s\n", vo_sub_last->text[i]);
220 fclose(f);
224 /// \defgroup Properties
225 ///@{
227 /// \defgroup GeneralProperties General properties
228 /// \ingroup Properties
229 ///@{
231 static int mp_property_generic_option(struct m_option *prop, int action,
232 void *arg, MPContext *mpctx)
234 char *optname = prop->priv;
235 const struct m_option *opt = m_config_get_option(mpctx->mconfig, optname);
236 void *valptr = m_option_get_ptr(opt, &mpctx->opts);
238 switch (action) {
239 case M_PROPERTY_GET_TYPE:
240 *(const struct m_option **)arg = opt;
241 return M_PROPERTY_OK;
242 case M_PROPERTY_GET:
243 m_option_copy(opt, arg, valptr);
244 return M_PROPERTY_OK;
245 case M_PROPERTY_SET:
246 m_option_copy(opt, valptr, arg);
247 return M_PROPERTY_OK;
248 case M_PROPERTY_STEP_UP:
249 if (opt->type == &m_option_type_choice) {
250 int v = *(int *) valptr;
251 int best = v;
252 struct m_opt_choice_alternatives *alt;
253 for (alt = opt->priv; alt->name; alt++)
254 if ((unsigned) alt->value - v - 1 < (unsigned) best - v - 1)
255 best = alt->value;
256 *(int *) valptr = best;
257 return M_PROPERTY_OK;
259 break;
261 return M_PROPERTY_NOT_IMPLEMENTED;
264 /// OSD level (RW)
265 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
266 MPContext *mpctx)
268 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
271 /// Loop (RW)
272 static int mp_property_loop(m_option_t *prop, int action, void *arg,
273 MPContext *mpctx)
275 struct MPOpts *opts = &mpctx->opts;
276 switch (action) {
277 case M_PROPERTY_PRINT:
278 if (!arg) return M_PROPERTY_ERROR;
279 if (opts->loop_times < 0)
280 *(char**)arg = talloc_strdup(NULL, "off");
281 else if (opts->loop_times == 0)
282 *(char**)arg = talloc_strdup(NULL, "inf");
283 else
284 break;
285 return M_PROPERTY_OK;
287 return m_property_int_range(prop, action, arg, &opts->loop_times);
290 /// Playback speed (RW)
291 static int mp_property_playback_speed(m_option_t *prop, int action,
292 void *arg, MPContext *mpctx)
294 struct MPOpts *opts = &mpctx->opts;
295 switch (action) {
296 case M_PROPERTY_SET:
297 if (!arg)
298 return M_PROPERTY_ERROR;
299 M_PROPERTY_CLAMP(prop, *(float *) arg);
300 opts->playback_speed = *(float *) arg;
301 reinit_audio_chain(mpctx);
302 return M_PROPERTY_OK;
303 case M_PROPERTY_STEP_UP:
304 case M_PROPERTY_STEP_DOWN:
305 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
306 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
307 M_PROPERTY_CLAMP(prop, opts->playback_speed);
308 reinit_audio_chain(mpctx);
309 return M_PROPERTY_OK;
311 return m_property_float_range(prop, action, arg, &opts->playback_speed);
314 /// filename with path (RO)
315 static int mp_property_path(m_option_t *prop, int action, void *arg,
316 MPContext *mpctx)
318 return m_property_string_ro(prop, action, arg, mpctx->filename);
321 /// filename without path (RO)
322 static int mp_property_filename(m_option_t *prop, int action, void *arg,
323 MPContext *mpctx)
325 char *f;
326 if (!mpctx->filename)
327 return M_PROPERTY_UNAVAILABLE;
328 f = (char *)mp_basename(mpctx->filename);
329 if (!*f)
330 f = mpctx->filename;
331 return m_property_string_ro(prop, action, arg, f);
334 /// Demuxer name (RO)
335 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
336 MPContext *mpctx)
338 if (!mpctx->demuxer)
339 return M_PROPERTY_UNAVAILABLE;
340 return m_property_string_ro(prop, action, arg,
341 (char *) mpctx->demuxer->desc->name);
344 /// Position in the stream (RW)
345 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
346 MPContext *mpctx)
348 if (!mpctx->demuxer || !mpctx->demuxer->stream)
349 return M_PROPERTY_UNAVAILABLE;
350 if (!arg)
351 return M_PROPERTY_ERROR;
352 switch (action) {
353 case M_PROPERTY_GET:
354 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
355 return M_PROPERTY_OK;
356 case M_PROPERTY_SET:
357 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
358 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
359 return M_PROPERTY_OK;
361 return M_PROPERTY_NOT_IMPLEMENTED;
364 /// Stream start offset (RO)
365 static int mp_property_stream_start(m_option_t *prop, int action,
366 void *arg, MPContext *mpctx)
368 if (!mpctx->demuxer || !mpctx->demuxer->stream)
369 return M_PROPERTY_UNAVAILABLE;
370 switch (action) {
371 case M_PROPERTY_GET:
372 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
373 return M_PROPERTY_OK;
375 return M_PROPERTY_NOT_IMPLEMENTED;
378 /// Stream end offset (RO)
379 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
380 MPContext *mpctx)
382 if (!mpctx->demuxer || !mpctx->demuxer->stream)
383 return M_PROPERTY_UNAVAILABLE;
384 switch (action) {
385 case M_PROPERTY_GET:
386 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
387 return M_PROPERTY_OK;
389 return M_PROPERTY_NOT_IMPLEMENTED;
392 /// Stream length (RO)
393 static int mp_property_stream_length(m_option_t *prop, int action,
394 void *arg, MPContext *mpctx)
396 if (!mpctx->demuxer || !mpctx->demuxer->stream)
397 return M_PROPERTY_UNAVAILABLE;
398 switch (action) {
399 case M_PROPERTY_GET:
400 *(off_t *) arg =
401 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
402 return M_PROPERTY_OK;
404 return M_PROPERTY_NOT_IMPLEMENTED;
407 /// Current stream position in seconds (RO)
408 static int mp_property_stream_time_pos(m_option_t *prop, int action,
409 void *arg, MPContext *mpctx)
411 if (!mpctx->demuxer || mpctx->demuxer->stream_pts == MP_NOPTS_VALUE)
412 return M_PROPERTY_UNAVAILABLE;
414 return m_property_time_ro(prop, action, arg, mpctx->demuxer->stream_pts);
418 /// Media length in seconds (RO)
419 static int mp_property_length(m_option_t *prop, int action, void *arg,
420 MPContext *mpctx)
422 double len;
424 if (!mpctx->demuxer ||
425 !(int) (len = get_time_length(mpctx)))
426 return M_PROPERTY_UNAVAILABLE;
428 return m_property_time_ro(prop, action, arg, len);
431 /// Current position in percent (RW)
432 static int mp_property_percent_pos(m_option_t *prop, int action,
433 void *arg, MPContext *mpctx) {
434 int pos;
436 if (!mpctx->demuxer)
437 return M_PROPERTY_UNAVAILABLE;
439 switch(action) {
440 case M_PROPERTY_SET:
441 if(!arg) return M_PROPERTY_ERROR;
442 M_PROPERTY_CLAMP(prop, *(int*)arg);
443 pos = *(int*)arg;
444 break;
445 case M_PROPERTY_STEP_UP:
446 case M_PROPERTY_STEP_DOWN:
447 pos = get_percent_pos(mpctx);
448 pos += (arg ? *(int*)arg : 10) *
449 (action == M_PROPERTY_STEP_UP ? 1 : -1);
450 M_PROPERTY_CLAMP(prop, pos);
451 break;
452 default:
453 return m_property_int_ro(prop, action, arg, get_percent_pos(mpctx));
456 queue_seek(mpctx, MPSEEK_FACTOR, pos / 100.0, 0);
457 return M_PROPERTY_OK;
460 /// Current position in seconds (RW)
461 static int mp_property_time_pos(m_option_t *prop, int action,
462 void *arg, MPContext *mpctx) {
463 if (!(mpctx->sh_video || mpctx->sh_audio))
464 return M_PROPERTY_UNAVAILABLE;
466 switch(action) {
467 case M_PROPERTY_SET:
468 if(!arg) return M_PROPERTY_ERROR;
469 M_PROPERTY_CLAMP(prop, *(double*)arg);
470 queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double*)arg, 0);
471 return M_PROPERTY_OK;
472 case M_PROPERTY_STEP_UP:
473 case M_PROPERTY_STEP_DOWN:
474 queue_seek(mpctx, MPSEEK_RELATIVE, (arg ? *(double*)arg : 10.0) *
475 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0), 0);
476 return M_PROPERTY_OK;
478 return m_property_time_ro(prop, action, arg, get_current_time(mpctx));
481 /// Current chapter (RW)
482 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
483 MPContext *mpctx)
485 struct MPOpts *opts = &mpctx->opts;
486 int chapter = -1;
487 int step_all;
488 char *chapter_name = NULL;
490 if (mpctx->demuxer)
491 chapter = get_current_chapter(mpctx);
492 if (chapter < -1)
493 return M_PROPERTY_UNAVAILABLE;
495 switch (action) {
496 case M_PROPERTY_GET:
497 if (!arg)
498 return M_PROPERTY_ERROR;
499 *(int *) arg = chapter;
500 return M_PROPERTY_OK;
501 case M_PROPERTY_PRINT: {
502 if (!arg)
503 return M_PROPERTY_ERROR;
504 chapter_name = chapter_display_name(mpctx, chapter);
505 if (!chapter_name)
506 return M_PROPERTY_UNAVAILABLE;
507 *(char **) arg = chapter_name;
508 return M_PROPERTY_OK;
510 case M_PROPERTY_SET:
511 if (!arg)
512 return M_PROPERTY_ERROR;
513 M_PROPERTY_CLAMP(prop, *(int*)arg);
514 step_all = *(int *)arg - chapter;
515 chapter += step_all;
516 break;
517 case M_PROPERTY_STEP_UP:
518 case M_PROPERTY_STEP_DOWN: {
519 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
520 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
521 chapter += step_all;
522 if (chapter < 0)
523 chapter = 0;
524 break;
526 default:
527 return M_PROPERTY_NOT_IMPLEMENTED;
530 double next_pts = 0;
531 queue_seek(mpctx, MPSEEK_NONE, 0, 0);
532 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
533 if (chapter >= 0) {
534 if (next_pts > -1.0)
535 queue_seek(mpctx, MPSEEK_ABSOLUTE, next_pts, 0);
536 if (chapter_name)
537 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
538 "Chapter: (%d) %s", chapter + 1, chapter_name);
539 } else if (step_all > 0)
540 queue_seek(mpctx, MPSEEK_RELATIVE, 1000000000, 0);
541 else
542 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
543 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
544 talloc_free(chapter_name);
545 return M_PROPERTY_OK;
548 /// Number of chapters in file
549 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
550 MPContext *mpctx)
552 if (!mpctx->demuxer)
553 return M_PROPERTY_UNAVAILABLE;
554 if (mpctx->demuxer->num_chapters == 0)
555 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
556 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
559 /// Current dvd angle (RW)
560 static int mp_property_angle(m_option_t *prop, int action, void *arg,
561 MPContext *mpctx)
563 struct MPOpts *opts = &mpctx->opts;
564 int angle = -1;
565 int angles;
567 if (mpctx->demuxer)
568 angle = demuxer_get_current_angle(mpctx->demuxer);
569 if (angle < 0)
570 return M_PROPERTY_UNAVAILABLE;
571 angles = demuxer_angles_count(mpctx->demuxer);
572 if (angles <= 1)
573 return M_PROPERTY_UNAVAILABLE;
575 switch (action) {
576 case M_PROPERTY_GET:
577 if (!arg)
578 return M_PROPERTY_ERROR;
579 *(int *) arg = angle;
580 return M_PROPERTY_OK;
581 case M_PROPERTY_PRINT: {
582 if (!arg)
583 return M_PROPERTY_ERROR;
584 *(char **) arg = talloc_asprintf(NULL, "%d/%d", angle, angles);
585 return M_PROPERTY_OK;
587 case M_PROPERTY_SET:
588 if (!arg)
589 return M_PROPERTY_ERROR;
590 angle = *(int *)arg;
591 M_PROPERTY_CLAMP(prop, angle);
592 break;
593 case M_PROPERTY_STEP_UP:
594 case M_PROPERTY_STEP_DOWN: {
595 int step = 0;
596 if(arg)
597 step = *(int*)arg;
598 if(!step)
599 step = 1;
600 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
601 angle += step;
602 if (angle < 1) //cycle
603 angle = angles;
604 else if (angle > angles)
605 angle = 1;
606 break;
608 default:
609 return M_PROPERTY_NOT_IMPLEMENTED;
611 angle = demuxer_set_angle(mpctx->demuxer, angle);
612 if (angle >= 0) {
613 struct sh_video *sh_video = mpctx->demuxer->video->sh;
614 if (sh_video)
615 resync_video_stream(sh_video);
617 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
618 if (sh_audio)
619 resync_audio_stream(sh_audio);
622 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
623 "Angle: %d/%d", angle, angles);
624 return M_PROPERTY_OK;
627 /// Demuxer meta data
628 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
629 MPContext *mpctx) {
630 m_property_action_t* ka;
631 char* meta;
632 static const m_option_t key_type =
633 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
634 if (!mpctx->demuxer)
635 return M_PROPERTY_UNAVAILABLE;
637 switch(action) {
638 case M_PROPERTY_GET:
639 if(!arg) return M_PROPERTY_ERROR;
640 *(char***)arg = mpctx->demuxer->info;
641 return M_PROPERTY_OK;
642 case M_PROPERTY_KEY_ACTION:
643 if(!arg) return M_PROPERTY_ERROR;
644 ka = arg;
645 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
646 return M_PROPERTY_UNKNOWN;
647 switch(ka->action) {
648 case M_PROPERTY_GET:
649 if(!ka->arg) return M_PROPERTY_ERROR;
650 *(char**)ka->arg = meta;
651 return M_PROPERTY_OK;
652 case M_PROPERTY_GET_TYPE:
653 if(!ka->arg) return M_PROPERTY_ERROR;
654 *(const m_option_t**)ka->arg = &key_type;
655 return M_PROPERTY_OK;
658 return M_PROPERTY_NOT_IMPLEMENTED;
661 static int mp_property_pause(m_option_t *prop, int action, void *arg,
662 void *ctx)
664 MPContext *mpctx = ctx;
666 switch (action) {
667 case M_PROPERTY_SET:
668 if (!arg)
669 return M_PROPERTY_ERROR;
670 if (mpctx->paused == (bool)*(int *) arg)
671 return M_PROPERTY_OK;
672 case M_PROPERTY_STEP_UP:
673 case M_PROPERTY_STEP_DOWN:
674 if (mpctx->paused) {
675 unpause_player(mpctx);
676 mpctx->osd_function = OSD_PLAY;
678 else {
679 pause_player(mpctx);
680 mpctx->osd_function = OSD_PAUSE;
682 return M_PROPERTY_OK;
683 default:
684 return m_property_flag(prop, action, arg, &mpctx->paused);
689 ///@}
691 /// \defgroup AudioProperties Audio properties
692 /// \ingroup Properties
693 ///@{
695 /// Volume (RW)
696 static int mp_property_volume(m_option_t *prop, int action, void *arg,
697 MPContext *mpctx)
700 if (!mpctx->sh_audio)
701 return M_PROPERTY_UNAVAILABLE;
703 switch (action) {
704 case M_PROPERTY_GET:
705 if (!arg)
706 return M_PROPERTY_ERROR;
707 mixer_getbothvolume(&mpctx->mixer, arg);
708 return M_PROPERTY_OK;
709 case M_PROPERTY_PRINT:{
710 float vol;
711 if (!arg)
712 return M_PROPERTY_ERROR;
713 mixer_getbothvolume(&mpctx->mixer, &vol);
714 return m_property_float_range(prop, action, arg, &vol);
716 case M_PROPERTY_STEP_UP:
717 case M_PROPERTY_STEP_DOWN:
718 case M_PROPERTY_SET:
719 break;
720 default:
721 return M_PROPERTY_NOT_IMPLEMENTED;
724 if (mpctx->edl_muted)
725 return M_PROPERTY_DISABLED;
726 mpctx->user_muted = 0;
728 switch (action) {
729 case M_PROPERTY_SET:
730 if (!arg)
731 return M_PROPERTY_ERROR;
732 M_PROPERTY_CLAMP(prop, *(float *) arg);
733 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
734 return M_PROPERTY_OK;
735 case M_PROPERTY_STEP_UP:
736 if (arg && *(float *) arg <= 0)
737 mixer_decvolume(&mpctx->mixer);
738 else
739 mixer_incvolume(&mpctx->mixer);
740 return M_PROPERTY_OK;
741 case M_PROPERTY_STEP_DOWN:
742 if (arg && *(float *) arg <= 0)
743 mixer_incvolume(&mpctx->mixer);
744 else
745 mixer_decvolume(&mpctx->mixer);
746 return M_PROPERTY_OK;
748 return M_PROPERTY_NOT_IMPLEMENTED;
751 /// Mute (RW)
752 static int mp_property_mute(m_option_t *prop, int action, void *arg,
753 MPContext *mpctx)
756 if (!mpctx->sh_audio)
757 return M_PROPERTY_UNAVAILABLE;
759 switch (action) {
760 case M_PROPERTY_SET:
761 if (mpctx->edl_muted)
762 return M_PROPERTY_DISABLED;
763 if (!arg)
764 return M_PROPERTY_ERROR;
765 if ((!!*(int *) arg) != mpctx->mixer.muted)
766 mixer_mute(&mpctx->mixer);
767 mpctx->user_muted = mpctx->mixer.muted;
768 return M_PROPERTY_OK;
769 case M_PROPERTY_STEP_UP:
770 case M_PROPERTY_STEP_DOWN:
771 if (mpctx->edl_muted)
772 return M_PROPERTY_DISABLED;
773 mixer_mute(&mpctx->mixer);
774 mpctx->user_muted = mpctx->mixer.muted;
775 return M_PROPERTY_OK;
776 case M_PROPERTY_PRINT:
777 if (!arg)
778 return M_PROPERTY_ERROR;
779 if (mpctx->edl_muted) {
780 *(char **) arg = talloc_strdup(NULL, mp_gtext("enabled (EDL)"));
781 return M_PROPERTY_OK;
783 default:
784 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
789 /// Audio delay (RW)
790 static int mp_property_audio_delay(m_option_t *prop, int action,
791 void *arg, MPContext *mpctx)
793 if (!(mpctx->sh_audio && mpctx->sh_video))
794 return M_PROPERTY_UNAVAILABLE;
795 switch (action) {
796 case M_PROPERTY_SET:
797 case M_PROPERTY_STEP_UP:
798 case M_PROPERTY_STEP_DOWN: {
799 int ret;
800 float delay = audio_delay;
801 ret = m_property_delay(prop, action, arg, &audio_delay);
802 if (ret != M_PROPERTY_OK)
803 return ret;
804 if (mpctx->sh_audio)
805 mpctx->delay -= audio_delay - delay;
807 return M_PROPERTY_OK;
808 default:
809 return m_property_delay(prop, action, arg, &audio_delay);
813 /// Audio codec tag (RO)
814 static int mp_property_audio_format(m_option_t *prop, int action,
815 void *arg, MPContext *mpctx)
817 if (!mpctx->sh_audio)
818 return M_PROPERTY_UNAVAILABLE;
819 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
822 /// Audio codec name (RO)
823 static int mp_property_audio_codec(m_option_t *prop, int action,
824 void *arg, MPContext *mpctx)
826 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
827 return M_PROPERTY_UNAVAILABLE;
828 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
831 /// Audio bitrate (RO)
832 static int mp_property_audio_bitrate(m_option_t *prop, int action,
833 void *arg, MPContext *mpctx)
835 if (!mpctx->sh_audio)
836 return M_PROPERTY_UNAVAILABLE;
837 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
840 /// Samplerate (RO)
841 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
842 MPContext *mpctx)
844 if (!mpctx->sh_audio)
845 return M_PROPERTY_UNAVAILABLE;
846 switch(action) {
847 case M_PROPERTY_PRINT:
848 if(!arg) return M_PROPERTY_ERROR;
849 *(char**)arg = talloc_asprintf(NULL, "%d kHz",
850 mpctx->sh_audio->samplerate/1000);
851 return M_PROPERTY_OK;
853 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
856 /// Number of channels (RO)
857 static int mp_property_channels(m_option_t *prop, int action, void *arg,
858 MPContext *mpctx)
860 if (!mpctx->sh_audio)
861 return M_PROPERTY_UNAVAILABLE;
862 switch (action) {
863 case M_PROPERTY_PRINT:
864 if (!arg)
865 return M_PROPERTY_ERROR;
866 switch (mpctx->sh_audio->channels) {
867 case 1:
868 *(char **) arg = talloc_strdup(NULL, "mono");
869 break;
870 case 2:
871 *(char **) arg = talloc_strdup(NULL, "stereo");
872 break;
873 default:
874 *(char **) arg = talloc_asprintf(NULL, "%d channels",
875 mpctx->sh_audio->channels);
877 return M_PROPERTY_OK;
879 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
882 /// Balance (RW)
883 static int mp_property_balance(m_option_t *prop, int action, void *arg,
884 MPContext *mpctx)
886 float bal;
888 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
889 return M_PROPERTY_UNAVAILABLE;
891 switch (action) {
892 case M_PROPERTY_GET:
893 if (!arg)
894 return M_PROPERTY_ERROR;
895 mixer_getbalance(&mpctx->mixer, arg);
896 return M_PROPERTY_OK;
897 case M_PROPERTY_PRINT: {
898 char** str = arg;
899 if (!arg)
900 return M_PROPERTY_ERROR;
901 mixer_getbalance(&mpctx->mixer, &bal);
902 if (bal == 0.f)
903 *str = talloc_strdup(NULL, "center");
904 else if (bal == -1.f)
905 *str = talloc_strdup(NULL, "left only");
906 else if (bal == 1.f)
907 *str = talloc_strdup(NULL, "right only");
908 else {
909 unsigned right = (bal + 1.f) / 2.f * 100.f;
910 *str = talloc_asprintf(NULL, "left %d%%, right %d%%",
911 100 - right, right);
913 return M_PROPERTY_OK;
915 case M_PROPERTY_STEP_UP:
916 case M_PROPERTY_STEP_DOWN:
917 mixer_getbalance(&mpctx->mixer, &bal);
918 bal += (arg ? *(float*)arg : .1f) *
919 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
920 M_PROPERTY_CLAMP(prop, bal);
921 mixer_setbalance(&mpctx->mixer, bal);
922 return M_PROPERTY_OK;
923 case M_PROPERTY_SET:
924 if (!arg)
925 return M_PROPERTY_ERROR;
926 M_PROPERTY_CLAMP(prop, *(float*)arg);
927 mixer_setbalance(&mpctx->mixer, *(float*)arg);
928 return M_PROPERTY_OK;
930 return M_PROPERTY_NOT_IMPLEMENTED;
933 /// Selected audio id (RW)
934 static int mp_property_audio(m_option_t *prop, int action, void *arg,
935 MPContext *mpctx)
937 int current_id, tmp;
938 if (!mpctx->demuxer || !mpctx->d_audio)
939 return M_PROPERTY_UNAVAILABLE;
940 struct sh_audio *sh = mpctx->sh_audio;
941 current_id = sh ? sh->aid : -2;
943 switch (action) {
944 case M_PROPERTY_GET:
945 if (!arg)
946 return M_PROPERTY_ERROR;
947 *(int *) arg = current_id;
948 return M_PROPERTY_OK;
949 case M_PROPERTY_PRINT:
950 if (!arg)
951 return M_PROPERTY_ERROR;
953 if (current_id < 0)
954 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
955 else if (sh && (sh->lang || sh->title)) {
956 char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
957 if (sh->title)
958 *(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
959 current_id, lang, sh->title);
960 else
961 *(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id,
962 lang);
963 } else {
964 char lang[40];
965 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
966 if (0);
967 #ifdef CONFIG_DVDREAD
968 else if (mpctx->stream->type == STREAMTYPE_DVD) {
969 int code = dvd_lang_from_aid(mpctx->stream, current_id);
970 if (code) {
971 lang[0] = code >> 8;
972 lang[1] = code;
973 lang[2] = 0;
976 #endif
978 #ifdef CONFIG_DVDNAV
979 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
980 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
981 #endif
982 *(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id, lang);
984 return M_PROPERTY_OK;
986 case M_PROPERTY_STEP_UP:
987 case M_PROPERTY_SET:
988 if (action == M_PROPERTY_SET && arg)
989 tmp = *((int *) arg);
990 else
991 tmp = -1;
992 int new_id = demuxer_switch_audio(mpctx->d_audio->demuxer, tmp);
993 if (new_id != current_id)
994 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
995 if (new_id != current_id && new_id >= 0) {
996 sh_audio_t *sh2;
997 sh2 = mpctx->d_audio->demuxer->a_streams[mpctx->d_audio->id];
998 sh2->ds = mpctx->d_audio;
999 mpctx->sh_audio = sh2;
1000 reinit_audio_chain(mpctx);
1002 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
1003 return M_PROPERTY_OK;
1004 default:
1005 return M_PROPERTY_NOT_IMPLEMENTED;
1010 /// Selected video id (RW)
1011 static int mp_property_video(m_option_t *prop, int action, void *arg,
1012 MPContext *mpctx)
1014 struct MPOpts *opts = &mpctx->opts;
1015 int current_id, tmp;
1016 if (!mpctx->demuxer || !mpctx->d_video)
1017 return M_PROPERTY_UNAVAILABLE;
1018 current_id = mpctx->sh_video ? mpctx->sh_video->vid : -2;
1020 switch (action) {
1021 case M_PROPERTY_GET:
1022 if (!arg)
1023 return M_PROPERTY_ERROR;
1024 *(int *) arg = current_id;
1025 return M_PROPERTY_OK;
1026 case M_PROPERTY_PRINT:
1027 if (!arg)
1028 return M_PROPERTY_ERROR;
1030 if (current_id < 0)
1031 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1032 else {
1033 *(char **) arg = talloc_asprintf(NULL, "(%d) %s", current_id,
1034 mp_gtext("unknown"));
1036 return M_PROPERTY_OK;
1038 case M_PROPERTY_STEP_UP:
1039 case M_PROPERTY_SET:
1040 if (action == M_PROPERTY_SET && arg)
1041 tmp = *((int *) arg);
1042 else
1043 tmp = -1;
1044 int new_id = demuxer_switch_video(mpctx->d_video->demuxer, tmp);
1045 if (new_id != current_id)
1046 uninit_player(mpctx, INITIALIZED_VCODEC |
1047 (opts->fixed_vo && new_id >= 0 ? 0 : INITIALIZED_VO));
1048 if (new_id != current_id && new_id >= 0) {
1049 sh_video_t *sh2;
1050 sh2 = mpctx->d_video->demuxer->v_streams[mpctx->d_video->id];
1051 sh2->ds = mpctx->d_video;
1052 mpctx->sh_video = sh2;
1053 reinit_video_chain(mpctx);
1055 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", new_id);
1056 return M_PROPERTY_OK;
1058 default:
1059 return M_PROPERTY_NOT_IMPLEMENTED;
1063 static int mp_property_program(m_option_t *prop, int action, void *arg,
1064 MPContext *mpctx)
1066 demux_program_t prog;
1068 switch (action) {
1069 case M_PROPERTY_STEP_UP:
1070 case M_PROPERTY_SET:
1071 if (action == M_PROPERTY_SET && arg)
1072 prog.progid = *((int *) arg);
1073 else
1074 prog.progid = -1;
1075 if (demux_control
1076 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1077 &prog) == DEMUXER_CTRL_NOTIMPL)
1078 return M_PROPERTY_ERROR;
1080 if (prog.aid < 0 && prog.vid < 0) {
1081 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
1082 return M_PROPERTY_ERROR;
1084 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1085 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1086 return M_PROPERTY_OK;
1088 default:
1089 return M_PROPERTY_NOT_IMPLEMENTED;
1093 ///@}
1095 /// \defgroup VideoProperties Video properties
1096 /// \ingroup Properties
1097 ///@{
1099 /// Fullscreen state (RW)
1100 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1101 MPContext *mpctx)
1104 if (!mpctx->video_out)
1105 return M_PROPERTY_UNAVAILABLE;
1107 switch (action) {
1108 case M_PROPERTY_SET:
1109 if (!arg)
1110 return M_PROPERTY_ERROR;
1111 M_PROPERTY_CLAMP(prop, *(int *) arg);
1112 if (vo_fs == !!*(int *) arg)
1113 return M_PROPERTY_OK;
1114 case M_PROPERTY_STEP_UP:
1115 case M_PROPERTY_STEP_DOWN:
1116 if (mpctx->video_out->config_ok)
1117 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1118 mpctx->opts.fullscreen = vo_fs;
1119 return M_PROPERTY_OK;
1120 default:
1121 return m_property_flag(prop, action, arg, &vo_fs);
1125 static int mp_property_deinterlace(m_option_t *prop, int action,
1126 void *arg, MPContext *mpctx)
1128 int deinterlace;
1129 vf_instance_t *vf;
1130 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1131 return M_PROPERTY_UNAVAILABLE;
1132 vf = mpctx->sh_video->vfilter;
1133 switch (action) {
1134 case M_PROPERTY_GET:
1135 if (!arg)
1136 return M_PROPERTY_ERROR;
1137 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1138 return M_PROPERTY_OK;
1139 case M_PROPERTY_SET:
1140 if (!arg)
1141 return M_PROPERTY_ERROR;
1142 M_PROPERTY_CLAMP(prop, *(int *) arg);
1143 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1144 return M_PROPERTY_OK;
1145 case M_PROPERTY_STEP_UP:
1146 case M_PROPERTY_STEP_DOWN:
1147 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1148 deinterlace = !deinterlace;
1149 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1150 return M_PROPERTY_OK;
1152 int value = 0;
1153 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1154 return m_property_flag_ro(prop, action, arg, value);
1157 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1158 void *arg, MPContext *mpctx)
1160 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1161 return M_PROPERTY_UNAVAILABLE;
1163 struct vf_instance *vf = mpctx->sh_video->vfilter;
1164 int colorspace;
1165 switch (action) {
1166 case M_PROPERTY_GET:
1167 if (!arg)
1168 return M_PROPERTY_ERROR;
1169 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1170 return M_PROPERTY_UNAVAILABLE;
1171 return M_PROPERTY_OK;
1172 case M_PROPERTY_PRINT:
1173 if (!arg)
1174 return M_PROPERTY_ERROR;
1175 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1176 return M_PROPERTY_UNAVAILABLE;
1177 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1178 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1179 *(char **)arg = talloc_strdup(NULL, mp_gtext("unknown"));
1180 else
1181 *(char**)arg = talloc_strdup(NULL, names[colorspace]);
1182 return M_PROPERTY_OK;
1183 case M_PROPERTY_SET:
1184 if (!arg)
1185 return M_PROPERTY_ERROR;
1186 M_PROPERTY_CLAMP(prop, *(int *) arg);
1187 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1188 return M_PROPERTY_OK;
1189 case M_PROPERTY_STEP_UP:;
1190 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1191 return M_PROPERTY_UNAVAILABLE;
1192 colorspace += 1;
1193 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1194 return M_PROPERTY_OK;
1196 return M_PROPERTY_NOT_IMPLEMENTED;
1199 static int mp_property_capture(m_option_t *prop, int action,
1200 void *arg, MPContext *mpctx)
1202 struct MPOpts *opts = &mpctx->opts;
1204 if (!mpctx->stream)
1205 return M_PROPERTY_UNAVAILABLE;
1207 if (!opts->capture_dump) {
1208 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1209 "Capturing not enabled (forgot -capture parameter?)\n");
1210 return M_PROPERTY_ERROR;
1213 int capturing = !!mpctx->stream->capture_file;
1215 int ret = m_property_flag(prop, action, arg, &capturing);
1216 if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
1217 if (capturing) {
1218 mpctx->stream->capture_file = fopen(opts->stream_dump_name, "wb");
1219 if (!mpctx->stream->capture_file) {
1220 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1221 "Error opening capture file: %s\n", strerror(errno));
1222 ret = M_PROPERTY_ERROR;
1224 } else {
1225 fclose(mpctx->stream->capture_file);
1226 mpctx->stream->capture_file = NULL;
1230 return ret;
1233 /// Panscan (RW)
1234 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1235 MPContext *mpctx)
1238 if (!mpctx->video_out
1239 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1240 return M_PROPERTY_UNAVAILABLE;
1242 switch (action) {
1243 case M_PROPERTY_SET:
1244 if (!arg)
1245 return M_PROPERTY_ERROR;
1246 M_PROPERTY_CLAMP(prop, *(float *) arg);
1247 vo_panscan = *(float *) arg;
1248 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1249 return M_PROPERTY_OK;
1250 case M_PROPERTY_STEP_UP:
1251 case M_PROPERTY_STEP_DOWN:
1252 vo_panscan += (arg ? *(float *) arg : 0.1) *
1253 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1254 if (vo_panscan > 1)
1255 vo_panscan = 1;
1256 else if (vo_panscan < 0)
1257 vo_panscan = 0;
1258 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1259 return M_PROPERTY_OK;
1260 default:
1261 return m_property_float_range(prop, action, arg, &vo_panscan);
1265 /// Helper to set vo flags.
1266 /** \ingroup PropertyImplHelper
1268 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1269 int vo_ctrl, int *vo_var, MPContext *mpctx)
1272 if (!mpctx->video_out)
1273 return M_PROPERTY_UNAVAILABLE;
1275 switch (action) {
1276 case M_PROPERTY_SET:
1277 if (!arg)
1278 return M_PROPERTY_ERROR;
1279 M_PROPERTY_CLAMP(prop, *(int *) arg);
1280 if (*vo_var == !!*(int *) arg)
1281 return M_PROPERTY_OK;
1282 case M_PROPERTY_STEP_UP:
1283 case M_PROPERTY_STEP_DOWN:
1284 if (mpctx->video_out->config_ok)
1285 vo_control(mpctx->video_out, vo_ctrl, 0);
1286 return M_PROPERTY_OK;
1287 default:
1288 return m_property_flag(prop, action, arg, vo_var);
1292 /// Window always on top (RW)
1293 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1294 MPContext *mpctx)
1296 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1297 &mpctx->opts.vo_ontop, mpctx);
1300 /// Display in the root window (RW)
1301 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1302 MPContext *mpctx)
1304 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1305 &vo_rootwin, mpctx);
1308 /// Show window borders (RW)
1309 static int mp_property_border(m_option_t *prop, int action, void *arg,
1310 MPContext *mpctx)
1312 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1313 &vo_border, mpctx);
1316 /// Framedropping state (RW)
1317 static int mp_property_framedropping(m_option_t *prop, int action,
1318 void *arg, MPContext *mpctx)
1321 if (!mpctx->sh_video)
1322 return M_PROPERTY_UNAVAILABLE;
1324 switch (action) {
1325 case M_PROPERTY_PRINT:
1326 if (!arg)
1327 return M_PROPERTY_ERROR;
1328 *(char **) arg = talloc_strdup(NULL,
1329 frame_dropping == 1 ? mp_gtext("enabled") :
1330 (frame_dropping == 2 ? mp_gtext("hard") :
1331 mp_gtext("disabled")));
1332 return M_PROPERTY_OK;
1333 default:
1334 return m_property_choice(prop, action, arg, &frame_dropping);
1338 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1339 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1340 MPContext *mpctx)
1342 int *gamma = (int *)((char *)&mpctx->opts + prop->offset);
1343 int r, val;
1345 if (!mpctx->sh_video)
1346 return M_PROPERTY_UNAVAILABLE;
1348 if (gamma[0] == 1000) {
1349 gamma[0] = 0;
1350 get_video_colors(mpctx->sh_video, prop->name, gamma);
1353 switch (action) {
1354 case M_PROPERTY_SET:
1355 if (!arg)
1356 return M_PROPERTY_ERROR;
1357 M_PROPERTY_CLAMP(prop, *(int *) arg);
1358 *gamma = *(int *) arg;
1359 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1360 if (r <= 0)
1361 break;
1362 return r;
1363 case M_PROPERTY_GET:
1364 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1365 if (!arg)
1366 return M_PROPERTY_ERROR;
1367 *(int *)arg = val;
1368 return M_PROPERTY_OK;
1370 break;
1371 case M_PROPERTY_STEP_UP:
1372 case M_PROPERTY_STEP_DOWN:
1373 *gamma += (arg ? *(int *) arg : 1) *
1374 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1375 M_PROPERTY_CLAMP(prop, *gamma);
1376 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1377 if (r <= 0)
1378 break;
1379 return r;
1380 default:
1381 return M_PROPERTY_NOT_IMPLEMENTED;
1384 #ifdef CONFIG_TV
1385 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1386 int l = strlen(prop->name);
1387 char tv_prop[3 + l + 1];
1388 sprintf(tv_prop, "tv_%s", prop->name);
1389 return mp_property_do(tv_prop, action, arg, mpctx);
1391 #endif
1393 return M_PROPERTY_UNAVAILABLE;
1396 /// VSync (RW)
1397 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1398 MPContext *mpctx)
1400 return m_property_flag(prop, action, arg, &vo_vsync);
1403 /// Video codec tag (RO)
1404 static int mp_property_video_format(m_option_t *prop, int action,
1405 void *arg, MPContext *mpctx)
1407 char* meta;
1408 if (!mpctx->sh_video)
1409 return M_PROPERTY_UNAVAILABLE;
1410 switch(action) {
1411 case M_PROPERTY_PRINT:
1412 if (!arg)
1413 return M_PROPERTY_ERROR;
1414 switch(mpctx->sh_video->format) {
1415 case 0x10000001:
1416 meta = talloc_strdup(NULL, "mpeg1"); break;
1417 case 0x10000002:
1418 meta = talloc_strdup(NULL, "mpeg2"); break;
1419 case 0x10000004:
1420 meta = talloc_strdup(NULL, "mpeg4"); break;
1421 case 0x10000005:
1422 meta = talloc_strdup(NULL, "h264"); break;
1423 default:
1424 if(mpctx->sh_video->format >= 0x20202020) {
1425 meta = talloc_asprintf(NULL, "%.4s",
1426 (char *) &mpctx->sh_video->format);
1427 } else {
1428 meta = talloc_asprintf(NULL, "0x%08X", mpctx->sh_video->format);
1431 *(char**)arg = meta;
1432 return M_PROPERTY_OK;
1434 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1437 /// Video codec name (RO)
1438 static int mp_property_video_codec(m_option_t *prop, int action,
1439 void *arg, MPContext *mpctx)
1441 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1442 return M_PROPERTY_UNAVAILABLE;
1443 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1447 /// Video bitrate (RO)
1448 static int mp_property_video_bitrate(m_option_t *prop, int action,
1449 void *arg, MPContext *mpctx)
1451 if (!mpctx->sh_video)
1452 return M_PROPERTY_UNAVAILABLE;
1453 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1456 /// Video display width (RO)
1457 static int mp_property_width(m_option_t *prop, int action, void *arg,
1458 MPContext *mpctx)
1460 if (!mpctx->sh_video)
1461 return M_PROPERTY_UNAVAILABLE;
1462 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1465 /// Video display height (RO)
1466 static int mp_property_height(m_option_t *prop, int action, void *arg,
1467 MPContext *mpctx)
1469 if (!mpctx->sh_video)
1470 return M_PROPERTY_UNAVAILABLE;
1471 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1474 /// Video fps (RO)
1475 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1476 MPContext *mpctx)
1478 if (!mpctx->sh_video)
1479 return M_PROPERTY_UNAVAILABLE;
1480 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1483 /// Video aspect (RO)
1484 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1485 MPContext *mpctx)
1487 if (!mpctx->sh_video)
1488 return M_PROPERTY_UNAVAILABLE;
1489 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1492 ///@}
1494 /// \defgroup SubProprties Subtitles properties
1495 /// \ingroup Properties
1496 ///@{
1498 /// Text subtitle position (RW)
1499 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1500 MPContext *mpctx)
1502 switch (action) {
1503 case M_PROPERTY_SET:
1504 if (!arg)
1505 return M_PROPERTY_ERROR;
1506 case M_PROPERTY_STEP_UP:
1507 case M_PROPERTY_STEP_DOWN:
1508 vo_osd_changed(OSDTYPE_SUBTITLE);
1509 default:
1510 return m_property_int_range(prop, action, arg, &sub_pos);
1514 /// Selected subtitles (RW)
1515 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1516 MPContext *mpctx)
1518 struct MPOpts *opts = &mpctx->opts;
1519 demux_stream_t *const d_sub = mpctx->d_sub;
1520 int source = -1, reset_spu = 0;
1521 int source_pos = -1;
1523 update_global_sub_size(mpctx);
1524 const int global_sub_size = mpctx->global_sub_size;
1526 if (global_sub_size <= 0)
1527 return M_PROPERTY_UNAVAILABLE;
1529 switch (action) {
1530 case M_PROPERTY_GET:
1531 if (!arg)
1532 return M_PROPERTY_ERROR;
1533 *(int *) arg = mpctx->global_sub_pos;
1534 return M_PROPERTY_OK;
1535 case M_PROPERTY_PRINT:
1536 if (!arg)
1537 return M_PROPERTY_ERROR;
1538 char *sub_name = NULL;
1539 if (mpctx->subdata)
1540 sub_name = mpctx->subdata->filename;
1541 #ifdef CONFIG_ASS
1542 if (mpctx->osd->ass_track)
1543 sub_name = mpctx->osd->ass_track->name;
1544 #endif
1545 if (!sub_name && mpctx->subdata)
1546 sub_name = mpctx->subdata->filename;
1547 if (sub_name) {
1548 const char *tmp = mp_basename(sub_name);
1550 *(char **) arg = talloc_asprintf(NULL, "(%d) %s%s",
1551 mpctx->set_of_sub_pos + 1,
1552 strlen(tmp) < 20 ? "" : "...",
1553 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1554 return M_PROPERTY_OK;
1556 #ifdef CONFIG_DVDNAV
1557 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1558 if (vo_spudec && opts->sub_id >= 0) {
1559 unsigned char lang[3];
1560 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1561 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1562 opts->sub_id, lang);
1563 return M_PROPERTY_OK;
1567 #endif
1569 if ((d_sub->demuxer->type == DEMUXER_TYPE_MATROSKA
1570 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF
1571 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1572 || d_sub->demuxer->type == DEMUXER_TYPE_OGG)
1573 && d_sub->sh && opts->sub_id >= 0) {
1574 struct sh_sub *sh = d_sub->sh;
1575 char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
1576 if (sh->title)
1577 *(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
1578 opts->sub_id, lang, sh->title);
1579 else
1580 *(char **)arg = talloc_asprintf(NULL, "(%d) %s",
1581 opts->sub_id, lang);
1582 return M_PROPERTY_OK;
1585 if (vo_vobsub && vobsub_id >= 0) {
1586 const char *language = mp_gtext("unknown");
1587 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1588 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1589 vobsub_id, language ? language : mp_gtext("unknown"));
1590 return M_PROPERTY_OK;
1592 #ifdef CONFIG_DVDREAD
1593 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1594 && opts->sub_id >= 0) {
1595 char lang[3];
1596 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1597 lang[0] = code >> 8;
1598 lang[1] = code;
1599 lang[2] = 0;
1600 *(char **) arg = talloc_asprintf(NULL, "(%d) %s",
1601 opts->sub_id, lang);
1602 return M_PROPERTY_OK;
1604 #endif
1605 if (opts->sub_id >= 0) {
1606 *(char **) arg = talloc_asprintf(NULL, "(%d) %s", opts->sub_id,
1607 mp_gtext("unknown"));
1608 return M_PROPERTY_OK;
1610 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1611 return M_PROPERTY_OK;
1613 case M_PROPERTY_SET:
1614 if (!arg)
1615 return M_PROPERTY_ERROR;
1616 if (*(int *) arg < -1)
1617 *(int *) arg = -1;
1618 else if (*(int *) arg >= global_sub_size)
1619 *(int *) arg = global_sub_size - 1;
1620 mpctx->global_sub_pos = *(int *) arg;
1621 break;
1622 case M_PROPERTY_STEP_UP:
1623 mpctx->global_sub_pos += 2;
1624 mpctx->global_sub_pos =
1625 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1626 break;
1627 case M_PROPERTY_STEP_DOWN:
1628 mpctx->global_sub_pos += global_sub_size + 1;
1629 mpctx->global_sub_pos =
1630 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1631 break;
1632 default:
1633 return M_PROPERTY_NOT_IMPLEMENTED;
1636 if (mpctx->global_sub_pos >= 0) {
1637 source = sub_source(mpctx);
1638 source_pos = sub_source_pos(mpctx);
1641 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1642 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1643 global_sub_size,
1644 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1645 mpctx->sub_counts[SUB_SOURCE_SUBS],
1646 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1647 mpctx->global_sub_pos, source);
1649 mpctx->set_of_sub_pos = -1;
1650 mpctx->subdata = NULL;
1652 vobsub_id = -1;
1653 opts->sub_id = -1;
1654 if (d_sub) {
1655 if (d_sub->id > -2)
1656 reset_spu = 1;
1657 d_sub->id = -2;
1659 mpctx->osd->ass_track = NULL;
1660 uninit_player(mpctx, INITIALIZED_SUB);
1662 if (source == SUB_SOURCE_VOBSUB) {
1663 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1664 } else if (source == SUB_SOURCE_SUBS) {
1665 mpctx->set_of_sub_pos = source_pos;
1666 #ifdef CONFIG_ASS
1667 if (opts->ass_enabled
1668 && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]) {
1669 mpctx->osd->ass_track =
1670 mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1671 mpctx->osd->ass_track_changed = true;
1672 mpctx->osd->vsfilter_aspect =
1673 mpctx->track_was_native_ass[mpctx->set_of_sub_pos];
1674 } else
1675 #endif
1677 mpctx->subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1678 vo_osd_changed(OSDTYPE_SUBTITLE);
1680 } else if (source == SUB_SOURCE_DEMUX) {
1681 opts->sub_id = source_pos;
1682 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1683 int i = 0;
1684 // default: assume 1:1 mapping of sid and stream id
1685 d_sub->id = opts->sub_id;
1686 d_sub->sh = mpctx->d_sub->demuxer->s_streams[d_sub->id];
1687 ds_free_packs(d_sub);
1688 for (i = 0; i < MAX_S_STREAMS; i++) {
1689 sh_sub_t *sh = mpctx->d_sub->demuxer->s_streams[i];
1690 if (sh && sh->sid == opts->sub_id) {
1691 d_sub->id = i;
1692 d_sub->sh = sh;
1693 break;
1696 if (d_sub->sh && d_sub->id >= 0) {
1697 sh_sub_t *sh = d_sub->sh;
1698 if (sh->type == 'v')
1699 init_vo_spudec(mpctx);
1700 else {
1701 sub_init(sh, mpctx->osd);
1702 mpctx->initialized_flags |= INITIALIZED_SUB;
1704 } else {
1705 d_sub->id = -2;
1706 d_sub->sh = NULL;
1710 #ifdef CONFIG_DVDREAD
1711 if (vo_spudec
1712 && (mpctx->stream->type == STREAMTYPE_DVD
1713 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1714 && opts->sub_id < 0 && reset_spu) {
1715 d_sub->id = -2;
1716 d_sub->sh = NULL;
1718 #endif
1720 update_subtitles(mpctx, 0, 0, true);
1722 return M_PROPERTY_OK;
1725 /// Selected sub source (RW)
1726 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1727 MPContext *mpctx)
1729 int source;
1730 update_global_sub_size(mpctx);
1731 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1732 return M_PROPERTY_UNAVAILABLE;
1734 switch (action) {
1735 case M_PROPERTY_GET:
1736 if (!arg)
1737 return M_PROPERTY_ERROR;
1738 *(int *) arg = sub_source(mpctx);
1739 return M_PROPERTY_OK;
1740 case M_PROPERTY_PRINT:
1741 if (!arg)
1742 return M_PROPERTY_ERROR;
1743 char *sourcename;
1744 switch (sub_source(mpctx)) {
1745 case SUB_SOURCE_SUBS:
1746 sourcename = mp_gtext("file");
1747 break;
1748 case SUB_SOURCE_VOBSUB:
1749 sourcename = mp_gtext("vobsub");
1750 break;
1751 case SUB_SOURCE_DEMUX:
1752 sourcename = mp_gtext("embedded");
1753 break;
1754 default:
1755 sourcename = mp_gtext("disabled");
1757 *(char **)arg = talloc_strdup(NULL, sourcename);
1758 return M_PROPERTY_OK;
1759 case M_PROPERTY_SET:
1760 if (!arg)
1761 return M_PROPERTY_ERROR;
1762 M_PROPERTY_CLAMP(prop, *(int*)arg);
1763 if (*(int *) arg < 0)
1764 mpctx->global_sub_pos = -1;
1765 else if (*(int *) arg != sub_source(mpctx)) {
1766 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1767 if (new_pos == -1)
1768 return M_PROPERTY_UNAVAILABLE;
1769 mpctx->global_sub_pos = new_pos;
1771 break;
1772 case M_PROPERTY_STEP_UP:
1773 case M_PROPERTY_STEP_DOWN: {
1774 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1775 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1776 int step = (step_all > 0) ? 1 : -1;
1777 int cur_source = sub_source(mpctx);
1778 source = cur_source;
1779 while (step_all) {
1780 source += step;
1781 if (source >= SUB_SOURCES)
1782 source = -1;
1783 else if (source < -1)
1784 source = SUB_SOURCES - 1;
1785 if (source == cur_source || source == -1 ||
1786 mpctx->sub_counts[source])
1787 step_all -= step;
1789 if (source == cur_source)
1790 return M_PROPERTY_OK;
1791 if (source == -1)
1792 mpctx->global_sub_pos = -1;
1793 else
1794 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1795 break;
1797 default:
1798 return M_PROPERTY_NOT_IMPLEMENTED;
1800 --mpctx->global_sub_pos;
1801 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1804 /// Selected subtitles from specific source (RW)
1805 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1806 MPContext *mpctx)
1808 int source, is_cur_source, offset, new_pos;
1809 update_global_sub_size(mpctx);
1810 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1811 return M_PROPERTY_UNAVAILABLE;
1813 if (!strcmp(prop->name, "sub_file"))
1814 source = SUB_SOURCE_SUBS;
1815 else if (!strcmp(prop->name, "sub_vob"))
1816 source = SUB_SOURCE_VOBSUB;
1817 else if (!strcmp(prop->name, "sub_demux"))
1818 source = SUB_SOURCE_DEMUX;
1819 else
1820 return M_PROPERTY_ERROR;
1822 offset = sub_pos_by_source(mpctx, source);
1823 if (offset < 0)
1824 return M_PROPERTY_UNAVAILABLE;
1826 is_cur_source = sub_source(mpctx) == source;
1827 new_pos = mpctx->global_sub_pos;
1828 switch (action) {
1829 case M_PROPERTY_GET:
1830 if (!arg)
1831 return M_PROPERTY_ERROR;
1832 if (is_cur_source) {
1833 *(int *) arg = sub_source_pos(mpctx);
1834 if (source == SUB_SOURCE_VOBSUB)
1835 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1837 else
1838 *(int *) arg = -1;
1839 return M_PROPERTY_OK;
1840 case M_PROPERTY_PRINT:
1841 if (!arg)
1842 return M_PROPERTY_ERROR;
1843 if (is_cur_source)
1844 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1845 *(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
1846 return M_PROPERTY_OK;
1847 case M_PROPERTY_SET:
1848 if (!arg)
1849 return M_PROPERTY_ERROR;
1850 if (*(int *) arg >= 0) {
1851 int index = *(int *)arg;
1852 if (source == SUB_SOURCE_VOBSUB)
1853 index = vobsub_get_index_by_id(vo_vobsub, index);
1854 new_pos = offset + index;
1855 if (index < 0 || index > mpctx->sub_counts[source]) {
1856 new_pos = -1;
1857 *(int *) arg = -1;
1860 else
1861 new_pos = -1;
1862 break;
1863 case M_PROPERTY_STEP_UP:
1864 case M_PROPERTY_STEP_DOWN: {
1865 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1866 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1867 int step = (step_all > 0) ? 1 : -1;
1868 int max_sub_pos_for_source = -1;
1869 if (!is_cur_source)
1870 new_pos = -1;
1871 while (step_all) {
1872 if (new_pos == -1) {
1873 if (step > 0)
1874 new_pos = offset;
1875 else if (max_sub_pos_for_source == -1) {
1876 // Find max pos for specific source
1877 new_pos = mpctx->global_sub_size - 1;
1878 while (new_pos >= 0
1879 && sub_source(mpctx) != source)
1880 new_pos--;
1882 else
1883 new_pos = max_sub_pos_for_source;
1885 else {
1886 new_pos += step;
1887 if (new_pos < offset ||
1888 new_pos >= mpctx->global_sub_size ||
1889 sub_source(mpctx) != source)
1890 new_pos = -1;
1892 step_all -= step;
1894 break;
1896 default:
1897 return M_PROPERTY_NOT_IMPLEMENTED;
1899 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1902 /// Subtitle delay (RW)
1903 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1904 MPContext *mpctx)
1906 if (!mpctx->sh_video)
1907 return M_PROPERTY_UNAVAILABLE;
1908 return m_property_delay(prop, action, arg, &sub_delay);
1911 /// Alignment of text subtitles (RW)
1912 static int mp_property_sub_alignment(m_option_t *prop, int action,
1913 void *arg, MPContext *mpctx)
1915 char *name[] = { _("top"), _("center"), _("bottom") };
1917 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1918 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1919 return M_PROPERTY_UNAVAILABLE;
1921 switch (action) {
1922 case M_PROPERTY_PRINT:
1923 if (!arg)
1924 return M_PROPERTY_ERROR;
1925 M_PROPERTY_CLAMP(prop, sub_alignment);
1926 *(char **) arg = talloc_strdup(NULL, mp_gtext(name[sub_alignment]));
1927 return M_PROPERTY_OK;
1928 case M_PROPERTY_SET:
1929 if (!arg)
1930 return M_PROPERTY_ERROR;
1931 case M_PROPERTY_STEP_UP:
1932 case M_PROPERTY_STEP_DOWN:
1933 vo_osd_changed(OSDTYPE_SUBTITLE);
1934 default:
1935 return m_property_choice(prop, action, arg, &sub_alignment);
1939 /// Subtitle visibility (RW)
1940 static int mp_property_sub_visibility(m_option_t *prop, int action,
1941 void *arg, MPContext *mpctx)
1943 if (!mpctx->sh_video)
1944 return M_PROPERTY_UNAVAILABLE;
1946 switch (action) {
1947 case M_PROPERTY_SET:
1948 if (!arg)
1949 return M_PROPERTY_ERROR;
1950 case M_PROPERTY_STEP_UP:
1951 case M_PROPERTY_STEP_DOWN:
1952 vo_osd_changed(OSDTYPE_SUBTITLE);
1953 if (vo_spudec)
1954 vo_osd_changed(OSDTYPE_SPU);
1955 default:
1956 return m_property_flag(prop, action, arg, &sub_visibility);
1960 #ifdef CONFIG_ASS
1961 /// Use margins for libass subtitles (RW)
1962 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1963 void *arg, MPContext *mpctx)
1965 if (!mpctx->sh_video)
1966 return M_PROPERTY_UNAVAILABLE;
1968 switch (action) {
1969 case M_PROPERTY_SET:
1970 if (!arg)
1971 return M_PROPERTY_ERROR;
1972 case M_PROPERTY_STEP_UP:
1973 case M_PROPERTY_STEP_DOWN:
1974 ass_force_reload = 1;
1975 default:
1976 return m_property_flag(prop, action, arg, &ass_use_margins);
1979 #endif
1981 /// Show only forced subtitles (RW)
1982 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1983 void *arg, MPContext *mpctx)
1985 if (!vo_spudec)
1986 return M_PROPERTY_UNAVAILABLE;
1988 switch (action) {
1989 case M_PROPERTY_SET:
1990 if (!arg)
1991 return M_PROPERTY_ERROR;
1992 case M_PROPERTY_STEP_UP:
1993 case M_PROPERTY_STEP_DOWN:
1994 m_property_flag(prop, action, arg, &forced_subs_only);
1995 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1996 return M_PROPERTY_OK;
1997 default:
1998 return m_property_flag(prop, action, arg, &forced_subs_only);
2003 #ifdef CONFIG_FREETYPE
2004 /// Subtitle scale (RW)
2005 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
2006 MPContext *mpctx)
2008 struct MPOpts *opts = &mpctx->opts;
2010 switch (action) {
2011 case M_PROPERTY_SET:
2012 if (!arg)
2013 return M_PROPERTY_ERROR;
2014 M_PROPERTY_CLAMP(prop, *(float *) arg);
2015 #ifdef CONFIG_ASS
2016 if (opts->ass_enabled) {
2017 ass_font_scale = *(float *) arg;
2018 ass_force_reload = 1;
2020 #endif
2021 text_font_scale_factor = *(float *) arg;
2022 force_load_font = 1;
2023 return M_PROPERTY_OK;
2024 case M_PROPERTY_STEP_UP:
2025 case M_PROPERTY_STEP_DOWN:
2026 #ifdef CONFIG_ASS
2027 if (opts->ass_enabled) {
2028 ass_font_scale += (arg ? *(float *) arg : 0.1)*
2029 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2030 M_PROPERTY_CLAMP(prop, ass_font_scale);
2031 ass_force_reload = 1;
2033 #endif
2034 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
2035 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2036 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
2037 force_load_font = 1;
2038 return M_PROPERTY_OK;
2039 default:
2040 #ifdef CONFIG_ASS
2041 if (opts->ass_enabled)
2042 return m_property_float_ro(prop, action, arg, ass_font_scale);
2043 else
2044 #endif
2045 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
2048 #endif
2050 ///@}
2052 /// \defgroup TVProperties TV properties
2053 /// \ingroup Properties
2054 ///@{
2056 #ifdef CONFIG_TV
2058 /// TV color settings (RW)
2059 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2060 MPContext *mpctx)
2062 int r, val;
2063 tvi_handle_t *tvh = mpctx->demuxer->priv;
2064 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2065 return M_PROPERTY_UNAVAILABLE;
2067 switch (action) {
2068 case M_PROPERTY_SET:
2069 if (!arg)
2070 return M_PROPERTY_ERROR;
2071 M_PROPERTY_CLAMP(prop, *(int *) arg);
2072 return tv_set_color_options(tvh, prop->offset, *(int *) arg);
2073 case M_PROPERTY_GET:
2074 return tv_get_color_options(tvh, prop->offset, arg);
2075 case M_PROPERTY_STEP_UP:
2076 case M_PROPERTY_STEP_DOWN:
2077 if ((r = tv_get_color_options(tvh, prop->offset, &val)) >= 0) {
2078 if (!r)
2079 return M_PROPERTY_ERROR;
2080 val += (arg ? *(int *) arg : 1) *
2081 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2082 M_PROPERTY_CLAMP(prop, val);
2083 return tv_set_color_options(tvh, prop->offset, val);
2085 return M_PROPERTY_ERROR;
2087 return M_PROPERTY_NOT_IMPLEMENTED;
2090 #endif
2092 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2093 MPContext *mpctx)
2095 int val,result;
2096 int base_ioctl = prop->offset;
2098 for teletext's GET,SET,STEP ioctls this is not 0
2099 SET is GET+1
2100 STEP is GET+2
2102 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2103 return M_PROPERTY_UNAVAILABLE;
2104 if(!base_ioctl)
2105 return M_PROPERTY_ERROR;
2107 switch (action) {
2108 case M_PROPERTY_GET:
2109 if (!arg)
2110 return M_PROPERTY_ERROR;
2111 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2112 break;
2113 case M_PROPERTY_SET:
2114 if (!arg)
2115 return M_PROPERTY_ERROR;
2116 M_PROPERTY_CLAMP(prop, *(int *) arg);
2117 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
2118 break;
2119 case M_PROPERTY_STEP_UP:
2120 case M_PROPERTY_STEP_DOWN:
2121 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2122 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2123 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
2124 break;
2125 default:
2126 return M_PROPERTY_NOT_IMPLEMENTED;
2129 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2132 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2133 MPContext *mpctx)
2135 int result;
2136 int val;
2138 //with tvh==NULL will fail too
2139 result=mp_property_teletext_common(prop,action,arg,mpctx);
2140 if(result!=M_PROPERTY_OK)
2141 return result;
2143 if(teletext_control(mpctx->demuxer->teletext,
2144 prop->offset, &val)==VBI_CONTROL_TRUE && val)
2145 mp_input_set_section(mpctx->input, "teletext");
2146 else
2147 mp_input_set_section(mpctx->input, "tv");
2148 return M_PROPERTY_OK;
2151 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2152 MPContext *mpctx)
2154 int result;
2155 int val;
2156 if (!mpctx->demuxer->teletext)
2157 return M_PROPERTY_UNAVAILABLE;
2158 switch(action){
2159 case M_PROPERTY_STEP_UP:
2160 case M_PROPERTY_STEP_DOWN:
2161 //This should be handled separately
2162 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2163 result=teletext_control(mpctx->demuxer->teletext,
2164 TV_VBI_CONTROL_STEP_PAGE, &val);
2165 break;
2166 default:
2167 result=mp_property_teletext_common(prop,action,arg,mpctx);
2169 return result;
2172 ///@}
2174 /// All properties available in MPlayer.
2175 /** \ingroup Properties
2177 static const m_option_t mp_properties[] = {
2178 // General
2179 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2180 M_OPT_RANGE, 0, 3, NULL },
2181 { "loop", mp_property_loop, CONF_TYPE_INT,
2182 M_OPT_MIN, -1, 0, NULL },
2183 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2184 M_OPT_RANGE, 0.01, 100.0, NULL },
2185 { "filename", mp_property_filename, CONF_TYPE_STRING,
2186 0, 0, 0, NULL },
2187 { "path", mp_property_path, CONF_TYPE_STRING,
2188 0, 0, 0, NULL },
2189 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2190 0, 0, 0, NULL },
2191 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2192 M_OPT_MIN, 0, 0, NULL },
2193 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2194 M_OPT_MIN, 0, 0, NULL },
2195 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2196 M_OPT_MIN, 0, 0, NULL },
2197 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2198 M_OPT_MIN, 0, 0, NULL },
2199 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2200 M_OPT_MIN, 0, 0, NULL },
2201 { "length", mp_property_length, CONF_TYPE_TIME,
2202 M_OPT_MIN, 0, 0, NULL },
2203 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2204 M_OPT_RANGE, 0, 100, NULL },
2205 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2206 M_OPT_MIN, 0, 0, NULL },
2207 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2208 M_OPT_MIN, 0, 0, NULL },
2209 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2210 0, 0, 0, NULL },
2211 { "angle", mp_property_angle, CONF_TYPE_INT,
2212 CONF_RANGE, -2, 10, NULL },
2213 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2214 0, 0, 0, NULL },
2215 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2216 M_OPT_RANGE, 0, 1, NULL },
2217 { "capturing", mp_property_capture, CONF_TYPE_FLAG,
2218 M_OPT_RANGE, 0, 1, NULL },
2219 { "pts_association_mode", mp_property_generic_option, &m_option_type_choice,
2220 0, 0, 0, "pts-association-mode" },
2221 { "hr_seek", mp_property_generic_option, &m_option_type_choice,
2222 0, 0, 0, "hr-seek" },
2224 // Audio
2225 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2226 M_OPT_RANGE, 0, 100, NULL },
2227 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2228 M_OPT_RANGE, 0, 1, NULL },
2229 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2230 M_OPT_RANGE, -100, 100, NULL },
2231 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2232 0, 0, 0, NULL },
2233 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2234 0, 0, 0, NULL },
2235 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2236 0, 0, 0, NULL },
2237 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2238 0, 0, 0, NULL },
2239 { "channels", mp_property_channels, CONF_TYPE_INT,
2240 0, 0, 0, NULL },
2241 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2242 CONF_RANGE, -2, 65535, NULL },
2243 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2244 M_OPT_RANGE, -1, 1, NULL },
2246 // Video
2247 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2248 M_OPT_RANGE, 0, 1, NULL },
2249 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2250 M_OPT_RANGE, 0, 1, NULL },
2251 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2252 M_OPT_RANGE, 0, 2, NULL },
2253 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2254 M_OPT_RANGE, 0, 1, NULL },
2255 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2256 M_OPT_RANGE, 0, 1, NULL },
2257 { "border", mp_property_border, CONF_TYPE_FLAG,
2258 M_OPT_RANGE, 0, 1, NULL },
2259 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2260 M_OPT_RANGE, 0, 2, NULL },
2261 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2262 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_gamma)},
2263 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2264 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_brightness) },
2265 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2266 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_contrast) },
2267 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2268 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_saturation) },
2269 { "hue", mp_property_gamma, CONF_TYPE_INT,
2270 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_hue) },
2271 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2272 M_OPT_RANGE, 0, 1, NULL },
2273 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2274 M_OPT_RANGE, 0, 1, NULL },
2275 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2276 0, 0, 0, NULL },
2277 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2278 0, 0, 0, NULL },
2279 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2280 0, 0, 0, NULL },
2281 { "width", mp_property_width, CONF_TYPE_INT,
2282 0, 0, 0, NULL },
2283 { "height", mp_property_height, CONF_TYPE_INT,
2284 0, 0, 0, NULL },
2285 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2286 0, 0, 0, NULL },
2287 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2288 0, 0, 0, NULL },
2289 { "switch_video", mp_property_video, CONF_TYPE_INT,
2290 CONF_RANGE, -2, 65535, NULL },
2291 { "switch_program", mp_property_program, CONF_TYPE_INT,
2292 CONF_RANGE, -1, 65535, NULL },
2294 // Subs
2295 { "sub", mp_property_sub, CONF_TYPE_INT,
2296 M_OPT_MIN, -1, 0, NULL },
2297 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2298 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2299 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2300 M_OPT_MIN, -1, 0, NULL },
2301 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2302 M_OPT_MIN, -1, 0, NULL },
2303 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2304 M_OPT_MIN, -1, 0, NULL },
2305 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2306 0, 0, 0, NULL },
2307 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2308 M_OPT_RANGE, 0, 100, NULL },
2309 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2310 M_OPT_RANGE, 0, 2, NULL },
2311 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2312 M_OPT_RANGE, 0, 1, NULL },
2313 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2314 M_OPT_RANGE, 0, 1, NULL },
2315 #ifdef CONFIG_FREETYPE
2316 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2317 M_OPT_RANGE, 0, 100, NULL },
2318 #endif
2319 #ifdef CONFIG_ASS
2320 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2321 M_OPT_RANGE, 0, 1, NULL },
2322 #endif
2324 #ifdef CONFIG_TV
2325 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2326 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_BRIGHTNESS },
2327 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2328 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_CONTRAST },
2329 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2330 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_SATURATION },
2331 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2332 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_HUE },
2333 #endif
2334 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2335 M_OPT_RANGE, 100, 899, .offset=TV_VBI_CONTROL_GET_PAGE },
2336 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2337 M_OPT_RANGE, 0, 64, .offset=TV_VBI_CONTROL_GET_SUBPAGE },
2338 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2339 M_OPT_RANGE, 0, 1, .offset=TV_VBI_CONTROL_GET_MODE },
2340 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2341 M_OPT_RANGE, 0, 3, .offset=TV_VBI_CONTROL_GET_FORMAT },
2342 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2343 M_OPT_RANGE, 0, 2, .offset=TV_VBI_CONTROL_GET_HALF_PAGE },
2344 { NULL, NULL, NULL, 0, 0, 0, NULL }
2348 int mp_property_do(const char *name, int action, void *val, void *ctx)
2350 return m_property_do(mp_properties, name, action, val, ctx);
2353 char* mp_property_print(const char *name, void* ctx)
2355 char* ret = NULL;
2356 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2357 return NULL;
2358 return ret;
2361 char *property_expand_string(MPContext *mpctx, char *str)
2363 return m_properties_expand_string(mp_properties, str, mpctx);
2366 void property_print_help(void)
2368 m_properties_print_help_list(mp_properties);
2372 /* List of default ways to show a property on OSD.
2374 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2375 * a bar showing the current position between min/max values of the
2376 * property. In this case osd_msg is only used for terminal output
2377 * if there is no video; it'll be a label shown together with percentage.
2379 * Otherwise setting osd_msg will show the string on OSD, formatted with
2380 * the text value of the property as argument.
2382 static struct property_osd_display {
2383 /// property name
2384 const char *name;
2385 /// progressbar type
2386 int osd_progbar; // -1 is special value for seek indicators
2387 /// osd msg id if it must be shared
2388 int osd_id;
2389 /// osd msg template
2390 const char *osd_msg;
2391 } property_osd_display[] = {
2392 // general
2393 { "loop", 0, -1, _("Loop: %s") },
2394 { "chapter", -1, -1, NULL },
2395 { "capturing", 0, -1, _("Capturing: %s") },
2396 { "pts_association_mode", 0, -1, "PTS association mode: %s" },
2397 { "hr_seek", 0, -1, "hr-seek: %s" },
2398 { "speed", 0, -1, _("Speed: x %6s") },
2399 // audio
2400 { "volume", OSD_VOLUME, -1, _("Volume") },
2401 { "mute", 0, -1, _("Mute: %s") },
2402 { "audio_delay", 0, -1, _("A-V delay: %s") },
2403 { "switch_audio", 0, -1, _("Audio: %s") },
2404 { "balance", OSD_BALANCE, -1, _("Balance") },
2405 // video
2406 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2407 { "ontop", 0, -1, _("Stay on top: %s") },
2408 { "rootwin", 0, -1, _("Rootwin: %s") },
2409 { "border", 0, -1, _("Border: %s") },
2410 { "framedropping", 0, -1, _("Framedropping: %s") },
2411 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2412 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2413 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2414 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2415 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2416 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2417 { "hue", OSD_HUE, -1, _("Hue") },
2418 { "vsync", 0, -1, _("VSync: %s") },
2419 // subs
2420 { "sub", 0, -1, _("Subtitles: %s") },
2421 { "sub_source", 0, -1, _("Sub source: %s") },
2422 { "sub_vob", 0, -1, _("Subtitles: %s") },
2423 { "sub_demux", 0, -1, _("Subtitles: %s") },
2424 { "sub_file", 0, -1, _("Subtitles: %s") },
2425 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2426 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2427 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2428 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2429 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2430 #ifdef CONFIG_FREETYPE
2431 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2432 #endif
2433 #ifdef CONFIG_TV
2434 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2435 { "tv_hue", OSD_HUE, -1, _("Hue") },
2436 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2437 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2438 #endif
2442 static int show_property_osd(MPContext *mpctx, const char *pname)
2444 struct MPOpts *opts = &mpctx->opts;
2445 int r;
2446 m_option_t* prop;
2447 struct property_osd_display *p;
2449 // look for the command
2450 for (p = property_osd_display; p->name; p++)
2451 if (!strcmp(p->name, pname))
2452 break;
2453 if (!p->name)
2454 return -1;
2456 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2457 return -1;
2459 if (p->osd_progbar == -1)
2460 mpctx->add_osd_seek_info = true;
2461 else if (p->osd_progbar) {
2462 if (prop->type == CONF_TYPE_INT) {
2463 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2464 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2465 prop->min, prop->max, r);
2466 } else if (prop->type == CONF_TYPE_FLOAT) {
2467 float f;
2468 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2469 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2470 prop->min, prop->max, f);
2471 } else {
2472 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2473 "Property use an unsupported type.\n");
2474 return -1;
2476 return 0;
2479 if (p->osd_msg) {
2480 char *val = mp_property_print(pname, mpctx);
2481 if (val) {
2482 int index = p - property_osd_display;
2483 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2484 1, opts->osd_duration, p->osd_msg, val);
2485 talloc_free(val);
2488 return 0;
2493 * \defgroup Command2Property Command to property bridge
2495 * It is used to handle most commands that just set a property
2496 * and optionally display something on the OSD.
2497 * Two kinds of commands are handled: adjust or toggle.
2499 * Adjust commands take 1 or 2 parameters: <value> <abs>
2500 * If <abs> is non-zero the property is set to the given value
2501 * otherwise it is adjusted.
2503 * Toggle commands take 0 or 1 parameters. With no parameter
2504 * or a value less than the property minimum it just steps the
2505 * property to its next or previous value respectively.
2506 * Otherwise it sets it to the given value.
2511 /// List of the commands that can be handled by setting a property.
2512 static struct {
2513 /// property name
2514 const char *name;
2515 /// cmd id
2516 int cmd;
2517 /// set/adjust or toggle command
2518 int toggle;
2519 } set_prop_cmd[] = {
2520 // general
2521 { "loop", MP_CMD_LOOP, 0},
2522 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2523 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2524 { "pause", MP_CMD_PAUSE, 0},
2525 { "capturing", MP_CMD_CAPTURING, 1},
2526 // audio
2527 { "volume", MP_CMD_VOLUME, 0},
2528 { "mute", MP_CMD_MUTE, 1},
2529 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2530 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2531 { "balance", MP_CMD_BALANCE, 0},
2532 // video
2533 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2534 { "panscan", MP_CMD_PANSCAN, 0},
2535 { "ontop", MP_CMD_VO_ONTOP, 1},
2536 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2537 { "border", MP_CMD_VO_BORDER, 1},
2538 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2539 { "gamma", MP_CMD_GAMMA, 0},
2540 { "brightness", MP_CMD_BRIGHTNESS, 0},
2541 { "contrast", MP_CMD_CONTRAST, 0},
2542 { "saturation", MP_CMD_SATURATION, 0},
2543 { "hue", MP_CMD_HUE, 0},
2544 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2545 // subs
2546 { "sub", MP_CMD_SUB_SELECT, 1},
2547 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2548 { "sub_vob", MP_CMD_SUB_VOB, 1},
2549 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2550 { "sub_file", MP_CMD_SUB_FILE, 1},
2551 { "sub_pos", MP_CMD_SUB_POS, 0},
2552 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2553 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2554 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2555 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2556 #ifdef CONFIG_FREETYPE
2557 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2558 #endif
2559 #ifdef CONFIG_ASS
2560 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2561 #endif
2562 #ifdef CONFIG_TV
2563 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2564 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2565 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2566 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2567 #endif
2571 /// Handle commands that set a property.
2572 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2574 int i, r;
2575 m_option_t *prop;
2576 const char *pname;
2578 // look for the command
2579 for (i = 0; set_prop_cmd[i].name; i++)
2580 if (set_prop_cmd[i].cmd == cmd->id)
2581 break;
2582 if (!(pname = set_prop_cmd[i].name))
2583 return 0;
2585 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2586 return 0;
2588 // toggle command
2589 if (set_prop_cmd[i].toggle) {
2590 // set to value
2591 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2592 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2593 else if (cmd->nargs > 0)
2594 r = mp_property_do(pname, M_PROPERTY_STEP_DOWN, NULL, mpctx);
2595 else
2596 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2597 } else if (cmd->args[1].v.i) //set
2598 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2599 else // adjust
2600 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2602 if (r <= 0)
2603 return 1;
2605 show_property_osd(mpctx, pname);
2607 return 1;
2610 #ifdef CONFIG_DVDNAV
2611 static const struct {
2612 const char *name;
2613 const mp_command_type cmd;
2614 } mp_dvdnav_bindings[] = {
2615 { "up", MP_CMD_DVDNAV_UP },
2616 { "down", MP_CMD_DVDNAV_DOWN },
2617 { "left", MP_CMD_DVDNAV_LEFT },
2618 { "right", MP_CMD_DVDNAV_RIGHT },
2619 { "menu", MP_CMD_DVDNAV_MENU },
2620 { "select", MP_CMD_DVDNAV_SELECT },
2621 { "prev", MP_CMD_DVDNAV_PREVMENU },
2622 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2625 * keep old dvdnav sub-command options for a while in order not to
2626 * break slave-mode API too suddenly.
2628 { "1", MP_CMD_DVDNAV_UP },
2629 { "2", MP_CMD_DVDNAV_DOWN },
2630 { "3", MP_CMD_DVDNAV_LEFT },
2631 { "4", MP_CMD_DVDNAV_RIGHT },
2632 { "5", MP_CMD_DVDNAV_MENU },
2633 { "6", MP_CMD_DVDNAV_SELECT },
2634 { "7", MP_CMD_DVDNAV_PREVMENU },
2635 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2636 { NULL, 0 }
2638 #endif
2640 static const char *property_error_string(int error_value)
2642 switch (error_value) {
2643 case M_PROPERTY_ERROR:
2644 return "ERROR";
2645 case M_PROPERTY_UNAVAILABLE:
2646 return "PROPERTY_UNAVAILABLE";
2647 case M_PROPERTY_NOT_IMPLEMENTED:
2648 return "NOT_IMPLEMENTED";
2649 case M_PROPERTY_UNKNOWN:
2650 return "PROPERTY_UNKNOWN";
2651 case M_PROPERTY_DISABLED:
2652 return "DISABLED";
2654 return "UNKNOWN";
2657 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2659 int idx;
2660 int end = start + count;
2661 int after = mpctx->set_of_sub_size - end;
2662 sub_data **subs = mpctx->set_of_subtitles;
2663 #ifdef CONFIG_ASS
2664 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2665 #endif
2666 if (count < 0 || count > mpctx->set_of_sub_size ||
2667 start < 0 || start > mpctx->set_of_sub_size - count) {
2668 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2669 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2670 return;
2672 for (idx = start; idx < end; idx++) {
2673 sub_data *subd = subs[idx];
2674 char *filename = "";
2675 if (subd)
2676 filename = subd->filename;
2677 #ifdef CONFIG_ASS
2678 if (!subd)
2679 filename = ass_tracks[idx]->name;
2680 #endif
2681 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2682 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2683 filename_recode(filename));
2684 sub_free(subd);
2685 subs[idx] = NULL;
2686 #ifdef CONFIG_ASS
2687 if (ass_tracks[idx])
2688 ass_free_track(ass_tracks[idx]);
2689 ass_tracks[idx] = NULL;
2690 #endif
2693 mpctx->global_sub_size -= count;
2694 mpctx->set_of_sub_size -= count;
2695 if (mpctx->set_of_sub_size <= 0)
2696 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2698 memmove(subs + start, subs + end, after * sizeof(*subs));
2699 memset(subs + start + after, 0, count * sizeof(*subs));
2700 #ifdef CONFIG_ASS
2701 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2702 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2703 #endif
2705 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2706 mpctx->global_sub_pos = -2;
2707 mpctx->subdata = NULL;
2708 mpctx->osd->ass_track = NULL;
2709 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2710 } else if (mpctx->set_of_sub_pos >= end) {
2711 mpctx->set_of_sub_pos -= count;
2712 mpctx->global_sub_pos -= count;
2716 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2718 struct MPOpts *opts = &mpctx->opts;
2719 sh_audio_t * const sh_audio = mpctx->sh_audio;
2720 sh_video_t * const sh_video = mpctx->sh_video;
2721 int osd_duration = opts->osd_duration;
2722 int case_fallthrough_hack = 0;
2723 if (!set_property_command(mpctx, cmd))
2724 switch (cmd->id) {
2725 case MP_CMD_SEEK:{
2726 mpctx->add_osd_seek_info = true;
2727 float v = cmd->args[0].v.f;
2728 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2729 int exact = (cmd->nargs > 2) ? cmd->args[2].v.i : 0;
2730 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2731 queue_seek(mpctx, MPSEEK_ABSOLUTE, v, exact);
2732 mpctx->osd_function = v > get_current_time(mpctx) ?
2733 OSD_FFW : OSD_REW;
2734 } else if (abs) { /* Absolute seek by percentage */
2735 queue_seek(mpctx, MPSEEK_FACTOR, v / 100.0, exact);
2736 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2737 } else {
2738 queue_seek(mpctx, MPSEEK_RELATIVE, v, exact);
2739 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2742 break;
2744 case MP_CMD_SET_PROPERTY_OSD:
2745 case_fallthrough_hack = 1;
2747 case MP_CMD_SET_PROPERTY:{
2748 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2749 cmd->args[1].v.s, mpctx);
2750 if (r == M_PROPERTY_UNKNOWN)
2751 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2752 "Unknown property: '%s'\n", cmd->args[0].v.s);
2753 else if (r <= 0)
2754 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2755 "Failed to set property '%s' to '%s'.\n",
2756 cmd->args[0].v.s, cmd->args[1].v.s);
2757 else if (case_fallthrough_hack)
2758 show_property_osd(mpctx, cmd->args[0].v.s);
2759 if (r <= 0)
2760 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2762 break;
2764 case MP_CMD_STEP_PROPERTY_OSD:
2765 case_fallthrough_hack = 1;
2767 case MP_CMD_STEP_PROPERTY:{
2768 void* arg = NULL;
2769 int r,i;
2770 double d;
2771 off_t o;
2772 if (cmd->args[1].v.f) {
2773 m_option_t* prop;
2774 if((r = mp_property_do(cmd->args[0].v.s,
2775 M_PROPERTY_GET_TYPE,
2776 &prop, mpctx)) <= 0)
2777 goto step_prop_err;
2778 if(prop->type == CONF_TYPE_INT ||
2779 prop->type == CONF_TYPE_FLAG)
2780 i = cmd->args[1].v.f, arg = &i;
2781 else if(prop->type == CONF_TYPE_FLOAT)
2782 arg = &cmd->args[1].v.f;
2783 else if(prop->type == CONF_TYPE_DOUBLE ||
2784 prop->type == CONF_TYPE_TIME)
2785 d = cmd->args[1].v.f, arg = &d;
2786 else if(prop->type == CONF_TYPE_POSITION)
2787 o = cmd->args[1].v.f, arg = &o;
2788 else
2789 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2790 "Ignoring step size stepping property '%s'.\n",
2791 cmd->args[0].v.s);
2793 r = mp_property_do(cmd->args[0].v.s,
2794 cmd->args[2].v.i < 0 ?
2795 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2796 arg, mpctx);
2797 step_prop_err:
2798 if (r == M_PROPERTY_UNKNOWN)
2799 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2800 "Unknown property: '%s'\n", cmd->args[0].v.s);
2801 else if (r <= 0)
2802 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2803 "Failed to increment property '%s' by %f.\n",
2804 cmd->args[0].v.s, cmd->args[1].v.f);
2805 else if (case_fallthrough_hack)
2806 show_property_osd(mpctx, cmd->args[0].v.s);
2807 if (r <= 0)
2808 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2810 break;
2812 case MP_CMD_GET_PROPERTY:{
2813 char *tmp;
2814 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2815 &tmp, mpctx);
2816 if (r <= 0) {
2817 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2818 "Failed to get value of property '%s'.\n",
2819 cmd->args[0].v.s);
2820 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2821 break;
2823 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2824 cmd->args[0].v.s, tmp);
2825 talloc_free(tmp);
2827 break;
2829 case MP_CMD_EDL_MARK:
2830 if (edl_fd) {
2831 float v = get_current_time(mpctx);
2832 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2833 mpctx->begin_skip = v;
2834 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2835 } else {
2836 if (mpctx->begin_skip > v)
2837 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2838 else {
2839 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2840 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2842 mpctx->begin_skip = MP_NOPTS_VALUE;
2845 break;
2847 case MP_CMD_SWITCH_RATIO:
2848 if (!sh_video)
2849 break;
2850 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2851 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2852 else
2853 opts->movie_aspect = cmd->args[0].v.f;
2854 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2855 break;
2857 case MP_CMD_SPEED_INCR:{
2858 float v = cmd->args[0].v.f;
2859 mp_property_do("speed", M_PROPERTY_STEP_UP, &v, mpctx);
2860 show_property_osd(mpctx, "speed");
2861 break;
2864 case MP_CMD_SPEED_MULT:
2865 case_fallthrough_hack = true;
2867 case MP_CMD_SPEED_SET:{
2868 float v = cmd->args[0].v.f;
2869 if (case_fallthrough_hack)
2870 v *= mpctx->opts.playback_speed;
2871 mp_property_do("speed", M_PROPERTY_SET, &v, mpctx);
2872 show_property_osd(mpctx, "speed");
2873 break;
2876 case MP_CMD_FRAME_STEP:
2877 add_step_frame(mpctx);
2878 break;
2880 case MP_CMD_FILE_FILTER:
2881 file_filter = cmd->args[0].v.i;
2882 break;
2884 case MP_CMD_QUIT:
2885 exit_player_with_rc(mpctx, EXIT_QUIT,
2886 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2888 case MP_CMD_PLAY_TREE_STEP:{
2889 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2890 int force = cmd->args[1].v.i;
2893 if (!force && mpctx->playtree_iter) {
2894 play_tree_iter_t *i =
2895 play_tree_iter_new_copy(mpctx->playtree_iter);
2896 if (play_tree_iter_step(i, n, 0) ==
2897 PLAY_TREE_ITER_ENTRY)
2898 mpctx->stop_play =
2899 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2900 play_tree_iter_free(i);
2901 } else
2902 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2903 if (mpctx->stop_play)
2904 mpctx->play_tree_step = n;
2907 break;
2909 case MP_CMD_PLAY_TREE_UP_STEP:{
2910 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2911 int force = cmd->args[1].v.i;
2913 if (!force && mpctx->playtree_iter) {
2914 play_tree_iter_t *i =
2915 play_tree_iter_new_copy(mpctx->playtree_iter);
2916 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2917 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2918 play_tree_iter_free(i);
2919 } else
2920 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2922 break;
2924 case MP_CMD_PLAY_ALT_SRC_STEP:
2925 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2926 int v = cmd->args[0].v.i;
2927 if (v > 0
2928 && mpctx->playtree_iter->file <
2929 mpctx->playtree_iter->num_files)
2930 mpctx->stop_play = PT_NEXT_SRC;
2931 else if (v < 0 && mpctx->playtree_iter->file > 1)
2932 mpctx->stop_play = PT_PREV_SRC;
2934 break;
2936 case MP_CMD_SUB_STEP:
2937 if (sh_video) {
2938 int movement = cmd->args[0].v.i;
2939 step_sub(mpctx->subdata, mpctx->video_pts, movement);
2940 #ifdef CONFIG_ASS
2941 if (mpctx->osd->ass_track)
2942 sub_delay +=
2943 ass_step_sub(mpctx->osd->ass_track,
2944 (mpctx->video_pts +
2945 sub_delay) * 1000 + .5, movement) / 1000.;
2946 #endif
2947 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2948 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2950 break;
2952 case MP_CMD_SUB_LOG:
2953 log_sub(mpctx);
2954 break;
2956 case MP_CMD_OSD:{
2957 int v = cmd->args[0].v.i;
2958 int max = (opts->term_osd
2959 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2960 if (opts->osd_level > max)
2961 opts->osd_level = max;
2962 if (v < 0)
2963 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2964 else
2965 opts->osd_level = v > max ? max : v;
2966 /* Show OSD state when disabled, but not when an explicit
2967 argument is given to the OSD command, i.e. in slave mode. */
2968 if (v == -1 && opts->osd_level <= 1)
2969 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2970 "OSD: %s",
2971 opts->osd_level ? mp_gtext("enabled") :
2972 mp_gtext("disabled"));
2973 else
2974 rm_osd_msg(OSD_MSG_OSD_STATUS);
2976 break;
2978 case MP_CMD_OSD_SHOW_TEXT:
2979 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2980 (cmd->args[1].v.i <
2981 0 ? osd_duration : cmd->args[1].v.i),
2982 "%-.63s", cmd->args[0].v.s);
2983 break;
2985 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2986 char *txt = m_properties_expand_string(mp_properties,
2987 cmd->args[0].v.s,
2988 mpctx);
2989 /* if no argument supplied take default osd_duration, else <arg> ms. */
2990 if (txt) {
2991 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2992 (cmd->args[1].v.i <
2993 0 ? osd_duration : cmd->args[1].v.i),
2994 "%-.63s", txt);
2995 free(txt);
2998 break;
3000 case MP_CMD_LOADFILE:{
3001 play_tree_t *e = play_tree_new();
3002 play_tree_add_file(e, cmd->args[0].v.s);
3004 if (cmd->args[1].v.i) // append
3005 play_tree_append_entry(mpctx->playtree->child, e);
3006 else {
3007 // Go back to the starting point.
3008 while (play_tree_iter_up_step
3009 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3010 /* NOP */ ;
3011 play_tree_free_list(mpctx->playtree->child, 1);
3012 play_tree_set_child(mpctx->playtree, e);
3013 pt_iter_goto_head(mpctx->playtree_iter);
3014 mpctx->stop_play = PT_NEXT_SRC;
3017 break;
3019 case MP_CMD_LOADLIST:{
3020 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
3021 if (!e)
3022 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
3023 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
3024 else {
3025 if (cmd->args[1].v.i) // append
3026 play_tree_append_entry(mpctx->playtree->child, e);
3027 else {
3028 // Go back to the starting point.
3029 while (play_tree_iter_up_step
3030 (mpctx->playtree_iter, 0, 1)
3031 != PLAY_TREE_ITER_END)
3032 /* NOP */ ;
3033 play_tree_free_list(mpctx->playtree->child, 1);
3034 play_tree_set_child(mpctx->playtree, e);
3035 pt_iter_goto_head(mpctx->playtree_iter);
3036 mpctx->stop_play = PT_NEXT_SRC;
3040 break;
3042 case MP_CMD_STOP:
3043 // Go back to the starting point.
3044 while (play_tree_iter_up_step
3045 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3046 /* NOP */ ;
3047 mpctx->stop_play = PT_STOP;
3048 break;
3050 case MP_CMD_OSD_SHOW_PROGRESSION:{
3051 int len = get_time_length(mpctx);
3052 int pts = get_current_time(mpctx);
3053 set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3054 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3055 "%c %02d:%02d:%02d / %02d:%02d:%02d",
3056 mpctx->osd_function, pts/3600, (pts/60)%60, pts%60,
3057 len/3600, (len/60)%60, len%60);
3059 break;
3061 #ifdef CONFIG_RADIO
3062 case MP_CMD_RADIO_STEP_CHANNEL:
3063 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3064 int v = cmd->args[0].v.i;
3065 if (v > 0)
3066 radio_step_channel(mpctx->demuxer->stream,
3067 RADIO_CHANNEL_HIGHER);
3068 else
3069 radio_step_channel(mpctx->demuxer->stream,
3070 RADIO_CHANNEL_LOWER);
3071 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3072 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3073 "Channel: %s",
3074 radio_get_channel_name(mpctx->demuxer->stream));
3077 break;
3079 case MP_CMD_RADIO_SET_CHANNEL:
3080 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3081 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3082 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3083 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3084 "Channel: %s",
3085 radio_get_channel_name(mpctx->demuxer->stream));
3088 break;
3090 case MP_CMD_RADIO_SET_FREQ:
3091 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3092 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3093 break;
3095 case MP_CMD_RADIO_STEP_FREQ:
3096 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3097 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3098 break;
3099 #endif
3101 #ifdef CONFIG_TV
3102 case MP_CMD_TV_START_SCAN:
3103 if (mpctx->file_format == DEMUXER_TYPE_TV)
3104 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
3105 break;
3106 case MP_CMD_TV_SET_FREQ:
3107 if (mpctx->file_format == DEMUXER_TYPE_TV)
3108 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3109 cmd->args[0].v.f * 16.0);
3110 #ifdef CONFIG_PVR
3111 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3112 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
3113 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3114 pvr_get_current_channelname (mpctx->stream),
3115 pvr_get_current_stationname (mpctx->stream));
3117 #endif /* CONFIG_PVR */
3118 break;
3120 case MP_CMD_TV_STEP_FREQ:
3121 if (mpctx->file_format == DEMUXER_TYPE_TV)
3122 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3123 cmd->args[0].v.f * 16.0);
3124 #ifdef CONFIG_PVR
3125 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3126 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
3127 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3128 pvr_get_current_channelname (mpctx->stream),
3129 pvr_get_current_frequency (mpctx->stream));
3131 #endif /* CONFIG_PVR */
3132 break;
3134 case MP_CMD_TV_SET_NORM:
3135 if (mpctx->file_format == DEMUXER_TYPE_TV)
3136 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3137 cmd->args[0].v.s);
3138 break;
3140 case MP_CMD_TV_STEP_CHANNEL:{
3141 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3142 int v = cmd->args[0].v.i;
3143 if (v > 0) {
3144 tv_step_channel((tvi_handle_t *) (mpctx->
3145 demuxer->priv),
3146 TV_CHANNEL_HIGHER);
3147 } else {
3148 tv_step_channel((tvi_handle_t *) (mpctx->
3149 demuxer->priv),
3150 TV_CHANNEL_LOWER);
3152 if (tv_channel_list) {
3153 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3154 "Channel: %s", tv_channel_current->name);
3155 //vo_osd_changed(OSDTYPE_SUBTITLE);
3158 #ifdef CONFIG_PVR
3159 else if (mpctx->stream &&
3160 mpctx->stream->type == STREAMTYPE_PVR) {
3161 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3162 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3163 pvr_get_current_channelname (mpctx->stream),
3164 pvr_get_current_stationname (mpctx->stream));
3166 #endif /* CONFIG_PVR */
3168 #ifdef CONFIG_DVBIN
3169 if (mpctx->stream->type == STREAMTYPE_DVB) {
3170 int dir;
3171 int v = cmd->args[0].v.i;
3173 mpctx->last_dvb_step = v;
3174 if (v > 0)
3175 dir = DVB_CHANNEL_HIGHER;
3176 else
3177 dir = DVB_CHANNEL_LOWER;
3180 if (dvb_step_channel(mpctx->stream, dir)) {
3181 mpctx->stop_play = PT_NEXT_ENTRY;
3182 mpctx->dvbin_reopen = 1;
3185 #endif /* CONFIG_DVBIN */
3186 break;
3188 case MP_CMD_TV_SET_CHANNEL:
3189 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3190 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3191 cmd->args[0].v.s);
3192 if (tv_channel_list) {
3193 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3194 "Channel: %s", tv_channel_current->name);
3195 //vo_osd_changed(OSDTYPE_SUBTITLE);
3198 #ifdef CONFIG_PVR
3199 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3200 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3201 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3202 pvr_get_current_channelname (mpctx->stream),
3203 pvr_get_current_stationname (mpctx->stream));
3205 #endif /* CONFIG_PVR */
3206 break;
3208 #ifdef CONFIG_DVBIN
3209 case MP_CMD_DVB_SET_CHANNEL:
3210 if (mpctx->stream->type == STREAMTYPE_DVB) {
3211 mpctx->last_dvb_step = 1;
3213 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3214 cmd->args[0].v.i)) {
3215 mpctx->stop_play = PT_NEXT_ENTRY;
3216 mpctx->dvbin_reopen = 1;
3219 break;
3220 #endif /* CONFIG_DVBIN */
3222 case MP_CMD_TV_LAST_CHANNEL:
3223 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3224 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3225 if (tv_channel_list) {
3226 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3227 "Channel: %s", tv_channel_current->name);
3228 //vo_osd_changed(OSDTYPE_SUBTITLE);
3231 #ifdef CONFIG_PVR
3232 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3233 pvr_set_lastchannel (mpctx->stream);
3234 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3235 pvr_get_current_channelname (mpctx->stream),
3236 pvr_get_current_stationname (mpctx->stream));
3238 #endif /* CONFIG_PVR */
3239 break;
3241 case MP_CMD_TV_STEP_NORM:
3242 if (mpctx->file_format == DEMUXER_TYPE_TV)
3243 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3244 break;
3246 case MP_CMD_TV_STEP_CHANNEL_LIST:
3247 if (mpctx->file_format == DEMUXER_TYPE_TV)
3248 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3249 break;
3250 #endif /* CONFIG_TV */
3251 case MP_CMD_TV_TELETEXT_ADD_DEC:
3252 if (mpctx->demuxer->teletext)
3253 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3254 &(cmd->args[0].v.s));
3255 break;
3256 case MP_CMD_TV_TELETEXT_GO_LINK:
3257 if (mpctx->demuxer->teletext)
3258 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3259 &(cmd->args[0].v.i));
3260 break;
3262 case MP_CMD_SUB_LOAD:
3263 if (sh_video) {
3264 int n = mpctx->set_of_sub_size;
3265 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3266 if (n != mpctx->set_of_sub_size) {
3267 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3268 ++mpctx->global_sub_size;
3271 break;
3273 case MP_CMD_SUB_REMOVE:
3274 if (sh_video) {
3275 int v = cmd->args[0].v.i;
3276 if (v < 0) {
3277 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3278 } else if (v < mpctx->set_of_sub_size) {
3279 remove_subtitle_range(mpctx, v, 1);
3282 break;
3284 case MP_CMD_GET_SUB_VISIBILITY:
3285 if (sh_video) {
3286 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3287 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3289 break;
3291 case MP_CMD_SCREENSHOT:
3292 if (mpctx->video_out && mpctx->video_out->config_ok) {
3293 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3294 if (CONTROL_OK !=
3295 ((vf_instance_t *) sh_video->vfilter)->
3296 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3297 &cmd->args[0].v.i))
3298 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3300 break;
3302 case MP_CMD_VF_CHANGE_RECTANGLE:
3303 if (!sh_video)
3304 break;
3305 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3306 break;
3308 case MP_CMD_GET_TIME_LENGTH:{
3309 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3310 get_time_length(mpctx));
3312 break;
3314 case MP_CMD_GET_FILENAME:{
3315 char *inf = get_metadata(mpctx, META_NAME);
3316 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n", inf);
3317 talloc_free(inf);
3319 break;
3321 case MP_CMD_GET_VIDEO_CODEC:{
3322 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3323 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3324 talloc_free(inf);
3326 break;
3328 case MP_CMD_GET_VIDEO_BITRATE:{
3329 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3330 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3331 talloc_free(inf);
3333 break;
3335 case MP_CMD_GET_VIDEO_RESOLUTION:{
3336 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3337 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3338 talloc_free(inf);
3340 break;
3342 case MP_CMD_GET_AUDIO_CODEC:{
3343 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3344 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3345 talloc_free(inf);
3347 break;
3349 case MP_CMD_GET_AUDIO_BITRATE:{
3350 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3351 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3352 talloc_free(inf);
3354 break;
3356 case MP_CMD_GET_AUDIO_SAMPLES:{
3357 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3358 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3359 talloc_free(inf);
3361 break;
3363 case MP_CMD_GET_META_TITLE:{
3364 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3365 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3366 talloc_free(inf);
3368 break;
3370 case MP_CMD_GET_META_ARTIST:{
3371 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3372 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3373 talloc_free(inf);
3375 break;
3377 case MP_CMD_GET_META_ALBUM:{
3378 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3379 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3380 talloc_free(inf);
3382 break;
3384 case MP_CMD_GET_META_YEAR:{
3385 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3386 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3387 talloc_free(inf);
3389 break;
3391 case MP_CMD_GET_META_COMMENT:{
3392 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3393 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3394 talloc_free(inf);
3396 break;
3398 case MP_CMD_GET_META_TRACK:{
3399 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3400 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3401 talloc_free(inf);
3403 break;
3405 case MP_CMD_GET_META_GENRE:{
3406 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3407 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3408 talloc_free(inf);
3410 break;
3412 case MP_CMD_GET_VO_FULLSCREEN:
3413 if (mpctx->video_out && mpctx->video_out->config_ok)
3414 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3415 break;
3417 case MP_CMD_GET_PERCENT_POS:
3418 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3419 get_percent_pos(mpctx));
3420 break;
3422 case MP_CMD_GET_TIME_POS:{
3423 float pos = get_current_time(mpctx);
3424 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3426 break;
3428 case MP_CMD_RUN:
3429 #ifndef __MINGW32__
3430 if (!fork()) {
3431 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3432 exit(0);
3434 #endif
3435 break;
3437 case MP_CMD_KEYDOWN_EVENTS:
3438 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3439 break;
3441 case MP_CMD_SET_MOUSE_POS:{
3442 int pointer_x, pointer_y;
3443 double dx, dy;
3444 pointer_x = cmd->args[0].v.i;
3445 pointer_y = cmd->args[1].v.i;
3446 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3447 #ifdef CONFIG_DVDNAV
3448 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3449 && dx > 0.0 && dy > 0.0) {
3450 int button = -1;
3451 pointer_x = (int) (dx * (double) sh_video->disp_w);
3452 pointer_y = (int) (dy * (double) sh_video->disp_h);
3453 mp_dvdnav_update_mouse_pos(mpctx->stream,
3454 pointer_x, pointer_y, &button);
3455 if (opts->osd_level > 1 && button > 0)
3456 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3457 "Selected button number %d", button);
3459 #endif
3460 #ifdef CONFIG_MENU
3461 if (use_menu && dx >= 0.0 && dy >= 0.0)
3462 menu_update_mouse_pos(dx, dy);
3463 #endif
3465 break;
3467 #ifdef CONFIG_DVDNAV
3468 case MP_CMD_DVDNAV:{
3469 int button = -1;
3470 int i;
3471 mp_command_type command = 0;
3472 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3473 break;
3475 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3476 if (cmd->args[0].v.s &&
3477 !strcasecmp (cmd->args[0].v.s,
3478 mp_dvdnav_bindings[i].name))
3479 command = mp_dvdnav_bindings[i].cmd;
3481 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3482 if (opts->osd_level > 1 && button > 0)
3483 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3484 "Selected button number %d", button);
3486 break;
3488 case MP_CMD_SWITCH_TITLE:
3489 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3490 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3491 break;
3493 #endif
3495 case MP_CMD_AF_SWITCH:
3496 if (sh_audio)
3498 af_uninit(mpctx->mixer.afilter);
3499 af_init(mpctx->mixer.afilter);
3501 case MP_CMD_AF_ADD:
3502 case MP_CMD_AF_DEL:
3503 if (!sh_audio)
3504 break;
3506 char* af_args = strdup(cmd->args[0].v.s);
3507 char* af_commands = af_args;
3508 char* af_command;
3509 af_instance_t* af;
3510 while ((af_command = strsep(&af_commands, ",")) != NULL)
3512 if (cmd->id == MP_CMD_AF_DEL)
3514 af = af_get(mpctx->mixer.afilter, af_command);
3515 if (af != NULL)
3516 af_remove(mpctx->mixer.afilter, af);
3518 else
3519 af_add(mpctx->mixer.afilter, af_command);
3521 reinit_audio_chain(mpctx);
3522 free(af_args);
3524 break;
3525 case MP_CMD_AF_CLR:
3526 if (!sh_audio)
3527 break;
3528 af_uninit(mpctx->mixer.afilter);
3529 af_init(mpctx->mixer.afilter);
3530 reinit_audio_chain(mpctx);
3531 break;
3532 case MP_CMD_AF_CMDLINE:
3533 if (sh_audio) {
3534 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3535 if (!af) {
3536 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3537 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3538 break;
3540 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3541 af_reinit(sh_audio->afilter, af);
3543 break;
3545 default:
3546 mp_msg(MSGT_CPLAYER, MSGL_V,
3547 "Received unknown cmd %s\n", cmd->name);
3550 switch (cmd->pausing) {
3551 case 1: // "pausing"
3552 pause_player(mpctx);
3553 break;
3554 case 3: // "pausing_toggle"
3555 if (mpctx->paused)
3556 unpause_player(mpctx);
3557 else
3558 pause_player(mpctx);
3559 break;