vo_corevideo: Avoid some code duplication.
[mplayer/glamo.git] / command.c
blob364865b899f2f6508781ddc7b14ed6b3e8e620ef
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 /// Panscan (RW)
1182 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1183 MPContext *mpctx)
1186 if (!mpctx->video_out
1187 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1188 return M_PROPERTY_UNAVAILABLE;
1190 switch (action) {
1191 case M_PROPERTY_SET:
1192 if (!arg)
1193 return M_PROPERTY_ERROR;
1194 M_PROPERTY_CLAMP(prop, *(float *) arg);
1195 vo_panscan = *(float *) arg;
1196 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1197 return M_PROPERTY_OK;
1198 case M_PROPERTY_STEP_UP:
1199 case M_PROPERTY_STEP_DOWN:
1200 vo_panscan += (arg ? *(float *) arg : 0.1) *
1201 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1202 if (vo_panscan > 1)
1203 vo_panscan = 1;
1204 else if (vo_panscan < 0)
1205 vo_panscan = 0;
1206 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1207 return M_PROPERTY_OK;
1208 default:
1209 return m_property_float_range(prop, action, arg, &vo_panscan);
1213 /// Helper to set vo flags.
1214 /** \ingroup PropertyImplHelper
1216 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1217 int vo_ctrl, int *vo_var, MPContext *mpctx)
1220 if (!mpctx->video_out)
1221 return M_PROPERTY_UNAVAILABLE;
1223 switch (action) {
1224 case M_PROPERTY_SET:
1225 if (!arg)
1226 return M_PROPERTY_ERROR;
1227 M_PROPERTY_CLAMP(prop, *(int *) arg);
1228 if (*vo_var == !!*(int *) arg)
1229 return M_PROPERTY_OK;
1230 case M_PROPERTY_STEP_UP:
1231 case M_PROPERTY_STEP_DOWN:
1232 if (mpctx->video_out->config_ok)
1233 vo_control(mpctx->video_out, vo_ctrl, 0);
1234 return M_PROPERTY_OK;
1235 default:
1236 return m_property_flag(prop, action, arg, vo_var);
1240 /// Window always on top (RW)
1241 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1242 MPContext *mpctx)
1244 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1245 &mpctx->opts.vo_ontop, mpctx);
1248 /// Display in the root window (RW)
1249 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1250 MPContext *mpctx)
1252 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1253 &vo_rootwin, mpctx);
1256 /// Show window borders (RW)
1257 static int mp_property_border(m_option_t *prop, int action, void *arg,
1258 MPContext *mpctx)
1260 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1261 &vo_border, mpctx);
1264 /// Framedropping state (RW)
1265 static int mp_property_framedropping(m_option_t *prop, int action,
1266 void *arg, MPContext *mpctx)
1269 if (!mpctx->sh_video)
1270 return M_PROPERTY_UNAVAILABLE;
1272 switch (action) {
1273 case M_PROPERTY_PRINT:
1274 if (!arg)
1275 return M_PROPERTY_ERROR;
1276 *(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
1277 (frame_dropping == 2 ? mp_gtext("hard") :
1278 mp_gtext("disabled")));
1279 return M_PROPERTY_OK;
1280 default:
1281 return m_property_choice(prop, action, arg, &frame_dropping);
1285 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1286 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1287 MPContext *mpctx)
1289 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1290 int r, val;
1292 if (!mpctx->sh_video)
1293 return M_PROPERTY_UNAVAILABLE;
1295 if (gamma[0] == 1000) {
1296 gamma[0] = 0;
1297 get_video_colors(mpctx->sh_video, prop->name, gamma);
1300 switch (action) {
1301 case M_PROPERTY_SET:
1302 if (!arg)
1303 return M_PROPERTY_ERROR;
1304 M_PROPERTY_CLAMP(prop, *(int *) arg);
1305 *gamma = *(int *) arg;
1306 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1307 if (r <= 0)
1308 break;
1309 return r;
1310 case M_PROPERTY_GET:
1311 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1312 if (!arg)
1313 return M_PROPERTY_ERROR;
1314 *(int *)arg = val;
1315 return M_PROPERTY_OK;
1317 break;
1318 case M_PROPERTY_STEP_UP:
1319 case M_PROPERTY_STEP_DOWN:
1320 *gamma += (arg ? *(int *) arg : 1) *
1321 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1322 M_PROPERTY_CLAMP(prop, *gamma);
1323 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1324 if (r <= 0)
1325 break;
1326 return r;
1327 default:
1328 return M_PROPERTY_NOT_IMPLEMENTED;
1331 #ifdef CONFIG_TV
1332 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1333 int l = strlen(prop->name);
1334 char tv_prop[3 + l + 1];
1335 sprintf(tv_prop, "tv_%s", prop->name);
1336 return mp_property_do(tv_prop, action, arg, mpctx);
1338 #endif
1340 return M_PROPERTY_UNAVAILABLE;
1343 /// VSync (RW)
1344 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1345 MPContext *mpctx)
1347 return m_property_flag(prop, action, arg, &vo_vsync);
1350 /// Video codec tag (RO)
1351 static int mp_property_video_format(m_option_t *prop, int action,
1352 void *arg, MPContext *mpctx)
1354 char* meta;
1355 if (!mpctx->sh_video)
1356 return M_PROPERTY_UNAVAILABLE;
1357 switch(action) {
1358 case M_PROPERTY_PRINT:
1359 if (!arg)
1360 return M_PROPERTY_ERROR;
1361 switch(mpctx->sh_video->format) {
1362 case 0x10000001:
1363 meta = strdup ("mpeg1"); break;
1364 case 0x10000002:
1365 meta = strdup ("mpeg2"); break;
1366 case 0x10000004:
1367 meta = strdup ("mpeg4"); break;
1368 case 0x10000005:
1369 meta = strdup ("h264"); break;
1370 default:
1371 if(mpctx->sh_video->format >= 0x20202020) {
1372 meta = malloc(5);
1373 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1374 } else {
1375 meta = malloc(20);
1376 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1379 *(char**)arg = meta;
1380 return M_PROPERTY_OK;
1382 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1385 /// Video codec name (RO)
1386 static int mp_property_video_codec(m_option_t *prop, int action,
1387 void *arg, MPContext *mpctx)
1389 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1390 return M_PROPERTY_UNAVAILABLE;
1391 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1395 /// Video bitrate (RO)
1396 static int mp_property_video_bitrate(m_option_t *prop, int action,
1397 void *arg, MPContext *mpctx)
1399 if (!mpctx->sh_video)
1400 return M_PROPERTY_UNAVAILABLE;
1401 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1404 /// Video display width (RO)
1405 static int mp_property_width(m_option_t *prop, int action, void *arg,
1406 MPContext *mpctx)
1408 if (!mpctx->sh_video)
1409 return M_PROPERTY_UNAVAILABLE;
1410 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1413 /// Video display height (RO)
1414 static int mp_property_height(m_option_t *prop, int action, void *arg,
1415 MPContext *mpctx)
1417 if (!mpctx->sh_video)
1418 return M_PROPERTY_UNAVAILABLE;
1419 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1422 /// Video fps (RO)
1423 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1424 MPContext *mpctx)
1426 if (!mpctx->sh_video)
1427 return M_PROPERTY_UNAVAILABLE;
1428 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1431 /// Video aspect (RO)
1432 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1433 MPContext *mpctx)
1435 if (!mpctx->sh_video)
1436 return M_PROPERTY_UNAVAILABLE;
1437 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1440 ///@}
1442 /// \defgroup SubProprties Subtitles properties
1443 /// \ingroup Properties
1444 ///@{
1446 /// Text subtitle position (RW)
1447 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1448 MPContext *mpctx)
1450 switch (action) {
1451 case M_PROPERTY_SET:
1452 if (!arg)
1453 return M_PROPERTY_ERROR;
1454 case M_PROPERTY_STEP_UP:
1455 case M_PROPERTY_STEP_DOWN:
1456 vo_osd_changed(OSDTYPE_SUBTITLE);
1457 default:
1458 return m_property_int_range(prop, action, arg, &sub_pos);
1462 /// Selected subtitles (RW)
1463 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1464 MPContext *mpctx)
1466 struct MPOpts *opts = &mpctx->opts;
1467 demux_stream_t *const d_sub = mpctx->d_sub;
1468 int source = -1, reset_spu = 0;
1469 int source_pos = -1;
1470 char *sub_name;
1472 update_global_sub_size(mpctx);
1473 const int global_sub_size = mpctx->global_sub_size;
1475 if (global_sub_size <= 0)
1476 return M_PROPERTY_UNAVAILABLE;
1478 switch (action) {
1479 case M_PROPERTY_GET:
1480 if (!arg)
1481 return M_PROPERTY_ERROR;
1482 *(int *) arg = mpctx->global_sub_pos;
1483 return M_PROPERTY_OK;
1484 case M_PROPERTY_PRINT:
1485 if (!arg)
1486 return M_PROPERTY_ERROR;
1487 *(char **) arg = malloc(64);
1488 (*(char **) arg)[63] = 0;
1489 sub_name = 0;
1490 if (subdata)
1491 sub_name = subdata->filename;
1492 #ifdef CONFIG_ASS
1493 if (ass_track && ass_track->name)
1494 sub_name = ass_track->name;
1495 #endif
1496 if (sub_name) {
1497 char *tmp, *tmp2;
1498 tmp = sub_name;
1499 if ((tmp2 = strrchr(tmp, '/')))
1500 tmp = tmp2 + 1;
1502 snprintf(*(char **) arg, 63, "(%d) %s%s",
1503 mpctx->set_of_sub_pos + 1,
1504 strlen(tmp) < 20 ? "" : "...",
1505 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1506 return M_PROPERTY_OK;
1508 #ifdef CONFIG_DVDNAV
1509 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1510 if (vo_spudec && opts->sub_id >= 0) {
1511 unsigned char lang[3];
1512 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1513 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1514 return M_PROPERTY_OK;
1518 #endif
1520 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1521 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1522 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1523 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1524 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1525 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1526 if (!lang) lang = mp_gtext("unknown");
1527 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1528 return M_PROPERTY_OK;
1531 if (vo_vobsub && vobsub_id >= 0) {
1532 const char *language = mp_gtext("unknown");
1533 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1534 snprintf(*(char **) arg, 63, "(%d) %s",
1535 vobsub_id, language ? language : mp_gtext("unknown"));
1536 return M_PROPERTY_OK;
1538 #ifdef CONFIG_DVDREAD
1539 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1540 && opts->sub_id >= 0) {
1541 char lang[3];
1542 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1543 lang[0] = code >> 8;
1544 lang[1] = code;
1545 lang[2] = 0;
1546 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1547 return M_PROPERTY_OK;
1549 #endif
1550 if (opts->sub_id >= 0) {
1551 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
1552 mp_gtext("unknown"));
1553 return M_PROPERTY_OK;
1555 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1556 return M_PROPERTY_OK;
1558 case M_PROPERTY_SET:
1559 if (!arg)
1560 return M_PROPERTY_ERROR;
1561 if (*(int *) arg < -1)
1562 *(int *) arg = -1;
1563 else if (*(int *) arg >= global_sub_size)
1564 *(int *) arg = global_sub_size - 1;
1565 mpctx->global_sub_pos = *(int *) arg;
1566 break;
1567 case M_PROPERTY_STEP_UP:
1568 mpctx->global_sub_pos += 2;
1569 mpctx->global_sub_pos =
1570 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1571 break;
1572 case M_PROPERTY_STEP_DOWN:
1573 mpctx->global_sub_pos += global_sub_size + 1;
1574 mpctx->global_sub_pos =
1575 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1576 break;
1577 default:
1578 return M_PROPERTY_NOT_IMPLEMENTED;
1581 if (mpctx->global_sub_pos >= 0) {
1582 source = sub_source(mpctx);
1583 source_pos = sub_source_pos(mpctx);
1586 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1587 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1588 global_sub_size,
1589 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1590 mpctx->sub_counts[SUB_SOURCE_SUBS],
1591 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1592 mpctx->global_sub_pos, source);
1594 mpctx->set_of_sub_pos = -1;
1595 subdata = NULL;
1597 vobsub_id = -1;
1598 opts->sub_id = -1;
1599 if (d_sub) {
1600 if (d_sub->id > -2)
1601 reset_spu = 1;
1602 d_sub->id = -2;
1604 #ifdef CONFIG_ASS
1605 ass_track = 0;
1606 #endif
1608 if (source == SUB_SOURCE_VOBSUB) {
1609 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1610 } else if (source == SUB_SOURCE_SUBS) {
1611 mpctx->set_of_sub_pos = source_pos;
1612 #ifdef CONFIG_ASS
1613 if (opts->ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1614 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1615 else
1616 #endif
1618 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1619 vo_osd_changed(OSDTYPE_SUBTITLE);
1621 } else if (source == SUB_SOURCE_DEMUX) {
1622 opts->sub_id = source_pos;
1623 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1624 int i = 0;
1625 // default: assume 1:1 mapping of sid and stream id
1626 d_sub->id = opts->sub_id;
1627 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1628 ds_free_packs(d_sub);
1629 for (i = 0; i < MAX_S_STREAMS; i++) {
1630 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1631 if (sh && sh->sid == opts->sub_id) {
1632 d_sub->id = i;
1633 d_sub->sh = sh;
1634 break;
1637 if (d_sub->sh && d_sub->id >= 0) {
1638 sh_sub_t *sh = d_sub->sh;
1639 if (sh->type == 'v')
1640 init_vo_spudec(mpctx);
1641 #ifdef CONFIG_ASS
1642 else if (opts->ass_enabled)
1643 ass_track = sh->ass_track;
1644 #endif
1645 } else {
1646 d_sub->id = -2;
1647 d_sub->sh = NULL;
1651 #ifdef CONFIG_DVDREAD
1652 if (vo_spudec
1653 && (mpctx->stream->type == STREAMTYPE_DVD
1654 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1655 && opts->sub_id < 0 && reset_spu) {
1656 d_sub->id = -2;
1657 d_sub->sh = NULL;
1659 #endif
1661 update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, 0, 0, d_sub, 1);
1663 return M_PROPERTY_OK;
1666 /// Selected sub source (RW)
1667 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1668 MPContext *mpctx)
1670 int source;
1671 update_global_sub_size(mpctx);
1672 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1673 return M_PROPERTY_UNAVAILABLE;
1675 switch (action) {
1676 case M_PROPERTY_GET:
1677 if (!arg)
1678 return M_PROPERTY_ERROR;
1679 *(int *) arg = sub_source(mpctx);
1680 return M_PROPERTY_OK;
1681 case M_PROPERTY_PRINT:
1682 if (!arg)
1683 return M_PROPERTY_ERROR;
1684 *(char **) arg = malloc(64);
1685 (*(char **) arg)[63] = 0;
1686 switch (sub_source(mpctx))
1688 case SUB_SOURCE_SUBS:
1689 snprintf(*(char **) arg, 63, mp_gtext("file"));
1690 break;
1691 case SUB_SOURCE_VOBSUB:
1692 snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
1693 break;
1694 case SUB_SOURCE_DEMUX:
1695 snprintf(*(char **) arg, 63, mp_gtext("embedded"));
1696 break;
1697 default:
1698 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1700 return M_PROPERTY_OK;
1701 case M_PROPERTY_SET:
1702 if (!arg)
1703 return M_PROPERTY_ERROR;
1704 M_PROPERTY_CLAMP(prop, *(int*)arg);
1705 if (*(int *) arg < 0)
1706 mpctx->global_sub_pos = -1;
1707 else if (*(int *) arg != sub_source(mpctx)) {
1708 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1709 if (new_pos == -1)
1710 return M_PROPERTY_UNAVAILABLE;
1711 mpctx->global_sub_pos = new_pos;
1713 break;
1714 case M_PROPERTY_STEP_UP:
1715 case M_PROPERTY_STEP_DOWN: {
1716 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1717 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1718 int step = (step_all > 0) ? 1 : -1;
1719 int cur_source = sub_source(mpctx);
1720 source = cur_source;
1721 while (step_all) {
1722 source += step;
1723 if (source >= SUB_SOURCES)
1724 source = -1;
1725 else if (source < -1)
1726 source = SUB_SOURCES - 1;
1727 if (source == cur_source || source == -1 ||
1728 mpctx->sub_counts[source])
1729 step_all -= step;
1731 if (source == cur_source)
1732 return M_PROPERTY_OK;
1733 if (source == -1)
1734 mpctx->global_sub_pos = -1;
1735 else
1736 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1737 break;
1739 default:
1740 return M_PROPERTY_NOT_IMPLEMENTED;
1742 --mpctx->global_sub_pos;
1743 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1746 /// Selected subtitles from specific source (RW)
1747 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1748 MPContext *mpctx)
1750 int source, is_cur_source, offset, new_pos;
1751 update_global_sub_size(mpctx);
1752 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1753 return M_PROPERTY_UNAVAILABLE;
1755 if (!strcmp(prop->name, "sub_file"))
1756 source = SUB_SOURCE_SUBS;
1757 else if (!strcmp(prop->name, "sub_vob"))
1758 source = SUB_SOURCE_VOBSUB;
1759 else if (!strcmp(prop->name, "sub_demux"))
1760 source = SUB_SOURCE_DEMUX;
1761 else
1762 return M_PROPERTY_ERROR;
1764 offset = sub_pos_by_source(mpctx, source);
1765 if (offset < 0)
1766 return M_PROPERTY_UNAVAILABLE;
1768 is_cur_source = sub_source(mpctx) == source;
1769 new_pos = mpctx->global_sub_pos;
1770 switch (action) {
1771 case M_PROPERTY_GET:
1772 if (!arg)
1773 return M_PROPERTY_ERROR;
1774 if (is_cur_source) {
1775 *(int *) arg = sub_source_pos(mpctx);
1776 if (source == SUB_SOURCE_VOBSUB)
1777 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1779 else
1780 *(int *) arg = -1;
1781 return M_PROPERTY_OK;
1782 case M_PROPERTY_PRINT:
1783 if (!arg)
1784 return M_PROPERTY_ERROR;
1785 if (is_cur_source)
1786 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1787 *(char **) arg = malloc(64);
1788 (*(char **) arg)[63] = 0;
1789 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1790 return M_PROPERTY_OK;
1791 case M_PROPERTY_SET:
1792 if (!arg)
1793 return M_PROPERTY_ERROR;
1794 if (*(int *) arg >= 0) {
1795 int index = *(int *)arg;
1796 if (source == SUB_SOURCE_VOBSUB)
1797 index = vobsub_get_index_by_id(vo_vobsub, index);
1798 new_pos = offset + index;
1799 if (index < 0 || index > mpctx->sub_counts[source]) {
1800 new_pos = -1;
1801 *(int *) arg = -1;
1804 else
1805 new_pos = -1;
1806 break;
1807 case M_PROPERTY_STEP_UP:
1808 case M_PROPERTY_STEP_DOWN: {
1809 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1810 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1811 int step = (step_all > 0) ? 1 : -1;
1812 int max_sub_pos_for_source = -1;
1813 if (!is_cur_source)
1814 new_pos = -1;
1815 while (step_all) {
1816 if (new_pos == -1) {
1817 if (step > 0)
1818 new_pos = offset;
1819 else if (max_sub_pos_for_source == -1) {
1820 // Find max pos for specific source
1821 new_pos = mpctx->global_sub_size - 1;
1822 while (new_pos >= 0
1823 && sub_source(mpctx) != source)
1824 new_pos--;
1826 else
1827 new_pos = max_sub_pos_for_source;
1829 else {
1830 new_pos += step;
1831 if (new_pos < offset ||
1832 new_pos >= mpctx->global_sub_size ||
1833 sub_source(mpctx) != source)
1834 new_pos = -1;
1836 step_all -= step;
1838 break;
1840 default:
1841 return M_PROPERTY_NOT_IMPLEMENTED;
1843 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1846 /// Subtitle delay (RW)
1847 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1848 MPContext *mpctx)
1850 if (!mpctx->sh_video)
1851 return M_PROPERTY_UNAVAILABLE;
1852 return m_property_delay(prop, action, arg, &sub_delay);
1855 /// Alignment of text subtitles (RW)
1856 static int mp_property_sub_alignment(m_option_t *prop, int action,
1857 void *arg, MPContext *mpctx)
1859 char *name[] = { _("top"), _("center"), _("bottom") };
1861 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1862 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1863 return M_PROPERTY_UNAVAILABLE;
1865 switch (action) {
1866 case M_PROPERTY_PRINT:
1867 if (!arg)
1868 return M_PROPERTY_ERROR;
1869 M_PROPERTY_CLAMP(prop, sub_alignment);
1870 *(char **) arg = strdup(mp_gtext(name[sub_alignment]));
1871 return M_PROPERTY_OK;
1872 case M_PROPERTY_SET:
1873 if (!arg)
1874 return M_PROPERTY_ERROR;
1875 case M_PROPERTY_STEP_UP:
1876 case M_PROPERTY_STEP_DOWN:
1877 vo_osd_changed(OSDTYPE_SUBTITLE);
1878 default:
1879 return m_property_choice(prop, action, arg, &sub_alignment);
1883 /// Subtitle visibility (RW)
1884 static int mp_property_sub_visibility(m_option_t *prop, int action,
1885 void *arg, MPContext *mpctx)
1887 if (!mpctx->sh_video)
1888 return M_PROPERTY_UNAVAILABLE;
1890 switch (action) {
1891 case M_PROPERTY_SET:
1892 if (!arg)
1893 return M_PROPERTY_ERROR;
1894 case M_PROPERTY_STEP_UP:
1895 case M_PROPERTY_STEP_DOWN:
1896 vo_osd_changed(OSDTYPE_SUBTITLE);
1897 if (vo_spudec)
1898 vo_osd_changed(OSDTYPE_SPU);
1899 default:
1900 return m_property_flag(prop, action, arg, &sub_visibility);
1904 #ifdef CONFIG_ASS
1905 /// Use margins for libass subtitles (RW)
1906 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1907 void *arg, MPContext *mpctx)
1909 if (!mpctx->sh_video)
1910 return M_PROPERTY_UNAVAILABLE;
1912 switch (action) {
1913 case M_PROPERTY_SET:
1914 if (!arg)
1915 return M_PROPERTY_ERROR;
1916 case M_PROPERTY_STEP_UP:
1917 case M_PROPERTY_STEP_DOWN:
1918 ass_force_reload = 1;
1919 default:
1920 return m_property_flag(prop, action, arg, &ass_use_margins);
1923 #endif
1925 /// Show only forced subtitles (RW)
1926 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1927 void *arg, MPContext *mpctx)
1929 if (!vo_spudec)
1930 return M_PROPERTY_UNAVAILABLE;
1932 switch (action) {
1933 case M_PROPERTY_SET:
1934 if (!arg)
1935 return M_PROPERTY_ERROR;
1936 case M_PROPERTY_STEP_UP:
1937 case M_PROPERTY_STEP_DOWN:
1938 m_property_flag(prop, action, arg, &forced_subs_only);
1939 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1940 return M_PROPERTY_OK;
1941 default:
1942 return m_property_flag(prop, action, arg, &forced_subs_only);
1947 #ifdef CONFIG_FREETYPE
1948 /// Subtitle scale (RW)
1949 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1950 MPContext *mpctx)
1952 struct MPOpts *opts = &mpctx->opts;
1954 switch (action) {
1955 case M_PROPERTY_SET:
1956 if (!arg)
1957 return M_PROPERTY_ERROR;
1958 M_PROPERTY_CLAMP(prop, *(float *) arg);
1959 #ifdef CONFIG_ASS
1960 if (opts->ass_enabled) {
1961 ass_font_scale = *(float *) arg;
1962 ass_force_reload = 1;
1964 #endif
1965 text_font_scale_factor = *(float *) arg;
1966 force_load_font = 1;
1967 return M_PROPERTY_OK;
1968 case M_PROPERTY_STEP_UP:
1969 case M_PROPERTY_STEP_DOWN:
1970 #ifdef CONFIG_ASS
1971 if (opts->ass_enabled) {
1972 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1973 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1974 M_PROPERTY_CLAMP(prop, ass_font_scale);
1975 ass_force_reload = 1;
1977 #endif
1978 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1979 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1980 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1981 force_load_font = 1;
1982 return M_PROPERTY_OK;
1983 default:
1984 #ifdef CONFIG_ASS
1985 if (opts->ass_enabled)
1986 return m_property_float_ro(prop, action, arg, ass_font_scale);
1987 else
1988 #endif
1989 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1992 #endif
1994 ///@}
1996 /// \defgroup TVProperties TV properties
1997 /// \ingroup Properties
1998 ///@{
2000 #ifdef CONFIG_TV
2002 /// TV color settings (RW)
2003 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2004 MPContext *mpctx)
2006 int r, val;
2007 tvi_handle_t *tvh = mpctx->demuxer->priv;
2008 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2009 return M_PROPERTY_UNAVAILABLE;
2011 switch (action) {
2012 case M_PROPERTY_SET:
2013 if (!arg)
2014 return M_PROPERTY_ERROR;
2015 M_PROPERTY_CLAMP(prop, *(int *) arg);
2016 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
2017 case M_PROPERTY_GET:
2018 return tv_get_color_options(tvh, (int) prop->priv, arg);
2019 case M_PROPERTY_STEP_UP:
2020 case M_PROPERTY_STEP_DOWN:
2021 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
2022 if (!r)
2023 return M_PROPERTY_ERROR;
2024 val += (arg ? *(int *) arg : 1) *
2025 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2026 M_PROPERTY_CLAMP(prop, val);
2027 return tv_set_color_options(tvh, (int) prop->priv, val);
2029 return M_PROPERTY_ERROR;
2031 return M_PROPERTY_NOT_IMPLEMENTED;
2034 #endif
2036 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2037 MPContext *mpctx)
2039 int val,result;
2040 int base_ioctl=(int)prop->priv;
2042 for teletext's GET,SET,STEP ioctls this is not 0
2043 SET is GET+1
2044 STEP is GET+2
2046 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2047 return M_PROPERTY_UNAVAILABLE;
2048 if(!base_ioctl)
2049 return M_PROPERTY_ERROR;
2051 switch (action) {
2052 case M_PROPERTY_GET:
2053 if (!arg)
2054 return M_PROPERTY_ERROR;
2055 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2056 break;
2057 case M_PROPERTY_SET:
2058 if (!arg)
2059 return M_PROPERTY_ERROR;
2060 M_PROPERTY_CLAMP(prop, *(int *) arg);
2061 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
2062 break;
2063 case M_PROPERTY_STEP_UP:
2064 case M_PROPERTY_STEP_DOWN:
2065 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2066 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2067 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
2068 break;
2069 default:
2070 return M_PROPERTY_NOT_IMPLEMENTED;
2073 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2076 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2077 MPContext *mpctx)
2079 int result;
2080 int val;
2082 //with tvh==NULL will fail too
2083 result=mp_property_teletext_common(prop,action,arg,mpctx);
2084 if(result!=M_PROPERTY_OK)
2085 return result;
2087 if(teletext_control(mpctx->demuxer->teletext,
2088 (int)prop->priv, &val)==VBI_CONTROL_TRUE && val)
2089 mp_input_set_section(mpctx->input, "teletext");
2090 else
2091 mp_input_set_section(mpctx->input, "tv");
2092 return M_PROPERTY_OK;
2095 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2096 MPContext *mpctx)
2098 int result;
2099 int val;
2100 if (!mpctx->demuxer->teletext)
2101 return M_PROPERTY_UNAVAILABLE;
2102 switch(action){
2103 case M_PROPERTY_STEP_UP:
2104 case M_PROPERTY_STEP_DOWN:
2105 //This should be handled separately
2106 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2107 result=teletext_control(mpctx->demuxer->teletext,
2108 TV_VBI_CONTROL_STEP_PAGE, &val);
2109 break;
2110 default:
2111 result=mp_property_teletext_common(prop,action,arg,mpctx);
2113 return result;
2116 ///@}
2118 /// All properties available in MPlayer.
2119 /** \ingroup Properties
2121 static const m_option_t mp_properties[] = {
2122 // General
2123 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2124 M_OPT_RANGE, 0, 3, NULL },
2125 { "loop", mp_property_loop, CONF_TYPE_INT,
2126 M_OPT_MIN, -1, 0, NULL },
2127 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2128 M_OPT_RANGE, 0.01, 100.0, NULL },
2129 { "filename", mp_property_filename, CONF_TYPE_STRING,
2130 0, 0, 0, NULL },
2131 { "path", mp_property_path, CONF_TYPE_STRING,
2132 0, 0, 0, NULL },
2133 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2134 0, 0, 0, NULL },
2135 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2136 M_OPT_MIN, 0, 0, NULL },
2137 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2138 M_OPT_MIN, 0, 0, NULL },
2139 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2140 M_OPT_MIN, 0, 0, NULL },
2141 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2142 M_OPT_MIN, 0, 0, NULL },
2143 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2144 M_OPT_MIN, 0, 0, NULL },
2145 { "length", mp_property_length, CONF_TYPE_TIME,
2146 M_OPT_MIN, 0, 0, NULL },
2147 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2148 M_OPT_RANGE, 0, 100, NULL },
2149 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2150 M_OPT_MIN, 0, 0, NULL },
2151 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2152 M_OPT_MIN, 0, 0, NULL },
2153 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2154 0, 0, 0, NULL },
2155 { "angle", mp_property_angle, CONF_TYPE_INT,
2156 CONF_RANGE, -2, 10, NULL },
2157 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2158 0, 0, 0, NULL },
2159 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2160 M_OPT_RANGE, 0, 1, NULL },
2162 // Audio
2163 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2164 M_OPT_RANGE, 0, 100, NULL },
2165 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2166 M_OPT_RANGE, 0, 1, NULL },
2167 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2168 M_OPT_RANGE, -100, 100, NULL },
2169 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2170 0, 0, 0, NULL },
2171 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2172 0, 0, 0, NULL },
2173 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2174 0, 0, 0, NULL },
2175 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2176 0, 0, 0, NULL },
2177 { "channels", mp_property_channels, CONF_TYPE_INT,
2178 0, 0, 0, NULL },
2179 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2180 CONF_RANGE, -2, 65535, NULL },
2181 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2182 M_OPT_RANGE, -1, 1, NULL },
2184 // Video
2185 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2186 M_OPT_RANGE, 0, 1, NULL },
2187 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2188 M_OPT_RANGE, 0, 1, NULL },
2189 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2190 M_OPT_RANGE, 0, 2, NULL },
2191 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2192 M_OPT_RANGE, 0, 1, NULL },
2193 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2194 M_OPT_RANGE, 0, 1, NULL },
2195 { "border", mp_property_border, CONF_TYPE_FLAG,
2196 M_OPT_RANGE, 0, 1, NULL },
2197 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2198 M_OPT_RANGE, 0, 2, NULL },
2199 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2200 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2201 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2202 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2203 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2204 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2205 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2206 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2207 { "hue", mp_property_gamma, CONF_TYPE_INT,
2208 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2209 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2210 M_OPT_RANGE, 0, 1, NULL },
2211 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2212 M_OPT_RANGE, 0, 1, NULL },
2213 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2214 0, 0, 0, NULL },
2215 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2216 0, 0, 0, NULL },
2217 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2218 0, 0, 0, NULL },
2219 { "width", mp_property_width, CONF_TYPE_INT,
2220 0, 0, 0, NULL },
2221 { "height", mp_property_height, CONF_TYPE_INT,
2222 0, 0, 0, NULL },
2223 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2224 0, 0, 0, NULL },
2225 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2226 0, 0, 0, NULL },
2227 { "switch_video", mp_property_video, CONF_TYPE_INT,
2228 CONF_RANGE, -2, 65535, NULL },
2229 { "switch_program", mp_property_program, CONF_TYPE_INT,
2230 CONF_RANGE, -1, 65535, NULL },
2232 // Subs
2233 { "sub", mp_property_sub, CONF_TYPE_INT,
2234 M_OPT_MIN, -1, 0, NULL },
2235 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2236 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2237 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2238 M_OPT_MIN, -1, 0, NULL },
2239 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2240 M_OPT_MIN, -1, 0, NULL },
2241 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2242 M_OPT_MIN, -1, 0, NULL },
2243 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2244 0, 0, 0, NULL },
2245 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2246 M_OPT_RANGE, 0, 100, NULL },
2247 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2248 M_OPT_RANGE, 0, 2, NULL },
2249 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2250 M_OPT_RANGE, 0, 1, NULL },
2251 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2252 M_OPT_RANGE, 0, 1, NULL },
2253 #ifdef CONFIG_FREETYPE
2254 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2255 M_OPT_RANGE, 0, 100, NULL },
2256 #endif
2257 #ifdef CONFIG_ASS
2258 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2259 M_OPT_RANGE, 0, 1, NULL },
2260 #endif
2262 #ifdef CONFIG_TV
2263 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2264 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2265 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2266 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2267 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2268 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2269 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2270 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2271 #endif
2272 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2273 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2274 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2275 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2276 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2277 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2278 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2279 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2280 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2281 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2282 { NULL, NULL, NULL, 0, 0, 0, NULL }
2286 int mp_property_do(const char *name, int action, void *val, void *ctx)
2288 return m_property_do(mp_properties, name, action, val, ctx);
2291 char* mp_property_print(const char *name, void* ctx)
2293 char* ret = NULL;
2294 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2295 return NULL;
2296 return ret;
2299 char *property_expand_string(MPContext *mpctx, char *str)
2301 return m_properties_expand_string(mp_properties, str, mpctx);
2304 void property_print_help(void)
2306 m_properties_print_help_list(mp_properties);
2310 /* List of default ways to show a property on OSD.
2312 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2313 * a bar showing the current position between min/max values of the
2314 * property. In this case osd_msg is only used for terminal output
2315 * if there is no video; it'll be a label shown together with percentage.
2317 * Otherwise setting osd_msg will show the string on OSD, formatted with
2318 * the text value of the property as argument.
2320 static struct property_osd_display {
2321 /// property name
2322 const char *name;
2323 /// progressbar type
2324 int osd_progbar; // -1 is special value for seek indicators
2325 /// osd msg id if it must be shared
2326 int osd_id;
2327 /// osd msg template
2328 const char *osd_msg;
2329 } property_osd_display[] = {
2330 // general
2331 { "loop", 0, -1, _("Loop: %s") },
2332 { "chapter", -1, -1, NULL },
2333 // audio
2334 { "volume", OSD_VOLUME, -1, _("Volume") },
2335 { "mute", 0, -1, _("Mute: %s") },
2336 { "audio_delay", 0, -1, _("A-V delay: %s") },
2337 { "switch_audio", 0, -1, _("Audio: %s") },
2338 { "balance", OSD_BALANCE, -1, _("Balance") },
2339 // video
2340 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2341 { "ontop", 0, -1, _("Stay on top: %s") },
2342 { "rootwin", 0, -1, _("Rootwin: %s") },
2343 { "border", 0, -1, _("Border: %s") },
2344 { "framedropping", 0, -1, _("Framedropping: %s") },
2345 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2346 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2347 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2348 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2349 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2350 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2351 { "hue", OSD_HUE, -1, _("Hue") },
2352 { "vsync", 0, -1, _("VSync: %s") },
2353 // subs
2354 { "sub", 0, -1, _("Subtitles: %s") },
2355 { "sub_source", 0, -1, _("Sub source: %s") },
2356 { "sub_vob", 0, -1, _("Subtitles: %s") },
2357 { "sub_demux", 0, -1, _("Subtitles: %s") },
2358 { "sub_file", 0, -1, _("Subtitles: %s") },
2359 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2360 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2361 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2362 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2363 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2364 #ifdef CONFIG_FREETYPE
2365 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2366 #endif
2367 #ifdef CONFIG_TV
2368 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2369 { "tv_hue", OSD_HUE, -1, _("Hue") },
2370 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2371 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2372 #endif
2376 static int show_property_osd(MPContext *mpctx, const char *pname)
2378 struct MPOpts *opts = &mpctx->opts;
2379 int r;
2380 m_option_t* prop;
2381 struct property_osd_display *p;
2383 // look for the command
2384 for (p = property_osd_display; p->name; p++)
2385 if (!strcmp(p->name, pname))
2386 break;
2387 if (!p->name)
2388 return -1;
2390 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2391 return -1;
2393 if (p->osd_progbar == -1)
2394 mpctx->add_osd_seek_info = true;
2395 else if (p->osd_progbar) {
2396 if (prop->type == CONF_TYPE_INT) {
2397 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2398 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2399 prop->min, prop->max, r);
2400 } else if (prop->type == CONF_TYPE_FLOAT) {
2401 float f;
2402 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2403 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2404 prop->min, prop->max, f);
2405 } else {
2406 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2407 "Property use an unsupported type.\n");
2408 return -1;
2410 return 0;
2413 if (p->osd_msg) {
2414 char *val = mp_property_print(pname, mpctx);
2415 if (val) {
2416 int index = p - property_osd_display;
2417 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2418 1, opts->osd_duration, p->osd_msg, val);
2419 free(val);
2422 return 0;
2427 * \defgroup Command2Property Command to property bridge
2429 * It is used to handle most commands that just set a property
2430 * and optionally display something on the OSD.
2431 * Two kinds of commands are handled: adjust or toggle.
2433 * Adjust commands take 1 or 2 parameters: <value> <abs>
2434 * If <abs> is non-zero the property is set to the given value
2435 * otherwise it is adjusted.
2437 * Toggle commands take 0 or 1 parameters. With no parameter
2438 * or a value less than the property minimum it just steps the
2439 * property to its next value. Otherwise it sets it to the given
2440 * value.
2445 /// List of the commands that can be handled by setting a property.
2446 static struct {
2447 /// property name
2448 const char *name;
2449 /// cmd id
2450 int cmd;
2451 /// set/adjust or toggle command
2452 int toggle;
2453 } set_prop_cmd[] = {
2454 // general
2455 { "loop", MP_CMD_LOOP, 0},
2456 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2457 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2458 { "pause", MP_CMD_PAUSE, 0},
2459 // audio
2460 { "volume", MP_CMD_VOLUME, 0},
2461 { "mute", MP_CMD_MUTE, 1},
2462 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2463 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2464 { "balance", MP_CMD_BALANCE, 0},
2465 // video
2466 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2467 { "panscan", MP_CMD_PANSCAN, 0},
2468 { "ontop", MP_CMD_VO_ONTOP, 1},
2469 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2470 { "border", MP_CMD_VO_BORDER, 1},
2471 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2472 { "gamma", MP_CMD_GAMMA, 0},
2473 { "brightness", MP_CMD_BRIGHTNESS, 0},
2474 { "contrast", MP_CMD_CONTRAST, 0},
2475 { "saturation", MP_CMD_SATURATION, 0},
2476 { "hue", MP_CMD_HUE, 0},
2477 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2478 // subs
2479 { "sub", MP_CMD_SUB_SELECT, 1},
2480 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2481 { "sub_vob", MP_CMD_SUB_VOB, 1},
2482 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2483 { "sub_file", MP_CMD_SUB_FILE, 1},
2484 { "sub_pos", MP_CMD_SUB_POS, 0},
2485 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2486 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2487 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2488 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2489 #ifdef CONFIG_FREETYPE
2490 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2491 #endif
2492 #ifdef CONFIG_ASS
2493 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2494 #endif
2495 #ifdef CONFIG_TV
2496 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2497 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2498 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2499 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2500 #endif
2504 /// Handle commands that set a property.
2505 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2507 int i, r;
2508 m_option_t *prop;
2509 const char *pname;
2511 // look for the command
2512 for (i = 0; set_prop_cmd[i].name; i++)
2513 if (set_prop_cmd[i].cmd == cmd->id)
2514 break;
2515 if (!(pname = set_prop_cmd[i].name))
2516 return 0;
2518 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2519 return 0;
2521 // toggle command
2522 if (set_prop_cmd[i].toggle) {
2523 // set to value
2524 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2525 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2526 else
2527 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2528 } else if (cmd->args[1].v.i) //set
2529 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2530 else // adjust
2531 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2533 if (r <= 0)
2534 return 1;
2536 show_property_osd(mpctx, pname);
2538 return 1;
2541 #ifdef CONFIG_DVDNAV
2542 static const struct {
2543 const char *name;
2544 const mp_command_type cmd;
2545 } mp_dvdnav_bindings[] = {
2546 { "up", MP_CMD_DVDNAV_UP },
2547 { "down", MP_CMD_DVDNAV_DOWN },
2548 { "left", MP_CMD_DVDNAV_LEFT },
2549 { "right", MP_CMD_DVDNAV_RIGHT },
2550 { "menu", MP_CMD_DVDNAV_MENU },
2551 { "select", MP_CMD_DVDNAV_SELECT },
2552 { "prev", MP_CMD_DVDNAV_PREVMENU },
2553 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2556 * keep old dvdnav sub-command options for a while in order not to
2557 * break slave-mode API too suddenly.
2559 { "1", MP_CMD_DVDNAV_UP },
2560 { "2", MP_CMD_DVDNAV_DOWN },
2561 { "3", MP_CMD_DVDNAV_LEFT },
2562 { "4", MP_CMD_DVDNAV_RIGHT },
2563 { "5", MP_CMD_DVDNAV_MENU },
2564 { "6", MP_CMD_DVDNAV_SELECT },
2565 { "7", MP_CMD_DVDNAV_PREVMENU },
2566 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2567 { NULL, 0 }
2569 #endif
2571 static const char *property_error_string(int error_value)
2573 switch (error_value) {
2574 case M_PROPERTY_ERROR:
2575 return "ERROR";
2576 case M_PROPERTY_UNAVAILABLE:
2577 return "PROPERTY_UNAVAILABLE";
2578 case M_PROPERTY_NOT_IMPLEMENTED:
2579 return "NOT_IMPLEMENTED";
2580 case M_PROPERTY_UNKNOWN:
2581 return "PROPERTY_UNKNOWN";
2582 case M_PROPERTY_DISABLED:
2583 return "DISABLED";
2585 return "UNKNOWN";
2588 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2590 int idx;
2591 int end = start + count;
2592 int after = mpctx->set_of_sub_size - end;
2593 sub_data **subs = mpctx->set_of_subtitles;
2594 #ifdef CONFIG_ASS
2595 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2596 #endif
2597 if (count < 0 || count > mpctx->set_of_sub_size ||
2598 start < 0 || start > mpctx->set_of_sub_size - count) {
2599 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2600 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2601 return;
2603 for (idx = start; idx < end; idx++) {
2604 sub_data *subd = subs[idx];
2605 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2606 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2607 filename_recode(subd->filename));
2608 sub_free(subd);
2609 subs[idx] = NULL;
2610 #ifdef CONFIG_ASS
2611 if (ass_tracks[idx])
2612 ass_free_track(ass_tracks[idx]);
2613 ass_tracks[idx] = NULL;
2614 #endif
2617 mpctx->global_sub_size -= count;
2618 mpctx->set_of_sub_size -= count;
2619 if (mpctx->set_of_sub_size <= 0)
2620 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2622 memmove(subs + start, subs + end, after * sizeof(*subs));
2623 memset(subs + start + after, 0, count * sizeof(*subs));
2624 #ifdef CONFIG_ASS
2625 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2626 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2627 #endif
2629 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2630 mpctx->global_sub_pos = -2;
2631 subdata = NULL;
2632 #ifdef CONFIG_ASS
2633 ass_track = NULL;
2634 #endif
2635 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2636 } else if (mpctx->set_of_sub_pos >= end) {
2637 mpctx->set_of_sub_pos -= count;
2638 mpctx->global_sub_pos -= count;
2642 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2644 struct MPOpts *opts = &mpctx->opts;
2645 sh_audio_t * const sh_audio = mpctx->sh_audio;
2646 sh_video_t * const sh_video = mpctx->sh_video;
2647 int osd_duration = opts->osd_duration;
2648 int case_fallthrough_hack = 0;
2649 if (!set_property_command(mpctx, cmd))
2650 switch (cmd->id) {
2651 case MP_CMD_SEEK:{
2652 float v;
2653 int abs;
2654 mpctx->add_osd_seek_info = true;
2655 v = cmd->args[0].v.f;
2656 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2657 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2658 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2659 if (sh_video)
2660 mpctx->osd_function =
2661 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2662 mpctx->rel_seek_secs = v;
2663 } else if (abs) { /* Absolute seek by percentage */
2664 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2665 if (sh_video)
2666 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2667 mpctx->rel_seek_secs = v / 100.0;
2668 } else {
2669 mpctx->rel_seek_secs += v;
2670 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2673 break;
2675 case MP_CMD_SET_PROPERTY_OSD:
2676 case_fallthrough_hack = 1;
2678 case MP_CMD_SET_PROPERTY:{
2679 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2680 cmd->args[1].v.s, mpctx);
2681 if (r == M_PROPERTY_UNKNOWN)
2682 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2683 "Unknown property: '%s'\n", cmd->args[0].v.s);
2684 else if (r <= 0)
2685 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2686 "Failed to set property '%s' to '%s'.\n",
2687 cmd->args[0].v.s, cmd->args[1].v.s);
2688 else if (case_fallthrough_hack)
2689 show_property_osd(mpctx, cmd->args[0].v.s);
2690 if (r <= 0)
2691 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2693 break;
2695 case MP_CMD_STEP_PROPERTY_OSD:
2696 case_fallthrough_hack = 1;
2698 case MP_CMD_STEP_PROPERTY:{
2699 void* arg = NULL;
2700 int r,i;
2701 double d;
2702 off_t o;
2703 if (cmd->args[1].v.f) {
2704 m_option_t* prop;
2705 if((r = mp_property_do(cmd->args[0].v.s,
2706 M_PROPERTY_GET_TYPE,
2707 &prop, mpctx)) <= 0)
2708 goto step_prop_err;
2709 if(prop->type == CONF_TYPE_INT ||
2710 prop->type == CONF_TYPE_FLAG)
2711 i = cmd->args[1].v.f, arg = &i;
2712 else if(prop->type == CONF_TYPE_FLOAT)
2713 arg = &cmd->args[1].v.f;
2714 else if(prop->type == CONF_TYPE_DOUBLE ||
2715 prop->type == CONF_TYPE_TIME)
2716 d = cmd->args[1].v.f, arg = &d;
2717 else if(prop->type == CONF_TYPE_POSITION)
2718 o = cmd->args[1].v.f, arg = &o;
2719 else
2720 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2721 "Ignoring step size stepping property '%s'.\n",
2722 cmd->args[0].v.s);
2724 r = mp_property_do(cmd->args[0].v.s,
2725 cmd->args[2].v.i < 0 ?
2726 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2727 arg, mpctx);
2728 step_prop_err:
2729 if (r == M_PROPERTY_UNKNOWN)
2730 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2731 "Unknown property: '%s'\n", cmd->args[0].v.s);
2732 else if (r <= 0)
2733 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2734 "Failed to increment property '%s' by %f.\n",
2735 cmd->args[0].v.s, cmd->args[1].v.f);
2736 else if (case_fallthrough_hack)
2737 show_property_osd(mpctx, cmd->args[0].v.s);
2738 if (r <= 0)
2739 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2741 break;
2743 case MP_CMD_GET_PROPERTY:{
2744 char *tmp;
2745 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2746 &tmp, mpctx);
2747 if (r <= 0) {
2748 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2749 "Failed to get value of property '%s'.\n",
2750 cmd->args[0].v.s);
2751 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2752 break;
2754 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2755 cmd->args[0].v.s, tmp);
2756 free(tmp);
2758 break;
2760 case MP_CMD_EDL_MARK:
2761 if (edl_fd) {
2762 float v = sh_video ? sh_video->pts :
2763 playing_audio_pts(mpctx);
2764 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2765 mpctx->begin_skip = v;
2766 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2767 } else {
2768 if (mpctx->begin_skip > v)
2769 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2770 else {
2771 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2772 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2774 mpctx->begin_skip = MP_NOPTS_VALUE;
2777 break;
2779 case MP_CMD_SWITCH_RATIO:
2780 if (!sh_video)
2781 break;
2782 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2783 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2784 else
2785 opts->movie_aspect = cmd->args[0].v.f;
2786 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2787 break;
2789 case MP_CMD_SPEED_INCR:{
2790 float v = cmd->args[0].v.f;
2791 opts->playback_speed += v;
2792 build_afilter_chain(mpctx, sh_audio, &ao_data);
2793 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2794 opts->playback_speed);
2795 } break;
2797 case MP_CMD_SPEED_MULT:{
2798 float v = cmd->args[0].v.f;
2799 opts->playback_speed *= v;
2800 build_afilter_chain(mpctx, sh_audio, &ao_data);
2801 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2802 opts->playback_speed);
2803 } break;
2805 case MP_CMD_SPEED_SET:{
2806 float v = cmd->args[0].v.f;
2807 opts->playback_speed = v;
2808 build_afilter_chain(mpctx, sh_audio, &ao_data);
2809 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2810 opts->playback_speed);
2811 } break;
2813 case MP_CMD_FRAME_STEP:
2814 add_step_frame(mpctx);
2815 break;
2817 case MP_CMD_FILE_FILTER:
2818 file_filter = cmd->args[0].v.i;
2819 break;
2821 case MP_CMD_QUIT:
2822 exit_player_with_rc(mpctx, EXIT_QUIT,
2823 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2825 case MP_CMD_PLAY_TREE_STEP:{
2826 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2827 int force = cmd->args[1].v.i;
2830 if (!force && mpctx->playtree_iter) {
2831 play_tree_iter_t *i =
2832 play_tree_iter_new_copy(mpctx->playtree_iter);
2833 if (play_tree_iter_step(i, n, 0) ==
2834 PLAY_TREE_ITER_ENTRY)
2835 mpctx->stop_play =
2836 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2837 play_tree_iter_free(i);
2838 } else
2839 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2840 if (mpctx->stop_play)
2841 mpctx->play_tree_step = n;
2844 break;
2846 case MP_CMD_PLAY_TREE_UP_STEP:{
2847 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2848 int force = cmd->args[1].v.i;
2850 if (!force && mpctx->playtree_iter) {
2851 play_tree_iter_t *i =
2852 play_tree_iter_new_copy(mpctx->playtree_iter);
2853 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2854 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2855 play_tree_iter_free(i);
2856 } else
2857 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2859 break;
2861 case MP_CMD_PLAY_ALT_SRC_STEP:
2862 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2863 int v = cmd->args[0].v.i;
2864 if (v > 0
2865 && mpctx->playtree_iter->file <
2866 mpctx->playtree_iter->num_files)
2867 mpctx->stop_play = PT_NEXT_SRC;
2868 else if (v < 0 && mpctx->playtree_iter->file > 1)
2869 mpctx->stop_play = PT_PREV_SRC;
2871 break;
2873 case MP_CMD_SUB_STEP:
2874 if (sh_video) {
2875 int movement = cmd->args[0].v.i;
2876 step_sub(subdata, sh_video->pts, movement);
2877 #ifdef CONFIG_ASS
2878 if (ass_track)
2879 sub_delay +=
2880 ass_step_sub(ass_track,
2881 (sh_video->pts +
2882 sub_delay) * 1000 + .5, movement) / 1000.;
2883 #endif
2884 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2885 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2887 break;
2889 case MP_CMD_SUB_LOG:
2890 log_sub(mpctx);
2891 break;
2893 case MP_CMD_OSD:{
2894 int v = cmd->args[0].v.i;
2895 int max = (term_osd
2896 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2897 if (opts->osd_level > max)
2898 opts->osd_level = max;
2899 if (v < 0)
2900 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2901 else
2902 opts->osd_level = v > max ? max : v;
2903 /* Show OSD state when disabled, but not when an explicit
2904 argument is given to the OSD command, i.e. in slave mode. */
2905 if (v == -1 && opts->osd_level <= 1)
2906 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2907 "OSD: %s",
2908 opts->osd_level ? mp_gtext("enabled") :
2909 mp_gtext("disabled"));
2910 else
2911 rm_osd_msg(OSD_MSG_OSD_STATUS);
2913 break;
2915 case MP_CMD_OSD_SHOW_TEXT:
2916 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2917 (cmd->args[1].v.i <
2918 0 ? osd_duration : cmd->args[1].v.i),
2919 "%-.63s", cmd->args[0].v.s);
2920 break;
2922 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2923 char *txt = m_properties_expand_string(mp_properties,
2924 cmd->args[0].v.s,
2925 mpctx);
2926 /* if no argument supplied take default osd_duration, else <arg> ms. */
2927 if (txt) {
2928 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2929 (cmd->args[1].v.i <
2930 0 ? osd_duration : cmd->args[1].v.i),
2931 "%-.63s", txt);
2932 free(txt);
2935 break;
2937 case MP_CMD_LOADFILE:{
2938 play_tree_t *e = play_tree_new();
2939 play_tree_add_file(e, cmd->args[0].v.s);
2941 if (cmd->args[1].v.i) // append
2942 play_tree_append_entry(mpctx->playtree->child, e);
2943 else {
2944 // Go back to the starting point.
2945 while (play_tree_iter_up_step
2946 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2947 /* NOP */ ;
2948 play_tree_free_list(mpctx->playtree->child, 1);
2949 play_tree_set_child(mpctx->playtree, e);
2950 pt_iter_goto_head(mpctx->playtree_iter);
2951 mpctx->stop_play = PT_NEXT_SRC;
2954 break;
2956 case MP_CMD_LOADLIST:{
2957 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2958 if (!e)
2959 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2960 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2961 else {
2962 if (cmd->args[1].v.i) // append
2963 play_tree_append_entry(mpctx->playtree->child, e);
2964 else {
2965 // Go back to the starting point.
2966 while (play_tree_iter_up_step
2967 (mpctx->playtree_iter, 0, 1)
2968 != PLAY_TREE_ITER_END)
2969 /* NOP */ ;
2970 play_tree_free_list(mpctx->playtree->child, 1);
2971 play_tree_set_child(mpctx->playtree, e);
2972 pt_iter_goto_head(mpctx->playtree_iter);
2973 mpctx->stop_play = PT_NEXT_SRC;
2977 break;
2979 case MP_CMD_STOP:
2980 // Go back to the starting point.
2981 while (play_tree_iter_up_step
2982 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2983 /* NOP */ ;
2984 mpctx->stop_play = PT_STOP;
2985 break;
2987 case MP_CMD_OSD_SHOW_PROGRESSION:{
2988 int len = demuxer_get_time_length(mpctx->demuxer);
2989 int pts = demuxer_get_current_time(mpctx->demuxer);
2990 set_osd_bar(mpctx, 0, "Position", 0, 100, demuxer_get_percent_pos(mpctx->demuxer));
2991 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2992 "%c %02d:%02d:%02d / %02d:%02d:%02d",
2993 mpctx->osd_function, pts/3600, (pts/60)%60, pts%60,
2994 len/3600, (len/60)%60, len%60);
2996 break;
2998 #ifdef CONFIG_RADIO
2999 case MP_CMD_RADIO_STEP_CHANNEL:
3000 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3001 int v = cmd->args[0].v.i;
3002 if (v > 0)
3003 radio_step_channel(mpctx->demuxer->stream,
3004 RADIO_CHANNEL_HIGHER);
3005 else
3006 radio_step_channel(mpctx->demuxer->stream,
3007 RADIO_CHANNEL_LOWER);
3008 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3009 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3010 "Channel: %s",
3011 radio_get_channel_name(mpctx->demuxer->stream));
3014 break;
3016 case MP_CMD_RADIO_SET_CHANNEL:
3017 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3018 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3019 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3020 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3021 "Channel: %s",
3022 radio_get_channel_name(mpctx->demuxer->stream));
3025 break;
3027 case MP_CMD_RADIO_SET_FREQ:
3028 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3029 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3030 break;
3032 case MP_CMD_RADIO_STEP_FREQ:
3033 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3034 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3035 break;
3036 #endif
3038 #ifdef CONFIG_TV
3039 case MP_CMD_TV_START_SCAN:
3040 if (mpctx->file_format == DEMUXER_TYPE_TV)
3041 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
3042 break;
3043 case MP_CMD_TV_SET_FREQ:
3044 if (mpctx->file_format == DEMUXER_TYPE_TV)
3045 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3046 cmd->args[0].v.f * 16.0);
3047 #ifdef CONFIG_PVR
3048 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3049 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
3050 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3051 pvr_get_current_channelname (mpctx->stream),
3052 pvr_get_current_stationname (mpctx->stream));
3054 #endif /* CONFIG_PVR */
3055 break;
3057 case MP_CMD_TV_STEP_FREQ:
3058 if (mpctx->file_format == DEMUXER_TYPE_TV)
3059 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3060 cmd->args[0].v.f * 16.0);
3061 #ifdef CONFIG_PVR
3062 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3063 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
3064 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3065 pvr_get_current_channelname (mpctx->stream),
3066 pvr_get_current_frequency (mpctx->stream));
3068 #endif /* CONFIG_PVR */
3069 break;
3071 case MP_CMD_TV_SET_NORM:
3072 if (mpctx->file_format == DEMUXER_TYPE_TV)
3073 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3074 cmd->args[0].v.s);
3075 break;
3077 case MP_CMD_TV_STEP_CHANNEL:{
3078 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3079 int v = cmd->args[0].v.i;
3080 if (v > 0) {
3081 tv_step_channel((tvi_handle_t *) (mpctx->
3082 demuxer->priv),
3083 TV_CHANNEL_HIGHER);
3084 } else {
3085 tv_step_channel((tvi_handle_t *) (mpctx->
3086 demuxer->priv),
3087 TV_CHANNEL_LOWER);
3089 if (tv_channel_list) {
3090 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3091 "Channel: %s", tv_channel_current->name);
3092 //vo_osd_changed(OSDTYPE_SUBTITLE);
3095 #ifdef CONFIG_PVR
3096 else if (mpctx->stream &&
3097 mpctx->stream->type == STREAMTYPE_PVR) {
3098 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3099 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3100 pvr_get_current_channelname (mpctx->stream),
3101 pvr_get_current_stationname (mpctx->stream));
3103 #endif /* CONFIG_PVR */
3105 #ifdef CONFIG_DVBIN
3106 if (mpctx->stream->type == STREAMTYPE_DVB) {
3107 int dir;
3108 int v = cmd->args[0].v.i;
3110 mpctx->last_dvb_step = v;
3111 if (v > 0)
3112 dir = DVB_CHANNEL_HIGHER;
3113 else
3114 dir = DVB_CHANNEL_LOWER;
3117 if (dvb_step_channel(mpctx->stream, dir)) {
3118 mpctx->stop_play = PT_NEXT_ENTRY;
3119 mpctx->dvbin_reopen = 1;
3122 #endif /* CONFIG_DVBIN */
3123 break;
3125 case MP_CMD_TV_SET_CHANNEL:
3126 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3127 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3128 cmd->args[0].v.s);
3129 if (tv_channel_list) {
3130 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3131 "Channel: %s", tv_channel_current->name);
3132 //vo_osd_changed(OSDTYPE_SUBTITLE);
3135 #ifdef CONFIG_PVR
3136 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3137 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3138 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3139 pvr_get_current_channelname (mpctx->stream),
3140 pvr_get_current_stationname (mpctx->stream));
3142 #endif /* CONFIG_PVR */
3143 break;
3145 #ifdef CONFIG_DVBIN
3146 case MP_CMD_DVB_SET_CHANNEL:
3147 if (mpctx->stream->type == STREAMTYPE_DVB) {
3148 mpctx->last_dvb_step = 1;
3150 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3151 cmd->args[0].v.i)) {
3152 mpctx->stop_play = PT_NEXT_ENTRY;
3153 mpctx->dvbin_reopen = 1;
3156 break;
3157 #endif /* CONFIG_DVBIN */
3159 case MP_CMD_TV_LAST_CHANNEL:
3160 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3161 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3162 if (tv_channel_list) {
3163 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3164 "Channel: %s", tv_channel_current->name);
3165 //vo_osd_changed(OSDTYPE_SUBTITLE);
3168 #ifdef CONFIG_PVR
3169 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3170 pvr_set_lastchannel (mpctx->stream);
3171 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3172 pvr_get_current_channelname (mpctx->stream),
3173 pvr_get_current_stationname (mpctx->stream));
3175 #endif /* CONFIG_PVR */
3176 break;
3178 case MP_CMD_TV_STEP_NORM:
3179 if (mpctx->file_format == DEMUXER_TYPE_TV)
3180 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3181 break;
3183 case MP_CMD_TV_STEP_CHANNEL_LIST:
3184 if (mpctx->file_format == DEMUXER_TYPE_TV)
3185 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3186 break;
3187 #endif /* CONFIG_TV */
3188 case MP_CMD_TV_TELETEXT_ADD_DEC:
3190 if (mpctx->demuxer->teletext)
3191 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3192 &(cmd->args[0].v.s));
3193 break;
3195 case MP_CMD_TV_TELETEXT_GO_LINK:
3197 if (mpctx->demuxer->teletext)
3198 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3199 &(cmd->args[0].v.i));
3200 break;
3203 case MP_CMD_SUB_LOAD:
3204 if (sh_video) {
3205 int n = mpctx->set_of_sub_size;
3206 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3207 if (n != mpctx->set_of_sub_size) {
3208 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3209 ++mpctx->global_sub_size;
3212 break;
3214 case MP_CMD_SUB_REMOVE:
3215 if (sh_video) {
3216 int v = cmd->args[0].v.i;
3217 if (v < 0) {
3218 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3219 } else if (v < mpctx->set_of_sub_size) {
3220 remove_subtitle_range(mpctx, v, 1);
3223 break;
3225 case MP_CMD_GET_SUB_VISIBILITY:
3226 if (sh_video) {
3227 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3228 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3230 break;
3232 case MP_CMD_SCREENSHOT:
3233 if (mpctx->video_out && mpctx->video_out->config_ok) {
3234 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3235 if (CONTROL_OK !=
3236 ((vf_instance_t *) sh_video->vfilter)->
3237 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3238 &cmd->args[0].v.i))
3239 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3241 break;
3243 case MP_CMD_VF_CHANGE_RECTANGLE:
3244 if (!sh_video)
3245 break;
3246 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3247 break;
3249 case MP_CMD_GET_TIME_LENGTH:{
3250 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3251 demuxer_get_time_length(mpctx->demuxer));
3253 break;
3255 case MP_CMD_GET_FILENAME:{
3256 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3257 get_metadata(mpctx, META_NAME));
3259 break;
3261 case MP_CMD_GET_VIDEO_CODEC:{
3262 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3263 if (!inf)
3264 inf = strdup("");
3265 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3266 free(inf);
3268 break;
3270 case MP_CMD_GET_VIDEO_BITRATE:{
3271 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3272 if (!inf)
3273 inf = strdup("");
3274 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3275 free(inf);
3277 break;
3279 case MP_CMD_GET_VIDEO_RESOLUTION:{
3280 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3281 if (!inf)
3282 inf = strdup("");
3283 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3284 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3285 free(inf);
3287 break;
3289 case MP_CMD_GET_AUDIO_CODEC:{
3290 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3291 if (!inf)
3292 inf = strdup("");
3293 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3294 free(inf);
3296 break;
3298 case MP_CMD_GET_AUDIO_BITRATE:{
3299 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3300 if (!inf)
3301 inf = strdup("");
3302 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3303 free(inf);
3305 break;
3307 case MP_CMD_GET_AUDIO_SAMPLES:{
3308 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3309 if (!inf)
3310 inf = strdup("");
3311 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3312 free(inf);
3314 break;
3316 case MP_CMD_GET_META_TITLE:{
3317 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3318 if (!inf)
3319 inf = strdup("");
3320 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3321 free(inf);
3323 break;
3325 case MP_CMD_GET_META_ARTIST:{
3326 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3327 if (!inf)
3328 inf = strdup("");
3329 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3330 free(inf);
3332 break;
3334 case MP_CMD_GET_META_ALBUM:{
3335 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3336 if (!inf)
3337 inf = strdup("");
3338 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3339 free(inf);
3341 break;
3343 case MP_CMD_GET_META_YEAR:{
3344 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3345 if (!inf)
3346 inf = strdup("");
3347 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3348 free(inf);
3350 break;
3352 case MP_CMD_GET_META_COMMENT:{
3353 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3354 if (!inf)
3355 inf = strdup("");
3356 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3357 free(inf);
3359 break;
3361 case MP_CMD_GET_META_TRACK:{
3362 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3363 if (!inf)
3364 inf = strdup("");
3365 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3366 free(inf);
3368 break;
3370 case MP_CMD_GET_META_GENRE:{
3371 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3372 if (!inf)
3373 inf = strdup("");
3374 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3375 free(inf);
3377 break;
3379 case MP_CMD_GET_VO_FULLSCREEN:
3380 if (mpctx->video_out && mpctx->video_out->config_ok)
3381 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3382 break;
3384 case MP_CMD_GET_PERCENT_POS:
3385 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3386 demuxer_get_percent_pos(mpctx->demuxer));
3387 break;
3389 case MP_CMD_GET_TIME_POS:{
3390 float pos = 0;
3391 if (sh_video)
3392 pos = sh_video->pts;
3393 else if (sh_audio && mpctx->audio_out)
3394 pos = playing_audio_pts(mpctx);
3395 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3397 break;
3399 case MP_CMD_RUN:
3400 #ifndef __MINGW32__
3401 if (!fork()) {
3402 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3403 exit(0);
3405 #endif
3406 break;
3408 case MP_CMD_KEYDOWN_EVENTS:
3409 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3410 break;
3412 case MP_CMD_SET_MOUSE_POS:{
3413 int pointer_x, pointer_y;
3414 double dx, dy;
3415 pointer_x = cmd->args[0].v.i;
3416 pointer_y = cmd->args[1].v.i;
3417 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3418 #ifdef CONFIG_DVDNAV
3419 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3420 && dx > 0.0 && dy > 0.0) {
3421 int button = -1;
3422 pointer_x = (int) (dx * (double) sh_video->disp_w);
3423 pointer_y = (int) (dy * (double) sh_video->disp_h);
3424 mp_dvdnav_update_mouse_pos(mpctx->stream,
3425 pointer_x, pointer_y, &button);
3426 if (opts->osd_level > 1 && button > 0)
3427 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3428 "Selected button number %d", button);
3430 #endif
3431 #ifdef CONFIG_MENU
3432 if (use_menu && dx >= 0.0 && dy >= 0.0)
3433 menu_update_mouse_pos(dx, dy);
3434 #endif
3436 break;
3438 #ifdef CONFIG_DVDNAV
3439 case MP_CMD_DVDNAV:{
3440 int button = -1;
3441 int i;
3442 mp_command_type command = 0;
3443 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3444 break;
3446 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3447 if (cmd->args[0].v.s &&
3448 !strcasecmp (cmd->args[0].v.s,
3449 mp_dvdnav_bindings[i].name))
3450 command = mp_dvdnav_bindings[i].cmd;
3452 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3453 if (opts->osd_level > 1 && button > 0)
3454 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3455 "Selected button number %d", button);
3457 break;
3459 case MP_CMD_SWITCH_TITLE:
3460 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3461 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3462 break;
3464 #endif
3466 case MP_CMD_AF_SWITCH:
3467 if (sh_audio)
3469 af_uninit(mpctx->mixer.afilter);
3470 af_init(mpctx->mixer.afilter);
3472 case MP_CMD_AF_ADD:
3473 case MP_CMD_AF_DEL:
3474 if (!sh_audio)
3475 break;
3477 char* af_args = strdup(cmd->args[0].v.s);
3478 char* af_commands = af_args;
3479 char* af_command;
3480 af_instance_t* af;
3481 while ((af_command = strsep(&af_commands, ",")) != NULL)
3483 if (cmd->id == MP_CMD_AF_DEL)
3485 af = af_get(mpctx->mixer.afilter, af_command);
3486 if (af != NULL)
3487 af_remove(mpctx->mixer.afilter, af);
3489 else
3490 af_add(mpctx->mixer.afilter, af_command);
3492 build_afilter_chain(mpctx, sh_audio, &ao_data);
3493 free(af_args);
3495 break;
3496 case MP_CMD_AF_CLR:
3497 if (!sh_audio)
3498 break;
3499 af_uninit(mpctx->mixer.afilter);
3500 af_init(mpctx->mixer.afilter);
3501 build_afilter_chain(mpctx, sh_audio, &ao_data);
3502 break;
3503 default:
3504 mp_msg(MSGT_CPLAYER, MSGL_V,
3505 "Received unknown cmd %s\n", cmd->name);
3508 switch (cmd->pausing) {
3509 case 1: // "pausing"
3510 pause_player(mpctx);
3511 break;
3512 case 3: // "pausing_toggle"
3513 if (mpctx->paused)
3514 unpause_player(mpctx);
3515 else
3516 pause_player(mpctx);
3517 break;