Update sources
[mplayer/kovensky.git] / command.c
blob147c0232483e1f8e8f3861418d0fb837793afa6f
1 #include <stdlib.h>
2 #include <inttypes.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <stdbool.h>
7 #include "config.h"
8 #include "talloc.h"
9 #include "command.h"
10 #include "input/input.h"
11 #include "stream/stream.h"
12 #include "libmpdemux/demuxer.h"
13 #include "libmpdemux/stheader.h"
14 #include "codec-cfg.h"
15 #include "mplayer.h"
16 #include "libvo/sub.h"
17 #include "m_option.h"
18 #include "m_property.h"
19 #include "help_mp.h"
20 #include "metadata.h"
21 #include "libmpcodecs/vf.h"
22 #include "libmpcodecs/vd.h"
23 #include "mp_osd.h"
24 #include "libvo/video_out.h"
25 #include "libvo/font_load.h"
26 #include "playtree.h"
27 #include "libao2/audio_out.h"
28 #include "mpcommon.h"
29 #include "mixer.h"
30 #include "libmpcodecs/dec_video.h"
31 #include "libmpcodecs/dec_teletext.h"
32 #include "vobsub.h"
33 #include "spudec.h"
34 #include "get_path.h"
35 #include "ass_mp.h"
36 #include "stream/tv.h"
37 #include "stream/stream_radio.h"
38 #include "stream/pvr.h"
39 #ifdef CONFIG_DVBIN
40 #include "stream/dvbin.h"
41 #endif
42 #ifdef CONFIG_DVDREAD
43 #include "stream/stream_dvd.h"
44 #endif
45 #include "stream/stream_dvdnav.h"
46 #include "m_struct.h"
47 #include "libmenu/menu.h"
49 #include "mp_core.h"
50 #include "mp_fifo.h"
51 #include "libavutil/avstring.h"
53 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
55 extern int use_menu;
57 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
58 double *dx, double *dy)
60 struct MPOpts *opts = &mpctx->opts;
61 struct vo *vo = mpctx->video_out;
62 //remove the borders, if any, and rescale to the range [0,1],[0,1]
63 if (vo_fs) { //we are in full-screen mode
64 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
65 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
66 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
67 iy -= (opts->vo_screenheight - vo->dheight) / 2;
69 if (ix < 0 || ix > vo->dwidth) {
70 *dx = *dy = -1.0;
71 return;
72 } //we are on one of the borders
73 if (iy < 0 || iy > vo->dheight) {
74 *dx = *dy = -1.0;
75 return;
76 } //we are on one of the borders
79 *dx = (double) ix / (double) vo->dwidth;
80 *dy = (double) iy / (double) vo->dheight;
82 mp_msg(MSGT_CPLAYER, MSGL_V,
83 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
84 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
85 vo->dheight, vo_fs);
88 static int sub_source_by_pos(MPContext *mpctx, int pos)
90 int source = -1;
91 int top = -1;
92 int i;
93 for (i = 0; i < SUB_SOURCES; i++) {
94 int j = mpctx->global_sub_indices[i];
95 if ((j >= 0) && (j > top) && (pos >= j)) {
96 source = i;
97 top = j;
100 return source;
103 static int sub_source(MPContext *mpctx)
105 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
109 * \brief Log the currently displayed subtitle to a file
111 * Logs the current or last displayed subtitle together with filename
112 * and time information to ~/.mplayer/subtitle_log
114 * Intended purpose is to allow convenient marking of bogus subtitles
115 * which need to be fixed while watching the movie.
118 static void log_sub(struct MPContext *mpctx)
120 char *fname;
121 FILE *f;
122 int i;
124 if (subdata == NULL || vo_sub_last == NULL)
125 return;
126 fname = get_path("subtitle_log");
127 f = fopen(fname, "a");
128 if (!f)
129 return;
130 fprintf(f, "----------------------------------------------------------\n");
131 if (subdata->sub_uses_time) {
132 fprintf(f,
133 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
134 mpctx->filename, vo_sub_last->start / 360000,
135 (vo_sub_last->start / 6000) % 60,
136 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
137 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
138 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
139 } else {
140 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
141 vo_sub_last->start, vo_sub_last->end);
143 for (i = 0; i < vo_sub_last->lines; i++) {
144 fprintf(f, "%s\n", vo_sub_last->text[i]);
146 fclose(f);
150 /// \defgroup Properties
151 ///@{
153 /// \defgroup GeneralProperties General properties
154 /// \ingroup Properties
155 ///@{
157 /// OSD level (RW)
158 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
159 MPContext *mpctx)
161 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
164 /// Loop (RW)
165 static int mp_property_loop(m_option_t *prop, int action, void *arg,
166 MPContext *mpctx)
168 struct MPOpts *opts = &mpctx->opts;
169 switch (action) {
170 case M_PROPERTY_PRINT:
171 if (!arg) return M_PROPERTY_ERROR;
172 if (opts->loop_times < 0)
173 *(char**)arg = strdup("off");
174 else if (opts->loop_times == 0)
175 *(char**)arg = strdup("inf");
176 else
177 break;
178 return M_PROPERTY_OK;
180 return m_property_int_range(prop, action, arg, &opts->loop_times);
183 /// Playback speed (RW)
184 static int mp_property_playback_speed(m_option_t *prop, int action,
185 void *arg, MPContext *mpctx)
187 struct MPOpts *opts = &mpctx->opts;
188 switch (action) {
189 case M_PROPERTY_SET:
190 if (!arg)
191 return M_PROPERTY_ERROR;
192 M_PROPERTY_CLAMP(prop, *(float *) arg);
193 opts->playback_speed = *(float *) arg;
194 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
195 return M_PROPERTY_OK;
196 case M_PROPERTY_STEP_UP:
197 case M_PROPERTY_STEP_DOWN:
198 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
199 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
200 M_PROPERTY_CLAMP(prop, opts->playback_speed);
201 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
202 return M_PROPERTY_OK;
204 return m_property_float_range(prop, action, arg, &opts->playback_speed);
207 /// filename with path (RO)
208 static int mp_property_path(m_option_t *prop, int action, void *arg,
209 MPContext *mpctx)
211 return m_property_string_ro(prop, action, arg, mpctx->filename);
214 /// filename without path (RO)
215 static int mp_property_filename(m_option_t *prop, int action, void *arg,
216 MPContext *mpctx)
218 char *f;
219 if (!mpctx->filename)
220 return M_PROPERTY_UNAVAILABLE;
221 if (((f = strrchr(mpctx->filename, '/'))
222 || (f = strrchr(mpctx->filename, '\\'))) && f[1])
223 f++;
224 else
225 f = mpctx->filename;
226 return m_property_string_ro(prop, action, arg, f);
229 /// Demuxer name (RO)
230 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
231 MPContext *mpctx)
233 if (!mpctx->demuxer)
234 return M_PROPERTY_UNAVAILABLE;
235 return m_property_string_ro(prop, action, arg,
236 (char *) mpctx->demuxer->desc->name);
239 /// Position in the stream (RW)
240 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
241 MPContext *mpctx)
243 if (!mpctx->demuxer || !mpctx->demuxer->stream)
244 return M_PROPERTY_UNAVAILABLE;
245 if (!arg)
246 return M_PROPERTY_ERROR;
247 switch (action) {
248 case M_PROPERTY_GET:
249 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
250 return M_PROPERTY_OK;
251 case M_PROPERTY_SET:
252 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
253 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
254 return M_PROPERTY_OK;
256 return M_PROPERTY_NOT_IMPLEMENTED;
259 /// Stream start offset (RO)
260 static int mp_property_stream_start(m_option_t *prop, int action,
261 void *arg, MPContext *mpctx)
263 if (!mpctx->demuxer || !mpctx->demuxer->stream)
264 return M_PROPERTY_UNAVAILABLE;
265 switch (action) {
266 case M_PROPERTY_GET:
267 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
268 return M_PROPERTY_OK;
270 return M_PROPERTY_NOT_IMPLEMENTED;
273 /// Stream end offset (RO)
274 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
275 MPContext *mpctx)
277 if (!mpctx->demuxer || !mpctx->demuxer->stream)
278 return M_PROPERTY_UNAVAILABLE;
279 switch (action) {
280 case M_PROPERTY_GET:
281 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
282 return M_PROPERTY_OK;
284 return M_PROPERTY_NOT_IMPLEMENTED;
287 /// Stream length (RO)
288 static int mp_property_stream_length(m_option_t *prop, int action,
289 void *arg, MPContext *mpctx)
291 if (!mpctx->demuxer || !mpctx->demuxer->stream)
292 return M_PROPERTY_UNAVAILABLE;
293 switch (action) {
294 case M_PROPERTY_GET:
295 *(off_t *) arg =
296 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
297 return M_PROPERTY_OK;
299 return M_PROPERTY_NOT_IMPLEMENTED;
302 /// Media length in seconds (RO)
303 static int mp_property_length(m_option_t *prop, int action, void *arg,
304 MPContext *mpctx)
306 double len;
308 if (!mpctx->demuxer ||
309 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
310 return M_PROPERTY_UNAVAILABLE;
312 return m_property_time_ro(prop, action, arg, len);
315 /// Current position in percent (RW)
316 static int mp_property_percent_pos(m_option_t *prop, int action,
317 void *arg, MPContext *mpctx) {
318 int pos;
320 if (!mpctx->demuxer)
321 return M_PROPERTY_UNAVAILABLE;
323 switch(action) {
324 case M_PROPERTY_SET:
325 if(!arg) return M_PROPERTY_ERROR;
326 M_PROPERTY_CLAMP(prop, *(int*)arg);
327 pos = *(int*)arg;
328 break;
329 case M_PROPERTY_STEP_UP:
330 case M_PROPERTY_STEP_DOWN:
331 pos = demuxer_get_percent_pos(mpctx->demuxer);
332 pos += (arg ? *(int*)arg : 10) *
333 (action == M_PROPERTY_STEP_UP ? 1 : -1);
334 M_PROPERTY_CLAMP(prop, pos);
335 break;
336 default:
337 return m_property_int_ro(prop, action, arg,
338 demuxer_get_percent_pos(mpctx->demuxer));
341 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
342 mpctx->rel_seek_secs = pos / 100.0;
343 return M_PROPERTY_OK;
346 /// Current position in seconds (RW)
347 static int mp_property_time_pos(m_option_t *prop, int action,
348 void *arg, MPContext *mpctx) {
349 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
350 return M_PROPERTY_UNAVAILABLE;
352 switch(action) {
353 case M_PROPERTY_SET:
354 if(!arg) return M_PROPERTY_ERROR;
355 M_PROPERTY_CLAMP(prop, *(double*)arg);
356 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
357 mpctx->rel_seek_secs = *(double*)arg;
358 return M_PROPERTY_OK;
359 case M_PROPERTY_STEP_UP:
360 case M_PROPERTY_STEP_DOWN:
361 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
362 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
363 return M_PROPERTY_OK;
365 return m_property_time_ro(prop, action, arg,
366 mpctx->sh_video ? mpctx->sh_video->pts :
367 playing_audio_pts(mpctx));
370 /// Current chapter (RW)
371 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
372 MPContext *mpctx)
374 struct MPOpts *opts = &mpctx->opts;
375 int chapter = -1;
376 int step_all;
377 char *chapter_name = NULL;
379 if (mpctx->demuxer)
380 chapter = get_current_chapter(mpctx);
381 if (chapter < 0)
382 return M_PROPERTY_UNAVAILABLE;
384 switch (action) {
385 case M_PROPERTY_GET:
386 if (!arg)
387 return M_PROPERTY_ERROR;
388 *(int *) arg = chapter;
389 return M_PROPERTY_OK;
390 case M_PROPERTY_PRINT: {
391 if (!arg)
392 return M_PROPERTY_ERROR;
393 chapter_name = chapter_display_name(mpctx, chapter);
394 if (!chapter_name)
395 return M_PROPERTY_UNAVAILABLE;
396 *(char **) arg = chapter_name;
397 return M_PROPERTY_OK;
399 case M_PROPERTY_SET:
400 if (!arg)
401 return M_PROPERTY_ERROR;
402 M_PROPERTY_CLAMP(prop, *(int*)arg);
403 step_all = *(int *)arg - chapter;
404 chapter += step_all;
405 break;
406 case M_PROPERTY_STEP_UP:
407 case M_PROPERTY_STEP_DOWN: {
408 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
409 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
410 chapter += step_all;
411 if (chapter < 0)
412 chapter = 0;
413 break;
415 default:
416 return M_PROPERTY_NOT_IMPLEMENTED;
419 double next_pts = 0;
420 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
421 mpctx->rel_seek_secs = 0;
422 mpctx->abs_seek_pos = 0;
423 if (chapter >= 0) {
424 if (next_pts > -1.0) {
425 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
426 mpctx->rel_seek_secs = next_pts;
428 if (chapter_name)
429 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
430 _("Chapter: (%d) %s"), chapter + 1, chapter_name);
432 else if (step_all > 0)
433 mpctx->rel_seek_secs = 1000000000.;
434 else
435 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
436 _("Chapter: (%d) %s"), 0, _("unknown"));
437 if (chapter_name)
438 talloc_free(chapter_name);
439 return M_PROPERTY_OK;
442 /// Number of chapters in file
443 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
444 MPContext *mpctx)
446 if (!mpctx->demuxer)
447 return M_PROPERTY_UNAVAILABLE;
448 if (mpctx->demuxer->num_chapters == 0)
449 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
450 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
453 /// Current dvd angle (RW)
454 static int mp_property_angle(m_option_t *prop, int action, void *arg,
455 MPContext *mpctx)
457 struct MPOpts *opts = &mpctx->opts;
458 int angle = -1;
459 int angles;
460 char *angle_name = NULL;
462 if (mpctx->demuxer)
463 angle = demuxer_get_current_angle(mpctx->demuxer);
464 if (angle < 0)
465 return M_PROPERTY_UNAVAILABLE;
466 angles = demuxer_angles_count(mpctx->demuxer);
467 if (angles <= 1)
468 return M_PROPERTY_UNAVAILABLE;
470 switch (action) {
471 case M_PROPERTY_GET:
472 if (!arg)
473 return M_PROPERTY_ERROR;
474 *(int *) arg = angle;
475 return M_PROPERTY_OK;
476 case M_PROPERTY_PRINT: {
477 if (!arg)
478 return M_PROPERTY_ERROR;
479 angle_name = calloc(1, 64);
480 if (!angle_name)
481 return M_PROPERTY_UNAVAILABLE;
482 snprintf(angle_name, 64, "%d/%d", angle, angles);
483 *(char **) arg = angle_name;
484 return M_PROPERTY_OK;
486 case M_PROPERTY_SET:
487 if (!arg)
488 return M_PROPERTY_ERROR;
489 angle = *(int *)arg;
490 M_PROPERTY_CLAMP(prop, angle);
491 break;
492 case M_PROPERTY_STEP_UP:
493 case M_PROPERTY_STEP_DOWN: {
494 int step = 0;
495 if(arg)
496 step = *(int*)arg;
497 if(!step)
498 step = 1;
499 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
500 angle += step;
501 if (angle < 1) //cycle
502 angle = angles;
503 break;
505 default:
506 return M_PROPERTY_NOT_IMPLEMENTED;
508 angle = demuxer_set_angle(mpctx->demuxer, angle);
509 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
510 _("Angle: %d/%d"), angle, angles);
511 if (angle_name)
512 free(angle_name);
513 return M_PROPERTY_OK;
516 /// Demuxer meta data
517 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
518 MPContext *mpctx) {
519 m_property_action_t* ka;
520 char* meta;
521 static const m_option_t key_type =
522 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
523 if (!mpctx->demuxer)
524 return M_PROPERTY_UNAVAILABLE;
526 switch(action) {
527 case M_PROPERTY_GET:
528 if(!arg) return M_PROPERTY_ERROR;
529 *(char***)arg = mpctx->demuxer->info;
530 return M_PROPERTY_OK;
531 case M_PROPERTY_KEY_ACTION:
532 if(!arg) return M_PROPERTY_ERROR;
533 ka = arg;
534 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
535 return M_PROPERTY_UNKNOWN;
536 switch(ka->action) {
537 case M_PROPERTY_GET:
538 if(!ka->arg) return M_PROPERTY_ERROR;
539 *(char**)ka->arg = meta;
540 return M_PROPERTY_OK;
541 case M_PROPERTY_GET_TYPE:
542 if(!ka->arg) return M_PROPERTY_ERROR;
543 *(m_option_t**)ka->arg = &key_type;
544 return M_PROPERTY_OK;
547 return M_PROPERTY_NOT_IMPLEMENTED;
550 static int mp_property_pause(m_option_t *prop, int action, void *arg,
551 void *ctx)
553 MPContext *mpctx = ctx;
555 switch (action) {
556 case M_PROPERTY_SET:
557 if (!arg)
558 return M_PROPERTY_ERROR;
559 if (mpctx->paused == (bool)*(int *) arg)
560 return M_PROPERTY_OK;
561 case M_PROPERTY_STEP_UP:
562 case M_PROPERTY_STEP_DOWN:
563 if (mpctx->paused) {
564 unpause_player(mpctx);
565 mpctx->osd_function = OSD_PLAY;
567 else {
568 pause_player(mpctx);
569 mpctx->osd_function = OSD_PAUSE;
571 return M_PROPERTY_OK;
572 default:
573 return m_property_flag(prop, action, arg, &mpctx->paused);
578 ///@}
580 /// \defgroup AudioProperties Audio properties
581 /// \ingroup Properties
582 ///@{
584 /// Volume (RW)
585 static int mp_property_volume(m_option_t *prop, int action, void *arg,
586 MPContext *mpctx)
589 if (!mpctx->sh_audio)
590 return M_PROPERTY_UNAVAILABLE;
592 switch (action) {
593 case M_PROPERTY_GET:
594 if (!arg)
595 return M_PROPERTY_ERROR;
596 mixer_getbothvolume(&mpctx->mixer, arg);
597 return M_PROPERTY_OK;
598 case M_PROPERTY_PRINT:{
599 float vol;
600 if (!arg)
601 return M_PROPERTY_ERROR;
602 mixer_getbothvolume(&mpctx->mixer, &vol);
603 return m_property_float_range(prop, action, arg, &vol);
605 case M_PROPERTY_STEP_UP:
606 case M_PROPERTY_STEP_DOWN:
607 case M_PROPERTY_SET:
608 break;
609 default:
610 return M_PROPERTY_NOT_IMPLEMENTED;
613 if (mpctx->edl_muted)
614 return M_PROPERTY_DISABLED;
615 mpctx->user_muted = 0;
617 switch (action) {
618 case M_PROPERTY_SET:
619 if (!arg)
620 return M_PROPERTY_ERROR;
621 M_PROPERTY_CLAMP(prop, *(float *) arg);
622 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
623 return M_PROPERTY_OK;
624 case M_PROPERTY_STEP_UP:
625 if (arg && *(float *) arg <= 0)
626 mixer_decvolume(&mpctx->mixer);
627 else
628 mixer_incvolume(&mpctx->mixer);
629 return M_PROPERTY_OK;
630 case M_PROPERTY_STEP_DOWN:
631 if (arg && *(float *) arg <= 0)
632 mixer_incvolume(&mpctx->mixer);
633 else
634 mixer_decvolume(&mpctx->mixer);
635 return M_PROPERTY_OK;
637 return M_PROPERTY_NOT_IMPLEMENTED;
640 /// Mute (RW)
641 static int mp_property_mute(m_option_t *prop, int action, void *arg,
642 MPContext *mpctx)
645 if (!mpctx->sh_audio)
646 return M_PROPERTY_UNAVAILABLE;
648 switch (action) {
649 case M_PROPERTY_SET:
650 if (mpctx->edl_muted)
651 return M_PROPERTY_DISABLED;
652 if (!arg)
653 return M_PROPERTY_ERROR;
654 if ((!!*(int *) arg) != mpctx->mixer.muted)
655 mixer_mute(&mpctx->mixer);
656 mpctx->user_muted = mpctx->mixer.muted;
657 return M_PROPERTY_OK;
658 case M_PROPERTY_STEP_UP:
659 case M_PROPERTY_STEP_DOWN:
660 if (mpctx->edl_muted)
661 return M_PROPERTY_DISABLED;
662 mixer_mute(&mpctx->mixer);
663 mpctx->user_muted = mpctx->mixer.muted;
664 return M_PROPERTY_OK;
665 case M_PROPERTY_PRINT:
666 if (!arg)
667 return M_PROPERTY_ERROR;
668 if (mpctx->edl_muted) {
669 *(char **) arg = strdup(_("enabled (EDL)"));
670 return M_PROPERTY_OK;
672 default:
673 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
678 /// Audio delay (RW)
679 static int mp_property_audio_delay(m_option_t *prop, int action,
680 void *arg, MPContext *mpctx)
682 if (!(mpctx->sh_audio && mpctx->sh_video))
683 return M_PROPERTY_UNAVAILABLE;
684 switch (action) {
685 case M_PROPERTY_SET:
686 case M_PROPERTY_STEP_UP:
687 case M_PROPERTY_STEP_DOWN: {
688 int ret;
689 float delay = audio_delay;
690 ret = m_property_delay(prop, action, arg, &audio_delay);
691 if (ret != M_PROPERTY_OK)
692 return ret;
693 if (mpctx->sh_audio)
694 mpctx->delay -= audio_delay - delay;
696 return M_PROPERTY_OK;
697 default:
698 return m_property_delay(prop, action, arg, &audio_delay);
702 /// Audio codec tag (RO)
703 static int mp_property_audio_format(m_option_t *prop, int action,
704 void *arg, MPContext *mpctx)
706 if (!mpctx->sh_audio)
707 return M_PROPERTY_UNAVAILABLE;
708 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
711 /// Audio codec name (RO)
712 static int mp_property_audio_codec(m_option_t *prop, int action,
713 void *arg, MPContext *mpctx)
715 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
716 return M_PROPERTY_UNAVAILABLE;
717 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
720 /// Audio bitrate (RO)
721 static int mp_property_audio_bitrate(m_option_t *prop, int action,
722 void *arg, MPContext *mpctx)
724 if (!mpctx->sh_audio)
725 return M_PROPERTY_UNAVAILABLE;
726 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
729 /// Samplerate (RO)
730 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
731 MPContext *mpctx)
733 if (!mpctx->sh_audio)
734 return M_PROPERTY_UNAVAILABLE;
735 switch(action) {
736 case M_PROPERTY_PRINT:
737 if(!arg) return M_PROPERTY_ERROR;
738 *(char**)arg = malloc(16);
739 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
740 return M_PROPERTY_OK;
742 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
745 /// Number of channels (RO)
746 static int mp_property_channels(m_option_t *prop, int action, void *arg,
747 MPContext *mpctx)
749 if (!mpctx->sh_audio)
750 return M_PROPERTY_UNAVAILABLE;
751 switch (action) {
752 case M_PROPERTY_PRINT:
753 if (!arg)
754 return M_PROPERTY_ERROR;
755 switch (mpctx->sh_audio->channels) {
756 case 1:
757 *(char **) arg = strdup("mono");
758 break;
759 case 2:
760 *(char **) arg = strdup("stereo");
761 break;
762 default:
763 *(char **) arg = malloc(32);
764 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
766 return M_PROPERTY_OK;
768 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
771 /// Balance (RW)
772 static int mp_property_balance(m_option_t *prop, int action, void *arg,
773 MPContext *mpctx)
775 float bal;
777 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
778 return M_PROPERTY_UNAVAILABLE;
780 switch (action) {
781 case M_PROPERTY_GET:
782 if (!arg)
783 return M_PROPERTY_ERROR;
784 mixer_getbalance(&mpctx->mixer, arg);
785 return M_PROPERTY_OK;
786 case M_PROPERTY_PRINT: {
787 char** str = arg;
788 if (!arg)
789 return M_PROPERTY_ERROR;
790 mixer_getbalance(&mpctx->mixer, &bal);
791 if (bal == 0.f)
792 *str = strdup("center");
793 else if (bal == -1.f)
794 *str = strdup("left only");
795 else if (bal == 1.f)
796 *str = strdup("right only");
797 else {
798 unsigned right = (bal + 1.f) / 2.f * 100.f;
799 *str = malloc(sizeof("left xxx%, right xxx%"));
800 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
802 return M_PROPERTY_OK;
804 case M_PROPERTY_STEP_UP:
805 case M_PROPERTY_STEP_DOWN:
806 mixer_getbalance(&mpctx->mixer, &bal);
807 bal += (arg ? *(float*)arg : .1f) *
808 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
809 M_PROPERTY_CLAMP(prop, bal);
810 mixer_setbalance(&mpctx->mixer, bal);
811 return M_PROPERTY_OK;
812 case M_PROPERTY_SET:
813 if (!arg)
814 return M_PROPERTY_ERROR;
815 M_PROPERTY_CLAMP(prop, *(float*)arg);
816 mixer_setbalance(&mpctx->mixer, *(float*)arg);
817 return M_PROPERTY_OK;
819 return M_PROPERTY_NOT_IMPLEMENTED;
822 /// Selected audio id (RW)
823 static int mp_property_audio(m_option_t *prop, int action, void *arg,
824 MPContext *mpctx)
826 struct MPOpts *opts = &mpctx->opts;
827 int current_id = -1, tmp;
829 switch (action) {
830 case M_PROPERTY_GET:
831 if (!mpctx->sh_audio)
832 return M_PROPERTY_UNAVAILABLE;
833 if (!arg)
834 return M_PROPERTY_ERROR;
835 *(int *) arg = opts->audio_id;
836 return M_PROPERTY_OK;
837 case M_PROPERTY_PRINT:
838 if (!mpctx->sh_audio)
839 return M_PROPERTY_UNAVAILABLE;
840 if (!arg)
841 return M_PROPERTY_ERROR;
843 if (opts->audio_id < 0)
844 *(char **) arg = strdup(_("disabled"));
845 else {
846 char lang[40] = _("unknown");
847 sh_audio_t* sh = mpctx->sh_audio;
848 if (sh && sh->lang)
849 av_strlcpy(lang, sh->lang, 40);
850 #ifdef CONFIG_DVDREAD
851 else if (mpctx->stream->type == STREAMTYPE_DVD) {
852 int code = dvd_lang_from_aid(mpctx->stream, opts->audio_id);
853 if (code) {
854 lang[0] = code >> 8;
855 lang[1] = code;
856 lang[2] = 0;
859 #endif
861 #ifdef CONFIG_DVDNAV
862 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
863 mp_dvdnav_lang_from_aid(mpctx->stream, opts->audio_id, lang);
864 #endif
865 *(char **) arg = malloc(64);
866 snprintf(*(char **) arg, 64, "(%d) %s", opts->audio_id, lang);
868 return M_PROPERTY_OK;
870 case M_PROPERTY_STEP_UP:
871 case M_PROPERTY_SET:
872 if (!mpctx->demuxer)
873 return M_PROPERTY_UNAVAILABLE;
874 if (action == M_PROPERTY_SET && arg)
875 tmp = *((int *) arg);
876 else
877 tmp = -1;
878 current_id = mpctx->demuxer->audio->id;
879 opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
880 if (opts->audio_id == -2
881 || (opts->audio_id > -1
882 && mpctx->demuxer->audio->id != current_id && current_id != -2))
883 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
884 if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
885 sh_audio_t *sh2;
886 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
887 if (sh2) {
888 sh2->ds = mpctx->demuxer->audio;
889 mpctx->sh_audio = sh2;
890 reinit_audio_chain(mpctx);
893 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id);
894 return M_PROPERTY_OK;
895 default:
896 return M_PROPERTY_NOT_IMPLEMENTED;
901 /// Selected video id (RW)
902 static int mp_property_video(m_option_t *prop, int action, void *arg,
903 MPContext *mpctx)
905 struct MPOpts *opts = &mpctx->opts;
906 int current_id = -1, tmp;
908 switch (action) {
909 case M_PROPERTY_GET:
910 if (!mpctx->sh_video)
911 return M_PROPERTY_UNAVAILABLE;
912 if (!arg)
913 return M_PROPERTY_ERROR;
914 *(int *) arg = opts->video_id;
915 return M_PROPERTY_OK;
916 case M_PROPERTY_PRINT:
917 if (!mpctx->sh_video)
918 return M_PROPERTY_UNAVAILABLE;
919 if (!arg)
920 return M_PROPERTY_ERROR;
922 if (opts->video_id < 0)
923 *(char **) arg = strdup(_("disabled"));
924 else {
925 char lang[40] = _("unknown");
926 *(char **) arg = malloc(64);
927 snprintf(*(char **) arg, 64, "(%d) %s", opts->video_id, lang);
929 return M_PROPERTY_OK;
931 case M_PROPERTY_STEP_UP:
932 case M_PROPERTY_SET:
933 current_id = mpctx->demuxer->video->id;
934 if (action == M_PROPERTY_SET && arg)
935 tmp = *((int *) arg);
936 else
937 tmp = -1;
938 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
939 if (opts->video_id == -2
940 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
941 && current_id != -2))
942 uninit_player(mpctx, INITIALIZED_VCODEC |
943 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
944 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
945 sh_video_t *sh2;
946 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
947 if (sh2) {
948 sh2->ds = mpctx->demuxer->video;
949 mpctx->sh_video = sh2;
950 reinit_video_chain(mpctx);
953 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
954 return M_PROPERTY_OK;
956 default:
957 return M_PROPERTY_NOT_IMPLEMENTED;
961 static int mp_property_program(m_option_t *prop, int action, void *arg,
962 MPContext *mpctx)
964 demux_program_t prog;
966 switch (action) {
967 case M_PROPERTY_STEP_UP:
968 case M_PROPERTY_SET:
969 if (action == M_PROPERTY_SET && arg)
970 prog.progid = *((int *) arg);
971 else
972 prog.progid = -1;
973 if (demux_control
974 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
975 &prog) == DEMUXER_CTRL_NOTIMPL)
976 return M_PROPERTY_ERROR;
978 if (prog.aid < 0 && prog.vid < 0) {
979 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
980 return M_PROPERTY_ERROR;
982 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
983 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
984 return M_PROPERTY_OK;
986 default:
987 return M_PROPERTY_NOT_IMPLEMENTED;
991 ///@}
993 /// \defgroup VideoProperties Video properties
994 /// \ingroup Properties
995 ///@{
997 /// Fullscreen state (RW)
998 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
999 MPContext *mpctx)
1002 if (!mpctx->video_out)
1003 return M_PROPERTY_UNAVAILABLE;
1005 switch (action) {
1006 case M_PROPERTY_SET:
1007 if (!arg)
1008 return M_PROPERTY_ERROR;
1009 M_PROPERTY_CLAMP(prop, *(int *) arg);
1010 if (vo_fs == !!*(int *) arg)
1011 return M_PROPERTY_OK;
1012 case M_PROPERTY_STEP_UP:
1013 case M_PROPERTY_STEP_DOWN:
1014 if (mpctx->video_out->config_ok)
1015 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1016 mpctx->opts.fullscreen = vo_fs;
1017 return M_PROPERTY_OK;
1018 default:
1019 return m_property_flag(prop, action, arg, &vo_fs);
1023 static int mp_property_deinterlace(m_option_t *prop, int action,
1024 void *arg, MPContext *mpctx)
1026 int deinterlace;
1027 vf_instance_t *vf;
1028 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1029 return M_PROPERTY_UNAVAILABLE;
1030 vf = mpctx->sh_video->vfilter;
1031 switch (action) {
1032 case M_PROPERTY_GET:
1033 if (!arg)
1034 return M_PROPERTY_ERROR;
1035 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1036 return M_PROPERTY_OK;
1037 case M_PROPERTY_SET:
1038 if (!arg)
1039 return M_PROPERTY_ERROR;
1040 M_PROPERTY_CLAMP(prop, *(int *) arg);
1041 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1042 return M_PROPERTY_OK;
1043 case M_PROPERTY_STEP_UP:
1044 case M_PROPERTY_STEP_DOWN:
1045 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1046 deinterlace = !deinterlace;
1047 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1048 return M_PROPERTY_OK;
1050 int value = 0;
1051 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1052 return m_property_flag_ro(prop, action, arg, value);
1055 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1056 void *arg, MPContext *mpctx)
1058 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1059 return M_PROPERTY_UNAVAILABLE;
1061 struct vf_instance *vf = mpctx->sh_video->vfilter;
1062 int colorspace;
1063 switch (action) {
1064 case M_PROPERTY_GET:
1065 if (!arg)
1066 return M_PROPERTY_ERROR;
1067 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1068 return M_PROPERTY_UNAVAILABLE;
1069 return M_PROPERTY_OK;
1070 case M_PROPERTY_PRINT:
1071 if (!arg)
1072 return M_PROPERTY_ERROR;
1073 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1074 return M_PROPERTY_UNAVAILABLE;
1075 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1076 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1077 *(char **)arg = strdup("Unknown");
1078 else
1079 *(char**)arg = strdup(names[colorspace]);
1080 return M_PROPERTY_OK;
1081 case M_PROPERTY_SET:
1082 if (!arg)
1083 return M_PROPERTY_ERROR;
1084 M_PROPERTY_CLAMP(prop, *(int *) arg);
1085 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1086 return M_PROPERTY_OK;
1087 case M_PROPERTY_STEP_UP:;
1088 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1089 return M_PROPERTY_UNAVAILABLE;
1090 colorspace += 1;
1091 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1092 return M_PROPERTY_OK;
1094 return M_PROPERTY_NOT_IMPLEMENTED;
1097 /// Panscan (RW)
1098 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1099 MPContext *mpctx)
1102 if (!mpctx->video_out
1103 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1104 return M_PROPERTY_UNAVAILABLE;
1106 switch (action) {
1107 case M_PROPERTY_SET:
1108 if (!arg)
1109 return M_PROPERTY_ERROR;
1110 M_PROPERTY_CLAMP(prop, *(float *) arg);
1111 vo_panscan = *(float *) arg;
1112 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1113 return M_PROPERTY_OK;
1114 case M_PROPERTY_STEP_UP:
1115 case M_PROPERTY_STEP_DOWN:
1116 vo_panscan += (arg ? *(float *) arg : 0.1) *
1117 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1118 if (vo_panscan > 1)
1119 vo_panscan = 1;
1120 else if (vo_panscan < 0)
1121 vo_panscan = 0;
1122 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1123 return M_PROPERTY_OK;
1124 default:
1125 return m_property_float_range(prop, action, arg, &vo_panscan);
1129 /// Helper to set vo flags.
1130 /** \ingroup PropertyImplHelper
1132 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1133 int vo_ctrl, int *vo_var, MPContext *mpctx)
1136 if (!mpctx->video_out)
1137 return M_PROPERTY_UNAVAILABLE;
1139 switch (action) {
1140 case M_PROPERTY_SET:
1141 if (!arg)
1142 return M_PROPERTY_ERROR;
1143 M_PROPERTY_CLAMP(prop, *(int *) arg);
1144 if (*vo_var == !!*(int *) arg)
1145 return M_PROPERTY_OK;
1146 case M_PROPERTY_STEP_UP:
1147 case M_PROPERTY_STEP_DOWN:
1148 if (mpctx->video_out->config_ok)
1149 vo_control(mpctx->video_out, vo_ctrl, 0);
1150 return M_PROPERTY_OK;
1151 default:
1152 return m_property_flag(prop, action, arg, vo_var);
1156 /// Window always on top (RW)
1157 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1158 MPContext *mpctx)
1160 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1161 &mpctx->opts.vo_ontop, mpctx);
1164 /// Display in the root window (RW)
1165 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1166 MPContext *mpctx)
1168 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1169 &vo_rootwin, mpctx);
1172 /// Show window borders (RW)
1173 static int mp_property_border(m_option_t *prop, int action, void *arg,
1174 MPContext *mpctx)
1176 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1177 &vo_border, mpctx);
1180 /// Framedropping state (RW)
1181 static int mp_property_framedropping(m_option_t *prop, int action,
1182 void *arg, MPContext *mpctx)
1185 if (!mpctx->sh_video)
1186 return M_PROPERTY_UNAVAILABLE;
1188 switch (action) {
1189 case M_PROPERTY_PRINT:
1190 if (!arg)
1191 return M_PROPERTY_ERROR;
1192 *(char **) arg = strdup(frame_dropping == 1 ? _("enabled") :
1193 (frame_dropping == 2 ? _("hard") :
1194 _("disabled")));
1195 return M_PROPERTY_OK;
1196 default:
1197 return m_property_choice(prop, action, arg, &frame_dropping);
1201 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1202 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1203 MPContext *mpctx)
1205 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1206 int r, val;
1208 if (!mpctx->sh_video)
1209 return M_PROPERTY_UNAVAILABLE;
1211 if (gamma[0] == 1000) {
1212 gamma[0] = 0;
1213 get_video_colors(mpctx->sh_video, prop->name, gamma);
1216 switch (action) {
1217 case M_PROPERTY_SET:
1218 if (!arg)
1219 return M_PROPERTY_ERROR;
1220 M_PROPERTY_CLAMP(prop, *(int *) arg);
1221 *gamma = *(int *) arg;
1222 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1223 if (r <= 0)
1224 break;
1225 return r;
1226 case M_PROPERTY_GET:
1227 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1228 if (!arg)
1229 return M_PROPERTY_ERROR;
1230 *(int *)arg = val;
1231 return M_PROPERTY_OK;
1233 break;
1234 case M_PROPERTY_STEP_UP:
1235 case M_PROPERTY_STEP_DOWN:
1236 *gamma += (arg ? *(int *) arg : 1) *
1237 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1238 M_PROPERTY_CLAMP(prop, *gamma);
1239 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1240 if (r <= 0)
1241 break;
1242 return r;
1243 default:
1244 return M_PROPERTY_NOT_IMPLEMENTED;
1247 #ifdef CONFIG_TV
1248 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1249 int l = strlen(prop->name);
1250 char tv_prop[3 + l + 1];
1251 sprintf(tv_prop, "tv_%s", prop->name);
1252 return mp_property_do(tv_prop, action, arg, mpctx);
1254 #endif
1256 return M_PROPERTY_UNAVAILABLE;
1259 /// VSync (RW)
1260 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1261 MPContext *mpctx)
1263 return m_property_flag(prop, action, arg, &vo_vsync);
1266 /// Video codec tag (RO)
1267 static int mp_property_video_format(m_option_t *prop, int action,
1268 void *arg, MPContext *mpctx)
1270 char* meta;
1271 if (!mpctx->sh_video)
1272 return M_PROPERTY_UNAVAILABLE;
1273 switch(action) {
1274 case M_PROPERTY_PRINT:
1275 if (!arg)
1276 return M_PROPERTY_ERROR;
1277 switch(mpctx->sh_video->format) {
1278 case 0x10000001:
1279 meta = strdup ("mpeg1"); break;
1280 case 0x10000002:
1281 meta = strdup ("mpeg2"); break;
1282 case 0x10000004:
1283 meta = strdup ("mpeg4"); break;
1284 case 0x10000005:
1285 meta = strdup ("h264"); break;
1286 default:
1287 if(mpctx->sh_video->format >= 0x20202020) {
1288 meta = malloc(5);
1289 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1290 } else {
1291 meta = malloc(20);
1292 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1295 *(char**)arg = meta;
1296 return M_PROPERTY_OK;
1298 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1301 /// Video codec name (RO)
1302 static int mp_property_video_codec(m_option_t *prop, int action,
1303 void *arg, MPContext *mpctx)
1305 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1306 return M_PROPERTY_UNAVAILABLE;
1307 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1311 /// Video bitrate (RO)
1312 static int mp_property_video_bitrate(m_option_t *prop, int action,
1313 void *arg, MPContext *mpctx)
1315 if (!mpctx->sh_video)
1316 return M_PROPERTY_UNAVAILABLE;
1317 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1320 /// Video display width (RO)
1321 static int mp_property_width(m_option_t *prop, int action, void *arg,
1322 MPContext *mpctx)
1324 if (!mpctx->sh_video)
1325 return M_PROPERTY_UNAVAILABLE;
1326 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1329 /// Video display height (RO)
1330 static int mp_property_height(m_option_t *prop, int action, void *arg,
1331 MPContext *mpctx)
1333 if (!mpctx->sh_video)
1334 return M_PROPERTY_UNAVAILABLE;
1335 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1338 /// Video fps (RO)
1339 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1340 MPContext *mpctx)
1342 if (!mpctx->sh_video)
1343 return M_PROPERTY_UNAVAILABLE;
1344 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1347 /// Video aspect (RO)
1348 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1349 MPContext *mpctx)
1351 if (!mpctx->sh_video)
1352 return M_PROPERTY_UNAVAILABLE;
1353 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1356 ///@}
1358 /// \defgroup SubProprties Subtitles properties
1359 /// \ingroup Properties
1360 ///@{
1362 /// Text subtitle position (RW)
1363 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1364 MPContext *mpctx)
1366 if (!mpctx->sh_video)
1367 return M_PROPERTY_UNAVAILABLE;
1369 switch (action) {
1370 case M_PROPERTY_SET:
1371 if (!arg)
1372 return M_PROPERTY_ERROR;
1373 case M_PROPERTY_STEP_UP:
1374 case M_PROPERTY_STEP_DOWN:
1375 vo_osd_changed(OSDTYPE_SUBTITLE);
1376 default:
1377 return m_property_int_range(prop, action, arg, &sub_pos);
1381 /// Selected subtitles (RW)
1382 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1383 MPContext *mpctx)
1385 struct MPOpts *opts = &mpctx->opts;
1386 demux_stream_t *const d_sub = mpctx->d_sub;
1387 const int global_sub_size = mpctx->global_sub_size;
1388 int source = -1, reset_spu = 0;
1389 char *sub_name;
1391 if (global_sub_size <= 0)
1392 return M_PROPERTY_UNAVAILABLE;
1394 switch (action) {
1395 case M_PROPERTY_GET:
1396 if (!arg)
1397 return M_PROPERTY_ERROR;
1398 *(int *) arg = mpctx->global_sub_pos;
1399 return M_PROPERTY_OK;
1400 case M_PROPERTY_PRINT:
1401 if (!arg)
1402 return M_PROPERTY_ERROR;
1403 *(char **) arg = malloc(64);
1404 (*(char **) arg)[63] = 0;
1405 sub_name = 0;
1406 if (subdata)
1407 sub_name = subdata->filename;
1408 #ifdef CONFIG_ASS
1409 if (ass_track && ass_track->name)
1410 sub_name = ass_track->name;
1411 #endif
1412 if (sub_name) {
1413 char *tmp, *tmp2;
1414 tmp = sub_name;
1415 if ((tmp2 = strrchr(tmp, '/')))
1416 tmp = tmp2 + 1;
1418 snprintf(*(char **) arg, 63, "(%d) %s%s",
1419 mpctx->set_of_sub_pos + 1,
1420 strlen(tmp) < 20 ? "" : "...",
1421 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1422 return M_PROPERTY_OK;
1424 #ifdef CONFIG_DVDNAV
1425 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1426 if (vo_spudec && opts->sub_id >= 0) {
1427 unsigned char lang[3];
1428 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1429 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1430 return M_PROPERTY_OK;
1434 #endif
1436 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1437 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1438 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1439 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1440 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1441 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1442 if (!lang) lang = _("unknown");
1443 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1444 return M_PROPERTY_OK;
1447 if (vo_vobsub && vobsub_id >= 0) {
1448 const char *language = _("unknown");
1449 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1450 snprintf(*(char **) arg, 63, "(%d) %s",
1451 vobsub_id, language ? language : _("unknown"));
1452 return M_PROPERTY_OK;
1454 #ifdef CONFIG_DVDREAD
1455 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1456 && opts->sub_id >= 0) {
1457 char lang[3];
1458 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1459 lang[0] = code >> 8;
1460 lang[1] = code;
1461 lang[2] = 0;
1462 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1463 return M_PROPERTY_OK;
1465 #endif
1466 if (opts->sub_id >= 0) {
1467 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, _("unknown"));
1468 return M_PROPERTY_OK;
1470 snprintf(*(char **) arg, 63, _("disabled"));
1471 return M_PROPERTY_OK;
1473 case M_PROPERTY_SET:
1474 if (!arg)
1475 return M_PROPERTY_ERROR;
1476 if (*(int *) arg < -1)
1477 *(int *) arg = -1;
1478 else if (*(int *) arg >= global_sub_size)
1479 *(int *) arg = global_sub_size - 1;
1480 mpctx->global_sub_pos = *(int *) arg;
1481 break;
1482 case M_PROPERTY_STEP_UP:
1483 mpctx->global_sub_pos += 2;
1484 mpctx->global_sub_pos =
1485 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1486 break;
1487 case M_PROPERTY_STEP_DOWN:
1488 mpctx->global_sub_pos += global_sub_size + 1;
1489 mpctx->global_sub_pos =
1490 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1491 break;
1492 default:
1493 return M_PROPERTY_NOT_IMPLEMENTED;
1496 if (mpctx->global_sub_pos >= 0)
1497 source = sub_source(mpctx);
1499 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1500 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1501 global_sub_size,
1502 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1503 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1504 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1505 mpctx->global_sub_pos, source);
1507 mpctx->set_of_sub_pos = -1;
1508 subdata = NULL;
1510 vobsub_id = -1;
1511 opts->sub_id = -1;
1512 if (d_sub) {
1513 if (d_sub->id > -2)
1514 reset_spu = 1;
1515 d_sub->id = -2;
1517 #ifdef CONFIG_ASS
1518 ass_track = 0;
1519 #endif
1521 if (source == SUB_SOURCE_VOBSUB) {
1522 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1523 } else if (source == SUB_SOURCE_SUBS) {
1524 mpctx->set_of_sub_pos =
1525 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1526 #ifdef CONFIG_ASS
1527 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1528 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1529 else
1530 #endif
1532 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1533 vo_osd_changed(OSDTYPE_SUBTITLE);
1535 } else if (source == SUB_SOURCE_DEMUX) {
1536 opts->sub_id =
1537 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1538 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1539 int i = 0;
1540 // default: assume 1:1 mapping of sid and stream id
1541 d_sub->id = opts->sub_id;
1542 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1543 ds_free_packs(d_sub);
1544 for (i = 0; i < MAX_S_STREAMS; i++) {
1545 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1546 if (sh && sh->sid == opts->sub_id) {
1547 d_sub->id = i;
1548 d_sub->sh = sh;
1549 break;
1552 if (d_sub->sh && d_sub->id >= 0) {
1553 sh_sub_t *sh = d_sub->sh;
1554 if (sh->type == 'v')
1555 init_vo_spudec(mpctx);
1556 #ifdef CONFIG_ASS
1557 else if (ass_enabled)
1558 ass_track = sh->ass_track;
1559 #endif
1560 } else {
1561 d_sub->id = -2;
1562 d_sub->sh = NULL;
1566 #ifdef CONFIG_DVDREAD
1567 if (vo_spudec
1568 && (mpctx->stream->type == STREAMTYPE_DVD
1569 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1570 && opts->sub_id < 0 && reset_spu) {
1571 d_sub->id = -2;
1572 d_sub->sh = NULL;
1574 #endif
1576 update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, 0, 0, d_sub, 1);
1578 return M_PROPERTY_OK;
1581 /// Selected sub source (RW)
1582 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1583 MPContext *mpctx)
1585 int source;
1586 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1587 return M_PROPERTY_UNAVAILABLE;
1589 switch (action) {
1590 case M_PROPERTY_GET:
1591 if (!arg)
1592 return M_PROPERTY_ERROR;
1593 *(int *) arg = sub_source(mpctx);
1594 return M_PROPERTY_OK;
1595 case M_PROPERTY_PRINT:
1596 if (!arg)
1597 return M_PROPERTY_ERROR;
1598 *(char **) arg = malloc(64);
1599 (*(char **) arg)[63] = 0;
1600 switch (sub_source(mpctx))
1602 case SUB_SOURCE_SUBS:
1603 snprintf(*(char **) arg, 63, _("file"));
1604 break;
1605 case SUB_SOURCE_VOBSUB:
1606 snprintf(*(char **) arg, 63, _("vobsub"));
1607 break;
1608 case SUB_SOURCE_DEMUX:
1609 snprintf(*(char **) arg, 63, _("embedded"));
1610 break;
1611 default:
1612 snprintf(*(char **) arg, 63, _("disabled"));
1614 return M_PROPERTY_OK;
1615 case M_PROPERTY_SET:
1616 if (!arg)
1617 return M_PROPERTY_ERROR;
1618 M_PROPERTY_CLAMP(prop, *(int*)arg);
1619 if (*(int *) arg < 0)
1620 mpctx->global_sub_pos = -1;
1621 else if (*(int *) arg != sub_source(mpctx)) {
1622 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1623 return M_PROPERTY_UNAVAILABLE;
1624 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1626 break;
1627 case M_PROPERTY_STEP_UP:
1628 case M_PROPERTY_STEP_DOWN: {
1629 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1630 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1631 int step = (step_all > 0) ? 1 : -1;
1632 int cur_source = sub_source(mpctx);
1633 source = cur_source;
1634 while (step_all) {
1635 source += step;
1636 if (source >= SUB_SOURCES)
1637 source = -1;
1638 else if (source < -1)
1639 source = SUB_SOURCES - 1;
1640 if (source == cur_source || source == -1 ||
1641 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1642 step_all -= step;
1644 if (source == cur_source)
1645 return M_PROPERTY_OK;
1646 if (source == -1)
1647 mpctx->global_sub_pos = -1;
1648 else
1649 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1650 break;
1652 default:
1653 return M_PROPERTY_NOT_IMPLEMENTED;
1655 --mpctx->global_sub_pos;
1656 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1659 /// Selected subtitles from specific source (RW)
1660 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1661 MPContext *mpctx)
1663 int source, is_cur_source, offset;
1664 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1665 return M_PROPERTY_UNAVAILABLE;
1667 if (!strcmp(prop->name, "sub_file"))
1668 source = SUB_SOURCE_SUBS;
1669 else if (!strcmp(prop->name, "sub_vob"))
1670 source = SUB_SOURCE_VOBSUB;
1671 else if (!strcmp(prop->name, "sub_demux"))
1672 source = SUB_SOURCE_DEMUX;
1673 else
1674 return M_PROPERTY_ERROR;
1676 offset = mpctx->global_sub_indices[source];
1677 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1678 return M_PROPERTY_UNAVAILABLE;
1680 is_cur_source = sub_source(mpctx) == source;
1681 switch (action) {
1682 case M_PROPERTY_GET:
1683 if (!arg)
1684 return M_PROPERTY_ERROR;
1685 if (is_cur_source) {
1686 *(int *) arg = mpctx->global_sub_pos - offset;
1687 if (source == SUB_SOURCE_VOBSUB)
1688 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1690 else
1691 *(int *) arg = -1;
1692 return M_PROPERTY_OK;
1693 case M_PROPERTY_PRINT:
1694 if (!arg)
1695 return M_PROPERTY_ERROR;
1696 if (is_cur_source)
1697 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1698 *(char **) arg = malloc(64);
1699 (*(char **) arg)[63] = 0;
1700 snprintf(*(char **) arg, 63, _("disabled"));
1701 return M_PROPERTY_OK;
1702 case M_PROPERTY_SET:
1703 if (!arg)
1704 return M_PROPERTY_ERROR;
1705 if (*(int *) arg >= 0) {
1706 int index = *(int *)arg;
1707 if (source == SUB_SOURCE_VOBSUB)
1708 index = vobsub_get_index_by_id(vo_vobsub, index);
1709 mpctx->global_sub_pos = offset + index;
1710 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1711 || sub_source(mpctx) != source) {
1712 mpctx->global_sub_pos = -1;
1713 *(int *) arg = -1;
1716 else
1717 mpctx->global_sub_pos = -1;
1718 break;
1719 case M_PROPERTY_STEP_UP:
1720 case M_PROPERTY_STEP_DOWN: {
1721 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1722 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1723 int step = (step_all > 0) ? 1 : -1;
1724 int max_sub_pos_for_source = -1;
1725 if (!is_cur_source)
1726 mpctx->global_sub_pos = -1;
1727 while (step_all) {
1728 if (mpctx->global_sub_pos == -1) {
1729 if (step > 0)
1730 mpctx->global_sub_pos = offset;
1731 else if (max_sub_pos_for_source == -1) {
1732 // Find max pos for specific source
1733 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1734 while (mpctx->global_sub_pos >= 0
1735 && sub_source(mpctx) != source)
1736 --mpctx->global_sub_pos;
1738 else
1739 mpctx->global_sub_pos = max_sub_pos_for_source;
1741 else {
1742 mpctx->global_sub_pos += step;
1743 if (mpctx->global_sub_pos < offset ||
1744 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1745 sub_source(mpctx) != source)
1746 mpctx->global_sub_pos = -1;
1748 step_all -= step;
1750 break;
1752 default:
1753 return M_PROPERTY_NOT_IMPLEMENTED;
1755 --mpctx->global_sub_pos;
1756 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1759 /// Subtitle delay (RW)
1760 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1761 MPContext *mpctx)
1763 if (!mpctx->sh_video)
1764 return M_PROPERTY_UNAVAILABLE;
1765 return m_property_delay(prop, action, arg, &sub_delay);
1768 /// Alignment of text subtitles (RW)
1769 static int mp_property_sub_alignment(m_option_t *prop, int action,
1770 void *arg, MPContext *mpctx)
1772 char *name[] = { _("top"), _("center"), _("bottom") };
1774 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1775 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1776 return M_PROPERTY_UNAVAILABLE;
1778 switch (action) {
1779 case M_PROPERTY_PRINT:
1780 if (!arg)
1781 return M_PROPERTY_ERROR;
1782 M_PROPERTY_CLAMP(prop, sub_alignment);
1783 *(char **) arg = strdup(name[sub_alignment]);
1784 return M_PROPERTY_OK;
1785 case M_PROPERTY_SET:
1786 if (!arg)
1787 return M_PROPERTY_ERROR;
1788 case M_PROPERTY_STEP_UP:
1789 case M_PROPERTY_STEP_DOWN:
1790 vo_osd_changed(OSDTYPE_SUBTITLE);
1791 default:
1792 return m_property_choice(prop, action, arg, &sub_alignment);
1796 /// Subtitle visibility (RW)
1797 static int mp_property_sub_visibility(m_option_t *prop, int action,
1798 void *arg, MPContext *mpctx)
1800 if (!mpctx->sh_video)
1801 return M_PROPERTY_UNAVAILABLE;
1803 switch (action) {
1804 case M_PROPERTY_SET:
1805 if (!arg)
1806 return M_PROPERTY_ERROR;
1807 case M_PROPERTY_STEP_UP:
1808 case M_PROPERTY_STEP_DOWN:
1809 vo_osd_changed(OSDTYPE_SUBTITLE);
1810 if (vo_spudec)
1811 vo_osd_changed(OSDTYPE_SPU);
1812 default:
1813 return m_property_flag(prop, action, arg, &sub_visibility);
1817 #ifdef CONFIG_ASS
1818 /// Use margins for libass subtitles (RW)
1819 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1820 void *arg, MPContext *mpctx)
1822 if (!mpctx->sh_video)
1823 return M_PROPERTY_UNAVAILABLE;
1825 switch (action) {
1826 case M_PROPERTY_SET:
1827 if (!arg)
1828 return M_PROPERTY_ERROR;
1829 case M_PROPERTY_STEP_UP:
1830 case M_PROPERTY_STEP_DOWN:
1831 ass_force_reload = 1;
1832 default:
1833 return m_property_flag(prop, action, arg, &ass_use_margins);
1836 #endif
1838 /// Show only forced subtitles (RW)
1839 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1840 void *arg, MPContext *mpctx)
1842 if (!vo_spudec)
1843 return M_PROPERTY_UNAVAILABLE;
1845 switch (action) {
1846 case M_PROPERTY_SET:
1847 if (!arg)
1848 return M_PROPERTY_ERROR;
1849 case M_PROPERTY_STEP_UP:
1850 case M_PROPERTY_STEP_DOWN:
1851 m_property_flag(prop, action, arg, &forced_subs_only);
1852 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1853 return M_PROPERTY_OK;
1854 default:
1855 return m_property_flag(prop, action, arg, &forced_subs_only);
1860 #ifdef CONFIG_FREETYPE
1861 /// Subtitle scale (RW)
1862 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1863 MPContext *mpctx)
1866 switch (action) {
1867 case M_PROPERTY_SET:
1868 if (!arg)
1869 return M_PROPERTY_ERROR;
1870 M_PROPERTY_CLAMP(prop, *(float *) arg);
1871 #ifdef CONFIG_ASS
1872 if (ass_enabled) {
1873 ass_font_scale = *(float *) arg;
1874 ass_force_reload = 1;
1876 #endif
1877 text_font_scale_factor = *(float *) arg;
1878 force_load_font = 1;
1879 return M_PROPERTY_OK;
1880 case M_PROPERTY_STEP_UP:
1881 case M_PROPERTY_STEP_DOWN:
1882 #ifdef CONFIG_ASS
1883 if (ass_enabled) {
1884 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1885 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1886 M_PROPERTY_CLAMP(prop, ass_font_scale);
1887 ass_force_reload = 1;
1889 #endif
1890 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1891 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1892 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1893 force_load_font = 1;
1894 return M_PROPERTY_OK;
1895 default:
1896 #ifdef CONFIG_ASS
1897 if (ass_enabled)
1898 return m_property_float_ro(prop, action, arg, ass_font_scale);
1899 else
1900 #endif
1901 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1904 #endif
1906 ///@}
1908 /// \defgroup TVProperties TV properties
1909 /// \ingroup Properties
1910 ///@{
1912 #ifdef CONFIG_TV
1914 /// TV color settings (RW)
1915 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1916 MPContext *mpctx)
1918 int r, val;
1919 tvi_handle_t *tvh = mpctx->demuxer->priv;
1920 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1921 return M_PROPERTY_UNAVAILABLE;
1923 switch (action) {
1924 case M_PROPERTY_SET:
1925 if (!arg)
1926 return M_PROPERTY_ERROR;
1927 M_PROPERTY_CLAMP(prop, *(int *) arg);
1928 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1929 case M_PROPERTY_GET:
1930 return tv_get_color_options(tvh, (int) prop->priv, arg);
1931 case M_PROPERTY_STEP_UP:
1932 case M_PROPERTY_STEP_DOWN:
1933 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1934 if (!r)
1935 return M_PROPERTY_ERROR;
1936 val += (arg ? *(int *) arg : 1) *
1937 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1938 M_PROPERTY_CLAMP(prop, val);
1939 return tv_set_color_options(tvh, (int) prop->priv, val);
1941 return M_PROPERTY_ERROR;
1943 return M_PROPERTY_NOT_IMPLEMENTED;
1946 #endif
1948 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1949 MPContext *mpctx)
1951 int val,result;
1952 int base_ioctl=(int)prop->priv;
1954 for teletext's GET,SET,STEP ioctls this is not 0
1955 SET is GET+1
1956 STEP is GET+2
1958 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
1959 return M_PROPERTY_UNAVAILABLE;
1960 if(!base_ioctl)
1961 return M_PROPERTY_ERROR;
1963 switch (action) {
1964 case M_PROPERTY_GET:
1965 if (!arg)
1966 return M_PROPERTY_ERROR;
1967 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, arg);
1968 break;
1969 case M_PROPERTY_SET:
1970 if (!arg)
1971 return M_PROPERTY_ERROR;
1972 M_PROPERTY_CLAMP(prop, *(int *) arg);
1973 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
1974 break;
1975 case M_PROPERTY_STEP_UP:
1976 case M_PROPERTY_STEP_DOWN:
1977 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
1978 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1979 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
1980 break;
1981 default:
1982 return M_PROPERTY_NOT_IMPLEMENTED;
1985 return result == VBI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1988 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
1989 MPContext *mpctx)
1991 int result;
1992 int val;
1994 //with tvh==NULL will fail too
1995 result=mp_property_teletext_common(prop,action,arg,mpctx);
1996 if(result!=M_PROPERTY_OK)
1997 return result;
1999 if(teletext_control(mpctx->demuxer->teletext,
2000 (int)prop->priv, &val)==VBI_CONTROL_TRUE && val)
2001 mp_input_set_section(mpctx->input, "teletext");
2002 else
2003 mp_input_set_section(mpctx->input, "tv");
2004 return M_PROPERTY_OK;
2007 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2008 MPContext *mpctx)
2010 int result;
2011 int val;
2012 if (!mpctx->demuxer->teletext)
2013 return M_PROPERTY_UNAVAILABLE;
2014 switch(action){
2015 case M_PROPERTY_STEP_UP:
2016 case M_PROPERTY_STEP_DOWN:
2017 //This should be handled separately
2018 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2019 result=teletext_control(mpctx->demuxer->teletext,
2020 TV_VBI_CONTROL_STEP_PAGE, &val);
2021 break;
2022 default:
2023 result=mp_property_teletext_common(prop,action,arg,mpctx);
2025 return result;
2028 ///@}
2030 /// All properties available in MPlayer.
2031 /** \ingroup Properties
2033 static const m_option_t mp_properties[] = {
2034 // General
2035 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2036 M_OPT_RANGE, 0, 3, NULL },
2037 { "loop", mp_property_loop, CONF_TYPE_INT,
2038 M_OPT_MIN, -1, 0, NULL },
2039 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2040 M_OPT_RANGE, 0.01, 100.0, NULL },
2041 { "filename", mp_property_filename, CONF_TYPE_STRING,
2042 0, 0, 0, NULL },
2043 { "path", mp_property_path, CONF_TYPE_STRING,
2044 0, 0, 0, NULL },
2045 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2046 0, 0, 0, NULL },
2047 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2048 M_OPT_MIN, 0, 0, NULL },
2049 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2050 M_OPT_MIN, 0, 0, NULL },
2051 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2052 M_OPT_MIN, 0, 0, NULL },
2053 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2054 M_OPT_MIN, 0, 0, NULL },
2055 { "length", mp_property_length, CONF_TYPE_TIME,
2056 M_OPT_MIN, 0, 0, NULL },
2057 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2058 M_OPT_RANGE, 0, 100, NULL },
2059 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2060 M_OPT_MIN, 0, 0, NULL },
2061 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2062 M_OPT_MIN, 0, 0, NULL },
2063 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2064 0, 0, 0, NULL },
2065 { "angle", mp_property_angle, CONF_TYPE_INT,
2066 CONF_RANGE, -2, 10, NULL },
2067 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2068 0, 0, 0, NULL },
2069 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2070 M_OPT_RANGE, 0, 1, NULL },
2072 // Audio
2073 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2074 M_OPT_RANGE, 0, 100, NULL },
2075 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2076 M_OPT_RANGE, 0, 1, NULL },
2077 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2078 M_OPT_RANGE, -100, 100, NULL },
2079 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2080 0, 0, 0, NULL },
2081 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2082 0, 0, 0, NULL },
2083 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2084 0, 0, 0, NULL },
2085 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2086 0, 0, 0, NULL },
2087 { "channels", mp_property_channels, CONF_TYPE_INT,
2088 0, 0, 0, NULL },
2089 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2090 CONF_RANGE, -2, 65535, NULL },
2091 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2092 M_OPT_RANGE, -1, 1, NULL },
2094 // Video
2095 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2096 M_OPT_RANGE, 0, 1, NULL },
2097 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2098 M_OPT_RANGE, 0, 1, NULL },
2099 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2100 M_OPT_RANGE, 0, 2, NULL },
2101 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2102 M_OPT_RANGE, 0, 1, NULL },
2103 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2104 M_OPT_RANGE, 0, 1, NULL },
2105 { "border", mp_property_border, CONF_TYPE_FLAG,
2106 M_OPT_RANGE, 0, 1, NULL },
2107 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2108 M_OPT_RANGE, 0, 2, NULL },
2109 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2110 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2111 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2112 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2113 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2114 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2115 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2116 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2117 { "hue", mp_property_gamma, CONF_TYPE_INT,
2118 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2119 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2120 M_OPT_RANGE, 0, 1, NULL },
2121 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2122 M_OPT_RANGE, 0, 1, NULL },
2123 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2124 0, 0, 0, NULL },
2125 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2126 0, 0, 0, NULL },
2127 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2128 0, 0, 0, NULL },
2129 { "width", mp_property_width, CONF_TYPE_INT,
2130 0, 0, 0, NULL },
2131 { "height", mp_property_height, CONF_TYPE_INT,
2132 0, 0, 0, NULL },
2133 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2134 0, 0, 0, NULL },
2135 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2136 0, 0, 0, NULL },
2137 { "switch_video", mp_property_video, CONF_TYPE_INT,
2138 CONF_RANGE, -2, 65535, NULL },
2139 { "switch_program", mp_property_program, CONF_TYPE_INT,
2140 CONF_RANGE, -1, 65535, NULL },
2142 // Subs
2143 { "sub", mp_property_sub, CONF_TYPE_INT,
2144 M_OPT_MIN, -1, 0, NULL },
2145 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2146 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2147 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2148 M_OPT_MIN, -1, 0, NULL },
2149 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2150 M_OPT_MIN, -1, 0, NULL },
2151 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2152 M_OPT_MIN, -1, 0, NULL },
2153 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2154 0, 0, 0, NULL },
2155 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2156 M_OPT_RANGE, 0, 100, NULL },
2157 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2158 M_OPT_RANGE, 0, 2, NULL },
2159 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2160 M_OPT_RANGE, 0, 1, NULL },
2161 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2162 M_OPT_RANGE, 0, 1, NULL },
2163 #ifdef CONFIG_FREETYPE
2164 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2165 M_OPT_RANGE, 0, 100, NULL },
2166 #endif
2167 #ifdef CONFIG_ASS
2168 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2169 M_OPT_RANGE, 0, 1, NULL },
2170 #endif
2172 #ifdef CONFIG_TV
2173 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2174 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2175 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2176 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2177 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2178 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2179 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2180 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2181 #endif
2182 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2183 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2184 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2185 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2186 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2187 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2188 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2189 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2190 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2191 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2192 { NULL, NULL, NULL, 0, 0, 0, NULL }
2196 int mp_property_do(const char *name, int action, void *val, void *ctx)
2198 return m_property_do(mp_properties, name, action, val, ctx);
2201 char* mp_property_print(const char *name, void* ctx)
2203 char* ret = NULL;
2204 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2205 return NULL;
2206 return ret;
2209 char *property_expand_string(MPContext *mpctx, char *str)
2211 return m_properties_expand_string(mp_properties, str, mpctx);
2214 void property_print_help(void)
2216 m_properties_print_help_list(mp_properties);
2220 /* List of default ways to show a property on OSD.
2222 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2223 * a bar showing the current position between min/max values of the
2224 * property. In this case osd_msg is only used for terminal output
2225 * if there is no video; it'll be a label shown together with percentage.
2227 * Otherwise setting osd_msg will show the string on OSD, formatted with
2228 * the text value of the property as argument.
2230 static struct property_osd_display {
2231 /// property name
2232 const char *name;
2233 /// progressbar type
2234 int osd_progbar; // -1 is special value for seek indicators
2235 /// osd msg id if it must be shared
2236 int osd_id;
2237 /// osd msg template
2238 const char *osd_msg;
2239 } property_osd_display[] = {
2240 // general
2241 { "loop", 0, -1, _("Loop: %s") },
2242 { "chapter", -1, -1, NULL },
2243 // audio
2244 { "volume", OSD_VOLUME, -1, _("Volume") },
2245 { "mute", 0, -1, _("Mute: %s") },
2246 { "audio_delay", 0, -1, _("A-V delay: %s") },
2247 { "switch_audio", 0, -1, _("Audio: %s") },
2248 { "balance", OSD_BALANCE, -1, _("Balance") },
2249 // video
2250 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2251 { "ontop", 0, -1, _("Stay on top: %s") },
2252 { "rootwin", 0, -1, _("Rootwin: %s") },
2253 { "border", 0, -1, _("Border: %s") },
2254 { "framedropping", 0, -1, _("Framedropping: %s") },
2255 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2256 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2257 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2258 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2259 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2260 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2261 { "hue", OSD_HUE, -1, _("Hue") },
2262 { "vsync", 0, -1, _("VSync: %s") },
2263 // subs
2264 { "sub", 0, -1, _("Subtitles: %s") },
2265 { "sub_source", 0, -1, _("Sub source: %s") },
2266 { "sub_vob", 0, -1, _("Subtitles: %s") },
2267 { "sub_demux", 0, -1, _("Subtitles: %s") },
2268 { "sub_file", 0, -1, _("Subtitles: %s") },
2269 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2270 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2271 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2272 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2273 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2274 #ifdef CONFIG_FREETYPE
2275 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2276 #endif
2277 #ifdef CONFIG_TV
2278 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2279 { "tv_hue", OSD_HUE, -1, _("Hue") },
2280 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2281 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2282 #endif
2286 static int show_property_osd(MPContext *mpctx, const char *pname)
2288 struct MPOpts *opts = &mpctx->opts;
2289 int r;
2290 m_option_t* prop;
2291 struct property_osd_display *p;
2293 // look for the command
2294 for (p = property_osd_display; p->name; p++)
2295 if (!strcmp(p->name, pname))
2296 break;
2297 if (!p->name)
2298 return -1;
2300 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2301 return -1;
2303 if (p->osd_progbar == -1)
2304 mpctx->add_osd_seek_info = true;
2305 else if (p->osd_progbar) {
2306 if (prop->type == CONF_TYPE_INT) {
2307 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2308 set_osd_bar(mpctx, p->osd_progbar, p->osd_msg,
2309 prop->min, prop->max, r);
2310 } else if (prop->type == CONF_TYPE_FLOAT) {
2311 float f;
2312 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2313 set_osd_bar(mpctx, p->osd_progbar, p->osd_msg,
2314 prop->min, prop->max, f);
2315 } else {
2316 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2317 "Property use an unsupported type.\n");
2318 return -1;
2320 return 0;
2323 if (p->osd_msg) {
2324 char *val = mp_property_print(pname, mpctx);
2325 if (val) {
2326 int index = p - property_osd_display;
2327 set_osd_msg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2328 1, opts->osd_duration, p->osd_msg, val);
2329 free(val);
2332 return 0;
2337 * \defgroup Command2Property Command to property bridge
2339 * It is used to handle most commands that just set a property
2340 * and optionally display something on the OSD.
2341 * Two kinds of commands are handled: adjust or toggle.
2343 * Adjust commands take 1 or 2 parameters: <value> <abs>
2344 * If <abs> is non-zero the property is set to the given value
2345 * otherwise it is adjusted.
2347 * Toggle commands take 0 or 1 parameters. With no parameter
2348 * or a value less than the property minimum it just steps the
2349 * property to its next value. Otherwise it sets it to the given
2350 * value.
2355 /// List of the commands that can be handled by setting a property.
2356 static struct {
2357 /// property name
2358 const char *name;
2359 /// cmd id
2360 int cmd;
2361 /// set/adjust or toggle command
2362 int toggle;
2363 } set_prop_cmd[] = {
2364 // general
2365 { "loop", MP_CMD_LOOP, 0},
2366 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2367 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2368 { "pause", MP_CMD_PAUSE, 0},
2369 // audio
2370 { "volume", MP_CMD_VOLUME, 0},
2371 { "mute", MP_CMD_MUTE, 1},
2372 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2373 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2374 { "balance", MP_CMD_BALANCE, 0},
2375 // video
2376 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2377 { "panscan", MP_CMD_PANSCAN, 0},
2378 { "ontop", MP_CMD_VO_ONTOP, 1},
2379 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2380 { "border", MP_CMD_VO_BORDER, 1},
2381 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2382 { "gamma", MP_CMD_GAMMA, 0},
2383 { "brightness", MP_CMD_BRIGHTNESS, 0},
2384 { "contrast", MP_CMD_CONTRAST, 0},
2385 { "saturation", MP_CMD_SATURATION, 0},
2386 { "hue", MP_CMD_HUE, 0},
2387 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2388 // subs
2389 { "sub", MP_CMD_SUB_SELECT, 1},
2390 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2391 { "sub_vob", MP_CMD_SUB_VOB, 1},
2392 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2393 { "sub_file", MP_CMD_SUB_FILE, 1},
2394 { "sub_pos", MP_CMD_SUB_POS, 0},
2395 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2396 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2397 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2398 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2399 #ifdef CONFIG_FREETYPE
2400 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2401 #endif
2402 #ifdef CONFIG_ASS
2403 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2404 #endif
2405 #ifdef CONFIG_TV
2406 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2407 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2408 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2409 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2410 #endif
2414 /// Handle commands that set a property.
2415 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2417 int i, r;
2418 m_option_t* prop;
2419 const char *pname;
2421 // look for the command
2422 for (i = 0; set_prop_cmd[i].name; i++)
2423 if (set_prop_cmd[i].cmd == cmd->id)
2424 break;
2425 if (!(pname = set_prop_cmd[i].name))
2426 return 0;
2428 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2429 return 0;
2431 // toggle command
2432 if (set_prop_cmd[i].toggle) {
2433 // set to value
2434 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2435 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2436 else
2437 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2438 } else if (cmd->args[1].v.i) //set
2439 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2440 else // adjust
2441 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2443 if (r <= 0)
2444 return 1;
2446 show_property_osd(mpctx, pname);
2448 return 1;
2451 #ifdef CONFIG_DVDNAV
2452 static const struct {
2453 const char *name;
2454 const mp_command_type cmd;
2455 } mp_dvdnav_bindings[] = {
2456 { "up", MP_CMD_DVDNAV_UP },
2457 { "down", MP_CMD_DVDNAV_DOWN },
2458 { "left", MP_CMD_DVDNAV_LEFT },
2459 { "right", MP_CMD_DVDNAV_RIGHT },
2460 { "menu", MP_CMD_DVDNAV_MENU },
2461 { "select", MP_CMD_DVDNAV_SELECT },
2462 { "prev", MP_CMD_DVDNAV_PREVMENU },
2463 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2466 * keep old dvdnav sub-command options for a while in order not to
2467 * break slave-mode API too suddenly.
2469 { "1", MP_CMD_DVDNAV_UP },
2470 { "2", MP_CMD_DVDNAV_DOWN },
2471 { "3", MP_CMD_DVDNAV_LEFT },
2472 { "4", MP_CMD_DVDNAV_RIGHT },
2473 { "5", MP_CMD_DVDNAV_MENU },
2474 { "6", MP_CMD_DVDNAV_SELECT },
2475 { "7", MP_CMD_DVDNAV_PREVMENU },
2476 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2477 { NULL, 0 }
2479 #endif
2481 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2483 struct MPOpts *opts = &mpctx->opts;
2484 sh_audio_t * const sh_audio = mpctx->sh_audio;
2485 sh_video_t * const sh_video = mpctx->sh_video;
2486 int osd_duration = opts->osd_duration;
2487 int case_fallthrough_hack = 0;
2488 if (!set_property_command(mpctx, cmd))
2489 switch (cmd->id) {
2490 case MP_CMD_SEEK:{
2491 float v;
2492 int abs;
2493 mpctx->add_osd_seek_info = true;
2494 v = cmd->args[0].v.f;
2495 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2496 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2497 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2498 if (sh_video)
2499 mpctx->osd_function =
2500 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2501 mpctx->rel_seek_secs = v;
2502 } else if (abs) { /* Absolute seek by percentage */
2503 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2504 if (sh_video)
2505 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2506 mpctx->rel_seek_secs = v / 100.0;
2507 } else {
2508 mpctx->rel_seek_secs += v;
2509 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2512 break;
2514 case MP_CMD_SET_PROPERTY_OSD:
2515 case_fallthrough_hack = 1;
2517 case MP_CMD_SET_PROPERTY:{
2518 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2519 cmd->args[1].v.s, mpctx);
2520 if (r == M_PROPERTY_UNKNOWN)
2521 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2522 "Unknown property: '%s'\n", cmd->args[0].v.s);
2523 else if (r <= 0)
2524 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2525 "Failed to set property '%s' to '%s'.\n",
2526 cmd->args[0].v.s, cmd->args[1].v.s);
2527 else if (case_fallthrough_hack)
2528 show_property_osd(mpctx, cmd->args[0].v.s);
2530 break;
2532 case MP_CMD_STEP_PROPERTY_OSD:
2533 case_fallthrough_hack = 1;
2535 case MP_CMD_STEP_PROPERTY:{
2536 void* arg = NULL;
2537 int r,i;
2538 double d;
2539 off_t o;
2540 if (cmd->args[1].v.f) {
2541 m_option_t* prop;
2542 if((r = mp_property_do(cmd->args[0].v.s,
2543 M_PROPERTY_GET_TYPE,
2544 &prop, mpctx)) <= 0)
2545 goto step_prop_err;
2546 if(prop->type == CONF_TYPE_INT ||
2547 prop->type == CONF_TYPE_FLAG)
2548 i = cmd->args[1].v.f, arg = &i;
2549 else if(prop->type == CONF_TYPE_FLOAT)
2550 arg = &cmd->args[1].v.f;
2551 else if(prop->type == CONF_TYPE_DOUBLE ||
2552 prop->type == CONF_TYPE_TIME)
2553 d = cmd->args[1].v.f, arg = &d;
2554 else if(prop->type == CONF_TYPE_POSITION)
2555 o = cmd->args[1].v.f, arg = &o;
2556 else
2557 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2558 "Ignoring step size stepping property '%s'.\n",
2559 cmd->args[0].v.s);
2561 r = mp_property_do(cmd->args[0].v.s,
2562 cmd->args[2].v.i < 0 ?
2563 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2564 arg, mpctx);
2565 step_prop_err:
2566 if (r == M_PROPERTY_UNKNOWN)
2567 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2568 "Unknown property: '%s'\n", cmd->args[0].v.s);
2569 else if (r <= 0)
2570 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2571 "Failed to increment property '%s' by %f.\n",
2572 cmd->args[0].v.s, cmd->args[1].v.f);
2573 else if (case_fallthrough_hack)
2574 show_property_osd(mpctx, cmd->args[0].v.s);
2576 break;
2578 case MP_CMD_GET_PROPERTY:{
2579 char *tmp;
2580 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2581 &tmp, mpctx) <= 0) {
2582 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2583 "Failed to get value of property '%s'.\n",
2584 cmd->args[0].v.s);
2585 break;
2587 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2588 cmd->args[0].v.s, tmp);
2589 free(tmp);
2591 break;
2593 case MP_CMD_EDL_MARK:
2594 if (edl_fd) {
2595 float v = sh_video ? sh_video->pts :
2596 playing_audio_pts(mpctx);
2597 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2598 mpctx->begin_skip = v;
2599 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2600 } else {
2601 if (mpctx->begin_skip > v)
2602 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2603 else {
2604 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2605 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2607 mpctx->begin_skip = MP_NOPTS_VALUE;
2610 break;
2612 case MP_CMD_SWITCH_RATIO:
2613 if (!sh_video)
2614 break;
2615 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2616 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2617 else
2618 opts->movie_aspect = cmd->args[0].v.f;
2619 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2620 break;
2622 case MP_CMD_SPEED_INCR:{
2623 float v = cmd->args[0].v.f;
2624 opts->playback_speed += v;
2625 build_afilter_chain(mpctx, sh_audio, &ao_data);
2626 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2627 opts->playback_speed);
2628 } break;
2630 case MP_CMD_SPEED_MULT:{
2631 float v = cmd->args[0].v.f;
2632 opts->playback_speed *= v;
2633 build_afilter_chain(mpctx, sh_audio, &ao_data);
2634 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2635 opts->playback_speed);
2636 } break;
2638 case MP_CMD_SPEED_SET:{
2639 float v = cmd->args[0].v.f;
2640 opts->playback_speed = v;
2641 build_afilter_chain(mpctx, sh_audio, &ao_data);
2642 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2643 opts->playback_speed);
2644 } break;
2646 case MP_CMD_FRAME_STEP:
2647 add_step_frame(mpctx);
2648 break;
2650 case MP_CMD_FILE_FILTER:
2651 file_filter = cmd->args[0].v.i;
2652 break;
2654 case MP_CMD_QUIT:
2655 exit_player_with_rc(mpctx, EXIT_QUIT,
2656 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2658 case MP_CMD_PLAY_TREE_STEP:{
2659 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2660 int force = cmd->args[1].v.i;
2663 if (!force && mpctx->playtree_iter) {
2664 play_tree_iter_t *i =
2665 play_tree_iter_new_copy(mpctx->playtree_iter);
2666 if (play_tree_iter_step(i, n, 0) ==
2667 PLAY_TREE_ITER_ENTRY)
2668 mpctx->stop_play =
2669 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2670 play_tree_iter_free(i);
2671 } else
2672 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2673 if (mpctx->stop_play)
2674 mpctx->play_tree_step = n;
2677 break;
2679 case MP_CMD_PLAY_TREE_UP_STEP:{
2680 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2681 int force = cmd->args[1].v.i;
2683 if (!force && mpctx->playtree_iter) {
2684 play_tree_iter_t *i =
2685 play_tree_iter_new_copy(mpctx->playtree_iter);
2686 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2687 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2688 play_tree_iter_free(i);
2689 } else
2690 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2692 break;
2694 case MP_CMD_PLAY_ALT_SRC_STEP:
2695 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2696 int v = cmd->args[0].v.i;
2697 if (v > 0
2698 && mpctx->playtree_iter->file <
2699 mpctx->playtree_iter->num_files)
2700 mpctx->stop_play = PT_NEXT_SRC;
2701 else if (v < 0 && mpctx->playtree_iter->file > 1)
2702 mpctx->stop_play = PT_PREV_SRC;
2704 break;
2706 case MP_CMD_SUB_STEP:
2707 if (sh_video) {
2708 int movement = cmd->args[0].v.i;
2709 step_sub(subdata, sh_video->pts, movement);
2710 #ifdef CONFIG_ASS
2711 if (ass_track)
2712 sub_delay +=
2713 ass_step_sub(ass_track,
2714 (sh_video->pts +
2715 sub_delay) * 1000 + .5, movement) / 1000.;
2716 #endif
2717 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2718 _("Sub delay: %d ms"), ROUND(sub_delay * 1000));
2720 break;
2722 case MP_CMD_SUB_LOG:
2723 log_sub(mpctx);
2724 break;
2726 case MP_CMD_OSD:{
2727 int v = cmd->args[0].v.i;
2728 int max = (term_osd
2729 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2730 if (opts->osd_level > max)
2731 opts->osd_level = max;
2732 if (v < 0)
2733 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2734 else
2735 opts->osd_level = v > max ? max : v;
2736 /* Show OSD state when disabled, but not when an explicit
2737 argument is given to the OSD command, i.e. in slave mode. */
2738 if (v == -1 && opts->osd_level <= 1)
2739 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2740 _("OSD: %s"),
2741 opts->osd_level ? _("enabled") :
2742 _("disabled"));
2743 else
2744 rm_osd_msg(OSD_MSG_OSD_STATUS);
2746 break;
2748 case MP_CMD_OSD_SHOW_TEXT:
2749 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2750 (cmd->args[1].v.i <
2751 0 ? osd_duration : cmd->args[1].v.i),
2752 "%-.63s", cmd->args[0].v.s);
2753 break;
2755 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2756 char *txt = m_properties_expand_string(mp_properties,
2757 cmd->args[0].v.s,
2758 mpctx);
2759 /* if no argument supplied take default osd_duration, else <arg> ms. */
2760 if (txt) {
2761 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2762 (cmd->args[1].v.i <
2763 0 ? osd_duration : cmd->args[1].v.i),
2764 "%-.63s", txt);
2765 free(txt);
2768 break;
2770 case MP_CMD_LOADFILE:{
2771 play_tree_t *e = play_tree_new();
2772 play_tree_add_file(e, cmd->args[0].v.s);
2774 if (cmd->args[1].v.i) // append
2775 play_tree_append_entry(mpctx->playtree->child, e);
2776 else {
2777 // Go back to the starting point.
2778 while (play_tree_iter_up_step
2779 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2780 /* NOP */ ;
2781 play_tree_free_list(mpctx->playtree->child, 1);
2782 play_tree_set_child(mpctx->playtree, e);
2783 pt_iter_goto_head(mpctx->playtree_iter);
2784 mpctx->stop_play = PT_NEXT_SRC;
2787 break;
2789 case MP_CMD_LOADLIST:{
2790 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2791 if (!e)
2792 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2793 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2794 else {
2795 if (cmd->args[1].v.i) // append
2796 play_tree_append_entry(mpctx->playtree->child, e);
2797 else {
2798 // Go back to the starting point.
2799 while (play_tree_iter_up_step
2800 (mpctx->playtree_iter, 0, 1)
2801 != PLAY_TREE_ITER_END)
2802 /* NOP */ ;
2803 play_tree_free_list(mpctx->playtree->child, 1);
2804 play_tree_set_child(mpctx->playtree, e);
2805 pt_iter_goto_head(mpctx->playtree_iter);
2806 mpctx->stop_play = PT_NEXT_SRC;
2810 break;
2812 case MP_CMD_STOP:
2813 // Go back to the starting point.
2814 while (play_tree_iter_up_step
2815 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2816 /* NOP */ ;
2817 mpctx->stop_play = PT_STOP;
2818 break;
2820 #ifdef CONFIG_RADIO
2821 case MP_CMD_RADIO_STEP_CHANNEL:
2822 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2823 int v = cmd->args[0].v.i;
2824 if (v > 0)
2825 radio_step_channel(mpctx->demuxer->stream,
2826 RADIO_CHANNEL_HIGHER);
2827 else
2828 radio_step_channel(mpctx->demuxer->stream,
2829 RADIO_CHANNEL_LOWER);
2830 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2831 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2832 _("Channel: %s"),
2833 radio_get_channel_name(mpctx->demuxer->stream));
2836 break;
2838 case MP_CMD_RADIO_SET_CHANNEL:
2839 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2840 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2841 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2842 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2843 _("Channel: %s"),
2844 radio_get_channel_name(mpctx->demuxer->stream));
2847 break;
2849 case MP_CMD_RADIO_SET_FREQ:
2850 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2851 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2852 break;
2854 case MP_CMD_RADIO_STEP_FREQ:
2855 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2856 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2857 break;
2858 #endif
2860 #ifdef CONFIG_TV
2861 case MP_CMD_TV_START_SCAN:
2862 if (mpctx->file_format == DEMUXER_TYPE_TV)
2863 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2864 break;
2865 case MP_CMD_TV_SET_FREQ:
2866 if (mpctx->file_format == DEMUXER_TYPE_TV)
2867 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2868 cmd->args[0].v.f * 16.0);
2869 #ifdef CONFIG_PVR
2870 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2871 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2872 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2873 pvr_get_current_channelname (mpctx->stream),
2874 pvr_get_current_stationname (mpctx->stream));
2876 #endif /* CONFIG_PVR */
2877 break;
2879 case MP_CMD_TV_STEP_FREQ:
2880 if (mpctx->file_format == DEMUXER_TYPE_TV)
2881 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2882 cmd->args[0].v.f * 16.0);
2883 #ifdef CONFIG_PVR
2884 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2885 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2886 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2887 pvr_get_current_channelname (mpctx->stream),
2888 pvr_get_current_frequency (mpctx->stream));
2890 #endif /* CONFIG_PVR */
2891 break;
2893 case MP_CMD_TV_SET_NORM:
2894 if (mpctx->file_format == DEMUXER_TYPE_TV)
2895 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2896 cmd->args[0].v.s);
2897 break;
2899 case MP_CMD_TV_STEP_CHANNEL:{
2900 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2901 int v = cmd->args[0].v.i;
2902 if (v > 0) {
2903 tv_step_channel((tvi_handle_t *) (mpctx->
2904 demuxer->priv),
2905 TV_CHANNEL_HIGHER);
2906 } else {
2907 tv_step_channel((tvi_handle_t *) (mpctx->
2908 demuxer->priv),
2909 TV_CHANNEL_LOWER);
2911 if (tv_channel_list) {
2912 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2913 _("Channel: %s"), tv_channel_current->name);
2914 //vo_osd_changed(OSDTYPE_SUBTITLE);
2917 #ifdef CONFIG_PVR
2918 else if (mpctx->stream &&
2919 mpctx->stream->type == STREAMTYPE_PVR) {
2920 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2921 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2922 pvr_get_current_channelname (mpctx->stream),
2923 pvr_get_current_stationname (mpctx->stream));
2925 #endif /* CONFIG_PVR */
2927 #ifdef CONFIG_DVBIN
2928 if (mpctx->stream->type == STREAMTYPE_DVB) {
2929 int dir;
2930 int v = cmd->args[0].v.i;
2932 mpctx->last_dvb_step = v;
2933 if (v > 0)
2934 dir = DVB_CHANNEL_HIGHER;
2935 else
2936 dir = DVB_CHANNEL_LOWER;
2939 if (dvb_step_channel(mpctx->stream, dir)) {
2940 mpctx->stop_play = PT_NEXT_ENTRY;
2941 mpctx->dvbin_reopen = 1;
2944 #endif /* CONFIG_DVBIN */
2945 break;
2947 case MP_CMD_TV_SET_CHANNEL:
2948 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2949 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2950 cmd->args[0].v.s);
2951 if (tv_channel_list) {
2952 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2953 _("Channel: %s"), tv_channel_current->name);
2954 //vo_osd_changed(OSDTYPE_SUBTITLE);
2957 #ifdef CONFIG_PVR
2958 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2959 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2960 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2961 pvr_get_current_channelname (mpctx->stream),
2962 pvr_get_current_stationname (mpctx->stream));
2964 #endif /* CONFIG_PVR */
2965 break;
2967 #ifdef CONFIG_DVBIN
2968 case MP_CMD_DVB_SET_CHANNEL:
2969 if (mpctx->stream->type == STREAMTYPE_DVB) {
2970 mpctx->last_dvb_step = 1;
2972 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
2973 cmd->args[0].v.i)) {
2974 mpctx->stop_play = PT_NEXT_ENTRY;
2975 mpctx->dvbin_reopen = 1;
2978 break;
2979 #endif /* CONFIG_DVBIN */
2981 case MP_CMD_TV_LAST_CHANNEL:
2982 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2983 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2984 if (tv_channel_list) {
2985 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2986 _("Channel: %s"), tv_channel_current->name);
2987 //vo_osd_changed(OSDTYPE_SUBTITLE);
2990 #ifdef CONFIG_PVR
2991 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2992 pvr_set_lastchannel (mpctx->stream);
2993 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2994 pvr_get_current_channelname (mpctx->stream),
2995 pvr_get_current_stationname (mpctx->stream));
2997 #endif /* CONFIG_PVR */
2998 break;
3000 case MP_CMD_TV_STEP_NORM:
3001 if (mpctx->file_format == DEMUXER_TYPE_TV)
3002 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3003 break;
3005 case MP_CMD_TV_STEP_CHANNEL_LIST:
3006 if (mpctx->file_format == DEMUXER_TYPE_TV)
3007 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3008 break;
3009 #endif /* CONFIG_TV */
3010 case MP_CMD_TV_TELETEXT_ADD_DEC:
3012 if (mpctx->demuxer->teletext)
3013 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
3014 &(cmd->args[0].v.s));
3015 break;
3017 case MP_CMD_TV_TELETEXT_GO_LINK:
3019 if (mpctx->demuxer->teletext)
3020 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
3021 &(cmd->args[0].v.i));
3022 break;
3025 case MP_CMD_SUB_LOAD:
3026 if (sh_video) {
3027 int n = mpctx->set_of_sub_size;
3028 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3029 if (n != mpctx->set_of_sub_size) {
3030 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
3031 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
3032 mpctx->global_sub_size;
3033 ++mpctx->global_sub_size;
3036 break;
3038 case MP_CMD_SUB_REMOVE:
3039 if (sh_video) {
3040 int v = cmd->args[0].v.i;
3041 sub_data *subd;
3042 if (v < 0) {
3043 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
3044 subd = mpctx->set_of_subtitles[v];
3045 mp_tmsg(MSGT_CPLAYER, MSGL_STATUS,
3046 "SUB: Removed subtitle file (%d): %s\n", v + 1,
3047 filename_recode(subd->filename));
3048 sub_free(subd);
3049 mpctx->set_of_subtitles[v] = NULL;
3051 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
3052 mpctx->global_sub_size -= mpctx->set_of_sub_size;
3053 mpctx->set_of_sub_size = 0;
3054 if (mpctx->set_of_sub_pos >= 0) {
3055 mpctx->global_sub_pos = -2;
3056 subdata = NULL;
3057 mp_input_queue_cmd(mpctx->input,
3058 mp_input_parse_cmd("sub_select"));
3060 } else if (v < mpctx->set_of_sub_size) {
3061 subd = mpctx->set_of_subtitles[v];
3062 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
3063 "SUB: Removed subtitle file (%d): %s\n", v + 1,
3064 filename_recode(subd->filename));
3065 sub_free(subd);
3066 if (mpctx->set_of_sub_pos == v) {
3067 mpctx->global_sub_pos = -2;
3068 subdata = NULL;
3069 mp_input_queue_cmd(mpctx->input,
3070 mp_input_parse_cmd("sub_select"));
3071 } else if (mpctx->set_of_sub_pos > v) {
3072 --mpctx->set_of_sub_pos;
3073 --mpctx->global_sub_pos;
3075 while (++v < mpctx->set_of_sub_size)
3076 mpctx->set_of_subtitles[v - 1] =
3077 mpctx->set_of_subtitles[v];
3078 --mpctx->set_of_sub_size;
3079 --mpctx->global_sub_size;
3080 if (mpctx->set_of_sub_size <= 0)
3081 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
3082 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
3085 break;
3087 case MP_CMD_GET_SUB_VISIBILITY:
3088 if (sh_video) {
3089 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3090 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3092 break;
3094 case MP_CMD_SCREENSHOT:
3095 if (mpctx->video_out && mpctx->video_out->config_ok) {
3096 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3097 if (CONTROL_OK !=
3098 ((vf_instance_t *) sh_video->vfilter)->
3099 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3100 &cmd->args[0].v.i))
3101 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3103 break;
3105 case MP_CMD_AF_EQ_SET:{
3106 af_instance_t* m1=af_get(sh_audio->afilter, "equalizer");
3107 if (m1) m1->control( m1, AF_CONTROL_COMMAND_LINE, cmd->args[0].v.s);
3108 else mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -af equalizer=0:0 ?)\n");
3110 break;
3112 case MP_CMD_VF_CHANGE_RECTANGLE:
3113 if (!sh_video)
3114 break;
3115 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3116 break;
3118 case MP_CMD_GET_TIME_LENGTH:{
3119 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
3120 demuxer_get_time_length(mpctx->demuxer));
3122 break;
3124 case MP_CMD_GET_FILENAME:{
3125 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3126 get_metadata(mpctx, META_NAME));
3128 break;
3130 case MP_CMD_GET_VIDEO_CODEC:{
3131 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3132 if (!inf)
3133 inf = strdup("");
3134 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3135 free(inf);
3137 break;
3139 case MP_CMD_GET_VIDEO_BITRATE:{
3140 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3141 if (!inf)
3142 inf = strdup("");
3143 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3144 free(inf);
3146 break;
3148 case MP_CMD_GET_VIDEO_RESOLUTION:{
3149 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3150 if (!inf)
3151 inf = strdup("");
3152 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3153 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3154 free(inf);
3156 break;
3158 case MP_CMD_GET_AUDIO_CODEC:{
3159 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3160 if (!inf)
3161 inf = strdup("");
3162 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3163 free(inf);
3165 break;
3167 case MP_CMD_GET_AUDIO_BITRATE:{
3168 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3169 if (!inf)
3170 inf = strdup("");
3171 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3172 free(inf);
3174 break;
3176 case MP_CMD_GET_AUDIO_SAMPLES:{
3177 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3178 if (!inf)
3179 inf = strdup("");
3180 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3181 free(inf);
3183 break;
3185 case MP_CMD_GET_META_TITLE:{
3186 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3187 if (!inf)
3188 inf = strdup("");
3189 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3190 free(inf);
3192 break;
3194 case MP_CMD_GET_META_ARTIST:{
3195 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3196 if (!inf)
3197 inf = strdup("");
3198 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3199 free(inf);
3201 break;
3203 case MP_CMD_GET_META_ALBUM:{
3204 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3205 if (!inf)
3206 inf = strdup("");
3207 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3208 free(inf);
3210 break;
3212 case MP_CMD_GET_META_YEAR:{
3213 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3214 if (!inf)
3215 inf = strdup("");
3216 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3217 free(inf);
3219 break;
3221 case MP_CMD_GET_META_COMMENT:{
3222 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3223 if (!inf)
3224 inf = strdup("");
3225 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3226 free(inf);
3228 break;
3230 case MP_CMD_GET_META_TRACK:{
3231 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3232 if (!inf)
3233 inf = strdup("");
3234 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3235 free(inf);
3237 break;
3239 case MP_CMD_GET_META_GENRE:{
3240 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3241 if (!inf)
3242 inf = strdup("");
3243 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3244 free(inf);
3246 break;
3248 case MP_CMD_GET_VO_FULLSCREEN:
3249 if (mpctx->video_out && mpctx->video_out->config_ok)
3250 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3251 break;
3253 case MP_CMD_GET_PERCENT_POS:
3254 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3255 demuxer_get_percent_pos(mpctx->demuxer));
3256 break;
3258 case MP_CMD_GET_TIME_POS:{
3259 float pos = 0;
3260 if (sh_video)
3261 pos = sh_video->pts;
3262 else if (sh_audio && mpctx->audio_out)
3263 pos = playing_audio_pts(mpctx);
3264 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3266 break;
3268 case MP_CMD_RUN:
3269 #ifndef __MINGW32__
3270 if (!fork()) {
3271 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3272 exit(0);
3274 #endif
3275 break;
3277 case MP_CMD_KEYDOWN_EVENTS:
3278 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3279 break;
3281 case MP_CMD_SET_MOUSE_POS:{
3282 int pointer_x, pointer_y;
3283 double dx, dy;
3284 pointer_x = cmd->args[0].v.i;
3285 pointer_y = cmd->args[1].v.i;
3286 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3287 #ifdef CONFIG_DVDNAV
3288 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3289 && dx > 0.0 && dy > 0.0) {
3290 int button = -1;
3291 pointer_x = (int) (dx * (double) sh_video->disp_w);
3292 pointer_y = (int) (dy * (double) sh_video->disp_h);
3293 mp_dvdnav_update_mouse_pos(mpctx->stream,
3294 pointer_x, pointer_y, &button);
3295 if (opts->osd_level > 1 && button > 0)
3296 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3297 "Selected button number %d", button);
3299 #endif
3300 #ifdef CONFIG_MENU
3301 if (use_menu && dx >= 0.0 && dy >= 0.0)
3302 menu_update_mouse_pos(dx, dy);
3303 #endif
3305 break;
3307 #ifdef CONFIG_DVDNAV
3308 case MP_CMD_DVDNAV:{
3309 int button = -1;
3310 int i;
3311 mp_command_type command = 0;
3312 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3313 break;
3315 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3316 if (cmd->args[0].v.s &&
3317 !strcasecmp (cmd->args[0].v.s,
3318 mp_dvdnav_bindings[i].name))
3319 command = mp_dvdnav_bindings[i].cmd;
3321 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3322 if (opts->osd_level > 1 && button > 0)
3323 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3324 "Selected button number %d", button);
3326 break;
3328 case MP_CMD_SWITCH_TITLE:
3329 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3330 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3331 break;
3333 #endif
3335 default:
3336 mp_msg(MSGT_CPLAYER, MSGL_V,
3337 "Received unknown cmd %s\n", cmd->name);
3340 switch (cmd->pausing) {
3341 case 1: // "pausing"
3342 pause_player(mpctx);
3343 break;
3344 case 3: // "pausing_toggle"
3345 if (mpctx->paused)
3346 unpause_player(mpctx);
3347 else
3348 pause_player(mpctx);
3349 break;