Revert "fix missing event on move that breaks xmga window movement"
[mplayer/glamo.git] / command.c
blobff36cd8c8b46415f2e72bbcc0ade39e767e0e60d
1 #include <stdlib.h>
2 #include <inttypes.h>
3 #include <unistd.h>
4 #include <string.h>
6 #include "config.h"
7 #include "command.h"
8 #include "input/input.h"
9 #include "stream/stream.h"
10 #include "libmpdemux/demuxer.h"
11 #include "libmpdemux/stheader.h"
12 #include "codec-cfg.h"
13 #include "mplayer.h"
14 #include "libvo/sub.h"
15 #include "m_option.h"
16 #include "m_property.h"
17 #include "help_mp.h"
18 #include "metadata.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 "libmpcodecs/dec_video.h"
28 #include "vobsub.h"
29 #include "spudec.h"
30 #include "get_path.h"
31 #ifdef CONFIG_TV
32 #include "stream/tv.h"
33 #endif
34 #ifdef CONFIG_RADIO
35 #include "stream/stream_radio.h"
36 #endif
37 #ifdef CONFIG_PVR
38 #include "stream/pvr.h"
39 #endif
40 #ifdef CONFIG_DVBIN
41 #include "stream/dvbin.h"
42 #endif
43 #ifdef CONFIG_DVDREAD
44 #include "stream/stream_dvd.h"
45 #endif
46 #ifdef CONFIG_DVDNAV
47 #include "stream/stream_dvdnav.h"
48 #endif
49 #ifdef CONFIG_ASS
50 #include "libass/ass.h"
51 #include "libass/ass_mp.h"
52 #endif
53 #ifdef CONFIG_MENU
54 #include "m_struct.h"
55 #include "libmenu/menu.h"
56 #endif
57 #ifdef CONFIG_GUI
58 #include "gui/interface.h"
59 #endif
61 #include "mp_core.h"
62 #include "mp_fifo.h"
63 #include "libavutil/avstring.h"
65 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
67 extern int use_menu;
69 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy)
71 //remove the borders, if any, and rescale to the range [0,1],[0,1]
72 if (vo_fs) { //we are in full-screen mode
73 if (vo_screenwidth > vo_dwidth) //there are borders along the x axis
74 ix -= (vo_screenwidth - vo_dwidth) / 2;
75 if (vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
76 iy -= (vo_screenheight - vo_dheight) / 2;
78 if (ix < 0 || ix > vo_dwidth) {
79 *dx = *dy = -1.0;
80 return;
81 } //we are on one of the borders
82 if (iy < 0 || iy > vo_dheight) {
83 *dx = *dy = -1.0;
84 return;
85 } //we are on one of the borders
88 *dx = (double) ix / (double) vo_dwidth;
89 *dy = (double) iy / (double) vo_dheight;
91 mp_msg(MSGT_CPLAYER, MSGL_V,
92 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
93 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth,
94 vo_dheight, vo_fs);
97 static int sub_source_by_pos(MPContext * mpctx, int pos)
99 int source = -1;
100 int top = -1;
101 int i;
102 for (i = 0; i < SUB_SOURCES; i++) {
103 int j = mpctx->global_sub_indices[i];
104 if ((j >= 0) && (j > top) && (pos >= j)) {
105 source = i;
106 top = j;
109 return source;
112 static int sub_source(MPContext * mpctx)
114 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
118 * \brief Log the currently displayed subtitle to a file
120 * Logs the current or last displayed subtitle together with filename
121 * and time information to ~/.mplayer/subtitle_log
123 * Intended purpose is to allow convenient marking of bogus subtitles
124 * which need to be fixed while watching the movie.
127 static void log_sub(void)
129 char *fname;
130 FILE *f;
131 int i;
133 if (subdata == NULL || vo_sub_last == NULL)
134 return;
135 fname = get_path("subtitle_log");
136 f = fopen(fname, "a");
137 if (!f)
138 return;
139 fprintf(f, "----------------------------------------------------------\n");
140 if (subdata->sub_uses_time) {
141 fprintf(f,
142 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
143 filename, vo_sub_last->start / 360000,
144 (vo_sub_last->start / 6000) % 60,
145 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
146 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
147 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
148 } else {
149 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start,
150 vo_sub_last->end);
152 for (i = 0; i < vo_sub_last->lines; i++) {
153 fprintf(f, "%s\n", vo_sub_last->text[i]);
155 fclose(f);
159 /// \defgroup Properties
160 ///@{
162 /// \defgroup GeneralProperties General properties
163 /// \ingroup Properties
164 ///@{
166 /// OSD level (RW)
167 static int mp_property_osdlevel(m_option_t * prop, int action, void *arg,
168 MPContext * mpctx)
170 return m_property_choice(prop, action, arg, &osd_level);
173 /// Loop (RW)
174 static int mp_property_loop(m_option_t * prop, int action, void *arg,
175 MPContext * mpctx)
177 switch (action) {
178 case M_PROPERTY_PRINT:
179 if (!arg) return M_PROPERTY_ERROR;
180 if (mpctx->loop_times < 0)
181 *(char**)arg = strdup("off");
182 else if (mpctx->loop_times == 0)
183 *(char**)arg = strdup("inf");
184 else
185 break;
186 return M_PROPERTY_OK;
188 return m_property_int_range(prop, action, arg, &mpctx->loop_times);
191 /// Playback speed (RW)
192 static int mp_property_playback_speed(m_option_t * prop, int action,
193 void *arg, MPContext * mpctx)
195 switch (action) {
196 case M_PROPERTY_SET:
197 if (!arg)
198 return M_PROPERTY_ERROR;
199 M_PROPERTY_CLAMP(prop, *(float *) arg);
200 playback_speed = *(float *) arg;
201 build_afilter_chain(mpctx->sh_audio, &ao_data);
202 return M_PROPERTY_OK;
203 case M_PROPERTY_STEP_UP:
204 case M_PROPERTY_STEP_DOWN:
205 playback_speed += (arg ? *(float *) arg : 0.1) *
206 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
207 M_PROPERTY_CLAMP(prop, playback_speed);
208 build_afilter_chain(mpctx->sh_audio, &ao_data);
209 return M_PROPERTY_OK;
211 return m_property_float_range(prop, action, arg, &playback_speed);
214 /// filename with path (RO)
215 static int mp_property_path(m_option_t * prop, int action, void *arg,
216 MPContext * mpctx)
218 return m_property_string_ro(prop, action, arg, filename);
221 /// filename without path (RO)
222 static int mp_property_filename(m_option_t * prop, int action, void *arg,
223 MPContext * mpctx)
225 char *f;
226 if (!filename)
227 return M_PROPERTY_UNAVAILABLE;
228 if (((f = strrchr(filename, '/')) || (f = strrchr(filename, '\\'))) && f[1])
229 f++;
230 else
231 f = filename;
232 return m_property_string_ro(prop, action, arg, f);
235 /// Demuxer name (RO)
236 static int mp_property_demuxer(m_option_t * prop, int action, void *arg,
237 MPContext * mpctx)
239 if (!mpctx->demuxer)
240 return M_PROPERTY_UNAVAILABLE;
241 return m_property_string_ro(prop, action, arg,
242 (char *) mpctx->demuxer->desc->name);
245 /// Position in the stream (RW)
246 static int mp_property_stream_pos(m_option_t * prop, int action, void *arg,
247 MPContext * mpctx)
249 if (!mpctx->demuxer || !mpctx->demuxer->stream)
250 return M_PROPERTY_UNAVAILABLE;
251 if (!arg)
252 return M_PROPERTY_ERROR;
253 switch (action) {
254 case M_PROPERTY_GET:
255 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
256 return M_PROPERTY_OK;
257 case M_PROPERTY_SET:
258 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
259 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
260 return M_PROPERTY_OK;
262 return M_PROPERTY_NOT_IMPLEMENTED;
265 /// Stream start offset (RO)
266 static int mp_property_stream_start(m_option_t * prop, int action,
267 void *arg, MPContext * mpctx)
269 if (!mpctx->demuxer || !mpctx->demuxer->stream)
270 return M_PROPERTY_UNAVAILABLE;
271 switch (action) {
272 case M_PROPERTY_GET:
273 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
274 return M_PROPERTY_OK;
276 return M_PROPERTY_NOT_IMPLEMENTED;
279 /// Stream end offset (RO)
280 static int mp_property_stream_end(m_option_t * prop, int action, void *arg,
281 MPContext * mpctx)
283 if (!mpctx->demuxer || !mpctx->demuxer->stream)
284 return M_PROPERTY_UNAVAILABLE;
285 switch (action) {
286 case M_PROPERTY_GET:
287 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
288 return M_PROPERTY_OK;
290 return M_PROPERTY_NOT_IMPLEMENTED;
293 /// Stream length (RO)
294 static int mp_property_stream_length(m_option_t * prop, int action,
295 void *arg, MPContext * mpctx)
297 if (!mpctx->demuxer || !mpctx->demuxer->stream)
298 return M_PROPERTY_UNAVAILABLE;
299 switch (action) {
300 case M_PROPERTY_GET:
301 *(off_t *) arg =
302 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
303 return M_PROPERTY_OK;
305 return M_PROPERTY_NOT_IMPLEMENTED;
308 /// Media length in seconds (RO)
309 static int mp_property_length(m_option_t * prop, int action, void *arg,
310 MPContext * mpctx)
312 double len;
314 if (!mpctx->demuxer ||
315 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
316 return M_PROPERTY_UNAVAILABLE;
318 return m_property_time_ro(prop, action, arg, len);
321 /// Current position in percent (RW)
322 static int mp_property_percent_pos(m_option_t * prop, int action,
323 void *arg, MPContext * mpctx) {
324 int pos;
326 if (!mpctx->demuxer)
327 return M_PROPERTY_UNAVAILABLE;
329 switch(action) {
330 case M_PROPERTY_SET:
331 if(!arg) return M_PROPERTY_ERROR;
332 M_PROPERTY_CLAMP(prop, *(int*)arg);
333 pos = *(int*)arg;
334 break;
335 case M_PROPERTY_STEP_UP:
336 case M_PROPERTY_STEP_DOWN:
337 pos = demuxer_get_percent_pos(mpctx->demuxer);
338 pos += (arg ? *(int*)arg : 10) *
339 (action == M_PROPERTY_STEP_UP ? 1 : -1);
340 M_PROPERTY_CLAMP(prop, pos);
341 break;
342 default:
343 return m_property_int_ro(prop, action, arg,
344 demuxer_get_percent_pos(mpctx->demuxer));
347 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
348 rel_seek_secs = pos / 100.0;
349 return M_PROPERTY_OK;
352 /// Current position in seconds (RW)
353 static int mp_property_time_pos(m_option_t * prop, int action,
354 void *arg, MPContext * mpctx) {
355 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
356 return M_PROPERTY_UNAVAILABLE;
358 switch(action) {
359 case M_PROPERTY_SET:
360 if(!arg) return M_PROPERTY_ERROR;
361 M_PROPERTY_CLAMP(prop, *(double*)arg);
362 abs_seek_pos = SEEK_ABSOLUTE;
363 rel_seek_secs = *(double*)arg;
364 return M_PROPERTY_OK;
365 case M_PROPERTY_STEP_UP:
366 case M_PROPERTY_STEP_DOWN:
367 rel_seek_secs += (arg ? *(double*)arg : 10.0) *
368 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
369 return M_PROPERTY_OK;
371 return m_property_time_ro(prop, action, arg,
372 mpctx->sh_video ? mpctx->sh_video->pts :
373 playing_audio_pts(mpctx->sh_audio,
374 mpctx->d_audio,
375 mpctx->audio_out));
378 /// Current chapter (RW)
379 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
380 MPContext *mpctx)
382 int chapter = -1;
383 float next_pts = 0;
384 int chapter_num;
385 int step_all;
386 char *chapter_name = NULL;
388 if (mpctx->demuxer)
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;
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 /// Number of chapters in file
451 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
452 MPContext *mpctx)
454 if (!mpctx->demuxer)
455 return M_PROPERTY_UNAVAILABLE;
456 if (mpctx->demuxer->num_chapters == 0)
457 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
458 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
461 /// Current dvd angle (RW)
462 static int mp_property_angle(m_option_t *prop, int action, void *arg,
463 MPContext *mpctx)
465 int angle = -1;
466 int angles;
467 char *angle_name = NULL;
469 if (mpctx->demuxer)
470 angle = demuxer_get_current_angle(mpctx->demuxer);
471 if (angle < 0)
472 return M_PROPERTY_UNAVAILABLE;
473 angles = demuxer_angles_count(mpctx->demuxer);
474 if (angles <= 1)
475 return M_PROPERTY_UNAVAILABLE;
477 switch (action) {
478 case M_PROPERTY_GET:
479 if (!arg)
480 return M_PROPERTY_ERROR;
481 *(int *) arg = angle;
482 return M_PROPERTY_OK;
483 case M_PROPERTY_PRINT: {
484 if (!arg)
485 return M_PROPERTY_ERROR;
486 angle_name = calloc(1, 64);
487 if (!angle_name)
488 return M_PROPERTY_UNAVAILABLE;
489 snprintf(angle_name, 64, "%d/%d", angle, angles);
490 *(char **) arg = angle_name;
491 return M_PROPERTY_OK;
493 case M_PROPERTY_SET:
494 if (!arg)
495 return M_PROPERTY_ERROR;
496 angle = *(int *)arg;
497 M_PROPERTY_CLAMP(prop, angle);
498 break;
499 case M_PROPERTY_STEP_UP:
500 case M_PROPERTY_STEP_DOWN: {
501 int step = 0;
502 if(arg)
503 step = *(int*)arg;
504 if(!step)
505 step = 1;
506 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
507 angle += step;
508 if (angle < 1) //cycle
509 angle = angles;
510 break;
512 default:
513 return M_PROPERTY_NOT_IMPLEMENTED;
515 angle = demuxer_set_angle(mpctx->demuxer, angle);
516 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
517 MSGTR_OSDAngle, angle, angles);
518 if (angle_name)
519 free(angle_name);
520 return M_PROPERTY_OK;
523 /// Demuxer meta data
524 static int mp_property_metadata(m_option_t * prop, int action, void *arg,
525 MPContext * mpctx) {
526 m_property_action_t* ka;
527 char* meta;
528 static m_option_t key_type =
529 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
530 if (!mpctx->demuxer)
531 return M_PROPERTY_UNAVAILABLE;
533 switch(action) {
534 case M_PROPERTY_GET:
535 if(!arg) return M_PROPERTY_ERROR;
536 *(char***)arg = mpctx->demuxer->info;
537 return M_PROPERTY_OK;
538 case M_PROPERTY_KEY_ACTION:
539 if(!arg) return M_PROPERTY_ERROR;
540 ka = arg;
541 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
542 return M_PROPERTY_UNKNOWN;
543 switch(ka->action) {
544 case M_PROPERTY_GET:
545 if(!ka->arg) return M_PROPERTY_ERROR;
546 *(char**)ka->arg = meta;
547 return M_PROPERTY_OK;
548 case M_PROPERTY_GET_TYPE:
549 if(!ka->arg) return M_PROPERTY_ERROR;
550 *(m_option_t**)ka->arg = &key_type;
551 return M_PROPERTY_OK;
554 return M_PROPERTY_NOT_IMPLEMENTED;
557 static int mp_property_pause(m_option_t * prop, int action, void *arg,
558 MPContext * mpctx)
560 return m_property_flag_ro(prop, action, arg, mpctx->osd_function == OSD_PAUSE);
564 ///@}
566 /// \defgroup AudioProperties Audio properties
567 /// \ingroup Properties
568 ///@{
570 /// Volume (RW)
571 static int mp_property_volume(m_option_t * prop, int action, void *arg,
572 MPContext * mpctx)
575 if (!mpctx->sh_audio)
576 return M_PROPERTY_UNAVAILABLE;
578 switch (action) {
579 case M_PROPERTY_GET:
580 if (!arg)
581 return M_PROPERTY_ERROR;
582 mixer_getbothvolume(&mpctx->mixer, arg);
583 return M_PROPERTY_OK;
584 case M_PROPERTY_PRINT:{
585 float vol;
586 if (!arg)
587 return M_PROPERTY_ERROR;
588 mixer_getbothvolume(&mpctx->mixer, &vol);
589 return m_property_float_range(prop, action, arg, &vol);
591 case M_PROPERTY_STEP_UP:
592 case M_PROPERTY_STEP_DOWN:
593 case M_PROPERTY_SET:
594 break;
595 default:
596 return M_PROPERTY_NOT_IMPLEMENTED;
599 if (mpctx->edl_muted)
600 return M_PROPERTY_DISABLED;
601 mpctx->user_muted = 0;
603 switch (action) {
604 case M_PROPERTY_SET:
605 if (!arg)
606 return M_PROPERTY_ERROR;
607 M_PROPERTY_CLAMP(prop, *(float *) arg);
608 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
609 return M_PROPERTY_OK;
610 case M_PROPERTY_STEP_UP:
611 if (arg && *(float *) arg <= 0)
612 mixer_decvolume(&mpctx->mixer);
613 else
614 mixer_incvolume(&mpctx->mixer);
615 return M_PROPERTY_OK;
616 case M_PROPERTY_STEP_DOWN:
617 if (arg && *(float *) arg <= 0)
618 mixer_incvolume(&mpctx->mixer);
619 else
620 mixer_decvolume(&mpctx->mixer);
621 return M_PROPERTY_OK;
623 return M_PROPERTY_NOT_IMPLEMENTED;
626 /// Mute (RW)
627 static int mp_property_mute(m_option_t * prop, int action, void *arg,
628 MPContext * mpctx)
631 if (!mpctx->sh_audio)
632 return M_PROPERTY_UNAVAILABLE;
634 switch (action) {
635 case M_PROPERTY_SET:
636 if (mpctx->edl_muted)
637 return M_PROPERTY_DISABLED;
638 if (!arg)
639 return M_PROPERTY_ERROR;
640 if ((!!*(int *) arg) != mpctx->mixer.muted)
641 mixer_mute(&mpctx->mixer);
642 mpctx->user_muted = mpctx->mixer.muted;
643 return M_PROPERTY_OK;
644 case M_PROPERTY_STEP_UP:
645 case M_PROPERTY_STEP_DOWN:
646 if (mpctx->edl_muted)
647 return M_PROPERTY_DISABLED;
648 mixer_mute(&mpctx->mixer);
649 mpctx->user_muted = mpctx->mixer.muted;
650 return M_PROPERTY_OK;
651 case M_PROPERTY_PRINT:
652 if (!arg)
653 return M_PROPERTY_ERROR;
654 if (mpctx->edl_muted) {
655 *(char **) arg = strdup(MSGTR_EnabledEdl);
656 return M_PROPERTY_OK;
658 default:
659 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
664 /// Audio delay (RW)
665 static int mp_property_audio_delay(m_option_t * prop, int action,
666 void *arg, MPContext * mpctx)
668 if (!(mpctx->sh_audio && mpctx->sh_video))
669 return M_PROPERTY_UNAVAILABLE;
670 switch (action) {
671 case M_PROPERTY_SET:
672 case M_PROPERTY_STEP_UP:
673 case M_PROPERTY_STEP_DOWN: {
674 int ret;
675 float delay = audio_delay;
676 ret = m_property_delay(prop, action, arg, &audio_delay);
677 if (ret != M_PROPERTY_OK)
678 return ret;
679 if (mpctx->sh_audio)
680 mpctx->delay -= audio_delay - delay;
682 return M_PROPERTY_OK;
683 default:
684 return m_property_delay(prop, action, arg, &audio_delay);
688 /// Audio codec tag (RO)
689 static int mp_property_audio_format(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_int_ro(prop, action, arg, mpctx->sh_audio->format);
697 /// Audio codec name (RO)
698 static int mp_property_audio_codec(m_option_t * prop, int action,
699 void *arg, MPContext * mpctx)
701 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
702 return M_PROPERTY_UNAVAILABLE;
703 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
706 /// Audio bitrate (RO)
707 static int mp_property_audio_bitrate(m_option_t * prop, int action,
708 void *arg, MPContext * mpctx)
710 if (!mpctx->sh_audio)
711 return M_PROPERTY_UNAVAILABLE;
712 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
715 /// Samplerate (RO)
716 static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
717 MPContext * mpctx)
719 if (!mpctx->sh_audio)
720 return M_PROPERTY_UNAVAILABLE;
721 switch(action) {
722 case M_PROPERTY_PRINT:
723 if(!arg) return M_PROPERTY_ERROR;
724 *(char**)arg = malloc(16);
725 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
726 return M_PROPERTY_OK;
728 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
731 /// Number of channels (RO)
732 static int mp_property_channels(m_option_t * prop, int action, void *arg,
733 MPContext * mpctx)
735 if (!mpctx->sh_audio)
736 return M_PROPERTY_UNAVAILABLE;
737 switch (action) {
738 case M_PROPERTY_PRINT:
739 if (!arg)
740 return M_PROPERTY_ERROR;
741 switch (mpctx->sh_audio->channels) {
742 case 1:
743 *(char **) arg = strdup("mono");
744 break;
745 case 2:
746 *(char **) arg = strdup("stereo");
747 break;
748 default:
749 *(char **) arg = malloc(32);
750 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
752 return M_PROPERTY_OK;
754 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
757 /// Balance (RW)
758 static int mp_property_balance(m_option_t * prop, int action, void *arg,
759 MPContext * mpctx)
761 float bal;
763 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
764 return M_PROPERTY_UNAVAILABLE;
766 switch (action) {
767 case M_PROPERTY_GET:
768 if (!arg)
769 return M_PROPERTY_ERROR;
770 mixer_getbalance(&mpctx->mixer, arg);
771 return M_PROPERTY_OK;
772 case M_PROPERTY_PRINT: {
773 char** str = arg;
774 if (!arg)
775 return M_PROPERTY_ERROR;
776 mixer_getbalance(&mpctx->mixer, &bal);
777 if (bal == 0.f)
778 *str = strdup("center");
779 else if (bal == -1.f)
780 *str = strdup("left only");
781 else if (bal == 1.f)
782 *str = strdup("right only");
783 else {
784 unsigned right = (bal + 1.f) / 2.f * 100.f;
785 *str = malloc(sizeof("left xxx%, right xxx%"));
786 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
788 return M_PROPERTY_OK;
790 case M_PROPERTY_STEP_UP:
791 case M_PROPERTY_STEP_DOWN:
792 mixer_getbalance(&mpctx->mixer, &bal);
793 bal += (arg ? *(float*)arg : .1f) *
794 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
795 M_PROPERTY_CLAMP(prop, bal);
796 mixer_setbalance(&mpctx->mixer, bal);
797 return M_PROPERTY_OK;
798 case M_PROPERTY_SET:
799 if (!arg)
800 return M_PROPERTY_ERROR;
801 M_PROPERTY_CLAMP(prop, *(float*)arg);
802 mixer_setbalance(&mpctx->mixer, *(float*)arg);
803 return M_PROPERTY_OK;
805 return M_PROPERTY_NOT_IMPLEMENTED;
808 /// Selected audio id (RW)
809 static int mp_property_audio(m_option_t * prop, int action, void *arg,
810 MPContext * mpctx)
812 int current_id = -1, tmp;
814 switch (action) {
815 case M_PROPERTY_GET:
816 if (!mpctx->sh_audio)
817 return M_PROPERTY_UNAVAILABLE;
818 if (!arg)
819 return M_PROPERTY_ERROR;
820 *(int *) arg = audio_id;
821 return M_PROPERTY_OK;
822 case M_PROPERTY_PRINT:
823 if (!mpctx->sh_audio)
824 return M_PROPERTY_UNAVAILABLE;
825 if (!arg)
826 return M_PROPERTY_ERROR;
828 if (audio_id < 0)
829 *(char **) arg = strdup(MSGTR_Disabled);
830 else {
831 char lang[40] = MSGTR_Unknown;
832 sh_audio_t* sh = mpctx->sh_audio;
833 if (sh && sh->lang)
834 av_strlcpy(lang, sh->lang, 40);
835 #ifdef CONFIG_DVDREAD
836 else if (mpctx->stream->type == STREAMTYPE_DVD) {
837 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
838 if (code) {
839 lang[0] = code >> 8;
840 lang[1] = code;
841 lang[2] = 0;
844 #endif
846 #ifdef CONFIG_DVDNAV
847 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
848 mp_dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
849 #endif
850 *(char **) arg = malloc(64);
851 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
853 return M_PROPERTY_OK;
855 case M_PROPERTY_STEP_UP:
856 case M_PROPERTY_SET:
857 if (!mpctx->demuxer)
858 return M_PROPERTY_UNAVAILABLE;
859 if (action == M_PROPERTY_SET && arg)
860 tmp = *((int *) arg);
861 else
862 tmp = -1;
863 current_id = mpctx->demuxer->audio->id;
864 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
865 if (audio_id == -2
866 || (audio_id > -1
867 && mpctx->demuxer->audio->id != current_id && current_id != -2))
868 uninit_player(INITIALIZED_AO | INITIALIZED_ACODEC);
869 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
870 sh_audio_t *sh2;
871 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
872 if (sh2) {
873 sh2->ds = mpctx->demuxer->audio;
874 mpctx->sh_audio = sh2;
875 reinit_audio_chain();
878 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
879 return M_PROPERTY_OK;
880 default:
881 return M_PROPERTY_NOT_IMPLEMENTED;
886 /// Selected video id (RW)
887 static int mp_property_video(m_option_t * prop, int action, void *arg,
888 MPContext * mpctx)
890 int current_id = -1, tmp;
892 switch (action) {
893 case M_PROPERTY_GET:
894 if (!mpctx->sh_video)
895 return M_PROPERTY_UNAVAILABLE;
896 if (!arg)
897 return M_PROPERTY_ERROR;
898 *(int *) arg = video_id;
899 return M_PROPERTY_OK;
900 case M_PROPERTY_PRINT:
901 if (!mpctx->sh_video)
902 return M_PROPERTY_UNAVAILABLE;
903 if (!arg)
904 return M_PROPERTY_ERROR;
906 if (video_id < 0)
907 *(char **) arg = strdup(MSGTR_Disabled);
908 else {
909 char lang[40] = MSGTR_Unknown;
910 *(char **) arg = malloc(64);
911 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
913 return M_PROPERTY_OK;
915 case M_PROPERTY_STEP_UP:
916 case M_PROPERTY_SET:
917 current_id = mpctx->demuxer->video->id;
918 if (action == M_PROPERTY_SET && arg)
919 tmp = *((int *) arg);
920 else
921 tmp = -1;
922 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
923 if (video_id == -2
924 || (video_id > -1 && mpctx->demuxer->video->id != current_id
925 && current_id != -2))
926 uninit_player(INITIALIZED_VCODEC |
927 (fixed_vo && video_id != -2 ? 0 : INITIALIZED_VO));
928 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
929 sh_video_t *sh2;
930 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
931 if (sh2) {
932 sh2->ds = mpctx->demuxer->video;
933 mpctx->sh_video = sh2;
934 reinit_video_chain();
937 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
938 return M_PROPERTY_OK;
940 default:
941 return M_PROPERTY_NOT_IMPLEMENTED;
945 static int mp_property_program(m_option_t * prop, int action, void *arg,
946 MPContext * mpctx)
948 demux_program_t prog;
950 switch (action) {
951 case M_PROPERTY_STEP_UP:
952 case M_PROPERTY_SET:
953 if (action == M_PROPERTY_SET && arg)
954 prog.progid = *((int *) arg);
955 else
956 prog.progid = -1;
957 if (demux_control
958 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
959 &prog) == DEMUXER_CTRL_NOTIMPL)
960 return M_PROPERTY_ERROR;
962 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
963 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
964 return M_PROPERTY_OK;
966 default:
967 return M_PROPERTY_NOT_IMPLEMENTED;
971 ///@}
973 /// \defgroup VideoProperties Video properties
974 /// \ingroup Properties
975 ///@{
977 /// Fullscreen state (RW)
978 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
979 MPContext * mpctx)
982 if (!mpctx->video_out)
983 return M_PROPERTY_UNAVAILABLE;
985 switch (action) {
986 case M_PROPERTY_SET:
987 if (!arg)
988 return M_PROPERTY_ERROR;
989 M_PROPERTY_CLAMP(prop, *(int *) arg);
990 if (vo_fs == !!*(int *) arg)
991 return M_PROPERTY_OK;
992 case M_PROPERTY_STEP_UP:
993 case M_PROPERTY_STEP_DOWN:
994 #ifdef CONFIG_GUI
995 if (use_gui)
996 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
997 else
998 #endif
999 if (vo_config_count)
1000 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
1001 return M_PROPERTY_OK;
1002 default:
1003 return m_property_flag(prop, action, arg, &vo_fs);
1007 static int mp_property_deinterlace(m_option_t * prop, int action,
1008 void *arg, MPContext * mpctx)
1010 int deinterlace;
1011 vf_instance_t *vf;
1012 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1013 return M_PROPERTY_UNAVAILABLE;
1014 vf = mpctx->sh_video->vfilter;
1015 switch (action) {
1016 case M_PROPERTY_GET:
1017 if (!arg)
1018 return M_PROPERTY_ERROR;
1019 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1020 return M_PROPERTY_OK;
1021 case M_PROPERTY_SET:
1022 if (!arg)
1023 return M_PROPERTY_ERROR;
1024 M_PROPERTY_CLAMP(prop, *(int *) arg);
1025 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1026 return M_PROPERTY_OK;
1027 case M_PROPERTY_STEP_UP:
1028 case M_PROPERTY_STEP_DOWN:
1029 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1030 deinterlace = !deinterlace;
1031 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1032 return M_PROPERTY_OK;
1034 return M_PROPERTY_NOT_IMPLEMENTED;
1037 /// Panscan (RW)
1038 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
1039 MPContext * mpctx)
1042 if (!mpctx->video_out
1043 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1044 return M_PROPERTY_UNAVAILABLE;
1046 switch (action) {
1047 case M_PROPERTY_SET:
1048 if (!arg)
1049 return M_PROPERTY_ERROR;
1050 M_PROPERTY_CLAMP(prop, *(float *) arg);
1051 vo_panscan = *(float *) arg;
1052 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1053 return M_PROPERTY_OK;
1054 case M_PROPERTY_STEP_UP:
1055 case M_PROPERTY_STEP_DOWN:
1056 vo_panscan += (arg ? *(float *) arg : 0.1) *
1057 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1058 if (vo_panscan > 1)
1059 vo_panscan = 1;
1060 else if (vo_panscan < 0)
1061 vo_panscan = 0;
1062 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1063 return M_PROPERTY_OK;
1064 default:
1065 return m_property_float_range(prop, action, arg, &vo_panscan);
1069 /// Helper to set vo flags.
1070 /** \ingroup PropertyImplHelper
1072 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
1073 int vo_ctrl, int *vo_var, MPContext * mpctx)
1076 if (!mpctx->video_out)
1077 return M_PROPERTY_UNAVAILABLE;
1079 switch (action) {
1080 case M_PROPERTY_SET:
1081 if (!arg)
1082 return M_PROPERTY_ERROR;
1083 M_PROPERTY_CLAMP(prop, *(int *) arg);
1084 if (*vo_var == !!*(int *) arg)
1085 return M_PROPERTY_OK;
1086 case M_PROPERTY_STEP_UP:
1087 case M_PROPERTY_STEP_DOWN:
1088 if (vo_config_count)
1089 mpctx->video_out->control(vo_ctrl, 0);
1090 return M_PROPERTY_OK;
1091 default:
1092 return m_property_flag(prop, action, arg, vo_var);
1096 /// Window always on top (RW)
1097 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
1098 MPContext * mpctx)
1100 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
1101 mpctx);
1104 /// Display in the root window (RW)
1105 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
1106 MPContext * mpctx)
1108 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1109 &vo_rootwin, mpctx);
1112 /// Show window borders (RW)
1113 static int mp_property_border(m_option_t * prop, int action, void *arg,
1114 MPContext * mpctx)
1116 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1117 &vo_border, mpctx);
1120 /// Framedropping state (RW)
1121 static int mp_property_framedropping(m_option_t * prop, int action,
1122 void *arg, MPContext * mpctx)
1125 if (!mpctx->sh_video)
1126 return M_PROPERTY_UNAVAILABLE;
1128 switch (action) {
1129 case M_PROPERTY_PRINT:
1130 if (!arg)
1131 return M_PROPERTY_ERROR;
1132 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1133 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1134 MSGTR_Disabled));
1135 return M_PROPERTY_OK;
1136 default:
1137 return m_property_choice(prop, action, arg, &frame_dropping);
1141 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1142 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
1143 MPContext * mpctx)
1145 int *gamma = prop->priv, r, val;
1147 if (!mpctx->sh_video)
1148 return M_PROPERTY_UNAVAILABLE;
1150 if (gamma[0] == 1000) {
1151 gamma[0] = 0;
1152 get_video_colors(mpctx->sh_video, prop->name, gamma);
1155 switch (action) {
1156 case M_PROPERTY_SET:
1157 if (!arg)
1158 return M_PROPERTY_ERROR;
1159 M_PROPERTY_CLAMP(prop, *(int *) arg);
1160 *gamma = *(int *) arg;
1161 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1162 if (r <= 0)
1163 break;
1164 return r;
1165 case M_PROPERTY_GET:
1166 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1167 if (!arg)
1168 return M_PROPERTY_ERROR;
1169 *(int *)arg = val;
1170 return M_PROPERTY_OK;
1172 break;
1173 case M_PROPERTY_STEP_UP:
1174 case M_PROPERTY_STEP_DOWN:
1175 *gamma += (arg ? *(int *) arg : 1) *
1176 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1177 M_PROPERTY_CLAMP(prop, *gamma);
1178 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1179 if (r <= 0)
1180 break;
1181 return r;
1182 default:
1183 return M_PROPERTY_NOT_IMPLEMENTED;
1186 #ifdef CONFIG_TV
1187 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1188 int l = strlen(prop->name);
1189 char tv_prop[3 + l + 1];
1190 sprintf(tv_prop, "tv_%s", prop->name);
1191 return mp_property_do(tv_prop, action, arg, mpctx);
1193 #endif
1195 return M_PROPERTY_UNAVAILABLE;
1198 /// VSync (RW)
1199 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1200 MPContext * mpctx)
1202 return m_property_flag(prop, action, arg, &vo_vsync);
1205 /// Video codec tag (RO)
1206 static int mp_property_video_format(m_option_t * prop, int action,
1207 void *arg, MPContext * mpctx)
1209 char* meta;
1210 if (!mpctx->sh_video)
1211 return M_PROPERTY_UNAVAILABLE;
1212 switch(action) {
1213 case M_PROPERTY_PRINT:
1214 if (!arg)
1215 return M_PROPERTY_ERROR;
1216 switch(mpctx->sh_video->format) {
1217 case 0x10000001:
1218 meta = strdup ("mpeg1"); break;
1219 case 0x10000002:
1220 meta = strdup ("mpeg2"); break;
1221 case 0x10000004:
1222 meta = strdup ("mpeg4"); break;
1223 case 0x10000005:
1224 meta = strdup ("h264"); break;
1225 default:
1226 if(mpctx->sh_video->format >= 0x20202020) {
1227 meta = malloc(5);
1228 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1229 } else {
1230 meta = malloc(20);
1231 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1234 *(char**)arg = meta;
1235 return M_PROPERTY_OK;
1237 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1240 /// Video codec name (RO)
1241 static int mp_property_video_codec(m_option_t * prop, int action,
1242 void *arg, MPContext * mpctx)
1244 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1245 return M_PROPERTY_UNAVAILABLE;
1246 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1250 /// Video bitrate (RO)
1251 static int mp_property_video_bitrate(m_option_t * prop, int action,
1252 void *arg, MPContext * mpctx)
1254 if (!mpctx->sh_video)
1255 return M_PROPERTY_UNAVAILABLE;
1256 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1259 /// Video display width (RO)
1260 static int mp_property_width(m_option_t * prop, int action, void *arg,
1261 MPContext * mpctx)
1263 if (!mpctx->sh_video)
1264 return M_PROPERTY_UNAVAILABLE;
1265 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1268 /// Video display height (RO)
1269 static int mp_property_height(m_option_t * prop, int action, void *arg,
1270 MPContext * mpctx)
1272 if (!mpctx->sh_video)
1273 return M_PROPERTY_UNAVAILABLE;
1274 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1277 /// Video fps (RO)
1278 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1279 MPContext * mpctx)
1281 if (!mpctx->sh_video)
1282 return M_PROPERTY_UNAVAILABLE;
1283 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1286 /// Video aspect (RO)
1287 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1288 MPContext * mpctx)
1290 if (!mpctx->sh_video)
1291 return M_PROPERTY_UNAVAILABLE;
1292 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1295 ///@}
1297 /// \defgroup SubProprties Subtitles properties
1298 /// \ingroup Properties
1299 ///@{
1301 /// Text subtitle position (RW)
1302 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1303 MPContext * mpctx)
1305 if (!mpctx->sh_video)
1306 return M_PROPERTY_UNAVAILABLE;
1308 switch (action) {
1309 case M_PROPERTY_SET:
1310 if (!arg)
1311 return M_PROPERTY_ERROR;
1312 case M_PROPERTY_STEP_UP:
1313 case M_PROPERTY_STEP_DOWN:
1314 vo_osd_changed(OSDTYPE_SUBTITLE);
1315 default:
1316 return m_property_int_range(prop, action, arg, &sub_pos);
1320 /// Selected subtitles (RW)
1321 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1322 MPContext * mpctx)
1324 demux_stream_t *const d_sub = mpctx->d_sub;
1325 const int global_sub_size = mpctx->global_sub_size;
1326 int source = -1, reset_spu = 0;
1327 char *sub_name;
1329 if (global_sub_size <= 0)
1330 return M_PROPERTY_UNAVAILABLE;
1332 switch (action) {
1333 case M_PROPERTY_GET:
1334 if (!arg)
1335 return M_PROPERTY_ERROR;
1336 *(int *) arg = mpctx->global_sub_pos;
1337 return M_PROPERTY_OK;
1338 case M_PROPERTY_PRINT:
1339 if (!arg)
1340 return M_PROPERTY_ERROR;
1341 *(char **) arg = malloc(64);
1342 (*(char **) arg)[63] = 0;
1343 sub_name = 0;
1344 if (subdata)
1345 sub_name = subdata->filename;
1346 #ifdef CONFIG_ASS
1347 if (ass_track && ass_track->name)
1348 sub_name = ass_track->name;
1349 #endif
1350 if (sub_name) {
1351 char *tmp, *tmp2;
1352 tmp = sub_name;
1353 if ((tmp2 = strrchr(tmp, '/')))
1354 tmp = tmp2 + 1;
1356 snprintf(*(char **) arg, 63, "(%d) %s%s",
1357 mpctx->set_of_sub_pos + 1,
1358 strlen(tmp) < 20 ? "" : "...",
1359 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1360 return M_PROPERTY_OK;
1362 #ifdef CONFIG_DVDNAV
1363 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1364 if (vo_spudec && dvdsub_id >= 0) {
1365 unsigned char lang[3];
1366 if (mp_dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1367 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1368 return M_PROPERTY_OK;
1372 #endif
1374 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1375 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1376 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1377 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1378 && d_sub && d_sub->sh && dvdsub_id >= 0) {
1379 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1380 if (!lang) lang = MSGTR_Unknown;
1381 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1382 return M_PROPERTY_OK;
1385 if (vo_vobsub && vobsub_id >= 0) {
1386 const char *language = MSGTR_Unknown;
1387 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1388 snprintf(*(char **) arg, 63, "(%d) %s",
1389 vobsub_id, language ? language : MSGTR_Unknown);
1390 return M_PROPERTY_OK;
1392 #ifdef CONFIG_DVDREAD
1393 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1394 && dvdsub_id >= 0) {
1395 char lang[3];
1396 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1397 lang[0] = code >> 8;
1398 lang[1] = code;
1399 lang[2] = 0;
1400 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1401 return M_PROPERTY_OK;
1403 #endif
1404 if (dvdsub_id >= 0) {
1405 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1406 return M_PROPERTY_OK;
1408 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1409 return M_PROPERTY_OK;
1411 case M_PROPERTY_SET:
1412 if (!arg)
1413 return M_PROPERTY_ERROR;
1414 if (*(int *) arg < -1)
1415 *(int *) arg = -1;
1416 else if (*(int *) arg >= global_sub_size)
1417 *(int *) arg = global_sub_size - 1;
1418 mpctx->global_sub_pos = *(int *) arg;
1419 break;
1420 case M_PROPERTY_STEP_UP:
1421 mpctx->global_sub_pos += 2;
1422 mpctx->global_sub_pos =
1423 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1424 break;
1425 case M_PROPERTY_STEP_DOWN:
1426 mpctx->global_sub_pos += global_sub_size + 1;
1427 mpctx->global_sub_pos =
1428 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1429 break;
1430 default:
1431 return M_PROPERTY_NOT_IMPLEMENTED;
1434 if (mpctx->global_sub_pos >= 0)
1435 source = sub_source(mpctx);
1437 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1438 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1439 global_sub_size,
1440 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1441 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1442 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1443 mpctx->global_sub_pos, source);
1445 mpctx->set_of_sub_pos = -1;
1446 subdata = NULL;
1448 vobsub_id = -1;
1449 dvdsub_id = -1;
1450 if (d_sub) {
1451 if (d_sub->id > -2)
1452 reset_spu = 1;
1453 d_sub->id = -2;
1455 #ifdef CONFIG_ASS
1456 ass_track = 0;
1457 #endif
1459 if (source == SUB_SOURCE_VOBSUB) {
1460 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1461 } else if (source == SUB_SOURCE_SUBS) {
1462 mpctx->set_of_sub_pos =
1463 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1464 #ifdef CONFIG_ASS
1465 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1466 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1467 else
1468 #endif
1470 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1471 vo_osd_changed(OSDTYPE_SUBTITLE);
1473 } else if (source == SUB_SOURCE_DEMUX) {
1474 dvdsub_id =
1475 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1476 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1477 int i = 0;
1478 // default: assume 1:1 mapping of sid and stream id
1479 d_sub->id = dvdsub_id;
1480 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1481 ds_free_packs(d_sub);
1482 for (i = 0; i < MAX_S_STREAMS; i++) {
1483 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1484 if (sh && sh->sid == dvdsub_id) {
1485 d_sub->id = i;
1486 d_sub->sh = sh;
1487 break;
1490 if (d_sub->sh && d_sub->id >= 0) {
1491 sh_sub_t *sh = d_sub->sh;
1492 if (sh->type == 'v')
1493 init_vo_spudec();
1494 #ifdef CONFIG_ASS
1495 else if (ass_enabled)
1496 ass_track = sh->ass_track;
1497 #endif
1498 } else {
1499 d_sub->id = -2;
1500 d_sub->sh = NULL;
1504 #ifdef CONFIG_DVDREAD
1505 if (vo_spudec
1506 && (mpctx->stream->type == STREAMTYPE_DVD
1507 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1508 && dvdsub_id < 0 && reset_spu) {
1509 dvdsub_id = -2;
1510 d_sub->id = dvdsub_id;
1512 #endif
1513 update_subtitles(mpctx->sh_video, d_sub, 1);
1515 return M_PROPERTY_OK;
1518 /// Selected sub source (RW)
1519 static int mp_property_sub_source(m_option_t * prop, int action, void *arg,
1520 MPContext * mpctx)
1522 int source;
1523 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1524 return M_PROPERTY_UNAVAILABLE;
1526 switch (action) {
1527 case M_PROPERTY_GET:
1528 if (!arg)
1529 return M_PROPERTY_ERROR;
1530 *(int *) arg = sub_source(mpctx);
1531 return M_PROPERTY_OK;
1532 case M_PROPERTY_PRINT:
1533 if (!arg)
1534 return M_PROPERTY_ERROR;
1535 *(char **) arg = malloc(64);
1536 (*(char **) arg)[63] = 0;
1537 switch (sub_source(mpctx))
1539 case SUB_SOURCE_SUBS:
1540 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1541 break;
1542 case SUB_SOURCE_VOBSUB:
1543 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1544 break;
1545 case SUB_SOURCE_DEMUX:
1546 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1547 break;
1548 default:
1549 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1551 return M_PROPERTY_OK;
1552 case M_PROPERTY_SET:
1553 if (!arg)
1554 return M_PROPERTY_ERROR;
1555 M_PROPERTY_CLAMP(prop, *(int*)arg);
1556 if (*(int *) arg < 0)
1557 mpctx->global_sub_pos = -1;
1558 else if (*(int *) arg != sub_source(mpctx)) {
1559 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1560 return M_PROPERTY_UNAVAILABLE;
1561 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1563 break;
1564 case M_PROPERTY_STEP_UP:
1565 case M_PROPERTY_STEP_DOWN: {
1566 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1567 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1568 int step = (step_all > 0) ? 1 : -1;
1569 int cur_source = sub_source(mpctx);
1570 source = cur_source;
1571 while (step_all) {
1572 source += step;
1573 if (source >= SUB_SOURCES)
1574 source = -1;
1575 else if (source < -1)
1576 source = SUB_SOURCES - 1;
1577 if (source == cur_source || source == -1 ||
1578 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1579 step_all -= step;
1581 if (source == cur_source)
1582 return M_PROPERTY_OK;
1583 if (source == -1)
1584 mpctx->global_sub_pos = -1;
1585 else
1586 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1587 break;
1589 default:
1590 return M_PROPERTY_NOT_IMPLEMENTED;
1592 --mpctx->global_sub_pos;
1593 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1596 /// Selected subtitles from specific source (RW)
1597 static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg,
1598 MPContext * mpctx)
1600 int source, is_cur_source, offset;
1601 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1602 return M_PROPERTY_UNAVAILABLE;
1604 if (!strcmp(prop->name, "sub_file"))
1605 source = SUB_SOURCE_SUBS;
1606 else if (!strcmp(prop->name, "sub_vob"))
1607 source = SUB_SOURCE_VOBSUB;
1608 else if (!strcmp(prop->name, "sub_demux"))
1609 source = SUB_SOURCE_DEMUX;
1610 else
1611 return M_PROPERTY_ERROR;
1613 offset = mpctx->global_sub_indices[source];
1614 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1615 return M_PROPERTY_UNAVAILABLE;
1617 is_cur_source = sub_source(mpctx) == source;
1618 switch (action) {
1619 case M_PROPERTY_GET:
1620 if (!arg)
1621 return M_PROPERTY_ERROR;
1622 if (is_cur_source) {
1623 *(int *) arg = mpctx->global_sub_pos - offset;
1624 if (source == SUB_SOURCE_VOBSUB)
1625 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1627 else
1628 *(int *) arg = -1;
1629 return M_PROPERTY_OK;
1630 case M_PROPERTY_PRINT:
1631 if (!arg)
1632 return M_PROPERTY_ERROR;
1633 if (is_cur_source)
1634 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1635 *(char **) arg = malloc(64);
1636 (*(char **) arg)[63] = 0;
1637 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1638 return M_PROPERTY_OK;
1639 case M_PROPERTY_SET:
1640 if (!arg)
1641 return M_PROPERTY_ERROR;
1642 if (*(int *) arg >= 0) {
1643 int index = *(int *)arg;
1644 if (source == SUB_SOURCE_VOBSUB)
1645 index = vobsub_get_index_by_id(vo_vobsub, index);
1646 mpctx->global_sub_pos = offset + index;
1647 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1648 || sub_source(mpctx) != source) {
1649 mpctx->global_sub_pos = -1;
1650 *(int *) arg = -1;
1653 else
1654 mpctx->global_sub_pos = -1;
1655 break;
1656 case M_PROPERTY_STEP_UP:
1657 case M_PROPERTY_STEP_DOWN: {
1658 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1659 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1660 int step = (step_all > 0) ? 1 : -1;
1661 int max_sub_pos_for_source = -1;
1662 if (!is_cur_source)
1663 mpctx->global_sub_pos = -1;
1664 while (step_all) {
1665 if (mpctx->global_sub_pos == -1) {
1666 if (step > 0)
1667 mpctx->global_sub_pos = offset;
1668 else if (max_sub_pos_for_source == -1) {
1669 // Find max pos for specific source
1670 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1671 while (mpctx->global_sub_pos >= 0
1672 && sub_source(mpctx) != source)
1673 --mpctx->global_sub_pos;
1675 else
1676 mpctx->global_sub_pos = max_sub_pos_for_source;
1678 else {
1679 mpctx->global_sub_pos += step;
1680 if (mpctx->global_sub_pos < offset ||
1681 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1682 sub_source(mpctx) != source)
1683 mpctx->global_sub_pos = -1;
1685 step_all -= step;
1687 break;
1689 default:
1690 return M_PROPERTY_NOT_IMPLEMENTED;
1692 --mpctx->global_sub_pos;
1693 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1696 /// Subtitle delay (RW)
1697 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1698 MPContext * mpctx)
1700 if (!mpctx->sh_video)
1701 return M_PROPERTY_UNAVAILABLE;
1702 return m_property_delay(prop, action, arg, &sub_delay);
1705 /// Alignment of text subtitles (RW)
1706 static int mp_property_sub_alignment(m_option_t * prop, int action,
1707 void *arg, MPContext * mpctx)
1709 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1711 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1712 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1713 return M_PROPERTY_UNAVAILABLE;
1715 switch (action) {
1716 case M_PROPERTY_PRINT:
1717 if (!arg)
1718 return M_PROPERTY_ERROR;
1719 M_PROPERTY_CLAMP(prop, sub_alignment);
1720 *(char **) arg = strdup(name[sub_alignment]);
1721 return M_PROPERTY_OK;
1722 case M_PROPERTY_SET:
1723 if (!arg)
1724 return M_PROPERTY_ERROR;
1725 case M_PROPERTY_STEP_UP:
1726 case M_PROPERTY_STEP_DOWN:
1727 vo_osd_changed(OSDTYPE_SUBTITLE);
1728 default:
1729 return m_property_choice(prop, action, arg, &sub_alignment);
1733 /// Subtitle visibility (RW)
1734 static int mp_property_sub_visibility(m_option_t * prop, int action,
1735 void *arg, MPContext * mpctx)
1737 if (!mpctx->sh_video)
1738 return M_PROPERTY_UNAVAILABLE;
1740 switch (action) {
1741 case M_PROPERTY_SET:
1742 if (!arg)
1743 return M_PROPERTY_ERROR;
1744 case M_PROPERTY_STEP_UP:
1745 case M_PROPERTY_STEP_DOWN:
1746 vo_osd_changed(OSDTYPE_SUBTITLE);
1747 if (vo_spudec)
1748 vo_osd_changed(OSDTYPE_SPU);
1749 default:
1750 return m_property_flag(prop, action, arg, &sub_visibility);
1754 #ifdef CONFIG_ASS
1755 /// Use margins for libass subtitles (RW)
1756 static int mp_property_ass_use_margins(m_option_t * prop, int action,
1757 void *arg, MPContext * mpctx)
1759 if (!mpctx->sh_video)
1760 return M_PROPERTY_UNAVAILABLE;
1762 switch (action) {
1763 case M_PROPERTY_SET:
1764 if (!arg)
1765 return M_PROPERTY_ERROR;
1766 case M_PROPERTY_STEP_UP:
1767 case M_PROPERTY_STEP_DOWN:
1768 ass_force_reload = 1;
1769 default:
1770 return m_property_flag(prop, action, arg, &ass_use_margins);
1773 #endif
1775 /// Show only forced subtitles (RW)
1776 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1777 void *arg, MPContext * mpctx)
1779 if (!vo_spudec)
1780 return M_PROPERTY_UNAVAILABLE;
1782 switch (action) {
1783 case M_PROPERTY_SET:
1784 if (!arg)
1785 return M_PROPERTY_ERROR;
1786 case M_PROPERTY_STEP_UP:
1787 case M_PROPERTY_STEP_DOWN:
1788 m_property_flag(prop, action, arg, &forced_subs_only);
1789 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1790 return M_PROPERTY_OK;
1791 default:
1792 return m_property_flag(prop, action, arg, &forced_subs_only);
1797 #ifdef CONFIG_FREETYPE
1798 /// Subtitle scale (RW)
1799 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1800 MPContext * mpctx)
1803 switch (action) {
1804 case M_PROPERTY_SET:
1805 if (!arg)
1806 return M_PROPERTY_ERROR;
1807 M_PROPERTY_CLAMP(prop, *(float *) arg);
1808 #ifdef CONFIG_ASS
1809 if (ass_enabled) {
1810 ass_font_scale = *(float *) arg;
1811 ass_force_reload = 1;
1813 #endif
1814 text_font_scale_factor = *(float *) arg;
1815 force_load_font = 1;
1816 return M_PROPERTY_OK;
1817 case M_PROPERTY_STEP_UP:
1818 case M_PROPERTY_STEP_DOWN:
1819 #ifdef CONFIG_ASS
1820 if (ass_enabled) {
1821 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1822 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1823 M_PROPERTY_CLAMP(prop, ass_font_scale);
1824 ass_force_reload = 1;
1826 #endif
1827 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1828 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1829 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1830 force_load_font = 1;
1831 return M_PROPERTY_OK;
1832 default:
1833 #ifdef CONFIG_ASS
1834 if (ass_enabled)
1835 return m_property_float_ro(prop, action, arg, ass_font_scale);
1836 else
1837 #endif
1838 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1841 #endif
1843 ///@}
1845 /// \defgroup TVProperties TV properties
1846 /// \ingroup Properties
1847 ///@{
1849 #ifdef CONFIG_TV
1851 /// TV color settings (RW)
1852 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1853 MPContext * mpctx)
1855 int r, val;
1856 tvi_handle_t *tvh = mpctx->demuxer->priv;
1857 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1858 return M_PROPERTY_UNAVAILABLE;
1860 switch (action) {
1861 case M_PROPERTY_SET:
1862 if (!arg)
1863 return M_PROPERTY_ERROR;
1864 M_PROPERTY_CLAMP(prop, *(int *) arg);
1865 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1866 case M_PROPERTY_GET:
1867 return tv_get_color_options(tvh, (int) prop->priv, arg);
1868 case M_PROPERTY_STEP_UP:
1869 case M_PROPERTY_STEP_DOWN:
1870 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1871 if (!r)
1872 return M_PROPERTY_ERROR;
1873 val += (arg ? *(int *) arg : 1) *
1874 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1875 M_PROPERTY_CLAMP(prop, val);
1876 return tv_set_color_options(tvh, (int) prop->priv, val);
1878 return M_PROPERTY_ERROR;
1880 return M_PROPERTY_NOT_IMPLEMENTED;
1883 #endif
1885 #ifdef CONFIG_TV_TELETEXT
1886 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1887 MPContext * mpctx)
1889 int val,result;
1890 int base_ioctl=(int)prop->priv;
1892 for teletext's GET,SET,STEP ioctls this is not 0
1893 SET is GET+1
1894 STEP is GET+2
1896 tvi_handle_t *tvh = mpctx->demuxer->priv;
1897 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1898 return M_PROPERTY_UNAVAILABLE;
1899 if(!base_ioctl)
1900 return M_PROPERTY_ERROR;
1902 switch (action) {
1903 case M_PROPERTY_GET:
1904 if (!arg)
1905 return M_PROPERTY_ERROR;
1906 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1907 break;
1908 case M_PROPERTY_SET:
1909 if (!arg)
1910 return M_PROPERTY_ERROR;
1911 M_PROPERTY_CLAMP(prop, *(int *) arg);
1912 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1913 break;
1914 case M_PROPERTY_STEP_UP:
1915 case M_PROPERTY_STEP_DOWN:
1916 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1917 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1918 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1919 break;
1920 default:
1921 return M_PROPERTY_NOT_IMPLEMENTED;
1924 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1927 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1928 MPContext * mpctx)
1930 tvi_handle_t *tvh = mpctx->demuxer->priv;
1931 int result;
1932 int val;
1934 //with tvh==NULL will fail too
1935 result=mp_property_teletext_common(prop,action,arg,mpctx);
1936 if(result!=M_PROPERTY_OK)
1937 return result;
1939 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1940 mp_input_set_section("teletext");
1941 else
1942 mp_input_set_section("tv");
1943 return M_PROPERTY_OK;
1946 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1947 MPContext * mpctx)
1949 tvi_handle_t *tvh = mpctx->demuxer->priv;
1950 int result;
1951 int val;
1952 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1953 return M_PROPERTY_UNAVAILABLE;
1954 switch(action){
1955 case M_PROPERTY_STEP_UP:
1956 case M_PROPERTY_STEP_DOWN:
1957 //This should be handled separately
1958 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1959 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1960 break;
1961 default:
1962 result=mp_property_teletext_common(prop,action,arg,mpctx);
1964 return result;
1968 #endif /* CONFIG_TV_TELETEXT */
1970 ///@}
1972 /// All properties available in MPlayer.
1973 /** \ingroup Properties
1975 static const m_option_t mp_properties[] = {
1976 // General
1977 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1978 M_OPT_RANGE, 0, 3, NULL },
1979 { "loop", mp_property_loop, CONF_TYPE_INT,
1980 M_OPT_MIN, -1, 0, NULL },
1981 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1982 M_OPT_RANGE, 0.01, 100.0, NULL },
1983 { "filename", mp_property_filename, CONF_TYPE_STRING,
1984 0, 0, 0, NULL },
1985 { "path", mp_property_path, CONF_TYPE_STRING,
1986 0, 0, 0, NULL },
1987 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1988 0, 0, 0, NULL },
1989 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1990 M_OPT_MIN, 0, 0, NULL },
1991 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1992 M_OPT_MIN, 0, 0, NULL },
1993 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1994 M_OPT_MIN, 0, 0, NULL },
1995 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1996 M_OPT_MIN, 0, 0, NULL },
1997 { "length", mp_property_length, CONF_TYPE_TIME,
1998 M_OPT_MIN, 0, 0, NULL },
1999 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2000 M_OPT_RANGE, 0, 100, NULL },
2001 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2002 M_OPT_MIN, 0, 0, NULL },
2003 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2004 M_OPT_MIN, 0, 0, NULL },
2005 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2006 0, 0, 0, NULL },
2007 { "angle", mp_property_angle, CONF_TYPE_INT,
2008 CONF_RANGE, -2, 10, NULL },
2009 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2010 0, 0, 0, NULL },
2011 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2012 M_OPT_RANGE, 0, 1, NULL },
2014 // Audio
2015 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2016 M_OPT_RANGE, 0, 100, NULL },
2017 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2018 M_OPT_RANGE, 0, 1, NULL },
2019 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2020 M_OPT_RANGE, -100, 100, NULL },
2021 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2022 0, 0, 0, NULL },
2023 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2024 0, 0, 0, NULL },
2025 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2026 0, 0, 0, NULL },
2027 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2028 0, 0, 0, NULL },
2029 { "channels", mp_property_channels, CONF_TYPE_INT,
2030 0, 0, 0, NULL },
2031 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2032 CONF_RANGE, -2, 65535, NULL },
2033 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2034 M_OPT_RANGE, -1, 1, NULL },
2036 // Video
2037 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2038 M_OPT_RANGE, 0, 1, NULL },
2039 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2040 M_OPT_RANGE, 0, 1, NULL },
2041 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2042 M_OPT_RANGE, 0, 1, NULL },
2043 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2044 M_OPT_RANGE, 0, 1, NULL },
2045 { "border", mp_property_border, CONF_TYPE_FLAG,
2046 M_OPT_RANGE, 0, 1, NULL },
2047 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2048 M_OPT_RANGE, 0, 2, NULL },
2049 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2050 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2051 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2052 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2053 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2054 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2055 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2056 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2057 { "hue", mp_property_gamma, CONF_TYPE_INT,
2058 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2059 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2060 M_OPT_RANGE, 0, 1, NULL },
2061 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2062 M_OPT_RANGE, 0, 1, NULL },
2063 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2064 0, 0, 0, NULL },
2065 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2066 0, 0, 0, NULL },
2067 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2068 0, 0, 0, NULL },
2069 { "width", mp_property_width, CONF_TYPE_INT,
2070 0, 0, 0, NULL },
2071 { "height", mp_property_height, CONF_TYPE_INT,
2072 0, 0, 0, NULL },
2073 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2074 0, 0, 0, NULL },
2075 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2076 0, 0, 0, NULL },
2077 { "switch_video", mp_property_video, CONF_TYPE_INT,
2078 CONF_RANGE, -2, 65535, NULL },
2079 { "switch_program", mp_property_program, CONF_TYPE_INT,
2080 CONF_RANGE, -1, 65535, NULL },
2082 // Subs
2083 { "sub", mp_property_sub, CONF_TYPE_INT,
2084 M_OPT_MIN, -1, 0, NULL },
2085 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2086 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2087 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2088 M_OPT_MIN, -1, 0, NULL },
2089 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2090 M_OPT_MIN, -1, 0, NULL },
2091 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2092 M_OPT_MIN, -1, 0, NULL },
2093 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2094 0, 0, 0, NULL },
2095 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2096 M_OPT_RANGE, 0, 100, NULL },
2097 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2098 M_OPT_RANGE, 0, 2, NULL },
2099 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2100 M_OPT_RANGE, 0, 1, NULL },
2101 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2102 M_OPT_RANGE, 0, 1, NULL },
2103 #ifdef CONFIG_FREETYPE
2104 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2105 M_OPT_RANGE, 0, 100, NULL },
2106 #endif
2107 #ifdef CONFIG_ASS
2108 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2109 M_OPT_RANGE, 0, 1, NULL },
2110 #endif
2112 #ifdef CONFIG_TV
2113 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2114 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2115 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2116 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2117 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2118 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2119 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2120 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2121 #endif
2123 #ifdef CONFIG_TV_TELETEXT
2124 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2125 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2126 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2127 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2128 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2129 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2130 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2131 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2132 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2133 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2134 #endif
2136 { NULL, NULL, NULL, 0, 0, 0, NULL }
2140 int mp_property_do(const char *name, int action, void *val, void *ctx)
2142 return m_property_do(mp_properties, name, action, val, ctx);
2145 char* mp_property_print(const char *name, void* ctx)
2147 char* ret = NULL;
2148 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2149 return NULL;
2150 return ret;
2153 char *property_expand_string(MPContext * mpctx, char *str)
2155 return m_properties_expand_string(mp_properties, str, mpctx);
2158 void property_print_help(void)
2160 m_properties_print_help_list(mp_properties);
2164 ///@}
2165 // Properties group
2169 * \defgroup Command2Property Command to property bridge
2171 * It is used to handle most commands that just set a property
2172 * and optionally display something on the OSD.
2173 * Two kinds of commands are handled: adjust or toggle.
2175 * Adjust commands take 1 or 2 parameters: <value> <abs>
2176 * If <abs> is non-zero the property is set to the given value
2177 * otherwise it is adjusted.
2179 * Toggle commands take 0 or 1 parameters. With no parameter
2180 * or a value less than the property minimum it just steps the
2181 * property to its next value. Otherwise it sets it to the given
2182 * value.
2187 /// List of the commands that can be handled by setting a property.
2188 static struct {
2189 /// property name
2190 const char *name;
2191 /// cmd id
2192 int cmd;
2193 /// set/adjust or toggle command
2194 int toggle;
2195 /// progressbar type
2196 int osd_progbar;
2197 /// osd msg id if it must be shared
2198 int osd_id;
2199 /// osd msg template
2200 const char *osd_msg;
2201 } set_prop_cmd[] = {
2202 // general
2203 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2204 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2205 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2206 // audio
2207 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2208 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2209 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2210 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2211 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2212 // video
2213 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2214 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2215 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2216 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2217 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2218 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2219 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2220 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2221 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2222 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2223 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2224 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2225 // subs
2226 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2227 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2228 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2229 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2230 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2231 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2232 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2233 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2234 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2235 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2236 #ifdef CONFIG_FREETYPE
2237 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2238 #endif
2239 #ifdef CONFIG_ASS
2240 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2241 #endif
2242 #ifdef CONFIG_TV
2243 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2244 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2245 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2246 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2247 #endif
2248 { NULL, 0, 0, 0, -1, NULL }
2252 /// Handle commands that set a property.
2253 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
2255 int i, r;
2256 m_option_t* prop;
2257 const char *pname;
2259 // look for the command
2260 for (i = 0; set_prop_cmd[i].name; i++)
2261 if (set_prop_cmd[i].cmd == cmd->id)
2262 break;
2263 if (!(pname = set_prop_cmd[i].name))
2264 return 0;
2266 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2267 return 0;
2269 // toggle command
2270 if (set_prop_cmd[i].toggle) {
2271 // set to value
2272 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2273 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2274 else
2275 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2276 } else if (cmd->args[1].v.i) //set
2277 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2278 else // adjust
2279 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2281 if (r <= 0)
2282 return 1;
2284 if (set_prop_cmd[i].osd_progbar) {
2285 if (prop->type == CONF_TYPE_INT) {
2286 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2287 set_osd_bar(set_prop_cmd[i].osd_progbar,
2288 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2289 } else if (prop->type == CONF_TYPE_FLOAT) {
2290 float f;
2291 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2292 set_osd_bar(set_prop_cmd[i].osd_progbar,
2293 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2294 } else
2295 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2296 "Property use an unsupported type.\n");
2297 return 1;
2300 if (set_prop_cmd[i].osd_msg) {
2301 char *val = mp_property_print(pname, mpctx);
2302 if (val) {
2303 set_osd_msg(set_prop_cmd[i].osd_id >=
2304 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2305 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2306 free(val);
2309 return 1;
2312 #ifdef CONFIG_DVDNAV
2313 static const struct {
2314 const char *name;
2315 const mp_command_type cmd;
2316 } mp_dvdnav_bindings[] = {
2317 { "up", MP_CMD_DVDNAV_UP },
2318 { "down", MP_CMD_DVDNAV_DOWN },
2319 { "left", MP_CMD_DVDNAV_LEFT },
2320 { "right", MP_CMD_DVDNAV_RIGHT },
2321 { "menu", MP_CMD_DVDNAV_MENU },
2322 { "select", MP_CMD_DVDNAV_SELECT },
2323 { "prev", MP_CMD_DVDNAV_PREVMENU },
2324 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2327 * keep old dvdnav sub-command options for a while in order not to
2328 * break slave-mode API too suddenly.
2330 { "1", MP_CMD_DVDNAV_UP },
2331 { "2", MP_CMD_DVDNAV_DOWN },
2332 { "3", MP_CMD_DVDNAV_LEFT },
2333 { "4", MP_CMD_DVDNAV_RIGHT },
2334 { "5", MP_CMD_DVDNAV_MENU },
2335 { "6", MP_CMD_DVDNAV_SELECT },
2336 { "7", MP_CMD_DVDNAV_PREVMENU },
2337 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2338 { NULL, 0 }
2340 #endif
2342 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
2344 sh_audio_t * const sh_audio = mpctx->sh_audio;
2345 sh_video_t * const sh_video = mpctx->sh_video;
2346 int brk_cmd = 0;
2347 if (!set_property_command(mpctx, cmd))
2348 switch (cmd->id) {
2349 case MP_CMD_SEEK:{
2350 float v;
2351 int abs;
2352 if (sh_video)
2353 mpctx->osd_show_percentage = sh_video->fps;
2354 v = cmd->args[0].v.f;
2355 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2356 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2357 abs_seek_pos = SEEK_ABSOLUTE;
2358 if (sh_video)
2359 mpctx->osd_function =
2360 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2361 rel_seek_secs = v;
2362 } else if (abs) { /* Absolute seek by percentage */
2363 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2364 if (sh_video)
2365 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2366 rel_seek_secs = v / 100.0;
2367 } else {
2368 rel_seek_secs += v;
2369 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2371 brk_cmd = 1;
2373 break;
2375 case MP_CMD_SET_PROPERTY:{
2376 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2377 cmd->args[1].v.s, mpctx);
2378 if (r == M_PROPERTY_UNKNOWN)
2379 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2380 "Unknown property: '%s'\n", cmd->args[0].v.s);
2381 else if (r <= 0)
2382 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2383 "Failed to set property '%s' to '%s'.\n",
2384 cmd->args[0].v.s, cmd->args[1].v.s);
2386 break;
2388 case MP_CMD_STEP_PROPERTY:{
2389 void* arg = NULL;
2390 int r,i;
2391 double d;
2392 off_t o;
2393 if (cmd->args[1].v.f) {
2394 m_option_t* prop;
2395 if((r = mp_property_do(cmd->args[0].v.s,
2396 M_PROPERTY_GET_TYPE,
2397 &prop, mpctx)) <= 0)
2398 goto step_prop_err;
2399 if(prop->type == CONF_TYPE_INT ||
2400 prop->type == CONF_TYPE_FLAG)
2401 i = cmd->args[1].v.f, arg = &i;
2402 else if(prop->type == CONF_TYPE_FLOAT)
2403 arg = &cmd->args[1].v.f;
2404 else if(prop->type == CONF_TYPE_DOUBLE ||
2405 prop->type == CONF_TYPE_TIME)
2406 d = cmd->args[1].v.f, arg = &d;
2407 else if(prop->type == CONF_TYPE_POSITION)
2408 o = cmd->args[1].v.f, arg = &o;
2409 else
2410 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2411 "Ignoring step size stepping property '%s'.\n",
2412 cmd->args[0].v.s);
2414 r = mp_property_do(cmd->args[0].v.s,
2415 cmd->args[2].v.i < 0 ?
2416 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2417 arg, mpctx);
2418 step_prop_err:
2419 if (r == M_PROPERTY_UNKNOWN)
2420 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2421 "Unknown property: '%s'\n", cmd->args[0].v.s);
2422 else if (r <= 0)
2423 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2424 "Failed to increment property '%s' by %f.\n",
2425 cmd->args[0].v.s, cmd->args[1].v.f);
2427 break;
2429 case MP_CMD_GET_PROPERTY:{
2430 char *tmp;
2431 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2432 &tmp, mpctx) <= 0) {
2433 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2434 "Failed to get value of property '%s'.\n",
2435 cmd->args[0].v.s);
2436 break;
2438 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2439 cmd->args[0].v.s, tmp);
2440 free(tmp);
2442 break;
2444 case MP_CMD_EDL_MARK:
2445 if (edl_fd) {
2446 float v = sh_video ? sh_video->pts :
2447 playing_audio_pts(sh_audio, mpctx->d_audio,
2448 mpctx->audio_out);
2450 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2451 mpctx->begin_skip = v;
2452 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2453 } else {
2454 if (mpctx->begin_skip > v)
2455 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2456 else {
2457 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2458 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2460 mpctx->begin_skip = MP_NOPTS_VALUE;
2463 break;
2465 case MP_CMD_SWITCH_RATIO:
2466 if (!sh_video)
2467 break;
2468 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2469 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2470 else
2471 movie_aspect = cmd->args[0].v.f;
2472 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2473 break;
2475 case MP_CMD_SPEED_INCR:{
2476 float v = cmd->args[0].v.f;
2477 playback_speed += v;
2478 build_afilter_chain(sh_audio, &ao_data);
2479 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2480 playback_speed);
2481 } break;
2483 case MP_CMD_SPEED_MULT:{
2484 float v = cmd->args[0].v.f;
2485 playback_speed *= v;
2486 build_afilter_chain(sh_audio, &ao_data);
2487 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2488 playback_speed);
2489 } break;
2491 case MP_CMD_SPEED_SET:{
2492 float v = cmd->args[0].v.f;
2493 playback_speed = v;
2494 build_afilter_chain(sh_audio, &ao_data);
2495 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2496 playback_speed);
2497 } break;
2499 case MP_CMD_FRAME_STEP:
2500 case MP_CMD_PAUSE:
2501 cmd->pausing = 1;
2502 brk_cmd = 1;
2503 break;
2505 case MP_CMD_FILE_FILTER:
2506 file_filter = cmd->args[0].v.i;
2507 break;
2509 case MP_CMD_QUIT:
2510 exit_player_with_rc(EXIT_QUIT,
2511 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2513 case MP_CMD_PLAY_TREE_STEP:{
2514 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2515 int force = cmd->args[1].v.i;
2517 #ifdef CONFIG_GUI
2518 if (use_gui) {
2519 int i = 0;
2520 if (n > 0)
2521 for (i = 0; i < n; i++)
2522 mplNext();
2523 else
2524 for (i = 0; i < -1 * n; i++)
2525 mplPrev();
2526 } else
2527 #endif
2529 if (!force && mpctx->playtree_iter) {
2530 play_tree_iter_t *i =
2531 play_tree_iter_new_copy(mpctx->playtree_iter);
2532 if (play_tree_iter_step(i, n, 0) ==
2533 PLAY_TREE_ITER_ENTRY)
2534 mpctx->eof =
2535 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2536 play_tree_iter_free(i);
2537 } else
2538 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2539 if (mpctx->eof)
2540 mpctx->play_tree_step = n;
2541 brk_cmd = 1;
2544 break;
2546 case MP_CMD_PLAY_TREE_UP_STEP:{
2547 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2548 int force = cmd->args[1].v.i;
2550 if (!force && mpctx->playtree_iter) {
2551 play_tree_iter_t *i =
2552 play_tree_iter_new_copy(mpctx->playtree_iter);
2553 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2554 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2555 play_tree_iter_free(i);
2556 } else
2557 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2558 brk_cmd = 1;
2560 break;
2562 case MP_CMD_PLAY_ALT_SRC_STEP:
2563 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2564 int v = cmd->args[0].v.i;
2565 if (v > 0
2566 && mpctx->playtree_iter->file <
2567 mpctx->playtree_iter->num_files)
2568 mpctx->eof = PT_NEXT_SRC;
2569 else if (v < 0 && mpctx->playtree_iter->file > 1)
2570 mpctx->eof = PT_PREV_SRC;
2572 brk_cmd = 1;
2573 break;
2575 case MP_CMD_SUB_STEP:
2576 if (sh_video) {
2577 int movement = cmd->args[0].v.i;
2578 step_sub(subdata, sh_video->pts, movement);
2579 #ifdef CONFIG_ASS
2580 if (ass_track)
2581 sub_delay +=
2582 ass_step_sub(ass_track,
2583 (sh_video->pts +
2584 sub_delay) * 1000 + .5, movement) / 1000.;
2585 #endif
2586 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2587 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2589 break;
2591 case MP_CMD_SUB_LOG:
2592 log_sub();
2593 break;
2595 case MP_CMD_OSD:{
2596 int v = cmd->args[0].v.i;
2597 int max = (term_osd
2598 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2599 if (osd_level > max)
2600 osd_level = max;
2601 if (v < 0)
2602 osd_level = (osd_level + 1) % (max + 1);
2603 else
2604 osd_level = v > max ? max : v;
2605 /* Show OSD state when disabled, but not when an explicit
2606 argument is given to the OSD command, i.e. in slave mode. */
2607 if (v == -1 && osd_level <= 1)
2608 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2609 MSGTR_OSDosd,
2610 osd_level ? MSGTR_OSDenabled :
2611 MSGTR_OSDdisabled);
2612 else
2613 rm_osd_msg(OSD_MSG_OSD_STATUS);
2615 break;
2617 case MP_CMD_OSD_SHOW_TEXT:
2618 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2619 (cmd->args[1].v.i <
2620 0 ? osd_duration : cmd->args[1].v.i),
2621 "%-.63s", cmd->args[0].v.s);
2622 break;
2624 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2625 char *txt = m_properties_expand_string(mp_properties,
2626 cmd->args[0].v.s,
2627 mpctx);
2628 /* if no argument supplied take default osd_duration, else <arg> ms. */
2629 if (txt) {
2630 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2631 (cmd->args[1].v.i <
2632 0 ? osd_duration : cmd->args[1].v.i),
2633 "%-.63s", txt);
2634 free(txt);
2637 break;
2639 case MP_CMD_LOADFILE:{
2640 play_tree_t *e = play_tree_new();
2641 play_tree_add_file(e, cmd->args[0].v.s);
2643 if (cmd->args[1].v.i) // append
2644 play_tree_append_entry(mpctx->playtree->child, e);
2645 else {
2646 // Go back to the starting point.
2647 while (play_tree_iter_up_step
2648 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2649 /* NOP */ ;
2650 play_tree_free_list(mpctx->playtree->child, 1);
2651 play_tree_set_child(mpctx->playtree, e);
2652 pt_iter_goto_head(mpctx->playtree_iter);
2653 mpctx->eof = PT_NEXT_SRC;
2655 brk_cmd = 1;
2657 break;
2659 case MP_CMD_LOADLIST:{
2660 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2661 if (!e)
2662 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2663 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2664 else {
2665 if (cmd->args[1].v.i) // append
2666 play_tree_append_entry(mpctx->playtree->child, e);
2667 else {
2668 // Go back to the starting point.
2669 while (play_tree_iter_up_step
2670 (mpctx->playtree_iter, 0, 1)
2671 != PLAY_TREE_ITER_END)
2672 /* NOP */ ;
2673 play_tree_free_list(mpctx->playtree->child, 1);
2674 play_tree_set_child(mpctx->playtree, e);
2675 pt_iter_goto_head(mpctx->playtree_iter);
2676 mpctx->eof = PT_NEXT_SRC;
2679 brk_cmd = 1;
2681 break;
2683 case MP_CMD_STOP:
2684 // Go back to the starting point.
2685 while (play_tree_iter_up_step
2686 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2687 /* NOP */ ;
2688 mpctx->eof = PT_STOP;
2689 brk_cmd = 1;
2690 break;
2692 #ifdef CONFIG_RADIO
2693 case MP_CMD_RADIO_STEP_CHANNEL:
2694 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2695 int v = cmd->args[0].v.i;
2696 if (v > 0)
2697 radio_step_channel(mpctx->demuxer->stream,
2698 RADIO_CHANNEL_HIGHER);
2699 else
2700 radio_step_channel(mpctx->demuxer->stream,
2701 RADIO_CHANNEL_LOWER);
2702 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2703 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2704 MSGTR_OSDChannel,
2705 radio_get_channel_name(mpctx->demuxer->stream));
2708 break;
2710 case MP_CMD_RADIO_SET_CHANNEL:
2711 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2712 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2713 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2714 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2715 MSGTR_OSDChannel,
2716 radio_get_channel_name(mpctx->demuxer->stream));
2719 break;
2721 case MP_CMD_RADIO_SET_FREQ:
2722 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2723 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2724 break;
2726 case MP_CMD_RADIO_STEP_FREQ:
2727 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2728 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2729 break;
2730 #endif
2732 #ifdef CONFIG_TV
2733 case MP_CMD_TV_START_SCAN:
2734 if (mpctx->file_format == DEMUXER_TYPE_TV)
2735 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2736 break;
2737 case MP_CMD_TV_SET_FREQ:
2738 if (mpctx->file_format == DEMUXER_TYPE_TV)
2739 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2740 cmd->args[0].v.f * 16.0);
2741 #ifdef CONFIG_PVR
2742 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2743 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2744 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2745 pvr_get_current_channelname (mpctx->stream),
2746 pvr_get_current_stationname (mpctx->stream));
2748 #endif /* CONFIG_PVR */
2749 break;
2751 case MP_CMD_TV_STEP_FREQ:
2752 if (mpctx->file_format == DEMUXER_TYPE_TV)
2753 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2754 cmd->args[0].v.f * 16.0);
2755 #ifdef CONFIG_PVR
2756 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2757 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2758 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2759 pvr_get_current_channelname (mpctx->stream),
2760 pvr_get_current_frequency (mpctx->stream));
2762 #endif /* CONFIG_PVR */
2763 break;
2765 case MP_CMD_TV_SET_NORM:
2766 if (mpctx->file_format == DEMUXER_TYPE_TV)
2767 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2768 cmd->args[0].v.s);
2769 break;
2771 case MP_CMD_TV_STEP_CHANNEL:{
2772 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2773 int v = cmd->args[0].v.i;
2774 if (v > 0) {
2775 tv_step_channel((tvi_handle_t *) (mpctx->
2776 demuxer->priv),
2777 TV_CHANNEL_HIGHER);
2778 } else {
2779 tv_step_channel((tvi_handle_t *) (mpctx->
2780 demuxer->priv),
2781 TV_CHANNEL_LOWER);
2783 if (tv_channel_list) {
2784 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2785 MSGTR_OSDChannel, tv_channel_current->name);
2786 //vo_osd_changed(OSDTYPE_SUBTITLE);
2789 #ifdef CONFIG_PVR
2790 else if (mpctx->stream &&
2791 mpctx->stream->type == STREAMTYPE_PVR) {
2792 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2793 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2794 pvr_get_current_channelname (mpctx->stream),
2795 pvr_get_current_stationname (mpctx->stream));
2797 #endif /* CONFIG_PVR */
2799 #ifdef CONFIG_DVBIN
2800 if (mpctx->stream->type == STREAMTYPE_DVB) {
2801 int dir;
2802 int v = cmd->args[0].v.i;
2804 mpctx->last_dvb_step = v;
2805 if (v > 0)
2806 dir = DVB_CHANNEL_HIGHER;
2807 else
2808 dir = DVB_CHANNEL_LOWER;
2811 if (dvb_step_channel(mpctx->stream, dir))
2812 mpctx->eof = mpctx->dvbin_reopen = 1;
2814 #endif /* CONFIG_DVBIN */
2815 break;
2817 case MP_CMD_TV_SET_CHANNEL:
2818 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2819 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2820 cmd->args[0].v.s);
2821 if (tv_channel_list) {
2822 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2823 MSGTR_OSDChannel, tv_channel_current->name);
2824 //vo_osd_changed(OSDTYPE_SUBTITLE);
2827 #ifdef CONFIG_PVR
2828 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2829 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2830 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2831 pvr_get_current_channelname (mpctx->stream),
2832 pvr_get_current_stationname (mpctx->stream));
2834 #endif /* CONFIG_PVR */
2835 break;
2837 #ifdef CONFIG_DVBIN
2838 case MP_CMD_DVB_SET_CHANNEL:
2839 if (mpctx->stream->type == STREAMTYPE_DVB) {
2840 mpctx->last_dvb_step = 1;
2842 if (dvb_set_channel
2843 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2844 mpctx->eof = mpctx->dvbin_reopen = 1;
2846 break;
2847 #endif /* CONFIG_DVBIN */
2849 case MP_CMD_TV_LAST_CHANNEL:
2850 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2851 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2852 if (tv_channel_list) {
2853 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2854 MSGTR_OSDChannel, tv_channel_current->name);
2855 //vo_osd_changed(OSDTYPE_SUBTITLE);
2858 #ifdef CONFIG_PVR
2859 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2860 pvr_set_lastchannel (mpctx->stream);
2861 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2862 pvr_get_current_channelname (mpctx->stream),
2863 pvr_get_current_stationname (mpctx->stream));
2865 #endif /* CONFIG_PVR */
2866 break;
2868 case MP_CMD_TV_STEP_NORM:
2869 if (mpctx->file_format == DEMUXER_TYPE_TV)
2870 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2871 break;
2873 case MP_CMD_TV_STEP_CHANNEL_LIST:
2874 if (mpctx->file_format == DEMUXER_TYPE_TV)
2875 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2876 break;
2877 #ifdef CONFIG_TV_TELETEXT
2878 case MP_CMD_TV_TELETEXT_ADD_DEC:
2880 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2881 if (mpctx->file_format == DEMUXER_TYPE_TV)
2882 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2883 break;
2885 case MP_CMD_TV_TELETEXT_GO_LINK:
2887 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2888 if (mpctx->file_format == DEMUXER_TYPE_TV)
2889 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2890 break;
2892 #endif /* CONFIG_TV_TELETEXT */
2893 #endif /* CONFIG_TV */
2895 case MP_CMD_SUB_LOAD:
2896 if (sh_video) {
2897 int n = mpctx->set_of_sub_size;
2898 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2899 if (n != mpctx->set_of_sub_size) {
2900 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2901 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2902 mpctx->global_sub_size;
2903 ++mpctx->global_sub_size;
2906 break;
2908 case MP_CMD_SUB_REMOVE:
2909 if (sh_video) {
2910 int v = cmd->args[0].v.i;
2911 sub_data *subd;
2912 if (v < 0) {
2913 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2914 subd = mpctx->set_of_subtitles[v];
2915 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2916 MSGTR_RemovedSubtitleFile, v + 1,
2917 filename_recode(subd->filename));
2918 sub_free(subd);
2919 mpctx->set_of_subtitles[v] = NULL;
2921 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2922 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2923 mpctx->set_of_sub_size = 0;
2924 if (mpctx->set_of_sub_pos >= 0) {
2925 mpctx->global_sub_pos = -2;
2926 subdata = NULL;
2927 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2929 } else if (v < mpctx->set_of_sub_size) {
2930 subd = mpctx->set_of_subtitles[v];
2931 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2932 MSGTR_RemovedSubtitleFile, v + 1,
2933 filename_recode(subd->filename));
2934 sub_free(subd);
2935 if (mpctx->set_of_sub_pos == v) {
2936 mpctx->global_sub_pos = -2;
2937 subdata = NULL;
2938 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2939 } else if (mpctx->set_of_sub_pos > v) {
2940 --mpctx->set_of_sub_pos;
2941 --mpctx->global_sub_pos;
2943 while (++v < mpctx->set_of_sub_size)
2944 mpctx->set_of_subtitles[v - 1] =
2945 mpctx->set_of_subtitles[v];
2946 --mpctx->set_of_sub_size;
2947 --mpctx->global_sub_size;
2948 if (mpctx->set_of_sub_size <= 0)
2949 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2950 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2953 break;
2955 case MP_CMD_GET_SUB_VISIBILITY:
2956 if (sh_video) {
2957 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2958 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2960 break;
2962 case MP_CMD_SCREENSHOT:
2963 if (vo_config_count) {
2964 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2965 if (CONTROL_OK !=
2966 ((vf_instance_t *) sh_video->vfilter)->
2967 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2968 &cmd->args[0].v.i))
2969 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2971 break;
2973 case MP_CMD_VF_CHANGE_RECTANGLE:
2974 if (!sh_video)
2975 break;
2976 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2977 break;
2979 case MP_CMD_GET_TIME_LENGTH:{
2980 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2981 demuxer_get_time_length(mpctx->demuxer));
2983 break;
2985 case MP_CMD_GET_FILENAME:{
2986 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2987 get_metadata(META_NAME));
2989 break;
2991 case MP_CMD_GET_VIDEO_CODEC:{
2992 char *inf = get_metadata(META_VIDEO_CODEC);
2993 if (!inf)
2994 inf = strdup("");
2995 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2996 free(inf);
2998 break;
3000 case MP_CMD_GET_VIDEO_BITRATE:{
3001 char *inf = get_metadata(META_VIDEO_BITRATE);
3002 if (!inf)
3003 inf = strdup("");
3004 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3005 free(inf);
3007 break;
3009 case MP_CMD_GET_VIDEO_RESOLUTION:{
3010 char *inf = get_metadata(META_VIDEO_RESOLUTION);
3011 if (!inf)
3012 inf = strdup("");
3013 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3014 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3015 free(inf);
3017 break;
3019 case MP_CMD_GET_AUDIO_CODEC:{
3020 char *inf = get_metadata(META_AUDIO_CODEC);
3021 if (!inf)
3022 inf = strdup("");
3023 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3024 free(inf);
3026 break;
3028 case MP_CMD_GET_AUDIO_BITRATE:{
3029 char *inf = get_metadata(META_AUDIO_BITRATE);
3030 if (!inf)
3031 inf = strdup("");
3032 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3033 free(inf);
3035 break;
3037 case MP_CMD_GET_AUDIO_SAMPLES:{
3038 char *inf = get_metadata(META_AUDIO_SAMPLES);
3039 if (!inf)
3040 inf = strdup("");
3041 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3042 free(inf);
3044 break;
3046 case MP_CMD_GET_META_TITLE:{
3047 char *inf = get_metadata(META_INFO_TITLE);
3048 if (!inf)
3049 inf = strdup("");
3050 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3051 free(inf);
3053 break;
3055 case MP_CMD_GET_META_ARTIST:{
3056 char *inf = get_metadata(META_INFO_ARTIST);
3057 if (!inf)
3058 inf = strdup("");
3059 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3060 free(inf);
3062 break;
3064 case MP_CMD_GET_META_ALBUM:{
3065 char *inf = get_metadata(META_INFO_ALBUM);
3066 if (!inf)
3067 inf = strdup("");
3068 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3069 free(inf);
3071 break;
3073 case MP_CMD_GET_META_YEAR:{
3074 char *inf = get_metadata(META_INFO_YEAR);
3075 if (!inf)
3076 inf = strdup("");
3077 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3078 free(inf);
3080 break;
3082 case MP_CMD_GET_META_COMMENT:{
3083 char *inf = get_metadata(META_INFO_COMMENT);
3084 if (!inf)
3085 inf = strdup("");
3086 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3087 free(inf);
3089 break;
3091 case MP_CMD_GET_META_TRACK:{
3092 char *inf = get_metadata(META_INFO_TRACK);
3093 if (!inf)
3094 inf = strdup("");
3095 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3096 free(inf);
3098 break;
3100 case MP_CMD_GET_META_GENRE:{
3101 char *inf = get_metadata(META_INFO_GENRE);
3102 if (!inf)
3103 inf = strdup("");
3104 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3105 free(inf);
3107 break;
3109 case MP_CMD_GET_VO_FULLSCREEN:
3110 if (mpctx->video_out && vo_config_count)
3111 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3112 break;
3114 case MP_CMD_GET_PERCENT_POS:
3115 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3116 demuxer_get_percent_pos(mpctx->demuxer));
3117 break;
3119 case MP_CMD_GET_TIME_POS:{
3120 float pos = 0;
3121 if (sh_video)
3122 pos = sh_video->pts;
3123 else if (sh_audio && mpctx->audio_out)
3124 pos =
3125 playing_audio_pts(sh_audio, mpctx->d_audio,
3126 mpctx->audio_out);
3127 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3129 break;
3131 case MP_CMD_RUN:
3132 #ifndef __MINGW32__
3133 if (!fork()) {
3134 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3135 exit(0);
3137 #endif
3138 break;
3140 case MP_CMD_KEYDOWN_EVENTS:
3141 mplayer_put_key(cmd->args[0].v.i);
3142 break;
3144 case MP_CMD_SET_MOUSE_POS:{
3145 int pointer_x, pointer_y;
3146 double dx, dy;
3147 pointer_x = cmd->args[0].v.i;
3148 pointer_y = cmd->args[1].v.i;
3149 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
3150 #ifdef CONFIG_DVDNAV
3151 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3152 && dx > 0.0 && dy > 0.0) {
3153 int button = -1;
3154 pointer_x = (int) (dx * (double) sh_video->disp_w);
3155 pointer_y = (int) (dy * (double) sh_video->disp_h);
3156 mp_dvdnav_update_mouse_pos(mpctx->stream,
3157 pointer_x, pointer_y, &button);
3158 if (osd_level > 1 && button > 0)
3159 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3160 "Selected button number %d", button);
3162 #endif
3163 #ifdef CONFIG_MENU
3164 if (use_menu && dx >= 0.0 && dy >= 0.0)
3165 menu_update_mouse_pos(dx, dy);
3166 #endif
3168 break;
3170 #ifdef CONFIG_DVDNAV
3171 case MP_CMD_DVDNAV:{
3172 int button = -1;
3173 int i;
3174 mp_command_type command = 0;
3175 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3176 break;
3178 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3179 if (cmd->args[0].v.s &&
3180 !strcasecmp (cmd->args[0].v.s,
3181 mp_dvdnav_bindings[i].name))
3182 command = mp_dvdnav_bindings[i].cmd;
3184 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3185 if (osd_level > 1 && button > 0)
3186 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3187 "Selected button number %d", button);
3189 break;
3191 case MP_CMD_SWITCH_TITLE:
3192 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3193 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3194 break;
3196 #endif
3198 default:
3199 #ifdef CONFIG_GUI
3200 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3201 guiGetEvent(guiIEvent, (char *) cmd->id);
3202 else
3203 #endif
3204 mp_msg(MSGT_CPLAYER, MSGL_V,
3205 "Received unknown cmd %s\n", cmd->name);
3208 switch (cmd->pausing) {
3209 case 1: // "pausing"
3210 mpctx->osd_function = OSD_PAUSE;
3211 break;
3212 case 3: // "pausing_toggle"
3213 mpctx->was_paused = !mpctx->was_paused;
3214 if (mpctx->was_paused)
3215 mpctx->osd_function = OSD_PAUSE;
3216 else if (mpctx->osd_function == OSD_PAUSE)
3217 mpctx->osd_function = OSD_PLAY;
3218 break;
3219 case 2: // "pausing_keep"
3220 if (mpctx->was_paused)
3221 mpctx->osd_function = OSD_PAUSE;
3223 return brk_cmd;