core: audio: make ogg missing audio timing workaround more complex
[mplayer/glamo.git] / command.c
blobc1519d001dec25e2dc96a68e885c523ce68eb413
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 "m_config.h"
38 #include "metadata.h"
39 #include "libmpcodecs/vf.h"
40 #include "libmpcodecs/vd.h"
41 #include "mp_osd.h"
42 #include "libvo/video_out.h"
43 #include "libvo/font_load.h"
44 #include "playtree.h"
45 #include "libao2/audio_out.h"
46 #include "mpcommon.h"
47 #include "mixer.h"
48 #include "libmpcodecs/dec_video.h"
49 #include "libmpcodecs/dec_audio.h"
50 #include "libmpcodecs/dec_teletext.h"
51 #include "vobsub.h"
52 #include "spudec.h"
53 #include "path.h"
54 #include "ass_mp.h"
55 #include "stream/tv.h"
56 #include "stream/stream_radio.h"
57 #include "stream/pvr.h"
58 #ifdef CONFIG_DVBIN
59 #include "stream/dvbin.h"
60 #endif
61 #ifdef CONFIG_DVDREAD
62 #include "stream/stream_dvd.h"
63 #endif
64 #include "stream/stream_dvdnav.h"
65 #include "m_struct.h"
66 #include "libmenu/menu.h"
68 #include "mp_core.h"
69 #include "mp_fifo.h"
70 #include "libavutil/avstring.h"
72 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
74 extern int use_menu;
76 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
77 double *dx, double *dy)
79 struct MPOpts *opts = &mpctx->opts;
80 struct vo *vo = mpctx->video_out;
81 //remove the borders, if any, and rescale to the range [0,1],[0,1]
82 if (vo_fs) { //we are in full-screen mode
83 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
84 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
85 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
86 iy -= (opts->vo_screenheight - vo->dheight) / 2;
88 if (ix < 0 || ix > vo->dwidth) {
89 *dx = *dy = -1.0;
90 return;
91 } //we are on one of the borders
92 if (iy < 0 || iy > vo->dheight) {
93 *dx = *dy = -1.0;
94 return;
95 } //we are on one of the borders
98 *dx = (double) ix / (double) vo->dwidth;
99 *dy = (double) iy / (double) vo->dheight;
101 mp_msg(MSGT_CPLAYER, MSGL_V,
102 "\r\nrescaled coordinates: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
103 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
104 vo->dheight, vo_fs);
107 static int sub_pos_by_source(MPContext *mpctx, int src)
109 int i, cnt = 0;
110 if (src >= SUB_SOURCES || mpctx->sub_counts[src] == 0)
111 return -1;
112 for (i = 0; i < src; i++)
113 cnt += mpctx->sub_counts[i];
114 return cnt;
117 static int sub_source_and_index_by_pos(MPContext *mpctx, int *pos)
119 int start = 0;
120 int i;
121 for (i = 0; i < SUB_SOURCES; i++) {
122 int cnt = mpctx->sub_counts[i];
123 if (*pos >= start && *pos < start + cnt) {
124 *pos -= start;
125 return i;
127 start += cnt;
129 *pos = -1;
130 return -1;
133 static int sub_source_by_pos(MPContext *mpctx, int pos)
135 return sub_source_and_index_by_pos(mpctx, &pos);
138 static int sub_source_pos(MPContext *mpctx)
140 int pos = mpctx->global_sub_pos;
141 sub_source_and_index_by_pos(mpctx, &pos);
142 return pos;
145 static int sub_source(MPContext *mpctx)
147 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
150 static void update_global_sub_size(MPContext *mpctx)
152 struct MPOpts *opts = &mpctx->opts;
153 int i;
154 int cnt = 0;
156 // update number of demuxer sub streams
157 for (i = 0; i < MAX_S_STREAMS; i++)
158 if (mpctx->d_sub->demuxer->s_streams[i])
159 cnt++;
160 if (cnt > mpctx->sub_counts[SUB_SOURCE_DEMUX])
161 mpctx->sub_counts[SUB_SOURCE_DEMUX] = cnt;
163 // update global size
164 mpctx->global_sub_size = 0;
165 for (i = 0; i < SUB_SOURCES; i++)
166 mpctx->global_sub_size += mpctx->sub_counts[i];
168 // update global_sub_pos if we auto-detected a demuxer sub
169 if (mpctx->global_sub_pos == -1) {
170 int sub_id = -1;
171 if (mpctx->demuxer->sub)
172 sub_id = mpctx->demuxer->sub->id;
173 if (sub_id < 0)
174 sub_id = opts->sub_id;
175 if (sub_id >= 0 && sub_id < mpctx->sub_counts[SUB_SOURCE_DEMUX])
176 mpctx->global_sub_pos = sub_pos_by_source(mpctx, SUB_SOURCE_DEMUX) +
177 sub_id;
182 * \brief Log the currently displayed subtitle to a file
184 * Logs the current or last displayed subtitle together with filename
185 * and time information to ~/.mplayer/subtitle_log
187 * Intended purpose is to allow convenient marking of bogus subtitles
188 * which need to be fixed while watching the movie.
191 static void log_sub(struct MPContext *mpctx)
193 char *fname;
194 FILE *f;
195 int i;
197 if (subdata == NULL || vo_sub_last == NULL)
198 return;
199 fname = get_path("subtitle_log");
200 f = fopen(fname, "a");
201 if (!f)
202 return;
203 fprintf(f, "----------------------------------------------------------\n");
204 if (subdata->sub_uses_time) {
205 fprintf(f,
206 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
207 mpctx->filename, vo_sub_last->start / 360000,
208 (vo_sub_last->start / 6000) % 60,
209 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
210 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
211 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
212 } else {
213 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
214 vo_sub_last->start, vo_sub_last->end);
216 for (i = 0; i < vo_sub_last->lines; i++) {
217 fprintf(f, "%s\n", vo_sub_last->text[i]);
219 fclose(f);
223 /// \defgroup Properties
224 ///@{
226 /// \defgroup GeneralProperties General properties
227 /// \ingroup Properties
228 ///@{
230 static int mp_property_generic_option(struct m_option *prop, int action,
231 void *arg, MPContext *mpctx)
233 char *optname = prop->priv;
234 const struct m_option *opt = m_config_get_option(mpctx->mconfig, optname);
235 void *valptr = m_option_get_ptr(opt, &mpctx->opts);
237 switch (action) {
238 case M_PROPERTY_GET_TYPE:
239 *(const struct m_option **)arg = opt;
240 return M_PROPERTY_OK;
241 case M_PROPERTY_GET:
242 m_option_copy(opt, arg, valptr);
243 return M_PROPERTY_OK;
244 case M_PROPERTY_SET:
245 m_option_copy(opt, valptr, arg);
246 return M_PROPERTY_OK;
247 case M_PROPERTY_STEP_UP:
248 if (opt->type == &m_option_type_choice) {
249 int v = *(int *) valptr;
250 int best = v;
251 struct m_opt_choice_alternatives *alt;
252 for (alt = opt->priv; alt->name; alt++)
253 if ((unsigned) alt->value - v - 1 < (unsigned) best - v - 1)
254 best = alt->value;
255 *(int *) valptr = best;
256 return M_PROPERTY_OK;
258 break;
260 return M_PROPERTY_NOT_IMPLEMENTED;
263 /// OSD level (RW)
264 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
265 MPContext *mpctx)
267 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
270 /// Loop (RW)
271 static int mp_property_loop(m_option_t *prop, int action, void *arg,
272 MPContext *mpctx)
274 struct MPOpts *opts = &mpctx->opts;
275 switch (action) {
276 case M_PROPERTY_PRINT:
277 if (!arg) return M_PROPERTY_ERROR;
278 if (opts->loop_times < 0)
279 *(char**)arg = strdup("off");
280 else if (opts->loop_times == 0)
281 *(char**)arg = strdup("inf");
282 else
283 break;
284 return M_PROPERTY_OK;
286 return m_property_int_range(prop, action, arg, &opts->loop_times);
289 /// Playback speed (RW)
290 static int mp_property_playback_speed(m_option_t *prop, int action,
291 void *arg, MPContext *mpctx)
293 struct MPOpts *opts = &mpctx->opts;
294 switch (action) {
295 case M_PROPERTY_SET:
296 if (!arg)
297 return M_PROPERTY_ERROR;
298 M_PROPERTY_CLAMP(prop, *(float *) arg);
299 opts->playback_speed = *(float *) arg;
300 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
301 return M_PROPERTY_OK;
302 case M_PROPERTY_STEP_UP:
303 case M_PROPERTY_STEP_DOWN:
304 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
305 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
306 M_PROPERTY_CLAMP(prop, opts->playback_speed);
307 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
308 return M_PROPERTY_OK;
310 return m_property_float_range(prop, action, arg, &opts->playback_speed);
313 /// filename with path (RO)
314 static int mp_property_path(m_option_t *prop, int action, void *arg,
315 MPContext *mpctx)
317 return m_property_string_ro(prop, action, arg, mpctx->filename);
320 /// filename without path (RO)
321 static int mp_property_filename(m_option_t *prop, int action, void *arg,
322 MPContext *mpctx)
324 char *f;
325 if (!mpctx->filename)
326 return M_PROPERTY_UNAVAILABLE;
327 if (((f = strrchr(mpctx->filename, '/'))
328 || (f = strrchr(mpctx->filename, '\\'))) && f[1])
329 f++;
330 else
331 f = mpctx->filename;
332 return m_property_string_ro(prop, action, arg, f);
335 /// Demuxer name (RO)
336 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
337 MPContext *mpctx)
339 if (!mpctx->demuxer)
340 return M_PROPERTY_UNAVAILABLE;
341 return m_property_string_ro(prop, action, arg,
342 (char *) mpctx->demuxer->desc->name);
345 /// Position in the stream (RW)
346 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
347 MPContext *mpctx)
349 if (!mpctx->demuxer || !mpctx->demuxer->stream)
350 return M_PROPERTY_UNAVAILABLE;
351 if (!arg)
352 return M_PROPERTY_ERROR;
353 switch (action) {
354 case M_PROPERTY_GET:
355 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
356 return M_PROPERTY_OK;
357 case M_PROPERTY_SET:
358 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
359 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
360 return M_PROPERTY_OK;
362 return M_PROPERTY_NOT_IMPLEMENTED;
365 /// Stream start offset (RO)
366 static int mp_property_stream_start(m_option_t *prop, int action,
367 void *arg, MPContext *mpctx)
369 if (!mpctx->demuxer || !mpctx->demuxer->stream)
370 return M_PROPERTY_UNAVAILABLE;
371 switch (action) {
372 case M_PROPERTY_GET:
373 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
374 return M_PROPERTY_OK;
376 return M_PROPERTY_NOT_IMPLEMENTED;
379 /// Stream end offset (RO)
380 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
381 MPContext *mpctx)
383 if (!mpctx->demuxer || !mpctx->demuxer->stream)
384 return M_PROPERTY_UNAVAILABLE;
385 switch (action) {
386 case M_PROPERTY_GET:
387 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
388 return M_PROPERTY_OK;
390 return M_PROPERTY_NOT_IMPLEMENTED;
393 /// Stream length (RO)
394 static int mp_property_stream_length(m_option_t *prop, int action,
395 void *arg, MPContext *mpctx)
397 if (!mpctx->demuxer || !mpctx->demuxer->stream)
398 return M_PROPERTY_UNAVAILABLE;
399 switch (action) {
400 case M_PROPERTY_GET:
401 *(off_t *) arg =
402 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
403 return M_PROPERTY_OK;
405 return M_PROPERTY_NOT_IMPLEMENTED;
408 /// Current stream position in seconds (RO)
409 static int mp_property_stream_time_pos(m_option_t *prop, int action,
410 void *arg, MPContext *mpctx)
412 if (!mpctx->demuxer || mpctx->demuxer->stream_pts == MP_NOPTS_VALUE)
413 return M_PROPERTY_UNAVAILABLE;
415 return m_property_time_ro(prop, action, arg, mpctx->demuxer->stream_pts);
419 /// Media length in seconds (RO)
420 static int mp_property_length(m_option_t *prop, int action, void *arg,
421 MPContext *mpctx)
423 double len;
425 if (!mpctx->demuxer ||
426 !(int) (len = get_time_length(mpctx)))
427 return M_PROPERTY_UNAVAILABLE;
429 return m_property_time_ro(prop, action, arg, len);
432 /// Current position in percent (RW)
433 static int mp_property_percent_pos(m_option_t *prop, int action,
434 void *arg, MPContext *mpctx) {
435 int pos;
437 if (!mpctx->demuxer)
438 return M_PROPERTY_UNAVAILABLE;
440 switch(action) {
441 case M_PROPERTY_SET:
442 if(!arg) return M_PROPERTY_ERROR;
443 M_PROPERTY_CLAMP(prop, *(int*)arg);
444 pos = *(int*)arg;
445 break;
446 case M_PROPERTY_STEP_UP:
447 case M_PROPERTY_STEP_DOWN:
448 pos = get_percent_pos(mpctx);
449 pos += (arg ? *(int*)arg : 10) *
450 (action == M_PROPERTY_STEP_UP ? 1 : -1);
451 M_PROPERTY_CLAMP(prop, pos);
452 break;
453 default:
454 return m_property_int_ro(prop, action, arg, get_percent_pos(mpctx));
457 queue_seek(mpctx, MPSEEK_FACTOR, pos / 100.0, 0);
458 return M_PROPERTY_OK;
461 /// Current position in seconds (RW)
462 static int mp_property_time_pos(m_option_t *prop, int action,
463 void *arg, MPContext *mpctx) {
464 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
465 return M_PROPERTY_UNAVAILABLE;
467 switch(action) {
468 case M_PROPERTY_SET:
469 if(!arg) return M_PROPERTY_ERROR;
470 M_PROPERTY_CLAMP(prop, *(double*)arg);
471 queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double*)arg, 0);
472 return M_PROPERTY_OK;
473 case M_PROPERTY_STEP_UP:
474 case M_PROPERTY_STEP_DOWN:
475 queue_seek(mpctx, MPSEEK_RELATIVE, (arg ? *(double*)arg : 10.0) *
476 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0), 0);
477 return M_PROPERTY_OK;
479 return m_property_time_ro(prop, action, arg, get_current_time(mpctx));
482 /// Current chapter (RW)
483 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
484 MPContext *mpctx)
486 struct MPOpts *opts = &mpctx->opts;
487 int chapter = -1;
488 int step_all;
489 char *chapter_name = NULL;
491 if (mpctx->demuxer)
492 chapter = get_current_chapter(mpctx);
493 if (chapter < -1)
494 return M_PROPERTY_UNAVAILABLE;
496 switch (action) {
497 case M_PROPERTY_GET:
498 if (!arg)
499 return M_PROPERTY_ERROR;
500 *(int *) arg = chapter;
501 return M_PROPERTY_OK;
502 case M_PROPERTY_PRINT: {
503 if (!arg)
504 return M_PROPERTY_ERROR;
505 chapter_name = chapter_display_name(mpctx, chapter);
506 if (!chapter_name)
507 return M_PROPERTY_UNAVAILABLE;
508 *(char **) arg = chapter_name;
509 return M_PROPERTY_OK;
511 case M_PROPERTY_SET:
512 if (!arg)
513 return M_PROPERTY_ERROR;
514 M_PROPERTY_CLAMP(prop, *(int*)arg);
515 step_all = *(int *)arg - chapter;
516 chapter += step_all;
517 break;
518 case M_PROPERTY_STEP_UP:
519 case M_PROPERTY_STEP_DOWN: {
520 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
521 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
522 chapter += step_all;
523 if (chapter < 0)
524 chapter = 0;
525 break;
527 default:
528 return M_PROPERTY_NOT_IMPLEMENTED;
531 double next_pts = 0;
532 queue_seek(mpctx, MPSEEK_NONE, 0, 0);
533 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
534 if (chapter >= 0) {
535 if (next_pts > -1.0)
536 queue_seek(mpctx, MPSEEK_ABSOLUTE, next_pts, 0);
537 if (chapter_name)
538 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
539 "Chapter: (%d) %s", chapter + 1, chapter_name);
540 } else if (step_all > 0)
541 queue_seek(mpctx, MPSEEK_RELATIVE, 1000000000, 0);
542 else
543 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
544 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
545 talloc_free(chapter_name);
546 return M_PROPERTY_OK;
549 /// Number of chapters in file
550 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
551 MPContext *mpctx)
553 if (!mpctx->demuxer)
554 return M_PROPERTY_UNAVAILABLE;
555 if (mpctx->demuxer->num_chapters == 0)
556 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
557 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
560 /// Current dvd angle (RW)
561 static int mp_property_angle(m_option_t *prop, int action, void *arg,
562 MPContext *mpctx)
564 struct MPOpts *opts = &mpctx->opts;
565 int angle = -1;
566 int angles;
567 char *angle_name = NULL;
569 if (mpctx->demuxer)
570 angle = demuxer_get_current_angle(mpctx->demuxer);
571 if (angle < 0)
572 return M_PROPERTY_UNAVAILABLE;
573 angles = demuxer_angles_count(mpctx->demuxer);
574 if (angles <= 1)
575 return M_PROPERTY_UNAVAILABLE;
577 switch (action) {
578 case M_PROPERTY_GET:
579 if (!arg)
580 return M_PROPERTY_ERROR;
581 *(int *) arg = angle;
582 return M_PROPERTY_OK;
583 case M_PROPERTY_PRINT: {
584 if (!arg)
585 return M_PROPERTY_ERROR;
586 angle_name = calloc(1, 64);
587 if (!angle_name)
588 return M_PROPERTY_UNAVAILABLE;
589 snprintf(angle_name, 64, "%d/%d", angle, angles);
590 *(char **) arg = angle_name;
591 return M_PROPERTY_OK;
593 case M_PROPERTY_SET:
594 if (!arg)
595 return M_PROPERTY_ERROR;
596 angle = *(int *)arg;
597 M_PROPERTY_CLAMP(prop, angle);
598 break;
599 case M_PROPERTY_STEP_UP:
600 case M_PROPERTY_STEP_DOWN: {
601 int step = 0;
602 if(arg)
603 step = *(int*)arg;
604 if(!step)
605 step = 1;
606 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
607 angle += step;
608 if (angle < 1) //cycle
609 angle = angles;
610 break;
612 default:
613 return M_PROPERTY_NOT_IMPLEMENTED;
615 angle = demuxer_set_angle(mpctx->demuxer, angle);
616 if (angle >= 0) {
617 struct sh_video *sh_video = mpctx->demuxer->video->sh;
618 if (sh_video)
619 resync_video_stream(sh_video);
621 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
622 if (sh_audio)
623 resync_audio_stream(sh_audio);
626 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
627 "Angle: %d/%d", angle, angles);
628 free(angle_name);
629 return M_PROPERTY_OK;
632 /// Demuxer meta data
633 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
634 MPContext *mpctx) {
635 m_property_action_t* ka;
636 char* meta;
637 static const m_option_t key_type =
638 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
639 if (!mpctx->demuxer)
640 return M_PROPERTY_UNAVAILABLE;
642 switch(action) {
643 case M_PROPERTY_GET:
644 if(!arg) return M_PROPERTY_ERROR;
645 *(char***)arg = mpctx->demuxer->info;
646 return M_PROPERTY_OK;
647 case M_PROPERTY_KEY_ACTION:
648 if(!arg) return M_PROPERTY_ERROR;
649 ka = arg;
650 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
651 return M_PROPERTY_UNKNOWN;
652 switch(ka->action) {
653 case M_PROPERTY_GET:
654 if(!ka->arg) return M_PROPERTY_ERROR;
655 *(char**)ka->arg = meta;
656 return M_PROPERTY_OK;
657 case M_PROPERTY_GET_TYPE:
658 if(!ka->arg) return M_PROPERTY_ERROR;
659 *(const m_option_t**)ka->arg = &key_type;
660 return M_PROPERTY_OK;
663 return M_PROPERTY_NOT_IMPLEMENTED;
666 static int mp_property_pause(m_option_t *prop, int action, void *arg,
667 void *ctx)
669 MPContext *mpctx = ctx;
671 switch (action) {
672 case M_PROPERTY_SET:
673 if (!arg)
674 return M_PROPERTY_ERROR;
675 if (mpctx->paused == (bool)*(int *) arg)
676 return M_PROPERTY_OK;
677 case M_PROPERTY_STEP_UP:
678 case M_PROPERTY_STEP_DOWN:
679 if (mpctx->paused) {
680 unpause_player(mpctx);
681 mpctx->osd_function = OSD_PLAY;
683 else {
684 pause_player(mpctx);
685 mpctx->osd_function = OSD_PAUSE;
687 return M_PROPERTY_OK;
688 default:
689 return m_property_flag(prop, action, arg, &mpctx->paused);
694 ///@}
696 /// \defgroup AudioProperties Audio properties
697 /// \ingroup Properties
698 ///@{
700 /// Volume (RW)
701 static int mp_property_volume(m_option_t *prop, int action, void *arg,
702 MPContext *mpctx)
705 if (!mpctx->sh_audio)
706 return M_PROPERTY_UNAVAILABLE;
708 switch (action) {
709 case M_PROPERTY_GET:
710 if (!arg)
711 return M_PROPERTY_ERROR;
712 mixer_getbothvolume(&mpctx->mixer, arg);
713 return M_PROPERTY_OK;
714 case M_PROPERTY_PRINT:{
715 float vol;
716 if (!arg)
717 return M_PROPERTY_ERROR;
718 mixer_getbothvolume(&mpctx->mixer, &vol);
719 return m_property_float_range(prop, action, arg, &vol);
721 case M_PROPERTY_STEP_UP:
722 case M_PROPERTY_STEP_DOWN:
723 case M_PROPERTY_SET:
724 break;
725 default:
726 return M_PROPERTY_NOT_IMPLEMENTED;
729 if (mpctx->edl_muted)
730 return M_PROPERTY_DISABLED;
731 mpctx->user_muted = 0;
733 switch (action) {
734 case M_PROPERTY_SET:
735 if (!arg)
736 return M_PROPERTY_ERROR;
737 M_PROPERTY_CLAMP(prop, *(float *) arg);
738 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
739 return M_PROPERTY_OK;
740 case M_PROPERTY_STEP_UP:
741 if (arg && *(float *) arg <= 0)
742 mixer_decvolume(&mpctx->mixer);
743 else
744 mixer_incvolume(&mpctx->mixer);
745 return M_PROPERTY_OK;
746 case M_PROPERTY_STEP_DOWN:
747 if (arg && *(float *) arg <= 0)
748 mixer_incvolume(&mpctx->mixer);
749 else
750 mixer_decvolume(&mpctx->mixer);
751 return M_PROPERTY_OK;
753 return M_PROPERTY_NOT_IMPLEMENTED;
756 /// Mute (RW)
757 static int mp_property_mute(m_option_t *prop, int action, void *arg,
758 MPContext *mpctx)
761 if (!mpctx->sh_audio)
762 return M_PROPERTY_UNAVAILABLE;
764 switch (action) {
765 case M_PROPERTY_SET:
766 if (mpctx->edl_muted)
767 return M_PROPERTY_DISABLED;
768 if (!arg)
769 return M_PROPERTY_ERROR;
770 if ((!!*(int *) arg) != mpctx->mixer.muted)
771 mixer_mute(&mpctx->mixer);
772 mpctx->user_muted = mpctx->mixer.muted;
773 return M_PROPERTY_OK;
774 case M_PROPERTY_STEP_UP:
775 case M_PROPERTY_STEP_DOWN:
776 if (mpctx->edl_muted)
777 return M_PROPERTY_DISABLED;
778 mixer_mute(&mpctx->mixer);
779 mpctx->user_muted = mpctx->mixer.muted;
780 return M_PROPERTY_OK;
781 case M_PROPERTY_PRINT:
782 if (!arg)
783 return M_PROPERTY_ERROR;
784 if (mpctx->edl_muted) {
785 *(char **) arg = strdup(mp_gtext("enabled (EDL)"));
786 return M_PROPERTY_OK;
788 default:
789 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
794 /// Audio delay (RW)
795 static int mp_property_audio_delay(m_option_t *prop, int action,
796 void *arg, MPContext *mpctx)
798 if (!(mpctx->sh_audio && mpctx->sh_video))
799 return M_PROPERTY_UNAVAILABLE;
800 switch (action) {
801 case M_PROPERTY_SET:
802 case M_PROPERTY_STEP_UP:
803 case M_PROPERTY_STEP_DOWN: {
804 int ret;
805 float delay = audio_delay;
806 ret = m_property_delay(prop, action, arg, &audio_delay);
807 if (ret != M_PROPERTY_OK)
808 return ret;
809 if (mpctx->sh_audio)
810 mpctx->delay -= audio_delay - delay;
812 return M_PROPERTY_OK;
813 default:
814 return m_property_delay(prop, action, arg, &audio_delay);
818 /// Audio codec tag (RO)
819 static int mp_property_audio_format(m_option_t *prop, int action,
820 void *arg, MPContext *mpctx)
822 if (!mpctx->sh_audio)
823 return M_PROPERTY_UNAVAILABLE;
824 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
827 /// Audio codec name (RO)
828 static int mp_property_audio_codec(m_option_t *prop, int action,
829 void *arg, MPContext *mpctx)
831 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
832 return M_PROPERTY_UNAVAILABLE;
833 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
836 /// Audio bitrate (RO)
837 static int mp_property_audio_bitrate(m_option_t *prop, int action,
838 void *arg, MPContext *mpctx)
840 if (!mpctx->sh_audio)
841 return M_PROPERTY_UNAVAILABLE;
842 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
845 /// Samplerate (RO)
846 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
847 MPContext *mpctx)
849 if (!mpctx->sh_audio)
850 return M_PROPERTY_UNAVAILABLE;
851 switch(action) {
852 case M_PROPERTY_PRINT:
853 if(!arg) return M_PROPERTY_ERROR;
854 *(char**)arg = malloc(16);
855 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
856 return M_PROPERTY_OK;
858 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
861 /// Number of channels (RO)
862 static int mp_property_channels(m_option_t *prop, int action, void *arg,
863 MPContext *mpctx)
865 if (!mpctx->sh_audio)
866 return M_PROPERTY_UNAVAILABLE;
867 switch (action) {
868 case M_PROPERTY_PRINT:
869 if (!arg)
870 return M_PROPERTY_ERROR;
871 switch (mpctx->sh_audio->channels) {
872 case 1:
873 *(char **) arg = strdup("mono");
874 break;
875 case 2:
876 *(char **) arg = strdup("stereo");
877 break;
878 default:
879 *(char **) arg = malloc(32);
880 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
882 return M_PROPERTY_OK;
884 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
887 /// Balance (RW)
888 static int mp_property_balance(m_option_t *prop, int action, void *arg,
889 MPContext *mpctx)
891 float bal;
893 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
894 return M_PROPERTY_UNAVAILABLE;
896 switch (action) {
897 case M_PROPERTY_GET:
898 if (!arg)
899 return M_PROPERTY_ERROR;
900 mixer_getbalance(&mpctx->mixer, arg);
901 return M_PROPERTY_OK;
902 case M_PROPERTY_PRINT: {
903 char** str = arg;
904 if (!arg)
905 return M_PROPERTY_ERROR;
906 mixer_getbalance(&mpctx->mixer, &bal);
907 if (bal == 0.f)
908 *str = strdup("center");
909 else if (bal == -1.f)
910 *str = strdup("left only");
911 else if (bal == 1.f)
912 *str = strdup("right only");
913 else {
914 unsigned right = (bal + 1.f) / 2.f * 100.f;
915 *str = malloc(sizeof("left xxx%, right xxx%"));
916 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
918 return M_PROPERTY_OK;
920 case M_PROPERTY_STEP_UP:
921 case M_PROPERTY_STEP_DOWN:
922 mixer_getbalance(&mpctx->mixer, &bal);
923 bal += (arg ? *(float*)arg : .1f) *
924 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
925 M_PROPERTY_CLAMP(prop, bal);
926 mixer_setbalance(&mpctx->mixer, bal);
927 return M_PROPERTY_OK;
928 case M_PROPERTY_SET:
929 if (!arg)
930 return M_PROPERTY_ERROR;
931 M_PROPERTY_CLAMP(prop, *(float*)arg);
932 mixer_setbalance(&mpctx->mixer, *(float*)arg);
933 return M_PROPERTY_OK;
935 return M_PROPERTY_NOT_IMPLEMENTED;
938 /// Selected audio id (RW)
939 static int mp_property_audio(m_option_t *prop, int action, void *arg,
940 MPContext *mpctx)
942 int current_id, tmp;
943 if (!mpctx->demuxer || !mpctx->d_audio)
944 return M_PROPERTY_UNAVAILABLE;
945 current_id = mpctx->sh_audio ? mpctx->sh_audio->aid : -2;
947 switch (action) {
948 case M_PROPERTY_GET:
949 if (!arg)
950 return M_PROPERTY_ERROR;
951 *(int *) arg = current_id;
952 return M_PROPERTY_OK;
953 case M_PROPERTY_PRINT:
954 if (!arg)
955 return M_PROPERTY_ERROR;
957 if (current_id < 0)
958 *(char **) arg = strdup(mp_gtext("disabled"));
959 else {
960 char lang[40];
961 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
962 sh_audio_t* sh = mpctx->sh_audio;
963 if (sh && sh->lang)
964 av_strlcpy(lang, sh->lang, 40);
965 #ifdef CONFIG_DVDREAD
966 else if (mpctx->stream->type == STREAMTYPE_DVD) {
967 int code = dvd_lang_from_aid(mpctx->stream, current_id);
968 if (code) {
969 lang[0] = code >> 8;
970 lang[1] = code;
971 lang[2] = 0;
974 #endif
976 #ifdef CONFIG_DVDNAV
977 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
978 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
979 #endif
980 *(char **) arg = malloc(64);
981 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
983 return M_PROPERTY_OK;
985 case M_PROPERTY_STEP_UP:
986 case M_PROPERTY_SET:
987 if (action == M_PROPERTY_SET && arg)
988 tmp = *((int *) arg);
989 else
990 tmp = -1;
991 int new_id = demuxer_switch_audio(mpctx->d_audio->demuxer, tmp);
992 if (new_id != current_id)
993 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
994 if (new_id != current_id && new_id >= 0) {
995 sh_audio_t *sh2;
996 sh2 = mpctx->d_audio->demuxer->a_streams[mpctx->demuxer->audio->id];
997 sh2->ds = mpctx->demuxer->audio;
998 mpctx->sh_audio = sh2;
999 reinit_audio_chain(mpctx);
1001 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
1002 return M_PROPERTY_OK;
1003 default:
1004 return M_PROPERTY_NOT_IMPLEMENTED;
1009 /// Selected video id (RW)
1010 static int mp_property_video(m_option_t *prop, int action, void *arg,
1011 MPContext *mpctx)
1013 struct MPOpts *opts = &mpctx->opts;
1014 int current_id, tmp;
1015 if (!mpctx->demuxer || !mpctx->d_video)
1016 return M_PROPERTY_UNAVAILABLE;
1017 current_id = mpctx->d_video->id;
1019 switch (action) {
1020 case M_PROPERTY_GET:
1021 if (!arg)
1022 return M_PROPERTY_ERROR;
1023 *(int *) arg = current_id;
1024 return M_PROPERTY_OK;
1025 case M_PROPERTY_PRINT:
1026 if (!arg)
1027 return M_PROPERTY_ERROR;
1029 if (current_id < 0)
1030 *(char **) arg = strdup(mp_gtext("disabled"));
1031 else {
1032 char lang[40];
1033 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
1034 *(char **) arg = malloc(64);
1035 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
1037 return M_PROPERTY_OK;
1039 case M_PROPERTY_STEP_UP:
1040 case M_PROPERTY_SET:
1041 if (action == M_PROPERTY_SET && arg)
1042 tmp = *((int *) arg);
1043 else
1044 tmp = -1;
1045 opts->video_id = demuxer_switch_video(mpctx->d_video->demuxer, tmp);
1046 if (opts->video_id == -2
1047 || (opts->video_id > -1 && mpctx->d_video->id != current_id
1048 && current_id != -2))
1049 uninit_player(mpctx, INITIALIZED_VCODEC |
1050 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
1051 if (opts->video_id > -1 && mpctx->d_video->id != current_id) {
1052 sh_video_t *sh2;
1053 sh2 = mpctx->d_video->demuxer->v_streams[mpctx->d_video->id];
1054 if (sh2) {
1055 sh2->ds = mpctx->d_video;
1056 mpctx->sh_video = sh2;
1057 reinit_video_chain(mpctx);
1060 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
1061 return M_PROPERTY_OK;
1063 default:
1064 return M_PROPERTY_NOT_IMPLEMENTED;
1068 static int mp_property_program(m_option_t *prop, int action, void *arg,
1069 MPContext *mpctx)
1071 demux_program_t prog;
1073 switch (action) {
1074 case M_PROPERTY_STEP_UP:
1075 case M_PROPERTY_SET:
1076 if (action == M_PROPERTY_SET && arg)
1077 prog.progid = *((int *) arg);
1078 else
1079 prog.progid = -1;
1080 if (demux_control
1081 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1082 &prog) == DEMUXER_CTRL_NOTIMPL)
1083 return M_PROPERTY_ERROR;
1085 if (prog.aid < 0 && prog.vid < 0) {
1086 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
1087 return M_PROPERTY_ERROR;
1089 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1090 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1091 return M_PROPERTY_OK;
1093 default:
1094 return M_PROPERTY_NOT_IMPLEMENTED;
1098 ///@}
1100 /// \defgroup VideoProperties Video properties
1101 /// \ingroup Properties
1102 ///@{
1104 /// Fullscreen state (RW)
1105 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1106 MPContext *mpctx)
1109 if (!mpctx->video_out)
1110 return M_PROPERTY_UNAVAILABLE;
1112 switch (action) {
1113 case M_PROPERTY_SET:
1114 if (!arg)
1115 return M_PROPERTY_ERROR;
1116 M_PROPERTY_CLAMP(prop, *(int *) arg);
1117 if (vo_fs == !!*(int *) arg)
1118 return M_PROPERTY_OK;
1119 case M_PROPERTY_STEP_UP:
1120 case M_PROPERTY_STEP_DOWN:
1121 if (mpctx->video_out->config_ok)
1122 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1123 mpctx->opts.fullscreen = vo_fs;
1124 return M_PROPERTY_OK;
1125 default:
1126 return m_property_flag(prop, action, arg, &vo_fs);
1130 static int mp_property_deinterlace(m_option_t *prop, int action,
1131 void *arg, MPContext *mpctx)
1133 int deinterlace;
1134 vf_instance_t *vf;
1135 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1136 return M_PROPERTY_UNAVAILABLE;
1137 vf = mpctx->sh_video->vfilter;
1138 switch (action) {
1139 case M_PROPERTY_GET:
1140 if (!arg)
1141 return M_PROPERTY_ERROR;
1142 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1143 return M_PROPERTY_OK;
1144 case M_PROPERTY_SET:
1145 if (!arg)
1146 return M_PROPERTY_ERROR;
1147 M_PROPERTY_CLAMP(prop, *(int *) arg);
1148 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1149 return M_PROPERTY_OK;
1150 case M_PROPERTY_STEP_UP:
1151 case M_PROPERTY_STEP_DOWN:
1152 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1153 deinterlace = !deinterlace;
1154 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1155 return M_PROPERTY_OK;
1157 int value = 0;
1158 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1159 return m_property_flag_ro(prop, action, arg, value);
1162 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1163 void *arg, MPContext *mpctx)
1165 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1166 return M_PROPERTY_UNAVAILABLE;
1168 struct vf_instance *vf = mpctx->sh_video->vfilter;
1169 int colorspace;
1170 switch (action) {
1171 case M_PROPERTY_GET:
1172 if (!arg)
1173 return M_PROPERTY_ERROR;
1174 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1175 return M_PROPERTY_UNAVAILABLE;
1176 return M_PROPERTY_OK;
1177 case M_PROPERTY_PRINT:
1178 if (!arg)
1179 return M_PROPERTY_ERROR;
1180 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1181 return M_PROPERTY_UNAVAILABLE;
1182 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1183 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1184 *(char **)arg = strdup("Unknown");
1185 else
1186 *(char**)arg = strdup(names[colorspace]);
1187 return M_PROPERTY_OK;
1188 case M_PROPERTY_SET:
1189 if (!arg)
1190 return M_PROPERTY_ERROR;
1191 M_PROPERTY_CLAMP(prop, *(int *) arg);
1192 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1193 return M_PROPERTY_OK;
1194 case M_PROPERTY_STEP_UP:;
1195 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1196 return M_PROPERTY_UNAVAILABLE;
1197 colorspace += 1;
1198 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1199 return M_PROPERTY_OK;
1201 return M_PROPERTY_NOT_IMPLEMENTED;
1204 static int mp_property_capture(m_option_t *prop, int action,
1205 void *arg, MPContext *mpctx)
1207 struct MPOpts *opts = &mpctx->opts;
1209 if (!mpctx->stream)
1210 return M_PROPERTY_UNAVAILABLE;
1212 if (!opts->capture_dump) {
1213 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1214 "Capturing not enabled (forgot -capture parameter?)\n");
1215 return M_PROPERTY_ERROR;
1218 int capturing = !!mpctx->stream->capture_file;
1220 int ret = m_property_flag(prop, action, arg, &capturing);
1221 if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
1222 if (capturing) {
1223 mpctx->stream->capture_file = fopen(opts->stream_dump_name, "wb");
1224 if (!mpctx->stream->capture_file) {
1225 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1226 "Error opening capture file: %s\n", strerror(errno));
1227 ret = M_PROPERTY_ERROR;
1229 } else {
1230 fclose(mpctx->stream->capture_file);
1231 mpctx->stream->capture_file = NULL;
1235 return ret;
1238 /// Panscan (RW)
1239 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1240 MPContext *mpctx)
1243 if (!mpctx->video_out
1244 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1245 return M_PROPERTY_UNAVAILABLE;
1247 switch (action) {
1248 case M_PROPERTY_SET:
1249 if (!arg)
1250 return M_PROPERTY_ERROR;
1251 M_PROPERTY_CLAMP(prop, *(float *) arg);
1252 vo_panscan = *(float *) arg;
1253 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1254 return M_PROPERTY_OK;
1255 case M_PROPERTY_STEP_UP:
1256 case M_PROPERTY_STEP_DOWN:
1257 vo_panscan += (arg ? *(float *) arg : 0.1) *
1258 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1259 if (vo_panscan > 1)
1260 vo_panscan = 1;
1261 else if (vo_panscan < 0)
1262 vo_panscan = 0;
1263 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1264 return M_PROPERTY_OK;
1265 default:
1266 return m_property_float_range(prop, action, arg, &vo_panscan);
1270 /// Helper to set vo flags.
1271 /** \ingroup PropertyImplHelper
1273 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1274 int vo_ctrl, int *vo_var, MPContext *mpctx)
1277 if (!mpctx->video_out)
1278 return M_PROPERTY_UNAVAILABLE;
1280 switch (action) {
1281 case M_PROPERTY_SET:
1282 if (!arg)
1283 return M_PROPERTY_ERROR;
1284 M_PROPERTY_CLAMP(prop, *(int *) arg);
1285 if (*vo_var == !!*(int *) arg)
1286 return M_PROPERTY_OK;
1287 case M_PROPERTY_STEP_UP:
1288 case M_PROPERTY_STEP_DOWN:
1289 if (mpctx->video_out->config_ok)
1290 vo_control(mpctx->video_out, vo_ctrl, 0);
1291 return M_PROPERTY_OK;
1292 default:
1293 return m_property_flag(prop, action, arg, vo_var);
1297 /// Window always on top (RW)
1298 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1299 MPContext *mpctx)
1301 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1302 &mpctx->opts.vo_ontop, mpctx);
1305 /// Display in the root window (RW)
1306 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1307 MPContext *mpctx)
1309 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1310 &vo_rootwin, mpctx);
1313 /// Show window borders (RW)
1314 static int mp_property_border(m_option_t *prop, int action, void *arg,
1315 MPContext *mpctx)
1317 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1318 &vo_border, mpctx);
1321 /// Framedropping state (RW)
1322 static int mp_property_framedropping(m_option_t *prop, int action,
1323 void *arg, MPContext *mpctx)
1326 if (!mpctx->sh_video)
1327 return M_PROPERTY_UNAVAILABLE;
1329 switch (action) {
1330 case M_PROPERTY_PRINT:
1331 if (!arg)
1332 return M_PROPERTY_ERROR;
1333 *(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
1334 (frame_dropping == 2 ? mp_gtext("hard") :
1335 mp_gtext("disabled")));
1336 return M_PROPERTY_OK;
1337 default:
1338 return m_property_choice(prop, action, arg, &frame_dropping);
1342 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1343 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1344 MPContext *mpctx)
1346 int *gamma = (int *)((char *)&mpctx->opts + prop->offset);
1347 int r, val;
1349 if (!mpctx->sh_video)
1350 return M_PROPERTY_UNAVAILABLE;
1352 if (gamma[0] == 1000) {
1353 gamma[0] = 0;
1354 get_video_colors(mpctx->sh_video, prop->name, gamma);
1357 switch (action) {
1358 case M_PROPERTY_SET:
1359 if (!arg)
1360 return M_PROPERTY_ERROR;
1361 M_PROPERTY_CLAMP(prop, *(int *) arg);
1362 *gamma = *(int *) arg;
1363 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1364 if (r <= 0)
1365 break;
1366 return r;
1367 case M_PROPERTY_GET:
1368 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1369 if (!arg)
1370 return M_PROPERTY_ERROR;
1371 *(int *)arg = val;
1372 return M_PROPERTY_OK;
1374 break;
1375 case M_PROPERTY_STEP_UP:
1376 case M_PROPERTY_STEP_DOWN:
1377 *gamma += (arg ? *(int *) arg : 1) *
1378 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1379 M_PROPERTY_CLAMP(prop, *gamma);
1380 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1381 if (r <= 0)
1382 break;
1383 return r;
1384 default:
1385 return M_PROPERTY_NOT_IMPLEMENTED;
1388 #ifdef CONFIG_TV
1389 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1390 int l = strlen(prop->name);
1391 char tv_prop[3 + l + 1];
1392 sprintf(tv_prop, "tv_%s", prop->name);
1393 return mp_property_do(tv_prop, action, arg, mpctx);
1395 #endif
1397 return M_PROPERTY_UNAVAILABLE;
1400 /// VSync (RW)
1401 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1402 MPContext *mpctx)
1404 return m_property_flag(prop, action, arg, &vo_vsync);
1407 /// Video codec tag (RO)
1408 static int mp_property_video_format(m_option_t *prop, int action,
1409 void *arg, MPContext *mpctx)
1411 char* meta;
1412 if (!mpctx->sh_video)
1413 return M_PROPERTY_UNAVAILABLE;
1414 switch(action) {
1415 case M_PROPERTY_PRINT:
1416 if (!arg)
1417 return M_PROPERTY_ERROR;
1418 switch(mpctx->sh_video->format) {
1419 case 0x10000001:
1420 meta = strdup ("mpeg1"); break;
1421 case 0x10000002:
1422 meta = strdup ("mpeg2"); break;
1423 case 0x10000004:
1424 meta = strdup ("mpeg4"); break;
1425 case 0x10000005:
1426 meta = strdup ("h264"); break;
1427 default:
1428 if(mpctx->sh_video->format >= 0x20202020) {
1429 meta = malloc(5);
1430 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1431 } else {
1432 meta = malloc(20);
1433 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1436 *(char**)arg = meta;
1437 return M_PROPERTY_OK;
1439 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1442 /// Video codec name (RO)
1443 static int mp_property_video_codec(m_option_t *prop, int action,
1444 void *arg, MPContext *mpctx)
1446 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1447 return M_PROPERTY_UNAVAILABLE;
1448 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1452 /// Video bitrate (RO)
1453 static int mp_property_video_bitrate(m_option_t *prop, int action,
1454 void *arg, MPContext *mpctx)
1456 if (!mpctx->sh_video)
1457 return M_PROPERTY_UNAVAILABLE;
1458 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1461 /// Video display width (RO)
1462 static int mp_property_width(m_option_t *prop, int action, void *arg,
1463 MPContext *mpctx)
1465 if (!mpctx->sh_video)
1466 return M_PROPERTY_UNAVAILABLE;
1467 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1470 /// Video display height (RO)
1471 static int mp_property_height(m_option_t *prop, int action, void *arg,
1472 MPContext *mpctx)
1474 if (!mpctx->sh_video)
1475 return M_PROPERTY_UNAVAILABLE;
1476 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1479 /// Video fps (RO)
1480 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1481 MPContext *mpctx)
1483 if (!mpctx->sh_video)
1484 return M_PROPERTY_UNAVAILABLE;
1485 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1488 /// Video aspect (RO)
1489 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1490 MPContext *mpctx)
1492 if (!mpctx->sh_video)
1493 return M_PROPERTY_UNAVAILABLE;
1494 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1497 ///@}
1499 /// \defgroup SubProprties Subtitles properties
1500 /// \ingroup Properties
1501 ///@{
1503 /// Text subtitle position (RW)
1504 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1505 MPContext *mpctx)
1507 switch (action) {
1508 case M_PROPERTY_SET:
1509 if (!arg)
1510 return M_PROPERTY_ERROR;
1511 case M_PROPERTY_STEP_UP:
1512 case M_PROPERTY_STEP_DOWN:
1513 vo_osd_changed(OSDTYPE_SUBTITLE);
1514 default:
1515 return m_property_int_range(prop, action, arg, &sub_pos);
1519 /// Selected subtitles (RW)
1520 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1521 MPContext *mpctx)
1523 struct MPOpts *opts = &mpctx->opts;
1524 demux_stream_t *const d_sub = mpctx->d_sub;
1525 int source = -1, reset_spu = 0;
1526 int source_pos = -1;
1527 char *sub_name;
1529 update_global_sub_size(mpctx);
1530 const int global_sub_size = mpctx->global_sub_size;
1532 if (global_sub_size <= 0)
1533 return M_PROPERTY_UNAVAILABLE;
1535 switch (action) {
1536 case M_PROPERTY_GET:
1537 if (!arg)
1538 return M_PROPERTY_ERROR;
1539 *(int *) arg = mpctx->global_sub_pos;
1540 return M_PROPERTY_OK;
1541 case M_PROPERTY_PRINT:
1542 if (!arg)
1543 return M_PROPERTY_ERROR;
1544 *(char **) arg = malloc(64);
1545 (*(char **) arg)[63] = 0;
1546 sub_name = 0;
1547 if (subdata)
1548 sub_name = subdata->filename;
1549 #ifdef CONFIG_ASS
1550 if (ass_track && ass_track->name)
1551 sub_name = ass_track->name;
1552 #endif
1553 if (sub_name) {
1554 char *tmp, *tmp2;
1555 tmp = sub_name;
1556 if ((tmp2 = strrchr(tmp, '/')))
1557 tmp = tmp2 + 1;
1559 snprintf(*(char **) arg, 63, "(%d) %s%s",
1560 mpctx->set_of_sub_pos + 1,
1561 strlen(tmp) < 20 ? "" : "...",
1562 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1563 return M_PROPERTY_OK;
1565 #ifdef CONFIG_DVDNAV
1566 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1567 if (vo_spudec && opts->sub_id >= 0) {
1568 unsigned char lang[3];
1569 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1570 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1571 return M_PROPERTY_OK;
1575 #endif
1577 if ((d_sub->demuxer->type == DEMUXER_TYPE_MATROSKA
1578 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF
1579 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1580 || d_sub->demuxer->type == DEMUXER_TYPE_OGG)
1581 && d_sub->sh && opts->sub_id >= 0) {
1582 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1583 if (!lang) lang = mp_gtext("unknown");
1584 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1585 return M_PROPERTY_OK;
1588 if (vo_vobsub && vobsub_id >= 0) {
1589 const char *language = mp_gtext("unknown");
1590 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1591 snprintf(*(char **) arg, 63, "(%d) %s",
1592 vobsub_id, language ? language : mp_gtext("unknown"));
1593 return M_PROPERTY_OK;
1595 #ifdef CONFIG_DVDREAD
1596 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1597 && opts->sub_id >= 0) {
1598 char lang[3];
1599 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1600 lang[0] = code >> 8;
1601 lang[1] = code;
1602 lang[2] = 0;
1603 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1604 return M_PROPERTY_OK;
1606 #endif
1607 if (opts->sub_id >= 0) {
1608 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
1609 mp_gtext("unknown"));
1610 return M_PROPERTY_OK;
1612 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1613 return M_PROPERTY_OK;
1615 case M_PROPERTY_SET:
1616 if (!arg)
1617 return M_PROPERTY_ERROR;
1618 if (*(int *) arg < -1)
1619 *(int *) arg = -1;
1620 else if (*(int *) arg >= global_sub_size)
1621 *(int *) arg = global_sub_size - 1;
1622 mpctx->global_sub_pos = *(int *) arg;
1623 break;
1624 case M_PROPERTY_STEP_UP:
1625 mpctx->global_sub_pos += 2;
1626 mpctx->global_sub_pos =
1627 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1628 break;
1629 case M_PROPERTY_STEP_DOWN:
1630 mpctx->global_sub_pos += global_sub_size + 1;
1631 mpctx->global_sub_pos =
1632 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1633 break;
1634 default:
1635 return M_PROPERTY_NOT_IMPLEMENTED;
1638 if (mpctx->global_sub_pos >= 0) {
1639 source = sub_source(mpctx);
1640 source_pos = sub_source_pos(mpctx);
1643 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1644 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1645 global_sub_size,
1646 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1647 mpctx->sub_counts[SUB_SOURCE_SUBS],
1648 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1649 mpctx->global_sub_pos, source);
1651 mpctx->set_of_sub_pos = -1;
1652 subdata = NULL;
1654 vobsub_id = -1;
1655 opts->sub_id = -1;
1656 if (d_sub) {
1657 if (d_sub->id > -2)
1658 reset_spu = 1;
1659 d_sub->id = -2;
1661 #ifdef CONFIG_ASS
1662 ass_track = 0;
1663 #endif
1665 if (source == SUB_SOURCE_VOBSUB) {
1666 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1667 } else if (source == SUB_SOURCE_SUBS) {
1668 mpctx->set_of_sub_pos = source_pos;
1669 #ifdef CONFIG_ASS
1670 if (opts->ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1671 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1672 else
1673 #endif
1675 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1676 vo_osd_changed(OSDTYPE_SUBTITLE);
1678 } else if (source == SUB_SOURCE_DEMUX) {
1679 opts->sub_id = source_pos;
1680 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1681 int i = 0;
1682 // default: assume 1:1 mapping of sid and stream id
1683 d_sub->id = opts->sub_id;
1684 d_sub->sh = mpctx->d_sub->demuxer->s_streams[d_sub->id];
1685 ds_free_packs(d_sub);
1686 for (i = 0; i < MAX_S_STREAMS; i++) {
1687 sh_sub_t *sh = mpctx->d_sub->demuxer->s_streams[i];
1688 if (sh && sh->sid == opts->sub_id) {
1689 d_sub->id = i;
1690 d_sub->sh = sh;
1691 break;
1694 if (d_sub->sh && d_sub->id >= 0) {
1695 sh_sub_t *sh = d_sub->sh;
1696 if (sh->type == 'v')
1697 init_vo_spudec(mpctx);
1698 #ifdef CONFIG_ASS
1699 else if (opts->ass_enabled)
1700 ass_track = sh->ass_track;
1701 #endif
1702 } else {
1703 d_sub->id = -2;
1704 d_sub->sh = NULL;
1708 #ifdef CONFIG_DVDREAD
1709 if (vo_spudec
1710 && (mpctx->stream->type == STREAMTYPE_DVD
1711 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1712 && opts->sub_id < 0 && reset_spu) {
1713 d_sub->id = -2;
1714 d_sub->sh = NULL;
1716 #endif
1718 update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, 0, 0, d_sub, 1);
1720 return M_PROPERTY_OK;
1723 /// Selected sub source (RW)
1724 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1725 MPContext *mpctx)
1727 int source;
1728 update_global_sub_size(mpctx);
1729 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1730 return M_PROPERTY_UNAVAILABLE;
1732 switch (action) {
1733 case M_PROPERTY_GET:
1734 if (!arg)
1735 return M_PROPERTY_ERROR;
1736 *(int *) arg = sub_source(mpctx);
1737 return M_PROPERTY_OK;
1738 case M_PROPERTY_PRINT:
1739 if (!arg)
1740 return M_PROPERTY_ERROR;
1741 *(char **) arg = malloc(64);
1742 (*(char **) arg)[63] = 0;
1743 switch (sub_source(mpctx))
1745 case SUB_SOURCE_SUBS:
1746 snprintf(*(char **) arg, 63, mp_gtext("file"));
1747 break;
1748 case SUB_SOURCE_VOBSUB:
1749 snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
1750 break;
1751 case SUB_SOURCE_DEMUX:
1752 snprintf(*(char **) arg, 63, mp_gtext("embedded"));
1753 break;
1754 default:
1755 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1757 return M_PROPERTY_OK;
1758 case M_PROPERTY_SET:
1759 if (!arg)
1760 return M_PROPERTY_ERROR;
1761 M_PROPERTY_CLAMP(prop, *(int*)arg);
1762 if (*(int *) arg < 0)
1763 mpctx->global_sub_pos = -1;
1764 else if (*(int *) arg != sub_source(mpctx)) {
1765 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1766 if (new_pos == -1)
1767 return M_PROPERTY_UNAVAILABLE;
1768 mpctx->global_sub_pos = new_pos;
1770 break;
1771 case M_PROPERTY_STEP_UP:
1772 case M_PROPERTY_STEP_DOWN: {
1773 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1774 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1775 int step = (step_all > 0) ? 1 : -1;
1776 int cur_source = sub_source(mpctx);
1777 source = cur_source;
1778 while (step_all) {
1779 source += step;
1780 if (source >= SUB_SOURCES)
1781 source = -1;
1782 else if (source < -1)
1783 source = SUB_SOURCES - 1;
1784 if (source == cur_source || source == -1 ||
1785 mpctx->sub_counts[source])
1786 step_all -= step;
1788 if (source == cur_source)
1789 return M_PROPERTY_OK;
1790 if (source == -1)
1791 mpctx->global_sub_pos = -1;
1792 else
1793 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1794 break;
1796 default:
1797 return M_PROPERTY_NOT_IMPLEMENTED;
1799 --mpctx->global_sub_pos;
1800 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1803 /// Selected subtitles from specific source (RW)
1804 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1805 MPContext *mpctx)
1807 int source, is_cur_source, offset, new_pos;
1808 update_global_sub_size(mpctx);
1809 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1810 return M_PROPERTY_UNAVAILABLE;
1812 if (!strcmp(prop->name, "sub_file"))
1813 source = SUB_SOURCE_SUBS;
1814 else if (!strcmp(prop->name, "sub_vob"))
1815 source = SUB_SOURCE_VOBSUB;
1816 else if (!strcmp(prop->name, "sub_demux"))
1817 source = SUB_SOURCE_DEMUX;
1818 else
1819 return M_PROPERTY_ERROR;
1821 offset = sub_pos_by_source(mpctx, source);
1822 if (offset < 0)
1823 return M_PROPERTY_UNAVAILABLE;
1825 is_cur_source = sub_source(mpctx) == source;
1826 new_pos = mpctx->global_sub_pos;
1827 switch (action) {
1828 case M_PROPERTY_GET:
1829 if (!arg)
1830 return M_PROPERTY_ERROR;
1831 if (is_cur_source) {
1832 *(int *) arg = sub_source_pos(mpctx);
1833 if (source == SUB_SOURCE_VOBSUB)
1834 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1836 else
1837 *(int *) arg = -1;
1838 return M_PROPERTY_OK;
1839 case M_PROPERTY_PRINT:
1840 if (!arg)
1841 return M_PROPERTY_ERROR;
1842 if (is_cur_source)
1843 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1844 *(char **) arg = malloc(64);
1845 (*(char **) arg)[63] = 0;
1846 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1847 return M_PROPERTY_OK;
1848 case M_PROPERTY_SET:
1849 if (!arg)
1850 return M_PROPERTY_ERROR;
1851 if (*(int *) arg >= 0) {
1852 int index = *(int *)arg;
1853 if (source == SUB_SOURCE_VOBSUB)
1854 index = vobsub_get_index_by_id(vo_vobsub, index);
1855 new_pos = offset + index;
1856 if (index < 0 || index > mpctx->sub_counts[source]) {
1857 new_pos = -1;
1858 *(int *) arg = -1;
1861 else
1862 new_pos = -1;
1863 break;
1864 case M_PROPERTY_STEP_UP:
1865 case M_PROPERTY_STEP_DOWN: {
1866 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1867 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1868 int step = (step_all > 0) ? 1 : -1;
1869 int max_sub_pos_for_source = -1;
1870 if (!is_cur_source)
1871 new_pos = -1;
1872 while (step_all) {
1873 if (new_pos == -1) {
1874 if (step > 0)
1875 new_pos = offset;
1876 else if (max_sub_pos_for_source == -1) {
1877 // Find max pos for specific source
1878 new_pos = mpctx->global_sub_size - 1;
1879 while (new_pos >= 0
1880 && sub_source(mpctx) != source)
1881 new_pos--;
1883 else
1884 new_pos = max_sub_pos_for_source;
1886 else {
1887 new_pos += step;
1888 if (new_pos < offset ||
1889 new_pos >= mpctx->global_sub_size ||
1890 sub_source(mpctx) != source)
1891 new_pos = -1;
1893 step_all -= step;
1895 break;
1897 default:
1898 return M_PROPERTY_NOT_IMPLEMENTED;
1900 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1903 /// Subtitle delay (RW)
1904 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1905 MPContext *mpctx)
1907 if (!mpctx->sh_video)
1908 return M_PROPERTY_UNAVAILABLE;
1909 return m_property_delay(prop, action, arg, &sub_delay);
1912 /// Alignment of text subtitles (RW)
1913 static int mp_property_sub_alignment(m_option_t *prop, int action,
1914 void *arg, MPContext *mpctx)
1916 char *name[] = { _("top"), _("center"), _("bottom") };
1918 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1919 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1920 return M_PROPERTY_UNAVAILABLE;
1922 switch (action) {
1923 case M_PROPERTY_PRINT:
1924 if (!arg)
1925 return M_PROPERTY_ERROR;
1926 M_PROPERTY_CLAMP(prop, sub_alignment);
1927 *(char **) arg = strdup(mp_gtext(name[sub_alignment]));
1928 return M_PROPERTY_OK;
1929 case M_PROPERTY_SET:
1930 if (!arg)
1931 return M_PROPERTY_ERROR;
1932 case M_PROPERTY_STEP_UP:
1933 case M_PROPERTY_STEP_DOWN:
1934 vo_osd_changed(OSDTYPE_SUBTITLE);
1935 default:
1936 return m_property_choice(prop, action, arg, &sub_alignment);
1940 /// Subtitle visibility (RW)
1941 static int mp_property_sub_visibility(m_option_t *prop, int action,
1942 void *arg, MPContext *mpctx)
1944 if (!mpctx->sh_video)
1945 return M_PROPERTY_UNAVAILABLE;
1947 switch (action) {
1948 case M_PROPERTY_SET:
1949 if (!arg)
1950 return M_PROPERTY_ERROR;
1951 case M_PROPERTY_STEP_UP:
1952 case M_PROPERTY_STEP_DOWN:
1953 vo_osd_changed(OSDTYPE_SUBTITLE);
1954 if (vo_spudec)
1955 vo_osd_changed(OSDTYPE_SPU);
1956 default:
1957 return m_property_flag(prop, action, arg, &sub_visibility);
1961 #ifdef CONFIG_ASS
1962 /// Use margins for libass subtitles (RW)
1963 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1964 void *arg, MPContext *mpctx)
1966 if (!mpctx->sh_video)
1967 return M_PROPERTY_UNAVAILABLE;
1969 switch (action) {
1970 case M_PROPERTY_SET:
1971 if (!arg)
1972 return M_PROPERTY_ERROR;
1973 case M_PROPERTY_STEP_UP:
1974 case M_PROPERTY_STEP_DOWN:
1975 ass_force_reload = 1;
1976 default:
1977 return m_property_flag(prop, action, arg, &ass_use_margins);
1980 #endif
1982 /// Show only forced subtitles (RW)
1983 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1984 void *arg, MPContext *mpctx)
1986 if (!vo_spudec)
1987 return M_PROPERTY_UNAVAILABLE;
1989 switch (action) {
1990 case M_PROPERTY_SET:
1991 if (!arg)
1992 return M_PROPERTY_ERROR;
1993 case M_PROPERTY_STEP_UP:
1994 case M_PROPERTY_STEP_DOWN:
1995 m_property_flag(prop, action, arg, &forced_subs_only);
1996 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1997 return M_PROPERTY_OK;
1998 default:
1999 return m_property_flag(prop, action, arg, &forced_subs_only);
2004 #ifdef CONFIG_FREETYPE
2005 /// Subtitle scale (RW)
2006 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
2007 MPContext *mpctx)
2009 struct MPOpts *opts = &mpctx->opts;
2011 switch (action) {
2012 case M_PROPERTY_SET:
2013 if (!arg)
2014 return M_PROPERTY_ERROR;
2015 M_PROPERTY_CLAMP(prop, *(float *) arg);
2016 #ifdef CONFIG_ASS
2017 if (opts->ass_enabled) {
2018 ass_font_scale = *(float *) arg;
2019 ass_force_reload = 1;
2021 #endif
2022 text_font_scale_factor = *(float *) arg;
2023 force_load_font = 1;
2024 return M_PROPERTY_OK;
2025 case M_PROPERTY_STEP_UP:
2026 case M_PROPERTY_STEP_DOWN:
2027 #ifdef CONFIG_ASS
2028 if (opts->ass_enabled) {
2029 ass_font_scale += (arg ? *(float *) arg : 0.1)*
2030 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2031 M_PROPERTY_CLAMP(prop, ass_font_scale);
2032 ass_force_reload = 1;
2034 #endif
2035 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
2036 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2037 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
2038 force_load_font = 1;
2039 return M_PROPERTY_OK;
2040 default:
2041 #ifdef CONFIG_ASS
2042 if (opts->ass_enabled)
2043 return m_property_float_ro(prop, action, arg, ass_font_scale);
2044 else
2045 #endif
2046 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
2049 #endif
2051 ///@}
2053 /// \defgroup TVProperties TV properties
2054 /// \ingroup Properties
2055 ///@{
2057 #ifdef CONFIG_TV
2059 /// TV color settings (RW)
2060 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2061 MPContext *mpctx)
2063 int r, val;
2064 tvi_handle_t *tvh = mpctx->demuxer->priv;
2065 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2066 return M_PROPERTY_UNAVAILABLE;
2068 switch (action) {
2069 case M_PROPERTY_SET:
2070 if (!arg)
2071 return M_PROPERTY_ERROR;
2072 M_PROPERTY_CLAMP(prop, *(int *) arg);
2073 return tv_set_color_options(tvh, prop->offset, *(int *) arg);
2074 case M_PROPERTY_GET:
2075 return tv_get_color_options(tvh, prop->offset, arg);
2076 case M_PROPERTY_STEP_UP:
2077 case M_PROPERTY_STEP_DOWN:
2078 if ((r = tv_get_color_options(tvh, prop->offset, &val)) >= 0) {
2079 if (!r)
2080 return M_PROPERTY_ERROR;
2081 val += (arg ? *(int *) arg : 1) *
2082 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2083 M_PROPERTY_CLAMP(prop, val);
2084 return tv_set_color_options(tvh, prop->offset, val);
2086 return M_PROPERTY_ERROR;
2088 return M_PROPERTY_NOT_IMPLEMENTED;
2091 #endif
2093 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2094 MPContext *mpctx)
2096 int val,result;
2097 int base_ioctl = prop->offset;
2099 for teletext's GET,SET,STEP ioctls this is not 0
2100 SET is GET+1
2101 STEP is GET+2
2103 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2104 return M_PROPERTY_UNAVAILABLE;
2105 if(!base_ioctl)
2106 return M_PROPERTY_ERROR;
2108 switch (action) {
2109 case M_PROPERTY_GET:
2110 if (!arg)
2111 return M_PROPERTY_ERROR;
2112 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2113 break;
2114 case M_PROPERTY_SET:
2115 if (!arg)
2116 return M_PROPERTY_ERROR;
2117 M_PROPERTY_CLAMP(prop, *(int *) arg);
2118 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
2119 break;
2120 case M_PROPERTY_STEP_UP:
2121 case M_PROPERTY_STEP_DOWN:
2122 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2123 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2124 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
2125 break;
2126 default:
2127 return M_PROPERTY_NOT_IMPLEMENTED;
2130 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2133 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2134 MPContext *mpctx)
2136 int result;
2137 int val;
2139 //with tvh==NULL will fail too
2140 result=mp_property_teletext_common(prop,action,arg,mpctx);
2141 if(result!=M_PROPERTY_OK)
2142 return result;
2144 if(teletext_control(mpctx->demuxer->teletext,
2145 prop->offset, &val)==VBI_CONTROL_TRUE && val)
2146 mp_input_set_section(mpctx->input, "teletext");
2147 else
2148 mp_input_set_section(mpctx->input, "tv");
2149 return M_PROPERTY_OK;
2152 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2153 MPContext *mpctx)
2155 int result;
2156 int val;
2157 if (!mpctx->demuxer->teletext)
2158 return M_PROPERTY_UNAVAILABLE;
2159 switch(action){
2160 case M_PROPERTY_STEP_UP:
2161 case M_PROPERTY_STEP_DOWN:
2162 //This should be handled separately
2163 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2164 result=teletext_control(mpctx->demuxer->teletext,
2165 TV_VBI_CONTROL_STEP_PAGE, &val);
2166 break;
2167 default:
2168 result=mp_property_teletext_common(prop,action,arg,mpctx);
2170 return result;
2173 ///@}
2175 /// All properties available in MPlayer.
2176 /** \ingroup Properties
2178 static const m_option_t mp_properties[] = {
2179 // General
2180 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2181 M_OPT_RANGE, 0, 3, NULL },
2182 { "loop", mp_property_loop, CONF_TYPE_INT,
2183 M_OPT_MIN, -1, 0, NULL },
2184 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2185 M_OPT_RANGE, 0.01, 100.0, NULL },
2186 { "filename", mp_property_filename, CONF_TYPE_STRING,
2187 0, 0, 0, NULL },
2188 { "path", mp_property_path, CONF_TYPE_STRING,
2189 0, 0, 0, NULL },
2190 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2191 0, 0, 0, NULL },
2192 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2193 M_OPT_MIN, 0, 0, NULL },
2194 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2195 M_OPT_MIN, 0, 0, NULL },
2196 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2197 M_OPT_MIN, 0, 0, NULL },
2198 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2199 M_OPT_MIN, 0, 0, NULL },
2200 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2201 M_OPT_MIN, 0, 0, NULL },
2202 { "length", mp_property_length, CONF_TYPE_TIME,
2203 M_OPT_MIN, 0, 0, NULL },
2204 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2205 M_OPT_RANGE, 0, 100, NULL },
2206 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2207 M_OPT_MIN, 0, 0, NULL },
2208 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2209 M_OPT_MIN, 0, 0, NULL },
2210 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2211 0, 0, 0, NULL },
2212 { "angle", mp_property_angle, CONF_TYPE_INT,
2213 CONF_RANGE, -2, 10, NULL },
2214 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2215 0, 0, 0, NULL },
2216 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2217 M_OPT_RANGE, 0, 1, NULL },
2218 { "capturing", mp_property_capture, CONF_TYPE_FLAG,
2219 M_OPT_RANGE, 0, 1, NULL },
2220 { "pts_association_mode", mp_property_generic_option, &m_option_type_choice,
2221 0, 0, 0, "pts-association-mode" },
2222 { "hr_seek", mp_property_generic_option, &m_option_type_choice,
2223 0, 0, 0, "hr-seek" },
2225 // Audio
2226 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2227 M_OPT_RANGE, 0, 100, NULL },
2228 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2229 M_OPT_RANGE, 0, 1, NULL },
2230 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2231 M_OPT_RANGE, -100, 100, NULL },
2232 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2233 0, 0, 0, NULL },
2234 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2235 0, 0, 0, NULL },
2236 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2237 0, 0, 0, NULL },
2238 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2239 0, 0, 0, NULL },
2240 { "channels", mp_property_channels, CONF_TYPE_INT,
2241 0, 0, 0, NULL },
2242 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2243 CONF_RANGE, -2, 65535, NULL },
2244 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2245 M_OPT_RANGE, -1, 1, NULL },
2247 // Video
2248 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2249 M_OPT_RANGE, 0, 1, NULL },
2250 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2251 M_OPT_RANGE, 0, 1, NULL },
2252 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2253 M_OPT_RANGE, 0, 2, NULL },
2254 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2255 M_OPT_RANGE, 0, 1, NULL },
2256 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2257 M_OPT_RANGE, 0, 1, NULL },
2258 { "border", mp_property_border, CONF_TYPE_FLAG,
2259 M_OPT_RANGE, 0, 1, NULL },
2260 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2261 M_OPT_RANGE, 0, 2, NULL },
2262 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2263 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_gamma)},
2264 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2265 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_brightness) },
2266 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2267 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_contrast) },
2268 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2269 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_saturation) },
2270 { "hue", mp_property_gamma, CONF_TYPE_INT,
2271 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_hue) },
2272 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2273 M_OPT_RANGE, 0, 1, NULL },
2274 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2275 M_OPT_RANGE, 0, 1, NULL },
2276 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2277 0, 0, 0, NULL },
2278 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2279 0, 0, 0, NULL },
2280 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2281 0, 0, 0, NULL },
2282 { "width", mp_property_width, CONF_TYPE_INT,
2283 0, 0, 0, NULL },
2284 { "height", mp_property_height, CONF_TYPE_INT,
2285 0, 0, 0, NULL },
2286 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2287 0, 0, 0, NULL },
2288 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2289 0, 0, 0, NULL },
2290 { "switch_video", mp_property_video, CONF_TYPE_INT,
2291 CONF_RANGE, -2, 65535, NULL },
2292 { "switch_program", mp_property_program, CONF_TYPE_INT,
2293 CONF_RANGE, -1, 65535, NULL },
2295 // Subs
2296 { "sub", mp_property_sub, CONF_TYPE_INT,
2297 M_OPT_MIN, -1, 0, NULL },
2298 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2299 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2300 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2301 M_OPT_MIN, -1, 0, NULL },
2302 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2303 M_OPT_MIN, -1, 0, NULL },
2304 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2305 M_OPT_MIN, -1, 0, NULL },
2306 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2307 0, 0, 0, NULL },
2308 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2309 M_OPT_RANGE, 0, 100, NULL },
2310 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2311 M_OPT_RANGE, 0, 2, NULL },
2312 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2313 M_OPT_RANGE, 0, 1, NULL },
2314 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2315 M_OPT_RANGE, 0, 1, NULL },
2316 #ifdef CONFIG_FREETYPE
2317 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2318 M_OPT_RANGE, 0, 100, NULL },
2319 #endif
2320 #ifdef CONFIG_ASS
2321 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2322 M_OPT_RANGE, 0, 1, NULL },
2323 #endif
2325 #ifdef CONFIG_TV
2326 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2327 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_BRIGHTNESS },
2328 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2329 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_CONTRAST },
2330 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2331 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_SATURATION },
2332 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2333 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_HUE },
2334 #endif
2335 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2336 M_OPT_RANGE, 100, 899, .offset=TV_VBI_CONTROL_GET_PAGE },
2337 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2338 M_OPT_RANGE, 0, 64, .offset=TV_VBI_CONTROL_GET_SUBPAGE },
2339 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2340 M_OPT_RANGE, 0, 1, .offset=TV_VBI_CONTROL_GET_MODE },
2341 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2342 M_OPT_RANGE, 0, 3, .offset=TV_VBI_CONTROL_GET_FORMAT },
2343 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2344 M_OPT_RANGE, 0, 2, .offset=TV_VBI_CONTROL_GET_HALF_PAGE },
2345 { NULL, NULL, NULL, 0, 0, 0, NULL }
2349 int mp_property_do(const char *name, int action, void *val, void *ctx)
2351 return m_property_do(mp_properties, name, action, val, ctx);
2354 char* mp_property_print(const char *name, void* ctx)
2356 char* ret = NULL;
2357 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2358 return NULL;
2359 return ret;
2362 char *property_expand_string(MPContext *mpctx, char *str)
2364 return m_properties_expand_string(mp_properties, str, mpctx);
2367 void property_print_help(void)
2369 m_properties_print_help_list(mp_properties);
2373 /* List of default ways to show a property on OSD.
2375 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2376 * a bar showing the current position between min/max values of the
2377 * property. In this case osd_msg is only used for terminal output
2378 * if there is no video; it'll be a label shown together with percentage.
2380 * Otherwise setting osd_msg will show the string on OSD, formatted with
2381 * the text value of the property as argument.
2383 static struct property_osd_display {
2384 /// property name
2385 const char *name;
2386 /// progressbar type
2387 int osd_progbar; // -1 is special value for seek indicators
2388 /// osd msg id if it must be shared
2389 int osd_id;
2390 /// osd msg template
2391 const char *osd_msg;
2392 } property_osd_display[] = {
2393 // general
2394 { "loop", 0, -1, _("Loop: %s") },
2395 { "chapter", -1, -1, NULL },
2396 { "capturing", 0, -1, _("Capturing: %s") },
2397 { "pts_association_mode", 0, -1, "PTS association mode: %s" },
2398 { "hr_seek", 0, -1, "hr-seek: %s" },
2399 // audio
2400 { "volume", OSD_VOLUME, -1, _("Volume") },
2401 { "mute", 0, -1, _("Mute: %s") },
2402 { "audio_delay", 0, -1, _("A-V delay: %s") },
2403 { "switch_audio", 0, -1, _("Audio: %s") },
2404 { "balance", OSD_BALANCE, -1, _("Balance") },
2405 // video
2406 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2407 { "ontop", 0, -1, _("Stay on top: %s") },
2408 { "rootwin", 0, -1, _("Rootwin: %s") },
2409 { "border", 0, -1, _("Border: %s") },
2410 { "framedropping", 0, -1, _("Framedropping: %s") },
2411 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2412 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2413 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2414 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2415 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2416 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2417 { "hue", OSD_HUE, -1, _("Hue") },
2418 { "vsync", 0, -1, _("VSync: %s") },
2419 // subs
2420 { "sub", 0, -1, _("Subtitles: %s") },
2421 { "sub_source", 0, -1, _("Sub source: %s") },
2422 { "sub_vob", 0, -1, _("Subtitles: %s") },
2423 { "sub_demux", 0, -1, _("Subtitles: %s") },
2424 { "sub_file", 0, -1, _("Subtitles: %s") },
2425 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2426 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2427 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2428 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2429 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2430 #ifdef CONFIG_FREETYPE
2431 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2432 #endif
2433 #ifdef CONFIG_TV
2434 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2435 { "tv_hue", OSD_HUE, -1, _("Hue") },
2436 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2437 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2438 #endif
2442 static int show_property_osd(MPContext *mpctx, const char *pname)
2444 struct MPOpts *opts = &mpctx->opts;
2445 int r;
2446 m_option_t* prop;
2447 struct property_osd_display *p;
2449 // look for the command
2450 for (p = property_osd_display; p->name; p++)
2451 if (!strcmp(p->name, pname))
2452 break;
2453 if (!p->name)
2454 return -1;
2456 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2457 return -1;
2459 if (p->osd_progbar == -1)
2460 mpctx->add_osd_seek_info = true;
2461 else if (p->osd_progbar) {
2462 if (prop->type == CONF_TYPE_INT) {
2463 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2464 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2465 prop->min, prop->max, r);
2466 } else if (prop->type == CONF_TYPE_FLOAT) {
2467 float f;
2468 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2469 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2470 prop->min, prop->max, f);
2471 } else {
2472 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2473 "Property use an unsupported type.\n");
2474 return -1;
2476 return 0;
2479 if (p->osd_msg) {
2480 char *val = mp_property_print(pname, mpctx);
2481 if (val) {
2482 int index = p - property_osd_display;
2483 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2484 1, opts->osd_duration, p->osd_msg, val);
2485 free(val);
2488 return 0;
2493 * \defgroup Command2Property Command to property bridge
2495 * It is used to handle most commands that just set a property
2496 * and optionally display something on the OSD.
2497 * Two kinds of commands are handled: adjust or toggle.
2499 * Adjust commands take 1 or 2 parameters: <value> <abs>
2500 * If <abs> is non-zero the property is set to the given value
2501 * otherwise it is adjusted.
2503 * Toggle commands take 0 or 1 parameters. With no parameter
2504 * or a value less than the property minimum it just steps the
2505 * property to its next value. Otherwise it sets it to the given
2506 * value.
2511 /// List of the commands that can be handled by setting a property.
2512 static struct {
2513 /// property name
2514 const char *name;
2515 /// cmd id
2516 int cmd;
2517 /// set/adjust or toggle command
2518 int toggle;
2519 } set_prop_cmd[] = {
2520 // general
2521 { "loop", MP_CMD_LOOP, 0},
2522 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2523 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2524 { "pause", MP_CMD_PAUSE, 0},
2525 { "capturing", MP_CMD_CAPTURING, 1},
2526 // audio
2527 { "volume", MP_CMD_VOLUME, 0},
2528 { "mute", MP_CMD_MUTE, 1},
2529 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2530 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2531 { "balance", MP_CMD_BALANCE, 0},
2532 // video
2533 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2534 { "panscan", MP_CMD_PANSCAN, 0},
2535 { "ontop", MP_CMD_VO_ONTOP, 1},
2536 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2537 { "border", MP_CMD_VO_BORDER, 1},
2538 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2539 { "gamma", MP_CMD_GAMMA, 0},
2540 { "brightness", MP_CMD_BRIGHTNESS, 0},
2541 { "contrast", MP_CMD_CONTRAST, 0},
2542 { "saturation", MP_CMD_SATURATION, 0},
2543 { "hue", MP_CMD_HUE, 0},
2544 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2545 // subs
2546 { "sub", MP_CMD_SUB_SELECT, 1},
2547 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2548 { "sub_vob", MP_CMD_SUB_VOB, 1},
2549 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2550 { "sub_file", MP_CMD_SUB_FILE, 1},
2551 { "sub_pos", MP_CMD_SUB_POS, 0},
2552 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2553 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2554 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2555 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2556 #ifdef CONFIG_FREETYPE
2557 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2558 #endif
2559 #ifdef CONFIG_ASS
2560 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2561 #endif
2562 #ifdef CONFIG_TV
2563 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2564 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2565 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2566 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2567 #endif
2571 /// Handle commands that set a property.
2572 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2574 int i, r;
2575 m_option_t *prop;
2576 const char *pname;
2578 // look for the command
2579 for (i = 0; set_prop_cmd[i].name; i++)
2580 if (set_prop_cmd[i].cmd == cmd->id)
2581 break;
2582 if (!(pname = set_prop_cmd[i].name))
2583 return 0;
2585 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2586 return 0;
2588 // toggle command
2589 if (set_prop_cmd[i].toggle) {
2590 // set to value
2591 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2592 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2593 else
2594 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2595 } else if (cmd->args[1].v.i) //set
2596 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2597 else // adjust
2598 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2600 if (r <= 0)
2601 return 1;
2603 show_property_osd(mpctx, pname);
2605 return 1;
2608 #ifdef CONFIG_DVDNAV
2609 static const struct {
2610 const char *name;
2611 const mp_command_type cmd;
2612 } mp_dvdnav_bindings[] = {
2613 { "up", MP_CMD_DVDNAV_UP },
2614 { "down", MP_CMD_DVDNAV_DOWN },
2615 { "left", MP_CMD_DVDNAV_LEFT },
2616 { "right", MP_CMD_DVDNAV_RIGHT },
2617 { "menu", MP_CMD_DVDNAV_MENU },
2618 { "select", MP_CMD_DVDNAV_SELECT },
2619 { "prev", MP_CMD_DVDNAV_PREVMENU },
2620 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2623 * keep old dvdnav sub-command options for a while in order not to
2624 * break slave-mode API too suddenly.
2626 { "1", MP_CMD_DVDNAV_UP },
2627 { "2", MP_CMD_DVDNAV_DOWN },
2628 { "3", MP_CMD_DVDNAV_LEFT },
2629 { "4", MP_CMD_DVDNAV_RIGHT },
2630 { "5", MP_CMD_DVDNAV_MENU },
2631 { "6", MP_CMD_DVDNAV_SELECT },
2632 { "7", MP_CMD_DVDNAV_PREVMENU },
2633 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2634 { NULL, 0 }
2636 #endif
2638 static const char *property_error_string(int error_value)
2640 switch (error_value) {
2641 case M_PROPERTY_ERROR:
2642 return "ERROR";
2643 case M_PROPERTY_UNAVAILABLE:
2644 return "PROPERTY_UNAVAILABLE";
2645 case M_PROPERTY_NOT_IMPLEMENTED:
2646 return "NOT_IMPLEMENTED";
2647 case M_PROPERTY_UNKNOWN:
2648 return "PROPERTY_UNKNOWN";
2649 case M_PROPERTY_DISABLED:
2650 return "DISABLED";
2652 return "UNKNOWN";
2655 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2657 int idx;
2658 int end = start + count;
2659 int after = mpctx->set_of_sub_size - end;
2660 sub_data **subs = mpctx->set_of_subtitles;
2661 #ifdef CONFIG_ASS
2662 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2663 #endif
2664 if (count < 0 || count > mpctx->set_of_sub_size ||
2665 start < 0 || start > mpctx->set_of_sub_size - count) {
2666 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2667 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2668 return;
2670 for (idx = start; idx < end; idx++) {
2671 sub_data *subd = subs[idx];
2672 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2673 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2674 filename_recode(subd->filename));
2675 sub_free(subd);
2676 subs[idx] = NULL;
2677 #ifdef CONFIG_ASS
2678 if (ass_tracks[idx])
2679 ass_free_track(ass_tracks[idx]);
2680 ass_tracks[idx] = NULL;
2681 #endif
2684 mpctx->global_sub_size -= count;
2685 mpctx->set_of_sub_size -= count;
2686 if (mpctx->set_of_sub_size <= 0)
2687 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2689 memmove(subs + start, subs + end, after * sizeof(*subs));
2690 memset(subs + start + after, 0, count * sizeof(*subs));
2691 #ifdef CONFIG_ASS
2692 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2693 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2694 #endif
2696 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2697 mpctx->global_sub_pos = -2;
2698 subdata = NULL;
2699 #ifdef CONFIG_ASS
2700 ass_track = NULL;
2701 #endif
2702 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2703 } else if (mpctx->set_of_sub_pos >= end) {
2704 mpctx->set_of_sub_pos -= count;
2705 mpctx->global_sub_pos -= count;
2709 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2711 struct MPOpts *opts = &mpctx->opts;
2712 sh_audio_t * const sh_audio = mpctx->sh_audio;
2713 sh_video_t * const sh_video = mpctx->sh_video;
2714 int osd_duration = opts->osd_duration;
2715 int case_fallthrough_hack = 0;
2716 if (!set_property_command(mpctx, cmd))
2717 switch (cmd->id) {
2718 case MP_CMD_SEEK:{
2719 mpctx->add_osd_seek_info = true;
2720 float v = cmd->args[0].v.f;
2721 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2722 int exact = (cmd->nargs > 2) ? cmd->args[2].v.i : 0;
2723 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2724 queue_seek(mpctx, MPSEEK_ABSOLUTE, v, exact);
2725 mpctx->osd_function = v > get_current_time(mpctx) ?
2726 OSD_FFW : OSD_REW;
2727 } else if (abs) { /* Absolute seek by percentage */
2728 queue_seek(mpctx, MPSEEK_FACTOR, v / 100.0, exact);
2729 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2730 } else {
2731 queue_seek(mpctx, MPSEEK_RELATIVE, v, exact);
2732 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2735 break;
2737 case MP_CMD_SET_PROPERTY_OSD:
2738 case_fallthrough_hack = 1;
2740 case MP_CMD_SET_PROPERTY:{
2741 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2742 cmd->args[1].v.s, mpctx);
2743 if (r == M_PROPERTY_UNKNOWN)
2744 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2745 "Unknown property: '%s'\n", cmd->args[0].v.s);
2746 else if (r <= 0)
2747 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2748 "Failed to set property '%s' to '%s'.\n",
2749 cmd->args[0].v.s, cmd->args[1].v.s);
2750 else if (case_fallthrough_hack)
2751 show_property_osd(mpctx, cmd->args[0].v.s);
2752 if (r <= 0)
2753 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2755 break;
2757 case MP_CMD_STEP_PROPERTY_OSD:
2758 case_fallthrough_hack = 1;
2760 case MP_CMD_STEP_PROPERTY:{
2761 void* arg = NULL;
2762 int r,i;
2763 double d;
2764 off_t o;
2765 if (cmd->args[1].v.f) {
2766 m_option_t* prop;
2767 if((r = mp_property_do(cmd->args[0].v.s,
2768 M_PROPERTY_GET_TYPE,
2769 &prop, mpctx)) <= 0)
2770 goto step_prop_err;
2771 if(prop->type == CONF_TYPE_INT ||
2772 prop->type == CONF_TYPE_FLAG)
2773 i = cmd->args[1].v.f, arg = &i;
2774 else if(prop->type == CONF_TYPE_FLOAT)
2775 arg = &cmd->args[1].v.f;
2776 else if(prop->type == CONF_TYPE_DOUBLE ||
2777 prop->type == CONF_TYPE_TIME)
2778 d = cmd->args[1].v.f, arg = &d;
2779 else if(prop->type == CONF_TYPE_POSITION)
2780 o = cmd->args[1].v.f, arg = &o;
2781 else
2782 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2783 "Ignoring step size stepping property '%s'.\n",
2784 cmd->args[0].v.s);
2786 r = mp_property_do(cmd->args[0].v.s,
2787 cmd->args[2].v.i < 0 ?
2788 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2789 arg, mpctx);
2790 step_prop_err:
2791 if (r == M_PROPERTY_UNKNOWN)
2792 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2793 "Unknown property: '%s'\n", cmd->args[0].v.s);
2794 else if (r <= 0)
2795 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2796 "Failed to increment property '%s' by %f.\n",
2797 cmd->args[0].v.s, cmd->args[1].v.f);
2798 else if (case_fallthrough_hack)
2799 show_property_osd(mpctx, cmd->args[0].v.s);
2800 if (r <= 0)
2801 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2803 break;
2805 case MP_CMD_GET_PROPERTY:{
2806 char *tmp;
2807 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2808 &tmp, mpctx);
2809 if (r <= 0) {
2810 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2811 "Failed to get value of property '%s'.\n",
2812 cmd->args[0].v.s);
2813 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2814 break;
2816 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2817 cmd->args[0].v.s, tmp);
2818 free(tmp);
2820 break;
2822 case MP_CMD_EDL_MARK:
2823 if (edl_fd) {
2824 float v = get_current_time(mpctx);
2825 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2826 mpctx->begin_skip = v;
2827 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2828 } else {
2829 if (mpctx->begin_skip > v)
2830 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2831 else {
2832 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2833 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2835 mpctx->begin_skip = MP_NOPTS_VALUE;
2838 break;
2840 case MP_CMD_SWITCH_RATIO:
2841 if (!sh_video)
2842 break;
2843 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2844 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2845 else
2846 opts->movie_aspect = cmd->args[0].v.f;
2847 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2848 break;
2850 case MP_CMD_SPEED_INCR:{
2851 float v = cmd->args[0].v.f;
2852 opts->playback_speed += v;
2853 build_afilter_chain(mpctx, sh_audio, &ao_data);
2854 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2855 opts->playback_speed);
2856 } break;
2858 case MP_CMD_SPEED_MULT:{
2859 float v = cmd->args[0].v.f;
2860 opts->playback_speed *= v;
2861 build_afilter_chain(mpctx, sh_audio, &ao_data);
2862 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2863 opts->playback_speed);
2864 } break;
2866 case MP_CMD_SPEED_SET:{
2867 float v = cmd->args[0].v.f;
2868 opts->playback_speed = v;
2869 build_afilter_chain(mpctx, sh_audio, &ao_data);
2870 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2871 opts->playback_speed);
2872 } break;
2874 case MP_CMD_FRAME_STEP:
2875 add_step_frame(mpctx);
2876 break;
2878 case MP_CMD_FILE_FILTER:
2879 file_filter = cmd->args[0].v.i;
2880 break;
2882 case MP_CMD_QUIT:
2883 exit_player_with_rc(mpctx, EXIT_QUIT,
2884 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2886 case MP_CMD_PLAY_TREE_STEP:{
2887 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2888 int force = cmd->args[1].v.i;
2891 if (!force && mpctx->playtree_iter) {
2892 play_tree_iter_t *i =
2893 play_tree_iter_new_copy(mpctx->playtree_iter);
2894 if (play_tree_iter_step(i, n, 0) ==
2895 PLAY_TREE_ITER_ENTRY)
2896 mpctx->stop_play =
2897 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2898 play_tree_iter_free(i);
2899 } else
2900 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2901 if (mpctx->stop_play)
2902 mpctx->play_tree_step = n;
2905 break;
2907 case MP_CMD_PLAY_TREE_UP_STEP:{
2908 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2909 int force = cmd->args[1].v.i;
2911 if (!force && mpctx->playtree_iter) {
2912 play_tree_iter_t *i =
2913 play_tree_iter_new_copy(mpctx->playtree_iter);
2914 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2915 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2916 play_tree_iter_free(i);
2917 } else
2918 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2920 break;
2922 case MP_CMD_PLAY_ALT_SRC_STEP:
2923 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2924 int v = cmd->args[0].v.i;
2925 if (v > 0
2926 && mpctx->playtree_iter->file <
2927 mpctx->playtree_iter->num_files)
2928 mpctx->stop_play = PT_NEXT_SRC;
2929 else if (v < 0 && mpctx->playtree_iter->file > 1)
2930 mpctx->stop_play = PT_PREV_SRC;
2932 break;
2934 case MP_CMD_SUB_STEP:
2935 if (sh_video) {
2936 int movement = cmd->args[0].v.i;
2937 step_sub(subdata, mpctx->video_pts, movement);
2938 #ifdef CONFIG_ASS
2939 if (ass_track)
2940 sub_delay +=
2941 ass_step_sub(ass_track,
2942 (mpctx->video_pts +
2943 sub_delay) * 1000 + .5, movement) / 1000.;
2944 #endif
2945 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2946 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2948 break;
2950 case MP_CMD_SUB_LOG:
2951 log_sub(mpctx);
2952 break;
2954 case MP_CMD_OSD:{
2955 int v = cmd->args[0].v.i;
2956 int max = (opts->term_osd
2957 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2958 if (opts->osd_level > max)
2959 opts->osd_level = max;
2960 if (v < 0)
2961 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2962 else
2963 opts->osd_level = v > max ? max : v;
2964 /* Show OSD state when disabled, but not when an explicit
2965 argument is given to the OSD command, i.e. in slave mode. */
2966 if (v == -1 && opts->osd_level <= 1)
2967 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2968 "OSD: %s",
2969 opts->osd_level ? mp_gtext("enabled") :
2970 mp_gtext("disabled"));
2971 else
2972 rm_osd_msg(OSD_MSG_OSD_STATUS);
2974 break;
2976 case MP_CMD_OSD_SHOW_TEXT:
2977 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2978 (cmd->args[1].v.i <
2979 0 ? osd_duration : cmd->args[1].v.i),
2980 "%-.63s", cmd->args[0].v.s);
2981 break;
2983 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2984 char *txt = m_properties_expand_string(mp_properties,
2985 cmd->args[0].v.s,
2986 mpctx);
2987 /* if no argument supplied take default osd_duration, else <arg> ms. */
2988 if (txt) {
2989 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2990 (cmd->args[1].v.i <
2991 0 ? osd_duration : cmd->args[1].v.i),
2992 "%-.63s", txt);
2993 free(txt);
2996 break;
2998 case MP_CMD_LOADFILE:{
2999 play_tree_t *e = play_tree_new();
3000 play_tree_add_file(e, cmd->args[0].v.s);
3002 if (cmd->args[1].v.i) // append
3003 play_tree_append_entry(mpctx->playtree->child, e);
3004 else {
3005 // Go back to the starting point.
3006 while (play_tree_iter_up_step
3007 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3008 /* NOP */ ;
3009 play_tree_free_list(mpctx->playtree->child, 1);
3010 play_tree_set_child(mpctx->playtree, e);
3011 pt_iter_goto_head(mpctx->playtree_iter);
3012 mpctx->stop_play = PT_NEXT_SRC;
3015 break;
3017 case MP_CMD_LOADLIST:{
3018 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
3019 if (!e)
3020 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
3021 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
3022 else {
3023 if (cmd->args[1].v.i) // append
3024 play_tree_append_entry(mpctx->playtree->child, e);
3025 else {
3026 // Go back to the starting point.
3027 while (play_tree_iter_up_step
3028 (mpctx->playtree_iter, 0, 1)
3029 != PLAY_TREE_ITER_END)
3030 /* NOP */ ;
3031 play_tree_free_list(mpctx->playtree->child, 1);
3032 play_tree_set_child(mpctx->playtree, e);
3033 pt_iter_goto_head(mpctx->playtree_iter);
3034 mpctx->stop_play = PT_NEXT_SRC;
3038 break;
3040 case MP_CMD_STOP:
3041 // Go back to the starting point.
3042 while (play_tree_iter_up_step
3043 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3044 /* NOP */ ;
3045 mpctx->stop_play = PT_STOP;
3046 break;
3048 case MP_CMD_OSD_SHOW_PROGRESSION:{
3049 int len = get_time_length(mpctx);
3050 int pts = get_current_time(mpctx);
3051 set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3052 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3053 "%c %02d:%02d:%02d / %02d:%02d:%02d",
3054 mpctx->osd_function, pts/3600, (pts/60)%60, pts%60,
3055 len/3600, (len/60)%60, len%60);
3057 break;
3059 #ifdef CONFIG_RADIO
3060 case MP_CMD_RADIO_STEP_CHANNEL:
3061 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3062 int v = cmd->args[0].v.i;
3063 if (v > 0)
3064 radio_step_channel(mpctx->demuxer->stream,
3065 RADIO_CHANNEL_HIGHER);
3066 else
3067 radio_step_channel(mpctx->demuxer->stream,
3068 RADIO_CHANNEL_LOWER);
3069 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3070 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3071 "Channel: %s",
3072 radio_get_channel_name(mpctx->demuxer->stream));
3075 break;
3077 case MP_CMD_RADIO_SET_CHANNEL:
3078 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3079 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3080 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3081 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3082 "Channel: %s",
3083 radio_get_channel_name(mpctx->demuxer->stream));
3086 break;
3088 case MP_CMD_RADIO_SET_FREQ:
3089 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3090 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3091 break;
3093 case MP_CMD_RADIO_STEP_FREQ:
3094 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3095 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3096 break;
3097 #endif
3099 #ifdef CONFIG_TV
3100 case MP_CMD_TV_START_SCAN:
3101 if (mpctx->file_format == DEMUXER_TYPE_TV)
3102 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
3103 break;
3104 case MP_CMD_TV_SET_FREQ:
3105 if (mpctx->file_format == DEMUXER_TYPE_TV)
3106 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3107 cmd->args[0].v.f * 16.0);
3108 #ifdef CONFIG_PVR
3109 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3110 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
3111 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3112 pvr_get_current_channelname (mpctx->stream),
3113 pvr_get_current_stationname (mpctx->stream));
3115 #endif /* CONFIG_PVR */
3116 break;
3118 case MP_CMD_TV_STEP_FREQ:
3119 if (mpctx->file_format == DEMUXER_TYPE_TV)
3120 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3121 cmd->args[0].v.f * 16.0);
3122 #ifdef CONFIG_PVR
3123 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3124 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
3125 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3126 pvr_get_current_channelname (mpctx->stream),
3127 pvr_get_current_frequency (mpctx->stream));
3129 #endif /* CONFIG_PVR */
3130 break;
3132 case MP_CMD_TV_SET_NORM:
3133 if (mpctx->file_format == DEMUXER_TYPE_TV)
3134 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3135 cmd->args[0].v.s);
3136 break;
3138 case MP_CMD_TV_STEP_CHANNEL:{
3139 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3140 int v = cmd->args[0].v.i;
3141 if (v > 0) {
3142 tv_step_channel((tvi_handle_t *) (mpctx->
3143 demuxer->priv),
3144 TV_CHANNEL_HIGHER);
3145 } else {
3146 tv_step_channel((tvi_handle_t *) (mpctx->
3147 demuxer->priv),
3148 TV_CHANNEL_LOWER);
3150 if (tv_channel_list) {
3151 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3152 "Channel: %s", tv_channel_current->name);
3153 //vo_osd_changed(OSDTYPE_SUBTITLE);
3156 #ifdef CONFIG_PVR
3157 else if (mpctx->stream &&
3158 mpctx->stream->type == STREAMTYPE_PVR) {
3159 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3160 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3161 pvr_get_current_channelname (mpctx->stream),
3162 pvr_get_current_stationname (mpctx->stream));
3164 #endif /* CONFIG_PVR */
3166 #ifdef CONFIG_DVBIN
3167 if (mpctx->stream->type == STREAMTYPE_DVB) {
3168 int dir;
3169 int v = cmd->args[0].v.i;
3171 mpctx->last_dvb_step = v;
3172 if (v > 0)
3173 dir = DVB_CHANNEL_HIGHER;
3174 else
3175 dir = DVB_CHANNEL_LOWER;
3178 if (dvb_step_channel(mpctx->stream, dir)) {
3179 mpctx->stop_play = PT_NEXT_ENTRY;
3180 mpctx->dvbin_reopen = 1;
3183 #endif /* CONFIG_DVBIN */
3184 break;
3186 case MP_CMD_TV_SET_CHANNEL:
3187 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3188 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3189 cmd->args[0].v.s);
3190 if (tv_channel_list) {
3191 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3192 "Channel: %s", tv_channel_current->name);
3193 //vo_osd_changed(OSDTYPE_SUBTITLE);
3196 #ifdef CONFIG_PVR
3197 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3198 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3199 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3200 pvr_get_current_channelname (mpctx->stream),
3201 pvr_get_current_stationname (mpctx->stream));
3203 #endif /* CONFIG_PVR */
3204 break;
3206 #ifdef CONFIG_DVBIN
3207 case MP_CMD_DVB_SET_CHANNEL:
3208 if (mpctx->stream->type == STREAMTYPE_DVB) {
3209 mpctx->last_dvb_step = 1;
3211 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3212 cmd->args[0].v.i)) {
3213 mpctx->stop_play = PT_NEXT_ENTRY;
3214 mpctx->dvbin_reopen = 1;
3217 break;
3218 #endif /* CONFIG_DVBIN */
3220 case MP_CMD_TV_LAST_CHANNEL:
3221 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3222 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3223 if (tv_channel_list) {
3224 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3225 "Channel: %s", tv_channel_current->name);
3226 //vo_osd_changed(OSDTYPE_SUBTITLE);
3229 #ifdef CONFIG_PVR
3230 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3231 pvr_set_lastchannel (mpctx->stream);
3232 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3233 pvr_get_current_channelname (mpctx->stream),
3234 pvr_get_current_stationname (mpctx->stream));
3236 #endif /* CONFIG_PVR */
3237 break;
3239 case MP_CMD_TV_STEP_NORM:
3240 if (mpctx->file_format == DEMUXER_TYPE_TV)
3241 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3242 break;
3244 case MP_CMD_TV_STEP_CHANNEL_LIST:
3245 if (mpctx->file_format == DEMUXER_TYPE_TV)
3246 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3247 break;
3248 #endif /* CONFIG_TV */
3249 case MP_CMD_TV_TELETEXT_ADD_DEC:
3250 if (mpctx->demuxer->teletext)
3251 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3252 &(cmd->args[0].v.s));
3253 break;
3254 case MP_CMD_TV_TELETEXT_GO_LINK:
3255 if (mpctx->demuxer->teletext)
3256 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3257 &(cmd->args[0].v.i));
3258 break;
3260 case MP_CMD_SUB_LOAD:
3261 if (sh_video) {
3262 int n = mpctx->set_of_sub_size;
3263 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3264 if (n != mpctx->set_of_sub_size) {
3265 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3266 ++mpctx->global_sub_size;
3269 break;
3271 case MP_CMD_SUB_REMOVE:
3272 if (sh_video) {
3273 int v = cmd->args[0].v.i;
3274 if (v < 0) {
3275 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3276 } else if (v < mpctx->set_of_sub_size) {
3277 remove_subtitle_range(mpctx, v, 1);
3280 break;
3282 case MP_CMD_GET_SUB_VISIBILITY:
3283 if (sh_video) {
3284 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3285 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3287 break;
3289 case MP_CMD_SCREENSHOT:
3290 if (mpctx->video_out && mpctx->video_out->config_ok) {
3291 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3292 if (CONTROL_OK !=
3293 ((vf_instance_t *) sh_video->vfilter)->
3294 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3295 &cmd->args[0].v.i))
3296 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3298 break;
3300 case MP_CMD_VF_CHANGE_RECTANGLE:
3301 if (!sh_video)
3302 break;
3303 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3304 break;
3306 case MP_CMD_GET_TIME_LENGTH:{
3307 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3308 get_time_length(mpctx));
3310 break;
3312 case MP_CMD_GET_FILENAME:{
3313 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3314 get_metadata(mpctx, META_NAME));
3316 break;
3318 case MP_CMD_GET_VIDEO_CODEC:{
3319 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3320 if (!inf)
3321 inf = strdup("");
3322 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3323 free(inf);
3325 break;
3327 case MP_CMD_GET_VIDEO_BITRATE:{
3328 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3329 if (!inf)
3330 inf = strdup("");
3331 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3332 free(inf);
3334 break;
3336 case MP_CMD_GET_VIDEO_RESOLUTION:{
3337 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3338 if (!inf)
3339 inf = strdup("");
3340 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3341 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3342 free(inf);
3344 break;
3346 case MP_CMD_GET_AUDIO_CODEC:{
3347 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3348 if (!inf)
3349 inf = strdup("");
3350 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3351 free(inf);
3353 break;
3355 case MP_CMD_GET_AUDIO_BITRATE:{
3356 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3357 if (!inf)
3358 inf = strdup("");
3359 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3360 free(inf);
3362 break;
3364 case MP_CMD_GET_AUDIO_SAMPLES:{
3365 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3366 if (!inf)
3367 inf = strdup("");
3368 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3369 free(inf);
3371 break;
3373 case MP_CMD_GET_META_TITLE:{
3374 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3375 if (!inf)
3376 inf = strdup("");
3377 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3378 free(inf);
3380 break;
3382 case MP_CMD_GET_META_ARTIST:{
3383 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3384 if (!inf)
3385 inf = strdup("");
3386 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3387 free(inf);
3389 break;
3391 case MP_CMD_GET_META_ALBUM:{
3392 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3393 if (!inf)
3394 inf = strdup("");
3395 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3396 free(inf);
3398 break;
3400 case MP_CMD_GET_META_YEAR:{
3401 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3402 if (!inf)
3403 inf = strdup("");
3404 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3405 free(inf);
3407 break;
3409 case MP_CMD_GET_META_COMMENT:{
3410 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3411 if (!inf)
3412 inf = strdup("");
3413 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3414 free(inf);
3416 break;
3418 case MP_CMD_GET_META_TRACK:{
3419 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3420 if (!inf)
3421 inf = strdup("");
3422 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3423 free(inf);
3425 break;
3427 case MP_CMD_GET_META_GENRE:{
3428 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3429 if (!inf)
3430 inf = strdup("");
3431 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3432 free(inf);
3434 break;
3436 case MP_CMD_GET_VO_FULLSCREEN:
3437 if (mpctx->video_out && mpctx->video_out->config_ok)
3438 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3439 break;
3441 case MP_CMD_GET_PERCENT_POS:
3442 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3443 get_percent_pos(mpctx));
3444 break;
3446 case MP_CMD_GET_TIME_POS:{
3447 float pos = get_current_time(mpctx);
3448 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3450 break;
3452 case MP_CMD_RUN:
3453 #ifndef __MINGW32__
3454 if (!fork()) {
3455 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3456 exit(0);
3458 #endif
3459 break;
3461 case MP_CMD_KEYDOWN_EVENTS:
3462 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3463 break;
3465 case MP_CMD_SET_MOUSE_POS:{
3466 int pointer_x, pointer_y;
3467 double dx, dy;
3468 pointer_x = cmd->args[0].v.i;
3469 pointer_y = cmd->args[1].v.i;
3470 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3471 #ifdef CONFIG_DVDNAV
3472 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3473 && dx > 0.0 && dy > 0.0) {
3474 int button = -1;
3475 pointer_x = (int) (dx * (double) sh_video->disp_w);
3476 pointer_y = (int) (dy * (double) sh_video->disp_h);
3477 mp_dvdnav_update_mouse_pos(mpctx->stream,
3478 pointer_x, pointer_y, &button);
3479 if (opts->osd_level > 1 && button > 0)
3480 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3481 "Selected button number %d", button);
3483 #endif
3484 #ifdef CONFIG_MENU
3485 if (use_menu && dx >= 0.0 && dy >= 0.0)
3486 menu_update_mouse_pos(dx, dy);
3487 #endif
3489 break;
3491 #ifdef CONFIG_DVDNAV
3492 case MP_CMD_DVDNAV:{
3493 int button = -1;
3494 int i;
3495 mp_command_type command = 0;
3496 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3497 break;
3499 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3500 if (cmd->args[0].v.s &&
3501 !strcasecmp (cmd->args[0].v.s,
3502 mp_dvdnav_bindings[i].name))
3503 command = mp_dvdnav_bindings[i].cmd;
3505 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3506 if (opts->osd_level > 1 && button > 0)
3507 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3508 "Selected button number %d", button);
3510 break;
3512 case MP_CMD_SWITCH_TITLE:
3513 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3514 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3515 break;
3517 #endif
3519 case MP_CMD_AF_SWITCH:
3520 if (sh_audio)
3522 af_uninit(mpctx->mixer.afilter);
3523 af_init(mpctx->mixer.afilter);
3525 case MP_CMD_AF_ADD:
3526 case MP_CMD_AF_DEL:
3527 if (!sh_audio)
3528 break;
3530 char* af_args = strdup(cmd->args[0].v.s);
3531 char* af_commands = af_args;
3532 char* af_command;
3533 af_instance_t* af;
3534 while ((af_command = strsep(&af_commands, ",")) != NULL)
3536 if (cmd->id == MP_CMD_AF_DEL)
3538 af = af_get(mpctx->mixer.afilter, af_command);
3539 if (af != NULL)
3540 af_remove(mpctx->mixer.afilter, af);
3542 else
3543 af_add(mpctx->mixer.afilter, af_command);
3545 build_afilter_chain(mpctx, sh_audio, &ao_data);
3546 free(af_args);
3548 break;
3549 case MP_CMD_AF_CLR:
3550 if (!sh_audio)
3551 break;
3552 af_uninit(mpctx->mixer.afilter);
3553 af_init(mpctx->mixer.afilter);
3554 build_afilter_chain(mpctx, sh_audio, &ao_data);
3555 break;
3556 case MP_CMD_AF_CMDLINE:
3557 if (sh_audio) {
3558 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3559 if (!af) {
3560 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3561 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3562 break;
3564 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3565 af_reinit(sh_audio->afilter, af);
3567 break;
3569 default:
3570 mp_msg(MSGT_CPLAYER, MSGL_V,
3571 "Received unknown cmd %s\n", cmd->name);
3574 switch (cmd->pausing) {
3575 case 1: // "pausing"
3576 pause_player(mpctx);
3577 break;
3578 case 3: // "pausing_toggle"
3579 if (mpctx->paused)
3580 unpause_player(mpctx);
3581 else
3582 pause_player(mpctx);
3583 break;