Change some filename-handling code to use mp_basename()
[mplayer/glamo.git] / command.c
blob6bf48258485932f6eb1d089ffc60390f38f92729
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 value. Otherwise it sets it to the given
2467 * 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
2555 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2556 } else if (cmd->args[1].v.i) //set
2557 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2558 else // adjust
2559 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2561 if (r <= 0)
2562 return 1;
2564 show_property_osd(mpctx, pname);
2566 return 1;
2569 #ifdef CONFIG_DVDNAV
2570 static const struct {
2571 const char *name;
2572 const mp_command_type cmd;
2573 } mp_dvdnav_bindings[] = {
2574 { "up", MP_CMD_DVDNAV_UP },
2575 { "down", MP_CMD_DVDNAV_DOWN },
2576 { "left", MP_CMD_DVDNAV_LEFT },
2577 { "right", MP_CMD_DVDNAV_RIGHT },
2578 { "menu", MP_CMD_DVDNAV_MENU },
2579 { "select", MP_CMD_DVDNAV_SELECT },
2580 { "prev", MP_CMD_DVDNAV_PREVMENU },
2581 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2584 * keep old dvdnav sub-command options for a while in order not to
2585 * break slave-mode API too suddenly.
2587 { "1", MP_CMD_DVDNAV_UP },
2588 { "2", MP_CMD_DVDNAV_DOWN },
2589 { "3", MP_CMD_DVDNAV_LEFT },
2590 { "4", MP_CMD_DVDNAV_RIGHT },
2591 { "5", MP_CMD_DVDNAV_MENU },
2592 { "6", MP_CMD_DVDNAV_SELECT },
2593 { "7", MP_CMD_DVDNAV_PREVMENU },
2594 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2595 { NULL, 0 }
2597 #endif
2599 static const char *property_error_string(int error_value)
2601 switch (error_value) {
2602 case M_PROPERTY_ERROR:
2603 return "ERROR";
2604 case M_PROPERTY_UNAVAILABLE:
2605 return "PROPERTY_UNAVAILABLE";
2606 case M_PROPERTY_NOT_IMPLEMENTED:
2607 return "NOT_IMPLEMENTED";
2608 case M_PROPERTY_UNKNOWN:
2609 return "PROPERTY_UNKNOWN";
2610 case M_PROPERTY_DISABLED:
2611 return "DISABLED";
2613 return "UNKNOWN";
2616 static void remove_subtitle_range(MPContext *mpctx, int start, int count)
2618 int idx;
2619 int end = start + count;
2620 int after = mpctx->set_of_sub_size - end;
2621 sub_data **subs = mpctx->set_of_subtitles;
2622 #ifdef CONFIG_ASS
2623 struct ass_track **ass_tracks = mpctx->set_of_ass_tracks;
2624 #endif
2625 if (count < 0 || count > mpctx->set_of_sub_size ||
2626 start < 0 || start > mpctx->set_of_sub_size - count) {
2627 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2628 "Cannot remove invalid subtitle range %i +%i\n", start, count);
2629 return;
2631 for (idx = start; idx < end; idx++) {
2632 sub_data *subd = subs[idx];
2633 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2634 "SUB: Removed subtitle file (%d): %s\n", idx + 1,
2635 filename_recode(subd->filename));
2636 sub_free(subd);
2637 subs[idx] = NULL;
2638 #ifdef CONFIG_ASS
2639 if (ass_tracks[idx])
2640 ass_free_track(ass_tracks[idx]);
2641 ass_tracks[idx] = NULL;
2642 #endif
2645 mpctx->global_sub_size -= count;
2646 mpctx->set_of_sub_size -= count;
2647 if (mpctx->set_of_sub_size <= 0)
2648 mpctx->sub_counts[SUB_SOURCE_SUBS] = 0;
2650 memmove(subs + start, subs + end, after * sizeof(*subs));
2651 memset(subs + start + after, 0, count * sizeof(*subs));
2652 #ifdef CONFIG_ASS
2653 memmove(ass_tracks + start, ass_tracks + end, after * sizeof(*ass_tracks));
2654 memset(ass_tracks + start + after, 0, count * sizeof(*ass_tracks));
2655 #endif
2657 if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
2658 mpctx->global_sub_pos = -2;
2659 subdata = NULL;
2660 #ifdef CONFIG_ASS
2661 ass_track = NULL;
2662 #endif
2663 mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
2664 } else if (mpctx->set_of_sub_pos >= end) {
2665 mpctx->set_of_sub_pos -= count;
2666 mpctx->global_sub_pos -= count;
2670 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2672 struct MPOpts *opts = &mpctx->opts;
2673 sh_audio_t * const sh_audio = mpctx->sh_audio;
2674 sh_video_t * const sh_video = mpctx->sh_video;
2675 int osd_duration = opts->osd_duration;
2676 int case_fallthrough_hack = 0;
2677 if (!set_property_command(mpctx, cmd))
2678 switch (cmd->id) {
2679 case MP_CMD_SEEK:{
2680 float v;
2681 int abs;
2682 mpctx->add_osd_seek_info = true;
2683 v = cmd->args[0].v.f;
2684 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2685 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2686 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2687 if (sh_video)
2688 mpctx->osd_function =
2689 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2690 mpctx->rel_seek_secs = v;
2691 } else if (abs) { /* Absolute seek by percentage */
2692 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2693 if (sh_video)
2694 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2695 mpctx->rel_seek_secs = v / 100.0;
2696 } else {
2697 mpctx->rel_seek_secs += v;
2698 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2701 break;
2703 case MP_CMD_SET_PROPERTY_OSD:
2704 case_fallthrough_hack = 1;
2706 case MP_CMD_SET_PROPERTY:{
2707 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2708 cmd->args[1].v.s, mpctx);
2709 if (r == M_PROPERTY_UNKNOWN)
2710 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2711 "Unknown property: '%s'\n", cmd->args[0].v.s);
2712 else if (r <= 0)
2713 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2714 "Failed to set property '%s' to '%s'.\n",
2715 cmd->args[0].v.s, cmd->args[1].v.s);
2716 else if (case_fallthrough_hack)
2717 show_property_osd(mpctx, cmd->args[0].v.s);
2718 if (r <= 0)
2719 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2721 break;
2723 case MP_CMD_STEP_PROPERTY_OSD:
2724 case_fallthrough_hack = 1;
2726 case MP_CMD_STEP_PROPERTY:{
2727 void* arg = NULL;
2728 int r,i;
2729 double d;
2730 off_t o;
2731 if (cmd->args[1].v.f) {
2732 m_option_t* prop;
2733 if((r = mp_property_do(cmd->args[0].v.s,
2734 M_PROPERTY_GET_TYPE,
2735 &prop, mpctx)) <= 0)
2736 goto step_prop_err;
2737 if(prop->type == CONF_TYPE_INT ||
2738 prop->type == CONF_TYPE_FLAG)
2739 i = cmd->args[1].v.f, arg = &i;
2740 else if(prop->type == CONF_TYPE_FLOAT)
2741 arg = &cmd->args[1].v.f;
2742 else if(prop->type == CONF_TYPE_DOUBLE ||
2743 prop->type == CONF_TYPE_TIME)
2744 d = cmd->args[1].v.f, arg = &d;
2745 else if(prop->type == CONF_TYPE_POSITION)
2746 o = cmd->args[1].v.f, arg = &o;
2747 else
2748 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2749 "Ignoring step size stepping property '%s'.\n",
2750 cmd->args[0].v.s);
2752 r = mp_property_do(cmd->args[0].v.s,
2753 cmd->args[2].v.i < 0 ?
2754 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2755 arg, mpctx);
2756 step_prop_err:
2757 if (r == M_PROPERTY_UNKNOWN)
2758 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2759 "Unknown property: '%s'\n", cmd->args[0].v.s);
2760 else if (r <= 0)
2761 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2762 "Failed to increment property '%s' by %f.\n",
2763 cmd->args[0].v.s, cmd->args[1].v.f);
2764 else if (case_fallthrough_hack)
2765 show_property_osd(mpctx, cmd->args[0].v.s);
2766 if (r <= 0)
2767 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2769 break;
2771 case MP_CMD_GET_PROPERTY:{
2772 char *tmp;
2773 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2774 &tmp, mpctx);
2775 if (r <= 0) {
2776 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2777 "Failed to get value of property '%s'.\n",
2778 cmd->args[0].v.s);
2779 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_ERROR=%s\n", property_error_string(r));
2780 break;
2782 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2783 cmd->args[0].v.s, tmp);
2784 free(tmp);
2786 break;
2788 case MP_CMD_EDL_MARK:
2789 if (edl_fd) {
2790 float v = get_current_time(mpctx);
2791 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2792 mpctx->begin_skip = v;
2793 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2794 } else {
2795 if (mpctx->begin_skip > v)
2796 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2797 else {
2798 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2799 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2801 mpctx->begin_skip = MP_NOPTS_VALUE;
2804 break;
2806 case MP_CMD_SWITCH_RATIO:
2807 if (!sh_video)
2808 break;
2809 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2810 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2811 else
2812 opts->movie_aspect = cmd->args[0].v.f;
2813 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2814 break;
2816 case MP_CMD_SPEED_INCR:{
2817 float v = cmd->args[0].v.f;
2818 opts->playback_speed += v;
2819 reinit_audio_chain(mpctx);
2820 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2821 opts->playback_speed);
2822 } break;
2824 case MP_CMD_SPEED_MULT:{
2825 float v = cmd->args[0].v.f;
2826 opts->playback_speed *= v;
2827 reinit_audio_chain(mpctx);
2828 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2829 opts->playback_speed);
2830 } break;
2832 case MP_CMD_SPEED_SET:{
2833 float v = cmd->args[0].v.f;
2834 opts->playback_speed = v;
2835 reinit_audio_chain(mpctx);
2836 set_osd_tmsg(OSD_MSG_SPEED, 1, osd_duration, "Speed: x %6.2f",
2837 opts->playback_speed);
2838 } break;
2840 case MP_CMD_FRAME_STEP:
2841 add_step_frame(mpctx);
2842 break;
2844 case MP_CMD_FILE_FILTER:
2845 file_filter = cmd->args[0].v.i;
2846 break;
2848 case MP_CMD_QUIT:
2849 exit_player_with_rc(mpctx, EXIT_QUIT,
2850 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2852 case MP_CMD_PLAY_TREE_STEP:{
2853 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2854 int force = cmd->args[1].v.i;
2857 if (!force && mpctx->playtree_iter) {
2858 play_tree_iter_t *i =
2859 play_tree_iter_new_copy(mpctx->playtree_iter);
2860 if (play_tree_iter_step(i, n, 0) ==
2861 PLAY_TREE_ITER_ENTRY)
2862 mpctx->stop_play =
2863 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2864 play_tree_iter_free(i);
2865 } else
2866 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2867 if (mpctx->stop_play)
2868 mpctx->play_tree_step = n;
2871 break;
2873 case MP_CMD_PLAY_TREE_UP_STEP:{
2874 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2875 int force = cmd->args[1].v.i;
2877 if (!force && mpctx->playtree_iter) {
2878 play_tree_iter_t *i =
2879 play_tree_iter_new_copy(mpctx->playtree_iter);
2880 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2881 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2882 play_tree_iter_free(i);
2883 } else
2884 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2886 break;
2888 case MP_CMD_PLAY_ALT_SRC_STEP:
2889 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2890 int v = cmd->args[0].v.i;
2891 if (v > 0
2892 && mpctx->playtree_iter->file <
2893 mpctx->playtree_iter->num_files)
2894 mpctx->stop_play = PT_NEXT_SRC;
2895 else if (v < 0 && mpctx->playtree_iter->file > 1)
2896 mpctx->stop_play = PT_PREV_SRC;
2898 break;
2900 case MP_CMD_SUB_STEP:
2901 if (sh_video) {
2902 int movement = cmd->args[0].v.i;
2903 step_sub(subdata, sh_video->pts, movement);
2904 #ifdef CONFIG_ASS
2905 if (ass_track)
2906 sub_delay +=
2907 ass_step_sub(ass_track,
2908 (sh_video->pts +
2909 sub_delay) * 1000 + .5, movement) / 1000.;
2910 #endif
2911 set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2912 "Sub delay: %d ms", ROUND(sub_delay * 1000));
2914 break;
2916 case MP_CMD_SUB_LOG:
2917 log_sub(mpctx);
2918 break;
2920 case MP_CMD_OSD:{
2921 int v = cmd->args[0].v.i;
2922 int max = (opts->term_osd
2923 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2924 if (opts->osd_level > max)
2925 opts->osd_level = max;
2926 if (v < 0)
2927 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2928 else
2929 opts->osd_level = v > max ? max : v;
2930 /* Show OSD state when disabled, but not when an explicit
2931 argument is given to the OSD command, i.e. in slave mode. */
2932 if (v == -1 && opts->osd_level <= 1)
2933 set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2934 "OSD: %s",
2935 opts->osd_level ? mp_gtext("enabled") :
2936 mp_gtext("disabled"));
2937 else
2938 rm_osd_msg(OSD_MSG_OSD_STATUS);
2940 break;
2942 case MP_CMD_OSD_SHOW_TEXT:
2943 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2944 (cmd->args[1].v.i <
2945 0 ? osd_duration : cmd->args[1].v.i),
2946 "%-.63s", cmd->args[0].v.s);
2947 break;
2949 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2950 char *txt = m_properties_expand_string(mp_properties,
2951 cmd->args[0].v.s,
2952 mpctx);
2953 /* if no argument supplied take default osd_duration, else <arg> ms. */
2954 if (txt) {
2955 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2956 (cmd->args[1].v.i <
2957 0 ? osd_duration : cmd->args[1].v.i),
2958 "%-.63s", txt);
2959 free(txt);
2962 break;
2964 case MP_CMD_LOADFILE:{
2965 play_tree_t *e = play_tree_new();
2966 play_tree_add_file(e, cmd->args[0].v.s);
2968 if (cmd->args[1].v.i) // append
2969 play_tree_append_entry(mpctx->playtree->child, e);
2970 else {
2971 // Go back to the starting point.
2972 while (play_tree_iter_up_step
2973 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2974 /* NOP */ ;
2975 play_tree_free_list(mpctx->playtree->child, 1);
2976 play_tree_set_child(mpctx->playtree, e);
2977 pt_iter_goto_head(mpctx->playtree_iter);
2978 mpctx->stop_play = PT_NEXT_SRC;
2981 break;
2983 case MP_CMD_LOADLIST:{
2984 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2985 if (!e)
2986 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2987 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2988 else {
2989 if (cmd->args[1].v.i) // append
2990 play_tree_append_entry(mpctx->playtree->child, e);
2991 else {
2992 // Go back to the starting point.
2993 while (play_tree_iter_up_step
2994 (mpctx->playtree_iter, 0, 1)
2995 != PLAY_TREE_ITER_END)
2996 /* NOP */ ;
2997 play_tree_free_list(mpctx->playtree->child, 1);
2998 play_tree_set_child(mpctx->playtree, e);
2999 pt_iter_goto_head(mpctx->playtree_iter);
3000 mpctx->stop_play = PT_NEXT_SRC;
3004 break;
3006 case MP_CMD_STOP:
3007 // Go back to the starting point.
3008 while (play_tree_iter_up_step
3009 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
3010 /* NOP */ ;
3011 mpctx->stop_play = PT_STOP;
3012 break;
3014 case MP_CMD_OSD_SHOW_PROGRESSION:{
3015 int len = get_time_length(mpctx);
3016 int pts = get_current_time(mpctx);
3017 set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3018 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3019 "%c %02d:%02d:%02d / %02d:%02d:%02d",
3020 mpctx->osd_function, pts/3600, (pts/60)%60, pts%60,
3021 len/3600, (len/60)%60, len%60);
3023 break;
3025 #ifdef CONFIG_RADIO
3026 case MP_CMD_RADIO_STEP_CHANNEL:
3027 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3028 int v = cmd->args[0].v.i;
3029 if (v > 0)
3030 radio_step_channel(mpctx->demuxer->stream,
3031 RADIO_CHANNEL_HIGHER);
3032 else
3033 radio_step_channel(mpctx->demuxer->stream,
3034 RADIO_CHANNEL_LOWER);
3035 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3036 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3037 "Channel: %s",
3038 radio_get_channel_name(mpctx->demuxer->stream));
3041 break;
3043 case MP_CMD_RADIO_SET_CHANNEL:
3044 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
3045 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
3046 if (radio_get_channel_name(mpctx->demuxer->stream)) {
3047 set_osd_tmsg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
3048 "Channel: %s",
3049 radio_get_channel_name(mpctx->demuxer->stream));
3052 break;
3054 case MP_CMD_RADIO_SET_FREQ:
3055 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3056 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3057 break;
3059 case MP_CMD_RADIO_STEP_FREQ:
3060 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
3061 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
3062 break;
3063 #endif
3065 #ifdef CONFIG_TV
3066 case MP_CMD_TV_START_SCAN:
3067 if (mpctx->file_format == DEMUXER_TYPE_TV)
3068 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
3069 break;
3070 case MP_CMD_TV_SET_FREQ:
3071 if (mpctx->file_format == DEMUXER_TYPE_TV)
3072 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3073 cmd->args[0].v.f * 16.0);
3074 #ifdef CONFIG_PVR
3075 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3076 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
3077 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3078 pvr_get_current_channelname (mpctx->stream),
3079 pvr_get_current_stationname (mpctx->stream));
3081 #endif /* CONFIG_PVR */
3082 break;
3084 case MP_CMD_TV_STEP_FREQ:
3085 if (mpctx->file_format == DEMUXER_TYPE_TV)
3086 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
3087 cmd->args[0].v.f * 16.0);
3088 #ifdef CONFIG_PVR
3089 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3090 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
3091 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
3092 pvr_get_current_channelname (mpctx->stream),
3093 pvr_get_current_frequency (mpctx->stream));
3095 #endif /* CONFIG_PVR */
3096 break;
3098 case MP_CMD_TV_SET_NORM:
3099 if (mpctx->file_format == DEMUXER_TYPE_TV)
3100 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
3101 cmd->args[0].v.s);
3102 break;
3104 case MP_CMD_TV_STEP_CHANNEL:{
3105 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3106 int v = cmd->args[0].v.i;
3107 if (v > 0) {
3108 tv_step_channel((tvi_handle_t *) (mpctx->
3109 demuxer->priv),
3110 TV_CHANNEL_HIGHER);
3111 } else {
3112 tv_step_channel((tvi_handle_t *) (mpctx->
3113 demuxer->priv),
3114 TV_CHANNEL_LOWER);
3116 if (tv_channel_list) {
3117 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3118 "Channel: %s", tv_channel_current->name);
3119 //vo_osd_changed(OSDTYPE_SUBTITLE);
3122 #ifdef CONFIG_PVR
3123 else if (mpctx->stream &&
3124 mpctx->stream->type == STREAMTYPE_PVR) {
3125 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
3126 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3127 pvr_get_current_channelname (mpctx->stream),
3128 pvr_get_current_stationname (mpctx->stream));
3130 #endif /* CONFIG_PVR */
3132 #ifdef CONFIG_DVBIN
3133 if (mpctx->stream->type == STREAMTYPE_DVB) {
3134 int dir;
3135 int v = cmd->args[0].v.i;
3137 mpctx->last_dvb_step = v;
3138 if (v > 0)
3139 dir = DVB_CHANNEL_HIGHER;
3140 else
3141 dir = DVB_CHANNEL_LOWER;
3144 if (dvb_step_channel(mpctx->stream, dir)) {
3145 mpctx->stop_play = PT_NEXT_ENTRY;
3146 mpctx->dvbin_reopen = 1;
3149 #endif /* CONFIG_DVBIN */
3150 break;
3152 case MP_CMD_TV_SET_CHANNEL:
3153 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3154 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
3155 cmd->args[0].v.s);
3156 if (tv_channel_list) {
3157 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3158 "Channel: %s", tv_channel_current->name);
3159 //vo_osd_changed(OSDTYPE_SUBTITLE);
3162 #ifdef CONFIG_PVR
3163 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3164 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
3165 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3166 pvr_get_current_channelname (mpctx->stream),
3167 pvr_get_current_stationname (mpctx->stream));
3169 #endif /* CONFIG_PVR */
3170 break;
3172 #ifdef CONFIG_DVBIN
3173 case MP_CMD_DVB_SET_CHANNEL:
3174 if (mpctx->stream->type == STREAMTYPE_DVB) {
3175 mpctx->last_dvb_step = 1;
3177 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
3178 cmd->args[0].v.i)) {
3179 mpctx->stop_play = PT_NEXT_ENTRY;
3180 mpctx->dvbin_reopen = 1;
3183 break;
3184 #endif /* CONFIG_DVBIN */
3186 case MP_CMD_TV_LAST_CHANNEL:
3187 if (mpctx->file_format == DEMUXER_TYPE_TV) {
3188 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
3189 if (tv_channel_list) {
3190 set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
3191 "Channel: %s", tv_channel_current->name);
3192 //vo_osd_changed(OSDTYPE_SUBTITLE);
3195 #ifdef CONFIG_PVR
3196 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3197 pvr_set_lastchannel (mpctx->stream);
3198 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3199 pvr_get_current_channelname (mpctx->stream),
3200 pvr_get_current_stationname (mpctx->stream));
3202 #endif /* CONFIG_PVR */
3203 break;
3205 case MP_CMD_TV_STEP_NORM:
3206 if (mpctx->file_format == DEMUXER_TYPE_TV)
3207 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3208 break;
3210 case MP_CMD_TV_STEP_CHANNEL_LIST:
3211 if (mpctx->file_format == DEMUXER_TYPE_TV)
3212 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3213 break;
3214 #endif /* CONFIG_TV */
3215 case MP_CMD_TV_TELETEXT_ADD_DEC:
3216 if (mpctx->demuxer->teletext)
3217 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3218 &(cmd->args[0].v.s));
3219 break;
3220 case MP_CMD_TV_TELETEXT_GO_LINK:
3221 if (mpctx->demuxer->teletext)
3222 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3223 &(cmd->args[0].v.i));
3224 break;
3226 case MP_CMD_SUB_LOAD:
3227 if (sh_video) {
3228 int n = mpctx->set_of_sub_size;
3229 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3230 if (n != mpctx->set_of_sub_size) {
3231 mpctx->sub_counts[SUB_SOURCE_SUBS]++;
3232 ++mpctx->global_sub_size;
3235 break;
3237 case MP_CMD_SUB_REMOVE:
3238 if (sh_video) {
3239 int v = cmd->args[0].v.i;
3240 if (v < 0) {
3241 remove_subtitle_range(mpctx, 0, mpctx->set_of_sub_size);
3242 } else if (v < mpctx->set_of_sub_size) {
3243 remove_subtitle_range(mpctx, v, 1);
3246 break;
3248 case MP_CMD_GET_SUB_VISIBILITY:
3249 if (sh_video) {
3250 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3251 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3253 break;
3255 case MP_CMD_SCREENSHOT:
3256 if (mpctx->video_out && mpctx->video_out->config_ok) {
3257 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3258 if (CONTROL_OK !=
3259 ((vf_instance_t *) sh_video->vfilter)->
3260 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3261 &cmd->args[0].v.i))
3262 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3264 break;
3266 case MP_CMD_VF_CHANGE_RECTANGLE:
3267 if (!sh_video)
3268 break;
3269 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3270 break;
3272 case MP_CMD_GET_TIME_LENGTH:{
3273 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2f\n",
3274 get_time_length(mpctx));
3276 break;
3278 case MP_CMD_GET_FILENAME:{
3279 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3280 get_metadata(mpctx, META_NAME));
3282 break;
3284 case MP_CMD_GET_VIDEO_CODEC:{
3285 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3286 if (!inf)
3287 inf = strdup("");
3288 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3289 free(inf);
3291 break;
3293 case MP_CMD_GET_VIDEO_BITRATE:{
3294 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3295 if (!inf)
3296 inf = strdup("");
3297 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3298 free(inf);
3300 break;
3302 case MP_CMD_GET_VIDEO_RESOLUTION:{
3303 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3304 if (!inf)
3305 inf = strdup("");
3306 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3307 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3308 free(inf);
3310 break;
3312 case MP_CMD_GET_AUDIO_CODEC:{
3313 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3314 if (!inf)
3315 inf = strdup("");
3316 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3317 free(inf);
3319 break;
3321 case MP_CMD_GET_AUDIO_BITRATE:{
3322 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3323 if (!inf)
3324 inf = strdup("");
3325 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3326 free(inf);
3328 break;
3330 case MP_CMD_GET_AUDIO_SAMPLES:{
3331 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3332 if (!inf)
3333 inf = strdup("");
3334 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3335 free(inf);
3337 break;
3339 case MP_CMD_GET_META_TITLE:{
3340 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3341 if (!inf)
3342 inf = strdup("");
3343 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3344 free(inf);
3346 break;
3348 case MP_CMD_GET_META_ARTIST:{
3349 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3350 if (!inf)
3351 inf = strdup("");
3352 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3353 free(inf);
3355 break;
3357 case MP_CMD_GET_META_ALBUM:{
3358 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3359 if (!inf)
3360 inf = strdup("");
3361 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3362 free(inf);
3364 break;
3366 case MP_CMD_GET_META_YEAR:{
3367 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3368 if (!inf)
3369 inf = strdup("");
3370 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3371 free(inf);
3373 break;
3375 case MP_CMD_GET_META_COMMENT:{
3376 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3377 if (!inf)
3378 inf = strdup("");
3379 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3380 free(inf);
3382 break;
3384 case MP_CMD_GET_META_TRACK:{
3385 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3386 if (!inf)
3387 inf = strdup("");
3388 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3389 free(inf);
3391 break;
3393 case MP_CMD_GET_META_GENRE:{
3394 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3395 if (!inf)
3396 inf = strdup("");
3397 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3398 free(inf);
3400 break;
3402 case MP_CMD_GET_VO_FULLSCREEN:
3403 if (mpctx->video_out && mpctx->video_out->config_ok)
3404 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3405 break;
3407 case MP_CMD_GET_PERCENT_POS:
3408 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3409 get_percent_pos(mpctx));
3410 break;
3412 case MP_CMD_GET_TIME_POS:{
3413 float pos = get_current_time(mpctx);
3414 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3416 break;
3418 case MP_CMD_RUN:
3419 #ifndef __MINGW32__
3420 if (!fork()) {
3421 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3422 exit(0);
3424 #endif
3425 break;
3427 case MP_CMD_KEYDOWN_EVENTS:
3428 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3429 break;
3431 case MP_CMD_SET_MOUSE_POS:{
3432 int pointer_x, pointer_y;
3433 double dx, dy;
3434 pointer_x = cmd->args[0].v.i;
3435 pointer_y = cmd->args[1].v.i;
3436 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3437 #ifdef CONFIG_DVDNAV
3438 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3439 && dx > 0.0 && dy > 0.0) {
3440 int button = -1;
3441 pointer_x = (int) (dx * (double) sh_video->disp_w);
3442 pointer_y = (int) (dy * (double) sh_video->disp_h);
3443 mp_dvdnav_update_mouse_pos(mpctx->stream,
3444 pointer_x, pointer_y, &button);
3445 if (opts->osd_level > 1 && button > 0)
3446 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3447 "Selected button number %d", button);
3449 #endif
3450 #ifdef CONFIG_MENU
3451 if (use_menu && dx >= 0.0 && dy >= 0.0)
3452 menu_update_mouse_pos(dx, dy);
3453 #endif
3455 break;
3457 #ifdef CONFIG_DVDNAV
3458 case MP_CMD_DVDNAV:{
3459 int button = -1;
3460 int i;
3461 mp_command_type command = 0;
3462 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3463 break;
3465 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3466 if (cmd->args[0].v.s &&
3467 !strcasecmp (cmd->args[0].v.s,
3468 mp_dvdnav_bindings[i].name))
3469 command = mp_dvdnav_bindings[i].cmd;
3471 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3472 if (opts->osd_level > 1 && button > 0)
3473 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3474 "Selected button number %d", button);
3476 break;
3478 case MP_CMD_SWITCH_TITLE:
3479 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3480 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3481 break;
3483 #endif
3485 case MP_CMD_AF_SWITCH:
3486 if (sh_audio)
3488 af_uninit(mpctx->mixer.afilter);
3489 af_init(mpctx->mixer.afilter);
3491 case MP_CMD_AF_ADD:
3492 case MP_CMD_AF_DEL:
3493 if (!sh_audio)
3494 break;
3496 char* af_args = strdup(cmd->args[0].v.s);
3497 char* af_commands = af_args;
3498 char* af_command;
3499 af_instance_t* af;
3500 while ((af_command = strsep(&af_commands, ",")) != NULL)
3502 if (cmd->id == MP_CMD_AF_DEL)
3504 af = af_get(mpctx->mixer.afilter, af_command);
3505 if (af != NULL)
3506 af_remove(mpctx->mixer.afilter, af);
3508 else
3509 af_add(mpctx->mixer.afilter, af_command);
3511 reinit_audio_chain(mpctx);
3512 free(af_args);
3514 break;
3515 case MP_CMD_AF_CLR:
3516 if (!sh_audio)
3517 break;
3518 af_uninit(mpctx->mixer.afilter);
3519 af_init(mpctx->mixer.afilter);
3520 reinit_audio_chain(mpctx);
3521 break;
3522 case MP_CMD_AF_CMDLINE:
3523 if (sh_audio) {
3524 af_instance_t *af = af_get(sh_audio->afilter, cmd->args[0].v.s);
3525 if (!af) {
3526 mp_msg(MSGT_CPLAYER, MSGL_WARN,
3527 "Filter '%s' not found in chain.\n", cmd->args[0].v.s);
3528 break;
3530 af->control(af, AF_CONTROL_COMMAND_LINE, cmd->args[1].v.s);
3531 af_reinit(sh_audio->afilter, af);
3533 break;
3535 default:
3536 mp_msg(MSGT_CPLAYER, MSGL_V,
3537 "Received unknown cmd %s\n", cmd->name);
3540 switch (cmd->pausing) {
3541 case 1: // "pausing"
3542 pause_player(mpctx);
3543 break;
3544 case 3: // "pausing_toggle"
3545 if (mpctx->paused)
3546 unpause_player(mpctx);
3547 else
3548 pause_player(mpctx);
3549 break;