Update MPlayer sources
[mplayer/kovensky.git] / command.c
blobf7fda95fd87ba59901adc072edc2e8c5474eab2e
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_teletext.h"
49 #include "vobsub.h"
50 #include "spudec.h"
51 #include "get_path.h"
52 #include "ass_mp.h"
53 #include "stream/tv.h"
54 #include "stream/stream_radio.h"
55 #include "stream/pvr.h"
56 #ifdef CONFIG_DVBIN
57 #include "stream/dvbin.h"
58 #endif
59 #ifdef CONFIG_DVDREAD
60 #include "stream/stream_dvd.h"
61 #endif
62 #include "stream/stream_dvdnav.h"
63 #include "m_struct.h"
64 #include "libmenu/menu.h"
66 #include "mp_core.h"
67 #include "mp_fifo.h"
68 #include "libavutil/avstring.h"
70 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
72 extern int use_menu;
74 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
75 double *dx, double *dy)
77 struct MPOpts *opts = &mpctx->opts;
78 struct vo *vo = mpctx->video_out;
79 //remove the borders, if any, and rescale to the range [0,1],[0,1]
80 if (vo_fs) { //we are in full-screen mode
81 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
82 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
83 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
84 iy -= (opts->vo_screenheight - vo->dheight) / 2;
86 if (ix < 0 || ix > vo->dwidth) {
87 *dx = *dy = -1.0;
88 return;
89 } //we are on one of the borders
90 if (iy < 0 || iy > vo->dheight) {
91 *dx = *dy = -1.0;
92 return;
93 } //we are on one of the borders
96 *dx = (double) ix / (double) vo->dwidth;
97 *dy = (double) iy / (double) vo->dheight;
99 mp_msg(MSGT_CPLAYER, MSGL_V,
100 "\r\nrescaled coordinates: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
101 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
102 vo->dheight, vo_fs);
105 static int sub_source_by_pos(MPContext *mpctx, int pos)
107 int source = -1;
108 int top = -1;
109 int i;
110 for (i = 0; i < SUB_SOURCES; i++) {
111 int j = mpctx->global_sub_indices[i];
112 if ((j >= 0) && (j > top) && (pos >= j)) {
113 source = i;
114 top = j;
117 return source;
120 static int sub_source(MPContext *mpctx)
122 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
126 * \brief Log the currently displayed subtitle to a file
128 * Logs the current or last displayed subtitle together with filename
129 * and time information to ~/.mplayer/subtitle_log
131 * Intended purpose is to allow convenient marking of bogus subtitles
132 * which need to be fixed while watching the movie.
135 static void log_sub(struct MPContext *mpctx)
137 char *fname;
138 FILE *f;
139 int i;
141 if (subdata == NULL || vo_sub_last == NULL)
142 return;
143 fname = get_path("subtitle_log");
144 f = fopen(fname, "a");
145 if (!f)
146 return;
147 fprintf(f, "----------------------------------------------------------\n");
148 if (subdata->sub_uses_time) {
149 fprintf(f,
150 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
151 mpctx->filename, vo_sub_last->start / 360000,
152 (vo_sub_last->start / 6000) % 60,
153 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
154 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
155 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
156 } else {
157 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
158 vo_sub_last->start, vo_sub_last->end);
160 for (i = 0; i < vo_sub_last->lines; i++) {
161 fprintf(f, "%s\n", vo_sub_last->text[i]);
163 fclose(f);
167 /// \defgroup Properties
168 ///@{
170 /// \defgroup GeneralProperties General properties
171 /// \ingroup Properties
172 ///@{
174 /// OSD level (RW)
175 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
176 MPContext *mpctx)
178 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
181 /// Loop (RW)
182 static int mp_property_loop(m_option_t *prop, int action, void *arg,
183 MPContext *mpctx)
185 struct MPOpts *opts = &mpctx->opts;
186 switch (action) {
187 case M_PROPERTY_PRINT:
188 if (!arg) return M_PROPERTY_ERROR;
189 if (opts->loop_times < 0)
190 *(char**)arg = strdup("off");
191 else if (opts->loop_times == 0)
192 *(char**)arg = strdup("inf");
193 else
194 break;
195 return M_PROPERTY_OK;
197 return m_property_int_range(prop, action, arg, &opts->loop_times);
200 /// Playback speed (RW)
201 static int mp_property_playback_speed(m_option_t *prop, int action,
202 void *arg, MPContext *mpctx)
204 struct MPOpts *opts = &mpctx->opts;
205 switch (action) {
206 case M_PROPERTY_SET:
207 if (!arg)
208 return M_PROPERTY_ERROR;
209 M_PROPERTY_CLAMP(prop, *(float *) arg);
210 opts->playback_speed = *(float *) arg;
211 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
212 return M_PROPERTY_OK;
213 case M_PROPERTY_STEP_UP:
214 case M_PROPERTY_STEP_DOWN:
215 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
216 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
217 M_PROPERTY_CLAMP(prop, opts->playback_speed);
218 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
219 return M_PROPERTY_OK;
221 return m_property_float_range(prop, action, arg, &opts->playback_speed);
224 /// filename with path (RO)
225 static int mp_property_path(m_option_t *prop, int action, void *arg,
226 MPContext *mpctx)
228 return m_property_string_ro(prop, action, arg, mpctx->filename);
231 /// filename without path (RO)
232 static int mp_property_filename(m_option_t *prop, int action, void *arg,
233 MPContext *mpctx)
235 char *f;
236 if (!mpctx->filename)
237 return M_PROPERTY_UNAVAILABLE;
238 if (((f = strrchr(mpctx->filename, '/'))
239 || (f = strrchr(mpctx->filename, '\\'))) && f[1])
240 f++;
241 else
242 f = mpctx->filename;
243 return m_property_string_ro(prop, action, arg, f);
246 /// Demuxer name (RO)
247 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
248 MPContext *mpctx)
250 if (!mpctx->demuxer)
251 return M_PROPERTY_UNAVAILABLE;
252 return m_property_string_ro(prop, action, arg,
253 (char *) mpctx->demuxer->desc->name);
256 /// Position in the stream (RW)
257 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
258 MPContext *mpctx)
260 if (!mpctx->demuxer || !mpctx->demuxer->stream)
261 return M_PROPERTY_UNAVAILABLE;
262 if (!arg)
263 return M_PROPERTY_ERROR;
264 switch (action) {
265 case M_PROPERTY_GET:
266 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
267 return M_PROPERTY_OK;
268 case M_PROPERTY_SET:
269 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
270 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
271 return M_PROPERTY_OK;
273 return M_PROPERTY_NOT_IMPLEMENTED;
276 /// Stream start offset (RO)
277 static int mp_property_stream_start(m_option_t *prop, int action,
278 void *arg, MPContext *mpctx)
280 if (!mpctx->demuxer || !mpctx->demuxer->stream)
281 return M_PROPERTY_UNAVAILABLE;
282 switch (action) {
283 case M_PROPERTY_GET:
284 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
285 return M_PROPERTY_OK;
287 return M_PROPERTY_NOT_IMPLEMENTED;
290 /// Stream end offset (RO)
291 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
292 MPContext *mpctx)
294 if (!mpctx->demuxer || !mpctx->demuxer->stream)
295 return M_PROPERTY_UNAVAILABLE;
296 switch (action) {
297 case M_PROPERTY_GET:
298 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
299 return M_PROPERTY_OK;
301 return M_PROPERTY_NOT_IMPLEMENTED;
304 /// Stream length (RO)
305 static int mp_property_stream_length(m_option_t *prop, int action,
306 void *arg, MPContext *mpctx)
308 if (!mpctx->demuxer || !mpctx->demuxer->stream)
309 return M_PROPERTY_UNAVAILABLE;
310 switch (action) {
311 case M_PROPERTY_GET:
312 *(off_t *) arg =
313 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
314 return M_PROPERTY_OK;
316 return M_PROPERTY_NOT_IMPLEMENTED;
319 /// Media length in seconds (RO)
320 static int mp_property_length(m_option_t *prop, int action, void *arg,
321 MPContext *mpctx)
323 double len;
325 if (!mpctx->demuxer ||
326 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
327 return M_PROPERTY_UNAVAILABLE;
329 return m_property_time_ro(prop, action, arg, len);
332 /// Current position in percent (RW)
333 static int mp_property_percent_pos(m_option_t *prop, int action,
334 void *arg, MPContext *mpctx) {
335 int pos;
337 if (!mpctx->demuxer)
338 return M_PROPERTY_UNAVAILABLE;
340 switch(action) {
341 case M_PROPERTY_SET:
342 if(!arg) return M_PROPERTY_ERROR;
343 M_PROPERTY_CLAMP(prop, *(int*)arg);
344 pos = *(int*)arg;
345 break;
346 case M_PROPERTY_STEP_UP:
347 case M_PROPERTY_STEP_DOWN:
348 pos = demuxer_get_percent_pos(mpctx->demuxer);
349 pos += (arg ? *(int*)arg : 10) *
350 (action == M_PROPERTY_STEP_UP ? 1 : -1);
351 M_PROPERTY_CLAMP(prop, pos);
352 break;
353 default:
354 return m_property_int_ro(prop, action, arg,
355 demuxer_get_percent_pos(mpctx->demuxer));
358 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
359 mpctx->rel_seek_secs = pos / 100.0;
360 return M_PROPERTY_OK;
363 /// Current position in seconds (RW)
364 static int mp_property_time_pos(m_option_t *prop, int action,
365 void *arg, MPContext *mpctx) {
366 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
367 return M_PROPERTY_UNAVAILABLE;
369 switch(action) {
370 case M_PROPERTY_SET:
371 if(!arg) return M_PROPERTY_ERROR;
372 M_PROPERTY_CLAMP(prop, *(double*)arg);
373 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
374 mpctx->rel_seek_secs = *(double*)arg;
375 return M_PROPERTY_OK;
376 case M_PROPERTY_STEP_UP:
377 case M_PROPERTY_STEP_DOWN:
378 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
379 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
380 return M_PROPERTY_OK;
382 return m_property_time_ro(prop, action, arg,
383 mpctx->sh_video ? mpctx->sh_video->pts :
384 playing_audio_pts(mpctx));
387 /// Current chapter (RW)
388 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
389 MPContext *mpctx)
391 struct MPOpts *opts = &mpctx->opts;
392 int chapter = -1;
393 int step_all;
394 char *chapter_name = NULL;
396 if (mpctx->demuxer)
397 chapter = get_current_chapter(mpctx);
398 if (chapter < 0)
399 return M_PROPERTY_UNAVAILABLE;
401 switch (action) {
402 case M_PROPERTY_GET:
403 if (!arg)
404 return M_PROPERTY_ERROR;
405 *(int *) arg = chapter;
406 return M_PROPERTY_OK;
407 case M_PROPERTY_PRINT: {
408 if (!arg)
409 return M_PROPERTY_ERROR;
410 chapter_name = chapter_display_name(mpctx, chapter);
411 if (!chapter_name)
412 return M_PROPERTY_UNAVAILABLE;
413 *(char **) arg = chapter_name;
414 return M_PROPERTY_OK;
416 case M_PROPERTY_SET:
417 if (!arg)
418 return M_PROPERTY_ERROR;
419 M_PROPERTY_CLAMP(prop, *(int*)arg);
420 step_all = *(int *)arg - chapter;
421 chapter += step_all;
422 break;
423 case M_PROPERTY_STEP_UP:
424 case M_PROPERTY_STEP_DOWN: {
425 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
426 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
427 chapter += step_all;
428 if (chapter < 0)
429 chapter = 0;
430 break;
432 default:
433 return M_PROPERTY_NOT_IMPLEMENTED;
436 double next_pts = 0;
437 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
438 mpctx->rel_seek_secs = 0;
439 mpctx->abs_seek_pos = 0;
440 if (chapter >= 0) {
441 if (next_pts > -1.0) {
442 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
443 mpctx->rel_seek_secs = next_pts;
445 if (chapter_name)
446 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
447 "Chapter: (%d) %s", chapter + 1, chapter_name);
449 else if (step_all > 0)
450 mpctx->rel_seek_secs = 1000000000.;
451 else
452 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
453 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
454 if (chapter_name)
455 talloc_free(chapter_name);
456 return M_PROPERTY_OK;
459 /// Number of chapters in file
460 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
461 MPContext *mpctx)
463 if (!mpctx->demuxer)
464 return M_PROPERTY_UNAVAILABLE;
465 if (mpctx->demuxer->num_chapters == 0)
466 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
467 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
470 /// Current dvd angle (RW)
471 static int mp_property_angle(m_option_t *prop, int action, void *arg,
472 MPContext *mpctx)
474 struct MPOpts *opts = &mpctx->opts;
475 int angle = -1;
476 int angles;
477 char *angle_name = NULL;
479 if (mpctx->demuxer)
480 angle = demuxer_get_current_angle(mpctx->demuxer);
481 if (angle < 0)
482 return M_PROPERTY_UNAVAILABLE;
483 angles = demuxer_angles_count(mpctx->demuxer);
484 if (angles <= 1)
485 return M_PROPERTY_UNAVAILABLE;
487 switch (action) {
488 case M_PROPERTY_GET:
489 if (!arg)
490 return M_PROPERTY_ERROR;
491 *(int *) arg = angle;
492 return M_PROPERTY_OK;
493 case M_PROPERTY_PRINT: {
494 if (!arg)
495 return M_PROPERTY_ERROR;
496 angle_name = calloc(1, 64);
497 if (!angle_name)
498 return M_PROPERTY_UNAVAILABLE;
499 snprintf(angle_name, 64, "%d/%d", angle, angles);
500 *(char **) arg = angle_name;
501 return M_PROPERTY_OK;
503 case M_PROPERTY_SET:
504 if (!arg)
505 return M_PROPERTY_ERROR;
506 angle = *(int *)arg;
507 M_PROPERTY_CLAMP(prop, angle);
508 break;
509 case M_PROPERTY_STEP_UP:
510 case M_PROPERTY_STEP_DOWN: {
511 int step = 0;
512 if(arg)
513 step = *(int*)arg;
514 if(!step)
515 step = 1;
516 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
517 angle += step;
518 if (angle < 1) //cycle
519 angle = angles;
520 break;
522 default:
523 return M_PROPERTY_NOT_IMPLEMENTED;
525 angle = demuxer_set_angle(mpctx->demuxer, angle);
526 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
527 "Angle: %d/%d", angle, angles);
528 if (angle_name)
529 free(angle_name);
530 return M_PROPERTY_OK;
533 /// Demuxer meta data
534 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
535 MPContext *mpctx) {
536 m_property_action_t* ka;
537 char* meta;
538 static const m_option_t key_type =
539 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
540 if (!mpctx->demuxer)
541 return M_PROPERTY_UNAVAILABLE;
543 switch(action) {
544 case M_PROPERTY_GET:
545 if(!arg) return M_PROPERTY_ERROR;
546 *(char***)arg = mpctx->demuxer->info;
547 return M_PROPERTY_OK;
548 case M_PROPERTY_KEY_ACTION:
549 if(!arg) return M_PROPERTY_ERROR;
550 ka = arg;
551 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
552 return M_PROPERTY_UNKNOWN;
553 switch(ka->action) {
554 case M_PROPERTY_GET:
555 if(!ka->arg) return M_PROPERTY_ERROR;
556 *(char**)ka->arg = meta;
557 return M_PROPERTY_OK;
558 case M_PROPERTY_GET_TYPE:
559 if(!ka->arg) return M_PROPERTY_ERROR;
560 *(m_option_t**)ka->arg = &key_type;
561 return M_PROPERTY_OK;
564 return M_PROPERTY_NOT_IMPLEMENTED;
567 static int mp_property_pause(m_option_t *prop, int action, void *arg,
568 void *ctx)
570 MPContext *mpctx = ctx;
572 switch (action) {
573 case M_PROPERTY_SET:
574 if (!arg)
575 return M_PROPERTY_ERROR;
576 if (mpctx->paused == (bool)*(int *) arg)
577 return M_PROPERTY_OK;
578 case M_PROPERTY_STEP_UP:
579 case M_PROPERTY_STEP_DOWN:
580 if (mpctx->paused) {
581 unpause_player(mpctx);
582 mpctx->osd_function = OSD_PLAY;
584 else {
585 pause_player(mpctx);
586 mpctx->osd_function = OSD_PAUSE;
588 return M_PROPERTY_OK;
589 default:
590 return m_property_flag(prop, action, arg, &mpctx->paused);
595 ///@}
597 /// \defgroup AudioProperties Audio properties
598 /// \ingroup Properties
599 ///@{
601 /// Volume (RW)
602 static int mp_property_volume(m_option_t *prop, int action, void *arg,
603 MPContext *mpctx)
606 if (!mpctx->sh_audio)
607 return M_PROPERTY_UNAVAILABLE;
609 switch (action) {
610 case M_PROPERTY_GET:
611 if (!arg)
612 return M_PROPERTY_ERROR;
613 mixer_getbothvolume(&mpctx->mixer, arg);
614 return M_PROPERTY_OK;
615 case M_PROPERTY_PRINT:{
616 float vol;
617 if (!arg)
618 return M_PROPERTY_ERROR;
619 mixer_getbothvolume(&mpctx->mixer, &vol);
620 return m_property_float_range(prop, action, arg, &vol);
622 case M_PROPERTY_STEP_UP:
623 case M_PROPERTY_STEP_DOWN:
624 case M_PROPERTY_SET:
625 break;
626 default:
627 return M_PROPERTY_NOT_IMPLEMENTED;
630 if (mpctx->edl_muted)
631 return M_PROPERTY_DISABLED;
632 mpctx->user_muted = 0;
634 switch (action) {
635 case M_PROPERTY_SET:
636 if (!arg)
637 return M_PROPERTY_ERROR;
638 M_PROPERTY_CLAMP(prop, *(float *) arg);
639 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
640 return M_PROPERTY_OK;
641 case M_PROPERTY_STEP_UP:
642 if (arg && *(float *) arg <= 0)
643 mixer_decvolume(&mpctx->mixer);
644 else
645 mixer_incvolume(&mpctx->mixer);
646 return M_PROPERTY_OK;
647 case M_PROPERTY_STEP_DOWN:
648 if (arg && *(float *) arg <= 0)
649 mixer_incvolume(&mpctx->mixer);
650 else
651 mixer_decvolume(&mpctx->mixer);
652 return M_PROPERTY_OK;
654 return M_PROPERTY_NOT_IMPLEMENTED;
657 /// Mute (RW)
658 static int mp_property_mute(m_option_t *prop, int action, void *arg,
659 MPContext *mpctx)
662 if (!mpctx->sh_audio)
663 return M_PROPERTY_UNAVAILABLE;
665 switch (action) {
666 case M_PROPERTY_SET:
667 if (mpctx->edl_muted)
668 return M_PROPERTY_DISABLED;
669 if (!arg)
670 return M_PROPERTY_ERROR;
671 if ((!!*(int *) arg) != mpctx->mixer.muted)
672 mixer_mute(&mpctx->mixer);
673 mpctx->user_muted = mpctx->mixer.muted;
674 return M_PROPERTY_OK;
675 case M_PROPERTY_STEP_UP:
676 case M_PROPERTY_STEP_DOWN:
677 if (mpctx->edl_muted)
678 return M_PROPERTY_DISABLED;
679 mixer_mute(&mpctx->mixer);
680 mpctx->user_muted = mpctx->mixer.muted;
681 return M_PROPERTY_OK;
682 case M_PROPERTY_PRINT:
683 if (!arg)
684 return M_PROPERTY_ERROR;
685 if (mpctx->edl_muted) {
686 *(char **) arg = strdup(mp_gtext("enabled (EDL)"));
687 return M_PROPERTY_OK;
689 default:
690 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
695 /// Audio delay (RW)
696 static int mp_property_audio_delay(m_option_t *prop, int action,
697 void *arg, MPContext *mpctx)
699 if (!(mpctx->sh_audio && mpctx->sh_video))
700 return M_PROPERTY_UNAVAILABLE;
701 switch (action) {
702 case M_PROPERTY_SET:
703 case M_PROPERTY_STEP_UP:
704 case M_PROPERTY_STEP_DOWN: {
705 int ret;
706 float delay = audio_delay;
707 ret = m_property_delay(prop, action, arg, &audio_delay);
708 if (ret != M_PROPERTY_OK)
709 return ret;
710 if (mpctx->sh_audio)
711 mpctx->delay -= audio_delay - delay;
713 return M_PROPERTY_OK;
714 default:
715 return m_property_delay(prop, action, arg, &audio_delay);
719 /// Audio codec tag (RO)
720 static int mp_property_audio_format(m_option_t *prop, int action,
721 void *arg, MPContext *mpctx)
723 if (!mpctx->sh_audio)
724 return M_PROPERTY_UNAVAILABLE;
725 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
728 /// Audio codec name (RO)
729 static int mp_property_audio_codec(m_option_t *prop, int action,
730 void *arg, MPContext *mpctx)
732 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
733 return M_PROPERTY_UNAVAILABLE;
734 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
737 /// Audio bitrate (RO)
738 static int mp_property_audio_bitrate(m_option_t *prop, int action,
739 void *arg, MPContext *mpctx)
741 if (!mpctx->sh_audio)
742 return M_PROPERTY_UNAVAILABLE;
743 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
746 /// Samplerate (RO)
747 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
748 MPContext *mpctx)
750 if (!mpctx->sh_audio)
751 return M_PROPERTY_UNAVAILABLE;
752 switch(action) {
753 case M_PROPERTY_PRINT:
754 if(!arg) return M_PROPERTY_ERROR;
755 *(char**)arg = malloc(16);
756 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
757 return M_PROPERTY_OK;
759 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
762 /// Number of channels (RO)
763 static int mp_property_channels(m_option_t *prop, int action, void *arg,
764 MPContext *mpctx)
766 if (!mpctx->sh_audio)
767 return M_PROPERTY_UNAVAILABLE;
768 switch (action) {
769 case M_PROPERTY_PRINT:
770 if (!arg)
771 return M_PROPERTY_ERROR;
772 switch (mpctx->sh_audio->channels) {
773 case 1:
774 *(char **) arg = strdup("mono");
775 break;
776 case 2:
777 *(char **) arg = strdup("stereo");
778 break;
779 default:
780 *(char **) arg = malloc(32);
781 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
783 return M_PROPERTY_OK;
785 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
788 /// Balance (RW)
789 static int mp_property_balance(m_option_t *prop, int action, void *arg,
790 MPContext *mpctx)
792 float bal;
794 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
795 return M_PROPERTY_UNAVAILABLE;
797 switch (action) {
798 case M_PROPERTY_GET:
799 if (!arg)
800 return M_PROPERTY_ERROR;
801 mixer_getbalance(&mpctx->mixer, arg);
802 return M_PROPERTY_OK;
803 case M_PROPERTY_PRINT: {
804 char** str = arg;
805 if (!arg)
806 return M_PROPERTY_ERROR;
807 mixer_getbalance(&mpctx->mixer, &bal);
808 if (bal == 0.f)
809 *str = strdup("center");
810 else if (bal == -1.f)
811 *str = strdup("left only");
812 else if (bal == 1.f)
813 *str = strdup("right only");
814 else {
815 unsigned right = (bal + 1.f) / 2.f * 100.f;
816 *str = malloc(sizeof("left xxx%, right xxx%"));
817 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
819 return M_PROPERTY_OK;
821 case M_PROPERTY_STEP_UP:
822 case M_PROPERTY_STEP_DOWN:
823 mixer_getbalance(&mpctx->mixer, &bal);
824 bal += (arg ? *(float*)arg : .1f) *
825 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
826 M_PROPERTY_CLAMP(prop, bal);
827 mixer_setbalance(&mpctx->mixer, bal);
828 return M_PROPERTY_OK;
829 case M_PROPERTY_SET:
830 if (!arg)
831 return M_PROPERTY_ERROR;
832 M_PROPERTY_CLAMP(prop, *(float*)arg);
833 mixer_setbalance(&mpctx->mixer, *(float*)arg);
834 return M_PROPERTY_OK;
836 return M_PROPERTY_NOT_IMPLEMENTED;
839 /// Selected audio id (RW)
840 static int mp_property_audio(m_option_t *prop, int action, void *arg,
841 MPContext *mpctx)
843 struct MPOpts *opts = &mpctx->opts;
844 int current_id, tmp;
845 if (!mpctx->demuxer || !mpctx->demuxer->audio)
846 return M_PROPERTY_UNAVAILABLE;
847 current_id = mpctx->demuxer->audio->id;
849 switch (action) {
850 case M_PROPERTY_GET:
851 if (!arg)
852 return M_PROPERTY_ERROR;
853 *(int *) arg = current_id;
854 return M_PROPERTY_OK;
855 case M_PROPERTY_PRINT:
856 if (!arg)
857 return M_PROPERTY_ERROR;
859 if (current_id < 0)
860 *(char **) arg = strdup(mp_gtext("disabled"));
861 else {
862 char lang[40];
863 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
864 sh_audio_t* sh = mpctx->sh_audio;
865 if (sh && sh->lang)
866 av_strlcpy(lang, sh->lang, 40);
867 #ifdef CONFIG_DVDREAD
868 else if (mpctx->stream->type == STREAMTYPE_DVD) {
869 int code = dvd_lang_from_aid(mpctx->stream, current_id);
870 if (code) {
871 lang[0] = code >> 8;
872 lang[1] = code;
873 lang[2] = 0;
876 #endif
878 #ifdef CONFIG_DVDNAV
879 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
880 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
881 #endif
882 *(char **) arg = malloc(64);
883 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
885 return M_PROPERTY_OK;
887 case M_PROPERTY_STEP_UP:
888 case M_PROPERTY_SET:
889 if (action == M_PROPERTY_SET && arg)
890 tmp = *((int *) arg);
891 else
892 tmp = -1;
893 opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
894 if (opts->audio_id == -2
895 || (opts->audio_id > -1
896 && mpctx->demuxer->audio->id != current_id && current_id != -2))
897 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
898 if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
899 sh_audio_t *sh2;
900 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
901 if (sh2) {
902 sh2->ds = mpctx->demuxer->audio;
903 mpctx->sh_audio = sh2;
904 reinit_audio_chain(mpctx);
907 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id);
908 return M_PROPERTY_OK;
909 default:
910 return M_PROPERTY_NOT_IMPLEMENTED;
915 /// Selected video id (RW)
916 static int mp_property_video(m_option_t *prop, int action, void *arg,
917 MPContext *mpctx)
919 struct MPOpts *opts = &mpctx->opts;
920 int current_id, tmp;
921 if (!mpctx->demuxer || !mpctx->demuxer->video)
922 return M_PROPERTY_UNAVAILABLE;
923 current_id = mpctx->demuxer->video->id;
925 switch (action) {
926 case M_PROPERTY_GET:
927 if (!arg)
928 return M_PROPERTY_ERROR;
929 *(int *) arg = current_id;
930 return M_PROPERTY_OK;
931 case M_PROPERTY_PRINT:
932 if (!arg)
933 return M_PROPERTY_ERROR;
935 if (current_id < 0)
936 *(char **) arg = strdup(mp_gtext("disabled"));
937 else {
938 char lang[40];
939 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
940 *(char **) arg = malloc(64);
941 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
943 return M_PROPERTY_OK;
945 case M_PROPERTY_STEP_UP:
946 case M_PROPERTY_SET:
947 if (action == M_PROPERTY_SET && arg)
948 tmp = *((int *) arg);
949 else
950 tmp = -1;
951 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
952 if (opts->video_id == -2
953 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
954 && current_id != -2))
955 uninit_player(mpctx, INITIALIZED_VCODEC |
956 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
957 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
958 sh_video_t *sh2;
959 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
960 if (sh2) {
961 sh2->ds = mpctx->demuxer->video;
962 mpctx->sh_video = sh2;
963 reinit_video_chain(mpctx);
966 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
967 return M_PROPERTY_OK;
969 default:
970 return M_PROPERTY_NOT_IMPLEMENTED;
974 static int mp_property_program(m_option_t *prop, int action, void *arg,
975 MPContext *mpctx)
977 demux_program_t prog;
979 switch (action) {
980 case M_PROPERTY_STEP_UP:
981 case M_PROPERTY_SET:
982 if (action == M_PROPERTY_SET && arg)
983 prog.progid = *((int *) arg);
984 else
985 prog.progid = -1;
986 if (demux_control
987 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
988 &prog) == DEMUXER_CTRL_NOTIMPL)
989 return M_PROPERTY_ERROR;
991 if (prog.aid < 0 && prog.vid < 0) {
992 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
993 return M_PROPERTY_ERROR;
995 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
996 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
997 return M_PROPERTY_OK;
999 default:
1000 return M_PROPERTY_NOT_IMPLEMENTED;
1004 ///@}
1006 /// \defgroup VideoProperties Video properties
1007 /// \ingroup Properties
1008 ///@{
1010 /// Fullscreen state (RW)
1011 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1012 MPContext *mpctx)
1015 if (!mpctx->video_out)
1016 return M_PROPERTY_UNAVAILABLE;
1018 switch (action) {
1019 case M_PROPERTY_SET:
1020 if (!arg)
1021 return M_PROPERTY_ERROR;
1022 M_PROPERTY_CLAMP(prop, *(int *) arg);
1023 if (vo_fs == !!*(int *) arg)
1024 return M_PROPERTY_OK;
1025 case M_PROPERTY_STEP_UP:
1026 case M_PROPERTY_STEP_DOWN:
1027 if (mpctx->video_out->config_ok)
1028 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1029 mpctx->opts.fullscreen = vo_fs;
1030 return M_PROPERTY_OK;
1031 default:
1032 return m_property_flag(prop, action, arg, &vo_fs);
1036 static int mp_property_deinterlace(m_option_t *prop, int action,
1037 void *arg, MPContext *mpctx)
1039 int deinterlace;
1040 vf_instance_t *vf;
1041 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1042 return M_PROPERTY_UNAVAILABLE;
1043 vf = mpctx->sh_video->vfilter;
1044 switch (action) {
1045 case M_PROPERTY_GET:
1046 if (!arg)
1047 return M_PROPERTY_ERROR;
1048 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1049 return M_PROPERTY_OK;
1050 case M_PROPERTY_SET:
1051 if (!arg)
1052 return M_PROPERTY_ERROR;
1053 M_PROPERTY_CLAMP(prop, *(int *) arg);
1054 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1055 return M_PROPERTY_OK;
1056 case M_PROPERTY_STEP_UP:
1057 case M_PROPERTY_STEP_DOWN:
1058 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1059 deinterlace = !deinterlace;
1060 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1061 return M_PROPERTY_OK;
1063 int value = 0;
1064 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1065 return m_property_flag_ro(prop, action, arg, value);
1068 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1069 void *arg, MPContext *mpctx)
1071 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1072 return M_PROPERTY_UNAVAILABLE;
1074 struct vf_instance *vf = mpctx->sh_video->vfilter;
1075 int colorspace;
1076 switch (action) {
1077 case M_PROPERTY_GET:
1078 if (!arg)
1079 return M_PROPERTY_ERROR;
1080 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1081 return M_PROPERTY_UNAVAILABLE;
1082 return M_PROPERTY_OK;
1083 case M_PROPERTY_PRINT:
1084 if (!arg)
1085 return M_PROPERTY_ERROR;
1086 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1087 return M_PROPERTY_UNAVAILABLE;
1088 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1089 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1090 *(char **)arg = strdup("Unknown");
1091 else
1092 *(char**)arg = strdup(names[colorspace]);
1093 return M_PROPERTY_OK;
1094 case M_PROPERTY_SET:
1095 if (!arg)
1096 return M_PROPERTY_ERROR;
1097 M_PROPERTY_CLAMP(prop, *(int *) arg);
1098 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1099 return M_PROPERTY_OK;
1100 case M_PROPERTY_STEP_UP:;
1101 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1102 return M_PROPERTY_UNAVAILABLE;
1103 colorspace += 1;
1104 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1105 return M_PROPERTY_OK;
1107 return M_PROPERTY_NOT_IMPLEMENTED;
1110 /// Panscan (RW)
1111 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1112 MPContext *mpctx)
1115 if (!mpctx->video_out
1116 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1117 return M_PROPERTY_UNAVAILABLE;
1119 switch (action) {
1120 case M_PROPERTY_SET:
1121 if (!arg)
1122 return M_PROPERTY_ERROR;
1123 M_PROPERTY_CLAMP(prop, *(float *) arg);
1124 vo_panscan = *(float *) arg;
1125 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1126 return M_PROPERTY_OK;
1127 case M_PROPERTY_STEP_UP:
1128 case M_PROPERTY_STEP_DOWN:
1129 vo_panscan += (arg ? *(float *) arg : 0.1) *
1130 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1131 if (vo_panscan > 1)
1132 vo_panscan = 1;
1133 else if (vo_panscan < 0)
1134 vo_panscan = 0;
1135 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1136 return M_PROPERTY_OK;
1137 default:
1138 return m_property_float_range(prop, action, arg, &vo_panscan);
1142 /// Helper to set vo flags.
1143 /** \ingroup PropertyImplHelper
1145 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1146 int vo_ctrl, int *vo_var, MPContext *mpctx)
1149 if (!mpctx->video_out)
1150 return M_PROPERTY_UNAVAILABLE;
1152 switch (action) {
1153 case M_PROPERTY_SET:
1154 if (!arg)
1155 return M_PROPERTY_ERROR;
1156 M_PROPERTY_CLAMP(prop, *(int *) arg);
1157 if (*vo_var == !!*(int *) arg)
1158 return M_PROPERTY_OK;
1159 case M_PROPERTY_STEP_UP:
1160 case M_PROPERTY_STEP_DOWN:
1161 if (mpctx->video_out->config_ok)
1162 vo_control(mpctx->video_out, vo_ctrl, 0);
1163 return M_PROPERTY_OK;
1164 default:
1165 return m_property_flag(prop, action, arg, vo_var);
1169 /// Window always on top (RW)
1170 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1171 MPContext *mpctx)
1173 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1174 &mpctx->opts.vo_ontop, mpctx);
1177 /// Display in the root window (RW)
1178 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1179 MPContext *mpctx)
1181 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1182 &vo_rootwin, mpctx);
1185 /// Show window borders (RW)
1186 static int mp_property_border(m_option_t *prop, int action, void *arg,
1187 MPContext *mpctx)
1189 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1190 &vo_border, mpctx);
1193 /// Framedropping state (RW)
1194 static int mp_property_framedropping(m_option_t *prop, int action,
1195 void *arg, MPContext *mpctx)
1198 if (!mpctx->sh_video)
1199 return M_PROPERTY_UNAVAILABLE;
1201 switch (action) {
1202 case M_PROPERTY_PRINT:
1203 if (!arg)
1204 return M_PROPERTY_ERROR;
1205 *(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
1206 (frame_dropping == 2 ? mp_gtext("hard") :
1207 mp_gtext("disabled")));
1208 return M_PROPERTY_OK;
1209 default:
1210 return m_property_choice(prop, action, arg, &frame_dropping);
1214 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1215 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1216 MPContext *mpctx)
1218 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1219 int r, val;
1221 if (!mpctx->sh_video)
1222 return M_PROPERTY_UNAVAILABLE;
1224 if (gamma[0] == 1000) {
1225 gamma[0] = 0;
1226 get_video_colors(mpctx->sh_video, prop->name, gamma);
1229 switch (action) {
1230 case M_PROPERTY_SET:
1231 if (!arg)
1232 return M_PROPERTY_ERROR;
1233 M_PROPERTY_CLAMP(prop, *(int *) arg);
1234 *gamma = *(int *) arg;
1235 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1236 if (r <= 0)
1237 break;
1238 return r;
1239 case M_PROPERTY_GET:
1240 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1241 if (!arg)
1242 return M_PROPERTY_ERROR;
1243 *(int *)arg = val;
1244 return M_PROPERTY_OK;
1246 break;
1247 case M_PROPERTY_STEP_UP:
1248 case M_PROPERTY_STEP_DOWN:
1249 *gamma += (arg ? *(int *) arg : 1) *
1250 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1251 M_PROPERTY_CLAMP(prop, *gamma);
1252 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1253 if (r <= 0)
1254 break;
1255 return r;
1256 default:
1257 return M_PROPERTY_NOT_IMPLEMENTED;
1260 #ifdef CONFIG_TV
1261 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1262 int l = strlen(prop->name);
1263 char tv_prop[3 + l + 1];
1264 sprintf(tv_prop, "tv_%s", prop->name);
1265 return mp_property_do(tv_prop, action, arg, mpctx);
1267 #endif
1269 return M_PROPERTY_UNAVAILABLE;
1272 /// VSync (RW)
1273 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1274 MPContext *mpctx)
1276 return m_property_flag(prop, action, arg, &vo_vsync);
1279 /// Video codec tag (RO)
1280 static int mp_property_video_format(m_option_t *prop, int action,
1281 void *arg, MPContext *mpctx)
1283 char* meta;
1284 if (!mpctx->sh_video)
1285 return M_PROPERTY_UNAVAILABLE;
1286 switch(action) {
1287 case M_PROPERTY_PRINT:
1288 if (!arg)
1289 return M_PROPERTY_ERROR;
1290 switch(mpctx->sh_video->format) {
1291 case 0x10000001:
1292 meta = strdup ("mpeg1"); break;
1293 case 0x10000002:
1294 meta = strdup ("mpeg2"); break;
1295 case 0x10000004:
1296 meta = strdup ("mpeg4"); break;
1297 case 0x10000005:
1298 meta = strdup ("h264"); break;
1299 default:
1300 if(mpctx->sh_video->format >= 0x20202020) {
1301 meta = malloc(5);
1302 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1303 } else {
1304 meta = malloc(20);
1305 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1308 *(char**)arg = meta;
1309 return M_PROPERTY_OK;
1311 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1314 /// Video codec name (RO)
1315 static int mp_property_video_codec(m_option_t *prop, int action,
1316 void *arg, MPContext *mpctx)
1318 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1319 return M_PROPERTY_UNAVAILABLE;
1320 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1324 /// Video bitrate (RO)
1325 static int mp_property_video_bitrate(m_option_t *prop, int action,
1326 void *arg, MPContext *mpctx)
1328 if (!mpctx->sh_video)
1329 return M_PROPERTY_UNAVAILABLE;
1330 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1333 /// Video display width (RO)
1334 static int mp_property_width(m_option_t *prop, int action, void *arg,
1335 MPContext *mpctx)
1337 if (!mpctx->sh_video)
1338 return M_PROPERTY_UNAVAILABLE;
1339 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1342 /// Video display height (RO)
1343 static int mp_property_height(m_option_t *prop, int action, void *arg,
1344 MPContext *mpctx)
1346 if (!mpctx->sh_video)
1347 return M_PROPERTY_UNAVAILABLE;
1348 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1351 /// Video fps (RO)
1352 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1353 MPContext *mpctx)
1355 if (!mpctx->sh_video)
1356 return M_PROPERTY_UNAVAILABLE;
1357 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1360 /// Video aspect (RO)
1361 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1362 MPContext *mpctx)
1364 if (!mpctx->sh_video)
1365 return M_PROPERTY_UNAVAILABLE;
1366 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1369 ///@}
1371 /// \defgroup SubProprties Subtitles properties
1372 /// \ingroup Properties
1373 ///@{
1375 /// Text subtitle position (RW)
1376 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1377 MPContext *mpctx)
1379 switch (action) {
1380 case M_PROPERTY_SET:
1381 if (!arg)
1382 return M_PROPERTY_ERROR;
1383 case M_PROPERTY_STEP_UP:
1384 case M_PROPERTY_STEP_DOWN:
1385 vo_osd_changed(OSDTYPE_SUBTITLE);
1386 default:
1387 return m_property_int_range(prop, action, arg, &sub_pos);
1391 /// Selected subtitles (RW)
1392 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1393 MPContext *mpctx)
1395 struct MPOpts *opts = &mpctx->opts;
1396 demux_stream_t *const d_sub = mpctx->d_sub;
1397 const int global_sub_size = mpctx->global_sub_size;
1398 int source = -1, reset_spu = 0;
1399 char *sub_name;
1401 if (global_sub_size <= 0)
1402 return M_PROPERTY_UNAVAILABLE;
1404 switch (action) {
1405 case M_PROPERTY_GET:
1406 if (!arg)
1407 return M_PROPERTY_ERROR;
1408 *(int *) arg = mpctx->global_sub_pos;
1409 return M_PROPERTY_OK;
1410 case M_PROPERTY_PRINT:
1411 if (!arg)
1412 return M_PROPERTY_ERROR;
1413 *(char **) arg = malloc(64);
1414 (*(char **) arg)[63] = 0;
1415 sub_name = 0;
1416 if (subdata)
1417 sub_name = subdata->filename;
1418 #ifdef CONFIG_ASS
1419 if (ass_track && ass_track->name)
1420 sub_name = ass_track->name;
1421 #endif
1422 if (sub_name) {
1423 char *tmp, *tmp2;
1424 tmp = sub_name;
1425 if ((tmp2 = strrchr(tmp, '/')))
1426 tmp = tmp2 + 1;
1428 snprintf(*(char **) arg, 63, "(%d) %s%s",
1429 mpctx->set_of_sub_pos + 1,
1430 strlen(tmp) < 20 ? "" : "...",
1431 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1432 return M_PROPERTY_OK;
1434 #ifdef CONFIG_DVDNAV
1435 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1436 if (vo_spudec && opts->sub_id >= 0) {
1437 unsigned char lang[3];
1438 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1439 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1440 return M_PROPERTY_OK;
1444 #endif
1446 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1447 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1448 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1449 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1450 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1451 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1452 if (!lang) lang = mp_gtext("unknown");
1453 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1454 return M_PROPERTY_OK;
1457 if (vo_vobsub && vobsub_id >= 0) {
1458 const char *language = mp_gtext("unknown");
1459 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1460 snprintf(*(char **) arg, 63, "(%d) %s",
1461 vobsub_id, language ? language : mp_gtext("unknown"));
1462 return M_PROPERTY_OK;
1464 #ifdef CONFIG_DVDREAD
1465 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1466 && opts->sub_id >= 0) {
1467 char lang[3];
1468 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1469 lang[0] = code >> 8;
1470 lang[1] = code;
1471 lang[2] = 0;
1472 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1473 return M_PROPERTY_OK;
1475 #endif
1476 if (opts->sub_id >= 0) {
1477 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
1478 mp_gtext("unknown"));
1479 return M_PROPERTY_OK;
1481 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1482 return M_PROPERTY_OK;
1484 case M_PROPERTY_SET:
1485 if (!arg)
1486 return M_PROPERTY_ERROR;
1487 if (*(int *) arg < -1)
1488 *(int *) arg = -1;
1489 else if (*(int *) arg >= global_sub_size)
1490 *(int *) arg = global_sub_size - 1;
1491 mpctx->global_sub_pos = *(int *) arg;
1492 break;
1493 case M_PROPERTY_STEP_UP:
1494 mpctx->global_sub_pos += 2;
1495 mpctx->global_sub_pos =
1496 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1497 break;
1498 case M_PROPERTY_STEP_DOWN:
1499 mpctx->global_sub_pos += global_sub_size + 1;
1500 mpctx->global_sub_pos =
1501 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1502 break;
1503 default:
1504 return M_PROPERTY_NOT_IMPLEMENTED;
1507 if (mpctx->global_sub_pos >= 0)
1508 source = sub_source(mpctx);
1510 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1511 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1512 global_sub_size,
1513 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1514 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1515 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1516 mpctx->global_sub_pos, source);
1518 mpctx->set_of_sub_pos = -1;
1519 subdata = NULL;
1521 vobsub_id = -1;
1522 opts->sub_id = -1;
1523 if (d_sub) {
1524 if (d_sub->id > -2)
1525 reset_spu = 1;
1526 d_sub->id = -2;
1528 #ifdef CONFIG_ASS
1529 ass_track = 0;
1530 #endif
1532 if (source == SUB_SOURCE_VOBSUB) {
1533 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1534 } else if (source == SUB_SOURCE_SUBS) {
1535 mpctx->set_of_sub_pos =
1536 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1537 #ifdef CONFIG_ASS
1538 if (opts->ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1539 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1540 else
1541 #endif
1543 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1544 vo_osd_changed(OSDTYPE_SUBTITLE);
1546 } else if (source == SUB_SOURCE_DEMUX) {
1547 opts->sub_id =
1548 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1549 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1550 int i = 0;
1551 // default: assume 1:1 mapping of sid and stream id
1552 d_sub->id = opts->sub_id;
1553 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1554 ds_free_packs(d_sub);
1555 for (i = 0; i < MAX_S_STREAMS; i++) {
1556 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1557 if (sh && sh->sid == opts->sub_id) {
1558 d_sub->id = i;
1559 d_sub->sh = sh;
1560 break;
1563 if (d_sub->sh && d_sub->id >= 0) {
1564 sh_sub_t *sh = d_sub->sh;
1565 if (sh->type == 'v')
1566 init_vo_spudec(mpctx);
1567 #ifdef CONFIG_ASS
1568 else if (opts->ass_enabled)
1569 ass_track = sh->ass_track;
1570 #endif
1571 } else {
1572 d_sub->id = -2;
1573 d_sub->sh = NULL;
1577 #ifdef CONFIG_DVDREAD
1578 if (vo_spudec
1579 && (mpctx->stream->type == STREAMTYPE_DVD
1580 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1581 && opts->sub_id < 0 && reset_spu) {
1582 d_sub->id = -2;
1583 d_sub->sh = NULL;
1585 #endif
1587 update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, 0, 0, d_sub, 1);
1589 return M_PROPERTY_OK;
1592 /// Selected sub source (RW)
1593 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1594 MPContext *mpctx)
1596 int source;
1597 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1598 return M_PROPERTY_UNAVAILABLE;
1600 switch (action) {
1601 case M_PROPERTY_GET:
1602 if (!arg)
1603 return M_PROPERTY_ERROR;
1604 *(int *) arg = sub_source(mpctx);
1605 return M_PROPERTY_OK;
1606 case M_PROPERTY_PRINT:
1607 if (!arg)
1608 return M_PROPERTY_ERROR;
1609 *(char **) arg = malloc(64);
1610 (*(char **) arg)[63] = 0;
1611 switch (sub_source(mpctx))
1613 case SUB_SOURCE_SUBS:
1614 snprintf(*(char **) arg, 63, mp_gtext("file"));
1615 break;
1616 case SUB_SOURCE_VOBSUB:
1617 snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
1618 break;
1619 case SUB_SOURCE_DEMUX:
1620 snprintf(*(char **) arg, 63, mp_gtext("embedded"));
1621 break;
1622 default:
1623 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1625 return M_PROPERTY_OK;
1626 case M_PROPERTY_SET:
1627 if (!arg)
1628 return M_PROPERTY_ERROR;
1629 M_PROPERTY_CLAMP(prop, *(int*)arg);
1630 if (*(int *) arg < 0)
1631 mpctx->global_sub_pos = -1;
1632 else if (*(int *) arg != sub_source(mpctx)) {
1633 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1634 return M_PROPERTY_UNAVAILABLE;
1635 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1637 break;
1638 case M_PROPERTY_STEP_UP:
1639 case M_PROPERTY_STEP_DOWN: {
1640 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1641 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1642 int step = (step_all > 0) ? 1 : -1;
1643 int cur_source = sub_source(mpctx);
1644 source = cur_source;
1645 while (step_all) {
1646 source += step;
1647 if (source >= SUB_SOURCES)
1648 source = -1;
1649 else if (source < -1)
1650 source = SUB_SOURCES - 1;
1651 if (source == cur_source || source == -1 ||
1652 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1653 step_all -= step;
1655 if (source == cur_source)
1656 return M_PROPERTY_OK;
1657 if (source == -1)
1658 mpctx->global_sub_pos = -1;
1659 else
1660 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1661 break;
1663 default:
1664 return M_PROPERTY_NOT_IMPLEMENTED;
1666 --mpctx->global_sub_pos;
1667 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1670 /// Selected subtitles from specific source (RW)
1671 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1672 MPContext *mpctx)
1674 int source, is_cur_source, offset;
1675 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1676 return M_PROPERTY_UNAVAILABLE;
1678 if (!strcmp(prop->name, "sub_file"))
1679 source = SUB_SOURCE_SUBS;
1680 else if (!strcmp(prop->name, "sub_vob"))
1681 source = SUB_SOURCE_VOBSUB;
1682 else if (!strcmp(prop->name, "sub_demux"))
1683 source = SUB_SOURCE_DEMUX;
1684 else
1685 return M_PROPERTY_ERROR;
1687 offset = mpctx->global_sub_indices[source];
1688 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1689 return M_PROPERTY_UNAVAILABLE;
1691 is_cur_source = sub_source(mpctx) == source;
1692 switch (action) {
1693 case M_PROPERTY_GET:
1694 if (!arg)
1695 return M_PROPERTY_ERROR;
1696 if (is_cur_source) {
1697 *(int *) arg = mpctx->global_sub_pos - offset;
1698 if (source == SUB_SOURCE_VOBSUB)
1699 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1701 else
1702 *(int *) arg = -1;
1703 return M_PROPERTY_OK;
1704 case M_PROPERTY_PRINT:
1705 if (!arg)
1706 return M_PROPERTY_ERROR;
1707 if (is_cur_source)
1708 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1709 *(char **) arg = malloc(64);
1710 (*(char **) arg)[63] = 0;
1711 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1712 return M_PROPERTY_OK;
1713 case M_PROPERTY_SET:
1714 if (!arg)
1715 return M_PROPERTY_ERROR;
1716 if (*(int *) arg >= 0) {
1717 int index = *(int *)arg;
1718 if (source == SUB_SOURCE_VOBSUB)
1719 index = vobsub_get_index_by_id(vo_vobsub, index);
1720 mpctx->global_sub_pos = offset + index;
1721 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1722 || sub_source(mpctx) != source) {
1723 mpctx->global_sub_pos = -1;
1724 *(int *) arg = -1;
1727 else
1728 mpctx->global_sub_pos = -1;
1729 break;
1730 case M_PROPERTY_STEP_UP:
1731 case M_PROPERTY_STEP_DOWN: {
1732 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1733 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1734 int step = (step_all > 0) ? 1 : -1;
1735 int max_sub_pos_for_source = -1;
1736 if (!is_cur_source)
1737 mpctx->global_sub_pos = -1;
1738 while (step_all) {
1739 if (mpctx->global_sub_pos == -1) {
1740 if (step > 0)
1741 mpctx->global_sub_pos = offset;
1742 else if (max_sub_pos_for_source == -1) {
1743 // Find max pos for specific source
1744 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1745 while (mpctx->global_sub_pos >= 0
1746 && sub_source(mpctx) != source)
1747 --mpctx->global_sub_pos;
1749 else
1750 mpctx->global_sub_pos = max_sub_pos_for_source;
1752 else {
1753 mpctx->global_sub_pos += step;
1754 if (mpctx->global_sub_pos < offset ||
1755 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1756 sub_source(mpctx) != source)
1757 mpctx->global_sub_pos = -1;
1759 step_all -= step;
1761 break;
1763 default:
1764 return M_PROPERTY_NOT_IMPLEMENTED;
1766 --mpctx->global_sub_pos;
1767 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1770 /// Subtitle delay (RW)
1771 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1772 MPContext *mpctx)
1774 if (!mpctx->sh_video)
1775 return M_PROPERTY_UNAVAILABLE;
1776 return m_property_delay(prop, action, arg, &sub_delay);
1779 /// Alignment of text subtitles (RW)
1780 static int mp_property_sub_alignment(m_option_t *prop, int action,
1781 void *arg, MPContext *mpctx)
1783 char *name[] = { _("top"), _("center"), _("bottom") };
1785 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1786 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1787 return M_PROPERTY_UNAVAILABLE;
1789 switch (action) {
1790 case M_PROPERTY_PRINT:
1791 if (!arg)
1792 return M_PROPERTY_ERROR;
1793 M_PROPERTY_CLAMP(prop, sub_alignment);
1794 *(char **) arg = strdup(mp_gtext(name[sub_alignment]));
1795 return M_PROPERTY_OK;
1796 case M_PROPERTY_SET:
1797 if (!arg)
1798 return M_PROPERTY_ERROR;
1799 case M_PROPERTY_STEP_UP:
1800 case M_PROPERTY_STEP_DOWN:
1801 vo_osd_changed(OSDTYPE_SUBTITLE);
1802 default:
1803 return m_property_choice(prop, action, arg, &sub_alignment);
1807 /// Subtitle visibility (RW)
1808 static int mp_property_sub_visibility(m_option_t *prop, int action,
1809 void *arg, MPContext *mpctx)
1811 if (!mpctx->sh_video)
1812 return M_PROPERTY_UNAVAILABLE;
1814 switch (action) {
1815 case M_PROPERTY_SET:
1816 if (!arg)
1817 return M_PROPERTY_ERROR;
1818 case M_PROPERTY_STEP_UP:
1819 case M_PROPERTY_STEP_DOWN:
1820 vo_osd_changed(OSDTYPE_SUBTITLE);
1821 if (vo_spudec)
1822 vo_osd_changed(OSDTYPE_SPU);
1823 default:
1824 return m_property_flag(prop, action, arg, &sub_visibility);
1828 #ifdef CONFIG_ASS
1829 /// Use margins for libass subtitles (RW)
1830 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1831 void *arg, MPContext *mpctx)
1833 if (!mpctx->sh_video)
1834 return M_PROPERTY_UNAVAILABLE;
1836 switch (action) {
1837 case M_PROPERTY_SET:
1838 if (!arg)
1839 return M_PROPERTY_ERROR;
1840 case M_PROPERTY_STEP_UP:
1841 case M_PROPERTY_STEP_DOWN:
1842 ass_force_reload = 1;
1843 default:
1844 return m_property_flag(prop, action, arg, &ass_use_margins);
1847 #endif
1849 /// Show only forced subtitles (RW)
1850 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1851 void *arg, MPContext *mpctx)
1853 if (!vo_spudec)
1854 return M_PROPERTY_UNAVAILABLE;
1856 switch (action) {
1857 case M_PROPERTY_SET:
1858 if (!arg)
1859 return M_PROPERTY_ERROR;
1860 case M_PROPERTY_STEP_UP:
1861 case M_PROPERTY_STEP_DOWN:
1862 m_property_flag(prop, action, arg, &forced_subs_only);
1863 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1864 return M_PROPERTY_OK;
1865 default:
1866 return m_property_flag(prop, action, arg, &forced_subs_only);
1871 #ifdef CONFIG_FREETYPE
1872 /// Subtitle scale (RW)
1873 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1874 MPContext *mpctx)
1876 struct MPOpts *opts = &mpctx->opts;
1878 switch (action) {
1879 case M_PROPERTY_SET:
1880 if (!arg)
1881 return M_PROPERTY_ERROR;
1882 M_PROPERTY_CLAMP(prop, *(float *) arg);
1883 #ifdef CONFIG_ASS
1884 if (opts->ass_enabled) {
1885 ass_font_scale = *(float *) arg;
1886 ass_force_reload = 1;
1888 #endif
1889 text_font_scale_factor = *(float *) arg;
1890 force_load_font = 1;
1891 return M_PROPERTY_OK;
1892 case M_PROPERTY_STEP_UP:
1893 case M_PROPERTY_STEP_DOWN:
1894 #ifdef CONFIG_ASS
1895 if (opts->ass_enabled) {
1896 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1897 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1898 M_PROPERTY_CLAMP(prop, ass_font_scale);
1899 ass_force_reload = 1;
1901 #endif
1902 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1903 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1904 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1905 force_load_font = 1;
1906 return M_PROPERTY_OK;
1907 default:
1908 #ifdef CONFIG_ASS
1909 if (opts->ass_enabled)
1910 return m_property_float_ro(prop, action, arg, ass_font_scale);
1911 else
1912 #endif
1913 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1916 #endif
1918 ///@}
1920 /// \defgroup TVProperties TV properties
1921 /// \ingroup Properties
1922 ///@{
1924 #ifdef CONFIG_TV
1926 /// TV color settings (RW)
1927 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1928 MPContext *mpctx)
1930 int r, val;
1931 tvi_handle_t *tvh = mpctx->demuxer->priv;
1932 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1933 return M_PROPERTY_UNAVAILABLE;
1935 switch (action) {
1936 case M_PROPERTY_SET:
1937 if (!arg)
1938 return M_PROPERTY_ERROR;
1939 M_PROPERTY_CLAMP(prop, *(int *) arg);
1940 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1941 case M_PROPERTY_GET:
1942 return tv_get_color_options(tvh, (int) prop->priv, arg);
1943 case M_PROPERTY_STEP_UP:
1944 case M_PROPERTY_STEP_DOWN:
1945 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1946 if (!r)
1947 return M_PROPERTY_ERROR;
1948 val += (arg ? *(int *) arg : 1) *
1949 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1950 M_PROPERTY_CLAMP(prop, val);
1951 return tv_set_color_options(tvh, (int) prop->priv, val);
1953 return M_PROPERTY_ERROR;
1955 return M_PROPERTY_NOT_IMPLEMENTED;
1958 #endif
1960 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1961 MPContext *mpctx)
1963 int val,result;
1964 int base_ioctl=(int)prop->priv;
1966 for teletext's GET,SET,STEP ioctls this is not 0
1967 SET is GET+1
1968 STEP is GET+2
1970 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
1971 return M_PROPERTY_UNAVAILABLE;
1972 if(!base_ioctl)
1973 return M_PROPERTY_ERROR;
1975 switch (action) {
1976 case M_PROPERTY_GET:
1977 if (!arg)
1978 return M_PROPERTY_ERROR;
1979 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
1980 break;
1981 case M_PROPERTY_SET:
1982 if (!arg)
1983 return M_PROPERTY_ERROR;
1984 M_PROPERTY_CLAMP(prop, *(int *) arg);
1985 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
1986 break;
1987 case M_PROPERTY_STEP_UP:
1988 case M_PROPERTY_STEP_DOWN:
1989 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
1990 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1991 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
1992 break;
1993 default:
1994 return M_PROPERTY_NOT_IMPLEMENTED;
1997 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2000 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2001 MPContext *mpctx)
2003 int result;
2004 int val;
2006 //with tvh==NULL will fail too
2007 result=mp_property_teletext_common(prop,action,arg,mpctx);
2008 if(result!=M_PROPERTY_OK)
2009 return result;
2011 if(teletext_control(mpctx->demuxer->teletext,
2012 (int)prop->priv, &val)==VBI_CONTROL_TRUE && val)
2013 mp_input_set_section(mpctx->input, "teletext");
2014 else
2015 mp_input_set_section(mpctx->input, "tv");
2016 return M_PROPERTY_OK;
2019 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2020 MPContext *mpctx)
2022 int result;
2023 int val;
2024 if (!mpctx->demuxer->teletext)
2025 return M_PROPERTY_UNAVAILABLE;
2026 switch(action){
2027 case M_PROPERTY_STEP_UP:
2028 case M_PROPERTY_STEP_DOWN:
2029 //This should be handled separately
2030 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2031 result=teletext_control(mpctx->demuxer->teletext,
2032 TV_VBI_CONTROL_STEP_PAGE, &val);
2033 break;
2034 default:
2035 result=mp_property_teletext_common(prop,action,arg,mpctx);
2037 return result;
2040 ///@}
2042 /// All properties available in MPlayer.
2043 /** \ingroup Properties
2045 static const m_option_t mp_properties[] = {
2046 // General
2047 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2048 M_OPT_RANGE, 0, 3, NULL },
2049 { "loop", mp_property_loop, CONF_TYPE_INT,
2050 M_OPT_MIN, -1, 0, NULL },
2051 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2052 M_OPT_RANGE, 0.01, 100.0, NULL },
2053 { "filename", mp_property_filename, CONF_TYPE_STRING,
2054 0, 0, 0, NULL },
2055 { "path", mp_property_path, CONF_TYPE_STRING,
2056 0, 0, 0, NULL },
2057 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2058 0, 0, 0, NULL },
2059 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2060 M_OPT_MIN, 0, 0, NULL },
2061 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2062 M_OPT_MIN, 0, 0, NULL },
2063 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2064 M_OPT_MIN, 0, 0, NULL },
2065 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2066 M_OPT_MIN, 0, 0, NULL },
2067 { "length", mp_property_length, CONF_TYPE_TIME,
2068 M_OPT_MIN, 0, 0, NULL },
2069 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2070 M_OPT_RANGE, 0, 100, NULL },
2071 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2072 M_OPT_MIN, 0, 0, NULL },
2073 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2074 M_OPT_MIN, 0, 0, NULL },
2075 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2076 0, 0, 0, NULL },
2077 { "angle", mp_property_angle, CONF_TYPE_INT,
2078 CONF_RANGE, -2, 10, NULL },
2079 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2080 0, 0, 0, NULL },
2081 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2082 M_OPT_RANGE, 0, 1, NULL },
2084 // Audio
2085 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2086 M_OPT_RANGE, 0, 100, NULL },
2087 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2088 M_OPT_RANGE, 0, 1, NULL },
2089 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2090 M_OPT_RANGE, -100, 100, NULL },
2091 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2092 0, 0, 0, NULL },
2093 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2094 0, 0, 0, NULL },
2095 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2096 0, 0, 0, NULL },
2097 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2098 0, 0, 0, NULL },
2099 { "channels", mp_property_channels, CONF_TYPE_INT,
2100 0, 0, 0, NULL },
2101 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2102 CONF_RANGE, -2, 65535, NULL },
2103 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2104 M_OPT_RANGE, -1, 1, NULL },
2106 // Video
2107 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2108 M_OPT_RANGE, 0, 1, NULL },
2109 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2110 M_OPT_RANGE, 0, 1, NULL },
2111 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2112 M_OPT_RANGE, 0, 2, NULL },
2113 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2114 M_OPT_RANGE, 0, 1, NULL },
2115 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2116 M_OPT_RANGE, 0, 1, NULL },
2117 { "border", mp_property_border, CONF_TYPE_FLAG,
2118 M_OPT_RANGE, 0, 1, NULL },
2119 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2120 M_OPT_RANGE, 0, 2, NULL },
2121 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2122 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2123 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2124 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2125 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2126 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2127 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2128 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2129 { "hue", mp_property_gamma, CONF_TYPE_INT,
2130 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2131 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2132 M_OPT_RANGE, 0, 1, NULL },
2133 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2134 M_OPT_RANGE, 0, 1, NULL },
2135 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2136 0, 0, 0, NULL },
2137 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2138 0, 0, 0, NULL },
2139 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2140 0, 0, 0, NULL },
2141 { "width", mp_property_width, CONF_TYPE_INT,
2142 0, 0, 0, NULL },
2143 { "height", mp_property_height, CONF_TYPE_INT,
2144 0, 0, 0, NULL },
2145 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2146 0, 0, 0, NULL },
2147 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2148 0, 0, 0, NULL },
2149 { "switch_video", mp_property_video, CONF_TYPE_INT,
2150 CONF_RANGE, -2, 65535, NULL },
2151 { "switch_program", mp_property_program, CONF_TYPE_INT,
2152 CONF_RANGE, -1, 65535, NULL },
2154 // Subs
2155 { "sub", mp_property_sub, CONF_TYPE_INT,
2156 M_OPT_MIN, -1, 0, NULL },
2157 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2158 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2159 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2160 M_OPT_MIN, -1, 0, NULL },
2161 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2162 M_OPT_MIN, -1, 0, NULL },
2163 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2164 M_OPT_MIN, -1, 0, NULL },
2165 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2166 0, 0, 0, NULL },
2167 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2168 M_OPT_RANGE, 0, 100, NULL },
2169 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2170 M_OPT_RANGE, 0, 2, NULL },
2171 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2172 M_OPT_RANGE, 0, 1, NULL },
2173 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2174 M_OPT_RANGE, 0, 1, NULL },
2175 #ifdef CONFIG_FREETYPE
2176 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2177 M_OPT_RANGE, 0, 100, NULL },
2178 #endif
2179 #ifdef CONFIG_ASS
2180 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2181 M_OPT_RANGE, 0, 1, NULL },
2182 #endif
2184 #ifdef CONFIG_TV
2185 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2186 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2187 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2188 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2189 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2190 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2191 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2192 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2193 #endif
2194 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2195 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2196 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2197 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2198 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2199 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2200 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2201 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2202 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2203 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2204 { NULL, NULL, NULL, 0, 0, 0, NULL }
2208 int mp_property_do(const char *name, int action, void *val, void *ctx)
2210 return m_property_do(mp_properties, name, action, val, ctx);
2213 char* mp_property_print(const char *name, void* ctx)
2215 char* ret = NULL;
2216 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2217 return NULL;
2218 return ret;
2221 char *property_expand_string(MPContext *mpctx, char *str)
2223 return m_properties_expand_string(mp_properties, str, mpctx);
2226 void property_print_help(void)
2228 m_properties_print_help_list(mp_properties);
2232 /* List of default ways to show a property on OSD.
2234 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2235 * a bar showing the current position between min/max values of the
2236 * property. In this case osd_msg is only used for terminal output
2237 * if there is no video; it'll be a label shown together with percentage.
2239 * Otherwise setting osd_msg will show the string on OSD, formatted with
2240 * the text value of the property as argument.
2242 static struct property_osd_display {
2243 /// property name
2244 const char *name;
2245 /// progressbar type
2246 int osd_progbar; // -1 is special value for seek indicators
2247 /// osd msg id if it must be shared
2248 int osd_id;
2249 /// osd msg template
2250 const char *osd_msg;
2251 } property_osd_display[] = {
2252 // general
2253 { "loop", 0, -1, _("Loop: %s") },
2254 { "chapter", -1, -1, NULL },
2255 // audio
2256 { "volume", OSD_VOLUME, -1, _("Volume") },
2257 { "mute", 0, -1, _("Mute: %s") },
2258 { "audio_delay", 0, -1, _("A-V delay: %s") },
2259 { "switch_audio", 0, -1, _("Audio: %s") },
2260 { "balance", OSD_BALANCE, -1, _("Balance") },
2261 // video
2262 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2263 { "ontop", 0, -1, _("Stay on top: %s") },
2264 { "rootwin", 0, -1, _("Rootwin: %s") },
2265 { "border", 0, -1, _("Border: %s") },
2266 { "framedropping", 0, -1, _("Framedropping: %s") },
2267 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2268 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2269 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2270 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2271 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2272 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2273 { "hue", OSD_HUE, -1, _("Hue") },
2274 { "vsync", 0, -1, _("VSync: %s") },
2275 // subs
2276 { "sub", 0, -1, _("Subtitles: %s") },
2277 { "sub_source", 0, -1, _("Sub source: %s") },
2278 { "sub_vob", 0, -1, _("Subtitles: %s") },
2279 { "sub_demux", 0, -1, _("Subtitles: %s") },
2280 { "sub_file", 0, -1, _("Subtitles: %s") },
2281 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2282 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2283 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2284 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2285 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2286 #ifdef CONFIG_FREETYPE
2287 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2288 #endif
2289 #ifdef CONFIG_TV
2290 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2291 { "tv_hue", OSD_HUE, -1, _("Hue") },
2292 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2293 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2294 #endif
2298 static int show_property_osd(MPContext *mpctx, const char *pname)
2300 struct MPOpts *opts = &mpctx->opts;
2301 int r;
2302 m_option_t* prop;
2303 struct property_osd_display *p;
2305 // look for the command
2306 for (p = property_osd_display; p->name; p++)
2307 if (!strcmp(p->name, pname))
2308 break;
2309 if (!p->name)
2310 return -1;
2312 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2313 return -1;
2315 if (p->osd_progbar == -1)
2316 mpctx->add_osd_seek_info = true;
2317 else if (p->osd_progbar) {
2318 if (prop->type == CONF_TYPE_INT) {
2319 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2320 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2321 prop->min, prop->max, r);
2322 } else if (prop->type == CONF_TYPE_FLOAT) {
2323 float f;
2324 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2325 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2326 prop->min, prop->max, f);
2327 } else {
2328 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2329 "Property use an unsupported type.\n");
2330 return -1;
2332 return 0;
2335 if (p->osd_msg) {
2336 char *val = mp_property_print(pname, mpctx);
2337 if (val) {
2338 int index = p - property_osd_display;
2339 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2340 1, opts->osd_duration, p->osd_msg, val);
2341 free(val);
2344 return 0;
2349 * \defgroup Command2Property Command to property bridge
2351 * It is used to handle most commands that just set a property
2352 * and optionally display something on the OSD.
2353 * Two kinds of commands are handled: adjust or toggle.
2355 * Adjust commands take 1 or 2 parameters: <value> <abs>
2356 * If <abs> is non-zero the property is set to the given value
2357 * otherwise it is adjusted.
2359 * Toggle commands take 0 or 1 parameters. With no parameter
2360 * or a value less than the property minimum it just steps the
2361 * property to its next value. Otherwise it sets it to the given
2362 * value.
2367 /// List of the commands that can be handled by setting a property.
2368 static struct {
2369 /// property name
2370 const char *name;
2371 /// cmd id
2372 int cmd;
2373 /// set/adjust or toggle command
2374 int toggle;
2375 } set_prop_cmd[] = {
2376 // general
2377 { "loop", MP_CMD_LOOP, 0},
2378 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2379 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2380 { "pause", MP_CMD_PAUSE, 0},
2381 // audio
2382 { "volume", MP_CMD_VOLUME, 0},
2383 { "mute", MP_CMD_MUTE, 1},
2384 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2385 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2386 { "balance", MP_CMD_BALANCE, 0},
2387 // video
2388 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2389 { "panscan", MP_CMD_PANSCAN, 0},
2390 { "ontop", MP_CMD_VO_ONTOP, 1},
2391 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2392 { "border", MP_CMD_VO_BORDER, 1},
2393 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2394 { "gamma", MP_CMD_GAMMA, 0},
2395 { "brightness", MP_CMD_BRIGHTNESS, 0},
2396 { "contrast", MP_CMD_CONTRAST, 0},
2397 { "saturation", MP_CMD_SATURATION, 0},
2398 { "hue", MP_CMD_HUE, 0},
2399 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2400 // subs
2401 { "sub", MP_CMD_SUB_SELECT, 1},
2402 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2403 { "sub_vob", MP_CMD_SUB_VOB, 1},
2404 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2405 { "sub_file", MP_CMD_SUB_FILE, 1},
2406 { "sub_pos", MP_CMD_SUB_POS, 0},
2407 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2408 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2409 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2410 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2411 #ifdef CONFIG_FREETYPE
2412 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2413 #endif
2414 #ifdef CONFIG_ASS
2415 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2416 #endif
2417 #ifdef CONFIG_TV
2418 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2419 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2420 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2421 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2422 #endif
2426 /// Handle commands that set a property.
2427 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2429 int i, r;
2430 m_option_t* prop;
2431 const char *pname;
2433 // look for the command
2434 for (i = 0; set_prop_cmd[i].name; i++)
2435 if (set_prop_cmd[i].cmd == cmd->id)
2436 break;
2437 if (!(pname = set_prop_cmd[i].name))
2438 return 0;
2440 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2441 return 0;
2443 // toggle command
2444 if (set_prop_cmd[i].toggle) {
2445 // set to value
2446 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2447 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2448 else
2449 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2450 } else if (cmd->args[1].v.i) //set
2451 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2452 else // adjust
2453 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2455 if (r <= 0)
2456 return 1;
2458 show_property_osd(mpctx, pname);
2460 return 1;
2463 #ifdef CONFIG_DVDNAV
2464 static const struct {
2465 const char *name;
2466 const mp_command_type cmd;
2467 } mp_dvdnav_bindings[] = {
2468 { "up", MP_CMD_DVDNAV_UP },
2469 { "down", MP_CMD_DVDNAV_DOWN },
2470 { "left", MP_CMD_DVDNAV_LEFT },
2471 { "right", MP_CMD_DVDNAV_RIGHT },
2472 { "menu", MP_CMD_DVDNAV_MENU },
2473 { "select", MP_CMD_DVDNAV_SELECT },
2474 { "prev", MP_CMD_DVDNAV_PREVMENU },
2475 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2478 * keep old dvdnav sub-command options for a while in order not to
2479 * break slave-mode API too suddenly.
2481 { "1", MP_CMD_DVDNAV_UP },
2482 { "2", MP_CMD_DVDNAV_DOWN },
2483 { "3", MP_CMD_DVDNAV_LEFT },
2484 { "4", MP_CMD_DVDNAV_RIGHT },
2485 { "5", MP_CMD_DVDNAV_MENU },
2486 { "6", MP_CMD_DVDNAV_SELECT },
2487 { "7", MP_CMD_DVDNAV_PREVMENU },
2488 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2489 { NULL, 0 }
2491 #endif
2493 static const char *property_error_string(int error_value)
2495 switch (error_value) {
2496 case M_PROPERTY_ERROR:
2497 return "ERROR";
2498 case M_PROPERTY_UNAVAILABLE:
2499 return "PROPERTY_UNAVAILABLE";
2500 case M_PROPERTY_NOT_IMPLEMENTED:
2501 return "NOT_IMPLEMENTED";
2502 case M_PROPERTY_UNKNOWN:
2503 return "PROPERTY_UNKNOWN";
2504 case M_PROPERTY_DISABLED:
2505 return "DISABLED";
2507 return "UNKNOWN";
2510 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2512 int idx;
2513 int end = start + count;
2514 int after = mpctx->set_of_sub_size - end;
2515 sub_data **subs = mpctx->set_of_subtitles;
2516 #ifdef CONFIG_ASS
2517 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2518 #endif
2519 if (count < 0 || count > mpctx->set_of_sub_size ||
2520 start < 0 || start > mpctx->set_of_sub_size - count) {
2521 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2522 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2523 return;
2525 for (idx = start; idx < end; idx++) {
2526 sub_data *subd = subs[idx];
2527 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2528 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2529 filename_recode(subd->filename));
2530 sub_free(subd);
2531 subs[idx] = NULL;
2532 #ifdef CONFIG_ASS
2533 if (ass_tracks[idx])
2534 ass_free_track(ass_tracks[idx]);
2535 ass_tracks[idx] = NULL;
2536 #endif
2539 mpctx->global_sub_size -= count;
2540 mpctx->set_of_sub_size -= count;
2541 if (mpctx->set_of_sub_size <= 0)
2542 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2544 memmove(subs + start, subs + end, after * sizeof(*subs));
2545 memset(subs + start + after, 0, count * sizeof(*subs));
2546 #ifdef CONFIG_ASS
2547 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2548 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2549 #endif
2551 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2552 mpctx->global_sub_pos = -2;
2553 subdata = NULL;
2554 #ifdef CONFIG_ASS
2555 ass_track = NULL;
2556 #endif
2557 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2558 } else if (mpctx->set_of_sub_pos >= end) {
2559 mpctx->set_of_sub_pos -= count;
2560 mpctx->global_sub_pos -= count;
2564 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2566 struct MPOpts *opts = &mpctx->opts;
2567 sh_audio_t * const sh_audio = mpctx->sh_audio;
2568 sh_video_t * const sh_video = mpctx->sh_video;
2569 int osd_duration = opts->osd_duration;
2570 int case_fallthrough_hack = 0;
2571 if (!set_property_command(mpctx, cmd))
2572 switch (cmd->id) {
2573 case MP_CMD_SEEK:{
2574 float v;
2575 int abs;
2576 mpctx->add_osd_seek_info = true;
2577 v = cmd->args[0].v.f;
2578 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2579 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2580 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2581 if (sh_video)
2582 mpctx->osd_function =
2583 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2584 mpctx->rel_seek_secs = v;
2585 } else if (abs) { /* Absolute seek by percentage */
2586 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2587 if (sh_video)
2588 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2589 mpctx->rel_seek_secs = v / 100.0;
2590 } else {
2591 mpctx->rel_seek_secs += v;
2592 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2595 break;
2597 case MP_CMD_SET_PROPERTY_OSD:
2598 case_fallthrough_hack = 1;
2600 case MP_CMD_SET_PROPERTY:{
2601 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2602 cmd->args[1].v.s, mpctx);
2603 if (r == M_PROPERTY_UNKNOWN)
2604 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2605 "Unknown property: '%s'\n", cmd->args[0].v.s);
2606 else if (r <= 0)
2607 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2608 "Failed to set property '%s' to '%s'.\n",
2609 cmd->args[0].v.s, cmd->args[1].v.s);
2610 else if (case_fallthrough_hack)
2611 show_property_osd(mpctx, cmd->args[0].v.s);
2612 if (r <= 0)
2613 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2615 break;
2617 case MP_CMD_STEP_PROPERTY_OSD:
2618 case_fallthrough_hack = 1;
2620 case MP_CMD_STEP_PROPERTY:{
2621 void* arg = NULL;
2622 int r,i;
2623 double d;
2624 off_t o;
2625 if (cmd->args[1].v.f) {
2626 m_option_t* prop;
2627 if((r = mp_property_do(cmd->args[0].v.s,
2628 M_PROPERTY_GET_TYPE,
2629 &prop, mpctx)) <= 0)
2630 goto step_prop_err;
2631 if(prop->type == CONF_TYPE_INT ||
2632 prop->type == CONF_TYPE_FLAG)
2633 i = cmd->args[1].v.f, arg = &i;
2634 else if(prop->type == CONF_TYPE_FLOAT)
2635 arg = &cmd->args[1].v.f;
2636 else if(prop->type == CONF_TYPE_DOUBLE ||
2637 prop->type == CONF_TYPE_TIME)
2638 d = cmd->args[1].v.f, arg = &d;
2639 else if(prop->type == CONF_TYPE_POSITION)
2640 o = cmd->args[1].v.f, arg = &o;
2641 else
2642 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2643 "Ignoring step size stepping property '%s'.\n",
2644 cmd->args[0].v.s);
2646 r = mp_property_do(cmd->args[0].v.s,
2647 cmd->args[2].v.i < 0 ?
2648 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2649 arg, mpctx);
2650 step_prop_err:
2651 if (r == M_PROPERTY_UNKNOWN)
2652 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2653 "Unknown property: '%s'\n", cmd->args[0].v.s);
2654 else if (r <= 0)
2655 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2656 "Failed to increment property '%s' by %f.\n",
2657 cmd->args[0].v.s, cmd->args[1].v.f);
2658 else if (case_fallthrough_hack)
2659 show_property_osd(mpctx, cmd->args[0].v.s);
2660 if (r <= 0)
2661 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2663 break;
2665 case MP_CMD_GET_PROPERTY:{
2666 char *tmp;
2667 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2668 &tmp, mpctx);
2669 if (r <= 0) {
2670 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2671 "Failed to get value of property '%s'.\n",
2672 cmd->args[0].v.s);
2673 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2674 break;
2676 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2677 cmd->args[0].v.s, tmp);
2678 free(tmp);
2680 break;
2682 case MP_CMD_EDL_MARK:
2683 if (edl_fd) {
2684 float v = sh_video ? sh_video->pts :
2685 playing_audio_pts(mpctx);
2686 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2687 mpctx->begin_skip = v;
2688 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2689 } else {
2690 if (mpctx->begin_skip > v)
2691 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2692 else {
2693 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2694 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2696 mpctx->begin_skip = MP_NOPTS_VALUE;
2699 break;
2701 case MP_CMD_SWITCH_RATIO:
2702 if (!sh_video)
2703 break;
2704 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2705 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2706 else
2707 opts->movie_aspect = cmd->args[0].v.f;
2708 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2709 break;
2711 case MP_CMD_SPEED_INCR:{
2712 float v = cmd->args[0].v.f;
2713 opts->playback_speed += v;
2714 build_afilter_chain(mpctx, sh_audio, &ao_data);
2715 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2716 opts->playback_speed);
2717 } break;
2719 case MP_CMD_SPEED_MULT:{
2720 float v = cmd->args[0].v.f;
2721 opts->playback_speed *= v;
2722 build_afilter_chain(mpctx, sh_audio, &ao_data);
2723 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2724 opts->playback_speed);
2725 } break;
2727 case MP_CMD_SPEED_SET:{
2728 float v = cmd->args[0].v.f;
2729 opts->playback_speed = v;
2730 build_afilter_chain(mpctx, sh_audio, &ao_data);
2731 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2732 opts->playback_speed);
2733 } break;
2735 case MP_CMD_FRAME_STEP:
2736 add_step_frame(mpctx);
2737 break;
2739 case MP_CMD_FILE_FILTER:
2740 file_filter = cmd->args[0].v.i;
2741 break;
2743 case MP_CMD_QUIT:
2744 exit_player_with_rc(mpctx, EXIT_QUIT,
2745 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2747 case MP_CMD_PLAY_TREE_STEP:{
2748 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2749 int force = cmd->args[1].v.i;
2752 if (!force && mpctx->playtree_iter) {
2753 play_tree_iter_t *i =
2754 play_tree_iter_new_copy(mpctx->playtree_iter);
2755 if (play_tree_iter_step(i, n, 0) ==
2756 PLAY_TREE_ITER_ENTRY)
2757 mpctx->stop_play =
2758 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2759 play_tree_iter_free(i);
2760 } else
2761 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2762 if (mpctx->stop_play)
2763 mpctx->play_tree_step = n;
2766 break;
2768 case MP_CMD_PLAY_TREE_UP_STEP:{
2769 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2770 int force = cmd->args[1].v.i;
2772 if (!force && mpctx->playtree_iter) {
2773 play_tree_iter_t *i =
2774 play_tree_iter_new_copy(mpctx->playtree_iter);
2775 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2776 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2777 play_tree_iter_free(i);
2778 } else
2779 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2781 break;
2783 case MP_CMD_PLAY_ALT_SRC_STEP:
2784 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2785 int v = cmd->args[0].v.i;
2786 if (v > 0
2787 && mpctx->playtree_iter->file <
2788 mpctx->playtree_iter->num_files)
2789 mpctx->stop_play = PT_NEXT_SRC;
2790 else if (v < 0 && mpctx->playtree_iter->file > 1)
2791 mpctx->stop_play = PT_PREV_SRC;
2793 break;
2795 case MP_CMD_SUB_STEP:
2796 if (sh_video) {
2797 int movement = cmd->args[0].v.i;
2798 step_sub(subdata, sh_video->pts, movement);
2799 #ifdef CONFIG_ASS
2800 if (ass_track)
2801 sub_delay +=
2802 ass_step_sub(ass_track,
2803 (sh_video->pts +
2804 sub_delay) * 1000 + .5, movement) / 1000.;
2805 #endif
2806 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2807 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2809 break;
2811 case MP_CMD_SUB_LOG:
2812 log_sub(mpctx);
2813 break;
2815 case MP_CMD_OSD:{
2816 int v = cmd->args[0].v.i;
2817 int max = (term_osd
2818 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2819 if (opts->osd_level > max)
2820 opts->osd_level = max;
2821 if (v < 0)
2822 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2823 else
2824 opts->osd_level = v > max ? max : v;
2825 /* Show OSD state when disabled, but not when an explicit
2826 argument is given to the OSD command, i.e. in slave mode. */
2827 if (v == -1 && opts->osd_level <= 1)
2828 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2829 "OSD: %s",
2830 opts->osd_level ? mp_gtext("enabled") :
2831 mp_gtext("disabled"));
2832 else
2833 rm_osd_msg(OSD_MSG_OSD_STATUS);
2835 break;
2837 case MP_CMD_OSD_SHOW_TEXT:
2838 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2839 (cmd->args[1].v.i <
2840 0 ? osd_duration : cmd->args[1].v.i),
2841 "%-.63s", cmd->args[0].v.s);
2842 break;
2844 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2845 char *txt = m_properties_expand_string(mp_properties,
2846 cmd->args[0].v.s,
2847 mpctx);
2848 /* if no argument supplied take default osd_duration, else <arg> ms. */
2849 if (txt) {
2850 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2851 (cmd->args[1].v.i <
2852 0 ? osd_duration : cmd->args[1].v.i),
2853 "%-.63s", txt);
2854 free(txt);
2857 break;
2859 case MP_CMD_LOADFILE:{
2860 play_tree_t *e = play_tree_new();
2861 play_tree_add_file(e, cmd->args[0].v.s);
2863 if (cmd->args[1].v.i) // append
2864 play_tree_append_entry(mpctx->playtree->child, e);
2865 else {
2866 // Go back to the starting point.
2867 while (play_tree_iter_up_step
2868 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2869 /* NOP */ ;
2870 play_tree_free_list(mpctx->playtree->child, 1);
2871 play_tree_set_child(mpctx->playtree, e);
2872 pt_iter_goto_head(mpctx->playtree_iter);
2873 mpctx->stop_play = PT_NEXT_SRC;
2876 break;
2878 case MP_CMD_LOADLIST:{
2879 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2880 if (!e)
2881 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2882 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2883 else {
2884 if (cmd->args[1].v.i) // append
2885 play_tree_append_entry(mpctx->playtree->child, e);
2886 else {
2887 // Go back to the starting point.
2888 while (play_tree_iter_up_step
2889 (mpctx->playtree_iter, 0, 1)
2890 != PLAY_TREE_ITER_END)
2891 /* NOP */ ;
2892 play_tree_free_list(mpctx->playtree->child, 1);
2893 play_tree_set_child(mpctx->playtree, e);
2894 pt_iter_goto_head(mpctx->playtree_iter);
2895 mpctx->stop_play = PT_NEXT_SRC;
2899 break;
2901 case MP_CMD_STOP:
2902 // Go back to the starting point.
2903 while (play_tree_iter_up_step
2904 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2905 /* NOP */ ;
2906 mpctx->stop_play = PT_STOP;
2907 break;
2909 #ifdef CONFIG_RADIO
2910 case MP_CMD_RADIO_STEP_CHANNEL:
2911 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2912 int v = cmd->args[0].v.i;
2913 if (v > 0)
2914 radio_step_channel(mpctx->demuxer->stream,
2915 RADIO_CHANNEL_HIGHER);
2916 else
2917 radio_step_channel(mpctx->demuxer->stream,
2918 RADIO_CHANNEL_LOWER);
2919 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2920 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2921 "Channel: %s",
2922 radio_get_channel_name(mpctx->demuxer->stream));
2925 break;
2927 case MP_CMD_RADIO_SET_CHANNEL:
2928 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2929 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2930 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2931 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2932 "Channel: %s",
2933 radio_get_channel_name(mpctx->demuxer->stream));
2936 break;
2938 case MP_CMD_RADIO_SET_FREQ:
2939 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2940 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2941 break;
2943 case MP_CMD_RADIO_STEP_FREQ:
2944 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2945 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2946 break;
2947 #endif
2949 #ifdef CONFIG_TV
2950 case MP_CMD_TV_START_SCAN:
2951 if (mpctx->file_format == DEMUXER_TYPE_TV)
2952 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2953 break;
2954 case MP_CMD_TV_SET_FREQ:
2955 if (mpctx->file_format == DEMUXER_TYPE_TV)
2956 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2957 cmd->args[0].v.f * 16.0);
2958 #ifdef CONFIG_PVR
2959 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2960 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2961 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2962 pvr_get_current_channelname (mpctx->stream),
2963 pvr_get_current_stationname (mpctx->stream));
2965 #endif /* CONFIG_PVR */
2966 break;
2968 case MP_CMD_TV_STEP_FREQ:
2969 if (mpctx->file_format == DEMUXER_TYPE_TV)
2970 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2971 cmd->args[0].v.f * 16.0);
2972 #ifdef CONFIG_PVR
2973 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2974 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2975 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2976 pvr_get_current_channelname (mpctx->stream),
2977 pvr_get_current_frequency (mpctx->stream));
2979 #endif /* CONFIG_PVR */
2980 break;
2982 case MP_CMD_TV_SET_NORM:
2983 if (mpctx->file_format == DEMUXER_TYPE_TV)
2984 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2985 cmd->args[0].v.s);
2986 break;
2988 case MP_CMD_TV_STEP_CHANNEL:{
2989 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2990 int v = cmd->args[0].v.i;
2991 if (v > 0) {
2992 tv_step_channel((tvi_handle_t *) (mpctx->
2993 demuxer->priv),
2994 TV_CHANNEL_HIGHER);
2995 } else {
2996 tv_step_channel((tvi_handle_t *) (mpctx->
2997 demuxer->priv),
2998 TV_CHANNEL_LOWER);
3000 if (tv_channel_list) {
3001 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3002 "Channel: %s", tv_channel_current->name);
3003 //vo_osd_changed(OSDTYPE_SUBTITLE);
3006 #ifdef CONFIG_PVR
3007 else if (mpctx->stream &&
3008 mpctx->stream->type == STREAMTYPE_PVR) {
3009 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3010 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3011 pvr_get_current_channelname (mpctx->stream),
3012 pvr_get_current_stationname (mpctx->stream));
3014 #endif /* CONFIG_PVR */
3016 #ifdef CONFIG_DVBIN
3017 if (mpctx->stream->type == STREAMTYPE_DVB) {
3018 int dir;
3019 int v = cmd->args[0].v.i;
3021 mpctx->last_dvb_step = v;
3022 if (v > 0)
3023 dir = DVB_CHANNEL_HIGHER;
3024 else
3025 dir = DVB_CHANNEL_LOWER;
3028 if (dvb_step_channel(mpctx->stream, dir)) {
3029 mpctx->stop_play = PT_NEXT_ENTRY;
3030 mpctx->dvbin_reopen = 1;
3033 #endif /* CONFIG_DVBIN */
3034 break;
3036 case MP_CMD_TV_SET_CHANNEL:
3037 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3038 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3039 cmd->args[0].v.s);
3040 if (tv_channel_list) {
3041 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3042 "Channel: %s", tv_channel_current->name);
3043 //vo_osd_changed(OSDTYPE_SUBTITLE);
3046 #ifdef CONFIG_PVR
3047 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3048 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3049 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3050 pvr_get_current_channelname (mpctx->stream),
3051 pvr_get_current_stationname (mpctx->stream));
3053 #endif /* CONFIG_PVR */
3054 break;
3056 #ifdef CONFIG_DVBIN
3057 case MP_CMD_DVB_SET_CHANNEL:
3058 if (mpctx->stream->type == STREAMTYPE_DVB) {
3059 mpctx->last_dvb_step = 1;
3061 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3062 cmd->args[0].v.i)) {
3063 mpctx->stop_play = PT_NEXT_ENTRY;
3064 mpctx->dvbin_reopen = 1;
3067 break;
3068 #endif /* CONFIG_DVBIN */
3070 case MP_CMD_TV_LAST_CHANNEL:
3071 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3072 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3073 if (tv_channel_list) {
3074 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3075 "Channel: %s", tv_channel_current->name);
3076 //vo_osd_changed(OSDTYPE_SUBTITLE);
3079 #ifdef CONFIG_PVR
3080 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3081 pvr_set_lastchannel (mpctx->stream);
3082 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3083 pvr_get_current_channelname (mpctx->stream),
3084 pvr_get_current_stationname (mpctx->stream));
3086 #endif /* CONFIG_PVR */
3087 break;
3089 case MP_CMD_TV_STEP_NORM:
3090 if (mpctx->file_format == DEMUXER_TYPE_TV)
3091 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3092 break;
3094 case MP_CMD_TV_STEP_CHANNEL_LIST:
3095 if (mpctx->file_format == DEMUXER_TYPE_TV)
3096 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3097 break;
3098 #endif /* CONFIG_TV */
3099 case MP_CMD_TV_TELETEXT_ADD_DEC:
3101 if (mpctx->demuxer->teletext)
3102 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3103 &(cmd->args[0].v.s));
3104 break;
3106 case MP_CMD_TV_TELETEXT_GO_LINK:
3108 if (mpctx->demuxer->teletext)
3109 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3110 &(cmd->args[0].v.i));
3111 break;
3114 case MP_CMD_SUB_LOAD:
3115 if (sh_video) {
3116 int n = mpctx->set_of_sub_size;
3117 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3118 if (n != mpctx->set_of_sub_size) {
3119 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
3120 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
3121 mpctx->global_sub_size;
3122 ++mpctx->global_sub_size;
3125 break;
3127 case MP_CMD_SUB_REMOVE:
3128 if (sh_video) {
3129 int v = cmd->args[0].v.i;
3130 if (v < 0) {
3131 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3132 } else if (v < mpctx->set_of_sub_size) {
3133 remove_subtitle_range(mpctx, v, 1);
3136 break;
3138 case MP_CMD_GET_SUB_VISIBILITY:
3139 if (sh_video) {
3140 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3141 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3143 break;
3145 case MP_CMD_SCREENSHOT:
3146 if (mpctx->video_out && mpctx->video_out->config_ok) {
3147 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3148 if (CONTROL_OK !=
3149 ((vf_instance_t *) sh_video->vfilter)->
3150 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3151 &cmd->args[0].v.i))
3152 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3154 break;
3156 case MP_CMD_AF_EQ_SET:{
3157 af_instance_t* m1=af_get(sh_audio->afilter, "equalizer");
3158 if (m1) m1->control( m1, AF_CONTROL_COMMAND_LINE, cmd->args[0].v.s);
3159 else mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -af equalizer=0:0 ?)\n");
3161 break;
3163 case MP_CMD_VF_CHANGE_RECTANGLE:
3164 if (!sh_video)
3165 break;
3166 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3167 break;
3169 case MP_CMD_GET_TIME_LENGTH:{
3170 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3171 demuxer_get_time_length(mpctx->demuxer));
3173 break;
3175 case MP_CMD_GET_FILENAME:{
3176 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3177 get_metadata(mpctx, META_NAME));
3179 break;
3181 case MP_CMD_GET_VIDEO_CODEC:{
3182 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3183 if (!inf)
3184 inf = strdup("");
3185 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3186 free(inf);
3188 break;
3190 case MP_CMD_GET_VIDEO_BITRATE:{
3191 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3192 if (!inf)
3193 inf = strdup("");
3194 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3195 free(inf);
3197 break;
3199 case MP_CMD_GET_VIDEO_RESOLUTION:{
3200 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3201 if (!inf)
3202 inf = strdup("");
3203 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3204 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3205 free(inf);
3207 break;
3209 case MP_CMD_GET_AUDIO_CODEC:{
3210 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3211 if (!inf)
3212 inf = strdup("");
3213 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3214 free(inf);
3216 break;
3218 case MP_CMD_GET_AUDIO_BITRATE:{
3219 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3220 if (!inf)
3221 inf = strdup("");
3222 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3223 free(inf);
3225 break;
3227 case MP_CMD_GET_AUDIO_SAMPLES:{
3228 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3229 if (!inf)
3230 inf = strdup("");
3231 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3232 free(inf);
3234 break;
3236 case MP_CMD_GET_META_TITLE:{
3237 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3238 if (!inf)
3239 inf = strdup("");
3240 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3241 free(inf);
3243 break;
3245 case MP_CMD_GET_META_ARTIST:{
3246 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3247 if (!inf)
3248 inf = strdup("");
3249 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3250 free(inf);
3252 break;
3254 case MP_CMD_GET_META_ALBUM:{
3255 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3256 if (!inf)
3257 inf = strdup("");
3258 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3259 free(inf);
3261 break;
3263 case MP_CMD_GET_META_YEAR:{
3264 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3265 if (!inf)
3266 inf = strdup("");
3267 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3268 free(inf);
3270 break;
3272 case MP_CMD_GET_META_COMMENT:{
3273 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3274 if (!inf)
3275 inf = strdup("");
3276 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3277 free(inf);
3279 break;
3281 case MP_CMD_GET_META_TRACK:{
3282 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3283 if (!inf)
3284 inf = strdup("");
3285 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3286 free(inf);
3288 break;
3290 case MP_CMD_GET_META_GENRE:{
3291 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3292 if (!inf)
3293 inf = strdup("");
3294 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3295 free(inf);
3297 break;
3299 case MP_CMD_GET_VO_FULLSCREEN:
3300 if (mpctx->video_out && mpctx->video_out->config_ok)
3301 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3302 break;
3304 case MP_CMD_GET_PERCENT_POS:
3305 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3306 demuxer_get_percent_pos(mpctx->demuxer));
3307 break;
3309 case MP_CMD_GET_TIME_POS:{
3310 float pos = 0;
3311 if (sh_video)
3312 pos = sh_video->pts;
3313 else if (sh_audio && mpctx->audio_out)
3314 pos = playing_audio_pts(mpctx);
3315 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3317 break;
3319 case MP_CMD_RUN:
3320 #ifndef __MINGW32__
3321 if (!fork()) {
3322 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3323 exit(0);
3325 #endif
3326 break;
3328 case MP_CMD_KEYDOWN_EVENTS:
3329 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3330 break;
3332 case MP_CMD_SET_MOUSE_POS:{
3333 int pointer_x, pointer_y;
3334 double dx, dy;
3335 pointer_x = cmd->args[0].v.i;
3336 pointer_y = cmd->args[1].v.i;
3337 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3338 #ifdef CONFIG_DVDNAV
3339 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3340 && dx > 0.0 && dy > 0.0) {
3341 int button = -1;
3342 pointer_x = (int) (dx * (double) sh_video->disp_w);
3343 pointer_y = (int) (dy * (double) sh_video->disp_h);
3344 mp_dvdnav_update_mouse_pos(mpctx->stream,
3345 pointer_x, pointer_y, &button);
3346 if (opts->osd_level > 1 && button > 0)
3347 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3348 "Selected button number %d", button);
3350 #endif
3351 #ifdef CONFIG_MENU
3352 if (use_menu && dx >= 0.0 && dy >= 0.0)
3353 menu_update_mouse_pos(dx, dy);
3354 #endif
3356 break;
3358 #ifdef CONFIG_DVDNAV
3359 case MP_CMD_DVDNAV:{
3360 int button = -1;
3361 int i;
3362 mp_command_type command = 0;
3363 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3364 break;
3366 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3367 if (cmd->args[0].v.s &&
3368 !strcasecmp (cmd->args[0].v.s,
3369 mp_dvdnav_bindings[i].name))
3370 command = mp_dvdnav_bindings[i].cmd;
3372 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3373 if (opts->osd_level > 1 && button > 0)
3374 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3375 "Selected button number %d", button);
3377 break;
3379 case MP_CMD_SWITCH_TITLE:
3380 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3381 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3382 break;
3384 #endif
3386 default:
3387 mp_msg(MSGT_CPLAYER, MSGL_V,
3388 "Received unknown cmd %s\n", cmd->name);
3391 switch (cmd->pausing) {
3392 case 1: // "pausing"
3393 pause_player(mpctx);
3394 break;
3395 case 3: // "pausing_toggle"
3396 if (mpctx->paused)
3397 unpause_player(mpctx);
3398 else
3399 pause_player(mpctx);
3400 break;