Fix segfault if an 'strf' chunk couldn't be found in avi
[mplayer/glamo.git] / command.c
blobddfb85dbb2c59986792a232467e76288d88e651b
1 #include <stdlib.h>
2 #include <inttypes.h>
3 #include <unistd.h>
4 #include <string.h>
6 #include "config.h"
7 #include "input/input.h"
8 #include "stream/stream.h"
9 #include "libmpdemux/demuxer.h"
10 #include "libmpdemux/stheader.h"
11 #include "codec-cfg.h"
12 #include "mplayer.h"
13 #include "libvo/sub.h"
14 #include "m_option.h"
15 #include "m_property.h"
16 #include "help_mp.h"
17 #include "metadata.h"
18 #include "libmpcodecs/mp_image.h"
19 #include "libmpcodecs/vf.h"
20 #include "libmpcodecs/vd.h"
21 #include "libvo/video_out.h"
22 #include "libvo/font_load.h"
23 #include "playtree.h"
24 #include "libao2/audio_out.h"
25 #include "mpcommon.h"
26 #include "mixer.h"
27 #include "libmpdemux/matroska.h"
28 #include "libmpcodecs/dec_video.h"
29 #include "vobsub.h"
30 #include "spudec.h"
31 #ifdef USE_TV
32 #include "stream/tv.h"
33 #endif
34 #ifdef USE_RADIO
35 #include "stream/stream_radio.h"
36 #endif
37 #ifdef HAVE_PVR
38 #include "stream/pvr.h"
39 #endif
40 #ifdef HAS_DVBIN_SUPPORT
41 #include "stream/dvbin.h"
42 #endif
43 #ifdef USE_DVDREAD
44 #include "stream/stream_dvd.h"
45 #endif
46 #ifdef USE_DVDNAV
47 #include "stream/stream_dvdnav.h"
48 #endif
49 #ifdef USE_ASS
50 #include "libass/ass.h"
51 #include "libass/ass_mp.h"
52 #endif
53 #ifdef HAVE_NEW_GUI
54 #include "gui/interface.h"
55 #endif
57 #include "mp_core.h"
59 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
61 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy)
63 //remove the borders, if any, and rescale to the range [0,1],[0,1]
64 if (vo_fs) { //we are in full-screen mode
65 if (vo_screenwidth > vo_dwidth) //there are borders along the x axis
66 ix -= (vo_screenwidth - vo_dwidth) / 2;
67 if (vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
68 iy -= (vo_screenheight - vo_dheight) / 2;
70 if (ix < 0 || ix > vo_dwidth) {
71 *dx = *dy = -1.0;
72 return;
73 } //we are on one of the borders
74 if (iy < 0 || iy > vo_dheight) {
75 *dx = *dy = -1.0;
76 return;
77 } //we are on one of the borders
80 *dx = (double) ix / (double) vo_dwidth;
81 *dy = (double) iy / (double) vo_dheight;
83 mp_msg(MSGT_CPLAYER, MSGL_V,
84 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
85 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth,
86 vo_dheight, vo_fs);
89 static int sub_source(MPContext * mpctx)
91 int source = -1;
92 int top = -1;
93 int i;
94 for (i = 0; i < SUB_SOURCES; i++) {
95 int j = mpctx->global_sub_indices[i];
96 if ((j >= 0) && (j > top) && (mpctx->global_sub_pos >= j)) {
97 source = i;
98 top = j;
101 return source;
105 * \brief Log the currently displayed subtitle to a file
107 * Logs the current or last displayed subtitle together with filename
108 * and time information to ~/.mplayer/subtitle_log
110 * Intended purpose is to allow convenient marking of bogus subtitles
111 * which need to be fixed while watching the movie.
114 static void log_sub(void)
116 char *fname;
117 FILE *f;
118 int i;
120 if (subdata == NULL || vo_sub_last == NULL)
121 return;
122 fname = get_path("subtitle_log");
123 f = fopen(fname, "a");
124 if (!f)
125 return;
126 fprintf(f, "----------------------------------------------------------\n");
127 if (subdata->sub_uses_time) {
128 fprintf(f,
129 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
130 filename, vo_sub_last->start / 360000,
131 (vo_sub_last->start / 6000) % 60,
132 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
133 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
134 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
135 } else {
136 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start,
137 vo_sub_last->end);
139 for (i = 0; i < vo_sub_last->lines; i++) {
140 fprintf(f, "%s\n", vo_sub_last->text[i]);
142 fclose(f);
146 /// \defgroup Properties
147 ///@{
149 /// \defgroup GeneralProperties General properties
150 /// \ingroup Properties
151 ///@{
153 /// OSD level (RW)
154 static int mp_property_osdlevel(m_option_t * prop, int action, void *arg,
155 MPContext * mpctx)
157 return m_property_choice(prop, action, arg, &osd_level);
160 /// Loop (RW)
161 static int mp_property_loop(m_option_t * prop, int action, void *arg,
162 MPContext * mpctx)
164 switch (action) {
165 case M_PROPERTY_PRINT:
166 if (!arg) return M_PROPERTY_ERROR;
167 if (mpctx->loop_times < 0)
168 *(char**)arg = strdup("off");
169 else if (mpctx->loop_times == 0)
170 *(char**)arg = strdup("inf");
171 else
172 break;
173 return M_PROPERTY_OK;
175 return m_property_int_range(prop, action, arg, &mpctx->loop_times);
178 /// Playback speed (RW)
179 static int mp_property_playback_speed(m_option_t * prop, int action,
180 void *arg, MPContext * mpctx)
182 switch (action) {
183 case M_PROPERTY_SET:
184 if (!arg)
185 return M_PROPERTY_ERROR;
186 M_PROPERTY_CLAMP(prop, *(float *) arg);
187 playback_speed = *(float *) arg;
188 build_afilter_chain(mpctx->sh_audio, &ao_data);
189 return M_PROPERTY_OK;
190 case M_PROPERTY_STEP_UP:
191 case M_PROPERTY_STEP_DOWN:
192 playback_speed += (arg ? *(float *) arg : 0.1) *
193 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
194 M_PROPERTY_CLAMP(prop, playback_speed);
195 build_afilter_chain(mpctx->sh_audio, &ao_data);
196 return M_PROPERTY_OK;
198 return m_property_float_range(prop, action, arg, &playback_speed);
201 /// filename with path (RO)
202 static int mp_property_path(m_option_t * prop, int action, void *arg,
203 MPContext * mpctx)
205 return m_property_string_ro(prop, action, arg, filename);
208 /// filename without path (RO)
209 static int mp_property_filename(m_option_t * prop, int action, void *arg,
210 MPContext * mpctx)
212 char *f;
213 if (!filename)
214 return M_PROPERTY_UNAVAILABLE;
215 if (((f = strrchr(filename, '/')) || (f = strrchr(filename, '\\'))) && f[1])
216 f++;
217 else
218 f = filename;
219 return m_property_string_ro(prop, action, arg, f);
222 /// Demuxer name (RO)
223 static int mp_property_demuxer(m_option_t * prop, int action, void *arg,
224 MPContext * mpctx)
226 if (!mpctx->demuxer)
227 return M_PROPERTY_UNAVAILABLE;
228 return m_property_string_ro(prop, action, arg,
229 (char *) mpctx->demuxer->desc->name);
232 /// Position in the stream (RW)
233 static int mp_property_stream_pos(m_option_t * prop, int action, void *arg,
234 MPContext * mpctx)
236 if (!mpctx->demuxer || !mpctx->demuxer->stream)
237 return M_PROPERTY_UNAVAILABLE;
238 if (!arg)
239 return M_PROPERTY_ERROR;
240 switch (action) {
241 case M_PROPERTY_GET:
242 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
243 return M_PROPERTY_OK;
244 case M_PROPERTY_SET:
245 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
246 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
247 return M_PROPERTY_OK;
249 return M_PROPERTY_NOT_IMPLEMENTED;
252 /// Stream start offset (RO)
253 static int mp_property_stream_start(m_option_t * prop, int action,
254 void *arg, MPContext * mpctx)
256 if (!mpctx->demuxer || !mpctx->demuxer->stream)
257 return M_PROPERTY_UNAVAILABLE;
258 switch (action) {
259 case M_PROPERTY_GET:
260 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
261 return M_PROPERTY_OK;
263 return M_PROPERTY_NOT_IMPLEMENTED;
266 /// Stream end offset (RO)
267 static int mp_property_stream_end(m_option_t * prop, int action, void *arg,
268 MPContext * mpctx)
270 if (!mpctx->demuxer || !mpctx->demuxer->stream)
271 return M_PROPERTY_UNAVAILABLE;
272 switch (action) {
273 case M_PROPERTY_GET:
274 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
275 return M_PROPERTY_OK;
277 return M_PROPERTY_NOT_IMPLEMENTED;
280 /// Stream length (RO)
281 static int mp_property_stream_length(m_option_t * prop, int action,
282 void *arg, MPContext * mpctx)
284 if (!mpctx->demuxer || !mpctx->demuxer->stream)
285 return M_PROPERTY_UNAVAILABLE;
286 switch (action) {
287 case M_PROPERTY_GET:
288 *(off_t *) arg =
289 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
290 return M_PROPERTY_OK;
292 return M_PROPERTY_NOT_IMPLEMENTED;
295 /// Media length in seconds (RO)
296 static int mp_property_length(m_option_t * prop, int action, void *arg,
297 MPContext * mpctx)
299 double len;
301 if (!mpctx->demuxer ||
302 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
303 return M_PROPERTY_UNAVAILABLE;
305 return m_property_time_ro(prop, action, arg, len);
308 /// Current position in percent (RW)
309 static int mp_property_percent_pos(m_option_t * prop, int action,
310 void *arg, MPContext * mpctx) {
311 int pos;
313 if (!mpctx->demuxer)
314 return M_PROPERTY_UNAVAILABLE;
316 switch(action) {
317 case M_PROPERTY_SET:
318 if(!arg) return M_PROPERTY_ERROR;
319 M_PROPERTY_CLAMP(prop, *(int*)arg);
320 pos = *(int*)arg;
321 break;
322 case M_PROPERTY_STEP_UP:
323 case M_PROPERTY_STEP_DOWN:
324 pos = demuxer_get_percent_pos(mpctx->demuxer);
325 pos += (arg ? *(int*)arg : 10) *
326 (action == M_PROPERTY_STEP_UP ? 1 : -1);
327 M_PROPERTY_CLAMP(prop, pos);
328 break;
329 default:
330 return m_property_int_ro(prop, action, arg,
331 demuxer_get_percent_pos(mpctx->demuxer));
334 abs_seek_pos = 3;
335 rel_seek_secs = pos / 100.0;
336 return M_PROPERTY_OK;
339 /// Current position in seconds (RW)
340 static int mp_property_time_pos(m_option_t * prop, int action,
341 void *arg, MPContext * mpctx) {
342 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
343 return M_PROPERTY_UNAVAILABLE;
345 switch(action) {
346 case M_PROPERTY_SET:
347 if(!arg) return M_PROPERTY_ERROR;
348 M_PROPERTY_CLAMP(prop, *(double*)arg);
349 abs_seek_pos = 1;
350 rel_seek_secs = *(double*)arg;
351 return M_PROPERTY_OK;
352 case M_PROPERTY_STEP_UP:
353 case M_PROPERTY_STEP_DOWN:
354 rel_seek_secs += (arg ? *(double*)arg : 10.0) *
355 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
356 return M_PROPERTY_OK;
358 return m_property_time_ro(prop, action, arg,
359 mpctx->sh_video ? mpctx->sh_video->pts :
360 playing_audio_pts(mpctx->sh_audio,
361 mpctx->d_audio,
362 mpctx->audio_out));
365 /// Demuxer meta data
366 static int mp_property_metadata(m_option_t * prop, int action, void *arg,
367 MPContext * mpctx) {
368 m_property_action_t* ka;
369 char* meta;
370 static m_option_t key_type =
371 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
372 if (!mpctx->demuxer)
373 return M_PROPERTY_UNAVAILABLE;
375 switch(action) {
376 case M_PROPERTY_GET:
377 if(!arg) return M_PROPERTY_ERROR;
378 *(char***)arg = mpctx->demuxer->info;
379 return M_PROPERTY_OK;
380 case M_PROPERTY_KEY_ACTION:
381 if(!arg) return M_PROPERTY_ERROR;
382 ka = arg;
383 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
384 return M_PROPERTY_UNKNOWN;
385 switch(ka->action) {
386 case M_PROPERTY_GET:
387 if(!ka->arg) return M_PROPERTY_ERROR;
388 *(char**)ka->arg = meta;
389 return M_PROPERTY_OK;
390 case M_PROPERTY_GET_TYPE:
391 if(!ka->arg) return M_PROPERTY_ERROR;
392 *(m_option_t**)ka->arg = &key_type;
393 return M_PROPERTY_OK;
396 return M_PROPERTY_NOT_IMPLEMENTED;
400 ///@}
402 /// \defgroup AudioProperties Audio properties
403 /// \ingroup Properties
404 ///@{
406 /// Volume (RW)
407 static int mp_property_volume(m_option_t * prop, int action, void *arg,
408 MPContext * mpctx)
411 if (!mpctx->sh_audio)
412 return M_PROPERTY_UNAVAILABLE;
414 switch (action) {
415 case M_PROPERTY_GET:
416 if (!arg)
417 return M_PROPERTY_ERROR;
418 mixer_getbothvolume(&mpctx->mixer, arg);
419 return M_PROPERTY_OK;
420 case M_PROPERTY_PRINT:{
421 float vol;
422 if (!arg)
423 return M_PROPERTY_ERROR;
424 mixer_getbothvolume(&mpctx->mixer, &vol);
425 return m_property_float_range(prop, action, arg, &vol);
427 case M_PROPERTY_STEP_UP:
428 case M_PROPERTY_STEP_DOWN:
429 case M_PROPERTY_SET:
430 break;
431 default:
432 return M_PROPERTY_NOT_IMPLEMENTED;
435 if (mpctx->edl_muted)
436 return M_PROPERTY_DISABLED;
437 mpctx->user_muted = 0;
439 switch (action) {
440 case M_PROPERTY_SET:
441 if (!arg)
442 return M_PROPERTY_ERROR;
443 M_PROPERTY_CLAMP(prop, *(float *) arg);
444 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
445 return M_PROPERTY_OK;
446 case M_PROPERTY_STEP_UP:
447 if (arg && *(float *) arg <= 0)
448 mixer_decvolume(&mpctx->mixer);
449 else
450 mixer_incvolume(&mpctx->mixer);
451 return M_PROPERTY_OK;
452 case M_PROPERTY_STEP_DOWN:
453 if (arg && *(float *) arg <= 0)
454 mixer_incvolume(&mpctx->mixer);
455 else
456 mixer_decvolume(&mpctx->mixer);
457 return M_PROPERTY_OK;
459 return M_PROPERTY_NOT_IMPLEMENTED;
462 /// Mute (RW)
463 static int mp_property_mute(m_option_t * prop, int action, void *arg,
464 MPContext * mpctx)
467 if (!mpctx->sh_audio)
468 return M_PROPERTY_UNAVAILABLE;
470 switch (action) {
471 case M_PROPERTY_SET:
472 if (mpctx->edl_muted)
473 return M_PROPERTY_DISABLED;
474 if (!arg)
475 return M_PROPERTY_ERROR;
476 if ((!!*(int *) arg) != mpctx->mixer.muted)
477 mixer_mute(&mpctx->mixer);
478 mpctx->user_muted = mpctx->mixer.muted;
479 return M_PROPERTY_OK;
480 case M_PROPERTY_STEP_UP:
481 case M_PROPERTY_STEP_DOWN:
482 if (mpctx->edl_muted)
483 return M_PROPERTY_DISABLED;
484 mixer_mute(&mpctx->mixer);
485 mpctx->user_muted = mpctx->mixer.muted;
486 return M_PROPERTY_OK;
487 case M_PROPERTY_PRINT:
488 if (!arg)
489 return M_PROPERTY_ERROR;
490 if (mpctx->edl_muted) {
491 *(char **) arg = strdup(MSGTR_EnabledEdl);
492 return M_PROPERTY_OK;
494 default:
495 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
500 /// Audio delay (RW)
501 static int mp_property_audio_delay(m_option_t * prop, int action,
502 void *arg, MPContext * mpctx)
504 if (!(mpctx->sh_audio && mpctx->sh_video))
505 return M_PROPERTY_UNAVAILABLE;
506 switch (action) {
507 case M_PROPERTY_SET:
508 case M_PROPERTY_STEP_UP:
509 case M_PROPERTY_STEP_DOWN:
510 if (!arg)
511 return M_PROPERTY_ERROR;
512 else {
513 float delay = audio_delay;
514 m_property_delay(prop, action, arg, &audio_delay);
515 if (mpctx->sh_audio)
516 mpctx->delay -= audio_delay - delay;
518 return M_PROPERTY_OK;
519 default:
520 return m_property_delay(prop, action, arg, &audio_delay);
524 /// Audio codec tag (RO)
525 static int mp_property_audio_format(m_option_t * prop, int action,
526 void *arg, MPContext * mpctx)
528 if (!mpctx->sh_audio)
529 return M_PROPERTY_UNAVAILABLE;
530 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
533 /// Audio codec name (RO)
534 static int mp_property_audio_codec(m_option_t * prop, int action,
535 void *arg, MPContext * mpctx)
537 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
538 return M_PROPERTY_UNAVAILABLE;
539 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
542 /// Audio bitrate (RO)
543 static int mp_property_audio_bitrate(m_option_t * prop, int action,
544 void *arg, MPContext * mpctx)
546 if (!mpctx->sh_audio)
547 return M_PROPERTY_UNAVAILABLE;
548 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
551 /// Samplerate (RO)
552 static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
553 MPContext * mpctx)
555 if (!mpctx->sh_audio)
556 return M_PROPERTY_UNAVAILABLE;
557 switch(action) {
558 case M_PROPERTY_PRINT:
559 if(!arg) return M_PROPERTY_ERROR;
560 *(char**)arg = malloc(16);
561 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
562 return M_PROPERTY_OK;
564 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
567 /// Number of channels (RO)
568 static int mp_property_channels(m_option_t * prop, int action, void *arg,
569 MPContext * mpctx)
571 if (!mpctx->sh_audio)
572 return M_PROPERTY_UNAVAILABLE;
573 switch (action) {
574 case M_PROPERTY_PRINT:
575 if (!arg)
576 return M_PROPERTY_ERROR;
577 switch (mpctx->sh_audio->channels) {
578 case 1:
579 *(char **) arg = strdup("mono");
580 break;
581 case 2:
582 *(char **) arg = strdup("stereo");
583 break;
584 default:
585 *(char **) arg = malloc(32);
586 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
588 return M_PROPERTY_OK;
590 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
593 /// Balance (RW)
594 static int mp_property_balance(m_option_t * prop, int action, void *arg,
595 MPContext * mpctx)
597 float bal;
599 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
600 return M_PROPERTY_UNAVAILABLE;
602 switch (action) {
603 case M_PROPERTY_GET:
604 if (!arg)
605 return M_PROPERTY_ERROR;
606 mixer_getbalance(&mpctx->mixer, arg);
607 return M_PROPERTY_OK;
608 case M_PROPERTY_PRINT: {
609 char** str = arg;
610 if (!arg)
611 return M_PROPERTY_ERROR;
612 mixer_getbalance(&mpctx->mixer, &bal);
613 if (bal == 0.f)
614 *str = strdup("center");
615 else if (bal == -1.f)
616 *str = strdup("left only");
617 else if (bal == 1.f)
618 *str = strdup("right only");
619 else {
620 unsigned right = (bal + 1.f) / 2.f * 100.f;
621 *str = malloc(sizeof("left xxx%, right xxx%"));
622 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
624 return M_PROPERTY_OK;
626 case M_PROPERTY_STEP_UP:
627 case M_PROPERTY_STEP_DOWN:
628 mixer_getbalance(&mpctx->mixer, &bal);
629 bal += (arg ? *(float*)arg : .1f) *
630 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
631 M_PROPERTY_CLAMP(prop, bal);
632 mixer_setbalance(&mpctx->mixer, bal);
633 return M_PROPERTY_OK;
634 case M_PROPERTY_SET:
635 if (!arg)
636 return M_PROPERTY_ERROR;
637 M_PROPERTY_CLAMP(prop, *(float*)arg);
638 mixer_setbalance(&mpctx->mixer, *(float*)arg);
639 return M_PROPERTY_OK;
641 return M_PROPERTY_NOT_IMPLEMENTED;
644 /// Selected audio id (RW)
645 static int mp_property_audio(m_option_t * prop, int action, void *arg,
646 MPContext * mpctx)
648 int current_id = -1, tmp;
650 switch (action) {
651 case M_PROPERTY_GET:
652 if (!mpctx->sh_audio)
653 return M_PROPERTY_UNAVAILABLE;
654 if (!arg)
655 return M_PROPERTY_ERROR;
656 *(int *) arg = audio_id;
657 return M_PROPERTY_OK;
658 case M_PROPERTY_PRINT:
659 if (!mpctx->sh_audio)
660 return M_PROPERTY_UNAVAILABLE;
661 if (!arg)
662 return M_PROPERTY_ERROR;
664 if (audio_id < 0)
665 *(char **) arg = strdup(MSGTR_Disabled);
666 else {
667 char lang[40] = MSGTR_Unknown;
668 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA)
669 demux_mkv_get_audio_lang(mpctx->demuxer, audio_id, lang, 9);
670 #ifdef USE_DVDREAD
671 else if (mpctx->stream->type == STREAMTYPE_DVD) {
672 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
673 if (code) {
674 lang[0] = code >> 8;
675 lang[1] = code;
676 lang[2] = 0;
679 #endif
681 #ifdef USE_DVDNAV
682 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
683 dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
684 #endif
685 *(char **) arg = malloc(64);
686 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
688 return M_PROPERTY_OK;
690 case M_PROPERTY_STEP_UP:
691 case M_PROPERTY_SET:
692 if (action == M_PROPERTY_SET && arg)
693 tmp = *((int *) arg);
694 else
695 tmp = -1;
696 current_id = mpctx->demuxer->audio->id;
697 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
698 if (audio_id == -2
699 || (audio_id > -1
700 && mpctx->demuxer->audio->id != current_id && current_id != -2))
701 uninit_player(INITED_AO | INITED_ACODEC);
702 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
703 sh_audio_t *sh2;
704 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
705 if (sh2) {
706 sh2->ds = mpctx->demuxer->audio;
707 mpctx->sh_audio = sh2;
708 reinit_audio_chain();
711 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
712 return M_PROPERTY_OK;
713 default:
714 return M_PROPERTY_NOT_IMPLEMENTED;
719 /// Selected video id (RW)
720 static int mp_property_video(m_option_t * prop, int action, void *arg,
721 MPContext * mpctx)
723 int current_id = -1, tmp;
725 switch (action) {
726 case M_PROPERTY_GET:
727 if (!mpctx->sh_video)
728 return M_PROPERTY_UNAVAILABLE;
729 if (!arg)
730 return M_PROPERTY_ERROR;
731 *(int *) arg = video_id;
732 return M_PROPERTY_OK;
733 case M_PROPERTY_PRINT:
734 if (!mpctx->sh_video)
735 return M_PROPERTY_UNAVAILABLE;
736 if (!arg)
737 return M_PROPERTY_ERROR;
739 if (video_id < 0)
740 *(char **) arg = strdup(MSGTR_Disabled);
741 else {
742 char lang[40] = MSGTR_Unknown;
743 *(char **) arg = malloc(64);
744 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
746 return M_PROPERTY_OK;
748 case M_PROPERTY_STEP_UP:
749 case M_PROPERTY_SET:
750 current_id = mpctx->demuxer->video->id;
751 if (action == M_PROPERTY_SET && arg)
752 tmp = *((int *) arg);
753 else
754 tmp = -1;
755 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
756 if (video_id == -2
757 || (video_id > -1 && mpctx->demuxer->video->id != current_id
758 && current_id != -2))
759 uninit_player(INITED_VCODEC |
760 (fixed_vo && video_id != -2 ? 0 : INITED_VO));
761 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
762 sh_video_t *sh2;
763 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
764 if (sh2) {
765 sh2->ds = mpctx->demuxer->video;
766 mpctx->sh_video = sh2;
767 reinit_video_chain();
770 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
771 return M_PROPERTY_OK;
773 default:
774 return M_PROPERTY_NOT_IMPLEMENTED;
778 static int mp_property_program(m_option_t * prop, int action, void *arg,
779 MPContext * mpctx)
781 demux_program_t prog;
783 switch (action) {
784 case M_PROPERTY_STEP_UP:
785 case M_PROPERTY_SET:
786 if (action == M_PROPERTY_SET && arg)
787 prog.progid = *((int *) arg);
788 else
789 prog.progid = -1;
790 if (demux_control
791 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
792 &prog) == DEMUXER_CTRL_NOTIMPL)
793 return M_PROPERTY_ERROR;
795 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
796 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
797 return M_PROPERTY_OK;
799 default:
800 return M_PROPERTY_NOT_IMPLEMENTED;
804 ///@}
806 /// \defgroup VideoProperties Video properties
807 /// \ingroup Properties
808 ///@{
810 /// Fullscreen state (RW)
811 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
812 MPContext * mpctx)
815 if (!mpctx->video_out)
816 return M_PROPERTY_UNAVAILABLE;
818 switch (action) {
819 case M_PROPERTY_SET:
820 if (!arg)
821 return M_PROPERTY_ERROR;
822 M_PROPERTY_CLAMP(prop, *(int *) arg);
823 if (vo_fs == !!*(int *) arg)
824 return M_PROPERTY_OK;
825 case M_PROPERTY_STEP_UP:
826 case M_PROPERTY_STEP_DOWN:
827 #ifdef HAVE_NEW_GUI
828 if (use_gui)
829 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
830 else
831 #endif
832 if (vo_config_count)
833 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
834 return M_PROPERTY_OK;
835 default:
836 return m_property_flag(prop, action, arg, &vo_fs);
840 static int mp_property_deinterlace(m_option_t * prop, int action,
841 void *arg, MPContext * mpctx)
843 int deinterlace;
844 vf_instance_t *vf;
845 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
846 return M_PROPERTY_UNAVAILABLE;
847 vf = mpctx->sh_video->vfilter;
848 switch (action) {
849 case M_PROPERTY_GET:
850 if (!arg)
851 return M_PROPERTY_ERROR;
852 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
853 return M_PROPERTY_OK;
854 case M_PROPERTY_SET:
855 if (!arg)
856 return M_PROPERTY_ERROR;
857 M_PROPERTY_CLAMP(prop, *(int *) arg);
858 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
859 return M_PROPERTY_OK;
860 case M_PROPERTY_STEP_UP:
861 case M_PROPERTY_STEP_DOWN:
862 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
863 deinterlace = !deinterlace;
864 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
865 return M_PROPERTY_OK;
867 return M_PROPERTY_NOT_IMPLEMENTED;
870 /// Panscan (RW)
871 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
872 MPContext * mpctx)
875 if (!mpctx->video_out
876 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
877 return M_PROPERTY_UNAVAILABLE;
879 switch (action) {
880 case M_PROPERTY_SET:
881 if (!arg)
882 return M_PROPERTY_ERROR;
883 M_PROPERTY_CLAMP(prop, *(float *) arg);
884 vo_panscan = *(float *) arg;
885 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
886 return M_PROPERTY_OK;
887 case M_PROPERTY_STEP_UP:
888 case M_PROPERTY_STEP_DOWN:
889 vo_panscan += (arg ? *(float *) arg : 0.1) *
890 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
891 if (vo_panscan > 1)
892 vo_panscan = 1;
893 else if (vo_panscan < 0)
894 vo_panscan = 0;
895 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
896 return M_PROPERTY_OK;
897 default:
898 return m_property_float_range(prop, action, arg, &vo_panscan);
902 /// Helper to set vo flags.
903 /** \ingroup PropertyImplHelper
905 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
906 int vo_ctrl, int *vo_var, MPContext * mpctx)
909 if (!mpctx->video_out)
910 return M_PROPERTY_UNAVAILABLE;
912 switch (action) {
913 case M_PROPERTY_SET:
914 if (!arg)
915 return M_PROPERTY_ERROR;
916 M_PROPERTY_CLAMP(prop, *(int *) arg);
917 if (*vo_var == !!*(int *) arg)
918 return M_PROPERTY_OK;
919 case M_PROPERTY_STEP_UP:
920 case M_PROPERTY_STEP_DOWN:
921 if (vo_config_count)
922 mpctx->video_out->control(vo_ctrl, 0);
923 return M_PROPERTY_OK;
924 default:
925 return m_property_flag(prop, action, arg, vo_var);
929 /// Window always on top (RW)
930 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
931 MPContext * mpctx)
933 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
934 mpctx);
937 /// Display in the root window (RW)
938 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
939 MPContext * mpctx)
941 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
942 &vo_rootwin, mpctx);
945 /// Show window borders (RW)
946 static int mp_property_border(m_option_t * prop, int action, void *arg,
947 MPContext * mpctx)
949 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
950 &vo_border, mpctx);
953 /// Framedropping state (RW)
954 static int mp_property_framedropping(m_option_t * prop, int action,
955 void *arg, MPContext * mpctx)
958 if (!mpctx->sh_video)
959 return M_PROPERTY_UNAVAILABLE;
961 switch (action) {
962 case M_PROPERTY_PRINT:
963 if (!arg)
964 return M_PROPERTY_ERROR;
965 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
966 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
967 MSGTR_Disabled));
968 return M_PROPERTY_OK;
969 default:
970 return m_property_choice(prop, action, arg, &frame_dropping);
974 /// Color settings, try to use vf/vo then fall back on TV. (RW)
975 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
976 MPContext * mpctx)
978 int *gamma = prop->priv, r;
980 if (!mpctx->sh_video)
981 return M_PROPERTY_UNAVAILABLE;
983 if (gamma[0] == 1000) {
984 gamma[0] = 0;
985 get_video_colors(mpctx->sh_video, prop->name, gamma);
988 switch (action) {
989 case M_PROPERTY_SET:
990 if (!arg)
991 return M_PROPERTY_ERROR;
992 M_PROPERTY_CLAMP(prop, *(int *) arg);
993 *gamma = *(int *) arg;
994 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
995 if (r <= 0)
996 break;
997 return r;
998 case M_PROPERTY_GET:
999 if (!arg)
1000 return M_PROPERTY_ERROR;
1001 r = get_video_colors(mpctx->sh_video, prop->name, arg);
1002 if (r <= 0)
1003 break;
1004 return r;
1005 case M_PROPERTY_STEP_UP:
1006 case M_PROPERTY_STEP_DOWN:
1007 *gamma += (arg ? *(int *) arg : 1) *
1008 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1009 M_PROPERTY_CLAMP(prop, *gamma);
1010 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1011 if (r <= 0)
1012 break;
1013 return r;
1014 default:
1015 return M_PROPERTY_NOT_IMPLEMENTED;
1018 #ifdef USE_TV
1019 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1020 int l = strlen(prop->name);
1021 char tv_prop[3 + l + 1];
1022 sprintf(tv_prop, "tv_%s", prop->name);
1023 return mp_property_do(tv_prop, action, arg, mpctx);
1025 #endif
1027 return M_PROPERTY_UNAVAILABLE;
1030 /// VSync (RW)
1031 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1032 MPContext * mpctx)
1034 return m_property_flag(prop, action, arg, &vo_vsync);
1037 /// Video codec tag (RO)
1038 static int mp_property_video_format(m_option_t * prop, int action,
1039 void *arg, MPContext * mpctx)
1041 char* meta;
1042 if (!mpctx->sh_video)
1043 return M_PROPERTY_UNAVAILABLE;
1044 switch(action) {
1045 case M_PROPERTY_PRINT:
1046 if (!arg)
1047 return M_PROPERTY_ERROR;
1048 switch(mpctx->sh_video->format) {
1049 case 0x10000001:
1050 meta = strdup ("mpeg1"); break;
1051 case 0x10000002:
1052 meta = strdup ("mpeg2"); break;
1053 case 0x10000004:
1054 meta = strdup ("mpeg4"); break;
1055 case 0x10000005:
1056 meta = strdup ("h264"); break;
1057 default:
1058 if(mpctx->sh_video->format >= 0x20202020) {
1059 meta = malloc(5);
1060 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1061 } else {
1062 meta = malloc(20);
1063 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1066 *(char**)arg = meta;
1067 return M_PROPERTY_OK;
1069 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1072 /// Video codec name (RO)
1073 static int mp_property_video_codec(m_option_t * prop, int action,
1074 void *arg, MPContext * mpctx)
1076 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1077 return M_PROPERTY_UNAVAILABLE;
1078 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1082 /// Video bitrate (RO)
1083 static int mp_property_video_bitrate(m_option_t * prop, int action,
1084 void *arg, MPContext * mpctx)
1086 if (!mpctx->sh_video)
1087 return M_PROPERTY_UNAVAILABLE;
1088 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1091 /// Video display width (RO)
1092 static int mp_property_width(m_option_t * prop, int action, void *arg,
1093 MPContext * mpctx)
1095 if (!mpctx->sh_video)
1096 return M_PROPERTY_UNAVAILABLE;
1097 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1100 /// Video display height (RO)
1101 static int mp_property_height(m_option_t * prop, int action, void *arg,
1102 MPContext * mpctx)
1104 if (!mpctx->sh_video)
1105 return M_PROPERTY_UNAVAILABLE;
1106 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1109 /// Video fps (RO)
1110 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1111 MPContext * mpctx)
1113 if (!mpctx->sh_video)
1114 return M_PROPERTY_UNAVAILABLE;
1115 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1118 /// Video aspect (RO)
1119 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1120 MPContext * mpctx)
1122 if (!mpctx->sh_video)
1123 return M_PROPERTY_UNAVAILABLE;
1124 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1127 ///@}
1129 /// \defgroup SubProprties Subtitles properties
1130 /// \ingroup Properties
1131 ///@{
1133 /// Text subtitle position (RW)
1134 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1135 MPContext * mpctx)
1137 if (!mpctx->sh_video)
1138 return M_PROPERTY_UNAVAILABLE;
1140 switch (action) {
1141 case M_PROPERTY_SET:
1142 if (!arg)
1143 return M_PROPERTY_ERROR;
1144 case M_PROPERTY_STEP_UP:
1145 case M_PROPERTY_STEP_DOWN:
1146 vo_osd_changed(OSDTYPE_SUBTITLE);
1147 default:
1148 return m_property_int_range(prop, action, arg, &sub_pos);
1152 /// Selected subtitles (RW)
1153 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1154 MPContext * mpctx)
1156 demux_stream_t *const d_sub = mpctx->d_sub;
1157 const int global_sub_size = mpctx->global_sub_size;
1158 int source = -1, reset_spu = 0;
1159 char *sub_name;
1161 if (global_sub_size <= 0)
1162 return M_PROPERTY_UNAVAILABLE;
1164 switch (action) {
1165 case M_PROPERTY_GET:
1166 if (!arg)
1167 return M_PROPERTY_ERROR;
1168 *(int *) arg = mpctx->global_sub_pos;
1169 return M_PROPERTY_OK;
1170 case M_PROPERTY_PRINT:
1171 if (!arg)
1172 return M_PROPERTY_ERROR;
1173 *(char **) arg = malloc(64);
1174 (*(char **) arg)[63] = 0;
1175 sub_name = 0;
1176 if (subdata)
1177 sub_name = subdata->filename;
1178 #ifdef USE_ASS
1179 if (ass_track && ass_track->name)
1180 sub_name = ass_track->name;
1181 #endif
1182 if (sub_name) {
1183 char *tmp, *tmp2;
1184 tmp = sub_name;
1185 if ((tmp2 = strrchr(tmp, '/')))
1186 tmp = tmp2 + 1;
1188 snprintf(*(char **) arg, 63, "(%d) %s%s",
1189 mpctx->set_of_sub_pos + 1,
1190 strlen(tmp) < 20 ? "" : "...",
1191 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1192 return M_PROPERTY_OK;
1194 #ifdef USE_DVDNAV
1195 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1196 if (vo_spudec && dvdsub_id >= 0) {
1197 unsigned char lang[3];
1198 if (dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1199 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1200 return M_PROPERTY_OK;
1204 #endif
1206 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
1207 char lang[40] = MSGTR_Unknown;
1208 demux_mkv_get_sub_lang(mpctx->demuxer, dvdsub_id, lang, 9);
1209 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1210 return M_PROPERTY_OK;
1212 #ifdef HAVE_OGGVORBIS
1213 if (mpctx->demuxer->type == DEMUXER_TYPE_OGG && d_sub && dvdsub_id >= 0) {
1214 char *lang = demux_ogg_sub_lang(mpctx->demuxer, dvdsub_id);
1215 if (!lang)
1216 lang = MSGTR_Unknown;
1217 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1218 return M_PROPERTY_OK;
1220 #endif
1221 if (vo_vobsub && vobsub_id >= 0) {
1222 const char *language = MSGTR_Unknown;
1223 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1224 snprintf(*(char **) arg, 63, "(%d) %s",
1225 vobsub_id, language ? language : MSGTR_Unknown);
1226 return M_PROPERTY_OK;
1228 #ifdef USE_DVDREAD
1229 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1230 && dvdsub_id >= 0) {
1231 char lang[3];
1232 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1233 lang[0] = code >> 8;
1234 lang[1] = code;
1235 lang[2] = 0;
1236 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1237 return M_PROPERTY_OK;
1239 #endif
1240 if (dvdsub_id >= 0) {
1241 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1242 return M_PROPERTY_OK;
1244 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1245 return M_PROPERTY_OK;
1247 case M_PROPERTY_SET:
1248 if (!arg)
1249 return M_PROPERTY_ERROR;
1250 if (*(int *) arg < -1)
1251 *(int *) arg = -1;
1252 else if (*(int *) arg >= global_sub_size)
1253 *(int *) arg = global_sub_size - 1;
1254 mpctx->global_sub_pos = *(int *) arg;
1255 break;
1256 case M_PROPERTY_STEP_UP:
1257 mpctx->global_sub_pos += 2;
1258 mpctx->global_sub_pos =
1259 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1260 break;
1261 case M_PROPERTY_STEP_DOWN:
1262 mpctx->global_sub_pos += global_sub_size + 1;
1263 mpctx->global_sub_pos =
1264 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1265 break;
1266 default:
1267 return M_PROPERTY_NOT_IMPLEMENTED;
1270 if (mpctx->global_sub_pos >= 0)
1271 source = sub_source(mpctx);
1273 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1274 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1275 global_sub_size,
1276 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1277 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1278 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1279 mpctx->global_sub_pos, source);
1281 mpctx->set_of_sub_pos = -1;
1282 subdata = NULL;
1283 vo_sub_last = vo_sub = NULL;
1285 vobsub_id = -1;
1286 dvdsub_id = -1;
1287 if (d_sub) {
1288 if (d_sub->id > -2)
1289 reset_spu = 1;
1290 d_sub->id = -2;
1292 #ifdef USE_ASS
1293 ass_track = 0;
1294 #endif
1296 if (source == SUB_SOURCE_VOBSUB) {
1297 vobsub_id =
1298 mpctx->global_sub_pos -
1299 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB];
1300 } else if (source == SUB_SOURCE_SUBS) {
1301 mpctx->set_of_sub_pos =
1302 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1303 #ifdef USE_ASS
1304 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1305 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1306 else
1307 #endif
1309 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1310 vo_osd_changed(OSDTYPE_SUBTITLE);
1312 } else if (source == SUB_SOURCE_DEMUX) {
1313 dvdsub_id =
1314 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1315 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1316 int i = 0;
1317 // default: assume 1:1 mapping of sid and stream id
1318 d_sub->id = dvdsub_id;
1319 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1320 for (i = 0; i < MAX_S_STREAMS; i++) {
1321 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1322 if (sh && sh->sid == dvdsub_id) {
1323 d_sub->id = i;
1324 d_sub->sh = sh;
1325 break;
1328 if (d_sub->sh && d_sub->id >= 0) {
1329 sh_sub_t *sh = d_sub->sh;
1330 if (sh->type == 'v')
1331 init_vo_spudec();
1332 #ifdef USE_ASS
1333 else if (ass_enabled && sh->type == 'a')
1334 ass_track = sh->ass_track;
1335 #endif
1339 #ifdef USE_DVDREAD
1340 if (vo_spudec
1341 && (mpctx->stream->type == STREAMTYPE_DVD
1342 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1343 && dvdsub_id < 0 && reset_spu) {
1344 dvdsub_id = -2;
1345 d_sub->id = dvdsub_id;
1347 #endif
1348 update_subtitles(mpctx->sh_video, d_sub, 1);
1350 return M_PROPERTY_OK;
1353 /// Subtitle delay (RW)
1354 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1355 MPContext * mpctx)
1357 if (!mpctx->sh_video)
1358 return M_PROPERTY_UNAVAILABLE;
1359 return m_property_delay(prop, action, arg, &sub_delay);
1362 /// Alignment of text subtitles (RW)
1363 static int mp_property_sub_alignment(m_option_t * prop, int action,
1364 void *arg, MPContext * mpctx)
1366 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1368 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1369 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1370 return M_PROPERTY_UNAVAILABLE;
1372 switch (action) {
1373 case M_PROPERTY_PRINT:
1374 if (!arg)
1375 return M_PROPERTY_ERROR;
1376 M_PROPERTY_CLAMP(prop, sub_alignment);
1377 *(char **) arg = strdup(name[sub_alignment]);
1378 return M_PROPERTY_OK;
1379 case M_PROPERTY_SET:
1380 if (!arg)
1381 return M_PROPERTY_ERROR;
1382 case M_PROPERTY_STEP_UP:
1383 case M_PROPERTY_STEP_DOWN:
1384 vo_osd_changed(OSDTYPE_SUBTITLE);
1385 default:
1386 return m_property_choice(prop, action, arg, &sub_alignment);
1390 /// Subtitle visibility (RW)
1391 static int mp_property_sub_visibility(m_option_t * prop, int action,
1392 void *arg, MPContext * mpctx)
1394 if (!mpctx->sh_video)
1395 return M_PROPERTY_UNAVAILABLE;
1397 switch (action) {
1398 case M_PROPERTY_SET:
1399 if (!arg)
1400 return M_PROPERTY_ERROR;
1401 case M_PROPERTY_STEP_UP:
1402 case M_PROPERTY_STEP_DOWN:
1403 vo_osd_changed(OSDTYPE_SUBTITLE);
1404 if (vo_spudec)
1405 vo_osd_changed(OSDTYPE_SPU);
1406 default:
1407 return m_property_flag(prop, action, arg, &sub_visibility);
1411 /// Show only forced subtitles (RW)
1412 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1413 void *arg, MPContext * mpctx)
1415 if (!vo_spudec)
1416 return M_PROPERTY_UNAVAILABLE;
1418 switch (action) {
1419 case M_PROPERTY_SET:
1420 if (!arg)
1421 return M_PROPERTY_ERROR;
1422 case M_PROPERTY_STEP_UP:
1423 case M_PROPERTY_STEP_DOWN:
1424 m_property_flag(prop, action, arg, &forced_subs_only);
1425 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1426 return M_PROPERTY_OK;
1427 default:
1428 return m_property_flag(prop, action, arg, &forced_subs_only);
1433 #ifdef HAVE_FREETYPE
1434 /// Subtitle scale (RW)
1435 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1436 MPContext * mpctx)
1439 switch (action) {
1440 case M_PROPERTY_SET:
1441 if (!arg)
1442 return M_PROPERTY_ERROR;
1443 M_PROPERTY_CLAMP(prop, *(float *) arg);
1444 text_font_scale_factor = *(float *) arg;
1445 force_load_font = 1;
1446 return M_PROPERTY_OK;
1447 case M_PROPERTY_STEP_UP:
1448 case M_PROPERTY_STEP_DOWN:
1449 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1450 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1451 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1452 force_load_font = 1;
1453 return M_PROPERTY_OK;
1454 default:
1455 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1458 #endif
1460 ///@}
1462 /// \defgroup TVProperties TV properties
1463 /// \ingroup Properties
1464 ///@{
1466 #ifdef USE_TV
1468 /// TV color settings (RW)
1469 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1470 MPContext * mpctx)
1472 int r, val;
1473 tvi_handle_t *tvh = mpctx->demuxer->priv;
1474 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1475 return M_PROPERTY_UNAVAILABLE;
1477 switch (action) {
1478 case M_PROPERTY_SET:
1479 if (!arg)
1480 return M_PROPERTY_ERROR;
1481 M_PROPERTY_CLAMP(prop, *(int *) arg);
1482 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1483 case M_PROPERTY_GET:
1484 return tv_get_color_options(tvh, (int) prop->priv, arg);
1485 case M_PROPERTY_STEP_UP:
1486 case M_PROPERTY_STEP_DOWN:
1487 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1488 if (!r)
1489 return M_PROPERTY_ERROR;
1490 val += (arg ? *(int *) arg : 1) *
1491 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1492 M_PROPERTY_CLAMP(prop, val);
1493 return tv_set_color_options(tvh, (int) prop->priv, val);
1495 return M_PROPERTY_ERROR;
1497 return M_PROPERTY_NOT_IMPLEMENTED;
1500 #endif
1502 ///@}
1504 /// All properties available in MPlayer.
1505 /** \ingroup Properties
1507 static m_option_t mp_properties[] = {
1508 // General
1509 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1510 M_OPT_RANGE, 0, 3, NULL },
1511 { "loop", mp_property_loop, CONF_TYPE_INT,
1512 M_OPT_MIN, -1, 0, NULL },
1513 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1514 M_OPT_RANGE, 0.01, 100.0, NULL },
1515 { "filename", mp_property_filename, CONF_TYPE_STRING,
1516 0, 0, 0, NULL },
1517 { "path", mp_property_path, CONF_TYPE_STRING,
1518 0, 0, 0, NULL },
1519 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1520 0, 0, 0, NULL },
1521 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1522 M_OPT_MIN, 0, 0, NULL },
1523 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1524 M_OPT_MIN, 0, 0, NULL },
1525 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1526 M_OPT_MIN, 0, 0, NULL },
1527 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1528 M_OPT_MIN, 0, 0, NULL },
1529 { "length", mp_property_length, CONF_TYPE_TIME,
1530 M_OPT_MIN, 0, 0, NULL },
1531 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1532 M_OPT_RANGE, 0, 100, NULL },
1533 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1534 M_OPT_MIN, 0, 0, NULL },
1535 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
1536 0, 0, 0, NULL },
1538 // Audio
1539 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
1540 M_OPT_RANGE, 0, 100, NULL },
1541 { "mute", mp_property_mute, CONF_TYPE_FLAG,
1542 M_OPT_RANGE, 0, 1, NULL },
1543 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
1544 M_OPT_RANGE, -100, 100, NULL },
1545 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
1546 0, 0, 0, NULL },
1547 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
1548 0, 0, 0, NULL },
1549 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
1550 0, 0, 0, NULL },
1551 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
1552 0, 0, 0, NULL },
1553 { "channels", mp_property_channels, CONF_TYPE_INT,
1554 0, 0, 0, NULL },
1555 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
1556 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
1557 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
1558 M_OPT_RANGE, -1, 1, NULL },
1560 // Video
1561 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
1562 M_OPT_RANGE, 0, 1, NULL },
1563 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
1564 M_OPT_RANGE, 0, 1, NULL },
1565 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
1566 M_OPT_RANGE, 0, 1, NULL },
1567 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
1568 M_OPT_RANGE, 0, 1, NULL },
1569 { "border", mp_property_border, CONF_TYPE_FLAG,
1570 M_OPT_RANGE, 0, 1, NULL },
1571 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
1572 M_OPT_RANGE, 0, 2, NULL },
1573 { "gamma", mp_property_gamma, CONF_TYPE_INT,
1574 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
1575 { "brightness", mp_property_gamma, CONF_TYPE_INT,
1576 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
1577 { "contrast", mp_property_gamma, CONF_TYPE_INT,
1578 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
1579 { "saturation", mp_property_gamma, CONF_TYPE_INT,
1580 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
1581 { "hue", mp_property_gamma, CONF_TYPE_INT,
1582 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
1583 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
1584 M_OPT_RANGE, 0, 1, NULL },
1585 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
1586 M_OPT_RANGE, 0, 1, NULL },
1587 { "video_format", mp_property_video_format, CONF_TYPE_INT,
1588 0, 0, 0, NULL },
1589 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
1590 0, 0, 0, NULL },
1591 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
1592 0, 0, 0, NULL },
1593 { "width", mp_property_width, CONF_TYPE_INT,
1594 0, 0, 0, NULL },
1595 { "height", mp_property_height, CONF_TYPE_INT,
1596 0, 0, 0, NULL },
1597 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
1598 0, 0, 0, NULL },
1599 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
1600 0, 0, 0, NULL },
1601 { "switch_video", mp_property_video, CONF_TYPE_INT,
1602 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
1603 { "switch_program", mp_property_program, CONF_TYPE_INT,
1604 CONF_RANGE, -1, 65535, NULL },
1606 // Subs
1607 { "sub", mp_property_sub, CONF_TYPE_INT,
1608 M_OPT_MIN, -1, 0, NULL },
1609 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
1610 0, 0, 0, NULL },
1611 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
1612 M_OPT_RANGE, 0, 100, NULL },
1613 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
1614 M_OPT_RANGE, 0, 2, NULL },
1615 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
1616 M_OPT_RANGE, 0, 1, NULL },
1617 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
1618 M_OPT_RANGE, 0, 1, NULL },
1619 #ifdef HAVE_FREETYPE
1620 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
1621 M_OPT_RANGE, 0, 100, NULL },
1622 #endif
1624 #ifdef USE_TV
1625 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
1626 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
1627 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
1628 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
1629 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
1630 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
1631 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
1632 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
1633 #endif
1635 { NULL, NULL, NULL, 0, 0, 0, NULL }
1639 int mp_property_do(const char *name, int action, void *val, void *ctx)
1641 return m_property_do(mp_properties, name, action, val, ctx);
1644 char* mp_property_print(const char *name, void* ctx)
1646 char* ret = NULL;
1647 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
1648 return NULL;
1649 return ret;
1652 char *property_expand_string(MPContext * mpctx, char *str)
1654 return m_properties_expand_string(mp_properties, str, mpctx);
1657 void property_print_help(void)
1659 m_properties_print_help_list(mp_properties);
1663 ///@}
1664 // Properties group
1668 * \defgroup Command2Property Command to property bridge
1670 * It is used to handle most commands that just set a property
1671 * and optionally display something on the OSD.
1672 * Two kinds of commands are handled: adjust or toggle.
1674 * Adjust commands take 1 or 2 parameters: <value> <abs>
1675 * If <abs> is non-zero the property is set to the given value
1676 * otherwise it is adjusted.
1678 * Toggle commands take 0 or 1 parameters. With no parameter
1679 * or a value less than the property minimum it just steps the
1680 * property to its next value. Otherwise it sets it to the given
1681 * value.
1686 /// List of the commands that can be handled by setting a property.
1687 static struct {
1688 /// property name
1689 const char *name;
1690 /// cmd id
1691 int cmd;
1692 /// set/adjust or toggle command
1693 int toggle;
1694 /// progressbar type
1695 int osd_progbar;
1696 /// osd msg id if it must be shared
1697 int osd_id;
1698 /// osd msg template
1699 const char *osd_msg;
1700 } set_prop_cmd[] = {
1701 // general
1702 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
1703 // audio
1704 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
1705 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
1706 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
1707 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
1708 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
1709 // video
1710 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
1711 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
1712 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
1713 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
1714 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
1715 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
1716 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
1717 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
1718 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
1719 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
1720 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
1721 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
1722 // subs
1723 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
1724 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
1725 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
1726 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
1727 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
1728 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
1729 #ifdef HAVE_FREETYPE
1730 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
1731 #endif
1732 #ifdef USE_TV
1733 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
1734 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
1735 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
1736 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
1737 #endif
1738 { NULL, 0, 0, 0, -1, NULL }
1742 /// Handle commands that set a property.
1743 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
1745 int i, r;
1746 m_option_t* prop;
1747 const char *pname;
1749 // look for the command
1750 for (i = 0; set_prop_cmd[i].name; i++)
1751 if (set_prop_cmd[i].cmd == cmd->id)
1752 break;
1753 if (!(pname = set_prop_cmd[i].name))
1754 return 0;
1756 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
1757 return 0;
1759 // toggle command
1760 if (set_prop_cmd[i].toggle) {
1761 // set to value
1762 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
1763 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
1764 else
1765 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
1766 } else if (cmd->args[1].v.i) //set
1767 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
1768 else // adjust
1769 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
1771 if (r <= 0)
1772 return 1;
1774 if (set_prop_cmd[i].osd_progbar) {
1775 if (prop->type == CONF_TYPE_INT) {
1776 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
1777 set_osd_bar(set_prop_cmd[i].osd_progbar,
1778 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
1779 } else if (prop->type == CONF_TYPE_FLOAT) {
1780 float f;
1781 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
1782 set_osd_bar(set_prop_cmd[i].osd_progbar,
1783 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
1784 } else
1785 mp_msg(MSGT_CPLAYER, MSGL_ERR,
1786 "Property use an unsupported type.\n");
1787 return 1;
1790 if (set_prop_cmd[i].osd_msg) {
1791 char *val = mp_property_print(pname, mpctx);
1792 if (val) {
1793 set_osd_msg(set_prop_cmd[i].osd_id >=
1794 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
1795 1, osd_duration, set_prop_cmd[i].osd_msg, val);
1796 free(val);
1799 return 1;
1803 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
1805 sh_audio_t * const sh_audio = mpctx->sh_audio;
1806 sh_video_t * const sh_video = mpctx->sh_video;
1807 int brk_cmd = 0;
1808 if (!set_property_command(mpctx, cmd))
1809 switch (cmd->id) {
1810 case MP_CMD_SEEK:{
1811 float v;
1812 int abs;
1813 if (sh_video)
1814 mpctx->osd_show_percentage = sh_video->fps;
1815 v = cmd->args[0].v.f;
1816 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
1817 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
1818 abs_seek_pos = 1;
1819 if (sh_video)
1820 mpctx->osd_function =
1821 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
1822 rel_seek_secs = v;
1823 } else if (abs) { /* Absolute seek by percentage */
1824 abs_seek_pos = 3;
1825 if (sh_video)
1826 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
1827 rel_seek_secs = v / 100.0;
1828 } else {
1829 rel_seek_secs += v;
1830 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
1832 brk_cmd = 1;
1834 break;
1836 case MP_CMD_SET_PROPERTY:{
1837 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
1838 cmd->args[1].v.s, mpctx);
1839 if (r == M_PROPERTY_UNKNOWN)
1840 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1841 "Unknown property: '%s'\n", cmd->args[0].v.s);
1842 else if (r <= 0)
1843 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1844 "Failed to set property '%s' to '%s'.\n",
1845 cmd->args[0].v.s, cmd->args[1].v.s);
1847 break;
1849 case MP_CMD_STEP_PROPERTY:{
1850 void* arg = NULL;
1851 int r,i;
1852 double d;
1853 off_t o;
1854 if (cmd->args[1].v.f) {
1855 m_option_t* prop;
1856 if((r = mp_property_do(cmd->args[0].v.s,
1857 M_PROPERTY_GET_TYPE,
1858 &prop, mpctx)) <= 0)
1859 goto step_prop_err;
1860 if(prop->type == CONF_TYPE_INT ||
1861 prop->type == CONF_TYPE_FLAG)
1862 i = cmd->args[1].v.f, arg = &i;
1863 else if(prop->type == CONF_TYPE_FLOAT)
1864 arg = &cmd->args[1].v.f;
1865 else if(prop->type == CONF_TYPE_DOUBLE ||
1866 prop->type == CONF_TYPE_TIME)
1867 d = cmd->args[1].v.f, arg = &d;
1868 else if(prop->type == CONF_TYPE_POSITION)
1869 o = cmd->args[1].v.f, arg = &o;
1870 else
1871 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1872 "Ignoring step size stepping property '%s'.\n",
1873 cmd->args[0].v.s);
1875 r = mp_property_do(cmd->args[0].v.s,
1876 cmd->args[2].v.i < 0 ?
1877 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
1878 arg, mpctx);
1879 step_prop_err:
1880 if (r == M_PROPERTY_UNKNOWN)
1881 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1882 "Unknown property: '%s'\n", cmd->args[0].v.s);
1883 else if (r <= 0)
1884 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1885 "Failed to increment property '%s' by %f.\n",
1886 cmd->args[0].v.s, cmd->args[1].v.f);
1888 break;
1890 case MP_CMD_GET_PROPERTY:{
1891 char *tmp;
1892 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
1893 &tmp, mpctx) <= 0) {
1894 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1895 "Failed to get value of property '%s'.\n",
1896 cmd->args[0].v.s);
1897 break;
1899 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
1900 cmd->args[0].v.s, tmp);
1901 free(tmp);
1903 break;
1905 case MP_CMD_EDL_MARK:
1906 if (edl_fd) {
1907 float v = sh_video ? sh_video->pts :
1908 playing_audio_pts(sh_audio, mpctx->d_audio,
1909 mpctx->audio_out);
1911 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
1912 mpctx->begin_skip = v;
1913 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
1914 } else {
1915 if (mpctx->begin_skip > v)
1916 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
1917 else {
1918 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
1919 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
1921 mpctx->begin_skip = MP_NOPTS_VALUE;
1924 break;
1926 case MP_CMD_SWITCH_RATIO:
1927 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
1928 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
1929 else
1930 movie_aspect = cmd->args[0].v.f;
1931 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
1932 break;
1934 case MP_CMD_SPEED_INCR:{
1935 float v = cmd->args[0].v.f;
1936 playback_speed += v;
1937 build_afilter_chain(sh_audio, &ao_data);
1938 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
1939 playback_speed);
1940 } break;
1942 case MP_CMD_SPEED_MULT:{
1943 float v = cmd->args[0].v.f;
1944 playback_speed *= v;
1945 build_afilter_chain(sh_audio, &ao_data);
1946 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
1947 playback_speed);
1948 } break;
1950 case MP_CMD_SPEED_SET:{
1951 float v = cmd->args[0].v.f;
1952 playback_speed = v;
1953 build_afilter_chain(sh_audio, &ao_data);
1954 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
1955 playback_speed);
1956 } break;
1958 case MP_CMD_FRAME_STEP:
1959 case MP_CMD_PAUSE:
1960 cmd->pausing = 1;
1961 brk_cmd = 1;
1962 break;
1964 case MP_CMD_FILE_FILTER:
1965 file_filter = cmd->args[0].v.i;
1966 break;
1968 case MP_CMD_QUIT:
1969 exit_player_with_rc(MSGTR_Exit_quit,
1970 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
1972 case MP_CMD_PLAY_TREE_STEP:{
1973 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
1974 int force = cmd->args[1].v.i;
1976 #ifdef HAVE_NEW_GUI
1977 if (use_gui) {
1978 int i = 0;
1979 if (n > 0)
1980 for (i = 0; i < n; i++)
1981 mplNext();
1982 else
1983 for (i = 0; i < -1 * n; i++)
1984 mplPrev();
1985 } else
1986 #endif
1988 if (!force && mpctx->playtree_iter) {
1989 play_tree_iter_t *i =
1990 play_tree_iter_new_copy(mpctx->playtree_iter);
1991 if (play_tree_iter_step(i, n, 0) ==
1992 PLAY_TREE_ITER_ENTRY)
1993 mpctx->eof =
1994 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
1995 play_tree_iter_free(i);
1996 } else
1997 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
1998 if (mpctx->eof)
1999 mpctx->play_tree_step = n;
2000 brk_cmd = 1;
2003 break;
2005 case MP_CMD_PLAY_TREE_UP_STEP:{
2006 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2007 int force = cmd->args[1].v.i;
2009 if (!force && mpctx->playtree_iter) {
2010 play_tree_iter_t *i =
2011 play_tree_iter_new_copy(mpctx->playtree_iter);
2012 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2013 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2014 play_tree_iter_free(i);
2015 } else
2016 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2017 brk_cmd = 1;
2019 break;
2021 case MP_CMD_PLAY_ALT_SRC_STEP:
2022 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2023 int v = cmd->args[0].v.i;
2024 if (v > 0
2025 && mpctx->playtree_iter->file <
2026 mpctx->playtree_iter->num_files)
2027 mpctx->eof = PT_NEXT_SRC;
2028 else if (v < 0 && mpctx->playtree_iter->file > 1)
2029 mpctx->eof = PT_PREV_SRC;
2031 brk_cmd = 1;
2032 break;
2034 case MP_CMD_SUB_STEP:
2035 if (sh_video) {
2036 int movement = cmd->args[0].v.i;
2037 step_sub(subdata, sh_video->pts, movement);
2038 #ifdef USE_ASS
2039 if (ass_track)
2040 sub_delay +=
2041 ass_step_sub(ass_track,
2042 (sh_video->pts +
2043 sub_delay) * 1000 + .5, movement) / 1000.;
2044 #endif
2045 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2046 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2048 break;
2050 case MP_CMD_SUB_LOG:
2051 log_sub();
2052 break;
2054 case MP_CMD_OSD:{
2055 int v = cmd->args[0].v.i;
2056 int max = (term_osd
2057 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2058 if (osd_level > max)
2059 osd_level = max;
2060 if (v < 0)
2061 osd_level = (osd_level + 1) % (max + 1);
2062 else
2063 osd_level = v > max ? max : v;
2064 /* Show OSD state when disabled, but not when an explicit
2065 argument is given to the OSD command, i.e. in slave mode. */
2066 if (v == -1 && osd_level <= 1)
2067 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2068 MSGTR_OSDosd,
2069 osd_level ? MSGTR_OSDenabled :
2070 MSGTR_OSDdisabled);
2071 else
2072 rm_osd_msg(OSD_MSG_OSD_STATUS);
2074 break;
2076 case MP_CMD_OSD_SHOW_TEXT:
2077 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2078 (cmd->args[1].v.i <
2079 0 ? osd_duration : cmd->args[1].v.i),
2080 "%-.63s", cmd->args[0].v.s);
2081 break;
2083 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2084 char *txt = m_properties_expand_string(mp_properties,
2085 cmd->args[0].v.s,
2086 mpctx);
2087 /* if no argument supplied take default osd_duration, else <arg> ms. */
2088 if (txt) {
2089 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2090 (cmd->args[1].v.i <
2091 0 ? osd_duration : cmd->args[1].v.i),
2092 "%-.63s", txt);
2093 free(txt);
2096 break;
2098 case MP_CMD_LOADFILE:{
2099 play_tree_t *e = play_tree_new();
2100 play_tree_add_file(e, cmd->args[0].v.s);
2102 if (cmd->args[1].v.i) // append
2103 play_tree_append_entry(mpctx->playtree, e);
2104 else {
2105 // Go back to the starting point.
2106 while (play_tree_iter_up_step
2107 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2108 /* NOP */ ;
2109 play_tree_free_list(mpctx->playtree->child, 1);
2110 play_tree_set_child(mpctx->playtree, e);
2111 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2112 mpctx->eof = PT_NEXT_SRC;
2114 brk_cmd = 1;
2116 break;
2118 case MP_CMD_LOADLIST:{
2119 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2120 if (!e)
2121 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2122 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2123 else {
2124 if (cmd->args[1].v.i) // append
2125 play_tree_append_entry(mpctx->playtree, e);
2126 else {
2127 // Go back to the starting point.
2128 while (play_tree_iter_up_step
2129 (mpctx->playtree_iter, 0, 1)
2130 != PLAY_TREE_ITER_END)
2131 /* NOP */ ;
2132 play_tree_free_list(mpctx->playtree->child, 1);
2133 play_tree_set_child(mpctx->playtree, e);
2134 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2135 mpctx->eof = PT_NEXT_SRC;
2138 brk_cmd = 1;
2140 break;
2142 #ifdef USE_RADIO
2143 case MP_CMD_RADIO_STEP_CHANNEL:
2144 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2145 int v = cmd->args[0].v.i;
2146 if (v > 0)
2147 radio_step_channel(mpctx->demuxer->stream,
2148 RADIO_CHANNEL_HIGHER);
2149 else
2150 radio_step_channel(mpctx->demuxer->stream,
2151 RADIO_CHANNEL_LOWER);
2152 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2153 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2154 MSGTR_OSDChannel,
2155 radio_get_channel_name(mpctx->demuxer->stream));
2158 break;
2160 case MP_CMD_RADIO_SET_CHANNEL:
2161 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2162 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2163 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2164 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2165 MSGTR_OSDChannel,
2166 radio_get_channel_name(mpctx->demuxer->stream));
2169 break;
2171 case MP_CMD_RADIO_SET_FREQ:
2172 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2173 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2174 break;
2176 case MP_CMD_RADIO_STEP_FREQ:
2177 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2178 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2179 break;
2180 #endif
2182 #ifdef USE_TV
2183 case MP_CMD_TV_SET_FREQ:
2184 if (mpctx->file_format == DEMUXER_TYPE_TV)
2185 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2186 cmd->args[0].v.f * 16.0);
2187 #ifdef HAVE_PVR
2188 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2189 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2190 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2191 pvr_get_current_channelname (mpctx->stream),
2192 pvr_get_current_stationname (mpctx->stream));
2194 #endif /* HAVE_PVR */
2195 break;
2197 case MP_CMD_TV_STEP_FREQ:
2198 if (mpctx->file_format == DEMUXER_TYPE_TV)
2199 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2200 cmd->args[0].v.f * 16.0);
2201 #ifdef HAVE_PVR
2202 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2203 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2204 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2205 pvr_get_current_channelname (mpctx->stream),
2206 pvr_get_current_frequency (mpctx->stream));
2208 #endif /* HAVE_PVR */
2209 break;
2211 case MP_CMD_TV_SET_NORM:
2212 if (mpctx->file_format == DEMUXER_TYPE_TV)
2213 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2214 cmd->args[0].v.s);
2215 break;
2217 case MP_CMD_TV_STEP_CHANNEL:{
2218 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2219 int v = cmd->args[0].v.i;
2220 if (v > 0) {
2221 tv_step_channel((tvi_handle_t *) (mpctx->
2222 demuxer->priv),
2223 TV_CHANNEL_HIGHER);
2224 } else {
2225 tv_step_channel((tvi_handle_t *) (mpctx->
2226 demuxer->priv),
2227 TV_CHANNEL_LOWER);
2229 if (tv_channel_list) {
2230 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2231 MSGTR_OSDChannel, tv_channel_current->name);
2232 //vo_osd_changed(OSDTYPE_SUBTITLE);
2235 #ifdef HAVE_PVR
2236 else if (mpctx->stream &&
2237 mpctx->stream->type == STREAMTYPE_PVR) {
2238 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2239 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2240 pvr_get_current_channelname (mpctx->stream),
2241 pvr_get_current_stationname (mpctx->stream));
2243 #endif /* HAVE_PVR */
2245 #ifdef HAS_DVBIN_SUPPORT
2246 if ((mpctx->stream->type == STREAMTYPE_DVB)
2247 && mpctx->stream->priv) {
2248 dvb_priv_t *priv = (dvb_priv_t *) mpctx->stream->priv;
2249 if (priv->is_on) {
2250 int dir;
2251 int v = cmd->args[0].v.i;
2253 mpctx->last_dvb_step = v;
2254 if (v > 0)
2255 dir = DVB_CHANNEL_HIGHER;
2256 else
2257 dir = DVB_CHANNEL_LOWER;
2260 if (dvb_step_channel(priv, dir))
2261 mpctx->eof = mpctx->dvbin_reopen = 1;
2264 #endif /* HAS_DVBIN_SUPPORT */
2265 break;
2267 case MP_CMD_TV_SET_CHANNEL:
2268 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2269 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2270 cmd->args[0].v.s);
2271 if (tv_channel_list) {
2272 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2273 MSGTR_OSDChannel, tv_channel_current->name);
2274 //vo_osd_changed(OSDTYPE_SUBTITLE);
2277 #ifdef HAVE_PVR
2278 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2279 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2280 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2281 pvr_get_current_channelname (mpctx->stream),
2282 pvr_get_current_stationname (mpctx->stream));
2284 #endif /* HAVE_PVR */
2285 break;
2287 #ifdef HAS_DVBIN_SUPPORT
2288 case MP_CMD_DVB_SET_CHANNEL:
2289 if ((mpctx->stream->type == STREAMTYPE_DVB)
2290 && mpctx->stream->priv) {
2291 dvb_priv_t *priv = (dvb_priv_t *) mpctx->stream->priv;
2292 if (priv->is_on) {
2293 if (priv->list->current <= cmd->args[0].v.i)
2294 mpctx->last_dvb_step = 1;
2295 else
2296 mpctx->last_dvb_step = -1;
2298 if (dvb_set_channel
2299 (priv, cmd->args[1].v.i, cmd->args[0].v.i))
2300 mpctx->eof = mpctx->dvbin_reopen = 1;
2303 break;
2304 #endif /* HAS_DVBIN_SUPPORT */
2306 case MP_CMD_TV_LAST_CHANNEL:
2307 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2308 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2309 if (tv_channel_list) {
2310 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2311 MSGTR_OSDChannel, tv_channel_current->name);
2312 //vo_osd_changed(OSDTYPE_SUBTITLE);
2315 #ifdef HAVE_PVR
2316 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2317 pvr_set_lastchannel (mpctx->stream);
2318 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2319 pvr_get_current_channelname (mpctx->stream),
2320 pvr_get_current_stationname (mpctx->stream));
2322 #endif /* HAVE_PVR */
2323 break;
2325 case MP_CMD_TV_STEP_NORM:
2326 if (mpctx->file_format == DEMUXER_TYPE_TV)
2327 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2328 break;
2330 case MP_CMD_TV_STEP_CHANNEL_LIST:
2331 if (mpctx->file_format == DEMUXER_TYPE_TV)
2332 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2333 break;
2334 #endif /* USE_TV */
2336 case MP_CMD_SUB_LOAD:
2337 if (sh_video) {
2338 int n = mpctx->set_of_sub_size;
2339 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2340 if (n != mpctx->set_of_sub_size) {
2341 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2342 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2343 mpctx->global_sub_size;
2344 ++mpctx->global_sub_size;
2347 break;
2349 case MP_CMD_SUB_REMOVE:
2350 if (sh_video) {
2351 int v = cmd->args[0].v.i;
2352 sub_data *subd;
2353 if (v < 0) {
2354 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2355 subd = mpctx->set_of_subtitles[v];
2356 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2357 MSGTR_RemovedSubtitleFile, v + 1,
2358 filename_recode(subd->filename));
2359 sub_free(subd);
2360 mpctx->set_of_subtitles[v] = NULL;
2362 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2363 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2364 mpctx->set_of_sub_size = 0;
2365 if (mpctx->set_of_sub_pos >= 0) {
2366 mpctx->global_sub_pos = -2;
2367 vo_sub_last = vo_sub = NULL;
2368 vo_osd_changed(OSDTYPE_SUBTITLE);
2369 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
2370 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2372 } else if (v < mpctx->set_of_sub_size) {
2373 subd = mpctx->set_of_subtitles[v];
2374 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2375 MSGTR_RemovedSubtitleFile, v + 1,
2376 filename_recode(subd->filename));
2377 sub_free(subd);
2378 if (mpctx->set_of_sub_pos == v) {
2379 mpctx->global_sub_pos = -2;
2380 vo_sub_last = vo_sub = NULL;
2381 vo_osd_changed(OSDTYPE_SUBTITLE);
2382 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
2383 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2384 } else if (mpctx->set_of_sub_pos > v) {
2385 --mpctx->set_of_sub_pos;
2386 --mpctx->global_sub_pos;
2388 while (++v < mpctx->set_of_sub_size)
2389 mpctx->set_of_subtitles[v - 1] =
2390 mpctx->set_of_subtitles[v];
2391 --mpctx->set_of_sub_size;
2392 --mpctx->global_sub_size;
2393 if (mpctx->set_of_sub_size <= 0)
2394 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2395 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2398 break;
2400 case MP_CMD_GET_SUB_VISIBILITY:
2401 if (sh_video) {
2402 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2403 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2405 break;
2407 case MP_CMD_SCREENSHOT:
2408 if (vo_config_count) {
2409 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2410 if (CONTROL_OK !=
2411 ((vf_instance_t *) sh_video->vfilter)->
2412 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2413 &cmd->args[0].v.i))
2414 mpctx->video_out->control(VOCTRL_SCREENSHOT, NULL);
2416 break;
2418 case MP_CMD_VF_CHANGE_RECTANGLE:
2419 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2420 break;
2422 case MP_CMD_GET_TIME_LENGTH:{
2423 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2424 demuxer_get_time_length(mpctx->demuxer));
2426 break;
2428 case MP_CMD_GET_FILENAME:{
2429 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2430 get_metadata(META_NAME));
2432 break;
2434 case MP_CMD_GET_VIDEO_CODEC:{
2435 char *inf = get_metadata(META_VIDEO_CODEC);
2436 if (!inf)
2437 inf = strdup("");
2438 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2439 free(inf);
2441 break;
2443 case MP_CMD_GET_VIDEO_BITRATE:{
2444 char *inf = get_metadata(META_VIDEO_BITRATE);
2445 if (!inf)
2446 inf = strdup("");
2447 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2448 free(inf);
2450 break;
2452 case MP_CMD_GET_VIDEO_RESOLUTION:{
2453 char *inf = get_metadata(META_VIDEO_RESOLUTION);
2454 if (!inf)
2455 inf = strdup("");
2456 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2457 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
2458 free(inf);
2460 break;
2462 case MP_CMD_GET_AUDIO_CODEC:{
2463 char *inf = get_metadata(META_AUDIO_CODEC);
2464 if (!inf)
2465 inf = strdup("");
2466 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
2467 free(inf);
2469 break;
2471 case MP_CMD_GET_AUDIO_BITRATE:{
2472 char *inf = get_metadata(META_AUDIO_BITRATE);
2473 if (!inf)
2474 inf = strdup("");
2475 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
2476 free(inf);
2478 break;
2480 case MP_CMD_GET_AUDIO_SAMPLES:{
2481 char *inf = get_metadata(META_AUDIO_SAMPLES);
2482 if (!inf)
2483 inf = strdup("");
2484 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
2485 free(inf);
2487 break;
2489 case MP_CMD_GET_META_TITLE:{
2490 char *inf = get_metadata(META_INFO_TITLE);
2491 if (!inf)
2492 inf = strdup("");
2493 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
2494 free(inf);
2496 break;
2498 case MP_CMD_GET_META_ARTIST:{
2499 char *inf = get_metadata(META_INFO_ARTIST);
2500 if (!inf)
2501 inf = strdup("");
2502 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
2503 free(inf);
2505 break;
2507 case MP_CMD_GET_META_ALBUM:{
2508 char *inf = get_metadata(META_INFO_ALBUM);
2509 if (!inf)
2510 inf = strdup("");
2511 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
2512 free(inf);
2514 break;
2516 case MP_CMD_GET_META_YEAR:{
2517 char *inf = get_metadata(META_INFO_YEAR);
2518 if (!inf)
2519 inf = strdup("");
2520 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
2521 free(inf);
2523 break;
2525 case MP_CMD_GET_META_COMMENT:{
2526 char *inf = get_metadata(META_INFO_COMMENT);
2527 if (!inf)
2528 inf = strdup("");
2529 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
2530 free(inf);
2532 break;
2534 case MP_CMD_GET_META_TRACK:{
2535 char *inf = get_metadata(META_INFO_TRACK);
2536 if (!inf)
2537 inf = strdup("");
2538 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
2539 free(inf);
2541 break;
2543 case MP_CMD_GET_META_GENRE:{
2544 char *inf = get_metadata(META_INFO_GENRE);
2545 if (!inf)
2546 inf = strdup("");
2547 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
2548 free(inf);
2550 break;
2552 case MP_CMD_GET_VO_FULLSCREEN:
2553 if (mpctx->video_out && vo_config_count)
2554 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
2555 break;
2557 case MP_CMD_GET_PERCENT_POS:
2558 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
2559 demuxer_get_percent_pos(mpctx->demuxer));
2560 break;
2562 case MP_CMD_GET_TIME_POS:{
2563 float pos = 0;
2564 if (sh_video)
2565 pos = sh_video->pts;
2566 else if (sh_audio && mpctx->audio_out)
2567 pos =
2568 playing_audio_pts(sh_audio, mpctx->d_audio,
2569 mpctx->audio_out);
2570 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
2572 break;
2574 case MP_CMD_RUN:
2575 #ifndef __MINGW32__
2576 if (!fork()) {
2577 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
2578 exit(0);
2580 #endif
2581 break;
2583 case MP_CMD_KEYDOWN_EVENTS:
2584 mplayer_put_key(cmd->args[0].v.i);
2585 break;
2587 case MP_CMD_SEEK_CHAPTER:{
2588 int seek = cmd->args[0].v.i;
2589 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2590 int chap;
2591 float next_pts = 0;
2592 int num_chapters;
2593 char *chapter_name;
2595 rel_seek_secs = 0;
2596 abs_seek_pos = 0;
2597 chap =
2598 demuxer_seek_chapter(mpctx->demuxer, seek, abs,
2599 &next_pts, &num_chapters,
2600 &chapter_name);
2601 if (chap != -1) {
2602 if (next_pts > -1.0) {
2603 abs_seek_pos = 1;
2604 rel_seek_secs = next_pts;
2606 if (chapter_name) {
2607 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2608 MSGTR_OSDChapter, chap + 1, chapter_name);
2609 free(chapter_name);
2611 } else {
2612 if (seek > 0)
2613 rel_seek_secs = 1000000000.;
2614 else
2615 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2616 MSGTR_OSDChapter, 0, MSGTR_Unknown);
2618 break;
2620 break;
2622 case MP_CMD_SET_MOUSE_POS:{
2623 int button = -1, pointer_x, pointer_y;
2624 double dx, dy;
2625 pointer_x = cmd->args[0].v.i;
2626 pointer_y = cmd->args[1].v.i;
2627 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
2628 #ifdef USE_DVDNAV
2629 if (mpctx->stream->type == STREAMTYPE_DVDNAV
2630 && dx > 0.0 && dy > 0.0) {
2631 pointer_x = (int) (dx * (double) sh_video->disp_w);
2632 pointer_y = (int) (dy * (double) sh_video->disp_h);
2633 mp_dvdnav_update_mouse_pos(mpctx->stream,
2634 pointer_x, pointer_y, &button);
2635 if (button > 0)
2636 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2637 "Selected button number %d", button);
2639 #endif
2641 break;
2643 #ifdef USE_DVDNAV
2644 case MP_CMD_DVDNAV:{
2645 int button = -1;
2646 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
2647 break;
2649 if (mp_dvdnav_handle_input
2650 (mpctx->stream, cmd->args[0].v.i, &button)) {
2651 uninit_player(INITED_ALL - (INITED_STREAM | INITED_INPUT |
2652 (fixed_vo ? INITED_VO : 0)));
2653 brk_cmd = 2;
2654 } else if (button > 0)
2655 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2656 "Selected button number %d", button);
2658 break;
2659 #endif
2661 default:
2662 #ifdef HAVE_NEW_GUI
2663 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
2664 guiGetEvent(guiIEvent, (char *) cmd->id);
2665 else
2666 #endif
2667 mp_msg(MSGT_CPLAYER, MSGL_V,
2668 "Received unknown cmd %s\n", cmd->name);
2671 switch (cmd->pausing) {
2672 case 1: // "pausing"
2673 mpctx->osd_function = OSD_PAUSE;
2674 break;
2675 case 3: // "pausing_toggle"
2676 mpctx->was_paused = !mpctx->was_paused;
2677 // fall through
2678 case 2: // "pausing_keep"
2679 if (mpctx->was_paused)
2680 mpctx->osd_function = OSD_PAUSE;
2682 return brk_cmd;