ao_alsa: remove warning by simplifying error handling case
[mplayer/greg.git] / command.c
blob8aeff84e638d15ee803a7832fa6ec892f32aca9f
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdlib.h>
20 #include <inttypes.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <stdbool.h>
25 #include "config.h"
26 #include "talloc.h"
27 #include "command.h"
28 #include "input/input.h"
29 #include "stream/stream.h"
30 #include "libmpdemux/demuxer.h"
31 #include "libmpdemux/stheader.h"
32 #include "codec-cfg.h"
33 #include "mplayer.h"
34 #include "sub/sub.h"
35 #include "sub/dec_sub.h"
36 #include "m_option.h"
37 #include "m_property.h"
38 #include "m_config.h"
39 #include "metadata.h"
40 #include "libmpcodecs/vf.h"
41 #include "libmpcodecs/vd.h"
42 #include "mp_osd.h"
43 #include "libvo/video_out.h"
44 #include "sub/font_load.h"
45 #include "playtree.h"
46 #include "libao2/audio_out.h"
47 #include "mpcommon.h"
48 #include "mixer.h"
49 #include "libmpcodecs/dec_video.h"
50 #include "libmpcodecs/dec_audio.h"
51 #include "libmpcodecs/dec_teletext.h"
52 #include "sub/vobsub.h"
53 #include "sub/spudec.h"
54 #include "path.h"
55 #include "sub/ass_mp.h"
56 #include "stream/tv.h"
57 #include "stream/stream_radio.h"
58 #include "stream/pvr.h"
59 #ifdef CONFIG_DVBIN
60 #include "stream/dvbin.h"
61 #endif
62 #ifdef CONFIG_DVDREAD
63 #include "stream/stream_dvd.h"
64 #endif
65 #include "stream/stream_dvdnav.h"
66 #include "m_struct.h"
67 #include "libmenu/menu.h"
69 #include "mp_core.h"
70 #include "mp_fifo.h"
71 #include "libavutil/avstring.h"
73 extern int use_menu;
75 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
76 double *dx, double *dy)
78 struct MPOpts *opts = &mpctx->opts;
79 struct vo *vo = mpctx->video_out;
80 //remove the borders, if any, and rescale to the range [0,1],[0,1]
81 if (vo_fs) { //we are in full-screen mode
82 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
83 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
84 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
85 iy -= (opts->vo_screenheight - vo->dheight) / 2;
87 if (ix < 0 || ix > vo->dwidth) {
88 *dx = *dy = -1.0;
89 return;
90 } //we are on one of the borders
91 if (iy < 0 || iy > vo->dheight) {
92 *dx = *dy = -1.0;
93 return;
94 } //we are on one of the borders
97 *dx = (double) ix / (double) vo->dwidth;
98 *dy = (double) iy / (double) vo->dheight;
100 mp_msg(MSGT_CPLAYER, MSGL_V,
101 "\r\nrescaled coordinates: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
102 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
103 vo->dheight, vo_fs);
106 static int sub_pos_by_source(MPContext *mpctx, int src)
108 int i, cnt = 0;
109 if (src >= SUB_SOURCES || mpctx->sub_counts[src] == 0)
110 return -1;
111 for (i = 0; i < src; i++)
112 cnt += mpctx->sub_counts[i];
113 return cnt;
116 static int sub_source_and_index_by_pos(MPContext *mpctx, int *pos)
118 int start = 0;
119 int i;
120 for (i = 0; i < SUB_SOURCES; i++) {
121 int cnt = mpctx->sub_counts[i];
122 if (*pos >= start && *pos < start + cnt) {
123 *pos -= start;
124 return i;
126 start += cnt;
128 *pos = -1;
129 return -1;
132 static int sub_source_by_pos(MPContext *mpctx, int pos)
134 return sub_source_and_index_by_pos(mpctx, &pos);
137 static int sub_source_pos(MPContext *mpctx)
139 int pos = mpctx->global_sub_pos;
140 sub_source_and_index_by_pos(mpctx, &pos);
141 return pos;
144 static int sub_source(MPContext *mpctx)
146 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
149 static void update_global_sub_size(MPContext *mpctx)
151 struct MPOpts *opts = &mpctx->opts;
152 int i;
153 int cnt = 0;
155 // update number of demuxer sub streams
156 for (i = 0; i < MAX_S_STREAMS; i++)
157 if (mpctx->d_sub->demuxer->s_streams[i])
158 cnt++;
159 if (cnt > mpctx->sub_counts[SUB_SOURCE_DEMUX])
160 mpctx->sub_counts[SUB_SOURCE_DEMUX] = cnt;
162 // update global size
163 mpctx->global_sub_size = 0;
164 for (i = 0; i < SUB_SOURCES; i++)
165 mpctx->global_sub_size += mpctx->sub_counts[i];
167 // update global_sub_pos if we auto-detected a demuxer sub
168 if (mpctx->global_sub_pos == -1) {
169 int sub_id = -1;
170 if (mpctx->demuxer->sub)
171 sub_id = mpctx->demuxer->sub->id;
172 if (sub_id < 0)
173 sub_id = opts->sub_id;
174 if (sub_id >= 0 && sub_id < mpctx->sub_counts[SUB_SOURCE_DEMUX])
175 mpctx->global_sub_pos = sub_pos_by_source(mpctx, SUB_SOURCE_DEMUX) +
176 sub_id;
181 * \brief Log the currently displayed subtitle to a file
183 * Logs the current or last displayed subtitle together with filename
184 * and time information to ~/.mplayer/subtitle_log
186 * Intended purpose is to allow convenient marking of bogus subtitles
187 * which need to be fixed while watching the movie.
190 static void log_sub(struct MPContext *mpctx)
192 char *fname;
193 FILE *f;
194 int i;
195 struct subtitle *vo_sub_last = mpctx->vo_sub_last;
197 if (mpctx->subdata == NULL || vo_sub_last == NULL)
198 return;
199 fname = get_path("subtitle_log");
200 f = fopen(fname, "a");
201 if (!f)
202 return;
203 fprintf(f, "----------------------------------------------------------\n");
204 if (mpctx->subdata->sub_uses_time) {
205 fprintf(f,
206 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
207 mpctx->filename, vo_sub_last->start / 360000,
208 (vo_sub_last->start / 6000) % 60,
209 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
210 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
211 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
212 } else {
213 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
214 vo_sub_last->start, vo_sub_last->end);
216 for (i = 0; i < vo_sub_last->lines; i++) {
217 fprintf(f, "%s\n", vo_sub_last->text[i]);
219 fclose(f);
223 /// \defgroup Properties
224 ///@{
226 /// \defgroup GeneralProperties General properties
227 /// \ingroup Properties
228 ///@{
230 static int mp_property_generic_option(struct m_option *prop, int action,
231 void *arg, MPContext *mpctx)
233 char *optname = prop->priv;
234 const struct m_option *opt = m_config_get_option(mpctx->mconfig, optname);
235 void *valptr = m_option_get_ptr(opt, &mpctx->opts);
237 switch (action) {
238 case M_PROPERTY_GET_TYPE:
239 *(const struct m_option **)arg = opt;
240 return M_PROPERTY_OK;
241 case M_PROPERTY_GET:
242 m_option_copy(opt, arg, valptr);
243 return M_PROPERTY_OK;
244 case M_PROPERTY_SET:
245 m_option_copy(opt, valptr, arg);
246 return M_PROPERTY_OK;
247 case M_PROPERTY_STEP_UP:
248 if (opt->type == &m_option_type_choice) {
249 int v = *(int *) valptr;
250 int best = v;
251 struct m_opt_choice_alternatives *alt;
252 for (alt = opt->priv; alt->name; alt++)
253 if ((unsigned) alt->value - v - 1 < (unsigned) best - v - 1)
254 best = alt->value;
255 *(int *) valptr = best;
256 return M_PROPERTY_OK;
258 break;
260 return M_PROPERTY_NOT_IMPLEMENTED;
263 /// OSD level (RW)
264 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
265 MPContext *mpctx)
267 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
270 /// Loop (RW)
271 static int mp_property_loop(m_option_t *prop, int action, void *arg,
272 MPContext *mpctx)
274 struct MPOpts *opts = &mpctx->opts;
275 switch (action) {
276 case M_PROPERTY_PRINT:
277 if (!arg) return M_PROPERTY_ERROR;
278 if (opts->loop_times < 0)
279 *(char**)arg = strdup("off");
280 else if (opts->loop_times == 0)
281 *(char**)arg = strdup("inf");
282 else
283 break;
284 return M_PROPERTY_OK;
286 return m_property_int_range(prop, action, arg, &opts->loop_times);
289 /// Playback speed (RW)
290 static int mp_property_playback_speed(m_option_t *prop, int action,
291 void *arg, MPContext *mpctx)
293 struct MPOpts *opts = &mpctx->opts;
294 switch (action) {
295 case M_PROPERTY_SET:
296 if (!arg)
297 return M_PROPERTY_ERROR;
298 M_PROPERTY_CLAMP(prop, *(float *) arg);
299 opts->playback_speed = *(float *) arg;
300 reinit_audio_chain(mpctx);
301 return M_PROPERTY_OK;
302 case M_PROPERTY_STEP_UP:
303 case M_PROPERTY_STEP_DOWN:
304 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
305 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
306 M_PROPERTY_CLAMP(prop, opts->playback_speed);
307 reinit_audio_chain(mpctx);
308 return M_PROPERTY_OK;
310 return m_property_float_range(prop, action, arg, &opts->playback_speed);
313 /// filename with path (RO)
314 static int mp_property_path(m_option_t *prop, int action, void *arg,
315 MPContext *mpctx)
317 return m_property_string_ro(prop, action, arg, mpctx->filename);
320 /// filename without path (RO)
321 static int mp_property_filename(m_option_t *prop, int action, void *arg,
322 MPContext *mpctx)
324 char *f;
325 if (!mpctx->filename)
326 return M_PROPERTY_UNAVAILABLE;
327 f = (char *)mp_basename(mpctx->filename);
328 if (!*f)
329 f = mpctx->filename;
330 return m_property_string_ro(prop, action, arg, f);
333 /// Demuxer name (RO)
334 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
335 MPContext *mpctx)
337 if (!mpctx->demuxer)
338 return M_PROPERTY_UNAVAILABLE;
339 return m_property_string_ro(prop, action, arg,
340 (char *) mpctx->demuxer->desc->name);
343 /// Position in the stream (RW)
344 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
345 MPContext *mpctx)
347 if (!mpctx->demuxer || !mpctx->demuxer->stream)
348 return M_PROPERTY_UNAVAILABLE;
349 if (!arg)
350 return M_PROPERTY_ERROR;
351 switch (action) {
352 case M_PROPERTY_GET:
353 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
354 return M_PROPERTY_OK;
355 case M_PROPERTY_SET:
356 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
357 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
358 return M_PROPERTY_OK;
360 return M_PROPERTY_NOT_IMPLEMENTED;
363 /// Stream start offset (RO)
364 static int mp_property_stream_start(m_option_t *prop, int action,
365 void *arg, MPContext *mpctx)
367 if (!mpctx->demuxer || !mpctx->demuxer->stream)
368 return M_PROPERTY_UNAVAILABLE;
369 switch (action) {
370 case M_PROPERTY_GET:
371 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
372 return M_PROPERTY_OK;
374 return M_PROPERTY_NOT_IMPLEMENTED;
377 /// Stream end offset (RO)
378 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
379 MPContext *mpctx)
381 if (!mpctx->demuxer || !mpctx->demuxer->stream)
382 return M_PROPERTY_UNAVAILABLE;
383 switch (action) {
384 case M_PROPERTY_GET:
385 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
386 return M_PROPERTY_OK;
388 return M_PROPERTY_NOT_IMPLEMENTED;
391 /// Stream length (RO)
392 static int mp_property_stream_length(m_option_t *prop, int action,
393 void *arg, MPContext *mpctx)
395 if (!mpctx->demuxer || !mpctx->demuxer->stream)
396 return M_PROPERTY_UNAVAILABLE;
397 switch (action) {
398 case M_PROPERTY_GET:
399 *(off_t *) arg =
400 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
401 return M_PROPERTY_OK;
403 return M_PROPERTY_NOT_IMPLEMENTED;
406 /// Current stream position in seconds (RO)
407 static int mp_property_stream_time_pos(m_option_t *prop, int action,
408 void *arg, MPContext *mpctx)
410 if (!mpctx->demuxer || mpctx->demuxer->stream_pts == MP_NOPTS_VALUE)
411 return M_PROPERTY_UNAVAILABLE;
413 return m_property_time_ro(prop, action, arg, mpctx->demuxer->stream_pts);
417 /// Media length in seconds (RO)
418 static int mp_property_length(m_option_t *prop, int action, void *arg,
419 MPContext *mpctx)
421 double len;
423 if (!mpctx->demuxer ||
424 !(int) (len = get_time_length(mpctx)))
425 return M_PROPERTY_UNAVAILABLE;
427 return m_property_time_ro(prop, action, arg, len);
430 /// Current position in percent (RW)
431 static int mp_property_percent_pos(m_option_t *prop, int action,
432 void *arg, MPContext *mpctx) {
433 int pos;
435 if (!mpctx->demuxer)
436 return M_PROPERTY_UNAVAILABLE;
438 switch(action) {
439 case M_PROPERTY_SET:
440 if(!arg) return M_PROPERTY_ERROR;
441 M_PROPERTY_CLAMP(prop, *(int*)arg);
442 pos = *(int*)arg;
443 break;
444 case M_PROPERTY_STEP_UP:
445 case M_PROPERTY_STEP_DOWN:
446 pos = get_percent_pos(mpctx);
447 pos += (arg ? *(int*)arg : 10) *
448 (action == M_PROPERTY_STEP_UP ? 1 : -1);
449 M_PROPERTY_CLAMP(prop, pos);
450 break;
451 default:
452 return m_property_int_ro(prop, action, arg, get_percent_pos(mpctx));
455 queue_seek(mpctx, MPSEEK_FACTOR, pos / 100.0, 0);
456 return M_PROPERTY_OK;
459 /// Current position in seconds (RW)
460 static int mp_property_time_pos(m_option_t *prop, int action,
461 void *arg, MPContext *mpctx) {
462 if (!(mpctx->sh_video || mpctx->sh_audio))
463 return M_PROPERTY_UNAVAILABLE;
465 switch(action) {
466 case M_PROPERTY_SET:
467 if(!arg) return M_PROPERTY_ERROR;
468 M_PROPERTY_CLAMP(prop, *(double*)arg);
469 queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double*)arg, 0);
470 return M_PROPERTY_OK;
471 case M_PROPERTY_STEP_UP:
472 case M_PROPERTY_STEP_DOWN:
473 queue_seek(mpctx, MPSEEK_RELATIVE, (arg ? *(double*)arg : 10.0) *
474 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0), 0);
475 return M_PROPERTY_OK;
477 return m_property_time_ro(prop, action, arg, get_current_time(mpctx));
480 /// Current chapter (RW)
481 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
482 MPContext *mpctx)
484 struct MPOpts *opts = &mpctx->opts;
485 int chapter = -1;
486 int step_all;
487 char *chapter_name = NULL;
489 if (mpctx->demuxer)
490 chapter = get_current_chapter(mpctx);
491 if (chapter < -1)
492 return M_PROPERTY_UNAVAILABLE;
494 switch (action) {
495 case M_PROPERTY_GET:
496 if (!arg)
497 return M_PROPERTY_ERROR;
498 *(int *) arg = chapter;
499 return M_PROPERTY_OK;
500 case M_PROPERTY_PRINT: {
501 if (!arg)
502 return M_PROPERTY_ERROR;
503 chapter_name = chapter_display_name(mpctx, chapter);
504 if (!chapter_name)
505 return M_PROPERTY_UNAVAILABLE;
506 *(char **) arg = chapter_name;
507 return M_PROPERTY_OK;
509 case M_PROPERTY_SET:
510 if (!arg)
511 return M_PROPERTY_ERROR;
512 M_PROPERTY_CLAMP(prop, *(int*)arg);
513 step_all = *(int *)arg - chapter;
514 chapter += step_all;
515 break;
516 case M_PROPERTY_STEP_UP:
517 case M_PROPERTY_STEP_DOWN: {
518 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
519 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
520 chapter += step_all;
521 if (chapter < 0)
522 chapter = 0;
523 break;
525 default:
526 return M_PROPERTY_NOT_IMPLEMENTED;
529 double next_pts = 0;
530 queue_seek(mpctx, MPSEEK_NONE, 0, 0);
531 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
532 if (chapter >= 0) {
533 if (next_pts > -1.0)
534 queue_seek(mpctx, MPSEEK_ABSOLUTE, next_pts, 0);
535 if (chapter_name)
536 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
537 "Chapter: (%d) %s", chapter + 1, chapter_name);
538 } else if (step_all > 0)
539 queue_seek(mpctx, MPSEEK_RELATIVE, 1000000000, 0);
540 else
541 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
542 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
543 talloc_free(chapter_name);
544 return M_PROPERTY_OK;
547 /// Number of chapters in file
548 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
549 MPContext *mpctx)
551 if (!mpctx->demuxer)
552 return M_PROPERTY_UNAVAILABLE;
553 if (mpctx->demuxer->num_chapters == 0)
554 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
555 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
558 /// Current dvd angle (RW)
559 static int mp_property_angle(m_option_t *prop, int action, void *arg,
560 MPContext *mpctx)
562 struct MPOpts *opts = &mpctx->opts;
563 int angle = -1;
564 int angles;
565 char *angle_name = NULL;
567 if (mpctx->demuxer)
568 angle = demuxer_get_current_angle(mpctx->demuxer);
569 if (angle < 0)
570 return M_PROPERTY_UNAVAILABLE;
571 angles = demuxer_angles_count(mpctx->demuxer);
572 if (angles <= 1)
573 return M_PROPERTY_UNAVAILABLE;
575 switch (action) {
576 case M_PROPERTY_GET:
577 if (!arg)
578 return M_PROPERTY_ERROR;
579 *(int *) arg = angle;
580 return M_PROPERTY_OK;
581 case M_PROPERTY_PRINT: {
582 if (!arg)
583 return M_PROPERTY_ERROR;
584 angle_name = calloc(1, 64);
585 if (!angle_name)
586 return M_PROPERTY_UNAVAILABLE;
587 snprintf(angle_name, 64, "%d/%d", angle, angles);
588 *(char **) arg = angle_name;
589 return M_PROPERTY_OK;
591 case M_PROPERTY_SET:
592 if (!arg)
593 return M_PROPERTY_ERROR;
594 angle = *(int *)arg;
595 M_PROPERTY_CLAMP(prop, angle);
596 break;
597 case M_PROPERTY_STEP_UP:
598 case M_PROPERTY_STEP_DOWN: {
599 int step = 0;
600 if(arg)
601 step = *(int*)arg;
602 if(!step)
603 step = 1;
604 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
605 angle += step;
606 if (angle < 1) //cycle
607 angle = angles;
608 break;
610 default:
611 return M_PROPERTY_NOT_IMPLEMENTED;
613 angle = demuxer_set_angle(mpctx->demuxer, angle);
614 if (angle >= 0) {
615 struct sh_video *sh_video = mpctx->demuxer->video->sh;
616 if (sh_video)
617 resync_video_stream(sh_video);
619 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
620 if (sh_audio)
621 resync_audio_stream(sh_audio);
624 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
625 "Angle: %d/%d", angle, angles);
626 free(angle_name);
627 return M_PROPERTY_OK;
630 /// Demuxer meta data
631 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
632 MPContext *mpctx) {
633 m_property_action_t* ka;
634 char* meta;
635 static const m_option_t key_type =
636 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
637 if (!mpctx->demuxer)
638 return M_PROPERTY_UNAVAILABLE;
640 switch(action) {
641 case M_PROPERTY_GET:
642 if(!arg) return M_PROPERTY_ERROR;
643 *(char***)arg = mpctx->demuxer->info;
644 return M_PROPERTY_OK;
645 case M_PROPERTY_KEY_ACTION:
646 if(!arg) return M_PROPERTY_ERROR;
647 ka = arg;
648 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
649 return M_PROPERTY_UNKNOWN;
650 switch(ka->action) {
651 case M_PROPERTY_GET:
652 if(!ka->arg) return M_PROPERTY_ERROR;
653 *(char**)ka->arg = meta;
654 return M_PROPERTY_OK;
655 case M_PROPERTY_GET_TYPE:
656 if(!ka->arg) return M_PROPERTY_ERROR;
657 *(const m_option_t**)ka->arg = &key_type;
658 return M_PROPERTY_OK;
661 return M_PROPERTY_NOT_IMPLEMENTED;
664 static int mp_property_pause(m_option_t *prop, int action, void *arg,
665 void *ctx)
667 MPContext *mpctx = ctx;
669 switch (action) {
670 case M_PROPERTY_SET:
671 if (!arg)
672 return M_PROPERTY_ERROR;
673 if (mpctx->paused == (bool)*(int *) arg)
674 return M_PROPERTY_OK;
675 case M_PROPERTY_STEP_UP:
676 case M_PROPERTY_STEP_DOWN:
677 if (mpctx->paused) {
678 unpause_player(mpctx);
679 mpctx->osd_function = OSD_PLAY;
681 else {
682 pause_player(mpctx);
683 mpctx->osd_function = OSD_PAUSE;
685 return M_PROPERTY_OK;
686 default:
687 return m_property_flag(prop, action, arg, &mpctx->paused);
692 ///@}
694 /// \defgroup AudioProperties Audio properties
695 /// \ingroup Properties
696 ///@{
698 /// Volume (RW)
699 static int mp_property_volume(m_option_t *prop, int action, void *arg,
700 MPContext *mpctx)
703 if (!mpctx->sh_audio)
704 return M_PROPERTY_UNAVAILABLE;
706 switch (action) {
707 case M_PROPERTY_GET:
708 if (!arg)
709 return M_PROPERTY_ERROR;
710 mixer_getbothvolume(&mpctx->mixer, arg);
711 return M_PROPERTY_OK;
712 case M_PROPERTY_PRINT:{
713 float vol;
714 if (!arg)
715 return M_PROPERTY_ERROR;
716 mixer_getbothvolume(&mpctx->mixer, &vol);
717 return m_property_float_range(prop, action, arg, &vol);
719 case M_PROPERTY_STEP_UP:
720 case M_PROPERTY_STEP_DOWN:
721 case M_PROPERTY_SET:
722 break;
723 default:
724 return M_PROPERTY_NOT_IMPLEMENTED;
727 if (mpctx->edl_muted)
728 return M_PROPERTY_DISABLED;
729 mpctx->user_muted = 0;
731 switch (action) {
732 case M_PROPERTY_SET:
733 if (!arg)
734 return M_PROPERTY_ERROR;
735 M_PROPERTY_CLAMP(prop, *(float *) arg);
736 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
737 return M_PROPERTY_OK;
738 case M_PROPERTY_STEP_UP:
739 if (arg && *(float *) arg <= 0)
740 mixer_decvolume(&mpctx->mixer);
741 else
742 mixer_incvolume(&mpctx->mixer);
743 return M_PROPERTY_OK;
744 case M_PROPERTY_STEP_DOWN:
745 if (arg && *(float *) arg <= 0)
746 mixer_incvolume(&mpctx->mixer);
747 else
748 mixer_decvolume(&mpctx->mixer);
749 return M_PROPERTY_OK;
751 return M_PROPERTY_NOT_IMPLEMENTED;
754 /// Mute (RW)
755 static int mp_property_mute(m_option_t *prop, int action, void *arg,
756 MPContext *mpctx)
759 if (!mpctx->sh_audio)
760 return M_PROPERTY_UNAVAILABLE;
762 switch (action) {
763 case M_PROPERTY_SET:
764 if (mpctx->edl_muted)
765 return M_PROPERTY_DISABLED;
766 if (!arg)
767 return M_PROPERTY_ERROR;
768 if ((!!*(int *) arg) != mpctx->mixer.muted)
769 mixer_mute(&mpctx->mixer);
770 mpctx->user_muted = mpctx->mixer.muted;
771 return M_PROPERTY_OK;
772 case M_PROPERTY_STEP_UP:
773 case M_PROPERTY_STEP_DOWN:
774 if (mpctx->edl_muted)
775 return M_PROPERTY_DISABLED;
776 mixer_mute(&mpctx->mixer);
777 mpctx->user_muted = mpctx->mixer.muted;
778 return M_PROPERTY_OK;
779 case M_PROPERTY_PRINT:
780 if (!arg)
781 return M_PROPERTY_ERROR;
782 if (mpctx->edl_muted) {
783 *(char **) arg = strdup(mp_gtext("enabled (EDL)"));
784 return M_PROPERTY_OK;
786 default:
787 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
792 /// Audio delay (RW)
793 static int mp_property_audio_delay(m_option_t *prop, int action,
794 void *arg, MPContext *mpctx)
796 if (!(mpctx->sh_audio && mpctx->sh_video))
797 return M_PROPERTY_UNAVAILABLE;
798 switch (action) {
799 case M_PROPERTY_SET:
800 case M_PROPERTY_STEP_UP:
801 case M_PROPERTY_STEP_DOWN: {
802 int ret;
803 float delay = audio_delay;
804 ret = m_property_delay(prop, action, arg, &audio_delay);
805 if (ret != M_PROPERTY_OK)
806 return ret;
807 if (mpctx->sh_audio)
808 mpctx->delay -= audio_delay - delay;
810 return M_PROPERTY_OK;
811 default:
812 return m_property_delay(prop, action, arg, &audio_delay);
816 /// Audio codec tag (RO)
817 static int mp_property_audio_format(m_option_t *prop, int action,
818 void *arg, MPContext *mpctx)
820 if (!mpctx->sh_audio)
821 return M_PROPERTY_UNAVAILABLE;
822 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
825 /// Audio codec name (RO)
826 static int mp_property_audio_codec(m_option_t *prop, int action,
827 void *arg, MPContext *mpctx)
829 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
830 return M_PROPERTY_UNAVAILABLE;
831 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
834 /// Audio bitrate (RO)
835 static int mp_property_audio_bitrate(m_option_t *prop, int action,
836 void *arg, MPContext *mpctx)
838 if (!mpctx->sh_audio)
839 return M_PROPERTY_UNAVAILABLE;
840 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
843 /// Samplerate (RO)
844 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
845 MPContext *mpctx)
847 if (!mpctx->sh_audio)
848 return M_PROPERTY_UNAVAILABLE;
849 switch(action) {
850 case M_PROPERTY_PRINT:
851 if(!arg) return M_PROPERTY_ERROR;
852 *(char**)arg = malloc(16);
853 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
854 return M_PROPERTY_OK;
856 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
859 /// Number of channels (RO)
860 static int mp_property_channels(m_option_t *prop, int action, void *arg,
861 MPContext *mpctx)
863 if (!mpctx->sh_audio)
864 return M_PROPERTY_UNAVAILABLE;
865 switch (action) {
866 case M_PROPERTY_PRINT:
867 if (!arg)
868 return M_PROPERTY_ERROR;
869 switch (mpctx->sh_audio->channels) {
870 case 1:
871 *(char **) arg = strdup("mono");
872 break;
873 case 2:
874 *(char **) arg = strdup("stereo");
875 break;
876 default:
877 *(char **) arg = malloc(32);
878 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
880 return M_PROPERTY_OK;
882 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
885 /// Balance (RW)
886 static int mp_property_balance(m_option_t *prop, int action, void *arg,
887 MPContext *mpctx)
889 float bal;
891 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
892 return M_PROPERTY_UNAVAILABLE;
894 switch (action) {
895 case M_PROPERTY_GET:
896 if (!arg)
897 return M_PROPERTY_ERROR;
898 mixer_getbalance(&mpctx->mixer, arg);
899 return M_PROPERTY_OK;
900 case M_PROPERTY_PRINT: {
901 char** str = arg;
902 if (!arg)
903 return M_PROPERTY_ERROR;
904 mixer_getbalance(&mpctx->mixer, &bal);
905 if (bal == 0.f)
906 *str = strdup("center");
907 else if (bal == -1.f)
908 *str = strdup("left only");
909 else if (bal == 1.f)
910 *str = strdup("right only");
911 else {
912 unsigned right = (bal + 1.f) / 2.f * 100.f;
913 *str = malloc(sizeof("left xxx%, right xxx%"));
914 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
916 return M_PROPERTY_OK;
918 case M_PROPERTY_STEP_UP:
919 case M_PROPERTY_STEP_DOWN:
920 mixer_getbalance(&mpctx->mixer, &bal);
921 bal += (arg ? *(float*)arg : .1f) *
922 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
923 M_PROPERTY_CLAMP(prop, bal);
924 mixer_setbalance(&mpctx->mixer, bal);
925 return M_PROPERTY_OK;
926 case M_PROPERTY_SET:
927 if (!arg)
928 return M_PROPERTY_ERROR;
929 M_PROPERTY_CLAMP(prop, *(float*)arg);
930 mixer_setbalance(&mpctx->mixer, *(float*)arg);
931 return M_PROPERTY_OK;
933 return M_PROPERTY_NOT_IMPLEMENTED;
936 /// Selected audio id (RW)
937 static int mp_property_audio(m_option_t *prop, int action, void *arg,
938 MPContext *mpctx)
940 int current_id, tmp;
941 if (!mpctx->demuxer || !mpctx->d_audio)
942 return M_PROPERTY_UNAVAILABLE;
943 current_id = mpctx->sh_audio ? mpctx->sh_audio->aid : -2;
945 switch (action) {
946 case M_PROPERTY_GET:
947 if (!arg)
948 return M_PROPERTY_ERROR;
949 *(int *) arg = current_id;
950 return M_PROPERTY_OK;
951 case M_PROPERTY_PRINT:
952 if (!arg)
953 return M_PROPERTY_ERROR;
955 if (current_id < 0)
956 *(char **) arg = strdup(mp_gtext("disabled"));
957 else {
958 char lang[40];
959 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
960 sh_audio_t* sh = mpctx->sh_audio;
961 if (sh && sh->lang)
962 av_strlcpy(lang, sh->lang, 40);
963 #ifdef CONFIG_DVDREAD
964 else if (mpctx->stream->type == STREAMTYPE_DVD) {
965 int code = dvd_lang_from_aid(mpctx->stream, current_id);
966 if (code) {
967 lang[0] = code >> 8;
968 lang[1] = code;
969 lang[2] = 0;
972 #endif
974 #ifdef CONFIG_DVDNAV
975 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
976 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
977 #endif
978 *(char **) arg = malloc(64);
979 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
981 return M_PROPERTY_OK;
983 case M_PROPERTY_STEP_UP:
984 case M_PROPERTY_SET:
985 if (action == M_PROPERTY_SET && arg)
986 tmp = *((int *) arg);
987 else
988 tmp = -1;
989 int new_id = demuxer_switch_audio(mpctx->d_audio->demuxer, tmp);
990 if (new_id != current_id)
991 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
992 if (new_id != current_id && new_id >= 0) {
993 sh_audio_t *sh2;
994 sh2 = mpctx->d_audio->demuxer->a_streams[mpctx->d_audio->id];
995 sh2->ds = mpctx->d_audio;
996 mpctx->sh_audio = sh2;
997 reinit_audio_chain(mpctx);
999 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
1000 return M_PROPERTY_OK;
1001 default:
1002 return M_PROPERTY_NOT_IMPLEMENTED;
1007 /// Selected video id (RW)
1008 static int mp_property_video(m_option_t *prop, int action, void *arg,
1009 MPContext *mpctx)
1011 struct MPOpts *opts = &mpctx->opts;
1012 int current_id, tmp;
1013 if (!mpctx->demuxer || !mpctx->d_video)
1014 return M_PROPERTY_UNAVAILABLE;
1015 current_id = mpctx->sh_video ? mpctx->sh_video->vid : -2;
1017 switch (action) {
1018 case M_PROPERTY_GET:
1019 if (!arg)
1020 return M_PROPERTY_ERROR;
1021 *(int *) arg = current_id;
1022 return M_PROPERTY_OK;
1023 case M_PROPERTY_PRINT:
1024 if (!arg)
1025 return M_PROPERTY_ERROR;
1027 if (current_id < 0)
1028 *(char **) arg = strdup(mp_gtext("disabled"));
1029 else {
1030 char lang[40];
1031 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
1032 *(char **) arg = malloc(64);
1033 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
1035 return M_PROPERTY_OK;
1037 case M_PROPERTY_STEP_UP:
1038 case M_PROPERTY_SET:
1039 if (action == M_PROPERTY_SET && arg)
1040 tmp = *((int *) arg);
1041 else
1042 tmp = -1;
1043 int new_id = demuxer_switch_video(mpctx->d_video->demuxer, tmp);
1044 if (new_id != current_id)
1045 uninit_player(mpctx, INITIALIZED_VCODEC |
1046 (opts->fixed_vo && new_id >= 0 ? 0 : INITIALIZED_VO));
1047 if (new_id != current_id && new_id >= 0) {
1048 sh_video_t *sh2;
1049 sh2 = mpctx->d_video->demuxer->v_streams[mpctx->d_video->id];
1050 sh2->ds = mpctx->d_video;
1051 mpctx->sh_video = sh2;
1052 reinit_video_chain(mpctx);
1054 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", new_id);
1055 return M_PROPERTY_OK;
1057 default:
1058 return M_PROPERTY_NOT_IMPLEMENTED;
1062 static int mp_property_program(m_option_t *prop, int action, void *arg,
1063 MPContext *mpctx)
1065 demux_program_t prog;
1067 switch (action) {
1068 case M_PROPERTY_STEP_UP:
1069 case M_PROPERTY_SET:
1070 if (action == M_PROPERTY_SET && arg)
1071 prog.progid = *((int *) arg);
1072 else
1073 prog.progid = -1;
1074 if (demux_control
1075 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1076 &prog) == DEMUXER_CTRL_NOTIMPL)
1077 return M_PROPERTY_ERROR;
1079 if (prog.aid < 0 && prog.vid < 0) {
1080 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
1081 return M_PROPERTY_ERROR;
1083 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1084 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1085 return M_PROPERTY_OK;
1087 default:
1088 return M_PROPERTY_NOT_IMPLEMENTED;
1092 ///@}
1094 /// \defgroup VideoProperties Video properties
1095 /// \ingroup Properties
1096 ///@{
1098 /// Fullscreen state (RW)
1099 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1100 MPContext *mpctx)
1103 if (!mpctx->video_out)
1104 return M_PROPERTY_UNAVAILABLE;
1106 switch (action) {
1107 case M_PROPERTY_SET:
1108 if (!arg)
1109 return M_PROPERTY_ERROR;
1110 M_PROPERTY_CLAMP(prop, *(int *) arg);
1111 if (vo_fs == !!*(int *) arg)
1112 return M_PROPERTY_OK;
1113 case M_PROPERTY_STEP_UP:
1114 case M_PROPERTY_STEP_DOWN:
1115 if (mpctx->video_out->config_ok)
1116 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1117 mpctx->opts.fullscreen = vo_fs;
1118 return M_PROPERTY_OK;
1119 default:
1120 return m_property_flag(prop, action, arg, &vo_fs);
1124 static int mp_property_deinterlace(m_option_t *prop, int action,
1125 void *arg, MPContext *mpctx)
1127 int deinterlace;
1128 vf_instance_t *vf;
1129 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1130 return M_PROPERTY_UNAVAILABLE;
1131 vf = mpctx->sh_video->vfilter;
1132 switch (action) {
1133 case M_PROPERTY_GET:
1134 if (!arg)
1135 return M_PROPERTY_ERROR;
1136 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1137 return M_PROPERTY_OK;
1138 case M_PROPERTY_SET:
1139 if (!arg)
1140 return M_PROPERTY_ERROR;
1141 M_PROPERTY_CLAMP(prop, *(int *) arg);
1142 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1143 return M_PROPERTY_OK;
1144 case M_PROPERTY_STEP_UP:
1145 case M_PROPERTY_STEP_DOWN:
1146 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1147 deinterlace = !deinterlace;
1148 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1149 return M_PROPERTY_OK;
1151 int value = 0;
1152 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1153 return m_property_flag_ro(prop, action, arg, value);
1156 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1157 void *arg, MPContext *mpctx)
1159 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1160 return M_PROPERTY_UNAVAILABLE;
1162 struct vf_instance *vf = mpctx->sh_video->vfilter;
1163 int colorspace;
1164 switch (action) {
1165 case M_PROPERTY_GET:
1166 if (!arg)
1167 return M_PROPERTY_ERROR;
1168 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1169 return M_PROPERTY_UNAVAILABLE;
1170 return M_PROPERTY_OK;
1171 case M_PROPERTY_PRINT:
1172 if (!arg)
1173 return M_PROPERTY_ERROR;
1174 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1175 return M_PROPERTY_UNAVAILABLE;
1176 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1177 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1178 *(char **)arg = strdup("Unknown");
1179 else
1180 *(char**)arg = strdup(names[colorspace]);
1181 return M_PROPERTY_OK;
1182 case M_PROPERTY_SET:
1183 if (!arg)
1184 return M_PROPERTY_ERROR;
1185 M_PROPERTY_CLAMP(prop, *(int *) arg);
1186 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1187 return M_PROPERTY_OK;
1188 case M_PROPERTY_STEP_UP:;
1189 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1190 return M_PROPERTY_UNAVAILABLE;
1191 colorspace += 1;
1192 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1193 return M_PROPERTY_OK;
1195 return M_PROPERTY_NOT_IMPLEMENTED;
1198 static int mp_property_capture(m_option_t *prop, int action,
1199 void *arg, MPContext *mpctx)
1201 struct MPOpts *opts = &mpctx->opts;
1203 if (!mpctx->stream)
1204 return M_PROPERTY_UNAVAILABLE;
1206 if (!opts->capture_dump) {
1207 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1208 "Capturing not enabled (forgot -capture parameter?)\n");
1209 return M_PROPERTY_ERROR;
1212 int capturing = !!mpctx->stream->capture_file;
1214 int ret = m_property_flag(prop, action, arg, &capturing);
1215 if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
1216 if (capturing) {
1217 mpctx->stream->capture_file = fopen(opts->stream_dump_name, "wb");
1218 if (!mpctx->stream->capture_file) {
1219 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1220 "Error opening capture file: %s\n", strerror(errno));
1221 ret = M_PROPERTY_ERROR;
1223 } else {
1224 fclose(mpctx->stream->capture_file);
1225 mpctx->stream->capture_file = NULL;
1229 return ret;
1232 /// Panscan (RW)
1233 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1234 MPContext *mpctx)
1237 if (!mpctx->video_out
1238 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1239 return M_PROPERTY_UNAVAILABLE;
1241 switch (action) {
1242 case M_PROPERTY_SET:
1243 if (!arg)
1244 return M_PROPERTY_ERROR;
1245 M_PROPERTY_CLAMP(prop, *(float *) arg);
1246 vo_panscan = *(float *) arg;
1247 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1248 return M_PROPERTY_OK;
1249 case M_PROPERTY_STEP_UP:
1250 case M_PROPERTY_STEP_DOWN:
1251 vo_panscan += (arg ? *(float *) arg : 0.1) *
1252 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1253 if (vo_panscan > 1)
1254 vo_panscan = 1;
1255 else if (vo_panscan < 0)
1256 vo_panscan = 0;
1257 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1258 return M_PROPERTY_OK;
1259 default:
1260 return m_property_float_range(prop, action, arg, &vo_panscan);
1264 /// Helper to set vo flags.
1265 /** \ingroup PropertyImplHelper
1267 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1268 int vo_ctrl, int *vo_var, MPContext *mpctx)
1271 if (!mpctx->video_out)
1272 return M_PROPERTY_UNAVAILABLE;
1274 switch (action) {
1275 case M_PROPERTY_SET:
1276 if (!arg)
1277 return M_PROPERTY_ERROR;
1278 M_PROPERTY_CLAMP(prop, *(int *) arg);
1279 if (*vo_var == !!*(int *) arg)
1280 return M_PROPERTY_OK;
1281 case M_PROPERTY_STEP_UP:
1282 case M_PROPERTY_STEP_DOWN:
1283 if (mpctx->video_out->config_ok)
1284 vo_control(mpctx->video_out, vo_ctrl, 0);
1285 return M_PROPERTY_OK;
1286 default:
1287 return m_property_flag(prop, action, arg, vo_var);
1291 /// Window always on top (RW)
1292 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1293 MPContext *mpctx)
1295 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1296 &mpctx->opts.vo_ontop, mpctx);
1299 /// Display in the root window (RW)
1300 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1301 MPContext *mpctx)
1303 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1304 &vo_rootwin, mpctx);
1307 /// Show window borders (RW)
1308 static int mp_property_border(m_option_t *prop, int action, void *arg,
1309 MPContext *mpctx)
1311 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1312 &vo_border, mpctx);
1315 /// Framedropping state (RW)
1316 static int mp_property_framedropping(m_option_t *prop, int action,
1317 void *arg, MPContext *mpctx)
1320 if (!mpctx->sh_video)
1321 return M_PROPERTY_UNAVAILABLE;
1323 switch (action) {
1324 case M_PROPERTY_PRINT:
1325 if (!arg)
1326 return M_PROPERTY_ERROR;
1327 *(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
1328 (frame_dropping == 2 ? mp_gtext("hard") :
1329 mp_gtext("disabled")));
1330 return M_PROPERTY_OK;
1331 default:
1332 return m_property_choice(prop, action, arg, &frame_dropping);
1336 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1337 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1338 MPContext *mpctx)
1340 int *gamma = (int *)((char *)&mpctx->opts + prop->offset);
1341 int r, val;
1343 if (!mpctx->sh_video)
1344 return M_PROPERTY_UNAVAILABLE;
1346 if (gamma[0] == 1000) {
1347 gamma[0] = 0;
1348 get_video_colors(mpctx->sh_video, prop->name, gamma);
1351 switch (action) {
1352 case M_PROPERTY_SET:
1353 if (!arg)
1354 return M_PROPERTY_ERROR;
1355 M_PROPERTY_CLAMP(prop, *(int *) arg);
1356 *gamma = *(int *) arg;
1357 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1358 if (r <= 0)
1359 break;
1360 return r;
1361 case M_PROPERTY_GET:
1362 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1363 if (!arg)
1364 return M_PROPERTY_ERROR;
1365 *(int *)arg = val;
1366 return M_PROPERTY_OK;
1368 break;
1369 case M_PROPERTY_STEP_UP:
1370 case M_PROPERTY_STEP_DOWN:
1371 *gamma += (arg ? *(int *) arg : 1) *
1372 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1373 M_PROPERTY_CLAMP(prop, *gamma);
1374 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1375 if (r <= 0)
1376 break;
1377 return r;
1378 default:
1379 return M_PROPERTY_NOT_IMPLEMENTED;
1382 #ifdef CONFIG_TV
1383 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1384 int l = strlen(prop->name);
1385 char tv_prop[3 + l + 1];
1386 sprintf(tv_prop, "tv_%s", prop->name);
1387 return mp_property_do(tv_prop, action, arg, mpctx);
1389 #endif
1391 return M_PROPERTY_UNAVAILABLE;
1394 /// VSync (RW)
1395 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1396 MPContext *mpctx)
1398 return m_property_flag(prop, action, arg, &vo_vsync);
1401 /// Video codec tag (RO)
1402 static int mp_property_video_format(m_option_t *prop, int action,
1403 void *arg, MPContext *mpctx)
1405 char* meta;
1406 if (!mpctx->sh_video)
1407 return M_PROPERTY_UNAVAILABLE;
1408 switch(action) {
1409 case M_PROPERTY_PRINT:
1410 if (!arg)
1411 return M_PROPERTY_ERROR;
1412 switch(mpctx->sh_video->format) {
1413 case 0x10000001:
1414 meta = strdup ("mpeg1"); break;
1415 case 0x10000002:
1416 meta = strdup ("mpeg2"); break;
1417 case 0x10000004:
1418 meta = strdup ("mpeg4"); break;
1419 case 0x10000005:
1420 meta = strdup ("h264"); break;
1421 default:
1422 if(mpctx->sh_video->format >= 0x20202020) {
1423 meta = malloc(5);
1424 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1425 } else {
1426 meta = malloc(20);
1427 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1430 *(char**)arg = meta;
1431 return M_PROPERTY_OK;
1433 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1436 /// Video codec name (RO)
1437 static int mp_property_video_codec(m_option_t *prop, int action,
1438 void *arg, MPContext *mpctx)
1440 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1441 return M_PROPERTY_UNAVAILABLE;
1442 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1446 /// Video bitrate (RO)
1447 static int mp_property_video_bitrate(m_option_t *prop, int action,
1448 void *arg, MPContext *mpctx)
1450 if (!mpctx->sh_video)
1451 return M_PROPERTY_UNAVAILABLE;
1452 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1455 /// Video display width (RO)
1456 static int mp_property_width(m_option_t *prop, int action, void *arg,
1457 MPContext *mpctx)
1459 if (!mpctx->sh_video)
1460 return M_PROPERTY_UNAVAILABLE;
1461 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1464 /// Video display height (RO)
1465 static int mp_property_height(m_option_t *prop, int action, void *arg,
1466 MPContext *mpctx)
1468 if (!mpctx->sh_video)
1469 return M_PROPERTY_UNAVAILABLE;
1470 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1473 /// Video fps (RO)
1474 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1475 MPContext *mpctx)
1477 if (!mpctx->sh_video)
1478 return M_PROPERTY_UNAVAILABLE;
1479 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1482 /// Video aspect (RO)
1483 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1484 MPContext *mpctx)
1486 if (!mpctx->sh_video)
1487 return M_PROPERTY_UNAVAILABLE;
1488 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1491 ///@}
1493 /// \defgroup SubProprties Subtitles properties
1494 /// \ingroup Properties
1495 ///@{
1497 /// Text subtitle position (RW)
1498 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1499 MPContext *mpctx)
1501 switch (action) {
1502 case M_PROPERTY_SET:
1503 if (!arg)
1504 return M_PROPERTY_ERROR;
1505 case M_PROPERTY_STEP_UP:
1506 case M_PROPERTY_STEP_DOWN:
1507 vo_osd_changed(OSDTYPE_SUBTITLE);
1508 default:
1509 return m_property_int_range(prop, action, arg, &sub_pos);
1513 /// Selected subtitles (RW)
1514 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1515 MPContext *mpctx)
1517 struct MPOpts *opts = &mpctx->opts;
1518 demux_stream_t *const d_sub = mpctx->d_sub;
1519 int source = -1, reset_spu = 0;
1520 int source_pos = -1;
1522 update_global_sub_size(mpctx);
1523 const int global_sub_size = mpctx->global_sub_size;
1525 if (global_sub_size <= 0)
1526 return M_PROPERTY_UNAVAILABLE;
1528 switch (action) {
1529 case M_PROPERTY_GET:
1530 if (!arg)
1531 return M_PROPERTY_ERROR;
1532 *(int *) arg = mpctx->global_sub_pos;
1533 return M_PROPERTY_OK;
1534 case M_PROPERTY_PRINT:
1535 if (!arg)
1536 return M_PROPERTY_ERROR;
1537 *(char **) arg = malloc(64);
1538 (*(char **) arg)[63] = 0;
1539 char *sub_name = NULL;
1540 if (mpctx->subdata)
1541 sub_name = mpctx->subdata->filename;
1542 #ifdef CONFIG_ASS
1543 if (mpctx->osd->ass_track)
1544 sub_name = mpctx->osd->ass_track->name;
1545 #endif
1546 if (!sub_name && mpctx->subdata)
1547 sub_name = mpctx->subdata->filename;
1548 if (sub_name) {
1549 const char *tmp = mp_basename(sub_name);
1551 snprintf(*(char **) arg, 63, "(%d) %s%s",
1552 mpctx->set_of_sub_pos + 1,
1553 strlen(tmp) < 20 ? "" : "...",
1554 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1555 return M_PROPERTY_OK;
1557 #ifdef CONFIG_DVDNAV
1558 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1559 if (vo_spudec && opts->sub_id >= 0) {
1560 unsigned char lang[3];
1561 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1562 snprintf(*(char **) arg, 63, "(%d) %s", 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 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1575 if (!lang) lang = mp_gtext("unknown");
1576 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1577 return M_PROPERTY_OK;
1580 if (vo_vobsub && vobsub_id >= 0) {
1581 const char *language = mp_gtext("unknown");
1582 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1583 snprintf(*(char **) arg, 63, "(%d) %s",
1584 vobsub_id, language ? language : mp_gtext("unknown"));
1585 return M_PROPERTY_OK;
1587 #ifdef CONFIG_DVDREAD
1588 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1589 && opts->sub_id >= 0) {
1590 char lang[3];
1591 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1592 lang[0] = code >> 8;
1593 lang[1] = code;
1594 lang[2] = 0;
1595 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1596 return M_PROPERTY_OK;
1598 #endif
1599 if (opts->sub_id >= 0) {
1600 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
1601 mp_gtext("unknown"));
1602 return M_PROPERTY_OK;
1604 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1605 return M_PROPERTY_OK;
1607 case M_PROPERTY_SET:
1608 if (!arg)
1609 return M_PROPERTY_ERROR;
1610 if (*(int *) arg < -1)
1611 *(int *) arg = -1;
1612 else if (*(int *) arg >= global_sub_size)
1613 *(int *) arg = global_sub_size - 1;
1614 mpctx->global_sub_pos = *(int *) arg;
1615 break;
1616 case M_PROPERTY_STEP_UP:
1617 mpctx->global_sub_pos += 2;
1618 mpctx->global_sub_pos =
1619 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1620 break;
1621 case M_PROPERTY_STEP_DOWN:
1622 mpctx->global_sub_pos += global_sub_size + 1;
1623 mpctx->global_sub_pos =
1624 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1625 break;
1626 default:
1627 return M_PROPERTY_NOT_IMPLEMENTED;
1630 if (mpctx->global_sub_pos >= 0) {
1631 source = sub_source(mpctx);
1632 source_pos = sub_source_pos(mpctx);
1635 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1636 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1637 global_sub_size,
1638 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1639 mpctx->sub_counts[SUB_SOURCE_SUBS],
1640 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1641 mpctx->global_sub_pos, source);
1643 mpctx->set_of_sub_pos = -1;
1644 mpctx->subdata = NULL;
1646 vobsub_id = -1;
1647 opts->sub_id = -1;
1648 if (d_sub) {
1649 if (d_sub->id > -2)
1650 reset_spu = 1;
1651 d_sub->id = -2;
1653 mpctx->osd->ass_track = NULL;
1654 uninit_player(mpctx, INITIALIZED_SUB);
1656 if (source == SUB_SOURCE_VOBSUB) {
1657 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1658 } else if (source == SUB_SOURCE_SUBS) {
1659 mpctx->set_of_sub_pos = source_pos;
1660 #ifdef CONFIG_ASS
1661 if (opts->ass_enabled
1662 && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]) {
1663 mpctx->osd->ass_track =
1664 mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1665 mpctx->osd->ass_track_changed = true;
1666 mpctx->osd->vsfilter_aspect =
1667 mpctx->track_was_native_ass[mpctx->set_of_sub_pos];
1668 } else
1669 #endif
1671 mpctx->subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1672 vo_osd_changed(OSDTYPE_SUBTITLE);
1674 } else if (source == SUB_SOURCE_DEMUX) {
1675 opts->sub_id = source_pos;
1676 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1677 int i = 0;
1678 // default: assume 1:1 mapping of sid and stream id
1679 d_sub->id = opts->sub_id;
1680 d_sub->sh = mpctx->d_sub->demuxer->s_streams[d_sub->id];
1681 ds_free_packs(d_sub);
1682 for (i = 0; i < MAX_S_STREAMS; i++) {
1683 sh_sub_t *sh = mpctx->d_sub->demuxer->s_streams[i];
1684 if (sh && sh->sid == opts->sub_id) {
1685 d_sub->id = i;
1686 d_sub->sh = sh;
1687 break;
1690 if (d_sub->sh && d_sub->id >= 0) {
1691 sh_sub_t *sh = d_sub->sh;
1692 if (sh->type == 'v')
1693 init_vo_spudec(mpctx);
1694 else {
1695 sub_init(sh, mpctx->osd);
1696 mpctx->initialized_flags |= INITIALIZED_SUB;
1698 } else {
1699 d_sub->id = -2;
1700 d_sub->sh = NULL;
1704 #ifdef CONFIG_DVDREAD
1705 if (vo_spudec
1706 && (mpctx->stream->type == STREAMTYPE_DVD
1707 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1708 && opts->sub_id < 0 && reset_spu) {
1709 d_sub->id = -2;
1710 d_sub->sh = NULL;
1712 #endif
1714 update_subtitles(mpctx, 0, 0, true);
1716 return M_PROPERTY_OK;
1719 /// Selected sub source (RW)
1720 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1721 MPContext *mpctx)
1723 int source;
1724 update_global_sub_size(mpctx);
1725 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1726 return M_PROPERTY_UNAVAILABLE;
1728 switch (action) {
1729 case M_PROPERTY_GET:
1730 if (!arg)
1731 return M_PROPERTY_ERROR;
1732 *(int *) arg = sub_source(mpctx);
1733 return M_PROPERTY_OK;
1734 case M_PROPERTY_PRINT:
1735 if (!arg)
1736 return M_PROPERTY_ERROR;
1737 *(char **) arg = malloc(64);
1738 (*(char **) arg)[63] = 0;
1739 switch (sub_source(mpctx))
1741 case SUB_SOURCE_SUBS:
1742 snprintf(*(char **) arg, 63, mp_gtext("file"));
1743 break;
1744 case SUB_SOURCE_VOBSUB:
1745 snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
1746 break;
1747 case SUB_SOURCE_DEMUX:
1748 snprintf(*(char **) arg, 63, mp_gtext("embedded"));
1749 break;
1750 default:
1751 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1753 return M_PROPERTY_OK;
1754 case M_PROPERTY_SET:
1755 if (!arg)
1756 return M_PROPERTY_ERROR;
1757 M_PROPERTY_CLAMP(prop, *(int*)arg);
1758 if (*(int *) arg < 0)
1759 mpctx->global_sub_pos = -1;
1760 else if (*(int *) arg != sub_source(mpctx)) {
1761 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1762 if (new_pos == -1)
1763 return M_PROPERTY_UNAVAILABLE;
1764 mpctx->global_sub_pos = new_pos;
1766 break;
1767 case M_PROPERTY_STEP_UP:
1768 case M_PROPERTY_STEP_DOWN: {
1769 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1770 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1771 int step = (step_all > 0) ? 1 : -1;
1772 int cur_source = sub_source(mpctx);
1773 source = cur_source;
1774 while (step_all) {
1775 source += step;
1776 if (source >= SUB_SOURCES)
1777 source = -1;
1778 else if (source < -1)
1779 source = SUB_SOURCES - 1;
1780 if (source == cur_source || source == -1 ||
1781 mpctx->sub_counts[source])
1782 step_all -= step;
1784 if (source == cur_source)
1785 return M_PROPERTY_OK;
1786 if (source == -1)
1787 mpctx->global_sub_pos = -1;
1788 else
1789 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1790 break;
1792 default:
1793 return M_PROPERTY_NOT_IMPLEMENTED;
1795 --mpctx->global_sub_pos;
1796 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1799 /// Selected subtitles from specific source (RW)
1800 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1801 MPContext *mpctx)
1803 int source, is_cur_source, offset, new_pos;
1804 update_global_sub_size(mpctx);
1805 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1806 return M_PROPERTY_UNAVAILABLE;
1808 if (!strcmp(prop->name, "sub_file"))
1809 source = SUB_SOURCE_SUBS;
1810 else if (!strcmp(prop->name, "sub_vob"))
1811 source = SUB_SOURCE_VOBSUB;
1812 else if (!strcmp(prop->name, "sub_demux"))
1813 source = SUB_SOURCE_DEMUX;
1814 else
1815 return M_PROPERTY_ERROR;
1817 offset = sub_pos_by_source(mpctx, source);
1818 if (offset < 0)
1819 return M_PROPERTY_UNAVAILABLE;
1821 is_cur_source = sub_source(mpctx) == source;
1822 new_pos = mpctx->global_sub_pos;
1823 switch (action) {
1824 case M_PROPERTY_GET:
1825 if (!arg)
1826 return M_PROPERTY_ERROR;
1827 if (is_cur_source) {
1828 *(int *) arg = sub_source_pos(mpctx);
1829 if (source == SUB_SOURCE_VOBSUB)
1830 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1832 else
1833 *(int *) arg = -1;
1834 return M_PROPERTY_OK;
1835 case M_PROPERTY_PRINT:
1836 if (!arg)
1837 return M_PROPERTY_ERROR;
1838 if (is_cur_source)
1839 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1840 *(char **) arg = malloc(64);
1841 (*(char **) arg)[63] = 0;
1842 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1843 return M_PROPERTY_OK;
1844 case M_PROPERTY_SET:
1845 if (!arg)
1846 return M_PROPERTY_ERROR;
1847 if (*(int *) arg >= 0) {
1848 int index = *(int *)arg;
1849 if (source == SUB_SOURCE_VOBSUB)
1850 index = vobsub_get_index_by_id(vo_vobsub, index);
1851 new_pos = offset + index;
1852 if (index < 0 || index > mpctx->sub_counts[source]) {
1853 new_pos = -1;
1854 *(int *) arg = -1;
1857 else
1858 new_pos = -1;
1859 break;
1860 case M_PROPERTY_STEP_UP:
1861 case M_PROPERTY_STEP_DOWN: {
1862 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1863 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1864 int step = (step_all > 0) ? 1 : -1;
1865 int max_sub_pos_for_source = -1;
1866 if (!is_cur_source)
1867 new_pos = -1;
1868 while (step_all) {
1869 if (new_pos == -1) {
1870 if (step > 0)
1871 new_pos = offset;
1872 else if (max_sub_pos_for_source == -1) {
1873 // Find max pos for specific source
1874 new_pos = mpctx->global_sub_size - 1;
1875 while (new_pos >= 0
1876 && sub_source(mpctx) != source)
1877 new_pos--;
1879 else
1880 new_pos = max_sub_pos_for_source;
1882 else {
1883 new_pos += step;
1884 if (new_pos < offset ||
1885 new_pos >= mpctx->global_sub_size ||
1886 sub_source(mpctx) != source)
1887 new_pos = -1;
1889 step_all -= step;
1891 break;
1893 default:
1894 return M_PROPERTY_NOT_IMPLEMENTED;
1896 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1899 /// Subtitle delay (RW)
1900 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1901 MPContext *mpctx)
1903 if (!mpctx->sh_video)
1904 return M_PROPERTY_UNAVAILABLE;
1905 return m_property_delay(prop, action, arg, &sub_delay);
1908 /// Alignment of text subtitles (RW)
1909 static int mp_property_sub_alignment(m_option_t *prop, int action,
1910 void *arg, MPContext *mpctx)
1912 char *name[] = { _("top"), _("center"), _("bottom") };
1914 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1915 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1916 return M_PROPERTY_UNAVAILABLE;
1918 switch (action) {
1919 case M_PROPERTY_PRINT:
1920 if (!arg)
1921 return M_PROPERTY_ERROR;
1922 M_PROPERTY_CLAMP(prop, sub_alignment);
1923 *(char **) arg = strdup(mp_gtext(name[sub_alignment]));
1924 return M_PROPERTY_OK;
1925 case M_PROPERTY_SET:
1926 if (!arg)
1927 return M_PROPERTY_ERROR;
1928 case M_PROPERTY_STEP_UP:
1929 case M_PROPERTY_STEP_DOWN:
1930 vo_osd_changed(OSDTYPE_SUBTITLE);
1931 default:
1932 return m_property_choice(prop, action, arg, &sub_alignment);
1936 /// Subtitle visibility (RW)
1937 static int mp_property_sub_visibility(m_option_t *prop, int action,
1938 void *arg, MPContext *mpctx)
1940 if (!mpctx->sh_video)
1941 return M_PROPERTY_UNAVAILABLE;
1943 switch (action) {
1944 case M_PROPERTY_SET:
1945 if (!arg)
1946 return M_PROPERTY_ERROR;
1947 case M_PROPERTY_STEP_UP:
1948 case M_PROPERTY_STEP_DOWN:
1949 vo_osd_changed(OSDTYPE_SUBTITLE);
1950 if (vo_spudec)
1951 vo_osd_changed(OSDTYPE_SPU);
1952 default:
1953 return m_property_flag(prop, action, arg, &sub_visibility);
1957 #ifdef CONFIG_ASS
1958 /// Use margins for libass subtitles (RW)
1959 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1960 void *arg, MPContext *mpctx)
1962 if (!mpctx->sh_video)
1963 return M_PROPERTY_UNAVAILABLE;
1965 switch (action) {
1966 case M_PROPERTY_SET:
1967 if (!arg)
1968 return M_PROPERTY_ERROR;
1969 case M_PROPERTY_STEP_UP:
1970 case M_PROPERTY_STEP_DOWN:
1971 ass_force_reload = 1;
1972 default:
1973 return m_property_flag(prop, action, arg, &ass_use_margins);
1976 #endif
1978 /// Show only forced subtitles (RW)
1979 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1980 void *arg, MPContext *mpctx)
1982 if (!vo_spudec)
1983 return M_PROPERTY_UNAVAILABLE;
1985 switch (action) {
1986 case M_PROPERTY_SET:
1987 if (!arg)
1988 return M_PROPERTY_ERROR;
1989 case M_PROPERTY_STEP_UP:
1990 case M_PROPERTY_STEP_DOWN:
1991 m_property_flag(prop, action, arg, &forced_subs_only);
1992 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1993 return M_PROPERTY_OK;
1994 default:
1995 return m_property_flag(prop, action, arg, &forced_subs_only);
2000 #ifdef CONFIG_FREETYPE
2001 /// Subtitle scale (RW)
2002 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
2003 MPContext *mpctx)
2005 struct MPOpts *opts = &mpctx->opts;
2007 switch (action) {
2008 case M_PROPERTY_SET:
2009 if (!arg)
2010 return M_PROPERTY_ERROR;
2011 M_PROPERTY_CLAMP(prop, *(float *) arg);
2012 #ifdef CONFIG_ASS
2013 if (opts->ass_enabled) {
2014 ass_font_scale = *(float *) arg;
2015 ass_force_reload = 1;
2017 #endif
2018 text_font_scale_factor = *(float *) arg;
2019 force_load_font = 1;
2020 return M_PROPERTY_OK;
2021 case M_PROPERTY_STEP_UP:
2022 case M_PROPERTY_STEP_DOWN:
2023 #ifdef CONFIG_ASS
2024 if (opts->ass_enabled) {
2025 ass_font_scale += (arg ? *(float *) arg : 0.1)*
2026 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2027 M_PROPERTY_CLAMP(prop, ass_font_scale);
2028 ass_force_reload = 1;
2030 #endif
2031 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
2032 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2033 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
2034 force_load_font = 1;
2035 return M_PROPERTY_OK;
2036 default:
2037 #ifdef CONFIG_ASS
2038 if (opts->ass_enabled)
2039 return m_property_float_ro(prop, action, arg, ass_font_scale);
2040 else
2041 #endif
2042 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
2045 #endif
2047 ///@}
2049 /// \defgroup TVProperties TV properties
2050 /// \ingroup Properties
2051 ///@{
2053 #ifdef CONFIG_TV
2055 /// TV color settings (RW)
2056 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2057 MPContext *mpctx)
2059 int r, val;
2060 tvi_handle_t *tvh = mpctx->demuxer->priv;
2061 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2062 return M_PROPERTY_UNAVAILABLE;
2064 switch (action) {
2065 case M_PROPERTY_SET:
2066 if (!arg)
2067 return M_PROPERTY_ERROR;
2068 M_PROPERTY_CLAMP(prop, *(int *) arg);
2069 return tv_set_color_options(tvh, prop->offset, *(int *) arg);
2070 case M_PROPERTY_GET:
2071 return tv_get_color_options(tvh, prop->offset, arg);
2072 case M_PROPERTY_STEP_UP:
2073 case M_PROPERTY_STEP_DOWN:
2074 if ((r = tv_get_color_options(tvh, prop->offset, &val)) >= 0) {
2075 if (!r)
2076 return M_PROPERTY_ERROR;
2077 val += (arg ? *(int *) arg : 1) *
2078 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2079 M_PROPERTY_CLAMP(prop, val);
2080 return tv_set_color_options(tvh, prop->offset, val);
2082 return M_PROPERTY_ERROR;
2084 return M_PROPERTY_NOT_IMPLEMENTED;
2087 #endif
2089 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2090 MPContext *mpctx)
2092 int val,result;
2093 int base_ioctl = prop->offset;
2095 for teletext's GET,SET,STEP ioctls this is not 0
2096 SET is GET+1
2097 STEP is GET+2
2099 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2100 return M_PROPERTY_UNAVAILABLE;
2101 if(!base_ioctl)
2102 return M_PROPERTY_ERROR;
2104 switch (action) {
2105 case M_PROPERTY_GET:
2106 if (!arg)
2107 return M_PROPERTY_ERROR;
2108 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2109 break;
2110 case M_PROPERTY_SET:
2111 if (!arg)
2112 return M_PROPERTY_ERROR;
2113 M_PROPERTY_CLAMP(prop, *(int *) arg);
2114 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
2115 break;
2116 case M_PROPERTY_STEP_UP:
2117 case M_PROPERTY_STEP_DOWN:
2118 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2119 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2120 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
2121 break;
2122 default:
2123 return M_PROPERTY_NOT_IMPLEMENTED;
2126 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2129 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2130 MPContext *mpctx)
2132 int result;
2133 int val;
2135 //with tvh==NULL will fail too
2136 result=mp_property_teletext_common(prop,action,arg,mpctx);
2137 if(result!=M_PROPERTY_OK)
2138 return result;
2140 if(teletext_control(mpctx->demuxer->teletext,
2141 prop->offset, &val)==VBI_CONTROL_TRUE && val)
2142 mp_input_set_section(mpctx->input, "teletext");
2143 else
2144 mp_input_set_section(mpctx->input, "tv");
2145 return M_PROPERTY_OK;
2148 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2149 MPContext *mpctx)
2151 int result;
2152 int val;
2153 if (!mpctx->demuxer->teletext)
2154 return M_PROPERTY_UNAVAILABLE;
2155 switch(action){
2156 case M_PROPERTY_STEP_UP:
2157 case M_PROPERTY_STEP_DOWN:
2158 //This should be handled separately
2159 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2160 result=teletext_control(mpctx->demuxer->teletext,
2161 TV_VBI_CONTROL_STEP_PAGE, &val);
2162 break;
2163 default:
2164 result=mp_property_teletext_common(prop,action,arg,mpctx);
2166 return result;
2169 ///@}
2171 /// All properties available in MPlayer.
2172 /** \ingroup Properties
2174 static const m_option_t mp_properties[] = {
2175 // General
2176 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2177 M_OPT_RANGE, 0, 3, NULL },
2178 { "loop", mp_property_loop, CONF_TYPE_INT,
2179 M_OPT_MIN, -1, 0, NULL },
2180 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2181 M_OPT_RANGE, 0.01, 100.0, NULL },
2182 { "filename", mp_property_filename, CONF_TYPE_STRING,
2183 0, 0, 0, NULL },
2184 { "path", mp_property_path, CONF_TYPE_STRING,
2185 0, 0, 0, NULL },
2186 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2187 0, 0, 0, NULL },
2188 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2189 M_OPT_MIN, 0, 0, NULL },
2190 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2191 M_OPT_MIN, 0, 0, NULL },
2192 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2193 M_OPT_MIN, 0, 0, NULL },
2194 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2195 M_OPT_MIN, 0, 0, NULL },
2196 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2197 M_OPT_MIN, 0, 0, NULL },
2198 { "length", mp_property_length, CONF_TYPE_TIME,
2199 M_OPT_MIN, 0, 0, NULL },
2200 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2201 M_OPT_RANGE, 0, 100, NULL },
2202 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2203 M_OPT_MIN, 0, 0, NULL },
2204 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2205 M_OPT_MIN, 0, 0, NULL },
2206 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2207 0, 0, 0, NULL },
2208 { "angle", mp_property_angle, CONF_TYPE_INT,
2209 CONF_RANGE, -2, 10, NULL },
2210 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2211 0, 0, 0, NULL },
2212 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2213 M_OPT_RANGE, 0, 1, NULL },
2214 { "capturing", mp_property_capture, CONF_TYPE_FLAG,
2215 M_OPT_RANGE, 0, 1, NULL },
2216 { "pts_association_mode", mp_property_generic_option, &m_option_type_choice,
2217 0, 0, 0, "pts-association-mode" },
2218 { "hr_seek", mp_property_generic_option, &m_option_type_choice,
2219 0, 0, 0, "hr-seek" },
2221 // Audio
2222 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2223 M_OPT_RANGE, 0, 100, NULL },
2224 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2225 M_OPT_RANGE, 0, 1, NULL },
2226 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2227 M_OPT_RANGE, -100, 100, NULL },
2228 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2229 0, 0, 0, NULL },
2230 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2231 0, 0, 0, NULL },
2232 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2233 0, 0, 0, NULL },
2234 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2235 0, 0, 0, NULL },
2236 { "channels", mp_property_channels, CONF_TYPE_INT,
2237 0, 0, 0, NULL },
2238 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2239 CONF_RANGE, -2, 65535, NULL },
2240 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2241 M_OPT_RANGE, -1, 1, NULL },
2243 // Video
2244 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2245 M_OPT_RANGE, 0, 1, NULL },
2246 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2247 M_OPT_RANGE, 0, 1, NULL },
2248 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2249 M_OPT_RANGE, 0, 2, NULL },
2250 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2251 M_OPT_RANGE, 0, 1, NULL },
2252 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2253 M_OPT_RANGE, 0, 1, NULL },
2254 { "border", mp_property_border, CONF_TYPE_FLAG,
2255 M_OPT_RANGE, 0, 1, NULL },
2256 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2257 M_OPT_RANGE, 0, 2, NULL },
2258 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2259 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_gamma)},
2260 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2261 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_brightness) },
2262 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2263 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_contrast) },
2264 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2265 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_saturation) },
2266 { "hue", mp_property_gamma, CONF_TYPE_INT,
2267 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_hue) },
2268 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2269 M_OPT_RANGE, 0, 1, NULL },
2270 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2271 M_OPT_RANGE, 0, 1, NULL },
2272 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2273 0, 0, 0, NULL },
2274 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2275 0, 0, 0, NULL },
2276 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2277 0, 0, 0, NULL },
2278 { "width", mp_property_width, CONF_TYPE_INT,
2279 0, 0, 0, NULL },
2280 { "height", mp_property_height, CONF_TYPE_INT,
2281 0, 0, 0, NULL },
2282 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2283 0, 0, 0, NULL },
2284 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2285 0, 0, 0, NULL },
2286 { "switch_video", mp_property_video, CONF_TYPE_INT,
2287 CONF_RANGE, -2, 65535, NULL },
2288 { "switch_program", mp_property_program, CONF_TYPE_INT,
2289 CONF_RANGE, -1, 65535, NULL },
2291 // Subs
2292 { "sub", mp_property_sub, CONF_TYPE_INT,
2293 M_OPT_MIN, -1, 0, NULL },
2294 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2295 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2296 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2297 M_OPT_MIN, -1, 0, NULL },
2298 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2299 M_OPT_MIN, -1, 0, NULL },
2300 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2301 M_OPT_MIN, -1, 0, NULL },
2302 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2303 0, 0, 0, NULL },
2304 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2305 M_OPT_RANGE, 0, 100, NULL },
2306 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2307 M_OPT_RANGE, 0, 2, NULL },
2308 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2309 M_OPT_RANGE, 0, 1, NULL },
2310 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2311 M_OPT_RANGE, 0, 1, NULL },
2312 #ifdef CONFIG_FREETYPE
2313 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2314 M_OPT_RANGE, 0, 100, NULL },
2315 #endif
2316 #ifdef CONFIG_ASS
2317 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2318 M_OPT_RANGE, 0, 1, NULL },
2319 #endif
2321 #ifdef CONFIG_TV
2322 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2323 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_BRIGHTNESS },
2324 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2325 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_CONTRAST },
2326 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2327 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_SATURATION },
2328 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2329 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_HUE },
2330 #endif
2331 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2332 M_OPT_RANGE, 100, 899, .offset=TV_VBI_CONTROL_GET_PAGE },
2333 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2334 M_OPT_RANGE, 0, 64, .offset=TV_VBI_CONTROL_GET_SUBPAGE },
2335 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2336 M_OPT_RANGE, 0, 1, .offset=TV_VBI_CONTROL_GET_MODE },
2337 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2338 M_OPT_RANGE, 0, 3, .offset=TV_VBI_CONTROL_GET_FORMAT },
2339 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2340 M_OPT_RANGE, 0, 2, .offset=TV_VBI_CONTROL_GET_HALF_PAGE },
2341 { NULL, NULL, NULL, 0, 0, 0, NULL }
2345 int mp_property_do(const char *name, int action, void *val, void *ctx)
2347 return m_property_do(mp_properties, name, action, val, ctx);
2350 char* mp_property_print(const char *name, void* ctx)
2352 char* ret = NULL;
2353 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2354 return NULL;
2355 return ret;
2358 char *property_expand_string(MPContext *mpctx, char *str)
2360 return m_properties_expand_string(mp_properties, str, mpctx);
2363 void property_print_help(void)
2365 m_properties_print_help_list(mp_properties);
2369 /* List of default ways to show a property on OSD.
2371 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2372 * a bar showing the current position between min/max values of the
2373 * property. In this case osd_msg is only used for terminal output
2374 * if there is no video; it'll be a label shown together with percentage.
2376 * Otherwise setting osd_msg will show the string on OSD, formatted with
2377 * the text value of the property as argument.
2379 static struct property_osd_display {
2380 /// property name
2381 const char *name;
2382 /// progressbar type
2383 int osd_progbar; // -1 is special value for seek indicators
2384 /// osd msg id if it must be shared
2385 int osd_id;
2386 /// osd msg template
2387 const char *osd_msg;
2388 } property_osd_display[] = {
2389 // general
2390 { "loop", 0, -1, _("Loop: %s") },
2391 { "chapter", -1, -1, NULL },
2392 { "capturing", 0, -1, _("Capturing: %s") },
2393 { "pts_association_mode", 0, -1, "PTS association mode: %s" },
2394 { "hr_seek", 0, -1, "hr-seek: %s" },
2395 { "speed", 0, -1, _("Speed: x %6s") },
2396 // audio
2397 { "volume", OSD_VOLUME, -1, _("Volume") },
2398 { "mute", 0, -1, _("Mute: %s") },
2399 { "audio_delay", 0, -1, _("A-V delay: %s") },
2400 { "switch_audio", 0, -1, _("Audio: %s") },
2401 { "balance", OSD_BALANCE, -1, _("Balance") },
2402 // video
2403 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2404 { "ontop", 0, -1, _("Stay on top: %s") },
2405 { "rootwin", 0, -1, _("Rootwin: %s") },
2406 { "border", 0, -1, _("Border: %s") },
2407 { "framedropping", 0, -1, _("Framedropping: %s") },
2408 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2409 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2410 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2411 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2412 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2413 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2414 { "hue", OSD_HUE, -1, _("Hue") },
2415 { "vsync", 0, -1, _("VSync: %s") },
2416 // subs
2417 { "sub", 0, -1, _("Subtitles: %s") },
2418 { "sub_source", 0, -1, _("Sub source: %s") },
2419 { "sub_vob", 0, -1, _("Subtitles: %s") },
2420 { "sub_demux", 0, -1, _("Subtitles: %s") },
2421 { "sub_file", 0, -1, _("Subtitles: %s") },
2422 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2423 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2424 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2425 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2426 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2427 #ifdef CONFIG_FREETYPE
2428 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2429 #endif
2430 #ifdef CONFIG_TV
2431 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2432 { "tv_hue", OSD_HUE, -1, _("Hue") },
2433 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2434 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2435 #endif
2439 static int show_property_osd(MPContext *mpctx, const char *pname)
2441 struct MPOpts *opts = &mpctx->opts;
2442 int r;
2443 m_option_t* prop;
2444 struct property_osd_display *p;
2446 // look for the command
2447 for (p = property_osd_display; p->name; p++)
2448 if (!strcmp(p->name, pname))
2449 break;
2450 if (!p->name)
2451 return -1;
2453 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2454 return -1;
2456 if (p->osd_progbar == -1)
2457 mpctx->add_osd_seek_info = true;
2458 else if (p->osd_progbar) {
2459 if (prop->type == CONF_TYPE_INT) {
2460 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2461 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2462 prop->min, prop->max, r);
2463 } else if (prop->type == CONF_TYPE_FLOAT) {
2464 float f;
2465 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2466 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2467 prop->min, prop->max, f);
2468 } else {
2469 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2470 "Property use an unsupported type.\n");
2471 return -1;
2473 return 0;
2476 if (p->osd_msg) {
2477 char *val = mp_property_print(pname, mpctx);
2478 if (val) {
2479 int index = p - property_osd_display;
2480 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2481 1, opts->osd_duration, p->osd_msg, val);
2482 free(val);
2485 return 0;
2490 * \defgroup Command2Property Command to property bridge
2492 * It is used to handle most commands that just set a property
2493 * and optionally display something on the OSD.
2494 * Two kinds of commands are handled: adjust or toggle.
2496 * Adjust commands take 1 or 2 parameters: <value> <abs>
2497 * If <abs> is non-zero the property is set to the given value
2498 * otherwise it is adjusted.
2500 * Toggle commands take 0 or 1 parameters. With no parameter
2501 * or a value less than the property minimum it just steps the
2502 * property to its next or previous value respectively.
2503 * Otherwise it sets it to the given value.
2508 /// List of the commands that can be handled by setting a property.
2509 static struct {
2510 /// property name
2511 const char *name;
2512 /// cmd id
2513 int cmd;
2514 /// set/adjust or toggle command
2515 int toggle;
2516 } set_prop_cmd[] = {
2517 // general
2518 { "loop", MP_CMD_LOOP, 0},
2519 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2520 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2521 { "pause", MP_CMD_PAUSE, 0},
2522 { "capturing", MP_CMD_CAPTURING, 1},
2523 // audio
2524 { "volume", MP_CMD_VOLUME, 0},
2525 { "mute", MP_CMD_MUTE, 1},
2526 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2527 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2528 { "balance", MP_CMD_BALANCE, 0},
2529 // video
2530 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2531 { "panscan", MP_CMD_PANSCAN, 0},
2532 { "ontop", MP_CMD_VO_ONTOP, 1},
2533 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2534 { "border", MP_CMD_VO_BORDER, 1},
2535 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2536 { "gamma", MP_CMD_GAMMA, 0},
2537 { "brightness", MP_CMD_BRIGHTNESS, 0},
2538 { "contrast", MP_CMD_CONTRAST, 0},
2539 { "saturation", MP_CMD_SATURATION, 0},
2540 { "hue", MP_CMD_HUE, 0},
2541 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2542 // subs
2543 { "sub", MP_CMD_SUB_SELECT, 1},
2544 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2545 { "sub_vob", MP_CMD_SUB_VOB, 1},
2546 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2547 { "sub_file", MP_CMD_SUB_FILE, 1},
2548 { "sub_pos", MP_CMD_SUB_POS, 0},
2549 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2550 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2551 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2552 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2553 #ifdef CONFIG_FREETYPE
2554 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2555 #endif
2556 #ifdef CONFIG_ASS
2557 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2558 #endif
2559 #ifdef CONFIG_TV
2560 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2561 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2562 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2563 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2564 #endif
2568 /// Handle commands that set a property.
2569 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2571 int i, r;
2572 m_option_t *prop;
2573 const char *pname;
2575 // look for the command
2576 for (i = 0; set_prop_cmd[i].name; i++)
2577 if (set_prop_cmd[i].cmd == cmd->id)
2578 break;
2579 if (!(pname = set_prop_cmd[i].name))
2580 return 0;
2582 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2583 return 0;
2585 // toggle command
2586 if (set_prop_cmd[i].toggle) {
2587 // set to value
2588 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2589 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2590 else if (cmd->nargs > 0)
2591 r = mp_property_do(pname, M_PROPERTY_STEP_DOWN, NULL, mpctx);
2592 else
2593 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2594 } else if (cmd->args[1].v.i) //set
2595 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2596 else // adjust
2597 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2599 if (r <= 0)
2600 return 1;
2602 show_property_osd(mpctx, pname);
2604 return 1;
2607 #ifdef CONFIG_DVDNAV
2608 static const struct {
2609 const char *name;
2610 const mp_command_type cmd;
2611 } mp_dvdnav_bindings[] = {
2612 { "up", MP_CMD_DVDNAV_UP },
2613 { "down", MP_CMD_DVDNAV_DOWN },
2614 { "left", MP_CMD_DVDNAV_LEFT },
2615 { "right", MP_CMD_DVDNAV_RIGHT },
2616 { "menu", MP_CMD_DVDNAV_MENU },
2617 { "select", MP_CMD_DVDNAV_SELECT },
2618 { "prev", MP_CMD_DVDNAV_PREVMENU },
2619 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2622 * keep old dvdnav sub-command options for a while in order not to
2623 * break slave-mode API too suddenly.
2625 { "1", MP_CMD_DVDNAV_UP },
2626 { "2", MP_CMD_DVDNAV_DOWN },
2627 { "3", MP_CMD_DVDNAV_LEFT },
2628 { "4", MP_CMD_DVDNAV_RIGHT },
2629 { "5", MP_CMD_DVDNAV_MENU },
2630 { "6", MP_CMD_DVDNAV_SELECT },
2631 { "7", MP_CMD_DVDNAV_PREVMENU },
2632 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2633 { NULL, 0 }
2635 #endif
2637 static const char *property_error_string(int error_value)
2639 switch (error_value) {
2640 case M_PROPERTY_ERROR:
2641 return "ERROR";
2642 case M_PROPERTY_UNAVAILABLE:
2643 return "PROPERTY_UNAVAILABLE";
2644 case M_PROPERTY_NOT_IMPLEMENTED:
2645 return "NOT_IMPLEMENTED";
2646 case M_PROPERTY_UNKNOWN:
2647 return "PROPERTY_UNKNOWN";
2648 case M_PROPERTY_DISABLED:
2649 return "DISABLED";
2651 return "UNKNOWN";
2654 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2656 int idx;
2657 int end = start + count;
2658 int after = mpctx->set_of_sub_size - end;
2659 sub_data **subs = mpctx->set_of_subtitles;
2660 #ifdef CONFIG_ASS
2661 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2662 #endif
2663 if (count < 0 || count > mpctx->set_of_sub_size ||
2664 start < 0 || start > mpctx->set_of_sub_size - count) {
2665 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2666 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2667 return;
2669 for (idx = start; idx < end; idx++) {
2670 sub_data *subd = subs[idx];
2671 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2672 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2673 filename_recode(subd->filename));
2674 sub_free(subd);
2675 subs[idx] = NULL;
2676 #ifdef CONFIG_ASS
2677 if (ass_tracks[idx])
2678 ass_free_track(ass_tracks[idx]);
2679 ass_tracks[idx] = NULL;
2680 #endif
2683 mpctx->global_sub_size -= count;
2684 mpctx->set_of_sub_size -= count;
2685 if (mpctx->set_of_sub_size <= 0)
2686 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2688 memmove(subs + start, subs + end, after * sizeof(*subs));
2689 memset(subs + start + after, 0, count * sizeof(*subs));
2690 #ifdef CONFIG_ASS
2691 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2692 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2693 #endif
2695 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2696 mpctx->global_sub_pos = -2;
2697 mpctx->subdata = NULL;
2698 mpctx->osd->ass_track = NULL;
2699 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2700 } else if (mpctx->set_of_sub_pos >= end) {
2701 mpctx->set_of_sub_pos -= count;
2702 mpctx->global_sub_pos -= count;
2706 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2708 struct MPOpts *opts = &mpctx->opts;
2709 sh_audio_t * const sh_audio = mpctx->sh_audio;
2710 sh_video_t * const sh_video = mpctx->sh_video;
2711 int osd_duration = opts->osd_duration;
2712 int case_fallthrough_hack = 0;
2713 if (!set_property_command(mpctx, cmd))
2714 switch (cmd->id) {
2715 case MP_CMD_SEEK:{
2716 mpctx->add_osd_seek_info = true;
2717 float v = cmd->args[0].v.f;
2718 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2719 int exact = (cmd->nargs > 2) ? cmd->args[2].v.i : 0;
2720 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2721 queue_seek(mpctx, MPSEEK_ABSOLUTE, v, exact);
2722 mpctx->osd_function = v > get_current_time(mpctx) ?
2723 OSD_FFW : OSD_REW;
2724 } else if (abs) { /* Absolute seek by percentage */
2725 queue_seek(mpctx, MPSEEK_FACTOR, v / 100.0, exact);
2726 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2727 } else {
2728 queue_seek(mpctx, MPSEEK_RELATIVE, v, exact);
2729 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2732 break;
2734 case MP_CMD_SET_PROPERTY_OSD:
2735 case_fallthrough_hack = 1;
2737 case MP_CMD_SET_PROPERTY:{
2738 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2739 cmd->args[1].v.s, mpctx);
2740 if (r == M_PROPERTY_UNKNOWN)
2741 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2742 "Unknown property: '%s'\n", cmd->args[0].v.s);
2743 else if (r <= 0)
2744 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2745 "Failed to set property '%s' to '%s'.\n",
2746 cmd->args[0].v.s, cmd->args[1].v.s);
2747 else if (case_fallthrough_hack)
2748 show_property_osd(mpctx, cmd->args[0].v.s);
2749 if (r <= 0)
2750 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2752 break;
2754 case MP_CMD_STEP_PROPERTY_OSD:
2755 case_fallthrough_hack = 1;
2757 case MP_CMD_STEP_PROPERTY:{
2758 void* arg = NULL;
2759 int r,i;
2760 double d;
2761 off_t o;
2762 if (cmd->args[1].v.f) {
2763 m_option_t* prop;
2764 if((r = mp_property_do(cmd->args[0].v.s,
2765 M_PROPERTY_GET_TYPE,
2766 &prop, mpctx)) <= 0)
2767 goto step_prop_err;
2768 if(prop->type == CONF_TYPE_INT ||
2769 prop->type == CONF_TYPE_FLAG)
2770 i = cmd->args[1].v.f, arg = &i;
2771 else if(prop->type == CONF_TYPE_FLOAT)
2772 arg = &cmd->args[1].v.f;
2773 else if(prop->type == CONF_TYPE_DOUBLE ||
2774 prop->type == CONF_TYPE_TIME)
2775 d = cmd->args[1].v.f, arg = &d;
2776 else if(prop->type == CONF_TYPE_POSITION)
2777 o = cmd->args[1].v.f, arg = &o;
2778 else
2779 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2780 "Ignoring step size stepping property '%s'.\n",
2781 cmd->args[0].v.s);
2783 r = mp_property_do(cmd->args[0].v.s,
2784 cmd->args[2].v.i < 0 ?
2785 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2786 arg, mpctx);
2787 step_prop_err:
2788 if (r == M_PROPERTY_UNKNOWN)
2789 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2790 "Unknown property: '%s'\n", cmd->args[0].v.s);
2791 else if (r <= 0)
2792 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2793 "Failed to increment property '%s' by %f.\n",
2794 cmd->args[0].v.s, cmd->args[1].v.f);
2795 else if (case_fallthrough_hack)
2796 show_property_osd(mpctx, cmd->args[0].v.s);
2797 if (r <= 0)
2798 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2800 break;
2802 case MP_CMD_GET_PROPERTY:{
2803 char *tmp;
2804 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2805 &tmp, mpctx);
2806 if (r <= 0) {
2807 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2808 "Failed to get value of property '%s'.\n",
2809 cmd->args[0].v.s);
2810 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2811 break;
2813 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2814 cmd->args[0].v.s, tmp);
2815 free(tmp);
2817 break;
2819 case MP_CMD_EDL_MARK:
2820 if (edl_fd) {
2821 float v = get_current_time(mpctx);
2822 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2823 mpctx->begin_skip = v;
2824 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2825 } else {
2826 if (mpctx->begin_skip > v)
2827 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2828 else {
2829 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2830 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2832 mpctx->begin_skip = MP_NOPTS_VALUE;
2835 break;
2837 case MP_CMD_SWITCH_RATIO:
2838 if (!sh_video)
2839 break;
2840 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2841 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2842 else
2843 opts->movie_aspect = cmd->args[0].v.f;
2844 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2845 break;
2847 case MP_CMD_SPEED_INCR:{
2848 float v = cmd->args[0].v.f;
2849 mp_property_do("speed", M_PROPERTY_STEP_UP, &v, mpctx);
2850 show_property_osd(mpctx, "speed");
2851 break;
2854 case MP_CMD_SPEED_MULT:
2855 case_fallthrough_hack = true;
2857 case MP_CMD_SPEED_SET:{
2858 float v = cmd->args[0].v.f;
2859 if (case_fallthrough_hack)
2860 v *= mpctx->opts.playback_speed;
2861 mp_property_do("speed", M_PROPERTY_SET, &v, mpctx);
2862 show_property_osd(mpctx, "speed");
2863 break;
2866 case MP_CMD_FRAME_STEP:
2867 add_step_frame(mpctx);
2868 break;
2870 case MP_CMD_FILE_FILTER:
2871 file_filter = cmd->args[0].v.i;
2872 break;
2874 case MP_CMD_QUIT:
2875 exit_player_with_rc(mpctx, EXIT_QUIT,
2876 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2878 case MP_CMD_PLAY_TREE_STEP:{
2879 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2880 int force = cmd->args[1].v.i;
2883 if (!force && mpctx->playtree_iter) {
2884 play_tree_iter_t *i =
2885 play_tree_iter_new_copy(mpctx->playtree_iter);
2886 if (play_tree_iter_step(i, n, 0) ==
2887 PLAY_TREE_ITER_ENTRY)
2888 mpctx->stop_play =
2889 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2890 play_tree_iter_free(i);
2891 } else
2892 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2893 if (mpctx->stop_play)
2894 mpctx->play_tree_step = n;
2897 break;
2899 case MP_CMD_PLAY_TREE_UP_STEP:{
2900 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2901 int force = cmd->args[1].v.i;
2903 if (!force && mpctx->playtree_iter) {
2904 play_tree_iter_t *i =
2905 play_tree_iter_new_copy(mpctx->playtree_iter);
2906 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2907 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2908 play_tree_iter_free(i);
2909 } else
2910 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2912 break;
2914 case MP_CMD_PLAY_ALT_SRC_STEP:
2915 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2916 int v = cmd->args[0].v.i;
2917 if (v > 0
2918 && mpctx->playtree_iter->file <
2919 mpctx->playtree_iter->num_files)
2920 mpctx->stop_play = PT_NEXT_SRC;
2921 else if (v < 0 && mpctx->playtree_iter->file > 1)
2922 mpctx->stop_play = PT_PREV_SRC;
2924 break;
2926 case MP_CMD_SUB_STEP:
2927 if (sh_video) {
2928 int movement = cmd->args[0].v.i;
2929 step_sub(mpctx->subdata, mpctx->video_pts, movement);
2930 #ifdef CONFIG_ASS
2931 if (mpctx->osd->ass_track)
2932 sub_delay +=
2933 ass_step_sub(mpctx->osd->ass_track,
2934 (mpctx->video_pts +
2935 sub_delay) * 1000 + .5, movement) / 1000.;
2936 #endif
2937 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2938 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2940 break;
2942 case MP_CMD_SUB_LOG:
2943 log_sub(mpctx);
2944 break;
2946 case MP_CMD_OSD:{
2947 int v = cmd->args[0].v.i;
2948 int max = (opts->term_osd
2949 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2950 if (opts->osd_level > max)
2951 opts->osd_level = max;
2952 if (v < 0)
2953 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2954 else
2955 opts->osd_level = v > max ? max : v;
2956 /* Show OSD state when disabled, but not when an explicit
2957 argument is given to the OSD command, i.e. in slave mode. */
2958 if (v == -1 && opts->osd_level <= 1)
2959 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2960 "OSD: %s",
2961 opts->osd_level ? mp_gtext("enabled") :
2962 mp_gtext("disabled"));
2963 else
2964 rm_osd_msg(OSD_MSG_OSD_STATUS);
2966 break;
2968 case MP_CMD_OSD_SHOW_TEXT:
2969 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2970 (cmd->args[1].v.i <
2971 0 ? osd_duration : cmd->args[1].v.i),
2972 "%-.63s", cmd->args[0].v.s);
2973 break;
2975 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2976 char *txt = m_properties_expand_string(mp_properties,
2977 cmd->args[0].v.s,
2978 mpctx);
2979 /* if no argument supplied take default osd_duration, else <arg> ms. */
2980 if (txt) {
2981 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2982 (cmd->args[1].v.i <
2983 0 ? osd_duration : cmd->args[1].v.i),
2984 "%-.63s", txt);
2985 free(txt);
2988 break;
2990 case MP_CMD_LOADFILE:{
2991 play_tree_t *e = play_tree_new();
2992 play_tree_add_file(e, cmd->args[0].v.s);
2994 if (cmd->args[1].v.i) // append
2995 play_tree_append_entry(mpctx->playtree->child, e);
2996 else {
2997 // Go back to the starting point.
2998 while (play_tree_iter_up_step
2999 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3000 /* NOP */ ;
3001 play_tree_free_list(mpctx->playtree->child, 1);
3002 play_tree_set_child(mpctx->playtree, e);
3003 pt_iter_goto_head(mpctx->playtree_iter);
3004 mpctx->stop_play = PT_NEXT_SRC;
3007 break;
3009 case MP_CMD_LOADLIST:{
3010 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
3011 if (!e)
3012 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
3013 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
3014 else {
3015 if (cmd->args[1].v.i) // append
3016 play_tree_append_entry(mpctx->playtree->child, e);
3017 else {
3018 // Go back to the starting point.
3019 while (play_tree_iter_up_step
3020 (mpctx->playtree_iter, 0, 1)
3021 != PLAY_TREE_ITER_END)
3022 /* NOP */ ;
3023 play_tree_free_list(mpctx->playtree->child, 1);
3024 play_tree_set_child(mpctx->playtree, e);
3025 pt_iter_goto_head(mpctx->playtree_iter);
3026 mpctx->stop_play = PT_NEXT_SRC;
3030 break;
3032 case MP_CMD_STOP:
3033 // Go back to the starting point.
3034 while (play_tree_iter_up_step
3035 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3036 /* NOP */ ;
3037 mpctx->stop_play = PT_STOP;
3038 break;
3040 case MP_CMD_OSD_SHOW_PROGRESSION:{
3041 int len = get_time_length(mpctx);
3042 int pts = get_current_time(mpctx);
3043 set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3044 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3045 "%c %02d:%02d:%02d / %02d:%02d:%02d",
3046 mpctx->osd_function, pts/3600, (pts/60)%60, pts%60,
3047 len/3600, (len/60)%60, len%60);
3049 break;
3051 #ifdef CONFIG_RADIO
3052 case MP_CMD_RADIO_STEP_CHANNEL:
3053 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3054 int v = cmd->args[0].v.i;
3055 if (v > 0)
3056 radio_step_channel(mpctx->demuxer->stream,
3057 RADIO_CHANNEL_HIGHER);
3058 else
3059 radio_step_channel(mpctx->demuxer->stream,
3060 RADIO_CHANNEL_LOWER);
3061 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3062 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3063 "Channel: %s",
3064 radio_get_channel_name(mpctx->demuxer->stream));
3067 break;
3069 case MP_CMD_RADIO_SET_CHANNEL:
3070 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3071 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3072 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3073 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3074 "Channel: %s",
3075 radio_get_channel_name(mpctx->demuxer->stream));
3078 break;
3080 case MP_CMD_RADIO_SET_FREQ:
3081 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3082 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3083 break;
3085 case MP_CMD_RADIO_STEP_FREQ:
3086 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3087 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3088 break;
3089 #endif
3091 #ifdef CONFIG_TV
3092 case MP_CMD_TV_START_SCAN:
3093 if (mpctx->file_format == DEMUXER_TYPE_TV)
3094 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
3095 break;
3096 case MP_CMD_TV_SET_FREQ:
3097 if (mpctx->file_format == DEMUXER_TYPE_TV)
3098 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3099 cmd->args[0].v.f * 16.0);
3100 #ifdef CONFIG_PVR
3101 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3102 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
3103 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3104 pvr_get_current_channelname (mpctx->stream),
3105 pvr_get_current_stationname (mpctx->stream));
3107 #endif /* CONFIG_PVR */
3108 break;
3110 case MP_CMD_TV_STEP_FREQ:
3111 if (mpctx->file_format == DEMUXER_TYPE_TV)
3112 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3113 cmd->args[0].v.f * 16.0);
3114 #ifdef CONFIG_PVR
3115 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3116 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
3117 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3118 pvr_get_current_channelname (mpctx->stream),
3119 pvr_get_current_frequency (mpctx->stream));
3121 #endif /* CONFIG_PVR */
3122 break;
3124 case MP_CMD_TV_SET_NORM:
3125 if (mpctx->file_format == DEMUXER_TYPE_TV)
3126 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3127 cmd->args[0].v.s);
3128 break;
3130 case MP_CMD_TV_STEP_CHANNEL:{
3131 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3132 int v = cmd->args[0].v.i;
3133 if (v > 0) {
3134 tv_step_channel((tvi_handle_t *) (mpctx->
3135 demuxer->priv),
3136 TV_CHANNEL_HIGHER);
3137 } else {
3138 tv_step_channel((tvi_handle_t *) (mpctx->
3139 demuxer->priv),
3140 TV_CHANNEL_LOWER);
3142 if (tv_channel_list) {
3143 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3144 "Channel: %s", tv_channel_current->name);
3145 //vo_osd_changed(OSDTYPE_SUBTITLE);
3148 #ifdef CONFIG_PVR
3149 else if (mpctx->stream &&
3150 mpctx->stream->type == STREAMTYPE_PVR) {
3151 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3152 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3153 pvr_get_current_channelname (mpctx->stream),
3154 pvr_get_current_stationname (mpctx->stream));
3156 #endif /* CONFIG_PVR */
3158 #ifdef CONFIG_DVBIN
3159 if (mpctx->stream->type == STREAMTYPE_DVB) {
3160 int dir;
3161 int v = cmd->args[0].v.i;
3163 mpctx->last_dvb_step = v;
3164 if (v > 0)
3165 dir = DVB_CHANNEL_HIGHER;
3166 else
3167 dir = DVB_CHANNEL_LOWER;
3170 if (dvb_step_channel(mpctx->stream, dir)) {
3171 mpctx->stop_play = PT_NEXT_ENTRY;
3172 mpctx->dvbin_reopen = 1;
3175 #endif /* CONFIG_DVBIN */
3176 break;
3178 case MP_CMD_TV_SET_CHANNEL:
3179 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3180 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3181 cmd->args[0].v.s);
3182 if (tv_channel_list) {
3183 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3184 "Channel: %s", tv_channel_current->name);
3185 //vo_osd_changed(OSDTYPE_SUBTITLE);
3188 #ifdef CONFIG_PVR
3189 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3190 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3191 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3192 pvr_get_current_channelname (mpctx->stream),
3193 pvr_get_current_stationname (mpctx->stream));
3195 #endif /* CONFIG_PVR */
3196 break;
3198 #ifdef CONFIG_DVBIN
3199 case MP_CMD_DVB_SET_CHANNEL:
3200 if (mpctx->stream->type == STREAMTYPE_DVB) {
3201 mpctx->last_dvb_step = 1;
3203 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3204 cmd->args[0].v.i)) {
3205 mpctx->stop_play = PT_NEXT_ENTRY;
3206 mpctx->dvbin_reopen = 1;
3209 break;
3210 #endif /* CONFIG_DVBIN */
3212 case MP_CMD_TV_LAST_CHANNEL:
3213 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3214 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3215 if (tv_channel_list) {
3216 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3217 "Channel: %s", tv_channel_current->name);
3218 //vo_osd_changed(OSDTYPE_SUBTITLE);
3221 #ifdef CONFIG_PVR
3222 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3223 pvr_set_lastchannel (mpctx->stream);
3224 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3225 pvr_get_current_channelname (mpctx->stream),
3226 pvr_get_current_stationname (mpctx->stream));
3228 #endif /* CONFIG_PVR */
3229 break;
3231 case MP_CMD_TV_STEP_NORM:
3232 if (mpctx->file_format == DEMUXER_TYPE_TV)
3233 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3234 break;
3236 case MP_CMD_TV_STEP_CHANNEL_LIST:
3237 if (mpctx->file_format == DEMUXER_TYPE_TV)
3238 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3239 break;
3240 #endif /* CONFIG_TV */
3241 case MP_CMD_TV_TELETEXT_ADD_DEC:
3242 if (mpctx->demuxer->teletext)
3243 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3244 &(cmd->args[0].v.s));
3245 break;
3246 case MP_CMD_TV_TELETEXT_GO_LINK:
3247 if (mpctx->demuxer->teletext)
3248 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3249 &(cmd->args[0].v.i));
3250 break;
3252 case MP_CMD_SUB_LOAD:
3253 if (sh_video) {
3254 int n = mpctx->set_of_sub_size;
3255 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3256 if (n != mpctx->set_of_sub_size) {
3257 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3258 ++mpctx->global_sub_size;
3261 break;
3263 case MP_CMD_SUB_REMOVE:
3264 if (sh_video) {
3265 int v = cmd->args[0].v.i;
3266 if (v < 0) {
3267 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3268 } else if (v < mpctx->set_of_sub_size) {
3269 remove_subtitle_range(mpctx, v, 1);
3272 break;
3274 case MP_CMD_GET_SUB_VISIBILITY:
3275 if (sh_video) {
3276 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3277 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3279 break;
3281 case MP_CMD_SCREENSHOT:
3282 if (mpctx->video_out && mpctx->video_out->config_ok) {
3283 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3284 if (CONTROL_OK !=
3285 ((vf_instance_t *) sh_video->vfilter)->
3286 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3287 &cmd->args[0].v.i))
3288 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3290 break;
3292 case MP_CMD_VF_CHANGE_RECTANGLE:
3293 if (!sh_video)
3294 break;
3295 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3296 break;
3298 case MP_CMD_GET_TIME_LENGTH:{
3299 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3300 get_time_length(mpctx));
3302 break;
3304 case MP_CMD_GET_FILENAME:{
3305 char *inf = get_metadata(mpctx, META_NAME);
3306 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n", inf);
3307 talloc_free(inf);
3309 break;
3311 case MP_CMD_GET_VIDEO_CODEC:{
3312 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3313 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3314 talloc_free(inf);
3316 break;
3318 case MP_CMD_GET_VIDEO_BITRATE:{
3319 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3320 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3321 talloc_free(inf);
3323 break;
3325 case MP_CMD_GET_VIDEO_RESOLUTION:{
3326 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3327 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3328 talloc_free(inf);
3330 break;
3332 case MP_CMD_GET_AUDIO_CODEC:{
3333 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3334 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3335 talloc_free(inf);
3337 break;
3339 case MP_CMD_GET_AUDIO_BITRATE:{
3340 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3341 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3342 talloc_free(inf);
3344 break;
3346 case MP_CMD_GET_AUDIO_SAMPLES:{
3347 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3348 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3349 talloc_free(inf);
3351 break;
3353 case MP_CMD_GET_META_TITLE:{
3354 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3355 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3356 talloc_free(inf);
3358 break;
3360 case MP_CMD_GET_META_ARTIST:{
3361 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3362 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3363 talloc_free(inf);
3365 break;
3367 case MP_CMD_GET_META_ALBUM:{
3368 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3369 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3370 talloc_free(inf);
3372 break;
3374 case MP_CMD_GET_META_YEAR:{
3375 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3376 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3377 talloc_free(inf);
3379 break;
3381 case MP_CMD_GET_META_COMMENT:{
3382 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3383 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3384 talloc_free(inf);
3386 break;
3388 case MP_CMD_GET_META_TRACK:{
3389 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3390 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3391 talloc_free(inf);
3393 break;
3395 case MP_CMD_GET_META_GENRE:{
3396 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3397 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3398 talloc_free(inf);
3400 break;
3402 case MP_CMD_GET_VO_FULLSCREEN:
3403 if (mpctx->video_out && mpctx->video_out->config_ok)
3404 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3405 break;
3407 case MP_CMD_GET_PERCENT_POS:
3408 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3409 get_percent_pos(mpctx));
3410 break;
3412 case MP_CMD_GET_TIME_POS:{
3413 float pos = get_current_time(mpctx);
3414 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3416 break;
3418 case MP_CMD_RUN:
3419 #ifndef __MINGW32__
3420 if (!fork()) {
3421 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3422 exit(0);
3424 #endif
3425 break;
3427 case MP_CMD_KEYDOWN_EVENTS:
3428 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3429 break;
3431 case MP_CMD_SET_MOUSE_POS:{
3432 int pointer_x, pointer_y;
3433 double dx, dy;
3434 pointer_x = cmd->args[0].v.i;
3435 pointer_y = cmd->args[1].v.i;
3436 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3437 #ifdef CONFIG_DVDNAV
3438 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3439 && dx > 0.0 && dy > 0.0) {
3440 int button = -1;
3441 pointer_x = (int) (dx * (double) sh_video->disp_w);
3442 pointer_y = (int) (dy * (double) sh_video->disp_h);
3443 mp_dvdnav_update_mouse_pos(mpctx->stream,
3444 pointer_x, pointer_y, &button);
3445 if (opts->osd_level > 1 && button > 0)
3446 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3447 "Selected button number %d", button);
3449 #endif
3450 #ifdef CONFIG_MENU
3451 if (use_menu && dx >= 0.0 && dy >= 0.0)
3452 menu_update_mouse_pos(dx, dy);
3453 #endif
3455 break;
3457 #ifdef CONFIG_DVDNAV
3458 case MP_CMD_DVDNAV:{
3459 int button = -1;
3460 int i;
3461 mp_command_type command = 0;
3462 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3463 break;
3465 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3466 if (cmd->args[0].v.s &&
3467 !strcasecmp (cmd->args[0].v.s,
3468 mp_dvdnav_bindings[i].name))
3469 command = mp_dvdnav_bindings[i].cmd;
3471 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3472 if (opts->osd_level > 1 && button > 0)
3473 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3474 "Selected button number %d", button);
3476 break;
3478 case MP_CMD_SWITCH_TITLE:
3479 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3480 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3481 break;
3483 #endif
3485 case MP_CMD_AF_SWITCH:
3486 if (sh_audio)
3488 af_uninit(mpctx->mixer.afilter);
3489 af_init(mpctx->mixer.afilter);
3491 case MP_CMD_AF_ADD:
3492 case MP_CMD_AF_DEL:
3493 if (!sh_audio)
3494 break;
3496 char* af_args = strdup(cmd->args[0].v.s);
3497 char* af_commands = af_args;
3498 char* af_command;
3499 af_instance_t* af;
3500 while ((af_command = strsep(&af_commands, ",")) != NULL)
3502 if (cmd->id == MP_CMD_AF_DEL)
3504 af = af_get(mpctx->mixer.afilter, af_command);
3505 if (af != NULL)
3506 af_remove(mpctx->mixer.afilter, af);
3508 else
3509 af_add(mpctx->mixer.afilter, af_command);
3511 reinit_audio_chain(mpctx);
3512 free(af_args);
3514 break;
3515 case MP_CMD_AF_CLR:
3516 if (!sh_audio)
3517 break;
3518 af_uninit(mpctx->mixer.afilter);
3519 af_init(mpctx->mixer.afilter);
3520 reinit_audio_chain(mpctx);
3521 break;
3522 case MP_CMD_AF_CMDLINE:
3523 if (sh_audio) {
3524 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3525 if (!af) {
3526 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3527 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3528 break;
3530 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3531 af_reinit(sh_audio->afilter, af);
3533 break;
3535 default:
3536 mp_msg(MSGT_CPLAYER, MSGL_V,
3537 "Received unknown cmd %s\n", cmd->name);
3540 switch (cmd->pausing) {
3541 case 1: // "pausing"
3542 pause_player(mpctx);
3543 break;
3544 case 3: // "pausing_toggle"
3545 if (mpctx->paused)
3546 unpause_player(mpctx);
3547 else
3548 pause_player(mpctx);
3549 break;