TOOLS/binary_codecs.sh: make indentation consistent
[mplayer/glamo.git] / command.c
blobe367687c5a01eb0e9d1692ccc3f52e495b7db14e
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 "libvo/sub.h"
35 #include "m_option.h"
36 #include "m_property.h"
37 #include "metadata.h"
38 #include "libmpcodecs/vf.h"
39 #include "libmpcodecs/vd.h"
40 #include "mp_osd.h"
41 #include "libvo/video_out.h"
42 #include "libvo/font_load.h"
43 #include "playtree.h"
44 #include "libao2/audio_out.h"
45 #include "mpcommon.h"
46 #include "mixer.h"
47 #include "libmpcodecs/dec_video.h"
48 #include "libmpcodecs/dec_audio.h"
49 #include "libmpcodecs/dec_teletext.h"
50 #include "vobsub.h"
51 #include "spudec.h"
52 #include "path.h"
53 #include "ass_mp.h"
54 #include "stream/tv.h"
55 #include "stream/stream_radio.h"
56 #include "stream/pvr.h"
57 #ifdef CONFIG_DVBIN
58 #include "stream/dvbin.h"
59 #endif
60 #ifdef CONFIG_DVDREAD
61 #include "stream/stream_dvd.h"
62 #endif
63 #include "stream/stream_dvdnav.h"
64 #include "m_struct.h"
65 #include "libmenu/menu.h"
67 #include "mp_core.h"
68 #include "mp_fifo.h"
69 #include "libavutil/avstring.h"
71 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
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->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;
196 if (subdata == NULL || vo_sub_last == NULL)
197 return;
198 fname = get_path("subtitle_log");
199 f = fopen(fname, "a");
200 if (!f)
201 return;
202 fprintf(f, "----------------------------------------------------------\n");
203 if (subdata->sub_uses_time) {
204 fprintf(f,
205 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
206 mpctx->filename, vo_sub_last->start / 360000,
207 (vo_sub_last->start / 6000) % 60,
208 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
209 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
210 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
211 } else {
212 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
213 vo_sub_last->start, vo_sub_last->end);
215 for (i = 0; i < vo_sub_last->lines; i++) {
216 fprintf(f, "%s\n", vo_sub_last->text[i]);
218 fclose(f);
222 /// \defgroup Properties
223 ///@{
225 /// \defgroup GeneralProperties General properties
226 /// \ingroup Properties
227 ///@{
229 /// OSD level (RW)
230 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
231 MPContext *mpctx)
233 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
236 /// Loop (RW)
237 static int mp_property_loop(m_option_t *prop, int action, void *arg,
238 MPContext *mpctx)
240 struct MPOpts *opts = &mpctx->opts;
241 switch (action) {
242 case M_PROPERTY_PRINT:
243 if (!arg) return M_PROPERTY_ERROR;
244 if (opts->loop_times < 0)
245 *(char**)arg = strdup("off");
246 else if (opts->loop_times == 0)
247 *(char**)arg = strdup("inf");
248 else
249 break;
250 return M_PROPERTY_OK;
252 return m_property_int_range(prop, action, arg, &opts->loop_times);
255 /// Playback speed (RW)
256 static int mp_property_playback_speed(m_option_t *prop, int action,
257 void *arg, MPContext *mpctx)
259 struct MPOpts *opts = &mpctx->opts;
260 switch (action) {
261 case M_PROPERTY_SET:
262 if (!arg)
263 return M_PROPERTY_ERROR;
264 M_PROPERTY_CLAMP(prop, *(float *) arg);
265 opts->playback_speed = *(float *) arg;
266 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
267 return M_PROPERTY_OK;
268 case M_PROPERTY_STEP_UP:
269 case M_PROPERTY_STEP_DOWN:
270 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
271 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
272 M_PROPERTY_CLAMP(prop, opts->playback_speed);
273 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
274 return M_PROPERTY_OK;
276 return m_property_float_range(prop, action, arg, &opts->playback_speed);
279 /// filename with path (RO)
280 static int mp_property_path(m_option_t *prop, int action, void *arg,
281 MPContext *mpctx)
283 return m_property_string_ro(prop, action, arg, mpctx->filename);
286 /// filename without path (RO)
287 static int mp_property_filename(m_option_t *prop, int action, void *arg,
288 MPContext *mpctx)
290 char *f;
291 if (!mpctx->filename)
292 return M_PROPERTY_UNAVAILABLE;
293 if (((f = strrchr(mpctx->filename, '/'))
294 || (f = strrchr(mpctx->filename, '\\'))) && f[1])
295 f++;
296 else
297 f = mpctx->filename;
298 return m_property_string_ro(prop, action, arg, f);
301 /// Demuxer name (RO)
302 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
303 MPContext *mpctx)
305 if (!mpctx->demuxer)
306 return M_PROPERTY_UNAVAILABLE;
307 return m_property_string_ro(prop, action, arg,
308 (char *) mpctx->demuxer->desc->name);
311 /// Position in the stream (RW)
312 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
313 MPContext *mpctx)
315 if (!mpctx->demuxer || !mpctx->demuxer->stream)
316 return M_PROPERTY_UNAVAILABLE;
317 if (!arg)
318 return M_PROPERTY_ERROR;
319 switch (action) {
320 case M_PROPERTY_GET:
321 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
322 return M_PROPERTY_OK;
323 case M_PROPERTY_SET:
324 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
325 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
326 return M_PROPERTY_OK;
328 return M_PROPERTY_NOT_IMPLEMENTED;
331 /// Stream start offset (RO)
332 static int mp_property_stream_start(m_option_t *prop, int action,
333 void *arg, MPContext *mpctx)
335 if (!mpctx->demuxer || !mpctx->demuxer->stream)
336 return M_PROPERTY_UNAVAILABLE;
337 switch (action) {
338 case M_PROPERTY_GET:
339 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
340 return M_PROPERTY_OK;
342 return M_PROPERTY_NOT_IMPLEMENTED;
345 /// Stream end offset (RO)
346 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
347 MPContext *mpctx)
349 if (!mpctx->demuxer || !mpctx->demuxer->stream)
350 return M_PROPERTY_UNAVAILABLE;
351 switch (action) {
352 case M_PROPERTY_GET:
353 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
354 return M_PROPERTY_OK;
356 return M_PROPERTY_NOT_IMPLEMENTED;
359 /// Stream length (RO)
360 static int mp_property_stream_length(m_option_t *prop, int action,
361 void *arg, MPContext *mpctx)
363 if (!mpctx->demuxer || !mpctx->demuxer->stream)
364 return M_PROPERTY_UNAVAILABLE;
365 switch (action) {
366 case M_PROPERTY_GET:
367 *(off_t *) arg =
368 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
369 return M_PROPERTY_OK;
371 return M_PROPERTY_NOT_IMPLEMENTED;
374 /// Current stream position in seconds (RO)
375 static int mp_property_stream_time_pos(m_option_t *prop, int action,
376 void *arg, MPContext *mpctx)
378 if (!mpctx->demuxer || mpctx->demuxer->stream_pts == MP_NOPTS_VALUE)
379 return M_PROPERTY_UNAVAILABLE;
381 return m_property_time_ro(prop, action, arg, mpctx->demuxer->stream_pts);
385 /// Media length in seconds (RO)
386 static int mp_property_length(m_option_t *prop, int action, void *arg,
387 MPContext *mpctx)
389 double len;
391 if (!mpctx->demuxer ||
392 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
393 return M_PROPERTY_UNAVAILABLE;
395 return m_property_time_ro(prop, action, arg, len);
398 /// Current position in percent (RW)
399 static int mp_property_percent_pos(m_option_t *prop, int action,
400 void *arg, MPContext *mpctx) {
401 int pos;
403 if (!mpctx->demuxer)
404 return M_PROPERTY_UNAVAILABLE;
406 switch(action) {
407 case M_PROPERTY_SET:
408 if(!arg) return M_PROPERTY_ERROR;
409 M_PROPERTY_CLAMP(prop, *(int*)arg);
410 pos = *(int*)arg;
411 break;
412 case M_PROPERTY_STEP_UP:
413 case M_PROPERTY_STEP_DOWN:
414 pos = demuxer_get_percent_pos(mpctx->demuxer);
415 pos += (arg ? *(int*)arg : 10) *
416 (action == M_PROPERTY_STEP_UP ? 1 : -1);
417 M_PROPERTY_CLAMP(prop, pos);
418 break;
419 default:
420 return m_property_int_ro(prop, action, arg,
421 demuxer_get_percent_pos(mpctx->demuxer));
424 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
425 mpctx->rel_seek_secs = pos / 100.0;
426 return M_PROPERTY_OK;
429 /// Current position in seconds (RW)
430 static int mp_property_time_pos(m_option_t *prop, int action,
431 void *arg, MPContext *mpctx) {
432 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
433 return M_PROPERTY_UNAVAILABLE;
435 switch(action) {
436 case M_PROPERTY_SET:
437 if(!arg) return M_PROPERTY_ERROR;
438 M_PROPERTY_CLAMP(prop, *(double*)arg);
439 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
440 mpctx->rel_seek_secs = *(double*)arg;
441 return M_PROPERTY_OK;
442 case M_PROPERTY_STEP_UP:
443 case M_PROPERTY_STEP_DOWN:
444 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
445 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
446 return M_PROPERTY_OK;
448 return m_property_time_ro(prop, action, arg,
449 mpctx->sh_video ? mpctx->sh_video->pts :
450 playing_audio_pts(mpctx));
453 /// Current chapter (RW)
454 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
455 MPContext *mpctx)
457 struct MPOpts *opts = &mpctx->opts;
458 int chapter = -1;
459 int step_all;
460 char *chapter_name = NULL;
462 if (mpctx->demuxer)
463 chapter = get_current_chapter(mpctx);
464 if (chapter < -1)
465 return M_PROPERTY_UNAVAILABLE;
467 switch (action) {
468 case M_PROPERTY_GET:
469 if (!arg)
470 return M_PROPERTY_ERROR;
471 *(int *) arg = chapter;
472 return M_PROPERTY_OK;
473 case M_PROPERTY_PRINT: {
474 if (!arg)
475 return M_PROPERTY_ERROR;
476 chapter_name = chapter_display_name(mpctx, chapter);
477 if (!chapter_name)
478 return M_PROPERTY_UNAVAILABLE;
479 *(char **) arg = chapter_name;
480 return M_PROPERTY_OK;
482 case M_PROPERTY_SET:
483 if (!arg)
484 return M_PROPERTY_ERROR;
485 M_PROPERTY_CLAMP(prop, *(int*)arg);
486 step_all = *(int *)arg - chapter;
487 chapter += step_all;
488 break;
489 case M_PROPERTY_STEP_UP:
490 case M_PROPERTY_STEP_DOWN: {
491 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
492 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
493 chapter += step_all;
494 if (chapter < 0)
495 chapter = 0;
496 break;
498 default:
499 return M_PROPERTY_NOT_IMPLEMENTED;
502 double next_pts = 0;
503 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
504 mpctx->rel_seek_secs = 0;
505 mpctx->abs_seek_pos = 0;
506 if (chapter >= 0) {
507 if (next_pts > -1.0) {
508 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
509 mpctx->rel_seek_secs = next_pts;
511 if (chapter_name)
512 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
513 "Chapter: (%d) %s", chapter + 1, chapter_name);
515 else if (step_all > 0)
516 mpctx->rel_seek_secs = 1000000000.;
517 else
518 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
519 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
520 if (chapter_name)
521 talloc_free(chapter_name);
522 return M_PROPERTY_OK;
525 /// Number of chapters in file
526 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
527 MPContext *mpctx)
529 if (!mpctx->demuxer)
530 return M_PROPERTY_UNAVAILABLE;
531 if (mpctx->demuxer->num_chapters == 0)
532 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
533 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
536 /// Current dvd angle (RW)
537 static int mp_property_angle(m_option_t *prop, int action, void *arg,
538 MPContext *mpctx)
540 struct MPOpts *opts = &mpctx->opts;
541 int angle = -1;
542 int angles;
543 char *angle_name = NULL;
545 if (mpctx->demuxer)
546 angle = demuxer_get_current_angle(mpctx->demuxer);
547 if (angle < 0)
548 return M_PROPERTY_UNAVAILABLE;
549 angles = demuxer_angles_count(mpctx->demuxer);
550 if (angles <= 1)
551 return M_PROPERTY_UNAVAILABLE;
553 switch (action) {
554 case M_PROPERTY_GET:
555 if (!arg)
556 return M_PROPERTY_ERROR;
557 *(int *) arg = angle;
558 return M_PROPERTY_OK;
559 case M_PROPERTY_PRINT: {
560 if (!arg)
561 return M_PROPERTY_ERROR;
562 angle_name = calloc(1, 64);
563 if (!angle_name)
564 return M_PROPERTY_UNAVAILABLE;
565 snprintf(angle_name, 64, "%d/%d", angle, angles);
566 *(char **) arg = angle_name;
567 return M_PROPERTY_OK;
569 case M_PROPERTY_SET:
570 if (!arg)
571 return M_PROPERTY_ERROR;
572 angle = *(int *)arg;
573 M_PROPERTY_CLAMP(prop, angle);
574 break;
575 case M_PROPERTY_STEP_UP:
576 case M_PROPERTY_STEP_DOWN: {
577 int step = 0;
578 if(arg)
579 step = *(int*)arg;
580 if(!step)
581 step = 1;
582 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
583 angle += step;
584 if (angle < 1) //cycle
585 angle = angles;
586 break;
588 default:
589 return M_PROPERTY_NOT_IMPLEMENTED;
591 angle = demuxer_set_angle(mpctx->demuxer, angle);
592 if (angle >= 0) {
593 struct sh_video *sh_video = mpctx->demuxer->video->sh;
594 if (sh_video)
595 resync_video_stream(sh_video);
597 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
598 if (sh_audio)
599 resync_audio_stream(sh_audio);
602 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
603 "Angle: %d/%d", angle, angles);
604 if (angle_name)
605 free(angle_name);
606 return M_PROPERTY_OK;
609 /// Demuxer meta data
610 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
611 MPContext *mpctx) {
612 m_property_action_t* ka;
613 char* meta;
614 static const m_option_t key_type =
615 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
616 if (!mpctx->demuxer)
617 return M_PROPERTY_UNAVAILABLE;
619 switch(action) {
620 case M_PROPERTY_GET:
621 if(!arg) return M_PROPERTY_ERROR;
622 *(char***)arg = mpctx->demuxer->info;
623 return M_PROPERTY_OK;
624 case M_PROPERTY_KEY_ACTION:
625 if(!arg) return M_PROPERTY_ERROR;
626 ka = arg;
627 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
628 return M_PROPERTY_UNKNOWN;
629 switch(ka->action) {
630 case M_PROPERTY_GET:
631 if(!ka->arg) return M_PROPERTY_ERROR;
632 *(char**)ka->arg = meta;
633 return M_PROPERTY_OK;
634 case M_PROPERTY_GET_TYPE:
635 if(!ka->arg) return M_PROPERTY_ERROR;
636 *(const m_option_t**)ka->arg = &key_type;
637 return M_PROPERTY_OK;
640 return M_PROPERTY_NOT_IMPLEMENTED;
643 static int mp_property_pause(m_option_t *prop, int action, void *arg,
644 void *ctx)
646 MPContext *mpctx = ctx;
648 switch (action) {
649 case M_PROPERTY_SET:
650 if (!arg)
651 return M_PROPERTY_ERROR;
652 if (mpctx->paused == (bool)*(int *) arg)
653 return M_PROPERTY_OK;
654 case M_PROPERTY_STEP_UP:
655 case M_PROPERTY_STEP_DOWN:
656 if (mpctx->paused) {
657 unpause_player(mpctx);
658 mpctx->osd_function = OSD_PLAY;
660 else {
661 pause_player(mpctx);
662 mpctx->osd_function = OSD_PAUSE;
664 return M_PROPERTY_OK;
665 default:
666 return m_property_flag(prop, action, arg, &mpctx->paused);
671 ///@}
673 /// \defgroup AudioProperties Audio properties
674 /// \ingroup Properties
675 ///@{
677 /// Volume (RW)
678 static int mp_property_volume(m_option_t *prop, int action, void *arg,
679 MPContext *mpctx)
682 if (!mpctx->sh_audio)
683 return M_PROPERTY_UNAVAILABLE;
685 switch (action) {
686 case M_PROPERTY_GET:
687 if (!arg)
688 return M_PROPERTY_ERROR;
689 mixer_getbothvolume(&mpctx->mixer, arg);
690 return M_PROPERTY_OK;
691 case M_PROPERTY_PRINT:{
692 float vol;
693 if (!arg)
694 return M_PROPERTY_ERROR;
695 mixer_getbothvolume(&mpctx->mixer, &vol);
696 return m_property_float_range(prop, action, arg, &vol);
698 case M_PROPERTY_STEP_UP:
699 case M_PROPERTY_STEP_DOWN:
700 case M_PROPERTY_SET:
701 break;
702 default:
703 return M_PROPERTY_NOT_IMPLEMENTED;
706 if (mpctx->edl_muted)
707 return M_PROPERTY_DISABLED;
708 mpctx->user_muted = 0;
710 switch (action) {
711 case M_PROPERTY_SET:
712 if (!arg)
713 return M_PROPERTY_ERROR;
714 M_PROPERTY_CLAMP(prop, *(float *) arg);
715 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
716 return M_PROPERTY_OK;
717 case M_PROPERTY_STEP_UP:
718 if (arg && *(float *) arg <= 0)
719 mixer_decvolume(&mpctx->mixer);
720 else
721 mixer_incvolume(&mpctx->mixer);
722 return M_PROPERTY_OK;
723 case M_PROPERTY_STEP_DOWN:
724 if (arg && *(float *) arg <= 0)
725 mixer_incvolume(&mpctx->mixer);
726 else
727 mixer_decvolume(&mpctx->mixer);
728 return M_PROPERTY_OK;
730 return M_PROPERTY_NOT_IMPLEMENTED;
733 /// Mute (RW)
734 static int mp_property_mute(m_option_t *prop, int action, void *arg,
735 MPContext *mpctx)
738 if (!mpctx->sh_audio)
739 return M_PROPERTY_UNAVAILABLE;
741 switch (action) {
742 case M_PROPERTY_SET:
743 if (mpctx->edl_muted)
744 return M_PROPERTY_DISABLED;
745 if (!arg)
746 return M_PROPERTY_ERROR;
747 if ((!!*(int *) arg) != mpctx->mixer.muted)
748 mixer_mute(&mpctx->mixer);
749 mpctx->user_muted = mpctx->mixer.muted;
750 return M_PROPERTY_OK;
751 case M_PROPERTY_STEP_UP:
752 case M_PROPERTY_STEP_DOWN:
753 if (mpctx->edl_muted)
754 return M_PROPERTY_DISABLED;
755 mixer_mute(&mpctx->mixer);
756 mpctx->user_muted = mpctx->mixer.muted;
757 return M_PROPERTY_OK;
758 case M_PROPERTY_PRINT:
759 if (!arg)
760 return M_PROPERTY_ERROR;
761 if (mpctx->edl_muted) {
762 *(char **) arg = strdup(mp_gtext("enabled (EDL)"));
763 return M_PROPERTY_OK;
765 default:
766 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
771 /// Audio delay (RW)
772 static int mp_property_audio_delay(m_option_t *prop, int action,
773 void *arg, MPContext *mpctx)
775 if (!(mpctx->sh_audio && mpctx->sh_video))
776 return M_PROPERTY_UNAVAILABLE;
777 switch (action) {
778 case M_PROPERTY_SET:
779 case M_PROPERTY_STEP_UP:
780 case M_PROPERTY_STEP_DOWN: {
781 int ret;
782 float delay = audio_delay;
783 ret = m_property_delay(prop, action, arg, &audio_delay);
784 if (ret != M_PROPERTY_OK)
785 return ret;
786 if (mpctx->sh_audio)
787 mpctx->delay -= audio_delay - delay;
789 return M_PROPERTY_OK;
790 default:
791 return m_property_delay(prop, action, arg, &audio_delay);
795 /// Audio codec tag (RO)
796 static int mp_property_audio_format(m_option_t *prop, int action,
797 void *arg, MPContext *mpctx)
799 if (!mpctx->sh_audio)
800 return M_PROPERTY_UNAVAILABLE;
801 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
804 /// Audio codec name (RO)
805 static int mp_property_audio_codec(m_option_t *prop, int action,
806 void *arg, MPContext *mpctx)
808 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
809 return M_PROPERTY_UNAVAILABLE;
810 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
813 /// Audio bitrate (RO)
814 static int mp_property_audio_bitrate(m_option_t *prop, int action,
815 void *arg, MPContext *mpctx)
817 if (!mpctx->sh_audio)
818 return M_PROPERTY_UNAVAILABLE;
819 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
822 /// Samplerate (RO)
823 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
824 MPContext *mpctx)
826 if (!mpctx->sh_audio)
827 return M_PROPERTY_UNAVAILABLE;
828 switch(action) {
829 case M_PROPERTY_PRINT:
830 if(!arg) return M_PROPERTY_ERROR;
831 *(char**)arg = malloc(16);
832 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
833 return M_PROPERTY_OK;
835 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
838 /// Number of channels (RO)
839 static int mp_property_channels(m_option_t *prop, int action, void *arg,
840 MPContext *mpctx)
842 if (!mpctx->sh_audio)
843 return M_PROPERTY_UNAVAILABLE;
844 switch (action) {
845 case M_PROPERTY_PRINT:
846 if (!arg)
847 return M_PROPERTY_ERROR;
848 switch (mpctx->sh_audio->channels) {
849 case 1:
850 *(char **) arg = strdup("mono");
851 break;
852 case 2:
853 *(char **) arg = strdup("stereo");
854 break;
855 default:
856 *(char **) arg = malloc(32);
857 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
859 return M_PROPERTY_OK;
861 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
864 /// Balance (RW)
865 static int mp_property_balance(m_option_t *prop, int action, void *arg,
866 MPContext *mpctx)
868 float bal;
870 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
871 return M_PROPERTY_UNAVAILABLE;
873 switch (action) {
874 case M_PROPERTY_GET:
875 if (!arg)
876 return M_PROPERTY_ERROR;
877 mixer_getbalance(&mpctx->mixer, arg);
878 return M_PROPERTY_OK;
879 case M_PROPERTY_PRINT: {
880 char** str = arg;
881 if (!arg)
882 return M_PROPERTY_ERROR;
883 mixer_getbalance(&mpctx->mixer, &bal);
884 if (bal == 0.f)
885 *str = strdup("center");
886 else if (bal == -1.f)
887 *str = strdup("left only");
888 else if (bal == 1.f)
889 *str = strdup("right only");
890 else {
891 unsigned right = (bal + 1.f) / 2.f * 100.f;
892 *str = malloc(sizeof("left xxx%, right xxx%"));
893 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
895 return M_PROPERTY_OK;
897 case M_PROPERTY_STEP_UP:
898 case M_PROPERTY_STEP_DOWN:
899 mixer_getbalance(&mpctx->mixer, &bal);
900 bal += (arg ? *(float*)arg : .1f) *
901 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
902 M_PROPERTY_CLAMP(prop, bal);
903 mixer_setbalance(&mpctx->mixer, bal);
904 return M_PROPERTY_OK;
905 case M_PROPERTY_SET:
906 if (!arg)
907 return M_PROPERTY_ERROR;
908 M_PROPERTY_CLAMP(prop, *(float*)arg);
909 mixer_setbalance(&mpctx->mixer, *(float*)arg);
910 return M_PROPERTY_OK;
912 return M_PROPERTY_NOT_IMPLEMENTED;
915 /// Selected audio id (RW)
916 static int mp_property_audio(m_option_t *prop, int action, void *arg,
917 MPContext *mpctx)
919 int current_id, tmp;
920 if (!mpctx->demuxer || !mpctx->demuxer->audio)
921 return M_PROPERTY_UNAVAILABLE;
922 current_id = mpctx->sh_audio ? mpctx->sh_audio->aid : -2;
924 switch (action) {
925 case M_PROPERTY_GET:
926 if (!arg)
927 return M_PROPERTY_ERROR;
928 *(int *) arg = current_id;
929 return M_PROPERTY_OK;
930 case M_PROPERTY_PRINT:
931 if (!arg)
932 return M_PROPERTY_ERROR;
934 if (current_id < 0)
935 *(char **) arg = strdup(mp_gtext("disabled"));
936 else {
937 char lang[40];
938 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
939 sh_audio_t* sh = mpctx->sh_audio;
940 if (sh && sh->lang)
941 av_strlcpy(lang, sh->lang, 40);
942 #ifdef CONFIG_DVDREAD
943 else if (mpctx->stream->type == STREAMTYPE_DVD) {
944 int code = dvd_lang_from_aid(mpctx->stream, current_id);
945 if (code) {
946 lang[0] = code >> 8;
947 lang[1] = code;
948 lang[2] = 0;
951 #endif
953 #ifdef CONFIG_DVDNAV
954 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
955 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
956 #endif
957 *(char **) arg = malloc(64);
958 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
960 return M_PROPERTY_OK;
962 case M_PROPERTY_STEP_UP:
963 case M_PROPERTY_SET:
964 if (action == M_PROPERTY_SET && arg)
965 tmp = *((int *) arg);
966 else
967 tmp = -1;
968 int new_id = demuxer_switch_audio(mpctx->demuxer, tmp);
969 if (new_id != current_id)
970 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
971 if (new_id != current_id && new_id >= 0) {
972 sh_audio_t *sh2;
973 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
974 sh2->ds = mpctx->demuxer->audio;
975 mpctx->sh_audio = sh2;
976 reinit_audio_chain(mpctx);
978 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
979 return M_PROPERTY_OK;
980 default:
981 return M_PROPERTY_NOT_IMPLEMENTED;
986 /// Selected video id (RW)
987 static int mp_property_video(m_option_t *prop, int action, void *arg,
988 MPContext *mpctx)
990 struct MPOpts *opts = &mpctx->opts;
991 int current_id, tmp;
992 if (!mpctx->demuxer || !mpctx->demuxer->video)
993 return M_PROPERTY_UNAVAILABLE;
994 current_id = mpctx->demuxer->video->id;
996 switch (action) {
997 case M_PROPERTY_GET:
998 if (!arg)
999 return M_PROPERTY_ERROR;
1000 *(int *) arg = current_id;
1001 return M_PROPERTY_OK;
1002 case M_PROPERTY_PRINT:
1003 if (!arg)
1004 return M_PROPERTY_ERROR;
1006 if (current_id < 0)
1007 *(char **) arg = strdup(mp_gtext("disabled"));
1008 else {
1009 char lang[40];
1010 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
1011 *(char **) arg = malloc(64);
1012 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
1014 return M_PROPERTY_OK;
1016 case M_PROPERTY_STEP_UP:
1017 case M_PROPERTY_SET:
1018 if (action == M_PROPERTY_SET && arg)
1019 tmp = *((int *) arg);
1020 else
1021 tmp = -1;
1022 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
1023 if (opts->video_id == -2
1024 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
1025 && current_id != -2))
1026 uninit_player(mpctx, INITIALIZED_VCODEC |
1027 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
1028 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
1029 sh_video_t *sh2;
1030 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
1031 if (sh2) {
1032 sh2->ds = mpctx->demuxer->video;
1033 mpctx->sh_video = sh2;
1034 reinit_video_chain(mpctx);
1037 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
1038 return M_PROPERTY_OK;
1040 default:
1041 return M_PROPERTY_NOT_IMPLEMENTED;
1045 static int mp_property_program(m_option_t *prop, int action, void *arg,
1046 MPContext *mpctx)
1048 demux_program_t prog;
1050 switch (action) {
1051 case M_PROPERTY_STEP_UP:
1052 case M_PROPERTY_SET:
1053 if (action == M_PROPERTY_SET && arg)
1054 prog.progid = *((int *) arg);
1055 else
1056 prog.progid = -1;
1057 if (demux_control
1058 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1059 &prog) == DEMUXER_CTRL_NOTIMPL)
1060 return M_PROPERTY_ERROR;
1062 if (prog.aid < 0 && prog.vid < 0) {
1063 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
1064 return M_PROPERTY_ERROR;
1066 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1067 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1068 return M_PROPERTY_OK;
1070 default:
1071 return M_PROPERTY_NOT_IMPLEMENTED;
1075 ///@}
1077 /// \defgroup VideoProperties Video properties
1078 /// \ingroup Properties
1079 ///@{
1081 /// Fullscreen state (RW)
1082 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1083 MPContext *mpctx)
1086 if (!mpctx->video_out)
1087 return M_PROPERTY_UNAVAILABLE;
1089 switch (action) {
1090 case M_PROPERTY_SET:
1091 if (!arg)
1092 return M_PROPERTY_ERROR;
1093 M_PROPERTY_CLAMP(prop, *(int *) arg);
1094 if (vo_fs == !!*(int *) arg)
1095 return M_PROPERTY_OK;
1096 case M_PROPERTY_STEP_UP:
1097 case M_PROPERTY_STEP_DOWN:
1098 if (mpctx->video_out->config_ok)
1099 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1100 mpctx->opts.fullscreen = vo_fs;
1101 return M_PROPERTY_OK;
1102 default:
1103 return m_property_flag(prop, action, arg, &vo_fs);
1107 static int mp_property_deinterlace(m_option_t *prop, int action,
1108 void *arg, MPContext *mpctx)
1110 int deinterlace;
1111 vf_instance_t *vf;
1112 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1113 return M_PROPERTY_UNAVAILABLE;
1114 vf = mpctx->sh_video->vfilter;
1115 switch (action) {
1116 case M_PROPERTY_GET:
1117 if (!arg)
1118 return M_PROPERTY_ERROR;
1119 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1120 return M_PROPERTY_OK;
1121 case M_PROPERTY_SET:
1122 if (!arg)
1123 return M_PROPERTY_ERROR;
1124 M_PROPERTY_CLAMP(prop, *(int *) arg);
1125 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1126 return M_PROPERTY_OK;
1127 case M_PROPERTY_STEP_UP:
1128 case M_PROPERTY_STEP_DOWN:
1129 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1130 deinterlace = !deinterlace;
1131 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1132 return M_PROPERTY_OK;
1134 int value = 0;
1135 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1136 return m_property_flag_ro(prop, action, arg, value);
1139 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1140 void *arg, MPContext *mpctx)
1142 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1143 return M_PROPERTY_UNAVAILABLE;
1145 struct vf_instance *vf = mpctx->sh_video->vfilter;
1146 int colorspace;
1147 switch (action) {
1148 case M_PROPERTY_GET:
1149 if (!arg)
1150 return M_PROPERTY_ERROR;
1151 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1152 return M_PROPERTY_UNAVAILABLE;
1153 return M_PROPERTY_OK;
1154 case M_PROPERTY_PRINT:
1155 if (!arg)
1156 return M_PROPERTY_ERROR;
1157 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1158 return M_PROPERTY_UNAVAILABLE;
1159 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1160 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1161 *(char **)arg = strdup("Unknown");
1162 else
1163 *(char**)arg = strdup(names[colorspace]);
1164 return M_PROPERTY_OK;
1165 case M_PROPERTY_SET:
1166 if (!arg)
1167 return M_PROPERTY_ERROR;
1168 M_PROPERTY_CLAMP(prop, *(int *) arg);
1169 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1170 return M_PROPERTY_OK;
1171 case M_PROPERTY_STEP_UP:;
1172 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1173 return M_PROPERTY_UNAVAILABLE;
1174 colorspace += 1;
1175 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1176 return M_PROPERTY_OK;
1178 return M_PROPERTY_NOT_IMPLEMENTED;
1181 static int mp_property_capture(m_option_t *prop, int action,
1182 void *arg, MPContext *mpctx)
1184 struct MPOpts *opts = &mpctx->opts;
1186 if (!mpctx->stream)
1187 return M_PROPERTY_UNAVAILABLE;
1189 if (!opts->capture_dump) {
1190 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1191 "Capturing not enabled (forgot -capture parameter?)\n");
1192 return M_PROPERTY_ERROR;
1195 int capturing = !!mpctx->stream->capture_file;
1197 int ret = m_property_flag(prop, action, arg, &capturing);
1198 if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
1199 if (capturing) {
1200 mpctx->stream->capture_file = fopen(opts->stream_dump_name, "wb");
1201 if (!mpctx->stream->capture_file) {
1202 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1203 "Error opening capture file: %s\n", strerror(errno));
1204 ret = M_PROPERTY_ERROR;
1206 } else {
1207 fclose(mpctx->stream->capture_file);
1208 mpctx->stream->capture_file = NULL;
1212 return ret;
1215 /// Panscan (RW)
1216 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1217 MPContext *mpctx)
1220 if (!mpctx->video_out
1221 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1222 return M_PROPERTY_UNAVAILABLE;
1224 switch (action) {
1225 case M_PROPERTY_SET:
1226 if (!arg)
1227 return M_PROPERTY_ERROR;
1228 M_PROPERTY_CLAMP(prop, *(float *) arg);
1229 vo_panscan = *(float *) arg;
1230 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1231 return M_PROPERTY_OK;
1232 case M_PROPERTY_STEP_UP:
1233 case M_PROPERTY_STEP_DOWN:
1234 vo_panscan += (arg ? *(float *) arg : 0.1) *
1235 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1236 if (vo_panscan > 1)
1237 vo_panscan = 1;
1238 else if (vo_panscan < 0)
1239 vo_panscan = 0;
1240 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1241 return M_PROPERTY_OK;
1242 default:
1243 return m_property_float_range(prop, action, arg, &vo_panscan);
1247 /// Helper to set vo flags.
1248 /** \ingroup PropertyImplHelper
1250 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1251 int vo_ctrl, int *vo_var, MPContext *mpctx)
1254 if (!mpctx->video_out)
1255 return M_PROPERTY_UNAVAILABLE;
1257 switch (action) {
1258 case M_PROPERTY_SET:
1259 if (!arg)
1260 return M_PROPERTY_ERROR;
1261 M_PROPERTY_CLAMP(prop, *(int *) arg);
1262 if (*vo_var == !!*(int *) arg)
1263 return M_PROPERTY_OK;
1264 case M_PROPERTY_STEP_UP:
1265 case M_PROPERTY_STEP_DOWN:
1266 if (mpctx->video_out->config_ok)
1267 vo_control(mpctx->video_out, vo_ctrl, 0);
1268 return M_PROPERTY_OK;
1269 default:
1270 return m_property_flag(prop, action, arg, vo_var);
1274 /// Window always on top (RW)
1275 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1276 MPContext *mpctx)
1278 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1279 &mpctx->opts.vo_ontop, mpctx);
1282 /// Display in the root window (RW)
1283 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1284 MPContext *mpctx)
1286 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1287 &vo_rootwin, mpctx);
1290 /// Show window borders (RW)
1291 static int mp_property_border(m_option_t *prop, int action, void *arg,
1292 MPContext *mpctx)
1294 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1295 &vo_border, mpctx);
1298 /// Framedropping state (RW)
1299 static int mp_property_framedropping(m_option_t *prop, int action,
1300 void *arg, MPContext *mpctx)
1303 if (!mpctx->sh_video)
1304 return M_PROPERTY_UNAVAILABLE;
1306 switch (action) {
1307 case M_PROPERTY_PRINT:
1308 if (!arg)
1309 return M_PROPERTY_ERROR;
1310 *(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
1311 (frame_dropping == 2 ? mp_gtext("hard") :
1312 mp_gtext("disabled")));
1313 return M_PROPERTY_OK;
1314 default:
1315 return m_property_choice(prop, action, arg, &frame_dropping);
1319 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1320 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1321 MPContext *mpctx)
1323 int *gamma = (int *)((char *)&mpctx->opts + prop->offset);
1324 int r, val;
1326 if (!mpctx->sh_video)
1327 return M_PROPERTY_UNAVAILABLE;
1329 if (gamma[0] == 1000) {
1330 gamma[0] = 0;
1331 get_video_colors(mpctx->sh_video, prop->name, gamma);
1334 switch (action) {
1335 case M_PROPERTY_SET:
1336 if (!arg)
1337 return M_PROPERTY_ERROR;
1338 M_PROPERTY_CLAMP(prop, *(int *) arg);
1339 *gamma = *(int *) arg;
1340 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1341 if (r <= 0)
1342 break;
1343 return r;
1344 case M_PROPERTY_GET:
1345 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1346 if (!arg)
1347 return M_PROPERTY_ERROR;
1348 *(int *)arg = val;
1349 return M_PROPERTY_OK;
1351 break;
1352 case M_PROPERTY_STEP_UP:
1353 case M_PROPERTY_STEP_DOWN:
1354 *gamma += (arg ? *(int *) arg : 1) *
1355 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1356 M_PROPERTY_CLAMP(prop, *gamma);
1357 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1358 if (r <= 0)
1359 break;
1360 return r;
1361 default:
1362 return M_PROPERTY_NOT_IMPLEMENTED;
1365 #ifdef CONFIG_TV
1366 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1367 int l = strlen(prop->name);
1368 char tv_prop[3 + l + 1];
1369 sprintf(tv_prop, "tv_%s", prop->name);
1370 return mp_property_do(tv_prop, action, arg, mpctx);
1372 #endif
1374 return M_PROPERTY_UNAVAILABLE;
1377 /// VSync (RW)
1378 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1379 MPContext *mpctx)
1381 return m_property_flag(prop, action, arg, &vo_vsync);
1384 /// Video codec tag (RO)
1385 static int mp_property_video_format(m_option_t *prop, int action,
1386 void *arg, MPContext *mpctx)
1388 char* meta;
1389 if (!mpctx->sh_video)
1390 return M_PROPERTY_UNAVAILABLE;
1391 switch(action) {
1392 case M_PROPERTY_PRINT:
1393 if (!arg)
1394 return M_PROPERTY_ERROR;
1395 switch(mpctx->sh_video->format) {
1396 case 0x10000001:
1397 meta = strdup ("mpeg1"); break;
1398 case 0x10000002:
1399 meta = strdup ("mpeg2"); break;
1400 case 0x10000004:
1401 meta = strdup ("mpeg4"); break;
1402 case 0x10000005:
1403 meta = strdup ("h264"); break;
1404 default:
1405 if(mpctx->sh_video->format >= 0x20202020) {
1406 meta = malloc(5);
1407 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1408 } else {
1409 meta = malloc(20);
1410 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1413 *(char**)arg = meta;
1414 return M_PROPERTY_OK;
1416 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1419 /// Video codec name (RO)
1420 static int mp_property_video_codec(m_option_t *prop, int action,
1421 void *arg, MPContext *mpctx)
1423 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1424 return M_PROPERTY_UNAVAILABLE;
1425 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1429 /// Video bitrate (RO)
1430 static int mp_property_video_bitrate(m_option_t *prop, int action,
1431 void *arg, MPContext *mpctx)
1433 if (!mpctx->sh_video)
1434 return M_PROPERTY_UNAVAILABLE;
1435 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1438 /// Video display width (RO)
1439 static int mp_property_width(m_option_t *prop, int action, void *arg,
1440 MPContext *mpctx)
1442 if (!mpctx->sh_video)
1443 return M_PROPERTY_UNAVAILABLE;
1444 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1447 /// Video display height (RO)
1448 static int mp_property_height(m_option_t *prop, int action, void *arg,
1449 MPContext *mpctx)
1451 if (!mpctx->sh_video)
1452 return M_PROPERTY_UNAVAILABLE;
1453 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1456 /// Video fps (RO)
1457 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1458 MPContext *mpctx)
1460 if (!mpctx->sh_video)
1461 return M_PROPERTY_UNAVAILABLE;
1462 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1465 /// Video aspect (RO)
1466 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1467 MPContext *mpctx)
1469 if (!mpctx->sh_video)
1470 return M_PROPERTY_UNAVAILABLE;
1471 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1474 ///@}
1476 /// \defgroup SubProprties Subtitles properties
1477 /// \ingroup Properties
1478 ///@{
1480 /// Text subtitle position (RW)
1481 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1482 MPContext *mpctx)
1484 switch (action) {
1485 case M_PROPERTY_SET:
1486 if (!arg)
1487 return M_PROPERTY_ERROR;
1488 case M_PROPERTY_STEP_UP:
1489 case M_PROPERTY_STEP_DOWN:
1490 vo_osd_changed(OSDTYPE_SUBTITLE);
1491 default:
1492 return m_property_int_range(prop, action, arg, &sub_pos);
1496 /// Selected subtitles (RW)
1497 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1498 MPContext *mpctx)
1500 struct MPOpts *opts = &mpctx->opts;
1501 demux_stream_t *const d_sub = mpctx->d_sub;
1502 int source = -1, reset_spu = 0;
1503 int source_pos = -1;
1504 char *sub_name;
1506 update_global_sub_size(mpctx);
1507 const int global_sub_size = mpctx->global_sub_size;
1509 if (global_sub_size <= 0)
1510 return M_PROPERTY_UNAVAILABLE;
1512 switch (action) {
1513 case M_PROPERTY_GET:
1514 if (!arg)
1515 return M_PROPERTY_ERROR;
1516 *(int *) arg = mpctx->global_sub_pos;
1517 return M_PROPERTY_OK;
1518 case M_PROPERTY_PRINT:
1519 if (!arg)
1520 return M_PROPERTY_ERROR;
1521 *(char **) arg = malloc(64);
1522 (*(char **) arg)[63] = 0;
1523 sub_name = 0;
1524 if (subdata)
1525 sub_name = subdata->filename;
1526 #ifdef CONFIG_ASS
1527 if (ass_track && ass_track->name)
1528 sub_name = ass_track->name;
1529 #endif
1530 if (sub_name) {
1531 char *tmp, *tmp2;
1532 tmp = sub_name;
1533 if ((tmp2 = strrchr(tmp, '/')))
1534 tmp = tmp2 + 1;
1536 snprintf(*(char **) arg, 63, "(%d) %s%s",
1537 mpctx->set_of_sub_pos + 1,
1538 strlen(tmp) < 20 ? "" : "...",
1539 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1540 return M_PROPERTY_OK;
1542 #ifdef CONFIG_DVDNAV
1543 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1544 if (vo_spudec && opts->sub_id >= 0) {
1545 unsigned char lang[3];
1546 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1547 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1548 return M_PROPERTY_OK;
1552 #endif
1554 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1555 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1556 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1557 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1558 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1559 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1560 if (!lang) lang = mp_gtext("unknown");
1561 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1562 return M_PROPERTY_OK;
1565 if (vo_vobsub && vobsub_id >= 0) {
1566 const char *language = mp_gtext("unknown");
1567 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1568 snprintf(*(char **) arg, 63, "(%d) %s",
1569 vobsub_id, language ? language : mp_gtext("unknown"));
1570 return M_PROPERTY_OK;
1572 #ifdef CONFIG_DVDREAD
1573 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1574 && opts->sub_id >= 0) {
1575 char lang[3];
1576 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1577 lang[0] = code >> 8;
1578 lang[1] = code;
1579 lang[2] = 0;
1580 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1581 return M_PROPERTY_OK;
1583 #endif
1584 if (opts->sub_id >= 0) {
1585 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
1586 mp_gtext("unknown"));
1587 return M_PROPERTY_OK;
1589 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1590 return M_PROPERTY_OK;
1592 case M_PROPERTY_SET:
1593 if (!arg)
1594 return M_PROPERTY_ERROR;
1595 if (*(int *) arg < -1)
1596 *(int *) arg = -1;
1597 else if (*(int *) arg >= global_sub_size)
1598 *(int *) arg = global_sub_size - 1;
1599 mpctx->global_sub_pos = *(int *) arg;
1600 break;
1601 case M_PROPERTY_STEP_UP:
1602 mpctx->global_sub_pos += 2;
1603 mpctx->global_sub_pos =
1604 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1605 break;
1606 case M_PROPERTY_STEP_DOWN:
1607 mpctx->global_sub_pos += global_sub_size + 1;
1608 mpctx->global_sub_pos =
1609 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1610 break;
1611 default:
1612 return M_PROPERTY_NOT_IMPLEMENTED;
1615 if (mpctx->global_sub_pos >= 0) {
1616 source = sub_source(mpctx);
1617 source_pos = sub_source_pos(mpctx);
1620 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1621 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1622 global_sub_size,
1623 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1624 mpctx->sub_counts[SUB_SOURCE_SUBS],
1625 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1626 mpctx->global_sub_pos, source);
1628 mpctx->set_of_sub_pos = -1;
1629 subdata = NULL;
1631 vobsub_id = -1;
1632 opts->sub_id = -1;
1633 if (d_sub) {
1634 if (d_sub->id > -2)
1635 reset_spu = 1;
1636 d_sub->id = -2;
1638 #ifdef CONFIG_ASS
1639 ass_track = 0;
1640 #endif
1642 if (source == SUB_SOURCE_VOBSUB) {
1643 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1644 } else if (source == SUB_SOURCE_SUBS) {
1645 mpctx->set_of_sub_pos = source_pos;
1646 #ifdef CONFIG_ASS
1647 if (opts->ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1648 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1649 else
1650 #endif
1652 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1653 vo_osd_changed(OSDTYPE_SUBTITLE);
1655 } else if (source == SUB_SOURCE_DEMUX) {
1656 opts->sub_id = source_pos;
1657 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1658 int i = 0;
1659 // default: assume 1:1 mapping of sid and stream id
1660 d_sub->id = opts->sub_id;
1661 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1662 ds_free_packs(d_sub);
1663 for (i = 0; i < MAX_S_STREAMS; i++) {
1664 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1665 if (sh && sh->sid == opts->sub_id) {
1666 d_sub->id = i;
1667 d_sub->sh = sh;
1668 break;
1671 if (d_sub->sh && d_sub->id >= 0) {
1672 sh_sub_t *sh = d_sub->sh;
1673 if (sh->type == 'v')
1674 init_vo_spudec(mpctx);
1675 #ifdef CONFIG_ASS
1676 else if (opts->ass_enabled)
1677 ass_track = sh->ass_track;
1678 #endif
1679 } else {
1680 d_sub->id = -2;
1681 d_sub->sh = NULL;
1685 #ifdef CONFIG_DVDREAD
1686 if (vo_spudec
1687 && (mpctx->stream->type == STREAMTYPE_DVD
1688 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1689 && opts->sub_id < 0 && reset_spu) {
1690 d_sub->id = -2;
1691 d_sub->sh = NULL;
1693 #endif
1695 update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, 0, 0, d_sub, 1);
1697 return M_PROPERTY_OK;
1700 /// Selected sub source (RW)
1701 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1702 MPContext *mpctx)
1704 int source;
1705 update_global_sub_size(mpctx);
1706 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1707 return M_PROPERTY_UNAVAILABLE;
1709 switch (action) {
1710 case M_PROPERTY_GET:
1711 if (!arg)
1712 return M_PROPERTY_ERROR;
1713 *(int *) arg = sub_source(mpctx);
1714 return M_PROPERTY_OK;
1715 case M_PROPERTY_PRINT:
1716 if (!arg)
1717 return M_PROPERTY_ERROR;
1718 *(char **) arg = malloc(64);
1719 (*(char **) arg)[63] = 0;
1720 switch (sub_source(mpctx))
1722 case SUB_SOURCE_SUBS:
1723 snprintf(*(char **) arg, 63, mp_gtext("file"));
1724 break;
1725 case SUB_SOURCE_VOBSUB:
1726 snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
1727 break;
1728 case SUB_SOURCE_DEMUX:
1729 snprintf(*(char **) arg, 63, mp_gtext("embedded"));
1730 break;
1731 default:
1732 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1734 return M_PROPERTY_OK;
1735 case M_PROPERTY_SET:
1736 if (!arg)
1737 return M_PROPERTY_ERROR;
1738 M_PROPERTY_CLAMP(prop, *(int*)arg);
1739 if (*(int *) arg < 0)
1740 mpctx->global_sub_pos = -1;
1741 else if (*(int *) arg != sub_source(mpctx)) {
1742 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1743 if (new_pos == -1)
1744 return M_PROPERTY_UNAVAILABLE;
1745 mpctx->global_sub_pos = new_pos;
1747 break;
1748 case M_PROPERTY_STEP_UP:
1749 case M_PROPERTY_STEP_DOWN: {
1750 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1751 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1752 int step = (step_all > 0) ? 1 : -1;
1753 int cur_source = sub_source(mpctx);
1754 source = cur_source;
1755 while (step_all) {
1756 source += step;
1757 if (source >= SUB_SOURCES)
1758 source = -1;
1759 else if (source < -1)
1760 source = SUB_SOURCES - 1;
1761 if (source == cur_source || source == -1 ||
1762 mpctx->sub_counts[source])
1763 step_all -= step;
1765 if (source == cur_source)
1766 return M_PROPERTY_OK;
1767 if (source == -1)
1768 mpctx->global_sub_pos = -1;
1769 else
1770 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1771 break;
1773 default:
1774 return M_PROPERTY_NOT_IMPLEMENTED;
1776 --mpctx->global_sub_pos;
1777 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1780 /// Selected subtitles from specific source (RW)
1781 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1782 MPContext *mpctx)
1784 int source, is_cur_source, offset, new_pos;
1785 update_global_sub_size(mpctx);
1786 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1787 return M_PROPERTY_UNAVAILABLE;
1789 if (!strcmp(prop->name, "sub_file"))
1790 source = SUB_SOURCE_SUBS;
1791 else if (!strcmp(prop->name, "sub_vob"))
1792 source = SUB_SOURCE_VOBSUB;
1793 else if (!strcmp(prop->name, "sub_demux"))
1794 source = SUB_SOURCE_DEMUX;
1795 else
1796 return M_PROPERTY_ERROR;
1798 offset = sub_pos_by_source(mpctx, source);
1799 if (offset < 0)
1800 return M_PROPERTY_UNAVAILABLE;
1802 is_cur_source = sub_source(mpctx) == source;
1803 new_pos = mpctx->global_sub_pos;
1804 switch (action) {
1805 case M_PROPERTY_GET:
1806 if (!arg)
1807 return M_PROPERTY_ERROR;
1808 if (is_cur_source) {
1809 *(int *) arg = sub_source_pos(mpctx);
1810 if (source == SUB_SOURCE_VOBSUB)
1811 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1813 else
1814 *(int *) arg = -1;
1815 return M_PROPERTY_OK;
1816 case M_PROPERTY_PRINT:
1817 if (!arg)
1818 return M_PROPERTY_ERROR;
1819 if (is_cur_source)
1820 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1821 *(char **) arg = malloc(64);
1822 (*(char **) arg)[63] = 0;
1823 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1824 return M_PROPERTY_OK;
1825 case M_PROPERTY_SET:
1826 if (!arg)
1827 return M_PROPERTY_ERROR;
1828 if (*(int *) arg >= 0) {
1829 int index = *(int *)arg;
1830 if (source == SUB_SOURCE_VOBSUB)
1831 index = vobsub_get_index_by_id(vo_vobsub, index);
1832 new_pos = offset + index;
1833 if (index < 0 || index > mpctx->sub_counts[source]) {
1834 new_pos = -1;
1835 *(int *) arg = -1;
1838 else
1839 new_pos = -1;
1840 break;
1841 case M_PROPERTY_STEP_UP:
1842 case M_PROPERTY_STEP_DOWN: {
1843 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1844 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1845 int step = (step_all > 0) ? 1 : -1;
1846 int max_sub_pos_for_source = -1;
1847 if (!is_cur_source)
1848 new_pos = -1;
1849 while (step_all) {
1850 if (new_pos == -1) {
1851 if (step > 0)
1852 new_pos = offset;
1853 else if (max_sub_pos_for_source == -1) {
1854 // Find max pos for specific source
1855 new_pos = mpctx->global_sub_size - 1;
1856 while (new_pos >= 0
1857 && sub_source(mpctx) != source)
1858 new_pos--;
1860 else
1861 new_pos = max_sub_pos_for_source;
1863 else {
1864 new_pos += step;
1865 if (new_pos < offset ||
1866 new_pos >= mpctx->global_sub_size ||
1867 sub_source(mpctx) != source)
1868 new_pos = -1;
1870 step_all -= step;
1872 break;
1874 default:
1875 return M_PROPERTY_NOT_IMPLEMENTED;
1877 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1880 /// Subtitle delay (RW)
1881 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1882 MPContext *mpctx)
1884 if (!mpctx->sh_video)
1885 return M_PROPERTY_UNAVAILABLE;
1886 return m_property_delay(prop, action, arg, &sub_delay);
1889 /// Alignment of text subtitles (RW)
1890 static int mp_property_sub_alignment(m_option_t *prop, int action,
1891 void *arg, MPContext *mpctx)
1893 char *name[] = { _("top"), _("center"), _("bottom") };
1895 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1896 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1897 return M_PROPERTY_UNAVAILABLE;
1899 switch (action) {
1900 case M_PROPERTY_PRINT:
1901 if (!arg)
1902 return M_PROPERTY_ERROR;
1903 M_PROPERTY_CLAMP(prop, sub_alignment);
1904 *(char **) arg = strdup(mp_gtext(name[sub_alignment]));
1905 return M_PROPERTY_OK;
1906 case M_PROPERTY_SET:
1907 if (!arg)
1908 return M_PROPERTY_ERROR;
1909 case M_PROPERTY_STEP_UP:
1910 case M_PROPERTY_STEP_DOWN:
1911 vo_osd_changed(OSDTYPE_SUBTITLE);
1912 default:
1913 return m_property_choice(prop, action, arg, &sub_alignment);
1917 /// Subtitle visibility (RW)
1918 static int mp_property_sub_visibility(m_option_t *prop, int action,
1919 void *arg, MPContext *mpctx)
1921 if (!mpctx->sh_video)
1922 return M_PROPERTY_UNAVAILABLE;
1924 switch (action) {
1925 case M_PROPERTY_SET:
1926 if (!arg)
1927 return M_PROPERTY_ERROR;
1928 case M_PROPERTY_STEP_UP:
1929 case M_PROPERTY_STEP_DOWN:
1930 vo_osd_changed(OSDTYPE_SUBTITLE);
1931 if (vo_spudec)
1932 vo_osd_changed(OSDTYPE_SPU);
1933 default:
1934 return m_property_flag(prop, action, arg, &sub_visibility);
1938 #ifdef CONFIG_ASS
1939 /// Use margins for libass subtitles (RW)
1940 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1941 void *arg, MPContext *mpctx)
1943 if (!mpctx->sh_video)
1944 return M_PROPERTY_UNAVAILABLE;
1946 switch (action) {
1947 case M_PROPERTY_SET:
1948 if (!arg)
1949 return M_PROPERTY_ERROR;
1950 case M_PROPERTY_STEP_UP:
1951 case M_PROPERTY_STEP_DOWN:
1952 ass_force_reload = 1;
1953 default:
1954 return m_property_flag(prop, action, arg, &ass_use_margins);
1957 #endif
1959 /// Show only forced subtitles (RW)
1960 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1961 void *arg, MPContext *mpctx)
1963 if (!vo_spudec)
1964 return M_PROPERTY_UNAVAILABLE;
1966 switch (action) {
1967 case M_PROPERTY_SET:
1968 if (!arg)
1969 return M_PROPERTY_ERROR;
1970 case M_PROPERTY_STEP_UP:
1971 case M_PROPERTY_STEP_DOWN:
1972 m_property_flag(prop, action, arg, &forced_subs_only);
1973 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1974 return M_PROPERTY_OK;
1975 default:
1976 return m_property_flag(prop, action, arg, &forced_subs_only);
1981 #ifdef CONFIG_FREETYPE
1982 /// Subtitle scale (RW)
1983 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1984 MPContext *mpctx)
1986 struct MPOpts *opts = &mpctx->opts;
1988 switch (action) {
1989 case M_PROPERTY_SET:
1990 if (!arg)
1991 return M_PROPERTY_ERROR;
1992 M_PROPERTY_CLAMP(prop, *(float *) arg);
1993 #ifdef CONFIG_ASS
1994 if (opts->ass_enabled) {
1995 ass_font_scale = *(float *) arg;
1996 ass_force_reload = 1;
1998 #endif
1999 text_font_scale_factor = *(float *) arg;
2000 force_load_font = 1;
2001 return M_PROPERTY_OK;
2002 case M_PROPERTY_STEP_UP:
2003 case M_PROPERTY_STEP_DOWN:
2004 #ifdef CONFIG_ASS
2005 if (opts->ass_enabled) {
2006 ass_font_scale += (arg ? *(float *) arg : 0.1)*
2007 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2008 M_PROPERTY_CLAMP(prop, ass_font_scale);
2009 ass_force_reload = 1;
2011 #endif
2012 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
2013 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2014 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
2015 force_load_font = 1;
2016 return M_PROPERTY_OK;
2017 default:
2018 #ifdef CONFIG_ASS
2019 if (opts->ass_enabled)
2020 return m_property_float_ro(prop, action, arg, ass_font_scale);
2021 else
2022 #endif
2023 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
2026 #endif
2028 ///@}
2030 /// \defgroup TVProperties TV properties
2031 /// \ingroup Properties
2032 ///@{
2034 #ifdef CONFIG_TV
2036 /// TV color settings (RW)
2037 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2038 MPContext *mpctx)
2040 int r, val;
2041 tvi_handle_t *tvh = mpctx->demuxer->priv;
2042 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2043 return M_PROPERTY_UNAVAILABLE;
2045 switch (action) {
2046 case M_PROPERTY_SET:
2047 if (!arg)
2048 return M_PROPERTY_ERROR;
2049 M_PROPERTY_CLAMP(prop, *(int *) arg);
2050 return tv_set_color_options(tvh, prop->offset, *(int *) arg);
2051 case M_PROPERTY_GET:
2052 return tv_get_color_options(tvh, prop->offset, arg);
2053 case M_PROPERTY_STEP_UP:
2054 case M_PROPERTY_STEP_DOWN:
2055 if ((r = tv_get_color_options(tvh, prop->offset, &val)) >= 0) {
2056 if (!r)
2057 return M_PROPERTY_ERROR;
2058 val += (arg ? *(int *) arg : 1) *
2059 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2060 M_PROPERTY_CLAMP(prop, val);
2061 return tv_set_color_options(tvh, prop->offset, val);
2063 return M_PROPERTY_ERROR;
2065 return M_PROPERTY_NOT_IMPLEMENTED;
2068 #endif
2070 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2071 MPContext *mpctx)
2073 int val,result;
2074 int base_ioctl = prop->offset;
2076 for teletext's GET,SET,STEP ioctls this is not 0
2077 SET is GET+1
2078 STEP is GET+2
2080 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2081 return M_PROPERTY_UNAVAILABLE;
2082 if(!base_ioctl)
2083 return M_PROPERTY_ERROR;
2085 switch (action) {
2086 case M_PROPERTY_GET:
2087 if (!arg)
2088 return M_PROPERTY_ERROR;
2089 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2090 break;
2091 case M_PROPERTY_SET:
2092 if (!arg)
2093 return M_PROPERTY_ERROR;
2094 M_PROPERTY_CLAMP(prop, *(int *) arg);
2095 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
2096 break;
2097 case M_PROPERTY_STEP_UP:
2098 case M_PROPERTY_STEP_DOWN:
2099 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2100 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2101 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
2102 break;
2103 default:
2104 return M_PROPERTY_NOT_IMPLEMENTED;
2107 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2110 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2111 MPContext *mpctx)
2113 int result;
2114 int val;
2116 //with tvh==NULL will fail too
2117 result=mp_property_teletext_common(prop,action,arg,mpctx);
2118 if(result!=M_PROPERTY_OK)
2119 return result;
2121 if(teletext_control(mpctx->demuxer->teletext,
2122 prop->offset, &val)==VBI_CONTROL_TRUE && val)
2123 mp_input_set_section(mpctx->input, "teletext");
2124 else
2125 mp_input_set_section(mpctx->input, "tv");
2126 return M_PROPERTY_OK;
2129 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2130 MPContext *mpctx)
2132 int result;
2133 int val;
2134 if (!mpctx->demuxer->teletext)
2135 return M_PROPERTY_UNAVAILABLE;
2136 switch(action){
2137 case M_PROPERTY_STEP_UP:
2138 case M_PROPERTY_STEP_DOWN:
2139 //This should be handled separately
2140 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2141 result=teletext_control(mpctx->demuxer->teletext,
2142 TV_VBI_CONTROL_STEP_PAGE, &val);
2143 break;
2144 default:
2145 result=mp_property_teletext_common(prop,action,arg,mpctx);
2147 return result;
2150 ///@}
2152 /// All properties available in MPlayer.
2153 /** \ingroup Properties
2155 static const m_option_t mp_properties[] = {
2156 // General
2157 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2158 M_OPT_RANGE, 0, 3, NULL },
2159 { "loop", mp_property_loop, CONF_TYPE_INT,
2160 M_OPT_MIN, -1, 0, NULL },
2161 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2162 M_OPT_RANGE, 0.01, 100.0, NULL },
2163 { "filename", mp_property_filename, CONF_TYPE_STRING,
2164 0, 0, 0, NULL },
2165 { "path", mp_property_path, CONF_TYPE_STRING,
2166 0, 0, 0, NULL },
2167 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2168 0, 0, 0, NULL },
2169 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2170 M_OPT_MIN, 0, 0, NULL },
2171 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2172 M_OPT_MIN, 0, 0, NULL },
2173 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2174 M_OPT_MIN, 0, 0, NULL },
2175 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2176 M_OPT_MIN, 0, 0, NULL },
2177 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2178 M_OPT_MIN, 0, 0, NULL },
2179 { "length", mp_property_length, CONF_TYPE_TIME,
2180 M_OPT_MIN, 0, 0, NULL },
2181 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2182 M_OPT_RANGE, 0, 100, NULL },
2183 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2184 M_OPT_MIN, 0, 0, NULL },
2185 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2186 M_OPT_MIN, 0, 0, NULL },
2187 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2188 0, 0, 0, NULL },
2189 { "angle", mp_property_angle, CONF_TYPE_INT,
2190 CONF_RANGE, -2, 10, NULL },
2191 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2192 0, 0, 0, NULL },
2193 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2194 M_OPT_RANGE, 0, 1, NULL },
2195 { "capturing", mp_property_capture, CONF_TYPE_FLAG,
2196 M_OPT_RANGE, 0, 1, NULL },
2198 // Audio
2199 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2200 M_OPT_RANGE, 0, 100, NULL },
2201 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2202 M_OPT_RANGE, 0, 1, NULL },
2203 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2204 M_OPT_RANGE, -100, 100, NULL },
2205 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2206 0, 0, 0, NULL },
2207 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2208 0, 0, 0, NULL },
2209 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2210 0, 0, 0, NULL },
2211 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2212 0, 0, 0, NULL },
2213 { "channels", mp_property_channels, CONF_TYPE_INT,
2214 0, 0, 0, NULL },
2215 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2216 CONF_RANGE, -2, 65535, NULL },
2217 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2218 M_OPT_RANGE, -1, 1, NULL },
2220 // Video
2221 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2222 M_OPT_RANGE, 0, 1, NULL },
2223 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2224 M_OPT_RANGE, 0, 1, NULL },
2225 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2226 M_OPT_RANGE, 0, 2, NULL },
2227 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2228 M_OPT_RANGE, 0, 1, NULL },
2229 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2230 M_OPT_RANGE, 0, 1, NULL },
2231 { "border", mp_property_border, CONF_TYPE_FLAG,
2232 M_OPT_RANGE, 0, 1, NULL },
2233 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2234 M_OPT_RANGE, 0, 2, NULL },
2235 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2236 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_gamma)},
2237 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2238 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_brightness) },
2239 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2240 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_contrast) },
2241 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2242 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_saturation) },
2243 { "hue", mp_property_gamma, CONF_TYPE_INT,
2244 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_hue) },
2245 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2246 M_OPT_RANGE, 0, 1, NULL },
2247 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2248 M_OPT_RANGE, 0, 1, NULL },
2249 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2250 0, 0, 0, NULL },
2251 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2252 0, 0, 0, NULL },
2253 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2254 0, 0, 0, NULL },
2255 { "width", mp_property_width, CONF_TYPE_INT,
2256 0, 0, 0, NULL },
2257 { "height", mp_property_height, CONF_TYPE_INT,
2258 0, 0, 0, NULL },
2259 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2260 0, 0, 0, NULL },
2261 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2262 0, 0, 0, NULL },
2263 { "switch_video", mp_property_video, CONF_TYPE_INT,
2264 CONF_RANGE, -2, 65535, NULL },
2265 { "switch_program", mp_property_program, CONF_TYPE_INT,
2266 CONF_RANGE, -1, 65535, NULL },
2268 // Subs
2269 { "sub", mp_property_sub, CONF_TYPE_INT,
2270 M_OPT_MIN, -1, 0, NULL },
2271 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2272 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2273 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2274 M_OPT_MIN, -1, 0, NULL },
2275 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2276 M_OPT_MIN, -1, 0, NULL },
2277 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2278 M_OPT_MIN, -1, 0, NULL },
2279 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2280 0, 0, 0, NULL },
2281 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2282 M_OPT_RANGE, 0, 100, NULL },
2283 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2284 M_OPT_RANGE, 0, 2, NULL },
2285 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2286 M_OPT_RANGE, 0, 1, NULL },
2287 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2288 M_OPT_RANGE, 0, 1, NULL },
2289 #ifdef CONFIG_FREETYPE
2290 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2291 M_OPT_RANGE, 0, 100, NULL },
2292 #endif
2293 #ifdef CONFIG_ASS
2294 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2295 M_OPT_RANGE, 0, 1, NULL },
2296 #endif
2298 #ifdef CONFIG_TV
2299 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2300 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_BRIGHTNESS },
2301 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2302 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_CONTRAST },
2303 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2304 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_SATURATION },
2305 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2306 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_HUE },
2307 #endif
2308 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2309 M_OPT_RANGE, 100, 899, .offset=TV_VBI_CONTROL_GET_PAGE },
2310 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2311 M_OPT_RANGE, 0, 64, .offset=TV_VBI_CONTROL_GET_SUBPAGE },
2312 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2313 M_OPT_RANGE, 0, 1, .offset=TV_VBI_CONTROL_GET_MODE },
2314 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2315 M_OPT_RANGE, 0, 3, .offset=TV_VBI_CONTROL_GET_FORMAT },
2316 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2317 M_OPT_RANGE, 0, 2, .offset=TV_VBI_CONTROL_GET_HALF_PAGE },
2318 { NULL, NULL, NULL, 0, 0, 0, NULL }
2322 int mp_property_do(const char *name, int action, void *val, void *ctx)
2324 return m_property_do(mp_properties, name, action, val, ctx);
2327 char* mp_property_print(const char *name, void* ctx)
2329 char* ret = NULL;
2330 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2331 return NULL;
2332 return ret;
2335 char *property_expand_string(MPContext *mpctx, char *str)
2337 return m_properties_expand_string(mp_properties, str, mpctx);
2340 void property_print_help(void)
2342 m_properties_print_help_list(mp_properties);
2346 /* List of default ways to show a property on OSD.
2348 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2349 * a bar showing the current position between min/max values of the
2350 * property. In this case osd_msg is only used for terminal output
2351 * if there is no video; it'll be a label shown together with percentage.
2353 * Otherwise setting osd_msg will show the string on OSD, formatted with
2354 * the text value of the property as argument.
2356 static struct property_osd_display {
2357 /// property name
2358 const char *name;
2359 /// progressbar type
2360 int osd_progbar; // -1 is special value for seek indicators
2361 /// osd msg id if it must be shared
2362 int osd_id;
2363 /// osd msg template
2364 const char *osd_msg;
2365 } property_osd_display[] = {
2366 // general
2367 { "loop", 0, -1, _("Loop: %s") },
2368 { "chapter", -1, -1, NULL },
2369 { "capturing", 0, -1, _("Capturing: %s") },
2370 // audio
2371 { "volume", OSD_VOLUME, -1, _("Volume") },
2372 { "mute", 0, -1, _("Mute: %s") },
2373 { "audio_delay", 0, -1, _("A-V delay: %s") },
2374 { "switch_audio", 0, -1, _("Audio: %s") },
2375 { "balance", OSD_BALANCE, -1, _("Balance") },
2376 // video
2377 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2378 { "ontop", 0, -1, _("Stay on top: %s") },
2379 { "rootwin", 0, -1, _("Rootwin: %s") },
2380 { "border", 0, -1, _("Border: %s") },
2381 { "framedropping", 0, -1, _("Framedropping: %s") },
2382 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2383 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2384 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2385 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2386 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2387 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2388 { "hue", OSD_HUE, -1, _("Hue") },
2389 { "vsync", 0, -1, _("VSync: %s") },
2390 // subs
2391 { "sub", 0, -1, _("Subtitles: %s") },
2392 { "sub_source", 0, -1, _("Sub source: %s") },
2393 { "sub_vob", 0, -1, _("Subtitles: %s") },
2394 { "sub_demux", 0, -1, _("Subtitles: %s") },
2395 { "sub_file", 0, -1, _("Subtitles: %s") },
2396 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2397 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2398 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2399 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2400 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2401 #ifdef CONFIG_FREETYPE
2402 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2403 #endif
2404 #ifdef CONFIG_TV
2405 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2406 { "tv_hue", OSD_HUE, -1, _("Hue") },
2407 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2408 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2409 #endif
2413 static int show_property_osd(MPContext *mpctx, const char *pname)
2415 struct MPOpts *opts = &mpctx->opts;
2416 int r;
2417 m_option_t* prop;
2418 struct property_osd_display *p;
2420 // look for the command
2421 for (p = property_osd_display; p->name; p++)
2422 if (!strcmp(p->name, pname))
2423 break;
2424 if (!p->name)
2425 return -1;
2427 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2428 return -1;
2430 if (p->osd_progbar == -1)
2431 mpctx->add_osd_seek_info = true;
2432 else if (p->osd_progbar) {
2433 if (prop->type == CONF_TYPE_INT) {
2434 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2435 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2436 prop->min, prop->max, r);
2437 } else if (prop->type == CONF_TYPE_FLOAT) {
2438 float f;
2439 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2440 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2441 prop->min, prop->max, f);
2442 } else {
2443 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2444 "Property use an unsupported type.\n");
2445 return -1;
2447 return 0;
2450 if (p->osd_msg) {
2451 char *val = mp_property_print(pname, mpctx);
2452 if (val) {
2453 int index = p - property_osd_display;
2454 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2455 1, opts->osd_duration, p->osd_msg, val);
2456 free(val);
2459 return 0;
2464 * \defgroup Command2Property Command to property bridge
2466 * It is used to handle most commands that just set a property
2467 * and optionally display something on the OSD.
2468 * Two kinds of commands are handled: adjust or toggle.
2470 * Adjust commands take 1 or 2 parameters: <value> <abs>
2471 * If <abs> is non-zero the property is set to the given value
2472 * otherwise it is adjusted.
2474 * Toggle commands take 0 or 1 parameters. With no parameter
2475 * or a value less than the property minimum it just steps the
2476 * property to its next value. Otherwise it sets it to the given
2477 * value.
2482 /// List of the commands that can be handled by setting a property.
2483 static struct {
2484 /// property name
2485 const char *name;
2486 /// cmd id
2487 int cmd;
2488 /// set/adjust or toggle command
2489 int toggle;
2490 } set_prop_cmd[] = {
2491 // general
2492 { "loop", MP_CMD_LOOP, 0},
2493 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2494 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2495 { "pause", MP_CMD_PAUSE, 0},
2496 { "capturing", MP_CMD_CAPTURING, 1},
2497 // audio
2498 { "volume", MP_CMD_VOLUME, 0},
2499 { "mute", MP_CMD_MUTE, 1},
2500 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2501 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2502 { "balance", MP_CMD_BALANCE, 0},
2503 // video
2504 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2505 { "panscan", MP_CMD_PANSCAN, 0},
2506 { "ontop", MP_CMD_VO_ONTOP, 1},
2507 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2508 { "border", MP_CMD_VO_BORDER, 1},
2509 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2510 { "gamma", MP_CMD_GAMMA, 0},
2511 { "brightness", MP_CMD_BRIGHTNESS, 0},
2512 { "contrast", MP_CMD_CONTRAST, 0},
2513 { "saturation", MP_CMD_SATURATION, 0},
2514 { "hue", MP_CMD_HUE, 0},
2515 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2516 // subs
2517 { "sub", MP_CMD_SUB_SELECT, 1},
2518 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2519 { "sub_vob", MP_CMD_SUB_VOB, 1},
2520 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2521 { "sub_file", MP_CMD_SUB_FILE, 1},
2522 { "sub_pos", MP_CMD_SUB_POS, 0},
2523 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2524 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2525 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2526 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2527 #ifdef CONFIG_FREETYPE
2528 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2529 #endif
2530 #ifdef CONFIG_ASS
2531 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2532 #endif
2533 #ifdef CONFIG_TV
2534 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2535 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2536 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2537 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2538 #endif
2542 /// Handle commands that set a property.
2543 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2545 int i, r;
2546 m_option_t *prop;
2547 const char *pname;
2549 // look for the command
2550 for (i = 0; set_prop_cmd[i].name; i++)
2551 if (set_prop_cmd[i].cmd == cmd->id)
2552 break;
2553 if (!(pname = set_prop_cmd[i].name))
2554 return 0;
2556 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2557 return 0;
2559 // toggle command
2560 if (set_prop_cmd[i].toggle) {
2561 // set to value
2562 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2563 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2564 else
2565 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2566 } else if (cmd->args[1].v.i) //set
2567 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2568 else // adjust
2569 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2571 if (r <= 0)
2572 return 1;
2574 show_property_osd(mpctx, pname);
2576 return 1;
2579 #ifdef CONFIG_DVDNAV
2580 static const struct {
2581 const char *name;
2582 const mp_command_type cmd;
2583 } mp_dvdnav_bindings[] = {
2584 { "up", MP_CMD_DVDNAV_UP },
2585 { "down", MP_CMD_DVDNAV_DOWN },
2586 { "left", MP_CMD_DVDNAV_LEFT },
2587 { "right", MP_CMD_DVDNAV_RIGHT },
2588 { "menu", MP_CMD_DVDNAV_MENU },
2589 { "select", MP_CMD_DVDNAV_SELECT },
2590 { "prev", MP_CMD_DVDNAV_PREVMENU },
2591 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2594 * keep old dvdnav sub-command options for a while in order not to
2595 * break slave-mode API too suddenly.
2597 { "1", MP_CMD_DVDNAV_UP },
2598 { "2", MP_CMD_DVDNAV_DOWN },
2599 { "3", MP_CMD_DVDNAV_LEFT },
2600 { "4", MP_CMD_DVDNAV_RIGHT },
2601 { "5", MP_CMD_DVDNAV_MENU },
2602 { "6", MP_CMD_DVDNAV_SELECT },
2603 { "7", MP_CMD_DVDNAV_PREVMENU },
2604 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2605 { NULL, 0 }
2607 #endif
2609 static const char *property_error_string(int error_value)
2611 switch (error_value) {
2612 case M_PROPERTY_ERROR:
2613 return "ERROR";
2614 case M_PROPERTY_UNAVAILABLE:
2615 return "PROPERTY_UNAVAILABLE";
2616 case M_PROPERTY_NOT_IMPLEMENTED:
2617 return "NOT_IMPLEMENTED";
2618 case M_PROPERTY_UNKNOWN:
2619 return "PROPERTY_UNKNOWN";
2620 case M_PROPERTY_DISABLED:
2621 return "DISABLED";
2623 return "UNKNOWN";
2626 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2628 int idx;
2629 int end = start + count;
2630 int after = mpctx->set_of_sub_size - end;
2631 sub_data **subs = mpctx->set_of_subtitles;
2632 #ifdef CONFIG_ASS
2633 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2634 #endif
2635 if (count < 0 || count > mpctx->set_of_sub_size ||
2636 start < 0 || start > mpctx->set_of_sub_size - count) {
2637 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2638 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2639 return;
2641 for (idx = start; idx < end; idx++) {
2642 sub_data *subd = subs[idx];
2643 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2644 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2645 filename_recode(subd->filename));
2646 sub_free(subd);
2647 subs[idx] = NULL;
2648 #ifdef CONFIG_ASS
2649 if (ass_tracks[idx])
2650 ass_free_track(ass_tracks[idx]);
2651 ass_tracks[idx] = NULL;
2652 #endif
2655 mpctx->global_sub_size -= count;
2656 mpctx->set_of_sub_size -= count;
2657 if (mpctx->set_of_sub_size <= 0)
2658 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2660 memmove(subs + start, subs + end, after * sizeof(*subs));
2661 memset(subs + start + after, 0, count * sizeof(*subs));
2662 #ifdef CONFIG_ASS
2663 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2664 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2665 #endif
2667 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2668 mpctx->global_sub_pos = -2;
2669 subdata = NULL;
2670 #ifdef CONFIG_ASS
2671 ass_track = NULL;
2672 #endif
2673 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2674 } else if (mpctx->set_of_sub_pos >= end) {
2675 mpctx->set_of_sub_pos -= count;
2676 mpctx->global_sub_pos -= count;
2680 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2682 struct MPOpts *opts = &mpctx->opts;
2683 sh_audio_t * const sh_audio = mpctx->sh_audio;
2684 sh_video_t * const sh_video = mpctx->sh_video;
2685 int osd_duration = opts->osd_duration;
2686 int case_fallthrough_hack = 0;
2687 if (!set_property_command(mpctx, cmd))
2688 switch (cmd->id) {
2689 case MP_CMD_SEEK:{
2690 float v;
2691 int abs;
2692 mpctx->add_osd_seek_info = true;
2693 v = cmd->args[0].v.f;
2694 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2695 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2696 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2697 if (sh_video)
2698 mpctx->osd_function =
2699 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2700 mpctx->rel_seek_secs = v;
2701 } else if (abs) { /* Absolute seek by percentage */
2702 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2703 if (sh_video)
2704 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2705 mpctx->rel_seek_secs = v / 100.0;
2706 } else {
2707 mpctx->rel_seek_secs += v;
2708 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2711 break;
2713 case MP_CMD_SET_PROPERTY_OSD:
2714 case_fallthrough_hack = 1;
2716 case MP_CMD_SET_PROPERTY:{
2717 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2718 cmd->args[1].v.s, mpctx);
2719 if (r == M_PROPERTY_UNKNOWN)
2720 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2721 "Unknown property: '%s'\n", cmd->args[0].v.s);
2722 else if (r <= 0)
2723 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2724 "Failed to set property '%s' to '%s'.\n",
2725 cmd->args[0].v.s, cmd->args[1].v.s);
2726 else if (case_fallthrough_hack)
2727 show_property_osd(mpctx, cmd->args[0].v.s);
2728 if (r <= 0)
2729 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2731 break;
2733 case MP_CMD_STEP_PROPERTY_OSD:
2734 case_fallthrough_hack = 1;
2736 case MP_CMD_STEP_PROPERTY:{
2737 void* arg = NULL;
2738 int r,i;
2739 double d;
2740 off_t o;
2741 if (cmd->args[1].v.f) {
2742 m_option_t* prop;
2743 if((r = mp_property_do(cmd->args[0].v.s,
2744 M_PROPERTY_GET_TYPE,
2745 &prop, mpctx)) <= 0)
2746 goto step_prop_err;
2747 if(prop->type == CONF_TYPE_INT ||
2748 prop->type == CONF_TYPE_FLAG)
2749 i = cmd->args[1].v.f, arg = &i;
2750 else if(prop->type == CONF_TYPE_FLOAT)
2751 arg = &cmd->args[1].v.f;
2752 else if(prop->type == CONF_TYPE_DOUBLE ||
2753 prop->type == CONF_TYPE_TIME)
2754 d = cmd->args[1].v.f, arg = &d;
2755 else if(prop->type == CONF_TYPE_POSITION)
2756 o = cmd->args[1].v.f, arg = &o;
2757 else
2758 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2759 "Ignoring step size stepping property '%s'.\n",
2760 cmd->args[0].v.s);
2762 r = mp_property_do(cmd->args[0].v.s,
2763 cmd->args[2].v.i < 0 ?
2764 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2765 arg, mpctx);
2766 step_prop_err:
2767 if (r == M_PROPERTY_UNKNOWN)
2768 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2769 "Unknown property: '%s'\n", cmd->args[0].v.s);
2770 else if (r <= 0)
2771 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2772 "Failed to increment property '%s' by %f.\n",
2773 cmd->args[0].v.s, cmd->args[1].v.f);
2774 else if (case_fallthrough_hack)
2775 show_property_osd(mpctx, cmd->args[0].v.s);
2776 if (r <= 0)
2777 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2779 break;
2781 case MP_CMD_GET_PROPERTY:{
2782 char *tmp;
2783 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2784 &tmp, mpctx);
2785 if (r <= 0) {
2786 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2787 "Failed to get value of property '%s'.\n",
2788 cmd->args[0].v.s);
2789 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2790 break;
2792 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2793 cmd->args[0].v.s, tmp);
2794 free(tmp);
2796 break;
2798 case MP_CMD_EDL_MARK:
2799 if (edl_fd) {
2800 float v = sh_video ? sh_video->pts :
2801 playing_audio_pts(mpctx);
2802 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2803 mpctx->begin_skip = v;
2804 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2805 } else {
2806 if (mpctx->begin_skip > v)
2807 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2808 else {
2809 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2810 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2812 mpctx->begin_skip = MP_NOPTS_VALUE;
2815 break;
2817 case MP_CMD_SWITCH_RATIO:
2818 if (!sh_video)
2819 break;
2820 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2821 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2822 else
2823 opts->movie_aspect = cmd->args[0].v.f;
2824 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2825 break;
2827 case MP_CMD_SPEED_INCR:{
2828 float v = cmd->args[0].v.f;
2829 opts->playback_speed += v;
2830 build_afilter_chain(mpctx, sh_audio, &ao_data);
2831 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2832 opts->playback_speed);
2833 } break;
2835 case MP_CMD_SPEED_MULT:{
2836 float v = cmd->args[0].v.f;
2837 opts->playback_speed *= v;
2838 build_afilter_chain(mpctx, sh_audio, &ao_data);
2839 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2840 opts->playback_speed);
2841 } break;
2843 case MP_CMD_SPEED_SET:{
2844 float v = cmd->args[0].v.f;
2845 opts->playback_speed = v;
2846 build_afilter_chain(mpctx, sh_audio, &ao_data);
2847 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2848 opts->playback_speed);
2849 } break;
2851 case MP_CMD_FRAME_STEP:
2852 add_step_frame(mpctx);
2853 break;
2855 case MP_CMD_FILE_FILTER:
2856 file_filter = cmd->args[0].v.i;
2857 break;
2859 case MP_CMD_QUIT:
2860 exit_player_with_rc(mpctx, EXIT_QUIT,
2861 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2863 case MP_CMD_PLAY_TREE_STEP:{
2864 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2865 int force = cmd->args[1].v.i;
2868 if (!force && mpctx->playtree_iter) {
2869 play_tree_iter_t *i =
2870 play_tree_iter_new_copy(mpctx->playtree_iter);
2871 if (play_tree_iter_step(i, n, 0) ==
2872 PLAY_TREE_ITER_ENTRY)
2873 mpctx->stop_play =
2874 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2875 play_tree_iter_free(i);
2876 } else
2877 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2878 if (mpctx->stop_play)
2879 mpctx->play_tree_step = n;
2882 break;
2884 case MP_CMD_PLAY_TREE_UP_STEP:{
2885 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2886 int force = cmd->args[1].v.i;
2888 if (!force && mpctx->playtree_iter) {
2889 play_tree_iter_t *i =
2890 play_tree_iter_new_copy(mpctx->playtree_iter);
2891 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2892 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2893 play_tree_iter_free(i);
2894 } else
2895 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2897 break;
2899 case MP_CMD_PLAY_ALT_SRC_STEP:
2900 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2901 int v = cmd->args[0].v.i;
2902 if (v > 0
2903 && mpctx->playtree_iter->file <
2904 mpctx->playtree_iter->num_files)
2905 mpctx->stop_play = PT_NEXT_SRC;
2906 else if (v < 0 && mpctx->playtree_iter->file > 1)
2907 mpctx->stop_play = PT_PREV_SRC;
2909 break;
2911 case MP_CMD_SUB_STEP:
2912 if (sh_video) {
2913 int movement = cmd->args[0].v.i;
2914 step_sub(subdata, sh_video->pts, movement);
2915 #ifdef CONFIG_ASS
2916 if (ass_track)
2917 sub_delay +=
2918 ass_step_sub(ass_track,
2919 (sh_video->pts +
2920 sub_delay) * 1000 + .5, movement) / 1000.;
2921 #endif
2922 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2923 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2925 break;
2927 case MP_CMD_SUB_LOG:
2928 log_sub(mpctx);
2929 break;
2931 case MP_CMD_OSD:{
2932 int v = cmd->args[0].v.i;
2933 int max = (term_osd
2934 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2935 if (opts->osd_level > max)
2936 opts->osd_level = max;
2937 if (v < 0)
2938 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2939 else
2940 opts->osd_level = v > max ? max : v;
2941 /* Show OSD state when disabled, but not when an explicit
2942 argument is given to the OSD command, i.e. in slave mode. */
2943 if (v == -1 && opts->osd_level <= 1)
2944 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2945 "OSD: %s",
2946 opts->osd_level ? mp_gtext("enabled") :
2947 mp_gtext("disabled"));
2948 else
2949 rm_osd_msg(OSD_MSG_OSD_STATUS);
2951 break;
2953 case MP_CMD_OSD_SHOW_TEXT:
2954 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2955 (cmd->args[1].v.i <
2956 0 ? osd_duration : cmd->args[1].v.i),
2957 "%-.63s", cmd->args[0].v.s);
2958 break;
2960 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2961 char *txt = m_properties_expand_string(mp_properties,
2962 cmd->args[0].v.s,
2963 mpctx);
2964 /* if no argument supplied take default osd_duration, else <arg> ms. */
2965 if (txt) {
2966 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2967 (cmd->args[1].v.i <
2968 0 ? osd_duration : cmd->args[1].v.i),
2969 "%-.63s", txt);
2970 free(txt);
2973 break;
2975 case MP_CMD_LOADFILE:{
2976 play_tree_t *e = play_tree_new();
2977 play_tree_add_file(e, cmd->args[0].v.s);
2979 if (cmd->args[1].v.i) // append
2980 play_tree_append_entry(mpctx->playtree->child, e);
2981 else {
2982 // Go back to the starting point.
2983 while (play_tree_iter_up_step
2984 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2985 /* NOP */ ;
2986 play_tree_free_list(mpctx->playtree->child, 1);
2987 play_tree_set_child(mpctx->playtree, e);
2988 pt_iter_goto_head(mpctx->playtree_iter);
2989 mpctx->stop_play = PT_NEXT_SRC;
2992 break;
2994 case MP_CMD_LOADLIST:{
2995 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2996 if (!e)
2997 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2998 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2999 else {
3000 if (cmd->args[1].v.i) // append
3001 play_tree_append_entry(mpctx->playtree->child, e);
3002 else {
3003 // Go back to the starting point.
3004 while (play_tree_iter_up_step
3005 (mpctx->playtree_iter, 0, 1)
3006 != PLAY_TREE_ITER_END)
3007 /* NOP */ ;
3008 play_tree_free_list(mpctx->playtree->child, 1);
3009 play_tree_set_child(mpctx->playtree, e);
3010 pt_iter_goto_head(mpctx->playtree_iter);
3011 mpctx->stop_play = PT_NEXT_SRC;
3015 break;
3017 case MP_CMD_STOP:
3018 // Go back to the starting point.
3019 while (play_tree_iter_up_step
3020 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3021 /* NOP */ ;
3022 mpctx->stop_play = PT_STOP;
3023 break;
3025 case MP_CMD_OSD_SHOW_PROGRESSION:{
3026 int len = demuxer_get_time_length(mpctx->demuxer);
3027 int pts = demuxer_get_current_time(mpctx->demuxer);
3028 set_osd_bar(mpctx, 0, "Position", 0, 100, demuxer_get_percent_pos(mpctx->demuxer));
3029 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3030 "%c %02d:%02d:%02d / %02d:%02d:%02d",
3031 mpctx->osd_function, pts/3600, (pts/60)%60, pts%60,
3032 len/3600, (len/60)%60, len%60);
3034 break;
3036 #ifdef CONFIG_RADIO
3037 case MP_CMD_RADIO_STEP_CHANNEL:
3038 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3039 int v = cmd->args[0].v.i;
3040 if (v > 0)
3041 radio_step_channel(mpctx->demuxer->stream,
3042 RADIO_CHANNEL_HIGHER);
3043 else
3044 radio_step_channel(mpctx->demuxer->stream,
3045 RADIO_CHANNEL_LOWER);
3046 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3047 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3048 "Channel: %s",
3049 radio_get_channel_name(mpctx->demuxer->stream));
3052 break;
3054 case MP_CMD_RADIO_SET_CHANNEL:
3055 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3056 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3057 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3058 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3059 "Channel: %s",
3060 radio_get_channel_name(mpctx->demuxer->stream));
3063 break;
3065 case MP_CMD_RADIO_SET_FREQ:
3066 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3067 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3068 break;
3070 case MP_CMD_RADIO_STEP_FREQ:
3071 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3072 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3073 break;
3074 #endif
3076 #ifdef CONFIG_TV
3077 case MP_CMD_TV_START_SCAN:
3078 if (mpctx->file_format == DEMUXER_TYPE_TV)
3079 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
3080 break;
3081 case MP_CMD_TV_SET_FREQ:
3082 if (mpctx->file_format == DEMUXER_TYPE_TV)
3083 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3084 cmd->args[0].v.f * 16.0);
3085 #ifdef CONFIG_PVR
3086 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3087 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
3088 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3089 pvr_get_current_channelname (mpctx->stream),
3090 pvr_get_current_stationname (mpctx->stream));
3092 #endif /* CONFIG_PVR */
3093 break;
3095 case MP_CMD_TV_STEP_FREQ:
3096 if (mpctx->file_format == DEMUXER_TYPE_TV)
3097 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3098 cmd->args[0].v.f * 16.0);
3099 #ifdef CONFIG_PVR
3100 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3101 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
3102 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3103 pvr_get_current_channelname (mpctx->stream),
3104 pvr_get_current_frequency (mpctx->stream));
3106 #endif /* CONFIG_PVR */
3107 break;
3109 case MP_CMD_TV_SET_NORM:
3110 if (mpctx->file_format == DEMUXER_TYPE_TV)
3111 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3112 cmd->args[0].v.s);
3113 break;
3115 case MP_CMD_TV_STEP_CHANNEL:{
3116 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3117 int v = cmd->args[0].v.i;
3118 if (v > 0) {
3119 tv_step_channel((tvi_handle_t *) (mpctx->
3120 demuxer->priv),
3121 TV_CHANNEL_HIGHER);
3122 } else {
3123 tv_step_channel((tvi_handle_t *) (mpctx->
3124 demuxer->priv),
3125 TV_CHANNEL_LOWER);
3127 if (tv_channel_list) {
3128 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3129 "Channel: %s", tv_channel_current->name);
3130 //vo_osd_changed(OSDTYPE_SUBTITLE);
3133 #ifdef CONFIG_PVR
3134 else if (mpctx->stream &&
3135 mpctx->stream->type == STREAMTYPE_PVR) {
3136 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3137 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3138 pvr_get_current_channelname (mpctx->stream),
3139 pvr_get_current_stationname (mpctx->stream));
3141 #endif /* CONFIG_PVR */
3143 #ifdef CONFIG_DVBIN
3144 if (mpctx->stream->type == STREAMTYPE_DVB) {
3145 int dir;
3146 int v = cmd->args[0].v.i;
3148 mpctx->last_dvb_step = v;
3149 if (v > 0)
3150 dir = DVB_CHANNEL_HIGHER;
3151 else
3152 dir = DVB_CHANNEL_LOWER;
3155 if (dvb_step_channel(mpctx->stream, dir)) {
3156 mpctx->stop_play = PT_NEXT_ENTRY;
3157 mpctx->dvbin_reopen = 1;
3160 #endif /* CONFIG_DVBIN */
3161 break;
3163 case MP_CMD_TV_SET_CHANNEL:
3164 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3165 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3166 cmd->args[0].v.s);
3167 if (tv_channel_list) {
3168 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3169 "Channel: %s", tv_channel_current->name);
3170 //vo_osd_changed(OSDTYPE_SUBTITLE);
3173 #ifdef CONFIG_PVR
3174 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3175 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3176 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3177 pvr_get_current_channelname (mpctx->stream),
3178 pvr_get_current_stationname (mpctx->stream));
3180 #endif /* CONFIG_PVR */
3181 break;
3183 #ifdef CONFIG_DVBIN
3184 case MP_CMD_DVB_SET_CHANNEL:
3185 if (mpctx->stream->type == STREAMTYPE_DVB) {
3186 mpctx->last_dvb_step = 1;
3188 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3189 cmd->args[0].v.i)) {
3190 mpctx->stop_play = PT_NEXT_ENTRY;
3191 mpctx->dvbin_reopen = 1;
3194 break;
3195 #endif /* CONFIG_DVBIN */
3197 case MP_CMD_TV_LAST_CHANNEL:
3198 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3199 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3200 if (tv_channel_list) {
3201 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3202 "Channel: %s", tv_channel_current->name);
3203 //vo_osd_changed(OSDTYPE_SUBTITLE);
3206 #ifdef CONFIG_PVR
3207 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3208 pvr_set_lastchannel (mpctx->stream);
3209 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3210 pvr_get_current_channelname (mpctx->stream),
3211 pvr_get_current_stationname (mpctx->stream));
3213 #endif /* CONFIG_PVR */
3214 break;
3216 case MP_CMD_TV_STEP_NORM:
3217 if (mpctx->file_format == DEMUXER_TYPE_TV)
3218 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3219 break;
3221 case MP_CMD_TV_STEP_CHANNEL_LIST:
3222 if (mpctx->file_format == DEMUXER_TYPE_TV)
3223 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3224 break;
3225 #endif /* CONFIG_TV */
3226 case MP_CMD_TV_TELETEXT_ADD_DEC:
3227 if (mpctx->demuxer->teletext)
3228 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3229 &(cmd->args[0].v.s));
3230 break;
3231 case MP_CMD_TV_TELETEXT_GO_LINK:
3232 if (mpctx->demuxer->teletext)
3233 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3234 &(cmd->args[0].v.i));
3235 break;
3237 case MP_CMD_SUB_LOAD:
3238 if (sh_video) {
3239 int n = mpctx->set_of_sub_size;
3240 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3241 if (n != mpctx->set_of_sub_size) {
3242 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3243 ++mpctx->global_sub_size;
3246 break;
3248 case MP_CMD_SUB_REMOVE:
3249 if (sh_video) {
3250 int v = cmd->args[0].v.i;
3251 if (v < 0) {
3252 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3253 } else if (v < mpctx->set_of_sub_size) {
3254 remove_subtitle_range(mpctx, v, 1);
3257 break;
3259 case MP_CMD_GET_SUB_VISIBILITY:
3260 if (sh_video) {
3261 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3262 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3264 break;
3266 case MP_CMD_SCREENSHOT:
3267 if (mpctx->video_out && mpctx->video_out->config_ok) {
3268 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3269 if (CONTROL_OK !=
3270 ((vf_instance_t *) sh_video->vfilter)->
3271 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3272 &cmd->args[0].v.i))
3273 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3275 break;
3277 case MP_CMD_VF_CHANGE_RECTANGLE:
3278 if (!sh_video)
3279 break;
3280 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3281 break;
3283 case MP_CMD_GET_TIME_LENGTH:{
3284 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3285 demuxer_get_time_length(mpctx->demuxer));
3287 break;
3289 case MP_CMD_GET_FILENAME:{
3290 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3291 get_metadata(mpctx, META_NAME));
3293 break;
3295 case MP_CMD_GET_VIDEO_CODEC:{
3296 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3297 if (!inf)
3298 inf = strdup("");
3299 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3300 free(inf);
3302 break;
3304 case MP_CMD_GET_VIDEO_BITRATE:{
3305 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3306 if (!inf)
3307 inf = strdup("");
3308 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3309 free(inf);
3311 break;
3313 case MP_CMD_GET_VIDEO_RESOLUTION:{
3314 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3315 if (!inf)
3316 inf = strdup("");
3317 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3318 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3319 free(inf);
3321 break;
3323 case MP_CMD_GET_AUDIO_CODEC:{
3324 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3325 if (!inf)
3326 inf = strdup("");
3327 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3328 free(inf);
3330 break;
3332 case MP_CMD_GET_AUDIO_BITRATE:{
3333 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3334 if (!inf)
3335 inf = strdup("");
3336 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3337 free(inf);
3339 break;
3341 case MP_CMD_GET_AUDIO_SAMPLES:{
3342 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3343 if (!inf)
3344 inf = strdup("");
3345 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3346 free(inf);
3348 break;
3350 case MP_CMD_GET_META_TITLE:{
3351 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3352 if (!inf)
3353 inf = strdup("");
3354 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3355 free(inf);
3357 break;
3359 case MP_CMD_GET_META_ARTIST:{
3360 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3361 if (!inf)
3362 inf = strdup("");
3363 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3364 free(inf);
3366 break;
3368 case MP_CMD_GET_META_ALBUM:{
3369 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3370 if (!inf)
3371 inf = strdup("");
3372 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3373 free(inf);
3375 break;
3377 case MP_CMD_GET_META_YEAR:{
3378 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3379 if (!inf)
3380 inf = strdup("");
3381 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3382 free(inf);
3384 break;
3386 case MP_CMD_GET_META_COMMENT:{
3387 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3388 if (!inf)
3389 inf = strdup("");
3390 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3391 free(inf);
3393 break;
3395 case MP_CMD_GET_META_TRACK:{
3396 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3397 if (!inf)
3398 inf = strdup("");
3399 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3400 free(inf);
3402 break;
3404 case MP_CMD_GET_META_GENRE:{
3405 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3406 if (!inf)
3407 inf = strdup("");
3408 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3409 free(inf);
3411 break;
3413 case MP_CMD_GET_VO_FULLSCREEN:
3414 if (mpctx->video_out && mpctx->video_out->config_ok)
3415 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3416 break;
3418 case MP_CMD_GET_PERCENT_POS:
3419 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3420 demuxer_get_percent_pos(mpctx->demuxer));
3421 break;
3423 case MP_CMD_GET_TIME_POS:{
3424 float pos = 0;
3425 if (sh_video)
3426 pos = sh_video->pts;
3427 else if (sh_audio && mpctx->audio_out)
3428 pos = playing_audio_pts(mpctx);
3429 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3431 break;
3433 case MP_CMD_RUN:
3434 #ifndef __MINGW32__
3435 if (!fork()) {
3436 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3437 exit(0);
3439 #endif
3440 break;
3442 case MP_CMD_KEYDOWN_EVENTS:
3443 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3444 break;
3446 case MP_CMD_SET_MOUSE_POS:{
3447 int pointer_x, pointer_y;
3448 double dx, dy;
3449 pointer_x = cmd->args[0].v.i;
3450 pointer_y = cmd->args[1].v.i;
3451 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3452 #ifdef CONFIG_DVDNAV
3453 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3454 && dx > 0.0 && dy > 0.0) {
3455 int button = -1;
3456 pointer_x = (int) (dx * (double) sh_video->disp_w);
3457 pointer_y = (int) (dy * (double) sh_video->disp_h);
3458 mp_dvdnav_update_mouse_pos(mpctx->stream,
3459 pointer_x, pointer_y, &button);
3460 if (opts->osd_level > 1 && button > 0)
3461 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3462 "Selected button number %d", button);
3464 #endif
3465 #ifdef CONFIG_MENU
3466 if (use_menu && dx >= 0.0 && dy >= 0.0)
3467 menu_update_mouse_pos(dx, dy);
3468 #endif
3470 break;
3472 #ifdef CONFIG_DVDNAV
3473 case MP_CMD_DVDNAV:{
3474 int button = -1;
3475 int i;
3476 mp_command_type command = 0;
3477 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3478 break;
3480 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3481 if (cmd->args[0].v.s &&
3482 !strcasecmp (cmd->args[0].v.s,
3483 mp_dvdnav_bindings[i].name))
3484 command = mp_dvdnav_bindings[i].cmd;
3486 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3487 if (opts->osd_level > 1 && button > 0)
3488 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3489 "Selected button number %d", button);
3491 break;
3493 case MP_CMD_SWITCH_TITLE:
3494 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3495 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3496 break;
3498 #endif
3500 case MP_CMD_AF_SWITCH:
3501 if (sh_audio)
3503 af_uninit(mpctx->mixer.afilter);
3504 af_init(mpctx->mixer.afilter);
3506 case MP_CMD_AF_ADD:
3507 case MP_CMD_AF_DEL:
3508 if (!sh_audio)
3509 break;
3511 char* af_args = strdup(cmd->args[0].v.s);
3512 char* af_commands = af_args;
3513 char* af_command;
3514 af_instance_t* af;
3515 while ((af_command = strsep(&af_commands, ",")) != NULL)
3517 if (cmd->id == MP_CMD_AF_DEL)
3519 af = af_get(mpctx->mixer.afilter, af_command);
3520 if (af != NULL)
3521 af_remove(mpctx->mixer.afilter, af);
3523 else
3524 af_add(mpctx->mixer.afilter, af_command);
3526 build_afilter_chain(mpctx, sh_audio, &ao_data);
3527 free(af_args);
3529 break;
3530 case MP_CMD_AF_CLR:
3531 if (!sh_audio)
3532 break;
3533 af_uninit(mpctx->mixer.afilter);
3534 af_init(mpctx->mixer.afilter);
3535 build_afilter_chain(mpctx, sh_audio, &ao_data);
3536 break;
3537 case MP_CMD_AF_CMDLINE:
3538 if (sh_audio) {
3539 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3540 if (!af) {
3541 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3542 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3543 break;
3545 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3546 af_reinit(sh_audio->afilter, af);
3548 break;
3550 default:
3551 mp_msg(MSGT_CPLAYER, MSGL_V,
3552 "Received unknown cmd %s\n", cmd->name);
3555 switch (cmd->pausing) {
3556 case 1: // "pausing"
3557 pause_player(mpctx);
3558 break;
3559 case 3: // "pausing_toggle"
3560 if (mpctx->paused)
3561 unpause_player(mpctx);
3562 else
3563 pause_player(mpctx);
3564 break;