ao: fix crash after ao init failure (from recent 3a5fd15fa2)
[mplayer/greg.git] / command.c
blobde7f1fbca9645884f3ad0384b76364eb92022947
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 else if (angle > angles)
609 angle = 1;
610 break;
612 default:
613 return M_PROPERTY_NOT_IMPLEMENTED;
615 angle = demuxer_set_angle(mpctx->demuxer, angle);
616 if (angle >= 0) {
617 struct sh_video *sh_video = mpctx->demuxer->video->sh;
618 if (sh_video)
619 resync_video_stream(sh_video);
621 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
622 if (sh_audio)
623 resync_audio_stream(sh_audio);
626 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
627 "Angle: %d/%d", angle, angles);
628 free(angle_name);
629 return M_PROPERTY_OK;
632 /// Demuxer meta data
633 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
634 MPContext *mpctx) {
635 m_property_action_t* ka;
636 char* meta;
637 static const m_option_t key_type =
638 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
639 if (!mpctx->demuxer)
640 return M_PROPERTY_UNAVAILABLE;
642 switch(action) {
643 case M_PROPERTY_GET:
644 if(!arg) return M_PROPERTY_ERROR;
645 *(char***)arg = mpctx->demuxer->info;
646 return M_PROPERTY_OK;
647 case M_PROPERTY_KEY_ACTION:
648 if(!arg) return M_PROPERTY_ERROR;
649 ka = arg;
650 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
651 return M_PROPERTY_UNKNOWN;
652 switch(ka->action) {
653 case M_PROPERTY_GET:
654 if(!ka->arg) return M_PROPERTY_ERROR;
655 *(char**)ka->arg = meta;
656 return M_PROPERTY_OK;
657 case M_PROPERTY_GET_TYPE:
658 if(!ka->arg) return M_PROPERTY_ERROR;
659 *(const m_option_t**)ka->arg = &key_type;
660 return M_PROPERTY_OK;
663 return M_PROPERTY_NOT_IMPLEMENTED;
666 static int mp_property_pause(m_option_t *prop, int action, void *arg,
667 void *ctx)
669 MPContext *mpctx = ctx;
671 switch (action) {
672 case M_PROPERTY_SET:
673 if (!arg)
674 return M_PROPERTY_ERROR;
675 if (mpctx->paused == (bool)*(int *) arg)
676 return M_PROPERTY_OK;
677 case M_PROPERTY_STEP_UP:
678 case M_PROPERTY_STEP_DOWN:
679 if (mpctx->paused) {
680 unpause_player(mpctx);
681 mpctx->osd_function = OSD_PLAY;
683 else {
684 pause_player(mpctx);
685 mpctx->osd_function = OSD_PAUSE;
687 return M_PROPERTY_OK;
688 default:
689 return m_property_flag(prop, action, arg, &mpctx->paused);
694 ///@}
696 /// \defgroup AudioProperties Audio properties
697 /// \ingroup Properties
698 ///@{
700 /// Volume (RW)
701 static int mp_property_volume(m_option_t *prop, int action, void *arg,
702 MPContext *mpctx)
705 if (!mpctx->sh_audio)
706 return M_PROPERTY_UNAVAILABLE;
708 switch (action) {
709 case M_PROPERTY_GET:
710 if (!arg)
711 return M_PROPERTY_ERROR;
712 mixer_getbothvolume(&mpctx->mixer, arg);
713 return M_PROPERTY_OK;
714 case M_PROPERTY_PRINT:{
715 float vol;
716 if (!arg)
717 return M_PROPERTY_ERROR;
718 mixer_getbothvolume(&mpctx->mixer, &vol);
719 return m_property_float_range(prop, action, arg, &vol);
721 case M_PROPERTY_STEP_UP:
722 case M_PROPERTY_STEP_DOWN:
723 case M_PROPERTY_SET:
724 break;
725 default:
726 return M_PROPERTY_NOT_IMPLEMENTED;
729 if (mpctx->edl_muted)
730 return M_PROPERTY_DISABLED;
731 mpctx->user_muted = 0;
733 switch (action) {
734 case M_PROPERTY_SET:
735 if (!arg)
736 return M_PROPERTY_ERROR;
737 M_PROPERTY_CLAMP(prop, *(float *) arg);
738 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
739 return M_PROPERTY_OK;
740 case M_PROPERTY_STEP_UP:
741 if (arg && *(float *) arg <= 0)
742 mixer_decvolume(&mpctx->mixer);
743 else
744 mixer_incvolume(&mpctx->mixer);
745 return M_PROPERTY_OK;
746 case M_PROPERTY_STEP_DOWN:
747 if (arg && *(float *) arg <= 0)
748 mixer_incvolume(&mpctx->mixer);
749 else
750 mixer_decvolume(&mpctx->mixer);
751 return M_PROPERTY_OK;
753 return M_PROPERTY_NOT_IMPLEMENTED;
756 /// Mute (RW)
757 static int mp_property_mute(m_option_t *prop, int action, void *arg,
758 MPContext *mpctx)
761 if (!mpctx->sh_audio)
762 return M_PROPERTY_UNAVAILABLE;
764 switch (action) {
765 case M_PROPERTY_SET:
766 if (mpctx->edl_muted)
767 return M_PROPERTY_DISABLED;
768 if (!arg)
769 return M_PROPERTY_ERROR;
770 if ((!!*(int *) arg) != mpctx->mixer.muted)
771 mixer_mute(&mpctx->mixer);
772 mpctx->user_muted = mpctx->mixer.muted;
773 return M_PROPERTY_OK;
774 case M_PROPERTY_STEP_UP:
775 case M_PROPERTY_STEP_DOWN:
776 if (mpctx->edl_muted)
777 return M_PROPERTY_DISABLED;
778 mixer_mute(&mpctx->mixer);
779 mpctx->user_muted = mpctx->mixer.muted;
780 return M_PROPERTY_OK;
781 case M_PROPERTY_PRINT:
782 if (!arg)
783 return M_PROPERTY_ERROR;
784 if (mpctx->edl_muted) {
785 *(char **) arg = strdup(mp_gtext("enabled (EDL)"));
786 return M_PROPERTY_OK;
788 default:
789 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
794 /// Audio delay (RW)
795 static int mp_property_audio_delay(m_option_t *prop, int action,
796 void *arg, MPContext *mpctx)
798 if (!(mpctx->sh_audio && mpctx->sh_video))
799 return M_PROPERTY_UNAVAILABLE;
800 switch (action) {
801 case M_PROPERTY_SET:
802 case M_PROPERTY_STEP_UP:
803 case M_PROPERTY_STEP_DOWN: {
804 int ret;
805 float delay = audio_delay;
806 ret = m_property_delay(prop, action, arg, &audio_delay);
807 if (ret != M_PROPERTY_OK)
808 return ret;
809 if (mpctx->sh_audio)
810 mpctx->delay -= audio_delay - delay;
812 return M_PROPERTY_OK;
813 default:
814 return m_property_delay(prop, action, arg, &audio_delay);
818 /// Audio codec tag (RO)
819 static int mp_property_audio_format(m_option_t *prop, int action,
820 void *arg, MPContext *mpctx)
822 if (!mpctx->sh_audio)
823 return M_PROPERTY_UNAVAILABLE;
824 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
827 /// Audio codec name (RO)
828 static int mp_property_audio_codec(m_option_t *prop, int action,
829 void *arg, MPContext *mpctx)
831 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
832 return M_PROPERTY_UNAVAILABLE;
833 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
836 /// Audio bitrate (RO)
837 static int mp_property_audio_bitrate(m_option_t *prop, int action,
838 void *arg, MPContext *mpctx)
840 if (!mpctx->sh_audio)
841 return M_PROPERTY_UNAVAILABLE;
842 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
845 /// Samplerate (RO)
846 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
847 MPContext *mpctx)
849 if (!mpctx->sh_audio)
850 return M_PROPERTY_UNAVAILABLE;
851 switch(action) {
852 case M_PROPERTY_PRINT:
853 if(!arg) return M_PROPERTY_ERROR;
854 *(char**)arg = malloc(16);
855 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
856 return M_PROPERTY_OK;
858 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
861 /// Number of channels (RO)
862 static int mp_property_channels(m_option_t *prop, int action, void *arg,
863 MPContext *mpctx)
865 if (!mpctx->sh_audio)
866 return M_PROPERTY_UNAVAILABLE;
867 switch (action) {
868 case M_PROPERTY_PRINT:
869 if (!arg)
870 return M_PROPERTY_ERROR;
871 switch (mpctx->sh_audio->channels) {
872 case 1:
873 *(char **) arg = strdup("mono");
874 break;
875 case 2:
876 *(char **) arg = strdup("stereo");
877 break;
878 default:
879 *(char **) arg = malloc(32);
880 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
882 return M_PROPERTY_OK;
884 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
887 /// Balance (RW)
888 static int mp_property_balance(m_option_t *prop, int action, void *arg,
889 MPContext *mpctx)
891 float bal;
893 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
894 return M_PROPERTY_UNAVAILABLE;
896 switch (action) {
897 case M_PROPERTY_GET:
898 if (!arg)
899 return M_PROPERTY_ERROR;
900 mixer_getbalance(&mpctx->mixer, arg);
901 return M_PROPERTY_OK;
902 case M_PROPERTY_PRINT: {
903 char** str = arg;
904 if (!arg)
905 return M_PROPERTY_ERROR;
906 mixer_getbalance(&mpctx->mixer, &bal);
907 if (bal == 0.f)
908 *str = strdup("center");
909 else if (bal == -1.f)
910 *str = strdup("left only");
911 else if (bal == 1.f)
912 *str = strdup("right only");
913 else {
914 unsigned right = (bal + 1.f) / 2.f * 100.f;
915 *str = malloc(sizeof("left xxx%, right xxx%"));
916 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
918 return M_PROPERTY_OK;
920 case M_PROPERTY_STEP_UP:
921 case M_PROPERTY_STEP_DOWN:
922 mixer_getbalance(&mpctx->mixer, &bal);
923 bal += (arg ? *(float*)arg : .1f) *
924 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
925 M_PROPERTY_CLAMP(prop, bal);
926 mixer_setbalance(&mpctx->mixer, bal);
927 return M_PROPERTY_OK;
928 case M_PROPERTY_SET:
929 if (!arg)
930 return M_PROPERTY_ERROR;
931 M_PROPERTY_CLAMP(prop, *(float*)arg);
932 mixer_setbalance(&mpctx->mixer, *(float*)arg);
933 return M_PROPERTY_OK;
935 return M_PROPERTY_NOT_IMPLEMENTED;
938 /// Selected audio id (RW)
939 static int mp_property_audio(m_option_t *prop, int action, void *arg,
940 MPContext *mpctx)
942 int current_id, tmp;
943 if (!mpctx->demuxer || !mpctx->d_audio)
944 return M_PROPERTY_UNAVAILABLE;
945 current_id = mpctx->sh_audio ? mpctx->sh_audio->aid : -2;
947 switch (action) {
948 case M_PROPERTY_GET:
949 if (!arg)
950 return M_PROPERTY_ERROR;
951 *(int *) arg = current_id;
952 return M_PROPERTY_OK;
953 case M_PROPERTY_PRINT:
954 if (!arg)
955 return M_PROPERTY_ERROR;
957 if (current_id < 0)
958 *(char **) arg = strdup(mp_gtext("disabled"));
959 else {
960 char lang[40];
961 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
962 sh_audio_t* sh = mpctx->sh_audio;
963 if (sh && sh->lang)
964 av_strlcpy(lang, sh->lang, 40);
965 #ifdef CONFIG_DVDREAD
966 else if (mpctx->stream->type == STREAMTYPE_DVD) {
967 int code = dvd_lang_from_aid(mpctx->stream, current_id);
968 if (code) {
969 lang[0] = code >> 8;
970 lang[1] = code;
971 lang[2] = 0;
974 #endif
976 #ifdef CONFIG_DVDNAV
977 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
978 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
979 #endif
980 *(char **) arg = malloc(64);
981 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
983 return M_PROPERTY_OK;
985 case M_PROPERTY_STEP_UP:
986 case M_PROPERTY_SET:
987 if (action == M_PROPERTY_SET && arg)
988 tmp = *((int *) arg);
989 else
990 tmp = -1;
991 int new_id = demuxer_switch_audio(mpctx->d_audio->demuxer, tmp);
992 if (new_id != current_id)
993 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
994 if (new_id != current_id && new_id >= 0) {
995 sh_audio_t *sh2;
996 sh2 = mpctx->d_audio->demuxer->a_streams[mpctx->d_audio->id];
997 sh2->ds = mpctx->d_audio;
998 mpctx->sh_audio = sh2;
999 reinit_audio_chain(mpctx);
1001 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
1002 return M_PROPERTY_OK;
1003 default:
1004 return M_PROPERTY_NOT_IMPLEMENTED;
1009 /// Selected video id (RW)
1010 static int mp_property_video(m_option_t *prop, int action, void *arg,
1011 MPContext *mpctx)
1013 struct MPOpts *opts = &mpctx->opts;
1014 int current_id, tmp;
1015 if (!mpctx->demuxer || !mpctx->d_video)
1016 return M_PROPERTY_UNAVAILABLE;
1017 current_id = mpctx->sh_video ? mpctx->sh_video->vid : -2;
1019 switch (action) {
1020 case M_PROPERTY_GET:
1021 if (!arg)
1022 return M_PROPERTY_ERROR;
1023 *(int *) arg = current_id;
1024 return M_PROPERTY_OK;
1025 case M_PROPERTY_PRINT:
1026 if (!arg)
1027 return M_PROPERTY_ERROR;
1029 if (current_id < 0)
1030 *(char **) arg = strdup(mp_gtext("disabled"));
1031 else {
1032 char lang[40];
1033 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
1034 *(char **) arg = malloc(64);
1035 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
1037 return M_PROPERTY_OK;
1039 case M_PROPERTY_STEP_UP:
1040 case M_PROPERTY_SET:
1041 if (action == M_PROPERTY_SET && arg)
1042 tmp = *((int *) arg);
1043 else
1044 tmp = -1;
1045 int new_id = demuxer_switch_video(mpctx->d_video->demuxer, tmp);
1046 if (new_id != current_id)
1047 uninit_player(mpctx, INITIALIZED_VCODEC |
1048 (opts->fixed_vo && new_id >= 0 ? 0 : INITIALIZED_VO));
1049 if (new_id != current_id && new_id >= 0) {
1050 sh_video_t *sh2;
1051 sh2 = mpctx->d_video->demuxer->v_streams[mpctx->d_video->id];
1052 sh2->ds = mpctx->d_video;
1053 mpctx->sh_video = sh2;
1054 reinit_video_chain(mpctx);
1056 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", new_id);
1057 return M_PROPERTY_OK;
1059 default:
1060 return M_PROPERTY_NOT_IMPLEMENTED;
1064 static int mp_property_program(m_option_t *prop, int action, void *arg,
1065 MPContext *mpctx)
1067 demux_program_t prog;
1069 switch (action) {
1070 case M_PROPERTY_STEP_UP:
1071 case M_PROPERTY_SET:
1072 if (action == M_PROPERTY_SET && arg)
1073 prog.progid = *((int *) arg);
1074 else
1075 prog.progid = -1;
1076 if (demux_control
1077 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1078 &prog) == DEMUXER_CTRL_NOTIMPL)
1079 return M_PROPERTY_ERROR;
1081 if (prog.aid < 0 && prog.vid < 0) {
1082 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
1083 return M_PROPERTY_ERROR;
1085 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1086 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1087 return M_PROPERTY_OK;
1089 default:
1090 return M_PROPERTY_NOT_IMPLEMENTED;
1094 ///@}
1096 /// \defgroup VideoProperties Video properties
1097 /// \ingroup Properties
1098 ///@{
1100 /// Fullscreen state (RW)
1101 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1102 MPContext *mpctx)
1105 if (!mpctx->video_out)
1106 return M_PROPERTY_UNAVAILABLE;
1108 switch (action) {
1109 case M_PROPERTY_SET:
1110 if (!arg)
1111 return M_PROPERTY_ERROR;
1112 M_PROPERTY_CLAMP(prop, *(int *) arg);
1113 if (vo_fs == !!*(int *) arg)
1114 return M_PROPERTY_OK;
1115 case M_PROPERTY_STEP_UP:
1116 case M_PROPERTY_STEP_DOWN:
1117 if (mpctx->video_out->config_ok)
1118 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1119 mpctx->opts.fullscreen = vo_fs;
1120 return M_PROPERTY_OK;
1121 default:
1122 return m_property_flag(prop, action, arg, &vo_fs);
1126 static int mp_property_deinterlace(m_option_t *prop, int action,
1127 void *arg, MPContext *mpctx)
1129 int deinterlace;
1130 vf_instance_t *vf;
1131 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1132 return M_PROPERTY_UNAVAILABLE;
1133 vf = mpctx->sh_video->vfilter;
1134 switch (action) {
1135 case M_PROPERTY_GET:
1136 if (!arg)
1137 return M_PROPERTY_ERROR;
1138 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1139 return M_PROPERTY_OK;
1140 case M_PROPERTY_SET:
1141 if (!arg)
1142 return M_PROPERTY_ERROR;
1143 M_PROPERTY_CLAMP(prop, *(int *) arg);
1144 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1145 return M_PROPERTY_OK;
1146 case M_PROPERTY_STEP_UP:
1147 case M_PROPERTY_STEP_DOWN:
1148 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1149 deinterlace = !deinterlace;
1150 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1151 return M_PROPERTY_OK;
1153 int value = 0;
1154 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1155 return m_property_flag_ro(prop, action, arg, value);
1158 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1159 void *arg, MPContext *mpctx)
1161 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1162 return M_PROPERTY_UNAVAILABLE;
1164 struct vf_instance *vf = mpctx->sh_video->vfilter;
1165 int colorspace;
1166 switch (action) {
1167 case M_PROPERTY_GET:
1168 if (!arg)
1169 return M_PROPERTY_ERROR;
1170 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1171 return M_PROPERTY_UNAVAILABLE;
1172 return M_PROPERTY_OK;
1173 case M_PROPERTY_PRINT:
1174 if (!arg)
1175 return M_PROPERTY_ERROR;
1176 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1177 return M_PROPERTY_UNAVAILABLE;
1178 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1179 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1180 *(char **)arg = strdup("Unknown");
1181 else
1182 *(char**)arg = strdup(names[colorspace]);
1183 return M_PROPERTY_OK;
1184 case M_PROPERTY_SET:
1185 if (!arg)
1186 return M_PROPERTY_ERROR;
1187 M_PROPERTY_CLAMP(prop, *(int *) arg);
1188 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1189 return M_PROPERTY_OK;
1190 case M_PROPERTY_STEP_UP:;
1191 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1192 return M_PROPERTY_UNAVAILABLE;
1193 colorspace += 1;
1194 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1195 return M_PROPERTY_OK;
1197 return M_PROPERTY_NOT_IMPLEMENTED;
1200 static int mp_property_capture(m_option_t *prop, int action,
1201 void *arg, MPContext *mpctx)
1203 struct MPOpts *opts = &mpctx->opts;
1205 if (!mpctx->stream)
1206 return M_PROPERTY_UNAVAILABLE;
1208 if (!opts->capture_dump) {
1209 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1210 "Capturing not enabled (forgot -capture parameter?)\n");
1211 return M_PROPERTY_ERROR;
1214 int capturing = !!mpctx->stream->capture_file;
1216 int ret = m_property_flag(prop, action, arg, &capturing);
1217 if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
1218 if (capturing) {
1219 mpctx->stream->capture_file = fopen(opts->stream_dump_name, "wb");
1220 if (!mpctx->stream->capture_file) {
1221 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1222 "Error opening capture file: %s\n", strerror(errno));
1223 ret = M_PROPERTY_ERROR;
1225 } else {
1226 fclose(mpctx->stream->capture_file);
1227 mpctx->stream->capture_file = NULL;
1231 return ret;
1234 /// Panscan (RW)
1235 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1236 MPContext *mpctx)
1239 if (!mpctx->video_out
1240 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1241 return M_PROPERTY_UNAVAILABLE;
1243 switch (action) {
1244 case M_PROPERTY_SET:
1245 if (!arg)
1246 return M_PROPERTY_ERROR;
1247 M_PROPERTY_CLAMP(prop, *(float *) arg);
1248 vo_panscan = *(float *) arg;
1249 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1250 return M_PROPERTY_OK;
1251 case M_PROPERTY_STEP_UP:
1252 case M_PROPERTY_STEP_DOWN:
1253 vo_panscan += (arg ? *(float *) arg : 0.1) *
1254 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1255 if (vo_panscan > 1)
1256 vo_panscan = 1;
1257 else if (vo_panscan < 0)
1258 vo_panscan = 0;
1259 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1260 return M_PROPERTY_OK;
1261 default:
1262 return m_property_float_range(prop, action, arg, &vo_panscan);
1266 /// Helper to set vo flags.
1267 /** \ingroup PropertyImplHelper
1269 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1270 int vo_ctrl, int *vo_var, MPContext *mpctx)
1273 if (!mpctx->video_out)
1274 return M_PROPERTY_UNAVAILABLE;
1276 switch (action) {
1277 case M_PROPERTY_SET:
1278 if (!arg)
1279 return M_PROPERTY_ERROR;
1280 M_PROPERTY_CLAMP(prop, *(int *) arg);
1281 if (*vo_var == !!*(int *) arg)
1282 return M_PROPERTY_OK;
1283 case M_PROPERTY_STEP_UP:
1284 case M_PROPERTY_STEP_DOWN:
1285 if (mpctx->video_out->config_ok)
1286 vo_control(mpctx->video_out, vo_ctrl, 0);
1287 return M_PROPERTY_OK;
1288 default:
1289 return m_property_flag(prop, action, arg, vo_var);
1293 /// Window always on top (RW)
1294 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1295 MPContext *mpctx)
1297 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1298 &mpctx->opts.vo_ontop, mpctx);
1301 /// Display in the root window (RW)
1302 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1303 MPContext *mpctx)
1305 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1306 &vo_rootwin, mpctx);
1309 /// Show window borders (RW)
1310 static int mp_property_border(m_option_t *prop, int action, void *arg,
1311 MPContext *mpctx)
1313 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1314 &vo_border, mpctx);
1317 /// Framedropping state (RW)
1318 static int mp_property_framedropping(m_option_t *prop, int action,
1319 void *arg, MPContext *mpctx)
1322 if (!mpctx->sh_video)
1323 return M_PROPERTY_UNAVAILABLE;
1325 switch (action) {
1326 case M_PROPERTY_PRINT:
1327 if (!arg)
1328 return M_PROPERTY_ERROR;
1329 *(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
1330 (frame_dropping == 2 ? mp_gtext("hard") :
1331 mp_gtext("disabled")));
1332 return M_PROPERTY_OK;
1333 default:
1334 return m_property_choice(prop, action, arg, &frame_dropping);
1338 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1339 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1340 MPContext *mpctx)
1342 int *gamma = (int *)((char *)&mpctx->opts + prop->offset);
1343 int r, val;
1345 if (!mpctx->sh_video)
1346 return M_PROPERTY_UNAVAILABLE;
1348 if (gamma[0] == 1000) {
1349 gamma[0] = 0;
1350 get_video_colors(mpctx->sh_video, prop->name, gamma);
1353 switch (action) {
1354 case M_PROPERTY_SET:
1355 if (!arg)
1356 return M_PROPERTY_ERROR;
1357 M_PROPERTY_CLAMP(prop, *(int *) arg);
1358 *gamma = *(int *) arg;
1359 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1360 if (r <= 0)
1361 break;
1362 return r;
1363 case M_PROPERTY_GET:
1364 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1365 if (!arg)
1366 return M_PROPERTY_ERROR;
1367 *(int *)arg = val;
1368 return M_PROPERTY_OK;
1370 break;
1371 case M_PROPERTY_STEP_UP:
1372 case M_PROPERTY_STEP_DOWN:
1373 *gamma += (arg ? *(int *) arg : 1) *
1374 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1375 M_PROPERTY_CLAMP(prop, *gamma);
1376 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1377 if (r <= 0)
1378 break;
1379 return r;
1380 default:
1381 return M_PROPERTY_NOT_IMPLEMENTED;
1384 #ifdef CONFIG_TV
1385 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1386 int l = strlen(prop->name);
1387 char tv_prop[3 + l + 1];
1388 sprintf(tv_prop, "tv_%s", prop->name);
1389 return mp_property_do(tv_prop, action, arg, mpctx);
1391 #endif
1393 return M_PROPERTY_UNAVAILABLE;
1396 /// VSync (RW)
1397 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1398 MPContext *mpctx)
1400 return m_property_flag(prop, action, arg, &vo_vsync);
1403 /// Video codec tag (RO)
1404 static int mp_property_video_format(m_option_t *prop, int action,
1405 void *arg, MPContext *mpctx)
1407 char* meta;
1408 if (!mpctx->sh_video)
1409 return M_PROPERTY_UNAVAILABLE;
1410 switch(action) {
1411 case M_PROPERTY_PRINT:
1412 if (!arg)
1413 return M_PROPERTY_ERROR;
1414 switch(mpctx->sh_video->format) {
1415 case 0x10000001:
1416 meta = strdup ("mpeg1"); break;
1417 case 0x10000002:
1418 meta = strdup ("mpeg2"); break;
1419 case 0x10000004:
1420 meta = strdup ("mpeg4"); break;
1421 case 0x10000005:
1422 meta = strdup ("h264"); break;
1423 default:
1424 if(mpctx->sh_video->format >= 0x20202020) {
1425 meta = malloc(5);
1426 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1427 } else {
1428 meta = malloc(20);
1429 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1432 *(char**)arg = meta;
1433 return M_PROPERTY_OK;
1435 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1438 /// Video codec name (RO)
1439 static int mp_property_video_codec(m_option_t *prop, int action,
1440 void *arg, MPContext *mpctx)
1442 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1443 return M_PROPERTY_UNAVAILABLE;
1444 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1448 /// Video bitrate (RO)
1449 static int mp_property_video_bitrate(m_option_t *prop, int action,
1450 void *arg, MPContext *mpctx)
1452 if (!mpctx->sh_video)
1453 return M_PROPERTY_UNAVAILABLE;
1454 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1457 /// Video display width (RO)
1458 static int mp_property_width(m_option_t *prop, int action, void *arg,
1459 MPContext *mpctx)
1461 if (!mpctx->sh_video)
1462 return M_PROPERTY_UNAVAILABLE;
1463 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1466 /// Video display height (RO)
1467 static int mp_property_height(m_option_t *prop, int action, void *arg,
1468 MPContext *mpctx)
1470 if (!mpctx->sh_video)
1471 return M_PROPERTY_UNAVAILABLE;
1472 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1475 /// Video fps (RO)
1476 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1477 MPContext *mpctx)
1479 if (!mpctx->sh_video)
1480 return M_PROPERTY_UNAVAILABLE;
1481 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1484 /// Video aspect (RO)
1485 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1486 MPContext *mpctx)
1488 if (!mpctx->sh_video)
1489 return M_PROPERTY_UNAVAILABLE;
1490 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1493 ///@}
1495 /// \defgroup SubProprties Subtitles properties
1496 /// \ingroup Properties
1497 ///@{
1499 /// Text subtitle position (RW)
1500 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1501 MPContext *mpctx)
1503 switch (action) {
1504 case M_PROPERTY_SET:
1505 if (!arg)
1506 return M_PROPERTY_ERROR;
1507 case M_PROPERTY_STEP_UP:
1508 case M_PROPERTY_STEP_DOWN:
1509 vo_osd_changed(OSDTYPE_SUBTITLE);
1510 default:
1511 return m_property_int_range(prop, action, arg, &sub_pos);
1515 /// Selected subtitles (RW)
1516 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1517 MPContext *mpctx)
1519 struct MPOpts *opts = &mpctx->opts;
1520 demux_stream_t *const d_sub = mpctx->d_sub;
1521 int source = -1, reset_spu = 0;
1522 int source_pos = -1;
1524 update_global_sub_size(mpctx);
1525 const int global_sub_size = mpctx->global_sub_size;
1527 if (global_sub_size <= 0)
1528 return M_PROPERTY_UNAVAILABLE;
1530 switch (action) {
1531 case M_PROPERTY_GET:
1532 if (!arg)
1533 return M_PROPERTY_ERROR;
1534 *(int *) arg = mpctx->global_sub_pos;
1535 return M_PROPERTY_OK;
1536 case M_PROPERTY_PRINT:
1537 if (!arg)
1538 return M_PROPERTY_ERROR;
1539 *(char **) arg = malloc(64);
1540 (*(char **) arg)[63] = 0;
1541 char *sub_name = NULL;
1542 if (mpctx->subdata)
1543 sub_name = mpctx->subdata->filename;
1544 #ifdef CONFIG_ASS
1545 if (mpctx->osd->ass_track)
1546 sub_name = mpctx->osd->ass_track->name;
1547 #endif
1548 if (!sub_name && mpctx->subdata)
1549 sub_name = mpctx->subdata->filename;
1550 if (sub_name) {
1551 const char *tmp = mp_basename(sub_name);
1553 snprintf(*(char **) arg, 63, "(%d) %s%s",
1554 mpctx->set_of_sub_pos + 1,
1555 strlen(tmp) < 20 ? "" : "...",
1556 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1557 return M_PROPERTY_OK;
1559 #ifdef CONFIG_DVDNAV
1560 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1561 if (vo_spudec && opts->sub_id >= 0) {
1562 unsigned char lang[3];
1563 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1564 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1565 return M_PROPERTY_OK;
1569 #endif
1571 if ((d_sub->demuxer->type == DEMUXER_TYPE_MATROSKA
1572 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF
1573 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1574 || d_sub->demuxer->type == DEMUXER_TYPE_OGG)
1575 && d_sub->sh && opts->sub_id >= 0) {
1576 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1577 if (!lang) lang = mp_gtext("unknown");
1578 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1579 return M_PROPERTY_OK;
1582 if (vo_vobsub && vobsub_id >= 0) {
1583 const char *language = mp_gtext("unknown");
1584 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1585 snprintf(*(char **) arg, 63, "(%d) %s",
1586 vobsub_id, language ? language : mp_gtext("unknown"));
1587 return M_PROPERTY_OK;
1589 #ifdef CONFIG_DVDREAD
1590 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1591 && opts->sub_id >= 0) {
1592 char lang[3];
1593 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1594 lang[0] = code >> 8;
1595 lang[1] = code;
1596 lang[2] = 0;
1597 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1598 return M_PROPERTY_OK;
1600 #endif
1601 if (opts->sub_id >= 0) {
1602 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
1603 mp_gtext("unknown"));
1604 return M_PROPERTY_OK;
1606 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1607 return M_PROPERTY_OK;
1609 case M_PROPERTY_SET:
1610 if (!arg)
1611 return M_PROPERTY_ERROR;
1612 if (*(int *) arg < -1)
1613 *(int *) arg = -1;
1614 else if (*(int *) arg >= global_sub_size)
1615 *(int *) arg = global_sub_size - 1;
1616 mpctx->global_sub_pos = *(int *) arg;
1617 break;
1618 case M_PROPERTY_STEP_UP:
1619 mpctx->global_sub_pos += 2;
1620 mpctx->global_sub_pos =
1621 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1622 break;
1623 case M_PROPERTY_STEP_DOWN:
1624 mpctx->global_sub_pos += global_sub_size + 1;
1625 mpctx->global_sub_pos =
1626 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1627 break;
1628 default:
1629 return M_PROPERTY_NOT_IMPLEMENTED;
1632 if (mpctx->global_sub_pos >= 0) {
1633 source = sub_source(mpctx);
1634 source_pos = sub_source_pos(mpctx);
1637 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1638 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1639 global_sub_size,
1640 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1641 mpctx->sub_counts[SUB_SOURCE_SUBS],
1642 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1643 mpctx->global_sub_pos, source);
1645 mpctx->set_of_sub_pos = -1;
1646 mpctx->subdata = NULL;
1648 vobsub_id = -1;
1649 opts->sub_id = -1;
1650 if (d_sub) {
1651 if (d_sub->id > -2)
1652 reset_spu = 1;
1653 d_sub->id = -2;
1655 mpctx->osd->ass_track = NULL;
1656 uninit_player(mpctx, INITIALIZED_SUB);
1658 if (source == SUB_SOURCE_VOBSUB) {
1659 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1660 } else if (source == SUB_SOURCE_SUBS) {
1661 mpctx->set_of_sub_pos = source_pos;
1662 #ifdef CONFIG_ASS
1663 if (opts->ass_enabled
1664 && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]) {
1665 mpctx->osd->ass_track =
1666 mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1667 mpctx->osd->ass_track_changed = true;
1668 mpctx->osd->vsfilter_aspect =
1669 mpctx->track_was_native_ass[mpctx->set_of_sub_pos];
1670 } else
1671 #endif
1673 mpctx->subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1674 vo_osd_changed(OSDTYPE_SUBTITLE);
1676 } else if (source == SUB_SOURCE_DEMUX) {
1677 opts->sub_id = source_pos;
1678 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1679 int i = 0;
1680 // default: assume 1:1 mapping of sid and stream id
1681 d_sub->id = opts->sub_id;
1682 d_sub->sh = mpctx->d_sub->demuxer->s_streams[d_sub->id];
1683 ds_free_packs(d_sub);
1684 for (i = 0; i < MAX_S_STREAMS; i++) {
1685 sh_sub_t *sh = mpctx->d_sub->demuxer->s_streams[i];
1686 if (sh && sh->sid == opts->sub_id) {
1687 d_sub->id = i;
1688 d_sub->sh = sh;
1689 break;
1692 if (d_sub->sh && d_sub->id >= 0) {
1693 sh_sub_t *sh = d_sub->sh;
1694 if (sh->type == 'v')
1695 init_vo_spudec(mpctx);
1696 else {
1697 sub_init(sh, mpctx->osd);
1698 mpctx->initialized_flags |= INITIALIZED_SUB;
1700 } else {
1701 d_sub->id = -2;
1702 d_sub->sh = NULL;
1706 #ifdef CONFIG_DVDREAD
1707 if (vo_spudec
1708 && (mpctx->stream->type == STREAMTYPE_DVD
1709 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1710 && opts->sub_id < 0 && reset_spu) {
1711 d_sub->id = -2;
1712 d_sub->sh = NULL;
1714 #endif
1716 update_subtitles(mpctx, 0, 0, true);
1718 return M_PROPERTY_OK;
1721 /// Selected sub source (RW)
1722 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1723 MPContext *mpctx)
1725 int source;
1726 update_global_sub_size(mpctx);
1727 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1728 return M_PROPERTY_UNAVAILABLE;
1730 switch (action) {
1731 case M_PROPERTY_GET:
1732 if (!arg)
1733 return M_PROPERTY_ERROR;
1734 *(int *) arg = sub_source(mpctx);
1735 return M_PROPERTY_OK;
1736 case M_PROPERTY_PRINT:
1737 if (!arg)
1738 return M_PROPERTY_ERROR;
1739 *(char **) arg = malloc(64);
1740 (*(char **) arg)[63] = 0;
1741 switch (sub_source(mpctx))
1743 case SUB_SOURCE_SUBS:
1744 snprintf(*(char **) arg, 63, mp_gtext("file"));
1745 break;
1746 case SUB_SOURCE_VOBSUB:
1747 snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
1748 break;
1749 case SUB_SOURCE_DEMUX:
1750 snprintf(*(char **) arg, 63, mp_gtext("embedded"));
1751 break;
1752 default:
1753 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1755 return M_PROPERTY_OK;
1756 case M_PROPERTY_SET:
1757 if (!arg)
1758 return M_PROPERTY_ERROR;
1759 M_PROPERTY_CLAMP(prop, *(int*)arg);
1760 if (*(int *) arg < 0)
1761 mpctx->global_sub_pos = -1;
1762 else if (*(int *) arg != sub_source(mpctx)) {
1763 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1764 if (new_pos == -1)
1765 return M_PROPERTY_UNAVAILABLE;
1766 mpctx->global_sub_pos = new_pos;
1768 break;
1769 case M_PROPERTY_STEP_UP:
1770 case M_PROPERTY_STEP_DOWN: {
1771 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1772 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1773 int step = (step_all > 0) ? 1 : -1;
1774 int cur_source = sub_source(mpctx);
1775 source = cur_source;
1776 while (step_all) {
1777 source += step;
1778 if (source >= SUB_SOURCES)
1779 source = -1;
1780 else if (source < -1)
1781 source = SUB_SOURCES - 1;
1782 if (source == cur_source || source == -1 ||
1783 mpctx->sub_counts[source])
1784 step_all -= step;
1786 if (source == cur_source)
1787 return M_PROPERTY_OK;
1788 if (source == -1)
1789 mpctx->global_sub_pos = -1;
1790 else
1791 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1792 break;
1794 default:
1795 return M_PROPERTY_NOT_IMPLEMENTED;
1797 --mpctx->global_sub_pos;
1798 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1801 /// Selected subtitles from specific source (RW)
1802 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1803 MPContext *mpctx)
1805 int source, is_cur_source, offset, new_pos;
1806 update_global_sub_size(mpctx);
1807 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1808 return M_PROPERTY_UNAVAILABLE;
1810 if (!strcmp(prop->name, "sub_file"))
1811 source = SUB_SOURCE_SUBS;
1812 else if (!strcmp(prop->name, "sub_vob"))
1813 source = SUB_SOURCE_VOBSUB;
1814 else if (!strcmp(prop->name, "sub_demux"))
1815 source = SUB_SOURCE_DEMUX;
1816 else
1817 return M_PROPERTY_ERROR;
1819 offset = sub_pos_by_source(mpctx, source);
1820 if (offset < 0)
1821 return M_PROPERTY_UNAVAILABLE;
1823 is_cur_source = sub_source(mpctx) == source;
1824 new_pos = mpctx->global_sub_pos;
1825 switch (action) {
1826 case M_PROPERTY_GET:
1827 if (!arg)
1828 return M_PROPERTY_ERROR;
1829 if (is_cur_source) {
1830 *(int *) arg = sub_source_pos(mpctx);
1831 if (source == SUB_SOURCE_VOBSUB)
1832 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1834 else
1835 *(int *) arg = -1;
1836 return M_PROPERTY_OK;
1837 case M_PROPERTY_PRINT:
1838 if (!arg)
1839 return M_PROPERTY_ERROR;
1840 if (is_cur_source)
1841 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1842 *(char **) arg = malloc(64);
1843 (*(char **) arg)[63] = 0;
1844 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1845 return M_PROPERTY_OK;
1846 case M_PROPERTY_SET:
1847 if (!arg)
1848 return M_PROPERTY_ERROR;
1849 if (*(int *) arg >= 0) {
1850 int index = *(int *)arg;
1851 if (source == SUB_SOURCE_VOBSUB)
1852 index = vobsub_get_index_by_id(vo_vobsub, index);
1853 new_pos = offset + index;
1854 if (index < 0 || index > mpctx->sub_counts[source]) {
1855 new_pos = -1;
1856 *(int *) arg = -1;
1859 else
1860 new_pos = -1;
1861 break;
1862 case M_PROPERTY_STEP_UP:
1863 case M_PROPERTY_STEP_DOWN: {
1864 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1865 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1866 int step = (step_all > 0) ? 1 : -1;
1867 int max_sub_pos_for_source = -1;
1868 if (!is_cur_source)
1869 new_pos = -1;
1870 while (step_all) {
1871 if (new_pos == -1) {
1872 if (step > 0)
1873 new_pos = offset;
1874 else if (max_sub_pos_for_source == -1) {
1875 // Find max pos for specific source
1876 new_pos = mpctx->global_sub_size - 1;
1877 while (new_pos >= 0
1878 && sub_source(mpctx) != source)
1879 new_pos--;
1881 else
1882 new_pos = max_sub_pos_for_source;
1884 else {
1885 new_pos += step;
1886 if (new_pos < offset ||
1887 new_pos >= mpctx->global_sub_size ||
1888 sub_source(mpctx) != source)
1889 new_pos = -1;
1891 step_all -= step;
1893 break;
1895 default:
1896 return M_PROPERTY_NOT_IMPLEMENTED;
1898 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1901 /// Subtitle delay (RW)
1902 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1903 MPContext *mpctx)
1905 if (!mpctx->sh_video)
1906 return M_PROPERTY_UNAVAILABLE;
1907 return m_property_delay(prop, action, arg, &sub_delay);
1910 /// Alignment of text subtitles (RW)
1911 static int mp_property_sub_alignment(m_option_t *prop, int action,
1912 void *arg, MPContext *mpctx)
1914 char *name[] = { _("top"), _("center"), _("bottom") };
1916 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1917 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1918 return M_PROPERTY_UNAVAILABLE;
1920 switch (action) {
1921 case M_PROPERTY_PRINT:
1922 if (!arg)
1923 return M_PROPERTY_ERROR;
1924 M_PROPERTY_CLAMP(prop, sub_alignment);
1925 *(char **) arg = strdup(mp_gtext(name[sub_alignment]));
1926 return M_PROPERTY_OK;
1927 case M_PROPERTY_SET:
1928 if (!arg)
1929 return M_PROPERTY_ERROR;
1930 case M_PROPERTY_STEP_UP:
1931 case M_PROPERTY_STEP_DOWN:
1932 vo_osd_changed(OSDTYPE_SUBTITLE);
1933 default:
1934 return m_property_choice(prop, action, arg, &sub_alignment);
1938 /// Subtitle visibility (RW)
1939 static int mp_property_sub_visibility(m_option_t *prop, int action,
1940 void *arg, MPContext *mpctx)
1942 if (!mpctx->sh_video)
1943 return M_PROPERTY_UNAVAILABLE;
1945 switch (action) {
1946 case M_PROPERTY_SET:
1947 if (!arg)
1948 return M_PROPERTY_ERROR;
1949 case M_PROPERTY_STEP_UP:
1950 case M_PROPERTY_STEP_DOWN:
1951 vo_osd_changed(OSDTYPE_SUBTITLE);
1952 if (vo_spudec)
1953 vo_osd_changed(OSDTYPE_SPU);
1954 default:
1955 return m_property_flag(prop, action, arg, &sub_visibility);
1959 #ifdef CONFIG_ASS
1960 /// Use margins for libass subtitles (RW)
1961 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1962 void *arg, MPContext *mpctx)
1964 if (!mpctx->sh_video)
1965 return M_PROPERTY_UNAVAILABLE;
1967 switch (action) {
1968 case M_PROPERTY_SET:
1969 if (!arg)
1970 return M_PROPERTY_ERROR;
1971 case M_PROPERTY_STEP_UP:
1972 case M_PROPERTY_STEP_DOWN:
1973 ass_force_reload = 1;
1974 default:
1975 return m_property_flag(prop, action, arg, &ass_use_margins);
1978 #endif
1980 /// Show only forced subtitles (RW)
1981 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1982 void *arg, MPContext *mpctx)
1984 if (!vo_spudec)
1985 return M_PROPERTY_UNAVAILABLE;
1987 switch (action) {
1988 case M_PROPERTY_SET:
1989 if (!arg)
1990 return M_PROPERTY_ERROR;
1991 case M_PROPERTY_STEP_UP:
1992 case M_PROPERTY_STEP_DOWN:
1993 m_property_flag(prop, action, arg, &forced_subs_only);
1994 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1995 return M_PROPERTY_OK;
1996 default:
1997 return m_property_flag(prop, action, arg, &forced_subs_only);
2002 #ifdef CONFIG_FREETYPE
2003 /// Subtitle scale (RW)
2004 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
2005 MPContext *mpctx)
2007 struct MPOpts *opts = &mpctx->opts;
2009 switch (action) {
2010 case M_PROPERTY_SET:
2011 if (!arg)
2012 return M_PROPERTY_ERROR;
2013 M_PROPERTY_CLAMP(prop, *(float *) arg);
2014 #ifdef CONFIG_ASS
2015 if (opts->ass_enabled) {
2016 ass_font_scale = *(float *) arg;
2017 ass_force_reload = 1;
2019 #endif
2020 text_font_scale_factor = *(float *) arg;
2021 force_load_font = 1;
2022 return M_PROPERTY_OK;
2023 case M_PROPERTY_STEP_UP:
2024 case M_PROPERTY_STEP_DOWN:
2025 #ifdef CONFIG_ASS
2026 if (opts->ass_enabled) {
2027 ass_font_scale += (arg ? *(float *) arg : 0.1)*
2028 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2029 M_PROPERTY_CLAMP(prop, ass_font_scale);
2030 ass_force_reload = 1;
2032 #endif
2033 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
2034 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2035 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
2036 force_load_font = 1;
2037 return M_PROPERTY_OK;
2038 default:
2039 #ifdef CONFIG_ASS
2040 if (opts->ass_enabled)
2041 return m_property_float_ro(prop, action, arg, ass_font_scale);
2042 else
2043 #endif
2044 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
2047 #endif
2049 ///@}
2051 /// \defgroup TVProperties TV properties
2052 /// \ingroup Properties
2053 ///@{
2055 #ifdef CONFIG_TV
2057 /// TV color settings (RW)
2058 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2059 MPContext *mpctx)
2061 int r, val;
2062 tvi_handle_t *tvh = mpctx->demuxer->priv;
2063 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2064 return M_PROPERTY_UNAVAILABLE;
2066 switch (action) {
2067 case M_PROPERTY_SET:
2068 if (!arg)
2069 return M_PROPERTY_ERROR;
2070 M_PROPERTY_CLAMP(prop, *(int *) arg);
2071 return tv_set_color_options(tvh, prop->offset, *(int *) arg);
2072 case M_PROPERTY_GET:
2073 return tv_get_color_options(tvh, prop->offset, arg);
2074 case M_PROPERTY_STEP_UP:
2075 case M_PROPERTY_STEP_DOWN:
2076 if ((r = tv_get_color_options(tvh, prop->offset, &val)) >= 0) {
2077 if (!r)
2078 return M_PROPERTY_ERROR;
2079 val += (arg ? *(int *) arg : 1) *
2080 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2081 M_PROPERTY_CLAMP(prop, val);
2082 return tv_set_color_options(tvh, prop->offset, val);
2084 return M_PROPERTY_ERROR;
2086 return M_PROPERTY_NOT_IMPLEMENTED;
2089 #endif
2091 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2092 MPContext *mpctx)
2094 int val,result;
2095 int base_ioctl = prop->offset;
2097 for teletext's GET,SET,STEP ioctls this is not 0
2098 SET is GET+1
2099 STEP is GET+2
2101 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2102 return M_PROPERTY_UNAVAILABLE;
2103 if(!base_ioctl)
2104 return M_PROPERTY_ERROR;
2106 switch (action) {
2107 case M_PROPERTY_GET:
2108 if (!arg)
2109 return M_PROPERTY_ERROR;
2110 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2111 break;
2112 case M_PROPERTY_SET:
2113 if (!arg)
2114 return M_PROPERTY_ERROR;
2115 M_PROPERTY_CLAMP(prop, *(int *) arg);
2116 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
2117 break;
2118 case M_PROPERTY_STEP_UP:
2119 case M_PROPERTY_STEP_DOWN:
2120 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2121 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2122 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
2123 break;
2124 default:
2125 return M_PROPERTY_NOT_IMPLEMENTED;
2128 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2131 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2132 MPContext *mpctx)
2134 int result;
2135 int val;
2137 //with tvh==NULL will fail too
2138 result=mp_property_teletext_common(prop,action,arg,mpctx);
2139 if(result!=M_PROPERTY_OK)
2140 return result;
2142 if(teletext_control(mpctx->demuxer->teletext,
2143 prop->offset, &val)==VBI_CONTROL_TRUE && val)
2144 mp_input_set_section(mpctx->input, "teletext");
2145 else
2146 mp_input_set_section(mpctx->input, "tv");
2147 return M_PROPERTY_OK;
2150 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2151 MPContext *mpctx)
2153 int result;
2154 int val;
2155 if (!mpctx->demuxer->teletext)
2156 return M_PROPERTY_UNAVAILABLE;
2157 switch(action){
2158 case M_PROPERTY_STEP_UP:
2159 case M_PROPERTY_STEP_DOWN:
2160 //This should be handled separately
2161 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2162 result=teletext_control(mpctx->demuxer->teletext,
2163 TV_VBI_CONTROL_STEP_PAGE, &val);
2164 break;
2165 default:
2166 result=mp_property_teletext_common(prop,action,arg,mpctx);
2168 return result;
2171 ///@}
2173 /// All properties available in MPlayer.
2174 /** \ingroup Properties
2176 static const m_option_t mp_properties[] = {
2177 // General
2178 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2179 M_OPT_RANGE, 0, 3, NULL },
2180 { "loop", mp_property_loop, CONF_TYPE_INT,
2181 M_OPT_MIN, -1, 0, NULL },
2182 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2183 M_OPT_RANGE, 0.01, 100.0, NULL },
2184 { "filename", mp_property_filename, CONF_TYPE_STRING,
2185 0, 0, 0, NULL },
2186 { "path", mp_property_path, CONF_TYPE_STRING,
2187 0, 0, 0, NULL },
2188 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2189 0, 0, 0, NULL },
2190 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2191 M_OPT_MIN, 0, 0, NULL },
2192 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2193 M_OPT_MIN, 0, 0, NULL },
2194 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2195 M_OPT_MIN, 0, 0, NULL },
2196 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2197 M_OPT_MIN, 0, 0, NULL },
2198 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2199 M_OPT_MIN, 0, 0, NULL },
2200 { "length", mp_property_length, CONF_TYPE_TIME,
2201 M_OPT_MIN, 0, 0, NULL },
2202 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2203 M_OPT_RANGE, 0, 100, NULL },
2204 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2205 M_OPT_MIN, 0, 0, NULL },
2206 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2207 M_OPT_MIN, 0, 0, NULL },
2208 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2209 0, 0, 0, NULL },
2210 { "angle", mp_property_angle, CONF_TYPE_INT,
2211 CONF_RANGE, -2, 10, NULL },
2212 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2213 0, 0, 0, NULL },
2214 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2215 M_OPT_RANGE, 0, 1, NULL },
2216 { "capturing", mp_property_capture, CONF_TYPE_FLAG,
2217 M_OPT_RANGE, 0, 1, NULL },
2218 { "pts_association_mode", mp_property_generic_option, &m_option_type_choice,
2219 0, 0, 0, "pts-association-mode" },
2220 { "hr_seek", mp_property_generic_option, &m_option_type_choice,
2221 0, 0, 0, "hr-seek" },
2223 // Audio
2224 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2225 M_OPT_RANGE, 0, 100, NULL },
2226 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2227 M_OPT_RANGE, 0, 1, NULL },
2228 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2229 M_OPT_RANGE, -100, 100, NULL },
2230 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2231 0, 0, 0, NULL },
2232 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2233 0, 0, 0, NULL },
2234 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2235 0, 0, 0, NULL },
2236 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2237 0, 0, 0, NULL },
2238 { "channels", mp_property_channels, CONF_TYPE_INT,
2239 0, 0, 0, NULL },
2240 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2241 CONF_RANGE, -2, 65535, NULL },
2242 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2243 M_OPT_RANGE, -1, 1, NULL },
2245 // Video
2246 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2247 M_OPT_RANGE, 0, 1, NULL },
2248 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2249 M_OPT_RANGE, 0, 1, NULL },
2250 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2251 M_OPT_RANGE, 0, 2, NULL },
2252 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2253 M_OPT_RANGE, 0, 1, NULL },
2254 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2255 M_OPT_RANGE, 0, 1, NULL },
2256 { "border", mp_property_border, CONF_TYPE_FLAG,
2257 M_OPT_RANGE, 0, 1, NULL },
2258 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2259 M_OPT_RANGE, 0, 2, NULL },
2260 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2261 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_gamma)},
2262 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2263 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_brightness) },
2264 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2265 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_contrast) },
2266 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2267 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_saturation) },
2268 { "hue", mp_property_gamma, CONF_TYPE_INT,
2269 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_hue) },
2270 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2271 M_OPT_RANGE, 0, 1, NULL },
2272 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2273 M_OPT_RANGE, 0, 1, NULL },
2274 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2275 0, 0, 0, NULL },
2276 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2277 0, 0, 0, NULL },
2278 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2279 0, 0, 0, NULL },
2280 { "width", mp_property_width, CONF_TYPE_INT,
2281 0, 0, 0, NULL },
2282 { "height", mp_property_height, CONF_TYPE_INT,
2283 0, 0, 0, NULL },
2284 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2285 0, 0, 0, NULL },
2286 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2287 0, 0, 0, NULL },
2288 { "switch_video", mp_property_video, CONF_TYPE_INT,
2289 CONF_RANGE, -2, 65535, NULL },
2290 { "switch_program", mp_property_program, CONF_TYPE_INT,
2291 CONF_RANGE, -1, 65535, NULL },
2293 // Subs
2294 { "sub", mp_property_sub, CONF_TYPE_INT,
2295 M_OPT_MIN, -1, 0, NULL },
2296 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2297 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2298 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2299 M_OPT_MIN, -1, 0, NULL },
2300 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2301 M_OPT_MIN, -1, 0, NULL },
2302 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2303 M_OPT_MIN, -1, 0, NULL },
2304 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2305 0, 0, 0, NULL },
2306 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2307 M_OPT_RANGE, 0, 100, NULL },
2308 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2309 M_OPT_RANGE, 0, 2, NULL },
2310 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2311 M_OPT_RANGE, 0, 1, NULL },
2312 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2313 M_OPT_RANGE, 0, 1, NULL },
2314 #ifdef CONFIG_FREETYPE
2315 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2316 M_OPT_RANGE, 0, 100, NULL },
2317 #endif
2318 #ifdef CONFIG_ASS
2319 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2320 M_OPT_RANGE, 0, 1, NULL },
2321 #endif
2323 #ifdef CONFIG_TV
2324 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2325 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_BRIGHTNESS },
2326 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2327 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_CONTRAST },
2328 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2329 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_SATURATION },
2330 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2331 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_HUE },
2332 #endif
2333 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2334 M_OPT_RANGE, 100, 899, .offset=TV_VBI_CONTROL_GET_PAGE },
2335 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2336 M_OPT_RANGE, 0, 64, .offset=TV_VBI_CONTROL_GET_SUBPAGE },
2337 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2338 M_OPT_RANGE, 0, 1, .offset=TV_VBI_CONTROL_GET_MODE },
2339 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2340 M_OPT_RANGE, 0, 3, .offset=TV_VBI_CONTROL_GET_FORMAT },
2341 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2342 M_OPT_RANGE, 0, 2, .offset=TV_VBI_CONTROL_GET_HALF_PAGE },
2343 { NULL, NULL, NULL, 0, 0, 0, NULL }
2347 int mp_property_do(const char *name, int action, void *val, void *ctx)
2349 return m_property_do(mp_properties, name, action, val, ctx);
2352 char* mp_property_print(const char *name, void* ctx)
2354 char* ret = NULL;
2355 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2356 return NULL;
2357 return ret;
2360 char *property_expand_string(MPContext *mpctx, char *str)
2362 return m_properties_expand_string(mp_properties, str, mpctx);
2365 void property_print_help(void)
2367 m_properties_print_help_list(mp_properties);
2371 /* List of default ways to show a property on OSD.
2373 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2374 * a bar showing the current position between min/max values of the
2375 * property. In this case osd_msg is only used for terminal output
2376 * if there is no video; it'll be a label shown together with percentage.
2378 * Otherwise setting osd_msg will show the string on OSD, formatted with
2379 * the text value of the property as argument.
2381 static struct property_osd_display {
2382 /// property name
2383 const char *name;
2384 /// progressbar type
2385 int osd_progbar; // -1 is special value for seek indicators
2386 /// osd msg id if it must be shared
2387 int osd_id;
2388 /// osd msg template
2389 const char *osd_msg;
2390 } property_osd_display[] = {
2391 // general
2392 { "loop", 0, -1, _("Loop: %s") },
2393 { "chapter", -1, -1, NULL },
2394 { "capturing", 0, -1, _("Capturing: %s") },
2395 { "pts_association_mode", 0, -1, "PTS association mode: %s" },
2396 { "hr_seek", 0, -1, "hr-seek: %s" },
2397 { "speed", 0, -1, _("Speed: x %6s") },
2398 // audio
2399 { "volume", OSD_VOLUME, -1, _("Volume") },
2400 { "mute", 0, -1, _("Mute: %s") },
2401 { "audio_delay", 0, -1, _("A-V delay: %s") },
2402 { "switch_audio", 0, -1, _("Audio: %s") },
2403 { "balance", OSD_BALANCE, -1, _("Balance") },
2404 // video
2405 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2406 { "ontop", 0, -1, _("Stay on top: %s") },
2407 { "rootwin", 0, -1, _("Rootwin: %s") },
2408 { "border", 0, -1, _("Border: %s") },
2409 { "framedropping", 0, -1, _("Framedropping: %s") },
2410 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2411 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2412 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2413 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2414 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2415 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2416 { "hue", OSD_HUE, -1, _("Hue") },
2417 { "vsync", 0, -1, _("VSync: %s") },
2418 // subs
2419 { "sub", 0, -1, _("Subtitles: %s") },
2420 { "sub_source", 0, -1, _("Sub source: %s") },
2421 { "sub_vob", 0, -1, _("Subtitles: %s") },
2422 { "sub_demux", 0, -1, _("Subtitles: %s") },
2423 { "sub_file", 0, -1, _("Subtitles: %s") },
2424 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2425 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2426 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2427 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2428 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2429 #ifdef CONFIG_FREETYPE
2430 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2431 #endif
2432 #ifdef CONFIG_TV
2433 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2434 { "tv_hue", OSD_HUE, -1, _("Hue") },
2435 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2436 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2437 #endif
2441 static int show_property_osd(MPContext *mpctx, const char *pname)
2443 struct MPOpts *opts = &mpctx->opts;
2444 int r;
2445 m_option_t* prop;
2446 struct property_osd_display *p;
2448 // look for the command
2449 for (p = property_osd_display; p->name; p++)
2450 if (!strcmp(p->name, pname))
2451 break;
2452 if (!p->name)
2453 return -1;
2455 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2456 return -1;
2458 if (p->osd_progbar == -1)
2459 mpctx->add_osd_seek_info = true;
2460 else if (p->osd_progbar) {
2461 if (prop->type == CONF_TYPE_INT) {
2462 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2463 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2464 prop->min, prop->max, r);
2465 } else if (prop->type == CONF_TYPE_FLOAT) {
2466 float f;
2467 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2468 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2469 prop->min, prop->max, f);
2470 } else {
2471 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2472 "Property use an unsupported type.\n");
2473 return -1;
2475 return 0;
2478 if (p->osd_msg) {
2479 char *val = mp_property_print(pname, mpctx);
2480 if (val) {
2481 int index = p - property_osd_display;
2482 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2483 1, opts->osd_duration, p->osd_msg, val);
2484 free(val);
2487 return 0;
2492 * \defgroup Command2Property Command to property bridge
2494 * It is used to handle most commands that just set a property
2495 * and optionally display something on the OSD.
2496 * Two kinds of commands are handled: adjust or toggle.
2498 * Adjust commands take 1 or 2 parameters: <value> <abs>
2499 * If <abs> is non-zero the property is set to the given value
2500 * otherwise it is adjusted.
2502 * Toggle commands take 0 or 1 parameters. With no parameter
2503 * or a value less than the property minimum it just steps the
2504 * property to its next or previous value respectively.
2505 * Otherwise it sets it to the given value.
2510 /// List of the commands that can be handled by setting a property.
2511 static struct {
2512 /// property name
2513 const char *name;
2514 /// cmd id
2515 int cmd;
2516 /// set/adjust or toggle command
2517 int toggle;
2518 } set_prop_cmd[] = {
2519 // general
2520 { "loop", MP_CMD_LOOP, 0},
2521 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2522 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2523 { "pause", MP_CMD_PAUSE, 0},
2524 { "capturing", MP_CMD_CAPTURING, 1},
2525 // audio
2526 { "volume", MP_CMD_VOLUME, 0},
2527 { "mute", MP_CMD_MUTE, 1},
2528 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2529 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2530 { "balance", MP_CMD_BALANCE, 0},
2531 // video
2532 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2533 { "panscan", MP_CMD_PANSCAN, 0},
2534 { "ontop", MP_CMD_VO_ONTOP, 1},
2535 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2536 { "border", MP_CMD_VO_BORDER, 1},
2537 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2538 { "gamma", MP_CMD_GAMMA, 0},
2539 { "brightness", MP_CMD_BRIGHTNESS, 0},
2540 { "contrast", MP_CMD_CONTRAST, 0},
2541 { "saturation", MP_CMD_SATURATION, 0},
2542 { "hue", MP_CMD_HUE, 0},
2543 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2544 // subs
2545 { "sub", MP_CMD_SUB_SELECT, 1},
2546 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2547 { "sub_vob", MP_CMD_SUB_VOB, 1},
2548 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2549 { "sub_file", MP_CMD_SUB_FILE, 1},
2550 { "sub_pos", MP_CMD_SUB_POS, 0},
2551 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2552 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2553 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2554 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2555 #ifdef CONFIG_FREETYPE
2556 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2557 #endif
2558 #ifdef CONFIG_ASS
2559 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2560 #endif
2561 #ifdef CONFIG_TV
2562 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2563 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2564 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2565 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2566 #endif
2570 /// Handle commands that set a property.
2571 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2573 int i, r;
2574 m_option_t *prop;
2575 const char *pname;
2577 // look for the command
2578 for (i = 0; set_prop_cmd[i].name; i++)
2579 if (set_prop_cmd[i].cmd == cmd->id)
2580 break;
2581 if (!(pname = set_prop_cmd[i].name))
2582 return 0;
2584 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2585 return 0;
2587 // toggle command
2588 if (set_prop_cmd[i].toggle) {
2589 // set to value
2590 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2591 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2592 else if (cmd->nargs > 0)
2593 r = mp_property_do(pname, M_PROPERTY_STEP_DOWN, NULL, mpctx);
2594 else
2595 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2596 } else if (cmd->args[1].v.i) //set
2597 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2598 else // adjust
2599 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2601 if (r <= 0)
2602 return 1;
2604 show_property_osd(mpctx, pname);
2606 return 1;
2609 #ifdef CONFIG_DVDNAV
2610 static const struct {
2611 const char *name;
2612 const mp_command_type cmd;
2613 } mp_dvdnav_bindings[] = {
2614 { "up", MP_CMD_DVDNAV_UP },
2615 { "down", MP_CMD_DVDNAV_DOWN },
2616 { "left", MP_CMD_DVDNAV_LEFT },
2617 { "right", MP_CMD_DVDNAV_RIGHT },
2618 { "menu", MP_CMD_DVDNAV_MENU },
2619 { "select", MP_CMD_DVDNAV_SELECT },
2620 { "prev", MP_CMD_DVDNAV_PREVMENU },
2621 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2624 * keep old dvdnav sub-command options for a while in order not to
2625 * break slave-mode API too suddenly.
2627 { "1", MP_CMD_DVDNAV_UP },
2628 { "2", MP_CMD_DVDNAV_DOWN },
2629 { "3", MP_CMD_DVDNAV_LEFT },
2630 { "4", MP_CMD_DVDNAV_RIGHT },
2631 { "5", MP_CMD_DVDNAV_MENU },
2632 { "6", MP_CMD_DVDNAV_SELECT },
2633 { "7", MP_CMD_DVDNAV_PREVMENU },
2634 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2635 { NULL, 0 }
2637 #endif
2639 static const char *property_error_string(int error_value)
2641 switch (error_value) {
2642 case M_PROPERTY_ERROR:
2643 return "ERROR";
2644 case M_PROPERTY_UNAVAILABLE:
2645 return "PROPERTY_UNAVAILABLE";
2646 case M_PROPERTY_NOT_IMPLEMENTED:
2647 return "NOT_IMPLEMENTED";
2648 case M_PROPERTY_UNKNOWN:
2649 return "PROPERTY_UNKNOWN";
2650 case M_PROPERTY_DISABLED:
2651 return "DISABLED";
2653 return "UNKNOWN";
2656 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2658 int idx;
2659 int end = start + count;
2660 int after = mpctx->set_of_sub_size - end;
2661 sub_data **subs = mpctx->set_of_subtitles;
2662 #ifdef CONFIG_ASS
2663 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2664 #endif
2665 if (count < 0 || count > mpctx->set_of_sub_size ||
2666 start < 0 || start > mpctx->set_of_sub_size - count) {
2667 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2668 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2669 return;
2671 for (idx = start; idx < end; idx++) {
2672 sub_data *subd = subs[idx];
2673 char *filename = "";
2674 if (subd)
2675 filename = subd->filename;
2676 #ifdef CONFIG_ASS
2677 if (!subd)
2678 filename = ass_tracks[idx]->name;
2679 #endif
2680 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2681 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2682 filename_recode(filename));
2683 sub_free(subd);
2684 subs[idx] = NULL;
2685 #ifdef CONFIG_ASS
2686 if (ass_tracks[idx])
2687 ass_free_track(ass_tracks[idx]);
2688 ass_tracks[idx] = NULL;
2689 #endif
2692 mpctx->global_sub_size -= count;
2693 mpctx->set_of_sub_size -= count;
2694 if (mpctx->set_of_sub_size <= 0)
2695 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2697 memmove(subs + start, subs + end, after * sizeof(*subs));
2698 memset(subs + start + after, 0, count * sizeof(*subs));
2699 #ifdef CONFIG_ASS
2700 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2701 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2702 #endif
2704 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2705 mpctx->global_sub_pos = -2;
2706 mpctx->subdata = NULL;
2707 mpctx->osd->ass_track = NULL;
2708 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2709 } else if (mpctx->set_of_sub_pos >= end) {
2710 mpctx->set_of_sub_pos -= count;
2711 mpctx->global_sub_pos -= count;
2715 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2717 struct MPOpts *opts = &mpctx->opts;
2718 sh_audio_t * const sh_audio = mpctx->sh_audio;
2719 sh_video_t * const sh_video = mpctx->sh_video;
2720 int osd_duration = opts->osd_duration;
2721 int case_fallthrough_hack = 0;
2722 if (!set_property_command(mpctx, cmd))
2723 switch (cmd->id) {
2724 case MP_CMD_SEEK:{
2725 mpctx->add_osd_seek_info = true;
2726 float v = cmd->args[0].v.f;
2727 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2728 int exact = (cmd->nargs > 2) ? cmd->args[2].v.i : 0;
2729 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2730 queue_seek(mpctx, MPSEEK_ABSOLUTE, v, exact);
2731 mpctx->osd_function = v > get_current_time(mpctx) ?
2732 OSD_FFW : OSD_REW;
2733 } else if (abs) { /* Absolute seek by percentage */
2734 queue_seek(mpctx, MPSEEK_FACTOR, v / 100.0, exact);
2735 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2736 } else {
2737 queue_seek(mpctx, MPSEEK_RELATIVE, v, exact);
2738 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2741 break;
2743 case MP_CMD_SET_PROPERTY_OSD:
2744 case_fallthrough_hack = 1;
2746 case MP_CMD_SET_PROPERTY:{
2747 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2748 cmd->args[1].v.s, mpctx);
2749 if (r == M_PROPERTY_UNKNOWN)
2750 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2751 "Unknown property: '%s'\n", cmd->args[0].v.s);
2752 else if (r <= 0)
2753 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2754 "Failed to set property '%s' to '%s'.\n",
2755 cmd->args[0].v.s, cmd->args[1].v.s);
2756 else if (case_fallthrough_hack)
2757 show_property_osd(mpctx, cmd->args[0].v.s);
2758 if (r <= 0)
2759 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2761 break;
2763 case MP_CMD_STEP_PROPERTY_OSD:
2764 case_fallthrough_hack = 1;
2766 case MP_CMD_STEP_PROPERTY:{
2767 void* arg = NULL;
2768 int r,i;
2769 double d;
2770 off_t o;
2771 if (cmd->args[1].v.f) {
2772 m_option_t* prop;
2773 if((r = mp_property_do(cmd->args[0].v.s,
2774 M_PROPERTY_GET_TYPE,
2775 &prop, mpctx)) <= 0)
2776 goto step_prop_err;
2777 if(prop->type == CONF_TYPE_INT ||
2778 prop->type == CONF_TYPE_FLAG)
2779 i = cmd->args[1].v.f, arg = &i;
2780 else if(prop->type == CONF_TYPE_FLOAT)
2781 arg = &cmd->args[1].v.f;
2782 else if(prop->type == CONF_TYPE_DOUBLE ||
2783 prop->type == CONF_TYPE_TIME)
2784 d = cmd->args[1].v.f, arg = &d;
2785 else if(prop->type == CONF_TYPE_POSITION)
2786 o = cmd->args[1].v.f, arg = &o;
2787 else
2788 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2789 "Ignoring step size stepping property '%s'.\n",
2790 cmd->args[0].v.s);
2792 r = mp_property_do(cmd->args[0].v.s,
2793 cmd->args[2].v.i < 0 ?
2794 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2795 arg, mpctx);
2796 step_prop_err:
2797 if (r == M_PROPERTY_UNKNOWN)
2798 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2799 "Unknown property: '%s'\n", cmd->args[0].v.s);
2800 else if (r <= 0)
2801 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2802 "Failed to increment property '%s' by %f.\n",
2803 cmd->args[0].v.s, cmd->args[1].v.f);
2804 else if (case_fallthrough_hack)
2805 show_property_osd(mpctx, cmd->args[0].v.s);
2806 if (r <= 0)
2807 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2809 break;
2811 case MP_CMD_GET_PROPERTY:{
2812 char *tmp;
2813 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2814 &tmp, mpctx);
2815 if (r <= 0) {
2816 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2817 "Failed to get value of property '%s'.\n",
2818 cmd->args[0].v.s);
2819 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2820 break;
2822 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2823 cmd->args[0].v.s, tmp);
2824 free(tmp);
2826 break;
2828 case MP_CMD_EDL_MARK:
2829 if (edl_fd) {
2830 float v = get_current_time(mpctx);
2831 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2832 mpctx->begin_skip = v;
2833 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2834 } else {
2835 if (mpctx->begin_skip > v)
2836 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2837 else {
2838 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2839 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2841 mpctx->begin_skip = MP_NOPTS_VALUE;
2844 break;
2846 case MP_CMD_SWITCH_RATIO:
2847 if (!sh_video)
2848 break;
2849 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2850 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2851 else
2852 opts->movie_aspect = cmd->args[0].v.f;
2853 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2854 break;
2856 case MP_CMD_SPEED_INCR:{
2857 float v = cmd->args[0].v.f;
2858 mp_property_do("speed", M_PROPERTY_STEP_UP, &v, mpctx);
2859 show_property_osd(mpctx, "speed");
2860 break;
2863 case MP_CMD_SPEED_MULT:
2864 case_fallthrough_hack = true;
2866 case MP_CMD_SPEED_SET:{
2867 float v = cmd->args[0].v.f;
2868 if (case_fallthrough_hack)
2869 v *= mpctx->opts.playback_speed;
2870 mp_property_do("speed", M_PROPERTY_SET, &v, mpctx);
2871 show_property_osd(mpctx, "speed");
2872 break;
2875 case MP_CMD_FRAME_STEP:
2876 add_step_frame(mpctx);
2877 break;
2879 case MP_CMD_FILE_FILTER:
2880 file_filter = cmd->args[0].v.i;
2881 break;
2883 case MP_CMD_QUIT:
2884 exit_player_with_rc(mpctx, EXIT_QUIT,
2885 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2887 case MP_CMD_PLAY_TREE_STEP:{
2888 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2889 int force = cmd->args[1].v.i;
2892 if (!force && mpctx->playtree_iter) {
2893 play_tree_iter_t *i =
2894 play_tree_iter_new_copy(mpctx->playtree_iter);
2895 if (play_tree_iter_step(i, n, 0) ==
2896 PLAY_TREE_ITER_ENTRY)
2897 mpctx->stop_play =
2898 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2899 play_tree_iter_free(i);
2900 } else
2901 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2902 if (mpctx->stop_play)
2903 mpctx->play_tree_step = n;
2906 break;
2908 case MP_CMD_PLAY_TREE_UP_STEP:{
2909 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2910 int force = cmd->args[1].v.i;
2912 if (!force && mpctx->playtree_iter) {
2913 play_tree_iter_t *i =
2914 play_tree_iter_new_copy(mpctx->playtree_iter);
2915 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2916 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2917 play_tree_iter_free(i);
2918 } else
2919 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2921 break;
2923 case MP_CMD_PLAY_ALT_SRC_STEP:
2924 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2925 int v = cmd->args[0].v.i;
2926 if (v > 0
2927 && mpctx->playtree_iter->file <
2928 mpctx->playtree_iter->num_files)
2929 mpctx->stop_play = PT_NEXT_SRC;
2930 else if (v < 0 && mpctx->playtree_iter->file > 1)
2931 mpctx->stop_play = PT_PREV_SRC;
2933 break;
2935 case MP_CMD_SUB_STEP:
2936 if (sh_video) {
2937 int movement = cmd->args[0].v.i;
2938 step_sub(mpctx->subdata, mpctx->video_pts, movement);
2939 #ifdef CONFIG_ASS
2940 if (mpctx->osd->ass_track)
2941 sub_delay +=
2942 ass_step_sub(mpctx->osd->ass_track,
2943 (mpctx->video_pts +
2944 sub_delay) * 1000 + .5, movement) / 1000.;
2945 #endif
2946 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2947 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2949 break;
2951 case MP_CMD_SUB_LOG:
2952 log_sub(mpctx);
2953 break;
2955 case MP_CMD_OSD:{
2956 int v = cmd->args[0].v.i;
2957 int max = (opts->term_osd
2958 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2959 if (opts->osd_level > max)
2960 opts->osd_level = max;
2961 if (v < 0)
2962 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2963 else
2964 opts->osd_level = v > max ? max : v;
2965 /* Show OSD state when disabled, but not when an explicit
2966 argument is given to the OSD command, i.e. in slave mode. */
2967 if (v == -1 && opts->osd_level <= 1)
2968 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2969 "OSD: %s",
2970 opts->osd_level ? mp_gtext("enabled") :
2971 mp_gtext("disabled"));
2972 else
2973 rm_osd_msg(OSD_MSG_OSD_STATUS);
2975 break;
2977 case MP_CMD_OSD_SHOW_TEXT:
2978 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2979 (cmd->args[1].v.i <
2980 0 ? osd_duration : cmd->args[1].v.i),
2981 "%-.63s", cmd->args[0].v.s);
2982 break;
2984 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2985 char *txt = m_properties_expand_string(mp_properties,
2986 cmd->args[0].v.s,
2987 mpctx);
2988 /* if no argument supplied take default osd_duration, else <arg> ms. */
2989 if (txt) {
2990 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2991 (cmd->args[1].v.i <
2992 0 ? osd_duration : cmd->args[1].v.i),
2993 "%-.63s", txt);
2994 free(txt);
2997 break;
2999 case MP_CMD_LOADFILE:{
3000 play_tree_t *e = play_tree_new();
3001 play_tree_add_file(e, cmd->args[0].v.s);
3003 if (cmd->args[1].v.i) // append
3004 play_tree_append_entry(mpctx->playtree->child, e);
3005 else {
3006 // Go back to the starting point.
3007 while (play_tree_iter_up_step
3008 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3009 /* NOP */ ;
3010 play_tree_free_list(mpctx->playtree->child, 1);
3011 play_tree_set_child(mpctx->playtree, e);
3012 pt_iter_goto_head(mpctx->playtree_iter);
3013 mpctx->stop_play = PT_NEXT_SRC;
3016 break;
3018 case MP_CMD_LOADLIST:{
3019 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
3020 if (!e)
3021 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
3022 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
3023 else {
3024 if (cmd->args[1].v.i) // append
3025 play_tree_append_entry(mpctx->playtree->child, e);
3026 else {
3027 // Go back to the starting point.
3028 while (play_tree_iter_up_step
3029 (mpctx->playtree_iter, 0, 1)
3030 != PLAY_TREE_ITER_END)
3031 /* NOP */ ;
3032 play_tree_free_list(mpctx->playtree->child, 1);
3033 play_tree_set_child(mpctx->playtree, e);
3034 pt_iter_goto_head(mpctx->playtree_iter);
3035 mpctx->stop_play = PT_NEXT_SRC;
3039 break;
3041 case MP_CMD_STOP:
3042 // Go back to the starting point.
3043 while (play_tree_iter_up_step
3044 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3045 /* NOP */ ;
3046 mpctx->stop_play = PT_STOP;
3047 break;
3049 case MP_CMD_OSD_SHOW_PROGRESSION:{
3050 int len = get_time_length(mpctx);
3051 int pts = get_current_time(mpctx);
3052 set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3053 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3054 "%c %02d:%02d:%02d / %02d:%02d:%02d",
3055 mpctx->osd_function, pts/3600, (pts/60)%60, pts%60,
3056 len/3600, (len/60)%60, len%60);
3058 break;
3060 #ifdef CONFIG_RADIO
3061 case MP_CMD_RADIO_STEP_CHANNEL:
3062 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3063 int v = cmd->args[0].v.i;
3064 if (v > 0)
3065 radio_step_channel(mpctx->demuxer->stream,
3066 RADIO_CHANNEL_HIGHER);
3067 else
3068 radio_step_channel(mpctx->demuxer->stream,
3069 RADIO_CHANNEL_LOWER);
3070 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3071 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3072 "Channel: %s",
3073 radio_get_channel_name(mpctx->demuxer->stream));
3076 break;
3078 case MP_CMD_RADIO_SET_CHANNEL:
3079 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3080 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3081 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3082 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3083 "Channel: %s",
3084 radio_get_channel_name(mpctx->demuxer->stream));
3087 break;
3089 case MP_CMD_RADIO_SET_FREQ:
3090 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3091 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3092 break;
3094 case MP_CMD_RADIO_STEP_FREQ:
3095 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3096 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3097 break;
3098 #endif
3100 #ifdef CONFIG_TV
3101 case MP_CMD_TV_START_SCAN:
3102 if (mpctx->file_format == DEMUXER_TYPE_TV)
3103 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
3104 break;
3105 case MP_CMD_TV_SET_FREQ:
3106 if (mpctx->file_format == DEMUXER_TYPE_TV)
3107 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3108 cmd->args[0].v.f * 16.0);
3109 #ifdef CONFIG_PVR
3110 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3111 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
3112 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3113 pvr_get_current_channelname (mpctx->stream),
3114 pvr_get_current_stationname (mpctx->stream));
3116 #endif /* CONFIG_PVR */
3117 break;
3119 case MP_CMD_TV_STEP_FREQ:
3120 if (mpctx->file_format == DEMUXER_TYPE_TV)
3121 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3122 cmd->args[0].v.f * 16.0);
3123 #ifdef CONFIG_PVR
3124 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3125 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
3126 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3127 pvr_get_current_channelname (mpctx->stream),
3128 pvr_get_current_frequency (mpctx->stream));
3130 #endif /* CONFIG_PVR */
3131 break;
3133 case MP_CMD_TV_SET_NORM:
3134 if (mpctx->file_format == DEMUXER_TYPE_TV)
3135 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3136 cmd->args[0].v.s);
3137 break;
3139 case MP_CMD_TV_STEP_CHANNEL:{
3140 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3141 int v = cmd->args[0].v.i;
3142 if (v > 0) {
3143 tv_step_channel((tvi_handle_t *) (mpctx->
3144 demuxer->priv),
3145 TV_CHANNEL_HIGHER);
3146 } else {
3147 tv_step_channel((tvi_handle_t *) (mpctx->
3148 demuxer->priv),
3149 TV_CHANNEL_LOWER);
3151 if (tv_channel_list) {
3152 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3153 "Channel: %s", tv_channel_current->name);
3154 //vo_osd_changed(OSDTYPE_SUBTITLE);
3157 #ifdef CONFIG_PVR
3158 else if (mpctx->stream &&
3159 mpctx->stream->type == STREAMTYPE_PVR) {
3160 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3161 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3162 pvr_get_current_channelname (mpctx->stream),
3163 pvr_get_current_stationname (mpctx->stream));
3165 #endif /* CONFIG_PVR */
3167 #ifdef CONFIG_DVBIN
3168 if (mpctx->stream->type == STREAMTYPE_DVB) {
3169 int dir;
3170 int v = cmd->args[0].v.i;
3172 mpctx->last_dvb_step = v;
3173 if (v > 0)
3174 dir = DVB_CHANNEL_HIGHER;
3175 else
3176 dir = DVB_CHANNEL_LOWER;
3179 if (dvb_step_channel(mpctx->stream, dir)) {
3180 mpctx->stop_play = PT_NEXT_ENTRY;
3181 mpctx->dvbin_reopen = 1;
3184 #endif /* CONFIG_DVBIN */
3185 break;
3187 case MP_CMD_TV_SET_CHANNEL:
3188 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3189 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3190 cmd->args[0].v.s);
3191 if (tv_channel_list) {
3192 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3193 "Channel: %s", tv_channel_current->name);
3194 //vo_osd_changed(OSDTYPE_SUBTITLE);
3197 #ifdef CONFIG_PVR
3198 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3199 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3200 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3201 pvr_get_current_channelname (mpctx->stream),
3202 pvr_get_current_stationname (mpctx->stream));
3204 #endif /* CONFIG_PVR */
3205 break;
3207 #ifdef CONFIG_DVBIN
3208 case MP_CMD_DVB_SET_CHANNEL:
3209 if (mpctx->stream->type == STREAMTYPE_DVB) {
3210 mpctx->last_dvb_step = 1;
3212 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3213 cmd->args[0].v.i)) {
3214 mpctx->stop_play = PT_NEXT_ENTRY;
3215 mpctx->dvbin_reopen = 1;
3218 break;
3219 #endif /* CONFIG_DVBIN */
3221 case MP_CMD_TV_LAST_CHANNEL:
3222 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3223 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3224 if (tv_channel_list) {
3225 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3226 "Channel: %s", tv_channel_current->name);
3227 //vo_osd_changed(OSDTYPE_SUBTITLE);
3230 #ifdef CONFIG_PVR
3231 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3232 pvr_set_lastchannel (mpctx->stream);
3233 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3234 pvr_get_current_channelname (mpctx->stream),
3235 pvr_get_current_stationname (mpctx->stream));
3237 #endif /* CONFIG_PVR */
3238 break;
3240 case MP_CMD_TV_STEP_NORM:
3241 if (mpctx->file_format == DEMUXER_TYPE_TV)
3242 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3243 break;
3245 case MP_CMD_TV_STEP_CHANNEL_LIST:
3246 if (mpctx->file_format == DEMUXER_TYPE_TV)
3247 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3248 break;
3249 #endif /* CONFIG_TV */
3250 case MP_CMD_TV_TELETEXT_ADD_DEC:
3251 if (mpctx->demuxer->teletext)
3252 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3253 &(cmd->args[0].v.s));
3254 break;
3255 case MP_CMD_TV_TELETEXT_GO_LINK:
3256 if (mpctx->demuxer->teletext)
3257 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3258 &(cmd->args[0].v.i));
3259 break;
3261 case MP_CMD_SUB_LOAD:
3262 if (sh_video) {
3263 int n = mpctx->set_of_sub_size;
3264 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3265 if (n != mpctx->set_of_sub_size) {
3266 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3267 ++mpctx->global_sub_size;
3270 break;
3272 case MP_CMD_SUB_REMOVE:
3273 if (sh_video) {
3274 int v = cmd->args[0].v.i;
3275 if (v < 0) {
3276 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3277 } else if (v < mpctx->set_of_sub_size) {
3278 remove_subtitle_range(mpctx, v, 1);
3281 break;
3283 case MP_CMD_GET_SUB_VISIBILITY:
3284 if (sh_video) {
3285 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3286 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3288 break;
3290 case MP_CMD_SCREENSHOT:
3291 if (mpctx->video_out && mpctx->video_out->config_ok) {
3292 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3293 if (CONTROL_OK !=
3294 ((vf_instance_t *) sh_video->vfilter)->
3295 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3296 &cmd->args[0].v.i))
3297 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3299 break;
3301 case MP_CMD_VF_CHANGE_RECTANGLE:
3302 if (!sh_video)
3303 break;
3304 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3305 break;
3307 case MP_CMD_GET_TIME_LENGTH:{
3308 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3309 get_time_length(mpctx));
3311 break;
3313 case MP_CMD_GET_FILENAME:{
3314 char *inf = get_metadata(mpctx, META_NAME);
3315 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n", inf);
3316 talloc_free(inf);
3318 break;
3320 case MP_CMD_GET_VIDEO_CODEC:{
3321 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3322 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3323 talloc_free(inf);
3325 break;
3327 case MP_CMD_GET_VIDEO_BITRATE:{
3328 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3329 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3330 talloc_free(inf);
3332 break;
3334 case MP_CMD_GET_VIDEO_RESOLUTION:{
3335 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3336 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3337 talloc_free(inf);
3339 break;
3341 case MP_CMD_GET_AUDIO_CODEC:{
3342 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3343 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3344 talloc_free(inf);
3346 break;
3348 case MP_CMD_GET_AUDIO_BITRATE:{
3349 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3350 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3351 talloc_free(inf);
3353 break;
3355 case MP_CMD_GET_AUDIO_SAMPLES:{
3356 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3357 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3358 talloc_free(inf);
3360 break;
3362 case MP_CMD_GET_META_TITLE:{
3363 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3364 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3365 talloc_free(inf);
3367 break;
3369 case MP_CMD_GET_META_ARTIST:{
3370 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3371 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3372 talloc_free(inf);
3374 break;
3376 case MP_CMD_GET_META_ALBUM:{
3377 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3378 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3379 talloc_free(inf);
3381 break;
3383 case MP_CMD_GET_META_YEAR:{
3384 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3385 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3386 talloc_free(inf);
3388 break;
3390 case MP_CMD_GET_META_COMMENT:{
3391 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3392 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3393 talloc_free(inf);
3395 break;
3397 case MP_CMD_GET_META_TRACK:{
3398 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3399 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3400 talloc_free(inf);
3402 break;
3404 case MP_CMD_GET_META_GENRE:{
3405 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3406 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3407 talloc_free(inf);
3409 break;
3411 case MP_CMD_GET_VO_FULLSCREEN:
3412 if (mpctx->video_out && mpctx->video_out->config_ok)
3413 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3414 break;
3416 case MP_CMD_GET_PERCENT_POS:
3417 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3418 get_percent_pos(mpctx));
3419 break;
3421 case MP_CMD_GET_TIME_POS:{
3422 float pos = get_current_time(mpctx);
3423 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3425 break;
3427 case MP_CMD_RUN:
3428 #ifndef __MINGW32__
3429 if (!fork()) {
3430 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3431 exit(0);
3433 #endif
3434 break;
3436 case MP_CMD_KEYDOWN_EVENTS:
3437 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3438 break;
3440 case MP_CMD_SET_MOUSE_POS:{
3441 int pointer_x, pointer_y;
3442 double dx, dy;
3443 pointer_x = cmd->args[0].v.i;
3444 pointer_y = cmd->args[1].v.i;
3445 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3446 #ifdef CONFIG_DVDNAV
3447 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3448 && dx > 0.0 && dy > 0.0) {
3449 int button = -1;
3450 pointer_x = (int) (dx * (double) sh_video->disp_w);
3451 pointer_y = (int) (dy * (double) sh_video->disp_h);
3452 mp_dvdnav_update_mouse_pos(mpctx->stream,
3453 pointer_x, pointer_y, &button);
3454 if (opts->osd_level > 1 && button > 0)
3455 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3456 "Selected button number %d", button);
3458 #endif
3459 #ifdef CONFIG_MENU
3460 if (use_menu && dx >= 0.0 && dy >= 0.0)
3461 menu_update_mouse_pos(dx, dy);
3462 #endif
3464 break;
3466 #ifdef CONFIG_DVDNAV
3467 case MP_CMD_DVDNAV:{
3468 int button = -1;
3469 int i;
3470 mp_command_type command = 0;
3471 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3472 break;
3474 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3475 if (cmd->args[0].v.s &&
3476 !strcasecmp (cmd->args[0].v.s,
3477 mp_dvdnav_bindings[i].name))
3478 command = mp_dvdnav_bindings[i].cmd;
3480 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3481 if (opts->osd_level > 1 && button > 0)
3482 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3483 "Selected button number %d", button);
3485 break;
3487 case MP_CMD_SWITCH_TITLE:
3488 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3489 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3490 break;
3492 #endif
3494 case MP_CMD_AF_SWITCH:
3495 if (sh_audio)
3497 af_uninit(mpctx->mixer.afilter);
3498 af_init(mpctx->mixer.afilter);
3500 case MP_CMD_AF_ADD:
3501 case MP_CMD_AF_DEL:
3502 if (!sh_audio)
3503 break;
3505 char* af_args = strdup(cmd->args[0].v.s);
3506 char* af_commands = af_args;
3507 char* af_command;
3508 af_instance_t* af;
3509 while ((af_command = strsep(&af_commands, ",")) != NULL)
3511 if (cmd->id == MP_CMD_AF_DEL)
3513 af = af_get(mpctx->mixer.afilter, af_command);
3514 if (af != NULL)
3515 af_remove(mpctx->mixer.afilter, af);
3517 else
3518 af_add(mpctx->mixer.afilter, af_command);
3520 reinit_audio_chain(mpctx);
3521 free(af_args);
3523 break;
3524 case MP_CMD_AF_CLR:
3525 if (!sh_audio)
3526 break;
3527 af_uninit(mpctx->mixer.afilter);
3528 af_init(mpctx->mixer.afilter);
3529 reinit_audio_chain(mpctx);
3530 break;
3531 case MP_CMD_AF_CMDLINE:
3532 if (sh_audio) {
3533 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3534 if (!af) {
3535 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3536 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3537 break;
3539 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3540 af_reinit(sh_audio->afilter, af);
3542 break;
3544 default:
3545 mp_msg(MSGT_CPLAYER, MSGL_V,
3546 "Received unknown cmd %s\n", cmd->name);
3549 switch (cmd->pausing) {
3550 case 1: // "pausing"
3551 pause_player(mpctx);
3552 break;
3553 case 3: // "pausing_toggle"
3554 if (mpctx->paused)
3555 unpause_player(mpctx);
3556 else
3557 pause_player(mpctx);
3558 break;