subtitles: remove code trying to handle text subs with libavcodec
[mplayer/glamo.git] / command.c
blob5474b92fedb58466fea49c70fddb94d104ac20de
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;
196 struct subtitle *vo_sub_last = mpctx->vo_sub_last;
198 if (mpctx->subdata == NULL || vo_sub_last == NULL)
199 return;
200 fname = get_path("subtitle_log");
201 f = fopen(fname, "a");
202 if (!f)
203 return;
204 fprintf(f, "----------------------------------------------------------\n");
205 if (mpctx->subdata->sub_uses_time) {
206 fprintf(f,
207 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
208 mpctx->filename, vo_sub_last->start / 360000,
209 (vo_sub_last->start / 6000) % 60,
210 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
211 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
212 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
213 } else {
214 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
215 vo_sub_last->start, vo_sub_last->end);
217 for (i = 0; i < vo_sub_last->lines; i++) {
218 fprintf(f, "%s\n", vo_sub_last->text[i]);
220 fclose(f);
224 /// \defgroup Properties
225 ///@{
227 /// \defgroup GeneralProperties General properties
228 /// \ingroup Properties
229 ///@{
231 static int mp_property_generic_option(struct m_option *prop, int action,
232 void *arg, MPContext *mpctx)
234 char *optname = prop->priv;
235 const struct m_option *opt = m_config_get_option(mpctx->mconfig, optname);
236 void *valptr = m_option_get_ptr(opt, &mpctx->opts);
238 switch (action) {
239 case M_PROPERTY_GET_TYPE:
240 *(const struct m_option **)arg = opt;
241 return M_PROPERTY_OK;
242 case M_PROPERTY_GET:
243 m_option_copy(opt, arg, valptr);
244 return M_PROPERTY_OK;
245 case M_PROPERTY_SET:
246 m_option_copy(opt, valptr, arg);
247 return M_PROPERTY_OK;
248 case M_PROPERTY_STEP_UP:
249 if (opt->type == &m_option_type_choice) {
250 int v = *(int *) valptr;
251 int best = v;
252 struct m_opt_choice_alternatives *alt;
253 for (alt = opt->priv; alt->name; alt++)
254 if ((unsigned) alt->value - v - 1 < (unsigned) best - v - 1)
255 best = alt->value;
256 *(int *) valptr = best;
257 return M_PROPERTY_OK;
259 break;
261 return M_PROPERTY_NOT_IMPLEMENTED;
264 /// OSD level (RW)
265 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
266 MPContext *mpctx)
268 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
271 /// Loop (RW)
272 static int mp_property_loop(m_option_t *prop, int action, void *arg,
273 MPContext *mpctx)
275 struct MPOpts *opts = &mpctx->opts;
276 switch (action) {
277 case M_PROPERTY_PRINT:
278 if (!arg) return M_PROPERTY_ERROR;
279 if (opts->loop_times < 0)
280 *(char**)arg = strdup("off");
281 else if (opts->loop_times == 0)
282 *(char**)arg = strdup("inf");
283 else
284 break;
285 return M_PROPERTY_OK;
287 return m_property_int_range(prop, action, arg, &opts->loop_times);
290 /// Playback speed (RW)
291 static int mp_property_playback_speed(m_option_t *prop, int action,
292 void *arg, MPContext *mpctx)
294 struct MPOpts *opts = &mpctx->opts;
295 switch (action) {
296 case M_PROPERTY_SET:
297 if (!arg)
298 return M_PROPERTY_ERROR;
299 M_PROPERTY_CLAMP(prop, *(float *) arg);
300 opts->playback_speed = *(float *) arg;
301 reinit_audio_chain(mpctx);
302 return M_PROPERTY_OK;
303 case M_PROPERTY_STEP_UP:
304 case M_PROPERTY_STEP_DOWN:
305 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
306 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
307 M_PROPERTY_CLAMP(prop, opts->playback_speed);
308 reinit_audio_chain(mpctx);
309 return M_PROPERTY_OK;
311 return m_property_float_range(prop, action, arg, &opts->playback_speed);
314 /// filename with path (RO)
315 static int mp_property_path(m_option_t *prop, int action, void *arg,
316 MPContext *mpctx)
318 return m_property_string_ro(prop, action, arg, mpctx->filename);
321 /// filename without path (RO)
322 static int mp_property_filename(m_option_t *prop, int action, void *arg,
323 MPContext *mpctx)
325 char *f;
326 if (!mpctx->filename)
327 return M_PROPERTY_UNAVAILABLE;
328 f = (char *)mp_basename(mpctx->filename);
329 if (!*f)
330 f = mpctx->filename;
331 return m_property_string_ro(prop, action, arg, f);
334 /// Demuxer name (RO)
335 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
336 MPContext *mpctx)
338 if (!mpctx->demuxer)
339 return M_PROPERTY_UNAVAILABLE;
340 return m_property_string_ro(prop, action, arg,
341 (char *) mpctx->demuxer->desc->name);
344 /// Position in the stream (RW)
345 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
346 MPContext *mpctx)
348 if (!mpctx->demuxer || !mpctx->demuxer->stream)
349 return M_PROPERTY_UNAVAILABLE;
350 if (!arg)
351 return M_PROPERTY_ERROR;
352 switch (action) {
353 case M_PROPERTY_GET:
354 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
355 return M_PROPERTY_OK;
356 case M_PROPERTY_SET:
357 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
358 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
359 return M_PROPERTY_OK;
361 return M_PROPERTY_NOT_IMPLEMENTED;
364 /// Stream start offset (RO)
365 static int mp_property_stream_start(m_option_t *prop, int action,
366 void *arg, MPContext *mpctx)
368 if (!mpctx->demuxer || !mpctx->demuxer->stream)
369 return M_PROPERTY_UNAVAILABLE;
370 switch (action) {
371 case M_PROPERTY_GET:
372 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
373 return M_PROPERTY_OK;
375 return M_PROPERTY_NOT_IMPLEMENTED;
378 /// Stream end offset (RO)
379 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
380 MPContext *mpctx)
382 if (!mpctx->demuxer || !mpctx->demuxer->stream)
383 return M_PROPERTY_UNAVAILABLE;
384 switch (action) {
385 case M_PROPERTY_GET:
386 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
387 return M_PROPERTY_OK;
389 return M_PROPERTY_NOT_IMPLEMENTED;
392 /// Stream length (RO)
393 static int mp_property_stream_length(m_option_t *prop, int action,
394 void *arg, MPContext *mpctx)
396 if (!mpctx->demuxer || !mpctx->demuxer->stream)
397 return M_PROPERTY_UNAVAILABLE;
398 switch (action) {
399 case M_PROPERTY_GET:
400 *(off_t *) arg =
401 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
402 return M_PROPERTY_OK;
404 return M_PROPERTY_NOT_IMPLEMENTED;
407 /// Current stream position in seconds (RO)
408 static int mp_property_stream_time_pos(m_option_t *prop, int action,
409 void *arg, MPContext *mpctx)
411 if (!mpctx->demuxer || mpctx->demuxer->stream_pts == MP_NOPTS_VALUE)
412 return M_PROPERTY_UNAVAILABLE;
414 return m_property_time_ro(prop, action, arg, mpctx->demuxer->stream_pts);
418 /// Media length in seconds (RO)
419 static int mp_property_length(m_option_t *prop, int action, void *arg,
420 MPContext *mpctx)
422 double len;
424 if (!mpctx->demuxer ||
425 !(int) (len = get_time_length(mpctx)))
426 return M_PROPERTY_UNAVAILABLE;
428 return m_property_time_ro(prop, action, arg, len);
431 /// Current position in percent (RW)
432 static int mp_property_percent_pos(m_option_t *prop, int action,
433 void *arg, MPContext *mpctx) {
434 int pos;
436 if (!mpctx->demuxer)
437 return M_PROPERTY_UNAVAILABLE;
439 switch(action) {
440 case M_PROPERTY_SET:
441 if(!arg) return M_PROPERTY_ERROR;
442 M_PROPERTY_CLAMP(prop, *(int*)arg);
443 pos = *(int*)arg;
444 break;
445 case M_PROPERTY_STEP_UP:
446 case M_PROPERTY_STEP_DOWN:
447 pos = get_percent_pos(mpctx);
448 pos += (arg ? *(int*)arg : 10) *
449 (action == M_PROPERTY_STEP_UP ? 1 : -1);
450 M_PROPERTY_CLAMP(prop, pos);
451 break;
452 default:
453 return m_property_int_ro(prop, action, arg, get_percent_pos(mpctx));
456 queue_seek(mpctx, MPSEEK_FACTOR, pos / 100.0, 0);
457 return M_PROPERTY_OK;
460 /// Current position in seconds (RW)
461 static int mp_property_time_pos(m_option_t *prop, int action,
462 void *arg, MPContext *mpctx) {
463 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
464 return M_PROPERTY_UNAVAILABLE;
466 switch(action) {
467 case M_PROPERTY_SET:
468 if(!arg) return M_PROPERTY_ERROR;
469 M_PROPERTY_CLAMP(prop, *(double*)arg);
470 queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double*)arg, 0);
471 return M_PROPERTY_OK;
472 case M_PROPERTY_STEP_UP:
473 case M_PROPERTY_STEP_DOWN:
474 queue_seek(mpctx, MPSEEK_RELATIVE, (arg ? *(double*)arg : 10.0) *
475 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0), 0);
476 return M_PROPERTY_OK;
478 return m_property_time_ro(prop, action, arg, get_current_time(mpctx));
481 /// Current chapter (RW)
482 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
483 MPContext *mpctx)
485 struct MPOpts *opts = &mpctx->opts;
486 int chapter = -1;
487 int step_all;
488 char *chapter_name = NULL;
490 if (mpctx->demuxer)
491 chapter = get_current_chapter(mpctx);
492 if (chapter < -1)
493 return M_PROPERTY_UNAVAILABLE;
495 switch (action) {
496 case M_PROPERTY_GET:
497 if (!arg)
498 return M_PROPERTY_ERROR;
499 *(int *) arg = chapter;
500 return M_PROPERTY_OK;
501 case M_PROPERTY_PRINT: {
502 if (!arg)
503 return M_PROPERTY_ERROR;
504 chapter_name = chapter_display_name(mpctx, chapter);
505 if (!chapter_name)
506 return M_PROPERTY_UNAVAILABLE;
507 *(char **) arg = chapter_name;
508 return M_PROPERTY_OK;
510 case M_PROPERTY_SET:
511 if (!arg)
512 return M_PROPERTY_ERROR;
513 M_PROPERTY_CLAMP(prop, *(int*)arg);
514 step_all = *(int *)arg - chapter;
515 chapter += step_all;
516 break;
517 case M_PROPERTY_STEP_UP:
518 case M_PROPERTY_STEP_DOWN: {
519 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
520 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
521 chapter += step_all;
522 if (chapter < 0)
523 chapter = 0;
524 break;
526 default:
527 return M_PROPERTY_NOT_IMPLEMENTED;
530 double next_pts = 0;
531 queue_seek(mpctx, MPSEEK_NONE, 0, 0);
532 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
533 if (chapter >= 0) {
534 if (next_pts > -1.0)
535 queue_seek(mpctx, MPSEEK_ABSOLUTE, next_pts, 0);
536 if (chapter_name)
537 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
538 "Chapter: (%d) %s", chapter + 1, chapter_name);
539 } else if (step_all > 0)
540 queue_seek(mpctx, MPSEEK_RELATIVE, 1000000000, 0);
541 else
542 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
543 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
544 talloc_free(chapter_name);
545 return M_PROPERTY_OK;
548 /// Number of chapters in file
549 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
550 MPContext *mpctx)
552 if (!mpctx->demuxer)
553 return M_PROPERTY_UNAVAILABLE;
554 if (mpctx->demuxer->num_chapters == 0)
555 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
556 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
559 /// Current dvd angle (RW)
560 static int mp_property_angle(m_option_t *prop, int action, void *arg,
561 MPContext *mpctx)
563 struct MPOpts *opts = &mpctx->opts;
564 int angle = -1;
565 int angles;
566 char *angle_name = NULL;
568 if (mpctx->demuxer)
569 angle = demuxer_get_current_angle(mpctx->demuxer);
570 if (angle < 0)
571 return M_PROPERTY_UNAVAILABLE;
572 angles = demuxer_angles_count(mpctx->demuxer);
573 if (angles <= 1)
574 return M_PROPERTY_UNAVAILABLE;
576 switch (action) {
577 case M_PROPERTY_GET:
578 if (!arg)
579 return M_PROPERTY_ERROR;
580 *(int *) arg = angle;
581 return M_PROPERTY_OK;
582 case M_PROPERTY_PRINT: {
583 if (!arg)
584 return M_PROPERTY_ERROR;
585 angle_name = calloc(1, 64);
586 if (!angle_name)
587 return M_PROPERTY_UNAVAILABLE;
588 snprintf(angle_name, 64, "%d/%d", angle, angles);
589 *(char **) arg = angle_name;
590 return M_PROPERTY_OK;
592 case M_PROPERTY_SET:
593 if (!arg)
594 return M_PROPERTY_ERROR;
595 angle = *(int *)arg;
596 M_PROPERTY_CLAMP(prop, angle);
597 break;
598 case M_PROPERTY_STEP_UP:
599 case M_PROPERTY_STEP_DOWN: {
600 int step = 0;
601 if(arg)
602 step = *(int*)arg;
603 if(!step)
604 step = 1;
605 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
606 angle += step;
607 if (angle < 1) //cycle
608 angle = angles;
609 break;
611 default:
612 return M_PROPERTY_NOT_IMPLEMENTED;
614 angle = demuxer_set_angle(mpctx->demuxer, angle);
615 if (angle >= 0) {
616 struct sh_video *sh_video = mpctx->demuxer->video->sh;
617 if (sh_video)
618 resync_video_stream(sh_video);
620 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
621 if (sh_audio)
622 resync_audio_stream(sh_audio);
625 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
626 "Angle: %d/%d", angle, angles);
627 free(angle_name);
628 return M_PROPERTY_OK;
631 /// Demuxer meta data
632 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
633 MPContext *mpctx) {
634 m_property_action_t* ka;
635 char* meta;
636 static const m_option_t key_type =
637 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
638 if (!mpctx->demuxer)
639 return M_PROPERTY_UNAVAILABLE;
641 switch(action) {
642 case M_PROPERTY_GET:
643 if(!arg) return M_PROPERTY_ERROR;
644 *(char***)arg = mpctx->demuxer->info;
645 return M_PROPERTY_OK;
646 case M_PROPERTY_KEY_ACTION:
647 if(!arg) return M_PROPERTY_ERROR;
648 ka = arg;
649 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
650 return M_PROPERTY_UNKNOWN;
651 switch(ka->action) {
652 case M_PROPERTY_GET:
653 if(!ka->arg) return M_PROPERTY_ERROR;
654 *(char**)ka->arg = meta;
655 return M_PROPERTY_OK;
656 case M_PROPERTY_GET_TYPE:
657 if(!ka->arg) return M_PROPERTY_ERROR;
658 *(const m_option_t**)ka->arg = &key_type;
659 return M_PROPERTY_OK;
662 return M_PROPERTY_NOT_IMPLEMENTED;
665 static int mp_property_pause(m_option_t *prop, int action, void *arg,
666 void *ctx)
668 MPContext *mpctx = ctx;
670 switch (action) {
671 case M_PROPERTY_SET:
672 if (!arg)
673 return M_PROPERTY_ERROR;
674 if (mpctx->paused == (bool)*(int *) arg)
675 return M_PROPERTY_OK;
676 case M_PROPERTY_STEP_UP:
677 case M_PROPERTY_STEP_DOWN:
678 if (mpctx->paused) {
679 unpause_player(mpctx);
680 mpctx->osd_function = OSD_PLAY;
682 else {
683 pause_player(mpctx);
684 mpctx->osd_function = OSD_PAUSE;
686 return M_PROPERTY_OK;
687 default:
688 return m_property_flag(prop, action, arg, &mpctx->paused);
693 ///@}
695 /// \defgroup AudioProperties Audio properties
696 /// \ingroup Properties
697 ///@{
699 /// Volume (RW)
700 static int mp_property_volume(m_option_t *prop, int action, void *arg,
701 MPContext *mpctx)
704 if (!mpctx->sh_audio)
705 return M_PROPERTY_UNAVAILABLE;
707 switch (action) {
708 case M_PROPERTY_GET:
709 if (!arg)
710 return M_PROPERTY_ERROR;
711 mixer_getbothvolume(&mpctx->mixer, arg);
712 return M_PROPERTY_OK;
713 case M_PROPERTY_PRINT:{
714 float vol;
715 if (!arg)
716 return M_PROPERTY_ERROR;
717 mixer_getbothvolume(&mpctx->mixer, &vol);
718 return m_property_float_range(prop, action, arg, &vol);
720 case M_PROPERTY_STEP_UP:
721 case M_PROPERTY_STEP_DOWN:
722 case M_PROPERTY_SET:
723 break;
724 default:
725 return M_PROPERTY_NOT_IMPLEMENTED;
728 if (mpctx->edl_muted)
729 return M_PROPERTY_DISABLED;
730 mpctx->user_muted = 0;
732 switch (action) {
733 case M_PROPERTY_SET:
734 if (!arg)
735 return M_PROPERTY_ERROR;
736 M_PROPERTY_CLAMP(prop, *(float *) arg);
737 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
738 return M_PROPERTY_OK;
739 case M_PROPERTY_STEP_UP:
740 if (arg && *(float *) arg <= 0)
741 mixer_decvolume(&mpctx->mixer);
742 else
743 mixer_incvolume(&mpctx->mixer);
744 return M_PROPERTY_OK;
745 case M_PROPERTY_STEP_DOWN:
746 if (arg && *(float *) arg <= 0)
747 mixer_incvolume(&mpctx->mixer);
748 else
749 mixer_decvolume(&mpctx->mixer);
750 return M_PROPERTY_OK;
752 return M_PROPERTY_NOT_IMPLEMENTED;
755 /// Mute (RW)
756 static int mp_property_mute(m_option_t *prop, int action, void *arg,
757 MPContext *mpctx)
760 if (!mpctx->sh_audio)
761 return M_PROPERTY_UNAVAILABLE;
763 switch (action) {
764 case M_PROPERTY_SET:
765 if (mpctx->edl_muted)
766 return M_PROPERTY_DISABLED;
767 if (!arg)
768 return M_PROPERTY_ERROR;
769 if ((!!*(int *) arg) != mpctx->mixer.muted)
770 mixer_mute(&mpctx->mixer);
771 mpctx->user_muted = mpctx->mixer.muted;
772 return M_PROPERTY_OK;
773 case M_PROPERTY_STEP_UP:
774 case M_PROPERTY_STEP_DOWN:
775 if (mpctx->edl_muted)
776 return M_PROPERTY_DISABLED;
777 mixer_mute(&mpctx->mixer);
778 mpctx->user_muted = mpctx->mixer.muted;
779 return M_PROPERTY_OK;
780 case M_PROPERTY_PRINT:
781 if (!arg)
782 return M_PROPERTY_ERROR;
783 if (mpctx->edl_muted) {
784 *(char **) arg = strdup(mp_gtext("enabled (EDL)"));
785 return M_PROPERTY_OK;
787 default:
788 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
793 /// Audio delay (RW)
794 static int mp_property_audio_delay(m_option_t *prop, int action,
795 void *arg, MPContext *mpctx)
797 if (!(mpctx->sh_audio && mpctx->sh_video))
798 return M_PROPERTY_UNAVAILABLE;
799 switch (action) {
800 case M_PROPERTY_SET:
801 case M_PROPERTY_STEP_UP:
802 case M_PROPERTY_STEP_DOWN: {
803 int ret;
804 float delay = audio_delay;
805 ret = m_property_delay(prop, action, arg, &audio_delay);
806 if (ret != M_PROPERTY_OK)
807 return ret;
808 if (mpctx->sh_audio)
809 mpctx->delay -= audio_delay - delay;
811 return M_PROPERTY_OK;
812 default:
813 return m_property_delay(prop, action, arg, &audio_delay);
817 /// Audio codec tag (RO)
818 static int mp_property_audio_format(m_option_t *prop, int action,
819 void *arg, MPContext *mpctx)
821 if (!mpctx->sh_audio)
822 return M_PROPERTY_UNAVAILABLE;
823 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
826 /// Audio codec name (RO)
827 static int mp_property_audio_codec(m_option_t *prop, int action,
828 void *arg, MPContext *mpctx)
830 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
831 return M_PROPERTY_UNAVAILABLE;
832 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
835 /// Audio bitrate (RO)
836 static int mp_property_audio_bitrate(m_option_t *prop, int action,
837 void *arg, MPContext *mpctx)
839 if (!mpctx->sh_audio)
840 return M_PROPERTY_UNAVAILABLE;
841 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
844 /// Samplerate (RO)
845 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
846 MPContext *mpctx)
848 if (!mpctx->sh_audio)
849 return M_PROPERTY_UNAVAILABLE;
850 switch(action) {
851 case M_PROPERTY_PRINT:
852 if(!arg) return M_PROPERTY_ERROR;
853 *(char**)arg = malloc(16);
854 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
855 return M_PROPERTY_OK;
857 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
860 /// Number of channels (RO)
861 static int mp_property_channels(m_option_t *prop, int action, void *arg,
862 MPContext *mpctx)
864 if (!mpctx->sh_audio)
865 return M_PROPERTY_UNAVAILABLE;
866 switch (action) {
867 case M_PROPERTY_PRINT:
868 if (!arg)
869 return M_PROPERTY_ERROR;
870 switch (mpctx->sh_audio->channels) {
871 case 1:
872 *(char **) arg = strdup("mono");
873 break;
874 case 2:
875 *(char **) arg = strdup("stereo");
876 break;
877 default:
878 *(char **) arg = malloc(32);
879 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
881 return M_PROPERTY_OK;
883 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
886 /// Balance (RW)
887 static int mp_property_balance(m_option_t *prop, int action, void *arg,
888 MPContext *mpctx)
890 float bal;
892 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
893 return M_PROPERTY_UNAVAILABLE;
895 switch (action) {
896 case M_PROPERTY_GET:
897 if (!arg)
898 return M_PROPERTY_ERROR;
899 mixer_getbalance(&mpctx->mixer, arg);
900 return M_PROPERTY_OK;
901 case M_PROPERTY_PRINT: {
902 char** str = arg;
903 if (!arg)
904 return M_PROPERTY_ERROR;
905 mixer_getbalance(&mpctx->mixer, &bal);
906 if (bal == 0.f)
907 *str = strdup("center");
908 else if (bal == -1.f)
909 *str = strdup("left only");
910 else if (bal == 1.f)
911 *str = strdup("right only");
912 else {
913 unsigned right = (bal + 1.f) / 2.f * 100.f;
914 *str = malloc(sizeof("left xxx%, right xxx%"));
915 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
917 return M_PROPERTY_OK;
919 case M_PROPERTY_STEP_UP:
920 case M_PROPERTY_STEP_DOWN:
921 mixer_getbalance(&mpctx->mixer, &bal);
922 bal += (arg ? *(float*)arg : .1f) *
923 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
924 M_PROPERTY_CLAMP(prop, bal);
925 mixer_setbalance(&mpctx->mixer, bal);
926 return M_PROPERTY_OK;
927 case M_PROPERTY_SET:
928 if (!arg)
929 return M_PROPERTY_ERROR;
930 M_PROPERTY_CLAMP(prop, *(float*)arg);
931 mixer_setbalance(&mpctx->mixer, *(float*)arg);
932 return M_PROPERTY_OK;
934 return M_PROPERTY_NOT_IMPLEMENTED;
937 /// Selected audio id (RW)
938 static int mp_property_audio(m_option_t *prop, int action, void *arg,
939 MPContext *mpctx)
941 int current_id, tmp;
942 if (!mpctx->demuxer || !mpctx->d_audio)
943 return M_PROPERTY_UNAVAILABLE;
944 current_id = mpctx->sh_audio ? mpctx->sh_audio->aid : -2;
946 switch (action) {
947 case M_PROPERTY_GET:
948 if (!arg)
949 return M_PROPERTY_ERROR;
950 *(int *) arg = current_id;
951 return M_PROPERTY_OK;
952 case M_PROPERTY_PRINT:
953 if (!arg)
954 return M_PROPERTY_ERROR;
956 if (current_id < 0)
957 *(char **) arg = strdup(mp_gtext("disabled"));
958 else {
959 char lang[40];
960 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
961 sh_audio_t* sh = mpctx->sh_audio;
962 if (sh && sh->lang)
963 av_strlcpy(lang, sh->lang, 40);
964 #ifdef CONFIG_DVDREAD
965 else if (mpctx->stream->type == STREAMTYPE_DVD) {
966 int code = dvd_lang_from_aid(mpctx->stream, current_id);
967 if (code) {
968 lang[0] = code >> 8;
969 lang[1] = code;
970 lang[2] = 0;
973 #endif
975 #ifdef CONFIG_DVDNAV
976 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
977 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
978 #endif
979 *(char **) arg = malloc(64);
980 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
982 return M_PROPERTY_OK;
984 case M_PROPERTY_STEP_UP:
985 case M_PROPERTY_SET:
986 if (action == M_PROPERTY_SET && arg)
987 tmp = *((int *) arg);
988 else
989 tmp = -1;
990 int new_id = demuxer_switch_audio(mpctx->d_audio->demuxer, tmp);
991 if (new_id != current_id)
992 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
993 if (new_id != current_id && new_id >= 0) {
994 sh_audio_t *sh2;
995 sh2 = mpctx->d_audio->demuxer->a_streams[mpctx->demuxer->audio->id];
996 sh2->ds = mpctx->demuxer->audio;
997 mpctx->sh_audio = sh2;
998 reinit_audio_chain(mpctx);
1000 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
1001 return M_PROPERTY_OK;
1002 default:
1003 return M_PROPERTY_NOT_IMPLEMENTED;
1008 /// Selected video id (RW)
1009 static int mp_property_video(m_option_t *prop, int action, void *arg,
1010 MPContext *mpctx)
1012 struct MPOpts *opts = &mpctx->opts;
1013 int current_id, tmp;
1014 if (!mpctx->demuxer || !mpctx->d_video)
1015 return M_PROPERTY_UNAVAILABLE;
1016 current_id = mpctx->d_video->id;
1018 switch (action) {
1019 case M_PROPERTY_GET:
1020 if (!arg)
1021 return M_PROPERTY_ERROR;
1022 *(int *) arg = current_id;
1023 return M_PROPERTY_OK;
1024 case M_PROPERTY_PRINT:
1025 if (!arg)
1026 return M_PROPERTY_ERROR;
1028 if (current_id < 0)
1029 *(char **) arg = strdup(mp_gtext("disabled"));
1030 else {
1031 char lang[40];
1032 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
1033 *(char **) arg = malloc(64);
1034 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
1036 return M_PROPERTY_OK;
1038 case M_PROPERTY_STEP_UP:
1039 case M_PROPERTY_SET:
1040 if (action == M_PROPERTY_SET && arg)
1041 tmp = *((int *) arg);
1042 else
1043 tmp = -1;
1044 opts->video_id = demuxer_switch_video(mpctx->d_video->demuxer, tmp);
1045 if (opts->video_id == -2
1046 || (opts->video_id > -1 && mpctx->d_video->id != current_id
1047 && current_id != -2))
1048 uninit_player(mpctx, INITIALIZED_VCODEC |
1049 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
1050 if (opts->video_id > -1 && mpctx->d_video->id != current_id) {
1051 sh_video_t *sh2;
1052 sh2 = mpctx->d_video->demuxer->v_streams[mpctx->d_video->id];
1053 if (sh2) {
1054 sh2->ds = mpctx->d_video;
1055 mpctx->sh_video = sh2;
1056 reinit_video_chain(mpctx);
1059 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
1060 return M_PROPERTY_OK;
1062 default:
1063 return M_PROPERTY_NOT_IMPLEMENTED;
1067 static int mp_property_program(m_option_t *prop, int action, void *arg,
1068 MPContext *mpctx)
1070 demux_program_t prog;
1072 switch (action) {
1073 case M_PROPERTY_STEP_UP:
1074 case M_PROPERTY_SET:
1075 if (action == M_PROPERTY_SET && arg)
1076 prog.progid = *((int *) arg);
1077 else
1078 prog.progid = -1;
1079 if (demux_control
1080 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1081 &prog) == DEMUXER_CTRL_NOTIMPL)
1082 return M_PROPERTY_ERROR;
1084 if (prog.aid < 0 && prog.vid < 0) {
1085 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
1086 return M_PROPERTY_ERROR;
1088 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1089 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1090 return M_PROPERTY_OK;
1092 default:
1093 return M_PROPERTY_NOT_IMPLEMENTED;
1097 ///@}
1099 /// \defgroup VideoProperties Video properties
1100 /// \ingroup Properties
1101 ///@{
1103 /// Fullscreen state (RW)
1104 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1105 MPContext *mpctx)
1108 if (!mpctx->video_out)
1109 return M_PROPERTY_UNAVAILABLE;
1111 switch (action) {
1112 case M_PROPERTY_SET:
1113 if (!arg)
1114 return M_PROPERTY_ERROR;
1115 M_PROPERTY_CLAMP(prop, *(int *) arg);
1116 if (vo_fs == !!*(int *) arg)
1117 return M_PROPERTY_OK;
1118 case M_PROPERTY_STEP_UP:
1119 case M_PROPERTY_STEP_DOWN:
1120 if (mpctx->video_out->config_ok)
1121 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1122 mpctx->opts.fullscreen = vo_fs;
1123 return M_PROPERTY_OK;
1124 default:
1125 return m_property_flag(prop, action, arg, &vo_fs);
1129 static int mp_property_deinterlace(m_option_t *prop, int action,
1130 void *arg, MPContext *mpctx)
1132 int deinterlace;
1133 vf_instance_t *vf;
1134 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1135 return M_PROPERTY_UNAVAILABLE;
1136 vf = mpctx->sh_video->vfilter;
1137 switch (action) {
1138 case M_PROPERTY_GET:
1139 if (!arg)
1140 return M_PROPERTY_ERROR;
1141 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1142 return M_PROPERTY_OK;
1143 case M_PROPERTY_SET:
1144 if (!arg)
1145 return M_PROPERTY_ERROR;
1146 M_PROPERTY_CLAMP(prop, *(int *) arg);
1147 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1148 return M_PROPERTY_OK;
1149 case M_PROPERTY_STEP_UP:
1150 case M_PROPERTY_STEP_DOWN:
1151 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1152 deinterlace = !deinterlace;
1153 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1154 return M_PROPERTY_OK;
1156 int value = 0;
1157 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1158 return m_property_flag_ro(prop, action, arg, value);
1161 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1162 void *arg, MPContext *mpctx)
1164 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1165 return M_PROPERTY_UNAVAILABLE;
1167 struct vf_instance *vf = mpctx->sh_video->vfilter;
1168 int colorspace;
1169 switch (action) {
1170 case M_PROPERTY_GET:
1171 if (!arg)
1172 return M_PROPERTY_ERROR;
1173 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1174 return M_PROPERTY_UNAVAILABLE;
1175 return M_PROPERTY_OK;
1176 case M_PROPERTY_PRINT:
1177 if (!arg)
1178 return M_PROPERTY_ERROR;
1179 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1180 return M_PROPERTY_UNAVAILABLE;
1181 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1182 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1183 *(char **)arg = strdup("Unknown");
1184 else
1185 *(char**)arg = strdup(names[colorspace]);
1186 return M_PROPERTY_OK;
1187 case M_PROPERTY_SET:
1188 if (!arg)
1189 return M_PROPERTY_ERROR;
1190 M_PROPERTY_CLAMP(prop, *(int *) arg);
1191 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1192 return M_PROPERTY_OK;
1193 case M_PROPERTY_STEP_UP:;
1194 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1195 return M_PROPERTY_UNAVAILABLE;
1196 colorspace += 1;
1197 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1198 return M_PROPERTY_OK;
1200 return M_PROPERTY_NOT_IMPLEMENTED;
1203 static int mp_property_capture(m_option_t *prop, int action,
1204 void *arg, MPContext *mpctx)
1206 struct MPOpts *opts = &mpctx->opts;
1208 if (!mpctx->stream)
1209 return M_PROPERTY_UNAVAILABLE;
1211 if (!opts->capture_dump) {
1212 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1213 "Capturing not enabled (forgot -capture parameter?)\n");
1214 return M_PROPERTY_ERROR;
1217 int capturing = !!mpctx->stream->capture_file;
1219 int ret = m_property_flag(prop, action, arg, &capturing);
1220 if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
1221 if (capturing) {
1222 mpctx->stream->capture_file = fopen(opts->stream_dump_name, "wb");
1223 if (!mpctx->stream->capture_file) {
1224 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1225 "Error opening capture file: %s\n", strerror(errno));
1226 ret = M_PROPERTY_ERROR;
1228 } else {
1229 fclose(mpctx->stream->capture_file);
1230 mpctx->stream->capture_file = NULL;
1234 return ret;
1237 /// Panscan (RW)
1238 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1239 MPContext *mpctx)
1242 if (!mpctx->video_out
1243 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1244 return M_PROPERTY_UNAVAILABLE;
1246 switch (action) {
1247 case M_PROPERTY_SET:
1248 if (!arg)
1249 return M_PROPERTY_ERROR;
1250 M_PROPERTY_CLAMP(prop, *(float *) arg);
1251 vo_panscan = *(float *) arg;
1252 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1253 return M_PROPERTY_OK;
1254 case M_PROPERTY_STEP_UP:
1255 case M_PROPERTY_STEP_DOWN:
1256 vo_panscan += (arg ? *(float *) arg : 0.1) *
1257 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1258 if (vo_panscan > 1)
1259 vo_panscan = 1;
1260 else if (vo_panscan < 0)
1261 vo_panscan = 0;
1262 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1263 return M_PROPERTY_OK;
1264 default:
1265 return m_property_float_range(prop, action, arg, &vo_panscan);
1269 /// Helper to set vo flags.
1270 /** \ingroup PropertyImplHelper
1272 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1273 int vo_ctrl, int *vo_var, MPContext *mpctx)
1276 if (!mpctx->video_out)
1277 return M_PROPERTY_UNAVAILABLE;
1279 switch (action) {
1280 case M_PROPERTY_SET:
1281 if (!arg)
1282 return M_PROPERTY_ERROR;
1283 M_PROPERTY_CLAMP(prop, *(int *) arg);
1284 if (*vo_var == !!*(int *) arg)
1285 return M_PROPERTY_OK;
1286 case M_PROPERTY_STEP_UP:
1287 case M_PROPERTY_STEP_DOWN:
1288 if (mpctx->video_out->config_ok)
1289 vo_control(mpctx->video_out, vo_ctrl, 0);
1290 return M_PROPERTY_OK;
1291 default:
1292 return m_property_flag(prop, action, arg, vo_var);
1296 /// Window always on top (RW)
1297 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1298 MPContext *mpctx)
1300 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1301 &mpctx->opts.vo_ontop, mpctx);
1304 /// Display in the root window (RW)
1305 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1306 MPContext *mpctx)
1308 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1309 &vo_rootwin, mpctx);
1312 /// Show window borders (RW)
1313 static int mp_property_border(m_option_t *prop, int action, void *arg,
1314 MPContext *mpctx)
1316 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1317 &vo_border, mpctx);
1320 /// Framedropping state (RW)
1321 static int mp_property_framedropping(m_option_t *prop, int action,
1322 void *arg, MPContext *mpctx)
1325 if (!mpctx->sh_video)
1326 return M_PROPERTY_UNAVAILABLE;
1328 switch (action) {
1329 case M_PROPERTY_PRINT:
1330 if (!arg)
1331 return M_PROPERTY_ERROR;
1332 *(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
1333 (frame_dropping == 2 ? mp_gtext("hard") :
1334 mp_gtext("disabled")));
1335 return M_PROPERTY_OK;
1336 default:
1337 return m_property_choice(prop, action, arg, &frame_dropping);
1341 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1342 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1343 MPContext *mpctx)
1345 int *gamma = (int *)((char *)&mpctx->opts + prop->offset);
1346 int r, val;
1348 if (!mpctx->sh_video)
1349 return M_PROPERTY_UNAVAILABLE;
1351 if (gamma[0] == 1000) {
1352 gamma[0] = 0;
1353 get_video_colors(mpctx->sh_video, prop->name, gamma);
1356 switch (action) {
1357 case M_PROPERTY_SET:
1358 if (!arg)
1359 return M_PROPERTY_ERROR;
1360 M_PROPERTY_CLAMP(prop, *(int *) arg);
1361 *gamma = *(int *) arg;
1362 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1363 if (r <= 0)
1364 break;
1365 return r;
1366 case M_PROPERTY_GET:
1367 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1368 if (!arg)
1369 return M_PROPERTY_ERROR;
1370 *(int *)arg = val;
1371 return M_PROPERTY_OK;
1373 break;
1374 case M_PROPERTY_STEP_UP:
1375 case M_PROPERTY_STEP_DOWN:
1376 *gamma += (arg ? *(int *) arg : 1) *
1377 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1378 M_PROPERTY_CLAMP(prop, *gamma);
1379 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1380 if (r <= 0)
1381 break;
1382 return r;
1383 default:
1384 return M_PROPERTY_NOT_IMPLEMENTED;
1387 #ifdef CONFIG_TV
1388 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1389 int l = strlen(prop->name);
1390 char tv_prop[3 + l + 1];
1391 sprintf(tv_prop, "tv_%s", prop->name);
1392 return mp_property_do(tv_prop, action, arg, mpctx);
1394 #endif
1396 return M_PROPERTY_UNAVAILABLE;
1399 /// VSync (RW)
1400 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1401 MPContext *mpctx)
1403 return m_property_flag(prop, action, arg, &vo_vsync);
1406 /// Video codec tag (RO)
1407 static int mp_property_video_format(m_option_t *prop, int action,
1408 void *arg, MPContext *mpctx)
1410 char* meta;
1411 if (!mpctx->sh_video)
1412 return M_PROPERTY_UNAVAILABLE;
1413 switch(action) {
1414 case M_PROPERTY_PRINT:
1415 if (!arg)
1416 return M_PROPERTY_ERROR;
1417 switch(mpctx->sh_video->format) {
1418 case 0x10000001:
1419 meta = strdup ("mpeg1"); break;
1420 case 0x10000002:
1421 meta = strdup ("mpeg2"); break;
1422 case 0x10000004:
1423 meta = strdup ("mpeg4"); break;
1424 case 0x10000005:
1425 meta = strdup ("h264"); break;
1426 default:
1427 if(mpctx->sh_video->format >= 0x20202020) {
1428 meta = malloc(5);
1429 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1430 } else {
1431 meta = malloc(20);
1432 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1435 *(char**)arg = meta;
1436 return M_PROPERTY_OK;
1438 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1441 /// Video codec name (RO)
1442 static int mp_property_video_codec(m_option_t *prop, int action,
1443 void *arg, MPContext *mpctx)
1445 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1446 return M_PROPERTY_UNAVAILABLE;
1447 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1451 /// Video bitrate (RO)
1452 static int mp_property_video_bitrate(m_option_t *prop, int action,
1453 void *arg, MPContext *mpctx)
1455 if (!mpctx->sh_video)
1456 return M_PROPERTY_UNAVAILABLE;
1457 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1460 /// Video display width (RO)
1461 static int mp_property_width(m_option_t *prop, int action, void *arg,
1462 MPContext *mpctx)
1464 if (!mpctx->sh_video)
1465 return M_PROPERTY_UNAVAILABLE;
1466 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1469 /// Video display height (RO)
1470 static int mp_property_height(m_option_t *prop, int action, void *arg,
1471 MPContext *mpctx)
1473 if (!mpctx->sh_video)
1474 return M_PROPERTY_UNAVAILABLE;
1475 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1478 /// Video fps (RO)
1479 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1480 MPContext *mpctx)
1482 if (!mpctx->sh_video)
1483 return M_PROPERTY_UNAVAILABLE;
1484 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1487 /// Video aspect (RO)
1488 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1489 MPContext *mpctx)
1491 if (!mpctx->sh_video)
1492 return M_PROPERTY_UNAVAILABLE;
1493 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1496 ///@}
1498 /// \defgroup SubProprties Subtitles properties
1499 /// \ingroup Properties
1500 ///@{
1502 /// Text subtitle position (RW)
1503 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1504 MPContext *mpctx)
1506 switch (action) {
1507 case M_PROPERTY_SET:
1508 if (!arg)
1509 return M_PROPERTY_ERROR;
1510 case M_PROPERTY_STEP_UP:
1511 case M_PROPERTY_STEP_DOWN:
1512 vo_osd_changed(OSDTYPE_SUBTITLE);
1513 default:
1514 return m_property_int_range(prop, action, arg, &sub_pos);
1518 /// Selected subtitles (RW)
1519 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1520 MPContext *mpctx)
1522 struct MPOpts *opts = &mpctx->opts;
1523 demux_stream_t *const d_sub = mpctx->d_sub;
1524 int source = -1, reset_spu = 0;
1525 int source_pos = -1;
1527 update_global_sub_size(mpctx);
1528 const int global_sub_size = mpctx->global_sub_size;
1530 if (global_sub_size <= 0)
1531 return M_PROPERTY_UNAVAILABLE;
1533 switch (action) {
1534 case M_PROPERTY_GET:
1535 if (!arg)
1536 return M_PROPERTY_ERROR;
1537 *(int *) arg = mpctx->global_sub_pos;
1538 return M_PROPERTY_OK;
1539 case M_PROPERTY_PRINT:
1540 if (!arg)
1541 return M_PROPERTY_ERROR;
1542 *(char **) arg = malloc(64);
1543 (*(char **) arg)[63] = 0;
1544 char *sub_name = NULL;
1545 if (mpctx->subdata)
1546 sub_name = mpctx->subdata->filename;
1547 #ifdef CONFIG_ASS
1548 if (mpctx->osd->ass_track)
1549 sub_name = mpctx->osd->ass_track->name;
1550 #endif
1551 if (!sub_name && mpctx->subdata)
1552 sub_name = mpctx->subdata->filename;
1553 if (sub_name) {
1554 const char *tmp = mp_basename(sub_name);
1556 snprintf(*(char **) arg, 63, "(%d) %s%s",
1557 mpctx->set_of_sub_pos + 1,
1558 strlen(tmp) < 20 ? "" : "...",
1559 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1560 return M_PROPERTY_OK;
1562 #ifdef CONFIG_DVDNAV
1563 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1564 if (vo_spudec && opts->sub_id >= 0) {
1565 unsigned char lang[3];
1566 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1567 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1568 return M_PROPERTY_OK;
1572 #endif
1574 if ((d_sub->demuxer->type == DEMUXER_TYPE_MATROSKA
1575 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF
1576 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1577 || d_sub->demuxer->type == DEMUXER_TYPE_OGG)
1578 && d_sub->sh && opts->sub_id >= 0) {
1579 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1580 if (!lang) lang = mp_gtext("unknown");
1581 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1582 return M_PROPERTY_OK;
1585 if (vo_vobsub && vobsub_id >= 0) {
1586 const char *language = mp_gtext("unknown");
1587 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1588 snprintf(*(char **) arg, 63, "(%d) %s",
1589 vobsub_id, language ? language : mp_gtext("unknown"));
1590 return M_PROPERTY_OK;
1592 #ifdef CONFIG_DVDREAD
1593 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1594 && opts->sub_id >= 0) {
1595 char lang[3];
1596 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1597 lang[0] = code >> 8;
1598 lang[1] = code;
1599 lang[2] = 0;
1600 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1601 return M_PROPERTY_OK;
1603 #endif
1604 if (opts->sub_id >= 0) {
1605 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
1606 mp_gtext("unknown"));
1607 return M_PROPERTY_OK;
1609 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1610 return M_PROPERTY_OK;
1612 case M_PROPERTY_SET:
1613 if (!arg)
1614 return M_PROPERTY_ERROR;
1615 if (*(int *) arg < -1)
1616 *(int *) arg = -1;
1617 else if (*(int *) arg >= global_sub_size)
1618 *(int *) arg = global_sub_size - 1;
1619 mpctx->global_sub_pos = *(int *) arg;
1620 break;
1621 case M_PROPERTY_STEP_UP:
1622 mpctx->global_sub_pos += 2;
1623 mpctx->global_sub_pos =
1624 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1625 break;
1626 case M_PROPERTY_STEP_DOWN:
1627 mpctx->global_sub_pos += global_sub_size + 1;
1628 mpctx->global_sub_pos =
1629 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1630 break;
1631 default:
1632 return M_PROPERTY_NOT_IMPLEMENTED;
1635 if (mpctx->global_sub_pos >= 0) {
1636 source = sub_source(mpctx);
1637 source_pos = sub_source_pos(mpctx);
1640 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1641 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1642 global_sub_size,
1643 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1644 mpctx->sub_counts[SUB_SOURCE_SUBS],
1645 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1646 mpctx->global_sub_pos, source);
1648 mpctx->set_of_sub_pos = -1;
1649 mpctx->subdata = NULL;
1651 vobsub_id = -1;
1652 opts->sub_id = -1;
1653 if (d_sub) {
1654 if (d_sub->id > -2)
1655 reset_spu = 1;
1656 d_sub->id = -2;
1658 mpctx->osd->ass_track = NULL;
1660 if (source == SUB_SOURCE_VOBSUB) {
1661 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1662 } else if (source == SUB_SOURCE_SUBS) {
1663 mpctx->set_of_sub_pos = source_pos;
1664 #ifdef CONFIG_ASS
1665 if (opts->ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1666 mpctx->osd->ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1667 else
1668 #endif
1670 mpctx->subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1671 vo_osd_changed(OSDTYPE_SUBTITLE);
1673 } else if (source == SUB_SOURCE_DEMUX) {
1674 opts->sub_id = source_pos;
1675 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1676 int i = 0;
1677 // default: assume 1:1 mapping of sid and stream id
1678 d_sub->id = opts->sub_id;
1679 d_sub->sh = mpctx->d_sub->demuxer->s_streams[d_sub->id];
1680 ds_free_packs(d_sub);
1681 for (i = 0; i < MAX_S_STREAMS; i++) {
1682 sh_sub_t *sh = mpctx->d_sub->demuxer->s_streams[i];
1683 if (sh && sh->sid == opts->sub_id) {
1684 d_sub->id = i;
1685 d_sub->sh = sh;
1686 break;
1689 if (d_sub->sh && d_sub->id >= 0) {
1690 sh_sub_t *sh = d_sub->sh;
1691 if (sh->type == 'v')
1692 init_vo_spudec(mpctx);
1693 #ifdef CONFIG_ASS
1694 else if (opts->ass_enabled)
1695 mpctx->osd->ass_track = sh->ass_track;
1696 #endif
1697 } else {
1698 d_sub->id = -2;
1699 d_sub->sh = NULL;
1703 #ifdef CONFIG_DVDREAD
1704 if (vo_spudec
1705 && (mpctx->stream->type == STREAMTYPE_DVD
1706 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1707 && opts->sub_id < 0 && reset_spu) {
1708 d_sub->id = -2;
1709 d_sub->sh = NULL;
1711 #endif
1713 update_subtitles(mpctx, 0, 0, true);
1715 return M_PROPERTY_OK;
1718 /// Selected sub source (RW)
1719 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1720 MPContext *mpctx)
1722 int source;
1723 update_global_sub_size(mpctx);
1724 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1725 return M_PROPERTY_UNAVAILABLE;
1727 switch (action) {
1728 case M_PROPERTY_GET:
1729 if (!arg)
1730 return M_PROPERTY_ERROR;
1731 *(int *) arg = sub_source(mpctx);
1732 return M_PROPERTY_OK;
1733 case M_PROPERTY_PRINT:
1734 if (!arg)
1735 return M_PROPERTY_ERROR;
1736 *(char **) arg = malloc(64);
1737 (*(char **) arg)[63] = 0;
1738 switch (sub_source(mpctx))
1740 case SUB_SOURCE_SUBS:
1741 snprintf(*(char **) arg, 63, mp_gtext("file"));
1742 break;
1743 case SUB_SOURCE_VOBSUB:
1744 snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
1745 break;
1746 case SUB_SOURCE_DEMUX:
1747 snprintf(*(char **) arg, 63, mp_gtext("embedded"));
1748 break;
1749 default:
1750 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1752 return M_PROPERTY_OK;
1753 case M_PROPERTY_SET:
1754 if (!arg)
1755 return M_PROPERTY_ERROR;
1756 M_PROPERTY_CLAMP(prop, *(int*)arg);
1757 if (*(int *) arg < 0)
1758 mpctx->global_sub_pos = -1;
1759 else if (*(int *) arg != sub_source(mpctx)) {
1760 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1761 if (new_pos == -1)
1762 return M_PROPERTY_UNAVAILABLE;
1763 mpctx->global_sub_pos = new_pos;
1765 break;
1766 case M_PROPERTY_STEP_UP:
1767 case M_PROPERTY_STEP_DOWN: {
1768 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1769 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1770 int step = (step_all > 0) ? 1 : -1;
1771 int cur_source = sub_source(mpctx);
1772 source = cur_source;
1773 while (step_all) {
1774 source += step;
1775 if (source >= SUB_SOURCES)
1776 source = -1;
1777 else if (source < -1)
1778 source = SUB_SOURCES - 1;
1779 if (source == cur_source || source == -1 ||
1780 mpctx->sub_counts[source])
1781 step_all -= step;
1783 if (source == cur_source)
1784 return M_PROPERTY_OK;
1785 if (source == -1)
1786 mpctx->global_sub_pos = -1;
1787 else
1788 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1789 break;
1791 default:
1792 return M_PROPERTY_NOT_IMPLEMENTED;
1794 --mpctx->global_sub_pos;
1795 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1798 /// Selected subtitles from specific source (RW)
1799 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1800 MPContext *mpctx)
1802 int source, is_cur_source, offset, new_pos;
1803 update_global_sub_size(mpctx);
1804 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1805 return M_PROPERTY_UNAVAILABLE;
1807 if (!strcmp(prop->name, "sub_file"))
1808 source = SUB_SOURCE_SUBS;
1809 else if (!strcmp(prop->name, "sub_vob"))
1810 source = SUB_SOURCE_VOBSUB;
1811 else if (!strcmp(prop->name, "sub_demux"))
1812 source = SUB_SOURCE_DEMUX;
1813 else
1814 return M_PROPERTY_ERROR;
1816 offset = sub_pos_by_source(mpctx, source);
1817 if (offset < 0)
1818 return M_PROPERTY_UNAVAILABLE;
1820 is_cur_source = sub_source(mpctx) == source;
1821 new_pos = mpctx->global_sub_pos;
1822 switch (action) {
1823 case M_PROPERTY_GET:
1824 if (!arg)
1825 return M_PROPERTY_ERROR;
1826 if (is_cur_source) {
1827 *(int *) arg = sub_source_pos(mpctx);
1828 if (source == SUB_SOURCE_VOBSUB)
1829 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1831 else
1832 *(int *) arg = -1;
1833 return M_PROPERTY_OK;
1834 case M_PROPERTY_PRINT:
1835 if (!arg)
1836 return M_PROPERTY_ERROR;
1837 if (is_cur_source)
1838 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1839 *(char **) arg = malloc(64);
1840 (*(char **) arg)[63] = 0;
1841 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1842 return M_PROPERTY_OK;
1843 case M_PROPERTY_SET:
1844 if (!arg)
1845 return M_PROPERTY_ERROR;
1846 if (*(int *) arg >= 0) {
1847 int index = *(int *)arg;
1848 if (source == SUB_SOURCE_VOBSUB)
1849 index = vobsub_get_index_by_id(vo_vobsub, index);
1850 new_pos = offset + index;
1851 if (index < 0 || index > mpctx->sub_counts[source]) {
1852 new_pos = -1;
1853 *(int *) arg = -1;
1856 else
1857 new_pos = -1;
1858 break;
1859 case M_PROPERTY_STEP_UP:
1860 case M_PROPERTY_STEP_DOWN: {
1861 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1862 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1863 int step = (step_all > 0) ? 1 : -1;
1864 int max_sub_pos_for_source = -1;
1865 if (!is_cur_source)
1866 new_pos = -1;
1867 while (step_all) {
1868 if (new_pos == -1) {
1869 if (step > 0)
1870 new_pos = offset;
1871 else if (max_sub_pos_for_source == -1) {
1872 // Find max pos for specific source
1873 new_pos = mpctx->global_sub_size - 1;
1874 while (new_pos >= 0
1875 && sub_source(mpctx) != source)
1876 new_pos--;
1878 else
1879 new_pos = max_sub_pos_for_source;
1881 else {
1882 new_pos += step;
1883 if (new_pos < offset ||
1884 new_pos >= mpctx->global_sub_size ||
1885 sub_source(mpctx) != source)
1886 new_pos = -1;
1888 step_all -= step;
1890 break;
1892 default:
1893 return M_PROPERTY_NOT_IMPLEMENTED;
1895 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1898 /// Subtitle delay (RW)
1899 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1900 MPContext *mpctx)
1902 if (!mpctx->sh_video)
1903 return M_PROPERTY_UNAVAILABLE;
1904 return m_property_delay(prop, action, arg, &sub_delay);
1907 /// Alignment of text subtitles (RW)
1908 static int mp_property_sub_alignment(m_option_t *prop, int action,
1909 void *arg, MPContext *mpctx)
1911 char *name[] = { _("top"), _("center"), _("bottom") };
1913 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1914 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1915 return M_PROPERTY_UNAVAILABLE;
1917 switch (action) {
1918 case M_PROPERTY_PRINT:
1919 if (!arg)
1920 return M_PROPERTY_ERROR;
1921 M_PROPERTY_CLAMP(prop, sub_alignment);
1922 *(char **) arg = strdup(mp_gtext(name[sub_alignment]));
1923 return M_PROPERTY_OK;
1924 case M_PROPERTY_SET:
1925 if (!arg)
1926 return M_PROPERTY_ERROR;
1927 case M_PROPERTY_STEP_UP:
1928 case M_PROPERTY_STEP_DOWN:
1929 vo_osd_changed(OSDTYPE_SUBTITLE);
1930 default:
1931 return m_property_choice(prop, action, arg, &sub_alignment);
1935 /// Subtitle visibility (RW)
1936 static int mp_property_sub_visibility(m_option_t *prop, int action,
1937 void *arg, MPContext *mpctx)
1939 if (!mpctx->sh_video)
1940 return M_PROPERTY_UNAVAILABLE;
1942 switch (action) {
1943 case M_PROPERTY_SET:
1944 if (!arg)
1945 return M_PROPERTY_ERROR;
1946 case M_PROPERTY_STEP_UP:
1947 case M_PROPERTY_STEP_DOWN:
1948 vo_osd_changed(OSDTYPE_SUBTITLE);
1949 if (vo_spudec)
1950 vo_osd_changed(OSDTYPE_SPU);
1951 default:
1952 return m_property_flag(prop, action, arg, &sub_visibility);
1956 #ifdef CONFIG_ASS
1957 /// Use margins for libass subtitles (RW)
1958 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1959 void *arg, MPContext *mpctx)
1961 if (!mpctx->sh_video)
1962 return M_PROPERTY_UNAVAILABLE;
1964 switch (action) {
1965 case M_PROPERTY_SET:
1966 if (!arg)
1967 return M_PROPERTY_ERROR;
1968 case M_PROPERTY_STEP_UP:
1969 case M_PROPERTY_STEP_DOWN:
1970 ass_force_reload = 1;
1971 default:
1972 return m_property_flag(prop, action, arg, &ass_use_margins);
1975 #endif
1977 /// Show only forced subtitles (RW)
1978 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1979 void *arg, MPContext *mpctx)
1981 if (!vo_spudec)
1982 return M_PROPERTY_UNAVAILABLE;
1984 switch (action) {
1985 case M_PROPERTY_SET:
1986 if (!arg)
1987 return M_PROPERTY_ERROR;
1988 case M_PROPERTY_STEP_UP:
1989 case M_PROPERTY_STEP_DOWN:
1990 m_property_flag(prop, action, arg, &forced_subs_only);
1991 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1992 return M_PROPERTY_OK;
1993 default:
1994 return m_property_flag(prop, action, arg, &forced_subs_only);
1999 #ifdef CONFIG_FREETYPE
2000 /// Subtitle scale (RW)
2001 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
2002 MPContext *mpctx)
2004 struct MPOpts *opts = &mpctx->opts;
2006 switch (action) {
2007 case M_PROPERTY_SET:
2008 if (!arg)
2009 return M_PROPERTY_ERROR;
2010 M_PROPERTY_CLAMP(prop, *(float *) arg);
2011 #ifdef CONFIG_ASS
2012 if (opts->ass_enabled) {
2013 ass_font_scale = *(float *) arg;
2014 ass_force_reload = 1;
2016 #endif
2017 text_font_scale_factor = *(float *) arg;
2018 force_load_font = 1;
2019 return M_PROPERTY_OK;
2020 case M_PROPERTY_STEP_UP:
2021 case M_PROPERTY_STEP_DOWN:
2022 #ifdef CONFIG_ASS
2023 if (opts->ass_enabled) {
2024 ass_font_scale += (arg ? *(float *) arg : 0.1)*
2025 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2026 M_PROPERTY_CLAMP(prop, ass_font_scale);
2027 ass_force_reload = 1;
2029 #endif
2030 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
2031 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2032 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
2033 force_load_font = 1;
2034 return M_PROPERTY_OK;
2035 default:
2036 #ifdef CONFIG_ASS
2037 if (opts->ass_enabled)
2038 return m_property_float_ro(prop, action, arg, ass_font_scale);
2039 else
2040 #endif
2041 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
2044 #endif
2046 ///@}
2048 /// \defgroup TVProperties TV properties
2049 /// \ingroup Properties
2050 ///@{
2052 #ifdef CONFIG_TV
2054 /// TV color settings (RW)
2055 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2056 MPContext *mpctx)
2058 int r, val;
2059 tvi_handle_t *tvh = mpctx->demuxer->priv;
2060 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2061 return M_PROPERTY_UNAVAILABLE;
2063 switch (action) {
2064 case M_PROPERTY_SET:
2065 if (!arg)
2066 return M_PROPERTY_ERROR;
2067 M_PROPERTY_CLAMP(prop, *(int *) arg);
2068 return tv_set_color_options(tvh, prop->offset, *(int *) arg);
2069 case M_PROPERTY_GET:
2070 return tv_get_color_options(tvh, prop->offset, arg);
2071 case M_PROPERTY_STEP_UP:
2072 case M_PROPERTY_STEP_DOWN:
2073 if ((r = tv_get_color_options(tvh, prop->offset, &val)) >= 0) {
2074 if (!r)
2075 return M_PROPERTY_ERROR;
2076 val += (arg ? *(int *) arg : 1) *
2077 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2078 M_PROPERTY_CLAMP(prop, val);
2079 return tv_set_color_options(tvh, prop->offset, val);
2081 return M_PROPERTY_ERROR;
2083 return M_PROPERTY_NOT_IMPLEMENTED;
2086 #endif
2088 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2089 MPContext *mpctx)
2091 int val,result;
2092 int base_ioctl = prop->offset;
2094 for teletext's GET,SET,STEP ioctls this is not 0
2095 SET is GET+1
2096 STEP is GET+2
2098 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2099 return M_PROPERTY_UNAVAILABLE;
2100 if(!base_ioctl)
2101 return M_PROPERTY_ERROR;
2103 switch (action) {
2104 case M_PROPERTY_GET:
2105 if (!arg)
2106 return M_PROPERTY_ERROR;
2107 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2108 break;
2109 case M_PROPERTY_SET:
2110 if (!arg)
2111 return M_PROPERTY_ERROR;
2112 M_PROPERTY_CLAMP(prop, *(int *) arg);
2113 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
2114 break;
2115 case M_PROPERTY_STEP_UP:
2116 case M_PROPERTY_STEP_DOWN:
2117 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2118 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2119 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
2120 break;
2121 default:
2122 return M_PROPERTY_NOT_IMPLEMENTED;
2125 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2128 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2129 MPContext *mpctx)
2131 int result;
2132 int val;
2134 //with tvh==NULL will fail too
2135 result=mp_property_teletext_common(prop,action,arg,mpctx);
2136 if(result!=M_PROPERTY_OK)
2137 return result;
2139 if(teletext_control(mpctx->demuxer->teletext,
2140 prop->offset, &val)==VBI_CONTROL_TRUE && val)
2141 mp_input_set_section(mpctx->input, "teletext");
2142 else
2143 mp_input_set_section(mpctx->input, "tv");
2144 return M_PROPERTY_OK;
2147 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2148 MPContext *mpctx)
2150 int result;
2151 int val;
2152 if (!mpctx->demuxer->teletext)
2153 return M_PROPERTY_UNAVAILABLE;
2154 switch(action){
2155 case M_PROPERTY_STEP_UP:
2156 case M_PROPERTY_STEP_DOWN:
2157 //This should be handled separately
2158 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2159 result=teletext_control(mpctx->demuxer->teletext,
2160 TV_VBI_CONTROL_STEP_PAGE, &val);
2161 break;
2162 default:
2163 result=mp_property_teletext_common(prop,action,arg,mpctx);
2165 return result;
2168 ///@}
2170 /// All properties available in MPlayer.
2171 /** \ingroup Properties
2173 static const m_option_t mp_properties[] = {
2174 // General
2175 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2176 M_OPT_RANGE, 0, 3, NULL },
2177 { "loop", mp_property_loop, CONF_TYPE_INT,
2178 M_OPT_MIN, -1, 0, NULL },
2179 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2180 M_OPT_RANGE, 0.01, 100.0, NULL },
2181 { "filename", mp_property_filename, CONF_TYPE_STRING,
2182 0, 0, 0, NULL },
2183 { "path", mp_property_path, CONF_TYPE_STRING,
2184 0, 0, 0, NULL },
2185 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2186 0, 0, 0, NULL },
2187 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2188 M_OPT_MIN, 0, 0, NULL },
2189 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2190 M_OPT_MIN, 0, 0, NULL },
2191 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2192 M_OPT_MIN, 0, 0, NULL },
2193 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2194 M_OPT_MIN, 0, 0, NULL },
2195 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2196 M_OPT_MIN, 0, 0, NULL },
2197 { "length", mp_property_length, CONF_TYPE_TIME,
2198 M_OPT_MIN, 0, 0, NULL },
2199 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2200 M_OPT_RANGE, 0, 100, NULL },
2201 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2202 M_OPT_MIN, 0, 0, NULL },
2203 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2204 M_OPT_MIN, 0, 0, NULL },
2205 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2206 0, 0, 0, NULL },
2207 { "angle", mp_property_angle, CONF_TYPE_INT,
2208 CONF_RANGE, -2, 10, NULL },
2209 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2210 0, 0, 0, NULL },
2211 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2212 M_OPT_RANGE, 0, 1, NULL },
2213 { "capturing", mp_property_capture, CONF_TYPE_FLAG,
2214 M_OPT_RANGE, 0, 1, NULL },
2215 { "pts_association_mode", mp_property_generic_option, &m_option_type_choice,
2216 0, 0, 0, "pts-association-mode" },
2217 { "hr_seek", mp_property_generic_option, &m_option_type_choice,
2218 0, 0, 0, "hr-seek" },
2220 // Audio
2221 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2222 M_OPT_RANGE, 0, 100, NULL },
2223 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2224 M_OPT_RANGE, 0, 1, NULL },
2225 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2226 M_OPT_RANGE, -100, 100, NULL },
2227 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2228 0, 0, 0, NULL },
2229 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2230 0, 0, 0, NULL },
2231 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2232 0, 0, 0, NULL },
2233 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2234 0, 0, 0, NULL },
2235 { "channels", mp_property_channels, CONF_TYPE_INT,
2236 0, 0, 0, NULL },
2237 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2238 CONF_RANGE, -2, 65535, NULL },
2239 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2240 M_OPT_RANGE, -1, 1, NULL },
2242 // Video
2243 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2244 M_OPT_RANGE, 0, 1, NULL },
2245 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2246 M_OPT_RANGE, 0, 1, NULL },
2247 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2248 M_OPT_RANGE, 0, 2, NULL },
2249 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2250 M_OPT_RANGE, 0, 1, NULL },
2251 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2252 M_OPT_RANGE, 0, 1, NULL },
2253 { "border", mp_property_border, CONF_TYPE_FLAG,
2254 M_OPT_RANGE, 0, 1, NULL },
2255 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2256 M_OPT_RANGE, 0, 2, NULL },
2257 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2258 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_gamma)},
2259 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2260 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_brightness) },
2261 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2262 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_contrast) },
2263 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2264 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_saturation) },
2265 { "hue", mp_property_gamma, CONF_TYPE_INT,
2266 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_hue) },
2267 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2268 M_OPT_RANGE, 0, 1, NULL },
2269 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2270 M_OPT_RANGE, 0, 1, NULL },
2271 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2272 0, 0, 0, NULL },
2273 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2274 0, 0, 0, NULL },
2275 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2276 0, 0, 0, NULL },
2277 { "width", mp_property_width, CONF_TYPE_INT,
2278 0, 0, 0, NULL },
2279 { "height", mp_property_height, CONF_TYPE_INT,
2280 0, 0, 0, NULL },
2281 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2282 0, 0, 0, NULL },
2283 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2284 0, 0, 0, NULL },
2285 { "switch_video", mp_property_video, CONF_TYPE_INT,
2286 CONF_RANGE, -2, 65535, NULL },
2287 { "switch_program", mp_property_program, CONF_TYPE_INT,
2288 CONF_RANGE, -1, 65535, NULL },
2290 // Subs
2291 { "sub", mp_property_sub, CONF_TYPE_INT,
2292 M_OPT_MIN, -1, 0, NULL },
2293 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2294 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2295 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2296 M_OPT_MIN, -1, 0, NULL },
2297 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2298 M_OPT_MIN, -1, 0, NULL },
2299 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2300 M_OPT_MIN, -1, 0, NULL },
2301 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2302 0, 0, 0, NULL },
2303 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2304 M_OPT_RANGE, 0, 100, NULL },
2305 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2306 M_OPT_RANGE, 0, 2, NULL },
2307 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2308 M_OPT_RANGE, 0, 1, NULL },
2309 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2310 M_OPT_RANGE, 0, 1, NULL },
2311 #ifdef CONFIG_FREETYPE
2312 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2313 M_OPT_RANGE, 0, 100, NULL },
2314 #endif
2315 #ifdef CONFIG_ASS
2316 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2317 M_OPT_RANGE, 0, 1, NULL },
2318 #endif
2320 #ifdef CONFIG_TV
2321 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2322 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_BRIGHTNESS },
2323 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2324 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_CONTRAST },
2325 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2326 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_SATURATION },
2327 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2328 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_HUE },
2329 #endif
2330 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2331 M_OPT_RANGE, 100, 899, .offset=TV_VBI_CONTROL_GET_PAGE },
2332 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2333 M_OPT_RANGE, 0, 64, .offset=TV_VBI_CONTROL_GET_SUBPAGE },
2334 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2335 M_OPT_RANGE, 0, 1, .offset=TV_VBI_CONTROL_GET_MODE },
2336 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2337 M_OPT_RANGE, 0, 3, .offset=TV_VBI_CONTROL_GET_FORMAT },
2338 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2339 M_OPT_RANGE, 0, 2, .offset=TV_VBI_CONTROL_GET_HALF_PAGE },
2340 { NULL, NULL, NULL, 0, 0, 0, NULL }
2344 int mp_property_do(const char *name, int action, void *val, void *ctx)
2346 return m_property_do(mp_properties, name, action, val, ctx);
2349 char* mp_property_print(const char *name, void* ctx)
2351 char* ret = NULL;
2352 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2353 return NULL;
2354 return ret;
2357 char *property_expand_string(MPContext *mpctx, char *str)
2359 return m_properties_expand_string(mp_properties, str, mpctx);
2362 void property_print_help(void)
2364 m_properties_print_help_list(mp_properties);
2368 /* List of default ways to show a property on OSD.
2370 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2371 * a bar showing the current position between min/max values of the
2372 * property. In this case osd_msg is only used for terminal output
2373 * if there is no video; it'll be a label shown together with percentage.
2375 * Otherwise setting osd_msg will show the string on OSD, formatted with
2376 * the text value of the property as argument.
2378 static struct property_osd_display {
2379 /// property name
2380 const char *name;
2381 /// progressbar type
2382 int osd_progbar; // -1 is special value for seek indicators
2383 /// osd msg id if it must be shared
2384 int osd_id;
2385 /// osd msg template
2386 const char *osd_msg;
2387 } property_osd_display[] = {
2388 // general
2389 { "loop", 0, -1, _("Loop: %s") },
2390 { "chapter", -1, -1, NULL },
2391 { "capturing", 0, -1, _("Capturing: %s") },
2392 { "pts_association_mode", 0, -1, "PTS association mode: %s" },
2393 { "hr_seek", 0, -1, "hr-seek: %s" },
2394 // audio
2395 { "volume", OSD_VOLUME, -1, _("Volume") },
2396 { "mute", 0, -1, _("Mute: %s") },
2397 { "audio_delay", 0, -1, _("A-V delay: %s") },
2398 { "switch_audio", 0, -1, _("Audio: %s") },
2399 { "balance", OSD_BALANCE, -1, _("Balance") },
2400 // video
2401 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2402 { "ontop", 0, -1, _("Stay on top: %s") },
2403 { "rootwin", 0, -1, _("Rootwin: %s") },
2404 { "border", 0, -1, _("Border: %s") },
2405 { "framedropping", 0, -1, _("Framedropping: %s") },
2406 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2407 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2408 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2409 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2410 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2411 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2412 { "hue", OSD_HUE, -1, _("Hue") },
2413 { "vsync", 0, -1, _("VSync: %s") },
2414 // subs
2415 { "sub", 0, -1, _("Subtitles: %s") },
2416 { "sub_source", 0, -1, _("Sub source: %s") },
2417 { "sub_vob", 0, -1, _("Subtitles: %s") },
2418 { "sub_demux", 0, -1, _("Subtitles: %s") },
2419 { "sub_file", 0, -1, _("Subtitles: %s") },
2420 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2421 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2422 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2423 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2424 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2425 #ifdef CONFIG_FREETYPE
2426 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2427 #endif
2428 #ifdef CONFIG_TV
2429 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2430 { "tv_hue", OSD_HUE, -1, _("Hue") },
2431 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2432 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2433 #endif
2437 static int show_property_osd(MPContext *mpctx, const char *pname)
2439 struct MPOpts *opts = &mpctx->opts;
2440 int r;
2441 m_option_t* prop;
2442 struct property_osd_display *p;
2444 // look for the command
2445 for (p = property_osd_display; p->name; p++)
2446 if (!strcmp(p->name, pname))
2447 break;
2448 if (!p->name)
2449 return -1;
2451 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2452 return -1;
2454 if (p->osd_progbar == -1)
2455 mpctx->add_osd_seek_info = true;
2456 else if (p->osd_progbar) {
2457 if (prop->type == CONF_TYPE_INT) {
2458 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2459 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2460 prop->min, prop->max, r);
2461 } else if (prop->type == CONF_TYPE_FLOAT) {
2462 float f;
2463 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2464 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2465 prop->min, prop->max, f);
2466 } else {
2467 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2468 "Property use an unsupported type.\n");
2469 return -1;
2471 return 0;
2474 if (p->osd_msg) {
2475 char *val = mp_property_print(pname, mpctx);
2476 if (val) {
2477 int index = p - property_osd_display;
2478 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2479 1, opts->osd_duration, p->osd_msg, val);
2480 free(val);
2483 return 0;
2488 * \defgroup Command2Property Command to property bridge
2490 * It is used to handle most commands that just set a property
2491 * and optionally display something on the OSD.
2492 * Two kinds of commands are handled: adjust or toggle.
2494 * Adjust commands take 1 or 2 parameters: <value> <abs>
2495 * If <abs> is non-zero the property is set to the given value
2496 * otherwise it is adjusted.
2498 * Toggle commands take 0 or 1 parameters. With no parameter
2499 * or a value less than the property minimum it just steps the
2500 * property to its next or previous value respectively.
2501 * Otherwise it sets it to the given value.
2506 /// List of the commands that can be handled by setting a property.
2507 static struct {
2508 /// property name
2509 const char *name;
2510 /// cmd id
2511 int cmd;
2512 /// set/adjust or toggle command
2513 int toggle;
2514 } set_prop_cmd[] = {
2515 // general
2516 { "loop", MP_CMD_LOOP, 0},
2517 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2518 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2519 { "pause", MP_CMD_PAUSE, 0},
2520 { "capturing", MP_CMD_CAPTURING, 1},
2521 // audio
2522 { "volume", MP_CMD_VOLUME, 0},
2523 { "mute", MP_CMD_MUTE, 1},
2524 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2525 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2526 { "balance", MP_CMD_BALANCE, 0},
2527 // video
2528 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2529 { "panscan", MP_CMD_PANSCAN, 0},
2530 { "ontop", MP_CMD_VO_ONTOP, 1},
2531 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2532 { "border", MP_CMD_VO_BORDER, 1},
2533 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2534 { "gamma", MP_CMD_GAMMA, 0},
2535 { "brightness", MP_CMD_BRIGHTNESS, 0},
2536 { "contrast", MP_CMD_CONTRAST, 0},
2537 { "saturation", MP_CMD_SATURATION, 0},
2538 { "hue", MP_CMD_HUE, 0},
2539 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2540 // subs
2541 { "sub", MP_CMD_SUB_SELECT, 1},
2542 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2543 { "sub_vob", MP_CMD_SUB_VOB, 1},
2544 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2545 { "sub_file", MP_CMD_SUB_FILE, 1},
2546 { "sub_pos", MP_CMD_SUB_POS, 0},
2547 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2548 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2549 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2550 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2551 #ifdef CONFIG_FREETYPE
2552 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2553 #endif
2554 #ifdef CONFIG_ASS
2555 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2556 #endif
2557 #ifdef CONFIG_TV
2558 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2559 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2560 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2561 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2562 #endif
2566 /// Handle commands that set a property.
2567 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2569 int i, r;
2570 m_option_t *prop;
2571 const char *pname;
2573 // look for the command
2574 for (i = 0; set_prop_cmd[i].name; i++)
2575 if (set_prop_cmd[i].cmd == cmd->id)
2576 break;
2577 if (!(pname = set_prop_cmd[i].name))
2578 return 0;
2580 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2581 return 0;
2583 // toggle command
2584 if (set_prop_cmd[i].toggle) {
2585 // set to value
2586 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2587 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2588 else if (cmd->nargs > 0)
2589 r = mp_property_do(pname, M_PROPERTY_STEP_DOWN, NULL, mpctx);
2590 else
2591 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2592 } else if (cmd->args[1].v.i) //set
2593 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2594 else // adjust
2595 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2597 if (r <= 0)
2598 return 1;
2600 show_property_osd(mpctx, pname);
2602 return 1;
2605 #ifdef CONFIG_DVDNAV
2606 static const struct {
2607 const char *name;
2608 const mp_command_type cmd;
2609 } mp_dvdnav_bindings[] = {
2610 { "up", MP_CMD_DVDNAV_UP },
2611 { "down", MP_CMD_DVDNAV_DOWN },
2612 { "left", MP_CMD_DVDNAV_LEFT },
2613 { "right", MP_CMD_DVDNAV_RIGHT },
2614 { "menu", MP_CMD_DVDNAV_MENU },
2615 { "select", MP_CMD_DVDNAV_SELECT },
2616 { "prev", MP_CMD_DVDNAV_PREVMENU },
2617 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2620 * keep old dvdnav sub-command options for a while in order not to
2621 * break slave-mode API too suddenly.
2623 { "1", MP_CMD_DVDNAV_UP },
2624 { "2", MP_CMD_DVDNAV_DOWN },
2625 { "3", MP_CMD_DVDNAV_LEFT },
2626 { "4", MP_CMD_DVDNAV_RIGHT },
2627 { "5", MP_CMD_DVDNAV_MENU },
2628 { "6", MP_CMD_DVDNAV_SELECT },
2629 { "7", MP_CMD_DVDNAV_PREVMENU },
2630 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2631 { NULL, 0 }
2633 #endif
2635 static const char *property_error_string(int error_value)
2637 switch (error_value) {
2638 case M_PROPERTY_ERROR:
2639 return "ERROR";
2640 case M_PROPERTY_UNAVAILABLE:
2641 return "PROPERTY_UNAVAILABLE";
2642 case M_PROPERTY_NOT_IMPLEMENTED:
2643 return "NOT_IMPLEMENTED";
2644 case M_PROPERTY_UNKNOWN:
2645 return "PROPERTY_UNKNOWN";
2646 case M_PROPERTY_DISABLED:
2647 return "DISABLED";
2649 return "UNKNOWN";
2652 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2654 int idx;
2655 int end = start + count;
2656 int after = mpctx->set_of_sub_size - end;
2657 sub_data **subs = mpctx->set_of_subtitles;
2658 #ifdef CONFIG_ASS
2659 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2660 #endif
2661 if (count < 0 || count > mpctx->set_of_sub_size ||
2662 start < 0 || start > mpctx->set_of_sub_size - count) {
2663 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2664 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2665 return;
2667 for (idx = start; idx < end; idx++) {
2668 sub_data *subd = subs[idx];
2669 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2670 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2671 filename_recode(subd->filename));
2672 sub_free(subd);
2673 subs[idx] = NULL;
2674 #ifdef CONFIG_ASS
2675 if (ass_tracks[idx])
2676 ass_free_track(ass_tracks[idx]);
2677 ass_tracks[idx] = NULL;
2678 #endif
2681 mpctx->global_sub_size -= count;
2682 mpctx->set_of_sub_size -= count;
2683 if (mpctx->set_of_sub_size <= 0)
2684 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2686 memmove(subs + start, subs + end, after * sizeof(*subs));
2687 memset(subs + start + after, 0, count * sizeof(*subs));
2688 #ifdef CONFIG_ASS
2689 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2690 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2691 #endif
2693 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2694 mpctx->global_sub_pos = -2;
2695 mpctx->subdata = NULL;
2696 mpctx->osd->ass_track = NULL;
2697 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2698 } else if (mpctx->set_of_sub_pos >= end) {
2699 mpctx->set_of_sub_pos -= count;
2700 mpctx->global_sub_pos -= count;
2704 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2706 struct MPOpts *opts = &mpctx->opts;
2707 sh_audio_t * const sh_audio = mpctx->sh_audio;
2708 sh_video_t * const sh_video = mpctx->sh_video;
2709 int osd_duration = opts->osd_duration;
2710 int case_fallthrough_hack = 0;
2711 if (!set_property_command(mpctx, cmd))
2712 switch (cmd->id) {
2713 case MP_CMD_SEEK:{
2714 mpctx->add_osd_seek_info = true;
2715 float v = cmd->args[0].v.f;
2716 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2717 int exact = (cmd->nargs > 2) ? cmd->args[2].v.i : 0;
2718 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2719 queue_seek(mpctx, MPSEEK_ABSOLUTE, v, exact);
2720 mpctx->osd_function = v > get_current_time(mpctx) ?
2721 OSD_FFW : OSD_REW;
2722 } else if (abs) { /* Absolute seek by percentage */
2723 queue_seek(mpctx, MPSEEK_FACTOR, v / 100.0, exact);
2724 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2725 } else {
2726 queue_seek(mpctx, MPSEEK_RELATIVE, v, exact);
2727 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2730 break;
2732 case MP_CMD_SET_PROPERTY_OSD:
2733 case_fallthrough_hack = 1;
2735 case MP_CMD_SET_PROPERTY:{
2736 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2737 cmd->args[1].v.s, mpctx);
2738 if (r == M_PROPERTY_UNKNOWN)
2739 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2740 "Unknown property: '%s'\n", cmd->args[0].v.s);
2741 else if (r <= 0)
2742 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2743 "Failed to set property '%s' to '%s'.\n",
2744 cmd->args[0].v.s, cmd->args[1].v.s);
2745 else if (case_fallthrough_hack)
2746 show_property_osd(mpctx, cmd->args[0].v.s);
2747 if (r <= 0)
2748 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2750 break;
2752 case MP_CMD_STEP_PROPERTY_OSD:
2753 case_fallthrough_hack = 1;
2755 case MP_CMD_STEP_PROPERTY:{
2756 void* arg = NULL;
2757 int r,i;
2758 double d;
2759 off_t o;
2760 if (cmd->args[1].v.f) {
2761 m_option_t* prop;
2762 if((r = mp_property_do(cmd->args[0].v.s,
2763 M_PROPERTY_GET_TYPE,
2764 &prop, mpctx)) <= 0)
2765 goto step_prop_err;
2766 if(prop->type == CONF_TYPE_INT ||
2767 prop->type == CONF_TYPE_FLAG)
2768 i = cmd->args[1].v.f, arg = &i;
2769 else if(prop->type == CONF_TYPE_FLOAT)
2770 arg = &cmd->args[1].v.f;
2771 else if(prop->type == CONF_TYPE_DOUBLE ||
2772 prop->type == CONF_TYPE_TIME)
2773 d = cmd->args[1].v.f, arg = &d;
2774 else if(prop->type == CONF_TYPE_POSITION)
2775 o = cmd->args[1].v.f, arg = &o;
2776 else
2777 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2778 "Ignoring step size stepping property '%s'.\n",
2779 cmd->args[0].v.s);
2781 r = mp_property_do(cmd->args[0].v.s,
2782 cmd->args[2].v.i < 0 ?
2783 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2784 arg, mpctx);
2785 step_prop_err:
2786 if (r == M_PROPERTY_UNKNOWN)
2787 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2788 "Unknown property: '%s'\n", cmd->args[0].v.s);
2789 else if (r <= 0)
2790 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2791 "Failed to increment property '%s' by %f.\n",
2792 cmd->args[0].v.s, cmd->args[1].v.f);
2793 else if (case_fallthrough_hack)
2794 show_property_osd(mpctx, cmd->args[0].v.s);
2795 if (r <= 0)
2796 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2798 break;
2800 case MP_CMD_GET_PROPERTY:{
2801 char *tmp;
2802 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2803 &tmp, mpctx);
2804 if (r <= 0) {
2805 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2806 "Failed to get value of property '%s'.\n",
2807 cmd->args[0].v.s);
2808 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2809 break;
2811 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2812 cmd->args[0].v.s, tmp);
2813 free(tmp);
2815 break;
2817 case MP_CMD_EDL_MARK:
2818 if (edl_fd) {
2819 float v = get_current_time(mpctx);
2820 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2821 mpctx->begin_skip = v;
2822 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2823 } else {
2824 if (mpctx->begin_skip > v)
2825 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2826 else {
2827 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2828 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2830 mpctx->begin_skip = MP_NOPTS_VALUE;
2833 break;
2835 case MP_CMD_SWITCH_RATIO:
2836 if (!sh_video)
2837 break;
2838 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2839 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2840 else
2841 opts->movie_aspect = cmd->args[0].v.f;
2842 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2843 break;
2845 case MP_CMD_SPEED_INCR:{
2846 float v = cmd->args[0].v.f;
2847 opts->playback_speed += v;
2848 reinit_audio_chain(mpctx);
2849 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2850 opts->playback_speed);
2851 } break;
2853 case MP_CMD_SPEED_MULT:{
2854 float v = cmd->args[0].v.f;
2855 opts->playback_speed *= v;
2856 reinit_audio_chain(mpctx);
2857 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2858 opts->playback_speed);
2859 } break;
2861 case MP_CMD_SPEED_SET:{
2862 float v = cmd->args[0].v.f;
2863 opts->playback_speed = v;
2864 reinit_audio_chain(mpctx);
2865 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2866 opts->playback_speed);
2867 } break;
2869 case MP_CMD_FRAME_STEP:
2870 add_step_frame(mpctx);
2871 break;
2873 case MP_CMD_FILE_FILTER:
2874 file_filter = cmd->args[0].v.i;
2875 break;
2877 case MP_CMD_QUIT:
2878 exit_player_with_rc(mpctx, EXIT_QUIT,
2879 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2881 case MP_CMD_PLAY_TREE_STEP:{
2882 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2883 int force = cmd->args[1].v.i;
2886 if (!force && mpctx->playtree_iter) {
2887 play_tree_iter_t *i =
2888 play_tree_iter_new_copy(mpctx->playtree_iter);
2889 if (play_tree_iter_step(i, n, 0) ==
2890 PLAY_TREE_ITER_ENTRY)
2891 mpctx->stop_play =
2892 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2893 play_tree_iter_free(i);
2894 } else
2895 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2896 if (mpctx->stop_play)
2897 mpctx->play_tree_step = n;
2900 break;
2902 case MP_CMD_PLAY_TREE_UP_STEP:{
2903 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2904 int force = cmd->args[1].v.i;
2906 if (!force && mpctx->playtree_iter) {
2907 play_tree_iter_t *i =
2908 play_tree_iter_new_copy(mpctx->playtree_iter);
2909 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2910 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2911 play_tree_iter_free(i);
2912 } else
2913 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2915 break;
2917 case MP_CMD_PLAY_ALT_SRC_STEP:
2918 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2919 int v = cmd->args[0].v.i;
2920 if (v > 0
2921 && mpctx->playtree_iter->file <
2922 mpctx->playtree_iter->num_files)
2923 mpctx->stop_play = PT_NEXT_SRC;
2924 else if (v < 0 && mpctx->playtree_iter->file > 1)
2925 mpctx->stop_play = PT_PREV_SRC;
2927 break;
2929 case MP_CMD_SUB_STEP:
2930 if (sh_video) {
2931 int movement = cmd->args[0].v.i;
2932 step_sub(mpctx->subdata, mpctx->video_pts, movement);
2933 #ifdef CONFIG_ASS
2934 if (mpctx->osd->ass_track)
2935 sub_delay +=
2936 ass_step_sub(mpctx->osd->ass_track,
2937 (mpctx->video_pts +
2938 sub_delay) * 1000 + .5, movement) / 1000.;
2939 #endif
2940 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2941 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2943 break;
2945 case MP_CMD_SUB_LOG:
2946 log_sub(mpctx);
2947 break;
2949 case MP_CMD_OSD:{
2950 int v = cmd->args[0].v.i;
2951 int max = (opts->term_osd
2952 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2953 if (opts->osd_level > max)
2954 opts->osd_level = max;
2955 if (v < 0)
2956 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2957 else
2958 opts->osd_level = v > max ? max : v;
2959 /* Show OSD state when disabled, but not when an explicit
2960 argument is given to the OSD command, i.e. in slave mode. */
2961 if (v == -1 && opts->osd_level <= 1)
2962 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2963 "OSD: %s",
2964 opts->osd_level ? mp_gtext("enabled") :
2965 mp_gtext("disabled"));
2966 else
2967 rm_osd_msg(OSD_MSG_OSD_STATUS);
2969 break;
2971 case MP_CMD_OSD_SHOW_TEXT:
2972 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2973 (cmd->args[1].v.i <
2974 0 ? osd_duration : cmd->args[1].v.i),
2975 "%-.63s", cmd->args[0].v.s);
2976 break;
2978 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2979 char *txt = m_properties_expand_string(mp_properties,
2980 cmd->args[0].v.s,
2981 mpctx);
2982 /* if no argument supplied take default osd_duration, else <arg> ms. */
2983 if (txt) {
2984 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2985 (cmd->args[1].v.i <
2986 0 ? osd_duration : cmd->args[1].v.i),
2987 "%-.63s", txt);
2988 free(txt);
2991 break;
2993 case MP_CMD_LOADFILE:{
2994 play_tree_t *e = play_tree_new();
2995 play_tree_add_file(e, cmd->args[0].v.s);
2997 if (cmd->args[1].v.i) // append
2998 play_tree_append_entry(mpctx->playtree->child, e);
2999 else {
3000 // Go back to the starting point.
3001 while (play_tree_iter_up_step
3002 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3003 /* NOP */ ;
3004 play_tree_free_list(mpctx->playtree->child, 1);
3005 play_tree_set_child(mpctx->playtree, e);
3006 pt_iter_goto_head(mpctx->playtree_iter);
3007 mpctx->stop_play = PT_NEXT_SRC;
3010 break;
3012 case MP_CMD_LOADLIST:{
3013 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
3014 if (!e)
3015 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
3016 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
3017 else {
3018 if (cmd->args[1].v.i) // append
3019 play_tree_append_entry(mpctx->playtree->child, e);
3020 else {
3021 // Go back to the starting point.
3022 while (play_tree_iter_up_step
3023 (mpctx->playtree_iter, 0, 1)
3024 != PLAY_TREE_ITER_END)
3025 /* NOP */ ;
3026 play_tree_free_list(mpctx->playtree->child, 1);
3027 play_tree_set_child(mpctx->playtree, e);
3028 pt_iter_goto_head(mpctx->playtree_iter);
3029 mpctx->stop_play = PT_NEXT_SRC;
3033 break;
3035 case MP_CMD_STOP:
3036 // Go back to the starting point.
3037 while (play_tree_iter_up_step
3038 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3039 /* NOP */ ;
3040 mpctx->stop_play = PT_STOP;
3041 break;
3043 case MP_CMD_OSD_SHOW_PROGRESSION:{
3044 int len = get_time_length(mpctx);
3045 int pts = get_current_time(mpctx);
3046 set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3047 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3048 "%c %02d:%02d:%02d / %02d:%02d:%02d",
3049 mpctx->osd_function, pts/3600, (pts/60)%60, pts%60,
3050 len/3600, (len/60)%60, len%60);
3052 break;
3054 #ifdef CONFIG_RADIO
3055 case MP_CMD_RADIO_STEP_CHANNEL:
3056 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3057 int v = cmd->args[0].v.i;
3058 if (v > 0)
3059 radio_step_channel(mpctx->demuxer->stream,
3060 RADIO_CHANNEL_HIGHER);
3061 else
3062 radio_step_channel(mpctx->demuxer->stream,
3063 RADIO_CHANNEL_LOWER);
3064 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3065 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3066 "Channel: %s",
3067 radio_get_channel_name(mpctx->demuxer->stream));
3070 break;
3072 case MP_CMD_RADIO_SET_CHANNEL:
3073 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3074 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3075 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3076 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3077 "Channel: %s",
3078 radio_get_channel_name(mpctx->demuxer->stream));
3081 break;
3083 case MP_CMD_RADIO_SET_FREQ:
3084 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3085 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3086 break;
3088 case MP_CMD_RADIO_STEP_FREQ:
3089 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3090 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3091 break;
3092 #endif
3094 #ifdef CONFIG_TV
3095 case MP_CMD_TV_START_SCAN:
3096 if (mpctx->file_format == DEMUXER_TYPE_TV)
3097 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
3098 break;
3099 case MP_CMD_TV_SET_FREQ:
3100 if (mpctx->file_format == DEMUXER_TYPE_TV)
3101 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3102 cmd->args[0].v.f * 16.0);
3103 #ifdef CONFIG_PVR
3104 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3105 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
3106 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3107 pvr_get_current_channelname (mpctx->stream),
3108 pvr_get_current_stationname (mpctx->stream));
3110 #endif /* CONFIG_PVR */
3111 break;
3113 case MP_CMD_TV_STEP_FREQ:
3114 if (mpctx->file_format == DEMUXER_TYPE_TV)
3115 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3116 cmd->args[0].v.f * 16.0);
3117 #ifdef CONFIG_PVR
3118 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3119 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
3120 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3121 pvr_get_current_channelname (mpctx->stream),
3122 pvr_get_current_frequency (mpctx->stream));
3124 #endif /* CONFIG_PVR */
3125 break;
3127 case MP_CMD_TV_SET_NORM:
3128 if (mpctx->file_format == DEMUXER_TYPE_TV)
3129 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3130 cmd->args[0].v.s);
3131 break;
3133 case MP_CMD_TV_STEP_CHANNEL:{
3134 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3135 int v = cmd->args[0].v.i;
3136 if (v > 0) {
3137 tv_step_channel((tvi_handle_t *) (mpctx->
3138 demuxer->priv),
3139 TV_CHANNEL_HIGHER);
3140 } else {
3141 tv_step_channel((tvi_handle_t *) (mpctx->
3142 demuxer->priv),
3143 TV_CHANNEL_LOWER);
3145 if (tv_channel_list) {
3146 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3147 "Channel: %s", tv_channel_current->name);
3148 //vo_osd_changed(OSDTYPE_SUBTITLE);
3151 #ifdef CONFIG_PVR
3152 else if (mpctx->stream &&
3153 mpctx->stream->type == STREAMTYPE_PVR) {
3154 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3155 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3156 pvr_get_current_channelname (mpctx->stream),
3157 pvr_get_current_stationname (mpctx->stream));
3159 #endif /* CONFIG_PVR */
3161 #ifdef CONFIG_DVBIN
3162 if (mpctx->stream->type == STREAMTYPE_DVB) {
3163 int dir;
3164 int v = cmd->args[0].v.i;
3166 mpctx->last_dvb_step = v;
3167 if (v > 0)
3168 dir = DVB_CHANNEL_HIGHER;
3169 else
3170 dir = DVB_CHANNEL_LOWER;
3173 if (dvb_step_channel(mpctx->stream, dir)) {
3174 mpctx->stop_play = PT_NEXT_ENTRY;
3175 mpctx->dvbin_reopen = 1;
3178 #endif /* CONFIG_DVBIN */
3179 break;
3181 case MP_CMD_TV_SET_CHANNEL:
3182 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3183 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3184 cmd->args[0].v.s);
3185 if (tv_channel_list) {
3186 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3187 "Channel: %s", tv_channel_current->name);
3188 //vo_osd_changed(OSDTYPE_SUBTITLE);
3191 #ifdef CONFIG_PVR
3192 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3193 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3194 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3195 pvr_get_current_channelname (mpctx->stream),
3196 pvr_get_current_stationname (mpctx->stream));
3198 #endif /* CONFIG_PVR */
3199 break;
3201 #ifdef CONFIG_DVBIN
3202 case MP_CMD_DVB_SET_CHANNEL:
3203 if (mpctx->stream->type == STREAMTYPE_DVB) {
3204 mpctx->last_dvb_step = 1;
3206 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3207 cmd->args[0].v.i)) {
3208 mpctx->stop_play = PT_NEXT_ENTRY;
3209 mpctx->dvbin_reopen = 1;
3212 break;
3213 #endif /* CONFIG_DVBIN */
3215 case MP_CMD_TV_LAST_CHANNEL:
3216 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3217 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3218 if (tv_channel_list) {
3219 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3220 "Channel: %s", tv_channel_current->name);
3221 //vo_osd_changed(OSDTYPE_SUBTITLE);
3224 #ifdef CONFIG_PVR
3225 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3226 pvr_set_lastchannel (mpctx->stream);
3227 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3228 pvr_get_current_channelname (mpctx->stream),
3229 pvr_get_current_stationname (mpctx->stream));
3231 #endif /* CONFIG_PVR */
3232 break;
3234 case MP_CMD_TV_STEP_NORM:
3235 if (mpctx->file_format == DEMUXER_TYPE_TV)
3236 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3237 break;
3239 case MP_CMD_TV_STEP_CHANNEL_LIST:
3240 if (mpctx->file_format == DEMUXER_TYPE_TV)
3241 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3242 break;
3243 #endif /* CONFIG_TV */
3244 case MP_CMD_TV_TELETEXT_ADD_DEC:
3245 if (mpctx->demuxer->teletext)
3246 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3247 &(cmd->args[0].v.s));
3248 break;
3249 case MP_CMD_TV_TELETEXT_GO_LINK:
3250 if (mpctx->demuxer->teletext)
3251 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3252 &(cmd->args[0].v.i));
3253 break;
3255 case MP_CMD_SUB_LOAD:
3256 if (sh_video) {
3257 int n = mpctx->set_of_sub_size;
3258 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3259 if (n != mpctx->set_of_sub_size) {
3260 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3261 ++mpctx->global_sub_size;
3264 break;
3266 case MP_CMD_SUB_REMOVE:
3267 if (sh_video) {
3268 int v = cmd->args[0].v.i;
3269 if (v < 0) {
3270 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3271 } else if (v < mpctx->set_of_sub_size) {
3272 remove_subtitle_range(mpctx, v, 1);
3275 break;
3277 case MP_CMD_GET_SUB_VISIBILITY:
3278 if (sh_video) {
3279 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3280 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3282 break;
3284 case MP_CMD_SCREENSHOT:
3285 if (mpctx->video_out && mpctx->video_out->config_ok) {
3286 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3287 if (CONTROL_OK !=
3288 ((vf_instance_t *) sh_video->vfilter)->
3289 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3290 &cmd->args[0].v.i))
3291 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3293 break;
3295 case MP_CMD_VF_CHANGE_RECTANGLE:
3296 if (!sh_video)
3297 break;
3298 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3299 break;
3301 case MP_CMD_GET_TIME_LENGTH:{
3302 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3303 get_time_length(mpctx));
3305 break;
3307 case MP_CMD_GET_FILENAME:{
3308 char *inf = get_metadata(mpctx, META_NAME);
3309 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n", inf);
3310 talloc_free(inf);
3312 break;
3314 case MP_CMD_GET_VIDEO_CODEC:{
3315 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3316 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3317 talloc_free(inf);
3319 break;
3321 case MP_CMD_GET_VIDEO_BITRATE:{
3322 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3323 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3324 talloc_free(inf);
3326 break;
3328 case MP_CMD_GET_VIDEO_RESOLUTION:{
3329 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3330 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3331 talloc_free(inf);
3333 break;
3335 case MP_CMD_GET_AUDIO_CODEC:{
3336 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3337 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3338 talloc_free(inf);
3340 break;
3342 case MP_CMD_GET_AUDIO_BITRATE:{
3343 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3344 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3345 talloc_free(inf);
3347 break;
3349 case MP_CMD_GET_AUDIO_SAMPLES:{
3350 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3351 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3352 talloc_free(inf);
3354 break;
3356 case MP_CMD_GET_META_TITLE:{
3357 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3358 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3359 talloc_free(inf);
3361 break;
3363 case MP_CMD_GET_META_ARTIST:{
3364 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3365 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3366 talloc_free(inf);
3368 break;
3370 case MP_CMD_GET_META_ALBUM:{
3371 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3372 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3373 talloc_free(inf);
3375 break;
3377 case MP_CMD_GET_META_YEAR:{
3378 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3379 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3380 talloc_free(inf);
3382 break;
3384 case MP_CMD_GET_META_COMMENT:{
3385 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3386 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3387 talloc_free(inf);
3389 break;
3391 case MP_CMD_GET_META_TRACK:{
3392 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3393 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3394 talloc_free(inf);
3396 break;
3398 case MP_CMD_GET_META_GENRE:{
3399 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3400 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3401 talloc_free(inf);
3403 break;
3405 case MP_CMD_GET_VO_FULLSCREEN:
3406 if (mpctx->video_out && mpctx->video_out->config_ok)
3407 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3408 break;
3410 case MP_CMD_GET_PERCENT_POS:
3411 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3412 get_percent_pos(mpctx));
3413 break;
3415 case MP_CMD_GET_TIME_POS:{
3416 float pos = get_current_time(mpctx);
3417 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3419 break;
3421 case MP_CMD_RUN:
3422 #ifndef __MINGW32__
3423 if (!fork()) {
3424 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3425 exit(0);
3427 #endif
3428 break;
3430 case MP_CMD_KEYDOWN_EVENTS:
3431 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3432 break;
3434 case MP_CMD_SET_MOUSE_POS:{
3435 int pointer_x, pointer_y;
3436 double dx, dy;
3437 pointer_x = cmd->args[0].v.i;
3438 pointer_y = cmd->args[1].v.i;
3439 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3440 #ifdef CONFIG_DVDNAV
3441 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3442 && dx > 0.0 && dy > 0.0) {
3443 int button = -1;
3444 pointer_x = (int) (dx * (double) sh_video->disp_w);
3445 pointer_y = (int) (dy * (double) sh_video->disp_h);
3446 mp_dvdnav_update_mouse_pos(mpctx->stream,
3447 pointer_x, pointer_y, &button);
3448 if (opts->osd_level > 1 && button > 0)
3449 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3450 "Selected button number %d", button);
3452 #endif
3453 #ifdef CONFIG_MENU
3454 if (use_menu && dx >= 0.0 && dy >= 0.0)
3455 menu_update_mouse_pos(dx, dy);
3456 #endif
3458 break;
3460 #ifdef CONFIG_DVDNAV
3461 case MP_CMD_DVDNAV:{
3462 int button = -1;
3463 int i;
3464 mp_command_type command = 0;
3465 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3466 break;
3468 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3469 if (cmd->args[0].v.s &&
3470 !strcasecmp (cmd->args[0].v.s,
3471 mp_dvdnav_bindings[i].name))
3472 command = mp_dvdnav_bindings[i].cmd;
3474 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3475 if (opts->osd_level > 1 && button > 0)
3476 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3477 "Selected button number %d", button);
3479 break;
3481 case MP_CMD_SWITCH_TITLE:
3482 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3483 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3484 break;
3486 #endif
3488 case MP_CMD_AF_SWITCH:
3489 if (sh_audio)
3491 af_uninit(mpctx->mixer.afilter);
3492 af_init(mpctx->mixer.afilter);
3494 case MP_CMD_AF_ADD:
3495 case MP_CMD_AF_DEL:
3496 if (!sh_audio)
3497 break;
3499 char* af_args = strdup(cmd->args[0].v.s);
3500 char* af_commands = af_args;
3501 char* af_command;
3502 af_instance_t* af;
3503 while ((af_command = strsep(&af_commands, ",")) != NULL)
3505 if (cmd->id == MP_CMD_AF_DEL)
3507 af = af_get(mpctx->mixer.afilter, af_command);
3508 if (af != NULL)
3509 af_remove(mpctx->mixer.afilter, af);
3511 else
3512 af_add(mpctx->mixer.afilter, af_command);
3514 reinit_audio_chain(mpctx);
3515 free(af_args);
3517 break;
3518 case MP_CMD_AF_CLR:
3519 if (!sh_audio)
3520 break;
3521 af_uninit(mpctx->mixer.afilter);
3522 af_init(mpctx->mixer.afilter);
3523 reinit_audio_chain(mpctx);
3524 break;
3525 case MP_CMD_AF_CMDLINE:
3526 if (sh_audio) {
3527 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3528 if (!af) {
3529 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3530 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3531 break;
3533 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3534 af_reinit(sh_audio->afilter, af);
3536 break;
3538 default:
3539 mp_msg(MSGT_CPLAYER, MSGL_V,
3540 "Received unknown cmd %s\n", cmd->name);
3543 switch (cmd->pausing) {
3544 case 1: // "pausing"
3545 pause_player(mpctx);
3546 break;
3547 case 3: // "pausing_toggle"
3548 if (mpctx->paused)
3549 unpause_player(mpctx);
3550 else
3551 pause_player(mpctx);
3552 break;