Remove workaround for rgb/bgr mess.
[mplayer/greg.git] / command.c
blobe5b17abafe343f798a734bcb289da627d72a4787
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 + 1);
413 chapter += step_all;
414 break;
415 case M_PROPERTY_STEP_UP:
416 case M_PROPERTY_STEP_DOWN: {
417 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
418 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
419 chapter += step_all;
420 if (chapter < 0)
421 chapter = 0;
422 break;
424 default:
425 return M_PROPERTY_NOT_IMPLEMENTED;
427 rel_seek_secs = 0;
428 abs_seek_pos = 0;
429 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
430 &next_pts, &chapter_num, &chapter_name);
431 if (chapter >= 0) {
432 if (next_pts > -1.0) {
433 abs_seek_pos = SEEK_ABSOLUTE;
434 rel_seek_secs = next_pts;
436 if (chapter_name)
437 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
438 MSGTR_OSDChapter, chapter + 1, chapter_name);
440 else if (step_all > 0)
441 rel_seek_secs = 1000000000.;
442 else
443 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
444 MSGTR_OSDChapter, 0, MSGTR_Unknown);
445 if (chapter_name)
446 free(chapter_name);
447 return M_PROPERTY_OK;
450 /// Current dvd angle (RW)
451 static int mp_property_angle(m_option_t *prop, int action, void *arg,
452 MPContext *mpctx)
454 int angle = -1;
455 int angles;
456 char *angle_name = NULL;
458 if (mpctx->demuxer)
459 angle = demuxer_get_current_angle(mpctx->demuxer);
460 if (angle < 0)
461 return M_PROPERTY_UNAVAILABLE;
462 angles = demuxer_angles_count(mpctx->demuxer);
463 if (angles <= 1)
464 return M_PROPERTY_UNAVAILABLE;
466 switch (action) {
467 case M_PROPERTY_GET:
468 if (!arg)
469 return M_PROPERTY_ERROR;
470 *(int *) arg = angle;
471 return M_PROPERTY_OK;
472 case M_PROPERTY_PRINT: {
473 if (!arg)
474 return M_PROPERTY_ERROR;
475 angle_name = calloc(1, 64);
476 if (!angle_name)
477 return M_PROPERTY_UNAVAILABLE;
478 snprintf(angle_name, 64, "%d/%d", angle, angles);
479 *(char **) arg = angle_name;
480 return M_PROPERTY_OK;
482 case M_PROPERTY_SET:
483 if (!arg)
484 return M_PROPERTY_ERROR;
485 angle = *(int *)arg;
486 M_PROPERTY_CLAMP(prop, angle);
487 break;
488 case M_PROPERTY_STEP_UP:
489 case M_PROPERTY_STEP_DOWN: {
490 int step = 0;
491 if(arg)
492 step = *(int*)arg;
493 if(!step)
494 step = 1;
495 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
496 angle += step;
497 if (angle < 1) //cycle
498 angle = angles;
499 break;
501 default:
502 return M_PROPERTY_NOT_IMPLEMENTED;
504 angle = demuxer_set_angle(mpctx->demuxer, angle);
505 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
506 MSGTR_OSDAngle, angle, angles);
507 if (angle_name)
508 free(angle_name);
509 return M_PROPERTY_OK;
512 /// Demuxer meta data
513 static int mp_property_metadata(m_option_t * prop, int action, void *arg,
514 MPContext * mpctx) {
515 m_property_action_t* ka;
516 char* meta;
517 static m_option_t key_type =
518 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
519 if (!mpctx->demuxer)
520 return M_PROPERTY_UNAVAILABLE;
522 switch(action) {
523 case M_PROPERTY_GET:
524 if(!arg) return M_PROPERTY_ERROR;
525 *(char***)arg = mpctx->demuxer->info;
526 return M_PROPERTY_OK;
527 case M_PROPERTY_KEY_ACTION:
528 if(!arg) return M_PROPERTY_ERROR;
529 ka = arg;
530 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
531 return M_PROPERTY_UNKNOWN;
532 switch(ka->action) {
533 case M_PROPERTY_GET:
534 if(!ka->arg) return M_PROPERTY_ERROR;
535 *(char**)ka->arg = meta;
536 return M_PROPERTY_OK;
537 case M_PROPERTY_GET_TYPE:
538 if(!ka->arg) return M_PROPERTY_ERROR;
539 *(m_option_t**)ka->arg = &key_type;
540 return M_PROPERTY_OK;
543 return M_PROPERTY_NOT_IMPLEMENTED;
547 ///@}
549 /// \defgroup AudioProperties Audio properties
550 /// \ingroup Properties
551 ///@{
553 /// Volume (RW)
554 static int mp_property_volume(m_option_t * prop, int action, void *arg,
555 MPContext * mpctx)
558 if (!mpctx->sh_audio)
559 return M_PROPERTY_UNAVAILABLE;
561 switch (action) {
562 case M_PROPERTY_GET:
563 if (!arg)
564 return M_PROPERTY_ERROR;
565 mixer_getbothvolume(&mpctx->mixer, arg);
566 return M_PROPERTY_OK;
567 case M_PROPERTY_PRINT:{
568 float vol;
569 if (!arg)
570 return M_PROPERTY_ERROR;
571 mixer_getbothvolume(&mpctx->mixer, &vol);
572 return m_property_float_range(prop, action, arg, &vol);
574 case M_PROPERTY_STEP_UP:
575 case M_PROPERTY_STEP_DOWN:
576 case M_PROPERTY_SET:
577 break;
578 default:
579 return M_PROPERTY_NOT_IMPLEMENTED;
582 if (mpctx->edl_muted)
583 return M_PROPERTY_DISABLED;
584 mpctx->user_muted = 0;
586 switch (action) {
587 case M_PROPERTY_SET:
588 if (!arg)
589 return M_PROPERTY_ERROR;
590 M_PROPERTY_CLAMP(prop, *(float *) arg);
591 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
592 return M_PROPERTY_OK;
593 case M_PROPERTY_STEP_UP:
594 if (arg && *(float *) arg <= 0)
595 mixer_decvolume(&mpctx->mixer);
596 else
597 mixer_incvolume(&mpctx->mixer);
598 return M_PROPERTY_OK;
599 case M_PROPERTY_STEP_DOWN:
600 if (arg && *(float *) arg <= 0)
601 mixer_incvolume(&mpctx->mixer);
602 else
603 mixer_decvolume(&mpctx->mixer);
604 return M_PROPERTY_OK;
606 return M_PROPERTY_NOT_IMPLEMENTED;
609 /// Mute (RW)
610 static int mp_property_mute(m_option_t * prop, int action, void *arg,
611 MPContext * mpctx)
614 if (!mpctx->sh_audio)
615 return M_PROPERTY_UNAVAILABLE;
617 switch (action) {
618 case M_PROPERTY_SET:
619 if (mpctx->edl_muted)
620 return M_PROPERTY_DISABLED;
621 if (!arg)
622 return M_PROPERTY_ERROR;
623 if ((!!*(int *) arg) != mpctx->mixer.muted)
624 mixer_mute(&mpctx->mixer);
625 mpctx->user_muted = mpctx->mixer.muted;
626 return M_PROPERTY_OK;
627 case M_PROPERTY_STEP_UP:
628 case M_PROPERTY_STEP_DOWN:
629 if (mpctx->edl_muted)
630 return M_PROPERTY_DISABLED;
631 mixer_mute(&mpctx->mixer);
632 mpctx->user_muted = mpctx->mixer.muted;
633 return M_PROPERTY_OK;
634 case M_PROPERTY_PRINT:
635 if (!arg)
636 return M_PROPERTY_ERROR;
637 if (mpctx->edl_muted) {
638 *(char **) arg = strdup(MSGTR_EnabledEdl);
639 return M_PROPERTY_OK;
641 default:
642 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
647 /// Audio delay (RW)
648 static int mp_property_audio_delay(m_option_t * prop, int action,
649 void *arg, MPContext * mpctx)
651 if (!(mpctx->sh_audio && mpctx->sh_video))
652 return M_PROPERTY_UNAVAILABLE;
653 switch (action) {
654 case M_PROPERTY_SET:
655 case M_PROPERTY_STEP_UP:
656 case M_PROPERTY_STEP_DOWN: {
657 int ret;
658 float delay = audio_delay;
659 ret = m_property_delay(prop, action, arg, &audio_delay);
660 if (ret != M_PROPERTY_OK)
661 return ret;
662 if (mpctx->sh_audio)
663 mpctx->delay -= audio_delay - delay;
665 return M_PROPERTY_OK;
666 default:
667 return m_property_delay(prop, action, arg, &audio_delay);
671 /// Audio codec tag (RO)
672 static int mp_property_audio_format(m_option_t * prop, int action,
673 void *arg, MPContext * mpctx)
675 if (!mpctx->sh_audio)
676 return M_PROPERTY_UNAVAILABLE;
677 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
680 /// Audio codec name (RO)
681 static int mp_property_audio_codec(m_option_t * prop, int action,
682 void *arg, MPContext * mpctx)
684 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
685 return M_PROPERTY_UNAVAILABLE;
686 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
689 /// Audio bitrate (RO)
690 static int mp_property_audio_bitrate(m_option_t * prop, int action,
691 void *arg, MPContext * mpctx)
693 if (!mpctx->sh_audio)
694 return M_PROPERTY_UNAVAILABLE;
695 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
698 /// Samplerate (RO)
699 static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
700 MPContext * mpctx)
702 if (!mpctx->sh_audio)
703 return M_PROPERTY_UNAVAILABLE;
704 switch(action) {
705 case M_PROPERTY_PRINT:
706 if(!arg) return M_PROPERTY_ERROR;
707 *(char**)arg = malloc(16);
708 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
709 return M_PROPERTY_OK;
711 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
714 /// Number of channels (RO)
715 static int mp_property_channels(m_option_t * prop, int action, void *arg,
716 MPContext * mpctx)
718 if (!mpctx->sh_audio)
719 return M_PROPERTY_UNAVAILABLE;
720 switch (action) {
721 case M_PROPERTY_PRINT:
722 if (!arg)
723 return M_PROPERTY_ERROR;
724 switch (mpctx->sh_audio->channels) {
725 case 1:
726 *(char **) arg = strdup("mono");
727 break;
728 case 2:
729 *(char **) arg = strdup("stereo");
730 break;
731 default:
732 *(char **) arg = malloc(32);
733 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
735 return M_PROPERTY_OK;
737 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
740 /// Balance (RW)
741 static int mp_property_balance(m_option_t * prop, int action, void *arg,
742 MPContext * mpctx)
744 float bal;
746 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
747 return M_PROPERTY_UNAVAILABLE;
749 switch (action) {
750 case M_PROPERTY_GET:
751 if (!arg)
752 return M_PROPERTY_ERROR;
753 mixer_getbalance(&mpctx->mixer, arg);
754 return M_PROPERTY_OK;
755 case M_PROPERTY_PRINT: {
756 char** str = arg;
757 if (!arg)
758 return M_PROPERTY_ERROR;
759 mixer_getbalance(&mpctx->mixer, &bal);
760 if (bal == 0.f)
761 *str = strdup("center");
762 else if (bal == -1.f)
763 *str = strdup("left only");
764 else if (bal == 1.f)
765 *str = strdup("right only");
766 else {
767 unsigned right = (bal + 1.f) / 2.f * 100.f;
768 *str = malloc(sizeof("left xxx%, right xxx%"));
769 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
771 return M_PROPERTY_OK;
773 case M_PROPERTY_STEP_UP:
774 case M_PROPERTY_STEP_DOWN:
775 mixer_getbalance(&mpctx->mixer, &bal);
776 bal += (arg ? *(float*)arg : .1f) *
777 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
778 M_PROPERTY_CLAMP(prop, bal);
779 mixer_setbalance(&mpctx->mixer, bal);
780 return M_PROPERTY_OK;
781 case M_PROPERTY_SET:
782 if (!arg)
783 return M_PROPERTY_ERROR;
784 M_PROPERTY_CLAMP(prop, *(float*)arg);
785 mixer_setbalance(&mpctx->mixer, *(float*)arg);
786 return M_PROPERTY_OK;
788 return M_PROPERTY_NOT_IMPLEMENTED;
791 /// Selected audio id (RW)
792 static int mp_property_audio(m_option_t * prop, int action, void *arg,
793 MPContext * mpctx)
795 int current_id = -1, tmp;
797 switch (action) {
798 case M_PROPERTY_GET:
799 if (!mpctx->sh_audio)
800 return M_PROPERTY_UNAVAILABLE;
801 if (!arg)
802 return M_PROPERTY_ERROR;
803 *(int *) arg = audio_id;
804 return M_PROPERTY_OK;
805 case M_PROPERTY_PRINT:
806 if (!mpctx->sh_audio)
807 return M_PROPERTY_UNAVAILABLE;
808 if (!arg)
809 return M_PROPERTY_ERROR;
811 if (audio_id < 0)
812 *(char **) arg = strdup(MSGTR_Disabled);
813 else {
814 char lang[40] = MSGTR_Unknown;
815 sh_audio_t* sh = mpctx->sh_audio;
816 if (sh && sh->lang)
817 av_strlcpy(lang, sh->lang, 40);
818 #ifdef CONFIG_DVDREAD
819 else if (mpctx->stream->type == STREAMTYPE_DVD) {
820 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
821 if (code) {
822 lang[0] = code >> 8;
823 lang[1] = code;
824 lang[2] = 0;
827 #endif
829 #ifdef CONFIG_DVDNAV
830 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
831 mp_dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
832 #endif
833 *(char **) arg = malloc(64);
834 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
836 return M_PROPERTY_OK;
838 case M_PROPERTY_STEP_UP:
839 case M_PROPERTY_SET:
840 if (!mpctx->demuxer)
841 return M_PROPERTY_UNAVAILABLE;
842 if (action == M_PROPERTY_SET && arg)
843 tmp = *((int *) arg);
844 else
845 tmp = -1;
846 current_id = mpctx->demuxer->audio->id;
847 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
848 if (audio_id == -2
849 || (audio_id > -1
850 && mpctx->demuxer->audio->id != current_id && current_id != -2))
851 uninit_player(INITIALIZED_AO | INITIALIZED_ACODEC);
852 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
853 sh_audio_t *sh2;
854 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
855 if (sh2) {
856 sh2->ds = mpctx->demuxer->audio;
857 mpctx->sh_audio = sh2;
858 reinit_audio_chain();
861 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
862 return M_PROPERTY_OK;
863 default:
864 return M_PROPERTY_NOT_IMPLEMENTED;
869 /// Selected video id (RW)
870 static int mp_property_video(m_option_t * prop, int action, void *arg,
871 MPContext * mpctx)
873 int current_id = -1, tmp;
875 switch (action) {
876 case M_PROPERTY_GET:
877 if (!mpctx->sh_video)
878 return M_PROPERTY_UNAVAILABLE;
879 if (!arg)
880 return M_PROPERTY_ERROR;
881 *(int *) arg = video_id;
882 return M_PROPERTY_OK;
883 case M_PROPERTY_PRINT:
884 if (!mpctx->sh_video)
885 return M_PROPERTY_UNAVAILABLE;
886 if (!arg)
887 return M_PROPERTY_ERROR;
889 if (video_id < 0)
890 *(char **) arg = strdup(MSGTR_Disabled);
891 else {
892 char lang[40] = MSGTR_Unknown;
893 *(char **) arg = malloc(64);
894 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
896 return M_PROPERTY_OK;
898 case M_PROPERTY_STEP_UP:
899 case M_PROPERTY_SET:
900 current_id = mpctx->demuxer->video->id;
901 if (action == M_PROPERTY_SET && arg)
902 tmp = *((int *) arg);
903 else
904 tmp = -1;
905 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
906 if (video_id == -2
907 || (video_id > -1 && mpctx->demuxer->video->id != current_id
908 && current_id != -2))
909 uninit_player(INITIALIZED_VCODEC |
910 (fixed_vo && video_id != -2 ? 0 : INITIALIZED_VO));
911 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
912 sh_video_t *sh2;
913 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
914 if (sh2) {
915 sh2->ds = mpctx->demuxer->video;
916 mpctx->sh_video = sh2;
917 reinit_video_chain();
920 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
921 return M_PROPERTY_OK;
923 default:
924 return M_PROPERTY_NOT_IMPLEMENTED;
928 static int mp_property_program(m_option_t * prop, int action, void *arg,
929 MPContext * mpctx)
931 demux_program_t prog;
933 switch (action) {
934 case M_PROPERTY_STEP_UP:
935 case M_PROPERTY_SET:
936 if (action == M_PROPERTY_SET && arg)
937 prog.progid = *((int *) arg);
938 else
939 prog.progid = -1;
940 if (demux_control
941 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
942 &prog) == DEMUXER_CTRL_NOTIMPL)
943 return M_PROPERTY_ERROR;
945 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
946 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
947 return M_PROPERTY_OK;
949 default:
950 return M_PROPERTY_NOT_IMPLEMENTED;
954 ///@}
956 /// \defgroup VideoProperties Video properties
957 /// \ingroup Properties
958 ///@{
960 /// Fullscreen state (RW)
961 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
962 MPContext * mpctx)
965 if (!mpctx->video_out)
966 return M_PROPERTY_UNAVAILABLE;
968 switch (action) {
969 case M_PROPERTY_SET:
970 if (!arg)
971 return M_PROPERTY_ERROR;
972 M_PROPERTY_CLAMP(prop, *(int *) arg);
973 if (vo_fs == !!*(int *) arg)
974 return M_PROPERTY_OK;
975 case M_PROPERTY_STEP_UP:
976 case M_PROPERTY_STEP_DOWN:
977 #ifdef CONFIG_GUI
978 if (use_gui)
979 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
980 else
981 #endif
982 if (vo_config_count)
983 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
984 return M_PROPERTY_OK;
985 default:
986 return m_property_flag(prop, action, arg, &vo_fs);
990 static int mp_property_deinterlace(m_option_t * prop, int action,
991 void *arg, MPContext * mpctx)
993 int deinterlace;
994 vf_instance_t *vf;
995 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
996 return M_PROPERTY_UNAVAILABLE;
997 vf = mpctx->sh_video->vfilter;
998 switch (action) {
999 case M_PROPERTY_GET:
1000 if (!arg)
1001 return M_PROPERTY_ERROR;
1002 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1003 return M_PROPERTY_OK;
1004 case M_PROPERTY_SET:
1005 if (!arg)
1006 return M_PROPERTY_ERROR;
1007 M_PROPERTY_CLAMP(prop, *(int *) arg);
1008 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1009 return M_PROPERTY_OK;
1010 case M_PROPERTY_STEP_UP:
1011 case M_PROPERTY_STEP_DOWN:
1012 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1013 deinterlace = !deinterlace;
1014 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1015 return M_PROPERTY_OK;
1017 return M_PROPERTY_NOT_IMPLEMENTED;
1020 /// Panscan (RW)
1021 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
1022 MPContext * mpctx)
1025 if (!mpctx->video_out
1026 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1027 return M_PROPERTY_UNAVAILABLE;
1029 switch (action) {
1030 case M_PROPERTY_SET:
1031 if (!arg)
1032 return M_PROPERTY_ERROR;
1033 M_PROPERTY_CLAMP(prop, *(float *) arg);
1034 vo_panscan = *(float *) arg;
1035 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1036 return M_PROPERTY_OK;
1037 case M_PROPERTY_STEP_UP:
1038 case M_PROPERTY_STEP_DOWN:
1039 vo_panscan += (arg ? *(float *) arg : 0.1) *
1040 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1041 if (vo_panscan > 1)
1042 vo_panscan = 1;
1043 else if (vo_panscan < 0)
1044 vo_panscan = 0;
1045 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1046 return M_PROPERTY_OK;
1047 default:
1048 return m_property_float_range(prop, action, arg, &vo_panscan);
1052 /// Helper to set vo flags.
1053 /** \ingroup PropertyImplHelper
1055 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
1056 int vo_ctrl, int *vo_var, MPContext * mpctx)
1059 if (!mpctx->video_out)
1060 return M_PROPERTY_UNAVAILABLE;
1062 switch (action) {
1063 case M_PROPERTY_SET:
1064 if (!arg)
1065 return M_PROPERTY_ERROR;
1066 M_PROPERTY_CLAMP(prop, *(int *) arg);
1067 if (*vo_var == !!*(int *) arg)
1068 return M_PROPERTY_OK;
1069 case M_PROPERTY_STEP_UP:
1070 case M_PROPERTY_STEP_DOWN:
1071 if (vo_config_count)
1072 mpctx->video_out->control(vo_ctrl, 0);
1073 return M_PROPERTY_OK;
1074 default:
1075 return m_property_flag(prop, action, arg, vo_var);
1079 /// Window always on top (RW)
1080 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
1081 MPContext * mpctx)
1083 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
1084 mpctx);
1087 /// Display in the root window (RW)
1088 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
1089 MPContext * mpctx)
1091 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1092 &vo_rootwin, mpctx);
1095 /// Show window borders (RW)
1096 static int mp_property_border(m_option_t * prop, int action, void *arg,
1097 MPContext * mpctx)
1099 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1100 &vo_border, mpctx);
1103 /// Framedropping state (RW)
1104 static int mp_property_framedropping(m_option_t * prop, int action,
1105 void *arg, MPContext * mpctx)
1108 if (!mpctx->sh_video)
1109 return M_PROPERTY_UNAVAILABLE;
1111 switch (action) {
1112 case M_PROPERTY_PRINT:
1113 if (!arg)
1114 return M_PROPERTY_ERROR;
1115 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1116 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1117 MSGTR_Disabled));
1118 return M_PROPERTY_OK;
1119 default:
1120 return m_property_choice(prop, action, arg, &frame_dropping);
1124 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1125 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
1126 MPContext * mpctx)
1128 int *gamma = prop->priv, r, val;
1130 if (!mpctx->sh_video)
1131 return M_PROPERTY_UNAVAILABLE;
1133 if (gamma[0] == 1000) {
1134 gamma[0] = 0;
1135 get_video_colors(mpctx->sh_video, prop->name, gamma);
1138 switch (action) {
1139 case M_PROPERTY_SET:
1140 if (!arg)
1141 return M_PROPERTY_ERROR;
1142 M_PROPERTY_CLAMP(prop, *(int *) arg);
1143 *gamma = *(int *) arg;
1144 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1145 if (r <= 0)
1146 break;
1147 return r;
1148 case M_PROPERTY_GET:
1149 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1150 if (!arg)
1151 return M_PROPERTY_ERROR;
1152 *(int *)arg = val;
1153 return M_PROPERTY_OK;
1155 break;
1156 case M_PROPERTY_STEP_UP:
1157 case M_PROPERTY_STEP_DOWN:
1158 *gamma += (arg ? *(int *) arg : 1) *
1159 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1160 M_PROPERTY_CLAMP(prop, *gamma);
1161 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1162 if (r <= 0)
1163 break;
1164 return r;
1165 default:
1166 return M_PROPERTY_NOT_IMPLEMENTED;
1169 #ifdef CONFIG_TV
1170 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1171 int l = strlen(prop->name);
1172 char tv_prop[3 + l + 1];
1173 sprintf(tv_prop, "tv_%s", prop->name);
1174 return mp_property_do(tv_prop, action, arg, mpctx);
1176 #endif
1178 return M_PROPERTY_UNAVAILABLE;
1181 /// VSync (RW)
1182 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1183 MPContext * mpctx)
1185 return m_property_flag(prop, action, arg, &vo_vsync);
1188 /// Video codec tag (RO)
1189 static int mp_property_video_format(m_option_t * prop, int action,
1190 void *arg, MPContext * mpctx)
1192 char* meta;
1193 if (!mpctx->sh_video)
1194 return M_PROPERTY_UNAVAILABLE;
1195 switch(action) {
1196 case M_PROPERTY_PRINT:
1197 if (!arg)
1198 return M_PROPERTY_ERROR;
1199 switch(mpctx->sh_video->format) {
1200 case 0x10000001:
1201 meta = strdup ("mpeg1"); break;
1202 case 0x10000002:
1203 meta = strdup ("mpeg2"); break;
1204 case 0x10000004:
1205 meta = strdup ("mpeg4"); break;
1206 case 0x10000005:
1207 meta = strdup ("h264"); break;
1208 default:
1209 if(mpctx->sh_video->format >= 0x20202020) {
1210 meta = malloc(5);
1211 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1212 } else {
1213 meta = malloc(20);
1214 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1217 *(char**)arg = meta;
1218 return M_PROPERTY_OK;
1220 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1223 /// Video codec name (RO)
1224 static int mp_property_video_codec(m_option_t * prop, int action,
1225 void *arg, MPContext * mpctx)
1227 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1228 return M_PROPERTY_UNAVAILABLE;
1229 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1233 /// Video bitrate (RO)
1234 static int mp_property_video_bitrate(m_option_t * prop, int action,
1235 void *arg, MPContext * mpctx)
1237 if (!mpctx->sh_video)
1238 return M_PROPERTY_UNAVAILABLE;
1239 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1242 /// Video display width (RO)
1243 static int mp_property_width(m_option_t * prop, int action, void *arg,
1244 MPContext * mpctx)
1246 if (!mpctx->sh_video)
1247 return M_PROPERTY_UNAVAILABLE;
1248 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1251 /// Video display height (RO)
1252 static int mp_property_height(m_option_t * prop, int action, void *arg,
1253 MPContext * mpctx)
1255 if (!mpctx->sh_video)
1256 return M_PROPERTY_UNAVAILABLE;
1257 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1260 /// Video fps (RO)
1261 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1262 MPContext * mpctx)
1264 if (!mpctx->sh_video)
1265 return M_PROPERTY_UNAVAILABLE;
1266 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1269 /// Video aspect (RO)
1270 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1271 MPContext * mpctx)
1273 if (!mpctx->sh_video)
1274 return M_PROPERTY_UNAVAILABLE;
1275 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1278 ///@}
1280 /// \defgroup SubProprties Subtitles properties
1281 /// \ingroup Properties
1282 ///@{
1284 /// Text subtitle position (RW)
1285 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1286 MPContext * mpctx)
1288 if (!mpctx->sh_video)
1289 return M_PROPERTY_UNAVAILABLE;
1291 switch (action) {
1292 case M_PROPERTY_SET:
1293 if (!arg)
1294 return M_PROPERTY_ERROR;
1295 case M_PROPERTY_STEP_UP:
1296 case M_PROPERTY_STEP_DOWN:
1297 vo_osd_changed(OSDTYPE_SUBTITLE);
1298 default:
1299 return m_property_int_range(prop, action, arg, &sub_pos);
1303 /// Selected subtitles (RW)
1304 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1305 MPContext * mpctx)
1307 demux_stream_t *const d_sub = mpctx->d_sub;
1308 const int global_sub_size = mpctx->global_sub_size;
1309 int source = -1, reset_spu = 0;
1310 char *sub_name;
1312 if (global_sub_size <= 0)
1313 return M_PROPERTY_UNAVAILABLE;
1315 switch (action) {
1316 case M_PROPERTY_GET:
1317 if (!arg)
1318 return M_PROPERTY_ERROR;
1319 *(int *) arg = mpctx->global_sub_pos;
1320 return M_PROPERTY_OK;
1321 case M_PROPERTY_PRINT:
1322 if (!arg)
1323 return M_PROPERTY_ERROR;
1324 *(char **) arg = malloc(64);
1325 (*(char **) arg)[63] = 0;
1326 sub_name = 0;
1327 if (subdata)
1328 sub_name = subdata->filename;
1329 #ifdef CONFIG_ASS
1330 if (ass_track && ass_track->name)
1331 sub_name = ass_track->name;
1332 #endif
1333 if (sub_name) {
1334 char *tmp, *tmp2;
1335 tmp = sub_name;
1336 if ((tmp2 = strrchr(tmp, '/')))
1337 tmp = tmp2 + 1;
1339 snprintf(*(char **) arg, 63, "(%d) %s%s",
1340 mpctx->set_of_sub_pos + 1,
1341 strlen(tmp) < 20 ? "" : "...",
1342 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1343 return M_PROPERTY_OK;
1345 #ifdef CONFIG_DVDNAV
1346 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1347 if (vo_spudec && dvdsub_id >= 0) {
1348 unsigned char lang[3];
1349 if (mp_dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1350 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1351 return M_PROPERTY_OK;
1355 #endif
1357 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1358 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1359 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1360 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1361 && d_sub && d_sub->sh && dvdsub_id >= 0) {
1362 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1363 if (!lang) lang = MSGTR_Unknown;
1364 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1365 return M_PROPERTY_OK;
1368 if (vo_vobsub && vobsub_id >= 0) {
1369 const char *language = MSGTR_Unknown;
1370 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1371 snprintf(*(char **) arg, 63, "(%d) %s",
1372 vobsub_id, language ? language : MSGTR_Unknown);
1373 return M_PROPERTY_OK;
1375 #ifdef CONFIG_DVDREAD
1376 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1377 && dvdsub_id >= 0) {
1378 char lang[3];
1379 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1380 lang[0] = code >> 8;
1381 lang[1] = code;
1382 lang[2] = 0;
1383 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1384 return M_PROPERTY_OK;
1386 #endif
1387 if (dvdsub_id >= 0) {
1388 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1389 return M_PROPERTY_OK;
1391 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1392 return M_PROPERTY_OK;
1394 case M_PROPERTY_SET:
1395 if (!arg)
1396 return M_PROPERTY_ERROR;
1397 if (*(int *) arg < -1)
1398 *(int *) arg = -1;
1399 else if (*(int *) arg >= global_sub_size)
1400 *(int *) arg = global_sub_size - 1;
1401 mpctx->global_sub_pos = *(int *) arg;
1402 break;
1403 case M_PROPERTY_STEP_UP:
1404 mpctx->global_sub_pos += 2;
1405 mpctx->global_sub_pos =
1406 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1407 break;
1408 case M_PROPERTY_STEP_DOWN:
1409 mpctx->global_sub_pos += global_sub_size + 1;
1410 mpctx->global_sub_pos =
1411 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1412 break;
1413 default:
1414 return M_PROPERTY_NOT_IMPLEMENTED;
1417 if (mpctx->global_sub_pos >= 0)
1418 source = sub_source(mpctx);
1420 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1421 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1422 global_sub_size,
1423 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1424 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1425 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1426 mpctx->global_sub_pos, source);
1428 mpctx->set_of_sub_pos = -1;
1429 subdata = NULL;
1431 vobsub_id = -1;
1432 dvdsub_id = -1;
1433 if (d_sub) {
1434 if (d_sub->id > -2)
1435 reset_spu = 1;
1436 d_sub->id = -2;
1438 #ifdef CONFIG_ASS
1439 ass_track = 0;
1440 #endif
1442 if (source == SUB_SOURCE_VOBSUB) {
1443 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1444 } else if (source == SUB_SOURCE_SUBS) {
1445 mpctx->set_of_sub_pos =
1446 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1447 #ifdef CONFIG_ASS
1448 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1449 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1450 else
1451 #endif
1453 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1454 vo_osd_changed(OSDTYPE_SUBTITLE);
1456 } else if (source == SUB_SOURCE_DEMUX) {
1457 dvdsub_id =
1458 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1459 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1460 int i = 0;
1461 // default: assume 1:1 mapping of sid and stream id
1462 d_sub->id = dvdsub_id;
1463 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1464 ds_free_packs(d_sub);
1465 for (i = 0; i < MAX_S_STREAMS; i++) {
1466 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1467 if (sh && sh->sid == dvdsub_id) {
1468 d_sub->id = i;
1469 d_sub->sh = sh;
1470 break;
1473 if (d_sub->sh && d_sub->id >= 0) {
1474 sh_sub_t *sh = d_sub->sh;
1475 if (sh->type == 'v')
1476 init_vo_spudec();
1477 #ifdef CONFIG_ASS
1478 else if (ass_enabled)
1479 ass_track = sh->ass_track;
1480 #endif
1481 } else {
1482 d_sub->id = -2;
1483 d_sub->sh = NULL;
1487 #ifdef CONFIG_DVDREAD
1488 if (vo_spudec
1489 && (mpctx->stream->type == STREAMTYPE_DVD
1490 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1491 && dvdsub_id < 0 && reset_spu) {
1492 dvdsub_id = -2;
1493 d_sub->id = dvdsub_id;
1495 #endif
1496 update_subtitles(mpctx->sh_video, d_sub, 1);
1498 return M_PROPERTY_OK;
1501 /// Selected sub source (RW)
1502 static int mp_property_sub_source(m_option_t * prop, int action, void *arg,
1503 MPContext * mpctx)
1505 int source;
1506 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1507 return M_PROPERTY_UNAVAILABLE;
1509 switch (action) {
1510 case M_PROPERTY_GET:
1511 if (!arg)
1512 return M_PROPERTY_ERROR;
1513 *(int *) arg = sub_source(mpctx);
1514 return M_PROPERTY_OK;
1515 case M_PROPERTY_PRINT:
1516 if (!arg)
1517 return M_PROPERTY_ERROR;
1518 *(char **) arg = malloc(64);
1519 (*(char **) arg)[63] = 0;
1520 switch (sub_source(mpctx))
1522 case SUB_SOURCE_SUBS:
1523 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1524 break;
1525 case SUB_SOURCE_VOBSUB:
1526 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1527 break;
1528 case SUB_SOURCE_DEMUX:
1529 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1530 break;
1531 default:
1532 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1534 return M_PROPERTY_OK;
1535 case M_PROPERTY_SET:
1536 if (!arg)
1537 return M_PROPERTY_ERROR;
1538 M_PROPERTY_CLAMP(prop, *(int*)arg);
1539 if (*(int *) arg < 0)
1540 mpctx->global_sub_pos = -1;
1541 else if (*(int *) arg != sub_source(mpctx)) {
1542 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1543 return M_PROPERTY_UNAVAILABLE;
1544 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1546 break;
1547 case M_PROPERTY_STEP_UP:
1548 case M_PROPERTY_STEP_DOWN: {
1549 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1550 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1551 int step = (step_all > 0) ? 1 : -1;
1552 int cur_source = sub_source(mpctx);
1553 source = cur_source;
1554 while (step_all) {
1555 source += step;
1556 if (source >= SUB_SOURCES)
1557 source = -1;
1558 else if (source < -1)
1559 source = SUB_SOURCES - 1;
1560 if (source == cur_source || source == -1 ||
1561 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1562 step_all -= step;
1564 if (source == cur_source)
1565 return M_PROPERTY_OK;
1566 if (source == -1)
1567 mpctx->global_sub_pos = -1;
1568 else
1569 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1570 break;
1572 default:
1573 return M_PROPERTY_NOT_IMPLEMENTED;
1575 --mpctx->global_sub_pos;
1576 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1579 /// Selected subtitles from specific source (RW)
1580 static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg,
1581 MPContext * mpctx)
1583 int source, is_cur_source, offset;
1584 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1585 return M_PROPERTY_UNAVAILABLE;
1587 if (!strcmp(prop->name, "sub_file"))
1588 source = SUB_SOURCE_SUBS;
1589 else if (!strcmp(prop->name, "sub_vob"))
1590 source = SUB_SOURCE_VOBSUB;
1591 else if (!strcmp(prop->name, "sub_demux"))
1592 source = SUB_SOURCE_DEMUX;
1593 else
1594 return M_PROPERTY_ERROR;
1596 offset = mpctx->global_sub_indices[source];
1597 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1598 return M_PROPERTY_UNAVAILABLE;
1600 is_cur_source = sub_source(mpctx) == source;
1601 switch (action) {
1602 case M_PROPERTY_GET:
1603 if (!arg)
1604 return M_PROPERTY_ERROR;
1605 if (is_cur_source) {
1606 *(int *) arg = mpctx->global_sub_pos - offset;
1607 if (source == SUB_SOURCE_VOBSUB)
1608 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1610 else
1611 *(int *) arg = -1;
1612 return M_PROPERTY_OK;
1613 case M_PROPERTY_PRINT:
1614 if (!arg)
1615 return M_PROPERTY_ERROR;
1616 if (is_cur_source)
1617 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1618 *(char **) arg = malloc(64);
1619 (*(char **) arg)[63] = 0;
1620 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1621 return M_PROPERTY_OK;
1622 case M_PROPERTY_SET:
1623 if (!arg)
1624 return M_PROPERTY_ERROR;
1625 if (*(int *) arg >= 0) {
1626 int index = *(int *)arg;
1627 if (source == SUB_SOURCE_VOBSUB)
1628 index = vobsub_get_index_by_id(vo_vobsub, index);
1629 mpctx->global_sub_pos = offset + index;
1630 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1631 || sub_source(mpctx) != source) {
1632 mpctx->global_sub_pos = -1;
1633 *(int *) arg = -1;
1636 else
1637 mpctx->global_sub_pos = -1;
1638 break;
1639 case M_PROPERTY_STEP_UP:
1640 case M_PROPERTY_STEP_DOWN: {
1641 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1642 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1643 int step = (step_all > 0) ? 1 : -1;
1644 int max_sub_pos_for_source = -1;
1645 if (!is_cur_source)
1646 mpctx->global_sub_pos = -1;
1647 while (step_all) {
1648 if (mpctx->global_sub_pos == -1) {
1649 if (step > 0)
1650 mpctx->global_sub_pos = offset;
1651 else if (max_sub_pos_for_source == -1) {
1652 // Find max pos for specific source
1653 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1654 while (mpctx->global_sub_pos >= 0
1655 && sub_source(mpctx) != source)
1656 --mpctx->global_sub_pos;
1658 else
1659 mpctx->global_sub_pos = max_sub_pos_for_source;
1661 else {
1662 mpctx->global_sub_pos += step;
1663 if (mpctx->global_sub_pos < offset ||
1664 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1665 sub_source(mpctx) != source)
1666 mpctx->global_sub_pos = -1;
1668 step_all -= step;
1670 break;
1672 default:
1673 return M_PROPERTY_NOT_IMPLEMENTED;
1675 --mpctx->global_sub_pos;
1676 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1679 /// Subtitle delay (RW)
1680 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1681 MPContext * mpctx)
1683 if (!mpctx->sh_video)
1684 return M_PROPERTY_UNAVAILABLE;
1685 return m_property_delay(prop, action, arg, &sub_delay);
1688 /// Alignment of text subtitles (RW)
1689 static int mp_property_sub_alignment(m_option_t * prop, int action,
1690 void *arg, MPContext * mpctx)
1692 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1694 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1695 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1696 return M_PROPERTY_UNAVAILABLE;
1698 switch (action) {
1699 case M_PROPERTY_PRINT:
1700 if (!arg)
1701 return M_PROPERTY_ERROR;
1702 M_PROPERTY_CLAMP(prop, sub_alignment);
1703 *(char **) arg = strdup(name[sub_alignment]);
1704 return M_PROPERTY_OK;
1705 case M_PROPERTY_SET:
1706 if (!arg)
1707 return M_PROPERTY_ERROR;
1708 case M_PROPERTY_STEP_UP:
1709 case M_PROPERTY_STEP_DOWN:
1710 vo_osd_changed(OSDTYPE_SUBTITLE);
1711 default:
1712 return m_property_choice(prop, action, arg, &sub_alignment);
1716 /// Subtitle visibility (RW)
1717 static int mp_property_sub_visibility(m_option_t * prop, int action,
1718 void *arg, MPContext * mpctx)
1720 if (!mpctx->sh_video)
1721 return M_PROPERTY_UNAVAILABLE;
1723 switch (action) {
1724 case M_PROPERTY_SET:
1725 if (!arg)
1726 return M_PROPERTY_ERROR;
1727 case M_PROPERTY_STEP_UP:
1728 case M_PROPERTY_STEP_DOWN:
1729 vo_osd_changed(OSDTYPE_SUBTITLE);
1730 if (vo_spudec)
1731 vo_osd_changed(OSDTYPE_SPU);
1732 default:
1733 return m_property_flag(prop, action, arg, &sub_visibility);
1737 #ifdef CONFIG_ASS
1738 /// Use margins for libass subtitles (RW)
1739 static int mp_property_ass_use_margins(m_option_t * prop, int action,
1740 void *arg, MPContext * mpctx)
1742 if (!mpctx->sh_video)
1743 return M_PROPERTY_UNAVAILABLE;
1745 switch (action) {
1746 case M_PROPERTY_SET:
1747 if (!arg)
1748 return M_PROPERTY_ERROR;
1749 case M_PROPERTY_STEP_UP:
1750 case M_PROPERTY_STEP_DOWN:
1751 ass_force_reload = 1;
1752 default:
1753 return m_property_flag(prop, action, arg, &ass_use_margins);
1756 #endif
1758 /// Show only forced subtitles (RW)
1759 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1760 void *arg, MPContext * mpctx)
1762 if (!vo_spudec)
1763 return M_PROPERTY_UNAVAILABLE;
1765 switch (action) {
1766 case M_PROPERTY_SET:
1767 if (!arg)
1768 return M_PROPERTY_ERROR;
1769 case M_PROPERTY_STEP_UP:
1770 case M_PROPERTY_STEP_DOWN:
1771 m_property_flag(prop, action, arg, &forced_subs_only);
1772 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1773 return M_PROPERTY_OK;
1774 default:
1775 return m_property_flag(prop, action, arg, &forced_subs_only);
1780 #ifdef CONFIG_FREETYPE
1781 /// Subtitle scale (RW)
1782 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1783 MPContext * mpctx)
1786 switch (action) {
1787 case M_PROPERTY_SET:
1788 if (!arg)
1789 return M_PROPERTY_ERROR;
1790 M_PROPERTY_CLAMP(prop, *(float *) arg);
1791 #ifdef CONFIG_ASS
1792 if (ass_enabled) {
1793 ass_font_scale = *(float *) arg;
1794 ass_force_reload = 1;
1796 #endif
1797 text_font_scale_factor = *(float *) arg;
1798 force_load_font = 1;
1799 return M_PROPERTY_OK;
1800 case M_PROPERTY_STEP_UP:
1801 case M_PROPERTY_STEP_DOWN:
1802 #ifdef CONFIG_ASS
1803 if (ass_enabled) {
1804 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1805 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1806 M_PROPERTY_CLAMP(prop, ass_font_scale);
1807 ass_force_reload = 1;
1809 #endif
1810 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1811 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1812 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1813 force_load_font = 1;
1814 return M_PROPERTY_OK;
1815 default:
1816 #ifdef CONFIG_ASS
1817 if (ass_enabled)
1818 return m_property_float_ro(prop, action, arg, ass_font_scale);
1819 else
1820 #endif
1821 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1824 #endif
1826 ///@}
1828 /// \defgroup TVProperties TV properties
1829 /// \ingroup Properties
1830 ///@{
1832 #ifdef CONFIG_TV
1834 /// TV color settings (RW)
1835 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1836 MPContext * mpctx)
1838 int r, val;
1839 tvi_handle_t *tvh = mpctx->demuxer->priv;
1840 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1841 return M_PROPERTY_UNAVAILABLE;
1843 switch (action) {
1844 case M_PROPERTY_SET:
1845 if (!arg)
1846 return M_PROPERTY_ERROR;
1847 M_PROPERTY_CLAMP(prop, *(int *) arg);
1848 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1849 case M_PROPERTY_GET:
1850 return tv_get_color_options(tvh, (int) prop->priv, arg);
1851 case M_PROPERTY_STEP_UP:
1852 case M_PROPERTY_STEP_DOWN:
1853 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1854 if (!r)
1855 return M_PROPERTY_ERROR;
1856 val += (arg ? *(int *) arg : 1) *
1857 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1858 M_PROPERTY_CLAMP(prop, val);
1859 return tv_set_color_options(tvh, (int) prop->priv, val);
1861 return M_PROPERTY_ERROR;
1863 return M_PROPERTY_NOT_IMPLEMENTED;
1866 #endif
1868 #ifdef CONFIG_TV_TELETEXT
1869 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1870 MPContext * mpctx)
1872 int val,result;
1873 int base_ioctl=(int)prop->priv;
1875 for teletext's GET,SET,STEP ioctls this is not 0
1876 SET is GET+1
1877 STEP is GET+2
1879 tvi_handle_t *tvh = mpctx->demuxer->priv;
1880 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1881 return M_PROPERTY_UNAVAILABLE;
1882 if(!base_ioctl)
1883 return M_PROPERTY_ERROR;
1885 switch (action) {
1886 case M_PROPERTY_GET:
1887 if (!arg)
1888 return M_PROPERTY_ERROR;
1889 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1890 break;
1891 case M_PROPERTY_SET:
1892 if (!arg)
1893 return M_PROPERTY_ERROR;
1894 M_PROPERTY_CLAMP(prop, *(int *) arg);
1895 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1896 break;
1897 case M_PROPERTY_STEP_UP:
1898 case M_PROPERTY_STEP_DOWN:
1899 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1900 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1901 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1902 break;
1903 default:
1904 return M_PROPERTY_NOT_IMPLEMENTED;
1907 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1910 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1911 MPContext * mpctx)
1913 tvi_handle_t *tvh = mpctx->demuxer->priv;
1914 int result;
1915 int val;
1917 //with tvh==NULL will fail too
1918 result=mp_property_teletext_common(prop,action,arg,mpctx);
1919 if(result!=M_PROPERTY_OK)
1920 return result;
1922 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1923 mp_input_set_section("teletext");
1924 else
1925 mp_input_set_section("tv");
1926 return M_PROPERTY_OK;
1929 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1930 MPContext * mpctx)
1932 tvi_handle_t *tvh = mpctx->demuxer->priv;
1933 int result;
1934 int val;
1935 switch(action){
1936 case M_PROPERTY_STEP_UP:
1937 case M_PROPERTY_STEP_DOWN:
1938 //This should be handled separately
1939 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1940 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1941 break;
1942 default:
1943 result=mp_property_teletext_common(prop,action,arg,mpctx);
1945 return result;
1949 #endif /* CONFIG_TV_TELETEXT */
1951 ///@}
1953 /// All properties available in MPlayer.
1954 /** \ingroup Properties
1956 static const m_option_t mp_properties[] = {
1957 // General
1958 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1959 M_OPT_RANGE, 0, 3, NULL },
1960 { "loop", mp_property_loop, CONF_TYPE_INT,
1961 M_OPT_MIN, -1, 0, NULL },
1962 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1963 M_OPT_RANGE, 0.01, 100.0, NULL },
1964 { "filename", mp_property_filename, CONF_TYPE_STRING,
1965 0, 0, 0, NULL },
1966 { "path", mp_property_path, CONF_TYPE_STRING,
1967 0, 0, 0, NULL },
1968 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1969 0, 0, 0, NULL },
1970 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1971 M_OPT_MIN, 0, 0, NULL },
1972 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1973 M_OPT_MIN, 0, 0, NULL },
1974 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1975 M_OPT_MIN, 0, 0, NULL },
1976 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1977 M_OPT_MIN, 0, 0, NULL },
1978 { "length", mp_property_length, CONF_TYPE_TIME,
1979 M_OPT_MIN, 0, 0, NULL },
1980 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1981 M_OPT_RANGE, 0, 100, NULL },
1982 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1983 M_OPT_MIN, 0, 0, NULL },
1984 { "chapter", mp_property_chapter, CONF_TYPE_INT,
1985 M_OPT_MIN, 1, 0, NULL },
1986 { "angle", mp_property_angle, CONF_TYPE_INT,
1987 CONF_RANGE, -2, 10, NULL },
1988 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
1989 0, 0, 0, NULL },
1991 // Audio
1992 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
1993 M_OPT_RANGE, 0, 100, NULL },
1994 { "mute", mp_property_mute, CONF_TYPE_FLAG,
1995 M_OPT_RANGE, 0, 1, NULL },
1996 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
1997 M_OPT_RANGE, -100, 100, NULL },
1998 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
1999 0, 0, 0, NULL },
2000 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2001 0, 0, 0, NULL },
2002 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2003 0, 0, 0, NULL },
2004 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2005 0, 0, 0, NULL },
2006 { "channels", mp_property_channels, CONF_TYPE_INT,
2007 0, 0, 0, NULL },
2008 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2009 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
2010 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2011 M_OPT_RANGE, -1, 1, NULL },
2013 // Video
2014 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2015 M_OPT_RANGE, 0, 1, NULL },
2016 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2017 M_OPT_RANGE, 0, 1, NULL },
2018 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2019 M_OPT_RANGE, 0, 1, NULL },
2020 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2021 M_OPT_RANGE, 0, 1, NULL },
2022 { "border", mp_property_border, CONF_TYPE_FLAG,
2023 M_OPT_RANGE, 0, 1, NULL },
2024 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2025 M_OPT_RANGE, 0, 2, NULL },
2026 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2027 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2028 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2029 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2030 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2031 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2032 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2033 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2034 { "hue", mp_property_gamma, CONF_TYPE_INT,
2035 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2036 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2037 M_OPT_RANGE, 0, 1, NULL },
2038 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2039 M_OPT_RANGE, 0, 1, NULL },
2040 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2041 0, 0, 0, NULL },
2042 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2043 0, 0, 0, NULL },
2044 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2045 0, 0, 0, NULL },
2046 { "width", mp_property_width, CONF_TYPE_INT,
2047 0, 0, 0, NULL },
2048 { "height", mp_property_height, CONF_TYPE_INT,
2049 0, 0, 0, NULL },
2050 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2051 0, 0, 0, NULL },
2052 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2053 0, 0, 0, NULL },
2054 { "switch_video", mp_property_video, CONF_TYPE_INT,
2055 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
2056 { "switch_program", mp_property_program, CONF_TYPE_INT,
2057 CONF_RANGE, -1, 65535, NULL },
2059 // Subs
2060 { "sub", mp_property_sub, CONF_TYPE_INT,
2061 M_OPT_MIN, -1, 0, NULL },
2062 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2063 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2064 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2065 M_OPT_MIN, -1, 0, NULL },
2066 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2067 M_OPT_MIN, -1, 0, NULL },
2068 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2069 M_OPT_MIN, -1, 0, NULL },
2070 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2071 0, 0, 0, NULL },
2072 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2073 M_OPT_RANGE, 0, 100, NULL },
2074 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2075 M_OPT_RANGE, 0, 2, NULL },
2076 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2077 M_OPT_RANGE, 0, 1, NULL },
2078 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2079 M_OPT_RANGE, 0, 1, NULL },
2080 #ifdef CONFIG_FREETYPE
2081 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2082 M_OPT_RANGE, 0, 100, NULL },
2083 #endif
2084 #ifdef CONFIG_ASS
2085 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2086 M_OPT_RANGE, 0, 1, NULL },
2087 #endif
2089 #ifdef CONFIG_TV
2090 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2091 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2092 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2093 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2094 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2095 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2096 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2097 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2098 #endif
2100 #ifdef CONFIG_TV_TELETEXT
2101 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2102 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2103 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2104 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2105 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2106 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2107 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2108 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2109 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2110 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2111 #endif
2113 { NULL, NULL, NULL, 0, 0, 0, NULL }
2117 int mp_property_do(const char *name, int action, void *val, void *ctx)
2119 return m_property_do(mp_properties, name, action, val, ctx);
2122 char* mp_property_print(const char *name, void* ctx)
2124 char* ret = NULL;
2125 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2126 return NULL;
2127 return ret;
2130 char *property_expand_string(MPContext * mpctx, char *str)
2132 return m_properties_expand_string(mp_properties, str, mpctx);
2135 void property_print_help(void)
2137 m_properties_print_help_list(mp_properties);
2141 ///@}
2142 // Properties group
2146 * \defgroup Command2Property Command to property bridge
2148 * It is used to handle most commands that just set a property
2149 * and optionally display something on the OSD.
2150 * Two kinds of commands are handled: adjust or toggle.
2152 * Adjust commands take 1 or 2 parameters: <value> <abs>
2153 * If <abs> is non-zero the property is set to the given value
2154 * otherwise it is adjusted.
2156 * Toggle commands take 0 or 1 parameters. With no parameter
2157 * or a value less than the property minimum it just steps the
2158 * property to its next value. Otherwise it sets it to the given
2159 * value.
2164 /// List of the commands that can be handled by setting a property.
2165 static struct {
2166 /// property name
2167 const char *name;
2168 /// cmd id
2169 int cmd;
2170 /// set/adjust or toggle command
2171 int toggle;
2172 /// progressbar type
2173 int osd_progbar;
2174 /// osd msg id if it must be shared
2175 int osd_id;
2176 /// osd msg template
2177 const char *osd_msg;
2178 } set_prop_cmd[] = {
2179 // general
2180 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2181 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2182 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2183 // audio
2184 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2185 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2186 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2187 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2188 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2189 // video
2190 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2191 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2192 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2193 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2194 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2195 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2196 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2197 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2198 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2199 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2200 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2201 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2202 // subs
2203 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2204 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2205 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2206 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2207 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2208 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2209 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2210 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2211 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2212 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2213 #ifdef CONFIG_FREETYPE
2214 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2215 #endif
2216 #ifdef CONFIG_ASS
2217 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2218 #endif
2219 #ifdef CONFIG_TV
2220 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2221 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2222 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2223 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2224 #endif
2225 { NULL, 0, 0, 0, -1, NULL }
2229 /// Handle commands that set a property.
2230 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
2232 int i, r;
2233 m_option_t* prop;
2234 const char *pname;
2236 // look for the command
2237 for (i = 0; set_prop_cmd[i].name; i++)
2238 if (set_prop_cmd[i].cmd == cmd->id)
2239 break;
2240 if (!(pname = set_prop_cmd[i].name))
2241 return 0;
2243 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2244 return 0;
2246 // toggle command
2247 if (set_prop_cmd[i].toggle) {
2248 // set to value
2249 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2250 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2251 else
2252 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2253 } else if (cmd->args[1].v.i) //set
2254 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2255 else // adjust
2256 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2258 if (r <= 0)
2259 return 1;
2261 if (set_prop_cmd[i].osd_progbar) {
2262 if (prop->type == CONF_TYPE_INT) {
2263 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2264 set_osd_bar(set_prop_cmd[i].osd_progbar,
2265 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2266 } else if (prop->type == CONF_TYPE_FLOAT) {
2267 float f;
2268 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2269 set_osd_bar(set_prop_cmd[i].osd_progbar,
2270 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2271 } else
2272 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2273 "Property use an unsupported type.\n");
2274 return 1;
2277 if (set_prop_cmd[i].osd_msg) {
2278 char *val = mp_property_print(pname, mpctx);
2279 if (val) {
2280 set_osd_msg(set_prop_cmd[i].osd_id >=
2281 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2282 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2283 free(val);
2286 return 1;
2289 #ifdef CONFIG_DVDNAV
2290 static const struct {
2291 const char *name;
2292 const mp_command_type cmd;
2293 } mp_dvdnav_bindings[] = {
2294 { "up", MP_CMD_DVDNAV_UP },
2295 { "down", MP_CMD_DVDNAV_DOWN },
2296 { "left", MP_CMD_DVDNAV_LEFT },
2297 { "right", MP_CMD_DVDNAV_RIGHT },
2298 { "menu", MP_CMD_DVDNAV_MENU },
2299 { "select", MP_CMD_DVDNAV_SELECT },
2300 { "prev", MP_CMD_DVDNAV_PREVMENU },
2301 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2304 * keep old dvdnav sub-command options for a while in order not to
2305 * break slave-mode API too suddenly.
2307 { "1", MP_CMD_DVDNAV_UP },
2308 { "2", MP_CMD_DVDNAV_DOWN },
2309 { "3", MP_CMD_DVDNAV_LEFT },
2310 { "4", MP_CMD_DVDNAV_RIGHT },
2311 { "5", MP_CMD_DVDNAV_MENU },
2312 { "6", MP_CMD_DVDNAV_SELECT },
2313 { "7", MP_CMD_DVDNAV_PREVMENU },
2314 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2315 { NULL, 0 }
2317 #endif
2319 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
2321 sh_audio_t * const sh_audio = mpctx->sh_audio;
2322 sh_video_t * const sh_video = mpctx->sh_video;
2323 int brk_cmd = 0;
2324 if (!set_property_command(mpctx, cmd))
2325 switch (cmd->id) {
2326 case MP_CMD_SEEK:{
2327 float v;
2328 int abs;
2329 if (sh_video)
2330 mpctx->osd_show_percentage = sh_video->fps;
2331 v = cmd->args[0].v.f;
2332 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2333 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2334 abs_seek_pos = SEEK_ABSOLUTE;
2335 if (sh_video)
2336 mpctx->osd_function =
2337 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2338 rel_seek_secs = v;
2339 } else if (abs) { /* Absolute seek by percentage */
2340 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2341 if (sh_video)
2342 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2343 rel_seek_secs = v / 100.0;
2344 } else {
2345 rel_seek_secs += v;
2346 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2348 brk_cmd = 1;
2350 break;
2352 case MP_CMD_SET_PROPERTY:{
2353 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2354 cmd->args[1].v.s, mpctx);
2355 if (r == M_PROPERTY_UNKNOWN)
2356 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2357 "Unknown property: '%s'\n", cmd->args[0].v.s);
2358 else if (r <= 0)
2359 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2360 "Failed to set property '%s' to '%s'.\n",
2361 cmd->args[0].v.s, cmd->args[1].v.s);
2363 break;
2365 case MP_CMD_STEP_PROPERTY:{
2366 void* arg = NULL;
2367 int r,i;
2368 double d;
2369 off_t o;
2370 if (cmd->args[1].v.f) {
2371 m_option_t* prop;
2372 if((r = mp_property_do(cmd->args[0].v.s,
2373 M_PROPERTY_GET_TYPE,
2374 &prop, mpctx)) <= 0)
2375 goto step_prop_err;
2376 if(prop->type == CONF_TYPE_INT ||
2377 prop->type == CONF_TYPE_FLAG)
2378 i = cmd->args[1].v.f, arg = &i;
2379 else if(prop->type == CONF_TYPE_FLOAT)
2380 arg = &cmd->args[1].v.f;
2381 else if(prop->type == CONF_TYPE_DOUBLE ||
2382 prop->type == CONF_TYPE_TIME)
2383 d = cmd->args[1].v.f, arg = &d;
2384 else if(prop->type == CONF_TYPE_POSITION)
2385 o = cmd->args[1].v.f, arg = &o;
2386 else
2387 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2388 "Ignoring step size stepping property '%s'.\n",
2389 cmd->args[0].v.s);
2391 r = mp_property_do(cmd->args[0].v.s,
2392 cmd->args[2].v.i < 0 ?
2393 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2394 arg, mpctx);
2395 step_prop_err:
2396 if (r == M_PROPERTY_UNKNOWN)
2397 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2398 "Unknown property: '%s'\n", cmd->args[0].v.s);
2399 else if (r <= 0)
2400 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2401 "Failed to increment property '%s' by %f.\n",
2402 cmd->args[0].v.s, cmd->args[1].v.f);
2404 break;
2406 case MP_CMD_GET_PROPERTY:{
2407 char *tmp;
2408 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2409 &tmp, mpctx) <= 0) {
2410 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2411 "Failed to get value of property '%s'.\n",
2412 cmd->args[0].v.s);
2413 break;
2415 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2416 cmd->args[0].v.s, tmp);
2417 free(tmp);
2419 break;
2421 case MP_CMD_EDL_MARK:
2422 if (edl_fd) {
2423 float v = sh_video ? sh_video->pts :
2424 playing_audio_pts(sh_audio, mpctx->d_audio,
2425 mpctx->audio_out);
2427 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2428 mpctx->begin_skip = v;
2429 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2430 } else {
2431 if (mpctx->begin_skip > v)
2432 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2433 else {
2434 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2435 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2437 mpctx->begin_skip = MP_NOPTS_VALUE;
2440 break;
2442 case MP_CMD_SWITCH_RATIO:
2443 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2444 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2445 else
2446 movie_aspect = cmd->args[0].v.f;
2447 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2448 break;
2450 case MP_CMD_SPEED_INCR:{
2451 float v = cmd->args[0].v.f;
2452 playback_speed += v;
2453 build_afilter_chain(sh_audio, &ao_data);
2454 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2455 playback_speed);
2456 } break;
2458 case MP_CMD_SPEED_MULT:{
2459 float v = cmd->args[0].v.f;
2460 playback_speed *= v;
2461 build_afilter_chain(sh_audio, &ao_data);
2462 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2463 playback_speed);
2464 } break;
2466 case MP_CMD_SPEED_SET:{
2467 float v = cmd->args[0].v.f;
2468 playback_speed = v;
2469 build_afilter_chain(sh_audio, &ao_data);
2470 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2471 playback_speed);
2472 } break;
2474 case MP_CMD_FRAME_STEP:
2475 case MP_CMD_PAUSE:
2476 cmd->pausing = 1;
2477 brk_cmd = 1;
2478 break;
2480 case MP_CMD_FILE_FILTER:
2481 file_filter = cmd->args[0].v.i;
2482 break;
2484 case MP_CMD_QUIT:
2485 exit_player_with_rc(MSGTR_Exit_quit,
2486 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2488 case MP_CMD_PLAY_TREE_STEP:{
2489 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2490 int force = cmd->args[1].v.i;
2492 #ifdef CONFIG_GUI
2493 if (use_gui) {
2494 int i = 0;
2495 if (n > 0)
2496 for (i = 0; i < n; i++)
2497 mplNext();
2498 else
2499 for (i = 0; i < -1 * n; i++)
2500 mplPrev();
2501 } else
2502 #endif
2504 if (!force && mpctx->playtree_iter) {
2505 play_tree_iter_t *i =
2506 play_tree_iter_new_copy(mpctx->playtree_iter);
2507 if (play_tree_iter_step(i, n, 0) ==
2508 PLAY_TREE_ITER_ENTRY)
2509 mpctx->eof =
2510 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2511 play_tree_iter_free(i);
2512 } else
2513 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2514 if (mpctx->eof)
2515 mpctx->play_tree_step = n;
2516 brk_cmd = 1;
2519 break;
2521 case MP_CMD_PLAY_TREE_UP_STEP:{
2522 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2523 int force = cmd->args[1].v.i;
2525 if (!force && mpctx->playtree_iter) {
2526 play_tree_iter_t *i =
2527 play_tree_iter_new_copy(mpctx->playtree_iter);
2528 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2529 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2530 play_tree_iter_free(i);
2531 } else
2532 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2533 brk_cmd = 1;
2535 break;
2537 case MP_CMD_PLAY_ALT_SRC_STEP:
2538 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2539 int v = cmd->args[0].v.i;
2540 if (v > 0
2541 && mpctx->playtree_iter->file <
2542 mpctx->playtree_iter->num_files)
2543 mpctx->eof = PT_NEXT_SRC;
2544 else if (v < 0 && mpctx->playtree_iter->file > 1)
2545 mpctx->eof = PT_PREV_SRC;
2547 brk_cmd = 1;
2548 break;
2550 case MP_CMD_SUB_STEP:
2551 if (sh_video) {
2552 int movement = cmd->args[0].v.i;
2553 step_sub(subdata, sh_video->pts, movement);
2554 #ifdef CONFIG_ASS
2555 if (ass_track)
2556 sub_delay +=
2557 ass_step_sub(ass_track,
2558 (sh_video->pts +
2559 sub_delay) * 1000 + .5, movement) / 1000.;
2560 #endif
2561 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2562 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2564 break;
2566 case MP_CMD_SUB_LOG:
2567 log_sub();
2568 break;
2570 case MP_CMD_OSD:{
2571 int v = cmd->args[0].v.i;
2572 int max = (term_osd
2573 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2574 if (osd_level > max)
2575 osd_level = max;
2576 if (v < 0)
2577 osd_level = (osd_level + 1) % (max + 1);
2578 else
2579 osd_level = v > max ? max : v;
2580 /* Show OSD state when disabled, but not when an explicit
2581 argument is given to the OSD command, i.e. in slave mode. */
2582 if (v == -1 && osd_level <= 1)
2583 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2584 MSGTR_OSDosd,
2585 osd_level ? MSGTR_OSDenabled :
2586 MSGTR_OSDdisabled);
2587 else
2588 rm_osd_msg(OSD_MSG_OSD_STATUS);
2590 break;
2592 case MP_CMD_OSD_SHOW_TEXT:
2593 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2594 (cmd->args[1].v.i <
2595 0 ? osd_duration : cmd->args[1].v.i),
2596 "%-.63s", cmd->args[0].v.s);
2597 break;
2599 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2600 char *txt = m_properties_expand_string(mp_properties,
2601 cmd->args[0].v.s,
2602 mpctx);
2603 /* if no argument supplied take default osd_duration, else <arg> ms. */
2604 if (txt) {
2605 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2606 (cmd->args[1].v.i <
2607 0 ? osd_duration : cmd->args[1].v.i),
2608 "%-.63s", txt);
2609 free(txt);
2612 break;
2614 case MP_CMD_LOADFILE:{
2615 play_tree_t *e = play_tree_new();
2616 play_tree_add_file(e, cmd->args[0].v.s);
2618 if (cmd->args[1].v.i) // append
2619 play_tree_append_entry(mpctx->playtree, e);
2620 else {
2621 // Go back to the starting point.
2622 while (play_tree_iter_up_step
2623 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2624 /* NOP */ ;
2625 play_tree_free_list(mpctx->playtree->child, 1);
2626 play_tree_set_child(mpctx->playtree, e);
2627 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2628 mpctx->eof = PT_NEXT_SRC;
2630 brk_cmd = 1;
2632 break;
2634 case MP_CMD_LOADLIST:{
2635 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2636 if (!e)
2637 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2638 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2639 else {
2640 if (cmd->args[1].v.i) // append
2641 play_tree_append_entry(mpctx->playtree, e);
2642 else {
2643 // Go back to the starting point.
2644 while (play_tree_iter_up_step
2645 (mpctx->playtree_iter, 0, 1)
2646 != PLAY_TREE_ITER_END)
2647 /* NOP */ ;
2648 play_tree_free_list(mpctx->playtree->child, 1);
2649 play_tree_set_child(mpctx->playtree, e);
2650 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2651 mpctx->eof = PT_NEXT_SRC;
2654 brk_cmd = 1;
2656 break;
2658 case MP_CMD_STOP:
2659 // Go back to the starting point.
2660 while (play_tree_iter_up_step
2661 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2662 /* NOP */ ;
2663 mpctx->eof = PT_STOP;
2664 brk_cmd = 1;
2665 break;
2667 #ifdef CONFIG_RADIO
2668 case MP_CMD_RADIO_STEP_CHANNEL:
2669 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2670 int v = cmd->args[0].v.i;
2671 if (v > 0)
2672 radio_step_channel(mpctx->demuxer->stream,
2673 RADIO_CHANNEL_HIGHER);
2674 else
2675 radio_step_channel(mpctx->demuxer->stream,
2676 RADIO_CHANNEL_LOWER);
2677 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2678 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2679 MSGTR_OSDChannel,
2680 radio_get_channel_name(mpctx->demuxer->stream));
2683 break;
2685 case MP_CMD_RADIO_SET_CHANNEL:
2686 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2687 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2688 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2689 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2690 MSGTR_OSDChannel,
2691 radio_get_channel_name(mpctx->demuxer->stream));
2694 break;
2696 case MP_CMD_RADIO_SET_FREQ:
2697 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2698 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2699 break;
2701 case MP_CMD_RADIO_STEP_FREQ:
2702 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2703 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2704 break;
2705 #endif
2707 #ifdef CONFIG_TV
2708 case MP_CMD_TV_START_SCAN:
2709 if (mpctx->file_format == DEMUXER_TYPE_TV)
2710 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2711 break;
2712 case MP_CMD_TV_SET_FREQ:
2713 if (mpctx->file_format == DEMUXER_TYPE_TV)
2714 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2715 cmd->args[0].v.f * 16.0);
2716 #ifdef CONFIG_PVR
2717 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2718 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2719 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2720 pvr_get_current_channelname (mpctx->stream),
2721 pvr_get_current_stationname (mpctx->stream));
2723 #endif /* CONFIG_PVR */
2724 break;
2726 case MP_CMD_TV_STEP_FREQ:
2727 if (mpctx->file_format == DEMUXER_TYPE_TV)
2728 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2729 cmd->args[0].v.f * 16.0);
2730 #ifdef CONFIG_PVR
2731 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2732 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2733 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2734 pvr_get_current_channelname (mpctx->stream),
2735 pvr_get_current_frequency (mpctx->stream));
2737 #endif /* CONFIG_PVR */
2738 break;
2740 case MP_CMD_TV_SET_NORM:
2741 if (mpctx->file_format == DEMUXER_TYPE_TV)
2742 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2743 cmd->args[0].v.s);
2744 break;
2746 case MP_CMD_TV_STEP_CHANNEL:{
2747 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2748 int v = cmd->args[0].v.i;
2749 if (v > 0) {
2750 tv_step_channel((tvi_handle_t *) (mpctx->
2751 demuxer->priv),
2752 TV_CHANNEL_HIGHER);
2753 } else {
2754 tv_step_channel((tvi_handle_t *) (mpctx->
2755 demuxer->priv),
2756 TV_CHANNEL_LOWER);
2758 if (tv_channel_list) {
2759 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2760 MSGTR_OSDChannel, tv_channel_current->name);
2761 //vo_osd_changed(OSDTYPE_SUBTITLE);
2764 #ifdef CONFIG_PVR
2765 else if (mpctx->stream &&
2766 mpctx->stream->type == STREAMTYPE_PVR) {
2767 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2768 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2769 pvr_get_current_channelname (mpctx->stream),
2770 pvr_get_current_stationname (mpctx->stream));
2772 #endif /* CONFIG_PVR */
2774 #ifdef CONFIG_DVBIN
2775 if (mpctx->stream->type == STREAMTYPE_DVB) {
2776 int dir;
2777 int v = cmd->args[0].v.i;
2779 mpctx->last_dvb_step = v;
2780 if (v > 0)
2781 dir = DVB_CHANNEL_HIGHER;
2782 else
2783 dir = DVB_CHANNEL_LOWER;
2786 if (dvb_step_channel(mpctx->stream, dir))
2787 mpctx->eof = mpctx->dvbin_reopen = 1;
2789 #endif /* CONFIG_DVBIN */
2790 break;
2792 case MP_CMD_TV_SET_CHANNEL:
2793 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2794 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2795 cmd->args[0].v.s);
2796 if (tv_channel_list) {
2797 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2798 MSGTR_OSDChannel, tv_channel_current->name);
2799 //vo_osd_changed(OSDTYPE_SUBTITLE);
2802 #ifdef CONFIG_PVR
2803 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2804 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2805 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2806 pvr_get_current_channelname (mpctx->stream),
2807 pvr_get_current_stationname (mpctx->stream));
2809 #endif /* CONFIG_PVR */
2810 break;
2812 #ifdef CONFIG_DVBIN
2813 case MP_CMD_DVB_SET_CHANNEL:
2814 if (mpctx->stream->type == STREAMTYPE_DVB) {
2815 mpctx->last_dvb_step = 1;
2817 if (dvb_set_channel
2818 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2819 mpctx->eof = mpctx->dvbin_reopen = 1;
2821 break;
2822 #endif /* CONFIG_DVBIN */
2824 case MP_CMD_TV_LAST_CHANNEL:
2825 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2826 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2827 if (tv_channel_list) {
2828 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2829 MSGTR_OSDChannel, tv_channel_current->name);
2830 //vo_osd_changed(OSDTYPE_SUBTITLE);
2833 #ifdef CONFIG_PVR
2834 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2835 pvr_set_lastchannel (mpctx->stream);
2836 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2837 pvr_get_current_channelname (mpctx->stream),
2838 pvr_get_current_stationname (mpctx->stream));
2840 #endif /* CONFIG_PVR */
2841 break;
2843 case MP_CMD_TV_STEP_NORM:
2844 if (mpctx->file_format == DEMUXER_TYPE_TV)
2845 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2846 break;
2848 case MP_CMD_TV_STEP_CHANNEL_LIST:
2849 if (mpctx->file_format == DEMUXER_TYPE_TV)
2850 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2851 break;
2852 #ifdef CONFIG_TV_TELETEXT
2853 case MP_CMD_TV_TELETEXT_ADD_DEC:
2855 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2856 if (mpctx->file_format == DEMUXER_TYPE_TV)
2857 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2858 break;
2860 case MP_CMD_TV_TELETEXT_GO_LINK:
2862 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2863 if (mpctx->file_format == DEMUXER_TYPE_TV)
2864 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2865 break;
2867 #endif /* CONFIG_TV_TELETEXT */
2868 #endif /* CONFIG_TV */
2870 case MP_CMD_SUB_LOAD:
2871 if (sh_video) {
2872 int n = mpctx->set_of_sub_size;
2873 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2874 if (n != mpctx->set_of_sub_size) {
2875 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2876 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2877 mpctx->global_sub_size;
2878 ++mpctx->global_sub_size;
2881 break;
2883 case MP_CMD_SUB_REMOVE:
2884 if (sh_video) {
2885 int v = cmd->args[0].v.i;
2886 sub_data *subd;
2887 if (v < 0) {
2888 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2889 subd = mpctx->set_of_subtitles[v];
2890 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2891 MSGTR_RemovedSubtitleFile, v + 1,
2892 filename_recode(subd->filename));
2893 sub_free(subd);
2894 mpctx->set_of_subtitles[v] = NULL;
2896 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2897 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2898 mpctx->set_of_sub_size = 0;
2899 if (mpctx->set_of_sub_pos >= 0) {
2900 mpctx->global_sub_pos = -2;
2901 subdata = NULL;
2902 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2904 } else if (v < mpctx->set_of_sub_size) {
2905 subd = mpctx->set_of_subtitles[v];
2906 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2907 MSGTR_RemovedSubtitleFile, v + 1,
2908 filename_recode(subd->filename));
2909 sub_free(subd);
2910 if (mpctx->set_of_sub_pos == v) {
2911 mpctx->global_sub_pos = -2;
2912 subdata = NULL;
2913 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2914 } else if (mpctx->set_of_sub_pos > v) {
2915 --mpctx->set_of_sub_pos;
2916 --mpctx->global_sub_pos;
2918 while (++v < mpctx->set_of_sub_size)
2919 mpctx->set_of_subtitles[v - 1] =
2920 mpctx->set_of_subtitles[v];
2921 --mpctx->set_of_sub_size;
2922 --mpctx->global_sub_size;
2923 if (mpctx->set_of_sub_size <= 0)
2924 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2925 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2928 break;
2930 case MP_CMD_GET_SUB_VISIBILITY:
2931 if (sh_video) {
2932 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2933 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2935 break;
2937 case MP_CMD_SCREENSHOT:
2938 if (vo_config_count) {
2939 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2940 if (CONTROL_OK !=
2941 ((vf_instance_t *) sh_video->vfilter)->
2942 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2943 &cmd->args[0].v.i))
2944 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2946 break;
2948 case MP_CMD_VF_CHANGE_RECTANGLE:
2949 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2950 break;
2952 case MP_CMD_GET_TIME_LENGTH:{
2953 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2954 demuxer_get_time_length(mpctx->demuxer));
2956 break;
2958 case MP_CMD_GET_FILENAME:{
2959 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2960 get_metadata(META_NAME));
2962 break;
2964 case MP_CMD_GET_VIDEO_CODEC:{
2965 char *inf = get_metadata(META_VIDEO_CODEC);
2966 if (!inf)
2967 inf = strdup("");
2968 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2969 free(inf);
2971 break;
2973 case MP_CMD_GET_VIDEO_BITRATE:{
2974 char *inf = get_metadata(META_VIDEO_BITRATE);
2975 if (!inf)
2976 inf = strdup("");
2977 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2978 free(inf);
2980 break;
2982 case MP_CMD_GET_VIDEO_RESOLUTION:{
2983 char *inf = get_metadata(META_VIDEO_RESOLUTION);
2984 if (!inf)
2985 inf = strdup("");
2986 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2987 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
2988 free(inf);
2990 break;
2992 case MP_CMD_GET_AUDIO_CODEC:{
2993 char *inf = get_metadata(META_AUDIO_CODEC);
2994 if (!inf)
2995 inf = strdup("");
2996 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
2997 free(inf);
2999 break;
3001 case MP_CMD_GET_AUDIO_BITRATE:{
3002 char *inf = get_metadata(META_AUDIO_BITRATE);
3003 if (!inf)
3004 inf = strdup("");
3005 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3006 free(inf);
3008 break;
3010 case MP_CMD_GET_AUDIO_SAMPLES:{
3011 char *inf = get_metadata(META_AUDIO_SAMPLES);
3012 if (!inf)
3013 inf = strdup("");
3014 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3015 free(inf);
3017 break;
3019 case MP_CMD_GET_META_TITLE:{
3020 char *inf = get_metadata(META_INFO_TITLE);
3021 if (!inf)
3022 inf = strdup("");
3023 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3024 free(inf);
3026 break;
3028 case MP_CMD_GET_META_ARTIST:{
3029 char *inf = get_metadata(META_INFO_ARTIST);
3030 if (!inf)
3031 inf = strdup("");
3032 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3033 free(inf);
3035 break;
3037 case MP_CMD_GET_META_ALBUM:{
3038 char *inf = get_metadata(META_INFO_ALBUM);
3039 if (!inf)
3040 inf = strdup("");
3041 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3042 free(inf);
3044 break;
3046 case MP_CMD_GET_META_YEAR:{
3047 char *inf = get_metadata(META_INFO_YEAR);
3048 if (!inf)
3049 inf = strdup("");
3050 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3051 free(inf);
3053 break;
3055 case MP_CMD_GET_META_COMMENT:{
3056 char *inf = get_metadata(META_INFO_COMMENT);
3057 if (!inf)
3058 inf = strdup("");
3059 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3060 free(inf);
3062 break;
3064 case MP_CMD_GET_META_TRACK:{
3065 char *inf = get_metadata(META_INFO_TRACK);
3066 if (!inf)
3067 inf = strdup("");
3068 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3069 free(inf);
3071 break;
3073 case MP_CMD_GET_META_GENRE:{
3074 char *inf = get_metadata(META_INFO_GENRE);
3075 if (!inf)
3076 inf = strdup("");
3077 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3078 free(inf);
3080 break;
3082 case MP_CMD_GET_VO_FULLSCREEN:
3083 if (mpctx->video_out && vo_config_count)
3084 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3085 break;
3087 case MP_CMD_GET_PERCENT_POS:
3088 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3089 demuxer_get_percent_pos(mpctx->demuxer));
3090 break;
3092 case MP_CMD_GET_TIME_POS:{
3093 float pos = 0;
3094 if (sh_video)
3095 pos = sh_video->pts;
3096 else if (sh_audio && mpctx->audio_out)
3097 pos =
3098 playing_audio_pts(sh_audio, mpctx->d_audio,
3099 mpctx->audio_out);
3100 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3102 break;
3104 case MP_CMD_RUN:
3105 #ifndef __MINGW32__
3106 if (!fork()) {
3107 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3108 exit(0);
3110 #endif
3111 break;
3113 case MP_CMD_KEYDOWN_EVENTS:
3114 mplayer_put_key(cmd->args[0].v.i);
3115 break;
3117 case MP_CMD_SET_MOUSE_POS:{
3118 int pointer_x, pointer_y;
3119 double dx, dy;
3120 pointer_x = cmd->args[0].v.i;
3121 pointer_y = cmd->args[1].v.i;
3122 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
3123 #ifdef CONFIG_DVDNAV
3124 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3125 && dx > 0.0 && dy > 0.0) {
3126 int button = -1;
3127 pointer_x = (int) (dx * (double) sh_video->disp_w);
3128 pointer_y = (int) (dy * (double) sh_video->disp_h);
3129 mp_dvdnav_update_mouse_pos(mpctx->stream,
3130 pointer_x, pointer_y, &button);
3131 if (osd_level > 1 && button > 0)
3132 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3133 "Selected button number %d", button);
3135 #endif
3136 #ifdef CONFIG_MENU
3137 if (use_menu && dx >= 0.0 && dy >= 0.0)
3138 menu_update_mouse_pos(dx, dy);
3139 #endif
3141 break;
3143 #ifdef CONFIG_DVDNAV
3144 case MP_CMD_DVDNAV:{
3145 int button = -1;
3146 int i;
3147 mp_command_type command = 0;
3148 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3149 break;
3151 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3152 if (cmd->args[0].v.s &&
3153 !strcasecmp (cmd->args[0].v.s,
3154 mp_dvdnav_bindings[i].name))
3155 command = mp_dvdnav_bindings[i].cmd;
3157 mp_dvdnav_handle_input(mpctx->stream,command,&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 break;
3164 case MP_CMD_SWITCH_TITLE:
3165 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3166 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3167 break;
3169 #endif
3171 default:
3172 #ifdef CONFIG_GUI
3173 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3174 guiGetEvent(guiIEvent, (char *) cmd->id);
3175 else
3176 #endif
3177 mp_msg(MSGT_CPLAYER, MSGL_V,
3178 "Received unknown cmd %s\n", cmd->name);
3181 switch (cmd->pausing) {
3182 case 1: // "pausing"
3183 mpctx->osd_function = OSD_PAUSE;
3184 break;
3185 case 3: // "pausing_toggle"
3186 mpctx->was_paused = !mpctx->was_paused;
3187 if (mpctx->was_paused)
3188 mpctx->osd_function = OSD_PAUSE;
3189 else if (mpctx->osd_function == OSD_PAUSE)
3190 mpctx->osd_function = OSD_PLAY;
3191 break;
3192 case 2: // "pausing_keep"
3193 if (mpctx->was_paused)
3194 mpctx->osd_function = OSD_PAUSE;
3196 return brk_cmd;