synced with r26138
[mplayer/glamo.git] / command.c
blobe666aee1d2d50e8d9015f1c4ec158b64de10caff
1 #include <stdlib.h>
2 #include <inttypes.h>
3 #include <unistd.h>
4 #include <string.h>
6 #include "config.h"
7 #include "input/input.h"
8 #include "stream/stream.h"
9 #include "libmpdemux/demuxer.h"
10 #include "libmpdemux/stheader.h"
11 #include "codec-cfg.h"
12 #include "mplayer.h"
13 #include "libvo/sub.h"
14 #include "m_option.h"
15 #include "m_property.h"
16 #include "help_mp.h"
17 #include "metadata.h"
18 #include "libmpcodecs/mp_image.h"
19 #include "libmpcodecs/vf.h"
20 #include "libmpcodecs/vd.h"
21 #include "libvo/video_out.h"
22 #include "libvo/font_load.h"
23 #include "playtree.h"
24 #include "libao2/audio_out.h"
25 #include "mpcommon.h"
26 #include "mixer.h"
27 #include "libmpdemux/matroska.h"
28 #include "libmpcodecs/dec_video.h"
29 #include "vobsub.h"
30 #include "spudec.h"
31 #include "get_path.h"
32 #ifdef USE_TV
33 #include "stream/tv.h"
34 #endif
35 #ifdef USE_RADIO
36 #include "stream/stream_radio.h"
37 #endif
38 #ifdef HAVE_PVR
39 #include "stream/pvr.h"
40 #endif
41 #ifdef HAS_DVBIN_SUPPORT
42 #include "stream/dvbin.h"
43 #endif
44 #ifdef USE_DVDREAD
45 #include "stream/stream_dvd.h"
46 #endif
47 #ifdef USE_DVDNAV
48 #include "stream/stream_dvdnav.h"
49 #endif
50 #ifdef USE_ASS
51 #include "libass/ass.h"
52 #include "libass/ass_mp.h"
53 #endif
54 #ifdef HAVE_MENU
55 #include "m_struct.h"
56 #include "libmenu/menu.h"
57 #endif
58 #ifdef HAVE_NEW_GUI
59 #include "gui/interface.h"
60 #endif
62 #include "mp_core.h"
63 #include "mp_fifo.h"
64 #include "libavutil/avstring.h"
66 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
68 extern int use_menu;
70 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy)
72 //remove the borders, if any, and rescale to the range [0,1],[0,1]
73 if (vo_fs) { //we are in full-screen mode
74 if (vo_screenwidth > vo_dwidth) //there are borders along the x axis
75 ix -= (vo_screenwidth - vo_dwidth) / 2;
76 if (vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
77 iy -= (vo_screenheight - vo_dheight) / 2;
79 if (ix < 0 || ix > vo_dwidth) {
80 *dx = *dy = -1.0;
81 return;
82 } //we are on one of the borders
83 if (iy < 0 || iy > vo_dheight) {
84 *dx = *dy = -1.0;
85 return;
86 } //we are on one of the borders
89 *dx = (double) ix / (double) vo_dwidth;
90 *dy = (double) iy / (double) vo_dheight;
92 mp_msg(MSGT_CPLAYER, MSGL_V,
93 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
94 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth,
95 vo_dheight, vo_fs);
98 static int sub_source_by_pos(MPContext * mpctx, int pos)
100 int source = -1;
101 int top = -1;
102 int i;
103 for (i = 0; i < SUB_SOURCES; i++) {
104 int j = mpctx->global_sub_indices[i];
105 if ((j >= 0) && (j > top) && (pos >= j)) {
106 source = i;
107 top = j;
110 return source;
113 static int sub_source(MPContext * mpctx)
115 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
119 * \brief Log the currently displayed subtitle to a file
121 * Logs the current or last displayed subtitle together with filename
122 * and time information to ~/.mplayer/subtitle_log
124 * Intended purpose is to allow convenient marking of bogus subtitles
125 * which need to be fixed while watching the movie.
128 static void log_sub(void)
130 char *fname;
131 FILE *f;
132 int i;
134 if (subdata == NULL || vo_sub_last == NULL)
135 return;
136 fname = get_path("subtitle_log");
137 f = fopen(fname, "a");
138 if (!f)
139 return;
140 fprintf(f, "----------------------------------------------------------\n");
141 if (subdata->sub_uses_time) {
142 fprintf(f,
143 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
144 filename, vo_sub_last->start / 360000,
145 (vo_sub_last->start / 6000) % 60,
146 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
147 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
148 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
149 } else {
150 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start,
151 vo_sub_last->end);
153 for (i = 0; i < vo_sub_last->lines; i++) {
154 fprintf(f, "%s\n", vo_sub_last->text[i]);
156 fclose(f);
160 /// \defgroup Properties
161 ///@{
163 /// \defgroup GeneralProperties General properties
164 /// \ingroup Properties
165 ///@{
167 /// OSD level (RW)
168 static int mp_property_osdlevel(m_option_t * prop, int action, void *arg,
169 MPContext * mpctx)
171 return m_property_choice(prop, action, arg, &osd_level);
174 /// Loop (RW)
175 static int mp_property_loop(m_option_t * prop, int action, void *arg,
176 MPContext * mpctx)
178 switch (action) {
179 case M_PROPERTY_PRINT:
180 if (!arg) return M_PROPERTY_ERROR;
181 if (mpctx->loop_times < 0)
182 *(char**)arg = strdup("off");
183 else if (mpctx->loop_times == 0)
184 *(char**)arg = strdup("inf");
185 else
186 break;
187 return M_PROPERTY_OK;
189 return m_property_int_range(prop, action, arg, &mpctx->loop_times);
192 /// Playback speed (RW)
193 static int mp_property_playback_speed(m_option_t * prop, int action,
194 void *arg, MPContext * mpctx)
196 switch (action) {
197 case M_PROPERTY_SET:
198 if (!arg)
199 return M_PROPERTY_ERROR;
200 M_PROPERTY_CLAMP(prop, *(float *) arg);
201 playback_speed = *(float *) arg;
202 build_afilter_chain(mpctx->sh_audio, &ao_data);
203 return M_PROPERTY_OK;
204 case M_PROPERTY_STEP_UP:
205 case M_PROPERTY_STEP_DOWN:
206 playback_speed += (arg ? *(float *) arg : 0.1) *
207 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
208 M_PROPERTY_CLAMP(prop, playback_speed);
209 build_afilter_chain(mpctx->sh_audio, &ao_data);
210 return M_PROPERTY_OK;
212 return m_property_float_range(prop, action, arg, &playback_speed);
215 /// filename with path (RO)
216 static int mp_property_path(m_option_t * prop, int action, void *arg,
217 MPContext * mpctx)
219 return m_property_string_ro(prop, action, arg, filename);
222 /// filename without path (RO)
223 static int mp_property_filename(m_option_t * prop, int action, void *arg,
224 MPContext * mpctx)
226 char *f;
227 if (!filename)
228 return M_PROPERTY_UNAVAILABLE;
229 if (((f = strrchr(filename, '/')) || (f = strrchr(filename, '\\'))) && f[1])
230 f++;
231 else
232 f = filename;
233 return m_property_string_ro(prop, action, arg, f);
236 /// Demuxer name (RO)
237 static int mp_property_demuxer(m_option_t * prop, int action, void *arg,
238 MPContext * mpctx)
240 if (!mpctx->demuxer)
241 return M_PROPERTY_UNAVAILABLE;
242 return m_property_string_ro(prop, action, arg,
243 (char *) mpctx->demuxer->desc->name);
246 /// Position in the stream (RW)
247 static int mp_property_stream_pos(m_option_t * prop, int action, void *arg,
248 MPContext * mpctx)
250 if (!mpctx->demuxer || !mpctx->demuxer->stream)
251 return M_PROPERTY_UNAVAILABLE;
252 if (!arg)
253 return M_PROPERTY_ERROR;
254 switch (action) {
255 case M_PROPERTY_GET:
256 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
257 return M_PROPERTY_OK;
258 case M_PROPERTY_SET:
259 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
260 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
261 return M_PROPERTY_OK;
263 return M_PROPERTY_NOT_IMPLEMENTED;
266 /// Stream start offset (RO)
267 static int mp_property_stream_start(m_option_t * prop, int action,
268 void *arg, MPContext * mpctx)
270 if (!mpctx->demuxer || !mpctx->demuxer->stream)
271 return M_PROPERTY_UNAVAILABLE;
272 switch (action) {
273 case M_PROPERTY_GET:
274 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
275 return M_PROPERTY_OK;
277 return M_PROPERTY_NOT_IMPLEMENTED;
280 /// Stream end offset (RO)
281 static int mp_property_stream_end(m_option_t * prop, int action, void *arg,
282 MPContext * mpctx)
284 if (!mpctx->demuxer || !mpctx->demuxer->stream)
285 return M_PROPERTY_UNAVAILABLE;
286 switch (action) {
287 case M_PROPERTY_GET:
288 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
289 return M_PROPERTY_OK;
291 return M_PROPERTY_NOT_IMPLEMENTED;
294 /// Stream length (RO)
295 static int mp_property_stream_length(m_option_t * prop, int action,
296 void *arg, MPContext * mpctx)
298 if (!mpctx->demuxer || !mpctx->demuxer->stream)
299 return M_PROPERTY_UNAVAILABLE;
300 switch (action) {
301 case M_PROPERTY_GET:
302 *(off_t *) arg =
303 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
304 return M_PROPERTY_OK;
306 return M_PROPERTY_NOT_IMPLEMENTED;
309 /// Media length in seconds (RO)
310 static int mp_property_length(m_option_t * prop, int action, void *arg,
311 MPContext * mpctx)
313 double len;
315 if (!mpctx->demuxer ||
316 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
317 return M_PROPERTY_UNAVAILABLE;
319 return m_property_time_ro(prop, action, arg, len);
322 /// Current position in percent (RW)
323 static int mp_property_percent_pos(m_option_t * prop, int action,
324 void *arg, MPContext * mpctx) {
325 int pos;
327 if (!mpctx->demuxer)
328 return M_PROPERTY_UNAVAILABLE;
330 switch(action) {
331 case M_PROPERTY_SET:
332 if(!arg) return M_PROPERTY_ERROR;
333 M_PROPERTY_CLAMP(prop, *(int*)arg);
334 pos = *(int*)arg;
335 break;
336 case M_PROPERTY_STEP_UP:
337 case M_PROPERTY_STEP_DOWN:
338 pos = demuxer_get_percent_pos(mpctx->demuxer);
339 pos += (arg ? *(int*)arg : 10) *
340 (action == M_PROPERTY_STEP_UP ? 1 : -1);
341 M_PROPERTY_CLAMP(prop, pos);
342 break;
343 default:
344 return m_property_int_ro(prop, action, arg,
345 demuxer_get_percent_pos(mpctx->demuxer));
348 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
349 rel_seek_secs = pos / 100.0;
350 return M_PROPERTY_OK;
353 /// Current position in seconds (RW)
354 static int mp_property_time_pos(m_option_t * prop, int action,
355 void *arg, MPContext * mpctx) {
356 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
357 return M_PROPERTY_UNAVAILABLE;
359 switch(action) {
360 case M_PROPERTY_SET:
361 if(!arg) return M_PROPERTY_ERROR;
362 M_PROPERTY_CLAMP(prop, *(double*)arg);
363 abs_seek_pos = SEEK_ABSOLUTE;
364 rel_seek_secs = *(double*)arg;
365 return M_PROPERTY_OK;
366 case M_PROPERTY_STEP_UP:
367 case M_PROPERTY_STEP_DOWN:
368 rel_seek_secs += (arg ? *(double*)arg : 10.0) *
369 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
370 return M_PROPERTY_OK;
372 return m_property_time_ro(prop, action, arg,
373 mpctx->sh_video ? mpctx->sh_video->pts :
374 playing_audio_pts(mpctx->sh_audio,
375 mpctx->d_audio,
376 mpctx->audio_out));
379 /// Current chapter (RW)
380 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
381 MPContext *mpctx)
383 int chapter;
384 float next_pts = 0;
385 int chapter_num;
386 int step_all;
387 char *chapter_name = NULL;
389 chapter = demuxer_get_current_chapter(mpctx->demuxer);
390 if (chapter < 0)
391 return M_PROPERTY_UNAVAILABLE;
393 switch (action) {
394 case M_PROPERTY_GET:
395 if (!arg)
396 return M_PROPERTY_ERROR;
397 *(int *) arg = chapter;
398 return M_PROPERTY_OK;
399 case M_PROPERTY_PRINT: {
400 if (!arg)
401 return M_PROPERTY_ERROR;
402 chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter);
403 if (!chapter_name)
404 return M_PROPERTY_UNAVAILABLE;
405 *(char **) arg = chapter_name;
406 return M_PROPERTY_OK;
408 case M_PROPERTY_SET:
409 if (!arg)
410 return M_PROPERTY_ERROR;
411 M_PROPERTY_CLAMP(prop, *(int*)arg);
412 step_all = *(int *)arg - (chapter + 1);
413 chapter += step_all;
414 break;
415 case M_PROPERTY_STEP_UP:
416 case M_PROPERTY_STEP_DOWN: {
417 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
418 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
419 chapter += step_all;
420 if (chapter < 0)
421 chapter = 0;
422 break;
424 default:
425 return M_PROPERTY_NOT_IMPLEMENTED;
427 rel_seek_secs = 0;
428 abs_seek_pos = 0;
429 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
430 &next_pts, &chapter_num, &chapter_name);
431 if (chapter >= 0) {
432 if (next_pts > -1.0) {
433 abs_seek_pos = SEEK_ABSOLUTE;
434 rel_seek_secs = next_pts;
436 if (chapter_name)
437 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
438 MSGTR_OSDChapter, chapter + 1, chapter_name);
440 else if (step_all > 0)
441 rel_seek_secs = 1000000000.;
442 else
443 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
444 MSGTR_OSDChapter, 0, MSGTR_Unknown);
445 if (chapter_name)
446 free(chapter_name);
447 return M_PROPERTY_OK;
450 /// Current dvd angle (RW)
451 static int mp_property_angle(m_option_t *prop, int action, void *arg,
452 MPContext *mpctx)
454 int angle;
455 int angles;
456 char *angle_name = NULL;
458 angle = demuxer_get_current_angle(mpctx->demuxer);
459 if (angle < 0)
460 return M_PROPERTY_UNAVAILABLE;
461 angles = demuxer_angles_count(mpctx->demuxer);
462 if (angles <= 1)
463 return M_PROPERTY_UNAVAILABLE;
465 switch (action) {
466 case M_PROPERTY_GET:
467 if (!arg)
468 return M_PROPERTY_ERROR;
469 *(int *) arg = angle;
470 return M_PROPERTY_OK;
471 case M_PROPERTY_PRINT: {
472 if (!arg)
473 return M_PROPERTY_ERROR;
474 angle_name = calloc(1, 64);
475 if (!angle_name)
476 return M_PROPERTY_UNAVAILABLE;
477 snprintf(angle_name, 64, "%d/%d", angle, angles);
478 *(char **) arg = angle_name;
479 return M_PROPERTY_OK;
481 case M_PROPERTY_SET:
482 if (!arg)
483 return M_PROPERTY_ERROR;
484 angle = *(int *)arg;
485 M_PROPERTY_CLAMP(prop, angle);
486 break;
487 case M_PROPERTY_STEP_UP:
488 case M_PROPERTY_STEP_DOWN: {
489 int step = 0;
490 if(arg)
491 step = *(int*)arg;
492 if(!step)
493 step = 1;
494 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
495 angle += step;
496 if (angle < 1) //cycle
497 angle = angles;
498 break;
500 default:
501 return M_PROPERTY_NOT_IMPLEMENTED;
503 angle = demuxer_set_angle(mpctx->demuxer, angle);
504 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
505 MSGTR_OSDAngle, angle, angles);
506 if (angle_name)
507 free(angle_name);
508 return M_PROPERTY_OK;
511 /// Demuxer meta data
512 static int mp_property_metadata(m_option_t * prop, int action, void *arg,
513 MPContext * mpctx) {
514 m_property_action_t* ka;
515 char* meta;
516 static m_option_t key_type =
517 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
518 if (!mpctx->demuxer)
519 return M_PROPERTY_UNAVAILABLE;
521 switch(action) {
522 case M_PROPERTY_GET:
523 if(!arg) return M_PROPERTY_ERROR;
524 *(char***)arg = mpctx->demuxer->info;
525 return M_PROPERTY_OK;
526 case M_PROPERTY_KEY_ACTION:
527 if(!arg) return M_PROPERTY_ERROR;
528 ka = arg;
529 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
530 return M_PROPERTY_UNKNOWN;
531 switch(ka->action) {
532 case M_PROPERTY_GET:
533 if(!ka->arg) return M_PROPERTY_ERROR;
534 *(char**)ka->arg = meta;
535 return M_PROPERTY_OK;
536 case M_PROPERTY_GET_TYPE:
537 if(!ka->arg) return M_PROPERTY_ERROR;
538 *(m_option_t**)ka->arg = &key_type;
539 return M_PROPERTY_OK;
542 return M_PROPERTY_NOT_IMPLEMENTED;
546 ///@}
548 /// \defgroup AudioProperties Audio properties
549 /// \ingroup Properties
550 ///@{
552 /// Volume (RW)
553 static int mp_property_volume(m_option_t * prop, int action, void *arg,
554 MPContext * mpctx)
557 if (!mpctx->sh_audio)
558 return M_PROPERTY_UNAVAILABLE;
560 switch (action) {
561 case M_PROPERTY_GET:
562 if (!arg)
563 return M_PROPERTY_ERROR;
564 mixer_getbothvolume(&mpctx->mixer, arg);
565 return M_PROPERTY_OK;
566 case M_PROPERTY_PRINT:{
567 float vol;
568 if (!arg)
569 return M_PROPERTY_ERROR;
570 mixer_getbothvolume(&mpctx->mixer, &vol);
571 return m_property_float_range(prop, action, arg, &vol);
573 case M_PROPERTY_STEP_UP:
574 case M_PROPERTY_STEP_DOWN:
575 case M_PROPERTY_SET:
576 break;
577 default:
578 return M_PROPERTY_NOT_IMPLEMENTED;
581 if (mpctx->edl_muted)
582 return M_PROPERTY_DISABLED;
583 mpctx->user_muted = 0;
585 switch (action) {
586 case M_PROPERTY_SET:
587 if (!arg)
588 return M_PROPERTY_ERROR;
589 M_PROPERTY_CLAMP(prop, *(float *) arg);
590 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
591 return M_PROPERTY_OK;
592 case M_PROPERTY_STEP_UP:
593 if (arg && *(float *) arg <= 0)
594 mixer_decvolume(&mpctx->mixer);
595 else
596 mixer_incvolume(&mpctx->mixer);
597 return M_PROPERTY_OK;
598 case M_PROPERTY_STEP_DOWN:
599 if (arg && *(float *) arg <= 0)
600 mixer_incvolume(&mpctx->mixer);
601 else
602 mixer_decvolume(&mpctx->mixer);
603 return M_PROPERTY_OK;
605 return M_PROPERTY_NOT_IMPLEMENTED;
608 /// Mute (RW)
609 static int mp_property_mute(m_option_t * prop, int action, void *arg,
610 MPContext * mpctx)
613 if (!mpctx->sh_audio)
614 return M_PROPERTY_UNAVAILABLE;
616 switch (action) {
617 case M_PROPERTY_SET:
618 if (mpctx->edl_muted)
619 return M_PROPERTY_DISABLED;
620 if (!arg)
621 return M_PROPERTY_ERROR;
622 if ((!!*(int *) arg) != mpctx->mixer.muted)
623 mixer_mute(&mpctx->mixer);
624 mpctx->user_muted = mpctx->mixer.muted;
625 return M_PROPERTY_OK;
626 case M_PROPERTY_STEP_UP:
627 case M_PROPERTY_STEP_DOWN:
628 if (mpctx->edl_muted)
629 return M_PROPERTY_DISABLED;
630 mixer_mute(&mpctx->mixer);
631 mpctx->user_muted = mpctx->mixer.muted;
632 return M_PROPERTY_OK;
633 case M_PROPERTY_PRINT:
634 if (!arg)
635 return M_PROPERTY_ERROR;
636 if (mpctx->edl_muted) {
637 *(char **) arg = strdup(MSGTR_EnabledEdl);
638 return M_PROPERTY_OK;
640 default:
641 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
646 /// Audio delay (RW)
647 static int mp_property_audio_delay(m_option_t * prop, int action,
648 void *arg, MPContext * mpctx)
650 if (!(mpctx->sh_audio && mpctx->sh_video))
651 return M_PROPERTY_UNAVAILABLE;
652 switch (action) {
653 case M_PROPERTY_SET:
654 case M_PROPERTY_STEP_UP:
655 case M_PROPERTY_STEP_DOWN: {
656 int ret;
657 float delay = audio_delay;
658 ret = m_property_delay(prop, action, arg, &audio_delay);
659 if (ret != M_PROPERTY_OK)
660 return ret;
661 if (mpctx->sh_audio)
662 mpctx->delay -= audio_delay - delay;
664 return M_PROPERTY_OK;
665 default:
666 return m_property_delay(prop, action, arg, &audio_delay);
670 /// Audio codec tag (RO)
671 static int mp_property_audio_format(m_option_t * prop, int action,
672 void *arg, MPContext * mpctx)
674 if (!mpctx->sh_audio)
675 return M_PROPERTY_UNAVAILABLE;
676 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
679 /// Audio codec name (RO)
680 static int mp_property_audio_codec(m_option_t * prop, int action,
681 void *arg, MPContext * mpctx)
683 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
684 return M_PROPERTY_UNAVAILABLE;
685 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
688 /// Audio bitrate (RO)
689 static int mp_property_audio_bitrate(m_option_t * prop, int action,
690 void *arg, MPContext * mpctx)
692 if (!mpctx->sh_audio)
693 return M_PROPERTY_UNAVAILABLE;
694 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
697 /// Samplerate (RO)
698 static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
699 MPContext * mpctx)
701 if (!mpctx->sh_audio)
702 return M_PROPERTY_UNAVAILABLE;
703 switch(action) {
704 case M_PROPERTY_PRINT:
705 if(!arg) return M_PROPERTY_ERROR;
706 *(char**)arg = malloc(16);
707 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
708 return M_PROPERTY_OK;
710 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
713 /// Number of channels (RO)
714 static int mp_property_channels(m_option_t * prop, int action, void *arg,
715 MPContext * mpctx)
717 if (!mpctx->sh_audio)
718 return M_PROPERTY_UNAVAILABLE;
719 switch (action) {
720 case M_PROPERTY_PRINT:
721 if (!arg)
722 return M_PROPERTY_ERROR;
723 switch (mpctx->sh_audio->channels) {
724 case 1:
725 *(char **) arg = strdup("mono");
726 break;
727 case 2:
728 *(char **) arg = strdup("stereo");
729 break;
730 default:
731 *(char **) arg = malloc(32);
732 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
734 return M_PROPERTY_OK;
736 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
739 /// Balance (RW)
740 static int mp_property_balance(m_option_t * prop, int action, void *arg,
741 MPContext * mpctx)
743 float bal;
745 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
746 return M_PROPERTY_UNAVAILABLE;
748 switch (action) {
749 case M_PROPERTY_GET:
750 if (!arg)
751 return M_PROPERTY_ERROR;
752 mixer_getbalance(&mpctx->mixer, arg);
753 return M_PROPERTY_OK;
754 case M_PROPERTY_PRINT: {
755 char** str = arg;
756 if (!arg)
757 return M_PROPERTY_ERROR;
758 mixer_getbalance(&mpctx->mixer, &bal);
759 if (bal == 0.f)
760 *str = strdup("center");
761 else if (bal == -1.f)
762 *str = strdup("left only");
763 else if (bal == 1.f)
764 *str = strdup("right only");
765 else {
766 unsigned right = (bal + 1.f) / 2.f * 100.f;
767 *str = malloc(sizeof("left xxx%, right xxx%"));
768 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
770 return M_PROPERTY_OK;
772 case M_PROPERTY_STEP_UP:
773 case M_PROPERTY_STEP_DOWN:
774 mixer_getbalance(&mpctx->mixer, &bal);
775 bal += (arg ? *(float*)arg : .1f) *
776 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
777 M_PROPERTY_CLAMP(prop, bal);
778 mixer_setbalance(&mpctx->mixer, bal);
779 return M_PROPERTY_OK;
780 case M_PROPERTY_SET:
781 if (!arg)
782 return M_PROPERTY_ERROR;
783 M_PROPERTY_CLAMP(prop, *(float*)arg);
784 mixer_setbalance(&mpctx->mixer, *(float*)arg);
785 return M_PROPERTY_OK;
787 return M_PROPERTY_NOT_IMPLEMENTED;
790 /// Selected audio id (RW)
791 static int mp_property_audio(m_option_t * prop, int action, void *arg,
792 MPContext * mpctx)
794 int current_id = -1, tmp;
796 switch (action) {
797 case M_PROPERTY_GET:
798 if (!mpctx->sh_audio)
799 return M_PROPERTY_UNAVAILABLE;
800 if (!arg)
801 return M_PROPERTY_ERROR;
802 *(int *) arg = audio_id;
803 return M_PROPERTY_OK;
804 case M_PROPERTY_PRINT:
805 if (!mpctx->sh_audio)
806 return M_PROPERTY_UNAVAILABLE;
807 if (!arg)
808 return M_PROPERTY_ERROR;
810 if (audio_id < 0)
811 *(char **) arg = strdup(MSGTR_Disabled);
812 else {
813 char lang[40] = MSGTR_Unknown;
814 sh_audio_t* sh = mpctx->sh_audio;
815 if (sh && sh->lang)
816 av_strlcpy(lang, sh->lang, 40);
817 #ifdef USE_DVDREAD
818 else if (mpctx->stream->type == STREAMTYPE_DVD) {
819 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
820 if (code) {
821 lang[0] = code >> 8;
822 lang[1] = code;
823 lang[2] = 0;
826 #endif
828 #ifdef USE_DVDNAV
829 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
830 dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
831 #endif
832 *(char **) arg = malloc(64);
833 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
835 return M_PROPERTY_OK;
837 case M_PROPERTY_STEP_UP:
838 case M_PROPERTY_SET:
839 if (action == M_PROPERTY_SET && arg)
840 tmp = *((int *) arg);
841 else
842 tmp = -1;
843 current_id = mpctx->demuxer->audio->id;
844 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
845 if (audio_id == -2
846 || (audio_id > -1
847 && mpctx->demuxer->audio->id != current_id && current_id != -2))
848 uninit_player(INITIALIZED_AO | INITIALIZED_ACODEC);
849 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
850 sh_audio_t *sh2;
851 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
852 if (sh2) {
853 sh2->ds = mpctx->demuxer->audio;
854 mpctx->sh_audio = sh2;
855 reinit_audio_chain();
858 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
859 return M_PROPERTY_OK;
860 default:
861 return M_PROPERTY_NOT_IMPLEMENTED;
866 /// Selected video id (RW)
867 static int mp_property_video(m_option_t * prop, int action, void *arg,
868 MPContext * mpctx)
870 int current_id = -1, tmp;
872 switch (action) {
873 case M_PROPERTY_GET:
874 if (!mpctx->sh_video)
875 return M_PROPERTY_UNAVAILABLE;
876 if (!arg)
877 return M_PROPERTY_ERROR;
878 *(int *) arg = video_id;
879 return M_PROPERTY_OK;
880 case M_PROPERTY_PRINT:
881 if (!mpctx->sh_video)
882 return M_PROPERTY_UNAVAILABLE;
883 if (!arg)
884 return M_PROPERTY_ERROR;
886 if (video_id < 0)
887 *(char **) arg = strdup(MSGTR_Disabled);
888 else {
889 char lang[40] = MSGTR_Unknown;
890 *(char **) arg = malloc(64);
891 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
893 return M_PROPERTY_OK;
895 case M_PROPERTY_STEP_UP:
896 case M_PROPERTY_SET:
897 current_id = mpctx->demuxer->video->id;
898 if (action == M_PROPERTY_SET && arg)
899 tmp = *((int *) arg);
900 else
901 tmp = -1;
902 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
903 if (video_id == -2
904 || (video_id > -1 && mpctx->demuxer->video->id != current_id
905 && current_id != -2))
906 uninit_player(INITIALIZED_VCODEC |
907 (fixed_vo && video_id != -2 ? 0 : INITIALIZED_VO));
908 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
909 sh_video_t *sh2;
910 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
911 if (sh2) {
912 sh2->ds = mpctx->demuxer->video;
913 mpctx->sh_video = sh2;
914 reinit_video_chain();
917 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
918 return M_PROPERTY_OK;
920 default:
921 return M_PROPERTY_NOT_IMPLEMENTED;
925 static int mp_property_program(m_option_t * prop, int action, void *arg,
926 MPContext * mpctx)
928 demux_program_t prog;
930 switch (action) {
931 case M_PROPERTY_STEP_UP:
932 case M_PROPERTY_SET:
933 if (action == M_PROPERTY_SET && arg)
934 prog.progid = *((int *) arg);
935 else
936 prog.progid = -1;
937 if (demux_control
938 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
939 &prog) == DEMUXER_CTRL_NOTIMPL)
940 return M_PROPERTY_ERROR;
942 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
943 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
944 return M_PROPERTY_OK;
946 default:
947 return M_PROPERTY_NOT_IMPLEMENTED;
951 ///@}
953 /// \defgroup VideoProperties Video properties
954 /// \ingroup Properties
955 ///@{
957 /// Fullscreen state (RW)
958 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
959 MPContext * mpctx)
962 if (!mpctx->video_out)
963 return M_PROPERTY_UNAVAILABLE;
965 switch (action) {
966 case M_PROPERTY_SET:
967 if (!arg)
968 return M_PROPERTY_ERROR;
969 M_PROPERTY_CLAMP(prop, *(int *) arg);
970 if (vo_fs == !!*(int *) arg)
971 return M_PROPERTY_OK;
972 case M_PROPERTY_STEP_UP:
973 case M_PROPERTY_STEP_DOWN:
974 #ifdef HAVE_NEW_GUI
975 if (use_gui)
976 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
977 else
978 #endif
979 if (vo_config_count)
980 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
981 return M_PROPERTY_OK;
982 default:
983 return m_property_flag(prop, action, arg, &vo_fs);
987 static int mp_property_deinterlace(m_option_t * prop, int action,
988 void *arg, MPContext * mpctx)
990 int deinterlace;
991 vf_instance_t *vf;
992 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
993 return M_PROPERTY_UNAVAILABLE;
994 vf = mpctx->sh_video->vfilter;
995 switch (action) {
996 case M_PROPERTY_GET:
997 if (!arg)
998 return M_PROPERTY_ERROR;
999 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1000 return M_PROPERTY_OK;
1001 case M_PROPERTY_SET:
1002 if (!arg)
1003 return M_PROPERTY_ERROR;
1004 M_PROPERTY_CLAMP(prop, *(int *) arg);
1005 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1006 return M_PROPERTY_OK;
1007 case M_PROPERTY_STEP_UP:
1008 case M_PROPERTY_STEP_DOWN:
1009 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1010 deinterlace = !deinterlace;
1011 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1012 return M_PROPERTY_OK;
1014 return M_PROPERTY_NOT_IMPLEMENTED;
1017 /// Panscan (RW)
1018 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
1019 MPContext * mpctx)
1022 if (!mpctx->video_out
1023 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1024 return M_PROPERTY_UNAVAILABLE;
1026 switch (action) {
1027 case M_PROPERTY_SET:
1028 if (!arg)
1029 return M_PROPERTY_ERROR;
1030 M_PROPERTY_CLAMP(prop, *(float *) arg);
1031 vo_panscan = *(float *) arg;
1032 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1033 return M_PROPERTY_OK;
1034 case M_PROPERTY_STEP_UP:
1035 case M_PROPERTY_STEP_DOWN:
1036 vo_panscan += (arg ? *(float *) arg : 0.1) *
1037 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1038 if (vo_panscan > 1)
1039 vo_panscan = 1;
1040 else if (vo_panscan < 0)
1041 vo_panscan = 0;
1042 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1043 return M_PROPERTY_OK;
1044 default:
1045 return m_property_float_range(prop, action, arg, &vo_panscan);
1049 /// Helper to set vo flags.
1050 /** \ingroup PropertyImplHelper
1052 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
1053 int vo_ctrl, int *vo_var, MPContext * mpctx)
1056 if (!mpctx->video_out)
1057 return M_PROPERTY_UNAVAILABLE;
1059 switch (action) {
1060 case M_PROPERTY_SET:
1061 if (!arg)
1062 return M_PROPERTY_ERROR;
1063 M_PROPERTY_CLAMP(prop, *(int *) arg);
1064 if (*vo_var == !!*(int *) arg)
1065 return M_PROPERTY_OK;
1066 case M_PROPERTY_STEP_UP:
1067 case M_PROPERTY_STEP_DOWN:
1068 if (vo_config_count)
1069 mpctx->video_out->control(vo_ctrl, 0);
1070 return M_PROPERTY_OK;
1071 default:
1072 return m_property_flag(prop, action, arg, vo_var);
1076 /// Window always on top (RW)
1077 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
1078 MPContext * mpctx)
1080 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
1081 mpctx);
1084 /// Display in the root window (RW)
1085 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
1086 MPContext * mpctx)
1088 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1089 &vo_rootwin, mpctx);
1092 /// Show window borders (RW)
1093 static int mp_property_border(m_option_t * prop, int action, void *arg,
1094 MPContext * mpctx)
1096 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1097 &vo_border, mpctx);
1100 /// Framedropping state (RW)
1101 static int mp_property_framedropping(m_option_t * prop, int action,
1102 void *arg, MPContext * mpctx)
1105 if (!mpctx->sh_video)
1106 return M_PROPERTY_UNAVAILABLE;
1108 switch (action) {
1109 case M_PROPERTY_PRINT:
1110 if (!arg)
1111 return M_PROPERTY_ERROR;
1112 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1113 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1114 MSGTR_Disabled));
1115 return M_PROPERTY_OK;
1116 default:
1117 return m_property_choice(prop, action, arg, &frame_dropping);
1121 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1122 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
1123 MPContext * mpctx)
1125 int *gamma = prop->priv, r, val;
1127 if (!mpctx->sh_video)
1128 return M_PROPERTY_UNAVAILABLE;
1130 if (gamma[0] == 1000) {
1131 gamma[0] = 0;
1132 get_video_colors(mpctx->sh_video, prop->name, gamma);
1135 switch (action) {
1136 case M_PROPERTY_SET:
1137 if (!arg)
1138 return M_PROPERTY_ERROR;
1139 M_PROPERTY_CLAMP(prop, *(int *) arg);
1140 *gamma = *(int *) arg;
1141 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1142 if (r <= 0)
1143 break;
1144 return r;
1145 case M_PROPERTY_GET:
1146 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1147 if (!arg)
1148 return M_PROPERTY_ERROR;
1149 *(int *)arg = val;
1150 return M_PROPERTY_OK;
1152 break;
1153 case M_PROPERTY_STEP_UP:
1154 case M_PROPERTY_STEP_DOWN:
1155 *gamma += (arg ? *(int *) arg : 1) *
1156 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1157 M_PROPERTY_CLAMP(prop, *gamma);
1158 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1159 if (r <= 0)
1160 break;
1161 return r;
1162 default:
1163 return M_PROPERTY_NOT_IMPLEMENTED;
1166 #ifdef USE_TV
1167 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1168 int l = strlen(prop->name);
1169 char tv_prop[3 + l + 1];
1170 sprintf(tv_prop, "tv_%s", prop->name);
1171 return mp_property_do(tv_prop, action, arg, mpctx);
1173 #endif
1175 return M_PROPERTY_UNAVAILABLE;
1178 /// VSync (RW)
1179 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1180 MPContext * mpctx)
1182 return m_property_flag(prop, action, arg, &vo_vsync);
1185 /// Video codec tag (RO)
1186 static int mp_property_video_format(m_option_t * prop, int action,
1187 void *arg, MPContext * mpctx)
1189 char* meta;
1190 if (!mpctx->sh_video)
1191 return M_PROPERTY_UNAVAILABLE;
1192 switch(action) {
1193 case M_PROPERTY_PRINT:
1194 if (!arg)
1195 return M_PROPERTY_ERROR;
1196 switch(mpctx->sh_video->format) {
1197 case 0x10000001:
1198 meta = strdup ("mpeg1"); break;
1199 case 0x10000002:
1200 meta = strdup ("mpeg2"); break;
1201 case 0x10000004:
1202 meta = strdup ("mpeg4"); break;
1203 case 0x10000005:
1204 meta = strdup ("h264"); break;
1205 default:
1206 if(mpctx->sh_video->format >= 0x20202020) {
1207 meta = malloc(5);
1208 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1209 } else {
1210 meta = malloc(20);
1211 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1214 *(char**)arg = meta;
1215 return M_PROPERTY_OK;
1217 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1220 /// Video codec name (RO)
1221 static int mp_property_video_codec(m_option_t * prop, int action,
1222 void *arg, MPContext * mpctx)
1224 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1225 return M_PROPERTY_UNAVAILABLE;
1226 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1230 /// Video bitrate (RO)
1231 static int mp_property_video_bitrate(m_option_t * prop, int action,
1232 void *arg, MPContext * mpctx)
1234 if (!mpctx->sh_video)
1235 return M_PROPERTY_UNAVAILABLE;
1236 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1239 /// Video display width (RO)
1240 static int mp_property_width(m_option_t * prop, int action, void *arg,
1241 MPContext * mpctx)
1243 if (!mpctx->sh_video)
1244 return M_PROPERTY_UNAVAILABLE;
1245 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1248 /// Video display height (RO)
1249 static int mp_property_height(m_option_t * prop, int action, void *arg,
1250 MPContext * mpctx)
1252 if (!mpctx->sh_video)
1253 return M_PROPERTY_UNAVAILABLE;
1254 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1257 /// Video fps (RO)
1258 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1259 MPContext * mpctx)
1261 if (!mpctx->sh_video)
1262 return M_PROPERTY_UNAVAILABLE;
1263 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1266 /// Video aspect (RO)
1267 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1268 MPContext * mpctx)
1270 if (!mpctx->sh_video)
1271 return M_PROPERTY_UNAVAILABLE;
1272 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1275 ///@}
1277 /// \defgroup SubProprties Subtitles properties
1278 /// \ingroup Properties
1279 ///@{
1281 /// Text subtitle position (RW)
1282 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1283 MPContext * mpctx)
1285 if (!mpctx->sh_video)
1286 return M_PROPERTY_UNAVAILABLE;
1288 switch (action) {
1289 case M_PROPERTY_SET:
1290 if (!arg)
1291 return M_PROPERTY_ERROR;
1292 case M_PROPERTY_STEP_UP:
1293 case M_PROPERTY_STEP_DOWN:
1294 vo_osd_changed(OSDTYPE_SUBTITLE);
1295 default:
1296 return m_property_int_range(prop, action, arg, &sub_pos);
1300 /// Selected subtitles (RW)
1301 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1302 MPContext * mpctx)
1304 demux_stream_t *const d_sub = mpctx->d_sub;
1305 const int global_sub_size = mpctx->global_sub_size;
1306 int source = -1, reset_spu = 0;
1307 char *sub_name;
1309 if (global_sub_size <= 0)
1310 return M_PROPERTY_UNAVAILABLE;
1312 switch (action) {
1313 case M_PROPERTY_GET:
1314 if (!arg)
1315 return M_PROPERTY_ERROR;
1316 *(int *) arg = mpctx->global_sub_pos;
1317 return M_PROPERTY_OK;
1318 case M_PROPERTY_PRINT:
1319 if (!arg)
1320 return M_PROPERTY_ERROR;
1321 *(char **) arg = malloc(64);
1322 (*(char **) arg)[63] = 0;
1323 sub_name = 0;
1324 if (subdata)
1325 sub_name = subdata->filename;
1326 #ifdef USE_ASS
1327 if (ass_track && ass_track->name)
1328 sub_name = ass_track->name;
1329 #endif
1330 if (sub_name) {
1331 char *tmp, *tmp2;
1332 tmp = sub_name;
1333 if ((tmp2 = strrchr(tmp, '/')))
1334 tmp = tmp2 + 1;
1336 snprintf(*(char **) arg, 63, "(%d) %s%s",
1337 mpctx->set_of_sub_pos + 1,
1338 strlen(tmp) < 20 ? "" : "...",
1339 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1340 return M_PROPERTY_OK;
1342 #ifdef USE_DVDNAV
1343 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1344 if (vo_spudec && dvdsub_id >= 0) {
1345 unsigned char lang[3];
1346 if (dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1347 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1348 return M_PROPERTY_OK;
1352 #endif
1354 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1355 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1356 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1357 && d_sub && d_sub->sh && dvdsub_id >= 0) {
1358 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1359 if (!lang) lang = MSGTR_Unknown;
1360 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1361 return M_PROPERTY_OK;
1364 if (vo_vobsub && vobsub_id >= 0) {
1365 const char *language = MSGTR_Unknown;
1366 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1367 snprintf(*(char **) arg, 63, "(%d) %s",
1368 vobsub_id, language ? language : MSGTR_Unknown);
1369 return M_PROPERTY_OK;
1371 #ifdef USE_DVDREAD
1372 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1373 && dvdsub_id >= 0) {
1374 char lang[3];
1375 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1376 lang[0] = code >> 8;
1377 lang[1] = code;
1378 lang[2] = 0;
1379 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1380 return M_PROPERTY_OK;
1382 #endif
1383 if (dvdsub_id >= 0) {
1384 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1385 return M_PROPERTY_OK;
1387 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1388 return M_PROPERTY_OK;
1390 case M_PROPERTY_SET:
1391 if (!arg)
1392 return M_PROPERTY_ERROR;
1393 if (*(int *) arg < -1)
1394 *(int *) arg = -1;
1395 else if (*(int *) arg >= global_sub_size)
1396 *(int *) arg = global_sub_size - 1;
1397 mpctx->global_sub_pos = *(int *) arg;
1398 break;
1399 case M_PROPERTY_STEP_UP:
1400 mpctx->global_sub_pos += 2;
1401 mpctx->global_sub_pos =
1402 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1403 break;
1404 case M_PROPERTY_STEP_DOWN:
1405 mpctx->global_sub_pos += global_sub_size + 1;
1406 mpctx->global_sub_pos =
1407 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1408 break;
1409 default:
1410 return M_PROPERTY_NOT_IMPLEMENTED;
1413 if (mpctx->global_sub_pos >= 0)
1414 source = sub_source(mpctx);
1416 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1417 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1418 global_sub_size,
1419 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1420 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1421 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1422 mpctx->global_sub_pos, source);
1424 mpctx->set_of_sub_pos = -1;
1425 subdata = NULL;
1427 vobsub_id = -1;
1428 dvdsub_id = -1;
1429 if (d_sub) {
1430 if (d_sub->id > -2)
1431 reset_spu = 1;
1432 d_sub->id = -2;
1434 #ifdef USE_ASS
1435 ass_track = 0;
1436 #endif
1438 if (source == SUB_SOURCE_VOBSUB) {
1439 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1440 } else if (source == SUB_SOURCE_SUBS) {
1441 mpctx->set_of_sub_pos =
1442 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1443 #ifdef USE_ASS
1444 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1445 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1446 else
1447 #endif
1449 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1450 vo_osd_changed(OSDTYPE_SUBTITLE);
1452 } else if (source == SUB_SOURCE_DEMUX) {
1453 dvdsub_id =
1454 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1455 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1456 int i = 0;
1457 // default: assume 1:1 mapping of sid and stream id
1458 d_sub->id = dvdsub_id;
1459 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1460 ds_free_packs(d_sub);
1461 for (i = 0; i < MAX_S_STREAMS; i++) {
1462 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1463 if (sh && sh->sid == dvdsub_id) {
1464 d_sub->id = i;
1465 d_sub->sh = sh;
1466 break;
1469 if (d_sub->sh && d_sub->id >= 0) {
1470 sh_sub_t *sh = d_sub->sh;
1471 if (sh->type == 'v')
1472 init_vo_spudec();
1473 #ifdef USE_ASS
1474 else if (ass_enabled)
1475 ass_track = sh->ass_track;
1476 #endif
1477 } else {
1478 d_sub->id = -2;
1479 d_sub->sh = NULL;
1483 #ifdef USE_DVDREAD
1484 if (vo_spudec
1485 && (mpctx->stream->type == STREAMTYPE_DVD
1486 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1487 && dvdsub_id < 0 && reset_spu) {
1488 dvdsub_id = -2;
1489 d_sub->id = dvdsub_id;
1491 #endif
1492 update_subtitles(mpctx->sh_video, d_sub, 1);
1494 return M_PROPERTY_OK;
1497 /// Selected sub source (RW)
1498 static int mp_property_sub_source(m_option_t * prop, int action, void *arg,
1499 MPContext * mpctx)
1501 int source;
1502 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1503 return M_PROPERTY_UNAVAILABLE;
1505 switch (action) {
1506 case M_PROPERTY_GET:
1507 if (!arg)
1508 return M_PROPERTY_ERROR;
1509 *(int *) arg = sub_source(mpctx);
1510 return M_PROPERTY_OK;
1511 case M_PROPERTY_PRINT:
1512 if (!arg)
1513 return M_PROPERTY_ERROR;
1514 *(char **) arg = malloc(64);
1515 (*(char **) arg)[63] = 0;
1516 switch (sub_source(mpctx))
1518 case SUB_SOURCE_SUBS:
1519 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1520 break;
1521 case SUB_SOURCE_VOBSUB:
1522 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1523 break;
1524 case SUB_SOURCE_DEMUX:
1525 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1526 break;
1527 default:
1528 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1530 return M_PROPERTY_OK;
1531 case M_PROPERTY_SET:
1532 if (!arg)
1533 return M_PROPERTY_ERROR;
1534 M_PROPERTY_CLAMP(prop, *(int*)arg);
1535 if (*(int *) arg < 0)
1536 mpctx->global_sub_pos = -1;
1537 else if (*(int *) arg != sub_source(mpctx)) {
1538 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1539 return M_PROPERTY_UNAVAILABLE;
1540 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1542 break;
1543 case M_PROPERTY_STEP_UP:
1544 case M_PROPERTY_STEP_DOWN: {
1545 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1546 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1547 int step = (step_all > 0) ? 1 : -1;
1548 int cur_source = sub_source(mpctx);
1549 source = cur_source;
1550 while (step_all) {
1551 source += step;
1552 if (source >= SUB_SOURCES)
1553 source = -1;
1554 else if (source < -1)
1555 source = SUB_SOURCES - 1;
1556 if (source == cur_source || source == -1 ||
1557 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1558 step_all -= step;
1560 if (source == cur_source)
1561 return M_PROPERTY_OK;
1562 if (source == -1)
1563 mpctx->global_sub_pos = -1;
1564 else
1565 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1566 break;
1568 default:
1569 return M_PROPERTY_NOT_IMPLEMENTED;
1571 --mpctx->global_sub_pos;
1572 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1575 /// Selected subtitles from specific source (RW)
1576 static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg,
1577 MPContext * mpctx)
1579 int source, is_cur_source, offset;
1580 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1581 return M_PROPERTY_UNAVAILABLE;
1583 if (!strcmp(prop->name, "sub_file"))
1584 source = SUB_SOURCE_SUBS;
1585 else if (!strcmp(prop->name, "sub_vob"))
1586 source = SUB_SOURCE_VOBSUB;
1587 else if (!strcmp(prop->name, "sub_demux"))
1588 source = SUB_SOURCE_DEMUX;
1589 else
1590 return M_PROPERTY_ERROR;
1592 offset = mpctx->global_sub_indices[source];
1593 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1594 return M_PROPERTY_UNAVAILABLE;
1596 is_cur_source = sub_source(mpctx) == source;
1597 switch (action) {
1598 case M_PROPERTY_GET:
1599 if (!arg)
1600 return M_PROPERTY_ERROR;
1601 if (is_cur_source) {
1602 *(int *) arg = mpctx->global_sub_pos - offset;
1603 if (source == SUB_SOURCE_VOBSUB)
1604 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1606 else
1607 *(int *) arg = -1;
1608 return M_PROPERTY_OK;
1609 case M_PROPERTY_PRINT:
1610 if (!arg)
1611 return M_PROPERTY_ERROR;
1612 if (is_cur_source)
1613 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1614 *(char **) arg = malloc(64);
1615 (*(char **) arg)[63] = 0;
1616 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1617 return M_PROPERTY_OK;
1618 case M_PROPERTY_SET:
1619 if (!arg)
1620 return M_PROPERTY_ERROR;
1621 if (*(int *) arg >= 0) {
1622 int index = *(int *)arg;
1623 if (source == SUB_SOURCE_VOBSUB)
1624 index = vobsub_get_index_by_id(vo_vobsub, index);
1625 mpctx->global_sub_pos = offset + index;
1626 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1627 || sub_source(mpctx) != source) {
1628 mpctx->global_sub_pos = -1;
1629 *(int *) arg = -1;
1632 else
1633 mpctx->global_sub_pos = -1;
1634 break;
1635 case M_PROPERTY_STEP_UP:
1636 case M_PROPERTY_STEP_DOWN: {
1637 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1638 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1639 int step = (step_all > 0) ? 1 : -1;
1640 int max_sub_pos_for_source = -1;
1641 if (!is_cur_source)
1642 mpctx->global_sub_pos = -1;
1643 while (step_all) {
1644 if (mpctx->global_sub_pos == -1) {
1645 if (step > 0)
1646 mpctx->global_sub_pos = offset;
1647 else if (max_sub_pos_for_source == -1) {
1648 // Find max pos for specific source
1649 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1650 while (mpctx->global_sub_pos >= 0
1651 && sub_source(mpctx) != source)
1652 --mpctx->global_sub_pos;
1654 else
1655 mpctx->global_sub_pos = max_sub_pos_for_source;
1657 else {
1658 mpctx->global_sub_pos += step;
1659 if (mpctx->global_sub_pos < offset ||
1660 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1661 sub_source(mpctx) != source)
1662 mpctx->global_sub_pos = -1;
1664 step_all -= step;
1666 break;
1668 default:
1669 return M_PROPERTY_NOT_IMPLEMENTED;
1671 --mpctx->global_sub_pos;
1672 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1675 /// Subtitle delay (RW)
1676 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1677 MPContext * mpctx)
1679 if (!mpctx->sh_video)
1680 return M_PROPERTY_UNAVAILABLE;
1681 return m_property_delay(prop, action, arg, &sub_delay);
1684 /// Alignment of text subtitles (RW)
1685 static int mp_property_sub_alignment(m_option_t * prop, int action,
1686 void *arg, MPContext * mpctx)
1688 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1690 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1691 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1692 return M_PROPERTY_UNAVAILABLE;
1694 switch (action) {
1695 case M_PROPERTY_PRINT:
1696 if (!arg)
1697 return M_PROPERTY_ERROR;
1698 M_PROPERTY_CLAMP(prop, sub_alignment);
1699 *(char **) arg = strdup(name[sub_alignment]);
1700 return M_PROPERTY_OK;
1701 case M_PROPERTY_SET:
1702 if (!arg)
1703 return M_PROPERTY_ERROR;
1704 case M_PROPERTY_STEP_UP:
1705 case M_PROPERTY_STEP_DOWN:
1706 vo_osd_changed(OSDTYPE_SUBTITLE);
1707 default:
1708 return m_property_choice(prop, action, arg, &sub_alignment);
1712 /// Subtitle visibility (RW)
1713 static int mp_property_sub_visibility(m_option_t * prop, int action,
1714 void *arg, MPContext * mpctx)
1716 if (!mpctx->sh_video)
1717 return M_PROPERTY_UNAVAILABLE;
1719 switch (action) {
1720 case M_PROPERTY_SET:
1721 if (!arg)
1722 return M_PROPERTY_ERROR;
1723 case M_PROPERTY_STEP_UP:
1724 case M_PROPERTY_STEP_DOWN:
1725 vo_osd_changed(OSDTYPE_SUBTITLE);
1726 if (vo_spudec)
1727 vo_osd_changed(OSDTYPE_SPU);
1728 default:
1729 return m_property_flag(prop, action, arg, &sub_visibility);
1733 #ifdef USE_ASS
1734 /// Use margins for libass subtitles (RW)
1735 static int mp_property_ass_use_margins(m_option_t * prop, int action,
1736 void *arg, MPContext * mpctx)
1738 if (!mpctx->sh_video)
1739 return M_PROPERTY_UNAVAILABLE;
1741 switch (action) {
1742 case M_PROPERTY_SET:
1743 if (!arg)
1744 return M_PROPERTY_ERROR;
1745 case M_PROPERTY_STEP_UP:
1746 case M_PROPERTY_STEP_DOWN:
1747 ass_force_reload = 1;
1748 default:
1749 return m_property_flag(prop, action, arg, &ass_use_margins);
1752 #endif
1754 /// Show only forced subtitles (RW)
1755 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1756 void *arg, MPContext * mpctx)
1758 if (!vo_spudec)
1759 return M_PROPERTY_UNAVAILABLE;
1761 switch (action) {
1762 case M_PROPERTY_SET:
1763 if (!arg)
1764 return M_PROPERTY_ERROR;
1765 case M_PROPERTY_STEP_UP:
1766 case M_PROPERTY_STEP_DOWN:
1767 m_property_flag(prop, action, arg, &forced_subs_only);
1768 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1769 return M_PROPERTY_OK;
1770 default:
1771 return m_property_flag(prop, action, arg, &forced_subs_only);
1776 #ifdef HAVE_FREETYPE
1777 /// Subtitle scale (RW)
1778 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1779 MPContext * mpctx)
1782 switch (action) {
1783 case M_PROPERTY_SET:
1784 if (!arg)
1785 return M_PROPERTY_ERROR;
1786 M_PROPERTY_CLAMP(prop, *(float *) arg);
1787 #ifdef USE_ASS
1788 if (ass_enabled) {
1789 ass_font_scale = *(float *) arg;
1790 ass_force_reload = 1;
1792 #endif
1793 text_font_scale_factor = *(float *) arg;
1794 force_load_font = 1;
1795 return M_PROPERTY_OK;
1796 case M_PROPERTY_STEP_UP:
1797 case M_PROPERTY_STEP_DOWN:
1798 #ifdef USE_ASS
1799 if (ass_enabled) {
1800 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1801 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1802 M_PROPERTY_CLAMP(prop, ass_font_scale);
1803 ass_force_reload = 1;
1805 #endif
1806 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1807 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1808 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1809 force_load_font = 1;
1810 return M_PROPERTY_OK;
1811 default:
1812 #ifdef USE_ASS
1813 if (ass_enabled)
1814 return m_property_float_ro(prop, action, arg, ass_font_scale);
1815 else
1816 #endif
1817 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1820 #endif
1822 ///@}
1824 /// \defgroup TVProperties TV properties
1825 /// \ingroup Properties
1826 ///@{
1828 #ifdef USE_TV
1830 /// TV color settings (RW)
1831 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1832 MPContext * mpctx)
1834 int r, val;
1835 tvi_handle_t *tvh = mpctx->demuxer->priv;
1836 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1837 return M_PROPERTY_UNAVAILABLE;
1839 switch (action) {
1840 case M_PROPERTY_SET:
1841 if (!arg)
1842 return M_PROPERTY_ERROR;
1843 M_PROPERTY_CLAMP(prop, *(int *) arg);
1844 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1845 case M_PROPERTY_GET:
1846 return tv_get_color_options(tvh, (int) prop->priv, arg);
1847 case M_PROPERTY_STEP_UP:
1848 case M_PROPERTY_STEP_DOWN:
1849 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1850 if (!r)
1851 return M_PROPERTY_ERROR;
1852 val += (arg ? *(int *) arg : 1) *
1853 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1854 M_PROPERTY_CLAMP(prop, val);
1855 return tv_set_color_options(tvh, (int) prop->priv, val);
1857 return M_PROPERTY_ERROR;
1859 return M_PROPERTY_NOT_IMPLEMENTED;
1862 #endif
1864 #ifdef HAVE_TV_TELETEXT
1865 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1866 MPContext * mpctx)
1868 int val,result;
1869 int base_ioctl=(int)prop->priv;
1871 for teletext's GET,SET,STEP ioctls this is not 0
1872 SET is GET+1
1873 STEP is GET+2
1875 tvi_handle_t *tvh = mpctx->demuxer->priv;
1876 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1877 return M_PROPERTY_UNAVAILABLE;
1878 if(!base_ioctl)
1879 return M_PROPERTY_ERROR;
1881 switch (action) {
1882 case M_PROPERTY_GET:
1883 if (!arg)
1884 return M_PROPERTY_ERROR;
1885 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1886 break;
1887 case M_PROPERTY_SET:
1888 if (!arg)
1889 return M_PROPERTY_ERROR;
1890 M_PROPERTY_CLAMP(prop, *(int *) arg);
1891 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1892 break;
1893 case M_PROPERTY_STEP_UP:
1894 case M_PROPERTY_STEP_DOWN:
1895 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1896 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1897 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1898 break;
1899 default:
1900 return M_PROPERTY_NOT_IMPLEMENTED;
1903 return (result==TVI_CONTROL_TRUE?M_PROPERTY_OK:M_PROPERTY_ERROR);
1906 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1907 MPContext * mpctx)
1909 tvi_handle_t *tvh = mpctx->demuxer->priv;
1910 int result;
1911 int val;
1913 //with tvh==NULL will fail too
1914 result=mp_property_teletext_common(prop,action,arg,mpctx);
1915 if(result!=M_PROPERTY_OK)
1916 return result;
1918 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1919 mp_input_set_section("teletext");
1920 else
1921 mp_input_set_section("tv");
1922 return M_PROPERTY_OK;
1925 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1926 MPContext * mpctx)
1928 tvi_handle_t *tvh = mpctx->demuxer->priv;
1929 int result;
1930 int val;
1931 switch(action){
1932 case M_PROPERTY_STEP_UP:
1933 case M_PROPERTY_STEP_DOWN:
1934 //This should be handled separately
1935 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1936 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1937 break;
1938 default:
1939 result=mp_property_teletext_common(prop,action,arg,mpctx);
1941 return result;
1945 #endif /* HAVE_TV_TELETEXT */
1947 ///@}
1949 /// All properties available in MPlayer.
1950 /** \ingroup Properties
1952 static const m_option_t mp_properties[] = {
1953 // General
1954 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1955 M_OPT_RANGE, 0, 3, NULL },
1956 { "loop", mp_property_loop, CONF_TYPE_INT,
1957 M_OPT_MIN, -1, 0, NULL },
1958 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1959 M_OPT_RANGE, 0.01, 100.0, NULL },
1960 { "filename", mp_property_filename, CONF_TYPE_STRING,
1961 0, 0, 0, NULL },
1962 { "path", mp_property_path, CONF_TYPE_STRING,
1963 0, 0, 0, NULL },
1964 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1965 0, 0, 0, NULL },
1966 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1967 M_OPT_MIN, 0, 0, NULL },
1968 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1969 M_OPT_MIN, 0, 0, NULL },
1970 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1971 M_OPT_MIN, 0, 0, NULL },
1972 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1973 M_OPT_MIN, 0, 0, NULL },
1974 { "length", mp_property_length, CONF_TYPE_TIME,
1975 M_OPT_MIN, 0, 0, NULL },
1976 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1977 M_OPT_RANGE, 0, 100, NULL },
1978 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1979 M_OPT_MIN, 0, 0, NULL },
1980 { "chapter", mp_property_chapter, CONF_TYPE_INT,
1981 M_OPT_MIN, 1, 0, NULL },
1982 { "angle", mp_property_angle, CONF_TYPE_INT,
1983 CONF_RANGE, -2, 10, NULL },
1984 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
1985 0, 0, 0, NULL },
1987 // Audio
1988 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
1989 M_OPT_RANGE, 0, 100, NULL },
1990 { "mute", mp_property_mute, CONF_TYPE_FLAG,
1991 M_OPT_RANGE, 0, 1, NULL },
1992 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
1993 M_OPT_RANGE, -100, 100, NULL },
1994 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
1995 0, 0, 0, NULL },
1996 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
1997 0, 0, 0, NULL },
1998 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
1999 0, 0, 0, NULL },
2000 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2001 0, 0, 0, NULL },
2002 { "channels", mp_property_channels, CONF_TYPE_INT,
2003 0, 0, 0, NULL },
2004 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2005 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
2006 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2007 M_OPT_RANGE, -1, 1, NULL },
2009 // Video
2010 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2011 M_OPT_RANGE, 0, 1, NULL },
2012 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2013 M_OPT_RANGE, 0, 1, NULL },
2014 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2015 M_OPT_RANGE, 0, 1, NULL },
2016 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2017 M_OPT_RANGE, 0, 1, NULL },
2018 { "border", mp_property_border, CONF_TYPE_FLAG,
2019 M_OPT_RANGE, 0, 1, NULL },
2020 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2021 M_OPT_RANGE, 0, 2, NULL },
2022 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2023 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2024 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2025 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2026 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2027 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2028 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2029 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2030 { "hue", mp_property_gamma, CONF_TYPE_INT,
2031 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2032 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2033 M_OPT_RANGE, 0, 1, NULL },
2034 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2035 M_OPT_RANGE, 0, 1, NULL },
2036 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2037 0, 0, 0, NULL },
2038 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2039 0, 0, 0, NULL },
2040 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2041 0, 0, 0, NULL },
2042 { "width", mp_property_width, CONF_TYPE_INT,
2043 0, 0, 0, NULL },
2044 { "height", mp_property_height, CONF_TYPE_INT,
2045 0, 0, 0, NULL },
2046 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2047 0, 0, 0, NULL },
2048 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2049 0, 0, 0, NULL },
2050 { "switch_video", mp_property_video, CONF_TYPE_INT,
2051 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
2052 { "switch_program", mp_property_program, CONF_TYPE_INT,
2053 CONF_RANGE, -1, 65535, NULL },
2055 // Subs
2056 { "sub", mp_property_sub, CONF_TYPE_INT,
2057 M_OPT_MIN, -1, 0, NULL },
2058 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2059 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2060 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2061 M_OPT_MIN, -1, 0, NULL },
2062 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2063 M_OPT_MIN, -1, 0, NULL },
2064 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2065 M_OPT_MIN, -1, 0, NULL },
2066 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2067 0, 0, 0, NULL },
2068 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2069 M_OPT_RANGE, 0, 100, NULL },
2070 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2071 M_OPT_RANGE, 0, 2, NULL },
2072 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2073 M_OPT_RANGE, 0, 1, NULL },
2074 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2075 M_OPT_RANGE, 0, 1, NULL },
2076 #ifdef HAVE_FREETYPE
2077 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2078 M_OPT_RANGE, 0, 100, NULL },
2079 #endif
2080 #ifdef USE_ASS
2081 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2082 M_OPT_RANGE, 0, 1, NULL },
2083 #endif
2085 #ifdef USE_TV
2086 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2087 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2088 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2089 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2090 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2091 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2092 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2093 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2094 #endif
2096 #ifdef HAVE_TV_TELETEXT
2097 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2098 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2099 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2100 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2101 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2102 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2103 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2104 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2105 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2106 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2107 #endif
2109 { NULL, NULL, NULL, 0, 0, 0, NULL }
2113 int mp_property_do(const char *name, int action, void *val, void *ctx)
2115 return m_property_do(mp_properties, name, action, val, ctx);
2118 char* mp_property_print(const char *name, void* ctx)
2120 char* ret = NULL;
2121 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2122 return NULL;
2123 return ret;
2126 char *property_expand_string(MPContext * mpctx, char *str)
2128 return m_properties_expand_string(mp_properties, str, mpctx);
2131 void property_print_help(void)
2133 m_properties_print_help_list(mp_properties);
2137 ///@}
2138 // Properties group
2142 * \defgroup Command2Property Command to property bridge
2144 * It is used to handle most commands that just set a property
2145 * and optionally display something on the OSD.
2146 * Two kinds of commands are handled: adjust or toggle.
2148 * Adjust commands take 1 or 2 parameters: <value> <abs>
2149 * If <abs> is non-zero the property is set to the given value
2150 * otherwise it is adjusted.
2152 * Toggle commands take 0 or 1 parameters. With no parameter
2153 * or a value less than the property minimum it just steps the
2154 * property to its next value. Otherwise it sets it to the given
2155 * value.
2160 /// List of the commands that can be handled by setting a property.
2161 static struct {
2162 /// property name
2163 const char *name;
2164 /// cmd id
2165 int cmd;
2166 /// set/adjust or toggle command
2167 int toggle;
2168 /// progressbar type
2169 int osd_progbar;
2170 /// osd msg id if it must be shared
2171 int osd_id;
2172 /// osd msg template
2173 const char *osd_msg;
2174 } set_prop_cmd[] = {
2175 // general
2176 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2177 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2178 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2179 // audio
2180 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2181 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2182 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2183 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2184 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2185 // video
2186 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2187 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2188 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2189 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2190 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2191 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2192 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2193 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2194 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2195 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2196 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2197 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2198 // subs
2199 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2200 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2201 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2202 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2203 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2204 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2205 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2206 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2207 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2208 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2209 #ifdef HAVE_FREETYPE
2210 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2211 #endif
2212 #ifdef USE_ASS
2213 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2214 #endif
2215 #ifdef USE_TV
2216 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2217 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2218 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2219 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2220 #endif
2221 { NULL, 0, 0, 0, -1, NULL }
2225 /// Handle commands that set a property.
2226 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
2228 int i, r;
2229 m_option_t* prop;
2230 const char *pname;
2232 // look for the command
2233 for (i = 0; set_prop_cmd[i].name; i++)
2234 if (set_prop_cmd[i].cmd == cmd->id)
2235 break;
2236 if (!(pname = set_prop_cmd[i].name))
2237 return 0;
2239 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2240 return 0;
2242 // toggle command
2243 if (set_prop_cmd[i].toggle) {
2244 // set to value
2245 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2246 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2247 else
2248 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2249 } else if (cmd->args[1].v.i) //set
2250 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2251 else // adjust
2252 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2254 if (r <= 0)
2255 return 1;
2257 if (set_prop_cmd[i].osd_progbar) {
2258 if (prop->type == CONF_TYPE_INT) {
2259 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2260 set_osd_bar(set_prop_cmd[i].osd_progbar,
2261 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2262 } else if (prop->type == CONF_TYPE_FLOAT) {
2263 float f;
2264 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2265 set_osd_bar(set_prop_cmd[i].osd_progbar,
2266 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2267 } else
2268 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2269 "Property use an unsupported type.\n");
2270 return 1;
2273 if (set_prop_cmd[i].osd_msg) {
2274 char *val = mp_property_print(pname, mpctx);
2275 if (val) {
2276 set_osd_msg(set_prop_cmd[i].osd_id >=
2277 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2278 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2279 free(val);
2282 return 1;
2286 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
2288 sh_audio_t * const sh_audio = mpctx->sh_audio;
2289 sh_video_t * const sh_video = mpctx->sh_video;
2290 int brk_cmd = 0;
2291 if (!set_property_command(mpctx, cmd))
2292 switch (cmd->id) {
2293 case MP_CMD_SEEK:{
2294 float v;
2295 int abs;
2296 if (sh_video)
2297 mpctx->osd_show_percentage = sh_video->fps;
2298 v = cmd->args[0].v.f;
2299 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2300 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2301 abs_seek_pos = SEEK_ABSOLUTE;
2302 if (sh_video)
2303 mpctx->osd_function =
2304 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2305 rel_seek_secs = v;
2306 } else if (abs) { /* Absolute seek by percentage */
2307 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2308 if (sh_video)
2309 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2310 rel_seek_secs = v / 100.0;
2311 } else {
2312 rel_seek_secs += v;
2313 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2315 brk_cmd = 1;
2317 break;
2319 case MP_CMD_SET_PROPERTY:{
2320 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2321 cmd->args[1].v.s, mpctx);
2322 if (r == M_PROPERTY_UNKNOWN)
2323 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2324 "Unknown property: '%s'\n", cmd->args[0].v.s);
2325 else if (r <= 0)
2326 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2327 "Failed to set property '%s' to '%s'.\n",
2328 cmd->args[0].v.s, cmd->args[1].v.s);
2330 break;
2332 case MP_CMD_STEP_PROPERTY:{
2333 void* arg = NULL;
2334 int r,i;
2335 double d;
2336 off_t o;
2337 if (cmd->args[1].v.f) {
2338 m_option_t* prop;
2339 if((r = mp_property_do(cmd->args[0].v.s,
2340 M_PROPERTY_GET_TYPE,
2341 &prop, mpctx)) <= 0)
2342 goto step_prop_err;
2343 if(prop->type == CONF_TYPE_INT ||
2344 prop->type == CONF_TYPE_FLAG)
2345 i = cmd->args[1].v.f, arg = &i;
2346 else if(prop->type == CONF_TYPE_FLOAT)
2347 arg = &cmd->args[1].v.f;
2348 else if(prop->type == CONF_TYPE_DOUBLE ||
2349 prop->type == CONF_TYPE_TIME)
2350 d = cmd->args[1].v.f, arg = &d;
2351 else if(prop->type == CONF_TYPE_POSITION)
2352 o = cmd->args[1].v.f, arg = &o;
2353 else
2354 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2355 "Ignoring step size stepping property '%s'.\n",
2356 cmd->args[0].v.s);
2358 r = mp_property_do(cmd->args[0].v.s,
2359 cmd->args[2].v.i < 0 ?
2360 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2361 arg, mpctx);
2362 step_prop_err:
2363 if (r == M_PROPERTY_UNKNOWN)
2364 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2365 "Unknown property: '%s'\n", cmd->args[0].v.s);
2366 else if (r <= 0)
2367 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2368 "Failed to increment property '%s' by %f.\n",
2369 cmd->args[0].v.s, cmd->args[1].v.f);
2371 break;
2373 case MP_CMD_GET_PROPERTY:{
2374 char *tmp;
2375 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2376 &tmp, mpctx) <= 0) {
2377 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2378 "Failed to get value of property '%s'.\n",
2379 cmd->args[0].v.s);
2380 break;
2382 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2383 cmd->args[0].v.s, tmp);
2384 free(tmp);
2386 break;
2388 case MP_CMD_EDL_MARK:
2389 if (edl_fd) {
2390 float v = sh_video ? sh_video->pts :
2391 playing_audio_pts(sh_audio, mpctx->d_audio,
2392 mpctx->audio_out);
2394 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2395 mpctx->begin_skip = v;
2396 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2397 } else {
2398 if (mpctx->begin_skip > v)
2399 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2400 else {
2401 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2402 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2404 mpctx->begin_skip = MP_NOPTS_VALUE;
2407 break;
2409 case MP_CMD_SWITCH_RATIO:
2410 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2411 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2412 else
2413 movie_aspect = cmd->args[0].v.f;
2414 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2415 break;
2417 case MP_CMD_SPEED_INCR:{
2418 float v = cmd->args[0].v.f;
2419 playback_speed += v;
2420 build_afilter_chain(sh_audio, &ao_data);
2421 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2422 playback_speed);
2423 } break;
2425 case MP_CMD_SPEED_MULT:{
2426 float v = cmd->args[0].v.f;
2427 playback_speed *= v;
2428 build_afilter_chain(sh_audio, &ao_data);
2429 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2430 playback_speed);
2431 } break;
2433 case MP_CMD_SPEED_SET:{
2434 float v = cmd->args[0].v.f;
2435 playback_speed = v;
2436 build_afilter_chain(sh_audio, &ao_data);
2437 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2438 playback_speed);
2439 } break;
2441 case MP_CMD_FRAME_STEP:
2442 case MP_CMD_PAUSE:
2443 cmd->pausing = 1;
2444 brk_cmd = 1;
2445 break;
2447 case MP_CMD_FILE_FILTER:
2448 file_filter = cmd->args[0].v.i;
2449 break;
2451 case MP_CMD_QUIT:
2452 exit_player_with_rc(MSGTR_Exit_quit,
2453 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2455 case MP_CMD_PLAY_TREE_STEP:{
2456 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2457 int force = cmd->args[1].v.i;
2459 #ifdef HAVE_NEW_GUI
2460 if (use_gui) {
2461 int i = 0;
2462 if (n > 0)
2463 for (i = 0; i < n; i++)
2464 mplNext();
2465 else
2466 for (i = 0; i < -1 * n; i++)
2467 mplPrev();
2468 } else
2469 #endif
2471 if (!force && mpctx->playtree_iter) {
2472 play_tree_iter_t *i =
2473 play_tree_iter_new_copy(mpctx->playtree_iter);
2474 if (play_tree_iter_step(i, n, 0) ==
2475 PLAY_TREE_ITER_ENTRY)
2476 mpctx->eof =
2477 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2478 play_tree_iter_free(i);
2479 } else
2480 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2481 if (mpctx->eof)
2482 mpctx->play_tree_step = n;
2483 brk_cmd = 1;
2486 break;
2488 case MP_CMD_PLAY_TREE_UP_STEP:{
2489 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2490 int force = cmd->args[1].v.i;
2492 if (!force && mpctx->playtree_iter) {
2493 play_tree_iter_t *i =
2494 play_tree_iter_new_copy(mpctx->playtree_iter);
2495 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2496 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2497 play_tree_iter_free(i);
2498 } else
2499 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2500 brk_cmd = 1;
2502 break;
2504 case MP_CMD_PLAY_ALT_SRC_STEP:
2505 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2506 int v = cmd->args[0].v.i;
2507 if (v > 0
2508 && mpctx->playtree_iter->file <
2509 mpctx->playtree_iter->num_files)
2510 mpctx->eof = PT_NEXT_SRC;
2511 else if (v < 0 && mpctx->playtree_iter->file > 1)
2512 mpctx->eof = PT_PREV_SRC;
2514 brk_cmd = 1;
2515 break;
2517 case MP_CMD_SUB_STEP:
2518 if (sh_video) {
2519 int movement = cmd->args[0].v.i;
2520 step_sub(subdata, sh_video->pts, movement);
2521 #ifdef USE_ASS
2522 if (ass_track)
2523 sub_delay +=
2524 ass_step_sub(ass_track,
2525 (sh_video->pts +
2526 sub_delay) * 1000 + .5, movement) / 1000.;
2527 #endif
2528 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2529 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2531 break;
2533 case MP_CMD_SUB_LOG:
2534 log_sub();
2535 break;
2537 case MP_CMD_OSD:{
2538 int v = cmd->args[0].v.i;
2539 int max = (term_osd
2540 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2541 if (osd_level > max)
2542 osd_level = max;
2543 if (v < 0)
2544 osd_level = (osd_level + 1) % (max + 1);
2545 else
2546 osd_level = v > max ? max : v;
2547 /* Show OSD state when disabled, but not when an explicit
2548 argument is given to the OSD command, i.e. in slave mode. */
2549 if (v == -1 && osd_level <= 1)
2550 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2551 MSGTR_OSDosd,
2552 osd_level ? MSGTR_OSDenabled :
2553 MSGTR_OSDdisabled);
2554 else
2555 rm_osd_msg(OSD_MSG_OSD_STATUS);
2557 break;
2559 case MP_CMD_OSD_SHOW_TEXT:
2560 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2561 (cmd->args[1].v.i <
2562 0 ? osd_duration : cmd->args[1].v.i),
2563 "%-.63s", cmd->args[0].v.s);
2564 break;
2566 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2567 char *txt = m_properties_expand_string(mp_properties,
2568 cmd->args[0].v.s,
2569 mpctx);
2570 /* if no argument supplied take default osd_duration, else <arg> ms. */
2571 if (txt) {
2572 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2573 (cmd->args[1].v.i <
2574 0 ? osd_duration : cmd->args[1].v.i),
2575 "%-.63s", txt);
2576 free(txt);
2579 break;
2581 case MP_CMD_LOADFILE:{
2582 play_tree_t *e = play_tree_new();
2583 play_tree_add_file(e, cmd->args[0].v.s);
2585 if (cmd->args[1].v.i) // append
2586 play_tree_append_entry(mpctx->playtree, e);
2587 else {
2588 // Go back to the starting point.
2589 while (play_tree_iter_up_step
2590 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2591 /* NOP */ ;
2592 play_tree_free_list(mpctx->playtree->child, 1);
2593 play_tree_set_child(mpctx->playtree, e);
2594 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2595 mpctx->eof = PT_NEXT_SRC;
2597 brk_cmd = 1;
2599 break;
2601 case MP_CMD_LOADLIST:{
2602 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2603 if (!e)
2604 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2605 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2606 else {
2607 if (cmd->args[1].v.i) // append
2608 play_tree_append_entry(mpctx->playtree, e);
2609 else {
2610 // Go back to the starting point.
2611 while (play_tree_iter_up_step
2612 (mpctx->playtree_iter, 0, 1)
2613 != PLAY_TREE_ITER_END)
2614 /* NOP */ ;
2615 play_tree_free_list(mpctx->playtree->child, 1);
2616 play_tree_set_child(mpctx->playtree, e);
2617 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2618 mpctx->eof = PT_NEXT_SRC;
2621 brk_cmd = 1;
2623 break;
2625 #ifdef USE_RADIO
2626 case MP_CMD_RADIO_STEP_CHANNEL:
2627 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2628 int v = cmd->args[0].v.i;
2629 if (v > 0)
2630 radio_step_channel(mpctx->demuxer->stream,
2631 RADIO_CHANNEL_HIGHER);
2632 else
2633 radio_step_channel(mpctx->demuxer->stream,
2634 RADIO_CHANNEL_LOWER);
2635 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2636 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2637 MSGTR_OSDChannel,
2638 radio_get_channel_name(mpctx->demuxer->stream));
2641 break;
2643 case MP_CMD_RADIO_SET_CHANNEL:
2644 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2645 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2646 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2647 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2648 MSGTR_OSDChannel,
2649 radio_get_channel_name(mpctx->demuxer->stream));
2652 break;
2654 case MP_CMD_RADIO_SET_FREQ:
2655 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2656 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2657 break;
2659 case MP_CMD_RADIO_STEP_FREQ:
2660 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2661 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2662 break;
2663 #endif
2665 #ifdef USE_TV
2666 case MP_CMD_TV_START_SCAN:
2667 if (mpctx->file_format == DEMUXER_TYPE_TV)
2668 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2669 break;
2670 case MP_CMD_TV_SET_FREQ:
2671 if (mpctx->file_format == DEMUXER_TYPE_TV)
2672 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2673 cmd->args[0].v.f * 16.0);
2674 #ifdef HAVE_PVR
2675 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2676 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2677 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2678 pvr_get_current_channelname (mpctx->stream),
2679 pvr_get_current_stationname (mpctx->stream));
2681 #endif /* HAVE_PVR */
2682 break;
2684 case MP_CMD_TV_STEP_FREQ:
2685 if (mpctx->file_format == DEMUXER_TYPE_TV)
2686 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2687 cmd->args[0].v.f * 16.0);
2688 #ifdef HAVE_PVR
2689 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2690 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2691 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2692 pvr_get_current_channelname (mpctx->stream),
2693 pvr_get_current_frequency (mpctx->stream));
2695 #endif /* HAVE_PVR */
2696 break;
2698 case MP_CMD_TV_SET_NORM:
2699 if (mpctx->file_format == DEMUXER_TYPE_TV)
2700 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2701 cmd->args[0].v.s);
2702 break;
2704 case MP_CMD_TV_STEP_CHANNEL:{
2705 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2706 int v = cmd->args[0].v.i;
2707 if (v > 0) {
2708 tv_step_channel((tvi_handle_t *) (mpctx->
2709 demuxer->priv),
2710 TV_CHANNEL_HIGHER);
2711 } else {
2712 tv_step_channel((tvi_handle_t *) (mpctx->
2713 demuxer->priv),
2714 TV_CHANNEL_LOWER);
2716 if (tv_channel_list) {
2717 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2718 MSGTR_OSDChannel, tv_channel_current->name);
2719 //vo_osd_changed(OSDTYPE_SUBTITLE);
2722 #ifdef HAVE_PVR
2723 else if (mpctx->stream &&
2724 mpctx->stream->type == STREAMTYPE_PVR) {
2725 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2726 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2727 pvr_get_current_channelname (mpctx->stream),
2728 pvr_get_current_stationname (mpctx->stream));
2730 #endif /* HAVE_PVR */
2732 #ifdef HAS_DVBIN_SUPPORT
2733 if (mpctx->stream->type == STREAMTYPE_DVB) {
2734 int dir;
2735 int v = cmd->args[0].v.i;
2737 mpctx->last_dvb_step = v;
2738 if (v > 0)
2739 dir = DVB_CHANNEL_HIGHER;
2740 else
2741 dir = DVB_CHANNEL_LOWER;
2744 if (dvb_step_channel(mpctx->stream, dir))
2745 mpctx->eof = mpctx->dvbin_reopen = 1;
2747 #endif /* HAS_DVBIN_SUPPORT */
2748 break;
2750 case MP_CMD_TV_SET_CHANNEL:
2751 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2752 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2753 cmd->args[0].v.s);
2754 if (tv_channel_list) {
2755 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2756 MSGTR_OSDChannel, tv_channel_current->name);
2757 //vo_osd_changed(OSDTYPE_SUBTITLE);
2760 #ifdef HAVE_PVR
2761 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2762 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2763 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2764 pvr_get_current_channelname (mpctx->stream),
2765 pvr_get_current_stationname (mpctx->stream));
2767 #endif /* HAVE_PVR */
2768 break;
2770 #ifdef HAS_DVBIN_SUPPORT
2771 case MP_CMD_DVB_SET_CHANNEL:
2772 if (mpctx->stream->type == STREAMTYPE_DVB) {
2773 mpctx->last_dvb_step = 1;
2775 if (dvb_set_channel
2776 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2777 mpctx->eof = mpctx->dvbin_reopen = 1;
2779 break;
2780 #endif /* HAS_DVBIN_SUPPORT */
2782 case MP_CMD_TV_LAST_CHANNEL:
2783 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2784 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2785 if (tv_channel_list) {
2786 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2787 MSGTR_OSDChannel, tv_channel_current->name);
2788 //vo_osd_changed(OSDTYPE_SUBTITLE);
2791 #ifdef HAVE_PVR
2792 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2793 pvr_set_lastchannel (mpctx->stream);
2794 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2795 pvr_get_current_channelname (mpctx->stream),
2796 pvr_get_current_stationname (mpctx->stream));
2798 #endif /* HAVE_PVR */
2799 break;
2801 case MP_CMD_TV_STEP_NORM:
2802 if (mpctx->file_format == DEMUXER_TYPE_TV)
2803 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2804 break;
2806 case MP_CMD_TV_STEP_CHANNEL_LIST:
2807 if (mpctx->file_format == DEMUXER_TYPE_TV)
2808 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2809 break;
2810 #ifdef HAVE_TV_TELETEXT
2811 case MP_CMD_TV_TELETEXT_ADD_DEC:
2813 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2814 if (mpctx->file_format == DEMUXER_TYPE_TV)
2815 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2816 break;
2818 case MP_CMD_TV_TELETEXT_GO_LINK:
2820 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2821 if (mpctx->file_format == DEMUXER_TYPE_TV)
2822 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2823 break;
2825 #endif /* HAVE_TV_TELETEXT */
2826 #endif /* USE_TV */
2828 case MP_CMD_SUB_LOAD:
2829 if (sh_video) {
2830 int n = mpctx->set_of_sub_size;
2831 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2832 if (n != mpctx->set_of_sub_size) {
2833 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2834 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2835 mpctx->global_sub_size;
2836 ++mpctx->global_sub_size;
2839 break;
2841 case MP_CMD_SUB_REMOVE:
2842 if (sh_video) {
2843 int v = cmd->args[0].v.i;
2844 sub_data *subd;
2845 if (v < 0) {
2846 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2847 subd = mpctx->set_of_subtitles[v];
2848 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2849 MSGTR_RemovedSubtitleFile, v + 1,
2850 filename_recode(subd->filename));
2851 sub_free(subd);
2852 mpctx->set_of_subtitles[v] = NULL;
2854 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2855 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2856 mpctx->set_of_sub_size = 0;
2857 if (mpctx->set_of_sub_pos >= 0) {
2858 mpctx->global_sub_pos = -2;
2859 subdata = NULL;
2860 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2862 } else if (v < mpctx->set_of_sub_size) {
2863 subd = mpctx->set_of_subtitles[v];
2864 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2865 MSGTR_RemovedSubtitleFile, v + 1,
2866 filename_recode(subd->filename));
2867 sub_free(subd);
2868 if (mpctx->set_of_sub_pos == v) {
2869 mpctx->global_sub_pos = -2;
2870 subdata = NULL;
2871 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2872 } else if (mpctx->set_of_sub_pos > v) {
2873 --mpctx->set_of_sub_pos;
2874 --mpctx->global_sub_pos;
2876 while (++v < mpctx->set_of_sub_size)
2877 mpctx->set_of_subtitles[v - 1] =
2878 mpctx->set_of_subtitles[v];
2879 --mpctx->set_of_sub_size;
2880 --mpctx->global_sub_size;
2881 if (mpctx->set_of_sub_size <= 0)
2882 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2883 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2886 break;
2888 case MP_CMD_GET_SUB_VISIBILITY:
2889 if (sh_video) {
2890 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2891 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2893 break;
2895 case MP_CMD_SCREENSHOT:
2896 if (vo_config_count) {
2897 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2898 if (CONTROL_OK !=
2899 ((vf_instance_t *) sh_video->vfilter)->
2900 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2901 &cmd->args[0].v.i))
2902 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2904 break;
2906 case MP_CMD_VF_CHANGE_RECTANGLE:
2907 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2908 break;
2910 case MP_CMD_GET_TIME_LENGTH:{
2911 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2912 demuxer_get_time_length(mpctx->demuxer));
2914 break;
2916 case MP_CMD_GET_FILENAME:{
2917 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2918 get_metadata(META_NAME));
2920 break;
2922 case MP_CMD_GET_VIDEO_CODEC:{
2923 char *inf = get_metadata(META_VIDEO_CODEC);
2924 if (!inf)
2925 inf = strdup("");
2926 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2927 free(inf);
2929 break;
2931 case MP_CMD_GET_VIDEO_BITRATE:{
2932 char *inf = get_metadata(META_VIDEO_BITRATE);
2933 if (!inf)
2934 inf = strdup("");
2935 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2936 free(inf);
2938 break;
2940 case MP_CMD_GET_VIDEO_RESOLUTION:{
2941 char *inf = get_metadata(META_VIDEO_RESOLUTION);
2942 if (!inf)
2943 inf = strdup("");
2944 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2945 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
2946 free(inf);
2948 break;
2950 case MP_CMD_GET_AUDIO_CODEC:{
2951 char *inf = get_metadata(META_AUDIO_CODEC);
2952 if (!inf)
2953 inf = strdup("");
2954 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
2955 free(inf);
2957 break;
2959 case MP_CMD_GET_AUDIO_BITRATE:{
2960 char *inf = get_metadata(META_AUDIO_BITRATE);
2961 if (!inf)
2962 inf = strdup("");
2963 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
2964 free(inf);
2966 break;
2968 case MP_CMD_GET_AUDIO_SAMPLES:{
2969 char *inf = get_metadata(META_AUDIO_SAMPLES);
2970 if (!inf)
2971 inf = strdup("");
2972 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
2973 free(inf);
2975 break;
2977 case MP_CMD_GET_META_TITLE:{
2978 char *inf = get_metadata(META_INFO_TITLE);
2979 if (!inf)
2980 inf = strdup("");
2981 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
2982 free(inf);
2984 break;
2986 case MP_CMD_GET_META_ARTIST:{
2987 char *inf = get_metadata(META_INFO_ARTIST);
2988 if (!inf)
2989 inf = strdup("");
2990 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
2991 free(inf);
2993 break;
2995 case MP_CMD_GET_META_ALBUM:{
2996 char *inf = get_metadata(META_INFO_ALBUM);
2997 if (!inf)
2998 inf = strdup("");
2999 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3000 free(inf);
3002 break;
3004 case MP_CMD_GET_META_YEAR:{
3005 char *inf = get_metadata(META_INFO_YEAR);
3006 if (!inf)
3007 inf = strdup("");
3008 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3009 free(inf);
3011 break;
3013 case MP_CMD_GET_META_COMMENT:{
3014 char *inf = get_metadata(META_INFO_COMMENT);
3015 if (!inf)
3016 inf = strdup("");
3017 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3018 free(inf);
3020 break;
3022 case MP_CMD_GET_META_TRACK:{
3023 char *inf = get_metadata(META_INFO_TRACK);
3024 if (!inf)
3025 inf = strdup("");
3026 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3027 free(inf);
3029 break;
3031 case MP_CMD_GET_META_GENRE:{
3032 char *inf = get_metadata(META_INFO_GENRE);
3033 if (!inf)
3034 inf = strdup("");
3035 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3036 free(inf);
3038 break;
3040 case MP_CMD_GET_VO_FULLSCREEN:
3041 if (mpctx->video_out && vo_config_count)
3042 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3043 break;
3045 case MP_CMD_GET_PERCENT_POS:
3046 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3047 demuxer_get_percent_pos(mpctx->demuxer));
3048 break;
3050 case MP_CMD_GET_TIME_POS:{
3051 float pos = 0;
3052 if (sh_video)
3053 pos = sh_video->pts;
3054 else if (sh_audio && mpctx->audio_out)
3055 pos =
3056 playing_audio_pts(sh_audio, mpctx->d_audio,
3057 mpctx->audio_out);
3058 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3060 break;
3062 case MP_CMD_RUN:
3063 #ifndef __MINGW32__
3064 if (!fork()) {
3065 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3066 exit(0);
3068 #endif
3069 break;
3071 case MP_CMD_KEYDOWN_EVENTS:
3072 mplayer_put_key(cmd->args[0].v.i);
3073 break;
3075 case MP_CMD_SET_MOUSE_POS:{
3076 int pointer_x, pointer_y;
3077 double dx, dy;
3078 pointer_x = cmd->args[0].v.i;
3079 pointer_y = cmd->args[1].v.i;
3080 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
3081 #ifdef USE_DVDNAV
3082 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3083 && dx > 0.0 && dy > 0.0) {
3084 int button = -1;
3085 pointer_x = (int) (dx * (double) sh_video->disp_w);
3086 pointer_y = (int) (dy * (double) sh_video->disp_h);
3087 mp_dvdnav_update_mouse_pos(mpctx->stream,
3088 pointer_x, pointer_y, &button);
3089 if (osd_level > 1 && button > 0)
3090 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3091 "Selected button number %d", button);
3093 #endif
3094 #ifdef HAVE_MENU
3095 if (use_menu && dx >= 0.0 && dy >= 0.0)
3096 menu_update_mouse_pos(dx, dy);
3097 #endif
3099 break;
3101 #ifdef USE_DVDNAV
3102 case MP_CMD_DVDNAV:{
3103 int button = -1;
3104 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3105 break;
3107 mp_dvdnav_handle_input(mpctx->stream,cmd->args[0].v.i,&button);
3108 if (osd_level > 1 && button > 0)
3109 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3110 "Selected button number %d", button);
3112 break;
3114 case MP_CMD_SWITCH_TITLE:
3115 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3116 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3117 break;
3119 #endif
3121 default:
3122 #ifdef HAVE_NEW_GUI
3123 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3124 guiGetEvent(guiIEvent, (char *) cmd->id);
3125 else
3126 #endif
3127 mp_msg(MSGT_CPLAYER, MSGL_V,
3128 "Received unknown cmd %s\n", cmd->name);
3131 switch (cmd->pausing) {
3132 case 1: // "pausing"
3133 mpctx->osd_function = OSD_PAUSE;
3134 break;
3135 case 3: // "pausing_toggle"
3136 mpctx->was_paused = !mpctx->was_paused;
3137 if (mpctx->was_paused)
3138 mpctx->osd_function = OSD_PAUSE;
3139 else if (mpctx->osd_function == OSD_PAUSE)
3140 mpctx->osd_function = OSD_PLAY;
3141 break;
3142 case 2: // "pausing_keep"
3143 if (mpctx->was_paused)
3144 mpctx->osd_function = OSD_PAUSE;
3146 return brk_cmd;