Merge svn changes up to r30876
[mplayer/kovensky.git] / command.c
blob54b1332d16231558a32f4b7b52474d085b54c5b5
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 "help_mp.h"
38 #include "metadata.h"
39 #include "libmpcodecs/vf.h"
40 #include "libmpcodecs/vd.h"
41 #include "mp_osd.h"
42 #include "libvo/video_out.h"
43 #include "libvo/font_load.h"
44 #include "playtree.h"
45 #include "libao2/audio_out.h"
46 #include "mpcommon.h"
47 #include "mixer.h"
48 #include "libmpcodecs/dec_video.h"
49 #include "libmpcodecs/dec_teletext.h"
50 #include "vobsub.h"
51 #include "spudec.h"
52 #include "get_path.h"
53 #include "ass_mp.h"
54 #include "stream/tv.h"
55 #include "stream/stream_radio.h"
56 #include "stream/pvr.h"
57 #ifdef CONFIG_DVBIN
58 #include "stream/dvbin.h"
59 #endif
60 #ifdef CONFIG_DVDREAD
61 #include "stream/stream_dvd.h"
62 #endif
63 #include "stream/stream_dvdnav.h"
64 #include "m_struct.h"
65 #include "libmenu/menu.h"
67 #include "mp_core.h"
68 #include "mp_fifo.h"
69 #include "libavutil/avstring.h"
71 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
73 extern int use_menu;
75 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
76 double *dx, double *dy)
78 struct MPOpts *opts = &mpctx->opts;
79 struct vo *vo = mpctx->video_out;
80 //remove the borders, if any, and rescale to the range [0,1],[0,1]
81 if (vo_fs) { //we are in full-screen mode
82 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
83 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
84 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
85 iy -= (opts->vo_screenheight - vo->dheight) / 2;
87 if (ix < 0 || ix > vo->dwidth) {
88 *dx = *dy = -1.0;
89 return;
90 } //we are on one of the borders
91 if (iy < 0 || iy > vo->dheight) {
92 *dx = *dy = -1.0;
93 return;
94 } //we are on one of the borders
97 *dx = (double) ix / (double) vo->dwidth;
98 *dy = (double) iy / (double) vo->dheight;
100 mp_msg(MSGT_CPLAYER, MSGL_V,
101 "\r\nrescaled coordinates: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
102 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
103 vo->dheight, vo_fs);
106 static int sub_source_by_pos(MPContext *mpctx, int pos)
108 int source = -1;
109 int top = -1;
110 int i;
111 for (i = 0; i < SUB_SOURCES; i++) {
112 int j = mpctx->global_sub_indices[i];
113 if ((j >= 0) && (j > top) && (pos >= j)) {
114 source = i;
115 top = j;
118 return source;
121 static int sub_source(MPContext *mpctx)
123 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
127 * \brief Log the currently displayed subtitle to a file
129 * Logs the current or last displayed subtitle together with filename
130 * and time information to ~/.mplayer/subtitle_log
132 * Intended purpose is to allow convenient marking of bogus subtitles
133 * which need to be fixed while watching the movie.
136 static void log_sub(struct MPContext *mpctx)
138 char *fname;
139 FILE *f;
140 int i;
142 if (subdata == NULL || vo_sub_last == NULL)
143 return;
144 fname = get_path("subtitle_log");
145 f = fopen(fname, "a");
146 if (!f)
147 return;
148 fprintf(f, "----------------------------------------------------------\n");
149 if (subdata->sub_uses_time) {
150 fprintf(f,
151 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
152 mpctx->filename, vo_sub_last->start / 360000,
153 (vo_sub_last->start / 6000) % 60,
154 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
155 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
156 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
157 } else {
158 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
159 vo_sub_last->start, vo_sub_last->end);
161 for (i = 0; i < vo_sub_last->lines; i++) {
162 fprintf(f, "%s\n", vo_sub_last->text[i]);
164 fclose(f);
168 /// \defgroup Properties
169 ///@{
171 /// \defgroup GeneralProperties General properties
172 /// \ingroup Properties
173 ///@{
175 /// OSD level (RW)
176 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
177 MPContext *mpctx)
179 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
182 /// Loop (RW)
183 static int mp_property_loop(m_option_t *prop, int action, void *arg,
184 MPContext *mpctx)
186 struct MPOpts *opts = &mpctx->opts;
187 switch (action) {
188 case M_PROPERTY_PRINT:
189 if (!arg) return M_PROPERTY_ERROR;
190 if (opts->loop_times < 0)
191 *(char**)arg = strdup("off");
192 else if (opts->loop_times == 0)
193 *(char**)arg = strdup("inf");
194 else
195 break;
196 return M_PROPERTY_OK;
198 return m_property_int_range(prop, action, arg, &opts->loop_times);
201 /// Playback speed (RW)
202 static int mp_property_playback_speed(m_option_t *prop, int action,
203 void *arg, MPContext *mpctx)
205 struct MPOpts *opts = &mpctx->opts;
206 switch (action) {
207 case M_PROPERTY_SET:
208 if (!arg)
209 return M_PROPERTY_ERROR;
210 M_PROPERTY_CLAMP(prop, *(float *) arg);
211 opts->playback_speed = *(float *) arg;
212 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
213 return M_PROPERTY_OK;
214 case M_PROPERTY_STEP_UP:
215 case M_PROPERTY_STEP_DOWN:
216 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
217 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
218 M_PROPERTY_CLAMP(prop, opts->playback_speed);
219 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
220 return M_PROPERTY_OK;
222 return m_property_float_range(prop, action, arg, &opts->playback_speed);
225 /// filename with path (RO)
226 static int mp_property_path(m_option_t *prop, int action, void *arg,
227 MPContext *mpctx)
229 return m_property_string_ro(prop, action, arg, mpctx->filename);
232 /// filename without path (RO)
233 static int mp_property_filename(m_option_t *prop, int action, void *arg,
234 MPContext *mpctx)
236 char *f;
237 if (!mpctx->filename)
238 return M_PROPERTY_UNAVAILABLE;
239 if (((f = strrchr(mpctx->filename, '/'))
240 || (f = strrchr(mpctx->filename, '\\'))) && f[1])
241 f++;
242 else
243 f = mpctx->filename;
244 return m_property_string_ro(prop, action, arg, f);
247 /// Demuxer name (RO)
248 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
249 MPContext *mpctx)
251 if (!mpctx->demuxer)
252 return M_PROPERTY_UNAVAILABLE;
253 return m_property_string_ro(prop, action, arg,
254 (char *) mpctx->demuxer->desc->name);
257 /// Position in the stream (RW)
258 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
259 MPContext *mpctx)
261 if (!mpctx->demuxer || !mpctx->demuxer->stream)
262 return M_PROPERTY_UNAVAILABLE;
263 if (!arg)
264 return M_PROPERTY_ERROR;
265 switch (action) {
266 case M_PROPERTY_GET:
267 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
268 return M_PROPERTY_OK;
269 case M_PROPERTY_SET:
270 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
271 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
272 return M_PROPERTY_OK;
274 return M_PROPERTY_NOT_IMPLEMENTED;
277 /// Stream start offset (RO)
278 static int mp_property_stream_start(m_option_t *prop, int action,
279 void *arg, MPContext *mpctx)
281 if (!mpctx->demuxer || !mpctx->demuxer->stream)
282 return M_PROPERTY_UNAVAILABLE;
283 switch (action) {
284 case M_PROPERTY_GET:
285 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
286 return M_PROPERTY_OK;
288 return M_PROPERTY_NOT_IMPLEMENTED;
291 /// Stream end offset (RO)
292 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
293 MPContext *mpctx)
295 if (!mpctx->demuxer || !mpctx->demuxer->stream)
296 return M_PROPERTY_UNAVAILABLE;
297 switch (action) {
298 case M_PROPERTY_GET:
299 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
300 return M_PROPERTY_OK;
302 return M_PROPERTY_NOT_IMPLEMENTED;
305 /// Stream length (RO)
306 static int mp_property_stream_length(m_option_t *prop, int action,
307 void *arg, MPContext *mpctx)
309 if (!mpctx->demuxer || !mpctx->demuxer->stream)
310 return M_PROPERTY_UNAVAILABLE;
311 switch (action) {
312 case M_PROPERTY_GET:
313 *(off_t *) arg =
314 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
315 return M_PROPERTY_OK;
317 return M_PROPERTY_NOT_IMPLEMENTED;
320 /// Media length in seconds (RO)
321 static int mp_property_length(m_option_t *prop, int action, void *arg,
322 MPContext *mpctx)
324 double len;
326 if (!mpctx->demuxer ||
327 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
328 return M_PROPERTY_UNAVAILABLE;
330 return m_property_time_ro(prop, action, arg, len);
333 /// Current position in percent (RW)
334 static int mp_property_percent_pos(m_option_t *prop, int action,
335 void *arg, MPContext *mpctx) {
336 int pos;
338 if (!mpctx->demuxer)
339 return M_PROPERTY_UNAVAILABLE;
341 switch(action) {
342 case M_PROPERTY_SET:
343 if(!arg) return M_PROPERTY_ERROR;
344 M_PROPERTY_CLAMP(prop, *(int*)arg);
345 pos = *(int*)arg;
346 break;
347 case M_PROPERTY_STEP_UP:
348 case M_PROPERTY_STEP_DOWN:
349 pos = demuxer_get_percent_pos(mpctx->demuxer);
350 pos += (arg ? *(int*)arg : 10) *
351 (action == M_PROPERTY_STEP_UP ? 1 : -1);
352 M_PROPERTY_CLAMP(prop, pos);
353 break;
354 default:
355 return m_property_int_ro(prop, action, arg,
356 demuxer_get_percent_pos(mpctx->demuxer));
359 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
360 mpctx->rel_seek_secs = pos / 100.0;
361 return M_PROPERTY_OK;
364 /// Current position in seconds (RW)
365 static int mp_property_time_pos(m_option_t *prop, int action,
366 void *arg, MPContext *mpctx) {
367 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
368 return M_PROPERTY_UNAVAILABLE;
370 switch(action) {
371 case M_PROPERTY_SET:
372 if(!arg) return M_PROPERTY_ERROR;
373 M_PROPERTY_CLAMP(prop, *(double*)arg);
374 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
375 mpctx->rel_seek_secs = *(double*)arg;
376 return M_PROPERTY_OK;
377 case M_PROPERTY_STEP_UP:
378 case M_PROPERTY_STEP_DOWN:
379 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
380 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
381 return M_PROPERTY_OK;
383 return m_property_time_ro(prop, action, arg,
384 mpctx->sh_video ? mpctx->sh_video->pts :
385 playing_audio_pts(mpctx));
388 /// Current chapter (RW)
389 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
390 MPContext *mpctx)
392 struct MPOpts *opts = &mpctx->opts;
393 int chapter = -1;
394 int step_all;
395 char *chapter_name = NULL;
397 if (mpctx->demuxer)
398 chapter = get_current_chapter(mpctx);
399 if (chapter < 0)
400 return M_PROPERTY_UNAVAILABLE;
402 switch (action) {
403 case M_PROPERTY_GET:
404 if (!arg)
405 return M_PROPERTY_ERROR;
406 *(int *) arg = chapter;
407 return M_PROPERTY_OK;
408 case M_PROPERTY_PRINT: {
409 if (!arg)
410 return M_PROPERTY_ERROR;
411 chapter_name = chapter_display_name(mpctx, chapter);
412 if (!chapter_name)
413 return M_PROPERTY_UNAVAILABLE;
414 *(char **) arg = chapter_name;
415 return M_PROPERTY_OK;
417 case M_PROPERTY_SET:
418 if (!arg)
419 return M_PROPERTY_ERROR;
420 M_PROPERTY_CLAMP(prop, *(int*)arg);
421 step_all = *(int *)arg - chapter;
422 chapter += step_all;
423 break;
424 case M_PROPERTY_STEP_UP:
425 case M_PROPERTY_STEP_DOWN: {
426 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
427 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
428 chapter += step_all;
429 if (chapter < 0)
430 chapter = 0;
431 break;
433 default:
434 return M_PROPERTY_NOT_IMPLEMENTED;
437 double next_pts = 0;
438 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
439 mpctx->rel_seek_secs = 0;
440 mpctx->abs_seek_pos = 0;
441 if (chapter >= 0) {
442 if (next_pts > -1.0) {
443 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
444 mpctx->rel_seek_secs = next_pts;
446 if (chapter_name)
447 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
448 "Chapter: (%d) %s", chapter + 1, chapter_name);
450 else if (step_all > 0)
451 mpctx->rel_seek_secs = 1000000000.;
452 else
453 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
454 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
455 if (chapter_name)
456 talloc_free(chapter_name);
457 return M_PROPERTY_OK;
460 /// Number of chapters in file
461 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
462 MPContext *mpctx)
464 if (!mpctx->demuxer)
465 return M_PROPERTY_UNAVAILABLE;
466 if (mpctx->demuxer->num_chapters == 0)
467 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
468 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
471 /// Current dvd angle (RW)
472 static int mp_property_angle(m_option_t *prop, int action, void *arg,
473 MPContext *mpctx)
475 struct MPOpts *opts = &mpctx->opts;
476 int angle = -1;
477 int angles;
478 char *angle_name = NULL;
480 if (mpctx->demuxer)
481 angle = demuxer_get_current_angle(mpctx->demuxer);
482 if (angle < 0)
483 return M_PROPERTY_UNAVAILABLE;
484 angles = demuxer_angles_count(mpctx->demuxer);
485 if (angles <= 1)
486 return M_PROPERTY_UNAVAILABLE;
488 switch (action) {
489 case M_PROPERTY_GET:
490 if (!arg)
491 return M_PROPERTY_ERROR;
492 *(int *) arg = angle;
493 return M_PROPERTY_OK;
494 case M_PROPERTY_PRINT: {
495 if (!arg)
496 return M_PROPERTY_ERROR;
497 angle_name = calloc(1, 64);
498 if (!angle_name)
499 return M_PROPERTY_UNAVAILABLE;
500 snprintf(angle_name, 64, "%d/%d", angle, angles);
501 *(char **) arg = angle_name;
502 return M_PROPERTY_OK;
504 case M_PROPERTY_SET:
505 if (!arg)
506 return M_PROPERTY_ERROR;
507 angle = *(int *)arg;
508 M_PROPERTY_CLAMP(prop, angle);
509 break;
510 case M_PROPERTY_STEP_UP:
511 case M_PROPERTY_STEP_DOWN: {
512 int step = 0;
513 if(arg)
514 step = *(int*)arg;
515 if(!step)
516 step = 1;
517 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
518 angle += step;
519 if (angle < 1) //cycle
520 angle = angles;
521 break;
523 default:
524 return M_PROPERTY_NOT_IMPLEMENTED;
526 angle = demuxer_set_angle(mpctx->demuxer, angle);
527 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
528 "Angle: %d/%d", angle, angles);
529 if (angle_name)
530 free(angle_name);
531 return M_PROPERTY_OK;
534 /// Demuxer meta data
535 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
536 MPContext *mpctx) {
537 m_property_action_t* ka;
538 char* meta;
539 static const m_option_t key_type =
540 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
541 if (!mpctx->demuxer)
542 return M_PROPERTY_UNAVAILABLE;
544 switch(action) {
545 case M_PROPERTY_GET:
546 if(!arg) return M_PROPERTY_ERROR;
547 *(char***)arg = mpctx->demuxer->info;
548 return M_PROPERTY_OK;
549 case M_PROPERTY_KEY_ACTION:
550 if(!arg) return M_PROPERTY_ERROR;
551 ka = arg;
552 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
553 return M_PROPERTY_UNKNOWN;
554 switch(ka->action) {
555 case M_PROPERTY_GET:
556 if(!ka->arg) return M_PROPERTY_ERROR;
557 *(char**)ka->arg = meta;
558 return M_PROPERTY_OK;
559 case M_PROPERTY_GET_TYPE:
560 if(!ka->arg) return M_PROPERTY_ERROR;
561 *(m_option_t**)ka->arg = &key_type;
562 return M_PROPERTY_OK;
565 return M_PROPERTY_NOT_IMPLEMENTED;
568 static int mp_property_pause(m_option_t *prop, int action, void *arg,
569 void *ctx)
571 MPContext *mpctx = ctx;
573 switch (action) {
574 case M_PROPERTY_SET:
575 if (!arg)
576 return M_PROPERTY_ERROR;
577 if (mpctx->paused == (bool)*(int *) arg)
578 return M_PROPERTY_OK;
579 case M_PROPERTY_STEP_UP:
580 case M_PROPERTY_STEP_DOWN:
581 if (mpctx->paused) {
582 unpause_player(mpctx);
583 mpctx->osd_function = OSD_PLAY;
585 else {
586 pause_player(mpctx);
587 mpctx->osd_function = OSD_PAUSE;
589 return M_PROPERTY_OK;
590 default:
591 return m_property_flag(prop, action, arg, &mpctx->paused);
596 ///@}
598 /// \defgroup AudioProperties Audio properties
599 /// \ingroup Properties
600 ///@{
602 /// Volume (RW)
603 static int mp_property_volume(m_option_t *prop, int action, void *arg,
604 MPContext *mpctx)
607 if (!mpctx->sh_audio)
608 return M_PROPERTY_UNAVAILABLE;
610 switch (action) {
611 case M_PROPERTY_GET:
612 if (!arg)
613 return M_PROPERTY_ERROR;
614 mixer_getbothvolume(&mpctx->mixer, arg);
615 return M_PROPERTY_OK;
616 case M_PROPERTY_PRINT:{
617 float vol;
618 if (!arg)
619 return M_PROPERTY_ERROR;
620 mixer_getbothvolume(&mpctx->mixer, &vol);
621 return m_property_float_range(prop, action, arg, &vol);
623 case M_PROPERTY_STEP_UP:
624 case M_PROPERTY_STEP_DOWN:
625 case M_PROPERTY_SET:
626 break;
627 default:
628 return M_PROPERTY_NOT_IMPLEMENTED;
631 if (mpctx->edl_muted)
632 return M_PROPERTY_DISABLED;
633 mpctx->user_muted = 0;
635 switch (action) {
636 case M_PROPERTY_SET:
637 if (!arg)
638 return M_PROPERTY_ERROR;
639 M_PROPERTY_CLAMP(prop, *(float *) arg);
640 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
641 return M_PROPERTY_OK;
642 case M_PROPERTY_STEP_UP:
643 if (arg && *(float *) arg <= 0)
644 mixer_decvolume(&mpctx->mixer);
645 else
646 mixer_incvolume(&mpctx->mixer);
647 return M_PROPERTY_OK;
648 case M_PROPERTY_STEP_DOWN:
649 if (arg && *(float *) arg <= 0)
650 mixer_incvolume(&mpctx->mixer);
651 else
652 mixer_decvolume(&mpctx->mixer);
653 return M_PROPERTY_OK;
655 return M_PROPERTY_NOT_IMPLEMENTED;
658 /// Mute (RW)
659 static int mp_property_mute(m_option_t *prop, int action, void *arg,
660 MPContext *mpctx)
663 if (!mpctx->sh_audio)
664 return M_PROPERTY_UNAVAILABLE;
666 switch (action) {
667 case M_PROPERTY_SET:
668 if (mpctx->edl_muted)
669 return M_PROPERTY_DISABLED;
670 if (!arg)
671 return M_PROPERTY_ERROR;
672 if ((!!*(int *) arg) != mpctx->mixer.muted)
673 mixer_mute(&mpctx->mixer);
674 mpctx->user_muted = mpctx->mixer.muted;
675 return M_PROPERTY_OK;
676 case M_PROPERTY_STEP_UP:
677 case M_PROPERTY_STEP_DOWN:
678 if (mpctx->edl_muted)
679 return M_PROPERTY_DISABLED;
680 mixer_mute(&mpctx->mixer);
681 mpctx->user_muted = mpctx->mixer.muted;
682 return M_PROPERTY_OK;
683 case M_PROPERTY_PRINT:
684 if (!arg)
685 return M_PROPERTY_ERROR;
686 if (mpctx->edl_muted) {
687 *(char **) arg = strdup(mp_gtext("enabled (EDL)"));
688 return M_PROPERTY_OK;
690 default:
691 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
696 /// Audio delay (RW)
697 static int mp_property_audio_delay(m_option_t *prop, int action,
698 void *arg, MPContext *mpctx)
700 if (!(mpctx->sh_audio && mpctx->sh_video))
701 return M_PROPERTY_UNAVAILABLE;
702 switch (action) {
703 case M_PROPERTY_SET:
704 case M_PROPERTY_STEP_UP:
705 case M_PROPERTY_STEP_DOWN: {
706 int ret;
707 float delay = audio_delay;
708 ret = m_property_delay(prop, action, arg, &audio_delay);
709 if (ret != M_PROPERTY_OK)
710 return ret;
711 if (mpctx->sh_audio)
712 mpctx->delay -= audio_delay - delay;
714 return M_PROPERTY_OK;
715 default:
716 return m_property_delay(prop, action, arg, &audio_delay);
720 /// Audio codec tag (RO)
721 static int mp_property_audio_format(m_option_t *prop, int action,
722 void *arg, MPContext *mpctx)
724 if (!mpctx->sh_audio)
725 return M_PROPERTY_UNAVAILABLE;
726 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
729 /// Audio codec name (RO)
730 static int mp_property_audio_codec(m_option_t *prop, int action,
731 void *arg, MPContext *mpctx)
733 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
734 return M_PROPERTY_UNAVAILABLE;
735 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
738 /// Audio bitrate (RO)
739 static int mp_property_audio_bitrate(m_option_t *prop, int action,
740 void *arg, MPContext *mpctx)
742 if (!mpctx->sh_audio)
743 return M_PROPERTY_UNAVAILABLE;
744 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
747 /// Samplerate (RO)
748 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
749 MPContext *mpctx)
751 if (!mpctx->sh_audio)
752 return M_PROPERTY_UNAVAILABLE;
753 switch(action) {
754 case M_PROPERTY_PRINT:
755 if(!arg) return M_PROPERTY_ERROR;
756 *(char**)arg = malloc(16);
757 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
758 return M_PROPERTY_OK;
760 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
763 /// Number of channels (RO)
764 static int mp_property_channels(m_option_t *prop, int action, void *arg,
765 MPContext *mpctx)
767 if (!mpctx->sh_audio)
768 return M_PROPERTY_UNAVAILABLE;
769 switch (action) {
770 case M_PROPERTY_PRINT:
771 if (!arg)
772 return M_PROPERTY_ERROR;
773 switch (mpctx->sh_audio->channels) {
774 case 1:
775 *(char **) arg = strdup("mono");
776 break;
777 case 2:
778 *(char **) arg = strdup("stereo");
779 break;
780 default:
781 *(char **) arg = malloc(32);
782 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
784 return M_PROPERTY_OK;
786 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
789 /// Balance (RW)
790 static int mp_property_balance(m_option_t *prop, int action, void *arg,
791 MPContext *mpctx)
793 float bal;
795 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
796 return M_PROPERTY_UNAVAILABLE;
798 switch (action) {
799 case M_PROPERTY_GET:
800 if (!arg)
801 return M_PROPERTY_ERROR;
802 mixer_getbalance(&mpctx->mixer, arg);
803 return M_PROPERTY_OK;
804 case M_PROPERTY_PRINT: {
805 char** str = arg;
806 if (!arg)
807 return M_PROPERTY_ERROR;
808 mixer_getbalance(&mpctx->mixer, &bal);
809 if (bal == 0.f)
810 *str = strdup("center");
811 else if (bal == -1.f)
812 *str = strdup("left only");
813 else if (bal == 1.f)
814 *str = strdup("right only");
815 else {
816 unsigned right = (bal + 1.f) / 2.f * 100.f;
817 *str = malloc(sizeof("left xxx%, right xxx%"));
818 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
820 return M_PROPERTY_OK;
822 case M_PROPERTY_STEP_UP:
823 case M_PROPERTY_STEP_DOWN:
824 mixer_getbalance(&mpctx->mixer, &bal);
825 bal += (arg ? *(float*)arg : .1f) *
826 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
827 M_PROPERTY_CLAMP(prop, bal);
828 mixer_setbalance(&mpctx->mixer, bal);
829 return M_PROPERTY_OK;
830 case M_PROPERTY_SET:
831 if (!arg)
832 return M_PROPERTY_ERROR;
833 M_PROPERTY_CLAMP(prop, *(float*)arg);
834 mixer_setbalance(&mpctx->mixer, *(float*)arg);
835 return M_PROPERTY_OK;
837 return M_PROPERTY_NOT_IMPLEMENTED;
840 /// Selected audio id (RW)
841 static int mp_property_audio(m_option_t *prop, int action, void *arg,
842 MPContext *mpctx)
844 struct MPOpts *opts = &mpctx->opts;
845 int current_id, tmp;
846 if (!mpctx->demuxer || !mpctx->demuxer->audio)
847 return M_PROPERTY_UNAVAILABLE;
848 current_id = mpctx->demuxer->audio->id;
850 switch (action) {
851 case M_PROPERTY_GET:
852 if (!arg)
853 return M_PROPERTY_ERROR;
854 *(int *) arg = current_id;
855 return M_PROPERTY_OK;
856 case M_PROPERTY_PRINT:
857 if (!arg)
858 return M_PROPERTY_ERROR;
860 if (current_id < 0)
861 *(char **) arg = strdup(mp_gtext("disabled"));
862 else {
863 char lang[40];
864 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
865 sh_audio_t* sh = mpctx->sh_audio;
866 if (sh && sh->lang)
867 av_strlcpy(lang, sh->lang, 40);
868 #ifdef CONFIG_DVDREAD
869 else if (mpctx->stream->type == STREAMTYPE_DVD) {
870 int code = dvd_lang_from_aid(mpctx->stream, current_id);
871 if (code) {
872 lang[0] = code >> 8;
873 lang[1] = code;
874 lang[2] = 0;
877 #endif
879 #ifdef CONFIG_DVDNAV
880 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
881 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
882 #endif
883 *(char **) arg = malloc(64);
884 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
886 return M_PROPERTY_OK;
888 case M_PROPERTY_STEP_UP:
889 case M_PROPERTY_SET:
890 if (action == M_PROPERTY_SET && arg)
891 tmp = *((int *) arg);
892 else
893 tmp = -1;
894 opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
895 if (opts->audio_id == -2
896 || (opts->audio_id > -1
897 && mpctx->demuxer->audio->id != current_id && current_id != -2))
898 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
899 if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
900 sh_audio_t *sh2;
901 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
902 if (sh2) {
903 sh2->ds = mpctx->demuxer->audio;
904 mpctx->sh_audio = sh2;
905 reinit_audio_chain(mpctx);
908 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id);
909 return M_PROPERTY_OK;
910 default:
911 return M_PROPERTY_NOT_IMPLEMENTED;
916 /// Selected video id (RW)
917 static int mp_property_video(m_option_t *prop, int action, void *arg,
918 MPContext *mpctx)
920 struct MPOpts *opts = &mpctx->opts;
921 int current_id, tmp;
922 if (!mpctx->demuxer || !mpctx->demuxer->video)
923 return M_PROPERTY_UNAVAILABLE;
924 current_id = mpctx->demuxer->video->id;
926 switch (action) {
927 case M_PROPERTY_GET:
928 if (!arg)
929 return M_PROPERTY_ERROR;
930 *(int *) arg = current_id;
931 return M_PROPERTY_OK;
932 case M_PROPERTY_PRINT:
933 if (!arg)
934 return M_PROPERTY_ERROR;
936 if (current_id < 0)
937 *(char **) arg = strdup(mp_gtext("disabled"));
938 else {
939 char lang[40];
940 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
941 *(char **) arg = malloc(64);
942 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
944 return M_PROPERTY_OK;
946 case M_PROPERTY_STEP_UP:
947 case M_PROPERTY_SET:
948 if (action == M_PROPERTY_SET && arg)
949 tmp = *((int *) arg);
950 else
951 tmp = -1;
952 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
953 if (opts->video_id == -2
954 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
955 && current_id != -2))
956 uninit_player(mpctx, INITIALIZED_VCODEC |
957 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
958 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
959 sh_video_t *sh2;
960 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
961 if (sh2) {
962 sh2->ds = mpctx->demuxer->video;
963 mpctx->sh_video = sh2;
964 reinit_video_chain(mpctx);
967 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
968 return M_PROPERTY_OK;
970 default:
971 return M_PROPERTY_NOT_IMPLEMENTED;
975 static int mp_property_program(m_option_t *prop, int action, void *arg,
976 MPContext *mpctx)
978 demux_program_t prog;
980 switch (action) {
981 case M_PROPERTY_STEP_UP:
982 case M_PROPERTY_SET:
983 if (action == M_PROPERTY_SET && arg)
984 prog.progid = *((int *) arg);
985 else
986 prog.progid = -1;
987 if (demux_control
988 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
989 &prog) == DEMUXER_CTRL_NOTIMPL)
990 return M_PROPERTY_ERROR;
992 if (prog.aid < 0 && prog.vid < 0) {
993 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
994 return M_PROPERTY_ERROR;
996 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
997 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
998 return M_PROPERTY_OK;
1000 default:
1001 return M_PROPERTY_NOT_IMPLEMENTED;
1005 ///@}
1007 /// \defgroup VideoProperties Video properties
1008 /// \ingroup Properties
1009 ///@{
1011 /// Fullscreen state (RW)
1012 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1013 MPContext *mpctx)
1016 if (!mpctx->video_out)
1017 return M_PROPERTY_UNAVAILABLE;
1019 switch (action) {
1020 case M_PROPERTY_SET:
1021 if (!arg)
1022 return M_PROPERTY_ERROR;
1023 M_PROPERTY_CLAMP(prop, *(int *) arg);
1024 if (vo_fs == !!*(int *) arg)
1025 return M_PROPERTY_OK;
1026 case M_PROPERTY_STEP_UP:
1027 case M_PROPERTY_STEP_DOWN:
1028 if (mpctx->video_out->config_ok)
1029 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1030 mpctx->opts.fullscreen = vo_fs;
1031 return M_PROPERTY_OK;
1032 default:
1033 return m_property_flag(prop, action, arg, &vo_fs);
1037 static int mp_property_deinterlace(m_option_t *prop, int action,
1038 void *arg, MPContext *mpctx)
1040 int deinterlace;
1041 vf_instance_t *vf;
1042 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1043 return M_PROPERTY_UNAVAILABLE;
1044 vf = mpctx->sh_video->vfilter;
1045 switch (action) {
1046 case M_PROPERTY_GET:
1047 if (!arg)
1048 return M_PROPERTY_ERROR;
1049 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1050 return M_PROPERTY_OK;
1051 case M_PROPERTY_SET:
1052 if (!arg)
1053 return M_PROPERTY_ERROR;
1054 M_PROPERTY_CLAMP(prop, *(int *) arg);
1055 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1056 return M_PROPERTY_OK;
1057 case M_PROPERTY_STEP_UP:
1058 case M_PROPERTY_STEP_DOWN:
1059 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1060 deinterlace = !deinterlace;
1061 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1062 return M_PROPERTY_OK;
1064 int value = 0;
1065 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1066 return m_property_flag_ro(prop, action, arg, value);
1069 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1070 void *arg, MPContext *mpctx)
1072 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1073 return M_PROPERTY_UNAVAILABLE;
1075 struct vf_instance *vf = mpctx->sh_video->vfilter;
1076 int colorspace;
1077 switch (action) {
1078 case M_PROPERTY_GET:
1079 if (!arg)
1080 return M_PROPERTY_ERROR;
1081 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1082 return M_PROPERTY_UNAVAILABLE;
1083 return M_PROPERTY_OK;
1084 case M_PROPERTY_PRINT:
1085 if (!arg)
1086 return M_PROPERTY_ERROR;
1087 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1088 return M_PROPERTY_UNAVAILABLE;
1089 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1090 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1091 *(char **)arg = strdup("Unknown");
1092 else
1093 *(char**)arg = strdup(names[colorspace]);
1094 return M_PROPERTY_OK;
1095 case M_PROPERTY_SET:
1096 if (!arg)
1097 return M_PROPERTY_ERROR;
1098 M_PROPERTY_CLAMP(prop, *(int *) arg);
1099 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1100 return M_PROPERTY_OK;
1101 case M_PROPERTY_STEP_UP:;
1102 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1103 return M_PROPERTY_UNAVAILABLE;
1104 colorspace += 1;
1105 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1106 return M_PROPERTY_OK;
1108 return M_PROPERTY_NOT_IMPLEMENTED;
1111 /// Panscan (RW)
1112 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1113 MPContext *mpctx)
1116 if (!mpctx->video_out
1117 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1118 return M_PROPERTY_UNAVAILABLE;
1120 switch (action) {
1121 case M_PROPERTY_SET:
1122 if (!arg)
1123 return M_PROPERTY_ERROR;
1124 M_PROPERTY_CLAMP(prop, *(float *) arg);
1125 vo_panscan = *(float *) arg;
1126 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1127 return M_PROPERTY_OK;
1128 case M_PROPERTY_STEP_UP:
1129 case M_PROPERTY_STEP_DOWN:
1130 vo_panscan += (arg ? *(float *) arg : 0.1) *
1131 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1132 if (vo_panscan > 1)
1133 vo_panscan = 1;
1134 else if (vo_panscan < 0)
1135 vo_panscan = 0;
1136 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1137 return M_PROPERTY_OK;
1138 default:
1139 return m_property_float_range(prop, action, arg, &vo_panscan);
1143 /// Helper to set vo flags.
1144 /** \ingroup PropertyImplHelper
1146 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1147 int vo_ctrl, int *vo_var, MPContext *mpctx)
1150 if (!mpctx->video_out)
1151 return M_PROPERTY_UNAVAILABLE;
1153 switch (action) {
1154 case M_PROPERTY_SET:
1155 if (!arg)
1156 return M_PROPERTY_ERROR;
1157 M_PROPERTY_CLAMP(prop, *(int *) arg);
1158 if (*vo_var == !!*(int *) arg)
1159 return M_PROPERTY_OK;
1160 case M_PROPERTY_STEP_UP:
1161 case M_PROPERTY_STEP_DOWN:
1162 if (mpctx->video_out->config_ok)
1163 vo_control(mpctx->video_out, vo_ctrl, 0);
1164 return M_PROPERTY_OK;
1165 default:
1166 return m_property_flag(prop, action, arg, vo_var);
1170 /// Window always on top (RW)
1171 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1172 MPContext *mpctx)
1174 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1175 &mpctx->opts.vo_ontop, mpctx);
1178 /// Display in the root window (RW)
1179 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1180 MPContext *mpctx)
1182 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1183 &vo_rootwin, mpctx);
1186 /// Show window borders (RW)
1187 static int mp_property_border(m_option_t *prop, int action, void *arg,
1188 MPContext *mpctx)
1190 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1191 &vo_border, mpctx);
1194 /// Framedropping state (RW)
1195 static int mp_property_framedropping(m_option_t *prop, int action,
1196 void *arg, MPContext *mpctx)
1199 if (!mpctx->sh_video)
1200 return M_PROPERTY_UNAVAILABLE;
1202 switch (action) {
1203 case M_PROPERTY_PRINT:
1204 if (!arg)
1205 return M_PROPERTY_ERROR;
1206 *(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
1207 (frame_dropping == 2 ? mp_gtext("hard") :
1208 mp_gtext("disabled")));
1209 return M_PROPERTY_OK;
1210 default:
1211 return m_property_choice(prop, action, arg, &frame_dropping);
1215 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1216 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1217 MPContext *mpctx)
1219 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1220 int r, val;
1222 if (!mpctx->sh_video)
1223 return M_PROPERTY_UNAVAILABLE;
1225 if (gamma[0] == 1000) {
1226 gamma[0] = 0;
1227 get_video_colors(mpctx->sh_video, prop->name, gamma);
1230 switch (action) {
1231 case M_PROPERTY_SET:
1232 if (!arg)
1233 return M_PROPERTY_ERROR;
1234 M_PROPERTY_CLAMP(prop, *(int *) arg);
1235 *gamma = *(int *) arg;
1236 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1237 if (r <= 0)
1238 break;
1239 return r;
1240 case M_PROPERTY_GET:
1241 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1242 if (!arg)
1243 return M_PROPERTY_ERROR;
1244 *(int *)arg = val;
1245 return M_PROPERTY_OK;
1247 break;
1248 case M_PROPERTY_STEP_UP:
1249 case M_PROPERTY_STEP_DOWN:
1250 *gamma += (arg ? *(int *) arg : 1) *
1251 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1252 M_PROPERTY_CLAMP(prop, *gamma);
1253 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1254 if (r <= 0)
1255 break;
1256 return r;
1257 default:
1258 return M_PROPERTY_NOT_IMPLEMENTED;
1261 #ifdef CONFIG_TV
1262 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1263 int l = strlen(prop->name);
1264 char tv_prop[3 + l + 1];
1265 sprintf(tv_prop, "tv_%s", prop->name);
1266 return mp_property_do(tv_prop, action, arg, mpctx);
1268 #endif
1270 return M_PROPERTY_UNAVAILABLE;
1273 /// VSync (RW)
1274 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1275 MPContext *mpctx)
1277 return m_property_flag(prop, action, arg, &vo_vsync);
1280 /// Video codec tag (RO)
1281 static int mp_property_video_format(m_option_t *prop, int action,
1282 void *arg, MPContext *mpctx)
1284 char* meta;
1285 if (!mpctx->sh_video)
1286 return M_PROPERTY_UNAVAILABLE;
1287 switch(action) {
1288 case M_PROPERTY_PRINT:
1289 if (!arg)
1290 return M_PROPERTY_ERROR;
1291 switch(mpctx->sh_video->format) {
1292 case 0x10000001:
1293 meta = strdup ("mpeg1"); break;
1294 case 0x10000002:
1295 meta = strdup ("mpeg2"); break;
1296 case 0x10000004:
1297 meta = strdup ("mpeg4"); break;
1298 case 0x10000005:
1299 meta = strdup ("h264"); break;
1300 default:
1301 if(mpctx->sh_video->format >= 0x20202020) {
1302 meta = malloc(5);
1303 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1304 } else {
1305 meta = malloc(20);
1306 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1309 *(char**)arg = meta;
1310 return M_PROPERTY_OK;
1312 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1315 /// Video codec name (RO)
1316 static int mp_property_video_codec(m_option_t *prop, int action,
1317 void *arg, MPContext *mpctx)
1319 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1320 return M_PROPERTY_UNAVAILABLE;
1321 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1325 /// Video bitrate (RO)
1326 static int mp_property_video_bitrate(m_option_t *prop, int action,
1327 void *arg, MPContext *mpctx)
1329 if (!mpctx->sh_video)
1330 return M_PROPERTY_UNAVAILABLE;
1331 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1334 /// Video display width (RO)
1335 static int mp_property_width(m_option_t *prop, int action, void *arg,
1336 MPContext *mpctx)
1338 if (!mpctx->sh_video)
1339 return M_PROPERTY_UNAVAILABLE;
1340 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1343 /// Video display height (RO)
1344 static int mp_property_height(m_option_t *prop, int action, void *arg,
1345 MPContext *mpctx)
1347 if (!mpctx->sh_video)
1348 return M_PROPERTY_UNAVAILABLE;
1349 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1352 /// Video fps (RO)
1353 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1354 MPContext *mpctx)
1356 if (!mpctx->sh_video)
1357 return M_PROPERTY_UNAVAILABLE;
1358 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1361 /// Video aspect (RO)
1362 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1363 MPContext *mpctx)
1365 if (!mpctx->sh_video)
1366 return M_PROPERTY_UNAVAILABLE;
1367 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1370 ///@}
1372 /// \defgroup SubProprties Subtitles properties
1373 /// \ingroup Properties
1374 ///@{
1376 /// Text subtitle position (RW)
1377 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1378 MPContext *mpctx)
1380 switch (action) {
1381 case M_PROPERTY_SET:
1382 if (!arg)
1383 return M_PROPERTY_ERROR;
1384 case M_PROPERTY_STEP_UP:
1385 case M_PROPERTY_STEP_DOWN:
1386 vo_osd_changed(OSDTYPE_SUBTITLE);
1387 default:
1388 return m_property_int_range(prop, action, arg, &sub_pos);
1392 /// Selected subtitles (RW)
1393 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1394 MPContext *mpctx)
1396 struct MPOpts *opts = &mpctx->opts;
1397 demux_stream_t *const d_sub = mpctx->d_sub;
1398 const int global_sub_size = mpctx->global_sub_size;
1399 int source = -1, reset_spu = 0;
1400 char *sub_name;
1402 if (global_sub_size <= 0)
1403 return M_PROPERTY_UNAVAILABLE;
1405 switch (action) {
1406 case M_PROPERTY_GET:
1407 if (!arg)
1408 return M_PROPERTY_ERROR;
1409 *(int *) arg = mpctx->global_sub_pos;
1410 return M_PROPERTY_OK;
1411 case M_PROPERTY_PRINT:
1412 if (!arg)
1413 return M_PROPERTY_ERROR;
1414 *(char **) arg = malloc(64);
1415 (*(char **) arg)[63] = 0;
1416 sub_name = 0;
1417 if (subdata)
1418 sub_name = subdata->filename;
1419 #ifdef CONFIG_ASS
1420 if (ass_track && ass_track->name)
1421 sub_name = ass_track->name;
1422 #endif
1423 if (sub_name) {
1424 char *tmp, *tmp2;
1425 tmp = sub_name;
1426 if ((tmp2 = strrchr(tmp, '/')))
1427 tmp = tmp2 + 1;
1429 snprintf(*(char **) arg, 63, "(%d) %s%s",
1430 mpctx->set_of_sub_pos + 1,
1431 strlen(tmp) < 20 ? "" : "...",
1432 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1433 return M_PROPERTY_OK;
1435 #ifdef CONFIG_DVDNAV
1436 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1437 if (vo_spudec && opts->sub_id >= 0) {
1438 unsigned char lang[3];
1439 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1440 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1441 return M_PROPERTY_OK;
1445 #endif
1447 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1448 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1449 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1450 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1451 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1452 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1453 if (!lang) lang = mp_gtext("unknown");
1454 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1455 return M_PROPERTY_OK;
1458 if (vo_vobsub && vobsub_id >= 0) {
1459 const char *language = mp_gtext("unknown");
1460 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1461 snprintf(*(char **) arg, 63, "(%d) %s",
1462 vobsub_id, language ? language : mp_gtext("unknown"));
1463 return M_PROPERTY_OK;
1465 #ifdef CONFIG_DVDREAD
1466 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1467 && opts->sub_id >= 0) {
1468 char lang[3];
1469 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1470 lang[0] = code >> 8;
1471 lang[1] = code;
1472 lang[2] = 0;
1473 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1474 return M_PROPERTY_OK;
1476 #endif
1477 if (opts->sub_id >= 0) {
1478 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
1479 mp_gtext("unknown"));
1480 return M_PROPERTY_OK;
1482 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1483 return M_PROPERTY_OK;
1485 case M_PROPERTY_SET:
1486 if (!arg)
1487 return M_PROPERTY_ERROR;
1488 if (*(int *) arg < -1)
1489 *(int *) arg = -1;
1490 else if (*(int *) arg >= global_sub_size)
1491 *(int *) arg = global_sub_size - 1;
1492 mpctx->global_sub_pos = *(int *) arg;
1493 break;
1494 case M_PROPERTY_STEP_UP:
1495 mpctx->global_sub_pos += 2;
1496 mpctx->global_sub_pos =
1497 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1498 break;
1499 case M_PROPERTY_STEP_DOWN:
1500 mpctx->global_sub_pos += global_sub_size + 1;
1501 mpctx->global_sub_pos =
1502 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1503 break;
1504 default:
1505 return M_PROPERTY_NOT_IMPLEMENTED;
1508 if (mpctx->global_sub_pos >= 0)
1509 source = sub_source(mpctx);
1511 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1512 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1513 global_sub_size,
1514 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1515 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1516 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1517 mpctx->global_sub_pos, source);
1519 mpctx->set_of_sub_pos = -1;
1520 subdata = NULL;
1522 vobsub_id = -1;
1523 opts->sub_id = -1;
1524 if (d_sub) {
1525 if (d_sub->id > -2)
1526 reset_spu = 1;
1527 d_sub->id = -2;
1529 #ifdef CONFIG_ASS
1530 ass_track = 0;
1531 #endif
1533 if (source == SUB_SOURCE_VOBSUB) {
1534 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1535 } else if (source == SUB_SOURCE_SUBS) {
1536 mpctx->set_of_sub_pos =
1537 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1538 #ifdef CONFIG_ASS
1539 if (opts->ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1540 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1541 else
1542 #endif
1544 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1545 vo_osd_changed(OSDTYPE_SUBTITLE);
1547 } else if (source == SUB_SOURCE_DEMUX) {
1548 opts->sub_id =
1549 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1550 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1551 int i = 0;
1552 // default: assume 1:1 mapping of sid and stream id
1553 d_sub->id = opts->sub_id;
1554 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1555 ds_free_packs(d_sub);
1556 for (i = 0; i < MAX_S_STREAMS; i++) {
1557 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1558 if (sh && sh->sid == opts->sub_id) {
1559 d_sub->id = i;
1560 d_sub->sh = sh;
1561 break;
1564 if (d_sub->sh && d_sub->id >= 0) {
1565 sh_sub_t *sh = d_sub->sh;
1566 if (sh->type == 'v')
1567 init_vo_spudec(mpctx);
1568 #ifdef CONFIG_ASS
1569 else if (opts->ass_enabled)
1570 ass_track = sh->ass_track;
1571 #endif
1572 } else {
1573 d_sub->id = -2;
1574 d_sub->sh = NULL;
1578 #ifdef CONFIG_DVDREAD
1579 if (vo_spudec
1580 && (mpctx->stream->type == STREAMTYPE_DVD
1581 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1582 && opts->sub_id < 0 && reset_spu) {
1583 d_sub->id = -2;
1584 d_sub->sh = NULL;
1586 #endif
1588 update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, 0, 0, d_sub, 1);
1590 return M_PROPERTY_OK;
1593 /// Selected sub source (RW)
1594 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1595 MPContext *mpctx)
1597 int source;
1598 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1599 return M_PROPERTY_UNAVAILABLE;
1601 switch (action) {
1602 case M_PROPERTY_GET:
1603 if (!arg)
1604 return M_PROPERTY_ERROR;
1605 *(int *) arg = sub_source(mpctx);
1606 return M_PROPERTY_OK;
1607 case M_PROPERTY_PRINT:
1608 if (!arg)
1609 return M_PROPERTY_ERROR;
1610 *(char **) arg = malloc(64);
1611 (*(char **) arg)[63] = 0;
1612 switch (sub_source(mpctx))
1614 case SUB_SOURCE_SUBS:
1615 snprintf(*(char **) arg, 63, mp_gtext("file"));
1616 break;
1617 case SUB_SOURCE_VOBSUB:
1618 snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
1619 break;
1620 case SUB_SOURCE_DEMUX:
1621 snprintf(*(char **) arg, 63, mp_gtext("embedded"));
1622 break;
1623 default:
1624 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1626 return M_PROPERTY_OK;
1627 case M_PROPERTY_SET:
1628 if (!arg)
1629 return M_PROPERTY_ERROR;
1630 M_PROPERTY_CLAMP(prop, *(int*)arg);
1631 if (*(int *) arg < 0)
1632 mpctx->global_sub_pos = -1;
1633 else if (*(int *) arg != sub_source(mpctx)) {
1634 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1635 return M_PROPERTY_UNAVAILABLE;
1636 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1638 break;
1639 case M_PROPERTY_STEP_UP:
1640 case M_PROPERTY_STEP_DOWN: {
1641 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1642 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1643 int step = (step_all > 0) ? 1 : -1;
1644 int cur_source = sub_source(mpctx);
1645 source = cur_source;
1646 while (step_all) {
1647 source += step;
1648 if (source >= SUB_SOURCES)
1649 source = -1;
1650 else if (source < -1)
1651 source = SUB_SOURCES - 1;
1652 if (source == cur_source || source == -1 ||
1653 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1654 step_all -= step;
1656 if (source == cur_source)
1657 return M_PROPERTY_OK;
1658 if (source == -1)
1659 mpctx->global_sub_pos = -1;
1660 else
1661 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1662 break;
1664 default:
1665 return M_PROPERTY_NOT_IMPLEMENTED;
1667 --mpctx->global_sub_pos;
1668 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1671 /// Selected subtitles from specific source (RW)
1672 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1673 MPContext *mpctx)
1675 int source, is_cur_source, offset;
1676 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1677 return M_PROPERTY_UNAVAILABLE;
1679 if (!strcmp(prop->name, "sub_file"))
1680 source = SUB_SOURCE_SUBS;
1681 else if (!strcmp(prop->name, "sub_vob"))
1682 source = SUB_SOURCE_VOBSUB;
1683 else if (!strcmp(prop->name, "sub_demux"))
1684 source = SUB_SOURCE_DEMUX;
1685 else
1686 return M_PROPERTY_ERROR;
1688 offset = mpctx->global_sub_indices[source];
1689 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1690 return M_PROPERTY_UNAVAILABLE;
1692 is_cur_source = sub_source(mpctx) == source;
1693 switch (action) {
1694 case M_PROPERTY_GET:
1695 if (!arg)
1696 return M_PROPERTY_ERROR;
1697 if (is_cur_source) {
1698 *(int *) arg = mpctx->global_sub_pos - offset;
1699 if (source == SUB_SOURCE_VOBSUB)
1700 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1702 else
1703 *(int *) arg = -1;
1704 return M_PROPERTY_OK;
1705 case M_PROPERTY_PRINT:
1706 if (!arg)
1707 return M_PROPERTY_ERROR;
1708 if (is_cur_source)
1709 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1710 *(char **) arg = malloc(64);
1711 (*(char **) arg)[63] = 0;
1712 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1713 return M_PROPERTY_OK;
1714 case M_PROPERTY_SET:
1715 if (!arg)
1716 return M_PROPERTY_ERROR;
1717 if (*(int *) arg >= 0) {
1718 int index = *(int *)arg;
1719 if (source == SUB_SOURCE_VOBSUB)
1720 index = vobsub_get_index_by_id(vo_vobsub, index);
1721 mpctx->global_sub_pos = offset + index;
1722 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1723 || sub_source(mpctx) != source) {
1724 mpctx->global_sub_pos = -1;
1725 *(int *) arg = -1;
1728 else
1729 mpctx->global_sub_pos = -1;
1730 break;
1731 case M_PROPERTY_STEP_UP:
1732 case M_PROPERTY_STEP_DOWN: {
1733 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1734 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1735 int step = (step_all > 0) ? 1 : -1;
1736 int max_sub_pos_for_source = -1;
1737 if (!is_cur_source)
1738 mpctx->global_sub_pos = -1;
1739 while (step_all) {
1740 if (mpctx->global_sub_pos == -1) {
1741 if (step > 0)
1742 mpctx->global_sub_pos = offset;
1743 else if (max_sub_pos_for_source == -1) {
1744 // Find max pos for specific source
1745 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1746 while (mpctx->global_sub_pos >= 0
1747 && sub_source(mpctx) != source)
1748 --mpctx->global_sub_pos;
1750 else
1751 mpctx->global_sub_pos = max_sub_pos_for_source;
1753 else {
1754 mpctx->global_sub_pos += step;
1755 if (mpctx->global_sub_pos < offset ||
1756 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1757 sub_source(mpctx) != source)
1758 mpctx->global_sub_pos = -1;
1760 step_all -= step;
1762 break;
1764 default:
1765 return M_PROPERTY_NOT_IMPLEMENTED;
1767 --mpctx->global_sub_pos;
1768 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1771 /// Subtitle delay (RW)
1772 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1773 MPContext *mpctx)
1775 if (!mpctx->sh_video)
1776 return M_PROPERTY_UNAVAILABLE;
1777 return m_property_delay(prop, action, arg, &sub_delay);
1780 /// Alignment of text subtitles (RW)
1781 static int mp_property_sub_alignment(m_option_t *prop, int action,
1782 void *arg, MPContext *mpctx)
1784 char *name[] = { _("top"), _("center"), _("bottom") };
1786 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1787 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1788 return M_PROPERTY_UNAVAILABLE;
1790 switch (action) {
1791 case M_PROPERTY_PRINT:
1792 if (!arg)
1793 return M_PROPERTY_ERROR;
1794 M_PROPERTY_CLAMP(prop, sub_alignment);
1795 *(char **) arg = strdup(mp_gtext(name[sub_alignment]));
1796 return M_PROPERTY_OK;
1797 case M_PROPERTY_SET:
1798 if (!arg)
1799 return M_PROPERTY_ERROR;
1800 case M_PROPERTY_STEP_UP:
1801 case M_PROPERTY_STEP_DOWN:
1802 vo_osd_changed(OSDTYPE_SUBTITLE);
1803 default:
1804 return m_property_choice(prop, action, arg, &sub_alignment);
1808 /// Subtitle visibility (RW)
1809 static int mp_property_sub_visibility(m_option_t *prop, int action,
1810 void *arg, MPContext *mpctx)
1812 if (!mpctx->sh_video)
1813 return M_PROPERTY_UNAVAILABLE;
1815 switch (action) {
1816 case M_PROPERTY_SET:
1817 if (!arg)
1818 return M_PROPERTY_ERROR;
1819 case M_PROPERTY_STEP_UP:
1820 case M_PROPERTY_STEP_DOWN:
1821 vo_osd_changed(OSDTYPE_SUBTITLE);
1822 if (vo_spudec)
1823 vo_osd_changed(OSDTYPE_SPU);
1824 default:
1825 return m_property_flag(prop, action, arg, &sub_visibility);
1829 #ifdef CONFIG_ASS
1830 /// Use margins for libass subtitles (RW)
1831 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1832 void *arg, MPContext *mpctx)
1834 if (!mpctx->sh_video)
1835 return M_PROPERTY_UNAVAILABLE;
1837 switch (action) {
1838 case M_PROPERTY_SET:
1839 if (!arg)
1840 return M_PROPERTY_ERROR;
1841 case M_PROPERTY_STEP_UP:
1842 case M_PROPERTY_STEP_DOWN:
1843 ass_force_reload = 1;
1844 default:
1845 return m_property_flag(prop, action, arg, &ass_use_margins);
1848 #endif
1850 /// Show only forced subtitles (RW)
1851 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1852 void *arg, MPContext *mpctx)
1854 if (!vo_spudec)
1855 return M_PROPERTY_UNAVAILABLE;
1857 switch (action) {
1858 case M_PROPERTY_SET:
1859 if (!arg)
1860 return M_PROPERTY_ERROR;
1861 case M_PROPERTY_STEP_UP:
1862 case M_PROPERTY_STEP_DOWN:
1863 m_property_flag(prop, action, arg, &forced_subs_only);
1864 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1865 return M_PROPERTY_OK;
1866 default:
1867 return m_property_flag(prop, action, arg, &forced_subs_only);
1872 #ifdef CONFIG_FREETYPE
1873 /// Subtitle scale (RW)
1874 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1875 MPContext *mpctx)
1877 struct MPOpts *opts = &mpctx->opts;
1879 switch (action) {
1880 case M_PROPERTY_SET:
1881 if (!arg)
1882 return M_PROPERTY_ERROR;
1883 M_PROPERTY_CLAMP(prop, *(float *) arg);
1884 #ifdef CONFIG_ASS
1885 if (opts->ass_enabled) {
1886 ass_font_scale = *(float *) arg;
1887 ass_force_reload = 1;
1889 #endif
1890 text_font_scale_factor = *(float *) arg;
1891 force_load_font = 1;
1892 return M_PROPERTY_OK;
1893 case M_PROPERTY_STEP_UP:
1894 case M_PROPERTY_STEP_DOWN:
1895 #ifdef CONFIG_ASS
1896 if (opts->ass_enabled) {
1897 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1898 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1899 M_PROPERTY_CLAMP(prop, ass_font_scale);
1900 ass_force_reload = 1;
1902 #endif
1903 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1904 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1905 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1906 force_load_font = 1;
1907 return M_PROPERTY_OK;
1908 default:
1909 #ifdef CONFIG_ASS
1910 if (opts->ass_enabled)
1911 return m_property_float_ro(prop, action, arg, ass_font_scale);
1912 else
1913 #endif
1914 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1917 #endif
1919 ///@}
1921 /// \defgroup TVProperties TV properties
1922 /// \ingroup Properties
1923 ///@{
1925 #ifdef CONFIG_TV
1927 /// TV color settings (RW)
1928 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1929 MPContext *mpctx)
1931 int r, val;
1932 tvi_handle_t *tvh = mpctx->demuxer->priv;
1933 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1934 return M_PROPERTY_UNAVAILABLE;
1936 switch (action) {
1937 case M_PROPERTY_SET:
1938 if (!arg)
1939 return M_PROPERTY_ERROR;
1940 M_PROPERTY_CLAMP(prop, *(int *) arg);
1941 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1942 case M_PROPERTY_GET:
1943 return tv_get_color_options(tvh, (int) prop->priv, arg);
1944 case M_PROPERTY_STEP_UP:
1945 case M_PROPERTY_STEP_DOWN:
1946 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1947 if (!r)
1948 return M_PROPERTY_ERROR;
1949 val += (arg ? *(int *) arg : 1) *
1950 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1951 M_PROPERTY_CLAMP(prop, val);
1952 return tv_set_color_options(tvh, (int) prop->priv, val);
1954 return M_PROPERTY_ERROR;
1956 return M_PROPERTY_NOT_IMPLEMENTED;
1959 #endif
1961 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1962 MPContext *mpctx)
1964 int val,result;
1965 int base_ioctl=(int)prop->priv;
1967 for teletext's GET,SET,STEP ioctls this is not 0
1968 SET is GET+1
1969 STEP is GET+2
1971 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
1972 return M_PROPERTY_UNAVAILABLE;
1973 if(!base_ioctl)
1974 return M_PROPERTY_ERROR;
1976 switch (action) {
1977 case M_PROPERTY_GET:
1978 if (!arg)
1979 return M_PROPERTY_ERROR;
1980 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
1981 break;
1982 case M_PROPERTY_SET:
1983 if (!arg)
1984 return M_PROPERTY_ERROR;
1985 M_PROPERTY_CLAMP(prop, *(int *) arg);
1986 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
1987 break;
1988 case M_PROPERTY_STEP_UP:
1989 case M_PROPERTY_STEP_DOWN:
1990 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
1991 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1992 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
1993 break;
1994 default:
1995 return M_PROPERTY_NOT_IMPLEMENTED;
1998 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2001 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2002 MPContext *mpctx)
2004 int result;
2005 int val;
2007 //with tvh==NULL will fail too
2008 result=mp_property_teletext_common(prop,action,arg,mpctx);
2009 if(result!=M_PROPERTY_OK)
2010 return result;
2012 if(teletext_control(mpctx->demuxer->teletext,
2013 (int)prop->priv, &val)==VBI_CONTROL_TRUE && val)
2014 mp_input_set_section(mpctx->input, "teletext");
2015 else
2016 mp_input_set_section(mpctx->input, "tv");
2017 return M_PROPERTY_OK;
2020 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2021 MPContext *mpctx)
2023 int result;
2024 int val;
2025 if (!mpctx->demuxer->teletext)
2026 return M_PROPERTY_UNAVAILABLE;
2027 switch(action){
2028 case M_PROPERTY_STEP_UP:
2029 case M_PROPERTY_STEP_DOWN:
2030 //This should be handled separately
2031 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2032 result=teletext_control(mpctx->demuxer->teletext,
2033 TV_VBI_CONTROL_STEP_PAGE, &val);
2034 break;
2035 default:
2036 result=mp_property_teletext_common(prop,action,arg,mpctx);
2038 return result;
2041 ///@}
2043 /// All properties available in MPlayer.
2044 /** \ingroup Properties
2046 static const m_option_t mp_properties[] = {
2047 // General
2048 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2049 M_OPT_RANGE, 0, 3, NULL },
2050 { "loop", mp_property_loop, CONF_TYPE_INT,
2051 M_OPT_MIN, -1, 0, NULL },
2052 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2053 M_OPT_RANGE, 0.01, 100.0, NULL },
2054 { "filename", mp_property_filename, CONF_TYPE_STRING,
2055 0, 0, 0, NULL },
2056 { "path", mp_property_path, CONF_TYPE_STRING,
2057 0, 0, 0, NULL },
2058 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2059 0, 0, 0, NULL },
2060 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2061 M_OPT_MIN, 0, 0, NULL },
2062 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2063 M_OPT_MIN, 0, 0, NULL },
2064 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2065 M_OPT_MIN, 0, 0, NULL },
2066 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2067 M_OPT_MIN, 0, 0, NULL },
2068 { "length", mp_property_length, CONF_TYPE_TIME,
2069 M_OPT_MIN, 0, 0, NULL },
2070 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2071 M_OPT_RANGE, 0, 100, NULL },
2072 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2073 M_OPT_MIN, 0, 0, NULL },
2074 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2075 M_OPT_MIN, 0, 0, NULL },
2076 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2077 0, 0, 0, NULL },
2078 { "angle", mp_property_angle, CONF_TYPE_INT,
2079 CONF_RANGE, -2, 10, NULL },
2080 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2081 0, 0, 0, NULL },
2082 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2083 M_OPT_RANGE, 0, 1, NULL },
2085 // Audio
2086 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2087 M_OPT_RANGE, 0, 100, NULL },
2088 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2089 M_OPT_RANGE, 0, 1, NULL },
2090 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2091 M_OPT_RANGE, -100, 100, NULL },
2092 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2093 0, 0, 0, NULL },
2094 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2095 0, 0, 0, NULL },
2096 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2097 0, 0, 0, NULL },
2098 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2099 0, 0, 0, NULL },
2100 { "channels", mp_property_channels, CONF_TYPE_INT,
2101 0, 0, 0, NULL },
2102 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2103 CONF_RANGE, -2, 65535, NULL },
2104 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2105 M_OPT_RANGE, -1, 1, NULL },
2107 // Video
2108 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2109 M_OPT_RANGE, 0, 1, NULL },
2110 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2111 M_OPT_RANGE, 0, 1, NULL },
2112 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2113 M_OPT_RANGE, 0, 2, NULL },
2114 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2115 M_OPT_RANGE, 0, 1, NULL },
2116 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2117 M_OPT_RANGE, 0, 1, NULL },
2118 { "border", mp_property_border, CONF_TYPE_FLAG,
2119 M_OPT_RANGE, 0, 1, NULL },
2120 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2121 M_OPT_RANGE, 0, 2, NULL },
2122 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2123 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2124 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2125 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2126 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2127 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2128 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2129 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2130 { "hue", mp_property_gamma, CONF_TYPE_INT,
2131 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2132 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2133 M_OPT_RANGE, 0, 1, NULL },
2134 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2135 M_OPT_RANGE, 0, 1, NULL },
2136 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2137 0, 0, 0, NULL },
2138 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2139 0, 0, 0, NULL },
2140 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2141 0, 0, 0, NULL },
2142 { "width", mp_property_width, CONF_TYPE_INT,
2143 0, 0, 0, NULL },
2144 { "height", mp_property_height, CONF_TYPE_INT,
2145 0, 0, 0, NULL },
2146 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2147 0, 0, 0, NULL },
2148 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2149 0, 0, 0, NULL },
2150 { "switch_video", mp_property_video, CONF_TYPE_INT,
2151 CONF_RANGE, -2, 65535, NULL },
2152 { "switch_program", mp_property_program, CONF_TYPE_INT,
2153 CONF_RANGE, -1, 65535, NULL },
2155 // Subs
2156 { "sub", mp_property_sub, CONF_TYPE_INT,
2157 M_OPT_MIN, -1, 0, NULL },
2158 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2159 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2160 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2161 M_OPT_MIN, -1, 0, NULL },
2162 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2163 M_OPT_MIN, -1, 0, NULL },
2164 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2165 M_OPT_MIN, -1, 0, NULL },
2166 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2167 0, 0, 0, NULL },
2168 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2169 M_OPT_RANGE, 0, 100, NULL },
2170 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2171 M_OPT_RANGE, 0, 2, NULL },
2172 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2173 M_OPT_RANGE, 0, 1, NULL },
2174 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2175 M_OPT_RANGE, 0, 1, NULL },
2176 #ifdef CONFIG_FREETYPE
2177 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2178 M_OPT_RANGE, 0, 100, NULL },
2179 #endif
2180 #ifdef CONFIG_ASS
2181 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2182 M_OPT_RANGE, 0, 1, NULL },
2183 #endif
2185 #ifdef CONFIG_TV
2186 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2187 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2188 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2189 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2190 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2191 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2192 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2193 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2194 #endif
2195 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2196 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2197 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2198 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2199 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2200 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2201 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2202 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2203 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2204 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2205 { NULL, NULL, NULL, 0, 0, 0, NULL }
2209 int mp_property_do(const char *name, int action, void *val, void *ctx)
2211 return m_property_do(mp_properties, name, action, val, ctx);
2214 char* mp_property_print(const char *name, void* ctx)
2216 char* ret = NULL;
2217 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2218 return NULL;
2219 return ret;
2222 char *property_expand_string(MPContext *mpctx, char *str)
2224 return m_properties_expand_string(mp_properties, str, mpctx);
2227 void property_print_help(void)
2229 m_properties_print_help_list(mp_properties);
2233 /* List of default ways to show a property on OSD.
2235 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2236 * a bar showing the current position between min/max values of the
2237 * property. In this case osd_msg is only used for terminal output
2238 * if there is no video; it'll be a label shown together with percentage.
2240 * Otherwise setting osd_msg will show the string on OSD, formatted with
2241 * the text value of the property as argument.
2243 static struct property_osd_display {
2244 /// property name
2245 const char *name;
2246 /// progressbar type
2247 int osd_progbar; // -1 is special value for seek indicators
2248 /// osd msg id if it must be shared
2249 int osd_id;
2250 /// osd msg template
2251 const char *osd_msg;
2252 } property_osd_display[] = {
2253 // general
2254 { "loop", 0, -1, _("Loop: %s") },
2255 { "chapter", -1, -1, NULL },
2256 // audio
2257 { "volume", OSD_VOLUME, -1, _("Volume") },
2258 { "mute", 0, -1, _("Mute: %s") },
2259 { "audio_delay", 0, -1, _("A-V delay: %s") },
2260 { "switch_audio", 0, -1, _("Audio: %s") },
2261 { "balance", OSD_BALANCE, -1, _("Balance") },
2262 // video
2263 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2264 { "ontop", 0, -1, _("Stay on top: %s") },
2265 { "rootwin", 0, -1, _("Rootwin: %s") },
2266 { "border", 0, -1, _("Border: %s") },
2267 { "framedropping", 0, -1, _("Framedropping: %s") },
2268 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2269 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2270 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2271 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2272 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2273 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2274 { "hue", OSD_HUE, -1, _("Hue") },
2275 { "vsync", 0, -1, _("VSync: %s") },
2276 // subs
2277 { "sub", 0, -1, _("Subtitles: %s") },
2278 { "sub_source", 0, -1, _("Sub source: %s") },
2279 { "sub_vob", 0, -1, _("Subtitles: %s") },
2280 { "sub_demux", 0, -1, _("Subtitles: %s") },
2281 { "sub_file", 0, -1, _("Subtitles: %s") },
2282 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2283 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2284 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2285 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2286 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2287 #ifdef CONFIG_FREETYPE
2288 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2289 #endif
2290 #ifdef CONFIG_TV
2291 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2292 { "tv_hue", OSD_HUE, -1, _("Hue") },
2293 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2294 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2295 #endif
2299 static int show_property_osd(MPContext *mpctx, const char *pname)
2301 struct MPOpts *opts = &mpctx->opts;
2302 int r;
2303 m_option_t* prop;
2304 struct property_osd_display *p;
2306 // look for the command
2307 for (p = property_osd_display; p->name; p++)
2308 if (!strcmp(p->name, pname))
2309 break;
2310 if (!p->name)
2311 return -1;
2313 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2314 return -1;
2316 if (p->osd_progbar == -1)
2317 mpctx->add_osd_seek_info = true;
2318 else if (p->osd_progbar) {
2319 if (prop->type == CONF_TYPE_INT) {
2320 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2321 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2322 prop->min, prop->max, r);
2323 } else if (prop->type == CONF_TYPE_FLOAT) {
2324 float f;
2325 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2326 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2327 prop->min, prop->max, f);
2328 } else {
2329 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2330 "Property use an unsupported type.\n");
2331 return -1;
2333 return 0;
2336 if (p->osd_msg) {
2337 char *val = mp_property_print(pname, mpctx);
2338 if (val) {
2339 int index = p - property_osd_display;
2340 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2341 1, opts->osd_duration, p->osd_msg, val);
2342 free(val);
2345 return 0;
2350 * \defgroup Command2Property Command to property bridge
2352 * It is used to handle most commands that just set a property
2353 * and optionally display something on the OSD.
2354 * Two kinds of commands are handled: adjust or toggle.
2356 * Adjust commands take 1 or 2 parameters: <value> <abs>
2357 * If <abs> is non-zero the property is set to the given value
2358 * otherwise it is adjusted.
2360 * Toggle commands take 0 or 1 parameters. With no parameter
2361 * or a value less than the property minimum it just steps the
2362 * property to its next value. Otherwise it sets it to the given
2363 * value.
2368 /// List of the commands that can be handled by setting a property.
2369 static struct {
2370 /// property name
2371 const char *name;
2372 /// cmd id
2373 int cmd;
2374 /// set/adjust or toggle command
2375 int toggle;
2376 } set_prop_cmd[] = {
2377 // general
2378 { "loop", MP_CMD_LOOP, 0},
2379 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2380 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2381 { "pause", MP_CMD_PAUSE, 0},
2382 // audio
2383 { "volume", MP_CMD_VOLUME, 0},
2384 { "mute", MP_CMD_MUTE, 1},
2385 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2386 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2387 { "balance", MP_CMD_BALANCE, 0},
2388 // video
2389 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2390 { "panscan", MP_CMD_PANSCAN, 0},
2391 { "ontop", MP_CMD_VO_ONTOP, 1},
2392 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2393 { "border", MP_CMD_VO_BORDER, 1},
2394 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2395 { "gamma", MP_CMD_GAMMA, 0},
2396 { "brightness", MP_CMD_BRIGHTNESS, 0},
2397 { "contrast", MP_CMD_CONTRAST, 0},
2398 { "saturation", MP_CMD_SATURATION, 0},
2399 { "hue", MP_CMD_HUE, 0},
2400 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2401 // subs
2402 { "sub", MP_CMD_SUB_SELECT, 1},
2403 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2404 { "sub_vob", MP_CMD_SUB_VOB, 1},
2405 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2406 { "sub_file", MP_CMD_SUB_FILE, 1},
2407 { "sub_pos", MP_CMD_SUB_POS, 0},
2408 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2409 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2410 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2411 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2412 #ifdef CONFIG_FREETYPE
2413 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2414 #endif
2415 #ifdef CONFIG_ASS
2416 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2417 #endif
2418 #ifdef CONFIG_TV
2419 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2420 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2421 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2422 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2423 #endif
2427 /// Handle commands that set a property.
2428 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2430 int i, r;
2431 m_option_t* prop;
2432 const char *pname;
2434 // look for the command
2435 for (i = 0; set_prop_cmd[i].name; i++)
2436 if (set_prop_cmd[i].cmd == cmd->id)
2437 break;
2438 if (!(pname = set_prop_cmd[i].name))
2439 return 0;
2441 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2442 return 0;
2444 // toggle command
2445 if (set_prop_cmd[i].toggle) {
2446 // set to value
2447 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2448 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2449 else
2450 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2451 } else if (cmd->args[1].v.i) //set
2452 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2453 else // adjust
2454 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2456 if (r <= 0)
2457 return 1;
2459 show_property_osd(mpctx, pname);
2461 return 1;
2464 #ifdef CONFIG_DVDNAV
2465 static const struct {
2466 const char *name;
2467 const mp_command_type cmd;
2468 } mp_dvdnav_bindings[] = {
2469 { "up", MP_CMD_DVDNAV_UP },
2470 { "down", MP_CMD_DVDNAV_DOWN },
2471 { "left", MP_CMD_DVDNAV_LEFT },
2472 { "right", MP_CMD_DVDNAV_RIGHT },
2473 { "menu", MP_CMD_DVDNAV_MENU },
2474 { "select", MP_CMD_DVDNAV_SELECT },
2475 { "prev", MP_CMD_DVDNAV_PREVMENU },
2476 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2479 * keep old dvdnav sub-command options for a while in order not to
2480 * break slave-mode API too suddenly.
2482 { "1", MP_CMD_DVDNAV_UP },
2483 { "2", MP_CMD_DVDNAV_DOWN },
2484 { "3", MP_CMD_DVDNAV_LEFT },
2485 { "4", MP_CMD_DVDNAV_RIGHT },
2486 { "5", MP_CMD_DVDNAV_MENU },
2487 { "6", MP_CMD_DVDNAV_SELECT },
2488 { "7", MP_CMD_DVDNAV_PREVMENU },
2489 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2490 { NULL, 0 }
2492 #endif
2494 static const char *property_error_string(int error_value)
2496 switch (error_value) {
2497 case M_PROPERTY_ERROR:
2498 return "ERROR";
2499 case M_PROPERTY_UNAVAILABLE:
2500 return "PROPERTY_UNAVAILABLE";
2501 case M_PROPERTY_NOT_IMPLEMENTED:
2502 return "NOT_IMPLEMENTED";
2503 case M_PROPERTY_UNKNOWN:
2504 return "PROPERTY_UNKNOWN";
2505 case M_PROPERTY_DISABLED:
2506 return "DISABLED";
2508 return "UNKNOWN";
2511 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2513 int idx;
2514 int end = start + count;
2515 int after = mpctx->set_of_sub_size - end;
2516 sub_data **subs = mpctx->set_of_subtitles;
2517 #ifdef CONFIG_ASS
2518 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2519 #endif
2520 if (count < 0 || count > mpctx->set_of_sub_size ||
2521 start < 0 || start > mpctx->set_of_sub_size - count) {
2522 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2523 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2524 return;
2526 for (idx = start; idx < end; idx++) {
2527 sub_data *subd = subs[idx];
2528 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2529 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2530 filename_recode(subd->filename));
2531 sub_free(subd);
2532 subs[idx] = NULL;
2533 #ifdef CONFIG_ASS
2534 if (ass_tracks[idx])
2535 ass_free_track(ass_tracks[idx]);
2536 ass_tracks[idx] = NULL;
2537 #endif
2540 mpctx->global_sub_size -= count;
2541 mpctx->set_of_sub_size -= count;
2542 if (mpctx->set_of_sub_size <= 0)
2543 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2545 memmove(subs + start, subs + end, after * sizeof(*subs));
2546 memset(subs + start + after, 0, count * sizeof(*subs));
2547 #ifdef CONFIG_ASS
2548 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2549 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2550 #endif
2552 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2553 mpctx->global_sub_pos = -2;
2554 subdata = NULL;
2555 #ifdef CONFIG_ASS
2556 ass_track = NULL;
2557 #endif
2558 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2559 } else if (mpctx->set_of_sub_pos >= end) {
2560 mpctx->set_of_sub_pos -= count;
2561 mpctx->global_sub_pos -= count;
2565 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2567 struct MPOpts *opts = &mpctx->opts;
2568 sh_audio_t * const sh_audio = mpctx->sh_audio;
2569 sh_video_t * const sh_video = mpctx->sh_video;
2570 int osd_duration = opts->osd_duration;
2571 int case_fallthrough_hack = 0;
2572 if (!set_property_command(mpctx, cmd))
2573 switch (cmd->id) {
2574 case MP_CMD_SEEK:{
2575 float v;
2576 int abs;
2577 mpctx->add_osd_seek_info = true;
2578 v = cmd->args[0].v.f;
2579 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2580 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2581 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2582 if (sh_video)
2583 mpctx->osd_function =
2584 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2585 mpctx->rel_seek_secs = v;
2586 } else if (abs) { /* Absolute seek by percentage */
2587 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2588 if (sh_video)
2589 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2590 mpctx->rel_seek_secs = v / 100.0;
2591 } else {
2592 mpctx->rel_seek_secs += v;
2593 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2596 break;
2598 case MP_CMD_SET_PROPERTY_OSD:
2599 case_fallthrough_hack = 1;
2601 case MP_CMD_SET_PROPERTY:{
2602 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2603 cmd->args[1].v.s, mpctx);
2604 if (r == M_PROPERTY_UNKNOWN)
2605 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2606 "Unknown property: '%s'\n", cmd->args[0].v.s);
2607 else if (r <= 0)
2608 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2609 "Failed to set property '%s' to '%s'.\n",
2610 cmd->args[0].v.s, cmd->args[1].v.s);
2611 else if (case_fallthrough_hack)
2612 show_property_osd(mpctx, cmd->args[0].v.s);
2613 if (r <= 0)
2614 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2616 break;
2618 case MP_CMD_STEP_PROPERTY_OSD:
2619 case_fallthrough_hack = 1;
2621 case MP_CMD_STEP_PROPERTY:{
2622 void* arg = NULL;
2623 int r,i;
2624 double d;
2625 off_t o;
2626 if (cmd->args[1].v.f) {
2627 m_option_t* prop;
2628 if((r = mp_property_do(cmd->args[0].v.s,
2629 M_PROPERTY_GET_TYPE,
2630 &prop, mpctx)) <= 0)
2631 goto step_prop_err;
2632 if(prop->type == CONF_TYPE_INT ||
2633 prop->type == CONF_TYPE_FLAG)
2634 i = cmd->args[1].v.f, arg = &i;
2635 else if(prop->type == CONF_TYPE_FLOAT)
2636 arg = &cmd->args[1].v.f;
2637 else if(prop->type == CONF_TYPE_DOUBLE ||
2638 prop->type == CONF_TYPE_TIME)
2639 d = cmd->args[1].v.f, arg = &d;
2640 else if(prop->type == CONF_TYPE_POSITION)
2641 o = cmd->args[1].v.f, arg = &o;
2642 else
2643 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2644 "Ignoring step size stepping property '%s'.\n",
2645 cmd->args[0].v.s);
2647 r = mp_property_do(cmd->args[0].v.s,
2648 cmd->args[2].v.i < 0 ?
2649 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2650 arg, mpctx);
2651 step_prop_err:
2652 if (r == M_PROPERTY_UNKNOWN)
2653 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2654 "Unknown property: '%s'\n", cmd->args[0].v.s);
2655 else if (r <= 0)
2656 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2657 "Failed to increment property '%s' by %f.\n",
2658 cmd->args[0].v.s, cmd->args[1].v.f);
2659 else if (case_fallthrough_hack)
2660 show_property_osd(mpctx, cmd->args[0].v.s);
2661 if (r <= 0)
2662 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2664 break;
2666 case MP_CMD_GET_PROPERTY:{
2667 char *tmp;
2668 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2669 &tmp, mpctx);
2670 if (r <= 0) {
2671 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2672 "Failed to get value of property '%s'.\n",
2673 cmd->args[0].v.s);
2674 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2675 break;
2677 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2678 cmd->args[0].v.s, tmp);
2679 free(tmp);
2681 break;
2683 case MP_CMD_EDL_MARK:
2684 if (edl_fd) {
2685 float v = sh_video ? sh_video->pts :
2686 playing_audio_pts(mpctx);
2687 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2688 mpctx->begin_skip = v;
2689 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2690 } else {
2691 if (mpctx->begin_skip > v)
2692 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2693 else {
2694 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2695 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2697 mpctx->begin_skip = MP_NOPTS_VALUE;
2700 break;
2702 case MP_CMD_SWITCH_RATIO:
2703 if (!sh_video)
2704 break;
2705 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2706 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2707 else
2708 opts->movie_aspect = cmd->args[0].v.f;
2709 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2710 break;
2712 case MP_CMD_SPEED_INCR:{
2713 float v = cmd->args[0].v.f;
2714 opts->playback_speed += v;
2715 build_afilter_chain(mpctx, sh_audio, &ao_data);
2716 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2717 opts->playback_speed);
2718 } break;
2720 case MP_CMD_SPEED_MULT:{
2721 float v = cmd->args[0].v.f;
2722 opts->playback_speed *= v;
2723 build_afilter_chain(mpctx, sh_audio, &ao_data);
2724 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2725 opts->playback_speed);
2726 } break;
2728 case MP_CMD_SPEED_SET:{
2729 float v = cmd->args[0].v.f;
2730 opts->playback_speed = v;
2731 build_afilter_chain(mpctx, sh_audio, &ao_data);
2732 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2733 opts->playback_speed);
2734 } break;
2736 case MP_CMD_FRAME_STEP:
2737 add_step_frame(mpctx);
2738 break;
2740 case MP_CMD_FILE_FILTER:
2741 file_filter = cmd->args[0].v.i;
2742 break;
2744 case MP_CMD_QUIT:
2745 exit_player_with_rc(mpctx, EXIT_QUIT,
2746 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2748 case MP_CMD_PLAY_TREE_STEP:{
2749 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2750 int force = cmd->args[1].v.i;
2753 if (!force && mpctx->playtree_iter) {
2754 play_tree_iter_t *i =
2755 play_tree_iter_new_copy(mpctx->playtree_iter);
2756 if (play_tree_iter_step(i, n, 0) ==
2757 PLAY_TREE_ITER_ENTRY)
2758 mpctx->stop_play =
2759 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2760 play_tree_iter_free(i);
2761 } else
2762 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2763 if (mpctx->stop_play)
2764 mpctx->play_tree_step = n;
2767 break;
2769 case MP_CMD_PLAY_TREE_UP_STEP:{
2770 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2771 int force = cmd->args[1].v.i;
2773 if (!force && mpctx->playtree_iter) {
2774 play_tree_iter_t *i =
2775 play_tree_iter_new_copy(mpctx->playtree_iter);
2776 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2777 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2778 play_tree_iter_free(i);
2779 } else
2780 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2782 break;
2784 case MP_CMD_PLAY_ALT_SRC_STEP:
2785 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2786 int v = cmd->args[0].v.i;
2787 if (v > 0
2788 && mpctx->playtree_iter->file <
2789 mpctx->playtree_iter->num_files)
2790 mpctx->stop_play = PT_NEXT_SRC;
2791 else if (v < 0 && mpctx->playtree_iter->file > 1)
2792 mpctx->stop_play = PT_PREV_SRC;
2794 break;
2796 case MP_CMD_SUB_STEP:
2797 if (sh_video) {
2798 int movement = cmd->args[0].v.i;
2799 step_sub(subdata, sh_video->pts, movement);
2800 #ifdef CONFIG_ASS
2801 if (ass_track)
2802 sub_delay +=
2803 ass_step_sub(ass_track,
2804 (sh_video->pts +
2805 sub_delay) * 1000 + .5, movement) / 1000.;
2806 #endif
2807 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2808 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2810 break;
2812 case MP_CMD_SUB_LOG:
2813 log_sub(mpctx);
2814 break;
2816 case MP_CMD_OSD:{
2817 int v = cmd->args[0].v.i;
2818 int max = (term_osd
2819 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2820 if (opts->osd_level > max)
2821 opts->osd_level = max;
2822 if (v < 0)
2823 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2824 else
2825 opts->osd_level = v > max ? max : v;
2826 /* Show OSD state when disabled, but not when an explicit
2827 argument is given to the OSD command, i.e. in slave mode. */
2828 if (v == -1 && opts->osd_level <= 1)
2829 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2830 "OSD: %s",
2831 opts->osd_level ? mp_gtext("enabled") :
2832 mp_gtext("disabled"));
2833 else
2834 rm_osd_msg(OSD_MSG_OSD_STATUS);
2836 break;
2838 case MP_CMD_OSD_SHOW_TEXT:
2839 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2840 (cmd->args[1].v.i <
2841 0 ? osd_duration : cmd->args[1].v.i),
2842 "%-.63s", cmd->args[0].v.s);
2843 break;
2845 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2846 char *txt = m_properties_expand_string(mp_properties,
2847 cmd->args[0].v.s,
2848 mpctx);
2849 /* if no argument supplied take default osd_duration, else <arg> ms. */
2850 if (txt) {
2851 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2852 (cmd->args[1].v.i <
2853 0 ? osd_duration : cmd->args[1].v.i),
2854 "%-.63s", txt);
2855 free(txt);
2858 break;
2860 case MP_CMD_LOADFILE:{
2861 play_tree_t *e = play_tree_new();
2862 play_tree_add_file(e, cmd->args[0].v.s);
2864 if (cmd->args[1].v.i) // append
2865 play_tree_append_entry(mpctx->playtree->child, e);
2866 else {
2867 // Go back to the starting point.
2868 while (play_tree_iter_up_step
2869 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2870 /* NOP */ ;
2871 play_tree_free_list(mpctx->playtree->child, 1);
2872 play_tree_set_child(mpctx->playtree, e);
2873 pt_iter_goto_head(mpctx->playtree_iter);
2874 mpctx->stop_play = PT_NEXT_SRC;
2877 break;
2879 case MP_CMD_LOADLIST:{
2880 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2881 if (!e)
2882 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2883 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2884 else {
2885 if (cmd->args[1].v.i) // append
2886 play_tree_append_entry(mpctx->playtree->child, e);
2887 else {
2888 // Go back to the starting point.
2889 while (play_tree_iter_up_step
2890 (mpctx->playtree_iter, 0, 1)
2891 != PLAY_TREE_ITER_END)
2892 /* NOP */ ;
2893 play_tree_free_list(mpctx->playtree->child, 1);
2894 play_tree_set_child(mpctx->playtree, e);
2895 pt_iter_goto_head(mpctx->playtree_iter);
2896 mpctx->stop_play = PT_NEXT_SRC;
2900 break;
2902 case MP_CMD_STOP:
2903 // Go back to the starting point.
2904 while (play_tree_iter_up_step
2905 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2906 /* NOP */ ;
2907 mpctx->stop_play = PT_STOP;
2908 break;
2910 #ifdef CONFIG_RADIO
2911 case MP_CMD_RADIO_STEP_CHANNEL:
2912 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2913 int v = cmd->args[0].v.i;
2914 if (v > 0)
2915 radio_step_channel(mpctx->demuxer->stream,
2916 RADIO_CHANNEL_HIGHER);
2917 else
2918 radio_step_channel(mpctx->demuxer->stream,
2919 RADIO_CHANNEL_LOWER);
2920 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2921 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2922 "Channel: %s",
2923 radio_get_channel_name(mpctx->demuxer->stream));
2926 break;
2928 case MP_CMD_RADIO_SET_CHANNEL:
2929 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2930 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2931 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2932 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2933 "Channel: %s",
2934 radio_get_channel_name(mpctx->demuxer->stream));
2937 break;
2939 case MP_CMD_RADIO_SET_FREQ:
2940 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2941 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2942 break;
2944 case MP_CMD_RADIO_STEP_FREQ:
2945 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2946 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2947 break;
2948 #endif
2950 #ifdef CONFIG_TV
2951 case MP_CMD_TV_START_SCAN:
2952 if (mpctx->file_format == DEMUXER_TYPE_TV)
2953 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2954 break;
2955 case MP_CMD_TV_SET_FREQ:
2956 if (mpctx->file_format == DEMUXER_TYPE_TV)
2957 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2958 cmd->args[0].v.f * 16.0);
2959 #ifdef CONFIG_PVR
2960 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2961 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2962 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2963 pvr_get_current_channelname (mpctx->stream),
2964 pvr_get_current_stationname (mpctx->stream));
2966 #endif /* CONFIG_PVR */
2967 break;
2969 case MP_CMD_TV_STEP_FREQ:
2970 if (mpctx->file_format == DEMUXER_TYPE_TV)
2971 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2972 cmd->args[0].v.f * 16.0);
2973 #ifdef CONFIG_PVR
2974 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2975 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2976 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2977 pvr_get_current_channelname (mpctx->stream),
2978 pvr_get_current_frequency (mpctx->stream));
2980 #endif /* CONFIG_PVR */
2981 break;
2983 case MP_CMD_TV_SET_NORM:
2984 if (mpctx->file_format == DEMUXER_TYPE_TV)
2985 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2986 cmd->args[0].v.s);
2987 break;
2989 case MP_CMD_TV_STEP_CHANNEL:{
2990 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2991 int v = cmd->args[0].v.i;
2992 if (v > 0) {
2993 tv_step_channel((tvi_handle_t *) (mpctx->
2994 demuxer->priv),
2995 TV_CHANNEL_HIGHER);
2996 } else {
2997 tv_step_channel((tvi_handle_t *) (mpctx->
2998 demuxer->priv),
2999 TV_CHANNEL_LOWER);
3001 if (tv_channel_list) {
3002 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3003 "Channel: %s", tv_channel_current->name);
3004 //vo_osd_changed(OSDTYPE_SUBTITLE);
3007 #ifdef CONFIG_PVR
3008 else if (mpctx->stream &&
3009 mpctx->stream->type == STREAMTYPE_PVR) {
3010 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3011 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3012 pvr_get_current_channelname (mpctx->stream),
3013 pvr_get_current_stationname (mpctx->stream));
3015 #endif /* CONFIG_PVR */
3017 #ifdef CONFIG_DVBIN
3018 if (mpctx->stream->type == STREAMTYPE_DVB) {
3019 int dir;
3020 int v = cmd->args[0].v.i;
3022 mpctx->last_dvb_step = v;
3023 if (v > 0)
3024 dir = DVB_CHANNEL_HIGHER;
3025 else
3026 dir = DVB_CHANNEL_LOWER;
3029 if (dvb_step_channel(mpctx->stream, dir)) {
3030 mpctx->stop_play = PT_NEXT_ENTRY;
3031 mpctx->dvbin_reopen = 1;
3034 #endif /* CONFIG_DVBIN */
3035 break;
3037 case MP_CMD_TV_SET_CHANNEL:
3038 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3039 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3040 cmd->args[0].v.s);
3041 if (tv_channel_list) {
3042 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3043 "Channel: %s", tv_channel_current->name);
3044 //vo_osd_changed(OSDTYPE_SUBTITLE);
3047 #ifdef CONFIG_PVR
3048 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3049 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3050 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3051 pvr_get_current_channelname (mpctx->stream),
3052 pvr_get_current_stationname (mpctx->stream));
3054 #endif /* CONFIG_PVR */
3055 break;
3057 #ifdef CONFIG_DVBIN
3058 case MP_CMD_DVB_SET_CHANNEL:
3059 if (mpctx->stream->type == STREAMTYPE_DVB) {
3060 mpctx->last_dvb_step = 1;
3062 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3063 cmd->args[0].v.i)) {
3064 mpctx->stop_play = PT_NEXT_ENTRY;
3065 mpctx->dvbin_reopen = 1;
3068 break;
3069 #endif /* CONFIG_DVBIN */
3071 case MP_CMD_TV_LAST_CHANNEL:
3072 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3073 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3074 if (tv_channel_list) {
3075 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3076 "Channel: %s", tv_channel_current->name);
3077 //vo_osd_changed(OSDTYPE_SUBTITLE);
3080 #ifdef CONFIG_PVR
3081 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3082 pvr_set_lastchannel (mpctx->stream);
3083 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3084 pvr_get_current_channelname (mpctx->stream),
3085 pvr_get_current_stationname (mpctx->stream));
3087 #endif /* CONFIG_PVR */
3088 break;
3090 case MP_CMD_TV_STEP_NORM:
3091 if (mpctx->file_format == DEMUXER_TYPE_TV)
3092 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3093 break;
3095 case MP_CMD_TV_STEP_CHANNEL_LIST:
3096 if (mpctx->file_format == DEMUXER_TYPE_TV)
3097 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3098 break;
3099 #endif /* CONFIG_TV */
3100 case MP_CMD_TV_TELETEXT_ADD_DEC:
3102 if (mpctx->demuxer->teletext)
3103 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3104 &(cmd->args[0].v.s));
3105 break;
3107 case MP_CMD_TV_TELETEXT_GO_LINK:
3109 if (mpctx->demuxer->teletext)
3110 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3111 &(cmd->args[0].v.i));
3112 break;
3115 case MP_CMD_SUB_LOAD:
3116 if (sh_video) {
3117 int n = mpctx->set_of_sub_size;
3118 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3119 if (n != mpctx->set_of_sub_size) {
3120 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
3121 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
3122 mpctx->global_sub_size;
3123 ++mpctx->global_sub_size;
3126 break;
3128 case MP_CMD_SUB_REMOVE:
3129 if (sh_video) {
3130 int v = cmd->args[0].v.i;
3131 if (v < 0) {
3132 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3133 } else if (v < mpctx->set_of_sub_size) {
3134 remove_subtitle_range(mpctx, v, 1);
3137 break;
3139 case MP_CMD_GET_SUB_VISIBILITY:
3140 if (sh_video) {
3141 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3142 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3144 break;
3146 case MP_CMD_SCREENSHOT:
3147 if (mpctx->video_out && mpctx->video_out->config_ok) {
3148 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3149 if (CONTROL_OK !=
3150 ((vf_instance_t *) sh_video->vfilter)->
3151 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3152 &cmd->args[0].v.i))
3153 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3155 break;
3157 case MP_CMD_VF_CHANGE_RECTANGLE:
3158 if (!sh_video)
3159 break;
3160 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3161 break;
3163 case MP_CMD_GET_TIME_LENGTH:{
3164 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3165 demuxer_get_time_length(mpctx->demuxer));
3167 break;
3169 case MP_CMD_GET_FILENAME:{
3170 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3171 get_metadata(mpctx, META_NAME));
3173 break;
3175 case MP_CMD_GET_VIDEO_CODEC:{
3176 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3177 if (!inf)
3178 inf = strdup("");
3179 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3180 free(inf);
3182 break;
3184 case MP_CMD_GET_VIDEO_BITRATE:{
3185 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3186 if (!inf)
3187 inf = strdup("");
3188 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3189 free(inf);
3191 break;
3193 case MP_CMD_GET_VIDEO_RESOLUTION:{
3194 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3195 if (!inf)
3196 inf = strdup("");
3197 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3198 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3199 free(inf);
3201 break;
3203 case MP_CMD_GET_AUDIO_CODEC:{
3204 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3205 if (!inf)
3206 inf = strdup("");
3207 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3208 free(inf);
3210 break;
3212 case MP_CMD_GET_AUDIO_BITRATE:{
3213 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3214 if (!inf)
3215 inf = strdup("");
3216 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3217 free(inf);
3219 break;
3221 case MP_CMD_GET_AUDIO_SAMPLES:{
3222 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3223 if (!inf)
3224 inf = strdup("");
3225 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3226 free(inf);
3228 break;
3230 case MP_CMD_GET_META_TITLE:{
3231 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3232 if (!inf)
3233 inf = strdup("");
3234 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3235 free(inf);
3237 break;
3239 case MP_CMD_GET_META_ARTIST:{
3240 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3241 if (!inf)
3242 inf = strdup("");
3243 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3244 free(inf);
3246 break;
3248 case MP_CMD_GET_META_ALBUM:{
3249 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3250 if (!inf)
3251 inf = strdup("");
3252 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3253 free(inf);
3255 break;
3257 case MP_CMD_GET_META_YEAR:{
3258 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3259 if (!inf)
3260 inf = strdup("");
3261 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3262 free(inf);
3264 break;
3266 case MP_CMD_GET_META_COMMENT:{
3267 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3268 if (!inf)
3269 inf = strdup("");
3270 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3271 free(inf);
3273 break;
3275 case MP_CMD_GET_META_TRACK:{
3276 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3277 if (!inf)
3278 inf = strdup("");
3279 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3280 free(inf);
3282 break;
3284 case MP_CMD_GET_META_GENRE:{
3285 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3286 if (!inf)
3287 inf = strdup("");
3288 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3289 free(inf);
3291 break;
3293 case MP_CMD_GET_VO_FULLSCREEN:
3294 if (mpctx->video_out && mpctx->video_out->config_ok)
3295 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3296 break;
3298 case MP_CMD_GET_PERCENT_POS:
3299 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3300 demuxer_get_percent_pos(mpctx->demuxer));
3301 break;
3303 case MP_CMD_GET_TIME_POS:{
3304 float pos = 0;
3305 if (sh_video)
3306 pos = sh_video->pts;
3307 else if (sh_audio && mpctx->audio_out)
3308 pos = playing_audio_pts(mpctx);
3309 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3311 break;
3313 case MP_CMD_RUN:
3314 #ifndef __MINGW32__
3315 if (!fork()) {
3316 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3317 exit(0);
3319 #endif
3320 break;
3322 case MP_CMD_KEYDOWN_EVENTS:
3323 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3324 break;
3326 case MP_CMD_SET_MOUSE_POS:{
3327 int pointer_x, pointer_y;
3328 double dx, dy;
3329 pointer_x = cmd->args[0].v.i;
3330 pointer_y = cmd->args[1].v.i;
3331 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3332 #ifdef CONFIG_DVDNAV
3333 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3334 && dx > 0.0 && dy > 0.0) {
3335 int button = -1;
3336 pointer_x = (int) (dx * (double) sh_video->disp_w);
3337 pointer_y = (int) (dy * (double) sh_video->disp_h);
3338 mp_dvdnav_update_mouse_pos(mpctx->stream,
3339 pointer_x, pointer_y, &button);
3340 if (opts->osd_level > 1 && button > 0)
3341 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3342 "Selected button number %d", button);
3344 #endif
3345 #ifdef CONFIG_MENU
3346 if (use_menu && dx >= 0.0 && dy >= 0.0)
3347 menu_update_mouse_pos(dx, dy);
3348 #endif
3350 break;
3352 #ifdef CONFIG_DVDNAV
3353 case MP_CMD_DVDNAV:{
3354 int button = -1;
3355 int i;
3356 mp_command_type command = 0;
3357 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3358 break;
3360 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3361 if (cmd->args[0].v.s &&
3362 !strcasecmp (cmd->args[0].v.s,
3363 mp_dvdnav_bindings[i].name))
3364 command = mp_dvdnav_bindings[i].cmd;
3366 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3367 if (opts->osd_level > 1 && button > 0)
3368 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3369 "Selected button number %d", button);
3371 break;
3373 case MP_CMD_SWITCH_TITLE:
3374 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3375 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3376 break;
3378 #endif
3380 default:
3381 mp_msg(MSGT_CPLAYER, MSGL_V,
3382 "Received unknown cmd %s\n", cmd->name);
3385 switch (cmd->pausing) {
3386 case 1: // "pausing"
3387 pause_player(mpctx);
3388 break;
3389 case 3: // "pausing_toggle"
3390 if (mpctx->paused)
3391 unpause_player(mpctx);
3392 else
3393 pause_player(mpctx);
3394 break;