demux_ts: fix several memleaks
[mplayer/greg.git] / command.c
blobaa4fb7cb2ba69daafed9149dd0f98ac3546e3674
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdlib.h>
20 #include <inttypes.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <stdbool.h>
25 #include "config.h"
26 #include "talloc.h"
27 #include "command.h"
28 #include "input/input.h"
29 #include "stream/stream.h"
30 #include "libmpdemux/demuxer.h"
31 #include "libmpdemux/stheader.h"
32 #include "codec-cfg.h"
33 #include "mplayer.h"
34 #include "libvo/sub.h"
35 #include "m_option.h"
36 #include "m_property.h"
37 #include "metadata.h"
38 #include "libmpcodecs/vf.h"
39 #include "libmpcodecs/vd.h"
40 #include "mp_osd.h"
41 #include "libvo/video_out.h"
42 #include "libvo/font_load.h"
43 #include "playtree.h"
44 #include "libao2/audio_out.h"
45 #include "mpcommon.h"
46 #include "mixer.h"
47 #include "libmpcodecs/dec_video.h"
48 #include "libmpcodecs/dec_audio.h"
49 #include "libmpcodecs/dec_teletext.h"
50 #include "vobsub.h"
51 #include "spudec.h"
52 #include "path.h"
53 #include "ass_mp.h"
54 #include "stream/tv.h"
55 #include "stream/stream_radio.h"
56 #include "stream/pvr.h"
57 #ifdef CONFIG_DVBIN
58 #include "stream/dvbin.h"
59 #endif
60 #ifdef CONFIG_DVDREAD
61 #include "stream/stream_dvd.h"
62 #endif
63 #include "stream/stream_dvdnav.h"
64 #include "m_struct.h"
65 #include "libmenu/menu.h"
67 #include "mp_core.h"
68 #include "mp_fifo.h"
69 #include "libavutil/avstring.h"
71 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
73 extern int use_menu;
75 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
76 double *dx, double *dy)
78 struct MPOpts *opts = &mpctx->opts;
79 struct vo *vo = mpctx->video_out;
80 //remove the borders, if any, and rescale to the range [0,1],[0,1]
81 if (vo_fs) { //we are in full-screen mode
82 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
83 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
84 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
85 iy -= (opts->vo_screenheight - vo->dheight) / 2;
87 if (ix < 0 || ix > vo->dwidth) {
88 *dx = *dy = -1.0;
89 return;
90 } //we are on one of the borders
91 if (iy < 0 || iy > vo->dheight) {
92 *dx = *dy = -1.0;
93 return;
94 } //we are on one of the borders
97 *dx = (double) ix / (double) vo->dwidth;
98 *dy = (double) iy / (double) vo->dheight;
100 mp_msg(MSGT_CPLAYER, MSGL_V,
101 "\r\nrescaled coordinates: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
102 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
103 vo->dheight, vo_fs);
106 static int sub_pos_by_source(MPContext *mpctx, int src)
108 int i, cnt = 0;
109 if (src >= SUB_SOURCES || mpctx->sub_counts[src] == 0)
110 return -1;
111 for (i = 0; i < src; i++)
112 cnt += mpctx->sub_counts[i];
113 return cnt;
116 static int sub_source_and_index_by_pos(MPContext *mpctx, int *pos)
118 int start = 0;
119 int i;
120 for (i = 0; i < SUB_SOURCES; i++) {
121 int cnt = mpctx->sub_counts[i];
122 if (*pos >= start && *pos < start + cnt) {
123 *pos -= start;
124 return i;
126 start += cnt;
128 *pos = -1;
129 return -1;
132 static int sub_source_by_pos(MPContext *mpctx, int pos)
134 return sub_source_and_index_by_pos(mpctx, &pos);
137 static int sub_source_pos(MPContext *mpctx)
139 int pos = mpctx->global_sub_pos;
140 sub_source_and_index_by_pos(mpctx, &pos);
141 return pos;
144 static int sub_source(MPContext *mpctx)
146 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
149 static void update_global_sub_size(MPContext *mpctx)
151 struct MPOpts *opts = &mpctx->opts;
152 int i;
153 int cnt = 0;
155 // update number of demuxer sub streams
156 for (i = 0; i < MAX_S_STREAMS; i++)
157 if (mpctx->d_sub->demuxer->s_streams[i])
158 cnt++;
159 if (cnt > mpctx->sub_counts[SUB_SOURCE_DEMUX])
160 mpctx->sub_counts[SUB_SOURCE_DEMUX] = cnt;
162 // update global size
163 mpctx->global_sub_size = 0;
164 for (i = 0; i < SUB_SOURCES; i++)
165 mpctx->global_sub_size += mpctx->sub_counts[i];
167 // update global_sub_pos if we auto-detected a demuxer sub
168 if (mpctx->global_sub_pos == -1) {
169 int sub_id = -1;
170 if (mpctx->demuxer->sub)
171 sub_id = mpctx->demuxer->sub->id;
172 if (sub_id < 0)
173 sub_id = opts->sub_id;
174 if (sub_id >= 0 && sub_id < mpctx->sub_counts[SUB_SOURCE_DEMUX])
175 mpctx->global_sub_pos = sub_pos_by_source(mpctx, SUB_SOURCE_DEMUX) +
176 sub_id;
181 * \brief Log the currently displayed subtitle to a file
183 * Logs the current or last displayed subtitle together with filename
184 * and time information to ~/.mplayer/subtitle_log
186 * Intended purpose is to allow convenient marking of bogus subtitles
187 * which need to be fixed while watching the movie.
190 static void log_sub(struct MPContext *mpctx)
192 char *fname;
193 FILE *f;
194 int i;
196 if (subdata == NULL || vo_sub_last == NULL)
197 return;
198 fname = get_path("subtitle_log");
199 f = fopen(fname, "a");
200 if (!f)
201 return;
202 fprintf(f, "----------------------------------------------------------\n");
203 if (subdata->sub_uses_time) {
204 fprintf(f,
205 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
206 mpctx->filename, vo_sub_last->start / 360000,
207 (vo_sub_last->start / 6000) % 60,
208 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
209 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
210 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
211 } else {
212 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
213 vo_sub_last->start, vo_sub_last->end);
215 for (i = 0; i < vo_sub_last->lines; i++) {
216 fprintf(f, "%s\n", vo_sub_last->text[i]);
218 fclose(f);
222 /// \defgroup Properties
223 ///@{
225 /// \defgroup GeneralProperties General properties
226 /// \ingroup Properties
227 ///@{
229 /// OSD level (RW)
230 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
231 MPContext *mpctx)
233 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
236 /// Loop (RW)
237 static int mp_property_loop(m_option_t *prop, int action, void *arg,
238 MPContext *mpctx)
240 struct MPOpts *opts = &mpctx->opts;
241 switch (action) {
242 case M_PROPERTY_PRINT:
243 if (!arg) return M_PROPERTY_ERROR;
244 if (opts->loop_times < 0)
245 *(char**)arg = strdup("off");
246 else if (opts->loop_times == 0)
247 *(char**)arg = strdup("inf");
248 else
249 break;
250 return M_PROPERTY_OK;
252 return m_property_int_range(prop, action, arg, &opts->loop_times);
255 /// Playback speed (RW)
256 static int mp_property_playback_speed(m_option_t *prop, int action,
257 void *arg, MPContext *mpctx)
259 struct MPOpts *opts = &mpctx->opts;
260 switch (action) {
261 case M_PROPERTY_SET:
262 if (!arg)
263 return M_PROPERTY_ERROR;
264 M_PROPERTY_CLAMP(prop, *(float *) arg);
265 opts->playback_speed = *(float *) arg;
266 reinit_audio_chain(mpctx);
267 return M_PROPERTY_OK;
268 case M_PROPERTY_STEP_UP:
269 case M_PROPERTY_STEP_DOWN:
270 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
271 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
272 M_PROPERTY_CLAMP(prop, opts->playback_speed);
273 reinit_audio_chain(mpctx);
274 return M_PROPERTY_OK;
276 return m_property_float_range(prop, action, arg, &opts->playback_speed);
279 /// filename with path (RO)
280 static int mp_property_path(m_option_t *prop, int action, void *arg,
281 MPContext *mpctx)
283 return m_property_string_ro(prop, action, arg, mpctx->filename);
286 /// filename without path (RO)
287 static int mp_property_filename(m_option_t *prop, int action, void *arg,
288 MPContext *mpctx)
290 char *f;
291 if (!mpctx->filename)
292 return M_PROPERTY_UNAVAILABLE;
293 f = (char *)mp_basename(mpctx->filename);
294 if (!*f)
295 f = mpctx->filename;
296 return m_property_string_ro(prop, action, arg, f);
299 /// Demuxer name (RO)
300 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
301 MPContext *mpctx)
303 if (!mpctx->demuxer)
304 return M_PROPERTY_UNAVAILABLE;
305 return m_property_string_ro(prop, action, arg,
306 (char *) mpctx->demuxer->desc->name);
309 /// Position in the stream (RW)
310 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
311 MPContext *mpctx)
313 if (!mpctx->demuxer || !mpctx->demuxer->stream)
314 return M_PROPERTY_UNAVAILABLE;
315 if (!arg)
316 return M_PROPERTY_ERROR;
317 switch (action) {
318 case M_PROPERTY_GET:
319 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
320 return M_PROPERTY_OK;
321 case M_PROPERTY_SET:
322 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
323 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
324 return M_PROPERTY_OK;
326 return M_PROPERTY_NOT_IMPLEMENTED;
329 /// Stream start offset (RO)
330 static int mp_property_stream_start(m_option_t *prop, int action,
331 void *arg, MPContext *mpctx)
333 if (!mpctx->demuxer || !mpctx->demuxer->stream)
334 return M_PROPERTY_UNAVAILABLE;
335 switch (action) {
336 case M_PROPERTY_GET:
337 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
338 return M_PROPERTY_OK;
340 return M_PROPERTY_NOT_IMPLEMENTED;
343 /// Stream end offset (RO)
344 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
345 MPContext *mpctx)
347 if (!mpctx->demuxer || !mpctx->demuxer->stream)
348 return M_PROPERTY_UNAVAILABLE;
349 switch (action) {
350 case M_PROPERTY_GET:
351 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
352 return M_PROPERTY_OK;
354 return M_PROPERTY_NOT_IMPLEMENTED;
357 /// Stream length (RO)
358 static int mp_property_stream_length(m_option_t *prop, int action,
359 void *arg, MPContext *mpctx)
361 if (!mpctx->demuxer || !mpctx->demuxer->stream)
362 return M_PROPERTY_UNAVAILABLE;
363 switch (action) {
364 case M_PROPERTY_GET:
365 *(off_t *) arg =
366 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
367 return M_PROPERTY_OK;
369 return M_PROPERTY_NOT_IMPLEMENTED;
372 /// Current stream position in seconds (RO)
373 static int mp_property_stream_time_pos(m_option_t *prop, int action,
374 void *arg, MPContext *mpctx)
376 if (!mpctx->demuxer || mpctx->demuxer->stream_pts == MP_NOPTS_VALUE)
377 return M_PROPERTY_UNAVAILABLE;
379 return m_property_time_ro(prop, action, arg, mpctx->demuxer->stream_pts);
383 /// Media length in seconds (RO)
384 static int mp_property_length(m_option_t *prop, int action, void *arg,
385 MPContext *mpctx)
387 double len;
389 if (!mpctx->demuxer ||
390 !(int) (len = get_time_length(mpctx)))
391 return M_PROPERTY_UNAVAILABLE;
393 return m_property_time_ro(prop, action, arg, len);
396 /// Current position in percent (RW)
397 static int mp_property_percent_pos(m_option_t *prop, int action,
398 void *arg, MPContext *mpctx) {
399 int pos;
401 if (!mpctx->demuxer)
402 return M_PROPERTY_UNAVAILABLE;
404 switch(action) {
405 case M_PROPERTY_SET:
406 if(!arg) return M_PROPERTY_ERROR;
407 M_PROPERTY_CLAMP(prop, *(int*)arg);
408 pos = *(int*)arg;
409 break;
410 case M_PROPERTY_STEP_UP:
411 case M_PROPERTY_STEP_DOWN:
412 pos = get_percent_pos(mpctx);
413 pos += (arg ? *(int*)arg : 10) *
414 (action == M_PROPERTY_STEP_UP ? 1 : -1);
415 M_PROPERTY_CLAMP(prop, pos);
416 break;
417 default:
418 return m_property_int_ro(prop, action, arg, get_percent_pos(mpctx));
421 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
422 mpctx->rel_seek_secs = pos / 100.0;
423 return M_PROPERTY_OK;
426 /// Current position in seconds (RW)
427 static int mp_property_time_pos(m_option_t *prop, int action,
428 void *arg, MPContext *mpctx) {
429 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
430 return M_PROPERTY_UNAVAILABLE;
432 switch(action) {
433 case M_PROPERTY_SET:
434 if(!arg) return M_PROPERTY_ERROR;
435 M_PROPERTY_CLAMP(prop, *(double*)arg);
436 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
437 mpctx->rel_seek_secs = *(double*)arg;
438 return M_PROPERTY_OK;
439 case M_PROPERTY_STEP_UP:
440 case M_PROPERTY_STEP_DOWN:
441 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
442 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
443 return M_PROPERTY_OK;
445 return m_property_time_ro(prop, action, arg, get_current_time(mpctx));
448 /// Current chapter (RW)
449 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
450 MPContext *mpctx)
452 struct MPOpts *opts = &mpctx->opts;
453 int chapter = -1;
454 int step_all;
455 char *chapter_name = NULL;
457 if (mpctx->demuxer)
458 chapter = get_current_chapter(mpctx);
459 if (chapter < -1)
460 return M_PROPERTY_UNAVAILABLE;
462 switch (action) {
463 case M_PROPERTY_GET:
464 if (!arg)
465 return M_PROPERTY_ERROR;
466 *(int *) arg = chapter;
467 return M_PROPERTY_OK;
468 case M_PROPERTY_PRINT: {
469 if (!arg)
470 return M_PROPERTY_ERROR;
471 chapter_name = chapter_display_name(mpctx, chapter);
472 if (!chapter_name)
473 return M_PROPERTY_UNAVAILABLE;
474 *(char **) arg = chapter_name;
475 return M_PROPERTY_OK;
477 case M_PROPERTY_SET:
478 if (!arg)
479 return M_PROPERTY_ERROR;
480 M_PROPERTY_CLAMP(prop, *(int*)arg);
481 step_all = *(int *)arg - chapter;
482 chapter += step_all;
483 break;
484 case M_PROPERTY_STEP_UP:
485 case M_PROPERTY_STEP_DOWN: {
486 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
487 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
488 chapter += step_all;
489 if (chapter < 0)
490 chapter = 0;
491 break;
493 default:
494 return M_PROPERTY_NOT_IMPLEMENTED;
497 double next_pts = 0;
498 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
499 mpctx->rel_seek_secs = 0;
500 mpctx->abs_seek_pos = 0;
501 if (chapter >= 0) {
502 if (next_pts > -1.0) {
503 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
504 mpctx->rel_seek_secs = next_pts;
506 if (chapter_name)
507 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
508 "Chapter: (%d) %s", chapter + 1, chapter_name);
510 else if (step_all > 0)
511 mpctx->rel_seek_secs = 1000000000.;
512 else
513 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
514 "Chapter: (%d) %s", 0, mp_gtext("unknown"));
515 talloc_free(chapter_name);
516 return M_PROPERTY_OK;
519 /// Number of chapters in file
520 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
521 MPContext *mpctx)
523 if (!mpctx->demuxer)
524 return M_PROPERTY_UNAVAILABLE;
525 if (mpctx->demuxer->num_chapters == 0)
526 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
527 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
530 /// Current dvd angle (RW)
531 static int mp_property_angle(m_option_t *prop, int action, void *arg,
532 MPContext *mpctx)
534 struct MPOpts *opts = &mpctx->opts;
535 int angle = -1;
536 int angles;
537 char *angle_name = NULL;
539 if (mpctx->demuxer)
540 angle = demuxer_get_current_angle(mpctx->demuxer);
541 if (angle < 0)
542 return M_PROPERTY_UNAVAILABLE;
543 angles = demuxer_angles_count(mpctx->demuxer);
544 if (angles <= 1)
545 return M_PROPERTY_UNAVAILABLE;
547 switch (action) {
548 case M_PROPERTY_GET:
549 if (!arg)
550 return M_PROPERTY_ERROR;
551 *(int *) arg = angle;
552 return M_PROPERTY_OK;
553 case M_PROPERTY_PRINT: {
554 if (!arg)
555 return M_PROPERTY_ERROR;
556 angle_name = calloc(1, 64);
557 if (!angle_name)
558 return M_PROPERTY_UNAVAILABLE;
559 snprintf(angle_name, 64, "%d/%d", angle, angles);
560 *(char **) arg = angle_name;
561 return M_PROPERTY_OK;
563 case M_PROPERTY_SET:
564 if (!arg)
565 return M_PROPERTY_ERROR;
566 angle = *(int *)arg;
567 M_PROPERTY_CLAMP(prop, angle);
568 break;
569 case M_PROPERTY_STEP_UP:
570 case M_PROPERTY_STEP_DOWN: {
571 int step = 0;
572 if(arg)
573 step = *(int*)arg;
574 if(!step)
575 step = 1;
576 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
577 angle += step;
578 if (angle < 1) //cycle
579 angle = angles;
580 break;
582 default:
583 return M_PROPERTY_NOT_IMPLEMENTED;
585 angle = demuxer_set_angle(mpctx->demuxer, angle);
586 if (angle >= 0) {
587 struct sh_video *sh_video = mpctx->demuxer->video->sh;
588 if (sh_video)
589 resync_video_stream(sh_video);
591 struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
592 if (sh_audio)
593 resync_audio_stream(sh_audio);
596 set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
597 "Angle: %d/%d", angle, angles);
598 free(angle_name);
599 return M_PROPERTY_OK;
602 /// Demuxer meta data
603 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
604 MPContext *mpctx) {
605 m_property_action_t* ka;
606 char* meta;
607 static const m_option_t key_type =
608 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
609 if (!mpctx->demuxer)
610 return M_PROPERTY_UNAVAILABLE;
612 switch(action) {
613 case M_PROPERTY_GET:
614 if(!arg) return M_PROPERTY_ERROR;
615 *(char***)arg = mpctx->demuxer->info;
616 return M_PROPERTY_OK;
617 case M_PROPERTY_KEY_ACTION:
618 if(!arg) return M_PROPERTY_ERROR;
619 ka = arg;
620 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
621 return M_PROPERTY_UNKNOWN;
622 switch(ka->action) {
623 case M_PROPERTY_GET:
624 if(!ka->arg) return M_PROPERTY_ERROR;
625 *(char**)ka->arg = meta;
626 return M_PROPERTY_OK;
627 case M_PROPERTY_GET_TYPE:
628 if(!ka->arg) return M_PROPERTY_ERROR;
629 *(const m_option_t**)ka->arg = &key_type;
630 return M_PROPERTY_OK;
633 return M_PROPERTY_NOT_IMPLEMENTED;
636 static int mp_property_pause(m_option_t *prop, int action, void *arg,
637 void *ctx)
639 MPContext *mpctx = ctx;
641 switch (action) {
642 case M_PROPERTY_SET:
643 if (!arg)
644 return M_PROPERTY_ERROR;
645 if (mpctx->paused == (bool)*(int *) arg)
646 return M_PROPERTY_OK;
647 case M_PROPERTY_STEP_UP:
648 case M_PROPERTY_STEP_DOWN:
649 if (mpctx->paused) {
650 unpause_player(mpctx);
651 mpctx->osd_function = OSD_PLAY;
653 else {
654 pause_player(mpctx);
655 mpctx->osd_function = OSD_PAUSE;
657 return M_PROPERTY_OK;
658 default:
659 return m_property_flag(prop, action, arg, &mpctx->paused);
664 ///@}
666 /// \defgroup AudioProperties Audio properties
667 /// \ingroup Properties
668 ///@{
670 /// Volume (RW)
671 static int mp_property_volume(m_option_t *prop, int action, void *arg,
672 MPContext *mpctx)
675 if (!mpctx->sh_audio)
676 return M_PROPERTY_UNAVAILABLE;
678 switch (action) {
679 case M_PROPERTY_GET:
680 if (!arg)
681 return M_PROPERTY_ERROR;
682 mixer_getbothvolume(&mpctx->mixer, arg);
683 return M_PROPERTY_OK;
684 case M_PROPERTY_PRINT:{
685 float vol;
686 if (!arg)
687 return M_PROPERTY_ERROR;
688 mixer_getbothvolume(&mpctx->mixer, &vol);
689 return m_property_float_range(prop, action, arg, &vol);
691 case M_PROPERTY_STEP_UP:
692 case M_PROPERTY_STEP_DOWN:
693 case M_PROPERTY_SET:
694 break;
695 default:
696 return M_PROPERTY_NOT_IMPLEMENTED;
699 if (mpctx->edl_muted)
700 return M_PROPERTY_DISABLED;
701 mpctx->user_muted = 0;
703 switch (action) {
704 case M_PROPERTY_SET:
705 if (!arg)
706 return M_PROPERTY_ERROR;
707 M_PROPERTY_CLAMP(prop, *(float *) arg);
708 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
709 return M_PROPERTY_OK;
710 case M_PROPERTY_STEP_UP:
711 if (arg && *(float *) arg <= 0)
712 mixer_decvolume(&mpctx->mixer);
713 else
714 mixer_incvolume(&mpctx->mixer);
715 return M_PROPERTY_OK;
716 case M_PROPERTY_STEP_DOWN:
717 if (arg && *(float *) arg <= 0)
718 mixer_incvolume(&mpctx->mixer);
719 else
720 mixer_decvolume(&mpctx->mixer);
721 return M_PROPERTY_OK;
723 return M_PROPERTY_NOT_IMPLEMENTED;
726 /// Mute (RW)
727 static int mp_property_mute(m_option_t *prop, int action, void *arg,
728 MPContext *mpctx)
731 if (!mpctx->sh_audio)
732 return M_PROPERTY_UNAVAILABLE;
734 switch (action) {
735 case M_PROPERTY_SET:
736 if (mpctx->edl_muted)
737 return M_PROPERTY_DISABLED;
738 if (!arg)
739 return M_PROPERTY_ERROR;
740 if ((!!*(int *) arg) != mpctx->mixer.muted)
741 mixer_mute(&mpctx->mixer);
742 mpctx->user_muted = mpctx->mixer.muted;
743 return M_PROPERTY_OK;
744 case M_PROPERTY_STEP_UP:
745 case M_PROPERTY_STEP_DOWN:
746 if (mpctx->edl_muted)
747 return M_PROPERTY_DISABLED;
748 mixer_mute(&mpctx->mixer);
749 mpctx->user_muted = mpctx->mixer.muted;
750 return M_PROPERTY_OK;
751 case M_PROPERTY_PRINT:
752 if (!arg)
753 return M_PROPERTY_ERROR;
754 if (mpctx->edl_muted) {
755 *(char **) arg = strdup(mp_gtext("enabled (EDL)"));
756 return M_PROPERTY_OK;
758 default:
759 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
764 /// Audio delay (RW)
765 static int mp_property_audio_delay(m_option_t *prop, int action,
766 void *arg, MPContext *mpctx)
768 if (!(mpctx->sh_audio && mpctx->sh_video))
769 return M_PROPERTY_UNAVAILABLE;
770 switch (action) {
771 case M_PROPERTY_SET:
772 case M_PROPERTY_STEP_UP:
773 case M_PROPERTY_STEP_DOWN: {
774 int ret;
775 float delay = audio_delay;
776 ret = m_property_delay(prop, action, arg, &audio_delay);
777 if (ret != M_PROPERTY_OK)
778 return ret;
779 if (mpctx->sh_audio)
780 mpctx->delay -= audio_delay - delay;
782 return M_PROPERTY_OK;
783 default:
784 return m_property_delay(prop, action, arg, &audio_delay);
788 /// Audio codec tag (RO)
789 static int mp_property_audio_format(m_option_t *prop, int action,
790 void *arg, MPContext *mpctx)
792 if (!mpctx->sh_audio)
793 return M_PROPERTY_UNAVAILABLE;
794 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
797 /// Audio codec name (RO)
798 static int mp_property_audio_codec(m_option_t *prop, int action,
799 void *arg, MPContext *mpctx)
801 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
802 return M_PROPERTY_UNAVAILABLE;
803 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
806 /// Audio bitrate (RO)
807 static int mp_property_audio_bitrate(m_option_t *prop, int action,
808 void *arg, MPContext *mpctx)
810 if (!mpctx->sh_audio)
811 return M_PROPERTY_UNAVAILABLE;
812 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
815 /// Samplerate (RO)
816 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
817 MPContext *mpctx)
819 if (!mpctx->sh_audio)
820 return M_PROPERTY_UNAVAILABLE;
821 switch(action) {
822 case M_PROPERTY_PRINT:
823 if(!arg) return M_PROPERTY_ERROR;
824 *(char**)arg = malloc(16);
825 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
826 return M_PROPERTY_OK;
828 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
831 /// Number of channels (RO)
832 static int mp_property_channels(m_option_t *prop, int action, void *arg,
833 MPContext *mpctx)
835 if (!mpctx->sh_audio)
836 return M_PROPERTY_UNAVAILABLE;
837 switch (action) {
838 case M_PROPERTY_PRINT:
839 if (!arg)
840 return M_PROPERTY_ERROR;
841 switch (mpctx->sh_audio->channels) {
842 case 1:
843 *(char **) arg = strdup("mono");
844 break;
845 case 2:
846 *(char **) arg = strdup("stereo");
847 break;
848 default:
849 *(char **) arg = malloc(32);
850 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
852 return M_PROPERTY_OK;
854 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
857 /// Balance (RW)
858 static int mp_property_balance(m_option_t *prop, int action, void *arg,
859 MPContext *mpctx)
861 float bal;
863 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
864 return M_PROPERTY_UNAVAILABLE;
866 switch (action) {
867 case M_PROPERTY_GET:
868 if (!arg)
869 return M_PROPERTY_ERROR;
870 mixer_getbalance(&mpctx->mixer, arg);
871 return M_PROPERTY_OK;
872 case M_PROPERTY_PRINT: {
873 char** str = arg;
874 if (!arg)
875 return M_PROPERTY_ERROR;
876 mixer_getbalance(&mpctx->mixer, &bal);
877 if (bal == 0.f)
878 *str = strdup("center");
879 else if (bal == -1.f)
880 *str = strdup("left only");
881 else if (bal == 1.f)
882 *str = strdup("right only");
883 else {
884 unsigned right = (bal + 1.f) / 2.f * 100.f;
885 *str = malloc(sizeof("left xxx%, right xxx%"));
886 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
888 return M_PROPERTY_OK;
890 case M_PROPERTY_STEP_UP:
891 case M_PROPERTY_STEP_DOWN:
892 mixer_getbalance(&mpctx->mixer, &bal);
893 bal += (arg ? *(float*)arg : .1f) *
894 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
895 M_PROPERTY_CLAMP(prop, bal);
896 mixer_setbalance(&mpctx->mixer, bal);
897 return M_PROPERTY_OK;
898 case M_PROPERTY_SET:
899 if (!arg)
900 return M_PROPERTY_ERROR;
901 M_PROPERTY_CLAMP(prop, *(float*)arg);
902 mixer_setbalance(&mpctx->mixer, *(float*)arg);
903 return M_PROPERTY_OK;
905 return M_PROPERTY_NOT_IMPLEMENTED;
908 /// Selected audio id (RW)
909 static int mp_property_audio(m_option_t *prop, int action, void *arg,
910 MPContext *mpctx)
912 int current_id, tmp;
913 if (!mpctx->demuxer || !mpctx->d_audio)
914 return M_PROPERTY_UNAVAILABLE;
915 current_id = mpctx->sh_audio ? mpctx->sh_audio->aid : -2;
917 switch (action) {
918 case M_PROPERTY_GET:
919 if (!arg)
920 return M_PROPERTY_ERROR;
921 *(int *) arg = current_id;
922 return M_PROPERTY_OK;
923 case M_PROPERTY_PRINT:
924 if (!arg)
925 return M_PROPERTY_ERROR;
927 if (current_id < 0)
928 *(char **) arg = strdup(mp_gtext("disabled"));
929 else {
930 char lang[40];
931 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
932 sh_audio_t* sh = mpctx->sh_audio;
933 if (sh && sh->lang)
934 av_strlcpy(lang, sh->lang, 40);
935 #ifdef CONFIG_DVDREAD
936 else if (mpctx->stream->type == STREAMTYPE_DVD) {
937 int code = dvd_lang_from_aid(mpctx->stream, current_id);
938 if (code) {
939 lang[0] = code >> 8;
940 lang[1] = code;
941 lang[2] = 0;
944 #endif
946 #ifdef CONFIG_DVDNAV
947 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
948 mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
949 #endif
950 *(char **) arg = malloc(64);
951 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
953 return M_PROPERTY_OK;
955 case M_PROPERTY_STEP_UP:
956 case M_PROPERTY_SET:
957 if (action == M_PROPERTY_SET && arg)
958 tmp = *((int *) arg);
959 else
960 tmp = -1;
961 int new_id = demuxer_switch_audio(mpctx->d_audio->demuxer, tmp);
962 if (new_id != current_id)
963 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
964 if (new_id != current_id && new_id >= 0) {
965 sh_audio_t *sh2;
966 sh2 = mpctx->d_audio->demuxer->a_streams[mpctx->demuxer->audio->id];
967 sh2->ds = mpctx->demuxer->audio;
968 mpctx->sh_audio = sh2;
969 reinit_audio_chain(mpctx);
971 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_id);
972 return M_PROPERTY_OK;
973 default:
974 return M_PROPERTY_NOT_IMPLEMENTED;
979 /// Selected video id (RW)
980 static int mp_property_video(m_option_t *prop, int action, void *arg,
981 MPContext *mpctx)
983 struct MPOpts *opts = &mpctx->opts;
984 int current_id, tmp;
985 if (!mpctx->demuxer || !mpctx->d_video)
986 return M_PROPERTY_UNAVAILABLE;
987 current_id = mpctx->d_video->id;
989 switch (action) {
990 case M_PROPERTY_GET:
991 if (!arg)
992 return M_PROPERTY_ERROR;
993 *(int *) arg = current_id;
994 return M_PROPERTY_OK;
995 case M_PROPERTY_PRINT:
996 if (!arg)
997 return M_PROPERTY_ERROR;
999 if (current_id < 0)
1000 *(char **) arg = strdup(mp_gtext("disabled"));
1001 else {
1002 char lang[40];
1003 strncpy(lang, mp_gtext("unknown"), sizeof(lang));
1004 *(char **) arg = malloc(64);
1005 snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
1007 return M_PROPERTY_OK;
1009 case M_PROPERTY_STEP_UP:
1010 case M_PROPERTY_SET:
1011 if (action == M_PROPERTY_SET && arg)
1012 tmp = *((int *) arg);
1013 else
1014 tmp = -1;
1015 opts->video_id = demuxer_switch_video(mpctx->d_video->demuxer, tmp);
1016 if (opts->video_id == -2
1017 || (opts->video_id > -1 && mpctx->d_video->id != current_id
1018 && current_id != -2))
1019 uninit_player(mpctx, INITIALIZED_VCODEC |
1020 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
1021 if (opts->video_id > -1 && mpctx->d_video->id != current_id) {
1022 sh_video_t *sh2;
1023 sh2 = mpctx->d_video->demuxer->v_streams[mpctx->d_video->id];
1024 if (sh2) {
1025 sh2->ds = mpctx->d_video;
1026 mpctx->sh_video = sh2;
1027 reinit_video_chain(mpctx);
1030 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
1031 return M_PROPERTY_OK;
1033 default:
1034 return M_PROPERTY_NOT_IMPLEMENTED;
1038 static int mp_property_program(m_option_t *prop, int action, void *arg,
1039 MPContext *mpctx)
1041 demux_program_t prog;
1043 switch (action) {
1044 case M_PROPERTY_STEP_UP:
1045 case M_PROPERTY_SET:
1046 if (action == M_PROPERTY_SET && arg)
1047 prog.progid = *((int *) arg);
1048 else
1049 prog.progid = -1;
1050 if (demux_control
1051 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
1052 &prog) == DEMUXER_CTRL_NOTIMPL)
1053 return M_PROPERTY_ERROR;
1055 if (prog.aid < 0 && prog.vid < 0) {
1056 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
1057 return M_PROPERTY_ERROR;
1059 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
1060 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
1061 return M_PROPERTY_OK;
1063 default:
1064 return M_PROPERTY_NOT_IMPLEMENTED;
1068 ///@}
1070 /// \defgroup VideoProperties Video properties
1071 /// \ingroup Properties
1072 ///@{
1074 /// Fullscreen state (RW)
1075 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1076 MPContext *mpctx)
1079 if (!mpctx->video_out)
1080 return M_PROPERTY_UNAVAILABLE;
1082 switch (action) {
1083 case M_PROPERTY_SET:
1084 if (!arg)
1085 return M_PROPERTY_ERROR;
1086 M_PROPERTY_CLAMP(prop, *(int *) arg);
1087 if (vo_fs == !!*(int *) arg)
1088 return M_PROPERTY_OK;
1089 case M_PROPERTY_STEP_UP:
1090 case M_PROPERTY_STEP_DOWN:
1091 if (mpctx->video_out->config_ok)
1092 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1093 mpctx->opts.fullscreen = vo_fs;
1094 return M_PROPERTY_OK;
1095 default:
1096 return m_property_flag(prop, action, arg, &vo_fs);
1100 static int mp_property_deinterlace(m_option_t *prop, int action,
1101 void *arg, MPContext *mpctx)
1103 int deinterlace;
1104 vf_instance_t *vf;
1105 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1106 return M_PROPERTY_UNAVAILABLE;
1107 vf = mpctx->sh_video->vfilter;
1108 switch (action) {
1109 case M_PROPERTY_GET:
1110 if (!arg)
1111 return M_PROPERTY_ERROR;
1112 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1113 return M_PROPERTY_OK;
1114 case M_PROPERTY_SET:
1115 if (!arg)
1116 return M_PROPERTY_ERROR;
1117 M_PROPERTY_CLAMP(prop, *(int *) arg);
1118 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1119 return M_PROPERTY_OK;
1120 case M_PROPERTY_STEP_UP:
1121 case M_PROPERTY_STEP_DOWN:
1122 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1123 deinterlace = !deinterlace;
1124 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1125 return M_PROPERTY_OK;
1127 int value = 0;
1128 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1129 return m_property_flag_ro(prop, action, arg, value);
1132 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1133 void *arg, MPContext *mpctx)
1135 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1136 return M_PROPERTY_UNAVAILABLE;
1138 struct vf_instance *vf = mpctx->sh_video->vfilter;
1139 int colorspace;
1140 switch (action) {
1141 case M_PROPERTY_GET:
1142 if (!arg)
1143 return M_PROPERTY_ERROR;
1144 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1145 return M_PROPERTY_UNAVAILABLE;
1146 return M_PROPERTY_OK;
1147 case M_PROPERTY_PRINT:
1148 if (!arg)
1149 return M_PROPERTY_ERROR;
1150 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1151 return M_PROPERTY_UNAVAILABLE;
1152 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1153 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1154 *(char **)arg = strdup("Unknown");
1155 else
1156 *(char**)arg = strdup(names[colorspace]);
1157 return M_PROPERTY_OK;
1158 case M_PROPERTY_SET:
1159 if (!arg)
1160 return M_PROPERTY_ERROR;
1161 M_PROPERTY_CLAMP(prop, *(int *) arg);
1162 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1163 return M_PROPERTY_OK;
1164 case M_PROPERTY_STEP_UP:;
1165 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1166 return M_PROPERTY_UNAVAILABLE;
1167 colorspace += 1;
1168 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1169 return M_PROPERTY_OK;
1171 return M_PROPERTY_NOT_IMPLEMENTED;
1174 static int mp_property_capture(m_option_t *prop, int action,
1175 void *arg, MPContext *mpctx)
1177 struct MPOpts *opts = &mpctx->opts;
1179 if (!mpctx->stream)
1180 return M_PROPERTY_UNAVAILABLE;
1182 if (!opts->capture_dump) {
1183 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1184 "Capturing not enabled (forgot -capture parameter?)\n");
1185 return M_PROPERTY_ERROR;
1188 int capturing = !!mpctx->stream->capture_file;
1190 int ret = m_property_flag(prop, action, arg, &capturing);
1191 if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
1192 if (capturing) {
1193 mpctx->stream->capture_file = fopen(opts->stream_dump_name, "wb");
1194 if (!mpctx->stream->capture_file) {
1195 mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
1196 "Error opening capture file: %s\n", strerror(errno));
1197 ret = M_PROPERTY_ERROR;
1199 } else {
1200 fclose(mpctx->stream->capture_file);
1201 mpctx->stream->capture_file = NULL;
1205 return ret;
1208 /// Panscan (RW)
1209 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1210 MPContext *mpctx)
1213 if (!mpctx->video_out
1214 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1215 return M_PROPERTY_UNAVAILABLE;
1217 switch (action) {
1218 case M_PROPERTY_SET:
1219 if (!arg)
1220 return M_PROPERTY_ERROR;
1221 M_PROPERTY_CLAMP(prop, *(float *) arg);
1222 vo_panscan = *(float *) arg;
1223 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1224 return M_PROPERTY_OK;
1225 case M_PROPERTY_STEP_UP:
1226 case M_PROPERTY_STEP_DOWN:
1227 vo_panscan += (arg ? *(float *) arg : 0.1) *
1228 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1229 if (vo_panscan > 1)
1230 vo_panscan = 1;
1231 else if (vo_panscan < 0)
1232 vo_panscan = 0;
1233 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1234 return M_PROPERTY_OK;
1235 default:
1236 return m_property_float_range(prop, action, arg, &vo_panscan);
1240 /// Helper to set vo flags.
1241 /** \ingroup PropertyImplHelper
1243 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1244 int vo_ctrl, int *vo_var, MPContext *mpctx)
1247 if (!mpctx->video_out)
1248 return M_PROPERTY_UNAVAILABLE;
1250 switch (action) {
1251 case M_PROPERTY_SET:
1252 if (!arg)
1253 return M_PROPERTY_ERROR;
1254 M_PROPERTY_CLAMP(prop, *(int *) arg);
1255 if (*vo_var == !!*(int *) arg)
1256 return M_PROPERTY_OK;
1257 case M_PROPERTY_STEP_UP:
1258 case M_PROPERTY_STEP_DOWN:
1259 if (mpctx->video_out->config_ok)
1260 vo_control(mpctx->video_out, vo_ctrl, 0);
1261 return M_PROPERTY_OK;
1262 default:
1263 return m_property_flag(prop, action, arg, vo_var);
1267 /// Window always on top (RW)
1268 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1269 MPContext *mpctx)
1271 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1272 &mpctx->opts.vo_ontop, mpctx);
1275 /// Display in the root window (RW)
1276 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1277 MPContext *mpctx)
1279 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1280 &vo_rootwin, mpctx);
1283 /// Show window borders (RW)
1284 static int mp_property_border(m_option_t *prop, int action, void *arg,
1285 MPContext *mpctx)
1287 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1288 &vo_border, mpctx);
1291 /// Framedropping state (RW)
1292 static int mp_property_framedropping(m_option_t *prop, int action,
1293 void *arg, MPContext *mpctx)
1296 if (!mpctx->sh_video)
1297 return M_PROPERTY_UNAVAILABLE;
1299 switch (action) {
1300 case M_PROPERTY_PRINT:
1301 if (!arg)
1302 return M_PROPERTY_ERROR;
1303 *(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
1304 (frame_dropping == 2 ? mp_gtext("hard") :
1305 mp_gtext("disabled")));
1306 return M_PROPERTY_OK;
1307 default:
1308 return m_property_choice(prop, action, arg, &frame_dropping);
1312 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1313 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1314 MPContext *mpctx)
1316 int *gamma = (int *)((char *)&mpctx->opts + prop->offset);
1317 int r, val;
1319 if (!mpctx->sh_video)
1320 return M_PROPERTY_UNAVAILABLE;
1322 if (gamma[0] == 1000) {
1323 gamma[0] = 0;
1324 get_video_colors(mpctx->sh_video, prop->name, gamma);
1327 switch (action) {
1328 case M_PROPERTY_SET:
1329 if (!arg)
1330 return M_PROPERTY_ERROR;
1331 M_PROPERTY_CLAMP(prop, *(int *) arg);
1332 *gamma = *(int *) arg;
1333 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1334 if (r <= 0)
1335 break;
1336 return r;
1337 case M_PROPERTY_GET:
1338 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1339 if (!arg)
1340 return M_PROPERTY_ERROR;
1341 *(int *)arg = val;
1342 return M_PROPERTY_OK;
1344 break;
1345 case M_PROPERTY_STEP_UP:
1346 case M_PROPERTY_STEP_DOWN:
1347 *gamma += (arg ? *(int *) arg : 1) *
1348 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1349 M_PROPERTY_CLAMP(prop, *gamma);
1350 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1351 if (r <= 0)
1352 break;
1353 return r;
1354 default:
1355 return M_PROPERTY_NOT_IMPLEMENTED;
1358 #ifdef CONFIG_TV
1359 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1360 int l = strlen(prop->name);
1361 char tv_prop[3 + l + 1];
1362 sprintf(tv_prop, "tv_%s", prop->name);
1363 return mp_property_do(tv_prop, action, arg, mpctx);
1365 #endif
1367 return M_PROPERTY_UNAVAILABLE;
1370 /// VSync (RW)
1371 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1372 MPContext *mpctx)
1374 return m_property_flag(prop, action, arg, &vo_vsync);
1377 /// Video codec tag (RO)
1378 static int mp_property_video_format(m_option_t *prop, int action,
1379 void *arg, MPContext *mpctx)
1381 char* meta;
1382 if (!mpctx->sh_video)
1383 return M_PROPERTY_UNAVAILABLE;
1384 switch(action) {
1385 case M_PROPERTY_PRINT:
1386 if (!arg)
1387 return M_PROPERTY_ERROR;
1388 switch(mpctx->sh_video->format) {
1389 case 0x10000001:
1390 meta = strdup ("mpeg1"); break;
1391 case 0x10000002:
1392 meta = strdup ("mpeg2"); break;
1393 case 0x10000004:
1394 meta = strdup ("mpeg4"); break;
1395 case 0x10000005:
1396 meta = strdup ("h264"); break;
1397 default:
1398 if(mpctx->sh_video->format >= 0x20202020) {
1399 meta = malloc(5);
1400 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1401 } else {
1402 meta = malloc(20);
1403 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1406 *(char**)arg = meta;
1407 return M_PROPERTY_OK;
1409 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1412 /// Video codec name (RO)
1413 static int mp_property_video_codec(m_option_t *prop, int action,
1414 void *arg, MPContext *mpctx)
1416 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1417 return M_PROPERTY_UNAVAILABLE;
1418 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1422 /// Video bitrate (RO)
1423 static int mp_property_video_bitrate(m_option_t *prop, int action,
1424 void *arg, MPContext *mpctx)
1426 if (!mpctx->sh_video)
1427 return M_PROPERTY_UNAVAILABLE;
1428 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1431 /// Video display width (RO)
1432 static int mp_property_width(m_option_t *prop, int action, void *arg,
1433 MPContext *mpctx)
1435 if (!mpctx->sh_video)
1436 return M_PROPERTY_UNAVAILABLE;
1437 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1440 /// Video display height (RO)
1441 static int mp_property_height(m_option_t *prop, int action, void *arg,
1442 MPContext *mpctx)
1444 if (!mpctx->sh_video)
1445 return M_PROPERTY_UNAVAILABLE;
1446 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1449 /// Video fps (RO)
1450 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1451 MPContext *mpctx)
1453 if (!mpctx->sh_video)
1454 return M_PROPERTY_UNAVAILABLE;
1455 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1458 /// Video aspect (RO)
1459 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1460 MPContext *mpctx)
1462 if (!mpctx->sh_video)
1463 return M_PROPERTY_UNAVAILABLE;
1464 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1467 ///@}
1469 /// \defgroup SubProprties Subtitles properties
1470 /// \ingroup Properties
1471 ///@{
1473 /// Text subtitle position (RW)
1474 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1475 MPContext *mpctx)
1477 switch (action) {
1478 case M_PROPERTY_SET:
1479 if (!arg)
1480 return M_PROPERTY_ERROR;
1481 case M_PROPERTY_STEP_UP:
1482 case M_PROPERTY_STEP_DOWN:
1483 vo_osd_changed(OSDTYPE_SUBTITLE);
1484 default:
1485 return m_property_int_range(prop, action, arg, &sub_pos);
1489 /// Selected subtitles (RW)
1490 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1491 MPContext *mpctx)
1493 struct MPOpts *opts = &mpctx->opts;
1494 demux_stream_t *const d_sub = mpctx->d_sub;
1495 int source = -1, reset_spu = 0;
1496 int source_pos = -1;
1497 char *sub_name;
1499 update_global_sub_size(mpctx);
1500 const int global_sub_size = mpctx->global_sub_size;
1502 if (global_sub_size <= 0)
1503 return M_PROPERTY_UNAVAILABLE;
1505 switch (action) {
1506 case M_PROPERTY_GET:
1507 if (!arg)
1508 return M_PROPERTY_ERROR;
1509 *(int *) arg = mpctx->global_sub_pos;
1510 return M_PROPERTY_OK;
1511 case M_PROPERTY_PRINT:
1512 if (!arg)
1513 return M_PROPERTY_ERROR;
1514 *(char **) arg = malloc(64);
1515 (*(char **) arg)[63] = 0;
1516 sub_name = 0;
1517 if (subdata)
1518 sub_name = subdata->filename;
1519 #ifdef CONFIG_ASS
1520 if (ass_track && ass_track->name)
1521 sub_name = ass_track->name;
1522 #endif
1523 if (sub_name) {
1524 const char *tmp = mp_basename(sub_name);
1526 snprintf(*(char **) arg, 63, "(%d) %s%s",
1527 mpctx->set_of_sub_pos + 1,
1528 strlen(tmp) < 20 ? "" : "...",
1529 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1530 return M_PROPERTY_OK;
1532 #ifdef CONFIG_DVDNAV
1533 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1534 if (vo_spudec && opts->sub_id >= 0) {
1535 unsigned char lang[3];
1536 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1537 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1538 return M_PROPERTY_OK;
1542 #endif
1544 if ((d_sub->demuxer->type == DEMUXER_TYPE_MATROSKA
1545 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF
1546 || d_sub->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1547 || d_sub->demuxer->type == DEMUXER_TYPE_OGG)
1548 && d_sub->sh && opts->sub_id >= 0) {
1549 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1550 if (!lang) lang = mp_gtext("unknown");
1551 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1552 return M_PROPERTY_OK;
1555 if (vo_vobsub && vobsub_id >= 0) {
1556 const char *language = mp_gtext("unknown");
1557 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1558 snprintf(*(char **) arg, 63, "(%d) %s",
1559 vobsub_id, language ? language : mp_gtext("unknown"));
1560 return M_PROPERTY_OK;
1562 #ifdef CONFIG_DVDREAD
1563 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1564 && opts->sub_id >= 0) {
1565 char lang[3];
1566 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1567 lang[0] = code >> 8;
1568 lang[1] = code;
1569 lang[2] = 0;
1570 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1571 return M_PROPERTY_OK;
1573 #endif
1574 if (opts->sub_id >= 0) {
1575 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
1576 mp_gtext("unknown"));
1577 return M_PROPERTY_OK;
1579 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1580 return M_PROPERTY_OK;
1582 case M_PROPERTY_SET:
1583 if (!arg)
1584 return M_PROPERTY_ERROR;
1585 if (*(int *) arg < -1)
1586 *(int *) arg = -1;
1587 else if (*(int *) arg >= global_sub_size)
1588 *(int *) arg = global_sub_size - 1;
1589 mpctx->global_sub_pos = *(int *) arg;
1590 break;
1591 case M_PROPERTY_STEP_UP:
1592 mpctx->global_sub_pos += 2;
1593 mpctx->global_sub_pos =
1594 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1595 break;
1596 case M_PROPERTY_STEP_DOWN:
1597 mpctx->global_sub_pos += global_sub_size + 1;
1598 mpctx->global_sub_pos =
1599 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1600 break;
1601 default:
1602 return M_PROPERTY_NOT_IMPLEMENTED;
1605 if (mpctx->global_sub_pos >= 0) {
1606 source = sub_source(mpctx);
1607 source_pos = sub_source_pos(mpctx);
1610 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1611 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1612 global_sub_size,
1613 mpctx->sub_counts[SUB_SOURCE_VOBSUB],
1614 mpctx->sub_counts[SUB_SOURCE_SUBS],
1615 mpctx->sub_counts[SUB_SOURCE_DEMUX],
1616 mpctx->global_sub_pos, source);
1618 mpctx->set_of_sub_pos = -1;
1619 subdata = NULL;
1621 vobsub_id = -1;
1622 opts->sub_id = -1;
1623 if (d_sub) {
1624 if (d_sub->id > -2)
1625 reset_spu = 1;
1626 d_sub->id = -2;
1628 #ifdef CONFIG_ASS
1629 ass_track = 0;
1630 #endif
1632 if (source == SUB_SOURCE_VOBSUB) {
1633 vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos);
1634 } else if (source == SUB_SOURCE_SUBS) {
1635 mpctx->set_of_sub_pos = source_pos;
1636 #ifdef CONFIG_ASS
1637 if (opts->ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1638 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1639 else
1640 #endif
1642 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1643 vo_osd_changed(OSDTYPE_SUBTITLE);
1645 } else if (source == SUB_SOURCE_DEMUX) {
1646 opts->sub_id = source_pos;
1647 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1648 int i = 0;
1649 // default: assume 1:1 mapping of sid and stream id
1650 d_sub->id = opts->sub_id;
1651 d_sub->sh = mpctx->d_sub->demuxer->s_streams[d_sub->id];
1652 ds_free_packs(d_sub);
1653 for (i = 0; i < MAX_S_STREAMS; i++) {
1654 sh_sub_t *sh = mpctx->d_sub->demuxer->s_streams[i];
1655 if (sh && sh->sid == opts->sub_id) {
1656 d_sub->id = i;
1657 d_sub->sh = sh;
1658 break;
1661 if (d_sub->sh && d_sub->id >= 0) {
1662 sh_sub_t *sh = d_sub->sh;
1663 if (sh->type == 'v')
1664 init_vo_spudec(mpctx);
1665 #ifdef CONFIG_ASS
1666 else if (opts->ass_enabled)
1667 ass_track = sh->ass_track;
1668 #endif
1669 } else {
1670 d_sub->id = -2;
1671 d_sub->sh = NULL;
1675 #ifdef CONFIG_DVDREAD
1676 if (vo_spudec
1677 && (mpctx->stream->type == STREAMTYPE_DVD
1678 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1679 && opts->sub_id < 0 && reset_spu) {
1680 d_sub->id = -2;
1681 d_sub->sh = NULL;
1683 #endif
1685 update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, 0, 0, d_sub, 1);
1687 return M_PROPERTY_OK;
1690 /// Selected sub source (RW)
1691 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1692 MPContext *mpctx)
1694 int source;
1695 update_global_sub_size(mpctx);
1696 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1697 return M_PROPERTY_UNAVAILABLE;
1699 switch (action) {
1700 case M_PROPERTY_GET:
1701 if (!arg)
1702 return M_PROPERTY_ERROR;
1703 *(int *) arg = sub_source(mpctx);
1704 return M_PROPERTY_OK;
1705 case M_PROPERTY_PRINT:
1706 if (!arg)
1707 return M_PROPERTY_ERROR;
1708 *(char **) arg = malloc(64);
1709 (*(char **) arg)[63] = 0;
1710 switch (sub_source(mpctx))
1712 case SUB_SOURCE_SUBS:
1713 snprintf(*(char **) arg, 63, mp_gtext("file"));
1714 break;
1715 case SUB_SOURCE_VOBSUB:
1716 snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
1717 break;
1718 case SUB_SOURCE_DEMUX:
1719 snprintf(*(char **) arg, 63, mp_gtext("embedded"));
1720 break;
1721 default:
1722 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1724 return M_PROPERTY_OK;
1725 case M_PROPERTY_SET:
1726 if (!arg)
1727 return M_PROPERTY_ERROR;
1728 M_PROPERTY_CLAMP(prop, *(int*)arg);
1729 if (*(int *) arg < 0)
1730 mpctx->global_sub_pos = -1;
1731 else if (*(int *) arg != sub_source(mpctx)) {
1732 int new_pos = sub_pos_by_source(mpctx, *(int *)arg);
1733 if (new_pos == -1)
1734 return M_PROPERTY_UNAVAILABLE;
1735 mpctx->global_sub_pos = new_pos;
1737 break;
1738 case M_PROPERTY_STEP_UP:
1739 case M_PROPERTY_STEP_DOWN: {
1740 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1741 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1742 int step = (step_all > 0) ? 1 : -1;
1743 int cur_source = sub_source(mpctx);
1744 source = cur_source;
1745 while (step_all) {
1746 source += step;
1747 if (source >= SUB_SOURCES)
1748 source = -1;
1749 else if (source < -1)
1750 source = SUB_SOURCES - 1;
1751 if (source == cur_source || source == -1 ||
1752 mpctx->sub_counts[source])
1753 step_all -= step;
1755 if (source == cur_source)
1756 return M_PROPERTY_OK;
1757 if (source == -1)
1758 mpctx->global_sub_pos = -1;
1759 else
1760 mpctx->global_sub_pos = sub_pos_by_source(mpctx, source);
1761 break;
1763 default:
1764 return M_PROPERTY_NOT_IMPLEMENTED;
1766 --mpctx->global_sub_pos;
1767 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1770 /// Selected subtitles from specific source (RW)
1771 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1772 MPContext *mpctx)
1774 int source, is_cur_source, offset, new_pos;
1775 update_global_sub_size(mpctx);
1776 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1777 return M_PROPERTY_UNAVAILABLE;
1779 if (!strcmp(prop->name, "sub_file"))
1780 source = SUB_SOURCE_SUBS;
1781 else if (!strcmp(prop->name, "sub_vob"))
1782 source = SUB_SOURCE_VOBSUB;
1783 else if (!strcmp(prop->name, "sub_demux"))
1784 source = SUB_SOURCE_DEMUX;
1785 else
1786 return M_PROPERTY_ERROR;
1788 offset = sub_pos_by_source(mpctx, source);
1789 if (offset < 0)
1790 return M_PROPERTY_UNAVAILABLE;
1792 is_cur_source = sub_source(mpctx) == source;
1793 new_pos = mpctx->global_sub_pos;
1794 switch (action) {
1795 case M_PROPERTY_GET:
1796 if (!arg)
1797 return M_PROPERTY_ERROR;
1798 if (is_cur_source) {
1799 *(int *) arg = sub_source_pos(mpctx);
1800 if (source == SUB_SOURCE_VOBSUB)
1801 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1803 else
1804 *(int *) arg = -1;
1805 return M_PROPERTY_OK;
1806 case M_PROPERTY_PRINT:
1807 if (!arg)
1808 return M_PROPERTY_ERROR;
1809 if (is_cur_source)
1810 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1811 *(char **) arg = malloc(64);
1812 (*(char **) arg)[63] = 0;
1813 snprintf(*(char **) arg, 63, mp_gtext("disabled"));
1814 return M_PROPERTY_OK;
1815 case M_PROPERTY_SET:
1816 if (!arg)
1817 return M_PROPERTY_ERROR;
1818 if (*(int *) arg >= 0) {
1819 int index = *(int *)arg;
1820 if (source == SUB_SOURCE_VOBSUB)
1821 index = vobsub_get_index_by_id(vo_vobsub, index);
1822 new_pos = offset + index;
1823 if (index < 0 || index > mpctx->sub_counts[source]) {
1824 new_pos = -1;
1825 *(int *) arg = -1;
1828 else
1829 new_pos = -1;
1830 break;
1831 case M_PROPERTY_STEP_UP:
1832 case M_PROPERTY_STEP_DOWN: {
1833 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1834 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1835 int step = (step_all > 0) ? 1 : -1;
1836 int max_sub_pos_for_source = -1;
1837 if (!is_cur_source)
1838 new_pos = -1;
1839 while (step_all) {
1840 if (new_pos == -1) {
1841 if (step > 0)
1842 new_pos = offset;
1843 else if (max_sub_pos_for_source == -1) {
1844 // Find max pos for specific source
1845 new_pos = mpctx->global_sub_size - 1;
1846 while (new_pos >= 0
1847 && sub_source(mpctx) != source)
1848 new_pos--;
1850 else
1851 new_pos = max_sub_pos_for_source;
1853 else {
1854 new_pos += step;
1855 if (new_pos < offset ||
1856 new_pos >= mpctx->global_sub_size ||
1857 sub_source(mpctx) != source)
1858 new_pos = -1;
1860 step_all -= step;
1862 break;
1864 default:
1865 return M_PROPERTY_NOT_IMPLEMENTED;
1867 return mp_property_sub(prop, M_PROPERTY_SET, &new_pos, mpctx);
1870 /// Subtitle delay (RW)
1871 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1872 MPContext *mpctx)
1874 if (!mpctx->sh_video)
1875 return M_PROPERTY_UNAVAILABLE;
1876 return m_property_delay(prop, action, arg, &sub_delay);
1879 /// Alignment of text subtitles (RW)
1880 static int mp_property_sub_alignment(m_option_t *prop, int action,
1881 void *arg, MPContext *mpctx)
1883 char *name[] = { _("top"), _("center"), _("bottom") };
1885 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1886 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1887 return M_PROPERTY_UNAVAILABLE;
1889 switch (action) {
1890 case M_PROPERTY_PRINT:
1891 if (!arg)
1892 return M_PROPERTY_ERROR;
1893 M_PROPERTY_CLAMP(prop, sub_alignment);
1894 *(char **) arg = strdup(mp_gtext(name[sub_alignment]));
1895 return M_PROPERTY_OK;
1896 case M_PROPERTY_SET:
1897 if (!arg)
1898 return M_PROPERTY_ERROR;
1899 case M_PROPERTY_STEP_UP:
1900 case M_PROPERTY_STEP_DOWN:
1901 vo_osd_changed(OSDTYPE_SUBTITLE);
1902 default:
1903 return m_property_choice(prop, action, arg, &sub_alignment);
1907 /// Subtitle visibility (RW)
1908 static int mp_property_sub_visibility(m_option_t *prop, int action,
1909 void *arg, MPContext *mpctx)
1911 if (!mpctx->sh_video)
1912 return M_PROPERTY_UNAVAILABLE;
1914 switch (action) {
1915 case M_PROPERTY_SET:
1916 if (!arg)
1917 return M_PROPERTY_ERROR;
1918 case M_PROPERTY_STEP_UP:
1919 case M_PROPERTY_STEP_DOWN:
1920 vo_osd_changed(OSDTYPE_SUBTITLE);
1921 if (vo_spudec)
1922 vo_osd_changed(OSDTYPE_SPU);
1923 default:
1924 return m_property_flag(prop, action, arg, &sub_visibility);
1928 #ifdef CONFIG_ASS
1929 /// Use margins for libass subtitles (RW)
1930 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1931 void *arg, MPContext *mpctx)
1933 if (!mpctx->sh_video)
1934 return M_PROPERTY_UNAVAILABLE;
1936 switch (action) {
1937 case M_PROPERTY_SET:
1938 if (!arg)
1939 return M_PROPERTY_ERROR;
1940 case M_PROPERTY_STEP_UP:
1941 case M_PROPERTY_STEP_DOWN:
1942 ass_force_reload = 1;
1943 default:
1944 return m_property_flag(prop, action, arg, &ass_use_margins);
1947 #endif
1949 /// Show only forced subtitles (RW)
1950 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1951 void *arg, MPContext *mpctx)
1953 if (!vo_spudec)
1954 return M_PROPERTY_UNAVAILABLE;
1956 switch (action) {
1957 case M_PROPERTY_SET:
1958 if (!arg)
1959 return M_PROPERTY_ERROR;
1960 case M_PROPERTY_STEP_UP:
1961 case M_PROPERTY_STEP_DOWN:
1962 m_property_flag(prop, action, arg, &forced_subs_only);
1963 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1964 return M_PROPERTY_OK;
1965 default:
1966 return m_property_flag(prop, action, arg, &forced_subs_only);
1971 #ifdef CONFIG_FREETYPE
1972 /// Subtitle scale (RW)
1973 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1974 MPContext *mpctx)
1976 struct MPOpts *opts = &mpctx->opts;
1978 switch (action) {
1979 case M_PROPERTY_SET:
1980 if (!arg)
1981 return M_PROPERTY_ERROR;
1982 M_PROPERTY_CLAMP(prop, *(float *) arg);
1983 #ifdef CONFIG_ASS
1984 if (opts->ass_enabled) {
1985 ass_font_scale = *(float *) arg;
1986 ass_force_reload = 1;
1988 #endif
1989 text_font_scale_factor = *(float *) arg;
1990 force_load_font = 1;
1991 return M_PROPERTY_OK;
1992 case M_PROPERTY_STEP_UP:
1993 case M_PROPERTY_STEP_DOWN:
1994 #ifdef CONFIG_ASS
1995 if (opts->ass_enabled) {
1996 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1997 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1998 M_PROPERTY_CLAMP(prop, ass_font_scale);
1999 ass_force_reload = 1;
2001 #endif
2002 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
2003 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
2004 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
2005 force_load_font = 1;
2006 return M_PROPERTY_OK;
2007 default:
2008 #ifdef CONFIG_ASS
2009 if (opts->ass_enabled)
2010 return m_property_float_ro(prop, action, arg, ass_font_scale);
2011 else
2012 #endif
2013 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
2016 #endif
2018 ///@}
2020 /// \defgroup TVProperties TV properties
2021 /// \ingroup Properties
2022 ///@{
2024 #ifdef CONFIG_TV
2026 /// TV color settings (RW)
2027 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
2028 MPContext *mpctx)
2030 int r, val;
2031 tvi_handle_t *tvh = mpctx->demuxer->priv;
2032 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2033 return M_PROPERTY_UNAVAILABLE;
2035 switch (action) {
2036 case M_PROPERTY_SET:
2037 if (!arg)
2038 return M_PROPERTY_ERROR;
2039 M_PROPERTY_CLAMP(prop, *(int *) arg);
2040 return tv_set_color_options(tvh, prop->offset, *(int *) arg);
2041 case M_PROPERTY_GET:
2042 return tv_get_color_options(tvh, prop->offset, arg);
2043 case M_PROPERTY_STEP_UP:
2044 case M_PROPERTY_STEP_DOWN:
2045 if ((r = tv_get_color_options(tvh, prop->offset, &val)) >= 0) {
2046 if (!r)
2047 return M_PROPERTY_ERROR;
2048 val += (arg ? *(int *) arg : 1) *
2049 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2050 M_PROPERTY_CLAMP(prop, val);
2051 return tv_set_color_options(tvh, prop->offset, val);
2053 return M_PROPERTY_ERROR;
2055 return M_PROPERTY_NOT_IMPLEMENTED;
2058 #endif
2060 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
2061 MPContext *mpctx)
2063 int val,result;
2064 int base_ioctl = prop->offset;
2066 for teletext's GET,SET,STEP ioctls this is not 0
2067 SET is GET+1
2068 STEP is GET+2
2070 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
2071 return M_PROPERTY_UNAVAILABLE;
2072 if(!base_ioctl)
2073 return M_PROPERTY_ERROR;
2075 switch (action) {
2076 case M_PROPERTY_GET:
2077 if (!arg)
2078 return M_PROPERTY_ERROR;
2079 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
2080 break;
2081 case M_PROPERTY_SET:
2082 if (!arg)
2083 return M_PROPERTY_ERROR;
2084 M_PROPERTY_CLAMP(prop, *(int *) arg);
2085 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
2086 break;
2087 case M_PROPERTY_STEP_UP:
2088 case M_PROPERTY_STEP_DOWN:
2089 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
2090 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2091 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
2092 break;
2093 default:
2094 return M_PROPERTY_NOT_IMPLEMENTED;
2097 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
2100 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
2101 MPContext *mpctx)
2103 int result;
2104 int val;
2106 //with tvh==NULL will fail too
2107 result=mp_property_teletext_common(prop,action,arg,mpctx);
2108 if(result!=M_PROPERTY_OK)
2109 return result;
2111 if(teletext_control(mpctx->demuxer->teletext,
2112 prop->offset, &val)==VBI_CONTROL_TRUE && val)
2113 mp_input_set_section(mpctx->input, "teletext");
2114 else
2115 mp_input_set_section(mpctx->input, "tv");
2116 return M_PROPERTY_OK;
2119 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2120 MPContext *mpctx)
2122 int result;
2123 int val;
2124 if (!mpctx->demuxer->teletext)
2125 return M_PROPERTY_UNAVAILABLE;
2126 switch(action){
2127 case M_PROPERTY_STEP_UP:
2128 case M_PROPERTY_STEP_DOWN:
2129 //This should be handled separately
2130 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2131 result=teletext_control(mpctx->demuxer->teletext,
2132 TV_VBI_CONTROL_STEP_PAGE, &val);
2133 break;
2134 default:
2135 result=mp_property_teletext_common(prop,action,arg,mpctx);
2137 return result;
2140 ///@}
2142 /// All properties available in MPlayer.
2143 /** \ingroup Properties
2145 static const m_option_t mp_properties[] = {
2146 // General
2147 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2148 M_OPT_RANGE, 0, 3, NULL },
2149 { "loop", mp_property_loop, CONF_TYPE_INT,
2150 M_OPT_MIN, -1, 0, NULL },
2151 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2152 M_OPT_RANGE, 0.01, 100.0, NULL },
2153 { "filename", mp_property_filename, CONF_TYPE_STRING,
2154 0, 0, 0, NULL },
2155 { "path", mp_property_path, CONF_TYPE_STRING,
2156 0, 0, 0, NULL },
2157 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2158 0, 0, 0, NULL },
2159 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2160 M_OPT_MIN, 0, 0, NULL },
2161 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2162 M_OPT_MIN, 0, 0, NULL },
2163 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2164 M_OPT_MIN, 0, 0, NULL },
2165 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2166 M_OPT_MIN, 0, 0, NULL },
2167 { "stream_time_pos", mp_property_stream_time_pos, CONF_TYPE_TIME,
2168 M_OPT_MIN, 0, 0, NULL },
2169 { "length", mp_property_length, CONF_TYPE_TIME,
2170 M_OPT_MIN, 0, 0, NULL },
2171 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2172 M_OPT_RANGE, 0, 100, NULL },
2173 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2174 M_OPT_MIN, 0, 0, NULL },
2175 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2176 M_OPT_MIN, 0, 0, NULL },
2177 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2178 0, 0, 0, NULL },
2179 { "angle", mp_property_angle, CONF_TYPE_INT,
2180 CONF_RANGE, -2, 10, NULL },
2181 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2182 0, 0, 0, NULL },
2183 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2184 M_OPT_RANGE, 0, 1, NULL },
2185 { "capturing", mp_property_capture, CONF_TYPE_FLAG,
2186 M_OPT_RANGE, 0, 1, NULL },
2188 // Audio
2189 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2190 M_OPT_RANGE, 0, 100, NULL },
2191 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2192 M_OPT_RANGE, 0, 1, NULL },
2193 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2194 M_OPT_RANGE, -100, 100, NULL },
2195 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2196 0, 0, 0, NULL },
2197 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2198 0, 0, 0, NULL },
2199 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2200 0, 0, 0, NULL },
2201 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2202 0, 0, 0, NULL },
2203 { "channels", mp_property_channels, CONF_TYPE_INT,
2204 0, 0, 0, NULL },
2205 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2206 CONF_RANGE, -2, 65535, NULL },
2207 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2208 M_OPT_RANGE, -1, 1, NULL },
2210 // Video
2211 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2212 M_OPT_RANGE, 0, 1, NULL },
2213 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2214 M_OPT_RANGE, 0, 1, NULL },
2215 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2216 M_OPT_RANGE, 0, 2, NULL },
2217 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2218 M_OPT_RANGE, 0, 1, NULL },
2219 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2220 M_OPT_RANGE, 0, 1, NULL },
2221 { "border", mp_property_border, CONF_TYPE_FLAG,
2222 M_OPT_RANGE, 0, 1, NULL },
2223 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2224 M_OPT_RANGE, 0, 2, NULL },
2225 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2226 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_gamma)},
2227 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2228 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_brightness) },
2229 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2230 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_contrast) },
2231 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2232 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_saturation) },
2233 { "hue", mp_property_gamma, CONF_TYPE_INT,
2234 M_OPT_RANGE, -100, 100, .offset=offsetof(struct MPOpts, vo_gamma_hue) },
2235 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2236 M_OPT_RANGE, 0, 1, NULL },
2237 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2238 M_OPT_RANGE, 0, 1, NULL },
2239 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2240 0, 0, 0, NULL },
2241 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2242 0, 0, 0, NULL },
2243 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2244 0, 0, 0, NULL },
2245 { "width", mp_property_width, CONF_TYPE_INT,
2246 0, 0, 0, NULL },
2247 { "height", mp_property_height, CONF_TYPE_INT,
2248 0, 0, 0, NULL },
2249 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2250 0, 0, 0, NULL },
2251 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2252 0, 0, 0, NULL },
2253 { "switch_video", mp_property_video, CONF_TYPE_INT,
2254 CONF_RANGE, -2, 65535, NULL },
2255 { "switch_program", mp_property_program, CONF_TYPE_INT,
2256 CONF_RANGE, -1, 65535, NULL },
2258 // Subs
2259 { "sub", mp_property_sub, CONF_TYPE_INT,
2260 M_OPT_MIN, -1, 0, NULL },
2261 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2262 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2263 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2264 M_OPT_MIN, -1, 0, NULL },
2265 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2266 M_OPT_MIN, -1, 0, NULL },
2267 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2268 M_OPT_MIN, -1, 0, NULL },
2269 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2270 0, 0, 0, NULL },
2271 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2272 M_OPT_RANGE, 0, 100, NULL },
2273 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2274 M_OPT_RANGE, 0, 2, NULL },
2275 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2276 M_OPT_RANGE, 0, 1, NULL },
2277 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2278 M_OPT_RANGE, 0, 1, NULL },
2279 #ifdef CONFIG_FREETYPE
2280 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2281 M_OPT_RANGE, 0, 100, NULL },
2282 #endif
2283 #ifdef CONFIG_ASS
2284 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2285 M_OPT_RANGE, 0, 1, NULL },
2286 #endif
2288 #ifdef CONFIG_TV
2289 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2290 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_BRIGHTNESS },
2291 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2292 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_CONTRAST },
2293 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2294 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_SATURATION },
2295 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2296 M_OPT_RANGE, -100, 100, .offset=TV_COLOR_HUE },
2297 #endif
2298 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2299 M_OPT_RANGE, 100, 899, .offset=TV_VBI_CONTROL_GET_PAGE },
2300 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2301 M_OPT_RANGE, 0, 64, .offset=TV_VBI_CONTROL_GET_SUBPAGE },
2302 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2303 M_OPT_RANGE, 0, 1, .offset=TV_VBI_CONTROL_GET_MODE },
2304 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2305 M_OPT_RANGE, 0, 3, .offset=TV_VBI_CONTROL_GET_FORMAT },
2306 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2307 M_OPT_RANGE, 0, 2, .offset=TV_VBI_CONTROL_GET_HALF_PAGE },
2308 { NULL, NULL, NULL, 0, 0, 0, NULL }
2312 int mp_property_do(const char *name, int action, void *val, void *ctx)
2314 return m_property_do(mp_properties, name, action, val, ctx);
2317 char* mp_property_print(const char *name, void* ctx)
2319 char* ret = NULL;
2320 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2321 return NULL;
2322 return ret;
2325 char *property_expand_string(MPContext *mpctx, char *str)
2327 return m_properties_expand_string(mp_properties, str, mpctx);
2330 void property_print_help(void)
2332 m_properties_print_help_list(mp_properties);
2336 /* List of default ways to show a property on OSD.
2338 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2339 * a bar showing the current position between min/max values of the
2340 * property. In this case osd_msg is only used for terminal output
2341 * if there is no video; it'll be a label shown together with percentage.
2343 * Otherwise setting osd_msg will show the string on OSD, formatted with
2344 * the text value of the property as argument.
2346 static struct property_osd_display {
2347 /// property name
2348 const char *name;
2349 /// progressbar type
2350 int osd_progbar; // -1 is special value for seek indicators
2351 /// osd msg id if it must be shared
2352 int osd_id;
2353 /// osd msg template
2354 const char *osd_msg;
2355 } property_osd_display[] = {
2356 // general
2357 { "loop", 0, -1, _("Loop: %s") },
2358 { "chapter", -1, -1, NULL },
2359 { "capturing", 0, -1, _("Capturing: %s") },
2360 // audio
2361 { "volume", OSD_VOLUME, -1, _("Volume") },
2362 { "mute", 0, -1, _("Mute: %s") },
2363 { "audio_delay", 0, -1, _("A-V delay: %s") },
2364 { "switch_audio", 0, -1, _("Audio: %s") },
2365 { "balance", OSD_BALANCE, -1, _("Balance") },
2366 // video
2367 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2368 { "ontop", 0, -1, _("Stay on top: %s") },
2369 { "rootwin", 0, -1, _("Rootwin: %s") },
2370 { "border", 0, -1, _("Border: %s") },
2371 { "framedropping", 0, -1, _("Framedropping: %s") },
2372 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2373 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2374 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2375 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2376 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2377 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2378 { "hue", OSD_HUE, -1, _("Hue") },
2379 { "vsync", 0, -1, _("VSync: %s") },
2380 // subs
2381 { "sub", 0, -1, _("Subtitles: %s") },
2382 { "sub_source", 0, -1, _("Sub source: %s") },
2383 { "sub_vob", 0, -1, _("Subtitles: %s") },
2384 { "sub_demux", 0, -1, _("Subtitles: %s") },
2385 { "sub_file", 0, -1, _("Subtitles: %s") },
2386 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2387 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2388 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2389 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2390 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2391 #ifdef CONFIG_FREETYPE
2392 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2393 #endif
2394 #ifdef CONFIG_TV
2395 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2396 { "tv_hue", OSD_HUE, -1, _("Hue") },
2397 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2398 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2399 #endif
2403 static int show_property_osd(MPContext *mpctx, const char *pname)
2405 struct MPOpts *opts = &mpctx->opts;
2406 int r;
2407 m_option_t* prop;
2408 struct property_osd_display *p;
2410 // look for the command
2411 for (p = property_osd_display; p->name; p++)
2412 if (!strcmp(p->name, pname))
2413 break;
2414 if (!p->name)
2415 return -1;
2417 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2418 return -1;
2420 if (p->osd_progbar == -1)
2421 mpctx->add_osd_seek_info = true;
2422 else if (p->osd_progbar) {
2423 if (prop->type == CONF_TYPE_INT) {
2424 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2425 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2426 prop->min, prop->max, r);
2427 } else if (prop->type == CONF_TYPE_FLOAT) {
2428 float f;
2429 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2430 set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
2431 prop->min, prop->max, f);
2432 } else {
2433 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2434 "Property use an unsupported type.\n");
2435 return -1;
2437 return 0;
2440 if (p->osd_msg) {
2441 char *val = mp_property_print(pname, mpctx);
2442 if (val) {
2443 int index = p - property_osd_display;
2444 set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2445 1, opts->osd_duration, p->osd_msg, val);
2446 free(val);
2449 return 0;
2454 * \defgroup Command2Property Command to property bridge
2456 * It is used to handle most commands that just set a property
2457 * and optionally display something on the OSD.
2458 * Two kinds of commands are handled: adjust or toggle.
2460 * Adjust commands take 1 or 2 parameters: <value> <abs>
2461 * If <abs> is non-zero the property is set to the given value
2462 * otherwise it is adjusted.
2464 * Toggle commands take 0 or 1 parameters. With no parameter
2465 * or a value less than the property minimum it just steps the
2466 * property to its next or previous value respectively.
2467 * Otherwise it sets it to the given value.
2472 /// List of the commands that can be handled by setting a property.
2473 static struct {
2474 /// property name
2475 const char *name;
2476 /// cmd id
2477 int cmd;
2478 /// set/adjust or toggle command
2479 int toggle;
2480 } set_prop_cmd[] = {
2481 // general
2482 { "loop", MP_CMD_LOOP, 0},
2483 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2484 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2485 { "pause", MP_CMD_PAUSE, 0},
2486 { "capturing", MP_CMD_CAPTURING, 1},
2487 // audio
2488 { "volume", MP_CMD_VOLUME, 0},
2489 { "mute", MP_CMD_MUTE, 1},
2490 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2491 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2492 { "balance", MP_CMD_BALANCE, 0},
2493 // video
2494 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2495 { "panscan", MP_CMD_PANSCAN, 0},
2496 { "ontop", MP_CMD_VO_ONTOP, 1},
2497 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2498 { "border", MP_CMD_VO_BORDER, 1},
2499 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2500 { "gamma", MP_CMD_GAMMA, 0},
2501 { "brightness", MP_CMD_BRIGHTNESS, 0},
2502 { "contrast", MP_CMD_CONTRAST, 0},
2503 { "saturation", MP_CMD_SATURATION, 0},
2504 { "hue", MP_CMD_HUE, 0},
2505 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2506 // subs
2507 { "sub", MP_CMD_SUB_SELECT, 1},
2508 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2509 { "sub_vob", MP_CMD_SUB_VOB, 1},
2510 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2511 { "sub_file", MP_CMD_SUB_FILE, 1},
2512 { "sub_pos", MP_CMD_SUB_POS, 0},
2513 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2514 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2515 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2516 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2517 #ifdef CONFIG_FREETYPE
2518 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2519 #endif
2520 #ifdef CONFIG_ASS
2521 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2522 #endif
2523 #ifdef CONFIG_TV
2524 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2525 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2526 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2527 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2528 #endif
2532 /// Handle commands that set a property.
2533 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2535 int i, r;
2536 m_option_t *prop;
2537 const char *pname;
2539 // look for the command
2540 for (i = 0; set_prop_cmd[i].name; i++)
2541 if (set_prop_cmd[i].cmd == cmd->id)
2542 break;
2543 if (!(pname = set_prop_cmd[i].name))
2544 return 0;
2546 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2547 return 0;
2549 // toggle command
2550 if (set_prop_cmd[i].toggle) {
2551 // set to value
2552 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2553 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2554 else if (cmd->nargs > 0)
2555 r = mp_property_do(pname, M_PROPERTY_STEP_DOWN, NULL, mpctx);
2556 else
2557 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2558 } else if (cmd->args[1].v.i) //set
2559 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2560 else // adjust
2561 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2563 if (r <= 0)
2564 return 1;
2566 show_property_osd(mpctx, pname);
2568 return 1;
2571 #ifdef CONFIG_DVDNAV
2572 static const struct {
2573 const char *name;
2574 const mp_command_type cmd;
2575 } mp_dvdnav_bindings[] = {
2576 { "up", MP_CMD_DVDNAV_UP },
2577 { "down", MP_CMD_DVDNAV_DOWN },
2578 { "left", MP_CMD_DVDNAV_LEFT },
2579 { "right", MP_CMD_DVDNAV_RIGHT },
2580 { "menu", MP_CMD_DVDNAV_MENU },
2581 { "select", MP_CMD_DVDNAV_SELECT },
2582 { "prev", MP_CMD_DVDNAV_PREVMENU },
2583 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2586 * keep old dvdnav sub-command options for a while in order not to
2587 * break slave-mode API too suddenly.
2589 { "1", MP_CMD_DVDNAV_UP },
2590 { "2", MP_CMD_DVDNAV_DOWN },
2591 { "3", MP_CMD_DVDNAV_LEFT },
2592 { "4", MP_CMD_DVDNAV_RIGHT },
2593 { "5", MP_CMD_DVDNAV_MENU },
2594 { "6", MP_CMD_DVDNAV_SELECT },
2595 { "7", MP_CMD_DVDNAV_PREVMENU },
2596 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2597 { NULL, 0 }
2599 #endif
2601 static const char *property_error_string(int error_value)
2603 switch (error_value) {
2604 case M_PROPERTY_ERROR:
2605 return "ERROR";
2606 case M_PROPERTY_UNAVAILABLE:
2607 return "PROPERTY_UNAVAILABLE";
2608 case M_PROPERTY_NOT_IMPLEMENTED:
2609 return "NOT_IMPLEMENTED";
2610 case M_PROPERTY_UNKNOWN:
2611 return "PROPERTY_UNKNOWN";
2612 case M_PROPERTY_DISABLED:
2613 return "DISABLED";
2615 return "UNKNOWN";
2618 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2620 int idx;
2621 int end = start + count;
2622 int after = mpctx->set_of_sub_size - end;
2623 sub_data **subs = mpctx->set_of_subtitles;
2624 #ifdef CONFIG_ASS
2625 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2626 #endif
2627 if (count < 0 || count > mpctx->set_of_sub_size ||
2628 start < 0 || start > mpctx->set_of_sub_size - count) {
2629 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2630 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2631 return;
2633 for (idx = start; idx < end; idx++) {
2634 sub_data *subd = subs[idx];
2635 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2636 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2637 filename_recode(subd->filename));
2638 sub_free(subd);
2639 subs[idx] = NULL;
2640 #ifdef CONFIG_ASS
2641 if (ass_tracks[idx])
2642 ass_free_track(ass_tracks[idx]);
2643 ass_tracks[idx] = NULL;
2644 #endif
2647 mpctx->global_sub_size -= count;
2648 mpctx->set_of_sub_size -= count;
2649 if (mpctx->set_of_sub_size <= 0)
2650 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2652 memmove(subs + start, subs + end, after * sizeof(*subs));
2653 memset(subs + start + after, 0, count * sizeof(*subs));
2654 #ifdef CONFIG_ASS
2655 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2656 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2657 #endif
2659 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2660 mpctx->global_sub_pos = -2;
2661 subdata = NULL;
2662 #ifdef CONFIG_ASS
2663 ass_track = NULL;
2664 #endif
2665 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2666 } else if (mpctx->set_of_sub_pos >= end) {
2667 mpctx->set_of_sub_pos -= count;
2668 mpctx->global_sub_pos -= count;
2672 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2674 struct MPOpts *opts = &mpctx->opts;
2675 sh_audio_t * const sh_audio = mpctx->sh_audio;
2676 sh_video_t * const sh_video = mpctx->sh_video;
2677 int osd_duration = opts->osd_duration;
2678 int case_fallthrough_hack = 0;
2679 if (!set_property_command(mpctx, cmd))
2680 switch (cmd->id) {
2681 case MP_CMD_SEEK:{
2682 float v;
2683 int abs;
2684 mpctx->add_osd_seek_info = true;
2685 v = cmd->args[0].v.f;
2686 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2687 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2688 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2689 if (sh_video)
2690 mpctx->osd_function =
2691 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2692 mpctx->rel_seek_secs = v;
2693 } else if (abs) { /* Absolute seek by percentage */
2694 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2695 if (sh_video)
2696 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2697 mpctx->rel_seek_secs = v / 100.0;
2698 } else {
2699 mpctx->rel_seek_secs += v;
2700 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2703 break;
2705 case MP_CMD_SET_PROPERTY_OSD:
2706 case_fallthrough_hack = 1;
2708 case MP_CMD_SET_PROPERTY:{
2709 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2710 cmd->args[1].v.s, mpctx);
2711 if (r == M_PROPERTY_UNKNOWN)
2712 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2713 "Unknown property: '%s'\n", cmd->args[0].v.s);
2714 else if (r <= 0)
2715 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2716 "Failed to set property '%s' to '%s'.\n",
2717 cmd->args[0].v.s, cmd->args[1].v.s);
2718 else if (case_fallthrough_hack)
2719 show_property_osd(mpctx, cmd->args[0].v.s);
2720 if (r <= 0)
2721 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2723 break;
2725 case MP_CMD_STEP_PROPERTY_OSD:
2726 case_fallthrough_hack = 1;
2728 case MP_CMD_STEP_PROPERTY:{
2729 void* arg = NULL;
2730 int r,i;
2731 double d;
2732 off_t o;
2733 if (cmd->args[1].v.f) {
2734 m_option_t* prop;
2735 if((r = mp_property_do(cmd->args[0].v.s,
2736 M_PROPERTY_GET_TYPE,
2737 &prop, mpctx)) <= 0)
2738 goto step_prop_err;
2739 if(prop->type == CONF_TYPE_INT ||
2740 prop->type == CONF_TYPE_FLAG)
2741 i = cmd->args[1].v.f, arg = &i;
2742 else if(prop->type == CONF_TYPE_FLOAT)
2743 arg = &cmd->args[1].v.f;
2744 else if(prop->type == CONF_TYPE_DOUBLE ||
2745 prop->type == CONF_TYPE_TIME)
2746 d = cmd->args[1].v.f, arg = &d;
2747 else if(prop->type == CONF_TYPE_POSITION)
2748 o = cmd->args[1].v.f, arg = &o;
2749 else
2750 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2751 "Ignoring step size stepping property '%s'.\n",
2752 cmd->args[0].v.s);
2754 r = mp_property_do(cmd->args[0].v.s,
2755 cmd->args[2].v.i < 0 ?
2756 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2757 arg, mpctx);
2758 step_prop_err:
2759 if (r == M_PROPERTY_UNKNOWN)
2760 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2761 "Unknown property: '%s'\n", cmd->args[0].v.s);
2762 else if (r <= 0)
2763 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2764 "Failed to increment property '%s' by %f.\n",
2765 cmd->args[0].v.s, cmd->args[1].v.f);
2766 else if (case_fallthrough_hack)
2767 show_property_osd(mpctx, cmd->args[0].v.s);
2768 if (r <= 0)
2769 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2771 break;
2773 case MP_CMD_GET_PROPERTY:{
2774 char *tmp;
2775 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2776 &tmp, mpctx);
2777 if (r <= 0) {
2778 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2779 "Failed to get value of property '%s'.\n",
2780 cmd->args[0].v.s);
2781 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2782 break;
2784 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2785 cmd->args[0].v.s, tmp);
2786 free(tmp);
2788 break;
2790 case MP_CMD_EDL_MARK:
2791 if (edl_fd) {
2792 float v = get_current_time(mpctx);
2793 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2794 mpctx->begin_skip = v;
2795 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2796 } else {
2797 if (mpctx->begin_skip > v)
2798 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2799 else {
2800 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2801 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2803 mpctx->begin_skip = MP_NOPTS_VALUE;
2806 break;
2808 case MP_CMD_SWITCH_RATIO:
2809 if (!sh_video)
2810 break;
2811 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2812 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2813 else
2814 opts->movie_aspect = cmd->args[0].v.f;
2815 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2816 break;
2818 case MP_CMD_SPEED_INCR:{
2819 float v = cmd->args[0].v.f;
2820 opts->playback_speed += v;
2821 reinit_audio_chain(mpctx);
2822 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2823 opts->playback_speed);
2824 } break;
2826 case MP_CMD_SPEED_MULT:{
2827 float v = cmd->args[0].v.f;
2828 opts->playback_speed *= v;
2829 reinit_audio_chain(mpctx);
2830 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2831 opts->playback_speed);
2832 } break;
2834 case MP_CMD_SPEED_SET:{
2835 float v = cmd->args[0].v.f;
2836 opts->playback_speed = v;
2837 reinit_audio_chain(mpctx);
2838 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2839 opts->playback_speed);
2840 } break;
2842 case MP_CMD_FRAME_STEP:
2843 add_step_frame(mpctx);
2844 break;
2846 case MP_CMD_FILE_FILTER:
2847 file_filter = cmd->args[0].v.i;
2848 break;
2850 case MP_CMD_QUIT:
2851 exit_player_with_rc(mpctx, EXIT_QUIT,
2852 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2854 case MP_CMD_PLAY_TREE_STEP:{
2855 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2856 int force = cmd->args[1].v.i;
2859 if (!force && mpctx->playtree_iter) {
2860 play_tree_iter_t *i =
2861 play_tree_iter_new_copy(mpctx->playtree_iter);
2862 if (play_tree_iter_step(i, n, 0) ==
2863 PLAY_TREE_ITER_ENTRY)
2864 mpctx->stop_play =
2865 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2866 play_tree_iter_free(i);
2867 } else
2868 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2869 if (mpctx->stop_play)
2870 mpctx->play_tree_step = n;
2873 break;
2875 case MP_CMD_PLAY_TREE_UP_STEP:{
2876 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2877 int force = cmd->args[1].v.i;
2879 if (!force && mpctx->playtree_iter) {
2880 play_tree_iter_t *i =
2881 play_tree_iter_new_copy(mpctx->playtree_iter);
2882 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2883 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2884 play_tree_iter_free(i);
2885 } else
2886 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2888 break;
2890 case MP_CMD_PLAY_ALT_SRC_STEP:
2891 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2892 int v = cmd->args[0].v.i;
2893 if (v > 0
2894 && mpctx->playtree_iter->file <
2895 mpctx->playtree_iter->num_files)
2896 mpctx->stop_play = PT_NEXT_SRC;
2897 else if (v < 0 && mpctx->playtree_iter->file > 1)
2898 mpctx->stop_play = PT_PREV_SRC;
2900 break;
2902 case MP_CMD_SUB_STEP:
2903 if (sh_video) {
2904 int movement = cmd->args[0].v.i;
2905 step_sub(subdata, sh_video->pts, movement);
2906 #ifdef CONFIG_ASS
2907 if (ass_track)
2908 sub_delay +=
2909 ass_step_sub(ass_track,
2910 (sh_video->pts +
2911 sub_delay) * 1000 + .5, movement) / 1000.;
2912 #endif
2913 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2914 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2916 break;
2918 case MP_CMD_SUB_LOG:
2919 log_sub(mpctx);
2920 break;
2922 case MP_CMD_OSD:{
2923 int v = cmd->args[0].v.i;
2924 int max = (opts->term_osd
2925 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2926 if (opts->osd_level > max)
2927 opts->osd_level = max;
2928 if (v < 0)
2929 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2930 else
2931 opts->osd_level = v > max ? max : v;
2932 /* Show OSD state when disabled, but not when an explicit
2933 argument is given to the OSD command, i.e. in slave mode. */
2934 if (v == -1 && opts->osd_level <= 1)
2935 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2936 "OSD: %s",
2937 opts->osd_level ? mp_gtext("enabled") :
2938 mp_gtext("disabled"));
2939 else
2940 rm_osd_msg(OSD_MSG_OSD_STATUS);
2942 break;
2944 case MP_CMD_OSD_SHOW_TEXT:
2945 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2946 (cmd->args[1].v.i <
2947 0 ? osd_duration : cmd->args[1].v.i),
2948 "%-.63s", cmd->args[0].v.s);
2949 break;
2951 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2952 char *txt = m_properties_expand_string(mp_properties,
2953 cmd->args[0].v.s,
2954 mpctx);
2955 /* if no argument supplied take default osd_duration, else <arg> ms. */
2956 if (txt) {
2957 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2958 (cmd->args[1].v.i <
2959 0 ? osd_duration : cmd->args[1].v.i),
2960 "%-.63s", txt);
2961 free(txt);
2964 break;
2966 case MP_CMD_LOADFILE:{
2967 play_tree_t *e = play_tree_new();
2968 play_tree_add_file(e, cmd->args[0].v.s);
2970 if (cmd->args[1].v.i) // append
2971 play_tree_append_entry(mpctx->playtree->child, e);
2972 else {
2973 // Go back to the starting point.
2974 while (play_tree_iter_up_step
2975 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2976 /* NOP */ ;
2977 play_tree_free_list(mpctx->playtree->child, 1);
2978 play_tree_set_child(mpctx->playtree, e);
2979 pt_iter_goto_head(mpctx->playtree_iter);
2980 mpctx->stop_play = PT_NEXT_SRC;
2983 break;
2985 case MP_CMD_LOADLIST:{
2986 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2987 if (!e)
2988 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2989 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2990 else {
2991 if (cmd->args[1].v.i) // append
2992 play_tree_append_entry(mpctx->playtree->child, e);
2993 else {
2994 // Go back to the starting point.
2995 while (play_tree_iter_up_step
2996 (mpctx->playtree_iter, 0, 1)
2997 != PLAY_TREE_ITER_END)
2998 /* NOP */ ;
2999 play_tree_free_list(mpctx->playtree->child, 1);
3000 play_tree_set_child(mpctx->playtree, e);
3001 pt_iter_goto_head(mpctx->playtree_iter);
3002 mpctx->stop_play = PT_NEXT_SRC;
3006 break;
3008 case MP_CMD_STOP:
3009 // Go back to the starting point.
3010 while (play_tree_iter_up_step
3011 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3012 /* NOP */ ;
3013 mpctx->stop_play = PT_STOP;
3014 break;
3016 case MP_CMD_OSD_SHOW_PROGRESSION:{
3017 int len = get_time_length(mpctx);
3018 int pts = get_current_time(mpctx);
3019 set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3020 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3021 "%c %02d:%02d:%02d / %02d:%02d:%02d",
3022 mpctx->osd_function, pts/3600, (pts/60)%60, pts%60,
3023 len/3600, (len/60)%60, len%60);
3025 break;
3027 #ifdef CONFIG_RADIO
3028 case MP_CMD_RADIO_STEP_CHANNEL:
3029 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3030 int v = cmd->args[0].v.i;
3031 if (v > 0)
3032 radio_step_channel(mpctx->demuxer->stream,
3033 RADIO_CHANNEL_HIGHER);
3034 else
3035 radio_step_channel(mpctx->demuxer->stream,
3036 RADIO_CHANNEL_LOWER);
3037 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3038 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3039 "Channel: %s",
3040 radio_get_channel_name(mpctx->demuxer->stream));
3043 break;
3045 case MP_CMD_RADIO_SET_CHANNEL:
3046 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3047 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3048 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3049 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3050 "Channel: %s",
3051 radio_get_channel_name(mpctx->demuxer->stream));
3054 break;
3056 case MP_CMD_RADIO_SET_FREQ:
3057 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3058 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3059 break;
3061 case MP_CMD_RADIO_STEP_FREQ:
3062 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3063 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3064 break;
3065 #endif
3067 #ifdef CONFIG_TV
3068 case MP_CMD_TV_START_SCAN:
3069 if (mpctx->file_format == DEMUXER_TYPE_TV)
3070 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
3071 break;
3072 case MP_CMD_TV_SET_FREQ:
3073 if (mpctx->file_format == DEMUXER_TYPE_TV)
3074 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3075 cmd->args[0].v.f * 16.0);
3076 #ifdef CONFIG_PVR
3077 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3078 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
3079 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3080 pvr_get_current_channelname (mpctx->stream),
3081 pvr_get_current_stationname (mpctx->stream));
3083 #endif /* CONFIG_PVR */
3084 break;
3086 case MP_CMD_TV_STEP_FREQ:
3087 if (mpctx->file_format == DEMUXER_TYPE_TV)
3088 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3089 cmd->args[0].v.f * 16.0);
3090 #ifdef CONFIG_PVR
3091 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3092 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
3093 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3094 pvr_get_current_channelname (mpctx->stream),
3095 pvr_get_current_frequency (mpctx->stream));
3097 #endif /* CONFIG_PVR */
3098 break;
3100 case MP_CMD_TV_SET_NORM:
3101 if (mpctx->file_format == DEMUXER_TYPE_TV)
3102 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3103 cmd->args[0].v.s);
3104 break;
3106 case MP_CMD_TV_STEP_CHANNEL:{
3107 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3108 int v = cmd->args[0].v.i;
3109 if (v > 0) {
3110 tv_step_channel((tvi_handle_t *) (mpctx->
3111 demuxer->priv),
3112 TV_CHANNEL_HIGHER);
3113 } else {
3114 tv_step_channel((tvi_handle_t *) (mpctx->
3115 demuxer->priv),
3116 TV_CHANNEL_LOWER);
3118 if (tv_channel_list) {
3119 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3120 "Channel: %s", tv_channel_current->name);
3121 //vo_osd_changed(OSDTYPE_SUBTITLE);
3124 #ifdef CONFIG_PVR
3125 else if (mpctx->stream &&
3126 mpctx->stream->type == STREAMTYPE_PVR) {
3127 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3128 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3129 pvr_get_current_channelname (mpctx->stream),
3130 pvr_get_current_stationname (mpctx->stream));
3132 #endif /* CONFIG_PVR */
3134 #ifdef CONFIG_DVBIN
3135 if (mpctx->stream->type == STREAMTYPE_DVB) {
3136 int dir;
3137 int v = cmd->args[0].v.i;
3139 mpctx->last_dvb_step = v;
3140 if (v > 0)
3141 dir = DVB_CHANNEL_HIGHER;
3142 else
3143 dir = DVB_CHANNEL_LOWER;
3146 if (dvb_step_channel(mpctx->stream, dir)) {
3147 mpctx->stop_play = PT_NEXT_ENTRY;
3148 mpctx->dvbin_reopen = 1;
3151 #endif /* CONFIG_DVBIN */
3152 break;
3154 case MP_CMD_TV_SET_CHANNEL:
3155 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3156 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3157 cmd->args[0].v.s);
3158 if (tv_channel_list) {
3159 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3160 "Channel: %s", tv_channel_current->name);
3161 //vo_osd_changed(OSDTYPE_SUBTITLE);
3164 #ifdef CONFIG_PVR
3165 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3166 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3167 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3168 pvr_get_current_channelname (mpctx->stream),
3169 pvr_get_current_stationname (mpctx->stream));
3171 #endif /* CONFIG_PVR */
3172 break;
3174 #ifdef CONFIG_DVBIN
3175 case MP_CMD_DVB_SET_CHANNEL:
3176 if (mpctx->stream->type == STREAMTYPE_DVB) {
3177 mpctx->last_dvb_step = 1;
3179 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3180 cmd->args[0].v.i)) {
3181 mpctx->stop_play = PT_NEXT_ENTRY;
3182 mpctx->dvbin_reopen = 1;
3185 break;
3186 #endif /* CONFIG_DVBIN */
3188 case MP_CMD_TV_LAST_CHANNEL:
3189 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3190 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3191 if (tv_channel_list) {
3192 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3193 "Channel: %s", tv_channel_current->name);
3194 //vo_osd_changed(OSDTYPE_SUBTITLE);
3197 #ifdef CONFIG_PVR
3198 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3199 pvr_set_lastchannel (mpctx->stream);
3200 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3201 pvr_get_current_channelname (mpctx->stream),
3202 pvr_get_current_stationname (mpctx->stream));
3204 #endif /* CONFIG_PVR */
3205 break;
3207 case MP_CMD_TV_STEP_NORM:
3208 if (mpctx->file_format == DEMUXER_TYPE_TV)
3209 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3210 break;
3212 case MP_CMD_TV_STEP_CHANNEL_LIST:
3213 if (mpctx->file_format == DEMUXER_TYPE_TV)
3214 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3215 break;
3216 #endif /* CONFIG_TV */
3217 case MP_CMD_TV_TELETEXT_ADD_DEC:
3218 if (mpctx->demuxer->teletext)
3219 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3220 &(cmd->args[0].v.s));
3221 break;
3222 case MP_CMD_TV_TELETEXT_GO_LINK:
3223 if (mpctx->demuxer->teletext)
3224 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3225 &(cmd->args[0].v.i));
3226 break;
3228 case MP_CMD_SUB_LOAD:
3229 if (sh_video) {
3230 int n = mpctx->set_of_sub_size;
3231 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3232 if (n != mpctx->set_of_sub_size) {
3233 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3234 ++mpctx->global_sub_size;
3237 break;
3239 case MP_CMD_SUB_REMOVE:
3240 if (sh_video) {
3241 int v = cmd->args[0].v.i;
3242 if (v < 0) {
3243 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3244 } else if (v < mpctx->set_of_sub_size) {
3245 remove_subtitle_range(mpctx, v, 1);
3248 break;
3250 case MP_CMD_GET_SUB_VISIBILITY:
3251 if (sh_video) {
3252 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3253 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3255 break;
3257 case MP_CMD_SCREENSHOT:
3258 if (mpctx->video_out && mpctx->video_out->config_ok) {
3259 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3260 if (CONTROL_OK !=
3261 ((vf_instance_t *) sh_video->vfilter)->
3262 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3263 &cmd->args[0].v.i))
3264 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3266 break;
3268 case MP_CMD_VF_CHANGE_RECTANGLE:
3269 if (!sh_video)
3270 break;
3271 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3272 break;
3274 case MP_CMD_GET_TIME_LENGTH:{
3275 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3276 get_time_length(mpctx));
3278 break;
3280 case MP_CMD_GET_FILENAME:{
3281 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3282 get_metadata(mpctx, META_NAME));
3284 break;
3286 case MP_CMD_GET_VIDEO_CODEC:{
3287 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3288 if (!inf)
3289 inf = strdup("");
3290 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3291 free(inf);
3293 break;
3295 case MP_CMD_GET_VIDEO_BITRATE:{
3296 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3297 if (!inf)
3298 inf = strdup("");
3299 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3300 free(inf);
3302 break;
3304 case MP_CMD_GET_VIDEO_RESOLUTION:{
3305 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3306 if (!inf)
3307 inf = strdup("");
3308 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3309 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3310 free(inf);
3312 break;
3314 case MP_CMD_GET_AUDIO_CODEC:{
3315 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3316 if (!inf)
3317 inf = strdup("");
3318 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3319 free(inf);
3321 break;
3323 case MP_CMD_GET_AUDIO_BITRATE:{
3324 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3325 if (!inf)
3326 inf = strdup("");
3327 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3328 free(inf);
3330 break;
3332 case MP_CMD_GET_AUDIO_SAMPLES:{
3333 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3334 if (!inf)
3335 inf = strdup("");
3336 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3337 free(inf);
3339 break;
3341 case MP_CMD_GET_META_TITLE:{
3342 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3343 if (!inf)
3344 inf = strdup("");
3345 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3346 free(inf);
3348 break;
3350 case MP_CMD_GET_META_ARTIST:{
3351 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3352 if (!inf)
3353 inf = strdup("");
3354 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3355 free(inf);
3357 break;
3359 case MP_CMD_GET_META_ALBUM:{
3360 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3361 if (!inf)
3362 inf = strdup("");
3363 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3364 free(inf);
3366 break;
3368 case MP_CMD_GET_META_YEAR:{
3369 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3370 if (!inf)
3371 inf = strdup("");
3372 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3373 free(inf);
3375 break;
3377 case MP_CMD_GET_META_COMMENT:{
3378 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3379 if (!inf)
3380 inf = strdup("");
3381 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3382 free(inf);
3384 break;
3386 case MP_CMD_GET_META_TRACK:{
3387 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3388 if (!inf)
3389 inf = strdup("");
3390 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3391 free(inf);
3393 break;
3395 case MP_CMD_GET_META_GENRE:{
3396 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3397 if (!inf)
3398 inf = strdup("");
3399 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3400 free(inf);
3402 break;
3404 case MP_CMD_GET_VO_FULLSCREEN:
3405 if (mpctx->video_out && mpctx->video_out->config_ok)
3406 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3407 break;
3409 case MP_CMD_GET_PERCENT_POS:
3410 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3411 get_percent_pos(mpctx));
3412 break;
3414 case MP_CMD_GET_TIME_POS:{
3415 float pos = get_current_time(mpctx);
3416 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3418 break;
3420 case MP_CMD_RUN:
3421 #ifndef __MINGW32__
3422 if (!fork()) {
3423 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3424 exit(0);
3426 #endif
3427 break;
3429 case MP_CMD_KEYDOWN_EVENTS:
3430 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3431 break;
3433 case MP_CMD_SET_MOUSE_POS:{
3434 int pointer_x, pointer_y;
3435 double dx, dy;
3436 pointer_x = cmd->args[0].v.i;
3437 pointer_y = cmd->args[1].v.i;
3438 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3439 #ifdef CONFIG_DVDNAV
3440 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3441 && dx > 0.0 && dy > 0.0) {
3442 int button = -1;
3443 pointer_x = (int) (dx * (double) sh_video->disp_w);
3444 pointer_y = (int) (dy * (double) sh_video->disp_h);
3445 mp_dvdnav_update_mouse_pos(mpctx->stream,
3446 pointer_x, pointer_y, &button);
3447 if (opts->osd_level > 1 && button > 0)
3448 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3449 "Selected button number %d", button);
3451 #endif
3452 #ifdef CONFIG_MENU
3453 if (use_menu && dx >= 0.0 && dy >= 0.0)
3454 menu_update_mouse_pos(dx, dy);
3455 #endif
3457 break;
3459 #ifdef CONFIG_DVDNAV
3460 case MP_CMD_DVDNAV:{
3461 int button = -1;
3462 int i;
3463 mp_command_type command = 0;
3464 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3465 break;
3467 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3468 if (cmd->args[0].v.s &&
3469 !strcasecmp (cmd->args[0].v.s,
3470 mp_dvdnav_bindings[i].name))
3471 command = mp_dvdnav_bindings[i].cmd;
3473 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3474 if (opts->osd_level > 1 && button > 0)
3475 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3476 "Selected button number %d", button);
3478 break;
3480 case MP_CMD_SWITCH_TITLE:
3481 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3482 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3483 break;
3485 #endif
3487 case MP_CMD_AF_SWITCH:
3488 if (sh_audio)
3490 af_uninit(mpctx->mixer.afilter);
3491 af_init(mpctx->mixer.afilter);
3493 case MP_CMD_AF_ADD:
3494 case MP_CMD_AF_DEL:
3495 if (!sh_audio)
3496 break;
3498 char* af_args = strdup(cmd->args[0].v.s);
3499 char* af_commands = af_args;
3500 char* af_command;
3501 af_instance_t* af;
3502 while ((af_command = strsep(&af_commands, ",")) != NULL)
3504 if (cmd->id == MP_CMD_AF_DEL)
3506 af = af_get(mpctx->mixer.afilter, af_command);
3507 if (af != NULL)
3508 af_remove(mpctx->mixer.afilter, af);
3510 else
3511 af_add(mpctx->mixer.afilter, af_command);
3513 reinit_audio_chain(mpctx);
3514 free(af_args);
3516 break;
3517 case MP_CMD_AF_CLR:
3518 if (!sh_audio)
3519 break;
3520 af_uninit(mpctx->mixer.afilter);
3521 af_init(mpctx->mixer.afilter);
3522 reinit_audio_chain(mpctx);
3523 break;
3524 case MP_CMD_AF_CMDLINE:
3525 if (sh_audio) {
3526 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3527 if (!af) {
3528 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3529 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3530 break;
3532 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3533 af_reinit(sh_audio->afilter, af);
3535 break;
3537 default:
3538 mp_msg(MSGT_CPLAYER, MSGL_V,
3539 "Received unknown cmd %s\n", cmd->name);
3542 switch (cmd->pausing) {
3543 case 1: // "pausing"
3544 pause_player(mpctx);
3545 break;
3546 case 3: // "pausing_toggle"
3547 if (mpctx->paused)
3548 unpause_player(mpctx);
3549 else
3550 pause_player(mpctx);
3551 break;