demux_ts: fix -sb when -aid stream is not found
[mplayer/glamo.git] / command.c
blob4ffe29a351b5fb13c5e273283ff0029a2fc0dab4
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdlib.h>
20 #include <inttypes.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <stdbool.h>
25 #include "config.h"
26 #include "talloc.h"
27 #include "command.h"
28 #include "input/input.h"
29 #include "stream/stream.h"
30 #include "libmpdemux/demuxer.h"
31 #include "libmpdemux/stheader.h"
32 #include "codec-cfg.h"
33 #include "mplayer.h"
34 #include "libvo/sub.h"
35 #include "m_option.h"
36 #include "m_property.h"
37 #include "metadata.h"
38 #include "libmpcodecs/vf.h"
39 #include "libmpcodecs/vd.h"
40 #include "mp_osd.h"
41 #include "libvo/video_out.h"
42 #include "libvo/font_load.h"
43 #include "playtree.h"
44 #include "libao2/audio_out.h"
45 #include "mpcommon.h"
46 #include "mixer.h"
47 #include "libmpcodecs/dec_video.h"
48 #include "libmpcodecs/dec_audio.h"
49 #include "libmpcodecs/dec_teletext.h"
50 #include "vobsub.h"
51 #include "spudec.h"
52 #include "path.h"
53 #include "ass_mp.h"
54 #include "stream/tv.h"
55 #include "stream/stream_radio.h"
56 #include "stream/pvr.h"
57 #ifdef CONFIG_DVBIN
58 #include "stream/dvbin.h"
59 #endif
60 #ifdef CONFIG_DVDREAD
61 #include "stream/stream_dvd.h"
62 #endif
63 #include "stream/stream_dvdnav.h"
64 #include "m_struct.h"
65 #include "libmenu/menu.h"
67 #include "mp_core.h"
68 #include "mp_fifo.h"
69 #include "libavutil/avstring.h"
71 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
73 extern int use_menu;
75 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
76 double *dx, double *dy)
78 struct MPOpts *opts = &mpctx->opts;
79 struct vo *vo = mpctx->video_out;
80 //remove the borders, if any, and rescale to the range [0,1],[0,1]
81 if (vo_fs) { //we are in full-screen mode
82 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
83 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
84 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
85 iy -= (opts->vo_screenheight - vo->dheight) / 2;
87 if (ix < 0 || ix > vo->dwidth) {
88 *dx = *dy = -1.0;
89 return;
90 } //we are on one of the borders
91 if (iy < 0 || iy > vo->dheight) {
92 *dx = *dy = -1.0;
93 return;
94 } //we are on one of the borders
97 *dx = (double) ix / (double) vo->dwidth;
98 *dy = (double) iy / (double) vo->dheight;
100 mp_msg(MSGT_CPLAYER, MSGL_V,
101 "\r\nrescaled coordinates: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
102 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
103 vo->dheight, vo_fs);
106 static int sub_pos_by_source(MPContext *mpctx, int src)
108 int i, cnt = 0;
109 if (src >= SUB_SOURCES || mpctx->sub_counts[src] == 0)
110 return -1;
111 for (i = 0; i < src; i++)
112 cnt += mpctx->sub_counts[i];
113 return cnt;
116 static int sub_source_and_index_by_pos(MPContext *mpctx, int *pos)
118 int start = 0;
119 int i;
120 for (i = 0; i < SUB_SOURCES; i++) {
121 int cnt = mpctx->sub_counts[i];
122 if (*pos >= start && *pos < start + cnt) {
123 *pos -= start;
124 return i;
126 start += cnt;
128 *pos = -1;
129 return -1;
132 static int sub_source_by_pos(MPContext *mpctx, int pos)
134 return sub_source_and_index_by_pos(mpctx, &pos);
137 static int sub_source_pos(MPContext *mpctx)
139 int pos = mpctx->global_sub_pos;
140 sub_source_and_index_by_pos(mpctx, &pos);
141 return pos;
144 static int sub_source(MPContext *mpctx)
146 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
149 static void update_global_sub_size(MPContext *mpctx)
151 struct MPOpts *opts = &mpctx->opts;
152 int i;
153 int cnt = 0;
155 // update number of demuxer sub streams
156 for (i = 0; i < MAX_S_STREAMS; i++)
157 if (mpctx->d_sub->demuxer->s_streams[i])
158 cnt++;
159 if (cnt > mpctx->sub_counts[SUB_SOURCE_DEMUX])
160 mpctx->sub_counts[SUB_SOURCE_DEMUX] = cnt;
162 // update global size
163 mpctx->global_sub_size = 0;
164 for (i = 0; i < SUB_SOURCES; i++)
165 mpctx->global_sub_size += mpctx->sub_counts[i];
167 // update global_sub_pos if we auto-detected a demuxer sub
168 if (mpctx->global_sub_pos == -1) {
169 int sub_id = -1;
170 if (mpctx->demuxer->sub)
171 sub_id = mpctx->demuxer->sub->id;
172 if (sub_id < 0)
173 sub_id = opts->sub_id;
174 if (sub_id >= 0 && sub_id < mpctx->sub_counts[SUB_SOURCE_DEMUX])
175 mpctx->global_sub_pos = sub_pos_by_source(mpctx, SUB_SOURCE_DEMUX) +
176 sub_id;
181 * \brief Log the currently displayed subtitle to a file
183 * Logs the current or last displayed subtitle together with filename
184 * and time information to ~/.mplayer/subtitle_log
186 * Intended purpose is to allow convenient marking of bogus subtitles
187 * which need to be fixed while watching the movie.
190 static void log_sub(struct MPContext *mpctx)
192 char *fname;
193 FILE *f;
194 int i;
196 if (subdata == NULL || vo_sub_last == NULL)
197 return;
198 fname = get_path("subtitle_log");
199 f = fopen(fname, "a");
200 if (!f)
201 return;
202 fprintf(f, "----------------------------------------------------------\n");
203 if (subdata->sub_uses_time) {
204 fprintf(f,
205 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
206 mpctx->filename, vo_sub_last->start / 360000,
207 (vo_sub_last->start / 6000) % 60,
208 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
209 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
210 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
211 } else {
212 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
213 vo_sub_last->start, vo_sub_last->end);
215 for (i = 0; i < vo_sub_last->lines; i++) {
216 fprintf(f, "%s\n", vo_sub_last->text[i]);
218 fclose(f);
222 /// \defgroup Properties
223 ///@{
225 /// \defgroup GeneralProperties General properties
226 /// \ingroup Properties
227 ///@{
229 /// OSD level (RW)
230 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
231 MPContext *mpctx)
233 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
236 /// Loop (RW)
237 static int mp_property_loop(m_option_t *prop, int action, void *arg,
238 MPContext *mpctx)
240 struct MPOpts *opts = &mpctx->opts;
241 switch (action) {
242 case M_PROPERTY_PRINT:
243 if (!arg) return M_PROPERTY_ERROR;
244 if (opts->loop_times < 0)
245 *(char**)arg = strdup("off");
246 else if (opts->loop_times == 0)
247 *(char**)arg = strdup("inf");
248 else
249 break;
250 return M_PROPERTY_OK;
252 return m_property_int_range(prop, action, arg, &opts->loop_times);
255 /// Playback speed (RW)
256 static int mp_property_playback_speed(m_option_t *prop, int action,
257 void *arg, MPContext *mpctx)
259 struct MPOpts *opts = &mpctx->opts;
260 switch (action) {
261 case M_PROPERTY_SET:
262 if (!arg)
263 return M_PROPERTY_ERROR;
264 M_PROPERTY_CLAMP(prop, *(float *) arg);
265 opts->playback_speed = *(float *) arg;
266 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
267 return M_PROPERTY_OK;
268 case M_PROPERTY_STEP_UP:
269 case M_PROPERTY_STEP_DOWN:
270 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
271 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
272 M_PROPERTY_CLAMP(prop, opts->playback_speed);
273 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
274 return M_PROPERTY_OK;
276 return m_property_float_range(prop, action, arg, &opts->playback_speed);
279 /// filename with path (RO)
280 static int mp_property_path(m_option_t *prop, int action, void *arg,
281 MPContext *mpctx)
283 return m_property_string_ro(prop, action, arg, mpctx->filename);
286 /// filename without path (RO)
287 static int mp_property_filename(m_option_t *prop, int action, void *arg,
288 MPContext *mpctx)
290 char *f;
291 if (!mpctx->filename)
292 return M_PROPERTY_UNAVAILABLE;
293 if (((f = strrchr(mpctx->filename, '/'))
294 || (f = strrchr(mpctx->filename, '\\'))) && f[1])
295 f++;
296 else
297 f = mpctx->filename;
298 return m_property_string_ro(prop, action, arg, f);
301 /// Demuxer name (RO)
302 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
303 MPContext *mpctx)
305 if (!mpctx->demuxer)
306 return M_PROPERTY_UNAVAILABLE;
307 return m_property_string_ro(prop, action, arg,
308 (char *) mpctx->demuxer->desc->name);
311 /// Position in the stream (RW)
312 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
313 MPContext *mpctx)
315 if (!mpctx->demuxer || !mpctx->demuxer->stream)
316 return M_PROPERTY_UNAVAILABLE;
317 if (!arg)
318 return M_PROPERTY_ERROR;
319 switch (action) {
320 case M_PROPERTY_GET:
321 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
322 return M_PROPERTY_OK;
323 case M_PROPERTY_SET:
324 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
325 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
326 return M_PROPERTY_OK;
328 return M_PROPERTY_NOT_IMPLEMENTED;
331 /// Stream start offset (RO)
332 static int mp_property_stream_start(m_option_t *prop, int action,
333 void *arg, MPContext *mpctx)
335 if (!mpctx->demuxer || !mpctx->demuxer->stream)
336 return M_PROPERTY_UNAVAILABLE;
337 switch (action) {
338 case M_PROPERTY_GET:
339 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
340 return M_PROPERTY_OK;
342 return M_PROPERTY_NOT_IMPLEMENTED;
345 /// Stream end offset (RO)
346 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
347 MPContext *mpctx)
349 if (!mpctx->demuxer || !mpctx->demuxer->stream)
350 return M_PROPERTY_UNAVAILABLE;
351 switch (action) {
352 case M_PROPERTY_GET:
353 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
354 return M_PROPERTY_OK;
356 return M_PROPERTY_NOT_IMPLEMENTED;
359 /// Stream length (RO)
360 static int mp_property_stream_length(m_option_t *prop, int action,
361 void *arg, MPContext *mpctx)
363 if (!mpctx->demuxer || !mpctx->demuxer->stream)
364 return M_PROPERTY_UNAVAILABLE;
365 switch (action) {
366 case M_PROPERTY_GET:
367 *(off_t *) arg =
368 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
369 return M_PROPERTY_OK;
371 return M_PROPERTY_NOT_IMPLEMENTED;
374 /// Current stream position in seconds (RO)
375 static int mp_property_stream_time_pos(m_option_t *prop, int action,
376 void *arg, MPContext *mpctx)
378 if (!mpctx->demuxer || mpctx->demuxer->stream_pts == MP_NOPTS_VALUE)
379 return M_PROPERTY_UNAVAILABLE;
381 return m_property_time_ro(prop, action, arg, mpctx->demuxer->stream_pts);
385 /// Media length in seconds (RO)
386 static int mp_property_length(m_option_t *prop, int action, void *arg,
387 MPContext *mpctx)
389 double len;
391 if (!mpctx->demuxer ||
392 !(int) (len = get_time_length(mpctx)))
393 return M_PROPERTY_UNAVAILABLE;
395 return m_property_time_ro(prop, action, arg, len);
398 /// Current position in percent (RW)
399 static int mp_property_percent_pos(m_option_t *prop, int action,
400 void *arg, MPContext *mpctx) {
401 int pos;
403 if (!mpctx->demuxer)
404 return M_PROPERTY_UNAVAILABLE;
406 switch(action) {
407 case M_PROPERTY_SET:
408 if(!arg) return M_PROPERTY_ERROR;
409 M_PROPERTY_CLAMP(prop, *(int*)arg);
410 pos = *(int*)arg;
411 break;
412 case M_PROPERTY_STEP_UP:
413 case M_PROPERTY_STEP_DOWN:
414 pos = get_percent_pos(mpctx);
415 pos += (arg ? *(int*)arg : 10) *
416 (action == M_PROPERTY_STEP_UP ? 1 : -1);
417 M_PROPERTY_CLAMP(prop, pos);
418 break;
419 default:
420 return m_property_int_ro(prop, action, arg, get_percent_pos(mpctx));
423 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
424 mpctx->rel_seek_secs = pos / 100.0;
425 return M_PROPERTY_OK;
428 /// Current position in seconds (RW)
429 static int mp_property_time_pos(m_option_t *prop, int action,
430 void *arg, MPContext *mpctx) {
431 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
432 return M_PROPERTY_UNAVAILABLE;
434 switch(action) {
435 case M_PROPERTY_SET:
436 if(!arg) return M_PROPERTY_ERROR;
437 M_PROPERTY_CLAMP(prop, *(double*)arg);
438 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
439 mpctx->rel_seek_secs = *(double*)arg;
440 return M_PROPERTY_OK;
441 case M_PROPERTY_STEP_UP:
442 case M_PROPERTY_STEP_DOWN:
443 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
444 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
445 return M_PROPERTY_OK;
447 return m_property_time_ro(prop, action, arg, get_current_time(mpctx));
450 /// Current chapter (RW)
451 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
452 MPContext *mpctx)
454 struct MPOpts *opts = &mpctx->opts;
455 int chapter = -1;
456 int step_all;
457 char *chapter_name = NULL;
459 if (mpctx->demuxer)
460 chapter = get_current_chapter(mpctx);
461 if (chapter < -1)
462 return M_PROPERTY_UNAVAILABLE;
464 switch (action) {
465 case M_PROPERTY_GET:
466 if (!arg)
467 return M_PROPERTY_ERROR;
468 *(int *) arg = chapter;
469 return M_PROPERTY_OK;
470 case M_PROPERTY_PRINT: {
471 if (!arg)
472 return M_PROPERTY_ERROR;
473 chapter_name = chapter_display_name(mpctx, chapter);
474 if (!chapter_name)
475 return M_PROPERTY_UNAVAILABLE;
476 *(char **) arg = chapter_name;
477 return M_PROPERTY_OK;
479 case M_PROPERTY_SET:
480 if (!arg)
481 return M_PROPERTY_ERROR;
482 M_PROPERTY_CLAMP(prop, *(int*)arg);
483 step_all = *(int *)arg - chapter;
484 chapter += step_all;
485 break;
486 case M_PROPERTY_STEP_UP:
487 case M_PROPERTY_STEP_DOWN: {
488 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
489 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
490 chapter += step_all;
491 if (chapter < 0)
492 chapter = 0;
493 break;
495 default:
496 return M_PROPERTY_NOT_IMPLEMENTED;
499 double next_pts = 0;
500 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
501 mpctx->rel_seek_secs = 0;
502 mpctx->abs_seek_pos = 0;
503 if (chapter >= 0) {
504 if (next_pts > -1.0) {
505 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
506 mpctx->rel_seek_secs = next_pts;
508 if (chapter_name)
509 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
510 "Chapter: (%d) %s", chapter + 1, chapter_name);
512 else if (step_all > 0)
513 mpctx->rel_seek_secs = 1000000000.;
514 else
515 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
516 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
517 talloc_free(chapter_name);
518 return M_PROPERTY_OK;
521 /// Number of chapters in file
522 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
523 MPContext *mpctx)
525 if (!mpctx->demuxer)
526 return M_PROPERTY_UNAVAILABLE;
527 if (mpctx->demuxer->num_chapters == 0)
528 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
529 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
532 /// Current dvd angle (RW)
533 static int mp_property_angle(m_option_t *prop, int action, void *arg,
534 MPContext *mpctx)
536 struct MPOpts *opts = &mpctx->opts;
537 int angle = -1;
538 int angles;
539 char *angle_name = NULL;
541 if (mpctx->demuxer)
542 angle = demuxer_get_current_angle(mpctx->demuxer);
543 if (angle < 0)
544 return M_PROPERTY_UNAVAILABLE;
545 angles = demuxer_angles_count(mpctx->demuxer);
546 if (angles <= 1)
547 return M_PROPERTY_UNAVAILABLE;
549 switch (action) {
550 case M_PROPERTY_GET:
551 if (!arg)
552 return M_PROPERTY_ERROR;
553 *(int *) arg = angle;
554 return M_PROPERTY_OK;
555 case M_PROPERTY_PRINT: {
556 if (!arg)
557 return M_PROPERTY_ERROR;
558 angle_name = calloc(1, 64);
559 if (!angle_name)
560 return M_PROPERTY_UNAVAILABLE;
561 snprintf(angle_name, 64, "%d/%d", angle, angles);
562 *(char **) arg = angle_name;
563 return M_PROPERTY_OK;
565 case M_PROPERTY_SET:
566 if (!arg)
567 return M_PROPERTY_ERROR;
568 angle = *(int *)arg;
569 M_PROPERTY_CLAMP(prop, angle);
570 break;
571 case M_PROPERTY_STEP_UP:
572 case M_PROPERTY_STEP_DOWN: {
573 int step = 0;
574 if(arg)
575 step = *(int*)arg;
576 if(!step)
577 step = 1;
578 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
579 angle += step;
580 if (angle < 1) //cycle
581 angle = angles;
582 break;
584 default:
585 return M_PROPERTY_NOT_IMPLEMENTED;
587 angle = demuxer_set_angle(mpctx->demuxer, angle);
588 if (angle >= 0) {
589 struct sh_video *sh_video = mpctx->demuxer->video->sh;
590 if (sh_video)
591 resync_video_stream(sh_video);
593 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
594 if (sh_audio)
595 resync_audio_stream(sh_audio);
598 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
599 "Angle: %d/%d", angle, angles);
600 free(angle_name);
601 return M_PROPERTY_OK;
604 /// Demuxer meta data
605 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
606 MPContext *mpctx) {
607 m_property_action_t* ka;
608 char* meta;
609 static const m_option_t key_type =
610 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
611 if (!mpctx->demuxer)
612 return M_PROPERTY_UNAVAILABLE;
614 switch(action) {
615 case M_PROPERTY_GET:
616 if(!arg) return M_PROPERTY_ERROR;
617 *(char***)arg = mpctx->demuxer->info;
618 return M_PROPERTY_OK;
619 case M_PROPERTY_KEY_ACTION:
620 if(!arg) return M_PROPERTY_ERROR;
621 ka = arg;
622 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
623 return M_PROPERTY_UNKNOWN;
624 switch(ka->action) {
625 case M_PROPERTY_GET:
626 if(!ka->arg) return M_PROPERTY_ERROR;
627 *(char**)ka->arg = meta;
628 return M_PROPERTY_OK;
629 case M_PROPERTY_GET_TYPE:
630 if(!ka->arg) return M_PROPERTY_ERROR;
631 *(const m_option_t**)ka->arg = &key_type;
632 return M_PROPERTY_OK;
635 return M_PROPERTY_NOT_IMPLEMENTED;
638 static int mp_property_pause(m_option_t *prop, int action, void *arg,
639 void *ctx)
641 MPContext *mpctx = ctx;
643 switch (action) {
644 case M_PROPERTY_SET:
645 if (!arg)
646 return M_PROPERTY_ERROR;
647 if (mpctx->paused == (bool)*(int *) arg)
648 return M_PROPERTY_OK;
649 case M_PROPERTY_STEP_UP:
650 case M_PROPERTY_STEP_DOWN:
651 if (mpctx->paused) {
652 unpause_player(mpctx);
653 mpctx->osd_function = OSD_PLAY;
655 else {
656 pause_player(mpctx);
657 mpctx->osd_function = OSD_PAUSE;
659 return M_PROPERTY_OK;
660 default:
661 return m_property_flag(prop, action, arg, &mpctx->paused);
666 ///@}
668 /// \defgroup AudioProperties Audio properties
669 /// \ingroup Properties
670 ///@{
672 /// Volume (RW)
673 static int mp_property_volume(m_option_t *prop, int action, void *arg,
674 MPContext *mpctx)
677 if (!mpctx->sh_audio)
678 return M_PROPERTY_UNAVAILABLE;
680 switch (action) {
681 case M_PROPERTY_GET:
682 if (!arg)
683 return M_PROPERTY_ERROR;
684 mixer_getbothvolume(&mpctx->mixer, arg);
685 return M_PROPERTY_OK;
686 case M_PROPERTY_PRINT:{
687 float vol;
688 if (!arg)
689 return M_PROPERTY_ERROR;
690 mixer_getbothvolume(&mpctx->mixer, &vol);
691 return m_property_float_range(prop, action, arg, &vol);
693 case M_PROPERTY_STEP_UP:
694 case M_PROPERTY_STEP_DOWN:
695 case M_PROPERTY_SET:
696 break;
697 default:
698 return M_PROPERTY_NOT_IMPLEMENTED;
701 if (mpctx->edl_muted)
702 return M_PROPERTY_DISABLED;
703 mpctx->user_muted = 0;
705 switch (action) {
706 case M_PROPERTY_SET:
707 if (!arg)
708 return M_PROPERTY_ERROR;
709 M_PROPERTY_CLAMP(prop, *(float *) arg);
710 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
711 return M_PROPERTY_OK;
712 case M_PROPERTY_STEP_UP:
713 if (arg && *(float *) arg <= 0)
714 mixer_decvolume(&mpctx->mixer);
715 else
716 mixer_incvolume(&mpctx->mixer);
717 return M_PROPERTY_OK;
718 case M_PROPERTY_STEP_DOWN:
719 if (arg && *(float *) arg <= 0)
720 mixer_incvolume(&mpctx->mixer);
721 else
722 mixer_decvolume(&mpctx->mixer);
723 return M_PROPERTY_OK;
725 return M_PROPERTY_NOT_IMPLEMENTED;
728 /// Mute (RW)
729 static int mp_property_mute(m_option_t *prop, int action, void *arg,
730 MPContext *mpctx)
733 if (!mpctx->sh_audio)
734 return M_PROPERTY_UNAVAILABLE;
736 switch (action) {
737 case M_PROPERTY_SET:
738 if (mpctx->edl_muted)
739 return M_PROPERTY_DISABLED;
740 if (!arg)
741 return M_PROPERTY_ERROR;
742 if ((!!*(int *) arg) != mpctx->mixer.muted)
743 mixer_mute(&mpctx->mixer);
744 mpctx->user_muted = mpctx->mixer.muted;
745 return M_PROPERTY_OK;
746 case M_PROPERTY_STEP_UP:
747 case M_PROPERTY_STEP_DOWN:
748 if (mpctx->edl_muted)
749 return M_PROPERTY_DISABLED;
750 mixer_mute(&mpctx->mixer);
751 mpctx->user_muted = mpctx->mixer.muted;
752 return M_PROPERTY_OK;
753 case M_PROPERTY_PRINT:
754 if (!arg)
755 return M_PROPERTY_ERROR;
756 if (mpctx->edl_muted) {
757 *(char **) arg = strdup(mp_gtext("enabled (EDL)"));
758 return M_PROPERTY_OK;
760 default:
761 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
766 /// Audio delay (RW)
767 static int mp_property_audio_delay(m_option_t *prop, int action,
768 void *arg, MPContext *mpctx)
770 if (!(mpctx->sh_audio && mpctx->sh_video))
771 return M_PROPERTY_UNAVAILABLE;
772 switch (action) {
773 case M_PROPERTY_SET:
774 case M_PROPERTY_STEP_UP:
775 case M_PROPERTY_STEP_DOWN: {
776 int ret;
777 float delay = audio_delay;
778 ret = m_property_delay(prop, action, arg, &audio_delay);
779 if (ret != M_PROPERTY_OK)
780 return ret;
781 if (mpctx->sh_audio)
782 mpctx->delay -= audio_delay - delay;
784 return M_PROPERTY_OK;
785 default:
786 return m_property_delay(prop, action, arg, &audio_delay);
790 /// Audio codec tag (RO)
791 static int mp_property_audio_format(m_option_t *prop, int action,
792 void *arg, MPContext *mpctx)
794 if (!mpctx->sh_audio)
795 return M_PROPERTY_UNAVAILABLE;
796 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
799 /// Audio codec name (RO)
800 static int mp_property_audio_codec(m_option_t *prop, int action,
801 void *arg, MPContext *mpctx)
803 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
804 return M_PROPERTY_UNAVAILABLE;
805 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
808 /// Audio bitrate (RO)
809 static int mp_property_audio_bitrate(m_option_t *prop, int action,
810 void *arg, MPContext *mpctx)
812 if (!mpctx->sh_audio)
813 return M_PROPERTY_UNAVAILABLE;
814 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
817 /// Samplerate (RO)
818 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
819 MPContext *mpctx)
821 if (!mpctx->sh_audio)
822 return M_PROPERTY_UNAVAILABLE;
823 switch(action) {
824 case M_PROPERTY_PRINT:
825 if(!arg) return M_PROPERTY_ERROR;
826 *(char**)arg = malloc(16);
827 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
828 return M_PROPERTY_OK;
830 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
833 /// Number of channels (RO)
834 static int mp_property_channels(m_option_t *prop, int action, void *arg,
835 MPContext *mpctx)
837 if (!mpctx->sh_audio)
838 return M_PROPERTY_UNAVAILABLE;
839 switch (action) {
840 case M_PROPERTY_PRINT:
841 if (!arg)
842 return M_PROPERTY_ERROR;
843 switch (mpctx->sh_audio->channels) {
844 case 1:
845 *(char **) arg = strdup("mono");
846 break;
847 case 2:
848 *(char **) arg = strdup("stereo");
849 break;
850 default:
851 *(char **) arg = malloc(32);
852 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
854 return M_PROPERTY_OK;
856 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
859 /// Balance (RW)
860 static int mp_property_balance(m_option_t *prop, int action, void *arg,
861 MPContext *mpctx)
863 float bal;
865 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
866 return M_PROPERTY_UNAVAILABLE;
868 switch (action) {
869 case M_PROPERTY_GET:
870 if (!arg)
871 return M_PROPERTY_ERROR;
872 mixer_getbalance(&mpctx->mixer, arg);
873 return M_PROPERTY_OK;
874 case M_PROPERTY_PRINT: {
875 char** str = arg;
876 if (!arg)
877 return M_PROPERTY_ERROR;
878 mixer_getbalance(&mpctx->mixer, &bal);
879 if (bal == 0.f)
880 *str = strdup("center");
881 else if (bal == -1.f)
882 *str = strdup("left only");
883 else if (bal == 1.f)
884 *str = strdup("right only");
885 else {
886 unsigned right = (bal + 1.f) / 2.f * 100.f;
887 *str = malloc(sizeof("left xxx%, right xxx%"));
888 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
890 return M_PROPERTY_OK;
892 case M_PROPERTY_STEP_UP:
893 case M_PROPERTY_STEP_DOWN:
894 mixer_getbalance(&mpctx->mixer, &bal);
895 bal += (arg ? *(float*)arg : .1f) *
896 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
897 M_PROPERTY_CLAMP(prop, bal);
898 mixer_setbalance(&mpctx->mixer, bal);
899 return M_PROPERTY_OK;
900 case M_PROPERTY_SET:
901 if (!arg)
902 return M_PROPERTY_ERROR;
903 M_PROPERTY_CLAMP(prop, *(float*)arg);
904 mixer_setbalance(&mpctx->mixer, *(float*)arg);
905 return M_PROPERTY_OK;
907 return M_PROPERTY_NOT_IMPLEMENTED;
910 /// Selected audio id (RW)
911 static int mp_property_audio(m_option_t *prop, int action, void *arg,
912 MPContext *mpctx)
914 int current_id, tmp;
915 if (!mpctx->demuxer || !mpctx->d_audio)
916 return M_PROPERTY_UNAVAILABLE;
917 current_id = mpctx->sh_audio ? mpctx->sh_audio->aid : -2;
919 switch (action) {
920 case M_PROPERTY_GET:
921 if (!arg)
922 return M_PROPERTY_ERROR;
923 *(int *) arg = current_id;
924 return M_PROPERTY_OK;
925 case M_PROPERTY_PRINT:
926 if (!arg)
927 return M_PROPERTY_ERROR;
929 if (current_id < 0)
930 *(char **) arg = strdup(mp_gtext("disabled"));
931 else {
932 char lang[40];
933 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
934 sh_audio_t* sh = mpctx->sh_audio;
935 if (sh && sh->lang)
936 av_strlcpy(lang, sh->lang, 40);
937 #ifdef CONFIG_DVDREAD
938 else if (mpctx->stream->type == STREAMTYPE_DVD) {
939 int code = dvd_lang_from_aid(mpctx->stream, current_id);
940 if (code) {
941 lang[0] = code >> 8;
942 lang[1] = code;
943 lang[2] = 0;
946 #endif
948 #ifdef CONFIG_DVDNAV
949 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
950 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
951 #endif
952 *(char **) arg = malloc(64);
953 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
955 return M_PROPERTY_OK;
957 case M_PROPERTY_STEP_UP:
958 case M_PROPERTY_SET:
959 if (action == M_PROPERTY_SET && arg)
960 tmp = *((int *) arg);
961 else
962 tmp = -1;
963 int new_id = demuxer_switch_audio(mpctx->d_audio->demuxer, tmp);
964 if (new_id != current_id)
965 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
966 if (new_id != current_id && new_id >= 0) {
967 sh_audio_t *sh2;
968 sh2 = mpctx->d_audio->demuxer->a_streams[mpctx->demuxer->audio->id];
969 sh2->ds = mpctx->demuxer->audio;
970 mpctx->sh_audio = sh2;
971 reinit_audio_chain(mpctx);
973 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
974 return M_PROPERTY_OK;
975 default:
976 return M_PROPERTY_NOT_IMPLEMENTED;
981 /// Selected video id (RW)
982 static int mp_property_video(m_option_t *prop, int action, void *arg,
983 MPContext *mpctx)
985 struct MPOpts *opts = &mpctx->opts;
986 int current_id, tmp;
987 if (!mpctx->demuxer || !mpctx->d_video)
988 return M_PROPERTY_UNAVAILABLE;
989 current_id = mpctx->d_video->id;
991 switch (action) {
992 case M_PROPERTY_GET:
993 if (!arg)
994 return M_PROPERTY_ERROR;
995 *(int *) arg = current_id;
996 return M_PROPERTY_OK;
997 case M_PROPERTY_PRINT:
998 if (!arg)
999 return M_PROPERTY_ERROR;
1001 if (current_id < 0)
1002 *(char **) arg = strdup(mp_gtext("disabled"));
1003 else {
1004 char lang[40];
1005 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
1006 *(char **) arg = malloc(64);
1007 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
1009 return M_PROPERTY_OK;
1011 case M_PROPERTY_STEP_UP:
1012 case M_PROPERTY_SET:
1013 if (action == M_PROPERTY_SET && arg)
1014 tmp = *((int *) arg);
1015 else
1016 tmp = -1;
1017 opts->video_id = demuxer_switch_video(mpctx->d_video->demuxer, tmp);
1018 if (opts->video_id == -2
1019 || (opts->video_id > -1 && mpctx->d_video->id != current_id
1020 && current_id != -2))
1021 uninit_player(mpctx, INITIALIZED_VCODEC |
1022 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
1023 if (opts->video_id > -1 && mpctx->d_video->id != current_id) {
1024 sh_video_t *sh2;
1025 sh2 = mpctx->d_video->demuxer->v_streams[mpctx->d_video->id];
1026 if (sh2) {
1027 sh2->ds = mpctx->d_video;
1028 mpctx->sh_video = sh2;
1029 reinit_video_chain(mpctx);
1032 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
1033 return M_PROPERTY_OK;
1035 default:
1036 return M_PROPERTY_NOT_IMPLEMENTED;
1040 static int mp_property_program(m_option_t *prop, int action, void *arg,
1041 MPContext *mpctx)
1043 demux_program_t prog;
1045 switch (action) {
1046 case M_PROPERTY_STEP_UP:
1047 case M_PROPERTY_SET:
1048 if (action == M_PROPERTY_SET && arg)
1049 prog.progid = *((int *) arg);
1050 else
1051 prog.progid = -1;
1052 if (demux_control
1053 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1054 &prog) == DEMUXER_CTRL_NOTIMPL)
1055 return M_PROPERTY_ERROR;
1057 if (prog.aid < 0 && prog.vid < 0) {
1058 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
1059 return M_PROPERTY_ERROR;
1061 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1062 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1063 return M_PROPERTY_OK;
1065 default:
1066 return M_PROPERTY_NOT_IMPLEMENTED;
1070 ///@}
1072 /// \defgroup VideoProperties Video properties
1073 /// \ingroup Properties
1074 ///@{
1076 /// Fullscreen state (RW)
1077 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1078 MPContext *mpctx)
1081 if (!mpctx->video_out)
1082 return M_PROPERTY_UNAVAILABLE;
1084 switch (action) {
1085 case M_PROPERTY_SET:
1086 if (!arg)
1087 return M_PROPERTY_ERROR;
1088 M_PROPERTY_CLAMP(prop, *(int *) arg);
1089 if (vo_fs == !!*(int *) arg)
1090 return M_PROPERTY_OK;
1091 case M_PROPERTY_STEP_UP:
1092 case M_PROPERTY_STEP_DOWN:
1093 if (mpctx->video_out->config_ok)
1094 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1095 mpctx->opts.fullscreen = vo_fs;
1096 return M_PROPERTY_OK;
1097 default:
1098 return m_property_flag(prop, action, arg, &vo_fs);
1102 static int mp_property_deinterlace(m_option_t *prop, int action,
1103 void *arg, MPContext *mpctx)
1105 int deinterlace;
1106 vf_instance_t *vf;
1107 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1108 return M_PROPERTY_UNAVAILABLE;
1109 vf = mpctx->sh_video->vfilter;
1110 switch (action) {
1111 case M_PROPERTY_GET:
1112 if (!arg)
1113 return M_PROPERTY_ERROR;
1114 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1115 return M_PROPERTY_OK;
1116 case M_PROPERTY_SET:
1117 if (!arg)
1118 return M_PROPERTY_ERROR;
1119 M_PROPERTY_CLAMP(prop, *(int *) arg);
1120 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1121 return M_PROPERTY_OK;
1122 case M_PROPERTY_STEP_UP:
1123 case M_PROPERTY_STEP_DOWN:
1124 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1125 deinterlace = !deinterlace;
1126 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1127 return M_PROPERTY_OK;
1129 int value = 0;
1130 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1131 return m_property_flag_ro(prop, action, arg, value);
1134 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1135 void *arg, MPContext *mpctx)
1137 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1138 return M_PROPERTY_UNAVAILABLE;
1140 struct vf_instance *vf = mpctx->sh_video->vfilter;
1141 int colorspace;
1142 switch (action) {
1143 case M_PROPERTY_GET:
1144 if (!arg)
1145 return M_PROPERTY_ERROR;
1146 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1147 return M_PROPERTY_UNAVAILABLE;
1148 return M_PROPERTY_OK;
1149 case M_PROPERTY_PRINT:
1150 if (!arg)
1151 return M_PROPERTY_ERROR;
1152 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1153 return M_PROPERTY_UNAVAILABLE;
1154 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1155 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1156 *(char **)arg = strdup("Unknown");
1157 else
1158 *(char**)arg = strdup(names[colorspace]);
1159 return M_PROPERTY_OK;
1160 case M_PROPERTY_SET:
1161 if (!arg)
1162 return M_PROPERTY_ERROR;
1163 M_PROPERTY_CLAMP(prop, *(int *) arg);
1164 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1165 return M_PROPERTY_OK;
1166 case M_PROPERTY_STEP_UP:;
1167 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1168 return M_PROPERTY_UNAVAILABLE;
1169 colorspace += 1;
1170 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1171 return M_PROPERTY_OK;
1173 return M_PROPERTY_NOT_IMPLEMENTED;
1176 static int mp_property_capture(m_option_t *prop, int action,
1177 void *arg, MPContext *mpctx)
1179 struct MPOpts *opts = &mpctx->opts;
1181 if (!mpctx->stream)
1182 return M_PROPERTY_UNAVAILABLE;
1184 if (!opts->capture_dump) {
1185 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1186 "Capturing not enabled (forgot -capture parameter?)\n");
1187 return M_PROPERTY_ERROR;
1190 int capturing = !!mpctx->stream->capture_file;
1192 int ret = m_property_flag(prop, action, arg, &capturing);
1193 if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
1194 if (capturing) {
1195 mpctx->stream->capture_file = fopen(opts->stream_dump_name, "wb");
1196 if (!mpctx->stream->capture_file) {
1197 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1198 "Error opening capture file: %s\n", strerror(errno));
1199 ret = M_PROPERTY_ERROR;
1201 } else {
1202 fclose(mpctx->stream->capture_file);
1203 mpctx->stream->capture_file = NULL;
1207 return ret;
1210 /// Panscan (RW)
1211 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1212 MPContext *mpctx)
1215 if (!mpctx->video_out
1216 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1217 return M_PROPERTY_UNAVAILABLE;
1219 switch (action) {
1220 case M_PROPERTY_SET:
1221 if (!arg)
1222 return M_PROPERTY_ERROR;
1223 M_PROPERTY_CLAMP(prop, *(float *) arg);
1224 vo_panscan = *(float *) arg;
1225 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1226 return M_PROPERTY_OK;
1227 case M_PROPERTY_STEP_UP:
1228 case M_PROPERTY_STEP_DOWN:
1229 vo_panscan += (arg ? *(float *) arg : 0.1) *
1230 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1231 if (vo_panscan > 1)
1232 vo_panscan = 1;
1233 else if (vo_panscan < 0)
1234 vo_panscan = 0;
1235 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1236 return M_PROPERTY_OK;
1237 default:
1238 return m_property_float_range(prop, action, arg, &vo_panscan);
1242 /// Helper to set vo flags.
1243 /** \ingroup PropertyImplHelper
1245 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1246 int vo_ctrl, int *vo_var, MPContext *mpctx)
1249 if (!mpctx->video_out)
1250 return M_PROPERTY_UNAVAILABLE;
1252 switch (action) {
1253 case M_PROPERTY_SET:
1254 if (!arg)
1255 return M_PROPERTY_ERROR;
1256 M_PROPERTY_CLAMP(prop, *(int *) arg);
1257 if (*vo_var == !!*(int *) arg)
1258 return M_PROPERTY_OK;
1259 case M_PROPERTY_STEP_UP:
1260 case M_PROPERTY_STEP_DOWN:
1261 if (mpctx->video_out->config_ok)
1262 vo_control(mpctx->video_out, vo_ctrl, 0);
1263 return M_PROPERTY_OK;
1264 default:
1265 return m_property_flag(prop, action, arg, vo_var);
1269 /// Window always on top (RW)
1270 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1271 MPContext *mpctx)
1273 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1274 &mpctx->opts.vo_ontop, mpctx);
1277 /// Display in the root window (RW)
1278 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1279 MPContext *mpctx)
1281 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1282 &vo_rootwin, mpctx);
1285 /// Show window borders (RW)
1286 static int mp_property_border(m_option_t *prop, int action, void *arg,
1287 MPContext *mpctx)
1289 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1290 &vo_border, mpctx);
1293 /// Framedropping state (RW)
1294 static int mp_property_framedropping(m_option_t *prop, int action,
1295 void *arg, MPContext *mpctx)
1298 if (!mpctx->sh_video)
1299 return M_PROPERTY_UNAVAILABLE;
1301 switch (action) {
1302 case M_PROPERTY_PRINT:
1303 if (!arg)
1304 return M_PROPERTY_ERROR;
1305 *(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
1306 (frame_dropping == 2 ? mp_gtext("hard") :
1307 mp_gtext("disabled")));
1308 return M_PROPERTY_OK;
1309 default:
1310 return m_property_choice(prop, action, arg, &frame_dropping);
1314 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1315 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1316 MPContext *mpctx)
1318 int *gamma = (int *)((char *)&mpctx->opts + prop->offset);
1319 int r, val;
1321 if (!mpctx->sh_video)
1322 return M_PROPERTY_UNAVAILABLE;
1324 if (gamma[0] == 1000) {
1325 gamma[0] = 0;
1326 get_video_colors(mpctx->sh_video, prop->name, gamma);
1329 switch (action) {
1330 case M_PROPERTY_SET:
1331 if (!arg)
1332 return M_PROPERTY_ERROR;
1333 M_PROPERTY_CLAMP(prop, *(int *) arg);
1334 *gamma = *(int *) arg;
1335 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1336 if (r <= 0)
1337 break;
1338 return r;
1339 case M_PROPERTY_GET:
1340 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1341 if (!arg)
1342 return M_PROPERTY_ERROR;
1343 *(int *)arg = val;
1344 return M_PROPERTY_OK;
1346 break;
1347 case M_PROPERTY_STEP_UP:
1348 case M_PROPERTY_STEP_DOWN:
1349 *gamma += (arg ? *(int *) arg : 1) *
1350 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1351 M_PROPERTY_CLAMP(prop, *gamma);
1352 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1353 if (r <= 0)
1354 break;
1355 return r;
1356 default:
1357 return M_PROPERTY_NOT_IMPLEMENTED;
1360 #ifdef CONFIG_TV
1361 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1362 int l = strlen(prop->name);
1363 char tv_prop[3 + l + 1];
1364 sprintf(tv_prop, "tv_%s", prop->name);
1365 return mp_property_do(tv_prop, action, arg, mpctx);
1367 #endif
1369 return M_PROPERTY_UNAVAILABLE;
1372 /// VSync (RW)
1373 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1374 MPContext *mpctx)
1376 return m_property_flag(prop, action, arg, &vo_vsync);
1379 /// Video codec tag (RO)
1380 static int mp_property_video_format(m_option_t *prop, int action,
1381 void *arg, MPContext *mpctx)
1383 char* meta;
1384 if (!mpctx->sh_video)
1385 return M_PROPERTY_UNAVAILABLE;
1386 switch(action) {
1387 case M_PROPERTY_PRINT:
1388 if (!arg)
1389 return M_PROPERTY_ERROR;
1390 switch(mpctx->sh_video->format) {
1391 case 0x10000001:
1392 meta = strdup ("mpeg1"); break;
1393 case 0x10000002:
1394 meta = strdup ("mpeg2"); break;
1395 case 0x10000004:
1396 meta = strdup ("mpeg4"); break;
1397 case 0x10000005:
1398 meta = strdup ("h264"); break;
1399 default:
1400 if(mpctx->sh_video->format >= 0x20202020) {
1401 meta = malloc(5);
1402 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1403 } else {
1404 meta = malloc(20);
1405 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1408 *(char**)arg = meta;
1409 return M_PROPERTY_OK;
1411 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1414 /// Video codec name (RO)
1415 static int mp_property_video_codec(m_option_t *prop, int action,
1416 void *arg, MPContext *mpctx)
1418 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1419 return M_PROPERTY_UNAVAILABLE;
1420 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1424 /// Video bitrate (RO)
1425 static int mp_property_video_bitrate(m_option_t *prop, int action,
1426 void *arg, MPContext *mpctx)
1428 if (!mpctx->sh_video)
1429 return M_PROPERTY_UNAVAILABLE;
1430 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1433 /// Video display width (RO)
1434 static int mp_property_width(m_option_t *prop, int action, void *arg,
1435 MPContext *mpctx)
1437 if (!mpctx->sh_video)
1438 return M_PROPERTY_UNAVAILABLE;
1439 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1442 /// Video display height (RO)
1443 static int mp_property_height(m_option_t *prop, int action, void *arg,
1444 MPContext *mpctx)
1446 if (!mpctx->sh_video)
1447 return M_PROPERTY_UNAVAILABLE;
1448 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1451 /// Video fps (RO)
1452 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1453 MPContext *mpctx)
1455 if (!mpctx->sh_video)
1456 return M_PROPERTY_UNAVAILABLE;
1457 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1460 /// Video aspect (RO)
1461 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1462 MPContext *mpctx)
1464 if (!mpctx->sh_video)
1465 return M_PROPERTY_UNAVAILABLE;
1466 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1469 ///@}
1471 /// \defgroup SubProprties Subtitles properties
1472 /// \ingroup Properties
1473 ///@{
1475 /// Text subtitle position (RW)
1476 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1477 MPContext *mpctx)
1479 switch (action) {
1480 case M_PROPERTY_SET:
1481 if (!arg)
1482 return M_PROPERTY_ERROR;
1483 case M_PROPERTY_STEP_UP:
1484 case M_PROPERTY_STEP_DOWN:
1485 vo_osd_changed(OSDTYPE_SUBTITLE);
1486 default:
1487 return m_property_int_range(prop, action, arg, &sub_pos);
1491 /// Selected subtitles (RW)
1492 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1493 MPContext *mpctx)
1495 struct MPOpts *opts = &mpctx->opts;
1496 demux_stream_t *const d_sub = mpctx->d_sub;
1497 int source = -1, reset_spu = 0;
1498 int source_pos = -1;
1499 char *sub_name;
1501 update_global_sub_size(mpctx);
1502 const int global_sub_size = mpctx->global_sub_size;
1504 if (global_sub_size <= 0)
1505 return M_PROPERTY_UNAVAILABLE;
1507 switch (action) {
1508 case M_PROPERTY_GET:
1509 if (!arg)
1510 return M_PROPERTY_ERROR;
1511 *(int *) arg = mpctx->global_sub_pos;
1512 return M_PROPERTY_OK;
1513 case M_PROPERTY_PRINT:
1514 if (!arg)
1515 return M_PROPERTY_ERROR;
1516 *(char **) arg = malloc(64);
1517 (*(char **) arg)[63] = 0;
1518 sub_name = 0;
1519 if (subdata)
1520 sub_name = subdata->filename;
1521 #ifdef CONFIG_ASS
1522 if (ass_track && ass_track->name)
1523 sub_name = ass_track->name;
1524 #endif
1525 if (sub_name) {
1526 char *tmp, *tmp2;
1527 tmp = sub_name;
1528 if ((tmp2 = strrchr(tmp, '/')))
1529 tmp = tmp2 + 1;
1531 snprintf(*(char **) arg, 63, "(%d) %s%s",
1532 mpctx->set_of_sub_pos + 1,
1533 strlen(tmp) < 20 ? "" : "...",
1534 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1535 return M_PROPERTY_OK;
1537 #ifdef CONFIG_DVDNAV
1538 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1539 if (vo_spudec && opts->sub_id >= 0) {
1540 unsigned char lang[3];
1541 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1542 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1543 return M_PROPERTY_OK;
1547 #endif
1549 if ((d_sub->demuxer->type == DEMUXER_TYPE_MATROSKA
1550 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF
1551 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1552 || d_sub->demuxer->type == DEMUXER_TYPE_OGG)
1553 && d_sub->sh && opts->sub_id >= 0) {
1554 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1555 if (!lang) lang = mp_gtext("unknown");
1556 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1557 return M_PROPERTY_OK;
1560 if (vo_vobsub && vobsub_id >= 0) {
1561 const char *language = mp_gtext("unknown");
1562 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1563 snprintf(*(char **) arg, 63, "(%d) %s",
1564 vobsub_id, language ? language : mp_gtext("unknown"));
1565 return M_PROPERTY_OK;
1567 #ifdef CONFIG_DVDREAD
1568 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1569 && opts->sub_id >= 0) {
1570 char lang[3];
1571 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1572 lang[0] = code >> 8;
1573 lang[1] = code;
1574 lang[2] = 0;
1575 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1576 return M_PROPERTY_OK;
1578 #endif
1579 if (opts->sub_id >= 0) {
1580 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
1581 mp_gtext("unknown"));
1582 return M_PROPERTY_OK;
1584 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1585 return M_PROPERTY_OK;
1587 case M_PROPERTY_SET:
1588 if (!arg)
1589 return M_PROPERTY_ERROR;
1590 if (*(int *) arg < -1)
1591 *(int *) arg = -1;
1592 else if (*(int *) arg >= global_sub_size)
1593 *(int *) arg = global_sub_size - 1;
1594 mpctx->global_sub_pos = *(int *) arg;
1595 break;
1596 case M_PROPERTY_STEP_UP:
1597 mpctx->global_sub_pos += 2;
1598 mpctx->global_sub_pos =
1599 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1600 break;
1601 case M_PROPERTY_STEP_DOWN:
1602 mpctx->global_sub_pos += global_sub_size + 1;
1603 mpctx->global_sub_pos =
1604 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1605 break;
1606 default:
1607 return M_PROPERTY_NOT_IMPLEMENTED;
1610 if (mpctx->global_sub_pos >= 0) {
1611 source = sub_source(mpctx);
1612 source_pos = sub_source_pos(mpctx);
1615 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1616 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1617 global_sub_size,
1618 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1619 mpctx->sub_counts[SUB_SOURCE_SUBS],
1620 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1621 mpctx->global_sub_pos, source);
1623 mpctx->set_of_sub_pos = -1;
1624 subdata = NULL;
1626 vobsub_id = -1;
1627 opts->sub_id = -1;
1628 if (d_sub) {
1629 if (d_sub->id > -2)
1630 reset_spu = 1;
1631 d_sub->id = -2;
1633 #ifdef CONFIG_ASS
1634 ass_track = 0;
1635 #endif
1637 if (source == SUB_SOURCE_VOBSUB) {
1638 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1639 } else if (source == SUB_SOURCE_SUBS) {
1640 mpctx->set_of_sub_pos = source_pos;
1641 #ifdef CONFIG_ASS
1642 if (opts->ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1643 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1644 else
1645 #endif
1647 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1648 vo_osd_changed(OSDTYPE_SUBTITLE);
1650 } else if (source == SUB_SOURCE_DEMUX) {
1651 opts->sub_id = source_pos;
1652 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1653 int i = 0;
1654 // default: assume 1:1 mapping of sid and stream id
1655 d_sub->id = opts->sub_id;
1656 d_sub->sh = mpctx->d_sub->demuxer->s_streams[d_sub->id];
1657 ds_free_packs(d_sub);
1658 for (i = 0; i < MAX_S_STREAMS; i++) {
1659 sh_sub_t *sh = mpctx->d_sub->demuxer->s_streams[i];
1660 if (sh && sh->sid == opts->sub_id) {
1661 d_sub->id = i;
1662 d_sub->sh = sh;
1663 break;
1666 if (d_sub->sh && d_sub->id >= 0) {
1667 sh_sub_t *sh = d_sub->sh;
1668 if (sh->type == 'v')
1669 init_vo_spudec(mpctx);
1670 #ifdef CONFIG_ASS
1671 else if (opts->ass_enabled)
1672 ass_track = sh->ass_track;
1673 #endif
1674 } else {
1675 d_sub->id = -2;
1676 d_sub->sh = NULL;
1680 #ifdef CONFIG_DVDREAD
1681 if (vo_spudec
1682 && (mpctx->stream->type == STREAMTYPE_DVD
1683 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1684 && opts->sub_id < 0 && reset_spu) {
1685 d_sub->id = -2;
1686 d_sub->sh = NULL;
1688 #endif
1690 update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, 0, 0, d_sub, 1);
1692 return M_PROPERTY_OK;
1695 /// Selected sub source (RW)
1696 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1697 MPContext *mpctx)
1699 int source;
1700 update_global_sub_size(mpctx);
1701 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1702 return M_PROPERTY_UNAVAILABLE;
1704 switch (action) {
1705 case M_PROPERTY_GET:
1706 if (!arg)
1707 return M_PROPERTY_ERROR;
1708 *(int *) arg = sub_source(mpctx);
1709 return M_PROPERTY_OK;
1710 case M_PROPERTY_PRINT:
1711 if (!arg)
1712 return M_PROPERTY_ERROR;
1713 *(char **) arg = malloc(64);
1714 (*(char **) arg)[63] = 0;
1715 switch (sub_source(mpctx))
1717 case SUB_SOURCE_SUBS:
1718 snprintf(*(char **) arg, 63, mp_gtext("file"));
1719 break;
1720 case SUB_SOURCE_VOBSUB:
1721 snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
1722 break;
1723 case SUB_SOURCE_DEMUX:
1724 snprintf(*(char **) arg, 63, mp_gtext("embedded"));
1725 break;
1726 default:
1727 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1729 return M_PROPERTY_OK;
1730 case M_PROPERTY_SET:
1731 if (!arg)
1732 return M_PROPERTY_ERROR;
1733 M_PROPERTY_CLAMP(prop, *(int*)arg);
1734 if (*(int *) arg < 0)
1735 mpctx->global_sub_pos = -1;
1736 else if (*(int *) arg != sub_source(mpctx)) {
1737 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1738 if (new_pos == -1)
1739 return M_PROPERTY_UNAVAILABLE;
1740 mpctx->global_sub_pos = new_pos;
1742 break;
1743 case M_PROPERTY_STEP_UP:
1744 case M_PROPERTY_STEP_DOWN: {
1745 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1746 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1747 int step = (step_all > 0) ? 1 : -1;
1748 int cur_source = sub_source(mpctx);
1749 source = cur_source;
1750 while (step_all) {
1751 source += step;
1752 if (source >= SUB_SOURCES)
1753 source = -1;
1754 else if (source < -1)
1755 source = SUB_SOURCES - 1;
1756 if (source == cur_source || source == -1 ||
1757 mpctx->sub_counts[source])
1758 step_all -= step;
1760 if (source == cur_source)
1761 return M_PROPERTY_OK;
1762 if (source == -1)
1763 mpctx->global_sub_pos = -1;
1764 else
1765 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1766 break;
1768 default:
1769 return M_PROPERTY_NOT_IMPLEMENTED;
1771 --mpctx->global_sub_pos;
1772 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1775 /// Selected subtitles from specific source (RW)
1776 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1777 MPContext *mpctx)
1779 int source, is_cur_source, offset, new_pos;
1780 update_global_sub_size(mpctx);
1781 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1782 return M_PROPERTY_UNAVAILABLE;
1784 if (!strcmp(prop->name, "sub_file"))
1785 source = SUB_SOURCE_SUBS;
1786 else if (!strcmp(prop->name, "sub_vob"))
1787 source = SUB_SOURCE_VOBSUB;
1788 else if (!strcmp(prop->name, "sub_demux"))
1789 source = SUB_SOURCE_DEMUX;
1790 else
1791 return M_PROPERTY_ERROR;
1793 offset = sub_pos_by_source(mpctx, source);
1794 if (offset < 0)
1795 return M_PROPERTY_UNAVAILABLE;
1797 is_cur_source = sub_source(mpctx) == source;
1798 new_pos = mpctx->global_sub_pos;
1799 switch (action) {
1800 case M_PROPERTY_GET:
1801 if (!arg)
1802 return M_PROPERTY_ERROR;
1803 if (is_cur_source) {
1804 *(int *) arg = sub_source_pos(mpctx);
1805 if (source == SUB_SOURCE_VOBSUB)
1806 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1808 else
1809 *(int *) arg = -1;
1810 return M_PROPERTY_OK;
1811 case M_PROPERTY_PRINT:
1812 if (!arg)
1813 return M_PROPERTY_ERROR;
1814 if (is_cur_source)
1815 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1816 *(char **) arg = malloc(64);
1817 (*(char **) arg)[63] = 0;
1818 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1819 return M_PROPERTY_OK;
1820 case M_PROPERTY_SET:
1821 if (!arg)
1822 return M_PROPERTY_ERROR;
1823 if (*(int *) arg >= 0) {
1824 int index = *(int *)arg;
1825 if (source == SUB_SOURCE_VOBSUB)
1826 index = vobsub_get_index_by_id(vo_vobsub, index);
1827 new_pos = offset + index;
1828 if (index < 0 || index > mpctx->sub_counts[source]) {
1829 new_pos = -1;
1830 *(int *) arg = -1;
1833 else
1834 new_pos = -1;
1835 break;
1836 case M_PROPERTY_STEP_UP:
1837 case M_PROPERTY_STEP_DOWN: {
1838 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1839 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1840 int step = (step_all > 0) ? 1 : -1;
1841 int max_sub_pos_for_source = -1;
1842 if (!is_cur_source)
1843 new_pos = -1;
1844 while (step_all) {
1845 if (new_pos == -1) {
1846 if (step > 0)
1847 new_pos = offset;
1848 else if (max_sub_pos_for_source == -1) {
1849 // Find max pos for specific source
1850 new_pos = mpctx->global_sub_size - 1;
1851 while (new_pos >= 0
1852 && sub_source(mpctx) != source)
1853 new_pos--;
1855 else
1856 new_pos = max_sub_pos_for_source;
1858 else {
1859 new_pos += step;
1860 if (new_pos < offset ||
1861 new_pos >= mpctx->global_sub_size ||
1862 sub_source(mpctx) != source)
1863 new_pos = -1;
1865 step_all -= step;
1867 break;
1869 default:
1870 return M_PROPERTY_NOT_IMPLEMENTED;
1872 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1875 /// Subtitle delay (RW)
1876 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1877 MPContext *mpctx)
1879 if (!mpctx->sh_video)
1880 return M_PROPERTY_UNAVAILABLE;
1881 return m_property_delay(prop, action, arg, &sub_delay);
1884 /// Alignment of text subtitles (RW)
1885 static int mp_property_sub_alignment(m_option_t *prop, int action,
1886 void *arg, MPContext *mpctx)
1888 char *name[] = { _("top"), _("center"), _("bottom") };
1890 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1891 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1892 return M_PROPERTY_UNAVAILABLE;
1894 switch (action) {
1895 case M_PROPERTY_PRINT:
1896 if (!arg)
1897 return M_PROPERTY_ERROR;
1898 M_PROPERTY_CLAMP(prop, sub_alignment);
1899 *(char **) arg = strdup(mp_gtext(name[sub_alignment]));
1900 return M_PROPERTY_OK;
1901 case M_PROPERTY_SET:
1902 if (!arg)
1903 return M_PROPERTY_ERROR;
1904 case M_PROPERTY_STEP_UP:
1905 case M_PROPERTY_STEP_DOWN:
1906 vo_osd_changed(OSDTYPE_SUBTITLE);
1907 default:
1908 return m_property_choice(prop, action, arg, &sub_alignment);
1912 /// Subtitle visibility (RW)
1913 static int mp_property_sub_visibility(m_option_t *prop, int action,
1914 void *arg, MPContext *mpctx)
1916 if (!mpctx->sh_video)
1917 return M_PROPERTY_UNAVAILABLE;
1919 switch (action) {
1920 case M_PROPERTY_SET:
1921 if (!arg)
1922 return M_PROPERTY_ERROR;
1923 case M_PROPERTY_STEP_UP:
1924 case M_PROPERTY_STEP_DOWN:
1925 vo_osd_changed(OSDTYPE_SUBTITLE);
1926 if (vo_spudec)
1927 vo_osd_changed(OSDTYPE_SPU);
1928 default:
1929 return m_property_flag(prop, action, arg, &sub_visibility);
1933 #ifdef CONFIG_ASS
1934 /// Use margins for libass subtitles (RW)
1935 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1936 void *arg, MPContext *mpctx)
1938 if (!mpctx->sh_video)
1939 return M_PROPERTY_UNAVAILABLE;
1941 switch (action) {
1942 case M_PROPERTY_SET:
1943 if (!arg)
1944 return M_PROPERTY_ERROR;
1945 case M_PROPERTY_STEP_UP:
1946 case M_PROPERTY_STEP_DOWN:
1947 ass_force_reload = 1;
1948 default:
1949 return m_property_flag(prop, action, arg, &ass_use_margins);
1952 #endif
1954 /// Show only forced subtitles (RW)
1955 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1956 void *arg, MPContext *mpctx)
1958 if (!vo_spudec)
1959 return M_PROPERTY_UNAVAILABLE;
1961 switch (action) {
1962 case M_PROPERTY_SET:
1963 if (!arg)
1964 return M_PROPERTY_ERROR;
1965 case M_PROPERTY_STEP_UP:
1966 case M_PROPERTY_STEP_DOWN:
1967 m_property_flag(prop, action, arg, &forced_subs_only);
1968 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1969 return M_PROPERTY_OK;
1970 default:
1971 return m_property_flag(prop, action, arg, &forced_subs_only);
1976 #ifdef CONFIG_FREETYPE
1977 /// Subtitle scale (RW)
1978 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1979 MPContext *mpctx)
1981 struct MPOpts *opts = &mpctx->opts;
1983 switch (action) {
1984 case M_PROPERTY_SET:
1985 if (!arg)
1986 return M_PROPERTY_ERROR;
1987 M_PROPERTY_CLAMP(prop, *(float *) arg);
1988 #ifdef CONFIG_ASS
1989 if (opts->ass_enabled) {
1990 ass_font_scale = *(float *) arg;
1991 ass_force_reload = 1;
1993 #endif
1994 text_font_scale_factor = *(float *) arg;
1995 force_load_font = 1;
1996 return M_PROPERTY_OK;
1997 case M_PROPERTY_STEP_UP:
1998 case M_PROPERTY_STEP_DOWN:
1999 #ifdef CONFIG_ASS
2000 if (opts->ass_enabled) {
2001 ass_font_scale += (arg ? *(float *) arg : 0.1)*
2002 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2003 M_PROPERTY_CLAMP(prop, ass_font_scale);
2004 ass_force_reload = 1;
2006 #endif
2007 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
2008 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2009 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
2010 force_load_font = 1;
2011 return M_PROPERTY_OK;
2012 default:
2013 #ifdef CONFIG_ASS
2014 if (opts->ass_enabled)
2015 return m_property_float_ro(prop, action, arg, ass_font_scale);
2016 else
2017 #endif
2018 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
2021 #endif
2023 ///@}
2025 /// \defgroup TVProperties TV properties
2026 /// \ingroup Properties
2027 ///@{
2029 #ifdef CONFIG_TV
2031 /// TV color settings (RW)
2032 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2033 MPContext *mpctx)
2035 int r, val;
2036 tvi_handle_t *tvh = mpctx->demuxer->priv;
2037 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2038 return M_PROPERTY_UNAVAILABLE;
2040 switch (action) {
2041 case M_PROPERTY_SET:
2042 if (!arg)
2043 return M_PROPERTY_ERROR;
2044 M_PROPERTY_CLAMP(prop, *(int *) arg);
2045 return tv_set_color_options(tvh, prop->offset, *(int *) arg);
2046 case M_PROPERTY_GET:
2047 return tv_get_color_options(tvh, prop->offset, arg);
2048 case M_PROPERTY_STEP_UP:
2049 case M_PROPERTY_STEP_DOWN:
2050 if ((r = tv_get_color_options(tvh, prop->offset, &val)) >= 0) {
2051 if (!r)
2052 return M_PROPERTY_ERROR;
2053 val += (arg ? *(int *) arg : 1) *
2054 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2055 M_PROPERTY_CLAMP(prop, val);
2056 return tv_set_color_options(tvh, prop->offset, val);
2058 return M_PROPERTY_ERROR;
2060 return M_PROPERTY_NOT_IMPLEMENTED;
2063 #endif
2065 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2066 MPContext *mpctx)
2068 int val,result;
2069 int base_ioctl = prop->offset;
2071 for teletext's GET,SET,STEP ioctls this is not 0
2072 SET is GET+1
2073 STEP is GET+2
2075 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2076 return M_PROPERTY_UNAVAILABLE;
2077 if(!base_ioctl)
2078 return M_PROPERTY_ERROR;
2080 switch (action) {
2081 case M_PROPERTY_GET:
2082 if (!arg)
2083 return M_PROPERTY_ERROR;
2084 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2085 break;
2086 case M_PROPERTY_SET:
2087 if (!arg)
2088 return M_PROPERTY_ERROR;
2089 M_PROPERTY_CLAMP(prop, *(int *) arg);
2090 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
2091 break;
2092 case M_PROPERTY_STEP_UP:
2093 case M_PROPERTY_STEP_DOWN:
2094 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2095 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2096 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
2097 break;
2098 default:
2099 return M_PROPERTY_NOT_IMPLEMENTED;
2102 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2105 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2106 MPContext *mpctx)
2108 int result;
2109 int val;
2111 //with tvh==NULL will fail too
2112 result=mp_property_teletext_common(prop,action,arg,mpctx);
2113 if(result!=M_PROPERTY_OK)
2114 return result;
2116 if(teletext_control(mpctx->demuxer->teletext,
2117 prop->offset, &val)==VBI_CONTROL_TRUE && val)
2118 mp_input_set_section(mpctx->input, "teletext");
2119 else
2120 mp_input_set_section(mpctx->input, "tv");
2121 return M_PROPERTY_OK;
2124 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2125 MPContext *mpctx)
2127 int result;
2128 int val;
2129 if (!mpctx->demuxer->teletext)
2130 return M_PROPERTY_UNAVAILABLE;
2131 switch(action){
2132 case M_PROPERTY_STEP_UP:
2133 case M_PROPERTY_STEP_DOWN:
2134 //This should be handled separately
2135 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2136 result=teletext_control(mpctx->demuxer->teletext,
2137 TV_VBI_CONTROL_STEP_PAGE, &val);
2138 break;
2139 default:
2140 result=mp_property_teletext_common(prop,action,arg,mpctx);
2142 return result;
2145 ///@}
2147 /// All properties available in MPlayer.
2148 /** \ingroup Properties
2150 static const m_option_t mp_properties[] = {
2151 // General
2152 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2153 M_OPT_RANGE, 0, 3, NULL },
2154 { "loop", mp_property_loop, CONF_TYPE_INT,
2155 M_OPT_MIN, -1, 0, NULL },
2156 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2157 M_OPT_RANGE, 0.01, 100.0, NULL },
2158 { "filename", mp_property_filename, CONF_TYPE_STRING,
2159 0, 0, 0, NULL },
2160 { "path", mp_property_path, CONF_TYPE_STRING,
2161 0, 0, 0, NULL },
2162 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2163 0, 0, 0, NULL },
2164 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2165 M_OPT_MIN, 0, 0, NULL },
2166 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2167 M_OPT_MIN, 0, 0, NULL },
2168 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2169 M_OPT_MIN, 0, 0, NULL },
2170 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2171 M_OPT_MIN, 0, 0, NULL },
2172 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2173 M_OPT_MIN, 0, 0, NULL },
2174 { "length", mp_property_length, CONF_TYPE_TIME,
2175 M_OPT_MIN, 0, 0, NULL },
2176 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2177 M_OPT_RANGE, 0, 100, NULL },
2178 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2179 M_OPT_MIN, 0, 0, NULL },
2180 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2181 M_OPT_MIN, 0, 0, NULL },
2182 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2183 0, 0, 0, NULL },
2184 { "angle", mp_property_angle, CONF_TYPE_INT,
2185 CONF_RANGE, -2, 10, NULL },
2186 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2187 0, 0, 0, NULL },
2188 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2189 M_OPT_RANGE, 0, 1, NULL },
2190 { "capturing", mp_property_capture, CONF_TYPE_FLAG,
2191 M_OPT_RANGE, 0, 1, NULL },
2193 // Audio
2194 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2195 M_OPT_RANGE, 0, 100, NULL },
2196 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2197 M_OPT_RANGE, 0, 1, NULL },
2198 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2199 M_OPT_RANGE, -100, 100, NULL },
2200 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2201 0, 0, 0, NULL },
2202 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2203 0, 0, 0, NULL },
2204 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2205 0, 0, 0, NULL },
2206 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2207 0, 0, 0, NULL },
2208 { "channels", mp_property_channels, CONF_TYPE_INT,
2209 0, 0, 0, NULL },
2210 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2211 CONF_RANGE, -2, 65535, NULL },
2212 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2213 M_OPT_RANGE, -1, 1, NULL },
2215 // Video
2216 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2217 M_OPT_RANGE, 0, 1, NULL },
2218 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2219 M_OPT_RANGE, 0, 1, NULL },
2220 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2221 M_OPT_RANGE, 0, 2, NULL },
2222 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2223 M_OPT_RANGE, 0, 1, NULL },
2224 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2225 M_OPT_RANGE, 0, 1, NULL },
2226 { "border", mp_property_border, CONF_TYPE_FLAG,
2227 M_OPT_RANGE, 0, 1, NULL },
2228 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2229 M_OPT_RANGE, 0, 2, NULL },
2230 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2231 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_gamma)},
2232 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2233 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_brightness) },
2234 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2235 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_contrast) },
2236 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2237 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_saturation) },
2238 { "hue", mp_property_gamma, CONF_TYPE_INT,
2239 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_hue) },
2240 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2241 M_OPT_RANGE, 0, 1, NULL },
2242 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2243 M_OPT_RANGE, 0, 1, NULL },
2244 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2245 0, 0, 0, NULL },
2246 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2247 0, 0, 0, NULL },
2248 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2249 0, 0, 0, NULL },
2250 { "width", mp_property_width, CONF_TYPE_INT,
2251 0, 0, 0, NULL },
2252 { "height", mp_property_height, CONF_TYPE_INT,
2253 0, 0, 0, NULL },
2254 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2255 0, 0, 0, NULL },
2256 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2257 0, 0, 0, NULL },
2258 { "switch_video", mp_property_video, CONF_TYPE_INT,
2259 CONF_RANGE, -2, 65535, NULL },
2260 { "switch_program", mp_property_program, CONF_TYPE_INT,
2261 CONF_RANGE, -1, 65535, NULL },
2263 // Subs
2264 { "sub", mp_property_sub, CONF_TYPE_INT,
2265 M_OPT_MIN, -1, 0, NULL },
2266 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2267 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2268 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2269 M_OPT_MIN, -1, 0, NULL },
2270 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2271 M_OPT_MIN, -1, 0, NULL },
2272 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2273 M_OPT_MIN, -1, 0, NULL },
2274 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2275 0, 0, 0, NULL },
2276 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2277 M_OPT_RANGE, 0, 100, NULL },
2278 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2279 M_OPT_RANGE, 0, 2, NULL },
2280 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2281 M_OPT_RANGE, 0, 1, NULL },
2282 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2283 M_OPT_RANGE, 0, 1, NULL },
2284 #ifdef CONFIG_FREETYPE
2285 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2286 M_OPT_RANGE, 0, 100, NULL },
2287 #endif
2288 #ifdef CONFIG_ASS
2289 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2290 M_OPT_RANGE, 0, 1, NULL },
2291 #endif
2293 #ifdef CONFIG_TV
2294 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2295 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_BRIGHTNESS },
2296 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2297 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_CONTRAST },
2298 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2299 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_SATURATION },
2300 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2301 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_HUE },
2302 #endif
2303 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2304 M_OPT_RANGE, 100, 899, .offset=TV_VBI_CONTROL_GET_PAGE },
2305 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2306 M_OPT_RANGE, 0, 64, .offset=TV_VBI_CONTROL_GET_SUBPAGE },
2307 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2308 M_OPT_RANGE, 0, 1, .offset=TV_VBI_CONTROL_GET_MODE },
2309 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2310 M_OPT_RANGE, 0, 3, .offset=TV_VBI_CONTROL_GET_FORMAT },
2311 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2312 M_OPT_RANGE, 0, 2, .offset=TV_VBI_CONTROL_GET_HALF_PAGE },
2313 { NULL, NULL, NULL, 0, 0, 0, NULL }
2317 int mp_property_do(const char *name, int action, void *val, void *ctx)
2319 return m_property_do(mp_properties, name, action, val, ctx);
2322 char* mp_property_print(const char *name, void* ctx)
2324 char* ret = NULL;
2325 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2326 return NULL;
2327 return ret;
2330 char *property_expand_string(MPContext *mpctx, char *str)
2332 return m_properties_expand_string(mp_properties, str, mpctx);
2335 void property_print_help(void)
2337 m_properties_print_help_list(mp_properties);
2341 /* List of default ways to show a property on OSD.
2343 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2344 * a bar showing the current position between min/max values of the
2345 * property. In this case osd_msg is only used for terminal output
2346 * if there is no video; it'll be a label shown together with percentage.
2348 * Otherwise setting osd_msg will show the string on OSD, formatted with
2349 * the text value of the property as argument.
2351 static struct property_osd_display {
2352 /// property name
2353 const char *name;
2354 /// progressbar type
2355 int osd_progbar; // -1 is special value for seek indicators
2356 /// osd msg id if it must be shared
2357 int osd_id;
2358 /// osd msg template
2359 const char *osd_msg;
2360 } property_osd_display[] = {
2361 // general
2362 { "loop", 0, -1, _("Loop: %s") },
2363 { "chapter", -1, -1, NULL },
2364 { "capturing", 0, -1, _("Capturing: %s") },
2365 // audio
2366 { "volume", OSD_VOLUME, -1, _("Volume") },
2367 { "mute", 0, -1, _("Mute: %s") },
2368 { "audio_delay", 0, -1, _("A-V delay: %s") },
2369 { "switch_audio", 0, -1, _("Audio: %s") },
2370 { "balance", OSD_BALANCE, -1, _("Balance") },
2371 // video
2372 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2373 { "ontop", 0, -1, _("Stay on top: %s") },
2374 { "rootwin", 0, -1, _("Rootwin: %s") },
2375 { "border", 0, -1, _("Border: %s") },
2376 { "framedropping", 0, -1, _("Framedropping: %s") },
2377 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2378 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2379 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2380 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2381 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2382 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2383 { "hue", OSD_HUE, -1, _("Hue") },
2384 { "vsync", 0, -1, _("VSync: %s") },
2385 // subs
2386 { "sub", 0, -1, _("Subtitles: %s") },
2387 { "sub_source", 0, -1, _("Sub source: %s") },
2388 { "sub_vob", 0, -1, _("Subtitles: %s") },
2389 { "sub_demux", 0, -1, _("Subtitles: %s") },
2390 { "sub_file", 0, -1, _("Subtitles: %s") },
2391 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2392 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2393 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2394 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2395 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2396 #ifdef CONFIG_FREETYPE
2397 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2398 #endif
2399 #ifdef CONFIG_TV
2400 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2401 { "tv_hue", OSD_HUE, -1, _("Hue") },
2402 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2403 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2404 #endif
2408 static int show_property_osd(MPContext *mpctx, const char *pname)
2410 struct MPOpts *opts = &mpctx->opts;
2411 int r;
2412 m_option_t* prop;
2413 struct property_osd_display *p;
2415 // look for the command
2416 for (p = property_osd_display; p->name; p++)
2417 if (!strcmp(p->name, pname))
2418 break;
2419 if (!p->name)
2420 return -1;
2422 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2423 return -1;
2425 if (p->osd_progbar == -1)
2426 mpctx->add_osd_seek_info = true;
2427 else if (p->osd_progbar) {
2428 if (prop->type == CONF_TYPE_INT) {
2429 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2430 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2431 prop->min, prop->max, r);
2432 } else if (prop->type == CONF_TYPE_FLOAT) {
2433 float f;
2434 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2435 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2436 prop->min, prop->max, f);
2437 } else {
2438 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2439 "Property use an unsupported type.\n");
2440 return -1;
2442 return 0;
2445 if (p->osd_msg) {
2446 char *val = mp_property_print(pname, mpctx);
2447 if (val) {
2448 int index = p - property_osd_display;
2449 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2450 1, opts->osd_duration, p->osd_msg, val);
2451 free(val);
2454 return 0;
2459 * \defgroup Command2Property Command to property bridge
2461 * It is used to handle most commands that just set a property
2462 * and optionally display something on the OSD.
2463 * Two kinds of commands are handled: adjust or toggle.
2465 * Adjust commands take 1 or 2 parameters: <value> <abs>
2466 * If <abs> is non-zero the property is set to the given value
2467 * otherwise it is adjusted.
2469 * Toggle commands take 0 or 1 parameters. With no parameter
2470 * or a value less than the property minimum it just steps the
2471 * property to its next value. Otherwise it sets it to the given
2472 * value.
2477 /// List of the commands that can be handled by setting a property.
2478 static struct {
2479 /// property name
2480 const char *name;
2481 /// cmd id
2482 int cmd;
2483 /// set/adjust or toggle command
2484 int toggle;
2485 } set_prop_cmd[] = {
2486 // general
2487 { "loop", MP_CMD_LOOP, 0},
2488 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2489 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2490 { "pause", MP_CMD_PAUSE, 0},
2491 { "capturing", MP_CMD_CAPTURING, 1},
2492 // audio
2493 { "volume", MP_CMD_VOLUME, 0},
2494 { "mute", MP_CMD_MUTE, 1},
2495 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2496 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2497 { "balance", MP_CMD_BALANCE, 0},
2498 // video
2499 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2500 { "panscan", MP_CMD_PANSCAN, 0},
2501 { "ontop", MP_CMD_VO_ONTOP, 1},
2502 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2503 { "border", MP_CMD_VO_BORDER, 1},
2504 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2505 { "gamma", MP_CMD_GAMMA, 0},
2506 { "brightness", MP_CMD_BRIGHTNESS, 0},
2507 { "contrast", MP_CMD_CONTRAST, 0},
2508 { "saturation", MP_CMD_SATURATION, 0},
2509 { "hue", MP_CMD_HUE, 0},
2510 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2511 // subs
2512 { "sub", MP_CMD_SUB_SELECT, 1},
2513 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2514 { "sub_vob", MP_CMD_SUB_VOB, 1},
2515 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2516 { "sub_file", MP_CMD_SUB_FILE, 1},
2517 { "sub_pos", MP_CMD_SUB_POS, 0},
2518 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2519 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2520 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2521 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2522 #ifdef CONFIG_FREETYPE
2523 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2524 #endif
2525 #ifdef CONFIG_ASS
2526 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2527 #endif
2528 #ifdef CONFIG_TV
2529 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2530 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2531 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2532 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2533 #endif
2537 /// Handle commands that set a property.
2538 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2540 int i, r;
2541 m_option_t *prop;
2542 const char *pname;
2544 // look for the command
2545 for (i = 0; set_prop_cmd[i].name; i++)
2546 if (set_prop_cmd[i].cmd == cmd->id)
2547 break;
2548 if (!(pname = set_prop_cmd[i].name))
2549 return 0;
2551 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2552 return 0;
2554 // toggle command
2555 if (set_prop_cmd[i].toggle) {
2556 // set to value
2557 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2558 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2559 else
2560 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2561 } else if (cmd->args[1].v.i) //set
2562 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2563 else // adjust
2564 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2566 if (r <= 0)
2567 return 1;
2569 show_property_osd(mpctx, pname);
2571 return 1;
2574 #ifdef CONFIG_DVDNAV
2575 static const struct {
2576 const char *name;
2577 const mp_command_type cmd;
2578 } mp_dvdnav_bindings[] = {
2579 { "up", MP_CMD_DVDNAV_UP },
2580 { "down", MP_CMD_DVDNAV_DOWN },
2581 { "left", MP_CMD_DVDNAV_LEFT },
2582 { "right", MP_CMD_DVDNAV_RIGHT },
2583 { "menu", MP_CMD_DVDNAV_MENU },
2584 { "select", MP_CMD_DVDNAV_SELECT },
2585 { "prev", MP_CMD_DVDNAV_PREVMENU },
2586 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2589 * keep old dvdnav sub-command options for a while in order not to
2590 * break slave-mode API too suddenly.
2592 { "1", MP_CMD_DVDNAV_UP },
2593 { "2", MP_CMD_DVDNAV_DOWN },
2594 { "3", MP_CMD_DVDNAV_LEFT },
2595 { "4", MP_CMD_DVDNAV_RIGHT },
2596 { "5", MP_CMD_DVDNAV_MENU },
2597 { "6", MP_CMD_DVDNAV_SELECT },
2598 { "7", MP_CMD_DVDNAV_PREVMENU },
2599 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2600 { NULL, 0 }
2602 #endif
2604 static const char *property_error_string(int error_value)
2606 switch (error_value) {
2607 case M_PROPERTY_ERROR:
2608 return "ERROR";
2609 case M_PROPERTY_UNAVAILABLE:
2610 return "PROPERTY_UNAVAILABLE";
2611 case M_PROPERTY_NOT_IMPLEMENTED:
2612 return "NOT_IMPLEMENTED";
2613 case M_PROPERTY_UNKNOWN:
2614 return "PROPERTY_UNKNOWN";
2615 case M_PROPERTY_DISABLED:
2616 return "DISABLED";
2618 return "UNKNOWN";
2621 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2623 int idx;
2624 int end = start + count;
2625 int after = mpctx->set_of_sub_size - end;
2626 sub_data **subs = mpctx->set_of_subtitles;
2627 #ifdef CONFIG_ASS
2628 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2629 #endif
2630 if (count < 0 || count > mpctx->set_of_sub_size ||
2631 start < 0 || start > mpctx->set_of_sub_size - count) {
2632 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2633 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2634 return;
2636 for (idx = start; idx < end; idx++) {
2637 sub_data *subd = subs[idx];
2638 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2639 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2640 filename_recode(subd->filename));
2641 sub_free(subd);
2642 subs[idx] = NULL;
2643 #ifdef CONFIG_ASS
2644 if (ass_tracks[idx])
2645 ass_free_track(ass_tracks[idx]);
2646 ass_tracks[idx] = NULL;
2647 #endif
2650 mpctx->global_sub_size -= count;
2651 mpctx->set_of_sub_size -= count;
2652 if (mpctx->set_of_sub_size <= 0)
2653 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2655 memmove(subs + start, subs + end, after * sizeof(*subs));
2656 memset(subs + start + after, 0, count * sizeof(*subs));
2657 #ifdef CONFIG_ASS
2658 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2659 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2660 #endif
2662 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2663 mpctx->global_sub_pos = -2;
2664 subdata = NULL;
2665 #ifdef CONFIG_ASS
2666 ass_track = NULL;
2667 #endif
2668 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2669 } else if (mpctx->set_of_sub_pos >= end) {
2670 mpctx->set_of_sub_pos -= count;
2671 mpctx->global_sub_pos -= count;
2675 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2677 struct MPOpts *opts = &mpctx->opts;
2678 sh_audio_t * const sh_audio = mpctx->sh_audio;
2679 sh_video_t * const sh_video = mpctx->sh_video;
2680 int osd_duration = opts->osd_duration;
2681 int case_fallthrough_hack = 0;
2682 if (!set_property_command(mpctx, cmd))
2683 switch (cmd->id) {
2684 case MP_CMD_SEEK:{
2685 float v;
2686 int abs;
2687 mpctx->add_osd_seek_info = true;
2688 v = cmd->args[0].v.f;
2689 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2690 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2691 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2692 if (sh_video)
2693 mpctx->osd_function =
2694 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2695 mpctx->rel_seek_secs = v;
2696 } else if (abs) { /* Absolute seek by percentage */
2697 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2698 if (sh_video)
2699 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2700 mpctx->rel_seek_secs = v / 100.0;
2701 } else {
2702 mpctx->rel_seek_secs += v;
2703 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2706 break;
2708 case MP_CMD_SET_PROPERTY_OSD:
2709 case_fallthrough_hack = 1;
2711 case MP_CMD_SET_PROPERTY:{
2712 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2713 cmd->args[1].v.s, mpctx);
2714 if (r == M_PROPERTY_UNKNOWN)
2715 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2716 "Unknown property: '%s'\n", cmd->args[0].v.s);
2717 else if (r <= 0)
2718 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2719 "Failed to set property '%s' to '%s'.\n",
2720 cmd->args[0].v.s, cmd->args[1].v.s);
2721 else if (case_fallthrough_hack)
2722 show_property_osd(mpctx, cmd->args[0].v.s);
2723 if (r <= 0)
2724 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2726 break;
2728 case MP_CMD_STEP_PROPERTY_OSD:
2729 case_fallthrough_hack = 1;
2731 case MP_CMD_STEP_PROPERTY:{
2732 void* arg = NULL;
2733 int r,i;
2734 double d;
2735 off_t o;
2736 if (cmd->args[1].v.f) {
2737 m_option_t* prop;
2738 if((r = mp_property_do(cmd->args[0].v.s,
2739 M_PROPERTY_GET_TYPE,
2740 &prop, mpctx)) <= 0)
2741 goto step_prop_err;
2742 if(prop->type == CONF_TYPE_INT ||
2743 prop->type == CONF_TYPE_FLAG)
2744 i = cmd->args[1].v.f, arg = &i;
2745 else if(prop->type == CONF_TYPE_FLOAT)
2746 arg = &cmd->args[1].v.f;
2747 else if(prop->type == CONF_TYPE_DOUBLE ||
2748 prop->type == CONF_TYPE_TIME)
2749 d = cmd->args[1].v.f, arg = &d;
2750 else if(prop->type == CONF_TYPE_POSITION)
2751 o = cmd->args[1].v.f, arg = &o;
2752 else
2753 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2754 "Ignoring step size stepping property '%s'.\n",
2755 cmd->args[0].v.s);
2757 r = mp_property_do(cmd->args[0].v.s,
2758 cmd->args[2].v.i < 0 ?
2759 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2760 arg, mpctx);
2761 step_prop_err:
2762 if (r == M_PROPERTY_UNKNOWN)
2763 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2764 "Unknown property: '%s'\n", cmd->args[0].v.s);
2765 else if (r <= 0)
2766 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2767 "Failed to increment property '%s' by %f.\n",
2768 cmd->args[0].v.s, cmd->args[1].v.f);
2769 else if (case_fallthrough_hack)
2770 show_property_osd(mpctx, cmd->args[0].v.s);
2771 if (r <= 0)
2772 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2774 break;
2776 case MP_CMD_GET_PROPERTY:{
2777 char *tmp;
2778 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2779 &tmp, mpctx);
2780 if (r <= 0) {
2781 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2782 "Failed to get value of property '%s'.\n",
2783 cmd->args[0].v.s);
2784 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2785 break;
2787 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2788 cmd->args[0].v.s, tmp);
2789 free(tmp);
2791 break;
2793 case MP_CMD_EDL_MARK:
2794 if (edl_fd) {
2795 float v = get_current_time(mpctx);
2796 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2797 mpctx->begin_skip = v;
2798 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2799 } else {
2800 if (mpctx->begin_skip > v)
2801 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2802 else {
2803 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2804 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2806 mpctx->begin_skip = MP_NOPTS_VALUE;
2809 break;
2811 case MP_CMD_SWITCH_RATIO:
2812 if (!sh_video)
2813 break;
2814 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2815 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2816 else
2817 opts->movie_aspect = cmd->args[0].v.f;
2818 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2819 break;
2821 case MP_CMD_SPEED_INCR:{
2822 float v = cmd->args[0].v.f;
2823 opts->playback_speed += v;
2824 build_afilter_chain(mpctx, sh_audio, &ao_data);
2825 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2826 opts->playback_speed);
2827 } break;
2829 case MP_CMD_SPEED_MULT:{
2830 float v = cmd->args[0].v.f;
2831 opts->playback_speed *= v;
2832 build_afilter_chain(mpctx, sh_audio, &ao_data);
2833 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2834 opts->playback_speed);
2835 } break;
2837 case MP_CMD_SPEED_SET:{
2838 float v = cmd->args[0].v.f;
2839 opts->playback_speed = v;
2840 build_afilter_chain(mpctx, sh_audio, &ao_data);
2841 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2842 opts->playback_speed);
2843 } break;
2845 case MP_CMD_FRAME_STEP:
2846 add_step_frame(mpctx);
2847 break;
2849 case MP_CMD_FILE_FILTER:
2850 file_filter = cmd->args[0].v.i;
2851 break;
2853 case MP_CMD_QUIT:
2854 exit_player_with_rc(mpctx, EXIT_QUIT,
2855 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2857 case MP_CMD_PLAY_TREE_STEP:{
2858 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2859 int force = cmd->args[1].v.i;
2862 if (!force && mpctx->playtree_iter) {
2863 play_tree_iter_t *i =
2864 play_tree_iter_new_copy(mpctx->playtree_iter);
2865 if (play_tree_iter_step(i, n, 0) ==
2866 PLAY_TREE_ITER_ENTRY)
2867 mpctx->stop_play =
2868 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2869 play_tree_iter_free(i);
2870 } else
2871 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2872 if (mpctx->stop_play)
2873 mpctx->play_tree_step = n;
2876 break;
2878 case MP_CMD_PLAY_TREE_UP_STEP:{
2879 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2880 int force = cmd->args[1].v.i;
2882 if (!force && mpctx->playtree_iter) {
2883 play_tree_iter_t *i =
2884 play_tree_iter_new_copy(mpctx->playtree_iter);
2885 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2886 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2887 play_tree_iter_free(i);
2888 } else
2889 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2891 break;
2893 case MP_CMD_PLAY_ALT_SRC_STEP:
2894 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2895 int v = cmd->args[0].v.i;
2896 if (v > 0
2897 && mpctx->playtree_iter->file <
2898 mpctx->playtree_iter->num_files)
2899 mpctx->stop_play = PT_NEXT_SRC;
2900 else if (v < 0 && mpctx->playtree_iter->file > 1)
2901 mpctx->stop_play = PT_PREV_SRC;
2903 break;
2905 case MP_CMD_SUB_STEP:
2906 if (sh_video) {
2907 int movement = cmd->args[0].v.i;
2908 step_sub(subdata, sh_video->pts, movement);
2909 #ifdef CONFIG_ASS
2910 if (ass_track)
2911 sub_delay +=
2912 ass_step_sub(ass_track,
2913 (sh_video->pts +
2914 sub_delay) * 1000 + .5, movement) / 1000.;
2915 #endif
2916 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2917 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2919 break;
2921 case MP_CMD_SUB_LOG:
2922 log_sub(mpctx);
2923 break;
2925 case MP_CMD_OSD:{
2926 int v = cmd->args[0].v.i;
2927 int max = (opts->term_osd
2928 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2929 if (opts->osd_level > max)
2930 opts->osd_level = max;
2931 if (v < 0)
2932 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2933 else
2934 opts->osd_level = v > max ? max : v;
2935 /* Show OSD state when disabled, but not when an explicit
2936 argument is given to the OSD command, i.e. in slave mode. */
2937 if (v == -1 && opts->osd_level <= 1)
2938 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2939 "OSD: %s",
2940 opts->osd_level ? mp_gtext("enabled") :
2941 mp_gtext("disabled"));
2942 else
2943 rm_osd_msg(OSD_MSG_OSD_STATUS);
2945 break;
2947 case MP_CMD_OSD_SHOW_TEXT:
2948 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2949 (cmd->args[1].v.i <
2950 0 ? osd_duration : cmd->args[1].v.i),
2951 "%-.63s", cmd->args[0].v.s);
2952 break;
2954 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2955 char *txt = m_properties_expand_string(mp_properties,
2956 cmd->args[0].v.s,
2957 mpctx);
2958 /* if no argument supplied take default osd_duration, else <arg> ms. */
2959 if (txt) {
2960 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2961 (cmd->args[1].v.i <
2962 0 ? osd_duration : cmd->args[1].v.i),
2963 "%-.63s", txt);
2964 free(txt);
2967 break;
2969 case MP_CMD_LOADFILE:{
2970 play_tree_t *e = play_tree_new();
2971 play_tree_add_file(e, cmd->args[0].v.s);
2973 if (cmd->args[1].v.i) // append
2974 play_tree_append_entry(mpctx->playtree->child, e);
2975 else {
2976 // Go back to the starting point.
2977 while (play_tree_iter_up_step
2978 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2979 /* NOP */ ;
2980 play_tree_free_list(mpctx->playtree->child, 1);
2981 play_tree_set_child(mpctx->playtree, e);
2982 pt_iter_goto_head(mpctx->playtree_iter);
2983 mpctx->stop_play = PT_NEXT_SRC;
2986 break;
2988 case MP_CMD_LOADLIST:{
2989 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2990 if (!e)
2991 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2992 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2993 else {
2994 if (cmd->args[1].v.i) // append
2995 play_tree_append_entry(mpctx->playtree->child, e);
2996 else {
2997 // Go back to the starting point.
2998 while (play_tree_iter_up_step
2999 (mpctx->playtree_iter, 0, 1)
3000 != PLAY_TREE_ITER_END)
3001 /* NOP */ ;
3002 play_tree_free_list(mpctx->playtree->child, 1);
3003 play_tree_set_child(mpctx->playtree, e);
3004 pt_iter_goto_head(mpctx->playtree_iter);
3005 mpctx->stop_play = PT_NEXT_SRC;
3009 break;
3011 case MP_CMD_STOP:
3012 // Go back to the starting point.
3013 while (play_tree_iter_up_step
3014 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3015 /* NOP */ ;
3016 mpctx->stop_play = PT_STOP;
3017 break;
3019 case MP_CMD_OSD_SHOW_PROGRESSION:{
3020 int len = get_time_length(mpctx);
3021 int pts = get_current_time(mpctx);
3022 set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3023 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3024 "%c %02d:%02d:%02d / %02d:%02d:%02d",
3025 mpctx->osd_function, pts/3600, (pts/60)%60, pts%60,
3026 len/3600, (len/60)%60, len%60);
3028 break;
3030 #ifdef CONFIG_RADIO
3031 case MP_CMD_RADIO_STEP_CHANNEL:
3032 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3033 int v = cmd->args[0].v.i;
3034 if (v > 0)
3035 radio_step_channel(mpctx->demuxer->stream,
3036 RADIO_CHANNEL_HIGHER);
3037 else
3038 radio_step_channel(mpctx->demuxer->stream,
3039 RADIO_CHANNEL_LOWER);
3040 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3041 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3042 "Channel: %s",
3043 radio_get_channel_name(mpctx->demuxer->stream));
3046 break;
3048 case MP_CMD_RADIO_SET_CHANNEL:
3049 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3050 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3051 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3052 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3053 "Channel: %s",
3054 radio_get_channel_name(mpctx->demuxer->stream));
3057 break;
3059 case MP_CMD_RADIO_SET_FREQ:
3060 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3061 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3062 break;
3064 case MP_CMD_RADIO_STEP_FREQ:
3065 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3066 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3067 break;
3068 #endif
3070 #ifdef CONFIG_TV
3071 case MP_CMD_TV_START_SCAN:
3072 if (mpctx->file_format == DEMUXER_TYPE_TV)
3073 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
3074 break;
3075 case MP_CMD_TV_SET_FREQ:
3076 if (mpctx->file_format == DEMUXER_TYPE_TV)
3077 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3078 cmd->args[0].v.f * 16.0);
3079 #ifdef CONFIG_PVR
3080 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3081 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
3082 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3083 pvr_get_current_channelname (mpctx->stream),
3084 pvr_get_current_stationname (mpctx->stream));
3086 #endif /* CONFIG_PVR */
3087 break;
3089 case MP_CMD_TV_STEP_FREQ:
3090 if (mpctx->file_format == DEMUXER_TYPE_TV)
3091 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3092 cmd->args[0].v.f * 16.0);
3093 #ifdef CONFIG_PVR
3094 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3095 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
3096 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3097 pvr_get_current_channelname (mpctx->stream),
3098 pvr_get_current_frequency (mpctx->stream));
3100 #endif /* CONFIG_PVR */
3101 break;
3103 case MP_CMD_TV_SET_NORM:
3104 if (mpctx->file_format == DEMUXER_TYPE_TV)
3105 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3106 cmd->args[0].v.s);
3107 break;
3109 case MP_CMD_TV_STEP_CHANNEL:{
3110 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3111 int v = cmd->args[0].v.i;
3112 if (v > 0) {
3113 tv_step_channel((tvi_handle_t *) (mpctx->
3114 demuxer->priv),
3115 TV_CHANNEL_HIGHER);
3116 } else {
3117 tv_step_channel((tvi_handle_t *) (mpctx->
3118 demuxer->priv),
3119 TV_CHANNEL_LOWER);
3121 if (tv_channel_list) {
3122 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3123 "Channel: %s", tv_channel_current->name);
3124 //vo_osd_changed(OSDTYPE_SUBTITLE);
3127 #ifdef CONFIG_PVR
3128 else if (mpctx->stream &&
3129 mpctx->stream->type == STREAMTYPE_PVR) {
3130 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3131 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3132 pvr_get_current_channelname (mpctx->stream),
3133 pvr_get_current_stationname (mpctx->stream));
3135 #endif /* CONFIG_PVR */
3137 #ifdef CONFIG_DVBIN
3138 if (mpctx->stream->type == STREAMTYPE_DVB) {
3139 int dir;
3140 int v = cmd->args[0].v.i;
3142 mpctx->last_dvb_step = v;
3143 if (v > 0)
3144 dir = DVB_CHANNEL_HIGHER;
3145 else
3146 dir = DVB_CHANNEL_LOWER;
3149 if (dvb_step_channel(mpctx->stream, dir)) {
3150 mpctx->stop_play = PT_NEXT_ENTRY;
3151 mpctx->dvbin_reopen = 1;
3154 #endif /* CONFIG_DVBIN */
3155 break;
3157 case MP_CMD_TV_SET_CHANNEL:
3158 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3159 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3160 cmd->args[0].v.s);
3161 if (tv_channel_list) {
3162 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3163 "Channel: %s", tv_channel_current->name);
3164 //vo_osd_changed(OSDTYPE_SUBTITLE);
3167 #ifdef CONFIG_PVR
3168 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3169 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3170 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3171 pvr_get_current_channelname (mpctx->stream),
3172 pvr_get_current_stationname (mpctx->stream));
3174 #endif /* CONFIG_PVR */
3175 break;
3177 #ifdef CONFIG_DVBIN
3178 case MP_CMD_DVB_SET_CHANNEL:
3179 if (mpctx->stream->type == STREAMTYPE_DVB) {
3180 mpctx->last_dvb_step = 1;
3182 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3183 cmd->args[0].v.i)) {
3184 mpctx->stop_play = PT_NEXT_ENTRY;
3185 mpctx->dvbin_reopen = 1;
3188 break;
3189 #endif /* CONFIG_DVBIN */
3191 case MP_CMD_TV_LAST_CHANNEL:
3192 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3193 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3194 if (tv_channel_list) {
3195 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3196 "Channel: %s", tv_channel_current->name);
3197 //vo_osd_changed(OSDTYPE_SUBTITLE);
3200 #ifdef CONFIG_PVR
3201 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3202 pvr_set_lastchannel (mpctx->stream);
3203 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3204 pvr_get_current_channelname (mpctx->stream),
3205 pvr_get_current_stationname (mpctx->stream));
3207 #endif /* CONFIG_PVR */
3208 break;
3210 case MP_CMD_TV_STEP_NORM:
3211 if (mpctx->file_format == DEMUXER_TYPE_TV)
3212 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3213 break;
3215 case MP_CMD_TV_STEP_CHANNEL_LIST:
3216 if (mpctx->file_format == DEMUXER_TYPE_TV)
3217 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3218 break;
3219 #endif /* CONFIG_TV */
3220 case MP_CMD_TV_TELETEXT_ADD_DEC:
3221 if (mpctx->demuxer->teletext)
3222 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3223 &(cmd->args[0].v.s));
3224 break;
3225 case MP_CMD_TV_TELETEXT_GO_LINK:
3226 if (mpctx->demuxer->teletext)
3227 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3228 &(cmd->args[0].v.i));
3229 break;
3231 case MP_CMD_SUB_LOAD:
3232 if (sh_video) {
3233 int n = mpctx->set_of_sub_size;
3234 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3235 if (n != mpctx->set_of_sub_size) {
3236 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3237 ++mpctx->global_sub_size;
3240 break;
3242 case MP_CMD_SUB_REMOVE:
3243 if (sh_video) {
3244 int v = cmd->args[0].v.i;
3245 if (v < 0) {
3246 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3247 } else if (v < mpctx->set_of_sub_size) {
3248 remove_subtitle_range(mpctx, v, 1);
3251 break;
3253 case MP_CMD_GET_SUB_VISIBILITY:
3254 if (sh_video) {
3255 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3256 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3258 break;
3260 case MP_CMD_SCREENSHOT:
3261 if (mpctx->video_out && mpctx->video_out->config_ok) {
3262 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3263 if (CONTROL_OK !=
3264 ((vf_instance_t *) sh_video->vfilter)->
3265 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3266 &cmd->args[0].v.i))
3267 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3269 break;
3271 case MP_CMD_VF_CHANGE_RECTANGLE:
3272 if (!sh_video)
3273 break;
3274 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3275 break;
3277 case MP_CMD_GET_TIME_LENGTH:{
3278 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3279 get_time_length(mpctx));
3281 break;
3283 case MP_CMD_GET_FILENAME:{
3284 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3285 get_metadata(mpctx, META_NAME));
3287 break;
3289 case MP_CMD_GET_VIDEO_CODEC:{
3290 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3291 if (!inf)
3292 inf = strdup("");
3293 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3294 free(inf);
3296 break;
3298 case MP_CMD_GET_VIDEO_BITRATE:{
3299 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3300 if (!inf)
3301 inf = strdup("");
3302 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3303 free(inf);
3305 break;
3307 case MP_CMD_GET_VIDEO_RESOLUTION:{
3308 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3309 if (!inf)
3310 inf = strdup("");
3311 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3312 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3313 free(inf);
3315 break;
3317 case MP_CMD_GET_AUDIO_CODEC:{
3318 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3319 if (!inf)
3320 inf = strdup("");
3321 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3322 free(inf);
3324 break;
3326 case MP_CMD_GET_AUDIO_BITRATE:{
3327 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3328 if (!inf)
3329 inf = strdup("");
3330 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3331 free(inf);
3333 break;
3335 case MP_CMD_GET_AUDIO_SAMPLES:{
3336 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3337 if (!inf)
3338 inf = strdup("");
3339 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3340 free(inf);
3342 break;
3344 case MP_CMD_GET_META_TITLE:{
3345 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3346 if (!inf)
3347 inf = strdup("");
3348 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3349 free(inf);
3351 break;
3353 case MP_CMD_GET_META_ARTIST:{
3354 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3355 if (!inf)
3356 inf = strdup("");
3357 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3358 free(inf);
3360 break;
3362 case MP_CMD_GET_META_ALBUM:{
3363 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3364 if (!inf)
3365 inf = strdup("");
3366 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3367 free(inf);
3369 break;
3371 case MP_CMD_GET_META_YEAR:{
3372 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3373 if (!inf)
3374 inf = strdup("");
3375 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3376 free(inf);
3378 break;
3380 case MP_CMD_GET_META_COMMENT:{
3381 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3382 if (!inf)
3383 inf = strdup("");
3384 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3385 free(inf);
3387 break;
3389 case MP_CMD_GET_META_TRACK:{
3390 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3391 if (!inf)
3392 inf = strdup("");
3393 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3394 free(inf);
3396 break;
3398 case MP_CMD_GET_META_GENRE:{
3399 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3400 if (!inf)
3401 inf = strdup("");
3402 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3403 free(inf);
3405 break;
3407 case MP_CMD_GET_VO_FULLSCREEN:
3408 if (mpctx->video_out && mpctx->video_out->config_ok)
3409 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3410 break;
3412 case MP_CMD_GET_PERCENT_POS:
3413 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3414 get_percent_pos(mpctx));
3415 break;
3417 case MP_CMD_GET_TIME_POS:{
3418 float pos = get_current_time(mpctx);
3419 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3421 break;
3423 case MP_CMD_RUN:
3424 #ifndef __MINGW32__
3425 if (!fork()) {
3426 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3427 exit(0);
3429 #endif
3430 break;
3432 case MP_CMD_KEYDOWN_EVENTS:
3433 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3434 break;
3436 case MP_CMD_SET_MOUSE_POS:{
3437 int pointer_x, pointer_y;
3438 double dx, dy;
3439 pointer_x = cmd->args[0].v.i;
3440 pointer_y = cmd->args[1].v.i;
3441 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3442 #ifdef CONFIG_DVDNAV
3443 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3444 && dx > 0.0 && dy > 0.0) {
3445 int button = -1;
3446 pointer_x = (int) (dx * (double) sh_video->disp_w);
3447 pointer_y = (int) (dy * (double) sh_video->disp_h);
3448 mp_dvdnav_update_mouse_pos(mpctx->stream,
3449 pointer_x, pointer_y, &button);
3450 if (opts->osd_level > 1 && button > 0)
3451 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3452 "Selected button number %d", button);
3454 #endif
3455 #ifdef CONFIG_MENU
3456 if (use_menu && dx >= 0.0 && dy >= 0.0)
3457 menu_update_mouse_pos(dx, dy);
3458 #endif
3460 break;
3462 #ifdef CONFIG_DVDNAV
3463 case MP_CMD_DVDNAV:{
3464 int button = -1;
3465 int i;
3466 mp_command_type command = 0;
3467 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3468 break;
3470 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3471 if (cmd->args[0].v.s &&
3472 !strcasecmp (cmd->args[0].v.s,
3473 mp_dvdnav_bindings[i].name))
3474 command = mp_dvdnav_bindings[i].cmd;
3476 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3477 if (opts->osd_level > 1 && button > 0)
3478 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3479 "Selected button number %d", button);
3481 break;
3483 case MP_CMD_SWITCH_TITLE:
3484 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3485 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3486 break;
3488 #endif
3490 case MP_CMD_AF_SWITCH:
3491 if (sh_audio)
3493 af_uninit(mpctx->mixer.afilter);
3494 af_init(mpctx->mixer.afilter);
3496 case MP_CMD_AF_ADD:
3497 case MP_CMD_AF_DEL:
3498 if (!sh_audio)
3499 break;
3501 char* af_args = strdup(cmd->args[0].v.s);
3502 char* af_commands = af_args;
3503 char* af_command;
3504 af_instance_t* af;
3505 while ((af_command = strsep(&af_commands, ",")) != NULL)
3507 if (cmd->id == MP_CMD_AF_DEL)
3509 af = af_get(mpctx->mixer.afilter, af_command);
3510 if (af != NULL)
3511 af_remove(mpctx->mixer.afilter, af);
3513 else
3514 af_add(mpctx->mixer.afilter, af_command);
3516 build_afilter_chain(mpctx, sh_audio, &ao_data);
3517 free(af_args);
3519 break;
3520 case MP_CMD_AF_CLR:
3521 if (!sh_audio)
3522 break;
3523 af_uninit(mpctx->mixer.afilter);
3524 af_init(mpctx->mixer.afilter);
3525 build_afilter_chain(mpctx, sh_audio, &ao_data);
3526 break;
3527 case MP_CMD_AF_CMDLINE:
3528 if (sh_audio) {
3529 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3530 if (!af) {
3531 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3532 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3533 break;
3535 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3536 af_reinit(sh_audio->afilter, af);
3538 break;
3540 default:
3541 mp_msg(MSGT_CPLAYER, MSGL_V,
3542 "Received unknown cmd %s\n", cmd->name);
3545 switch (cmd->pausing) {
3546 case 1: // "pausing"
3547 pause_player(mpctx);
3548 break;
3549 case 3: // "pausing_toggle"
3550 if (mpctx->paused)
3551 unpause_player(mpctx);
3552 else
3553 pause_player(mpctx);
3554 break;