debian/: delegate handling of mplayer.conf to dpkg.
[mplayer/glamo.git] / command.c
blob67b3ac16f45c3af5ca9e4ffd67cee46c78c2f3f2
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 #include "stream/tv.h"
36 #include "stream/stream_radio.h"
37 #include "stream/pvr.h"
38 #ifdef CONFIG_DVBIN
39 #include "stream/dvbin.h"
40 #endif
41 #ifdef CONFIG_DVDREAD
42 #include "stream/stream_dvd.h"
43 #endif
44 #include "stream/stream_dvdnav.h"
45 #include "m_struct.h"
46 #include "libmenu/menu.h"
48 #include "mp_core.h"
49 #include "mp_fifo.h"
50 #include "libavutil/avstring.h"
52 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
54 extern int use_menu;
56 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
57 double *dx, double *dy)
59 struct MPOpts *opts = &mpctx->opts;
60 struct vo *vo = mpctx->video_out;
61 //remove the borders, if any, and rescale to the range [0,1],[0,1]
62 if (vo_fs) { //we are in full-screen mode
63 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
64 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
65 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
66 iy -= (opts->vo_screenheight - vo->dheight) / 2;
68 if (ix < 0 || ix > vo->dwidth) {
69 *dx = *dy = -1.0;
70 return;
71 } //we are on one of the borders
72 if (iy < 0 || iy > vo->dheight) {
73 *dx = *dy = -1.0;
74 return;
75 } //we are on one of the borders
78 *dx = (double) ix / (double) vo->dwidth;
79 *dy = (double) iy / (double) vo->dheight;
81 mp_msg(MSGT_CPLAYER, MSGL_V,
82 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
83 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
84 vo->dheight, vo_fs);
87 static int sub_source_by_pos(MPContext *mpctx, int pos)
89 int source = -1;
90 int top = -1;
91 int i;
92 for (i = 0; i < SUB_SOURCES; i++) {
93 int j = mpctx->global_sub_indices[i];
94 if ((j >= 0) && (j > top) && (pos >= j)) {
95 source = i;
96 top = j;
99 return source;
102 static int sub_source(MPContext *mpctx)
104 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
108 * \brief Log the currently displayed subtitle to a file
110 * Logs the current or last displayed subtitle together with filename
111 * and time information to ~/.mplayer/subtitle_log
113 * Intended purpose is to allow convenient marking of bogus subtitles
114 * which need to be fixed while watching the movie.
117 static void log_sub(struct MPContext *mpctx)
119 char *fname;
120 FILE *f;
121 int i;
123 if (subdata == NULL || vo_sub_last == NULL)
124 return;
125 fname = get_path("subtitle_log");
126 f = fopen(fname, "a");
127 if (!f)
128 return;
129 fprintf(f, "----------------------------------------------------------\n");
130 if (subdata->sub_uses_time) {
131 fprintf(f,
132 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
133 mpctx->filename, vo_sub_last->start / 360000,
134 (vo_sub_last->start / 6000) % 60,
135 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
136 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
137 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
138 } else {
139 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
140 vo_sub_last->start, vo_sub_last->end);
142 for (i = 0; i < vo_sub_last->lines; i++) {
143 fprintf(f, "%s\n", vo_sub_last->text[i]);
145 fclose(f);
149 /// \defgroup Properties
150 ///@{
152 /// \defgroup GeneralProperties General properties
153 /// \ingroup Properties
154 ///@{
156 /// OSD level (RW)
157 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
158 MPContext *mpctx)
160 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
163 /// Loop (RW)
164 static int mp_property_loop(m_option_t *prop, int action, void *arg,
165 MPContext *mpctx)
167 struct MPOpts *opts = &mpctx->opts;
168 switch (action) {
169 case M_PROPERTY_PRINT:
170 if (!arg) return M_PROPERTY_ERROR;
171 if (opts->loop_times < 0)
172 *(char**)arg = strdup("off");
173 else if (opts->loop_times == 0)
174 *(char**)arg = strdup("inf");
175 else
176 break;
177 return M_PROPERTY_OK;
179 return m_property_int_range(prop, action, arg, &opts->loop_times);
182 /// Playback speed (RW)
183 static int mp_property_playback_speed(m_option_t *prop, int action,
184 void *arg, MPContext *mpctx)
186 struct MPOpts *opts = &mpctx->opts;
187 switch (action) {
188 case M_PROPERTY_SET:
189 if (!arg)
190 return M_PROPERTY_ERROR;
191 M_PROPERTY_CLAMP(prop, *(float *) arg);
192 opts->playback_speed = *(float *) arg;
193 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
194 return M_PROPERTY_OK;
195 case M_PROPERTY_STEP_UP:
196 case M_PROPERTY_STEP_DOWN:
197 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
198 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
199 M_PROPERTY_CLAMP(prop, opts->playback_speed);
200 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
201 return M_PROPERTY_OK;
203 return m_property_float_range(prop, action, arg, &opts->playback_speed);
206 /// filename with path (RO)
207 static int mp_property_path(m_option_t *prop, int action, void *arg,
208 MPContext *mpctx)
210 return m_property_string_ro(prop, action, arg, mpctx->filename);
213 /// filename without path (RO)
214 static int mp_property_filename(m_option_t *prop, int action, void *arg,
215 MPContext *mpctx)
217 char *f;
218 if (!mpctx->filename)
219 return M_PROPERTY_UNAVAILABLE;
220 if (((f = strrchr(mpctx->filename, '/'))
221 || (f = strrchr(mpctx->filename, '\\'))) && f[1])
222 f++;
223 else
224 f = mpctx->filename;
225 return m_property_string_ro(prop, action, arg, f);
228 /// Demuxer name (RO)
229 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
230 MPContext *mpctx)
232 if (!mpctx->demuxer)
233 return M_PROPERTY_UNAVAILABLE;
234 return m_property_string_ro(prop, action, arg,
235 (char *) mpctx->demuxer->desc->name);
238 /// Position in the stream (RW)
239 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
240 MPContext *mpctx)
242 if (!mpctx->demuxer || !mpctx->demuxer->stream)
243 return M_PROPERTY_UNAVAILABLE;
244 if (!arg)
245 return M_PROPERTY_ERROR;
246 switch (action) {
247 case M_PROPERTY_GET:
248 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
249 return M_PROPERTY_OK;
250 case M_PROPERTY_SET:
251 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
252 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
253 return M_PROPERTY_OK;
255 return M_PROPERTY_NOT_IMPLEMENTED;
258 /// Stream start offset (RO)
259 static int mp_property_stream_start(m_option_t *prop, int action,
260 void *arg, MPContext *mpctx)
262 if (!mpctx->demuxer || !mpctx->demuxer->stream)
263 return M_PROPERTY_UNAVAILABLE;
264 switch (action) {
265 case M_PROPERTY_GET:
266 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
267 return M_PROPERTY_OK;
269 return M_PROPERTY_NOT_IMPLEMENTED;
272 /// Stream end offset (RO)
273 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
274 MPContext *mpctx)
276 if (!mpctx->demuxer || !mpctx->demuxer->stream)
277 return M_PROPERTY_UNAVAILABLE;
278 switch (action) {
279 case M_PROPERTY_GET:
280 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
281 return M_PROPERTY_OK;
283 return M_PROPERTY_NOT_IMPLEMENTED;
286 /// Stream length (RO)
287 static int mp_property_stream_length(m_option_t *prop, int action,
288 void *arg, MPContext *mpctx)
290 if (!mpctx->demuxer || !mpctx->demuxer->stream)
291 return M_PROPERTY_UNAVAILABLE;
292 switch (action) {
293 case M_PROPERTY_GET:
294 *(off_t *) arg =
295 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
296 return M_PROPERTY_OK;
298 return M_PROPERTY_NOT_IMPLEMENTED;
301 /// Media length in seconds (RO)
302 static int mp_property_length(m_option_t *prop, int action, void *arg,
303 MPContext *mpctx)
305 double len;
307 if (!mpctx->demuxer ||
308 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
309 return M_PROPERTY_UNAVAILABLE;
311 return m_property_time_ro(prop, action, arg, len);
314 /// Current position in percent (RW)
315 static int mp_property_percent_pos(m_option_t *prop, int action,
316 void *arg, MPContext *mpctx) {
317 int pos;
319 if (!mpctx->demuxer)
320 return M_PROPERTY_UNAVAILABLE;
322 switch(action) {
323 case M_PROPERTY_SET:
324 if(!arg) return M_PROPERTY_ERROR;
325 M_PROPERTY_CLAMP(prop, *(int*)arg);
326 pos = *(int*)arg;
327 break;
328 case M_PROPERTY_STEP_UP:
329 case M_PROPERTY_STEP_DOWN:
330 pos = demuxer_get_percent_pos(mpctx->demuxer);
331 pos += (arg ? *(int*)arg : 10) *
332 (action == M_PROPERTY_STEP_UP ? 1 : -1);
333 M_PROPERTY_CLAMP(prop, pos);
334 break;
335 default:
336 return m_property_int_ro(prop, action, arg,
337 demuxer_get_percent_pos(mpctx->demuxer));
340 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
341 mpctx->rel_seek_secs = pos / 100.0;
342 return M_PROPERTY_OK;
345 /// Current position in seconds (RW)
346 static int mp_property_time_pos(m_option_t *prop, int action,
347 void *arg, MPContext *mpctx) {
348 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
349 return M_PROPERTY_UNAVAILABLE;
351 switch(action) {
352 case M_PROPERTY_SET:
353 if(!arg) return M_PROPERTY_ERROR;
354 M_PROPERTY_CLAMP(prop, *(double*)arg);
355 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
356 mpctx->rel_seek_secs = *(double*)arg;
357 return M_PROPERTY_OK;
358 case M_PROPERTY_STEP_UP:
359 case M_PROPERTY_STEP_DOWN:
360 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
361 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
362 return M_PROPERTY_OK;
364 return m_property_time_ro(prop, action, arg,
365 mpctx->sh_video ? mpctx->sh_video->pts :
366 playing_audio_pts(mpctx));
369 /// Current chapter (RW)
370 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
371 MPContext *mpctx)
373 struct MPOpts *opts = &mpctx->opts;
374 int chapter = -1;
375 int step_all;
376 char *chapter_name = NULL;
378 if (mpctx->demuxer)
379 chapter = get_current_chapter(mpctx);
380 if (chapter < 0)
381 return M_PROPERTY_UNAVAILABLE;
383 switch (action) {
384 case M_PROPERTY_GET:
385 if (!arg)
386 return M_PROPERTY_ERROR;
387 *(int *) arg = chapter;
388 return M_PROPERTY_OK;
389 case M_PROPERTY_PRINT: {
390 if (!arg)
391 return M_PROPERTY_ERROR;
392 chapter_name = chapter_display_name(mpctx, chapter);
393 if (!chapter_name)
394 return M_PROPERTY_UNAVAILABLE;
395 *(char **) arg = chapter_name;
396 return M_PROPERTY_OK;
398 case M_PROPERTY_SET:
399 if (!arg)
400 return M_PROPERTY_ERROR;
401 M_PROPERTY_CLAMP(prop, *(int*)arg);
402 step_all = *(int *)arg - chapter;
403 chapter += step_all;
404 break;
405 case M_PROPERTY_STEP_UP:
406 case M_PROPERTY_STEP_DOWN: {
407 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
408 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
409 chapter += step_all;
410 if (chapter < 0)
411 chapter = 0;
412 break;
414 default:
415 return M_PROPERTY_NOT_IMPLEMENTED;
418 double next_pts = 0;
419 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
420 mpctx->rel_seek_secs = 0;
421 mpctx->abs_seek_pos = 0;
422 if (chapter >= 0) {
423 if (next_pts > -1.0) {
424 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
425 mpctx->rel_seek_secs = next_pts;
427 if (chapter_name)
428 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
429 _("Chapter: (%d) %s"), chapter + 1, chapter_name);
431 else if (step_all > 0)
432 mpctx->rel_seek_secs = 1000000000.;
433 else
434 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
435 _("Chapter: (%d) %s"), 0, _("unknown"));
436 if (chapter_name)
437 talloc_free(chapter_name);
438 return M_PROPERTY_OK;
441 /// Number of chapters in file
442 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
443 MPContext *mpctx)
445 if (!mpctx->demuxer)
446 return M_PROPERTY_UNAVAILABLE;
447 if (mpctx->demuxer->num_chapters == 0)
448 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
449 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
452 /// Current dvd angle (RW)
453 static int mp_property_angle(m_option_t *prop, int action, void *arg,
454 MPContext *mpctx)
456 struct MPOpts *opts = &mpctx->opts;
457 int angle = -1;
458 int angles;
459 char *angle_name = NULL;
461 if (mpctx->demuxer)
462 angle = demuxer_get_current_angle(mpctx->demuxer);
463 if (angle < 0)
464 return M_PROPERTY_UNAVAILABLE;
465 angles = demuxer_angles_count(mpctx->demuxer);
466 if (angles <= 1)
467 return M_PROPERTY_UNAVAILABLE;
469 switch (action) {
470 case M_PROPERTY_GET:
471 if (!arg)
472 return M_PROPERTY_ERROR;
473 *(int *) arg = angle;
474 return M_PROPERTY_OK;
475 case M_PROPERTY_PRINT: {
476 if (!arg)
477 return M_PROPERTY_ERROR;
478 angle_name = calloc(1, 64);
479 if (!angle_name)
480 return M_PROPERTY_UNAVAILABLE;
481 snprintf(angle_name, 64, "%d/%d", angle, angles);
482 *(char **) arg = angle_name;
483 return M_PROPERTY_OK;
485 case M_PROPERTY_SET:
486 if (!arg)
487 return M_PROPERTY_ERROR;
488 angle = *(int *)arg;
489 M_PROPERTY_CLAMP(prop, angle);
490 break;
491 case M_PROPERTY_STEP_UP:
492 case M_PROPERTY_STEP_DOWN: {
493 int step = 0;
494 if(arg)
495 step = *(int*)arg;
496 if(!step)
497 step = 1;
498 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
499 angle += step;
500 if (angle < 1) //cycle
501 angle = angles;
502 break;
504 default:
505 return M_PROPERTY_NOT_IMPLEMENTED;
507 angle = demuxer_set_angle(mpctx->demuxer, angle);
508 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
509 _("Angle: %d/%d"), angle, angles);
510 if (angle_name)
511 free(angle_name);
512 return M_PROPERTY_OK;
515 /// Demuxer meta data
516 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
517 MPContext *mpctx) {
518 m_property_action_t* ka;
519 char* meta;
520 static const m_option_t key_type =
521 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
522 if (!mpctx->demuxer)
523 return M_PROPERTY_UNAVAILABLE;
525 switch(action) {
526 case M_PROPERTY_GET:
527 if(!arg) return M_PROPERTY_ERROR;
528 *(char***)arg = mpctx->demuxer->info;
529 return M_PROPERTY_OK;
530 case M_PROPERTY_KEY_ACTION:
531 if(!arg) return M_PROPERTY_ERROR;
532 ka = arg;
533 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
534 return M_PROPERTY_UNKNOWN;
535 switch(ka->action) {
536 case M_PROPERTY_GET:
537 if(!ka->arg) return M_PROPERTY_ERROR;
538 *(char**)ka->arg = meta;
539 return M_PROPERTY_OK;
540 case M_PROPERTY_GET_TYPE:
541 if(!ka->arg) return M_PROPERTY_ERROR;
542 *(m_option_t**)ka->arg = &key_type;
543 return M_PROPERTY_OK;
546 return M_PROPERTY_NOT_IMPLEMENTED;
549 static int mp_property_pause(m_option_t *prop, int action, void *arg,
550 void *ctx)
552 MPContext *mpctx = ctx;
554 switch (action) {
555 case M_PROPERTY_SET:
556 if (!arg)
557 return M_PROPERTY_ERROR;
558 if (mpctx->paused == (bool)*(int *) arg)
559 return M_PROPERTY_OK;
560 case M_PROPERTY_STEP_UP:
561 case M_PROPERTY_STEP_DOWN:
562 if (mpctx->paused) {
563 unpause_player(mpctx);
564 mpctx->osd_function = OSD_PLAY;
566 else {
567 pause_player(mpctx);
568 mpctx->osd_function = OSD_PAUSE;
570 return M_PROPERTY_OK;
571 default:
572 return m_property_flag(prop, action, arg, &mpctx->paused);
577 ///@}
579 /// \defgroup AudioProperties Audio properties
580 /// \ingroup Properties
581 ///@{
583 /// Volume (RW)
584 static int mp_property_volume(m_option_t *prop, int action, void *arg,
585 MPContext *mpctx)
588 if (!mpctx->sh_audio)
589 return M_PROPERTY_UNAVAILABLE;
591 switch (action) {
592 case M_PROPERTY_GET:
593 if (!arg)
594 return M_PROPERTY_ERROR;
595 mixer_getbothvolume(&mpctx->mixer, arg);
596 return M_PROPERTY_OK;
597 case M_PROPERTY_PRINT:{
598 float vol;
599 if (!arg)
600 return M_PROPERTY_ERROR;
601 mixer_getbothvolume(&mpctx->mixer, &vol);
602 return m_property_float_range(prop, action, arg, &vol);
604 case M_PROPERTY_STEP_UP:
605 case M_PROPERTY_STEP_DOWN:
606 case M_PROPERTY_SET:
607 break;
608 default:
609 return M_PROPERTY_NOT_IMPLEMENTED;
612 if (mpctx->edl_muted)
613 return M_PROPERTY_DISABLED;
614 mpctx->user_muted = 0;
616 switch (action) {
617 case M_PROPERTY_SET:
618 if (!arg)
619 return M_PROPERTY_ERROR;
620 M_PROPERTY_CLAMP(prop, *(float *) arg);
621 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
622 return M_PROPERTY_OK;
623 case M_PROPERTY_STEP_UP:
624 if (arg && *(float *) arg <= 0)
625 mixer_decvolume(&mpctx->mixer);
626 else
627 mixer_incvolume(&mpctx->mixer);
628 return M_PROPERTY_OK;
629 case M_PROPERTY_STEP_DOWN:
630 if (arg && *(float *) arg <= 0)
631 mixer_incvolume(&mpctx->mixer);
632 else
633 mixer_decvolume(&mpctx->mixer);
634 return M_PROPERTY_OK;
636 return M_PROPERTY_NOT_IMPLEMENTED;
639 /// Mute (RW)
640 static int mp_property_mute(m_option_t *prop, int action, void *arg,
641 MPContext *mpctx)
644 if (!mpctx->sh_audio)
645 return M_PROPERTY_UNAVAILABLE;
647 switch (action) {
648 case M_PROPERTY_SET:
649 if (mpctx->edl_muted)
650 return M_PROPERTY_DISABLED;
651 if (!arg)
652 return M_PROPERTY_ERROR;
653 if ((!!*(int *) arg) != mpctx->mixer.muted)
654 mixer_mute(&mpctx->mixer);
655 mpctx->user_muted = mpctx->mixer.muted;
656 return M_PROPERTY_OK;
657 case M_PROPERTY_STEP_UP:
658 case M_PROPERTY_STEP_DOWN:
659 if (mpctx->edl_muted)
660 return M_PROPERTY_DISABLED;
661 mixer_mute(&mpctx->mixer);
662 mpctx->user_muted = mpctx->mixer.muted;
663 return M_PROPERTY_OK;
664 case M_PROPERTY_PRINT:
665 if (!arg)
666 return M_PROPERTY_ERROR;
667 if (mpctx->edl_muted) {
668 *(char **) arg = strdup(_("enabled (EDL)"));
669 return M_PROPERTY_OK;
671 default:
672 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
677 /// Audio delay (RW)
678 static int mp_property_audio_delay(m_option_t *prop, int action,
679 void *arg, MPContext *mpctx)
681 if (!(mpctx->sh_audio && mpctx->sh_video))
682 return M_PROPERTY_UNAVAILABLE;
683 switch (action) {
684 case M_PROPERTY_SET:
685 case M_PROPERTY_STEP_UP:
686 case M_PROPERTY_STEP_DOWN: {
687 int ret;
688 float delay = audio_delay;
689 ret = m_property_delay(prop, action, arg, &audio_delay);
690 if (ret != M_PROPERTY_OK)
691 return ret;
692 if (mpctx->sh_audio)
693 mpctx->delay -= audio_delay - delay;
695 return M_PROPERTY_OK;
696 default:
697 return m_property_delay(prop, action, arg, &audio_delay);
701 /// Audio codec tag (RO)
702 static int mp_property_audio_format(m_option_t *prop, int action,
703 void *arg, MPContext *mpctx)
705 if (!mpctx->sh_audio)
706 return M_PROPERTY_UNAVAILABLE;
707 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
710 /// Audio codec name (RO)
711 static int mp_property_audio_codec(m_option_t *prop, int action,
712 void *arg, MPContext *mpctx)
714 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
715 return M_PROPERTY_UNAVAILABLE;
716 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
719 /// Audio bitrate (RO)
720 static int mp_property_audio_bitrate(m_option_t *prop, int action,
721 void *arg, MPContext *mpctx)
723 if (!mpctx->sh_audio)
724 return M_PROPERTY_UNAVAILABLE;
725 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
728 /// Samplerate (RO)
729 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
730 MPContext *mpctx)
732 if (!mpctx->sh_audio)
733 return M_PROPERTY_UNAVAILABLE;
734 switch(action) {
735 case M_PROPERTY_PRINT:
736 if(!arg) return M_PROPERTY_ERROR;
737 *(char**)arg = malloc(16);
738 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
739 return M_PROPERTY_OK;
741 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
744 /// Number of channels (RO)
745 static int mp_property_channels(m_option_t *prop, int action, void *arg,
746 MPContext *mpctx)
748 if (!mpctx->sh_audio)
749 return M_PROPERTY_UNAVAILABLE;
750 switch (action) {
751 case M_PROPERTY_PRINT:
752 if (!arg)
753 return M_PROPERTY_ERROR;
754 switch (mpctx->sh_audio->channels) {
755 case 1:
756 *(char **) arg = strdup("mono");
757 break;
758 case 2:
759 *(char **) arg = strdup("stereo");
760 break;
761 default:
762 *(char **) arg = malloc(32);
763 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
765 return M_PROPERTY_OK;
767 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
770 /// Balance (RW)
771 static int mp_property_balance(m_option_t *prop, int action, void *arg,
772 MPContext *mpctx)
774 float bal;
776 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
777 return M_PROPERTY_UNAVAILABLE;
779 switch (action) {
780 case M_PROPERTY_GET:
781 if (!arg)
782 return M_PROPERTY_ERROR;
783 mixer_getbalance(&mpctx->mixer, arg);
784 return M_PROPERTY_OK;
785 case M_PROPERTY_PRINT: {
786 char** str = arg;
787 if (!arg)
788 return M_PROPERTY_ERROR;
789 mixer_getbalance(&mpctx->mixer, &bal);
790 if (bal == 0.f)
791 *str = strdup("center");
792 else if (bal == -1.f)
793 *str = strdup("left only");
794 else if (bal == 1.f)
795 *str = strdup("right only");
796 else {
797 unsigned right = (bal + 1.f) / 2.f * 100.f;
798 *str = malloc(sizeof("left xxx%, right xxx%"));
799 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
801 return M_PROPERTY_OK;
803 case M_PROPERTY_STEP_UP:
804 case M_PROPERTY_STEP_DOWN:
805 mixer_getbalance(&mpctx->mixer, &bal);
806 bal += (arg ? *(float*)arg : .1f) *
807 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
808 M_PROPERTY_CLAMP(prop, bal);
809 mixer_setbalance(&mpctx->mixer, bal);
810 return M_PROPERTY_OK;
811 case M_PROPERTY_SET:
812 if (!arg)
813 return M_PROPERTY_ERROR;
814 M_PROPERTY_CLAMP(prop, *(float*)arg);
815 mixer_setbalance(&mpctx->mixer, *(float*)arg);
816 return M_PROPERTY_OK;
818 return M_PROPERTY_NOT_IMPLEMENTED;
821 /// Selected audio id (RW)
822 static int mp_property_audio(m_option_t *prop, int action, void *arg,
823 MPContext *mpctx)
825 struct MPOpts *opts = &mpctx->opts;
826 int current_id = -1, tmp;
828 switch (action) {
829 case M_PROPERTY_GET:
830 if (!mpctx->sh_audio)
831 return M_PROPERTY_UNAVAILABLE;
832 if (!arg)
833 return M_PROPERTY_ERROR;
834 *(int *) arg = opts->audio_id;
835 return M_PROPERTY_OK;
836 case M_PROPERTY_PRINT:
837 if (!mpctx->sh_audio)
838 return M_PROPERTY_UNAVAILABLE;
839 if (!arg)
840 return M_PROPERTY_ERROR;
842 if (opts->audio_id < 0)
843 *(char **) arg = strdup(_("disabled"));
844 else {
845 char lang[40] = _("unknown");
846 sh_audio_t* sh = mpctx->sh_audio;
847 if (sh && sh->lang)
848 av_strlcpy(lang, sh->lang, 40);
849 #ifdef CONFIG_DVDREAD
850 else if (mpctx->stream->type == STREAMTYPE_DVD) {
851 int code = dvd_lang_from_aid(mpctx->stream, opts->audio_id);
852 if (code) {
853 lang[0] = code >> 8;
854 lang[1] = code;
855 lang[2] = 0;
858 #endif
860 #ifdef CONFIG_DVDNAV
861 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
862 mp_dvdnav_lang_from_aid(mpctx->stream, opts->audio_id, lang);
863 #endif
864 *(char **) arg = malloc(64);
865 snprintf(*(char **) arg, 64, "(%d) %s", opts->audio_id, lang);
867 return M_PROPERTY_OK;
869 case M_PROPERTY_STEP_UP:
870 case M_PROPERTY_SET:
871 if (!mpctx->demuxer)
872 return M_PROPERTY_UNAVAILABLE;
873 if (action == M_PROPERTY_SET && arg)
874 tmp = *((int *) arg);
875 else
876 tmp = -1;
877 current_id = mpctx->demuxer->audio->id;
878 opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
879 if (opts->audio_id == -2
880 || (opts->audio_id > -1
881 && mpctx->demuxer->audio->id != current_id && current_id != -2))
882 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
883 if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
884 sh_audio_t *sh2;
885 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
886 if (sh2) {
887 sh2->ds = mpctx->demuxer->audio;
888 mpctx->sh_audio = sh2;
889 reinit_audio_chain(mpctx);
892 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id);
893 return M_PROPERTY_OK;
894 default:
895 return M_PROPERTY_NOT_IMPLEMENTED;
900 /// Selected video id (RW)
901 static int mp_property_video(m_option_t *prop, int action, void *arg,
902 MPContext *mpctx)
904 struct MPOpts *opts = &mpctx->opts;
905 int current_id = -1, tmp;
907 switch (action) {
908 case M_PROPERTY_GET:
909 if (!mpctx->sh_video)
910 return M_PROPERTY_UNAVAILABLE;
911 if (!arg)
912 return M_PROPERTY_ERROR;
913 *(int *) arg = opts->video_id;
914 return M_PROPERTY_OK;
915 case M_PROPERTY_PRINT:
916 if (!mpctx->sh_video)
917 return M_PROPERTY_UNAVAILABLE;
918 if (!arg)
919 return M_PROPERTY_ERROR;
921 if (opts->video_id < 0)
922 *(char **) arg = strdup(_("disabled"));
923 else {
924 char lang[40] = _("unknown");
925 *(char **) arg = malloc(64);
926 snprintf(*(char **) arg, 64, "(%d) %s", opts->video_id, lang);
928 return M_PROPERTY_OK;
930 case M_PROPERTY_STEP_UP:
931 case M_PROPERTY_SET:
932 current_id = mpctx->demuxer->video->id;
933 if (action == M_PROPERTY_SET && arg)
934 tmp = *((int *) arg);
935 else
936 tmp = -1;
937 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
938 if (opts->video_id == -2
939 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
940 && current_id != -2))
941 uninit_player(mpctx, INITIALIZED_VCODEC |
942 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
943 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
944 sh_video_t *sh2;
945 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
946 if (sh2) {
947 sh2->ds = mpctx->demuxer->video;
948 mpctx->sh_video = sh2;
949 reinit_video_chain(mpctx);
952 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
953 return M_PROPERTY_OK;
955 default:
956 return M_PROPERTY_NOT_IMPLEMENTED;
960 static int mp_property_program(m_option_t *prop, int action, void *arg,
961 MPContext *mpctx)
963 demux_program_t prog;
965 switch (action) {
966 case M_PROPERTY_STEP_UP:
967 case M_PROPERTY_SET:
968 if (action == M_PROPERTY_SET && arg)
969 prog.progid = *((int *) arg);
970 else
971 prog.progid = -1;
972 if (demux_control
973 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
974 &prog) == DEMUXER_CTRL_NOTIMPL)
975 return M_PROPERTY_ERROR;
977 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
978 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
979 return M_PROPERTY_OK;
981 default:
982 return M_PROPERTY_NOT_IMPLEMENTED;
986 ///@}
988 /// \defgroup VideoProperties Video properties
989 /// \ingroup Properties
990 ///@{
992 /// Fullscreen state (RW)
993 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
994 MPContext *mpctx)
997 if (!mpctx->video_out)
998 return M_PROPERTY_UNAVAILABLE;
1000 switch (action) {
1001 case M_PROPERTY_SET:
1002 if (!arg)
1003 return M_PROPERTY_ERROR;
1004 M_PROPERTY_CLAMP(prop, *(int *) arg);
1005 if (vo_fs == !!*(int *) arg)
1006 return M_PROPERTY_OK;
1007 case M_PROPERTY_STEP_UP:
1008 case M_PROPERTY_STEP_DOWN:
1009 if (mpctx->video_out->config_ok)
1010 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1011 mpctx->opts.fullscreen = vo_fs;
1012 return M_PROPERTY_OK;
1013 default:
1014 return m_property_flag(prop, action, arg, &vo_fs);
1018 static int mp_property_deinterlace(m_option_t *prop, int action,
1019 void *arg, MPContext *mpctx)
1021 int deinterlace;
1022 vf_instance_t *vf;
1023 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1024 return M_PROPERTY_UNAVAILABLE;
1025 vf = mpctx->sh_video->vfilter;
1026 switch (action) {
1027 case M_PROPERTY_GET:
1028 if (!arg)
1029 return M_PROPERTY_ERROR;
1030 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1031 return M_PROPERTY_OK;
1032 case M_PROPERTY_SET:
1033 if (!arg)
1034 return M_PROPERTY_ERROR;
1035 M_PROPERTY_CLAMP(prop, *(int *) arg);
1036 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1037 return M_PROPERTY_OK;
1038 case M_PROPERTY_STEP_UP:
1039 case M_PROPERTY_STEP_DOWN:
1040 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1041 deinterlace = !deinterlace;
1042 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1043 return M_PROPERTY_OK;
1045 return M_PROPERTY_NOT_IMPLEMENTED;
1048 /// Panscan (RW)
1049 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1050 MPContext *mpctx)
1053 if (!mpctx->video_out
1054 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1055 return M_PROPERTY_UNAVAILABLE;
1057 switch (action) {
1058 case M_PROPERTY_SET:
1059 if (!arg)
1060 return M_PROPERTY_ERROR;
1061 M_PROPERTY_CLAMP(prop, *(float *) arg);
1062 vo_panscan = *(float *) arg;
1063 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1064 return M_PROPERTY_OK;
1065 case M_PROPERTY_STEP_UP:
1066 case M_PROPERTY_STEP_DOWN:
1067 vo_panscan += (arg ? *(float *) arg : 0.1) *
1068 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1069 if (vo_panscan > 1)
1070 vo_panscan = 1;
1071 else if (vo_panscan < 0)
1072 vo_panscan = 0;
1073 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1074 return M_PROPERTY_OK;
1075 default:
1076 return m_property_float_range(prop, action, arg, &vo_panscan);
1080 /// Helper to set vo flags.
1081 /** \ingroup PropertyImplHelper
1083 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1084 int vo_ctrl, int *vo_var, MPContext *mpctx)
1087 if (!mpctx->video_out)
1088 return M_PROPERTY_UNAVAILABLE;
1090 switch (action) {
1091 case M_PROPERTY_SET:
1092 if (!arg)
1093 return M_PROPERTY_ERROR;
1094 M_PROPERTY_CLAMP(prop, *(int *) arg);
1095 if (*vo_var == !!*(int *) arg)
1096 return M_PROPERTY_OK;
1097 case M_PROPERTY_STEP_UP:
1098 case M_PROPERTY_STEP_DOWN:
1099 if (mpctx->video_out->config_ok)
1100 vo_control(mpctx->video_out, vo_ctrl, 0);
1101 return M_PROPERTY_OK;
1102 default:
1103 return m_property_flag(prop, action, arg, vo_var);
1107 /// Window always on top (RW)
1108 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1109 MPContext *mpctx)
1111 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1112 &mpctx->opts.vo_ontop, mpctx);
1115 /// Display in the root window (RW)
1116 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1117 MPContext *mpctx)
1119 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1120 &vo_rootwin, mpctx);
1123 /// Show window borders (RW)
1124 static int mp_property_border(m_option_t *prop, int action, void *arg,
1125 MPContext *mpctx)
1127 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1128 &vo_border, mpctx);
1131 /// Framedropping state (RW)
1132 static int mp_property_framedropping(m_option_t *prop, int action,
1133 void *arg, MPContext *mpctx)
1136 if (!mpctx->sh_video)
1137 return M_PROPERTY_UNAVAILABLE;
1139 switch (action) {
1140 case M_PROPERTY_PRINT:
1141 if (!arg)
1142 return M_PROPERTY_ERROR;
1143 *(char **) arg = strdup(frame_dropping == 1 ? _("enabled") :
1144 (frame_dropping == 2 ? _("hard") :
1145 _("disabled")));
1146 return M_PROPERTY_OK;
1147 default:
1148 return m_property_choice(prop, action, arg, &frame_dropping);
1152 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1153 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1154 MPContext *mpctx)
1156 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1157 int r, val;
1159 if (!mpctx->sh_video)
1160 return M_PROPERTY_UNAVAILABLE;
1162 if (gamma[0] == 1000) {
1163 gamma[0] = 0;
1164 get_video_colors(mpctx->sh_video, prop->name, gamma);
1167 switch (action) {
1168 case M_PROPERTY_SET:
1169 if (!arg)
1170 return M_PROPERTY_ERROR;
1171 M_PROPERTY_CLAMP(prop, *(int *) arg);
1172 *gamma = *(int *) arg;
1173 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1174 if (r <= 0)
1175 break;
1176 return r;
1177 case M_PROPERTY_GET:
1178 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1179 if (!arg)
1180 return M_PROPERTY_ERROR;
1181 *(int *)arg = val;
1182 return M_PROPERTY_OK;
1184 break;
1185 case M_PROPERTY_STEP_UP:
1186 case M_PROPERTY_STEP_DOWN:
1187 *gamma += (arg ? *(int *) arg : 1) *
1188 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1189 M_PROPERTY_CLAMP(prop, *gamma);
1190 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1191 if (r <= 0)
1192 break;
1193 return r;
1194 default:
1195 return M_PROPERTY_NOT_IMPLEMENTED;
1198 #ifdef CONFIG_TV
1199 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1200 int l = strlen(prop->name);
1201 char tv_prop[3 + l + 1];
1202 sprintf(tv_prop, "tv_%s", prop->name);
1203 return mp_property_do(tv_prop, action, arg, mpctx);
1205 #endif
1207 return M_PROPERTY_UNAVAILABLE;
1210 /// VSync (RW)
1211 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1212 MPContext *mpctx)
1214 return m_property_flag(prop, action, arg, &vo_vsync);
1217 /// Video codec tag (RO)
1218 static int mp_property_video_format(m_option_t *prop, int action,
1219 void *arg, MPContext *mpctx)
1221 char* meta;
1222 if (!mpctx->sh_video)
1223 return M_PROPERTY_UNAVAILABLE;
1224 switch(action) {
1225 case M_PROPERTY_PRINT:
1226 if (!arg)
1227 return M_PROPERTY_ERROR;
1228 switch(mpctx->sh_video->format) {
1229 case 0x10000001:
1230 meta = strdup ("mpeg1"); break;
1231 case 0x10000002:
1232 meta = strdup ("mpeg2"); break;
1233 case 0x10000004:
1234 meta = strdup ("mpeg4"); break;
1235 case 0x10000005:
1236 meta = strdup ("h264"); break;
1237 default:
1238 if(mpctx->sh_video->format >= 0x20202020) {
1239 meta = malloc(5);
1240 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1241 } else {
1242 meta = malloc(20);
1243 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1246 *(char**)arg = meta;
1247 return M_PROPERTY_OK;
1249 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1252 /// Video codec name (RO)
1253 static int mp_property_video_codec(m_option_t *prop, int action,
1254 void *arg, MPContext *mpctx)
1256 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1257 return M_PROPERTY_UNAVAILABLE;
1258 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1262 /// Video bitrate (RO)
1263 static int mp_property_video_bitrate(m_option_t *prop, int action,
1264 void *arg, MPContext *mpctx)
1266 if (!mpctx->sh_video)
1267 return M_PROPERTY_UNAVAILABLE;
1268 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1271 /// Video display width (RO)
1272 static int mp_property_width(m_option_t *prop, int action, void *arg,
1273 MPContext *mpctx)
1275 if (!mpctx->sh_video)
1276 return M_PROPERTY_UNAVAILABLE;
1277 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1280 /// Video display height (RO)
1281 static int mp_property_height(m_option_t *prop, int action, void *arg,
1282 MPContext *mpctx)
1284 if (!mpctx->sh_video)
1285 return M_PROPERTY_UNAVAILABLE;
1286 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1289 /// Video fps (RO)
1290 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1291 MPContext *mpctx)
1293 if (!mpctx->sh_video)
1294 return M_PROPERTY_UNAVAILABLE;
1295 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1298 /// Video aspect (RO)
1299 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1300 MPContext *mpctx)
1302 if (!mpctx->sh_video)
1303 return M_PROPERTY_UNAVAILABLE;
1304 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1307 ///@}
1309 /// \defgroup SubProprties Subtitles properties
1310 /// \ingroup Properties
1311 ///@{
1313 /// Text subtitle position (RW)
1314 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1315 MPContext *mpctx)
1317 if (!mpctx->sh_video)
1318 return M_PROPERTY_UNAVAILABLE;
1320 switch (action) {
1321 case M_PROPERTY_SET:
1322 if (!arg)
1323 return M_PROPERTY_ERROR;
1324 case M_PROPERTY_STEP_UP:
1325 case M_PROPERTY_STEP_DOWN:
1326 vo_osd_changed(OSDTYPE_SUBTITLE);
1327 default:
1328 return m_property_int_range(prop, action, arg, &sub_pos);
1332 /// Selected subtitles (RW)
1333 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1334 MPContext *mpctx)
1336 struct MPOpts *opts = &mpctx->opts;
1337 demux_stream_t *const d_sub = mpctx->d_sub;
1338 const int global_sub_size = mpctx->global_sub_size;
1339 int source = -1, reset_spu = 0;
1340 char *sub_name;
1342 if (!mpctx->sh_video || global_sub_size <= 0)
1343 return M_PROPERTY_UNAVAILABLE;
1345 switch (action) {
1346 case M_PROPERTY_GET:
1347 if (!arg)
1348 return M_PROPERTY_ERROR;
1349 *(int *) arg = mpctx->global_sub_pos;
1350 return M_PROPERTY_OK;
1351 case M_PROPERTY_PRINT:
1352 if (!arg)
1353 return M_PROPERTY_ERROR;
1354 *(char **) arg = malloc(64);
1355 (*(char **) arg)[63] = 0;
1356 sub_name = 0;
1357 if (subdata)
1358 sub_name = subdata->filename;
1359 #ifdef CONFIG_ASS
1360 if (ass_track && ass_track->name)
1361 sub_name = ass_track->name;
1362 #endif
1363 if (sub_name) {
1364 char *tmp, *tmp2;
1365 tmp = sub_name;
1366 if ((tmp2 = strrchr(tmp, '/')))
1367 tmp = tmp2 + 1;
1369 snprintf(*(char **) arg, 63, "(%d) %s%s",
1370 mpctx->set_of_sub_pos + 1,
1371 strlen(tmp) < 20 ? "" : "...",
1372 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1373 return M_PROPERTY_OK;
1375 #ifdef CONFIG_DVDNAV
1376 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1377 if (vo_spudec && opts->sub_id >= 0) {
1378 unsigned char lang[3];
1379 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1380 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1381 return M_PROPERTY_OK;
1385 #endif
1387 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1388 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1389 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1390 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1391 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1392 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1393 if (!lang) lang = _("unknown");
1394 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1395 return M_PROPERTY_OK;
1398 if (vo_vobsub && vobsub_id >= 0) {
1399 const char *language = _("unknown");
1400 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1401 snprintf(*(char **) arg, 63, "(%d) %s",
1402 vobsub_id, language ? language : _("unknown"));
1403 return M_PROPERTY_OK;
1405 #ifdef CONFIG_DVDREAD
1406 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1407 && opts->sub_id >= 0) {
1408 char lang[3];
1409 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1410 lang[0] = code >> 8;
1411 lang[1] = code;
1412 lang[2] = 0;
1413 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1414 return M_PROPERTY_OK;
1416 #endif
1417 if (opts->sub_id >= 0) {
1418 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, _("unknown"));
1419 return M_PROPERTY_OK;
1421 snprintf(*(char **) arg, 63, _("disabled"));
1422 return M_PROPERTY_OK;
1424 case M_PROPERTY_SET:
1425 if (!arg)
1426 return M_PROPERTY_ERROR;
1427 if (*(int *) arg < -1)
1428 *(int *) arg = -1;
1429 else if (*(int *) arg >= global_sub_size)
1430 *(int *) arg = global_sub_size - 1;
1431 mpctx->global_sub_pos = *(int *) arg;
1432 break;
1433 case M_PROPERTY_STEP_UP:
1434 mpctx->global_sub_pos += 2;
1435 mpctx->global_sub_pos =
1436 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1437 break;
1438 case M_PROPERTY_STEP_DOWN:
1439 mpctx->global_sub_pos += global_sub_size + 1;
1440 mpctx->global_sub_pos =
1441 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1442 break;
1443 default:
1444 return M_PROPERTY_NOT_IMPLEMENTED;
1447 if (mpctx->global_sub_pos >= 0)
1448 source = sub_source(mpctx);
1450 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1451 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1452 global_sub_size,
1453 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1454 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1455 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1456 mpctx->global_sub_pos, source);
1458 mpctx->set_of_sub_pos = -1;
1459 subdata = NULL;
1461 vobsub_id = -1;
1462 opts->sub_id = -1;
1463 if (d_sub) {
1464 if (d_sub->id > -2)
1465 reset_spu = 1;
1466 d_sub->id = -2;
1468 #ifdef CONFIG_ASS
1469 ass_track = 0;
1470 #endif
1472 if (source == SUB_SOURCE_VOBSUB) {
1473 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1474 } else if (source == SUB_SOURCE_SUBS) {
1475 mpctx->set_of_sub_pos =
1476 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1477 #ifdef CONFIG_ASS
1478 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1479 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1480 else
1481 #endif
1483 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1484 vo_osd_changed(OSDTYPE_SUBTITLE);
1486 } else if (source == SUB_SOURCE_DEMUX) {
1487 opts->sub_id =
1488 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1489 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1490 int i = 0;
1491 // default: assume 1:1 mapping of sid and stream id
1492 d_sub->id = opts->sub_id;
1493 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1494 ds_free_packs(d_sub);
1495 for (i = 0; i < MAX_S_STREAMS; i++) {
1496 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1497 if (sh && sh->sid == opts->sub_id) {
1498 d_sub->id = i;
1499 d_sub->sh = sh;
1500 break;
1503 if (d_sub->sh && d_sub->id >= 0) {
1504 sh_sub_t *sh = d_sub->sh;
1505 if (sh->type == 'v')
1506 init_vo_spudec(mpctx);
1507 #ifdef CONFIG_ASS
1508 else if (ass_enabled)
1509 ass_track = sh->ass_track;
1510 #endif
1511 } else {
1512 d_sub->id = -2;
1513 d_sub->sh = NULL;
1517 #ifdef CONFIG_DVDREAD
1518 if (vo_spudec
1519 && (mpctx->stream->type == STREAMTYPE_DVD
1520 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1521 && opts->sub_id < 0 && reset_spu) {
1522 opts->sub_id = -2;
1523 d_sub->id = opts->sub_id;
1525 #endif
1526 update_subtitles(mpctx->sh_video, d_sub, 0, 1);
1528 return M_PROPERTY_OK;
1531 /// Selected sub source (RW)
1532 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1533 MPContext *mpctx)
1535 int source;
1536 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1537 return M_PROPERTY_UNAVAILABLE;
1539 switch (action) {
1540 case M_PROPERTY_GET:
1541 if (!arg)
1542 return M_PROPERTY_ERROR;
1543 *(int *) arg = sub_source(mpctx);
1544 return M_PROPERTY_OK;
1545 case M_PROPERTY_PRINT:
1546 if (!arg)
1547 return M_PROPERTY_ERROR;
1548 *(char **) arg = malloc(64);
1549 (*(char **) arg)[63] = 0;
1550 switch (sub_source(mpctx))
1552 case SUB_SOURCE_SUBS:
1553 snprintf(*(char **) arg, 63, _("file"));
1554 break;
1555 case SUB_SOURCE_VOBSUB:
1556 snprintf(*(char **) arg, 63, _("vobsub"));
1557 break;
1558 case SUB_SOURCE_DEMUX:
1559 snprintf(*(char **) arg, 63, _("embedded"));
1560 break;
1561 default:
1562 snprintf(*(char **) arg, 63, _("disabled"));
1564 return M_PROPERTY_OK;
1565 case M_PROPERTY_SET:
1566 if (!arg)
1567 return M_PROPERTY_ERROR;
1568 M_PROPERTY_CLAMP(prop, *(int*)arg);
1569 if (*(int *) arg < 0)
1570 mpctx->global_sub_pos = -1;
1571 else if (*(int *) arg != sub_source(mpctx)) {
1572 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1573 return M_PROPERTY_UNAVAILABLE;
1574 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1576 break;
1577 case M_PROPERTY_STEP_UP:
1578 case M_PROPERTY_STEP_DOWN: {
1579 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1580 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1581 int step = (step_all > 0) ? 1 : -1;
1582 int cur_source = sub_source(mpctx);
1583 source = cur_source;
1584 while (step_all) {
1585 source += step;
1586 if (source >= SUB_SOURCES)
1587 source = -1;
1588 else if (source < -1)
1589 source = SUB_SOURCES - 1;
1590 if (source == cur_source || source == -1 ||
1591 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1592 step_all -= step;
1594 if (source == cur_source)
1595 return M_PROPERTY_OK;
1596 if (source == -1)
1597 mpctx->global_sub_pos = -1;
1598 else
1599 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1600 break;
1602 default:
1603 return M_PROPERTY_NOT_IMPLEMENTED;
1605 --mpctx->global_sub_pos;
1606 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1609 /// Selected subtitles from specific source (RW)
1610 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1611 MPContext *mpctx)
1613 int source, is_cur_source, offset;
1614 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1615 return M_PROPERTY_UNAVAILABLE;
1617 if (!strcmp(prop->name, "sub_file"))
1618 source = SUB_SOURCE_SUBS;
1619 else if (!strcmp(prop->name, "sub_vob"))
1620 source = SUB_SOURCE_VOBSUB;
1621 else if (!strcmp(prop->name, "sub_demux"))
1622 source = SUB_SOURCE_DEMUX;
1623 else
1624 return M_PROPERTY_ERROR;
1626 offset = mpctx->global_sub_indices[source];
1627 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1628 return M_PROPERTY_UNAVAILABLE;
1630 is_cur_source = sub_source(mpctx) == source;
1631 switch (action) {
1632 case M_PROPERTY_GET:
1633 if (!arg)
1634 return M_PROPERTY_ERROR;
1635 if (is_cur_source) {
1636 *(int *) arg = mpctx->global_sub_pos - offset;
1637 if (source == SUB_SOURCE_VOBSUB)
1638 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1640 else
1641 *(int *) arg = -1;
1642 return M_PROPERTY_OK;
1643 case M_PROPERTY_PRINT:
1644 if (!arg)
1645 return M_PROPERTY_ERROR;
1646 if (is_cur_source)
1647 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1648 *(char **) arg = malloc(64);
1649 (*(char **) arg)[63] = 0;
1650 snprintf(*(char **) arg, 63, _("disabled"));
1651 return M_PROPERTY_OK;
1652 case M_PROPERTY_SET:
1653 if (!arg)
1654 return M_PROPERTY_ERROR;
1655 if (*(int *) arg >= 0) {
1656 int index = *(int *)arg;
1657 if (source == SUB_SOURCE_VOBSUB)
1658 index = vobsub_get_index_by_id(vo_vobsub, index);
1659 mpctx->global_sub_pos = offset + index;
1660 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1661 || sub_source(mpctx) != source) {
1662 mpctx->global_sub_pos = -1;
1663 *(int *) arg = -1;
1666 else
1667 mpctx->global_sub_pos = -1;
1668 break;
1669 case M_PROPERTY_STEP_UP:
1670 case M_PROPERTY_STEP_DOWN: {
1671 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1672 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1673 int step = (step_all > 0) ? 1 : -1;
1674 int max_sub_pos_for_source = -1;
1675 if (!is_cur_source)
1676 mpctx->global_sub_pos = -1;
1677 while (step_all) {
1678 if (mpctx->global_sub_pos == -1) {
1679 if (step > 0)
1680 mpctx->global_sub_pos = offset;
1681 else if (max_sub_pos_for_source == -1) {
1682 // Find max pos for specific source
1683 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1684 while (mpctx->global_sub_pos >= 0
1685 && sub_source(mpctx) != source)
1686 --mpctx->global_sub_pos;
1688 else
1689 mpctx->global_sub_pos = max_sub_pos_for_source;
1691 else {
1692 mpctx->global_sub_pos += step;
1693 if (mpctx->global_sub_pos < offset ||
1694 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1695 sub_source(mpctx) != source)
1696 mpctx->global_sub_pos = -1;
1698 step_all -= step;
1700 break;
1702 default:
1703 return M_PROPERTY_NOT_IMPLEMENTED;
1705 --mpctx->global_sub_pos;
1706 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1709 /// Subtitle delay (RW)
1710 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1711 MPContext *mpctx)
1713 if (!mpctx->sh_video)
1714 return M_PROPERTY_UNAVAILABLE;
1715 return m_property_delay(prop, action, arg, &sub_delay);
1718 /// Alignment of text subtitles (RW)
1719 static int mp_property_sub_alignment(m_option_t *prop, int action,
1720 void *arg, MPContext *mpctx)
1722 char *name[] = { _("top"), _("center"), _("bottom") };
1724 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1725 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1726 return M_PROPERTY_UNAVAILABLE;
1728 switch (action) {
1729 case M_PROPERTY_PRINT:
1730 if (!arg)
1731 return M_PROPERTY_ERROR;
1732 M_PROPERTY_CLAMP(prop, sub_alignment);
1733 *(char **) arg = strdup(name[sub_alignment]);
1734 return M_PROPERTY_OK;
1735 case M_PROPERTY_SET:
1736 if (!arg)
1737 return M_PROPERTY_ERROR;
1738 case M_PROPERTY_STEP_UP:
1739 case M_PROPERTY_STEP_DOWN:
1740 vo_osd_changed(OSDTYPE_SUBTITLE);
1741 default:
1742 return m_property_choice(prop, action, arg, &sub_alignment);
1746 /// Subtitle visibility (RW)
1747 static int mp_property_sub_visibility(m_option_t *prop, int action,
1748 void *arg, MPContext *mpctx)
1750 if (!mpctx->sh_video)
1751 return M_PROPERTY_UNAVAILABLE;
1753 switch (action) {
1754 case M_PROPERTY_SET:
1755 if (!arg)
1756 return M_PROPERTY_ERROR;
1757 case M_PROPERTY_STEP_UP:
1758 case M_PROPERTY_STEP_DOWN:
1759 vo_osd_changed(OSDTYPE_SUBTITLE);
1760 if (vo_spudec)
1761 vo_osd_changed(OSDTYPE_SPU);
1762 default:
1763 return m_property_flag(prop, action, arg, &sub_visibility);
1767 #ifdef CONFIG_ASS
1768 /// Use margins for libass subtitles (RW)
1769 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1770 void *arg, MPContext *mpctx)
1772 if (!mpctx->sh_video)
1773 return M_PROPERTY_UNAVAILABLE;
1775 switch (action) {
1776 case M_PROPERTY_SET:
1777 if (!arg)
1778 return M_PROPERTY_ERROR;
1779 case M_PROPERTY_STEP_UP:
1780 case M_PROPERTY_STEP_DOWN:
1781 ass_force_reload = 1;
1782 default:
1783 return m_property_flag(prop, action, arg, &ass_use_margins);
1786 #endif
1788 /// Show only forced subtitles (RW)
1789 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1790 void *arg, MPContext *mpctx)
1792 if (!vo_spudec)
1793 return M_PROPERTY_UNAVAILABLE;
1795 switch (action) {
1796 case M_PROPERTY_SET:
1797 if (!arg)
1798 return M_PROPERTY_ERROR;
1799 case M_PROPERTY_STEP_UP:
1800 case M_PROPERTY_STEP_DOWN:
1801 m_property_flag(prop, action, arg, &forced_subs_only);
1802 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1803 return M_PROPERTY_OK;
1804 default:
1805 return m_property_flag(prop, action, arg, &forced_subs_only);
1810 #ifdef CONFIG_FREETYPE
1811 /// Subtitle scale (RW)
1812 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1813 MPContext *mpctx)
1816 switch (action) {
1817 case M_PROPERTY_SET:
1818 if (!arg)
1819 return M_PROPERTY_ERROR;
1820 M_PROPERTY_CLAMP(prop, *(float *) arg);
1821 #ifdef CONFIG_ASS
1822 if (ass_enabled) {
1823 ass_font_scale = *(float *) arg;
1824 ass_force_reload = 1;
1826 #endif
1827 text_font_scale_factor = *(float *) arg;
1828 force_load_font = 1;
1829 return M_PROPERTY_OK;
1830 case M_PROPERTY_STEP_UP:
1831 case M_PROPERTY_STEP_DOWN:
1832 #ifdef CONFIG_ASS
1833 if (ass_enabled) {
1834 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1835 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1836 M_PROPERTY_CLAMP(prop, ass_font_scale);
1837 ass_force_reload = 1;
1839 #endif
1840 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1841 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1842 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1843 force_load_font = 1;
1844 return M_PROPERTY_OK;
1845 default:
1846 #ifdef CONFIG_ASS
1847 if (ass_enabled)
1848 return m_property_float_ro(prop, action, arg, ass_font_scale);
1849 else
1850 #endif
1851 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1854 #endif
1856 ///@}
1858 /// \defgroup TVProperties TV properties
1859 /// \ingroup Properties
1860 ///@{
1862 #ifdef CONFIG_TV
1864 /// TV color settings (RW)
1865 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1866 MPContext *mpctx)
1868 int r, val;
1869 tvi_handle_t *tvh = mpctx->demuxer->priv;
1870 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1871 return M_PROPERTY_UNAVAILABLE;
1873 switch (action) {
1874 case M_PROPERTY_SET:
1875 if (!arg)
1876 return M_PROPERTY_ERROR;
1877 M_PROPERTY_CLAMP(prop, *(int *) arg);
1878 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1879 case M_PROPERTY_GET:
1880 return tv_get_color_options(tvh, (int) prop->priv, arg);
1881 case M_PROPERTY_STEP_UP:
1882 case M_PROPERTY_STEP_DOWN:
1883 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1884 if (!r)
1885 return M_PROPERTY_ERROR;
1886 val += (arg ? *(int *) arg : 1) *
1887 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1888 M_PROPERTY_CLAMP(prop, val);
1889 return tv_set_color_options(tvh, (int) prop->priv, val);
1891 return M_PROPERTY_ERROR;
1893 return M_PROPERTY_NOT_IMPLEMENTED;
1896 #endif
1898 #ifdef CONFIG_TV_TELETEXT
1899 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1900 MPContext *mpctx)
1902 int val,result;
1903 int base_ioctl=(int)prop->priv;
1905 for teletext's GET,SET,STEP ioctls this is not 0
1906 SET is GET+1
1907 STEP is GET+2
1909 tvi_handle_t *tvh = mpctx->demuxer->priv;
1910 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1911 return M_PROPERTY_UNAVAILABLE;
1912 if(!base_ioctl)
1913 return M_PROPERTY_ERROR;
1915 switch (action) {
1916 case M_PROPERTY_GET:
1917 if (!arg)
1918 return M_PROPERTY_ERROR;
1919 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1920 break;
1921 case M_PROPERTY_SET:
1922 if (!arg)
1923 return M_PROPERTY_ERROR;
1924 M_PROPERTY_CLAMP(prop, *(int *) arg);
1925 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1926 break;
1927 case M_PROPERTY_STEP_UP:
1928 case M_PROPERTY_STEP_DOWN:
1929 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1930 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1931 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1932 break;
1933 default:
1934 return M_PROPERTY_NOT_IMPLEMENTED;
1937 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1940 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
1941 MPContext *mpctx)
1943 tvi_handle_t *tvh = mpctx->demuxer->priv;
1944 int result;
1945 int val;
1947 //with tvh==NULL will fail too
1948 result=mp_property_teletext_common(prop,action,arg,mpctx);
1949 if(result!=M_PROPERTY_OK)
1950 return result;
1952 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1953 mp_input_set_section(mpctx->input, "teletext");
1954 else
1955 mp_input_set_section(mpctx->input, "tv");
1956 return M_PROPERTY_OK;
1959 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
1960 MPContext *mpctx)
1962 tvi_handle_t *tvh = mpctx->demuxer->priv;
1963 int result;
1964 int val;
1965 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1966 return M_PROPERTY_UNAVAILABLE;
1967 switch(action){
1968 case M_PROPERTY_STEP_UP:
1969 case M_PROPERTY_STEP_DOWN:
1970 //This should be handled separately
1971 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1972 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1973 break;
1974 default:
1975 result=mp_property_teletext_common(prop,action,arg,mpctx);
1977 return result;
1981 #endif /* CONFIG_TV_TELETEXT */
1983 ///@}
1985 /// All properties available in MPlayer.
1986 /** \ingroup Properties
1988 static const m_option_t mp_properties[] = {
1989 // General
1990 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1991 M_OPT_RANGE, 0, 3, NULL },
1992 { "loop", mp_property_loop, CONF_TYPE_INT,
1993 M_OPT_MIN, -1, 0, NULL },
1994 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1995 M_OPT_RANGE, 0.01, 100.0, NULL },
1996 { "filename", mp_property_filename, CONF_TYPE_STRING,
1997 0, 0, 0, NULL },
1998 { "path", mp_property_path, CONF_TYPE_STRING,
1999 0, 0, 0, NULL },
2000 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2001 0, 0, 0, NULL },
2002 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2003 M_OPT_MIN, 0, 0, NULL },
2004 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2005 M_OPT_MIN, 0, 0, NULL },
2006 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2007 M_OPT_MIN, 0, 0, NULL },
2008 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2009 M_OPT_MIN, 0, 0, NULL },
2010 { "length", mp_property_length, CONF_TYPE_TIME,
2011 M_OPT_MIN, 0, 0, NULL },
2012 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2013 M_OPT_RANGE, 0, 100, NULL },
2014 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2015 M_OPT_MIN, 0, 0, NULL },
2016 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2017 M_OPT_MIN, 0, 0, NULL },
2018 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2019 0, 0, 0, NULL },
2020 { "angle", mp_property_angle, CONF_TYPE_INT,
2021 CONF_RANGE, -2, 10, NULL },
2022 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2023 0, 0, 0, NULL },
2024 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2025 M_OPT_RANGE, 0, 1, NULL },
2027 // Audio
2028 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2029 M_OPT_RANGE, 0, 100, NULL },
2030 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2031 M_OPT_RANGE, 0, 1, NULL },
2032 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2033 M_OPT_RANGE, -100, 100, NULL },
2034 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2035 0, 0, 0, NULL },
2036 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2037 0, 0, 0, NULL },
2038 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2039 0, 0, 0, NULL },
2040 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2041 0, 0, 0, NULL },
2042 { "channels", mp_property_channels, CONF_TYPE_INT,
2043 0, 0, 0, NULL },
2044 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2045 CONF_RANGE, -2, 65535, NULL },
2046 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2047 M_OPT_RANGE, -1, 1, NULL },
2049 // Video
2050 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2051 M_OPT_RANGE, 0, 1, NULL },
2052 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2053 M_OPT_RANGE, 0, 1, NULL },
2054 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2055 M_OPT_RANGE, 0, 1, NULL },
2056 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2057 M_OPT_RANGE, 0, 1, NULL },
2058 { "border", mp_property_border, CONF_TYPE_FLAG,
2059 M_OPT_RANGE, 0, 1, NULL },
2060 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2061 M_OPT_RANGE, 0, 2, NULL },
2062 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2063 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2064 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2065 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2066 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2067 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2068 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2069 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2070 { "hue", mp_property_gamma, CONF_TYPE_INT,
2071 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2072 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2073 M_OPT_RANGE, 0, 1, NULL },
2074 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2075 M_OPT_RANGE, 0, 1, NULL },
2076 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2077 0, 0, 0, NULL },
2078 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2079 0, 0, 0, NULL },
2080 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2081 0, 0, 0, NULL },
2082 { "width", mp_property_width, CONF_TYPE_INT,
2083 0, 0, 0, NULL },
2084 { "height", mp_property_height, CONF_TYPE_INT,
2085 0, 0, 0, NULL },
2086 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2087 0, 0, 0, NULL },
2088 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2089 0, 0, 0, NULL },
2090 { "switch_video", mp_property_video, CONF_TYPE_INT,
2091 CONF_RANGE, -2, 65535, NULL },
2092 { "switch_program", mp_property_program, CONF_TYPE_INT,
2093 CONF_RANGE, -1, 65535, NULL },
2095 // Subs
2096 { "sub", mp_property_sub, CONF_TYPE_INT,
2097 M_OPT_MIN, -1, 0, NULL },
2098 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2099 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2100 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2101 M_OPT_MIN, -1, 0, NULL },
2102 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2103 M_OPT_MIN, -1, 0, NULL },
2104 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2105 M_OPT_MIN, -1, 0, NULL },
2106 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2107 0, 0, 0, NULL },
2108 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2109 M_OPT_RANGE, 0, 100, NULL },
2110 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2111 M_OPT_RANGE, 0, 2, NULL },
2112 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2113 M_OPT_RANGE, 0, 1, NULL },
2114 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2115 M_OPT_RANGE, 0, 1, NULL },
2116 #ifdef CONFIG_FREETYPE
2117 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2118 M_OPT_RANGE, 0, 100, NULL },
2119 #endif
2120 #ifdef CONFIG_ASS
2121 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2122 M_OPT_RANGE, 0, 1, NULL },
2123 #endif
2125 #ifdef CONFIG_TV
2126 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2127 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2128 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2129 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2130 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2131 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2132 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2133 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2134 #endif
2136 #ifdef CONFIG_TV_TELETEXT
2137 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2138 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2139 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2140 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2141 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2142 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2143 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2144 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2145 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2146 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2147 #endif
2149 { NULL, NULL, NULL, 0, 0, 0, NULL }
2153 int mp_property_do(const char *name, int action, void *val, void *ctx)
2155 return m_property_do(mp_properties, name, action, val, ctx);
2158 char* mp_property_print(const char *name, void* ctx)
2160 char* ret = NULL;
2161 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2162 return NULL;
2163 return ret;
2166 char *property_expand_string(MPContext *mpctx, char *str)
2168 return m_properties_expand_string(mp_properties, str, mpctx);
2171 void property_print_help(void)
2173 m_properties_print_help_list(mp_properties);
2177 ///@}
2178 // Properties group
2182 * \defgroup Command2Property Command to property bridge
2184 * It is used to handle most commands that just set a property
2185 * and optionally display something on the OSD.
2186 * Two kinds of commands are handled: adjust or toggle.
2188 * Adjust commands take 1 or 2 parameters: <value> <abs>
2189 * If <abs> is non-zero the property is set to the given value
2190 * otherwise it is adjusted.
2192 * Toggle commands take 0 or 1 parameters. With no parameter
2193 * or a value less than the property minimum it just steps the
2194 * property to its next value. Otherwise it sets it to the given
2195 * value.
2200 /// List of the commands that can be handled by setting a property.
2201 static struct {
2202 /// property name
2203 const char *name;
2204 /// cmd id
2205 int cmd;
2206 /// set/adjust or toggle command
2207 int toggle;
2208 /// progressbar type
2209 int osd_progbar; // -1 is special value for seek indicators
2210 /// osd msg id if it must be shared
2211 int osd_id;
2212 /// osd msg template
2213 const char *osd_msg;
2214 } set_prop_cmd[] = {
2215 // general
2216 { "loop", MP_CMD_LOOP, 0, 0, -1, _("Loop: %s") },
2217 { "chapter", MP_CMD_SEEK_CHAPTER, 0, -1, -1, NULL },
2218 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2219 { "pause", MP_CMD_PAUSE, 0, 0, -1, NULL },
2220 // audio
2221 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, _("Volume") },
2222 { "mute", MP_CMD_MUTE, 1, 0, -1, _("Mute: %s") },
2223 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, _("A-V delay: %s") },
2224 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, _("Audio: %s") },
2225 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, _("Balance") },
2226 // video
2227 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2228 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, _("Panscan") },
2229 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, _("Stay on top: %s") },
2230 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, _("Rootwin: %s") },
2231 { "border", MP_CMD_VO_BORDER, 1, 0, -1, _("Border: %s") },
2232 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, _("Framedropping: %s") },
2233 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, _("Gamma") },
2234 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, _("Brightness") },
2235 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, _("Contrast") },
2236 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, _("Saturation") },
2237 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, _("Hue") },
2238 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, _("VSync: %s") },
2239 // subs
2240 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, _("Subtitles: %s") },
2241 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, _("Sub source: %s") },
2242 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, _("Subtitles: %s") },
2243 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, _("Subtitles: %s") },
2244 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, _("Subtitles: %s") },
2245 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, _("Sub position: %s/100") },
2246 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, _("Sub alignment: %s") },
2247 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2248 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, _("Subtitles: %s") },
2249 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, _("Forced sub only: %s") },
2250 #ifdef CONFIG_FREETYPE
2251 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, _("Sub Scale: %s")},
2252 #endif
2253 #ifdef CONFIG_ASS
2254 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2255 #endif
2256 #ifdef CONFIG_TV
2257 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, _("Brightness") },
2258 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, _("Hue") },
2259 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, _("Saturation") },
2260 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, _("Contrast") },
2261 #endif
2262 { NULL, 0, 0, 0, -1, NULL }
2266 /// Handle commands that set a property.
2267 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2269 struct MPOpts *opts = &mpctx->opts;
2270 int i, r;
2271 m_option_t* prop;
2272 const char *pname;
2274 // look for the command
2275 for (i = 0; set_prop_cmd[i].name; i++)
2276 if (set_prop_cmd[i].cmd == cmd->id)
2277 break;
2278 if (!(pname = set_prop_cmd[i].name))
2279 return 0;
2281 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2282 return 0;
2284 // toggle command
2285 if (set_prop_cmd[i].toggle) {
2286 // set to value
2287 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2288 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2289 else
2290 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2291 } else if (cmd->args[1].v.i) //set
2292 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2293 else // adjust
2294 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2296 if (r <= 0)
2297 return 1;
2299 if (set_prop_cmd[i].osd_progbar == -1)
2300 mpctx->add_osd_seek_info = true;
2301 else if (set_prop_cmd[i].osd_progbar) {
2302 if (prop->type == CONF_TYPE_INT) {
2303 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2304 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2305 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2306 } else if (prop->type == CONF_TYPE_FLOAT) {
2307 float f;
2308 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2309 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2310 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2311 } else
2312 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2313 "Property use an unsupported type.\n");
2314 return 1;
2317 if (set_prop_cmd[i].osd_msg) {
2318 char *val = mp_property_print(pname, mpctx);
2319 if (val) {
2320 set_osd_msg(set_prop_cmd[i].osd_id >=
2321 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2322 1, opts->osd_duration, set_prop_cmd[i].osd_msg, val);
2323 free(val);
2326 return 1;
2329 #ifdef CONFIG_DVDNAV
2330 static const struct {
2331 const char *name;
2332 const mp_command_type cmd;
2333 } mp_dvdnav_bindings[] = {
2334 { "up", MP_CMD_DVDNAV_UP },
2335 { "down", MP_CMD_DVDNAV_DOWN },
2336 { "left", MP_CMD_DVDNAV_LEFT },
2337 { "right", MP_CMD_DVDNAV_RIGHT },
2338 { "menu", MP_CMD_DVDNAV_MENU },
2339 { "select", MP_CMD_DVDNAV_SELECT },
2340 { "prev", MP_CMD_DVDNAV_PREVMENU },
2341 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2344 * keep old dvdnav sub-command options for a while in order not to
2345 * break slave-mode API too suddenly.
2347 { "1", MP_CMD_DVDNAV_UP },
2348 { "2", MP_CMD_DVDNAV_DOWN },
2349 { "3", MP_CMD_DVDNAV_LEFT },
2350 { "4", MP_CMD_DVDNAV_RIGHT },
2351 { "5", MP_CMD_DVDNAV_MENU },
2352 { "6", MP_CMD_DVDNAV_SELECT },
2353 { "7", MP_CMD_DVDNAV_PREVMENU },
2354 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2355 { NULL, 0 }
2357 #endif
2359 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2361 struct MPOpts *opts = &mpctx->opts;
2362 sh_audio_t * const sh_audio = mpctx->sh_audio;
2363 sh_video_t * const sh_video = mpctx->sh_video;
2364 int osd_duration = opts->osd_duration;
2365 if (!set_property_command(mpctx, cmd))
2366 switch (cmd->id) {
2367 case MP_CMD_SEEK:{
2368 float v;
2369 int abs;
2370 mpctx->add_osd_seek_info = true;
2371 v = cmd->args[0].v.f;
2372 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2373 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2374 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2375 if (sh_video)
2376 mpctx->osd_function =
2377 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2378 mpctx->rel_seek_secs = v;
2379 } else if (abs) { /* Absolute seek by percentage */
2380 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2381 if (sh_video)
2382 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2383 mpctx->rel_seek_secs = v / 100.0;
2384 } else {
2385 mpctx->rel_seek_secs += v;
2386 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2389 break;
2391 case MP_CMD_SET_PROPERTY:{
2392 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2393 cmd->args[1].v.s, mpctx);
2394 if (r == M_PROPERTY_UNKNOWN)
2395 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2396 "Unknown property: '%s'\n", cmd->args[0].v.s);
2397 else if (r <= 0)
2398 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2399 "Failed to set property '%s' to '%s'.\n",
2400 cmd->args[0].v.s, cmd->args[1].v.s);
2402 break;
2404 case MP_CMD_STEP_PROPERTY:{
2405 void* arg = NULL;
2406 int r,i;
2407 double d;
2408 off_t o;
2409 if (cmd->args[1].v.f) {
2410 m_option_t* prop;
2411 if((r = mp_property_do(cmd->args[0].v.s,
2412 M_PROPERTY_GET_TYPE,
2413 &prop, mpctx)) <= 0)
2414 goto step_prop_err;
2415 if(prop->type == CONF_TYPE_INT ||
2416 prop->type == CONF_TYPE_FLAG)
2417 i = cmd->args[1].v.f, arg = &i;
2418 else if(prop->type == CONF_TYPE_FLOAT)
2419 arg = &cmd->args[1].v.f;
2420 else if(prop->type == CONF_TYPE_DOUBLE ||
2421 prop->type == CONF_TYPE_TIME)
2422 d = cmd->args[1].v.f, arg = &d;
2423 else if(prop->type == CONF_TYPE_POSITION)
2424 o = cmd->args[1].v.f, arg = &o;
2425 else
2426 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2427 "Ignoring step size stepping property '%s'.\n",
2428 cmd->args[0].v.s);
2430 r = mp_property_do(cmd->args[0].v.s,
2431 cmd->args[2].v.i < 0 ?
2432 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2433 arg, mpctx);
2434 step_prop_err:
2435 if (r == M_PROPERTY_UNKNOWN)
2436 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2437 "Unknown property: '%s'\n", cmd->args[0].v.s);
2438 else if (r <= 0)
2439 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2440 "Failed to increment property '%s' by %f.\n",
2441 cmd->args[0].v.s, cmd->args[1].v.f);
2443 break;
2445 case MP_CMD_GET_PROPERTY:{
2446 char *tmp;
2447 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2448 &tmp, mpctx) <= 0) {
2449 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2450 "Failed to get value of property '%s'.\n",
2451 cmd->args[0].v.s);
2452 break;
2454 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2455 cmd->args[0].v.s, tmp);
2456 free(tmp);
2458 break;
2460 case MP_CMD_EDL_MARK:
2461 if (edl_fd) {
2462 float v = sh_video ? sh_video->pts :
2463 playing_audio_pts(mpctx);
2464 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2465 mpctx->begin_skip = v;
2466 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2467 } else {
2468 if (mpctx->begin_skip > v)
2469 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2470 else {
2471 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2472 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2474 mpctx->begin_skip = MP_NOPTS_VALUE;
2477 break;
2479 case MP_CMD_SWITCH_RATIO:
2480 if (!sh_video)
2481 break;
2482 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2483 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2484 else
2485 opts->movie_aspect = cmd->args[0].v.f;
2486 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2487 break;
2489 case MP_CMD_SPEED_INCR:{
2490 float v = cmd->args[0].v.f;
2491 opts->playback_speed += v;
2492 build_afilter_chain(mpctx, sh_audio, &ao_data);
2493 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2494 opts->playback_speed);
2495 } break;
2497 case MP_CMD_SPEED_MULT:{
2498 float v = cmd->args[0].v.f;
2499 opts->playback_speed *= v;
2500 build_afilter_chain(mpctx, sh_audio, &ao_data);
2501 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2502 opts->playback_speed);
2503 } break;
2505 case MP_CMD_SPEED_SET:{
2506 float v = cmd->args[0].v.f;
2507 opts->playback_speed = v;
2508 build_afilter_chain(mpctx, sh_audio, &ao_data);
2509 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2510 opts->playback_speed);
2511 } break;
2513 case MP_CMD_FRAME_STEP:
2514 add_step_frame(mpctx);
2515 break;
2517 case MP_CMD_FILE_FILTER:
2518 file_filter = cmd->args[0].v.i;
2519 break;
2521 case MP_CMD_QUIT:
2522 exit_player_with_rc(mpctx, EXIT_QUIT,
2523 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2525 case MP_CMD_PLAY_TREE_STEP:{
2526 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2527 int force = cmd->args[1].v.i;
2530 if (!force && mpctx->playtree_iter) {
2531 play_tree_iter_t *i =
2532 play_tree_iter_new_copy(mpctx->playtree_iter);
2533 if (play_tree_iter_step(i, n, 0) ==
2534 PLAY_TREE_ITER_ENTRY)
2535 mpctx->stop_play =
2536 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2537 play_tree_iter_free(i);
2538 } else
2539 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2540 if (mpctx->stop_play)
2541 mpctx->play_tree_step = n;
2544 break;
2546 case MP_CMD_PLAY_TREE_UP_STEP:{
2547 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2548 int force = cmd->args[1].v.i;
2550 if (!force && mpctx->playtree_iter) {
2551 play_tree_iter_t *i =
2552 play_tree_iter_new_copy(mpctx->playtree_iter);
2553 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2554 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2555 play_tree_iter_free(i);
2556 } else
2557 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2559 break;
2561 case MP_CMD_PLAY_ALT_SRC_STEP:
2562 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2563 int v = cmd->args[0].v.i;
2564 if (v > 0
2565 && mpctx->playtree_iter->file <
2566 mpctx->playtree_iter->num_files)
2567 mpctx->stop_play = PT_NEXT_SRC;
2568 else if (v < 0 && mpctx->playtree_iter->file > 1)
2569 mpctx->stop_play = PT_PREV_SRC;
2571 break;
2573 case MP_CMD_SUB_STEP:
2574 if (sh_video) {
2575 int movement = cmd->args[0].v.i;
2576 step_sub(subdata, sh_video->pts, movement);
2577 #ifdef CONFIG_ASS
2578 if (ass_track)
2579 sub_delay +=
2580 ass_step_sub(ass_track,
2581 (sh_video->pts +
2582 sub_delay) * 1000 + .5, movement) / 1000.;
2583 #endif
2584 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2585 _("Sub delay: %d ms"), ROUND(sub_delay * 1000));
2587 break;
2589 case MP_CMD_SUB_LOG:
2590 log_sub(mpctx);
2591 break;
2593 case MP_CMD_OSD:{
2594 int v = cmd->args[0].v.i;
2595 int max = (term_osd
2596 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2597 if (opts->osd_level > max)
2598 opts->osd_level = max;
2599 if (v < 0)
2600 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2601 else
2602 opts->osd_level = v > max ? max : v;
2603 /* Show OSD state when disabled, but not when an explicit
2604 argument is given to the OSD command, i.e. in slave mode. */
2605 if (v == -1 && opts->osd_level <= 1)
2606 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2607 _("OSD: %s"),
2608 opts->osd_level ? _("enabled") :
2609 _("disabled"));
2610 else
2611 rm_osd_msg(OSD_MSG_OSD_STATUS);
2613 break;
2615 case MP_CMD_OSD_SHOW_TEXT:
2616 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2617 (cmd->args[1].v.i <
2618 0 ? osd_duration : cmd->args[1].v.i),
2619 "%-.63s", cmd->args[0].v.s);
2620 break;
2622 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2623 char *txt = m_properties_expand_string(mp_properties,
2624 cmd->args[0].v.s,
2625 mpctx);
2626 /* if no argument supplied take default osd_duration, else <arg> ms. */
2627 if (txt) {
2628 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2629 (cmd->args[1].v.i <
2630 0 ? osd_duration : cmd->args[1].v.i),
2631 "%-.63s", txt);
2632 free(txt);
2635 break;
2637 case MP_CMD_LOADFILE:{
2638 play_tree_t *e = play_tree_new();
2639 play_tree_add_file(e, cmd->args[0].v.s);
2641 if (cmd->args[1].v.i) // append
2642 play_tree_append_entry(mpctx->playtree->child, e);
2643 else {
2644 // Go back to the starting point.
2645 while (play_tree_iter_up_step
2646 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2647 /* NOP */ ;
2648 play_tree_free_list(mpctx->playtree->child, 1);
2649 play_tree_set_child(mpctx->playtree, e);
2650 pt_iter_goto_head(mpctx->playtree_iter);
2651 mpctx->stop_play = PT_NEXT_SRC;
2654 break;
2656 case MP_CMD_LOADLIST:{
2657 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2658 if (!e)
2659 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2660 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2661 else {
2662 if (cmd->args[1].v.i) // append
2663 play_tree_append_entry(mpctx->playtree->child, e);
2664 else {
2665 // Go back to the starting point.
2666 while (play_tree_iter_up_step
2667 (mpctx->playtree_iter, 0, 1)
2668 != PLAY_TREE_ITER_END)
2669 /* NOP */ ;
2670 play_tree_free_list(mpctx->playtree->child, 1);
2671 play_tree_set_child(mpctx->playtree, e);
2672 pt_iter_goto_head(mpctx->playtree_iter);
2673 mpctx->stop_play = PT_NEXT_SRC;
2677 break;
2679 case MP_CMD_STOP:
2680 // Go back to the starting point.
2681 while (play_tree_iter_up_step
2682 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2683 /* NOP */ ;
2684 mpctx->stop_play = PT_STOP;
2685 break;
2687 #ifdef CONFIG_RADIO
2688 case MP_CMD_RADIO_STEP_CHANNEL:
2689 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2690 int v = cmd->args[0].v.i;
2691 if (v > 0)
2692 radio_step_channel(mpctx->demuxer->stream,
2693 RADIO_CHANNEL_HIGHER);
2694 else
2695 radio_step_channel(mpctx->demuxer->stream,
2696 RADIO_CHANNEL_LOWER);
2697 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2698 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2699 _("Channel: %s"),
2700 radio_get_channel_name(mpctx->demuxer->stream));
2703 break;
2705 case MP_CMD_RADIO_SET_CHANNEL:
2706 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2707 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2708 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2709 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2710 _("Channel: %s"),
2711 radio_get_channel_name(mpctx->demuxer->stream));
2714 break;
2716 case MP_CMD_RADIO_SET_FREQ:
2717 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2718 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2719 break;
2721 case MP_CMD_RADIO_STEP_FREQ:
2722 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2723 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2724 break;
2725 #endif
2727 #ifdef CONFIG_TV
2728 case MP_CMD_TV_START_SCAN:
2729 if (mpctx->file_format == DEMUXER_TYPE_TV)
2730 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2731 break;
2732 case MP_CMD_TV_SET_FREQ:
2733 if (mpctx->file_format == DEMUXER_TYPE_TV)
2734 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2735 cmd->args[0].v.f * 16.0);
2736 #ifdef CONFIG_PVR
2737 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2738 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2739 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2740 pvr_get_current_channelname (mpctx->stream),
2741 pvr_get_current_stationname (mpctx->stream));
2743 #endif /* CONFIG_PVR */
2744 break;
2746 case MP_CMD_TV_STEP_FREQ:
2747 if (mpctx->file_format == DEMUXER_TYPE_TV)
2748 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2749 cmd->args[0].v.f * 16.0);
2750 #ifdef CONFIG_PVR
2751 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2752 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2753 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2754 pvr_get_current_channelname (mpctx->stream),
2755 pvr_get_current_frequency (mpctx->stream));
2757 #endif /* CONFIG_PVR */
2758 break;
2760 case MP_CMD_TV_SET_NORM:
2761 if (mpctx->file_format == DEMUXER_TYPE_TV)
2762 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2763 cmd->args[0].v.s);
2764 break;
2766 case MP_CMD_TV_STEP_CHANNEL:{
2767 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2768 int v = cmd->args[0].v.i;
2769 if (v > 0) {
2770 tv_step_channel((tvi_handle_t *) (mpctx->
2771 demuxer->priv),
2772 TV_CHANNEL_HIGHER);
2773 } else {
2774 tv_step_channel((tvi_handle_t *) (mpctx->
2775 demuxer->priv),
2776 TV_CHANNEL_LOWER);
2778 if (tv_channel_list) {
2779 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2780 _("Channel: %s"), tv_channel_current->name);
2781 //vo_osd_changed(OSDTYPE_SUBTITLE);
2784 #ifdef CONFIG_PVR
2785 else if (mpctx->stream &&
2786 mpctx->stream->type == STREAMTYPE_PVR) {
2787 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2788 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2789 pvr_get_current_channelname (mpctx->stream),
2790 pvr_get_current_stationname (mpctx->stream));
2792 #endif /* CONFIG_PVR */
2794 #ifdef CONFIG_DVBIN
2795 if (mpctx->stream->type == STREAMTYPE_DVB) {
2796 int dir;
2797 int v = cmd->args[0].v.i;
2799 mpctx->last_dvb_step = v;
2800 if (v > 0)
2801 dir = DVB_CHANNEL_HIGHER;
2802 else
2803 dir = DVB_CHANNEL_LOWER;
2806 if (dvb_step_channel(mpctx->stream, dir)) {
2807 mpctx->stop_play = PT_NEXT_ENTRY;
2808 mpctx->dvbin_reopen = 1;
2811 #endif /* CONFIG_DVBIN */
2812 break;
2814 case MP_CMD_TV_SET_CHANNEL:
2815 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2816 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2817 cmd->args[0].v.s);
2818 if (tv_channel_list) {
2819 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2820 _("Channel: %s"), tv_channel_current->name);
2821 //vo_osd_changed(OSDTYPE_SUBTITLE);
2824 #ifdef CONFIG_PVR
2825 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2826 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2827 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2828 pvr_get_current_channelname (mpctx->stream),
2829 pvr_get_current_stationname (mpctx->stream));
2831 #endif /* CONFIG_PVR */
2832 break;
2834 #ifdef CONFIG_DVBIN
2835 case MP_CMD_DVB_SET_CHANNEL:
2836 if (mpctx->stream->type == STREAMTYPE_DVB) {
2837 mpctx->last_dvb_step = 1;
2839 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
2840 cmd->args[0].v.i)) {
2841 mpctx->stop_play = PT_NEXT_ENTRY;
2842 mpctx->dvbin_reopen = 1;
2845 break;
2846 #endif /* CONFIG_DVBIN */
2848 case MP_CMD_TV_LAST_CHANNEL:
2849 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2850 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2851 if (tv_channel_list) {
2852 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2853 _("Channel: %s"), tv_channel_current->name);
2854 //vo_osd_changed(OSDTYPE_SUBTITLE);
2857 #ifdef CONFIG_PVR
2858 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2859 pvr_set_lastchannel (mpctx->stream);
2860 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2861 pvr_get_current_channelname (mpctx->stream),
2862 pvr_get_current_stationname (mpctx->stream));
2864 #endif /* CONFIG_PVR */
2865 break;
2867 case MP_CMD_TV_STEP_NORM:
2868 if (mpctx->file_format == DEMUXER_TYPE_TV)
2869 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2870 break;
2872 case MP_CMD_TV_STEP_CHANNEL_LIST:
2873 if (mpctx->file_format == DEMUXER_TYPE_TV)
2874 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2875 break;
2876 #ifdef CONFIG_TV_TELETEXT
2877 case MP_CMD_TV_TELETEXT_ADD_DEC:
2879 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2880 if (mpctx->file_format == DEMUXER_TYPE_TV)
2881 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2882 break;
2884 case MP_CMD_TV_TELETEXT_GO_LINK:
2886 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2887 if (mpctx->file_format == DEMUXER_TYPE_TV)
2888 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2889 break;
2891 #endif /* CONFIG_TV_TELETEXT */
2892 #endif /* CONFIG_TV */
2894 case MP_CMD_SUB_LOAD:
2895 if (sh_video) {
2896 int n = mpctx->set_of_sub_size;
2897 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
2898 if (n != mpctx->set_of_sub_size) {
2899 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2900 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2901 mpctx->global_sub_size;
2902 ++mpctx->global_sub_size;
2905 break;
2907 case MP_CMD_SUB_REMOVE:
2908 if (sh_video) {
2909 int v = cmd->args[0].v.i;
2910 sub_data *subd;
2911 if (v < 0) {
2912 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2913 subd = mpctx->set_of_subtitles[v];
2914 mp_tmsg(MSGT_CPLAYER, MSGL_STATUS,
2915 "SUB: Removed subtitle file (%d): %s\n", v + 1,
2916 filename_recode(subd->filename));
2917 sub_free(subd);
2918 mpctx->set_of_subtitles[v] = NULL;
2920 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2921 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2922 mpctx->set_of_sub_size = 0;
2923 if (mpctx->set_of_sub_pos >= 0) {
2924 mpctx->global_sub_pos = -2;
2925 subdata = NULL;
2926 mp_input_queue_cmd(mpctx->input,
2927 mp_input_parse_cmd("sub_select"));
2929 } else if (v < mpctx->set_of_sub_size) {
2930 subd = mpctx->set_of_subtitles[v];
2931 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2932 "SUB: Removed subtitle file (%d): %s\n", v + 1,
2933 filename_recode(subd->filename));
2934 sub_free(subd);
2935 if (mpctx->set_of_sub_pos == v) {
2936 mpctx->global_sub_pos = -2;
2937 subdata = NULL;
2938 mp_input_queue_cmd(mpctx->input,
2939 mp_input_parse_cmd("sub_select"));
2940 } else if (mpctx->set_of_sub_pos > v) {
2941 --mpctx->set_of_sub_pos;
2942 --mpctx->global_sub_pos;
2944 while (++v < mpctx->set_of_sub_size)
2945 mpctx->set_of_subtitles[v - 1] =
2946 mpctx->set_of_subtitles[v];
2947 --mpctx->set_of_sub_size;
2948 --mpctx->global_sub_size;
2949 if (mpctx->set_of_sub_size <= 0)
2950 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2951 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2954 break;
2956 case MP_CMD_GET_SUB_VISIBILITY:
2957 if (sh_video) {
2958 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2959 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2961 break;
2963 case MP_CMD_SCREENSHOT:
2964 if (mpctx->video_out && mpctx->video_out->config_ok) {
2965 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2966 if (CONTROL_OK !=
2967 ((vf_instance_t *) sh_video->vfilter)->
2968 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2969 &cmd->args[0].v.i))
2970 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2972 break;
2974 case MP_CMD_VF_CHANGE_RECTANGLE:
2975 if (!sh_video)
2976 break;
2977 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2978 break;
2980 case MP_CMD_GET_TIME_LENGTH:{
2981 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2982 demuxer_get_time_length(mpctx->demuxer));
2984 break;
2986 case MP_CMD_GET_FILENAME:{
2987 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2988 get_metadata(mpctx, META_NAME));
2990 break;
2992 case MP_CMD_GET_VIDEO_CODEC:{
2993 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
2994 if (!inf)
2995 inf = strdup("");
2996 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2997 free(inf);
2999 break;
3001 case MP_CMD_GET_VIDEO_BITRATE:{
3002 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3003 if (!inf)
3004 inf = strdup("");
3005 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3006 free(inf);
3008 break;
3010 case MP_CMD_GET_VIDEO_RESOLUTION:{
3011 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3012 if (!inf)
3013 inf = strdup("");
3014 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3015 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3016 free(inf);
3018 break;
3020 case MP_CMD_GET_AUDIO_CODEC:{
3021 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3022 if (!inf)
3023 inf = strdup("");
3024 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3025 free(inf);
3027 break;
3029 case MP_CMD_GET_AUDIO_BITRATE:{
3030 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3031 if (!inf)
3032 inf = strdup("");
3033 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3034 free(inf);
3036 break;
3038 case MP_CMD_GET_AUDIO_SAMPLES:{
3039 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3040 if (!inf)
3041 inf = strdup("");
3042 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3043 free(inf);
3045 break;
3047 case MP_CMD_GET_META_TITLE:{
3048 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3049 if (!inf)
3050 inf = strdup("");
3051 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3052 free(inf);
3054 break;
3056 case MP_CMD_GET_META_ARTIST:{
3057 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3058 if (!inf)
3059 inf = strdup("");
3060 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3061 free(inf);
3063 break;
3065 case MP_CMD_GET_META_ALBUM:{
3066 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3067 if (!inf)
3068 inf = strdup("");
3069 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3070 free(inf);
3072 break;
3074 case MP_CMD_GET_META_YEAR:{
3075 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3076 if (!inf)
3077 inf = strdup("");
3078 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3079 free(inf);
3081 break;
3083 case MP_CMD_GET_META_COMMENT:{
3084 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3085 if (!inf)
3086 inf = strdup("");
3087 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3088 free(inf);
3090 break;
3092 case MP_CMD_GET_META_TRACK:{
3093 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3094 if (!inf)
3095 inf = strdup("");
3096 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3097 free(inf);
3099 break;
3101 case MP_CMD_GET_META_GENRE:{
3102 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3103 if (!inf)
3104 inf = strdup("");
3105 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3106 free(inf);
3108 break;
3110 case MP_CMD_GET_VO_FULLSCREEN:
3111 if (mpctx->video_out && mpctx->video_out->config_ok)
3112 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3113 break;
3115 case MP_CMD_GET_PERCENT_POS:
3116 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3117 demuxer_get_percent_pos(mpctx->demuxer));
3118 break;
3120 case MP_CMD_GET_TIME_POS:{
3121 float pos = 0;
3122 if (sh_video)
3123 pos = sh_video->pts;
3124 else if (sh_audio && mpctx->audio_out)
3125 pos = playing_audio_pts(mpctx);
3126 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3128 break;
3130 case MP_CMD_RUN:
3131 #ifndef __MINGW32__
3132 if (!fork()) {
3133 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3134 exit(0);
3136 #endif
3137 break;
3139 case MP_CMD_KEYDOWN_EVENTS:
3140 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3141 break;
3143 case MP_CMD_SET_MOUSE_POS:{
3144 int pointer_x, pointer_y;
3145 double dx, dy;
3146 pointer_x = cmd->args[0].v.i;
3147 pointer_y = cmd->args[1].v.i;
3148 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3149 #ifdef CONFIG_DVDNAV
3150 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3151 && dx > 0.0 && dy > 0.0) {
3152 int button = -1;
3153 pointer_x = (int) (dx * (double) sh_video->disp_w);
3154 pointer_y = (int) (dy * (double) sh_video->disp_h);
3155 mp_dvdnav_update_mouse_pos(mpctx->stream,
3156 pointer_x, pointer_y, &button);
3157 if (opts->osd_level > 1 && button > 0)
3158 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3159 "Selected button number %d", button);
3161 #endif
3162 #ifdef CONFIG_MENU
3163 if (use_menu && dx >= 0.0 && dy >= 0.0)
3164 menu_update_mouse_pos(dx, dy);
3165 #endif
3167 break;
3169 #ifdef CONFIG_DVDNAV
3170 case MP_CMD_DVDNAV:{
3171 int button = -1;
3172 int i;
3173 mp_command_type command = 0;
3174 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3175 break;
3177 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3178 if (cmd->args[0].v.s &&
3179 !strcasecmp (cmd->args[0].v.s,
3180 mp_dvdnav_bindings[i].name))
3181 command = mp_dvdnav_bindings[i].cmd;
3183 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3184 if (opts->osd_level > 1 && button > 0)
3185 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3186 "Selected button number %d", button);
3188 break;
3190 case MP_CMD_SWITCH_TITLE:
3191 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3192 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3193 break;
3195 #endif
3197 default:
3198 mp_msg(MSGT_CPLAYER, MSGL_V,
3199 "Received unknown cmd %s\n", cmd->name);
3202 switch (cmd->pausing) {
3203 case 1: // "pausing"
3204 pause_player(mpctx);
3205 break;
3206 case 3: // "pausing_toggle"
3207 if (mpctx->paused)
3208 unpause_player(mpctx);
3209 else
3210 pause_player(mpctx);
3211 break;