vo_gl2: Use identical code to -vo gl for -wid mode
[mplayer/glamo.git] / command.c
blob3a9c3aa17943071ab413da61be60757a639a2ecb
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 /// Media length in seconds (RO)
375 static int mp_property_length(m_option_t *prop, int action, void *arg,
376 MPContext *mpctx)
378 double len;
380 if (!mpctx->demuxer ||
381 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
382 return M_PROPERTY_UNAVAILABLE;
384 return m_property_time_ro(prop, action, arg, len);
387 /// Current position in percent (RW)
388 static int mp_property_percent_pos(m_option_t *prop, int action,
389 void *arg, MPContext *mpctx) {
390 int pos;
392 if (!mpctx->demuxer)
393 return M_PROPERTY_UNAVAILABLE;
395 switch(action) {
396 case M_PROPERTY_SET:
397 if(!arg) return M_PROPERTY_ERROR;
398 M_PROPERTY_CLAMP(prop, *(int*)arg);
399 pos = *(int*)arg;
400 break;
401 case M_PROPERTY_STEP_UP:
402 case M_PROPERTY_STEP_DOWN:
403 pos = demuxer_get_percent_pos(mpctx->demuxer);
404 pos += (arg ? *(int*)arg : 10) *
405 (action == M_PROPERTY_STEP_UP ? 1 : -1);
406 M_PROPERTY_CLAMP(prop, pos);
407 break;
408 default:
409 return m_property_int_ro(prop, action, arg,
410 demuxer_get_percent_pos(mpctx->demuxer));
413 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
414 mpctx->rel_seek_secs = pos / 100.0;
415 return M_PROPERTY_OK;
418 /// Current position in seconds (RW)
419 static int mp_property_time_pos(m_option_t *prop, int action,
420 void *arg, MPContext *mpctx) {
421 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
422 return M_PROPERTY_UNAVAILABLE;
424 switch(action) {
425 case M_PROPERTY_SET:
426 if(!arg) return M_PROPERTY_ERROR;
427 M_PROPERTY_CLAMP(prop, *(double*)arg);
428 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
429 mpctx->rel_seek_secs = *(double*)arg;
430 return M_PROPERTY_OK;
431 case M_PROPERTY_STEP_UP:
432 case M_PROPERTY_STEP_DOWN:
433 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
434 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
435 return M_PROPERTY_OK;
437 return m_property_time_ro(prop, action, arg,
438 mpctx->sh_video ? mpctx->sh_video->pts :
439 playing_audio_pts(mpctx));
442 /// Current chapter (RW)
443 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
444 MPContext *mpctx)
446 struct MPOpts *opts = &mpctx->opts;
447 int chapter = -1;
448 int step_all;
449 char *chapter_name = NULL;
451 if (mpctx->demuxer)
452 chapter = get_current_chapter(mpctx);
453 if (chapter < -1)
454 return M_PROPERTY_UNAVAILABLE;
456 switch (action) {
457 case M_PROPERTY_GET:
458 if (!arg)
459 return M_PROPERTY_ERROR;
460 *(int *) arg = chapter;
461 return M_PROPERTY_OK;
462 case M_PROPERTY_PRINT: {
463 if (!arg)
464 return M_PROPERTY_ERROR;
465 chapter_name = chapter_display_name(mpctx, chapter);
466 if (!chapter_name)
467 return M_PROPERTY_UNAVAILABLE;
468 *(char **) arg = chapter_name;
469 return M_PROPERTY_OK;
471 case M_PROPERTY_SET:
472 if (!arg)
473 return M_PROPERTY_ERROR;
474 M_PROPERTY_CLAMP(prop, *(int*)arg);
475 step_all = *(int *)arg - chapter;
476 chapter += step_all;
477 break;
478 case M_PROPERTY_STEP_UP:
479 case M_PROPERTY_STEP_DOWN: {
480 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
481 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
482 chapter += step_all;
483 if (chapter < 0)
484 chapter = 0;
485 break;
487 default:
488 return M_PROPERTY_NOT_IMPLEMENTED;
491 double next_pts = 0;
492 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
493 mpctx->rel_seek_secs = 0;
494 mpctx->abs_seek_pos = 0;
495 if (chapter >= 0) {
496 if (next_pts > -1.0) {
497 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
498 mpctx->rel_seek_secs = next_pts;
500 if (chapter_name)
501 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
502 "Chapter: (%d) %s", chapter + 1, chapter_name);
504 else if (step_all > 0)
505 mpctx->rel_seek_secs = 1000000000.;
506 else
507 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
508 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
509 if (chapter_name)
510 talloc_free(chapter_name);
511 return M_PROPERTY_OK;
514 /// Number of chapters in file
515 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
516 MPContext *mpctx)
518 if (!mpctx->demuxer)
519 return M_PROPERTY_UNAVAILABLE;
520 if (mpctx->demuxer->num_chapters == 0)
521 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
522 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
525 /// Current dvd angle (RW)
526 static int mp_property_angle(m_option_t *prop, int action, void *arg,
527 MPContext *mpctx)
529 struct MPOpts *opts = &mpctx->opts;
530 int angle = -1;
531 int angles;
532 char *angle_name = NULL;
534 if (mpctx->demuxer)
535 angle = demuxer_get_current_angle(mpctx->demuxer);
536 if (angle < 0)
537 return M_PROPERTY_UNAVAILABLE;
538 angles = demuxer_angles_count(mpctx->demuxer);
539 if (angles <= 1)
540 return M_PROPERTY_UNAVAILABLE;
542 switch (action) {
543 case M_PROPERTY_GET:
544 if (!arg)
545 return M_PROPERTY_ERROR;
546 *(int *) arg = angle;
547 return M_PROPERTY_OK;
548 case M_PROPERTY_PRINT: {
549 if (!arg)
550 return M_PROPERTY_ERROR;
551 angle_name = calloc(1, 64);
552 if (!angle_name)
553 return M_PROPERTY_UNAVAILABLE;
554 snprintf(angle_name, 64, "%d/%d", angle, angles);
555 *(char **) arg = angle_name;
556 return M_PROPERTY_OK;
558 case M_PROPERTY_SET:
559 if (!arg)
560 return M_PROPERTY_ERROR;
561 angle = *(int *)arg;
562 M_PROPERTY_CLAMP(prop, angle);
563 break;
564 case M_PROPERTY_STEP_UP:
565 case M_PROPERTY_STEP_DOWN: {
566 int step = 0;
567 if(arg)
568 step = *(int*)arg;
569 if(!step)
570 step = 1;
571 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
572 angle += step;
573 if (angle < 1) //cycle
574 angle = angles;
575 break;
577 default:
578 return M_PROPERTY_NOT_IMPLEMENTED;
580 angle = demuxer_set_angle(mpctx->demuxer, angle);
581 if (angle >= 0) {
582 struct sh_video *sh_video = mpctx->demuxer->video->sh;
583 if (sh_video)
584 resync_video_stream(sh_video);
586 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
587 if (sh_audio)
588 resync_audio_stream(sh_audio);
591 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
592 "Angle: %d/%d", angle, angles);
593 if (angle_name)
594 free(angle_name);
595 return M_PROPERTY_OK;
598 /// Demuxer meta data
599 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
600 MPContext *mpctx) {
601 m_property_action_t* ka;
602 char* meta;
603 static const m_option_t key_type =
604 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
605 if (!mpctx->demuxer)
606 return M_PROPERTY_UNAVAILABLE;
608 switch(action) {
609 case M_PROPERTY_GET:
610 if(!arg) return M_PROPERTY_ERROR;
611 *(char***)arg = mpctx->demuxer->info;
612 return M_PROPERTY_OK;
613 case M_PROPERTY_KEY_ACTION:
614 if(!arg) return M_PROPERTY_ERROR;
615 ka = arg;
616 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
617 return M_PROPERTY_UNKNOWN;
618 switch(ka->action) {
619 case M_PROPERTY_GET:
620 if(!ka->arg) return M_PROPERTY_ERROR;
621 *(char**)ka->arg = meta;
622 return M_PROPERTY_OK;
623 case M_PROPERTY_GET_TYPE:
624 if(!ka->arg) return M_PROPERTY_ERROR;
625 *(m_option_t**)ka->arg = &key_type;
626 return M_PROPERTY_OK;
629 return M_PROPERTY_NOT_IMPLEMENTED;
632 static int mp_property_pause(m_option_t *prop, int action, void *arg,
633 void *ctx)
635 MPContext *mpctx = ctx;
637 switch (action) {
638 case M_PROPERTY_SET:
639 if (!arg)
640 return M_PROPERTY_ERROR;
641 if (mpctx->paused == (bool)*(int *) arg)
642 return M_PROPERTY_OK;
643 case M_PROPERTY_STEP_UP:
644 case M_PROPERTY_STEP_DOWN:
645 if (mpctx->paused) {
646 unpause_player(mpctx);
647 mpctx->osd_function = OSD_PLAY;
649 else {
650 pause_player(mpctx);
651 mpctx->osd_function = OSD_PAUSE;
653 return M_PROPERTY_OK;
654 default:
655 return m_property_flag(prop, action, arg, &mpctx->paused);
660 ///@}
662 /// \defgroup AudioProperties Audio properties
663 /// \ingroup Properties
664 ///@{
666 /// Volume (RW)
667 static int mp_property_volume(m_option_t *prop, int action, void *arg,
668 MPContext *mpctx)
671 if (!mpctx->sh_audio)
672 return M_PROPERTY_UNAVAILABLE;
674 switch (action) {
675 case M_PROPERTY_GET:
676 if (!arg)
677 return M_PROPERTY_ERROR;
678 mixer_getbothvolume(&mpctx->mixer, arg);
679 return M_PROPERTY_OK;
680 case M_PROPERTY_PRINT:{
681 float vol;
682 if (!arg)
683 return M_PROPERTY_ERROR;
684 mixer_getbothvolume(&mpctx->mixer, &vol);
685 return m_property_float_range(prop, action, arg, &vol);
687 case M_PROPERTY_STEP_UP:
688 case M_PROPERTY_STEP_DOWN:
689 case M_PROPERTY_SET:
690 break;
691 default:
692 return M_PROPERTY_NOT_IMPLEMENTED;
695 if (mpctx->edl_muted)
696 return M_PROPERTY_DISABLED;
697 mpctx->user_muted = 0;
699 switch (action) {
700 case M_PROPERTY_SET:
701 if (!arg)
702 return M_PROPERTY_ERROR;
703 M_PROPERTY_CLAMP(prop, *(float *) arg);
704 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
705 return M_PROPERTY_OK;
706 case M_PROPERTY_STEP_UP:
707 if (arg && *(float *) arg <= 0)
708 mixer_decvolume(&mpctx->mixer);
709 else
710 mixer_incvolume(&mpctx->mixer);
711 return M_PROPERTY_OK;
712 case M_PROPERTY_STEP_DOWN:
713 if (arg && *(float *) arg <= 0)
714 mixer_incvolume(&mpctx->mixer);
715 else
716 mixer_decvolume(&mpctx->mixer);
717 return M_PROPERTY_OK;
719 return M_PROPERTY_NOT_IMPLEMENTED;
722 /// Mute (RW)
723 static int mp_property_mute(m_option_t *prop, int action, void *arg,
724 MPContext *mpctx)
727 if (!mpctx->sh_audio)
728 return M_PROPERTY_UNAVAILABLE;
730 switch (action) {
731 case M_PROPERTY_SET:
732 if (mpctx->edl_muted)
733 return M_PROPERTY_DISABLED;
734 if (!arg)
735 return M_PROPERTY_ERROR;
736 if ((!!*(int *) arg) != mpctx->mixer.muted)
737 mixer_mute(&mpctx->mixer);
738 mpctx->user_muted = mpctx->mixer.muted;
739 return M_PROPERTY_OK;
740 case M_PROPERTY_STEP_UP:
741 case M_PROPERTY_STEP_DOWN:
742 if (mpctx->edl_muted)
743 return M_PROPERTY_DISABLED;
744 mixer_mute(&mpctx->mixer);
745 mpctx->user_muted = mpctx->mixer.muted;
746 return M_PROPERTY_OK;
747 case M_PROPERTY_PRINT:
748 if (!arg)
749 return M_PROPERTY_ERROR;
750 if (mpctx->edl_muted) {
751 *(char **) arg = strdup(mp_gtext("enabled (EDL)"));
752 return M_PROPERTY_OK;
754 default:
755 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
760 /// Audio delay (RW)
761 static int mp_property_audio_delay(m_option_t *prop, int action,
762 void *arg, MPContext *mpctx)
764 if (!(mpctx->sh_audio && mpctx->sh_video))
765 return M_PROPERTY_UNAVAILABLE;
766 switch (action) {
767 case M_PROPERTY_SET:
768 case M_PROPERTY_STEP_UP:
769 case M_PROPERTY_STEP_DOWN: {
770 int ret;
771 float delay = audio_delay;
772 ret = m_property_delay(prop, action, arg, &audio_delay);
773 if (ret != M_PROPERTY_OK)
774 return ret;
775 if (mpctx->sh_audio)
776 mpctx->delay -= audio_delay - delay;
778 return M_PROPERTY_OK;
779 default:
780 return m_property_delay(prop, action, arg, &audio_delay);
784 /// Audio codec tag (RO)
785 static int mp_property_audio_format(m_option_t *prop, int action,
786 void *arg, MPContext *mpctx)
788 if (!mpctx->sh_audio)
789 return M_PROPERTY_UNAVAILABLE;
790 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
793 /// Audio codec name (RO)
794 static int mp_property_audio_codec(m_option_t *prop, int action,
795 void *arg, MPContext *mpctx)
797 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
798 return M_PROPERTY_UNAVAILABLE;
799 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
802 /// Audio bitrate (RO)
803 static int mp_property_audio_bitrate(m_option_t *prop, int action,
804 void *arg, MPContext *mpctx)
806 if (!mpctx->sh_audio)
807 return M_PROPERTY_UNAVAILABLE;
808 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
811 /// Samplerate (RO)
812 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
813 MPContext *mpctx)
815 if (!mpctx->sh_audio)
816 return M_PROPERTY_UNAVAILABLE;
817 switch(action) {
818 case M_PROPERTY_PRINT:
819 if(!arg) return M_PROPERTY_ERROR;
820 *(char**)arg = malloc(16);
821 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
822 return M_PROPERTY_OK;
824 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
827 /// Number of channels (RO)
828 static int mp_property_channels(m_option_t *prop, int action, void *arg,
829 MPContext *mpctx)
831 if (!mpctx->sh_audio)
832 return M_PROPERTY_UNAVAILABLE;
833 switch (action) {
834 case M_PROPERTY_PRINT:
835 if (!arg)
836 return M_PROPERTY_ERROR;
837 switch (mpctx->sh_audio->channels) {
838 case 1:
839 *(char **) arg = strdup("mono");
840 break;
841 case 2:
842 *(char **) arg = strdup("stereo");
843 break;
844 default:
845 *(char **) arg = malloc(32);
846 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
848 return M_PROPERTY_OK;
850 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
853 /// Balance (RW)
854 static int mp_property_balance(m_option_t *prop, int action, void *arg,
855 MPContext *mpctx)
857 float bal;
859 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
860 return M_PROPERTY_UNAVAILABLE;
862 switch (action) {
863 case M_PROPERTY_GET:
864 if (!arg)
865 return M_PROPERTY_ERROR;
866 mixer_getbalance(&mpctx->mixer, arg);
867 return M_PROPERTY_OK;
868 case M_PROPERTY_PRINT: {
869 char** str = arg;
870 if (!arg)
871 return M_PROPERTY_ERROR;
872 mixer_getbalance(&mpctx->mixer, &bal);
873 if (bal == 0.f)
874 *str = strdup("center");
875 else if (bal == -1.f)
876 *str = strdup("left only");
877 else if (bal == 1.f)
878 *str = strdup("right only");
879 else {
880 unsigned right = (bal + 1.f) / 2.f * 100.f;
881 *str = malloc(sizeof("left xxx%, right xxx%"));
882 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
884 return M_PROPERTY_OK;
886 case M_PROPERTY_STEP_UP:
887 case M_PROPERTY_STEP_DOWN:
888 mixer_getbalance(&mpctx->mixer, &bal);
889 bal += (arg ? *(float*)arg : .1f) *
890 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
891 M_PROPERTY_CLAMP(prop, bal);
892 mixer_setbalance(&mpctx->mixer, bal);
893 return M_PROPERTY_OK;
894 case M_PROPERTY_SET:
895 if (!arg)
896 return M_PROPERTY_ERROR;
897 M_PROPERTY_CLAMP(prop, *(float*)arg);
898 mixer_setbalance(&mpctx->mixer, *(float*)arg);
899 return M_PROPERTY_OK;
901 return M_PROPERTY_NOT_IMPLEMENTED;
904 /// Selected audio id (RW)
905 static int mp_property_audio(m_option_t *prop, int action, void *arg,
906 MPContext *mpctx)
908 int current_id, tmp;
909 if (!mpctx->demuxer || !mpctx->demuxer->audio)
910 return M_PROPERTY_UNAVAILABLE;
911 current_id = mpctx->sh_audio ? mpctx->sh_audio->aid : -2;
913 switch (action) {
914 case M_PROPERTY_GET:
915 if (!arg)
916 return M_PROPERTY_ERROR;
917 *(int *) arg = current_id;
918 return M_PROPERTY_OK;
919 case M_PROPERTY_PRINT:
920 if (!arg)
921 return M_PROPERTY_ERROR;
923 if (current_id < 0)
924 *(char **) arg = strdup(mp_gtext("disabled"));
925 else {
926 char lang[40];
927 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
928 sh_audio_t* sh = mpctx->sh_audio;
929 if (sh && sh->lang)
930 av_strlcpy(lang, sh->lang, 40);
931 #ifdef CONFIG_DVDREAD
932 else if (mpctx->stream->type == STREAMTYPE_DVD) {
933 int code = dvd_lang_from_aid(mpctx->stream, current_id);
934 if (code) {
935 lang[0] = code >> 8;
936 lang[1] = code;
937 lang[2] = 0;
940 #endif
942 #ifdef CONFIG_DVDNAV
943 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
944 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
945 #endif
946 *(char **) arg = malloc(64);
947 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
949 return M_PROPERTY_OK;
951 case M_PROPERTY_STEP_UP:
952 case M_PROPERTY_SET:
953 if (action == M_PROPERTY_SET && arg)
954 tmp = *((int *) arg);
955 else
956 tmp = -1;
957 int new_id = demuxer_switch_audio(mpctx->demuxer, tmp);
958 if (new_id != current_id)
959 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
960 if (new_id != current_id && new_id >= 0) {
961 sh_audio_t *sh2;
962 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
963 sh2->ds = mpctx->demuxer->audio;
964 mpctx->sh_audio = sh2;
965 reinit_audio_chain(mpctx);
967 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
968 return M_PROPERTY_OK;
969 default:
970 return M_PROPERTY_NOT_IMPLEMENTED;
975 /// Selected video id (RW)
976 static int mp_property_video(m_option_t *prop, int action, void *arg,
977 MPContext *mpctx)
979 struct MPOpts *opts = &mpctx->opts;
980 int current_id, tmp;
981 if (!mpctx->demuxer || !mpctx->demuxer->video)
982 return M_PROPERTY_UNAVAILABLE;
983 current_id = mpctx->demuxer->video->id;
985 switch (action) {
986 case M_PROPERTY_GET:
987 if (!arg)
988 return M_PROPERTY_ERROR;
989 *(int *) arg = current_id;
990 return M_PROPERTY_OK;
991 case M_PROPERTY_PRINT:
992 if (!arg)
993 return M_PROPERTY_ERROR;
995 if (current_id < 0)
996 *(char **) arg = strdup(mp_gtext("disabled"));
997 else {
998 char lang[40];
999 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
1000 *(char **) arg = malloc(64);
1001 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
1003 return M_PROPERTY_OK;
1005 case M_PROPERTY_STEP_UP:
1006 case M_PROPERTY_SET:
1007 if (action == M_PROPERTY_SET && arg)
1008 tmp = *((int *) arg);
1009 else
1010 tmp = -1;
1011 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
1012 if (opts->video_id == -2
1013 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
1014 && current_id != -2))
1015 uninit_player(mpctx, INITIALIZED_VCODEC |
1016 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
1017 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
1018 sh_video_t *sh2;
1019 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
1020 if (sh2) {
1021 sh2->ds = mpctx->demuxer->video;
1022 mpctx->sh_video = sh2;
1023 reinit_video_chain(mpctx);
1026 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
1027 return M_PROPERTY_OK;
1029 default:
1030 return M_PROPERTY_NOT_IMPLEMENTED;
1034 static int mp_property_program(m_option_t *prop, int action, void *arg,
1035 MPContext *mpctx)
1037 demux_program_t prog;
1039 switch (action) {
1040 case M_PROPERTY_STEP_UP:
1041 case M_PROPERTY_SET:
1042 if (action == M_PROPERTY_SET && arg)
1043 prog.progid = *((int *) arg);
1044 else
1045 prog.progid = -1;
1046 if (demux_control
1047 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1048 &prog) == DEMUXER_CTRL_NOTIMPL)
1049 return M_PROPERTY_ERROR;
1051 if (prog.aid < 0 && prog.vid < 0) {
1052 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
1053 return M_PROPERTY_ERROR;
1055 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1056 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1057 return M_PROPERTY_OK;
1059 default:
1060 return M_PROPERTY_NOT_IMPLEMENTED;
1064 ///@}
1066 /// \defgroup VideoProperties Video properties
1067 /// \ingroup Properties
1068 ///@{
1070 /// Fullscreen state (RW)
1071 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1072 MPContext *mpctx)
1075 if (!mpctx->video_out)
1076 return M_PROPERTY_UNAVAILABLE;
1078 switch (action) {
1079 case M_PROPERTY_SET:
1080 if (!arg)
1081 return M_PROPERTY_ERROR;
1082 M_PROPERTY_CLAMP(prop, *(int *) arg);
1083 if (vo_fs == !!*(int *) arg)
1084 return M_PROPERTY_OK;
1085 case M_PROPERTY_STEP_UP:
1086 case M_PROPERTY_STEP_DOWN:
1087 if (mpctx->video_out->config_ok)
1088 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1089 mpctx->opts.fullscreen = vo_fs;
1090 return M_PROPERTY_OK;
1091 default:
1092 return m_property_flag(prop, action, arg, &vo_fs);
1096 static int mp_property_deinterlace(m_option_t *prop, int action,
1097 void *arg, MPContext *mpctx)
1099 int deinterlace;
1100 vf_instance_t *vf;
1101 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1102 return M_PROPERTY_UNAVAILABLE;
1103 vf = mpctx->sh_video->vfilter;
1104 switch (action) {
1105 case M_PROPERTY_GET:
1106 if (!arg)
1107 return M_PROPERTY_ERROR;
1108 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1109 return M_PROPERTY_OK;
1110 case M_PROPERTY_SET:
1111 if (!arg)
1112 return M_PROPERTY_ERROR;
1113 M_PROPERTY_CLAMP(prop, *(int *) arg);
1114 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1115 return M_PROPERTY_OK;
1116 case M_PROPERTY_STEP_UP:
1117 case M_PROPERTY_STEP_DOWN:
1118 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1119 deinterlace = !deinterlace;
1120 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1121 return M_PROPERTY_OK;
1123 int value = 0;
1124 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1125 return m_property_flag_ro(prop, action, arg, value);
1128 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1129 void *arg, MPContext *mpctx)
1131 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1132 return M_PROPERTY_UNAVAILABLE;
1134 struct vf_instance *vf = mpctx->sh_video->vfilter;
1135 int colorspace;
1136 switch (action) {
1137 case M_PROPERTY_GET:
1138 if (!arg)
1139 return M_PROPERTY_ERROR;
1140 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1141 return M_PROPERTY_UNAVAILABLE;
1142 return M_PROPERTY_OK;
1143 case M_PROPERTY_PRINT:
1144 if (!arg)
1145 return M_PROPERTY_ERROR;
1146 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1147 return M_PROPERTY_UNAVAILABLE;
1148 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1149 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1150 *(char **)arg = strdup("Unknown");
1151 else
1152 *(char**)arg = strdup(names[colorspace]);
1153 return M_PROPERTY_OK;
1154 case M_PROPERTY_SET:
1155 if (!arg)
1156 return M_PROPERTY_ERROR;
1157 M_PROPERTY_CLAMP(prop, *(int *) arg);
1158 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1159 return M_PROPERTY_OK;
1160 case M_PROPERTY_STEP_UP:;
1161 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1162 return M_PROPERTY_UNAVAILABLE;
1163 colorspace += 1;
1164 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1165 return M_PROPERTY_OK;
1167 return M_PROPERTY_NOT_IMPLEMENTED;
1170 /// Panscan (RW)
1171 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1172 MPContext *mpctx)
1175 if (!mpctx->video_out
1176 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1177 return M_PROPERTY_UNAVAILABLE;
1179 switch (action) {
1180 case M_PROPERTY_SET:
1181 if (!arg)
1182 return M_PROPERTY_ERROR;
1183 M_PROPERTY_CLAMP(prop, *(float *) arg);
1184 vo_panscan = *(float *) arg;
1185 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1186 return M_PROPERTY_OK;
1187 case M_PROPERTY_STEP_UP:
1188 case M_PROPERTY_STEP_DOWN:
1189 vo_panscan += (arg ? *(float *) arg : 0.1) *
1190 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1191 if (vo_panscan > 1)
1192 vo_panscan = 1;
1193 else if (vo_panscan < 0)
1194 vo_panscan = 0;
1195 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1196 return M_PROPERTY_OK;
1197 default:
1198 return m_property_float_range(prop, action, arg, &vo_panscan);
1202 /// Helper to set vo flags.
1203 /** \ingroup PropertyImplHelper
1205 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1206 int vo_ctrl, int *vo_var, MPContext *mpctx)
1209 if (!mpctx->video_out)
1210 return M_PROPERTY_UNAVAILABLE;
1212 switch (action) {
1213 case M_PROPERTY_SET:
1214 if (!arg)
1215 return M_PROPERTY_ERROR;
1216 M_PROPERTY_CLAMP(prop, *(int *) arg);
1217 if (*vo_var == !!*(int *) arg)
1218 return M_PROPERTY_OK;
1219 case M_PROPERTY_STEP_UP:
1220 case M_PROPERTY_STEP_DOWN:
1221 if (mpctx->video_out->config_ok)
1222 vo_control(mpctx->video_out, vo_ctrl, 0);
1223 return M_PROPERTY_OK;
1224 default:
1225 return m_property_flag(prop, action, arg, vo_var);
1229 /// Window always on top (RW)
1230 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1231 MPContext *mpctx)
1233 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1234 &mpctx->opts.vo_ontop, mpctx);
1237 /// Display in the root window (RW)
1238 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1239 MPContext *mpctx)
1241 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1242 &vo_rootwin, mpctx);
1245 /// Show window borders (RW)
1246 static int mp_property_border(m_option_t *prop, int action, void *arg,
1247 MPContext *mpctx)
1249 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1250 &vo_border, mpctx);
1253 /// Framedropping state (RW)
1254 static int mp_property_framedropping(m_option_t *prop, int action,
1255 void *arg, MPContext *mpctx)
1258 if (!mpctx->sh_video)
1259 return M_PROPERTY_UNAVAILABLE;
1261 switch (action) {
1262 case M_PROPERTY_PRINT:
1263 if (!arg)
1264 return M_PROPERTY_ERROR;
1265 *(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
1266 (frame_dropping == 2 ? mp_gtext("hard") :
1267 mp_gtext("disabled")));
1268 return M_PROPERTY_OK;
1269 default:
1270 return m_property_choice(prop, action, arg, &frame_dropping);
1274 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1275 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1276 MPContext *mpctx)
1278 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1279 int r, val;
1281 if (!mpctx->sh_video)
1282 return M_PROPERTY_UNAVAILABLE;
1284 if (gamma[0] == 1000) {
1285 gamma[0] = 0;
1286 get_video_colors(mpctx->sh_video, prop->name, gamma);
1289 switch (action) {
1290 case M_PROPERTY_SET:
1291 if (!arg)
1292 return M_PROPERTY_ERROR;
1293 M_PROPERTY_CLAMP(prop, *(int *) arg);
1294 *gamma = *(int *) arg;
1295 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1296 if (r <= 0)
1297 break;
1298 return r;
1299 case M_PROPERTY_GET:
1300 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1301 if (!arg)
1302 return M_PROPERTY_ERROR;
1303 *(int *)arg = val;
1304 return M_PROPERTY_OK;
1306 break;
1307 case M_PROPERTY_STEP_UP:
1308 case M_PROPERTY_STEP_DOWN:
1309 *gamma += (arg ? *(int *) arg : 1) *
1310 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1311 M_PROPERTY_CLAMP(prop, *gamma);
1312 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1313 if (r <= 0)
1314 break;
1315 return r;
1316 default:
1317 return M_PROPERTY_NOT_IMPLEMENTED;
1320 #ifdef CONFIG_TV
1321 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1322 int l = strlen(prop->name);
1323 char tv_prop[3 + l + 1];
1324 sprintf(tv_prop, "tv_%s", prop->name);
1325 return mp_property_do(tv_prop, action, arg, mpctx);
1327 #endif
1329 return M_PROPERTY_UNAVAILABLE;
1332 /// VSync (RW)
1333 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1334 MPContext *mpctx)
1336 return m_property_flag(prop, action, arg, &vo_vsync);
1339 /// Video codec tag (RO)
1340 static int mp_property_video_format(m_option_t *prop, int action,
1341 void *arg, MPContext *mpctx)
1343 char* meta;
1344 if (!mpctx->sh_video)
1345 return M_PROPERTY_UNAVAILABLE;
1346 switch(action) {
1347 case M_PROPERTY_PRINT:
1348 if (!arg)
1349 return M_PROPERTY_ERROR;
1350 switch(mpctx->sh_video->format) {
1351 case 0x10000001:
1352 meta = strdup ("mpeg1"); break;
1353 case 0x10000002:
1354 meta = strdup ("mpeg2"); break;
1355 case 0x10000004:
1356 meta = strdup ("mpeg4"); break;
1357 case 0x10000005:
1358 meta = strdup ("h264"); break;
1359 default:
1360 if(mpctx->sh_video->format >= 0x20202020) {
1361 meta = malloc(5);
1362 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1363 } else {
1364 meta = malloc(20);
1365 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1368 *(char**)arg = meta;
1369 return M_PROPERTY_OK;
1371 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1374 /// Video codec name (RO)
1375 static int mp_property_video_codec(m_option_t *prop, int action,
1376 void *arg, MPContext *mpctx)
1378 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1379 return M_PROPERTY_UNAVAILABLE;
1380 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1384 /// Video bitrate (RO)
1385 static int mp_property_video_bitrate(m_option_t *prop, int action,
1386 void *arg, MPContext *mpctx)
1388 if (!mpctx->sh_video)
1389 return M_PROPERTY_UNAVAILABLE;
1390 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1393 /// Video display width (RO)
1394 static int mp_property_width(m_option_t *prop, int action, void *arg,
1395 MPContext *mpctx)
1397 if (!mpctx->sh_video)
1398 return M_PROPERTY_UNAVAILABLE;
1399 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1402 /// Video display height (RO)
1403 static int mp_property_height(m_option_t *prop, int action, void *arg,
1404 MPContext *mpctx)
1406 if (!mpctx->sh_video)
1407 return M_PROPERTY_UNAVAILABLE;
1408 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1411 /// Video fps (RO)
1412 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1413 MPContext *mpctx)
1415 if (!mpctx->sh_video)
1416 return M_PROPERTY_UNAVAILABLE;
1417 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1420 /// Video aspect (RO)
1421 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1422 MPContext *mpctx)
1424 if (!mpctx->sh_video)
1425 return M_PROPERTY_UNAVAILABLE;
1426 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1429 ///@}
1431 /// \defgroup SubProprties Subtitles properties
1432 /// \ingroup Properties
1433 ///@{
1435 /// Text subtitle position (RW)
1436 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1437 MPContext *mpctx)
1439 switch (action) {
1440 case M_PROPERTY_SET:
1441 if (!arg)
1442 return M_PROPERTY_ERROR;
1443 case M_PROPERTY_STEP_UP:
1444 case M_PROPERTY_STEP_DOWN:
1445 vo_osd_changed(OSDTYPE_SUBTITLE);
1446 default:
1447 return m_property_int_range(prop, action, arg, &sub_pos);
1451 /// Selected subtitles (RW)
1452 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1453 MPContext *mpctx)
1455 struct MPOpts *opts = &mpctx->opts;
1456 demux_stream_t *const d_sub = mpctx->d_sub;
1457 int source = -1, reset_spu = 0;
1458 int source_pos = -1;
1459 char *sub_name;
1461 update_global_sub_size(mpctx);
1462 const int global_sub_size = mpctx->global_sub_size;
1464 if (global_sub_size <= 0)
1465 return M_PROPERTY_UNAVAILABLE;
1467 switch (action) {
1468 case M_PROPERTY_GET:
1469 if (!arg)
1470 return M_PROPERTY_ERROR;
1471 *(int *) arg = mpctx->global_sub_pos;
1472 return M_PROPERTY_OK;
1473 case M_PROPERTY_PRINT:
1474 if (!arg)
1475 return M_PROPERTY_ERROR;
1476 *(char **) arg = malloc(64);
1477 (*(char **) arg)[63] = 0;
1478 sub_name = 0;
1479 if (subdata)
1480 sub_name = subdata->filename;
1481 #ifdef CONFIG_ASS
1482 if (ass_track && ass_track->name)
1483 sub_name = ass_track->name;
1484 #endif
1485 if (sub_name) {
1486 char *tmp, *tmp2;
1487 tmp = sub_name;
1488 if ((tmp2 = strrchr(tmp, '/')))
1489 tmp = tmp2 + 1;
1491 snprintf(*(char **) arg, 63, "(%d) %s%s",
1492 mpctx->set_of_sub_pos + 1,
1493 strlen(tmp) < 20 ? "" : "...",
1494 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1495 return M_PROPERTY_OK;
1497 #ifdef CONFIG_DVDNAV
1498 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1499 if (vo_spudec && opts->sub_id >= 0) {
1500 unsigned char lang[3];
1501 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1502 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1503 return M_PROPERTY_OK;
1507 #endif
1509 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1510 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1511 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1512 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1513 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1514 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1515 if (!lang) lang = mp_gtext("unknown");
1516 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1517 return M_PROPERTY_OK;
1520 if (vo_vobsub && vobsub_id >= 0) {
1521 const char *language = mp_gtext("unknown");
1522 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1523 snprintf(*(char **) arg, 63, "(%d) %s",
1524 vobsub_id, language ? language : mp_gtext("unknown"));
1525 return M_PROPERTY_OK;
1527 #ifdef CONFIG_DVDREAD
1528 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1529 && opts->sub_id >= 0) {
1530 char lang[3];
1531 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1532 lang[0] = code >> 8;
1533 lang[1] = code;
1534 lang[2] = 0;
1535 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1536 return M_PROPERTY_OK;
1538 #endif
1539 if (opts->sub_id >= 0) {
1540 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
1541 mp_gtext("unknown"));
1542 return M_PROPERTY_OK;
1544 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1545 return M_PROPERTY_OK;
1547 case M_PROPERTY_SET:
1548 if (!arg)
1549 return M_PROPERTY_ERROR;
1550 if (*(int *) arg < -1)
1551 *(int *) arg = -1;
1552 else if (*(int *) arg >= global_sub_size)
1553 *(int *) arg = global_sub_size - 1;
1554 mpctx->global_sub_pos = *(int *) arg;
1555 break;
1556 case M_PROPERTY_STEP_UP:
1557 mpctx->global_sub_pos += 2;
1558 mpctx->global_sub_pos =
1559 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1560 break;
1561 case M_PROPERTY_STEP_DOWN:
1562 mpctx->global_sub_pos += global_sub_size + 1;
1563 mpctx->global_sub_pos =
1564 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1565 break;
1566 default:
1567 return M_PROPERTY_NOT_IMPLEMENTED;
1570 if (mpctx->global_sub_pos >= 0) {
1571 source = sub_source(mpctx);
1572 source_pos = sub_source_pos(mpctx);
1575 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1576 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1577 global_sub_size,
1578 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1579 mpctx->sub_counts[SUB_SOURCE_SUBS],
1580 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1581 mpctx->global_sub_pos, source);
1583 mpctx->set_of_sub_pos = -1;
1584 subdata = NULL;
1586 vobsub_id = -1;
1587 opts->sub_id = -1;
1588 if (d_sub) {
1589 if (d_sub->id > -2)
1590 reset_spu = 1;
1591 d_sub->id = -2;
1593 #ifdef CONFIG_ASS
1594 ass_track = 0;
1595 #endif
1597 if (source == SUB_SOURCE_VOBSUB) {
1598 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1599 } else if (source == SUB_SOURCE_SUBS) {
1600 mpctx->set_of_sub_pos = source_pos;
1601 #ifdef CONFIG_ASS
1602 if (opts->ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1603 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1604 else
1605 #endif
1607 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1608 vo_osd_changed(OSDTYPE_SUBTITLE);
1610 } else if (source == SUB_SOURCE_DEMUX) {
1611 opts->sub_id = source_pos;
1612 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1613 int i = 0;
1614 // default: assume 1:1 mapping of sid and stream id
1615 d_sub->id = opts->sub_id;
1616 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1617 ds_free_packs(d_sub);
1618 for (i = 0; i < MAX_S_STREAMS; i++) {
1619 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1620 if (sh && sh->sid == opts->sub_id) {
1621 d_sub->id = i;
1622 d_sub->sh = sh;
1623 break;
1626 if (d_sub->sh && d_sub->id >= 0) {
1627 sh_sub_t *sh = d_sub->sh;
1628 if (sh->type == 'v')
1629 init_vo_spudec(mpctx);
1630 #ifdef CONFIG_ASS
1631 else if (opts->ass_enabled)
1632 ass_track = sh->ass_track;
1633 #endif
1634 } else {
1635 d_sub->id = -2;
1636 d_sub->sh = NULL;
1640 #ifdef CONFIG_DVDREAD
1641 if (vo_spudec
1642 && (mpctx->stream->type == STREAMTYPE_DVD
1643 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1644 && opts->sub_id < 0 && reset_spu) {
1645 d_sub->id = -2;
1646 d_sub->sh = NULL;
1648 #endif
1650 update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, 0, 0, d_sub, 1);
1652 return M_PROPERTY_OK;
1655 /// Selected sub source (RW)
1656 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1657 MPContext *mpctx)
1659 int source;
1660 update_global_sub_size(mpctx);
1661 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1662 return M_PROPERTY_UNAVAILABLE;
1664 switch (action) {
1665 case M_PROPERTY_GET:
1666 if (!arg)
1667 return M_PROPERTY_ERROR;
1668 *(int *) arg = sub_source(mpctx);
1669 return M_PROPERTY_OK;
1670 case M_PROPERTY_PRINT:
1671 if (!arg)
1672 return M_PROPERTY_ERROR;
1673 *(char **) arg = malloc(64);
1674 (*(char **) arg)[63] = 0;
1675 switch (sub_source(mpctx))
1677 case SUB_SOURCE_SUBS:
1678 snprintf(*(char **) arg, 63, mp_gtext("file"));
1679 break;
1680 case SUB_SOURCE_VOBSUB:
1681 snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
1682 break;
1683 case SUB_SOURCE_DEMUX:
1684 snprintf(*(char **) arg, 63, mp_gtext("embedded"));
1685 break;
1686 default:
1687 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1689 return M_PROPERTY_OK;
1690 case M_PROPERTY_SET:
1691 if (!arg)
1692 return M_PROPERTY_ERROR;
1693 M_PROPERTY_CLAMP(prop, *(int*)arg);
1694 if (*(int *) arg < 0)
1695 mpctx->global_sub_pos = -1;
1696 else if (*(int *) arg != sub_source(mpctx)) {
1697 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1698 if (new_pos == -1)
1699 return M_PROPERTY_UNAVAILABLE;
1700 mpctx->global_sub_pos = new_pos;
1702 break;
1703 case M_PROPERTY_STEP_UP:
1704 case M_PROPERTY_STEP_DOWN: {
1705 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1706 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1707 int step = (step_all > 0) ? 1 : -1;
1708 int cur_source = sub_source(mpctx);
1709 source = cur_source;
1710 while (step_all) {
1711 source += step;
1712 if (source >= SUB_SOURCES)
1713 source = -1;
1714 else if (source < -1)
1715 source = SUB_SOURCES - 1;
1716 if (source == cur_source || source == -1 ||
1717 mpctx->sub_counts[source])
1718 step_all -= step;
1720 if (source == cur_source)
1721 return M_PROPERTY_OK;
1722 if (source == -1)
1723 mpctx->global_sub_pos = -1;
1724 else
1725 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1726 break;
1728 default:
1729 return M_PROPERTY_NOT_IMPLEMENTED;
1731 --mpctx->global_sub_pos;
1732 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1735 /// Selected subtitles from specific source (RW)
1736 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1737 MPContext *mpctx)
1739 int source, is_cur_source, offset, new_pos;
1740 update_global_sub_size(mpctx);
1741 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1742 return M_PROPERTY_UNAVAILABLE;
1744 if (!strcmp(prop->name, "sub_file"))
1745 source = SUB_SOURCE_SUBS;
1746 else if (!strcmp(prop->name, "sub_vob"))
1747 source = SUB_SOURCE_VOBSUB;
1748 else if (!strcmp(prop->name, "sub_demux"))
1749 source = SUB_SOURCE_DEMUX;
1750 else
1751 return M_PROPERTY_ERROR;
1753 offset = sub_pos_by_source(mpctx, source);
1754 if (offset < 0)
1755 return M_PROPERTY_UNAVAILABLE;
1757 is_cur_source = sub_source(mpctx) == source;
1758 new_pos = mpctx->global_sub_pos;
1759 switch (action) {
1760 case M_PROPERTY_GET:
1761 if (!arg)
1762 return M_PROPERTY_ERROR;
1763 if (is_cur_source) {
1764 *(int *) arg = sub_source_pos(mpctx);
1765 if (source == SUB_SOURCE_VOBSUB)
1766 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1768 else
1769 *(int *) arg = -1;
1770 return M_PROPERTY_OK;
1771 case M_PROPERTY_PRINT:
1772 if (!arg)
1773 return M_PROPERTY_ERROR;
1774 if (is_cur_source)
1775 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1776 *(char **) arg = malloc(64);
1777 (*(char **) arg)[63] = 0;
1778 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1779 return M_PROPERTY_OK;
1780 case M_PROPERTY_SET:
1781 if (!arg)
1782 return M_PROPERTY_ERROR;
1783 if (*(int *) arg >= 0) {
1784 int index = *(int *)arg;
1785 if (source == SUB_SOURCE_VOBSUB)
1786 index = vobsub_get_index_by_id(vo_vobsub, index);
1787 new_pos = offset + index;
1788 if (index < 0 || index > mpctx->sub_counts[source]) {
1789 new_pos = -1;
1790 *(int *) arg = -1;
1793 else
1794 new_pos = -1;
1795 break;
1796 case M_PROPERTY_STEP_UP:
1797 case M_PROPERTY_STEP_DOWN: {
1798 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1799 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1800 int step = (step_all > 0) ? 1 : -1;
1801 int max_sub_pos_for_source = -1;
1802 if (!is_cur_source)
1803 new_pos = -1;
1804 while (step_all) {
1805 if (new_pos == -1) {
1806 if (step > 0)
1807 new_pos = offset;
1808 else if (max_sub_pos_for_source == -1) {
1809 // Find max pos for specific source
1810 new_pos = mpctx->global_sub_size - 1;
1811 while (new_pos >= 0
1812 && sub_source(mpctx) != source)
1813 new_pos--;
1815 else
1816 new_pos = max_sub_pos_for_source;
1818 else {
1819 new_pos += step;
1820 if (new_pos < offset ||
1821 new_pos >= mpctx->global_sub_size ||
1822 sub_source(mpctx) != source)
1823 new_pos = -1;
1825 step_all -= step;
1827 break;
1829 default:
1830 return M_PROPERTY_NOT_IMPLEMENTED;
1832 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1835 /// Subtitle delay (RW)
1836 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1837 MPContext *mpctx)
1839 if (!mpctx->sh_video)
1840 return M_PROPERTY_UNAVAILABLE;
1841 return m_property_delay(prop, action, arg, &sub_delay);
1844 /// Alignment of text subtitles (RW)
1845 static int mp_property_sub_alignment(m_option_t *prop, int action,
1846 void *arg, MPContext *mpctx)
1848 char *name[] = { _("top"), _("center"), _("bottom") };
1850 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1851 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1852 return M_PROPERTY_UNAVAILABLE;
1854 switch (action) {
1855 case M_PROPERTY_PRINT:
1856 if (!arg)
1857 return M_PROPERTY_ERROR;
1858 M_PROPERTY_CLAMP(prop, sub_alignment);
1859 *(char **) arg = strdup(mp_gtext(name[sub_alignment]));
1860 return M_PROPERTY_OK;
1861 case M_PROPERTY_SET:
1862 if (!arg)
1863 return M_PROPERTY_ERROR;
1864 case M_PROPERTY_STEP_UP:
1865 case M_PROPERTY_STEP_DOWN:
1866 vo_osd_changed(OSDTYPE_SUBTITLE);
1867 default:
1868 return m_property_choice(prop, action, arg, &sub_alignment);
1872 /// Subtitle visibility (RW)
1873 static int mp_property_sub_visibility(m_option_t *prop, int action,
1874 void *arg, MPContext *mpctx)
1876 if (!mpctx->sh_video)
1877 return M_PROPERTY_UNAVAILABLE;
1879 switch (action) {
1880 case M_PROPERTY_SET:
1881 if (!arg)
1882 return M_PROPERTY_ERROR;
1883 case M_PROPERTY_STEP_UP:
1884 case M_PROPERTY_STEP_DOWN:
1885 vo_osd_changed(OSDTYPE_SUBTITLE);
1886 if (vo_spudec)
1887 vo_osd_changed(OSDTYPE_SPU);
1888 default:
1889 return m_property_flag(prop, action, arg, &sub_visibility);
1893 #ifdef CONFIG_ASS
1894 /// Use margins for libass subtitles (RW)
1895 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1896 void *arg, MPContext *mpctx)
1898 if (!mpctx->sh_video)
1899 return M_PROPERTY_UNAVAILABLE;
1901 switch (action) {
1902 case M_PROPERTY_SET:
1903 if (!arg)
1904 return M_PROPERTY_ERROR;
1905 case M_PROPERTY_STEP_UP:
1906 case M_PROPERTY_STEP_DOWN:
1907 ass_force_reload = 1;
1908 default:
1909 return m_property_flag(prop, action, arg, &ass_use_margins);
1912 #endif
1914 /// Show only forced subtitles (RW)
1915 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1916 void *arg, MPContext *mpctx)
1918 if (!vo_spudec)
1919 return M_PROPERTY_UNAVAILABLE;
1921 switch (action) {
1922 case M_PROPERTY_SET:
1923 if (!arg)
1924 return M_PROPERTY_ERROR;
1925 case M_PROPERTY_STEP_UP:
1926 case M_PROPERTY_STEP_DOWN:
1927 m_property_flag(prop, action, arg, &forced_subs_only);
1928 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1929 return M_PROPERTY_OK;
1930 default:
1931 return m_property_flag(prop, action, arg, &forced_subs_only);
1936 #ifdef CONFIG_FREETYPE
1937 /// Subtitle scale (RW)
1938 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1939 MPContext *mpctx)
1941 struct MPOpts *opts = &mpctx->opts;
1943 switch (action) {
1944 case M_PROPERTY_SET:
1945 if (!arg)
1946 return M_PROPERTY_ERROR;
1947 M_PROPERTY_CLAMP(prop, *(float *) arg);
1948 #ifdef CONFIG_ASS
1949 if (opts->ass_enabled) {
1950 ass_font_scale = *(float *) arg;
1951 ass_force_reload = 1;
1953 #endif
1954 text_font_scale_factor = *(float *) arg;
1955 force_load_font = 1;
1956 return M_PROPERTY_OK;
1957 case M_PROPERTY_STEP_UP:
1958 case M_PROPERTY_STEP_DOWN:
1959 #ifdef CONFIG_ASS
1960 if (opts->ass_enabled) {
1961 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1962 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1963 M_PROPERTY_CLAMP(prop, ass_font_scale);
1964 ass_force_reload = 1;
1966 #endif
1967 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1968 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1969 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1970 force_load_font = 1;
1971 return M_PROPERTY_OK;
1972 default:
1973 #ifdef CONFIG_ASS
1974 if (opts->ass_enabled)
1975 return m_property_float_ro(prop, action, arg, ass_font_scale);
1976 else
1977 #endif
1978 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1981 #endif
1983 ///@}
1985 /// \defgroup TVProperties TV properties
1986 /// \ingroup Properties
1987 ///@{
1989 #ifdef CONFIG_TV
1991 /// TV color settings (RW)
1992 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1993 MPContext *mpctx)
1995 int r, val;
1996 tvi_handle_t *tvh = mpctx->demuxer->priv;
1997 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1998 return M_PROPERTY_UNAVAILABLE;
2000 switch (action) {
2001 case M_PROPERTY_SET:
2002 if (!arg)
2003 return M_PROPERTY_ERROR;
2004 M_PROPERTY_CLAMP(prop, *(int *) arg);
2005 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
2006 case M_PROPERTY_GET:
2007 return tv_get_color_options(tvh, (int) prop->priv, arg);
2008 case M_PROPERTY_STEP_UP:
2009 case M_PROPERTY_STEP_DOWN:
2010 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
2011 if (!r)
2012 return M_PROPERTY_ERROR;
2013 val += (arg ? *(int *) arg : 1) *
2014 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2015 M_PROPERTY_CLAMP(prop, val);
2016 return tv_set_color_options(tvh, (int) prop->priv, val);
2018 return M_PROPERTY_ERROR;
2020 return M_PROPERTY_NOT_IMPLEMENTED;
2023 #endif
2025 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2026 MPContext *mpctx)
2028 int val,result;
2029 int base_ioctl=(int)prop->priv;
2031 for teletext's GET,SET,STEP ioctls this is not 0
2032 SET is GET+1
2033 STEP is GET+2
2035 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2036 return M_PROPERTY_UNAVAILABLE;
2037 if(!base_ioctl)
2038 return M_PROPERTY_ERROR;
2040 switch (action) {
2041 case M_PROPERTY_GET:
2042 if (!arg)
2043 return M_PROPERTY_ERROR;
2044 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2045 break;
2046 case M_PROPERTY_SET:
2047 if (!arg)
2048 return M_PROPERTY_ERROR;
2049 M_PROPERTY_CLAMP(prop, *(int *) arg);
2050 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
2051 break;
2052 case M_PROPERTY_STEP_UP:
2053 case M_PROPERTY_STEP_DOWN:
2054 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2055 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2056 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
2057 break;
2058 default:
2059 return M_PROPERTY_NOT_IMPLEMENTED;
2062 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2065 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2066 MPContext *mpctx)
2068 int result;
2069 int val;
2071 //with tvh==NULL will fail too
2072 result=mp_property_teletext_common(prop,action,arg,mpctx);
2073 if(result!=M_PROPERTY_OK)
2074 return result;
2076 if(teletext_control(mpctx->demuxer->teletext,
2077 (int)prop->priv, &val)==VBI_CONTROL_TRUE && val)
2078 mp_input_set_section(mpctx->input, "teletext");
2079 else
2080 mp_input_set_section(mpctx->input, "tv");
2081 return M_PROPERTY_OK;
2084 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2085 MPContext *mpctx)
2087 int result;
2088 int val;
2089 if (!mpctx->demuxer->teletext)
2090 return M_PROPERTY_UNAVAILABLE;
2091 switch(action){
2092 case M_PROPERTY_STEP_UP:
2093 case M_PROPERTY_STEP_DOWN:
2094 //This should be handled separately
2095 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2096 result=teletext_control(mpctx->demuxer->teletext,
2097 TV_VBI_CONTROL_STEP_PAGE, &val);
2098 break;
2099 default:
2100 result=mp_property_teletext_common(prop,action,arg,mpctx);
2102 return result;
2105 ///@}
2107 /// All properties available in MPlayer.
2108 /** \ingroup Properties
2110 static const m_option_t mp_properties[] = {
2111 // General
2112 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2113 M_OPT_RANGE, 0, 3, NULL },
2114 { "loop", mp_property_loop, CONF_TYPE_INT,
2115 M_OPT_MIN, -1, 0, NULL },
2116 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2117 M_OPT_RANGE, 0.01, 100.0, NULL },
2118 { "filename", mp_property_filename, CONF_TYPE_STRING,
2119 0, 0, 0, NULL },
2120 { "path", mp_property_path, CONF_TYPE_STRING,
2121 0, 0, 0, NULL },
2122 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2123 0, 0, 0, NULL },
2124 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2125 M_OPT_MIN, 0, 0, NULL },
2126 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2127 M_OPT_MIN, 0, 0, NULL },
2128 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2129 M_OPT_MIN, 0, 0, NULL },
2130 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2131 M_OPT_MIN, 0, 0, NULL },
2132 { "length", mp_property_length, CONF_TYPE_TIME,
2133 M_OPT_MIN, 0, 0, NULL },
2134 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2135 M_OPT_RANGE, 0, 100, NULL },
2136 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2137 M_OPT_MIN, 0, 0, NULL },
2138 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2139 M_OPT_MIN, 0, 0, NULL },
2140 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2141 0, 0, 0, NULL },
2142 { "angle", mp_property_angle, CONF_TYPE_INT,
2143 CONF_RANGE, -2, 10, NULL },
2144 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2145 0, 0, 0, NULL },
2146 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2147 M_OPT_RANGE, 0, 1, NULL },
2149 // Audio
2150 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2151 M_OPT_RANGE, 0, 100, NULL },
2152 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2153 M_OPT_RANGE, 0, 1, NULL },
2154 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2155 M_OPT_RANGE, -100, 100, NULL },
2156 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2157 0, 0, 0, NULL },
2158 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2159 0, 0, 0, NULL },
2160 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2161 0, 0, 0, NULL },
2162 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2163 0, 0, 0, NULL },
2164 { "channels", mp_property_channels, CONF_TYPE_INT,
2165 0, 0, 0, NULL },
2166 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2167 CONF_RANGE, -2, 65535, NULL },
2168 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2169 M_OPT_RANGE, -1, 1, NULL },
2171 // Video
2172 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2173 M_OPT_RANGE, 0, 1, NULL },
2174 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2175 M_OPT_RANGE, 0, 1, NULL },
2176 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2177 M_OPT_RANGE, 0, 2, NULL },
2178 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2179 M_OPT_RANGE, 0, 1, NULL },
2180 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2181 M_OPT_RANGE, 0, 1, NULL },
2182 { "border", mp_property_border, CONF_TYPE_FLAG,
2183 M_OPT_RANGE, 0, 1, NULL },
2184 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2185 M_OPT_RANGE, 0, 2, NULL },
2186 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2187 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2188 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2189 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2190 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2191 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2192 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2193 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2194 { "hue", mp_property_gamma, CONF_TYPE_INT,
2195 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2196 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2197 M_OPT_RANGE, 0, 1, NULL },
2198 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2199 M_OPT_RANGE, 0, 1, NULL },
2200 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2201 0, 0, 0, NULL },
2202 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2203 0, 0, 0, NULL },
2204 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2205 0, 0, 0, NULL },
2206 { "width", mp_property_width, CONF_TYPE_INT,
2207 0, 0, 0, NULL },
2208 { "height", mp_property_height, CONF_TYPE_INT,
2209 0, 0, 0, NULL },
2210 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2211 0, 0, 0, NULL },
2212 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2213 0, 0, 0, NULL },
2214 { "switch_video", mp_property_video, CONF_TYPE_INT,
2215 CONF_RANGE, -2, 65535, NULL },
2216 { "switch_program", mp_property_program, CONF_TYPE_INT,
2217 CONF_RANGE, -1, 65535, NULL },
2219 // Subs
2220 { "sub", mp_property_sub, CONF_TYPE_INT,
2221 M_OPT_MIN, -1, 0, NULL },
2222 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2223 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2224 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2225 M_OPT_MIN, -1, 0, NULL },
2226 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2227 M_OPT_MIN, -1, 0, NULL },
2228 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2229 M_OPT_MIN, -1, 0, NULL },
2230 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2231 0, 0, 0, NULL },
2232 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2233 M_OPT_RANGE, 0, 100, NULL },
2234 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2235 M_OPT_RANGE, 0, 2, NULL },
2236 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2237 M_OPT_RANGE, 0, 1, NULL },
2238 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2239 M_OPT_RANGE, 0, 1, NULL },
2240 #ifdef CONFIG_FREETYPE
2241 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2242 M_OPT_RANGE, 0, 100, NULL },
2243 #endif
2244 #ifdef CONFIG_ASS
2245 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2246 M_OPT_RANGE, 0, 1, NULL },
2247 #endif
2249 #ifdef CONFIG_TV
2250 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2251 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2252 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2253 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2254 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2255 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2256 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2257 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2258 #endif
2259 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2260 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2261 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2262 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2263 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2264 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2265 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2266 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2267 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2268 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2269 { NULL, NULL, NULL, 0, 0, 0, NULL }
2273 int mp_property_do(const char *name, int action, void *val, void *ctx)
2275 return m_property_do(mp_properties, name, action, val, ctx);
2278 char* mp_property_print(const char *name, void* ctx)
2280 char* ret = NULL;
2281 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2282 return NULL;
2283 return ret;
2286 char *property_expand_string(MPContext *mpctx, char *str)
2288 return m_properties_expand_string(mp_properties, str, mpctx);
2291 void property_print_help(void)
2293 m_properties_print_help_list(mp_properties);
2297 /* List of default ways to show a property on OSD.
2299 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2300 * a bar showing the current position between min/max values of the
2301 * property. In this case osd_msg is only used for terminal output
2302 * if there is no video; it'll be a label shown together with percentage.
2304 * Otherwise setting osd_msg will show the string on OSD, formatted with
2305 * the text value of the property as argument.
2307 static struct property_osd_display {
2308 /// property name
2309 const char *name;
2310 /// progressbar type
2311 int osd_progbar; // -1 is special value for seek indicators
2312 /// osd msg id if it must be shared
2313 int osd_id;
2314 /// osd msg template
2315 const char *osd_msg;
2316 } property_osd_display[] = {
2317 // general
2318 { "loop", 0, -1, _("Loop: %s") },
2319 { "chapter", -1, -1, NULL },
2320 // audio
2321 { "volume", OSD_VOLUME, -1, _("Volume") },
2322 { "mute", 0, -1, _("Mute: %s") },
2323 { "audio_delay", 0, -1, _("A-V delay: %s") },
2324 { "switch_audio", 0, -1, _("Audio: %s") },
2325 { "balance", OSD_BALANCE, -1, _("Balance") },
2326 // video
2327 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2328 { "ontop", 0, -1, _("Stay on top: %s") },
2329 { "rootwin", 0, -1, _("Rootwin: %s") },
2330 { "border", 0, -1, _("Border: %s") },
2331 { "framedropping", 0, -1, _("Framedropping: %s") },
2332 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2333 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2334 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2335 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2336 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2337 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2338 { "hue", OSD_HUE, -1, _("Hue") },
2339 { "vsync", 0, -1, _("VSync: %s") },
2340 // subs
2341 { "sub", 0, -1, _("Subtitles: %s") },
2342 { "sub_source", 0, -1, _("Sub source: %s") },
2343 { "sub_vob", 0, -1, _("Subtitles: %s") },
2344 { "sub_demux", 0, -1, _("Subtitles: %s") },
2345 { "sub_file", 0, -1, _("Subtitles: %s") },
2346 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2347 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2348 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2349 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2350 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2351 #ifdef CONFIG_FREETYPE
2352 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2353 #endif
2354 #ifdef CONFIG_TV
2355 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2356 { "tv_hue", OSD_HUE, -1, _("Hue") },
2357 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2358 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2359 #endif
2363 static int show_property_osd(MPContext *mpctx, const char *pname)
2365 struct MPOpts *opts = &mpctx->opts;
2366 int r;
2367 m_option_t* prop;
2368 struct property_osd_display *p;
2370 // look for the command
2371 for (p = property_osd_display; p->name; p++)
2372 if (!strcmp(p->name, pname))
2373 break;
2374 if (!p->name)
2375 return -1;
2377 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2378 return -1;
2380 if (p->osd_progbar == -1)
2381 mpctx->add_osd_seek_info = true;
2382 else if (p->osd_progbar) {
2383 if (prop->type == CONF_TYPE_INT) {
2384 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2385 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2386 prop->min, prop->max, r);
2387 } else if (prop->type == CONF_TYPE_FLOAT) {
2388 float f;
2389 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2390 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2391 prop->min, prop->max, f);
2392 } else {
2393 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2394 "Property use an unsupported type.\n");
2395 return -1;
2397 return 0;
2400 if (p->osd_msg) {
2401 char *val = mp_property_print(pname, mpctx);
2402 if (val) {
2403 int index = p - property_osd_display;
2404 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2405 1, opts->osd_duration, p->osd_msg, val);
2406 free(val);
2409 return 0;
2414 * \defgroup Command2Property Command to property bridge
2416 * It is used to handle most commands that just set a property
2417 * and optionally display something on the OSD.
2418 * Two kinds of commands are handled: adjust or toggle.
2420 * Adjust commands take 1 or 2 parameters: <value> <abs>
2421 * If <abs> is non-zero the property is set to the given value
2422 * otherwise it is adjusted.
2424 * Toggle commands take 0 or 1 parameters. With no parameter
2425 * or a value less than the property minimum it just steps the
2426 * property to its next value. Otherwise it sets it to the given
2427 * value.
2432 /// List of the commands that can be handled by setting a property.
2433 static struct {
2434 /// property name
2435 const char *name;
2436 /// cmd id
2437 int cmd;
2438 /// set/adjust or toggle command
2439 int toggle;
2440 } set_prop_cmd[] = {
2441 // general
2442 { "loop", MP_CMD_LOOP, 0},
2443 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2444 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2445 { "pause", MP_CMD_PAUSE, 0},
2446 // audio
2447 { "volume", MP_CMD_VOLUME, 0},
2448 { "mute", MP_CMD_MUTE, 1},
2449 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2450 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2451 { "balance", MP_CMD_BALANCE, 0},
2452 // video
2453 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2454 { "panscan", MP_CMD_PANSCAN, 0},
2455 { "ontop", MP_CMD_VO_ONTOP, 1},
2456 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2457 { "border", MP_CMD_VO_BORDER, 1},
2458 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2459 { "gamma", MP_CMD_GAMMA, 0},
2460 { "brightness", MP_CMD_BRIGHTNESS, 0},
2461 { "contrast", MP_CMD_CONTRAST, 0},
2462 { "saturation", MP_CMD_SATURATION, 0},
2463 { "hue", MP_CMD_HUE, 0},
2464 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2465 // subs
2466 { "sub", MP_CMD_SUB_SELECT, 1},
2467 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2468 { "sub_vob", MP_CMD_SUB_VOB, 1},
2469 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2470 { "sub_file", MP_CMD_SUB_FILE, 1},
2471 { "sub_pos", MP_CMD_SUB_POS, 0},
2472 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2473 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2474 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2475 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2476 #ifdef CONFIG_FREETYPE
2477 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2478 #endif
2479 #ifdef CONFIG_ASS
2480 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2481 #endif
2482 #ifdef CONFIG_TV
2483 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2484 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2485 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2486 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2487 #endif
2491 /// Handle commands that set a property.
2492 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2494 int i, r;
2495 m_option_t *prop;
2496 const char *pname;
2498 // look for the command
2499 for (i = 0; set_prop_cmd[i].name; i++)
2500 if (set_prop_cmd[i].cmd == cmd->id)
2501 break;
2502 if (!(pname = set_prop_cmd[i].name))
2503 return 0;
2505 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2506 return 0;
2508 // toggle command
2509 if (set_prop_cmd[i].toggle) {
2510 // set to value
2511 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2512 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2513 else
2514 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2515 } else if (cmd->args[1].v.i) //set
2516 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2517 else // adjust
2518 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2520 if (r <= 0)
2521 return 1;
2523 show_property_osd(mpctx, pname);
2525 return 1;
2528 #ifdef CONFIG_DVDNAV
2529 static const struct {
2530 const char *name;
2531 const mp_command_type cmd;
2532 } mp_dvdnav_bindings[] = {
2533 { "up", MP_CMD_DVDNAV_UP },
2534 { "down", MP_CMD_DVDNAV_DOWN },
2535 { "left", MP_CMD_DVDNAV_LEFT },
2536 { "right", MP_CMD_DVDNAV_RIGHT },
2537 { "menu", MP_CMD_DVDNAV_MENU },
2538 { "select", MP_CMD_DVDNAV_SELECT },
2539 { "prev", MP_CMD_DVDNAV_PREVMENU },
2540 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2543 * keep old dvdnav sub-command options for a while in order not to
2544 * break slave-mode API too suddenly.
2546 { "1", MP_CMD_DVDNAV_UP },
2547 { "2", MP_CMD_DVDNAV_DOWN },
2548 { "3", MP_CMD_DVDNAV_LEFT },
2549 { "4", MP_CMD_DVDNAV_RIGHT },
2550 { "5", MP_CMD_DVDNAV_MENU },
2551 { "6", MP_CMD_DVDNAV_SELECT },
2552 { "7", MP_CMD_DVDNAV_PREVMENU },
2553 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2554 { NULL, 0 }
2556 #endif
2558 static const char *property_error_string(int error_value)
2560 switch (error_value) {
2561 case M_PROPERTY_ERROR:
2562 return "ERROR";
2563 case M_PROPERTY_UNAVAILABLE:
2564 return "PROPERTY_UNAVAILABLE";
2565 case M_PROPERTY_NOT_IMPLEMENTED:
2566 return "NOT_IMPLEMENTED";
2567 case M_PROPERTY_UNKNOWN:
2568 return "PROPERTY_UNKNOWN";
2569 case M_PROPERTY_DISABLED:
2570 return "DISABLED";
2572 return "UNKNOWN";
2575 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2577 int idx;
2578 int end = start + count;
2579 int after = mpctx->set_of_sub_size - end;
2580 sub_data **subs = mpctx->set_of_subtitles;
2581 #ifdef CONFIG_ASS
2582 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2583 #endif
2584 if (count < 0 || count > mpctx->set_of_sub_size ||
2585 start < 0 || start > mpctx->set_of_sub_size - count) {
2586 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2587 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2588 return;
2590 for (idx = start; idx < end; idx++) {
2591 sub_data *subd = subs[idx];
2592 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2593 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2594 filename_recode(subd->filename));
2595 sub_free(subd);
2596 subs[idx] = NULL;
2597 #ifdef CONFIG_ASS
2598 if (ass_tracks[idx])
2599 ass_free_track(ass_tracks[idx]);
2600 ass_tracks[idx] = NULL;
2601 #endif
2604 mpctx->global_sub_size -= count;
2605 mpctx->set_of_sub_size -= count;
2606 if (mpctx->set_of_sub_size <= 0)
2607 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2609 memmove(subs + start, subs + end, after * sizeof(*subs));
2610 memset(subs + start + after, 0, count * sizeof(*subs));
2611 #ifdef CONFIG_ASS
2612 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2613 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2614 #endif
2616 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2617 mpctx->global_sub_pos = -2;
2618 subdata = NULL;
2619 #ifdef CONFIG_ASS
2620 ass_track = NULL;
2621 #endif
2622 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2623 } else if (mpctx->set_of_sub_pos >= end) {
2624 mpctx->set_of_sub_pos -= count;
2625 mpctx->global_sub_pos -= count;
2629 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2631 struct MPOpts *opts = &mpctx->opts;
2632 sh_audio_t * const sh_audio = mpctx->sh_audio;
2633 sh_video_t * const sh_video = mpctx->sh_video;
2634 int osd_duration = opts->osd_duration;
2635 int case_fallthrough_hack = 0;
2636 if (!set_property_command(mpctx, cmd))
2637 switch (cmd->id) {
2638 case MP_CMD_SEEK:{
2639 float v;
2640 int abs;
2641 mpctx->add_osd_seek_info = true;
2642 v = cmd->args[0].v.f;
2643 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2644 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2645 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2646 if (sh_video)
2647 mpctx->osd_function =
2648 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2649 mpctx->rel_seek_secs = v;
2650 } else if (abs) { /* Absolute seek by percentage */
2651 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2652 if (sh_video)
2653 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2654 mpctx->rel_seek_secs = v / 100.0;
2655 } else {
2656 mpctx->rel_seek_secs += v;
2657 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2660 break;
2662 case MP_CMD_SET_PROPERTY_OSD:
2663 case_fallthrough_hack = 1;
2665 case MP_CMD_SET_PROPERTY:{
2666 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2667 cmd->args[1].v.s, mpctx);
2668 if (r == M_PROPERTY_UNKNOWN)
2669 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2670 "Unknown property: '%s'\n", cmd->args[0].v.s);
2671 else if (r <= 0)
2672 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2673 "Failed to set property '%s' to '%s'.\n",
2674 cmd->args[0].v.s, cmd->args[1].v.s);
2675 else if (case_fallthrough_hack)
2676 show_property_osd(mpctx, cmd->args[0].v.s);
2677 if (r <= 0)
2678 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2680 break;
2682 case MP_CMD_STEP_PROPERTY_OSD:
2683 case_fallthrough_hack = 1;
2685 case MP_CMD_STEP_PROPERTY:{
2686 void* arg = NULL;
2687 int r,i;
2688 double d;
2689 off_t o;
2690 if (cmd->args[1].v.f) {
2691 m_option_t* prop;
2692 if((r = mp_property_do(cmd->args[0].v.s,
2693 M_PROPERTY_GET_TYPE,
2694 &prop, mpctx)) <= 0)
2695 goto step_prop_err;
2696 if(prop->type == CONF_TYPE_INT ||
2697 prop->type == CONF_TYPE_FLAG)
2698 i = cmd->args[1].v.f, arg = &i;
2699 else if(prop->type == CONF_TYPE_FLOAT)
2700 arg = &cmd->args[1].v.f;
2701 else if(prop->type == CONF_TYPE_DOUBLE ||
2702 prop->type == CONF_TYPE_TIME)
2703 d = cmd->args[1].v.f, arg = &d;
2704 else if(prop->type == CONF_TYPE_POSITION)
2705 o = cmd->args[1].v.f, arg = &o;
2706 else
2707 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2708 "Ignoring step size stepping property '%s'.\n",
2709 cmd->args[0].v.s);
2711 r = mp_property_do(cmd->args[0].v.s,
2712 cmd->args[2].v.i < 0 ?
2713 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2714 arg, mpctx);
2715 step_prop_err:
2716 if (r == M_PROPERTY_UNKNOWN)
2717 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2718 "Unknown property: '%s'\n", cmd->args[0].v.s);
2719 else if (r <= 0)
2720 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2721 "Failed to increment property '%s' by %f.\n",
2722 cmd->args[0].v.s, cmd->args[1].v.f);
2723 else if (case_fallthrough_hack)
2724 show_property_osd(mpctx, cmd->args[0].v.s);
2725 if (r <= 0)
2726 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2728 break;
2730 case MP_CMD_GET_PROPERTY:{
2731 char *tmp;
2732 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2733 &tmp, mpctx);
2734 if (r <= 0) {
2735 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2736 "Failed to get value of property '%s'.\n",
2737 cmd->args[0].v.s);
2738 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2739 break;
2741 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2742 cmd->args[0].v.s, tmp);
2743 free(tmp);
2745 break;
2747 case MP_CMD_EDL_MARK:
2748 if (edl_fd) {
2749 float v = sh_video ? sh_video->pts :
2750 playing_audio_pts(mpctx);
2751 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2752 mpctx->begin_skip = v;
2753 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2754 } else {
2755 if (mpctx->begin_skip > v)
2756 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2757 else {
2758 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2759 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2761 mpctx->begin_skip = MP_NOPTS_VALUE;
2764 break;
2766 case MP_CMD_SWITCH_RATIO:
2767 if (!sh_video)
2768 break;
2769 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2770 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2771 else
2772 opts->movie_aspect = cmd->args[0].v.f;
2773 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2774 break;
2776 case MP_CMD_SPEED_INCR:{
2777 float v = cmd->args[0].v.f;
2778 opts->playback_speed += v;
2779 build_afilter_chain(mpctx, sh_audio, &ao_data);
2780 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2781 opts->playback_speed);
2782 } break;
2784 case MP_CMD_SPEED_MULT:{
2785 float v = cmd->args[0].v.f;
2786 opts->playback_speed *= v;
2787 build_afilter_chain(mpctx, sh_audio, &ao_data);
2788 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2789 opts->playback_speed);
2790 } break;
2792 case MP_CMD_SPEED_SET:{
2793 float v = cmd->args[0].v.f;
2794 opts->playback_speed = v;
2795 build_afilter_chain(mpctx, sh_audio, &ao_data);
2796 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2797 opts->playback_speed);
2798 } break;
2800 case MP_CMD_FRAME_STEP:
2801 add_step_frame(mpctx);
2802 break;
2804 case MP_CMD_FILE_FILTER:
2805 file_filter = cmd->args[0].v.i;
2806 break;
2808 case MP_CMD_QUIT:
2809 exit_player_with_rc(mpctx, EXIT_QUIT,
2810 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2812 case MP_CMD_PLAY_TREE_STEP:{
2813 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2814 int force = cmd->args[1].v.i;
2817 if (!force && mpctx->playtree_iter) {
2818 play_tree_iter_t *i =
2819 play_tree_iter_new_copy(mpctx->playtree_iter);
2820 if (play_tree_iter_step(i, n, 0) ==
2821 PLAY_TREE_ITER_ENTRY)
2822 mpctx->stop_play =
2823 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2824 play_tree_iter_free(i);
2825 } else
2826 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2827 if (mpctx->stop_play)
2828 mpctx->play_tree_step = n;
2831 break;
2833 case MP_CMD_PLAY_TREE_UP_STEP:{
2834 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2835 int force = cmd->args[1].v.i;
2837 if (!force && mpctx->playtree_iter) {
2838 play_tree_iter_t *i =
2839 play_tree_iter_new_copy(mpctx->playtree_iter);
2840 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2841 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2842 play_tree_iter_free(i);
2843 } else
2844 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2846 break;
2848 case MP_CMD_PLAY_ALT_SRC_STEP:
2849 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2850 int v = cmd->args[0].v.i;
2851 if (v > 0
2852 && mpctx->playtree_iter->file <
2853 mpctx->playtree_iter->num_files)
2854 mpctx->stop_play = PT_NEXT_SRC;
2855 else if (v < 0 && mpctx->playtree_iter->file > 1)
2856 mpctx->stop_play = PT_PREV_SRC;
2858 break;
2860 case MP_CMD_SUB_STEP:
2861 if (sh_video) {
2862 int movement = cmd->args[0].v.i;
2863 step_sub(subdata, sh_video->pts, movement);
2864 #ifdef CONFIG_ASS
2865 if (ass_track)
2866 sub_delay +=
2867 ass_step_sub(ass_track,
2868 (sh_video->pts +
2869 sub_delay) * 1000 + .5, movement) / 1000.;
2870 #endif
2871 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2872 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2874 break;
2876 case MP_CMD_SUB_LOG:
2877 log_sub(mpctx);
2878 break;
2880 case MP_CMD_OSD:{
2881 int v = cmd->args[0].v.i;
2882 int max = (term_osd
2883 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2884 if (opts->osd_level > max)
2885 opts->osd_level = max;
2886 if (v < 0)
2887 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2888 else
2889 opts->osd_level = v > max ? max : v;
2890 /* Show OSD state when disabled, but not when an explicit
2891 argument is given to the OSD command, i.e. in slave mode. */
2892 if (v == -1 && opts->osd_level <= 1)
2893 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2894 "OSD: %s",
2895 opts->osd_level ? mp_gtext("enabled") :
2896 mp_gtext("disabled"));
2897 else
2898 rm_osd_msg(OSD_MSG_OSD_STATUS);
2900 break;
2902 case MP_CMD_OSD_SHOW_TEXT:
2903 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2904 (cmd->args[1].v.i <
2905 0 ? osd_duration : cmd->args[1].v.i),
2906 "%-.63s", cmd->args[0].v.s);
2907 break;
2909 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2910 char *txt = m_properties_expand_string(mp_properties,
2911 cmd->args[0].v.s,
2912 mpctx);
2913 /* if no argument supplied take default osd_duration, else <arg> ms. */
2914 if (txt) {
2915 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2916 (cmd->args[1].v.i <
2917 0 ? osd_duration : cmd->args[1].v.i),
2918 "%-.63s", txt);
2919 free(txt);
2922 break;
2924 case MP_CMD_LOADFILE:{
2925 play_tree_t *e = play_tree_new();
2926 play_tree_add_file(e, cmd->args[0].v.s);
2928 if (cmd->args[1].v.i) // append
2929 play_tree_append_entry(mpctx->playtree->child, e);
2930 else {
2931 // Go back to the starting point.
2932 while (play_tree_iter_up_step
2933 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2934 /* NOP */ ;
2935 play_tree_free_list(mpctx->playtree->child, 1);
2936 play_tree_set_child(mpctx->playtree, e);
2937 pt_iter_goto_head(mpctx->playtree_iter);
2938 mpctx->stop_play = PT_NEXT_SRC;
2941 break;
2943 case MP_CMD_LOADLIST:{
2944 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2945 if (!e)
2946 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2947 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2948 else {
2949 if (cmd->args[1].v.i) // append
2950 play_tree_append_entry(mpctx->playtree->child, e);
2951 else {
2952 // Go back to the starting point.
2953 while (play_tree_iter_up_step
2954 (mpctx->playtree_iter, 0, 1)
2955 != PLAY_TREE_ITER_END)
2956 /* NOP */ ;
2957 play_tree_free_list(mpctx->playtree->child, 1);
2958 play_tree_set_child(mpctx->playtree, e);
2959 pt_iter_goto_head(mpctx->playtree_iter);
2960 mpctx->stop_play = PT_NEXT_SRC;
2964 break;
2966 case MP_CMD_STOP:
2967 // Go back to the starting point.
2968 while (play_tree_iter_up_step
2969 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2970 /* NOP */ ;
2971 mpctx->stop_play = PT_STOP;
2972 break;
2974 case MP_CMD_OSD_SHOW_PROGRESSION:{
2975 int len = demuxer_get_time_length(mpctx->demuxer);
2976 int pts = demuxer_get_current_time(mpctx->demuxer);
2977 set_osd_bar(mpctx, 0, "Position", 0, 100, demuxer_get_percent_pos(mpctx->demuxer));
2978 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2979 "%c %02d:%02d:%02d / %02d:%02d:%02d",
2980 mpctx->osd_function, pts/3600, (pts/60)%60, pts%60,
2981 len/3600, (len/60)%60, len%60);
2983 break;
2985 #ifdef CONFIG_RADIO
2986 case MP_CMD_RADIO_STEP_CHANNEL:
2987 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2988 int v = cmd->args[0].v.i;
2989 if (v > 0)
2990 radio_step_channel(mpctx->demuxer->stream,
2991 RADIO_CHANNEL_HIGHER);
2992 else
2993 radio_step_channel(mpctx->demuxer->stream,
2994 RADIO_CHANNEL_LOWER);
2995 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2996 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2997 "Channel: %s",
2998 radio_get_channel_name(mpctx->demuxer->stream));
3001 break;
3003 case MP_CMD_RADIO_SET_CHANNEL:
3004 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3005 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3006 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3007 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3008 "Channel: %s",
3009 radio_get_channel_name(mpctx->demuxer->stream));
3012 break;
3014 case MP_CMD_RADIO_SET_FREQ:
3015 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3016 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3017 break;
3019 case MP_CMD_RADIO_STEP_FREQ:
3020 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3021 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3022 break;
3023 #endif
3025 #ifdef CONFIG_TV
3026 case MP_CMD_TV_START_SCAN:
3027 if (mpctx->file_format == DEMUXER_TYPE_TV)
3028 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
3029 break;
3030 case MP_CMD_TV_SET_FREQ:
3031 if (mpctx->file_format == DEMUXER_TYPE_TV)
3032 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3033 cmd->args[0].v.f * 16.0);
3034 #ifdef CONFIG_PVR
3035 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3036 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
3037 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3038 pvr_get_current_channelname (mpctx->stream),
3039 pvr_get_current_stationname (mpctx->stream));
3041 #endif /* CONFIG_PVR */
3042 break;
3044 case MP_CMD_TV_STEP_FREQ:
3045 if (mpctx->file_format == DEMUXER_TYPE_TV)
3046 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3047 cmd->args[0].v.f * 16.0);
3048 #ifdef CONFIG_PVR
3049 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3050 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
3051 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3052 pvr_get_current_channelname (mpctx->stream),
3053 pvr_get_current_frequency (mpctx->stream));
3055 #endif /* CONFIG_PVR */
3056 break;
3058 case MP_CMD_TV_SET_NORM:
3059 if (mpctx->file_format == DEMUXER_TYPE_TV)
3060 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3061 cmd->args[0].v.s);
3062 break;
3064 case MP_CMD_TV_STEP_CHANNEL:{
3065 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3066 int v = cmd->args[0].v.i;
3067 if (v > 0) {
3068 tv_step_channel((tvi_handle_t *) (mpctx->
3069 demuxer->priv),
3070 TV_CHANNEL_HIGHER);
3071 } else {
3072 tv_step_channel((tvi_handle_t *) (mpctx->
3073 demuxer->priv),
3074 TV_CHANNEL_LOWER);
3076 if (tv_channel_list) {
3077 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3078 "Channel: %s", tv_channel_current->name);
3079 //vo_osd_changed(OSDTYPE_SUBTITLE);
3082 #ifdef CONFIG_PVR
3083 else if (mpctx->stream &&
3084 mpctx->stream->type == STREAMTYPE_PVR) {
3085 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3086 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3087 pvr_get_current_channelname (mpctx->stream),
3088 pvr_get_current_stationname (mpctx->stream));
3090 #endif /* CONFIG_PVR */
3092 #ifdef CONFIG_DVBIN
3093 if (mpctx->stream->type == STREAMTYPE_DVB) {
3094 int dir;
3095 int v = cmd->args[0].v.i;
3097 mpctx->last_dvb_step = v;
3098 if (v > 0)
3099 dir = DVB_CHANNEL_HIGHER;
3100 else
3101 dir = DVB_CHANNEL_LOWER;
3104 if (dvb_step_channel(mpctx->stream, dir)) {
3105 mpctx->stop_play = PT_NEXT_ENTRY;
3106 mpctx->dvbin_reopen = 1;
3109 #endif /* CONFIG_DVBIN */
3110 break;
3112 case MP_CMD_TV_SET_CHANNEL:
3113 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3114 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3115 cmd->args[0].v.s);
3116 if (tv_channel_list) {
3117 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3118 "Channel: %s", tv_channel_current->name);
3119 //vo_osd_changed(OSDTYPE_SUBTITLE);
3122 #ifdef CONFIG_PVR
3123 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3124 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3125 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3126 pvr_get_current_channelname (mpctx->stream),
3127 pvr_get_current_stationname (mpctx->stream));
3129 #endif /* CONFIG_PVR */
3130 break;
3132 #ifdef CONFIG_DVBIN
3133 case MP_CMD_DVB_SET_CHANNEL:
3134 if (mpctx->stream->type == STREAMTYPE_DVB) {
3135 mpctx->last_dvb_step = 1;
3137 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3138 cmd->args[0].v.i)) {
3139 mpctx->stop_play = PT_NEXT_ENTRY;
3140 mpctx->dvbin_reopen = 1;
3143 break;
3144 #endif /* CONFIG_DVBIN */
3146 case MP_CMD_TV_LAST_CHANNEL:
3147 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3148 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3149 if (tv_channel_list) {
3150 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3151 "Channel: %s", tv_channel_current->name);
3152 //vo_osd_changed(OSDTYPE_SUBTITLE);
3155 #ifdef CONFIG_PVR
3156 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3157 pvr_set_lastchannel (mpctx->stream);
3158 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3159 pvr_get_current_channelname (mpctx->stream),
3160 pvr_get_current_stationname (mpctx->stream));
3162 #endif /* CONFIG_PVR */
3163 break;
3165 case MP_CMD_TV_STEP_NORM:
3166 if (mpctx->file_format == DEMUXER_TYPE_TV)
3167 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3168 break;
3170 case MP_CMD_TV_STEP_CHANNEL_LIST:
3171 if (mpctx->file_format == DEMUXER_TYPE_TV)
3172 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3173 break;
3174 #endif /* CONFIG_TV */
3175 case MP_CMD_TV_TELETEXT_ADD_DEC:
3177 if (mpctx->demuxer->teletext)
3178 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3179 &(cmd->args[0].v.s));
3180 break;
3182 case MP_CMD_TV_TELETEXT_GO_LINK:
3184 if (mpctx->demuxer->teletext)
3185 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3186 &(cmd->args[0].v.i));
3187 break;
3190 case MP_CMD_SUB_LOAD:
3191 if (sh_video) {
3192 int n = mpctx->set_of_sub_size;
3193 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3194 if (n != mpctx->set_of_sub_size) {
3195 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3196 ++mpctx->global_sub_size;
3199 break;
3201 case MP_CMD_SUB_REMOVE:
3202 if (sh_video) {
3203 int v = cmd->args[0].v.i;
3204 if (v < 0) {
3205 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3206 } else if (v < mpctx->set_of_sub_size) {
3207 remove_subtitle_range(mpctx, v, 1);
3210 break;
3212 case MP_CMD_GET_SUB_VISIBILITY:
3213 if (sh_video) {
3214 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3215 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3217 break;
3219 case MP_CMD_SCREENSHOT:
3220 if (mpctx->video_out && mpctx->video_out->config_ok) {
3221 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3222 if (CONTROL_OK !=
3223 ((vf_instance_t *) sh_video->vfilter)->
3224 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3225 &cmd->args[0].v.i))
3226 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3228 break;
3230 case MP_CMD_VF_CHANGE_RECTANGLE:
3231 if (!sh_video)
3232 break;
3233 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3234 break;
3236 case MP_CMD_GET_TIME_LENGTH:{
3237 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3238 demuxer_get_time_length(mpctx->demuxer));
3240 break;
3242 case MP_CMD_GET_FILENAME:{
3243 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3244 get_metadata(mpctx, META_NAME));
3246 break;
3248 case MP_CMD_GET_VIDEO_CODEC:{
3249 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3250 if (!inf)
3251 inf = strdup("");
3252 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3253 free(inf);
3255 break;
3257 case MP_CMD_GET_VIDEO_BITRATE:{
3258 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3259 if (!inf)
3260 inf = strdup("");
3261 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3262 free(inf);
3264 break;
3266 case MP_CMD_GET_VIDEO_RESOLUTION:{
3267 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3268 if (!inf)
3269 inf = strdup("");
3270 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3271 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3272 free(inf);
3274 break;
3276 case MP_CMD_GET_AUDIO_CODEC:{
3277 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3278 if (!inf)
3279 inf = strdup("");
3280 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3281 free(inf);
3283 break;
3285 case MP_CMD_GET_AUDIO_BITRATE:{
3286 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3287 if (!inf)
3288 inf = strdup("");
3289 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3290 free(inf);
3292 break;
3294 case MP_CMD_GET_AUDIO_SAMPLES:{
3295 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3296 if (!inf)
3297 inf = strdup("");
3298 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3299 free(inf);
3301 break;
3303 case MP_CMD_GET_META_TITLE:{
3304 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3305 if (!inf)
3306 inf = strdup("");
3307 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3308 free(inf);
3310 break;
3312 case MP_CMD_GET_META_ARTIST:{
3313 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3314 if (!inf)
3315 inf = strdup("");
3316 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3317 free(inf);
3319 break;
3321 case MP_CMD_GET_META_ALBUM:{
3322 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3323 if (!inf)
3324 inf = strdup("");
3325 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3326 free(inf);
3328 break;
3330 case MP_CMD_GET_META_YEAR:{
3331 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3332 if (!inf)
3333 inf = strdup("");
3334 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3335 free(inf);
3337 break;
3339 case MP_CMD_GET_META_COMMENT:{
3340 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3341 if (!inf)
3342 inf = strdup("");
3343 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3344 free(inf);
3346 break;
3348 case MP_CMD_GET_META_TRACK:{
3349 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3350 if (!inf)
3351 inf = strdup("");
3352 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3353 free(inf);
3355 break;
3357 case MP_CMD_GET_META_GENRE:{
3358 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3359 if (!inf)
3360 inf = strdup("");
3361 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3362 free(inf);
3364 break;
3366 case MP_CMD_GET_VO_FULLSCREEN:
3367 if (mpctx->video_out && mpctx->video_out->config_ok)
3368 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3369 break;
3371 case MP_CMD_GET_PERCENT_POS:
3372 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3373 demuxer_get_percent_pos(mpctx->demuxer));
3374 break;
3376 case MP_CMD_GET_TIME_POS:{
3377 float pos = 0;
3378 if (sh_video)
3379 pos = sh_video->pts;
3380 else if (sh_audio && mpctx->audio_out)
3381 pos = playing_audio_pts(mpctx);
3382 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3384 break;
3386 case MP_CMD_RUN:
3387 #ifndef __MINGW32__
3388 if (!fork()) {
3389 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3390 exit(0);
3392 #endif
3393 break;
3395 case MP_CMD_KEYDOWN_EVENTS:
3396 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3397 break;
3399 case MP_CMD_SET_MOUSE_POS:{
3400 int pointer_x, pointer_y;
3401 double dx, dy;
3402 pointer_x = cmd->args[0].v.i;
3403 pointer_y = cmd->args[1].v.i;
3404 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3405 #ifdef CONFIG_DVDNAV
3406 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3407 && dx > 0.0 && dy > 0.0) {
3408 int button = -1;
3409 pointer_x = (int) (dx * (double) sh_video->disp_w);
3410 pointer_y = (int) (dy * (double) sh_video->disp_h);
3411 mp_dvdnav_update_mouse_pos(mpctx->stream,
3412 pointer_x, pointer_y, &button);
3413 if (opts->osd_level > 1 && button > 0)
3414 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3415 "Selected button number %d", button);
3417 #endif
3418 #ifdef CONFIG_MENU
3419 if (use_menu && dx >= 0.0 && dy >= 0.0)
3420 menu_update_mouse_pos(dx, dy);
3421 #endif
3423 break;
3425 #ifdef CONFIG_DVDNAV
3426 case MP_CMD_DVDNAV:{
3427 int button = -1;
3428 int i;
3429 mp_command_type command = 0;
3430 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3431 break;
3433 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3434 if (cmd->args[0].v.s &&
3435 !strcasecmp (cmd->args[0].v.s,
3436 mp_dvdnav_bindings[i].name))
3437 command = mp_dvdnav_bindings[i].cmd;
3439 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3440 if (opts->osd_level > 1 && button > 0)
3441 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3442 "Selected button number %d", button);
3444 break;
3446 case MP_CMD_SWITCH_TITLE:
3447 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3448 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3449 break;
3451 #endif
3453 case MP_CMD_AF_SWITCH:
3454 if (sh_audio)
3456 af_uninit(mpctx->mixer.afilter);
3457 af_init(mpctx->mixer.afilter);
3459 case MP_CMD_AF_ADD:
3460 case MP_CMD_AF_DEL:
3461 if (!sh_audio)
3462 break;
3464 char* af_args = strdup(cmd->args[0].v.s);
3465 char* af_commands = af_args;
3466 char* af_command;
3467 af_instance_t* af;
3468 while ((af_command = strsep(&af_commands, ",")) != NULL)
3470 if (cmd->id == MP_CMD_AF_DEL)
3472 af = af_get(mpctx->mixer.afilter, af_command);
3473 if (af != NULL)
3474 af_remove(mpctx->mixer.afilter, af);
3476 else
3477 af_add(mpctx->mixer.afilter, af_command);
3479 build_afilter_chain(mpctx, sh_audio, &ao_data);
3480 free(af_args);
3482 break;
3483 case MP_CMD_AF_CLR:
3484 if (!sh_audio)
3485 break;
3486 af_uninit(mpctx->mixer.afilter);
3487 af_init(mpctx->mixer.afilter);
3488 build_afilter_chain(mpctx, sh_audio, &ao_data);
3489 break;
3490 default:
3491 mp_msg(MSGT_CPLAYER, MSGL_V,
3492 "Received unknown cmd %s\n", cmd->name);
3495 switch (cmd->pausing) {
3496 case 1: // "pausing"
3497 pause_player(mpctx);
3498 break;
3499 case 3: // "pausing_toggle"
3500 if (mpctx->paused)
3501 unpause_player(mpctx);
3502 else
3503 pause_player(mpctx);
3504 break;