Merge svn changes up to r30917
[mplayer/glamo.git] / command.c
blob9084ff37df19f13184109d8ff3d05f33522ab0a5
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdlib.h>
20 #include <inttypes.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <stdbool.h>
25 #include "config.h"
26 #include "talloc.h"
27 #include "command.h"
28 #include "input/input.h"
29 #include "stream/stream.h"
30 #include "libmpdemux/demuxer.h"
31 #include "libmpdemux/stheader.h"
32 #include "codec-cfg.h"
33 #include "mplayer.h"
34 #include "libvo/sub.h"
35 #include "m_option.h"
36 #include "m_property.h"
37 #include "metadata.h"
38 #include "libmpcodecs/vf.h"
39 #include "libmpcodecs/vd.h"
40 #include "mp_osd.h"
41 #include "libvo/video_out.h"
42 #include "libvo/font_load.h"
43 #include "playtree.h"
44 #include "libao2/audio_out.h"
45 #include "mpcommon.h"
46 #include "mixer.h"
47 #include "libmpcodecs/dec_video.h"
48 #include "libmpcodecs/dec_audio.h"
49 #include "libmpcodecs/dec_teletext.h"
50 #include "vobsub.h"
51 #include "spudec.h"
52 #include "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 < -1)
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 if (angle >= 0) {
528 struct sh_video *sh_video = mpctx->demuxer->video->sh;
529 if (sh_video)
530 resync_video_stream(sh_video);
532 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
533 if (sh_audio)
534 resync_audio_stream(sh_audio);
537 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
538 "Angle: %d/%d", angle, angles);
539 if (angle_name)
540 free(angle_name);
541 return M_PROPERTY_OK;
544 /// Demuxer meta data
545 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
546 MPContext *mpctx) {
547 m_property_action_t* ka;
548 char* meta;
549 static const m_option_t key_type =
550 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
551 if (!mpctx->demuxer)
552 return M_PROPERTY_UNAVAILABLE;
554 switch(action) {
555 case M_PROPERTY_GET:
556 if(!arg) return M_PROPERTY_ERROR;
557 *(char***)arg = mpctx->demuxer->info;
558 return M_PROPERTY_OK;
559 case M_PROPERTY_KEY_ACTION:
560 if(!arg) return M_PROPERTY_ERROR;
561 ka = arg;
562 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
563 return M_PROPERTY_UNKNOWN;
564 switch(ka->action) {
565 case M_PROPERTY_GET:
566 if(!ka->arg) return M_PROPERTY_ERROR;
567 *(char**)ka->arg = meta;
568 return M_PROPERTY_OK;
569 case M_PROPERTY_GET_TYPE:
570 if(!ka->arg) return M_PROPERTY_ERROR;
571 *(m_option_t**)ka->arg = &key_type;
572 return M_PROPERTY_OK;
575 return M_PROPERTY_NOT_IMPLEMENTED;
578 static int mp_property_pause(m_option_t *prop, int action, void *arg,
579 void *ctx)
581 MPContext *mpctx = ctx;
583 switch (action) {
584 case M_PROPERTY_SET:
585 if (!arg)
586 return M_PROPERTY_ERROR;
587 if (mpctx->paused == (bool)*(int *) arg)
588 return M_PROPERTY_OK;
589 case M_PROPERTY_STEP_UP:
590 case M_PROPERTY_STEP_DOWN:
591 if (mpctx->paused) {
592 unpause_player(mpctx);
593 mpctx->osd_function = OSD_PLAY;
595 else {
596 pause_player(mpctx);
597 mpctx->osd_function = OSD_PAUSE;
599 return M_PROPERTY_OK;
600 default:
601 return m_property_flag(prop, action, arg, &mpctx->paused);
606 ///@}
608 /// \defgroup AudioProperties Audio properties
609 /// \ingroup Properties
610 ///@{
612 /// Volume (RW)
613 static int mp_property_volume(m_option_t *prop, int action, void *arg,
614 MPContext *mpctx)
617 if (!mpctx->sh_audio)
618 return M_PROPERTY_UNAVAILABLE;
620 switch (action) {
621 case M_PROPERTY_GET:
622 if (!arg)
623 return M_PROPERTY_ERROR;
624 mixer_getbothvolume(&mpctx->mixer, arg);
625 return M_PROPERTY_OK;
626 case M_PROPERTY_PRINT:{
627 float vol;
628 if (!arg)
629 return M_PROPERTY_ERROR;
630 mixer_getbothvolume(&mpctx->mixer, &vol);
631 return m_property_float_range(prop, action, arg, &vol);
633 case M_PROPERTY_STEP_UP:
634 case M_PROPERTY_STEP_DOWN:
635 case M_PROPERTY_SET:
636 break;
637 default:
638 return M_PROPERTY_NOT_IMPLEMENTED;
641 if (mpctx->edl_muted)
642 return M_PROPERTY_DISABLED;
643 mpctx->user_muted = 0;
645 switch (action) {
646 case M_PROPERTY_SET:
647 if (!arg)
648 return M_PROPERTY_ERROR;
649 M_PROPERTY_CLAMP(prop, *(float *) arg);
650 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
651 return M_PROPERTY_OK;
652 case M_PROPERTY_STEP_UP:
653 if (arg && *(float *) arg <= 0)
654 mixer_decvolume(&mpctx->mixer);
655 else
656 mixer_incvolume(&mpctx->mixer);
657 return M_PROPERTY_OK;
658 case M_PROPERTY_STEP_DOWN:
659 if (arg && *(float *) arg <= 0)
660 mixer_incvolume(&mpctx->mixer);
661 else
662 mixer_decvolume(&mpctx->mixer);
663 return M_PROPERTY_OK;
665 return M_PROPERTY_NOT_IMPLEMENTED;
668 /// Mute (RW)
669 static int mp_property_mute(m_option_t *prop, int action, void *arg,
670 MPContext *mpctx)
673 if (!mpctx->sh_audio)
674 return M_PROPERTY_UNAVAILABLE;
676 switch (action) {
677 case M_PROPERTY_SET:
678 if (mpctx->edl_muted)
679 return M_PROPERTY_DISABLED;
680 if (!arg)
681 return M_PROPERTY_ERROR;
682 if ((!!*(int *) arg) != mpctx->mixer.muted)
683 mixer_mute(&mpctx->mixer);
684 mpctx->user_muted = mpctx->mixer.muted;
685 return M_PROPERTY_OK;
686 case M_PROPERTY_STEP_UP:
687 case M_PROPERTY_STEP_DOWN:
688 if (mpctx->edl_muted)
689 return M_PROPERTY_DISABLED;
690 mixer_mute(&mpctx->mixer);
691 mpctx->user_muted = mpctx->mixer.muted;
692 return M_PROPERTY_OK;
693 case M_PROPERTY_PRINT:
694 if (!arg)
695 return M_PROPERTY_ERROR;
696 if (mpctx->edl_muted) {
697 *(char **) arg = strdup(mp_gtext("enabled (EDL)"));
698 return M_PROPERTY_OK;
700 default:
701 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
706 /// Audio delay (RW)
707 static int mp_property_audio_delay(m_option_t *prop, int action,
708 void *arg, MPContext *mpctx)
710 if (!(mpctx->sh_audio && mpctx->sh_video))
711 return M_PROPERTY_UNAVAILABLE;
712 switch (action) {
713 case M_PROPERTY_SET:
714 case M_PROPERTY_STEP_UP:
715 case M_PROPERTY_STEP_DOWN: {
716 int ret;
717 float delay = audio_delay;
718 ret = m_property_delay(prop, action, arg, &audio_delay);
719 if (ret != M_PROPERTY_OK)
720 return ret;
721 if (mpctx->sh_audio)
722 mpctx->delay -= audio_delay - delay;
724 return M_PROPERTY_OK;
725 default:
726 return m_property_delay(prop, action, arg, &audio_delay);
730 /// Audio codec tag (RO)
731 static int mp_property_audio_format(m_option_t *prop, int action,
732 void *arg, MPContext *mpctx)
734 if (!mpctx->sh_audio)
735 return M_PROPERTY_UNAVAILABLE;
736 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
739 /// Audio codec name (RO)
740 static int mp_property_audio_codec(m_option_t *prop, int action,
741 void *arg, MPContext *mpctx)
743 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
744 return M_PROPERTY_UNAVAILABLE;
745 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
748 /// Audio bitrate (RO)
749 static int mp_property_audio_bitrate(m_option_t *prop, int action,
750 void *arg, MPContext *mpctx)
752 if (!mpctx->sh_audio)
753 return M_PROPERTY_UNAVAILABLE;
754 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
757 /// Samplerate (RO)
758 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
759 MPContext *mpctx)
761 if (!mpctx->sh_audio)
762 return M_PROPERTY_UNAVAILABLE;
763 switch(action) {
764 case M_PROPERTY_PRINT:
765 if(!arg) return M_PROPERTY_ERROR;
766 *(char**)arg = malloc(16);
767 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
768 return M_PROPERTY_OK;
770 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
773 /// Number of channels (RO)
774 static int mp_property_channels(m_option_t *prop, int action, void *arg,
775 MPContext *mpctx)
777 if (!mpctx->sh_audio)
778 return M_PROPERTY_UNAVAILABLE;
779 switch (action) {
780 case M_PROPERTY_PRINT:
781 if (!arg)
782 return M_PROPERTY_ERROR;
783 switch (mpctx->sh_audio->channels) {
784 case 1:
785 *(char **) arg = strdup("mono");
786 break;
787 case 2:
788 *(char **) arg = strdup("stereo");
789 break;
790 default:
791 *(char **) arg = malloc(32);
792 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
794 return M_PROPERTY_OK;
796 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
799 /// Balance (RW)
800 static int mp_property_balance(m_option_t *prop, int action, void *arg,
801 MPContext *mpctx)
803 float bal;
805 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
806 return M_PROPERTY_UNAVAILABLE;
808 switch (action) {
809 case M_PROPERTY_GET:
810 if (!arg)
811 return M_PROPERTY_ERROR;
812 mixer_getbalance(&mpctx->mixer, arg);
813 return M_PROPERTY_OK;
814 case M_PROPERTY_PRINT: {
815 char** str = arg;
816 if (!arg)
817 return M_PROPERTY_ERROR;
818 mixer_getbalance(&mpctx->mixer, &bal);
819 if (bal == 0.f)
820 *str = strdup("center");
821 else if (bal == -1.f)
822 *str = strdup("left only");
823 else if (bal == 1.f)
824 *str = strdup("right only");
825 else {
826 unsigned right = (bal + 1.f) / 2.f * 100.f;
827 *str = malloc(sizeof("left xxx%, right xxx%"));
828 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
830 return M_PROPERTY_OK;
832 case M_PROPERTY_STEP_UP:
833 case M_PROPERTY_STEP_DOWN:
834 mixer_getbalance(&mpctx->mixer, &bal);
835 bal += (arg ? *(float*)arg : .1f) *
836 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
837 M_PROPERTY_CLAMP(prop, bal);
838 mixer_setbalance(&mpctx->mixer, bal);
839 return M_PROPERTY_OK;
840 case M_PROPERTY_SET:
841 if (!arg)
842 return M_PROPERTY_ERROR;
843 M_PROPERTY_CLAMP(prop, *(float*)arg);
844 mixer_setbalance(&mpctx->mixer, *(float*)arg);
845 return M_PROPERTY_OK;
847 return M_PROPERTY_NOT_IMPLEMENTED;
850 /// Selected audio id (RW)
851 static int mp_property_audio(m_option_t *prop, int action, void *arg,
852 MPContext *mpctx)
854 struct MPOpts *opts = &mpctx->opts;
855 int current_id, tmp;
856 if (!mpctx->demuxer || !mpctx->demuxer->audio)
857 return M_PROPERTY_UNAVAILABLE;
858 current_id = mpctx->demuxer->audio->id;
860 switch (action) {
861 case M_PROPERTY_GET:
862 if (!arg)
863 return M_PROPERTY_ERROR;
864 *(int *) arg = current_id;
865 return M_PROPERTY_OK;
866 case M_PROPERTY_PRINT:
867 if (!arg)
868 return M_PROPERTY_ERROR;
870 if (current_id < 0)
871 *(char **) arg = strdup(mp_gtext("disabled"));
872 else {
873 char lang[40];
874 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
875 sh_audio_t* sh = mpctx->sh_audio;
876 if (sh && sh->lang)
877 av_strlcpy(lang, sh->lang, 40);
878 #ifdef CONFIG_DVDREAD
879 else if (mpctx->stream->type == STREAMTYPE_DVD) {
880 int code = dvd_lang_from_aid(mpctx->stream, current_id);
881 if (code) {
882 lang[0] = code >> 8;
883 lang[1] = code;
884 lang[2] = 0;
887 #endif
889 #ifdef CONFIG_DVDNAV
890 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
891 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
892 #endif
893 *(char **) arg = malloc(64);
894 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
896 return M_PROPERTY_OK;
898 case M_PROPERTY_STEP_UP:
899 case M_PROPERTY_SET:
900 if (action == M_PROPERTY_SET && arg)
901 tmp = *((int *) arg);
902 else
903 tmp = -1;
904 opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
905 if (opts->audio_id == -2
906 || (opts->audio_id > -1
907 && mpctx->demuxer->audio->id != current_id && current_id != -2))
908 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
909 if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
910 sh_audio_t *sh2;
911 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
912 if (sh2) {
913 sh2->ds = mpctx->demuxer->audio;
914 mpctx->sh_audio = sh2;
915 reinit_audio_chain(mpctx);
918 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id);
919 return M_PROPERTY_OK;
920 default:
921 return M_PROPERTY_NOT_IMPLEMENTED;
926 /// Selected video id (RW)
927 static int mp_property_video(m_option_t *prop, int action, void *arg,
928 MPContext *mpctx)
930 struct MPOpts *opts = &mpctx->opts;
931 int current_id, tmp;
932 if (!mpctx->demuxer || !mpctx->demuxer->video)
933 return M_PROPERTY_UNAVAILABLE;
934 current_id = mpctx->demuxer->video->id;
936 switch (action) {
937 case M_PROPERTY_GET:
938 if (!arg)
939 return M_PROPERTY_ERROR;
940 *(int *) arg = current_id;
941 return M_PROPERTY_OK;
942 case M_PROPERTY_PRINT:
943 if (!arg)
944 return M_PROPERTY_ERROR;
946 if (current_id < 0)
947 *(char **) arg = strdup(mp_gtext("disabled"));
948 else {
949 char lang[40];
950 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
951 *(char **) arg = malloc(64);
952 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
954 return M_PROPERTY_OK;
956 case M_PROPERTY_STEP_UP:
957 case M_PROPERTY_SET:
958 if (action == M_PROPERTY_SET && arg)
959 tmp = *((int *) arg);
960 else
961 tmp = -1;
962 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
963 if (opts->video_id == -2
964 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
965 && current_id != -2))
966 uninit_player(mpctx, INITIALIZED_VCODEC |
967 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
968 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
969 sh_video_t *sh2;
970 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
971 if (sh2) {
972 sh2->ds = mpctx->demuxer->video;
973 mpctx->sh_video = sh2;
974 reinit_video_chain(mpctx);
977 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
978 return M_PROPERTY_OK;
980 default:
981 return M_PROPERTY_NOT_IMPLEMENTED;
985 static int mp_property_program(m_option_t *prop, int action, void *arg,
986 MPContext *mpctx)
988 demux_program_t prog;
990 switch (action) {
991 case M_PROPERTY_STEP_UP:
992 case M_PROPERTY_SET:
993 if (action == M_PROPERTY_SET && arg)
994 prog.progid = *((int *) arg);
995 else
996 prog.progid = -1;
997 if (demux_control
998 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
999 &prog) == DEMUXER_CTRL_NOTIMPL)
1000 return M_PROPERTY_ERROR;
1002 if (prog.aid < 0 && prog.vid < 0) {
1003 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
1004 return M_PROPERTY_ERROR;
1006 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1007 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1008 return M_PROPERTY_OK;
1010 default:
1011 return M_PROPERTY_NOT_IMPLEMENTED;
1015 ///@}
1017 /// \defgroup VideoProperties Video properties
1018 /// \ingroup Properties
1019 ///@{
1021 /// Fullscreen state (RW)
1022 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1023 MPContext *mpctx)
1026 if (!mpctx->video_out)
1027 return M_PROPERTY_UNAVAILABLE;
1029 switch (action) {
1030 case M_PROPERTY_SET:
1031 if (!arg)
1032 return M_PROPERTY_ERROR;
1033 M_PROPERTY_CLAMP(prop, *(int *) arg);
1034 if (vo_fs == !!*(int *) arg)
1035 return M_PROPERTY_OK;
1036 case M_PROPERTY_STEP_UP:
1037 case M_PROPERTY_STEP_DOWN:
1038 if (mpctx->video_out->config_ok)
1039 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1040 mpctx->opts.fullscreen = vo_fs;
1041 return M_PROPERTY_OK;
1042 default:
1043 return m_property_flag(prop, action, arg, &vo_fs);
1047 static int mp_property_deinterlace(m_option_t *prop, int action,
1048 void *arg, MPContext *mpctx)
1050 int deinterlace;
1051 vf_instance_t *vf;
1052 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1053 return M_PROPERTY_UNAVAILABLE;
1054 vf = mpctx->sh_video->vfilter;
1055 switch (action) {
1056 case M_PROPERTY_GET:
1057 if (!arg)
1058 return M_PROPERTY_ERROR;
1059 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1060 return M_PROPERTY_OK;
1061 case M_PROPERTY_SET:
1062 if (!arg)
1063 return M_PROPERTY_ERROR;
1064 M_PROPERTY_CLAMP(prop, *(int *) arg);
1065 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1066 return M_PROPERTY_OK;
1067 case M_PROPERTY_STEP_UP:
1068 case M_PROPERTY_STEP_DOWN:
1069 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1070 deinterlace = !deinterlace;
1071 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1072 return M_PROPERTY_OK;
1074 int value = 0;
1075 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1076 return m_property_flag_ro(prop, action, arg, value);
1079 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1080 void *arg, MPContext *mpctx)
1082 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1083 return M_PROPERTY_UNAVAILABLE;
1085 struct vf_instance *vf = mpctx->sh_video->vfilter;
1086 int colorspace;
1087 switch (action) {
1088 case M_PROPERTY_GET:
1089 if (!arg)
1090 return M_PROPERTY_ERROR;
1091 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1092 return M_PROPERTY_UNAVAILABLE;
1093 return M_PROPERTY_OK;
1094 case M_PROPERTY_PRINT:
1095 if (!arg)
1096 return M_PROPERTY_ERROR;
1097 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1098 return M_PROPERTY_UNAVAILABLE;
1099 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1100 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1101 *(char **)arg = strdup("Unknown");
1102 else
1103 *(char**)arg = strdup(names[colorspace]);
1104 return M_PROPERTY_OK;
1105 case M_PROPERTY_SET:
1106 if (!arg)
1107 return M_PROPERTY_ERROR;
1108 M_PROPERTY_CLAMP(prop, *(int *) arg);
1109 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1110 return M_PROPERTY_OK;
1111 case M_PROPERTY_STEP_UP:;
1112 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1113 return M_PROPERTY_UNAVAILABLE;
1114 colorspace += 1;
1115 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1116 return M_PROPERTY_OK;
1118 return M_PROPERTY_NOT_IMPLEMENTED;
1121 /// Panscan (RW)
1122 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1123 MPContext *mpctx)
1126 if (!mpctx->video_out
1127 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1128 return M_PROPERTY_UNAVAILABLE;
1130 switch (action) {
1131 case M_PROPERTY_SET:
1132 if (!arg)
1133 return M_PROPERTY_ERROR;
1134 M_PROPERTY_CLAMP(prop, *(float *) arg);
1135 vo_panscan = *(float *) arg;
1136 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1137 return M_PROPERTY_OK;
1138 case M_PROPERTY_STEP_UP:
1139 case M_PROPERTY_STEP_DOWN:
1140 vo_panscan += (arg ? *(float *) arg : 0.1) *
1141 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1142 if (vo_panscan > 1)
1143 vo_panscan = 1;
1144 else if (vo_panscan < 0)
1145 vo_panscan = 0;
1146 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1147 return M_PROPERTY_OK;
1148 default:
1149 return m_property_float_range(prop, action, arg, &vo_panscan);
1153 /// Helper to set vo flags.
1154 /** \ingroup PropertyImplHelper
1156 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1157 int vo_ctrl, int *vo_var, MPContext *mpctx)
1160 if (!mpctx->video_out)
1161 return M_PROPERTY_UNAVAILABLE;
1163 switch (action) {
1164 case M_PROPERTY_SET:
1165 if (!arg)
1166 return M_PROPERTY_ERROR;
1167 M_PROPERTY_CLAMP(prop, *(int *) arg);
1168 if (*vo_var == !!*(int *) arg)
1169 return M_PROPERTY_OK;
1170 case M_PROPERTY_STEP_UP:
1171 case M_PROPERTY_STEP_DOWN:
1172 if (mpctx->video_out->config_ok)
1173 vo_control(mpctx->video_out, vo_ctrl, 0);
1174 return M_PROPERTY_OK;
1175 default:
1176 return m_property_flag(prop, action, arg, vo_var);
1180 /// Window always on top (RW)
1181 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1182 MPContext *mpctx)
1184 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1185 &mpctx->opts.vo_ontop, mpctx);
1188 /// Display in the root window (RW)
1189 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1190 MPContext *mpctx)
1192 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1193 &vo_rootwin, mpctx);
1196 /// Show window borders (RW)
1197 static int mp_property_border(m_option_t *prop, int action, void *arg,
1198 MPContext *mpctx)
1200 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1201 &vo_border, mpctx);
1204 /// Framedropping state (RW)
1205 static int mp_property_framedropping(m_option_t *prop, int action,
1206 void *arg, MPContext *mpctx)
1209 if (!mpctx->sh_video)
1210 return M_PROPERTY_UNAVAILABLE;
1212 switch (action) {
1213 case M_PROPERTY_PRINT:
1214 if (!arg)
1215 return M_PROPERTY_ERROR;
1216 *(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
1217 (frame_dropping == 2 ? mp_gtext("hard") :
1218 mp_gtext("disabled")));
1219 return M_PROPERTY_OK;
1220 default:
1221 return m_property_choice(prop, action, arg, &frame_dropping);
1225 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1226 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1227 MPContext *mpctx)
1229 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1230 int r, val;
1232 if (!mpctx->sh_video)
1233 return M_PROPERTY_UNAVAILABLE;
1235 if (gamma[0] == 1000) {
1236 gamma[0] = 0;
1237 get_video_colors(mpctx->sh_video, prop->name, gamma);
1240 switch (action) {
1241 case M_PROPERTY_SET:
1242 if (!arg)
1243 return M_PROPERTY_ERROR;
1244 M_PROPERTY_CLAMP(prop, *(int *) arg);
1245 *gamma = *(int *) arg;
1246 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1247 if (r <= 0)
1248 break;
1249 return r;
1250 case M_PROPERTY_GET:
1251 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1252 if (!arg)
1253 return M_PROPERTY_ERROR;
1254 *(int *)arg = val;
1255 return M_PROPERTY_OK;
1257 break;
1258 case M_PROPERTY_STEP_UP:
1259 case M_PROPERTY_STEP_DOWN:
1260 *gamma += (arg ? *(int *) arg : 1) *
1261 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1262 M_PROPERTY_CLAMP(prop, *gamma);
1263 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1264 if (r <= 0)
1265 break;
1266 return r;
1267 default:
1268 return M_PROPERTY_NOT_IMPLEMENTED;
1271 #ifdef CONFIG_TV
1272 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1273 int l = strlen(prop->name);
1274 char tv_prop[3 + l + 1];
1275 sprintf(tv_prop, "tv_%s", prop->name);
1276 return mp_property_do(tv_prop, action, arg, mpctx);
1278 #endif
1280 return M_PROPERTY_UNAVAILABLE;
1283 /// VSync (RW)
1284 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1285 MPContext *mpctx)
1287 return m_property_flag(prop, action, arg, &vo_vsync);
1290 /// Video codec tag (RO)
1291 static int mp_property_video_format(m_option_t *prop, int action,
1292 void *arg, MPContext *mpctx)
1294 char* meta;
1295 if (!mpctx->sh_video)
1296 return M_PROPERTY_UNAVAILABLE;
1297 switch(action) {
1298 case M_PROPERTY_PRINT:
1299 if (!arg)
1300 return M_PROPERTY_ERROR;
1301 switch(mpctx->sh_video->format) {
1302 case 0x10000001:
1303 meta = strdup ("mpeg1"); break;
1304 case 0x10000002:
1305 meta = strdup ("mpeg2"); break;
1306 case 0x10000004:
1307 meta = strdup ("mpeg4"); break;
1308 case 0x10000005:
1309 meta = strdup ("h264"); break;
1310 default:
1311 if(mpctx->sh_video->format >= 0x20202020) {
1312 meta = malloc(5);
1313 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1314 } else {
1315 meta = malloc(20);
1316 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1319 *(char**)arg = meta;
1320 return M_PROPERTY_OK;
1322 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1325 /// Video codec name (RO)
1326 static int mp_property_video_codec(m_option_t *prop, int action,
1327 void *arg, MPContext *mpctx)
1329 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1330 return M_PROPERTY_UNAVAILABLE;
1331 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1335 /// Video bitrate (RO)
1336 static int mp_property_video_bitrate(m_option_t *prop, int action,
1337 void *arg, MPContext *mpctx)
1339 if (!mpctx->sh_video)
1340 return M_PROPERTY_UNAVAILABLE;
1341 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1344 /// Video display width (RO)
1345 static int mp_property_width(m_option_t *prop, int action, void *arg,
1346 MPContext *mpctx)
1348 if (!mpctx->sh_video)
1349 return M_PROPERTY_UNAVAILABLE;
1350 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1353 /// Video display height (RO)
1354 static int mp_property_height(m_option_t *prop, int action, void *arg,
1355 MPContext *mpctx)
1357 if (!mpctx->sh_video)
1358 return M_PROPERTY_UNAVAILABLE;
1359 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1362 /// Video fps (RO)
1363 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1364 MPContext *mpctx)
1366 if (!mpctx->sh_video)
1367 return M_PROPERTY_UNAVAILABLE;
1368 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1371 /// Video aspect (RO)
1372 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1373 MPContext *mpctx)
1375 if (!mpctx->sh_video)
1376 return M_PROPERTY_UNAVAILABLE;
1377 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1380 ///@}
1382 /// \defgroup SubProprties Subtitles properties
1383 /// \ingroup Properties
1384 ///@{
1386 /// Text subtitle position (RW)
1387 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1388 MPContext *mpctx)
1390 switch (action) {
1391 case M_PROPERTY_SET:
1392 if (!arg)
1393 return M_PROPERTY_ERROR;
1394 case M_PROPERTY_STEP_UP:
1395 case M_PROPERTY_STEP_DOWN:
1396 vo_osd_changed(OSDTYPE_SUBTITLE);
1397 default:
1398 return m_property_int_range(prop, action, arg, &sub_pos);
1402 /// Selected subtitles (RW)
1403 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1404 MPContext *mpctx)
1406 struct MPOpts *opts = &mpctx->opts;
1407 demux_stream_t *const d_sub = mpctx->d_sub;
1408 const int global_sub_size = mpctx->global_sub_size;
1409 int source = -1, reset_spu = 0;
1410 char *sub_name;
1412 if (global_sub_size <= 0)
1413 return M_PROPERTY_UNAVAILABLE;
1415 switch (action) {
1416 case M_PROPERTY_GET:
1417 if (!arg)
1418 return M_PROPERTY_ERROR;
1419 *(int *) arg = mpctx->global_sub_pos;
1420 return M_PROPERTY_OK;
1421 case M_PROPERTY_PRINT:
1422 if (!arg)
1423 return M_PROPERTY_ERROR;
1424 *(char **) arg = malloc(64);
1425 (*(char **) arg)[63] = 0;
1426 sub_name = 0;
1427 if (subdata)
1428 sub_name = subdata->filename;
1429 #ifdef CONFIG_ASS
1430 if (ass_track && ass_track->name)
1431 sub_name = ass_track->name;
1432 #endif
1433 if (sub_name) {
1434 char *tmp, *tmp2;
1435 tmp = sub_name;
1436 if ((tmp2 = strrchr(tmp, '/')))
1437 tmp = tmp2 + 1;
1439 snprintf(*(char **) arg, 63, "(%d) %s%s",
1440 mpctx->set_of_sub_pos + 1,
1441 strlen(tmp) < 20 ? "" : "...",
1442 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1443 return M_PROPERTY_OK;
1445 #ifdef CONFIG_DVDNAV
1446 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1447 if (vo_spudec && opts->sub_id >= 0) {
1448 unsigned char lang[3];
1449 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1450 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1451 return M_PROPERTY_OK;
1455 #endif
1457 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1458 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1459 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1460 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1461 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1462 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1463 if (!lang) lang = mp_gtext("unknown");
1464 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1465 return M_PROPERTY_OK;
1468 if (vo_vobsub && vobsub_id >= 0) {
1469 const char *language = mp_gtext("unknown");
1470 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1471 snprintf(*(char **) arg, 63, "(%d) %s",
1472 vobsub_id, language ? language : mp_gtext("unknown"));
1473 return M_PROPERTY_OK;
1475 #ifdef CONFIG_DVDREAD
1476 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1477 && opts->sub_id >= 0) {
1478 char lang[3];
1479 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1480 lang[0] = code >> 8;
1481 lang[1] = code;
1482 lang[2] = 0;
1483 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1484 return M_PROPERTY_OK;
1486 #endif
1487 if (opts->sub_id >= 0) {
1488 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
1489 mp_gtext("unknown"));
1490 return M_PROPERTY_OK;
1492 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1493 return M_PROPERTY_OK;
1495 case M_PROPERTY_SET:
1496 if (!arg)
1497 return M_PROPERTY_ERROR;
1498 if (*(int *) arg < -1)
1499 *(int *) arg = -1;
1500 else if (*(int *) arg >= global_sub_size)
1501 *(int *) arg = global_sub_size - 1;
1502 mpctx->global_sub_pos = *(int *) arg;
1503 break;
1504 case M_PROPERTY_STEP_UP:
1505 mpctx->global_sub_pos += 2;
1506 mpctx->global_sub_pos =
1507 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1508 break;
1509 case M_PROPERTY_STEP_DOWN:
1510 mpctx->global_sub_pos += global_sub_size + 1;
1511 mpctx->global_sub_pos =
1512 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1513 break;
1514 default:
1515 return M_PROPERTY_NOT_IMPLEMENTED;
1518 if (mpctx->global_sub_pos >= 0)
1519 source = sub_source(mpctx);
1521 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1522 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1523 global_sub_size,
1524 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1525 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1526 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1527 mpctx->global_sub_pos, source);
1529 mpctx->set_of_sub_pos = -1;
1530 subdata = NULL;
1532 vobsub_id = -1;
1533 opts->sub_id = -1;
1534 if (d_sub) {
1535 if (d_sub->id > -2)
1536 reset_spu = 1;
1537 d_sub->id = -2;
1539 #ifdef CONFIG_ASS
1540 ass_track = 0;
1541 #endif
1543 if (source == SUB_SOURCE_VOBSUB) {
1544 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1545 } else if (source == SUB_SOURCE_SUBS) {
1546 mpctx->set_of_sub_pos =
1547 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1548 #ifdef CONFIG_ASS
1549 if (opts->ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1550 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1551 else
1552 #endif
1554 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1555 vo_osd_changed(OSDTYPE_SUBTITLE);
1557 } else if (source == SUB_SOURCE_DEMUX) {
1558 opts->sub_id =
1559 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1560 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1561 int i = 0;
1562 // default: assume 1:1 mapping of sid and stream id
1563 d_sub->id = opts->sub_id;
1564 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1565 ds_free_packs(d_sub);
1566 for (i = 0; i < MAX_S_STREAMS; i++) {
1567 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1568 if (sh && sh->sid == opts->sub_id) {
1569 d_sub->id = i;
1570 d_sub->sh = sh;
1571 break;
1574 if (d_sub->sh && d_sub->id >= 0) {
1575 sh_sub_t *sh = d_sub->sh;
1576 if (sh->type == 'v')
1577 init_vo_spudec(mpctx);
1578 #ifdef CONFIG_ASS
1579 else if (opts->ass_enabled)
1580 ass_track = sh->ass_track;
1581 #endif
1582 } else {
1583 d_sub->id = -2;
1584 d_sub->sh = NULL;
1588 #ifdef CONFIG_DVDREAD
1589 if (vo_spudec
1590 && (mpctx->stream->type == STREAMTYPE_DVD
1591 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1592 && opts->sub_id < 0 && reset_spu) {
1593 d_sub->id = -2;
1594 d_sub->sh = NULL;
1596 #endif
1598 update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, 0, 0, d_sub, 1);
1600 return M_PROPERTY_OK;
1603 /// Selected sub source (RW)
1604 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1605 MPContext *mpctx)
1607 int source;
1608 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1609 return M_PROPERTY_UNAVAILABLE;
1611 switch (action) {
1612 case M_PROPERTY_GET:
1613 if (!arg)
1614 return M_PROPERTY_ERROR;
1615 *(int *) arg = sub_source(mpctx);
1616 return M_PROPERTY_OK;
1617 case M_PROPERTY_PRINT:
1618 if (!arg)
1619 return M_PROPERTY_ERROR;
1620 *(char **) arg = malloc(64);
1621 (*(char **) arg)[63] = 0;
1622 switch (sub_source(mpctx))
1624 case SUB_SOURCE_SUBS:
1625 snprintf(*(char **) arg, 63, mp_gtext("file"));
1626 break;
1627 case SUB_SOURCE_VOBSUB:
1628 snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
1629 break;
1630 case SUB_SOURCE_DEMUX:
1631 snprintf(*(char **) arg, 63, mp_gtext("embedded"));
1632 break;
1633 default:
1634 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1636 return M_PROPERTY_OK;
1637 case M_PROPERTY_SET:
1638 if (!arg)
1639 return M_PROPERTY_ERROR;
1640 M_PROPERTY_CLAMP(prop, *(int*)arg);
1641 if (*(int *) arg < 0)
1642 mpctx->global_sub_pos = -1;
1643 else if (*(int *) arg != sub_source(mpctx)) {
1644 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1645 return M_PROPERTY_UNAVAILABLE;
1646 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1648 break;
1649 case M_PROPERTY_STEP_UP:
1650 case M_PROPERTY_STEP_DOWN: {
1651 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1652 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1653 int step = (step_all > 0) ? 1 : -1;
1654 int cur_source = sub_source(mpctx);
1655 source = cur_source;
1656 while (step_all) {
1657 source += step;
1658 if (source >= SUB_SOURCES)
1659 source = -1;
1660 else if (source < -1)
1661 source = SUB_SOURCES - 1;
1662 if (source == cur_source || source == -1 ||
1663 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1664 step_all -= step;
1666 if (source == cur_source)
1667 return M_PROPERTY_OK;
1668 if (source == -1)
1669 mpctx->global_sub_pos = -1;
1670 else
1671 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1672 break;
1674 default:
1675 return M_PROPERTY_NOT_IMPLEMENTED;
1677 --mpctx->global_sub_pos;
1678 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1681 /// Selected subtitles from specific source (RW)
1682 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1683 MPContext *mpctx)
1685 int source, is_cur_source, offset;
1686 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1687 return M_PROPERTY_UNAVAILABLE;
1689 if (!strcmp(prop->name, "sub_file"))
1690 source = SUB_SOURCE_SUBS;
1691 else if (!strcmp(prop->name, "sub_vob"))
1692 source = SUB_SOURCE_VOBSUB;
1693 else if (!strcmp(prop->name, "sub_demux"))
1694 source = SUB_SOURCE_DEMUX;
1695 else
1696 return M_PROPERTY_ERROR;
1698 offset = mpctx->global_sub_indices[source];
1699 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1700 return M_PROPERTY_UNAVAILABLE;
1702 is_cur_source = sub_source(mpctx) == source;
1703 switch (action) {
1704 case M_PROPERTY_GET:
1705 if (!arg)
1706 return M_PROPERTY_ERROR;
1707 if (is_cur_source) {
1708 *(int *) arg = mpctx->global_sub_pos - offset;
1709 if (source == SUB_SOURCE_VOBSUB)
1710 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1712 else
1713 *(int *) arg = -1;
1714 return M_PROPERTY_OK;
1715 case M_PROPERTY_PRINT:
1716 if (!arg)
1717 return M_PROPERTY_ERROR;
1718 if (is_cur_source)
1719 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1720 *(char **) arg = malloc(64);
1721 (*(char **) arg)[63] = 0;
1722 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1723 return M_PROPERTY_OK;
1724 case M_PROPERTY_SET:
1725 if (!arg)
1726 return M_PROPERTY_ERROR;
1727 if (*(int *) arg >= 0) {
1728 int index = *(int *)arg;
1729 if (source == SUB_SOURCE_VOBSUB)
1730 index = vobsub_get_index_by_id(vo_vobsub, index);
1731 mpctx->global_sub_pos = offset + index;
1732 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1733 || sub_source(mpctx) != source) {
1734 mpctx->global_sub_pos = -1;
1735 *(int *) arg = -1;
1738 else
1739 mpctx->global_sub_pos = -1;
1740 break;
1741 case M_PROPERTY_STEP_UP:
1742 case M_PROPERTY_STEP_DOWN: {
1743 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1744 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1745 int step = (step_all > 0) ? 1 : -1;
1746 int max_sub_pos_for_source = -1;
1747 if (!is_cur_source)
1748 mpctx->global_sub_pos = -1;
1749 while (step_all) {
1750 if (mpctx->global_sub_pos == -1) {
1751 if (step > 0)
1752 mpctx->global_sub_pos = offset;
1753 else if (max_sub_pos_for_source == -1) {
1754 // Find max pos for specific source
1755 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1756 while (mpctx->global_sub_pos >= 0
1757 && sub_source(mpctx) != source)
1758 --mpctx->global_sub_pos;
1760 else
1761 mpctx->global_sub_pos = max_sub_pos_for_source;
1763 else {
1764 mpctx->global_sub_pos += step;
1765 if (mpctx->global_sub_pos < offset ||
1766 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1767 sub_source(mpctx) != source)
1768 mpctx->global_sub_pos = -1;
1770 step_all -= step;
1772 break;
1774 default:
1775 return M_PROPERTY_NOT_IMPLEMENTED;
1777 --mpctx->global_sub_pos;
1778 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1781 /// Subtitle delay (RW)
1782 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1783 MPContext *mpctx)
1785 if (!mpctx->sh_video)
1786 return M_PROPERTY_UNAVAILABLE;
1787 return m_property_delay(prop, action, arg, &sub_delay);
1790 /// Alignment of text subtitles (RW)
1791 static int mp_property_sub_alignment(m_option_t *prop, int action,
1792 void *arg, MPContext *mpctx)
1794 char *name[] = { _("top"), _("center"), _("bottom") };
1796 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1797 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1798 return M_PROPERTY_UNAVAILABLE;
1800 switch (action) {
1801 case M_PROPERTY_PRINT:
1802 if (!arg)
1803 return M_PROPERTY_ERROR;
1804 M_PROPERTY_CLAMP(prop, sub_alignment);
1805 *(char **) arg = strdup(mp_gtext(name[sub_alignment]));
1806 return M_PROPERTY_OK;
1807 case M_PROPERTY_SET:
1808 if (!arg)
1809 return M_PROPERTY_ERROR;
1810 case M_PROPERTY_STEP_UP:
1811 case M_PROPERTY_STEP_DOWN:
1812 vo_osd_changed(OSDTYPE_SUBTITLE);
1813 default:
1814 return m_property_choice(prop, action, arg, &sub_alignment);
1818 /// Subtitle visibility (RW)
1819 static int mp_property_sub_visibility(m_option_t *prop, int action,
1820 void *arg, MPContext *mpctx)
1822 if (!mpctx->sh_video)
1823 return M_PROPERTY_UNAVAILABLE;
1825 switch (action) {
1826 case M_PROPERTY_SET:
1827 if (!arg)
1828 return M_PROPERTY_ERROR;
1829 case M_PROPERTY_STEP_UP:
1830 case M_PROPERTY_STEP_DOWN:
1831 vo_osd_changed(OSDTYPE_SUBTITLE);
1832 if (vo_spudec)
1833 vo_osd_changed(OSDTYPE_SPU);
1834 default:
1835 return m_property_flag(prop, action, arg, &sub_visibility);
1839 #ifdef CONFIG_ASS
1840 /// Use margins for libass subtitles (RW)
1841 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1842 void *arg, MPContext *mpctx)
1844 if (!mpctx->sh_video)
1845 return M_PROPERTY_UNAVAILABLE;
1847 switch (action) {
1848 case M_PROPERTY_SET:
1849 if (!arg)
1850 return M_PROPERTY_ERROR;
1851 case M_PROPERTY_STEP_UP:
1852 case M_PROPERTY_STEP_DOWN:
1853 ass_force_reload = 1;
1854 default:
1855 return m_property_flag(prop, action, arg, &ass_use_margins);
1858 #endif
1860 /// Show only forced subtitles (RW)
1861 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1862 void *arg, MPContext *mpctx)
1864 if (!vo_spudec)
1865 return M_PROPERTY_UNAVAILABLE;
1867 switch (action) {
1868 case M_PROPERTY_SET:
1869 if (!arg)
1870 return M_PROPERTY_ERROR;
1871 case M_PROPERTY_STEP_UP:
1872 case M_PROPERTY_STEP_DOWN:
1873 m_property_flag(prop, action, arg, &forced_subs_only);
1874 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1875 return M_PROPERTY_OK;
1876 default:
1877 return m_property_flag(prop, action, arg, &forced_subs_only);
1882 #ifdef CONFIG_FREETYPE
1883 /// Subtitle scale (RW)
1884 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1885 MPContext *mpctx)
1887 struct MPOpts *opts = &mpctx->opts;
1889 switch (action) {
1890 case M_PROPERTY_SET:
1891 if (!arg)
1892 return M_PROPERTY_ERROR;
1893 M_PROPERTY_CLAMP(prop, *(float *) arg);
1894 #ifdef CONFIG_ASS
1895 if (opts->ass_enabled) {
1896 ass_font_scale = *(float *) arg;
1897 ass_force_reload = 1;
1899 #endif
1900 text_font_scale_factor = *(float *) arg;
1901 force_load_font = 1;
1902 return M_PROPERTY_OK;
1903 case M_PROPERTY_STEP_UP:
1904 case M_PROPERTY_STEP_DOWN:
1905 #ifdef CONFIG_ASS
1906 if (opts->ass_enabled) {
1907 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1908 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1909 M_PROPERTY_CLAMP(prop, ass_font_scale);
1910 ass_force_reload = 1;
1912 #endif
1913 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1914 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1915 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1916 force_load_font = 1;
1917 return M_PROPERTY_OK;
1918 default:
1919 #ifdef CONFIG_ASS
1920 if (opts->ass_enabled)
1921 return m_property_float_ro(prop, action, arg, ass_font_scale);
1922 else
1923 #endif
1924 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1927 #endif
1929 ///@}
1931 /// \defgroup TVProperties TV properties
1932 /// \ingroup Properties
1933 ///@{
1935 #ifdef CONFIG_TV
1937 /// TV color settings (RW)
1938 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1939 MPContext *mpctx)
1941 int r, val;
1942 tvi_handle_t *tvh = mpctx->demuxer->priv;
1943 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1944 return M_PROPERTY_UNAVAILABLE;
1946 switch (action) {
1947 case M_PROPERTY_SET:
1948 if (!arg)
1949 return M_PROPERTY_ERROR;
1950 M_PROPERTY_CLAMP(prop, *(int *) arg);
1951 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1952 case M_PROPERTY_GET:
1953 return tv_get_color_options(tvh, (int) prop->priv, arg);
1954 case M_PROPERTY_STEP_UP:
1955 case M_PROPERTY_STEP_DOWN:
1956 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1957 if (!r)
1958 return M_PROPERTY_ERROR;
1959 val += (arg ? *(int *) arg : 1) *
1960 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1961 M_PROPERTY_CLAMP(prop, val);
1962 return tv_set_color_options(tvh, (int) prop->priv, val);
1964 return M_PROPERTY_ERROR;
1966 return M_PROPERTY_NOT_IMPLEMENTED;
1969 #endif
1971 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1972 MPContext *mpctx)
1974 int val,result;
1975 int base_ioctl=(int)prop->priv;
1977 for teletext's GET,SET,STEP ioctls this is not 0
1978 SET is GET+1
1979 STEP is GET+2
1981 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
1982 return M_PROPERTY_UNAVAILABLE;
1983 if(!base_ioctl)
1984 return M_PROPERTY_ERROR;
1986 switch (action) {
1987 case M_PROPERTY_GET:
1988 if (!arg)
1989 return M_PROPERTY_ERROR;
1990 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
1991 break;
1992 case M_PROPERTY_SET:
1993 if (!arg)
1994 return M_PROPERTY_ERROR;
1995 M_PROPERTY_CLAMP(prop, *(int *) arg);
1996 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
1997 break;
1998 case M_PROPERTY_STEP_UP:
1999 case M_PROPERTY_STEP_DOWN:
2000 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2001 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2002 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
2003 break;
2004 default:
2005 return M_PROPERTY_NOT_IMPLEMENTED;
2008 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2011 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2012 MPContext *mpctx)
2014 int result;
2015 int val;
2017 //with tvh==NULL will fail too
2018 result=mp_property_teletext_common(prop,action,arg,mpctx);
2019 if(result!=M_PROPERTY_OK)
2020 return result;
2022 if(teletext_control(mpctx->demuxer->teletext,
2023 (int)prop->priv, &val)==VBI_CONTROL_TRUE && val)
2024 mp_input_set_section(mpctx->input, "teletext");
2025 else
2026 mp_input_set_section(mpctx->input, "tv");
2027 return M_PROPERTY_OK;
2030 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2031 MPContext *mpctx)
2033 int result;
2034 int val;
2035 if (!mpctx->demuxer->teletext)
2036 return M_PROPERTY_UNAVAILABLE;
2037 switch(action){
2038 case M_PROPERTY_STEP_UP:
2039 case M_PROPERTY_STEP_DOWN:
2040 //This should be handled separately
2041 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2042 result=teletext_control(mpctx->demuxer->teletext,
2043 TV_VBI_CONTROL_STEP_PAGE, &val);
2044 break;
2045 default:
2046 result=mp_property_teletext_common(prop,action,arg,mpctx);
2048 return result;
2051 ///@}
2053 /// All properties available in MPlayer.
2054 /** \ingroup Properties
2056 static const m_option_t mp_properties[] = {
2057 // General
2058 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2059 M_OPT_RANGE, 0, 3, NULL },
2060 { "loop", mp_property_loop, CONF_TYPE_INT,
2061 M_OPT_MIN, -1, 0, NULL },
2062 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2063 M_OPT_RANGE, 0.01, 100.0, NULL },
2064 { "filename", mp_property_filename, CONF_TYPE_STRING,
2065 0, 0, 0, NULL },
2066 { "path", mp_property_path, CONF_TYPE_STRING,
2067 0, 0, 0, NULL },
2068 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2069 0, 0, 0, NULL },
2070 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2071 M_OPT_MIN, 0, 0, NULL },
2072 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2073 M_OPT_MIN, 0, 0, NULL },
2074 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2075 M_OPT_MIN, 0, 0, NULL },
2076 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2077 M_OPT_MIN, 0, 0, NULL },
2078 { "length", mp_property_length, CONF_TYPE_TIME,
2079 M_OPT_MIN, 0, 0, NULL },
2080 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2081 M_OPT_RANGE, 0, 100, NULL },
2082 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2083 M_OPT_MIN, 0, 0, NULL },
2084 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2085 M_OPT_MIN, 0, 0, NULL },
2086 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2087 0, 0, 0, NULL },
2088 { "angle", mp_property_angle, CONF_TYPE_INT,
2089 CONF_RANGE, -2, 10, NULL },
2090 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2091 0, 0, 0, NULL },
2092 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2093 M_OPT_RANGE, 0, 1, NULL },
2095 // Audio
2096 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2097 M_OPT_RANGE, 0, 100, NULL },
2098 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2099 M_OPT_RANGE, 0, 1, NULL },
2100 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2101 M_OPT_RANGE, -100, 100, NULL },
2102 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2103 0, 0, 0, NULL },
2104 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2105 0, 0, 0, NULL },
2106 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2107 0, 0, 0, NULL },
2108 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2109 0, 0, 0, NULL },
2110 { "channels", mp_property_channels, CONF_TYPE_INT,
2111 0, 0, 0, NULL },
2112 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2113 CONF_RANGE, -2, 65535, NULL },
2114 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2115 M_OPT_RANGE, -1, 1, NULL },
2117 // Video
2118 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2119 M_OPT_RANGE, 0, 1, NULL },
2120 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2121 M_OPT_RANGE, 0, 1, NULL },
2122 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2123 M_OPT_RANGE, 0, 2, NULL },
2124 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2125 M_OPT_RANGE, 0, 1, NULL },
2126 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2127 M_OPT_RANGE, 0, 1, NULL },
2128 { "border", mp_property_border, CONF_TYPE_FLAG,
2129 M_OPT_RANGE, 0, 1, NULL },
2130 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2131 M_OPT_RANGE, 0, 2, NULL },
2132 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2133 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2134 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2135 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2136 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2137 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2138 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2139 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2140 { "hue", mp_property_gamma, CONF_TYPE_INT,
2141 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2142 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2143 M_OPT_RANGE, 0, 1, NULL },
2144 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2145 M_OPT_RANGE, 0, 1, NULL },
2146 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2147 0, 0, 0, NULL },
2148 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2149 0, 0, 0, NULL },
2150 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2151 0, 0, 0, NULL },
2152 { "width", mp_property_width, CONF_TYPE_INT,
2153 0, 0, 0, NULL },
2154 { "height", mp_property_height, CONF_TYPE_INT,
2155 0, 0, 0, NULL },
2156 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2157 0, 0, 0, NULL },
2158 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2159 0, 0, 0, NULL },
2160 { "switch_video", mp_property_video, CONF_TYPE_INT,
2161 CONF_RANGE, -2, 65535, NULL },
2162 { "switch_program", mp_property_program, CONF_TYPE_INT,
2163 CONF_RANGE, -1, 65535, NULL },
2165 // Subs
2166 { "sub", mp_property_sub, CONF_TYPE_INT,
2167 M_OPT_MIN, -1, 0, NULL },
2168 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2169 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2170 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2171 M_OPT_MIN, -1, 0, NULL },
2172 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2173 M_OPT_MIN, -1, 0, NULL },
2174 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2175 M_OPT_MIN, -1, 0, NULL },
2176 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2177 0, 0, 0, NULL },
2178 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2179 M_OPT_RANGE, 0, 100, NULL },
2180 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2181 M_OPT_RANGE, 0, 2, NULL },
2182 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2183 M_OPT_RANGE, 0, 1, NULL },
2184 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2185 M_OPT_RANGE, 0, 1, NULL },
2186 #ifdef CONFIG_FREETYPE
2187 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2188 M_OPT_RANGE, 0, 100, NULL },
2189 #endif
2190 #ifdef CONFIG_ASS
2191 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2192 M_OPT_RANGE, 0, 1, NULL },
2193 #endif
2195 #ifdef CONFIG_TV
2196 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2197 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2198 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2199 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2200 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2201 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2202 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2203 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2204 #endif
2205 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2206 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2207 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2208 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2209 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2210 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2211 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2212 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2213 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2214 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2215 { NULL, NULL, NULL, 0, 0, 0, NULL }
2219 int mp_property_do(const char *name, int action, void *val, void *ctx)
2221 return m_property_do(mp_properties, name, action, val, ctx);
2224 char* mp_property_print(const char *name, void* ctx)
2226 char* ret = NULL;
2227 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2228 return NULL;
2229 return ret;
2232 char *property_expand_string(MPContext *mpctx, char *str)
2234 return m_properties_expand_string(mp_properties, str, mpctx);
2237 void property_print_help(void)
2239 m_properties_print_help_list(mp_properties);
2243 /* List of default ways to show a property on OSD.
2245 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2246 * a bar showing the current position between min/max values of the
2247 * property. In this case osd_msg is only used for terminal output
2248 * if there is no video; it'll be a label shown together with percentage.
2250 * Otherwise setting osd_msg will show the string on OSD, formatted with
2251 * the text value of the property as argument.
2253 static struct property_osd_display {
2254 /// property name
2255 const char *name;
2256 /// progressbar type
2257 int osd_progbar; // -1 is special value for seek indicators
2258 /// osd msg id if it must be shared
2259 int osd_id;
2260 /// osd msg template
2261 const char *osd_msg;
2262 } property_osd_display[] = {
2263 // general
2264 { "loop", 0, -1, _("Loop: %s") },
2265 { "chapter", -1, -1, NULL },
2266 // audio
2267 { "volume", OSD_VOLUME, -1, _("Volume") },
2268 { "mute", 0, -1, _("Mute: %s") },
2269 { "audio_delay", 0, -1, _("A-V delay: %s") },
2270 { "switch_audio", 0, -1, _("Audio: %s") },
2271 { "balance", OSD_BALANCE, -1, _("Balance") },
2272 // video
2273 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2274 { "ontop", 0, -1, _("Stay on top: %s") },
2275 { "rootwin", 0, -1, _("Rootwin: %s") },
2276 { "border", 0, -1, _("Border: %s") },
2277 { "framedropping", 0, -1, _("Framedropping: %s") },
2278 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2279 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2280 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2281 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2282 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2283 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2284 { "hue", OSD_HUE, -1, _("Hue") },
2285 { "vsync", 0, -1, _("VSync: %s") },
2286 // subs
2287 { "sub", 0, -1, _("Subtitles: %s") },
2288 { "sub_source", 0, -1, _("Sub source: %s") },
2289 { "sub_vob", 0, -1, _("Subtitles: %s") },
2290 { "sub_demux", 0, -1, _("Subtitles: %s") },
2291 { "sub_file", 0, -1, _("Subtitles: %s") },
2292 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2293 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2294 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2295 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2296 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2297 #ifdef CONFIG_FREETYPE
2298 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2299 #endif
2300 #ifdef CONFIG_TV
2301 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2302 { "tv_hue", OSD_HUE, -1, _("Hue") },
2303 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2304 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2305 #endif
2309 static int show_property_osd(MPContext *mpctx, const char *pname)
2311 struct MPOpts *opts = &mpctx->opts;
2312 int r;
2313 m_option_t* prop;
2314 struct property_osd_display *p;
2316 // look for the command
2317 for (p = property_osd_display; p->name; p++)
2318 if (!strcmp(p->name, pname))
2319 break;
2320 if (!p->name)
2321 return -1;
2323 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2324 return -1;
2326 if (p->osd_progbar == -1)
2327 mpctx->add_osd_seek_info = true;
2328 else if (p->osd_progbar) {
2329 if (prop->type == CONF_TYPE_INT) {
2330 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2331 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2332 prop->min, prop->max, r);
2333 } else if (prop->type == CONF_TYPE_FLOAT) {
2334 float f;
2335 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2336 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2337 prop->min, prop->max, f);
2338 } else {
2339 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2340 "Property use an unsupported type.\n");
2341 return -1;
2343 return 0;
2346 if (p->osd_msg) {
2347 char *val = mp_property_print(pname, mpctx);
2348 if (val) {
2349 int index = p - property_osd_display;
2350 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2351 1, opts->osd_duration, p->osd_msg, val);
2352 free(val);
2355 return 0;
2360 * \defgroup Command2Property Command to property bridge
2362 * It is used to handle most commands that just set a property
2363 * and optionally display something on the OSD.
2364 * Two kinds of commands are handled: adjust or toggle.
2366 * Adjust commands take 1 or 2 parameters: <value> <abs>
2367 * If <abs> is non-zero the property is set to the given value
2368 * otherwise it is adjusted.
2370 * Toggle commands take 0 or 1 parameters. With no parameter
2371 * or a value less than the property minimum it just steps the
2372 * property to its next value. Otherwise it sets it to the given
2373 * value.
2378 /// List of the commands that can be handled by setting a property.
2379 static struct {
2380 /// property name
2381 const char *name;
2382 /// cmd id
2383 int cmd;
2384 /// set/adjust or toggle command
2385 int toggle;
2386 } set_prop_cmd[] = {
2387 // general
2388 { "loop", MP_CMD_LOOP, 0},
2389 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2390 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2391 { "pause", MP_CMD_PAUSE, 0},
2392 // audio
2393 { "volume", MP_CMD_VOLUME, 0},
2394 { "mute", MP_CMD_MUTE, 1},
2395 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2396 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2397 { "balance", MP_CMD_BALANCE, 0},
2398 // video
2399 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2400 { "panscan", MP_CMD_PANSCAN, 0},
2401 { "ontop", MP_CMD_VO_ONTOP, 1},
2402 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2403 { "border", MP_CMD_VO_BORDER, 1},
2404 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2405 { "gamma", MP_CMD_GAMMA, 0},
2406 { "brightness", MP_CMD_BRIGHTNESS, 0},
2407 { "contrast", MP_CMD_CONTRAST, 0},
2408 { "saturation", MP_CMD_SATURATION, 0},
2409 { "hue", MP_CMD_HUE, 0},
2410 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2411 // subs
2412 { "sub", MP_CMD_SUB_SELECT, 1},
2413 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2414 { "sub_vob", MP_CMD_SUB_VOB, 1},
2415 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2416 { "sub_file", MP_CMD_SUB_FILE, 1},
2417 { "sub_pos", MP_CMD_SUB_POS, 0},
2418 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2419 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2420 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2421 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2422 #ifdef CONFIG_FREETYPE
2423 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2424 #endif
2425 #ifdef CONFIG_ASS
2426 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2427 #endif
2428 #ifdef CONFIG_TV
2429 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2430 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2431 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2432 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2433 #endif
2437 /// Handle commands that set a property.
2438 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2440 int i, r;
2441 m_option_t* prop;
2442 const char *pname;
2444 // look for the command
2445 for (i = 0; set_prop_cmd[i].name; i++)
2446 if (set_prop_cmd[i].cmd == cmd->id)
2447 break;
2448 if (!(pname = set_prop_cmd[i].name))
2449 return 0;
2451 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2452 return 0;
2454 // toggle command
2455 if (set_prop_cmd[i].toggle) {
2456 // set to value
2457 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2458 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2459 else
2460 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2461 } else if (cmd->args[1].v.i) //set
2462 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2463 else // adjust
2464 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2466 if (r <= 0)
2467 return 1;
2469 show_property_osd(mpctx, pname);
2471 return 1;
2474 #ifdef CONFIG_DVDNAV
2475 static const struct {
2476 const char *name;
2477 const mp_command_type cmd;
2478 } mp_dvdnav_bindings[] = {
2479 { "up", MP_CMD_DVDNAV_UP },
2480 { "down", MP_CMD_DVDNAV_DOWN },
2481 { "left", MP_CMD_DVDNAV_LEFT },
2482 { "right", MP_CMD_DVDNAV_RIGHT },
2483 { "menu", MP_CMD_DVDNAV_MENU },
2484 { "select", MP_CMD_DVDNAV_SELECT },
2485 { "prev", MP_CMD_DVDNAV_PREVMENU },
2486 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2489 * keep old dvdnav sub-command options for a while in order not to
2490 * break slave-mode API too suddenly.
2492 { "1", MP_CMD_DVDNAV_UP },
2493 { "2", MP_CMD_DVDNAV_DOWN },
2494 { "3", MP_CMD_DVDNAV_LEFT },
2495 { "4", MP_CMD_DVDNAV_RIGHT },
2496 { "5", MP_CMD_DVDNAV_MENU },
2497 { "6", MP_CMD_DVDNAV_SELECT },
2498 { "7", MP_CMD_DVDNAV_PREVMENU },
2499 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2500 { NULL, 0 }
2502 #endif
2504 static const char *property_error_string(int error_value)
2506 switch (error_value) {
2507 case M_PROPERTY_ERROR:
2508 return "ERROR";
2509 case M_PROPERTY_UNAVAILABLE:
2510 return "PROPERTY_UNAVAILABLE";
2511 case M_PROPERTY_NOT_IMPLEMENTED:
2512 return "NOT_IMPLEMENTED";
2513 case M_PROPERTY_UNKNOWN:
2514 return "PROPERTY_UNKNOWN";
2515 case M_PROPERTY_DISABLED:
2516 return "DISABLED";
2518 return "UNKNOWN";
2521 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2523 int idx;
2524 int end = start + count;
2525 int after = mpctx->set_of_sub_size - end;
2526 sub_data **subs = mpctx->set_of_subtitles;
2527 #ifdef CONFIG_ASS
2528 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2529 #endif
2530 if (count < 0 || count > mpctx->set_of_sub_size ||
2531 start < 0 || start > mpctx->set_of_sub_size - count) {
2532 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2533 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2534 return;
2536 for (idx = start; idx < end; idx++) {
2537 sub_data *subd = subs[idx];
2538 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2539 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2540 filename_recode(subd->filename));
2541 sub_free(subd);
2542 subs[idx] = NULL;
2543 #ifdef CONFIG_ASS
2544 if (ass_tracks[idx])
2545 ass_free_track(ass_tracks[idx]);
2546 ass_tracks[idx] = NULL;
2547 #endif
2550 mpctx->global_sub_size -= count;
2551 mpctx->set_of_sub_size -= count;
2552 if (mpctx->set_of_sub_size <= 0)
2553 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2555 memmove(subs + start, subs + end, after * sizeof(*subs));
2556 memset(subs + start + after, 0, count * sizeof(*subs));
2557 #ifdef CONFIG_ASS
2558 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2559 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2560 #endif
2562 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2563 mpctx->global_sub_pos = -2;
2564 subdata = NULL;
2565 #ifdef CONFIG_ASS
2566 ass_track = NULL;
2567 #endif
2568 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2569 } else if (mpctx->set_of_sub_pos >= end) {
2570 mpctx->set_of_sub_pos -= count;
2571 mpctx->global_sub_pos -= count;
2575 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2577 struct MPOpts *opts = &mpctx->opts;
2578 sh_audio_t * const sh_audio = mpctx->sh_audio;
2579 sh_video_t * const sh_video = mpctx->sh_video;
2580 int osd_duration = opts->osd_duration;
2581 int case_fallthrough_hack = 0;
2582 if (!set_property_command(mpctx, cmd))
2583 switch (cmd->id) {
2584 case MP_CMD_SEEK:{
2585 float v;
2586 int abs;
2587 mpctx->add_osd_seek_info = true;
2588 v = cmd->args[0].v.f;
2589 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2590 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2591 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2592 if (sh_video)
2593 mpctx->osd_function =
2594 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2595 mpctx->rel_seek_secs = v;
2596 } else if (abs) { /* Absolute seek by percentage */
2597 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2598 if (sh_video)
2599 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2600 mpctx->rel_seek_secs = v / 100.0;
2601 } else {
2602 mpctx->rel_seek_secs += v;
2603 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2606 break;
2608 case MP_CMD_SET_PROPERTY_OSD:
2609 case_fallthrough_hack = 1;
2611 case MP_CMD_SET_PROPERTY:{
2612 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2613 cmd->args[1].v.s, mpctx);
2614 if (r == M_PROPERTY_UNKNOWN)
2615 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2616 "Unknown property: '%s'\n", cmd->args[0].v.s);
2617 else if (r <= 0)
2618 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2619 "Failed to set property '%s' to '%s'.\n",
2620 cmd->args[0].v.s, cmd->args[1].v.s);
2621 else if (case_fallthrough_hack)
2622 show_property_osd(mpctx, cmd->args[0].v.s);
2623 if (r <= 0)
2624 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2626 break;
2628 case MP_CMD_STEP_PROPERTY_OSD:
2629 case_fallthrough_hack = 1;
2631 case MP_CMD_STEP_PROPERTY:{
2632 void* arg = NULL;
2633 int r,i;
2634 double d;
2635 off_t o;
2636 if (cmd->args[1].v.f) {
2637 m_option_t* prop;
2638 if((r = mp_property_do(cmd->args[0].v.s,
2639 M_PROPERTY_GET_TYPE,
2640 &prop, mpctx)) <= 0)
2641 goto step_prop_err;
2642 if(prop->type == CONF_TYPE_INT ||
2643 prop->type == CONF_TYPE_FLAG)
2644 i = cmd->args[1].v.f, arg = &i;
2645 else if(prop->type == CONF_TYPE_FLOAT)
2646 arg = &cmd->args[1].v.f;
2647 else if(prop->type == CONF_TYPE_DOUBLE ||
2648 prop->type == CONF_TYPE_TIME)
2649 d = cmd->args[1].v.f, arg = &d;
2650 else if(prop->type == CONF_TYPE_POSITION)
2651 o = cmd->args[1].v.f, arg = &o;
2652 else
2653 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2654 "Ignoring step size stepping property '%s'.\n",
2655 cmd->args[0].v.s);
2657 r = mp_property_do(cmd->args[0].v.s,
2658 cmd->args[2].v.i < 0 ?
2659 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2660 arg, mpctx);
2661 step_prop_err:
2662 if (r == M_PROPERTY_UNKNOWN)
2663 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2664 "Unknown property: '%s'\n", cmd->args[0].v.s);
2665 else if (r <= 0)
2666 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2667 "Failed to increment property '%s' by %f.\n",
2668 cmd->args[0].v.s, cmd->args[1].v.f);
2669 else if (case_fallthrough_hack)
2670 show_property_osd(mpctx, cmd->args[0].v.s);
2671 if (r <= 0)
2672 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2674 break;
2676 case MP_CMD_GET_PROPERTY:{
2677 char *tmp;
2678 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2679 &tmp, mpctx);
2680 if (r <= 0) {
2681 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2682 "Failed to get value of property '%s'.\n",
2683 cmd->args[0].v.s);
2684 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2685 break;
2687 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2688 cmd->args[0].v.s, tmp);
2689 free(tmp);
2691 break;
2693 case MP_CMD_EDL_MARK:
2694 if (edl_fd) {
2695 float v = sh_video ? sh_video->pts :
2696 playing_audio_pts(mpctx);
2697 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2698 mpctx->begin_skip = v;
2699 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2700 } else {
2701 if (mpctx->begin_skip > v)
2702 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2703 else {
2704 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2705 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2707 mpctx->begin_skip = MP_NOPTS_VALUE;
2710 break;
2712 case MP_CMD_SWITCH_RATIO:
2713 if (!sh_video)
2714 break;
2715 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2716 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2717 else
2718 opts->movie_aspect = cmd->args[0].v.f;
2719 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2720 break;
2722 case MP_CMD_SPEED_INCR:{
2723 float v = cmd->args[0].v.f;
2724 opts->playback_speed += v;
2725 build_afilter_chain(mpctx, sh_audio, &ao_data);
2726 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2727 opts->playback_speed);
2728 } break;
2730 case MP_CMD_SPEED_MULT:{
2731 float v = cmd->args[0].v.f;
2732 opts->playback_speed *= v;
2733 build_afilter_chain(mpctx, sh_audio, &ao_data);
2734 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2735 opts->playback_speed);
2736 } break;
2738 case MP_CMD_SPEED_SET:{
2739 float v = cmd->args[0].v.f;
2740 opts->playback_speed = v;
2741 build_afilter_chain(mpctx, sh_audio, &ao_data);
2742 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2743 opts->playback_speed);
2744 } break;
2746 case MP_CMD_FRAME_STEP:
2747 add_step_frame(mpctx);
2748 break;
2750 case MP_CMD_FILE_FILTER:
2751 file_filter = cmd->args[0].v.i;
2752 break;
2754 case MP_CMD_QUIT:
2755 exit_player_with_rc(mpctx, EXIT_QUIT,
2756 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2758 case MP_CMD_PLAY_TREE_STEP:{
2759 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2760 int force = cmd->args[1].v.i;
2763 if (!force && mpctx->playtree_iter) {
2764 play_tree_iter_t *i =
2765 play_tree_iter_new_copy(mpctx->playtree_iter);
2766 if (play_tree_iter_step(i, n, 0) ==
2767 PLAY_TREE_ITER_ENTRY)
2768 mpctx->stop_play =
2769 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2770 play_tree_iter_free(i);
2771 } else
2772 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2773 if (mpctx->stop_play)
2774 mpctx->play_tree_step = n;
2777 break;
2779 case MP_CMD_PLAY_TREE_UP_STEP:{
2780 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2781 int force = cmd->args[1].v.i;
2783 if (!force && mpctx->playtree_iter) {
2784 play_tree_iter_t *i =
2785 play_tree_iter_new_copy(mpctx->playtree_iter);
2786 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2787 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2788 play_tree_iter_free(i);
2789 } else
2790 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2792 break;
2794 case MP_CMD_PLAY_ALT_SRC_STEP:
2795 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2796 int v = cmd->args[0].v.i;
2797 if (v > 0
2798 && mpctx->playtree_iter->file <
2799 mpctx->playtree_iter->num_files)
2800 mpctx->stop_play = PT_NEXT_SRC;
2801 else if (v < 0 && mpctx->playtree_iter->file > 1)
2802 mpctx->stop_play = PT_PREV_SRC;
2804 break;
2806 case MP_CMD_SUB_STEP:
2807 if (sh_video) {
2808 int movement = cmd->args[0].v.i;
2809 step_sub(subdata, sh_video->pts, movement);
2810 #ifdef CONFIG_ASS
2811 if (ass_track)
2812 sub_delay +=
2813 ass_step_sub(ass_track,
2814 (sh_video->pts +
2815 sub_delay) * 1000 + .5, movement) / 1000.;
2816 #endif
2817 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2818 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2820 break;
2822 case MP_CMD_SUB_LOG:
2823 log_sub(mpctx);
2824 break;
2826 case MP_CMD_OSD:{
2827 int v = cmd->args[0].v.i;
2828 int max = (term_osd
2829 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2830 if (opts->osd_level > max)
2831 opts->osd_level = max;
2832 if (v < 0)
2833 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2834 else
2835 opts->osd_level = v > max ? max : v;
2836 /* Show OSD state when disabled, but not when an explicit
2837 argument is given to the OSD command, i.e. in slave mode. */
2838 if (v == -1 && opts->osd_level <= 1)
2839 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2840 "OSD: %s",
2841 opts->osd_level ? mp_gtext("enabled") :
2842 mp_gtext("disabled"));
2843 else
2844 rm_osd_msg(OSD_MSG_OSD_STATUS);
2846 break;
2848 case MP_CMD_OSD_SHOW_TEXT:
2849 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2850 (cmd->args[1].v.i <
2851 0 ? osd_duration : cmd->args[1].v.i),
2852 "%-.63s", cmd->args[0].v.s);
2853 break;
2855 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2856 char *txt = m_properties_expand_string(mp_properties,
2857 cmd->args[0].v.s,
2858 mpctx);
2859 /* if no argument supplied take default osd_duration, else <arg> ms. */
2860 if (txt) {
2861 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2862 (cmd->args[1].v.i <
2863 0 ? osd_duration : cmd->args[1].v.i),
2864 "%-.63s", txt);
2865 free(txt);
2868 break;
2870 case MP_CMD_LOADFILE:{
2871 play_tree_t *e = play_tree_new();
2872 play_tree_add_file(e, cmd->args[0].v.s);
2874 if (cmd->args[1].v.i) // append
2875 play_tree_append_entry(mpctx->playtree->child, e);
2876 else {
2877 // Go back to the starting point.
2878 while (play_tree_iter_up_step
2879 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2880 /* NOP */ ;
2881 play_tree_free_list(mpctx->playtree->child, 1);
2882 play_tree_set_child(mpctx->playtree, e);
2883 pt_iter_goto_head(mpctx->playtree_iter);
2884 mpctx->stop_play = PT_NEXT_SRC;
2887 break;
2889 case MP_CMD_LOADLIST:{
2890 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2891 if (!e)
2892 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2893 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2894 else {
2895 if (cmd->args[1].v.i) // append
2896 play_tree_append_entry(mpctx->playtree->child, e);
2897 else {
2898 // Go back to the starting point.
2899 while (play_tree_iter_up_step
2900 (mpctx->playtree_iter, 0, 1)
2901 != PLAY_TREE_ITER_END)
2902 /* NOP */ ;
2903 play_tree_free_list(mpctx->playtree->child, 1);
2904 play_tree_set_child(mpctx->playtree, e);
2905 pt_iter_goto_head(mpctx->playtree_iter);
2906 mpctx->stop_play = PT_NEXT_SRC;
2910 break;
2912 case MP_CMD_STOP:
2913 // Go back to the starting point.
2914 while (play_tree_iter_up_step
2915 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2916 /* NOP */ ;
2917 mpctx->stop_play = PT_STOP;
2918 break;
2920 #ifdef CONFIG_RADIO
2921 case MP_CMD_RADIO_STEP_CHANNEL:
2922 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2923 int v = cmd->args[0].v.i;
2924 if (v > 0)
2925 radio_step_channel(mpctx->demuxer->stream,
2926 RADIO_CHANNEL_HIGHER);
2927 else
2928 radio_step_channel(mpctx->demuxer->stream,
2929 RADIO_CHANNEL_LOWER);
2930 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2931 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2932 "Channel: %s",
2933 radio_get_channel_name(mpctx->demuxer->stream));
2936 break;
2938 case MP_CMD_RADIO_SET_CHANNEL:
2939 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2940 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2941 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2942 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2943 "Channel: %s",
2944 radio_get_channel_name(mpctx->demuxer->stream));
2947 break;
2949 case MP_CMD_RADIO_SET_FREQ:
2950 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2951 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2952 break;
2954 case MP_CMD_RADIO_STEP_FREQ:
2955 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2956 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2957 break;
2958 #endif
2960 #ifdef CONFIG_TV
2961 case MP_CMD_TV_START_SCAN:
2962 if (mpctx->file_format == DEMUXER_TYPE_TV)
2963 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2964 break;
2965 case MP_CMD_TV_SET_FREQ:
2966 if (mpctx->file_format == DEMUXER_TYPE_TV)
2967 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2968 cmd->args[0].v.f * 16.0);
2969 #ifdef CONFIG_PVR
2970 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2971 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2972 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2973 pvr_get_current_channelname (mpctx->stream),
2974 pvr_get_current_stationname (mpctx->stream));
2976 #endif /* CONFIG_PVR */
2977 break;
2979 case MP_CMD_TV_STEP_FREQ:
2980 if (mpctx->file_format == DEMUXER_TYPE_TV)
2981 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2982 cmd->args[0].v.f * 16.0);
2983 #ifdef CONFIG_PVR
2984 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2985 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2986 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2987 pvr_get_current_channelname (mpctx->stream),
2988 pvr_get_current_frequency (mpctx->stream));
2990 #endif /* CONFIG_PVR */
2991 break;
2993 case MP_CMD_TV_SET_NORM:
2994 if (mpctx->file_format == DEMUXER_TYPE_TV)
2995 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2996 cmd->args[0].v.s);
2997 break;
2999 case MP_CMD_TV_STEP_CHANNEL:{
3000 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3001 int v = cmd->args[0].v.i;
3002 if (v > 0) {
3003 tv_step_channel((tvi_handle_t *) (mpctx->
3004 demuxer->priv),
3005 TV_CHANNEL_HIGHER);
3006 } else {
3007 tv_step_channel((tvi_handle_t *) (mpctx->
3008 demuxer->priv),
3009 TV_CHANNEL_LOWER);
3011 if (tv_channel_list) {
3012 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3013 "Channel: %s", tv_channel_current->name);
3014 //vo_osd_changed(OSDTYPE_SUBTITLE);
3017 #ifdef CONFIG_PVR
3018 else if (mpctx->stream &&
3019 mpctx->stream->type == STREAMTYPE_PVR) {
3020 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3021 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3022 pvr_get_current_channelname (mpctx->stream),
3023 pvr_get_current_stationname (mpctx->stream));
3025 #endif /* CONFIG_PVR */
3027 #ifdef CONFIG_DVBIN
3028 if (mpctx->stream->type == STREAMTYPE_DVB) {
3029 int dir;
3030 int v = cmd->args[0].v.i;
3032 mpctx->last_dvb_step = v;
3033 if (v > 0)
3034 dir = DVB_CHANNEL_HIGHER;
3035 else
3036 dir = DVB_CHANNEL_LOWER;
3039 if (dvb_step_channel(mpctx->stream, dir)) {
3040 mpctx->stop_play = PT_NEXT_ENTRY;
3041 mpctx->dvbin_reopen = 1;
3044 #endif /* CONFIG_DVBIN */
3045 break;
3047 case MP_CMD_TV_SET_CHANNEL:
3048 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3049 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3050 cmd->args[0].v.s);
3051 if (tv_channel_list) {
3052 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3053 "Channel: %s", tv_channel_current->name);
3054 //vo_osd_changed(OSDTYPE_SUBTITLE);
3057 #ifdef CONFIG_PVR
3058 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3059 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3060 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3061 pvr_get_current_channelname (mpctx->stream),
3062 pvr_get_current_stationname (mpctx->stream));
3064 #endif /* CONFIG_PVR */
3065 break;
3067 #ifdef CONFIG_DVBIN
3068 case MP_CMD_DVB_SET_CHANNEL:
3069 if (mpctx->stream->type == STREAMTYPE_DVB) {
3070 mpctx->last_dvb_step = 1;
3072 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3073 cmd->args[0].v.i)) {
3074 mpctx->stop_play = PT_NEXT_ENTRY;
3075 mpctx->dvbin_reopen = 1;
3078 break;
3079 #endif /* CONFIG_DVBIN */
3081 case MP_CMD_TV_LAST_CHANNEL:
3082 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3083 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3084 if (tv_channel_list) {
3085 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3086 "Channel: %s", tv_channel_current->name);
3087 //vo_osd_changed(OSDTYPE_SUBTITLE);
3090 #ifdef CONFIG_PVR
3091 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3092 pvr_set_lastchannel (mpctx->stream);
3093 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3094 pvr_get_current_channelname (mpctx->stream),
3095 pvr_get_current_stationname (mpctx->stream));
3097 #endif /* CONFIG_PVR */
3098 break;
3100 case MP_CMD_TV_STEP_NORM:
3101 if (mpctx->file_format == DEMUXER_TYPE_TV)
3102 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3103 break;
3105 case MP_CMD_TV_STEP_CHANNEL_LIST:
3106 if (mpctx->file_format == DEMUXER_TYPE_TV)
3107 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3108 break;
3109 #endif /* CONFIG_TV */
3110 case MP_CMD_TV_TELETEXT_ADD_DEC:
3112 if (mpctx->demuxer->teletext)
3113 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3114 &(cmd->args[0].v.s));
3115 break;
3117 case MP_CMD_TV_TELETEXT_GO_LINK:
3119 if (mpctx->demuxer->teletext)
3120 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3121 &(cmd->args[0].v.i));
3122 break;
3125 case MP_CMD_SUB_LOAD:
3126 if (sh_video) {
3127 int n = mpctx->set_of_sub_size;
3128 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3129 if (n != mpctx->set_of_sub_size) {
3130 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
3131 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
3132 mpctx->global_sub_size;
3133 ++mpctx->global_sub_size;
3136 break;
3138 case MP_CMD_SUB_REMOVE:
3139 if (sh_video) {
3140 int v = cmd->args[0].v.i;
3141 if (v < 0) {
3142 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3143 } else if (v < mpctx->set_of_sub_size) {
3144 remove_subtitle_range(mpctx, v, 1);
3147 break;
3149 case MP_CMD_GET_SUB_VISIBILITY:
3150 if (sh_video) {
3151 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3152 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3154 break;
3156 case MP_CMD_SCREENSHOT:
3157 if (mpctx->video_out && mpctx->video_out->config_ok) {
3158 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3159 if (CONTROL_OK !=
3160 ((vf_instance_t *) sh_video->vfilter)->
3161 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3162 &cmd->args[0].v.i))
3163 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3165 break;
3167 case MP_CMD_VF_CHANGE_RECTANGLE:
3168 if (!sh_video)
3169 break;
3170 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3171 break;
3173 case MP_CMD_GET_TIME_LENGTH:{
3174 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3175 demuxer_get_time_length(mpctx->demuxer));
3177 break;
3179 case MP_CMD_GET_FILENAME:{
3180 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3181 get_metadata(mpctx, META_NAME));
3183 break;
3185 case MP_CMD_GET_VIDEO_CODEC:{
3186 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3187 if (!inf)
3188 inf = strdup("");
3189 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3190 free(inf);
3192 break;
3194 case MP_CMD_GET_VIDEO_BITRATE:{
3195 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3196 if (!inf)
3197 inf = strdup("");
3198 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3199 free(inf);
3201 break;
3203 case MP_CMD_GET_VIDEO_RESOLUTION:{
3204 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3205 if (!inf)
3206 inf = strdup("");
3207 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3208 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3209 free(inf);
3211 break;
3213 case MP_CMD_GET_AUDIO_CODEC:{
3214 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3215 if (!inf)
3216 inf = strdup("");
3217 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3218 free(inf);
3220 break;
3222 case MP_CMD_GET_AUDIO_BITRATE:{
3223 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3224 if (!inf)
3225 inf = strdup("");
3226 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3227 free(inf);
3229 break;
3231 case MP_CMD_GET_AUDIO_SAMPLES:{
3232 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3233 if (!inf)
3234 inf = strdup("");
3235 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3236 free(inf);
3238 break;
3240 case MP_CMD_GET_META_TITLE:{
3241 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3242 if (!inf)
3243 inf = strdup("");
3244 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3245 free(inf);
3247 break;
3249 case MP_CMD_GET_META_ARTIST:{
3250 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3251 if (!inf)
3252 inf = strdup("");
3253 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3254 free(inf);
3256 break;
3258 case MP_CMD_GET_META_ALBUM:{
3259 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3260 if (!inf)
3261 inf = strdup("");
3262 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3263 free(inf);
3265 break;
3267 case MP_CMD_GET_META_YEAR:{
3268 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3269 if (!inf)
3270 inf = strdup("");
3271 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3272 free(inf);
3274 break;
3276 case MP_CMD_GET_META_COMMENT:{
3277 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3278 if (!inf)
3279 inf = strdup("");
3280 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3281 free(inf);
3283 break;
3285 case MP_CMD_GET_META_TRACK:{
3286 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3287 if (!inf)
3288 inf = strdup("");
3289 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3290 free(inf);
3292 break;
3294 case MP_CMD_GET_META_GENRE:{
3295 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3296 if (!inf)
3297 inf = strdup("");
3298 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3299 free(inf);
3301 break;
3303 case MP_CMD_GET_VO_FULLSCREEN:
3304 if (mpctx->video_out && mpctx->video_out->config_ok)
3305 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3306 break;
3308 case MP_CMD_GET_PERCENT_POS:
3309 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3310 demuxer_get_percent_pos(mpctx->demuxer));
3311 break;
3313 case MP_CMD_GET_TIME_POS:{
3314 float pos = 0;
3315 if (sh_video)
3316 pos = sh_video->pts;
3317 else if (sh_audio && mpctx->audio_out)
3318 pos = playing_audio_pts(mpctx);
3319 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3321 break;
3323 case MP_CMD_RUN:
3324 #ifndef __MINGW32__
3325 if (!fork()) {
3326 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3327 exit(0);
3329 #endif
3330 break;
3332 case MP_CMD_KEYDOWN_EVENTS:
3333 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3334 break;
3336 case MP_CMD_SET_MOUSE_POS:{
3337 int pointer_x, pointer_y;
3338 double dx, dy;
3339 pointer_x = cmd->args[0].v.i;
3340 pointer_y = cmd->args[1].v.i;
3341 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3342 #ifdef CONFIG_DVDNAV
3343 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3344 && dx > 0.0 && dy > 0.0) {
3345 int button = -1;
3346 pointer_x = (int) (dx * (double) sh_video->disp_w);
3347 pointer_y = (int) (dy * (double) sh_video->disp_h);
3348 mp_dvdnav_update_mouse_pos(mpctx->stream,
3349 pointer_x, pointer_y, &button);
3350 if (opts->osd_level > 1 && button > 0)
3351 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3352 "Selected button number %d", button);
3354 #endif
3355 #ifdef CONFIG_MENU
3356 if (use_menu && dx >= 0.0 && dy >= 0.0)
3357 menu_update_mouse_pos(dx, dy);
3358 #endif
3360 break;
3362 #ifdef CONFIG_DVDNAV
3363 case MP_CMD_DVDNAV:{
3364 int button = -1;
3365 int i;
3366 mp_command_type command = 0;
3367 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3368 break;
3370 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3371 if (cmd->args[0].v.s &&
3372 !strcasecmp (cmd->args[0].v.s,
3373 mp_dvdnav_bindings[i].name))
3374 command = mp_dvdnav_bindings[i].cmd;
3376 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3377 if (opts->osd_level > 1 && button > 0)
3378 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3379 "Selected button number %d", button);
3381 break;
3383 case MP_CMD_SWITCH_TITLE:
3384 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3385 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3386 break;
3388 #endif
3390 default:
3391 mp_msg(MSGT_CPLAYER, MSGL_V,
3392 "Received unknown cmd %s\n", cmd->name);
3395 switch (cmd->pausing) {
3396 case 1: // "pausing"
3397 pause_player(mpctx);
3398 break;
3399 case 3: // "pausing_toggle"
3400 if (mpctx->paused)
3401 unpause_player(mpctx);
3402 else
3403 pause_player(mpctx);
3404 break;