Updated libass
[mplayer/kovensky.git] / command.c
blob98a1d8625f02adae63632b771146ad32b198e2d3
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 "vobsub.h"
32 #include "spudec.h"
33 #include "get_path.h"
34 #include "ass_mp.h"
35 #ifdef CONFIG_TV
36 #include "stream/tv.h"
37 #endif
38 #ifdef CONFIG_RADIO
39 #include "stream/stream_radio.h"
40 #endif
41 #ifdef CONFIG_PVR
42 #include "stream/pvr.h"
43 #endif
44 #ifdef CONFIG_DVBIN
45 #include "stream/dvbin.h"
46 #endif
47 #ifdef CONFIG_DVDREAD
48 #include "stream/stream_dvd.h"
49 #endif
50 #ifdef CONFIG_DVDNAV
51 #include "stream/stream_dvdnav.h"
52 #endif
53 #ifdef CONFIG_MENU
54 #include "m_struct.h"
55 #include "libmenu/menu.h"
56 #endif
58 #include "mp_core.h"
59 #include "mp_fifo.h"
60 #include "libavutil/avstring.h"
62 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
64 extern int use_menu;
66 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
67 double *dx, double *dy)
69 struct MPOpts *opts = &mpctx->opts;
70 struct vo *vo = mpctx->video_out;
71 //remove the borders, if any, and rescale to the range [0,1],[0,1]
72 if (vo_fs) { //we are in full-screen mode
73 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
74 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
75 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
76 iy -= (opts->vo_screenheight - vo->dheight) / 2;
78 if (ix < 0 || ix > vo->dwidth) {
79 *dx = *dy = -1.0;
80 return;
81 } //we are on one of the borders
82 if (iy < 0 || iy > vo->dheight) {
83 *dx = *dy = -1.0;
84 return;
85 } //we are on one of the borders
88 *dx = (double) ix / (double) vo->dwidth;
89 *dy = (double) iy / (double) vo->dheight;
91 mp_msg(MSGT_CPLAYER, MSGL_V,
92 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
93 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
94 vo->dheight, vo_fs);
97 static int sub_source_by_pos(MPContext *mpctx, int pos)
99 int source = -1;
100 int top = -1;
101 int i;
102 for (i = 0; i < SUB_SOURCES; i++) {
103 int j = mpctx->global_sub_indices[i];
104 if ((j >= 0) && (j > top) && (pos >= j)) {
105 source = i;
106 top = j;
109 return source;
112 static int sub_source(MPContext *mpctx)
114 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
118 * \brief Log the currently displayed subtitle to a file
120 * Logs the current or last displayed subtitle together with filename
121 * and time information to ~/.mplayer/subtitle_log
123 * Intended purpose is to allow convenient marking of bogus subtitles
124 * which need to be fixed while watching the movie.
127 static void log_sub(struct MPContext *mpctx)
129 char *fname;
130 FILE *f;
131 int i;
133 if (subdata == NULL || vo_sub_last == NULL)
134 return;
135 fname = get_path("subtitle_log");
136 f = fopen(fname, "a");
137 if (!f)
138 return;
139 fprintf(f, "----------------------------------------------------------\n");
140 if (subdata->sub_uses_time) {
141 fprintf(f,
142 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
143 mpctx->filename, vo_sub_last->start / 360000,
144 (vo_sub_last->start / 6000) % 60,
145 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
146 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
147 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
148 } else {
149 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
150 vo_sub_last->start, vo_sub_last->end);
152 for (i = 0; i < vo_sub_last->lines; i++) {
153 fprintf(f, "%s\n", vo_sub_last->text[i]);
155 fclose(f);
159 /// \defgroup Properties
160 ///@{
162 /// \defgroup GeneralProperties General properties
163 /// \ingroup Properties
164 ///@{
166 /// OSD level (RW)
167 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
168 MPContext *mpctx)
170 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
173 /// Loop (RW)
174 static int mp_property_loop(m_option_t *prop, int action, void *arg,
175 MPContext *mpctx)
177 struct MPOpts *opts = &mpctx->opts;
178 switch (action) {
179 case M_PROPERTY_PRINT:
180 if (!arg) return M_PROPERTY_ERROR;
181 if (opts->loop_times < 0)
182 *(char**)arg = strdup("off");
183 else if (opts->loop_times == 0)
184 *(char**)arg = strdup("inf");
185 else
186 break;
187 return M_PROPERTY_OK;
189 return m_property_int_range(prop, action, arg, &opts->loop_times);
192 /// Playback speed (RW)
193 static int mp_property_playback_speed(m_option_t *prop, int action,
194 void *arg, MPContext *mpctx)
196 struct MPOpts *opts = &mpctx->opts;
197 switch (action) {
198 case M_PROPERTY_SET:
199 if (!arg)
200 return M_PROPERTY_ERROR;
201 M_PROPERTY_CLAMP(prop, *(float *) arg);
202 opts->playback_speed = *(float *) arg;
203 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
204 return M_PROPERTY_OK;
205 case M_PROPERTY_STEP_UP:
206 case M_PROPERTY_STEP_DOWN:
207 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
208 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
209 M_PROPERTY_CLAMP(prop, opts->playback_speed);
210 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
211 return M_PROPERTY_OK;
213 return m_property_float_range(prop, action, arg, &opts->playback_speed);
216 /// filename with path (RO)
217 static int mp_property_path(m_option_t *prop, int action, void *arg,
218 MPContext *mpctx)
220 return m_property_string_ro(prop, action, arg, mpctx->filename);
223 /// filename without path (RO)
224 static int mp_property_filename(m_option_t *prop, int action, void *arg,
225 MPContext *mpctx)
227 char *f;
228 if (!mpctx->filename)
229 return M_PROPERTY_UNAVAILABLE;
230 if (((f = strrchr(mpctx->filename, '/'))
231 || (f = strrchr(mpctx->filename, '\\'))) && f[1])
232 f++;
233 else
234 f = mpctx->filename;
235 return m_property_string_ro(prop, action, arg, f);
238 /// Demuxer name (RO)
239 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
240 MPContext *mpctx)
242 if (!mpctx->demuxer)
243 return M_PROPERTY_UNAVAILABLE;
244 return m_property_string_ro(prop, action, arg,
245 (char *) mpctx->demuxer->desc->name);
248 /// Position in the stream (RW)
249 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
250 MPContext *mpctx)
252 if (!mpctx->demuxer || !mpctx->demuxer->stream)
253 return M_PROPERTY_UNAVAILABLE;
254 if (!arg)
255 return M_PROPERTY_ERROR;
256 switch (action) {
257 case M_PROPERTY_GET:
258 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
259 return M_PROPERTY_OK;
260 case M_PROPERTY_SET:
261 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
262 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
263 return M_PROPERTY_OK;
265 return M_PROPERTY_NOT_IMPLEMENTED;
268 /// Stream start offset (RO)
269 static int mp_property_stream_start(m_option_t *prop, int action,
270 void *arg, MPContext *mpctx)
272 if (!mpctx->demuxer || !mpctx->demuxer->stream)
273 return M_PROPERTY_UNAVAILABLE;
274 switch (action) {
275 case M_PROPERTY_GET:
276 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
277 return M_PROPERTY_OK;
279 return M_PROPERTY_NOT_IMPLEMENTED;
282 /// Stream end offset (RO)
283 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
284 MPContext *mpctx)
286 if (!mpctx->demuxer || !mpctx->demuxer->stream)
287 return M_PROPERTY_UNAVAILABLE;
288 switch (action) {
289 case M_PROPERTY_GET:
290 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
291 return M_PROPERTY_OK;
293 return M_PROPERTY_NOT_IMPLEMENTED;
296 /// Stream length (RO)
297 static int mp_property_stream_length(m_option_t *prop, int action,
298 void *arg, MPContext *mpctx)
300 if (!mpctx->demuxer || !mpctx->demuxer->stream)
301 return M_PROPERTY_UNAVAILABLE;
302 switch (action) {
303 case M_PROPERTY_GET:
304 *(off_t *) arg =
305 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
306 return M_PROPERTY_OK;
308 return M_PROPERTY_NOT_IMPLEMENTED;
311 /// Media length in seconds (RO)
312 static int mp_property_length(m_option_t *prop, int action, void *arg,
313 MPContext *mpctx)
315 double len;
317 if (!mpctx->demuxer ||
318 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
319 return M_PROPERTY_UNAVAILABLE;
321 return m_property_time_ro(prop, action, arg, len);
324 /// Current position in percent (RW)
325 static int mp_property_percent_pos(m_option_t *prop, int action,
326 void *arg, MPContext *mpctx) {
327 int pos;
329 if (!mpctx->demuxer)
330 return M_PROPERTY_UNAVAILABLE;
332 switch(action) {
333 case M_PROPERTY_SET:
334 if(!arg) return M_PROPERTY_ERROR;
335 M_PROPERTY_CLAMP(prop, *(int*)arg);
336 pos = *(int*)arg;
337 break;
338 case M_PROPERTY_STEP_UP:
339 case M_PROPERTY_STEP_DOWN:
340 pos = demuxer_get_percent_pos(mpctx->demuxer);
341 pos += (arg ? *(int*)arg : 10) *
342 (action == M_PROPERTY_STEP_UP ? 1 : -1);
343 M_PROPERTY_CLAMP(prop, pos);
344 break;
345 default:
346 return m_property_int_ro(prop, action, arg,
347 demuxer_get_percent_pos(mpctx->demuxer));
350 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
351 mpctx->rel_seek_secs = pos / 100.0;
352 return M_PROPERTY_OK;
355 /// Current position in seconds (RW)
356 static int mp_property_time_pos(m_option_t *prop, int action,
357 void *arg, MPContext *mpctx) {
358 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
359 return M_PROPERTY_UNAVAILABLE;
361 switch(action) {
362 case M_PROPERTY_SET:
363 if(!arg) return M_PROPERTY_ERROR;
364 M_PROPERTY_CLAMP(prop, *(double*)arg);
365 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
366 mpctx->rel_seek_secs = *(double*)arg;
367 return M_PROPERTY_OK;
368 case M_PROPERTY_STEP_UP:
369 case M_PROPERTY_STEP_DOWN:
370 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
371 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
372 return M_PROPERTY_OK;
374 return m_property_time_ro(prop, action, arg,
375 mpctx->sh_video ? mpctx->sh_video->pts :
376 playing_audio_pts(mpctx));
379 /// Current chapter (RW)
380 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
381 MPContext *mpctx)
383 struct MPOpts *opts = &mpctx->opts;
384 int chapter = -1;
385 int step_all;
386 char *chapter_name = NULL;
388 if (mpctx->demuxer)
389 chapter = get_current_chapter(mpctx);
390 if (chapter < 0)
391 return M_PROPERTY_UNAVAILABLE;
393 switch (action) {
394 case M_PROPERTY_GET:
395 if (!arg)
396 return M_PROPERTY_ERROR;
397 *(int *) arg = chapter;
398 return M_PROPERTY_OK;
399 case M_PROPERTY_PRINT: {
400 if (!arg)
401 return M_PROPERTY_ERROR;
402 chapter_name = chapter_display_name(mpctx, chapter);
403 if (!chapter_name)
404 return M_PROPERTY_UNAVAILABLE;
405 *(char **) arg = chapter_name;
406 return M_PROPERTY_OK;
408 case M_PROPERTY_SET:
409 if (!arg)
410 return M_PROPERTY_ERROR;
411 M_PROPERTY_CLAMP(prop, *(int*)arg);
412 step_all = *(int *)arg - chapter;
413 chapter += step_all;
414 break;
415 case M_PROPERTY_STEP_UP:
416 case M_PROPERTY_STEP_DOWN: {
417 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
418 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
419 chapter += step_all;
420 if (chapter < 0)
421 chapter = 0;
422 break;
424 default:
425 return M_PROPERTY_NOT_IMPLEMENTED;
428 double next_pts = 0;
429 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
430 mpctx->rel_seek_secs = 0;
431 mpctx->abs_seek_pos = 0;
432 if (chapter >= 0) {
433 if (next_pts > -1.0) {
434 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
435 mpctx->rel_seek_secs = next_pts;
437 if (chapter_name)
438 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
439 _("Chapter: (%d) %s"), chapter + 1, chapter_name);
441 else if (step_all > 0)
442 mpctx->rel_seek_secs = 1000000000.;
443 else
444 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
445 _("Chapter: (%d) %s"), 0, _("unknown"));
446 if (chapter_name)
447 talloc_free(chapter_name);
448 return M_PROPERTY_OK;
451 /// Number of chapters in file
452 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
453 MPContext *mpctx)
455 if (!mpctx->demuxer)
456 return M_PROPERTY_UNAVAILABLE;
457 if (mpctx->demuxer->num_chapters == 0)
458 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
459 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
462 /// Current dvd angle (RW)
463 static int mp_property_angle(m_option_t *prop, int action, void *arg,
464 MPContext *mpctx)
466 struct MPOpts *opts = &mpctx->opts;
467 int angle = -1;
468 int angles;
469 char *angle_name = NULL;
471 if (mpctx->demuxer)
472 angle = demuxer_get_current_angle(mpctx->demuxer);
473 if (angle < 0)
474 return M_PROPERTY_UNAVAILABLE;
475 angles = demuxer_angles_count(mpctx->demuxer);
476 if (angles <= 1)
477 return M_PROPERTY_UNAVAILABLE;
479 switch (action) {
480 case M_PROPERTY_GET:
481 if (!arg)
482 return M_PROPERTY_ERROR;
483 *(int *) arg = angle;
484 return M_PROPERTY_OK;
485 case M_PROPERTY_PRINT: {
486 if (!arg)
487 return M_PROPERTY_ERROR;
488 angle_name = calloc(1, 64);
489 if (!angle_name)
490 return M_PROPERTY_UNAVAILABLE;
491 snprintf(angle_name, 64, "%d/%d", angle, angles);
492 *(char **) arg = angle_name;
493 return M_PROPERTY_OK;
495 case M_PROPERTY_SET:
496 if (!arg)
497 return M_PROPERTY_ERROR;
498 angle = *(int *)arg;
499 M_PROPERTY_CLAMP(prop, angle);
500 break;
501 case M_PROPERTY_STEP_UP:
502 case M_PROPERTY_STEP_DOWN: {
503 int step = 0;
504 if(arg)
505 step = *(int*)arg;
506 if(!step)
507 step = 1;
508 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
509 angle += step;
510 if (angle < 1) //cycle
511 angle = angles;
512 break;
514 default:
515 return M_PROPERTY_NOT_IMPLEMENTED;
517 angle = demuxer_set_angle(mpctx->demuxer, angle);
518 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
519 _("Angle: %d/%d"), angle, angles);
520 if (angle_name)
521 free(angle_name);
522 return M_PROPERTY_OK;
525 /// Demuxer meta data
526 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
527 MPContext *mpctx) {
528 m_property_action_t* ka;
529 char* meta;
530 static const m_option_t key_type =
531 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
532 if (!mpctx->demuxer)
533 return M_PROPERTY_UNAVAILABLE;
535 switch(action) {
536 case M_PROPERTY_GET:
537 if(!arg) return M_PROPERTY_ERROR;
538 *(char***)arg = mpctx->demuxer->info;
539 return M_PROPERTY_OK;
540 case M_PROPERTY_KEY_ACTION:
541 if(!arg) return M_PROPERTY_ERROR;
542 ka = arg;
543 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
544 return M_PROPERTY_UNKNOWN;
545 switch(ka->action) {
546 case M_PROPERTY_GET:
547 if(!ka->arg) return M_PROPERTY_ERROR;
548 *(char**)ka->arg = meta;
549 return M_PROPERTY_OK;
550 case M_PROPERTY_GET_TYPE:
551 if(!ka->arg) return M_PROPERTY_ERROR;
552 *(m_option_t**)ka->arg = &key_type;
553 return M_PROPERTY_OK;
556 return M_PROPERTY_NOT_IMPLEMENTED;
559 static int mp_property_pause(m_option_t *prop, int action, void *arg,
560 void *ctx)
562 MPContext *mpctx = ctx;
564 switch (action) {
565 case M_PROPERTY_SET:
566 if (!arg)
567 return M_PROPERTY_ERROR;
568 if (mpctx->paused == (bool)*(int *) arg)
569 return M_PROPERTY_OK;
570 case M_PROPERTY_STEP_UP:
571 case M_PROPERTY_STEP_DOWN:
572 if (mpctx->paused) {
573 unpause_player(mpctx);
574 mpctx->osd_function = OSD_PLAY;
576 else {
577 pause_player(mpctx);
578 mpctx->osd_function = OSD_PAUSE;
580 return M_PROPERTY_OK;
581 default:
582 return m_property_flag(prop, action, arg, &mpctx->paused);
587 ///@}
589 /// \defgroup AudioProperties Audio properties
590 /// \ingroup Properties
591 ///@{
593 /// Volume (RW)
594 static int mp_property_volume(m_option_t *prop, int action, void *arg,
595 MPContext *mpctx)
598 if (!mpctx->sh_audio)
599 return M_PROPERTY_UNAVAILABLE;
601 switch (action) {
602 case M_PROPERTY_GET:
603 if (!arg)
604 return M_PROPERTY_ERROR;
605 mixer_getbothvolume(&mpctx->mixer, arg);
606 return M_PROPERTY_OK;
607 case M_PROPERTY_PRINT:{
608 float vol;
609 if (!arg)
610 return M_PROPERTY_ERROR;
611 mixer_getbothvolume(&mpctx->mixer, &vol);
612 return m_property_float_range(prop, action, arg, &vol);
614 case M_PROPERTY_STEP_UP:
615 case M_PROPERTY_STEP_DOWN:
616 case M_PROPERTY_SET:
617 break;
618 default:
619 return M_PROPERTY_NOT_IMPLEMENTED;
622 if (mpctx->edl_muted)
623 return M_PROPERTY_DISABLED;
624 mpctx->user_muted = 0;
626 switch (action) {
627 case M_PROPERTY_SET:
628 if (!arg)
629 return M_PROPERTY_ERROR;
630 M_PROPERTY_CLAMP(prop, *(float *) arg);
631 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
632 return M_PROPERTY_OK;
633 case M_PROPERTY_STEP_UP:
634 if (arg && *(float *) arg <= 0)
635 mixer_decvolume(&mpctx->mixer);
636 else
637 mixer_incvolume(&mpctx->mixer);
638 return M_PROPERTY_OK;
639 case M_PROPERTY_STEP_DOWN:
640 if (arg && *(float *) arg <= 0)
641 mixer_incvolume(&mpctx->mixer);
642 else
643 mixer_decvolume(&mpctx->mixer);
644 return M_PROPERTY_OK;
646 return M_PROPERTY_NOT_IMPLEMENTED;
649 /// Mute (RW)
650 static int mp_property_mute(m_option_t *prop, int action, void *arg,
651 MPContext *mpctx)
654 if (!mpctx->sh_audio)
655 return M_PROPERTY_UNAVAILABLE;
657 switch (action) {
658 case M_PROPERTY_SET:
659 if (mpctx->edl_muted)
660 return M_PROPERTY_DISABLED;
661 if (!arg)
662 return M_PROPERTY_ERROR;
663 if ((!!*(int *) arg) != mpctx->mixer.muted)
664 mixer_mute(&mpctx->mixer);
665 mpctx->user_muted = mpctx->mixer.muted;
666 return M_PROPERTY_OK;
667 case M_PROPERTY_STEP_UP:
668 case M_PROPERTY_STEP_DOWN:
669 if (mpctx->edl_muted)
670 return M_PROPERTY_DISABLED;
671 mixer_mute(&mpctx->mixer);
672 mpctx->user_muted = mpctx->mixer.muted;
673 return M_PROPERTY_OK;
674 case M_PROPERTY_PRINT:
675 if (!arg)
676 return M_PROPERTY_ERROR;
677 if (mpctx->edl_muted) {
678 *(char **) arg = strdup(_("enabled (EDL)"));
679 return M_PROPERTY_OK;
681 default:
682 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
687 /// Audio delay (RW)
688 static int mp_property_audio_delay(m_option_t *prop, int action,
689 void *arg, MPContext *mpctx)
691 if (!(mpctx->sh_audio && mpctx->sh_video))
692 return M_PROPERTY_UNAVAILABLE;
693 switch (action) {
694 case M_PROPERTY_SET:
695 case M_PROPERTY_STEP_UP:
696 case M_PROPERTY_STEP_DOWN: {
697 int ret;
698 float delay = audio_delay;
699 ret = m_property_delay(prop, action, arg, &audio_delay);
700 if (ret != M_PROPERTY_OK)
701 return ret;
702 if (mpctx->sh_audio)
703 mpctx->delay -= audio_delay - delay;
705 return M_PROPERTY_OK;
706 default:
707 return m_property_delay(prop, action, arg, &audio_delay);
711 /// Audio codec tag (RO)
712 static int mp_property_audio_format(m_option_t *prop, int action,
713 void *arg, MPContext *mpctx)
715 if (!mpctx->sh_audio)
716 return M_PROPERTY_UNAVAILABLE;
717 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
720 /// Audio codec name (RO)
721 static int mp_property_audio_codec(m_option_t *prop, int action,
722 void *arg, MPContext *mpctx)
724 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
725 return M_PROPERTY_UNAVAILABLE;
726 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
729 /// Audio bitrate (RO)
730 static int mp_property_audio_bitrate(m_option_t *prop, int action,
731 void *arg, MPContext *mpctx)
733 if (!mpctx->sh_audio)
734 return M_PROPERTY_UNAVAILABLE;
735 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
738 /// Samplerate (RO)
739 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
740 MPContext *mpctx)
742 if (!mpctx->sh_audio)
743 return M_PROPERTY_UNAVAILABLE;
744 switch(action) {
745 case M_PROPERTY_PRINT:
746 if(!arg) return M_PROPERTY_ERROR;
747 *(char**)arg = malloc(16);
748 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
749 return M_PROPERTY_OK;
751 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
754 /// Number of channels (RO)
755 static int mp_property_channels(m_option_t *prop, int action, void *arg,
756 MPContext *mpctx)
758 if (!mpctx->sh_audio)
759 return M_PROPERTY_UNAVAILABLE;
760 switch (action) {
761 case M_PROPERTY_PRINT:
762 if (!arg)
763 return M_PROPERTY_ERROR;
764 switch (mpctx->sh_audio->channels) {
765 case 1:
766 *(char **) arg = strdup("mono");
767 break;
768 case 2:
769 *(char **) arg = strdup("stereo");
770 break;
771 default:
772 *(char **) arg = malloc(32);
773 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
775 return M_PROPERTY_OK;
777 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
780 /// Balance (RW)
781 static int mp_property_balance(m_option_t *prop, int action, void *arg,
782 MPContext *mpctx)
784 float bal;
786 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
787 return M_PROPERTY_UNAVAILABLE;
789 switch (action) {
790 case M_PROPERTY_GET:
791 if (!arg)
792 return M_PROPERTY_ERROR;
793 mixer_getbalance(&mpctx->mixer, arg);
794 return M_PROPERTY_OK;
795 case M_PROPERTY_PRINT: {
796 char** str = arg;
797 if (!arg)
798 return M_PROPERTY_ERROR;
799 mixer_getbalance(&mpctx->mixer, &bal);
800 if (bal == 0.f)
801 *str = strdup("center");
802 else if (bal == -1.f)
803 *str = strdup("left only");
804 else if (bal == 1.f)
805 *str = strdup("right only");
806 else {
807 unsigned right = (bal + 1.f) / 2.f * 100.f;
808 *str = malloc(sizeof("left xxx%, right xxx%"));
809 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
811 return M_PROPERTY_OK;
813 case M_PROPERTY_STEP_UP:
814 case M_PROPERTY_STEP_DOWN:
815 mixer_getbalance(&mpctx->mixer, &bal);
816 bal += (arg ? *(float*)arg : .1f) *
817 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
818 M_PROPERTY_CLAMP(prop, bal);
819 mixer_setbalance(&mpctx->mixer, bal);
820 return M_PROPERTY_OK;
821 case M_PROPERTY_SET:
822 if (!arg)
823 return M_PROPERTY_ERROR;
824 M_PROPERTY_CLAMP(prop, *(float*)arg);
825 mixer_setbalance(&mpctx->mixer, *(float*)arg);
826 return M_PROPERTY_OK;
828 return M_PROPERTY_NOT_IMPLEMENTED;
831 /// Selected audio id (RW)
832 static int mp_property_audio(m_option_t *prop, int action, void *arg,
833 MPContext *mpctx)
835 struct MPOpts *opts = &mpctx->opts;
836 int current_id = -1, tmp;
838 switch (action) {
839 case M_PROPERTY_GET:
840 if (!mpctx->sh_audio)
841 return M_PROPERTY_UNAVAILABLE;
842 if (!arg)
843 return M_PROPERTY_ERROR;
844 *(int *) arg = opts->audio_id;
845 return M_PROPERTY_OK;
846 case M_PROPERTY_PRINT:
847 if (!mpctx->sh_audio)
848 return M_PROPERTY_UNAVAILABLE;
849 if (!arg)
850 return M_PROPERTY_ERROR;
852 if (opts->audio_id < 0)
853 *(char **) arg = strdup(_("disabled"));
854 else {
855 char lang[40] = _("unknown");
856 sh_audio_t* sh = mpctx->sh_audio;
857 if (sh && sh->lang)
858 av_strlcpy(lang, sh->lang, 40);
859 #ifdef CONFIG_DVDREAD
860 else if (mpctx->stream->type == STREAMTYPE_DVD) {
861 int code = dvd_lang_from_aid(mpctx->stream, opts->audio_id);
862 if (code) {
863 lang[0] = code >> 8;
864 lang[1] = code;
865 lang[2] = 0;
868 #endif
870 #ifdef CONFIG_DVDNAV
871 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
872 mp_dvdnav_lang_from_aid(mpctx->stream, opts->audio_id, lang);
873 #endif
874 *(char **) arg = malloc(64);
875 snprintf(*(char **) arg, 64, "(%d) %s", opts->audio_id, lang);
877 return M_PROPERTY_OK;
879 case M_PROPERTY_STEP_UP:
880 case M_PROPERTY_SET:
881 if (!mpctx->demuxer)
882 return M_PROPERTY_UNAVAILABLE;
883 if (action == M_PROPERTY_SET && arg)
884 tmp = *((int *) arg);
885 else
886 tmp = -1;
887 current_id = mpctx->demuxer->audio->id;
888 opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
889 if (opts->audio_id == -2
890 || (opts->audio_id > -1
891 && mpctx->demuxer->audio->id != current_id && current_id != -2))
892 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
893 if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
894 sh_audio_t *sh2;
895 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
896 if (sh2) {
897 sh2->ds = mpctx->demuxer->audio;
898 mpctx->sh_audio = sh2;
899 reinit_audio_chain(mpctx);
902 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id);
903 return M_PROPERTY_OK;
904 default:
905 return M_PROPERTY_NOT_IMPLEMENTED;
910 /// Selected video id (RW)
911 static int mp_property_video(m_option_t *prop, int action, void *arg,
912 MPContext *mpctx)
914 struct MPOpts *opts = &mpctx->opts;
915 int current_id = -1, tmp;
917 switch (action) {
918 case M_PROPERTY_GET:
919 if (!mpctx->sh_video)
920 return M_PROPERTY_UNAVAILABLE;
921 if (!arg)
922 return M_PROPERTY_ERROR;
923 *(int *) arg = opts->video_id;
924 return M_PROPERTY_OK;
925 case M_PROPERTY_PRINT:
926 if (!mpctx->sh_video)
927 return M_PROPERTY_UNAVAILABLE;
928 if (!arg)
929 return M_PROPERTY_ERROR;
931 if (opts->video_id < 0)
932 *(char **) arg = strdup(_("disabled"));
933 else {
934 char lang[40] = _("unknown");
935 *(char **) arg = malloc(64);
936 snprintf(*(char **) arg, 64, "(%d) %s", opts->video_id, lang);
938 return M_PROPERTY_OK;
940 case M_PROPERTY_STEP_UP:
941 case M_PROPERTY_SET:
942 current_id = mpctx->demuxer->video->id;
943 if (action == M_PROPERTY_SET && arg)
944 tmp = *((int *) arg);
945 else
946 tmp = -1;
947 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
948 if (opts->video_id == -2
949 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
950 && current_id != -2))
951 uninit_player(mpctx, INITIALIZED_VCODEC |
952 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
953 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
954 sh_video_t *sh2;
955 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
956 if (sh2) {
957 sh2->ds = mpctx->demuxer->video;
958 mpctx->sh_video = sh2;
959 reinit_video_chain(mpctx);
962 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
963 return M_PROPERTY_OK;
965 default:
966 return M_PROPERTY_NOT_IMPLEMENTED;
970 static int mp_property_program(m_option_t *prop, int action, void *arg,
971 MPContext *mpctx)
973 demux_program_t prog;
975 switch (action) {
976 case M_PROPERTY_STEP_UP:
977 case M_PROPERTY_SET:
978 if (action == M_PROPERTY_SET && arg)
979 prog.progid = *((int *) arg);
980 else
981 prog.progid = -1;
982 if (demux_control
983 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
984 &prog) == DEMUXER_CTRL_NOTIMPL)
985 return M_PROPERTY_ERROR;
987 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
988 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
989 return M_PROPERTY_OK;
991 default:
992 return M_PROPERTY_NOT_IMPLEMENTED;
996 ///@}
998 /// \defgroup VideoProperties Video properties
999 /// \ingroup Properties
1000 ///@{
1002 /// Fullscreen state (RW)
1003 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1004 MPContext *mpctx)
1007 if (!mpctx->video_out)
1008 return M_PROPERTY_UNAVAILABLE;
1010 switch (action) {
1011 case M_PROPERTY_SET:
1012 if (!arg)
1013 return M_PROPERTY_ERROR;
1014 M_PROPERTY_CLAMP(prop, *(int *) arg);
1015 if (vo_fs == !!*(int *) arg)
1016 return M_PROPERTY_OK;
1017 case M_PROPERTY_STEP_UP:
1018 case M_PROPERTY_STEP_DOWN:
1019 if (mpctx->video_out->config_ok)
1020 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1021 mpctx->opts.fullscreen = vo_fs;
1022 return M_PROPERTY_OK;
1023 default:
1024 return m_property_flag(prop, action, arg, &vo_fs);
1028 static int mp_property_deinterlace(m_option_t *prop, int action,
1029 void *arg, MPContext *mpctx)
1031 int deinterlace;
1032 vf_instance_t *vf;
1033 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1034 return M_PROPERTY_UNAVAILABLE;
1035 vf = mpctx->sh_video->vfilter;
1036 switch (action) {
1037 case M_PROPERTY_GET:
1038 if (!arg)
1039 return M_PROPERTY_ERROR;
1040 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1041 return M_PROPERTY_OK;
1042 case M_PROPERTY_SET:
1043 if (!arg)
1044 return M_PROPERTY_ERROR;
1045 M_PROPERTY_CLAMP(prop, *(int *) arg);
1046 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1047 return M_PROPERTY_OK;
1048 case M_PROPERTY_STEP_UP:
1049 case M_PROPERTY_STEP_DOWN:
1050 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1051 deinterlace = !deinterlace;
1052 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1053 return M_PROPERTY_OK;
1055 return M_PROPERTY_NOT_IMPLEMENTED;
1058 /// Panscan (RW)
1059 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1060 MPContext *mpctx)
1063 if (!mpctx->video_out
1064 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1065 return M_PROPERTY_UNAVAILABLE;
1067 switch (action) {
1068 case M_PROPERTY_SET:
1069 if (!arg)
1070 return M_PROPERTY_ERROR;
1071 M_PROPERTY_CLAMP(prop, *(float *) arg);
1072 vo_panscan = *(float *) arg;
1073 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1074 return M_PROPERTY_OK;
1075 case M_PROPERTY_STEP_UP:
1076 case M_PROPERTY_STEP_DOWN:
1077 vo_panscan += (arg ? *(float *) arg : 0.1) *
1078 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1079 if (vo_panscan > 1)
1080 vo_panscan = 1;
1081 else if (vo_panscan < 0)
1082 vo_panscan = 0;
1083 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1084 return M_PROPERTY_OK;
1085 default:
1086 return m_property_float_range(prop, action, arg, &vo_panscan);
1090 /// Helper to set vo flags.
1091 /** \ingroup PropertyImplHelper
1093 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1094 int vo_ctrl, int *vo_var, MPContext *mpctx)
1097 if (!mpctx->video_out)
1098 return M_PROPERTY_UNAVAILABLE;
1100 switch (action) {
1101 case M_PROPERTY_SET:
1102 if (!arg)
1103 return M_PROPERTY_ERROR;
1104 M_PROPERTY_CLAMP(prop, *(int *) arg);
1105 if (*vo_var == !!*(int *) arg)
1106 return M_PROPERTY_OK;
1107 case M_PROPERTY_STEP_UP:
1108 case M_PROPERTY_STEP_DOWN:
1109 if (mpctx->video_out->config_ok)
1110 vo_control(mpctx->video_out, vo_ctrl, 0);
1111 return M_PROPERTY_OK;
1112 default:
1113 return m_property_flag(prop, action, arg, vo_var);
1117 /// Window always on top (RW)
1118 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1119 MPContext *mpctx)
1121 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1122 &mpctx->opts.vo_ontop, mpctx);
1125 /// Display in the root window (RW)
1126 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1127 MPContext *mpctx)
1129 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1130 &vo_rootwin, mpctx);
1133 /// Show window borders (RW)
1134 static int mp_property_border(m_option_t *prop, int action, void *arg,
1135 MPContext *mpctx)
1137 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1138 &vo_border, mpctx);
1141 /// Framedropping state (RW)
1142 static int mp_property_framedropping(m_option_t *prop, int action,
1143 void *arg, MPContext *mpctx)
1146 if (!mpctx->sh_video)
1147 return M_PROPERTY_UNAVAILABLE;
1149 switch (action) {
1150 case M_PROPERTY_PRINT:
1151 if (!arg)
1152 return M_PROPERTY_ERROR;
1153 *(char **) arg = strdup(frame_dropping == 1 ? _("enabled") :
1154 (frame_dropping == 2 ? _("hard") :
1155 _("disabled")));
1156 return M_PROPERTY_OK;
1157 default:
1158 return m_property_choice(prop, action, arg, &frame_dropping);
1162 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1163 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1164 MPContext *mpctx)
1166 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1167 int r, val;
1169 if (!mpctx->sh_video)
1170 return M_PROPERTY_UNAVAILABLE;
1172 if (gamma[0] == 1000) {
1173 gamma[0] = 0;
1174 get_video_colors(mpctx->sh_video, prop->name, gamma);
1177 switch (action) {
1178 case M_PROPERTY_SET:
1179 if (!arg)
1180 return M_PROPERTY_ERROR;
1181 M_PROPERTY_CLAMP(prop, *(int *) arg);
1182 *gamma = *(int *) arg;
1183 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1184 if (r <= 0)
1185 break;
1186 return r;
1187 case M_PROPERTY_GET:
1188 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1189 if (!arg)
1190 return M_PROPERTY_ERROR;
1191 *(int *)arg = val;
1192 return M_PROPERTY_OK;
1194 break;
1195 case M_PROPERTY_STEP_UP:
1196 case M_PROPERTY_STEP_DOWN:
1197 *gamma += (arg ? *(int *) arg : 1) *
1198 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1199 M_PROPERTY_CLAMP(prop, *gamma);
1200 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1201 if (r <= 0)
1202 break;
1203 return r;
1204 default:
1205 return M_PROPERTY_NOT_IMPLEMENTED;
1208 #ifdef CONFIG_TV
1209 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1210 int l = strlen(prop->name);
1211 char tv_prop[3 + l + 1];
1212 sprintf(tv_prop, "tv_%s", prop->name);
1213 return mp_property_do(tv_prop, action, arg, mpctx);
1215 #endif
1217 return M_PROPERTY_UNAVAILABLE;
1220 /// VSync (RW)
1221 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1222 MPContext *mpctx)
1224 return m_property_flag(prop, action, arg, &vo_vsync);
1227 /// Video codec tag (RO)
1228 static int mp_property_video_format(m_option_t *prop, int action,
1229 void *arg, MPContext *mpctx)
1231 char* meta;
1232 if (!mpctx->sh_video)
1233 return M_PROPERTY_UNAVAILABLE;
1234 switch(action) {
1235 case M_PROPERTY_PRINT:
1236 if (!arg)
1237 return M_PROPERTY_ERROR;
1238 switch(mpctx->sh_video->format) {
1239 case 0x10000001:
1240 meta = strdup ("mpeg1"); break;
1241 case 0x10000002:
1242 meta = strdup ("mpeg2"); break;
1243 case 0x10000004:
1244 meta = strdup ("mpeg4"); break;
1245 case 0x10000005:
1246 meta = strdup ("h264"); break;
1247 default:
1248 if(mpctx->sh_video->format >= 0x20202020) {
1249 meta = malloc(5);
1250 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1251 } else {
1252 meta = malloc(20);
1253 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1256 *(char**)arg = meta;
1257 return M_PROPERTY_OK;
1259 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1262 /// Video codec name (RO)
1263 static int mp_property_video_codec(m_option_t *prop, int action,
1264 void *arg, MPContext *mpctx)
1266 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1267 return M_PROPERTY_UNAVAILABLE;
1268 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1272 /// Video bitrate (RO)
1273 static int mp_property_video_bitrate(m_option_t *prop, int action,
1274 void *arg, MPContext *mpctx)
1276 if (!mpctx->sh_video)
1277 return M_PROPERTY_UNAVAILABLE;
1278 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1281 /// Video display width (RO)
1282 static int mp_property_width(m_option_t *prop, int action, void *arg,
1283 MPContext *mpctx)
1285 if (!mpctx->sh_video)
1286 return M_PROPERTY_UNAVAILABLE;
1287 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1290 /// Video display height (RO)
1291 static int mp_property_height(m_option_t *prop, int action, void *arg,
1292 MPContext *mpctx)
1294 if (!mpctx->sh_video)
1295 return M_PROPERTY_UNAVAILABLE;
1296 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1299 /// Video fps (RO)
1300 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1301 MPContext *mpctx)
1303 if (!mpctx->sh_video)
1304 return M_PROPERTY_UNAVAILABLE;
1305 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1308 /// Video aspect (RO)
1309 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1310 MPContext *mpctx)
1312 if (!mpctx->sh_video)
1313 return M_PROPERTY_UNAVAILABLE;
1314 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1317 ///@}
1319 /// \defgroup SubProprties Subtitles properties
1320 /// \ingroup Properties
1321 ///@{
1323 /// Text subtitle position (RW)
1324 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1325 MPContext *mpctx)
1327 if (!mpctx->sh_video)
1328 return M_PROPERTY_UNAVAILABLE;
1330 switch (action) {
1331 case M_PROPERTY_SET:
1332 if (!arg)
1333 return M_PROPERTY_ERROR;
1334 case M_PROPERTY_STEP_UP:
1335 case M_PROPERTY_STEP_DOWN:
1336 vo_osd_changed(OSDTYPE_SUBTITLE);
1337 default:
1338 return m_property_int_range(prop, action, arg, &sub_pos);
1342 /// Selected subtitles (RW)
1343 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1344 MPContext *mpctx)
1346 struct MPOpts *opts = &mpctx->opts;
1347 demux_stream_t *const d_sub = mpctx->d_sub;
1348 const int global_sub_size = mpctx->global_sub_size;
1349 int source = -1, reset_spu = 0;
1350 char *sub_name;
1352 if (!mpctx->sh_video || global_sub_size <= 0)
1353 return M_PROPERTY_UNAVAILABLE;
1355 switch (action) {
1356 case M_PROPERTY_GET:
1357 if (!arg)
1358 return M_PROPERTY_ERROR;
1359 *(int *) arg = mpctx->global_sub_pos;
1360 return M_PROPERTY_OK;
1361 case M_PROPERTY_PRINT:
1362 if (!arg)
1363 return M_PROPERTY_ERROR;
1364 *(char **) arg = malloc(64);
1365 (*(char **) arg)[63] = 0;
1366 sub_name = 0;
1367 if (subdata)
1368 sub_name = subdata->filename;
1369 #ifdef CONFIG_ASS
1370 if (ass_track && ass_track->name)
1371 sub_name = ass_track->name;
1372 #endif
1373 if (sub_name) {
1374 char *tmp, *tmp2;
1375 tmp = sub_name;
1376 if ((tmp2 = strrchr(tmp, '/')))
1377 tmp = tmp2 + 1;
1379 snprintf(*(char **) arg, 63, "(%d) %s%s",
1380 mpctx->set_of_sub_pos + 1,
1381 strlen(tmp) < 20 ? "" : "...",
1382 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1383 return M_PROPERTY_OK;
1385 #ifdef CONFIG_DVDNAV
1386 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1387 if (vo_spudec && opts->sub_id >= 0) {
1388 unsigned char lang[3];
1389 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1390 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1391 return M_PROPERTY_OK;
1395 #endif
1397 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1398 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1399 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1400 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1401 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1402 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1403 if (!lang) lang = _("unknown");
1404 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1405 return M_PROPERTY_OK;
1408 if (vo_vobsub && vobsub_id >= 0) {
1409 const char *language = _("unknown");
1410 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1411 snprintf(*(char **) arg, 63, "(%d) %s",
1412 vobsub_id, language ? language : _("unknown"));
1413 return M_PROPERTY_OK;
1415 #ifdef CONFIG_DVDREAD
1416 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1417 && opts->sub_id >= 0) {
1418 char lang[3];
1419 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1420 lang[0] = code >> 8;
1421 lang[1] = code;
1422 lang[2] = 0;
1423 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1424 return M_PROPERTY_OK;
1426 #endif
1427 if (opts->sub_id >= 0) {
1428 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, _("unknown"));
1429 return M_PROPERTY_OK;
1431 snprintf(*(char **) arg, 63, _("disabled"));
1432 return M_PROPERTY_OK;
1434 case M_PROPERTY_SET:
1435 if (!arg)
1436 return M_PROPERTY_ERROR;
1437 if (*(int *) arg < -1)
1438 *(int *) arg = -1;
1439 else if (*(int *) arg >= global_sub_size)
1440 *(int *) arg = global_sub_size - 1;
1441 mpctx->global_sub_pos = *(int *) arg;
1442 break;
1443 case M_PROPERTY_STEP_UP:
1444 mpctx->global_sub_pos += 2;
1445 mpctx->global_sub_pos =
1446 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1447 break;
1448 case M_PROPERTY_STEP_DOWN:
1449 mpctx->global_sub_pos += global_sub_size + 1;
1450 mpctx->global_sub_pos =
1451 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1452 break;
1453 default:
1454 return M_PROPERTY_NOT_IMPLEMENTED;
1457 if (mpctx->global_sub_pos >= 0)
1458 source = sub_source(mpctx);
1460 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1461 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1462 global_sub_size,
1463 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1464 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1465 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1466 mpctx->global_sub_pos, source);
1468 mpctx->set_of_sub_pos = -1;
1469 subdata = NULL;
1471 vobsub_id = -1;
1472 opts->sub_id = -1;
1473 if (d_sub) {
1474 if (d_sub->id > -2)
1475 reset_spu = 1;
1476 d_sub->id = -2;
1478 #ifdef CONFIG_ASS
1479 ass_track = 0;
1480 #endif
1482 if (source == SUB_SOURCE_VOBSUB) {
1483 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1484 } else if (source == SUB_SOURCE_SUBS) {
1485 mpctx->set_of_sub_pos =
1486 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1487 #ifdef CONFIG_ASS
1488 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1489 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1490 else
1491 #endif
1493 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1494 vo_osd_changed(OSDTYPE_SUBTITLE);
1496 } else if (source == SUB_SOURCE_DEMUX) {
1497 opts->sub_id =
1498 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1499 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1500 int i = 0;
1501 // default: assume 1:1 mapping of sid and stream id
1502 d_sub->id = opts->sub_id;
1503 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1504 ds_free_packs(d_sub);
1505 for (i = 0; i < MAX_S_STREAMS; i++) {
1506 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1507 if (sh && sh->sid == opts->sub_id) {
1508 d_sub->id = i;
1509 d_sub->sh = sh;
1510 break;
1513 if (d_sub->sh && d_sub->id >= 0) {
1514 sh_sub_t *sh = d_sub->sh;
1515 if (sh->type == 'v')
1516 init_vo_spudec(mpctx);
1517 #ifdef CONFIG_ASS
1518 else if (ass_enabled)
1519 ass_track = sh->ass_track;
1520 #endif
1521 } else {
1522 d_sub->id = -2;
1523 d_sub->sh = NULL;
1527 #ifdef CONFIG_DVDREAD
1528 if (vo_spudec
1529 && (mpctx->stream->type == STREAMTYPE_DVD
1530 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1531 && opts->sub_id < 0 && reset_spu) {
1532 opts->sub_id = -2;
1533 d_sub->id = opts->sub_id;
1535 #endif
1536 update_subtitles(mpctx->sh_video, d_sub, 0, 1);
1538 return M_PROPERTY_OK;
1541 /// Selected sub source (RW)
1542 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1543 MPContext *mpctx)
1545 int source;
1546 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1547 return M_PROPERTY_UNAVAILABLE;
1549 switch (action) {
1550 case M_PROPERTY_GET:
1551 if (!arg)
1552 return M_PROPERTY_ERROR;
1553 *(int *) arg = sub_source(mpctx);
1554 return M_PROPERTY_OK;
1555 case M_PROPERTY_PRINT:
1556 if (!arg)
1557 return M_PROPERTY_ERROR;
1558 *(char **) arg = malloc(64);
1559 (*(char **) arg)[63] = 0;
1560 switch (sub_source(mpctx))
1562 case SUB_SOURCE_SUBS:
1563 snprintf(*(char **) arg, 63, _("file"));
1564 break;
1565 case SUB_SOURCE_VOBSUB:
1566 snprintf(*(char **) arg, 63, _("vobsub"));
1567 break;
1568 case SUB_SOURCE_DEMUX:
1569 snprintf(*(char **) arg, 63, _("embedded"));
1570 break;
1571 default:
1572 snprintf(*(char **) arg, 63, _("disabled"));
1574 return M_PROPERTY_OK;
1575 case M_PROPERTY_SET:
1576 if (!arg)
1577 return M_PROPERTY_ERROR;
1578 M_PROPERTY_CLAMP(prop, *(int*)arg);
1579 if (*(int *) arg < 0)
1580 mpctx->global_sub_pos = -1;
1581 else if (*(int *) arg != sub_source(mpctx)) {
1582 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1583 return M_PROPERTY_UNAVAILABLE;
1584 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1586 break;
1587 case M_PROPERTY_STEP_UP:
1588 case M_PROPERTY_STEP_DOWN: {
1589 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1590 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1591 int step = (step_all > 0) ? 1 : -1;
1592 int cur_source = sub_source(mpctx);
1593 source = cur_source;
1594 while (step_all) {
1595 source += step;
1596 if (source >= SUB_SOURCES)
1597 source = -1;
1598 else if (source < -1)
1599 source = SUB_SOURCES - 1;
1600 if (source == cur_source || source == -1 ||
1601 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1602 step_all -= step;
1604 if (source == cur_source)
1605 return M_PROPERTY_OK;
1606 if (source == -1)
1607 mpctx->global_sub_pos = -1;
1608 else
1609 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1610 break;
1612 default:
1613 return M_PROPERTY_NOT_IMPLEMENTED;
1615 --mpctx->global_sub_pos;
1616 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1619 /// Selected subtitles from specific source (RW)
1620 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1621 MPContext *mpctx)
1623 int source, is_cur_source, offset;
1624 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1625 return M_PROPERTY_UNAVAILABLE;
1627 if (!strcmp(prop->name, "sub_file"))
1628 source = SUB_SOURCE_SUBS;
1629 else if (!strcmp(prop->name, "sub_vob"))
1630 source = SUB_SOURCE_VOBSUB;
1631 else if (!strcmp(prop->name, "sub_demux"))
1632 source = SUB_SOURCE_DEMUX;
1633 else
1634 return M_PROPERTY_ERROR;
1636 offset = mpctx->global_sub_indices[source];
1637 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1638 return M_PROPERTY_UNAVAILABLE;
1640 is_cur_source = sub_source(mpctx) == source;
1641 switch (action) {
1642 case M_PROPERTY_GET:
1643 if (!arg)
1644 return M_PROPERTY_ERROR;
1645 if (is_cur_source) {
1646 *(int *) arg = mpctx->global_sub_pos - offset;
1647 if (source == SUB_SOURCE_VOBSUB)
1648 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1650 else
1651 *(int *) arg = -1;
1652 return M_PROPERTY_OK;
1653 case M_PROPERTY_PRINT:
1654 if (!arg)
1655 return M_PROPERTY_ERROR;
1656 if (is_cur_source)
1657 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1658 *(char **) arg = malloc(64);
1659 (*(char **) arg)[63] = 0;
1660 snprintf(*(char **) arg, 63, _("disabled"));
1661 return M_PROPERTY_OK;
1662 case M_PROPERTY_SET:
1663 if (!arg)
1664 return M_PROPERTY_ERROR;
1665 if (*(int *) arg >= 0) {
1666 int index = *(int *)arg;
1667 if (source == SUB_SOURCE_VOBSUB)
1668 index = vobsub_get_index_by_id(vo_vobsub, index);
1669 mpctx->global_sub_pos = offset + index;
1670 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1671 || sub_source(mpctx) != source) {
1672 mpctx->global_sub_pos = -1;
1673 *(int *) arg = -1;
1676 else
1677 mpctx->global_sub_pos = -1;
1678 break;
1679 case M_PROPERTY_STEP_UP:
1680 case M_PROPERTY_STEP_DOWN: {
1681 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1682 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1683 int step = (step_all > 0) ? 1 : -1;
1684 int max_sub_pos_for_source = -1;
1685 if (!is_cur_source)
1686 mpctx->global_sub_pos = -1;
1687 while (step_all) {
1688 if (mpctx->global_sub_pos == -1) {
1689 if (step > 0)
1690 mpctx->global_sub_pos = offset;
1691 else if (max_sub_pos_for_source == -1) {
1692 // Find max pos for specific source
1693 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1694 while (mpctx->global_sub_pos >= 0
1695 && sub_source(mpctx) != source)
1696 --mpctx->global_sub_pos;
1698 else
1699 mpctx->global_sub_pos = max_sub_pos_for_source;
1701 else {
1702 mpctx->global_sub_pos += step;
1703 if (mpctx->global_sub_pos < offset ||
1704 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1705 sub_source(mpctx) != source)
1706 mpctx->global_sub_pos = -1;
1708 step_all -= step;
1710 break;
1712 default:
1713 return M_PROPERTY_NOT_IMPLEMENTED;
1715 --mpctx->global_sub_pos;
1716 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1719 /// Subtitle delay (RW)
1720 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1721 MPContext *mpctx)
1723 if (!mpctx->sh_video)
1724 return M_PROPERTY_UNAVAILABLE;
1725 return m_property_delay(prop, action, arg, &sub_delay);
1728 /// Alignment of text subtitles (RW)
1729 static int mp_property_sub_alignment(m_option_t *prop, int action,
1730 void *arg, MPContext *mpctx)
1732 char *name[] = { _("top"), _("center"), _("bottom") };
1734 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1735 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1736 return M_PROPERTY_UNAVAILABLE;
1738 switch (action) {
1739 case M_PROPERTY_PRINT:
1740 if (!arg)
1741 return M_PROPERTY_ERROR;
1742 M_PROPERTY_CLAMP(prop, sub_alignment);
1743 *(char **) arg = strdup(name[sub_alignment]);
1744 return M_PROPERTY_OK;
1745 case M_PROPERTY_SET:
1746 if (!arg)
1747 return M_PROPERTY_ERROR;
1748 case M_PROPERTY_STEP_UP:
1749 case M_PROPERTY_STEP_DOWN:
1750 vo_osd_changed(OSDTYPE_SUBTITLE);
1751 default:
1752 return m_property_choice(prop, action, arg, &sub_alignment);
1756 /// Subtitle visibility (RW)
1757 static int mp_property_sub_visibility(m_option_t *prop, int action,
1758 void *arg, MPContext *mpctx)
1760 if (!mpctx->sh_video)
1761 return M_PROPERTY_UNAVAILABLE;
1763 switch (action) {
1764 case M_PROPERTY_SET:
1765 if (!arg)
1766 return M_PROPERTY_ERROR;
1767 case M_PROPERTY_STEP_UP:
1768 case M_PROPERTY_STEP_DOWN:
1769 vo_osd_changed(OSDTYPE_SUBTITLE);
1770 if (vo_spudec)
1771 vo_osd_changed(OSDTYPE_SPU);
1772 default:
1773 return m_property_flag(prop, action, arg, &sub_visibility);
1777 #ifdef CONFIG_ASS
1778 /// Use margins for libass subtitles (RW)
1779 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1780 void *arg, MPContext *mpctx)
1782 if (!mpctx->sh_video)
1783 return M_PROPERTY_UNAVAILABLE;
1785 switch (action) {
1786 case M_PROPERTY_SET:
1787 if (!arg)
1788 return M_PROPERTY_ERROR;
1789 case M_PROPERTY_STEP_UP:
1790 case M_PROPERTY_STEP_DOWN:
1791 ass_force_reload = 1;
1792 default:
1793 return m_property_flag(prop, action, arg, &ass_use_margins);
1796 #endif
1798 /// Show only forced subtitles (RW)
1799 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1800 void *arg, MPContext *mpctx)
1802 if (!vo_spudec)
1803 return M_PROPERTY_UNAVAILABLE;
1805 switch (action) {
1806 case M_PROPERTY_SET:
1807 if (!arg)
1808 return M_PROPERTY_ERROR;
1809 case M_PROPERTY_STEP_UP:
1810 case M_PROPERTY_STEP_DOWN:
1811 m_property_flag(prop, action, arg, &forced_subs_only);
1812 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1813 return M_PROPERTY_OK;
1814 default:
1815 return m_property_flag(prop, action, arg, &forced_subs_only);
1820 #ifdef CONFIG_FREETYPE
1821 /// Subtitle scale (RW)
1822 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1823 MPContext *mpctx)
1826 switch (action) {
1827 case M_PROPERTY_SET:
1828 if (!arg)
1829 return M_PROPERTY_ERROR;
1830 M_PROPERTY_CLAMP(prop, *(float *) arg);
1831 #ifdef CONFIG_ASS
1832 if (ass_enabled) {
1833 ass_font_scale = *(float *) arg;
1834 ass_force_reload = 1;
1836 #endif
1837 text_font_scale_factor = *(float *) arg;
1838 force_load_font = 1;
1839 return M_PROPERTY_OK;
1840 case M_PROPERTY_STEP_UP:
1841 case M_PROPERTY_STEP_DOWN:
1842 #ifdef CONFIG_ASS
1843 if (ass_enabled) {
1844 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1845 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1846 M_PROPERTY_CLAMP(prop, ass_font_scale);
1847 ass_force_reload = 1;
1849 #endif
1850 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1851 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1852 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1853 force_load_font = 1;
1854 return M_PROPERTY_OK;
1855 default:
1856 #ifdef CONFIG_ASS
1857 if (ass_enabled)
1858 return m_property_float_ro(prop, action, arg, ass_font_scale);
1859 else
1860 #endif
1861 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1864 #endif
1866 ///@}
1868 /// \defgroup TVProperties TV properties
1869 /// \ingroup Properties
1870 ///@{
1872 #ifdef CONFIG_TV
1874 /// TV color settings (RW)
1875 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1876 MPContext *mpctx)
1878 int r, val;
1879 tvi_handle_t *tvh = mpctx->demuxer->priv;
1880 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1881 return M_PROPERTY_UNAVAILABLE;
1883 switch (action) {
1884 case M_PROPERTY_SET:
1885 if (!arg)
1886 return M_PROPERTY_ERROR;
1887 M_PROPERTY_CLAMP(prop, *(int *) arg);
1888 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1889 case M_PROPERTY_GET:
1890 return tv_get_color_options(tvh, (int) prop->priv, arg);
1891 case M_PROPERTY_STEP_UP:
1892 case M_PROPERTY_STEP_DOWN:
1893 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1894 if (!r)
1895 return M_PROPERTY_ERROR;
1896 val += (arg ? *(int *) arg : 1) *
1897 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1898 M_PROPERTY_CLAMP(prop, val);
1899 return tv_set_color_options(tvh, (int) prop->priv, val);
1901 return M_PROPERTY_ERROR;
1903 return M_PROPERTY_NOT_IMPLEMENTED;
1906 #endif
1908 #ifdef CONFIG_TV_TELETEXT
1909 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1910 MPContext *mpctx)
1912 int val,result;
1913 int base_ioctl=(int)prop->priv;
1915 for teletext's GET,SET,STEP ioctls this is not 0
1916 SET is GET+1
1917 STEP is GET+2
1919 tvi_handle_t *tvh = mpctx->demuxer->priv;
1920 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1921 return M_PROPERTY_UNAVAILABLE;
1922 if(!base_ioctl)
1923 return M_PROPERTY_ERROR;
1925 switch (action) {
1926 case M_PROPERTY_GET:
1927 if (!arg)
1928 return M_PROPERTY_ERROR;
1929 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1930 break;
1931 case M_PROPERTY_SET:
1932 if (!arg)
1933 return M_PROPERTY_ERROR;
1934 M_PROPERTY_CLAMP(prop, *(int *) arg);
1935 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1936 break;
1937 case M_PROPERTY_STEP_UP:
1938 case M_PROPERTY_STEP_DOWN:
1939 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1940 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1941 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1942 break;
1943 default:
1944 return M_PROPERTY_NOT_IMPLEMENTED;
1947 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1950 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
1951 MPContext *mpctx)
1953 tvi_handle_t *tvh = mpctx->demuxer->priv;
1954 int result;
1955 int val;
1957 //with tvh==NULL will fail too
1958 result=mp_property_teletext_common(prop,action,arg,mpctx);
1959 if(result!=M_PROPERTY_OK)
1960 return result;
1962 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1963 mp_input_set_section(mpctx->input, "teletext");
1964 else
1965 mp_input_set_section(mpctx->input, "tv");
1966 return M_PROPERTY_OK;
1969 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
1970 MPContext *mpctx)
1972 tvi_handle_t *tvh = mpctx->demuxer->priv;
1973 int result;
1974 int val;
1975 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1976 return M_PROPERTY_UNAVAILABLE;
1977 switch(action){
1978 case M_PROPERTY_STEP_UP:
1979 case M_PROPERTY_STEP_DOWN:
1980 //This should be handled separately
1981 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1982 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1983 break;
1984 default:
1985 result=mp_property_teletext_common(prop,action,arg,mpctx);
1987 return result;
1991 #endif /* CONFIG_TV_TELETEXT */
1993 ///@}
1995 /// All properties available in MPlayer.
1996 /** \ingroup Properties
1998 static const m_option_t mp_properties[] = {
1999 // General
2000 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2001 M_OPT_RANGE, 0, 3, NULL },
2002 { "loop", mp_property_loop, CONF_TYPE_INT,
2003 M_OPT_MIN, -1, 0, NULL },
2004 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2005 M_OPT_RANGE, 0.01, 100.0, NULL },
2006 { "filename", mp_property_filename, CONF_TYPE_STRING,
2007 0, 0, 0, NULL },
2008 { "path", mp_property_path, CONF_TYPE_STRING,
2009 0, 0, 0, NULL },
2010 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2011 0, 0, 0, NULL },
2012 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2013 M_OPT_MIN, 0, 0, NULL },
2014 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2015 M_OPT_MIN, 0, 0, NULL },
2016 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2017 M_OPT_MIN, 0, 0, NULL },
2018 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2019 M_OPT_MIN, 0, 0, NULL },
2020 { "length", mp_property_length, CONF_TYPE_TIME,
2021 M_OPT_MIN, 0, 0, NULL },
2022 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2023 M_OPT_RANGE, 0, 100, NULL },
2024 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2025 M_OPT_MIN, 0, 0, NULL },
2026 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2027 M_OPT_MIN, 0, 0, NULL },
2028 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2029 0, 0, 0, NULL },
2030 { "angle", mp_property_angle, CONF_TYPE_INT,
2031 CONF_RANGE, -2, 10, NULL },
2032 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2033 0, 0, 0, NULL },
2034 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2035 M_OPT_RANGE, 0, 1, NULL },
2037 // Audio
2038 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2039 M_OPT_RANGE, 0, 100, NULL },
2040 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2041 M_OPT_RANGE, 0, 1, NULL },
2042 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2043 M_OPT_RANGE, -100, 100, NULL },
2044 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2045 0, 0, 0, NULL },
2046 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2047 0, 0, 0, NULL },
2048 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2049 0, 0, 0, NULL },
2050 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2051 0, 0, 0, NULL },
2052 { "channels", mp_property_channels, CONF_TYPE_INT,
2053 0, 0, 0, NULL },
2054 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2055 CONF_RANGE, -2, 65535, NULL },
2056 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2057 M_OPT_RANGE, -1, 1, NULL },
2059 // Video
2060 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2061 M_OPT_RANGE, 0, 1, NULL },
2062 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2063 M_OPT_RANGE, 0, 1, NULL },
2064 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2065 M_OPT_RANGE, 0, 1, NULL },
2066 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2067 M_OPT_RANGE, 0, 1, NULL },
2068 { "border", mp_property_border, CONF_TYPE_FLAG,
2069 M_OPT_RANGE, 0, 1, NULL },
2070 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2071 M_OPT_RANGE, 0, 2, NULL },
2072 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2073 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2074 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2075 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2076 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2077 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2078 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2079 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2080 { "hue", mp_property_gamma, CONF_TYPE_INT,
2081 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2082 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2083 M_OPT_RANGE, 0, 1, NULL },
2084 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2085 M_OPT_RANGE, 0, 1, NULL },
2086 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2087 0, 0, 0, NULL },
2088 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2089 0, 0, 0, NULL },
2090 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2091 0, 0, 0, NULL },
2092 { "width", mp_property_width, CONF_TYPE_INT,
2093 0, 0, 0, NULL },
2094 { "height", mp_property_height, CONF_TYPE_INT,
2095 0, 0, 0, NULL },
2096 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2097 0, 0, 0, NULL },
2098 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2099 0, 0, 0, NULL },
2100 { "switch_video", mp_property_video, CONF_TYPE_INT,
2101 CONF_RANGE, -2, 65535, NULL },
2102 { "switch_program", mp_property_program, CONF_TYPE_INT,
2103 CONF_RANGE, -1, 65535, NULL },
2105 // Subs
2106 { "sub", mp_property_sub, CONF_TYPE_INT,
2107 M_OPT_MIN, -1, 0, NULL },
2108 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2109 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2110 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2111 M_OPT_MIN, -1, 0, NULL },
2112 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2113 M_OPT_MIN, -1, 0, NULL },
2114 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2115 M_OPT_MIN, -1, 0, NULL },
2116 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2117 0, 0, 0, NULL },
2118 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2119 M_OPT_RANGE, 0, 100, NULL },
2120 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2121 M_OPT_RANGE, 0, 2, NULL },
2122 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2123 M_OPT_RANGE, 0, 1, NULL },
2124 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2125 M_OPT_RANGE, 0, 1, NULL },
2126 #ifdef CONFIG_FREETYPE
2127 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2128 M_OPT_RANGE, 0, 100, NULL },
2129 #endif
2130 #ifdef CONFIG_ASS
2131 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2132 M_OPT_RANGE, 0, 1, NULL },
2133 #endif
2135 #ifdef CONFIG_TV
2136 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2137 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2138 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2139 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2140 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2141 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2142 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2143 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2144 #endif
2146 #ifdef CONFIG_TV_TELETEXT
2147 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2148 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2149 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2150 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2151 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2152 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2153 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2154 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2155 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2156 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2157 #endif
2159 { NULL, NULL, NULL, 0, 0, 0, NULL }
2163 int mp_property_do(const char *name, int action, void *val, void *ctx)
2165 return m_property_do(mp_properties, name, action, val, ctx);
2168 char* mp_property_print(const char *name, void* ctx)
2170 char* ret = NULL;
2171 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2172 return NULL;
2173 return ret;
2176 char *property_expand_string(MPContext *mpctx, char *str)
2178 return m_properties_expand_string(mp_properties, str, mpctx);
2181 void property_print_help(void)
2183 m_properties_print_help_list(mp_properties);
2187 ///@}
2188 // Properties group
2192 * \defgroup Command2Property Command to property bridge
2194 * It is used to handle most commands that just set a property
2195 * and optionally display something on the OSD.
2196 * Two kinds of commands are handled: adjust or toggle.
2198 * Adjust commands take 1 or 2 parameters: <value> <abs>
2199 * If <abs> is non-zero the property is set to the given value
2200 * otherwise it is adjusted.
2202 * Toggle commands take 0 or 1 parameters. With no parameter
2203 * or a value less than the property minimum it just steps the
2204 * property to its next value. Otherwise it sets it to the given
2205 * value.
2210 /// List of the commands that can be handled by setting a property.
2211 static struct {
2212 /// property name
2213 const char *name;
2214 /// cmd id
2215 int cmd;
2216 /// set/adjust or toggle command
2217 int toggle;
2218 /// progressbar type
2219 int osd_progbar; // -1 is special value for seek indicators
2220 /// osd msg id if it must be shared
2221 int osd_id;
2222 /// osd msg template
2223 const char *osd_msg;
2224 } set_prop_cmd[] = {
2225 // general
2226 { "loop", MP_CMD_LOOP, 0, 0, -1, _("Loop: %s") },
2227 { "chapter", MP_CMD_SEEK_CHAPTER, 0, -1, -1, NULL },
2228 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2229 { "pause", MP_CMD_PAUSE, 0, 0, -1, NULL },
2230 // audio
2231 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, _("Volume") },
2232 { "mute", MP_CMD_MUTE, 1, 0, -1, _("Mute: %s") },
2233 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, _("A-V delay: %s") },
2234 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, _("Audio: %s") },
2235 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, _("Balance") },
2236 // video
2237 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2238 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, _("Panscan") },
2239 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, _("Stay on top: %s") },
2240 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, _("Rootwin: %s") },
2241 { "border", MP_CMD_VO_BORDER, 1, 0, -1, _("Border: %s") },
2242 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, _("Framedropping: %s") },
2243 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, _("Gamma") },
2244 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, _("Brightness") },
2245 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, _("Contrast") },
2246 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, _("Saturation") },
2247 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, _("Hue") },
2248 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, _("VSync: %s") },
2249 // subs
2250 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, _("Subtitles: %s") },
2251 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, _("Sub source: %s") },
2252 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, _("Subtitles: %s") },
2253 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, _("Subtitles: %s") },
2254 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, _("Subtitles: %s") },
2255 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, _("Sub position: %s/100") },
2256 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, _("Sub alignment: %s") },
2257 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2258 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, _("Subtitles: %s") },
2259 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, _("Forced sub only: %s") },
2260 #ifdef CONFIG_FREETYPE
2261 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, _("Sub Scale: %s")},
2262 #endif
2263 #ifdef CONFIG_ASS
2264 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2265 #endif
2266 #ifdef CONFIG_TV
2267 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, _("Brightness") },
2268 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, _("Hue") },
2269 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, _("Saturation") },
2270 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, _("Contrast") },
2271 #endif
2272 { NULL, 0, 0, 0, -1, NULL }
2276 /// Handle commands that set a property.
2277 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2279 struct MPOpts *opts = &mpctx->opts;
2280 int i, r;
2281 m_option_t* prop;
2282 const char *pname;
2284 // look for the command
2285 for (i = 0; set_prop_cmd[i].name; i++)
2286 if (set_prop_cmd[i].cmd == cmd->id)
2287 break;
2288 if (!(pname = set_prop_cmd[i].name))
2289 return 0;
2291 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2292 return 0;
2294 // toggle command
2295 if (set_prop_cmd[i].toggle) {
2296 // set to value
2297 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2298 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2299 else
2300 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2301 } else if (cmd->args[1].v.i) //set
2302 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2303 else // adjust
2304 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2306 if (r <= 0)
2307 return 1;
2309 if (set_prop_cmd[i].osd_progbar == -1)
2310 mpctx->add_osd_seek_info = true;
2311 else if (set_prop_cmd[i].osd_progbar) {
2312 if (prop->type == CONF_TYPE_INT) {
2313 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2314 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2315 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2316 } else if (prop->type == CONF_TYPE_FLOAT) {
2317 float f;
2318 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2319 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2320 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2321 } else
2322 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2323 "Property use an unsupported type.\n");
2324 return 1;
2327 if (set_prop_cmd[i].osd_msg) {
2328 char *val = mp_property_print(pname, mpctx);
2329 if (val) {
2330 set_osd_msg(set_prop_cmd[i].osd_id >=
2331 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2332 1, opts->osd_duration, set_prop_cmd[i].osd_msg, val);
2333 free(val);
2336 return 1;
2339 #ifdef CONFIG_DVDNAV
2340 static const struct {
2341 const char *name;
2342 const mp_command_type cmd;
2343 } mp_dvdnav_bindings[] = {
2344 { "up", MP_CMD_DVDNAV_UP },
2345 { "down", MP_CMD_DVDNAV_DOWN },
2346 { "left", MP_CMD_DVDNAV_LEFT },
2347 { "right", MP_CMD_DVDNAV_RIGHT },
2348 { "menu", MP_CMD_DVDNAV_MENU },
2349 { "select", MP_CMD_DVDNAV_SELECT },
2350 { "prev", MP_CMD_DVDNAV_PREVMENU },
2351 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2354 * keep old dvdnav sub-command options for a while in order not to
2355 * break slave-mode API too suddenly.
2357 { "1", MP_CMD_DVDNAV_UP },
2358 { "2", MP_CMD_DVDNAV_DOWN },
2359 { "3", MP_CMD_DVDNAV_LEFT },
2360 { "4", MP_CMD_DVDNAV_RIGHT },
2361 { "5", MP_CMD_DVDNAV_MENU },
2362 { "6", MP_CMD_DVDNAV_SELECT },
2363 { "7", MP_CMD_DVDNAV_PREVMENU },
2364 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2365 { NULL, 0 }
2367 #endif
2369 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2371 struct MPOpts *opts = &mpctx->opts;
2372 sh_audio_t * const sh_audio = mpctx->sh_audio;
2373 sh_video_t * const sh_video = mpctx->sh_video;
2374 int osd_duration = opts->osd_duration;
2375 if (!set_property_command(mpctx, cmd))
2376 switch (cmd->id) {
2377 case MP_CMD_SEEK:{
2378 float v;
2379 int abs;
2380 mpctx->add_osd_seek_info = true;
2381 v = cmd->args[0].v.f;
2382 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2383 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2384 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2385 if (sh_video)
2386 mpctx->osd_function =
2387 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2388 mpctx->rel_seek_secs = v;
2389 } else if (abs) { /* Absolute seek by percentage */
2390 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2391 if (sh_video)
2392 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2393 mpctx->rel_seek_secs = v / 100.0;
2394 } else {
2395 mpctx->rel_seek_secs += v;
2396 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2399 break;
2401 case MP_CMD_SET_PROPERTY:{
2402 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2403 cmd->args[1].v.s, mpctx);
2404 if (r == M_PROPERTY_UNKNOWN)
2405 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2406 "Unknown property: '%s'\n", cmd->args[0].v.s);
2407 else if (r <= 0)
2408 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2409 "Failed to set property '%s' to '%s'.\n",
2410 cmd->args[0].v.s, cmd->args[1].v.s);
2412 break;
2414 case MP_CMD_STEP_PROPERTY:{
2415 void* arg = NULL;
2416 int r,i;
2417 double d;
2418 off_t o;
2419 if (cmd->args[1].v.f) {
2420 m_option_t* prop;
2421 if((r = mp_property_do(cmd->args[0].v.s,
2422 M_PROPERTY_GET_TYPE,
2423 &prop, mpctx)) <= 0)
2424 goto step_prop_err;
2425 if(prop->type == CONF_TYPE_INT ||
2426 prop->type == CONF_TYPE_FLAG)
2427 i = cmd->args[1].v.f, arg = &i;
2428 else if(prop->type == CONF_TYPE_FLOAT)
2429 arg = &cmd->args[1].v.f;
2430 else if(prop->type == CONF_TYPE_DOUBLE ||
2431 prop->type == CONF_TYPE_TIME)
2432 d = cmd->args[1].v.f, arg = &d;
2433 else if(prop->type == CONF_TYPE_POSITION)
2434 o = cmd->args[1].v.f, arg = &o;
2435 else
2436 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2437 "Ignoring step size stepping property '%s'.\n",
2438 cmd->args[0].v.s);
2440 r = mp_property_do(cmd->args[0].v.s,
2441 cmd->args[2].v.i < 0 ?
2442 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2443 arg, mpctx);
2444 step_prop_err:
2445 if (r == M_PROPERTY_UNKNOWN)
2446 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2447 "Unknown property: '%s'\n", cmd->args[0].v.s);
2448 else if (r <= 0)
2449 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2450 "Failed to increment property '%s' by %f.\n",
2451 cmd->args[0].v.s, cmd->args[1].v.f);
2453 break;
2455 case MP_CMD_GET_PROPERTY:{
2456 char *tmp;
2457 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2458 &tmp, mpctx) <= 0) {
2459 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2460 "Failed to get value of property '%s'.\n",
2461 cmd->args[0].v.s);
2462 break;
2464 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2465 cmd->args[0].v.s, tmp);
2466 free(tmp);
2468 break;
2470 case MP_CMD_EDL_MARK:
2471 if (edl_fd) {
2472 float v = sh_video ? sh_video->pts :
2473 playing_audio_pts(mpctx);
2474 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2475 mpctx->begin_skip = v;
2476 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2477 } else {
2478 if (mpctx->begin_skip > v)
2479 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2480 else {
2481 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2482 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2484 mpctx->begin_skip = MP_NOPTS_VALUE;
2487 break;
2489 case MP_CMD_SWITCH_RATIO:
2490 if (!sh_video)
2491 break;
2492 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2493 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2494 else
2495 opts->movie_aspect = cmd->args[0].v.f;
2496 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2497 break;
2499 case MP_CMD_SPEED_INCR:{
2500 float v = cmd->args[0].v.f;
2501 opts->playback_speed += v;
2502 build_afilter_chain(mpctx, sh_audio, &ao_data);
2503 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2504 opts->playback_speed);
2505 } break;
2507 case MP_CMD_SPEED_MULT:{
2508 float v = cmd->args[0].v.f;
2509 opts->playback_speed *= v;
2510 build_afilter_chain(mpctx, sh_audio, &ao_data);
2511 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2512 opts->playback_speed);
2513 } break;
2515 case MP_CMD_SPEED_SET:{
2516 float v = cmd->args[0].v.f;
2517 opts->playback_speed = v;
2518 build_afilter_chain(mpctx, sh_audio, &ao_data);
2519 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2520 opts->playback_speed);
2521 } break;
2523 case MP_CMD_FRAME_STEP:
2524 add_step_frame(mpctx);
2525 break;
2527 case MP_CMD_FILE_FILTER:
2528 file_filter = cmd->args[0].v.i;
2529 break;
2531 case MP_CMD_QUIT:
2532 exit_player_with_rc(mpctx, EXIT_QUIT,
2533 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2535 case MP_CMD_PLAY_TREE_STEP:{
2536 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2537 int force = cmd->args[1].v.i;
2540 if (!force && mpctx->playtree_iter) {
2541 play_tree_iter_t *i =
2542 play_tree_iter_new_copy(mpctx->playtree_iter);
2543 if (play_tree_iter_step(i, n, 0) ==
2544 PLAY_TREE_ITER_ENTRY)
2545 mpctx->stop_play =
2546 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2547 play_tree_iter_free(i);
2548 } else
2549 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2550 if (mpctx->stop_play)
2551 mpctx->play_tree_step = n;
2554 break;
2556 case MP_CMD_PLAY_TREE_UP_STEP:{
2557 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2558 int force = cmd->args[1].v.i;
2560 if (!force && mpctx->playtree_iter) {
2561 play_tree_iter_t *i =
2562 play_tree_iter_new_copy(mpctx->playtree_iter);
2563 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2564 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2565 play_tree_iter_free(i);
2566 } else
2567 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2569 break;
2571 case MP_CMD_PLAY_ALT_SRC_STEP:
2572 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2573 int v = cmd->args[0].v.i;
2574 if (v > 0
2575 && mpctx->playtree_iter->file <
2576 mpctx->playtree_iter->num_files)
2577 mpctx->stop_play = PT_NEXT_SRC;
2578 else if (v < 0 && mpctx->playtree_iter->file > 1)
2579 mpctx->stop_play = PT_PREV_SRC;
2581 break;
2583 case MP_CMD_SUB_STEP:
2584 if (sh_video) {
2585 int movement = cmd->args[0].v.i;
2586 step_sub(subdata, sh_video->pts, movement);
2587 #ifdef CONFIG_ASS
2588 if (ass_track)
2589 sub_delay +=
2590 ass_step_sub(ass_track,
2591 (sh_video->pts +
2592 sub_delay) * 1000 + .5, movement) / 1000.;
2593 #endif
2594 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2595 _("Sub delay: %d ms"), ROUND(sub_delay * 1000));
2597 break;
2599 case MP_CMD_SUB_LOG:
2600 log_sub(mpctx);
2601 break;
2603 case MP_CMD_OSD:{
2604 int v = cmd->args[0].v.i;
2605 int max = (term_osd
2606 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2607 if (opts->osd_level > max)
2608 opts->osd_level = max;
2609 if (v < 0)
2610 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2611 else
2612 opts->osd_level = v > max ? max : v;
2613 /* Show OSD state when disabled, but not when an explicit
2614 argument is given to the OSD command, i.e. in slave mode. */
2615 if (v == -1 && opts->osd_level <= 1)
2616 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2617 _("OSD: %s"),
2618 opts->osd_level ? _("enabled") :
2619 _("disabled"));
2620 else
2621 rm_osd_msg(OSD_MSG_OSD_STATUS);
2623 break;
2625 case MP_CMD_OSD_SHOW_TEXT:
2626 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2627 (cmd->args[1].v.i <
2628 0 ? osd_duration : cmd->args[1].v.i),
2629 "%-.63s", cmd->args[0].v.s);
2630 break;
2632 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2633 char *txt = m_properties_expand_string(mp_properties,
2634 cmd->args[0].v.s,
2635 mpctx);
2636 /* if no argument supplied take default osd_duration, else <arg> ms. */
2637 if (txt) {
2638 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2639 (cmd->args[1].v.i <
2640 0 ? osd_duration : cmd->args[1].v.i),
2641 "%-.63s", txt);
2642 free(txt);
2645 break;
2647 case MP_CMD_LOADFILE:{
2648 play_tree_t *e = play_tree_new();
2649 play_tree_add_file(e, cmd->args[0].v.s);
2651 if (cmd->args[1].v.i) // append
2652 play_tree_append_entry(mpctx->playtree->child, e);
2653 else {
2654 // Go back to the starting point.
2655 while (play_tree_iter_up_step
2656 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2657 /* NOP */ ;
2658 play_tree_free_list(mpctx->playtree->child, 1);
2659 play_tree_set_child(mpctx->playtree, e);
2660 pt_iter_goto_head(mpctx->playtree_iter);
2661 mpctx->stop_play = PT_NEXT_SRC;
2664 break;
2666 case MP_CMD_LOADLIST:{
2667 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2668 if (!e)
2669 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2670 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2671 else {
2672 if (cmd->args[1].v.i) // append
2673 play_tree_append_entry(mpctx->playtree->child, e);
2674 else {
2675 // Go back to the starting point.
2676 while (play_tree_iter_up_step
2677 (mpctx->playtree_iter, 0, 1)
2678 != PLAY_TREE_ITER_END)
2679 /* NOP */ ;
2680 play_tree_free_list(mpctx->playtree->child, 1);
2681 play_tree_set_child(mpctx->playtree, e);
2682 pt_iter_goto_head(mpctx->playtree_iter);
2683 mpctx->stop_play = PT_NEXT_SRC;
2687 break;
2689 case MP_CMD_STOP:
2690 // Go back to the starting point.
2691 while (play_tree_iter_up_step
2692 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2693 /* NOP */ ;
2694 mpctx->stop_play = PT_STOP;
2695 break;
2697 #ifdef CONFIG_RADIO
2698 case MP_CMD_RADIO_STEP_CHANNEL:
2699 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2700 int v = cmd->args[0].v.i;
2701 if (v > 0)
2702 radio_step_channel(mpctx->demuxer->stream,
2703 RADIO_CHANNEL_HIGHER);
2704 else
2705 radio_step_channel(mpctx->demuxer->stream,
2706 RADIO_CHANNEL_LOWER);
2707 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2708 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2709 _("Channel: %s"),
2710 radio_get_channel_name(mpctx->demuxer->stream));
2713 break;
2715 case MP_CMD_RADIO_SET_CHANNEL:
2716 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2717 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2718 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2719 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2720 _("Channel: %s"),
2721 radio_get_channel_name(mpctx->demuxer->stream));
2724 break;
2726 case MP_CMD_RADIO_SET_FREQ:
2727 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2728 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2729 break;
2731 case MP_CMD_RADIO_STEP_FREQ:
2732 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2733 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2734 break;
2735 #endif
2737 #ifdef CONFIG_TV
2738 case MP_CMD_TV_START_SCAN:
2739 if (mpctx->file_format == DEMUXER_TYPE_TV)
2740 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2741 break;
2742 case MP_CMD_TV_SET_FREQ:
2743 if (mpctx->file_format == DEMUXER_TYPE_TV)
2744 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2745 cmd->args[0].v.f * 16.0);
2746 #ifdef CONFIG_PVR
2747 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2748 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2749 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2750 pvr_get_current_channelname (mpctx->stream),
2751 pvr_get_current_stationname (mpctx->stream));
2753 #endif /* CONFIG_PVR */
2754 break;
2756 case MP_CMD_TV_STEP_FREQ:
2757 if (mpctx->file_format == DEMUXER_TYPE_TV)
2758 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2759 cmd->args[0].v.f * 16.0);
2760 #ifdef CONFIG_PVR
2761 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2762 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2763 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2764 pvr_get_current_channelname (mpctx->stream),
2765 pvr_get_current_frequency (mpctx->stream));
2767 #endif /* CONFIG_PVR */
2768 break;
2770 case MP_CMD_TV_SET_NORM:
2771 if (mpctx->file_format == DEMUXER_TYPE_TV)
2772 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2773 cmd->args[0].v.s);
2774 break;
2776 case MP_CMD_TV_STEP_CHANNEL:{
2777 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2778 int v = cmd->args[0].v.i;
2779 if (v > 0) {
2780 tv_step_channel((tvi_handle_t *) (mpctx->
2781 demuxer->priv),
2782 TV_CHANNEL_HIGHER);
2783 } else {
2784 tv_step_channel((tvi_handle_t *) (mpctx->
2785 demuxer->priv),
2786 TV_CHANNEL_LOWER);
2788 if (tv_channel_list) {
2789 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2790 _("Channel: %s"), tv_channel_current->name);
2791 //vo_osd_changed(OSDTYPE_SUBTITLE);
2794 #ifdef CONFIG_PVR
2795 else if (mpctx->stream &&
2796 mpctx->stream->type == STREAMTYPE_PVR) {
2797 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2798 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2799 pvr_get_current_channelname (mpctx->stream),
2800 pvr_get_current_stationname (mpctx->stream));
2802 #endif /* CONFIG_PVR */
2804 #ifdef CONFIG_DVBIN
2805 if (mpctx->stream->type == STREAMTYPE_DVB) {
2806 int dir;
2807 int v = cmd->args[0].v.i;
2809 mpctx->last_dvb_step = v;
2810 if (v > 0)
2811 dir = DVB_CHANNEL_HIGHER;
2812 else
2813 dir = DVB_CHANNEL_LOWER;
2816 if (dvb_step_channel(mpctx->stream, dir)) {
2817 mpctx->stop_play = PT_NEXT_ENTRY;
2818 mpctx->dvbin_reopen = 1;
2821 #endif /* CONFIG_DVBIN */
2822 break;
2824 case MP_CMD_TV_SET_CHANNEL:
2825 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2826 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2827 cmd->args[0].v.s);
2828 if (tv_channel_list) {
2829 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2830 _("Channel: %s"), tv_channel_current->name);
2831 //vo_osd_changed(OSDTYPE_SUBTITLE);
2834 #ifdef CONFIG_PVR
2835 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2836 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2837 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2838 pvr_get_current_channelname (mpctx->stream),
2839 pvr_get_current_stationname (mpctx->stream));
2841 #endif /* CONFIG_PVR */
2842 break;
2844 #ifdef CONFIG_DVBIN
2845 case MP_CMD_DVB_SET_CHANNEL:
2846 if (mpctx->stream->type == STREAMTYPE_DVB) {
2847 mpctx->last_dvb_step = 1;
2849 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
2850 cmd->args[0].v.i)) {
2851 mpctx->stop_play = PT_NEXT_ENTRY;
2852 mpctx->dvbin_reopen = 1;
2855 break;
2856 #endif /* CONFIG_DVBIN */
2858 case MP_CMD_TV_LAST_CHANNEL:
2859 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2860 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2861 if (tv_channel_list) {
2862 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2863 _("Channel: %s"), tv_channel_current->name);
2864 //vo_osd_changed(OSDTYPE_SUBTITLE);
2867 #ifdef CONFIG_PVR
2868 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2869 pvr_set_lastchannel (mpctx->stream);
2870 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2871 pvr_get_current_channelname (mpctx->stream),
2872 pvr_get_current_stationname (mpctx->stream));
2874 #endif /* CONFIG_PVR */
2875 break;
2877 case MP_CMD_TV_STEP_NORM:
2878 if (mpctx->file_format == DEMUXER_TYPE_TV)
2879 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2880 break;
2882 case MP_CMD_TV_STEP_CHANNEL_LIST:
2883 if (mpctx->file_format == DEMUXER_TYPE_TV)
2884 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2885 break;
2886 #ifdef CONFIG_TV_TELETEXT
2887 case MP_CMD_TV_TELETEXT_ADD_DEC:
2889 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2890 if (mpctx->file_format == DEMUXER_TYPE_TV)
2891 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2892 break;
2894 case MP_CMD_TV_TELETEXT_GO_LINK:
2896 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2897 if (mpctx->file_format == DEMUXER_TYPE_TV)
2898 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2899 break;
2901 #endif /* CONFIG_TV_TELETEXT */
2902 #endif /* CONFIG_TV */
2904 case MP_CMD_SUB_LOAD:
2905 if (sh_video) {
2906 int n = mpctx->set_of_sub_size;
2907 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
2908 if (n != mpctx->set_of_sub_size) {
2909 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2910 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2911 mpctx->global_sub_size;
2912 ++mpctx->global_sub_size;
2915 break;
2917 case MP_CMD_SUB_REMOVE:
2918 if (sh_video) {
2919 int v = cmd->args[0].v.i;
2920 sub_data *subd;
2921 if (v < 0) {
2922 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2923 subd = mpctx->set_of_subtitles[v];
2924 mp_tmsg(MSGT_CPLAYER, MSGL_STATUS,
2925 "SUB: Removed subtitle file (%d): %s\n", v + 1,
2926 filename_recode(subd->filename));
2927 sub_free(subd);
2928 mpctx->set_of_subtitles[v] = NULL;
2930 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2931 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2932 mpctx->set_of_sub_size = 0;
2933 if (mpctx->set_of_sub_pos >= 0) {
2934 mpctx->global_sub_pos = -2;
2935 subdata = NULL;
2936 mp_input_queue_cmd(mpctx->input,
2937 mp_input_parse_cmd("sub_select"));
2939 } else if (v < mpctx->set_of_sub_size) {
2940 subd = mpctx->set_of_subtitles[v];
2941 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2942 "SUB: Removed subtitle file (%d): %s\n", v + 1,
2943 filename_recode(subd->filename));
2944 sub_free(subd);
2945 if (mpctx->set_of_sub_pos == v) {
2946 mpctx->global_sub_pos = -2;
2947 subdata = NULL;
2948 mp_input_queue_cmd(mpctx->input,
2949 mp_input_parse_cmd("sub_select"));
2950 } else if (mpctx->set_of_sub_pos > v) {
2951 --mpctx->set_of_sub_pos;
2952 --mpctx->global_sub_pos;
2954 while (++v < mpctx->set_of_sub_size)
2955 mpctx->set_of_subtitles[v - 1] =
2956 mpctx->set_of_subtitles[v];
2957 --mpctx->set_of_sub_size;
2958 --mpctx->global_sub_size;
2959 if (mpctx->set_of_sub_size <= 0)
2960 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2961 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2964 break;
2966 case MP_CMD_GET_SUB_VISIBILITY:
2967 if (sh_video) {
2968 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2969 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2971 break;
2973 case MP_CMD_SCREENSHOT:
2974 if (mpctx->video_out && mpctx->video_out->config_ok) {
2975 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2976 if (CONTROL_OK !=
2977 ((vf_instance_t *) sh_video->vfilter)->
2978 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2979 &cmd->args[0].v.i))
2980 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2982 break;
2984 case MP_CMD_AF_EQ_SET:{
2985 af_instance_t* m1=af_get(sh_audio->afilter, "equalizer");
2986 if (m1) m1->control( m1, AF_CONTROL_COMMAND_LINE, cmd->args[0].v.s);
2987 else mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -af equalizer=0:0 ?)\n");
2989 break;
2991 case MP_CMD_VF_CHANGE_RECTANGLE:
2992 if (!sh_video)
2993 break;
2994 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2995 break;
2997 case MP_CMD_GET_TIME_LENGTH:{
2998 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2999 demuxer_get_time_length(mpctx->demuxer));
3001 break;
3003 case MP_CMD_GET_FILENAME:{
3004 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3005 get_metadata(mpctx, META_NAME));
3007 break;
3009 case MP_CMD_GET_VIDEO_CODEC:{
3010 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3011 if (!inf)
3012 inf = strdup("");
3013 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3014 free(inf);
3016 break;
3018 case MP_CMD_GET_VIDEO_BITRATE:{
3019 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3020 if (!inf)
3021 inf = strdup("");
3022 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3023 free(inf);
3025 break;
3027 case MP_CMD_GET_VIDEO_RESOLUTION:{
3028 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3029 if (!inf)
3030 inf = strdup("");
3031 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3032 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3033 free(inf);
3035 break;
3037 case MP_CMD_GET_AUDIO_CODEC:{
3038 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3039 if (!inf)
3040 inf = strdup("");
3041 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3042 free(inf);
3044 break;
3046 case MP_CMD_GET_AUDIO_BITRATE:{
3047 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3048 if (!inf)
3049 inf = strdup("");
3050 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3051 free(inf);
3053 break;
3055 case MP_CMD_GET_AUDIO_SAMPLES:{
3056 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3057 if (!inf)
3058 inf = strdup("");
3059 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3060 free(inf);
3062 break;
3064 case MP_CMD_GET_META_TITLE:{
3065 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3066 if (!inf)
3067 inf = strdup("");
3068 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3069 free(inf);
3071 break;
3073 case MP_CMD_GET_META_ARTIST:{
3074 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3075 if (!inf)
3076 inf = strdup("");
3077 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3078 free(inf);
3080 break;
3082 case MP_CMD_GET_META_ALBUM:{
3083 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3084 if (!inf)
3085 inf = strdup("");
3086 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3087 free(inf);
3089 break;
3091 case MP_CMD_GET_META_YEAR:{
3092 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3093 if (!inf)
3094 inf = strdup("");
3095 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3096 free(inf);
3098 break;
3100 case MP_CMD_GET_META_COMMENT:{
3101 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3102 if (!inf)
3103 inf = strdup("");
3104 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3105 free(inf);
3107 break;
3109 case MP_CMD_GET_META_TRACK:{
3110 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3111 if (!inf)
3112 inf = strdup("");
3113 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3114 free(inf);
3116 break;
3118 case MP_CMD_GET_META_GENRE:{
3119 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3120 if (!inf)
3121 inf = strdup("");
3122 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3123 free(inf);
3125 break;
3127 case MP_CMD_GET_VO_FULLSCREEN:
3128 if (mpctx->video_out && mpctx->video_out->config_ok)
3129 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3130 break;
3132 case MP_CMD_GET_PERCENT_POS:
3133 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3134 demuxer_get_percent_pos(mpctx->demuxer));
3135 break;
3137 case MP_CMD_GET_TIME_POS:{
3138 float pos = 0;
3139 if (sh_video)
3140 pos = sh_video->pts;
3141 else if (sh_audio && mpctx->audio_out)
3142 pos = playing_audio_pts(mpctx);
3143 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3145 break;
3147 case MP_CMD_RUN:
3148 #ifndef __MINGW32__
3149 if (!fork()) {
3150 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3151 exit(0);
3153 #endif
3154 break;
3156 case MP_CMD_KEYDOWN_EVENTS:
3157 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3158 break;
3160 case MP_CMD_SET_MOUSE_POS:{
3161 int pointer_x, pointer_y;
3162 double dx, dy;
3163 pointer_x = cmd->args[0].v.i;
3164 pointer_y = cmd->args[1].v.i;
3165 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3166 #ifdef CONFIG_DVDNAV
3167 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3168 && dx > 0.0 && dy > 0.0) {
3169 int button = -1;
3170 pointer_x = (int) (dx * (double) sh_video->disp_w);
3171 pointer_y = (int) (dy * (double) sh_video->disp_h);
3172 mp_dvdnav_update_mouse_pos(mpctx->stream,
3173 pointer_x, pointer_y, &button);
3174 if (opts->osd_level > 1 && button > 0)
3175 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3176 "Selected button number %d", button);
3178 #endif
3179 #ifdef CONFIG_MENU
3180 if (use_menu && dx >= 0.0 && dy >= 0.0)
3181 menu_update_mouse_pos(dx, dy);
3182 #endif
3184 break;
3186 #ifdef CONFIG_DVDNAV
3187 case MP_CMD_DVDNAV:{
3188 int button = -1;
3189 int i;
3190 mp_command_type command = 0;
3191 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3192 break;
3194 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3195 if (cmd->args[0].v.s &&
3196 !strcasecmp (cmd->args[0].v.s,
3197 mp_dvdnav_bindings[i].name))
3198 command = mp_dvdnav_bindings[i].cmd;
3200 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3201 if (opts->osd_level > 1 && button > 0)
3202 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3203 "Selected button number %d", button);
3205 break;
3207 case MP_CMD_SWITCH_TITLE:
3208 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3209 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3210 break;
3212 #endif
3214 default:
3215 mp_msg(MSGT_CPLAYER, MSGL_V,
3216 "Received unknown cmd %s\n", cmd->name);
3219 switch (cmd->pausing) {
3220 case 1: // "pausing"
3221 pause_player(mpctx);
3222 break;
3223 case 3: // "pausing_toggle"
3224 if (mpctx->paused)
3225 unpause_player(mpctx);
3226 else
3227 pause_player(mpctx);
3228 break;