demux_mkv: support V_MJPEG video tag
[mplayer/glamo.git] / command.c
blob8c3ad5d7789f9d21f1d46eb0796ccbea9ed31917
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdlib.h>
20 #include <inttypes.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <stdbool.h>
25 #include "config.h"
26 #include "talloc.h"
27 #include "command.h"
28 #include "input/input.h"
29 #include "stream/stream.h"
30 #include "libmpdemux/demuxer.h"
31 #include "libmpdemux/stheader.h"
32 #include "codec-cfg.h"
33 #include "mplayer.h"
34 #include "libvo/sub.h"
35 #include "m_option.h"
36 #include "m_property.h"
37 #include "metadata.h"
38 #include "libmpcodecs/vf.h"
39 #include "libmpcodecs/vd.h"
40 #include "mp_osd.h"
41 #include "libvo/video_out.h"
42 #include "libvo/font_load.h"
43 #include "playtree.h"
44 #include "libao2/audio_out.h"
45 #include "mpcommon.h"
46 #include "mixer.h"
47 #include "libmpcodecs/dec_video.h"
48 #include "libmpcodecs/dec_audio.h"
49 #include "libmpcodecs/dec_teletext.h"
50 #include "vobsub.h"
51 #include "spudec.h"
52 #include "path.h"
53 #include "ass_mp.h"
54 #include "stream/tv.h"
55 #include "stream/stream_radio.h"
56 #include "stream/pvr.h"
57 #ifdef CONFIG_DVBIN
58 #include "stream/dvbin.h"
59 #endif
60 #ifdef CONFIG_DVDREAD
61 #include "stream/stream_dvd.h"
62 #endif
63 #include "stream/stream_dvdnav.h"
64 #include "m_struct.h"
65 #include "libmenu/menu.h"
67 #include "mp_core.h"
68 #include "mp_fifo.h"
69 #include "libavutil/avstring.h"
71 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
73 extern int use_menu;
75 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
76 double *dx, double *dy)
78 struct MPOpts *opts = &mpctx->opts;
79 struct vo *vo = mpctx->video_out;
80 //remove the borders, if any, and rescale to the range [0,1],[0,1]
81 if (vo_fs) { //we are in full-screen mode
82 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
83 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
84 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
85 iy -= (opts->vo_screenheight - vo->dheight) / 2;
87 if (ix < 0 || ix > vo->dwidth) {
88 *dx = *dy = -1.0;
89 return;
90 } //we are on one of the borders
91 if (iy < 0 || iy > vo->dheight) {
92 *dx = *dy = -1.0;
93 return;
94 } //we are on one of the borders
97 *dx = (double) ix / (double) vo->dwidth;
98 *dy = (double) iy / (double) vo->dheight;
100 mp_msg(MSGT_CPLAYER, MSGL_V,
101 "\r\nrescaled coordinates: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
102 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
103 vo->dheight, vo_fs);
106 static int sub_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 int current_id, tmp;
855 if (!mpctx->demuxer || !mpctx->demuxer->audio)
856 return M_PROPERTY_UNAVAILABLE;
857 current_id = mpctx->sh_audio ? mpctx->sh_audio->aid : -2;
859 switch (action) {
860 case M_PROPERTY_GET:
861 if (!arg)
862 return M_PROPERTY_ERROR;
863 *(int *) arg = current_id;
864 return M_PROPERTY_OK;
865 case M_PROPERTY_PRINT:
866 if (!arg)
867 return M_PROPERTY_ERROR;
869 if (current_id < 0)
870 *(char **) arg = strdup(mp_gtext("disabled"));
871 else {
872 char lang[40];
873 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
874 sh_audio_t* sh = mpctx->sh_audio;
875 if (sh && sh->lang)
876 av_strlcpy(lang, sh->lang, 40);
877 #ifdef CONFIG_DVDREAD
878 else if (mpctx->stream->type == STREAMTYPE_DVD) {
879 int code = dvd_lang_from_aid(mpctx->stream, current_id);
880 if (code) {
881 lang[0] = code >> 8;
882 lang[1] = code;
883 lang[2] = 0;
886 #endif
888 #ifdef CONFIG_DVDNAV
889 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
890 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
891 #endif
892 *(char **) arg = malloc(64);
893 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
895 return M_PROPERTY_OK;
897 case M_PROPERTY_STEP_UP:
898 case M_PROPERTY_SET:
899 if (action == M_PROPERTY_SET && arg)
900 tmp = *((int *) arg);
901 else
902 tmp = -1;
903 int new_id = demuxer_switch_audio(mpctx->demuxer, tmp);
904 if (new_id != current_id)
905 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
906 if (new_id != current_id && new_id >= 0) {
907 sh_audio_t *sh2;
908 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
909 sh2->ds = mpctx->demuxer->audio;
910 mpctx->sh_audio = sh2;
911 reinit_audio_chain(mpctx);
913 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
914 return M_PROPERTY_OK;
915 default:
916 return M_PROPERTY_NOT_IMPLEMENTED;
921 /// Selected video id (RW)
922 static int mp_property_video(m_option_t *prop, int action, void *arg,
923 MPContext *mpctx)
925 struct MPOpts *opts = &mpctx->opts;
926 int current_id, tmp;
927 if (!mpctx->demuxer || !mpctx->demuxer->video)
928 return M_PROPERTY_UNAVAILABLE;
929 current_id = mpctx->demuxer->video->id;
931 switch (action) {
932 case M_PROPERTY_GET:
933 if (!arg)
934 return M_PROPERTY_ERROR;
935 *(int *) arg = current_id;
936 return M_PROPERTY_OK;
937 case M_PROPERTY_PRINT:
938 if (!arg)
939 return M_PROPERTY_ERROR;
941 if (current_id < 0)
942 *(char **) arg = strdup(mp_gtext("disabled"));
943 else {
944 char lang[40];
945 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
946 *(char **) arg = malloc(64);
947 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
949 return M_PROPERTY_OK;
951 case M_PROPERTY_STEP_UP:
952 case M_PROPERTY_SET:
953 if (action == M_PROPERTY_SET && arg)
954 tmp = *((int *) arg);
955 else
956 tmp = -1;
957 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
958 if (opts->video_id == -2
959 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
960 && current_id != -2))
961 uninit_player(mpctx, INITIALIZED_VCODEC |
962 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
963 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
964 sh_video_t *sh2;
965 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
966 if (sh2) {
967 sh2->ds = mpctx->demuxer->video;
968 mpctx->sh_video = sh2;
969 reinit_video_chain(mpctx);
972 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
973 return M_PROPERTY_OK;
975 default:
976 return M_PROPERTY_NOT_IMPLEMENTED;
980 static int mp_property_program(m_option_t *prop, int action, void *arg,
981 MPContext *mpctx)
983 demux_program_t prog;
985 switch (action) {
986 case M_PROPERTY_STEP_UP:
987 case M_PROPERTY_SET:
988 if (action == M_PROPERTY_SET && arg)
989 prog.progid = *((int *) arg);
990 else
991 prog.progid = -1;
992 if (demux_control
993 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
994 &prog) == DEMUXER_CTRL_NOTIMPL)
995 return M_PROPERTY_ERROR;
997 if (prog.aid < 0 && prog.vid < 0) {
998 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
999 return M_PROPERTY_ERROR;
1001 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1002 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1003 return M_PROPERTY_OK;
1005 default:
1006 return M_PROPERTY_NOT_IMPLEMENTED;
1010 ///@}
1012 /// \defgroup VideoProperties Video properties
1013 /// \ingroup Properties
1014 ///@{
1016 /// Fullscreen state (RW)
1017 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1018 MPContext *mpctx)
1021 if (!mpctx->video_out)
1022 return M_PROPERTY_UNAVAILABLE;
1024 switch (action) {
1025 case M_PROPERTY_SET:
1026 if (!arg)
1027 return M_PROPERTY_ERROR;
1028 M_PROPERTY_CLAMP(prop, *(int *) arg);
1029 if (vo_fs == !!*(int *) arg)
1030 return M_PROPERTY_OK;
1031 case M_PROPERTY_STEP_UP:
1032 case M_PROPERTY_STEP_DOWN:
1033 if (mpctx->video_out->config_ok)
1034 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1035 mpctx->opts.fullscreen = vo_fs;
1036 return M_PROPERTY_OK;
1037 default:
1038 return m_property_flag(prop, action, arg, &vo_fs);
1042 static int mp_property_deinterlace(m_option_t *prop, int action,
1043 void *arg, MPContext *mpctx)
1045 int deinterlace;
1046 vf_instance_t *vf;
1047 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1048 return M_PROPERTY_UNAVAILABLE;
1049 vf = mpctx->sh_video->vfilter;
1050 switch (action) {
1051 case M_PROPERTY_GET:
1052 if (!arg)
1053 return M_PROPERTY_ERROR;
1054 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1055 return M_PROPERTY_OK;
1056 case M_PROPERTY_SET:
1057 if (!arg)
1058 return M_PROPERTY_ERROR;
1059 M_PROPERTY_CLAMP(prop, *(int *) arg);
1060 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1061 return M_PROPERTY_OK;
1062 case M_PROPERTY_STEP_UP:
1063 case M_PROPERTY_STEP_DOWN:
1064 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1065 deinterlace = !deinterlace;
1066 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1067 return M_PROPERTY_OK;
1069 int value = 0;
1070 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1071 return m_property_flag_ro(prop, action, arg, value);
1074 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1075 void *arg, MPContext *mpctx)
1077 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1078 return M_PROPERTY_UNAVAILABLE;
1080 struct vf_instance *vf = mpctx->sh_video->vfilter;
1081 int colorspace;
1082 switch (action) {
1083 case M_PROPERTY_GET:
1084 if (!arg)
1085 return M_PROPERTY_ERROR;
1086 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1087 return M_PROPERTY_UNAVAILABLE;
1088 return M_PROPERTY_OK;
1089 case M_PROPERTY_PRINT:
1090 if (!arg)
1091 return M_PROPERTY_ERROR;
1092 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1093 return M_PROPERTY_UNAVAILABLE;
1094 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1095 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1096 *(char **)arg = strdup("Unknown");
1097 else
1098 *(char**)arg = strdup(names[colorspace]);
1099 return M_PROPERTY_OK;
1100 case M_PROPERTY_SET:
1101 if (!arg)
1102 return M_PROPERTY_ERROR;
1103 M_PROPERTY_CLAMP(prop, *(int *) arg);
1104 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1105 return M_PROPERTY_OK;
1106 case M_PROPERTY_STEP_UP:;
1107 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1108 return M_PROPERTY_UNAVAILABLE;
1109 colorspace += 1;
1110 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1111 return M_PROPERTY_OK;
1113 return M_PROPERTY_NOT_IMPLEMENTED;
1116 /// Panscan (RW)
1117 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1118 MPContext *mpctx)
1121 if (!mpctx->video_out
1122 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1123 return M_PROPERTY_UNAVAILABLE;
1125 switch (action) {
1126 case M_PROPERTY_SET:
1127 if (!arg)
1128 return M_PROPERTY_ERROR;
1129 M_PROPERTY_CLAMP(prop, *(float *) arg);
1130 vo_panscan = *(float *) arg;
1131 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1132 return M_PROPERTY_OK;
1133 case M_PROPERTY_STEP_UP:
1134 case M_PROPERTY_STEP_DOWN:
1135 vo_panscan += (arg ? *(float *) arg : 0.1) *
1136 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1137 if (vo_panscan > 1)
1138 vo_panscan = 1;
1139 else if (vo_panscan < 0)
1140 vo_panscan = 0;
1141 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1142 return M_PROPERTY_OK;
1143 default:
1144 return m_property_float_range(prop, action, arg, &vo_panscan);
1148 /// Helper to set vo flags.
1149 /** \ingroup PropertyImplHelper
1151 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1152 int vo_ctrl, int *vo_var, MPContext *mpctx)
1155 if (!mpctx->video_out)
1156 return M_PROPERTY_UNAVAILABLE;
1158 switch (action) {
1159 case M_PROPERTY_SET:
1160 if (!arg)
1161 return M_PROPERTY_ERROR;
1162 M_PROPERTY_CLAMP(prop, *(int *) arg);
1163 if (*vo_var == !!*(int *) arg)
1164 return M_PROPERTY_OK;
1165 case M_PROPERTY_STEP_UP:
1166 case M_PROPERTY_STEP_DOWN:
1167 if (mpctx->video_out->config_ok)
1168 vo_control(mpctx->video_out, vo_ctrl, 0);
1169 return M_PROPERTY_OK;
1170 default:
1171 return m_property_flag(prop, action, arg, vo_var);
1175 /// Window always on top (RW)
1176 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1177 MPContext *mpctx)
1179 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1180 &mpctx->opts.vo_ontop, mpctx);
1183 /// Display in the root window (RW)
1184 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1185 MPContext *mpctx)
1187 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1188 &vo_rootwin, mpctx);
1191 /// Show window borders (RW)
1192 static int mp_property_border(m_option_t *prop, int action, void *arg,
1193 MPContext *mpctx)
1195 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1196 &vo_border, mpctx);
1199 /// Framedropping state (RW)
1200 static int mp_property_framedropping(m_option_t *prop, int action,
1201 void *arg, MPContext *mpctx)
1204 if (!mpctx->sh_video)
1205 return M_PROPERTY_UNAVAILABLE;
1207 switch (action) {
1208 case M_PROPERTY_PRINT:
1209 if (!arg)
1210 return M_PROPERTY_ERROR;
1211 *(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
1212 (frame_dropping == 2 ? mp_gtext("hard") :
1213 mp_gtext("disabled")));
1214 return M_PROPERTY_OK;
1215 default:
1216 return m_property_choice(prop, action, arg, &frame_dropping);
1220 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1221 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1222 MPContext *mpctx)
1224 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1225 int r, val;
1227 if (!mpctx->sh_video)
1228 return M_PROPERTY_UNAVAILABLE;
1230 if (gamma[0] == 1000) {
1231 gamma[0] = 0;
1232 get_video_colors(mpctx->sh_video, prop->name, gamma);
1235 switch (action) {
1236 case M_PROPERTY_SET:
1237 if (!arg)
1238 return M_PROPERTY_ERROR;
1239 M_PROPERTY_CLAMP(prop, *(int *) arg);
1240 *gamma = *(int *) arg;
1241 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1242 if (r <= 0)
1243 break;
1244 return r;
1245 case M_PROPERTY_GET:
1246 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1247 if (!arg)
1248 return M_PROPERTY_ERROR;
1249 *(int *)arg = val;
1250 return M_PROPERTY_OK;
1252 break;
1253 case M_PROPERTY_STEP_UP:
1254 case M_PROPERTY_STEP_DOWN:
1255 *gamma += (arg ? *(int *) arg : 1) *
1256 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1257 M_PROPERTY_CLAMP(prop, *gamma);
1258 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1259 if (r <= 0)
1260 break;
1261 return r;
1262 default:
1263 return M_PROPERTY_NOT_IMPLEMENTED;
1266 #ifdef CONFIG_TV
1267 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1268 int l = strlen(prop->name);
1269 char tv_prop[3 + l + 1];
1270 sprintf(tv_prop, "tv_%s", prop->name);
1271 return mp_property_do(tv_prop, action, arg, mpctx);
1273 #endif
1275 return M_PROPERTY_UNAVAILABLE;
1278 /// VSync (RW)
1279 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1280 MPContext *mpctx)
1282 return m_property_flag(prop, action, arg, &vo_vsync);
1285 /// Video codec tag (RO)
1286 static int mp_property_video_format(m_option_t *prop, int action,
1287 void *arg, MPContext *mpctx)
1289 char* meta;
1290 if (!mpctx->sh_video)
1291 return M_PROPERTY_UNAVAILABLE;
1292 switch(action) {
1293 case M_PROPERTY_PRINT:
1294 if (!arg)
1295 return M_PROPERTY_ERROR;
1296 switch(mpctx->sh_video->format) {
1297 case 0x10000001:
1298 meta = strdup ("mpeg1"); break;
1299 case 0x10000002:
1300 meta = strdup ("mpeg2"); break;
1301 case 0x10000004:
1302 meta = strdup ("mpeg4"); break;
1303 case 0x10000005:
1304 meta = strdup ("h264"); break;
1305 default:
1306 if(mpctx->sh_video->format >= 0x20202020) {
1307 meta = malloc(5);
1308 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1309 } else {
1310 meta = malloc(20);
1311 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1314 *(char**)arg = meta;
1315 return M_PROPERTY_OK;
1317 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1320 /// Video codec name (RO)
1321 static int mp_property_video_codec(m_option_t *prop, int action,
1322 void *arg, MPContext *mpctx)
1324 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1325 return M_PROPERTY_UNAVAILABLE;
1326 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1330 /// Video bitrate (RO)
1331 static int mp_property_video_bitrate(m_option_t *prop, int action,
1332 void *arg, MPContext *mpctx)
1334 if (!mpctx->sh_video)
1335 return M_PROPERTY_UNAVAILABLE;
1336 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1339 /// Video display width (RO)
1340 static int mp_property_width(m_option_t *prop, int action, void *arg,
1341 MPContext *mpctx)
1343 if (!mpctx->sh_video)
1344 return M_PROPERTY_UNAVAILABLE;
1345 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1348 /// Video display height (RO)
1349 static int mp_property_height(m_option_t *prop, int action, void *arg,
1350 MPContext *mpctx)
1352 if (!mpctx->sh_video)
1353 return M_PROPERTY_UNAVAILABLE;
1354 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1357 /// Video fps (RO)
1358 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1359 MPContext *mpctx)
1361 if (!mpctx->sh_video)
1362 return M_PROPERTY_UNAVAILABLE;
1363 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1366 /// Video aspect (RO)
1367 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1368 MPContext *mpctx)
1370 if (!mpctx->sh_video)
1371 return M_PROPERTY_UNAVAILABLE;
1372 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1375 ///@}
1377 /// \defgroup SubProprties Subtitles properties
1378 /// \ingroup Properties
1379 ///@{
1381 /// Text subtitle position (RW)
1382 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1383 MPContext *mpctx)
1385 switch (action) {
1386 case M_PROPERTY_SET:
1387 if (!arg)
1388 return M_PROPERTY_ERROR;
1389 case M_PROPERTY_STEP_UP:
1390 case M_PROPERTY_STEP_DOWN:
1391 vo_osd_changed(OSDTYPE_SUBTITLE);
1392 default:
1393 return m_property_int_range(prop, action, arg, &sub_pos);
1397 /// Selected subtitles (RW)
1398 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1399 MPContext *mpctx)
1401 struct MPOpts *opts = &mpctx->opts;
1402 demux_stream_t *const d_sub = mpctx->d_sub;
1403 const int global_sub_size = mpctx->global_sub_size;
1404 int source = -1, reset_spu = 0;
1405 char *sub_name;
1407 if (global_sub_size <= 0)
1408 return M_PROPERTY_UNAVAILABLE;
1410 switch (action) {
1411 case M_PROPERTY_GET:
1412 if (!arg)
1413 return M_PROPERTY_ERROR;
1414 *(int *) arg = mpctx->global_sub_pos;
1415 return M_PROPERTY_OK;
1416 case M_PROPERTY_PRINT:
1417 if (!arg)
1418 return M_PROPERTY_ERROR;
1419 *(char **) arg = malloc(64);
1420 (*(char **) arg)[63] = 0;
1421 sub_name = 0;
1422 if (subdata)
1423 sub_name = subdata->filename;
1424 #ifdef CONFIG_ASS
1425 if (ass_track && ass_track->name)
1426 sub_name = ass_track->name;
1427 #endif
1428 if (sub_name) {
1429 char *tmp, *tmp2;
1430 tmp = sub_name;
1431 if ((tmp2 = strrchr(tmp, '/')))
1432 tmp = tmp2 + 1;
1434 snprintf(*(char **) arg, 63, "(%d) %s%s",
1435 mpctx->set_of_sub_pos + 1,
1436 strlen(tmp) < 20 ? "" : "...",
1437 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1438 return M_PROPERTY_OK;
1440 #ifdef CONFIG_DVDNAV
1441 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1442 if (vo_spudec && opts->sub_id >= 0) {
1443 unsigned char lang[3];
1444 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1445 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1446 return M_PROPERTY_OK;
1450 #endif
1452 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1453 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1454 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1455 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1456 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1457 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1458 if (!lang) lang = mp_gtext("unknown");
1459 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1460 return M_PROPERTY_OK;
1463 if (vo_vobsub && vobsub_id >= 0) {
1464 const char *language = mp_gtext("unknown");
1465 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1466 snprintf(*(char **) arg, 63, "(%d) %s",
1467 vobsub_id, language ? language : mp_gtext("unknown"));
1468 return M_PROPERTY_OK;
1470 #ifdef CONFIG_DVDREAD
1471 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1472 && opts->sub_id >= 0) {
1473 char lang[3];
1474 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1475 lang[0] = code >> 8;
1476 lang[1] = code;
1477 lang[2] = 0;
1478 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1479 return M_PROPERTY_OK;
1481 #endif
1482 if (opts->sub_id >= 0) {
1483 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
1484 mp_gtext("unknown"));
1485 return M_PROPERTY_OK;
1487 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1488 return M_PROPERTY_OK;
1490 case M_PROPERTY_SET:
1491 if (!arg)
1492 return M_PROPERTY_ERROR;
1493 if (*(int *) arg < -1)
1494 *(int *) arg = -1;
1495 else if (*(int *) arg >= global_sub_size)
1496 *(int *) arg = global_sub_size - 1;
1497 mpctx->global_sub_pos = *(int *) arg;
1498 break;
1499 case M_PROPERTY_STEP_UP:
1500 mpctx->global_sub_pos += 2;
1501 mpctx->global_sub_pos =
1502 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1503 break;
1504 case M_PROPERTY_STEP_DOWN:
1505 mpctx->global_sub_pos += global_sub_size + 1;
1506 mpctx->global_sub_pos =
1507 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1508 break;
1509 default:
1510 return M_PROPERTY_NOT_IMPLEMENTED;
1513 if (mpctx->global_sub_pos >= 0)
1514 source = sub_source(mpctx);
1516 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1517 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1518 global_sub_size,
1519 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1520 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1521 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1522 mpctx->global_sub_pos, source);
1524 mpctx->set_of_sub_pos = -1;
1525 subdata = NULL;
1527 vobsub_id = -1;
1528 opts->sub_id = -1;
1529 if (d_sub) {
1530 if (d_sub->id > -2)
1531 reset_spu = 1;
1532 d_sub->id = -2;
1534 #ifdef CONFIG_ASS
1535 ass_track = 0;
1536 #endif
1538 if (source == SUB_SOURCE_VOBSUB) {
1539 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1540 } else if (source == SUB_SOURCE_SUBS) {
1541 mpctx->set_of_sub_pos =
1542 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1543 #ifdef CONFIG_ASS
1544 if (opts->ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1545 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1546 else
1547 #endif
1549 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1550 vo_osd_changed(OSDTYPE_SUBTITLE);
1552 } else if (source == SUB_SOURCE_DEMUX) {
1553 opts->sub_id =
1554 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1555 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1556 int i = 0;
1557 // default: assume 1:1 mapping of sid and stream id
1558 d_sub->id = opts->sub_id;
1559 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1560 ds_free_packs(d_sub);
1561 for (i = 0; i < MAX_S_STREAMS; i++) {
1562 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1563 if (sh && sh->sid == opts->sub_id) {
1564 d_sub->id = i;
1565 d_sub->sh = sh;
1566 break;
1569 if (d_sub->sh && d_sub->id >= 0) {
1570 sh_sub_t *sh = d_sub->sh;
1571 if (sh->type == 'v')
1572 init_vo_spudec(mpctx);
1573 #ifdef CONFIG_ASS
1574 else if (opts->ass_enabled)
1575 ass_track = sh->ass_track;
1576 #endif
1577 } else {
1578 d_sub->id = -2;
1579 d_sub->sh = NULL;
1583 #ifdef CONFIG_DVDREAD
1584 if (vo_spudec
1585 && (mpctx->stream->type == STREAMTYPE_DVD
1586 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1587 && opts->sub_id < 0 && reset_spu) {
1588 d_sub->id = -2;
1589 d_sub->sh = NULL;
1591 #endif
1593 update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, 0, 0, d_sub, 1);
1595 return M_PROPERTY_OK;
1598 /// Selected sub source (RW)
1599 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1600 MPContext *mpctx)
1602 int source;
1603 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1604 return M_PROPERTY_UNAVAILABLE;
1606 switch (action) {
1607 case M_PROPERTY_GET:
1608 if (!arg)
1609 return M_PROPERTY_ERROR;
1610 *(int *) arg = sub_source(mpctx);
1611 return M_PROPERTY_OK;
1612 case M_PROPERTY_PRINT:
1613 if (!arg)
1614 return M_PROPERTY_ERROR;
1615 *(char **) arg = malloc(64);
1616 (*(char **) arg)[63] = 0;
1617 switch (sub_source(mpctx))
1619 case SUB_SOURCE_SUBS:
1620 snprintf(*(char **) arg, 63, mp_gtext("file"));
1621 break;
1622 case SUB_SOURCE_VOBSUB:
1623 snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
1624 break;
1625 case SUB_SOURCE_DEMUX:
1626 snprintf(*(char **) arg, 63, mp_gtext("embedded"));
1627 break;
1628 default:
1629 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1631 return M_PROPERTY_OK;
1632 case M_PROPERTY_SET:
1633 if (!arg)
1634 return M_PROPERTY_ERROR;
1635 M_PROPERTY_CLAMP(prop, *(int*)arg);
1636 if (*(int *) arg < 0)
1637 mpctx->global_sub_pos = -1;
1638 else if (*(int *) arg != sub_source(mpctx)) {
1639 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1640 return M_PROPERTY_UNAVAILABLE;
1641 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1643 break;
1644 case M_PROPERTY_STEP_UP:
1645 case M_PROPERTY_STEP_DOWN: {
1646 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1647 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1648 int step = (step_all > 0) ? 1 : -1;
1649 int cur_source = sub_source(mpctx);
1650 source = cur_source;
1651 while (step_all) {
1652 source += step;
1653 if (source >= SUB_SOURCES)
1654 source = -1;
1655 else if (source < -1)
1656 source = SUB_SOURCES - 1;
1657 if (source == cur_source || source == -1 ||
1658 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1659 step_all -= step;
1661 if (source == cur_source)
1662 return M_PROPERTY_OK;
1663 if (source == -1)
1664 mpctx->global_sub_pos = -1;
1665 else
1666 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1667 break;
1669 default:
1670 return M_PROPERTY_NOT_IMPLEMENTED;
1672 --mpctx->global_sub_pos;
1673 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1676 /// Selected subtitles from specific source (RW)
1677 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1678 MPContext *mpctx)
1680 int source, is_cur_source, offset;
1681 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1682 return M_PROPERTY_UNAVAILABLE;
1684 if (!strcmp(prop->name, "sub_file"))
1685 source = SUB_SOURCE_SUBS;
1686 else if (!strcmp(prop->name, "sub_vob"))
1687 source = SUB_SOURCE_VOBSUB;
1688 else if (!strcmp(prop->name, "sub_demux"))
1689 source = SUB_SOURCE_DEMUX;
1690 else
1691 return M_PROPERTY_ERROR;
1693 offset = mpctx->global_sub_indices[source];
1694 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1695 return M_PROPERTY_UNAVAILABLE;
1697 is_cur_source = sub_source(mpctx) == source;
1698 switch (action) {
1699 case M_PROPERTY_GET:
1700 if (!arg)
1701 return M_PROPERTY_ERROR;
1702 if (is_cur_source) {
1703 *(int *) arg = mpctx->global_sub_pos - offset;
1704 if (source == SUB_SOURCE_VOBSUB)
1705 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1707 else
1708 *(int *) arg = -1;
1709 return M_PROPERTY_OK;
1710 case M_PROPERTY_PRINT:
1711 if (!arg)
1712 return M_PROPERTY_ERROR;
1713 if (is_cur_source)
1714 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1715 *(char **) arg = malloc(64);
1716 (*(char **) arg)[63] = 0;
1717 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1718 return M_PROPERTY_OK;
1719 case M_PROPERTY_SET:
1720 if (!arg)
1721 return M_PROPERTY_ERROR;
1722 if (*(int *) arg >= 0) {
1723 int index = *(int *)arg;
1724 if (source == SUB_SOURCE_VOBSUB)
1725 index = vobsub_get_index_by_id(vo_vobsub, index);
1726 mpctx->global_sub_pos = offset + index;
1727 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1728 || sub_source(mpctx) != source) {
1729 mpctx->global_sub_pos = -1;
1730 *(int *) arg = -1;
1733 else
1734 mpctx->global_sub_pos = -1;
1735 break;
1736 case M_PROPERTY_STEP_UP:
1737 case M_PROPERTY_STEP_DOWN: {
1738 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1739 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1740 int step = (step_all > 0) ? 1 : -1;
1741 int max_sub_pos_for_source = -1;
1742 if (!is_cur_source)
1743 mpctx->global_sub_pos = -1;
1744 while (step_all) {
1745 if (mpctx->global_sub_pos == -1) {
1746 if (step > 0)
1747 mpctx->global_sub_pos = offset;
1748 else if (max_sub_pos_for_source == -1) {
1749 // Find max pos for specific source
1750 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1751 while (mpctx->global_sub_pos >= 0
1752 && sub_source(mpctx) != source)
1753 --mpctx->global_sub_pos;
1755 else
1756 mpctx->global_sub_pos = max_sub_pos_for_source;
1758 else {
1759 mpctx->global_sub_pos += step;
1760 if (mpctx->global_sub_pos < offset ||
1761 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1762 sub_source(mpctx) != source)
1763 mpctx->global_sub_pos = -1;
1765 step_all -= step;
1767 break;
1769 default:
1770 return M_PROPERTY_NOT_IMPLEMENTED;
1772 --mpctx->global_sub_pos;
1773 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1776 /// Subtitle delay (RW)
1777 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1778 MPContext *mpctx)
1780 if (!mpctx->sh_video)
1781 return M_PROPERTY_UNAVAILABLE;
1782 return m_property_delay(prop, action, arg, &sub_delay);
1785 /// Alignment of text subtitles (RW)
1786 static int mp_property_sub_alignment(m_option_t *prop, int action,
1787 void *arg, MPContext *mpctx)
1789 char *name[] = { _("top"), _("center"), _("bottom") };
1791 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1792 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1793 return M_PROPERTY_UNAVAILABLE;
1795 switch (action) {
1796 case M_PROPERTY_PRINT:
1797 if (!arg)
1798 return M_PROPERTY_ERROR;
1799 M_PROPERTY_CLAMP(prop, sub_alignment);
1800 *(char **) arg = strdup(mp_gtext(name[sub_alignment]));
1801 return M_PROPERTY_OK;
1802 case M_PROPERTY_SET:
1803 if (!arg)
1804 return M_PROPERTY_ERROR;
1805 case M_PROPERTY_STEP_UP:
1806 case M_PROPERTY_STEP_DOWN:
1807 vo_osd_changed(OSDTYPE_SUBTITLE);
1808 default:
1809 return m_property_choice(prop, action, arg, &sub_alignment);
1813 /// Subtitle visibility (RW)
1814 static int mp_property_sub_visibility(m_option_t *prop, int action,
1815 void *arg, MPContext *mpctx)
1817 if (!mpctx->sh_video)
1818 return M_PROPERTY_UNAVAILABLE;
1820 switch (action) {
1821 case M_PROPERTY_SET:
1822 if (!arg)
1823 return M_PROPERTY_ERROR;
1824 case M_PROPERTY_STEP_UP:
1825 case M_PROPERTY_STEP_DOWN:
1826 vo_osd_changed(OSDTYPE_SUBTITLE);
1827 if (vo_spudec)
1828 vo_osd_changed(OSDTYPE_SPU);
1829 default:
1830 return m_property_flag(prop, action, arg, &sub_visibility);
1834 #ifdef CONFIG_ASS
1835 /// Use margins for libass subtitles (RW)
1836 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1837 void *arg, MPContext *mpctx)
1839 if (!mpctx->sh_video)
1840 return M_PROPERTY_UNAVAILABLE;
1842 switch (action) {
1843 case M_PROPERTY_SET:
1844 if (!arg)
1845 return M_PROPERTY_ERROR;
1846 case M_PROPERTY_STEP_UP:
1847 case M_PROPERTY_STEP_DOWN:
1848 ass_force_reload = 1;
1849 default:
1850 return m_property_flag(prop, action, arg, &ass_use_margins);
1853 #endif
1855 /// Show only forced subtitles (RW)
1856 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1857 void *arg, MPContext *mpctx)
1859 if (!vo_spudec)
1860 return M_PROPERTY_UNAVAILABLE;
1862 switch (action) {
1863 case M_PROPERTY_SET:
1864 if (!arg)
1865 return M_PROPERTY_ERROR;
1866 case M_PROPERTY_STEP_UP:
1867 case M_PROPERTY_STEP_DOWN:
1868 m_property_flag(prop, action, arg, &forced_subs_only);
1869 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1870 return M_PROPERTY_OK;
1871 default:
1872 return m_property_flag(prop, action, arg, &forced_subs_only);
1877 #ifdef CONFIG_FREETYPE
1878 /// Subtitle scale (RW)
1879 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1880 MPContext *mpctx)
1882 struct MPOpts *opts = &mpctx->opts;
1884 switch (action) {
1885 case M_PROPERTY_SET:
1886 if (!arg)
1887 return M_PROPERTY_ERROR;
1888 M_PROPERTY_CLAMP(prop, *(float *) arg);
1889 #ifdef CONFIG_ASS
1890 if (opts->ass_enabled) {
1891 ass_font_scale = *(float *) arg;
1892 ass_force_reload = 1;
1894 #endif
1895 text_font_scale_factor = *(float *) arg;
1896 force_load_font = 1;
1897 return M_PROPERTY_OK;
1898 case M_PROPERTY_STEP_UP:
1899 case M_PROPERTY_STEP_DOWN:
1900 #ifdef CONFIG_ASS
1901 if (opts->ass_enabled) {
1902 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1903 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1904 M_PROPERTY_CLAMP(prop, ass_font_scale);
1905 ass_force_reload = 1;
1907 #endif
1908 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1909 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1910 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1911 force_load_font = 1;
1912 return M_PROPERTY_OK;
1913 default:
1914 #ifdef CONFIG_ASS
1915 if (opts->ass_enabled)
1916 return m_property_float_ro(prop, action, arg, ass_font_scale);
1917 else
1918 #endif
1919 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1922 #endif
1924 ///@}
1926 /// \defgroup TVProperties TV properties
1927 /// \ingroup Properties
1928 ///@{
1930 #ifdef CONFIG_TV
1932 /// TV color settings (RW)
1933 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1934 MPContext *mpctx)
1936 int r, val;
1937 tvi_handle_t *tvh = mpctx->demuxer->priv;
1938 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1939 return M_PROPERTY_UNAVAILABLE;
1941 switch (action) {
1942 case M_PROPERTY_SET:
1943 if (!arg)
1944 return M_PROPERTY_ERROR;
1945 M_PROPERTY_CLAMP(prop, *(int *) arg);
1946 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1947 case M_PROPERTY_GET:
1948 return tv_get_color_options(tvh, (int) prop->priv, arg);
1949 case M_PROPERTY_STEP_UP:
1950 case M_PROPERTY_STEP_DOWN:
1951 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1952 if (!r)
1953 return M_PROPERTY_ERROR;
1954 val += (arg ? *(int *) arg : 1) *
1955 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1956 M_PROPERTY_CLAMP(prop, val);
1957 return tv_set_color_options(tvh, (int) prop->priv, val);
1959 return M_PROPERTY_ERROR;
1961 return M_PROPERTY_NOT_IMPLEMENTED;
1964 #endif
1966 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1967 MPContext *mpctx)
1969 int val,result;
1970 int base_ioctl=(int)prop->priv;
1972 for teletext's GET,SET,STEP ioctls this is not 0
1973 SET is GET+1
1974 STEP is GET+2
1976 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
1977 return M_PROPERTY_UNAVAILABLE;
1978 if(!base_ioctl)
1979 return M_PROPERTY_ERROR;
1981 switch (action) {
1982 case M_PROPERTY_GET:
1983 if (!arg)
1984 return M_PROPERTY_ERROR;
1985 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
1986 break;
1987 case M_PROPERTY_SET:
1988 if (!arg)
1989 return M_PROPERTY_ERROR;
1990 M_PROPERTY_CLAMP(prop, *(int *) arg);
1991 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
1992 break;
1993 case M_PROPERTY_STEP_UP:
1994 case M_PROPERTY_STEP_DOWN:
1995 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
1996 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1997 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
1998 break;
1999 default:
2000 return M_PROPERTY_NOT_IMPLEMENTED;
2003 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2006 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2007 MPContext *mpctx)
2009 int result;
2010 int val;
2012 //with tvh==NULL will fail too
2013 result=mp_property_teletext_common(prop,action,arg,mpctx);
2014 if(result!=M_PROPERTY_OK)
2015 return result;
2017 if(teletext_control(mpctx->demuxer->teletext,
2018 (int)prop->priv, &val)==VBI_CONTROL_TRUE && val)
2019 mp_input_set_section(mpctx->input, "teletext");
2020 else
2021 mp_input_set_section(mpctx->input, "tv");
2022 return M_PROPERTY_OK;
2025 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2026 MPContext *mpctx)
2028 int result;
2029 int val;
2030 if (!mpctx->demuxer->teletext)
2031 return M_PROPERTY_UNAVAILABLE;
2032 switch(action){
2033 case M_PROPERTY_STEP_UP:
2034 case M_PROPERTY_STEP_DOWN:
2035 //This should be handled separately
2036 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2037 result=teletext_control(mpctx->demuxer->teletext,
2038 TV_VBI_CONTROL_STEP_PAGE, &val);
2039 break;
2040 default:
2041 result=mp_property_teletext_common(prop,action,arg,mpctx);
2043 return result;
2046 ///@}
2048 /// All properties available in MPlayer.
2049 /** \ingroup Properties
2051 static const m_option_t mp_properties[] = {
2052 // General
2053 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2054 M_OPT_RANGE, 0, 3, NULL },
2055 { "loop", mp_property_loop, CONF_TYPE_INT,
2056 M_OPT_MIN, -1, 0, NULL },
2057 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2058 M_OPT_RANGE, 0.01, 100.0, NULL },
2059 { "filename", mp_property_filename, CONF_TYPE_STRING,
2060 0, 0, 0, NULL },
2061 { "path", mp_property_path, CONF_TYPE_STRING,
2062 0, 0, 0, NULL },
2063 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2064 0, 0, 0, NULL },
2065 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2066 M_OPT_MIN, 0, 0, NULL },
2067 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2068 M_OPT_MIN, 0, 0, NULL },
2069 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2070 M_OPT_MIN, 0, 0, NULL },
2071 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2072 M_OPT_MIN, 0, 0, NULL },
2073 { "length", mp_property_length, CONF_TYPE_TIME,
2074 M_OPT_MIN, 0, 0, NULL },
2075 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2076 M_OPT_RANGE, 0, 100, NULL },
2077 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2078 M_OPT_MIN, 0, 0, NULL },
2079 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2080 M_OPT_MIN, 0, 0, NULL },
2081 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2082 0, 0, 0, NULL },
2083 { "angle", mp_property_angle, CONF_TYPE_INT,
2084 CONF_RANGE, -2, 10, NULL },
2085 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2086 0, 0, 0, NULL },
2087 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2088 M_OPT_RANGE, 0, 1, NULL },
2090 // Audio
2091 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2092 M_OPT_RANGE, 0, 100, NULL },
2093 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2094 M_OPT_RANGE, 0, 1, NULL },
2095 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2096 M_OPT_RANGE, -100, 100, NULL },
2097 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2098 0, 0, 0, NULL },
2099 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2100 0, 0, 0, NULL },
2101 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2102 0, 0, 0, NULL },
2103 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2104 0, 0, 0, NULL },
2105 { "channels", mp_property_channels, CONF_TYPE_INT,
2106 0, 0, 0, NULL },
2107 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2108 CONF_RANGE, -2, 65535, NULL },
2109 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2110 M_OPT_RANGE, -1, 1, NULL },
2112 // Video
2113 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2114 M_OPT_RANGE, 0, 1, NULL },
2115 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2116 M_OPT_RANGE, 0, 1, NULL },
2117 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2118 M_OPT_RANGE, 0, 2, NULL },
2119 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2120 M_OPT_RANGE, 0, 1, NULL },
2121 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2122 M_OPT_RANGE, 0, 1, NULL },
2123 { "border", mp_property_border, CONF_TYPE_FLAG,
2124 M_OPT_RANGE, 0, 1, NULL },
2125 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2126 M_OPT_RANGE, 0, 2, NULL },
2127 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2128 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2129 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2130 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2131 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2132 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2133 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2134 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2135 { "hue", mp_property_gamma, CONF_TYPE_INT,
2136 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2137 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2138 M_OPT_RANGE, 0, 1, NULL },
2139 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2140 M_OPT_RANGE, 0, 1, NULL },
2141 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2142 0, 0, 0, NULL },
2143 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2144 0, 0, 0, NULL },
2145 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2146 0, 0, 0, NULL },
2147 { "width", mp_property_width, CONF_TYPE_INT,
2148 0, 0, 0, NULL },
2149 { "height", mp_property_height, CONF_TYPE_INT,
2150 0, 0, 0, NULL },
2151 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2152 0, 0, 0, NULL },
2153 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2154 0, 0, 0, NULL },
2155 { "switch_video", mp_property_video, CONF_TYPE_INT,
2156 CONF_RANGE, -2, 65535, NULL },
2157 { "switch_program", mp_property_program, CONF_TYPE_INT,
2158 CONF_RANGE, -1, 65535, NULL },
2160 // Subs
2161 { "sub", mp_property_sub, CONF_TYPE_INT,
2162 M_OPT_MIN, -1, 0, NULL },
2163 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2164 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2165 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2166 M_OPT_MIN, -1, 0, NULL },
2167 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2168 M_OPT_MIN, -1, 0, NULL },
2169 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2170 M_OPT_MIN, -1, 0, NULL },
2171 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2172 0, 0, 0, NULL },
2173 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2174 M_OPT_RANGE, 0, 100, NULL },
2175 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2176 M_OPT_RANGE, 0, 2, NULL },
2177 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2178 M_OPT_RANGE, 0, 1, NULL },
2179 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2180 M_OPT_RANGE, 0, 1, NULL },
2181 #ifdef CONFIG_FREETYPE
2182 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2183 M_OPT_RANGE, 0, 100, NULL },
2184 #endif
2185 #ifdef CONFIG_ASS
2186 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2187 M_OPT_RANGE, 0, 1, NULL },
2188 #endif
2190 #ifdef CONFIG_TV
2191 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2192 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2193 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2194 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2195 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2196 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2197 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2198 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2199 #endif
2200 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2201 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2202 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2203 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2204 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2205 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2206 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2207 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2208 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2209 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2210 { NULL, NULL, NULL, 0, 0, 0, NULL }
2214 int mp_property_do(const char *name, int action, void *val, void *ctx)
2216 return m_property_do(mp_properties, name, action, val, ctx);
2219 char* mp_property_print(const char *name, void* ctx)
2221 char* ret = NULL;
2222 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2223 return NULL;
2224 return ret;
2227 char *property_expand_string(MPContext *mpctx, char *str)
2229 return m_properties_expand_string(mp_properties, str, mpctx);
2232 void property_print_help(void)
2234 m_properties_print_help_list(mp_properties);
2238 /* List of default ways to show a property on OSD.
2240 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2241 * a bar showing the current position between min/max values of the
2242 * property. In this case osd_msg is only used for terminal output
2243 * if there is no video; it'll be a label shown together with percentage.
2245 * Otherwise setting osd_msg will show the string on OSD, formatted with
2246 * the text value of the property as argument.
2248 static struct property_osd_display {
2249 /// property name
2250 const char *name;
2251 /// progressbar type
2252 int osd_progbar; // -1 is special value for seek indicators
2253 /// osd msg id if it must be shared
2254 int osd_id;
2255 /// osd msg template
2256 const char *osd_msg;
2257 } property_osd_display[] = {
2258 // general
2259 { "loop", 0, -1, _("Loop: %s") },
2260 { "chapter", -1, -1, NULL },
2261 // audio
2262 { "volume", OSD_VOLUME, -1, _("Volume") },
2263 { "mute", 0, -1, _("Mute: %s") },
2264 { "audio_delay", 0, -1, _("A-V delay: %s") },
2265 { "switch_audio", 0, -1, _("Audio: %s") },
2266 { "balance", OSD_BALANCE, -1, _("Balance") },
2267 // video
2268 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2269 { "ontop", 0, -1, _("Stay on top: %s") },
2270 { "rootwin", 0, -1, _("Rootwin: %s") },
2271 { "border", 0, -1, _("Border: %s") },
2272 { "framedropping", 0, -1, _("Framedropping: %s") },
2273 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2274 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2275 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2276 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2277 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2278 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2279 { "hue", OSD_HUE, -1, _("Hue") },
2280 { "vsync", 0, -1, _("VSync: %s") },
2281 // subs
2282 { "sub", 0, -1, _("Subtitles: %s") },
2283 { "sub_source", 0, -1, _("Sub source: %s") },
2284 { "sub_vob", 0, -1, _("Subtitles: %s") },
2285 { "sub_demux", 0, -1, _("Subtitles: %s") },
2286 { "sub_file", 0, -1, _("Subtitles: %s") },
2287 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2288 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2289 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2290 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2291 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2292 #ifdef CONFIG_FREETYPE
2293 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2294 #endif
2295 #ifdef CONFIG_TV
2296 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2297 { "tv_hue", OSD_HUE, -1, _("Hue") },
2298 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2299 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2300 #endif
2304 static int show_property_osd(MPContext *mpctx, const char *pname)
2306 struct MPOpts *opts = &mpctx->opts;
2307 int r;
2308 m_option_t* prop;
2309 struct property_osd_display *p;
2311 // look for the command
2312 for (p = property_osd_display; p->name; p++)
2313 if (!strcmp(p->name, pname))
2314 break;
2315 if (!p->name)
2316 return -1;
2318 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2319 return -1;
2321 if (p->osd_progbar == -1)
2322 mpctx->add_osd_seek_info = true;
2323 else if (p->osd_progbar) {
2324 if (prop->type == CONF_TYPE_INT) {
2325 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2326 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2327 prop->min, prop->max, r);
2328 } else if (prop->type == CONF_TYPE_FLOAT) {
2329 float f;
2330 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2331 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2332 prop->min, prop->max, f);
2333 } else {
2334 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2335 "Property use an unsupported type.\n");
2336 return -1;
2338 return 0;
2341 if (p->osd_msg) {
2342 char *val = mp_property_print(pname, mpctx);
2343 if (val) {
2344 int index = p - property_osd_display;
2345 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2346 1, opts->osd_duration, p->osd_msg, val);
2347 free(val);
2350 return 0;
2355 * \defgroup Command2Property Command to property bridge
2357 * It is used to handle most commands that just set a property
2358 * and optionally display something on the OSD.
2359 * Two kinds of commands are handled: adjust or toggle.
2361 * Adjust commands take 1 or 2 parameters: <value> <abs>
2362 * If <abs> is non-zero the property is set to the given value
2363 * otherwise it is adjusted.
2365 * Toggle commands take 0 or 1 parameters. With no parameter
2366 * or a value less than the property minimum it just steps the
2367 * property to its next value. Otherwise it sets it to the given
2368 * value.
2373 /// List of the commands that can be handled by setting a property.
2374 static struct {
2375 /// property name
2376 const char *name;
2377 /// cmd id
2378 int cmd;
2379 /// set/adjust or toggle command
2380 int toggle;
2381 } set_prop_cmd[] = {
2382 // general
2383 { "loop", MP_CMD_LOOP, 0},
2384 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2385 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2386 { "pause", MP_CMD_PAUSE, 0},
2387 // audio
2388 { "volume", MP_CMD_VOLUME, 0},
2389 { "mute", MP_CMD_MUTE, 1},
2390 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2391 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2392 { "balance", MP_CMD_BALANCE, 0},
2393 // video
2394 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2395 { "panscan", MP_CMD_PANSCAN, 0},
2396 { "ontop", MP_CMD_VO_ONTOP, 1},
2397 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2398 { "border", MP_CMD_VO_BORDER, 1},
2399 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2400 { "gamma", MP_CMD_GAMMA, 0},
2401 { "brightness", MP_CMD_BRIGHTNESS, 0},
2402 { "contrast", MP_CMD_CONTRAST, 0},
2403 { "saturation", MP_CMD_SATURATION, 0},
2404 { "hue", MP_CMD_HUE, 0},
2405 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2406 // subs
2407 { "sub", MP_CMD_SUB_SELECT, 1},
2408 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2409 { "sub_vob", MP_CMD_SUB_VOB, 1},
2410 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2411 { "sub_file", MP_CMD_SUB_FILE, 1},
2412 { "sub_pos", MP_CMD_SUB_POS, 0},
2413 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2414 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2415 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2416 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2417 #ifdef CONFIG_FREETYPE
2418 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2419 #endif
2420 #ifdef CONFIG_ASS
2421 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2422 #endif
2423 #ifdef CONFIG_TV
2424 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2425 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2426 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2427 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2428 #endif
2432 /// Handle commands that set a property.
2433 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2435 int i, r;
2436 m_option_t *prop;
2437 const char *pname;
2439 // look for the command
2440 for (i = 0; set_prop_cmd[i].name; i++)
2441 if (set_prop_cmd[i].cmd == cmd->id)
2442 break;
2443 if (!(pname = set_prop_cmd[i].name))
2444 return 0;
2446 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2447 return 0;
2449 // toggle command
2450 if (set_prop_cmd[i].toggle) {
2451 // set to value
2452 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2453 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2454 else
2455 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2456 } else if (cmd->args[1].v.i) //set
2457 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2458 else // adjust
2459 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2461 if (r <= 0)
2462 return 1;
2464 show_property_osd(mpctx, pname);
2466 return 1;
2469 #ifdef CONFIG_DVDNAV
2470 static const struct {
2471 const char *name;
2472 const mp_command_type cmd;
2473 } mp_dvdnav_bindings[] = {
2474 { "up", MP_CMD_DVDNAV_UP },
2475 { "down", MP_CMD_DVDNAV_DOWN },
2476 { "left", MP_CMD_DVDNAV_LEFT },
2477 { "right", MP_CMD_DVDNAV_RIGHT },
2478 { "menu", MP_CMD_DVDNAV_MENU },
2479 { "select", MP_CMD_DVDNAV_SELECT },
2480 { "prev", MP_CMD_DVDNAV_PREVMENU },
2481 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2484 * keep old dvdnav sub-command options for a while in order not to
2485 * break slave-mode API too suddenly.
2487 { "1", MP_CMD_DVDNAV_UP },
2488 { "2", MP_CMD_DVDNAV_DOWN },
2489 { "3", MP_CMD_DVDNAV_LEFT },
2490 { "4", MP_CMD_DVDNAV_RIGHT },
2491 { "5", MP_CMD_DVDNAV_MENU },
2492 { "6", MP_CMD_DVDNAV_SELECT },
2493 { "7", MP_CMD_DVDNAV_PREVMENU },
2494 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2495 { NULL, 0 }
2497 #endif
2499 static const char *property_error_string(int error_value)
2501 switch (error_value) {
2502 case M_PROPERTY_ERROR:
2503 return "ERROR";
2504 case M_PROPERTY_UNAVAILABLE:
2505 return "PROPERTY_UNAVAILABLE";
2506 case M_PROPERTY_NOT_IMPLEMENTED:
2507 return "NOT_IMPLEMENTED";
2508 case M_PROPERTY_UNKNOWN:
2509 return "PROPERTY_UNKNOWN";
2510 case M_PROPERTY_DISABLED:
2511 return "DISABLED";
2513 return "UNKNOWN";
2516 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2518 int idx;
2519 int end = start + count;
2520 int after = mpctx->set_of_sub_size - end;
2521 sub_data **subs = mpctx->set_of_subtitles;
2522 #ifdef CONFIG_ASS
2523 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2524 #endif
2525 if (count < 0 || count > mpctx->set_of_sub_size ||
2526 start < 0 || start > mpctx->set_of_sub_size - count) {
2527 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2528 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2529 return;
2531 for (idx = start; idx < end; idx++) {
2532 sub_data *subd = subs[idx];
2533 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2534 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2535 filename_recode(subd->filename));
2536 sub_free(subd);
2537 subs[idx] = NULL;
2538 #ifdef CONFIG_ASS
2539 if (ass_tracks[idx])
2540 ass_free_track(ass_tracks[idx]);
2541 ass_tracks[idx] = NULL;
2542 #endif
2545 mpctx->global_sub_size -= count;
2546 mpctx->set_of_sub_size -= count;
2547 if (mpctx->set_of_sub_size <= 0)
2548 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2550 memmove(subs + start, subs + end, after * sizeof(*subs));
2551 memset(subs + start + after, 0, count * sizeof(*subs));
2552 #ifdef CONFIG_ASS
2553 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2554 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2555 #endif
2557 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2558 mpctx->global_sub_pos = -2;
2559 subdata = NULL;
2560 #ifdef CONFIG_ASS
2561 ass_track = NULL;
2562 #endif
2563 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2564 } else if (mpctx->set_of_sub_pos >= end) {
2565 mpctx->set_of_sub_pos -= count;
2566 mpctx->global_sub_pos -= count;
2570 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2572 struct MPOpts *opts = &mpctx->opts;
2573 sh_audio_t * const sh_audio = mpctx->sh_audio;
2574 sh_video_t * const sh_video = mpctx->sh_video;
2575 int osd_duration = opts->osd_duration;
2576 int case_fallthrough_hack = 0;
2577 if (!set_property_command(mpctx, cmd))
2578 switch (cmd->id) {
2579 case MP_CMD_SEEK:{
2580 float v;
2581 int abs;
2582 mpctx->add_osd_seek_info = true;
2583 v = cmd->args[0].v.f;
2584 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2585 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2586 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2587 if (sh_video)
2588 mpctx->osd_function =
2589 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2590 mpctx->rel_seek_secs = v;
2591 } else if (abs) { /* Absolute seek by percentage */
2592 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2593 if (sh_video)
2594 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2595 mpctx->rel_seek_secs = v / 100.0;
2596 } else {
2597 mpctx->rel_seek_secs += v;
2598 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2601 break;
2603 case MP_CMD_SET_PROPERTY_OSD:
2604 case_fallthrough_hack = 1;
2606 case MP_CMD_SET_PROPERTY:{
2607 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2608 cmd->args[1].v.s, mpctx);
2609 if (r == M_PROPERTY_UNKNOWN)
2610 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2611 "Unknown property: '%s'\n", cmd->args[0].v.s);
2612 else if (r <= 0)
2613 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2614 "Failed to set property '%s' to '%s'.\n",
2615 cmd->args[0].v.s, cmd->args[1].v.s);
2616 else if (case_fallthrough_hack)
2617 show_property_osd(mpctx, cmd->args[0].v.s);
2618 if (r <= 0)
2619 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2621 break;
2623 case MP_CMD_STEP_PROPERTY_OSD:
2624 case_fallthrough_hack = 1;
2626 case MP_CMD_STEP_PROPERTY:{
2627 void* arg = NULL;
2628 int r,i;
2629 double d;
2630 off_t o;
2631 if (cmd->args[1].v.f) {
2632 m_option_t* prop;
2633 if((r = mp_property_do(cmd->args[0].v.s,
2634 M_PROPERTY_GET_TYPE,
2635 &prop, mpctx)) <= 0)
2636 goto step_prop_err;
2637 if(prop->type == CONF_TYPE_INT ||
2638 prop->type == CONF_TYPE_FLAG)
2639 i = cmd->args[1].v.f, arg = &i;
2640 else if(prop->type == CONF_TYPE_FLOAT)
2641 arg = &cmd->args[1].v.f;
2642 else if(prop->type == CONF_TYPE_DOUBLE ||
2643 prop->type == CONF_TYPE_TIME)
2644 d = cmd->args[1].v.f, arg = &d;
2645 else if(prop->type == CONF_TYPE_POSITION)
2646 o = cmd->args[1].v.f, arg = &o;
2647 else
2648 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2649 "Ignoring step size stepping property '%s'.\n",
2650 cmd->args[0].v.s);
2652 r = mp_property_do(cmd->args[0].v.s,
2653 cmd->args[2].v.i < 0 ?
2654 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2655 arg, mpctx);
2656 step_prop_err:
2657 if (r == M_PROPERTY_UNKNOWN)
2658 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2659 "Unknown property: '%s'\n", cmd->args[0].v.s);
2660 else if (r <= 0)
2661 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2662 "Failed to increment property '%s' by %f.\n",
2663 cmd->args[0].v.s, cmd->args[1].v.f);
2664 else if (case_fallthrough_hack)
2665 show_property_osd(mpctx, cmd->args[0].v.s);
2666 if (r <= 0)
2667 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2669 break;
2671 case MP_CMD_GET_PROPERTY:{
2672 char *tmp;
2673 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2674 &tmp, mpctx);
2675 if (r <= 0) {
2676 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2677 "Failed to get value of property '%s'.\n",
2678 cmd->args[0].v.s);
2679 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2680 break;
2682 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2683 cmd->args[0].v.s, tmp);
2684 free(tmp);
2686 break;
2688 case MP_CMD_EDL_MARK:
2689 if (edl_fd) {
2690 float v = sh_video ? sh_video->pts :
2691 playing_audio_pts(mpctx);
2692 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2693 mpctx->begin_skip = v;
2694 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2695 } else {
2696 if (mpctx->begin_skip > v)
2697 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2698 else {
2699 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2700 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2702 mpctx->begin_skip = MP_NOPTS_VALUE;
2705 break;
2707 case MP_CMD_SWITCH_RATIO:
2708 if (!sh_video)
2709 break;
2710 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2711 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2712 else
2713 opts->movie_aspect = cmd->args[0].v.f;
2714 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2715 break;
2717 case MP_CMD_SPEED_INCR:{
2718 float v = cmd->args[0].v.f;
2719 opts->playback_speed += v;
2720 build_afilter_chain(mpctx, sh_audio, &ao_data);
2721 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2722 opts->playback_speed);
2723 } break;
2725 case MP_CMD_SPEED_MULT:{
2726 float v = cmd->args[0].v.f;
2727 opts->playback_speed *= v;
2728 build_afilter_chain(mpctx, sh_audio, &ao_data);
2729 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2730 opts->playback_speed);
2731 } break;
2733 case MP_CMD_SPEED_SET:{
2734 float v = cmd->args[0].v.f;
2735 opts->playback_speed = v;
2736 build_afilter_chain(mpctx, sh_audio, &ao_data);
2737 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2738 opts->playback_speed);
2739 } break;
2741 case MP_CMD_FRAME_STEP:
2742 add_step_frame(mpctx);
2743 break;
2745 case MP_CMD_FILE_FILTER:
2746 file_filter = cmd->args[0].v.i;
2747 break;
2749 case MP_CMD_QUIT:
2750 exit_player_with_rc(mpctx, EXIT_QUIT,
2751 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2753 case MP_CMD_PLAY_TREE_STEP:{
2754 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2755 int force = cmd->args[1].v.i;
2758 if (!force && mpctx->playtree_iter) {
2759 play_tree_iter_t *i =
2760 play_tree_iter_new_copy(mpctx->playtree_iter);
2761 if (play_tree_iter_step(i, n, 0) ==
2762 PLAY_TREE_ITER_ENTRY)
2763 mpctx->stop_play =
2764 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2765 play_tree_iter_free(i);
2766 } else
2767 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2768 if (mpctx->stop_play)
2769 mpctx->play_tree_step = n;
2772 break;
2774 case MP_CMD_PLAY_TREE_UP_STEP:{
2775 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2776 int force = cmd->args[1].v.i;
2778 if (!force && mpctx->playtree_iter) {
2779 play_tree_iter_t *i =
2780 play_tree_iter_new_copy(mpctx->playtree_iter);
2781 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2782 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2783 play_tree_iter_free(i);
2784 } else
2785 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2787 break;
2789 case MP_CMD_PLAY_ALT_SRC_STEP:
2790 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2791 int v = cmd->args[0].v.i;
2792 if (v > 0
2793 && mpctx->playtree_iter->file <
2794 mpctx->playtree_iter->num_files)
2795 mpctx->stop_play = PT_NEXT_SRC;
2796 else if (v < 0 && mpctx->playtree_iter->file > 1)
2797 mpctx->stop_play = PT_PREV_SRC;
2799 break;
2801 case MP_CMD_SUB_STEP:
2802 if (sh_video) {
2803 int movement = cmd->args[0].v.i;
2804 step_sub(subdata, sh_video->pts, movement);
2805 #ifdef CONFIG_ASS
2806 if (ass_track)
2807 sub_delay +=
2808 ass_step_sub(ass_track,
2809 (sh_video->pts +
2810 sub_delay) * 1000 + .5, movement) / 1000.;
2811 #endif
2812 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2813 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2815 break;
2817 case MP_CMD_SUB_LOG:
2818 log_sub(mpctx);
2819 break;
2821 case MP_CMD_OSD:{
2822 int v = cmd->args[0].v.i;
2823 int max = (term_osd
2824 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2825 if (opts->osd_level > max)
2826 opts->osd_level = max;
2827 if (v < 0)
2828 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2829 else
2830 opts->osd_level = v > max ? max : v;
2831 /* Show OSD state when disabled, but not when an explicit
2832 argument is given to the OSD command, i.e. in slave mode. */
2833 if (v == -1 && opts->osd_level <= 1)
2834 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2835 "OSD: %s",
2836 opts->osd_level ? mp_gtext("enabled") :
2837 mp_gtext("disabled"));
2838 else
2839 rm_osd_msg(OSD_MSG_OSD_STATUS);
2841 break;
2843 case MP_CMD_OSD_SHOW_TEXT:
2844 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2845 (cmd->args[1].v.i <
2846 0 ? osd_duration : cmd->args[1].v.i),
2847 "%-.63s", cmd->args[0].v.s);
2848 break;
2850 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2851 char *txt = m_properties_expand_string(mp_properties,
2852 cmd->args[0].v.s,
2853 mpctx);
2854 /* if no argument supplied take default osd_duration, else <arg> ms. */
2855 if (txt) {
2856 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2857 (cmd->args[1].v.i <
2858 0 ? osd_duration : cmd->args[1].v.i),
2859 "%-.63s", txt);
2860 free(txt);
2863 break;
2865 case MP_CMD_LOADFILE:{
2866 play_tree_t *e = play_tree_new();
2867 play_tree_add_file(e, cmd->args[0].v.s);
2869 if (cmd->args[1].v.i) // append
2870 play_tree_append_entry(mpctx->playtree->child, e);
2871 else {
2872 // Go back to the starting point.
2873 while (play_tree_iter_up_step
2874 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2875 /* NOP */ ;
2876 play_tree_free_list(mpctx->playtree->child, 1);
2877 play_tree_set_child(mpctx->playtree, e);
2878 pt_iter_goto_head(mpctx->playtree_iter);
2879 mpctx->stop_play = PT_NEXT_SRC;
2882 break;
2884 case MP_CMD_LOADLIST:{
2885 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2886 if (!e)
2887 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2888 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2889 else {
2890 if (cmd->args[1].v.i) // append
2891 play_tree_append_entry(mpctx->playtree->child, e);
2892 else {
2893 // Go back to the starting point.
2894 while (play_tree_iter_up_step
2895 (mpctx->playtree_iter, 0, 1)
2896 != PLAY_TREE_ITER_END)
2897 /* NOP */ ;
2898 play_tree_free_list(mpctx->playtree->child, 1);
2899 play_tree_set_child(mpctx->playtree, e);
2900 pt_iter_goto_head(mpctx->playtree_iter);
2901 mpctx->stop_play = PT_NEXT_SRC;
2905 break;
2907 case MP_CMD_STOP:
2908 // Go back to the starting point.
2909 while (play_tree_iter_up_step
2910 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2911 /* NOP */ ;
2912 mpctx->stop_play = PT_STOP;
2913 break;
2915 case MP_CMD_OSD_SHOW_PROGRESSION:{
2916 int len = demuxer_get_time_length(mpctx->demuxer);
2917 int pts = demuxer_get_current_time(mpctx->demuxer);
2918 set_osd_bar(mpctx, 0, "Position", 0, 100, demuxer_get_percent_pos(mpctx->demuxer));
2919 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2920 "%c %02d:%02d:%02d / %02d:%02d:%02d",
2921 mpctx->osd_function, pts/3600, (pts/60)%60, pts%60,
2922 len/3600, (len/60)%60, len%60);
2924 break;
2926 #ifdef CONFIG_RADIO
2927 case MP_CMD_RADIO_STEP_CHANNEL:
2928 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2929 int v = cmd->args[0].v.i;
2930 if (v > 0)
2931 radio_step_channel(mpctx->demuxer->stream,
2932 RADIO_CHANNEL_HIGHER);
2933 else
2934 radio_step_channel(mpctx->demuxer->stream,
2935 RADIO_CHANNEL_LOWER);
2936 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2937 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2938 "Channel: %s",
2939 radio_get_channel_name(mpctx->demuxer->stream));
2942 break;
2944 case MP_CMD_RADIO_SET_CHANNEL:
2945 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2946 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2947 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2948 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2949 "Channel: %s",
2950 radio_get_channel_name(mpctx->demuxer->stream));
2953 break;
2955 case MP_CMD_RADIO_SET_FREQ:
2956 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2957 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2958 break;
2960 case MP_CMD_RADIO_STEP_FREQ:
2961 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2962 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2963 break;
2964 #endif
2966 #ifdef CONFIG_TV
2967 case MP_CMD_TV_START_SCAN:
2968 if (mpctx->file_format == DEMUXER_TYPE_TV)
2969 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2970 break;
2971 case MP_CMD_TV_SET_FREQ:
2972 if (mpctx->file_format == DEMUXER_TYPE_TV)
2973 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2974 cmd->args[0].v.f * 16.0);
2975 #ifdef CONFIG_PVR
2976 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2977 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2978 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2979 pvr_get_current_channelname (mpctx->stream),
2980 pvr_get_current_stationname (mpctx->stream));
2982 #endif /* CONFIG_PVR */
2983 break;
2985 case MP_CMD_TV_STEP_FREQ:
2986 if (mpctx->file_format == DEMUXER_TYPE_TV)
2987 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2988 cmd->args[0].v.f * 16.0);
2989 #ifdef CONFIG_PVR
2990 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2991 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2992 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2993 pvr_get_current_channelname (mpctx->stream),
2994 pvr_get_current_frequency (mpctx->stream));
2996 #endif /* CONFIG_PVR */
2997 break;
2999 case MP_CMD_TV_SET_NORM:
3000 if (mpctx->file_format == DEMUXER_TYPE_TV)
3001 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3002 cmd->args[0].v.s);
3003 break;
3005 case MP_CMD_TV_STEP_CHANNEL:{
3006 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3007 int v = cmd->args[0].v.i;
3008 if (v > 0) {
3009 tv_step_channel((tvi_handle_t *) (mpctx->
3010 demuxer->priv),
3011 TV_CHANNEL_HIGHER);
3012 } else {
3013 tv_step_channel((tvi_handle_t *) (mpctx->
3014 demuxer->priv),
3015 TV_CHANNEL_LOWER);
3017 if (tv_channel_list) {
3018 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3019 "Channel: %s", tv_channel_current->name);
3020 //vo_osd_changed(OSDTYPE_SUBTITLE);
3023 #ifdef CONFIG_PVR
3024 else if (mpctx->stream &&
3025 mpctx->stream->type == STREAMTYPE_PVR) {
3026 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3027 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3028 pvr_get_current_channelname (mpctx->stream),
3029 pvr_get_current_stationname (mpctx->stream));
3031 #endif /* CONFIG_PVR */
3033 #ifdef CONFIG_DVBIN
3034 if (mpctx->stream->type == STREAMTYPE_DVB) {
3035 int dir;
3036 int v = cmd->args[0].v.i;
3038 mpctx->last_dvb_step = v;
3039 if (v > 0)
3040 dir = DVB_CHANNEL_HIGHER;
3041 else
3042 dir = DVB_CHANNEL_LOWER;
3045 if (dvb_step_channel(mpctx->stream, dir)) {
3046 mpctx->stop_play = PT_NEXT_ENTRY;
3047 mpctx->dvbin_reopen = 1;
3050 #endif /* CONFIG_DVBIN */
3051 break;
3053 case MP_CMD_TV_SET_CHANNEL:
3054 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3055 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3056 cmd->args[0].v.s);
3057 if (tv_channel_list) {
3058 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3059 "Channel: %s", tv_channel_current->name);
3060 //vo_osd_changed(OSDTYPE_SUBTITLE);
3063 #ifdef CONFIG_PVR
3064 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3065 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3066 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3067 pvr_get_current_channelname (mpctx->stream),
3068 pvr_get_current_stationname (mpctx->stream));
3070 #endif /* CONFIG_PVR */
3071 break;
3073 #ifdef CONFIG_DVBIN
3074 case MP_CMD_DVB_SET_CHANNEL:
3075 if (mpctx->stream->type == STREAMTYPE_DVB) {
3076 mpctx->last_dvb_step = 1;
3078 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3079 cmd->args[0].v.i)) {
3080 mpctx->stop_play = PT_NEXT_ENTRY;
3081 mpctx->dvbin_reopen = 1;
3084 break;
3085 #endif /* CONFIG_DVBIN */
3087 case MP_CMD_TV_LAST_CHANNEL:
3088 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3089 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3090 if (tv_channel_list) {
3091 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3092 "Channel: %s", tv_channel_current->name);
3093 //vo_osd_changed(OSDTYPE_SUBTITLE);
3096 #ifdef CONFIG_PVR
3097 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3098 pvr_set_lastchannel (mpctx->stream);
3099 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3100 pvr_get_current_channelname (mpctx->stream),
3101 pvr_get_current_stationname (mpctx->stream));
3103 #endif /* CONFIG_PVR */
3104 break;
3106 case MP_CMD_TV_STEP_NORM:
3107 if (mpctx->file_format == DEMUXER_TYPE_TV)
3108 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3109 break;
3111 case MP_CMD_TV_STEP_CHANNEL_LIST:
3112 if (mpctx->file_format == DEMUXER_TYPE_TV)
3113 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3114 break;
3115 #endif /* CONFIG_TV */
3116 case MP_CMD_TV_TELETEXT_ADD_DEC:
3118 if (mpctx->demuxer->teletext)
3119 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3120 &(cmd->args[0].v.s));
3121 break;
3123 case MP_CMD_TV_TELETEXT_GO_LINK:
3125 if (mpctx->demuxer->teletext)
3126 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3127 &(cmd->args[0].v.i));
3128 break;
3131 case MP_CMD_SUB_LOAD:
3132 if (sh_video) {
3133 int n = mpctx->set_of_sub_size;
3134 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3135 if (n != mpctx->set_of_sub_size) {
3136 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
3137 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
3138 mpctx->global_sub_size;
3139 ++mpctx->global_sub_size;
3142 break;
3144 case MP_CMD_SUB_REMOVE:
3145 if (sh_video) {
3146 int v = cmd->args[0].v.i;
3147 if (v < 0) {
3148 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3149 } else if (v < mpctx->set_of_sub_size) {
3150 remove_subtitle_range(mpctx, v, 1);
3153 break;
3155 case MP_CMD_GET_SUB_VISIBILITY:
3156 if (sh_video) {
3157 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3158 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3160 break;
3162 case MP_CMD_SCREENSHOT:
3163 if (mpctx->video_out && mpctx->video_out->config_ok) {
3164 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3165 if (CONTROL_OK !=
3166 ((vf_instance_t *) sh_video->vfilter)->
3167 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3168 &cmd->args[0].v.i))
3169 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3171 break;
3173 case MP_CMD_VF_CHANGE_RECTANGLE:
3174 if (!sh_video)
3175 break;
3176 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3177 break;
3179 case MP_CMD_GET_TIME_LENGTH:{
3180 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3181 demuxer_get_time_length(mpctx->demuxer));
3183 break;
3185 case MP_CMD_GET_FILENAME:{
3186 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3187 get_metadata(mpctx, META_NAME));
3189 break;
3191 case MP_CMD_GET_VIDEO_CODEC:{
3192 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3193 if (!inf)
3194 inf = strdup("");
3195 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3196 free(inf);
3198 break;
3200 case MP_CMD_GET_VIDEO_BITRATE:{
3201 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3202 if (!inf)
3203 inf = strdup("");
3204 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3205 free(inf);
3207 break;
3209 case MP_CMD_GET_VIDEO_RESOLUTION:{
3210 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3211 if (!inf)
3212 inf = strdup("");
3213 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3214 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3215 free(inf);
3217 break;
3219 case MP_CMD_GET_AUDIO_CODEC:{
3220 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3221 if (!inf)
3222 inf = strdup("");
3223 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3224 free(inf);
3226 break;
3228 case MP_CMD_GET_AUDIO_BITRATE:{
3229 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3230 if (!inf)
3231 inf = strdup("");
3232 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3233 free(inf);
3235 break;
3237 case MP_CMD_GET_AUDIO_SAMPLES:{
3238 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3239 if (!inf)
3240 inf = strdup("");
3241 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3242 free(inf);
3244 break;
3246 case MP_CMD_GET_META_TITLE:{
3247 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3248 if (!inf)
3249 inf = strdup("");
3250 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3251 free(inf);
3253 break;
3255 case MP_CMD_GET_META_ARTIST:{
3256 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3257 if (!inf)
3258 inf = strdup("");
3259 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3260 free(inf);
3262 break;
3264 case MP_CMD_GET_META_ALBUM:{
3265 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3266 if (!inf)
3267 inf = strdup("");
3268 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3269 free(inf);
3271 break;
3273 case MP_CMD_GET_META_YEAR:{
3274 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3275 if (!inf)
3276 inf = strdup("");
3277 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3278 free(inf);
3280 break;
3282 case MP_CMD_GET_META_COMMENT:{
3283 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3284 if (!inf)
3285 inf = strdup("");
3286 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3287 free(inf);
3289 break;
3291 case MP_CMD_GET_META_TRACK:{
3292 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3293 if (!inf)
3294 inf = strdup("");
3295 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3296 free(inf);
3298 break;
3300 case MP_CMD_GET_META_GENRE:{
3301 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3302 if (!inf)
3303 inf = strdup("");
3304 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3305 free(inf);
3307 break;
3309 case MP_CMD_GET_VO_FULLSCREEN:
3310 if (mpctx->video_out && mpctx->video_out->config_ok)
3311 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3312 break;
3314 case MP_CMD_GET_PERCENT_POS:
3315 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3316 demuxer_get_percent_pos(mpctx->demuxer));
3317 break;
3319 case MP_CMD_GET_TIME_POS:{
3320 float pos = 0;
3321 if (sh_video)
3322 pos = sh_video->pts;
3323 else if (sh_audio && mpctx->audio_out)
3324 pos = playing_audio_pts(mpctx);
3325 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3327 break;
3329 case MP_CMD_RUN:
3330 #ifndef __MINGW32__
3331 if (!fork()) {
3332 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3333 exit(0);
3335 #endif
3336 break;
3338 case MP_CMD_KEYDOWN_EVENTS:
3339 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3340 break;
3342 case MP_CMD_SET_MOUSE_POS:{
3343 int pointer_x, pointer_y;
3344 double dx, dy;
3345 pointer_x = cmd->args[0].v.i;
3346 pointer_y = cmd->args[1].v.i;
3347 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3348 #ifdef CONFIG_DVDNAV
3349 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3350 && dx > 0.0 && dy > 0.0) {
3351 int button = -1;
3352 pointer_x = (int) (dx * (double) sh_video->disp_w);
3353 pointer_y = (int) (dy * (double) sh_video->disp_h);
3354 mp_dvdnav_update_mouse_pos(mpctx->stream,
3355 pointer_x, pointer_y, &button);
3356 if (opts->osd_level > 1 && button > 0)
3357 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3358 "Selected button number %d", button);
3360 #endif
3361 #ifdef CONFIG_MENU
3362 if (use_menu && dx >= 0.0 && dy >= 0.0)
3363 menu_update_mouse_pos(dx, dy);
3364 #endif
3366 break;
3368 #ifdef CONFIG_DVDNAV
3369 case MP_CMD_DVDNAV:{
3370 int button = -1;
3371 int i;
3372 mp_command_type command = 0;
3373 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3374 break;
3376 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3377 if (cmd->args[0].v.s &&
3378 !strcasecmp (cmd->args[0].v.s,
3379 mp_dvdnav_bindings[i].name))
3380 command = mp_dvdnav_bindings[i].cmd;
3382 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3383 if (opts->osd_level > 1 && button > 0)
3384 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3385 "Selected button number %d", button);
3387 break;
3389 case MP_CMD_SWITCH_TITLE:
3390 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3391 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3392 break;
3394 #endif
3396 case MP_CMD_AF_SWITCH:
3397 if (sh_audio)
3399 af_uninit(mpctx->mixer.afilter);
3400 af_init(mpctx->mixer.afilter);
3402 case MP_CMD_AF_ADD:
3403 case MP_CMD_AF_DEL:
3404 if (!sh_audio)
3405 break;
3407 char* af_args = strdup(cmd->args[0].v.s);
3408 char* af_commands = af_args;
3409 char* af_command;
3410 af_instance_t* af;
3411 while ((af_command = strsep(&af_commands, ",")) != NULL)
3413 if (cmd->id == MP_CMD_AF_DEL)
3415 af = af_get(mpctx->mixer.afilter, af_command);
3416 if (af != NULL)
3417 af_remove(mpctx->mixer.afilter, af);
3419 else
3420 af_add(mpctx->mixer.afilter, af_command);
3422 build_afilter_chain(mpctx, sh_audio, &ao_data);
3423 free(af_args);
3425 break;
3426 case MP_CMD_AF_CLR:
3427 if (!sh_audio)
3428 break;
3429 af_uninit(mpctx->mixer.afilter);
3430 af_init(mpctx->mixer.afilter);
3431 build_afilter_chain(mpctx, sh_audio, &ao_data);
3432 break;
3433 default:
3434 mp_msg(MSGT_CPLAYER, MSGL_V,
3435 "Received unknown cmd %s\n", cmd->name);
3438 switch (cmd->pausing) {
3439 case 1: // "pausing"
3440 pause_player(mpctx);
3441 break;
3442 case 3: // "pausing_toggle"
3443 if (mpctx->paused)
3444 unpause_player(mpctx);
3445 else
3446 pause_player(mpctx);
3447 break;