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