synced with r23928
[mplayer/glamo.git] / command.c
blob49252c6f967c01ff4d1cbfb4a1237a1c8d798195
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 char *demux_lavf_sub_lang(demuxer_t *demuxer, int track_num);
1154 /// Selected subtitles (RW)
1155 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1156 MPContext * mpctx)
1158 demux_stream_t *const d_sub = mpctx->d_sub;
1159 const int global_sub_size = mpctx->global_sub_size;
1160 int source = -1, reset_spu = 0;
1161 char *sub_name;
1163 if (global_sub_size <= 0)
1164 return M_PROPERTY_UNAVAILABLE;
1166 switch (action) {
1167 case M_PROPERTY_GET:
1168 if (!arg)
1169 return M_PROPERTY_ERROR;
1170 *(int *) arg = mpctx->global_sub_pos;
1171 return M_PROPERTY_OK;
1172 case M_PROPERTY_PRINT:
1173 if (!arg)
1174 return M_PROPERTY_ERROR;
1175 *(char **) arg = malloc(64);
1176 (*(char **) arg)[63] = 0;
1177 sub_name = 0;
1178 if (subdata)
1179 sub_name = subdata->filename;
1180 #ifdef USE_ASS
1181 if (ass_track && ass_track->name)
1182 sub_name = ass_track->name;
1183 #endif
1184 if (sub_name) {
1185 char *tmp, *tmp2;
1186 tmp = sub_name;
1187 if ((tmp2 = strrchr(tmp, '/')))
1188 tmp = tmp2 + 1;
1190 snprintf(*(char **) arg, 63, "(%d) %s%s",
1191 mpctx->set_of_sub_pos + 1,
1192 strlen(tmp) < 20 ? "" : "...",
1193 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1194 return M_PROPERTY_OK;
1196 #ifdef USE_DVDNAV
1197 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1198 if (vo_spudec && dvdsub_id >= 0) {
1199 unsigned char lang[3];
1200 if (dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1201 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1202 return M_PROPERTY_OK;
1206 #endif
1208 #ifdef USE_LIBAVFORMAT
1209 if (mpctx->demuxer->type == DEMUXER_TYPE_LAVF && dvdsub_id >= 0) {
1210 char *lang = demux_lavf_sub_lang(mpctx->demuxer, dvdsub_id);
1211 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1212 return M_PROPERTY_OK;
1214 #endif
1215 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
1216 char lang[40] = MSGTR_Unknown;
1217 demux_mkv_get_sub_lang(mpctx->demuxer, dvdsub_id, lang, 9);
1218 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1219 return M_PROPERTY_OK;
1221 #ifdef HAVE_OGGVORBIS
1222 if (mpctx->demuxer->type == DEMUXER_TYPE_OGG && d_sub && dvdsub_id >= 0) {
1223 char *lang = demux_ogg_sub_lang(mpctx->demuxer, dvdsub_id);
1224 if (!lang)
1225 lang = MSGTR_Unknown;
1226 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1227 return M_PROPERTY_OK;
1229 #endif
1230 if (vo_vobsub && vobsub_id >= 0) {
1231 const char *language = MSGTR_Unknown;
1232 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1233 snprintf(*(char **) arg, 63, "(%d) %s",
1234 vobsub_id, language ? language : MSGTR_Unknown);
1235 return M_PROPERTY_OK;
1237 #ifdef USE_DVDREAD
1238 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1239 && dvdsub_id >= 0) {
1240 char lang[3];
1241 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1242 lang[0] = code >> 8;
1243 lang[1] = code;
1244 lang[2] = 0;
1245 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1246 return M_PROPERTY_OK;
1248 #endif
1249 if (dvdsub_id >= 0) {
1250 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1251 return M_PROPERTY_OK;
1253 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1254 return M_PROPERTY_OK;
1256 case M_PROPERTY_SET:
1257 if (!arg)
1258 return M_PROPERTY_ERROR;
1259 if (*(int *) arg < -1)
1260 *(int *) arg = -1;
1261 else if (*(int *) arg >= global_sub_size)
1262 *(int *) arg = global_sub_size - 1;
1263 mpctx->global_sub_pos = *(int *) arg;
1264 break;
1265 case M_PROPERTY_STEP_UP:
1266 mpctx->global_sub_pos += 2;
1267 mpctx->global_sub_pos =
1268 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1269 break;
1270 case M_PROPERTY_STEP_DOWN:
1271 mpctx->global_sub_pos += global_sub_size + 1;
1272 mpctx->global_sub_pos =
1273 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1274 break;
1275 default:
1276 return M_PROPERTY_NOT_IMPLEMENTED;
1279 if (mpctx->global_sub_pos >= 0)
1280 source = sub_source(mpctx);
1282 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1283 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1284 global_sub_size,
1285 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1286 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1287 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1288 mpctx->global_sub_pos, source);
1290 mpctx->set_of_sub_pos = -1;
1291 subdata = NULL;
1293 vobsub_id = -1;
1294 dvdsub_id = -1;
1295 if (d_sub) {
1296 if (d_sub->id > -2)
1297 reset_spu = 1;
1298 d_sub->id = -2;
1300 #ifdef USE_ASS
1301 ass_track = 0;
1302 #endif
1304 if (source == SUB_SOURCE_VOBSUB) {
1305 vobsub_id =
1306 mpctx->global_sub_pos -
1307 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB];
1308 } else if (source == SUB_SOURCE_SUBS) {
1309 mpctx->set_of_sub_pos =
1310 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1311 #ifdef USE_ASS
1312 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1313 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1314 else
1315 #endif
1317 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1318 vo_osd_changed(OSDTYPE_SUBTITLE);
1320 } else if (source == SUB_SOURCE_DEMUX) {
1321 dvdsub_id =
1322 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1323 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1324 int i = 0;
1325 // default: assume 1:1 mapping of sid and stream id
1326 d_sub->id = dvdsub_id;
1327 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1328 for (i = 0; i < MAX_S_STREAMS; i++) {
1329 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1330 if (sh && sh->sid == dvdsub_id) {
1331 d_sub->id = i;
1332 d_sub->sh = sh;
1333 break;
1336 if (d_sub->sh && d_sub->id >= 0) {
1337 sh_sub_t *sh = d_sub->sh;
1338 if (sh->type == 'v')
1339 init_vo_spudec();
1340 #ifdef USE_ASS
1341 else if (ass_enabled && sh->type == 'a')
1342 ass_track = sh->ass_track;
1343 #endif
1344 } else {
1345 d_sub->id = -2;
1346 d_sub->sh = NULL;
1350 #ifdef USE_DVDREAD
1351 if (vo_spudec
1352 && (mpctx->stream->type == STREAMTYPE_DVD
1353 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1354 && dvdsub_id < 0 && reset_spu) {
1355 dvdsub_id = -2;
1356 d_sub->id = dvdsub_id;
1358 #endif
1359 update_subtitles(mpctx->sh_video, d_sub, 1);
1361 return M_PROPERTY_OK;
1364 /// Subtitle delay (RW)
1365 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1366 MPContext * mpctx)
1368 if (!mpctx->sh_video)
1369 return M_PROPERTY_UNAVAILABLE;
1370 return m_property_delay(prop, action, arg, &sub_delay);
1373 /// Alignment of text subtitles (RW)
1374 static int mp_property_sub_alignment(m_option_t * prop, int action,
1375 void *arg, MPContext * mpctx)
1377 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1379 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1380 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1381 return M_PROPERTY_UNAVAILABLE;
1383 switch (action) {
1384 case M_PROPERTY_PRINT:
1385 if (!arg)
1386 return M_PROPERTY_ERROR;
1387 M_PROPERTY_CLAMP(prop, sub_alignment);
1388 *(char **) arg = strdup(name[sub_alignment]);
1389 return M_PROPERTY_OK;
1390 case M_PROPERTY_SET:
1391 if (!arg)
1392 return M_PROPERTY_ERROR;
1393 case M_PROPERTY_STEP_UP:
1394 case M_PROPERTY_STEP_DOWN:
1395 vo_osd_changed(OSDTYPE_SUBTITLE);
1396 default:
1397 return m_property_choice(prop, action, arg, &sub_alignment);
1401 /// Subtitle visibility (RW)
1402 static int mp_property_sub_visibility(m_option_t * prop, int action,
1403 void *arg, MPContext * mpctx)
1405 if (!mpctx->sh_video)
1406 return M_PROPERTY_UNAVAILABLE;
1408 switch (action) {
1409 case M_PROPERTY_SET:
1410 if (!arg)
1411 return M_PROPERTY_ERROR;
1412 case M_PROPERTY_STEP_UP:
1413 case M_PROPERTY_STEP_DOWN:
1414 vo_osd_changed(OSDTYPE_SUBTITLE);
1415 if (vo_spudec)
1416 vo_osd_changed(OSDTYPE_SPU);
1417 default:
1418 return m_property_flag(prop, action, arg, &sub_visibility);
1422 /// Show only forced subtitles (RW)
1423 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1424 void *arg, MPContext * mpctx)
1426 if (!vo_spudec)
1427 return M_PROPERTY_UNAVAILABLE;
1429 switch (action) {
1430 case M_PROPERTY_SET:
1431 if (!arg)
1432 return M_PROPERTY_ERROR;
1433 case M_PROPERTY_STEP_UP:
1434 case M_PROPERTY_STEP_DOWN:
1435 m_property_flag(prop, action, arg, &forced_subs_only);
1436 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1437 return M_PROPERTY_OK;
1438 default:
1439 return m_property_flag(prop, action, arg, &forced_subs_only);
1444 #ifdef HAVE_FREETYPE
1445 /// Subtitle scale (RW)
1446 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1447 MPContext * mpctx)
1450 switch (action) {
1451 case M_PROPERTY_SET:
1452 if (!arg)
1453 return M_PROPERTY_ERROR;
1454 M_PROPERTY_CLAMP(prop, *(float *) arg);
1455 text_font_scale_factor = *(float *) arg;
1456 force_load_font = 1;
1457 return M_PROPERTY_OK;
1458 case M_PROPERTY_STEP_UP:
1459 case M_PROPERTY_STEP_DOWN:
1460 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1461 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1462 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1463 force_load_font = 1;
1464 return M_PROPERTY_OK;
1465 default:
1466 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1469 #endif
1471 ///@}
1473 /// \defgroup TVProperties TV properties
1474 /// \ingroup Properties
1475 ///@{
1477 #ifdef USE_TV
1479 /// TV color settings (RW)
1480 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1481 MPContext * mpctx)
1483 int r, val;
1484 tvi_handle_t *tvh = mpctx->demuxer->priv;
1485 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1486 return M_PROPERTY_UNAVAILABLE;
1488 switch (action) {
1489 case M_PROPERTY_SET:
1490 if (!arg)
1491 return M_PROPERTY_ERROR;
1492 M_PROPERTY_CLAMP(prop, *(int *) arg);
1493 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1494 case M_PROPERTY_GET:
1495 return tv_get_color_options(tvh, (int) prop->priv, arg);
1496 case M_PROPERTY_STEP_UP:
1497 case M_PROPERTY_STEP_DOWN:
1498 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1499 if (!r)
1500 return M_PROPERTY_ERROR;
1501 val += (arg ? *(int *) arg : 1) *
1502 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1503 M_PROPERTY_CLAMP(prop, val);
1504 return tv_set_color_options(tvh, (int) prop->priv, val);
1506 return M_PROPERTY_ERROR;
1508 return M_PROPERTY_NOT_IMPLEMENTED;
1511 #endif
1513 #ifdef HAVE_TV_TELETEXT
1514 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1515 MPContext * mpctx)
1517 int val,result;
1518 int base_ioctl=(int)prop->priv;
1520 for teletext's GET,SET,STEP ioctls this is not 0
1521 SET is GET+1
1522 STEP is GET+2
1524 tvi_handle_t *tvh = mpctx->demuxer->priv;
1525 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1526 return M_PROPERTY_UNAVAILABLE;
1527 if(!base_ioctl)
1528 return M_PROPERTY_ERROR;
1530 switch (action) {
1531 case M_PROPERTY_GET:
1532 if (!arg)
1533 return M_PROPERTY_ERROR;
1534 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1535 break;
1536 case M_PROPERTY_SET:
1537 if (!arg)
1538 return M_PROPERTY_ERROR;
1539 M_PROPERTY_CLAMP(prop, *(int *) arg);
1540 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1541 break;
1542 case M_PROPERTY_STEP_UP:
1543 case M_PROPERTY_STEP_DOWN:
1544 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1545 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1546 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1547 break;
1548 default:
1549 return M_PROPERTY_NOT_IMPLEMENTED;
1552 return (result==TVI_CONTROL_TRUE?M_PROPERTY_OK:M_PROPERTY_ERROR);
1555 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1556 MPContext * mpctx)
1558 tvi_handle_t *tvh = mpctx->demuxer->priv;
1559 int result;
1560 int val;
1562 //with tvh==NULL will fail too
1563 result=mp_property_teletext_common(prop,action,arg,mpctx);
1564 if(result!=M_PROPERTY_OK)
1565 return result;
1567 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1568 mp_input_set_section("teletext");
1569 else
1570 mp_input_set_section("tv");
1571 return M_PROPERTY_OK;
1574 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1575 MPContext * mpctx)
1577 tvi_handle_t *tvh = mpctx->demuxer->priv;
1578 int result;
1579 int val;
1580 switch(action){
1581 case M_PROPERTY_STEP_UP:
1582 case M_PROPERTY_STEP_DOWN:
1583 //This should be handled separately
1584 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1585 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1586 break;
1587 default:
1588 result=mp_property_teletext_common(prop,action,arg,mpctx);
1590 return result;
1594 #endif /* HAVE_TV_TELETEXT */
1596 ///@}
1598 /// All properties available in MPlayer.
1599 /** \ingroup Properties
1601 static m_option_t mp_properties[] = {
1602 // General
1603 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1604 M_OPT_RANGE, 0, 3, NULL },
1605 { "loop", mp_property_loop, CONF_TYPE_INT,
1606 M_OPT_MIN, -1, 0, NULL },
1607 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1608 M_OPT_RANGE, 0.01, 100.0, NULL },
1609 { "filename", mp_property_filename, CONF_TYPE_STRING,
1610 0, 0, 0, NULL },
1611 { "path", mp_property_path, CONF_TYPE_STRING,
1612 0, 0, 0, NULL },
1613 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1614 0, 0, 0, NULL },
1615 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1616 M_OPT_MIN, 0, 0, NULL },
1617 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1618 M_OPT_MIN, 0, 0, NULL },
1619 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1620 M_OPT_MIN, 0, 0, NULL },
1621 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1622 M_OPT_MIN, 0, 0, NULL },
1623 { "length", mp_property_length, CONF_TYPE_TIME,
1624 M_OPT_MIN, 0, 0, NULL },
1625 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1626 M_OPT_RANGE, 0, 100, NULL },
1627 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1628 M_OPT_MIN, 0, 0, NULL },
1629 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
1630 0, 0, 0, NULL },
1632 // Audio
1633 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
1634 M_OPT_RANGE, 0, 100, NULL },
1635 { "mute", mp_property_mute, CONF_TYPE_FLAG,
1636 M_OPT_RANGE, 0, 1, NULL },
1637 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
1638 M_OPT_RANGE, -100, 100, NULL },
1639 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
1640 0, 0, 0, NULL },
1641 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
1642 0, 0, 0, NULL },
1643 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
1644 0, 0, 0, NULL },
1645 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
1646 0, 0, 0, NULL },
1647 { "channels", mp_property_channels, CONF_TYPE_INT,
1648 0, 0, 0, NULL },
1649 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
1650 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
1651 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
1652 M_OPT_RANGE, -1, 1, NULL },
1654 // Video
1655 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
1656 M_OPT_RANGE, 0, 1, NULL },
1657 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
1658 M_OPT_RANGE, 0, 1, NULL },
1659 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
1660 M_OPT_RANGE, 0, 1, NULL },
1661 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
1662 M_OPT_RANGE, 0, 1, NULL },
1663 { "border", mp_property_border, CONF_TYPE_FLAG,
1664 M_OPT_RANGE, 0, 1, NULL },
1665 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
1666 M_OPT_RANGE, 0, 2, NULL },
1667 { "gamma", mp_property_gamma, CONF_TYPE_INT,
1668 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
1669 { "brightness", mp_property_gamma, CONF_TYPE_INT,
1670 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
1671 { "contrast", mp_property_gamma, CONF_TYPE_INT,
1672 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
1673 { "saturation", mp_property_gamma, CONF_TYPE_INT,
1674 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
1675 { "hue", mp_property_gamma, CONF_TYPE_INT,
1676 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
1677 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
1678 M_OPT_RANGE, 0, 1, NULL },
1679 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
1680 M_OPT_RANGE, 0, 1, NULL },
1681 { "video_format", mp_property_video_format, CONF_TYPE_INT,
1682 0, 0, 0, NULL },
1683 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
1684 0, 0, 0, NULL },
1685 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
1686 0, 0, 0, NULL },
1687 { "width", mp_property_width, CONF_TYPE_INT,
1688 0, 0, 0, NULL },
1689 { "height", mp_property_height, CONF_TYPE_INT,
1690 0, 0, 0, NULL },
1691 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
1692 0, 0, 0, NULL },
1693 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
1694 0, 0, 0, NULL },
1695 { "switch_video", mp_property_video, CONF_TYPE_INT,
1696 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
1697 { "switch_program", mp_property_program, CONF_TYPE_INT,
1698 CONF_RANGE, -1, 65535, NULL },
1700 // Subs
1701 { "sub", mp_property_sub, CONF_TYPE_INT,
1702 M_OPT_MIN, -1, 0, NULL },
1703 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
1704 0, 0, 0, NULL },
1705 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
1706 M_OPT_RANGE, 0, 100, NULL },
1707 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
1708 M_OPT_RANGE, 0, 2, NULL },
1709 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
1710 M_OPT_RANGE, 0, 1, NULL },
1711 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
1712 M_OPT_RANGE, 0, 1, NULL },
1713 #ifdef HAVE_FREETYPE
1714 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
1715 M_OPT_RANGE, 0, 100, NULL },
1716 #endif
1718 #ifdef USE_TV
1719 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
1720 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
1721 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
1722 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
1723 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
1724 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
1725 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
1726 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
1727 #endif
1729 #ifdef HAVE_TV_TELETEXT
1730 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
1731 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
1732 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
1733 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
1734 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
1735 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
1736 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
1737 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
1738 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
1739 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
1740 #endif
1742 { NULL, NULL, NULL, 0, 0, 0, NULL }
1746 int mp_property_do(const char *name, int action, void *val, void *ctx)
1748 return m_property_do(mp_properties, name, action, val, ctx);
1751 char* mp_property_print(const char *name, void* ctx)
1753 char* ret = NULL;
1754 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
1755 return NULL;
1756 return ret;
1759 char *property_expand_string(MPContext * mpctx, char *str)
1761 return m_properties_expand_string(mp_properties, str, mpctx);
1764 void property_print_help(void)
1766 m_properties_print_help_list(mp_properties);
1770 ///@}
1771 // Properties group
1775 * \defgroup Command2Property Command to property bridge
1777 * It is used to handle most commands that just set a property
1778 * and optionally display something on the OSD.
1779 * Two kinds of commands are handled: adjust or toggle.
1781 * Adjust commands take 1 or 2 parameters: <value> <abs>
1782 * If <abs> is non-zero the property is set to the given value
1783 * otherwise it is adjusted.
1785 * Toggle commands take 0 or 1 parameters. With no parameter
1786 * or a value less than the property minimum it just steps the
1787 * property to its next value. Otherwise it sets it to the given
1788 * value.
1793 /// List of the commands that can be handled by setting a property.
1794 static struct {
1795 /// property name
1796 const char *name;
1797 /// cmd id
1798 int cmd;
1799 /// set/adjust or toggle command
1800 int toggle;
1801 /// progressbar type
1802 int osd_progbar;
1803 /// osd msg id if it must be shared
1804 int osd_id;
1805 /// osd msg template
1806 const char *osd_msg;
1807 } set_prop_cmd[] = {
1808 // general
1809 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
1810 // audio
1811 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
1812 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
1813 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
1814 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
1815 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
1816 // video
1817 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
1818 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
1819 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
1820 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
1821 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
1822 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
1823 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
1824 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
1825 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
1826 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
1827 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
1828 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
1829 // subs
1830 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
1831 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
1832 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
1833 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
1834 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
1835 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
1836 #ifdef HAVE_FREETYPE
1837 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
1838 #endif
1839 #ifdef USE_TV
1840 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
1841 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
1842 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
1843 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
1844 #endif
1845 { NULL, 0, 0, 0, -1, NULL }
1849 /// Handle commands that set a property.
1850 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
1852 int i, r;
1853 m_option_t* prop;
1854 const char *pname;
1856 // look for the command
1857 for (i = 0; set_prop_cmd[i].name; i++)
1858 if (set_prop_cmd[i].cmd == cmd->id)
1859 break;
1860 if (!(pname = set_prop_cmd[i].name))
1861 return 0;
1863 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
1864 return 0;
1866 // toggle command
1867 if (set_prop_cmd[i].toggle) {
1868 // set to value
1869 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
1870 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
1871 else
1872 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
1873 } else if (cmd->args[1].v.i) //set
1874 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
1875 else // adjust
1876 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
1878 if (r <= 0)
1879 return 1;
1881 if (set_prop_cmd[i].osd_progbar) {
1882 if (prop->type == CONF_TYPE_INT) {
1883 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
1884 set_osd_bar(set_prop_cmd[i].osd_progbar,
1885 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
1886 } else if (prop->type == CONF_TYPE_FLOAT) {
1887 float f;
1888 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
1889 set_osd_bar(set_prop_cmd[i].osd_progbar,
1890 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
1891 } else
1892 mp_msg(MSGT_CPLAYER, MSGL_ERR,
1893 "Property use an unsupported type.\n");
1894 return 1;
1897 if (set_prop_cmd[i].osd_msg) {
1898 char *val = mp_property_print(pname, mpctx);
1899 if (val) {
1900 set_osd_msg(set_prop_cmd[i].osd_id >=
1901 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
1902 1, osd_duration, set_prop_cmd[i].osd_msg, val);
1903 free(val);
1906 return 1;
1910 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
1912 sh_audio_t * const sh_audio = mpctx->sh_audio;
1913 sh_video_t * const sh_video = mpctx->sh_video;
1914 int brk_cmd = 0;
1915 if (!set_property_command(mpctx, cmd))
1916 switch (cmd->id) {
1917 case MP_CMD_SEEK:{
1918 float v;
1919 int abs;
1920 if (sh_video)
1921 mpctx->osd_show_percentage = sh_video->fps;
1922 v = cmd->args[0].v.f;
1923 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
1924 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
1925 abs_seek_pos = 1;
1926 if (sh_video)
1927 mpctx->osd_function =
1928 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
1929 rel_seek_secs = v;
1930 } else if (abs) { /* Absolute seek by percentage */
1931 abs_seek_pos = 3;
1932 if (sh_video)
1933 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
1934 rel_seek_secs = v / 100.0;
1935 } else {
1936 rel_seek_secs += v;
1937 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
1939 brk_cmd = 1;
1941 break;
1943 case MP_CMD_SET_PROPERTY:{
1944 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
1945 cmd->args[1].v.s, mpctx);
1946 if (r == M_PROPERTY_UNKNOWN)
1947 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1948 "Unknown property: '%s'\n", cmd->args[0].v.s);
1949 else if (r <= 0)
1950 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1951 "Failed to set property '%s' to '%s'.\n",
1952 cmd->args[0].v.s, cmd->args[1].v.s);
1954 break;
1956 case MP_CMD_STEP_PROPERTY:{
1957 void* arg = NULL;
1958 int r,i;
1959 double d;
1960 off_t o;
1961 if (cmd->args[1].v.f) {
1962 m_option_t* prop;
1963 if((r = mp_property_do(cmd->args[0].v.s,
1964 M_PROPERTY_GET_TYPE,
1965 &prop, mpctx)) <= 0)
1966 goto step_prop_err;
1967 if(prop->type == CONF_TYPE_INT ||
1968 prop->type == CONF_TYPE_FLAG)
1969 i = cmd->args[1].v.f, arg = &i;
1970 else if(prop->type == CONF_TYPE_FLOAT)
1971 arg = &cmd->args[1].v.f;
1972 else if(prop->type == CONF_TYPE_DOUBLE ||
1973 prop->type == CONF_TYPE_TIME)
1974 d = cmd->args[1].v.f, arg = &d;
1975 else if(prop->type == CONF_TYPE_POSITION)
1976 o = cmd->args[1].v.f, arg = &o;
1977 else
1978 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1979 "Ignoring step size stepping property '%s'.\n",
1980 cmd->args[0].v.s);
1982 r = mp_property_do(cmd->args[0].v.s,
1983 cmd->args[2].v.i < 0 ?
1984 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
1985 arg, mpctx);
1986 step_prop_err:
1987 if (r == M_PROPERTY_UNKNOWN)
1988 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1989 "Unknown property: '%s'\n", cmd->args[0].v.s);
1990 else if (r <= 0)
1991 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1992 "Failed to increment property '%s' by %f.\n",
1993 cmd->args[0].v.s, cmd->args[1].v.f);
1995 break;
1997 case MP_CMD_GET_PROPERTY:{
1998 char *tmp;
1999 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2000 &tmp, mpctx) <= 0) {
2001 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2002 "Failed to get value of property '%s'.\n",
2003 cmd->args[0].v.s);
2004 break;
2006 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2007 cmd->args[0].v.s, tmp);
2008 free(tmp);
2010 break;
2012 case MP_CMD_EDL_MARK:
2013 if (edl_fd) {
2014 float v = sh_video ? sh_video->pts :
2015 playing_audio_pts(sh_audio, mpctx->d_audio,
2016 mpctx->audio_out);
2018 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2019 mpctx->begin_skip = v;
2020 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2021 } else {
2022 if (mpctx->begin_skip > v)
2023 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2024 else {
2025 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2026 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2028 mpctx->begin_skip = MP_NOPTS_VALUE;
2031 break;
2033 case MP_CMD_SWITCH_RATIO:
2034 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2035 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2036 else
2037 movie_aspect = cmd->args[0].v.f;
2038 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2039 break;
2041 case MP_CMD_SPEED_INCR:{
2042 float v = cmd->args[0].v.f;
2043 playback_speed += v;
2044 build_afilter_chain(sh_audio, &ao_data);
2045 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2046 playback_speed);
2047 } break;
2049 case MP_CMD_SPEED_MULT:{
2050 float v = cmd->args[0].v.f;
2051 playback_speed *= v;
2052 build_afilter_chain(sh_audio, &ao_data);
2053 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2054 playback_speed);
2055 } break;
2057 case MP_CMD_SPEED_SET:{
2058 float v = cmd->args[0].v.f;
2059 playback_speed = v;
2060 build_afilter_chain(sh_audio, &ao_data);
2061 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2062 playback_speed);
2063 } break;
2065 case MP_CMD_FRAME_STEP:
2066 case MP_CMD_PAUSE:
2067 cmd->pausing = 1;
2068 brk_cmd = 1;
2069 break;
2071 case MP_CMD_FILE_FILTER:
2072 file_filter = cmd->args[0].v.i;
2073 break;
2075 case MP_CMD_QUIT:
2076 exit_player_with_rc(MSGTR_Exit_quit,
2077 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2079 case MP_CMD_PLAY_TREE_STEP:{
2080 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2081 int force = cmd->args[1].v.i;
2083 #ifdef HAVE_NEW_GUI
2084 if (use_gui) {
2085 int i = 0;
2086 if (n > 0)
2087 for (i = 0; i < n; i++)
2088 mplNext();
2089 else
2090 for (i = 0; i < -1 * n; i++)
2091 mplPrev();
2092 } else
2093 #endif
2095 if (!force && mpctx->playtree_iter) {
2096 play_tree_iter_t *i =
2097 play_tree_iter_new_copy(mpctx->playtree_iter);
2098 if (play_tree_iter_step(i, n, 0) ==
2099 PLAY_TREE_ITER_ENTRY)
2100 mpctx->eof =
2101 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2102 play_tree_iter_free(i);
2103 } else
2104 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2105 if (mpctx->eof)
2106 mpctx->play_tree_step = n;
2107 brk_cmd = 1;
2110 break;
2112 case MP_CMD_PLAY_TREE_UP_STEP:{
2113 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2114 int force = cmd->args[1].v.i;
2116 if (!force && mpctx->playtree_iter) {
2117 play_tree_iter_t *i =
2118 play_tree_iter_new_copy(mpctx->playtree_iter);
2119 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2120 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2121 play_tree_iter_free(i);
2122 } else
2123 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2124 brk_cmd = 1;
2126 break;
2128 case MP_CMD_PLAY_ALT_SRC_STEP:
2129 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2130 int v = cmd->args[0].v.i;
2131 if (v > 0
2132 && mpctx->playtree_iter->file <
2133 mpctx->playtree_iter->num_files)
2134 mpctx->eof = PT_NEXT_SRC;
2135 else if (v < 0 && mpctx->playtree_iter->file > 1)
2136 mpctx->eof = PT_PREV_SRC;
2138 brk_cmd = 1;
2139 break;
2141 case MP_CMD_SUB_STEP:
2142 if (sh_video) {
2143 int movement = cmd->args[0].v.i;
2144 step_sub(subdata, sh_video->pts, movement);
2145 #ifdef USE_ASS
2146 if (ass_track)
2147 sub_delay +=
2148 ass_step_sub(ass_track,
2149 (sh_video->pts +
2150 sub_delay) * 1000 + .5, movement) / 1000.;
2151 #endif
2152 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2153 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2155 break;
2157 case MP_CMD_SUB_LOG:
2158 log_sub();
2159 break;
2161 case MP_CMD_OSD:{
2162 int v = cmd->args[0].v.i;
2163 int max = (term_osd
2164 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2165 if (osd_level > max)
2166 osd_level = max;
2167 if (v < 0)
2168 osd_level = (osd_level + 1) % (max + 1);
2169 else
2170 osd_level = v > max ? max : v;
2171 /* Show OSD state when disabled, but not when an explicit
2172 argument is given to the OSD command, i.e. in slave mode. */
2173 if (v == -1 && osd_level <= 1)
2174 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2175 MSGTR_OSDosd,
2176 osd_level ? MSGTR_OSDenabled :
2177 MSGTR_OSDdisabled);
2178 else
2179 rm_osd_msg(OSD_MSG_OSD_STATUS);
2181 break;
2183 case MP_CMD_OSD_SHOW_TEXT:
2184 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2185 (cmd->args[1].v.i <
2186 0 ? osd_duration : cmd->args[1].v.i),
2187 "%-.63s", cmd->args[0].v.s);
2188 break;
2190 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2191 char *txt = m_properties_expand_string(mp_properties,
2192 cmd->args[0].v.s,
2193 mpctx);
2194 /* if no argument supplied take default osd_duration, else <arg> ms. */
2195 if (txt) {
2196 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2197 (cmd->args[1].v.i <
2198 0 ? osd_duration : cmd->args[1].v.i),
2199 "%-.63s", txt);
2200 free(txt);
2203 break;
2205 case MP_CMD_LOADFILE:{
2206 play_tree_t *e = play_tree_new();
2207 play_tree_add_file(e, cmd->args[0].v.s);
2209 if (cmd->args[1].v.i) // append
2210 play_tree_append_entry(mpctx->playtree, e);
2211 else {
2212 // Go back to the starting point.
2213 while (play_tree_iter_up_step
2214 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2215 /* NOP */ ;
2216 play_tree_free_list(mpctx->playtree->child, 1);
2217 play_tree_set_child(mpctx->playtree, e);
2218 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2219 mpctx->eof = PT_NEXT_SRC;
2221 brk_cmd = 1;
2223 break;
2225 case MP_CMD_LOADLIST:{
2226 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2227 if (!e)
2228 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2229 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2230 else {
2231 if (cmd->args[1].v.i) // append
2232 play_tree_append_entry(mpctx->playtree, e);
2233 else {
2234 // Go back to the starting point.
2235 while (play_tree_iter_up_step
2236 (mpctx->playtree_iter, 0, 1)
2237 != PLAY_TREE_ITER_END)
2238 /* NOP */ ;
2239 play_tree_free_list(mpctx->playtree->child, 1);
2240 play_tree_set_child(mpctx->playtree, e);
2241 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2242 mpctx->eof = PT_NEXT_SRC;
2245 brk_cmd = 1;
2247 break;
2249 #ifdef USE_RADIO
2250 case MP_CMD_RADIO_STEP_CHANNEL:
2251 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2252 int v = cmd->args[0].v.i;
2253 if (v > 0)
2254 radio_step_channel(mpctx->demuxer->stream,
2255 RADIO_CHANNEL_HIGHER);
2256 else
2257 radio_step_channel(mpctx->demuxer->stream,
2258 RADIO_CHANNEL_LOWER);
2259 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2260 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2261 MSGTR_OSDChannel,
2262 radio_get_channel_name(mpctx->demuxer->stream));
2265 break;
2267 case MP_CMD_RADIO_SET_CHANNEL:
2268 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2269 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2270 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2271 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2272 MSGTR_OSDChannel,
2273 radio_get_channel_name(mpctx->demuxer->stream));
2276 break;
2278 case MP_CMD_RADIO_SET_FREQ:
2279 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2280 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2281 break;
2283 case MP_CMD_RADIO_STEP_FREQ:
2284 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2285 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2286 break;
2287 #endif
2289 #ifdef USE_TV
2290 case MP_CMD_TV_SET_FREQ:
2291 if (mpctx->file_format == DEMUXER_TYPE_TV)
2292 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2293 cmd->args[0].v.f * 16.0);
2294 #ifdef HAVE_PVR
2295 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2296 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2297 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2298 pvr_get_current_channelname (mpctx->stream),
2299 pvr_get_current_stationname (mpctx->stream));
2301 #endif /* HAVE_PVR */
2302 break;
2304 case MP_CMD_TV_STEP_FREQ:
2305 if (mpctx->file_format == DEMUXER_TYPE_TV)
2306 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2307 cmd->args[0].v.f * 16.0);
2308 #ifdef HAVE_PVR
2309 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2310 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2311 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2312 pvr_get_current_channelname (mpctx->stream),
2313 pvr_get_current_frequency (mpctx->stream));
2315 #endif /* HAVE_PVR */
2316 break;
2318 case MP_CMD_TV_SET_NORM:
2319 if (mpctx->file_format == DEMUXER_TYPE_TV)
2320 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2321 cmd->args[0].v.s);
2322 break;
2324 case MP_CMD_TV_STEP_CHANNEL:{
2325 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2326 int v = cmd->args[0].v.i;
2327 if (v > 0) {
2328 tv_step_channel((tvi_handle_t *) (mpctx->
2329 demuxer->priv),
2330 TV_CHANNEL_HIGHER);
2331 } else {
2332 tv_step_channel((tvi_handle_t *) (mpctx->
2333 demuxer->priv),
2334 TV_CHANNEL_LOWER);
2336 if (tv_channel_list) {
2337 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2338 MSGTR_OSDChannel, tv_channel_current->name);
2339 //vo_osd_changed(OSDTYPE_SUBTITLE);
2342 #ifdef HAVE_PVR
2343 else if (mpctx->stream &&
2344 mpctx->stream->type == STREAMTYPE_PVR) {
2345 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2346 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2347 pvr_get_current_channelname (mpctx->stream),
2348 pvr_get_current_stationname (mpctx->stream));
2350 #endif /* HAVE_PVR */
2352 #ifdef HAS_DVBIN_SUPPORT
2353 if ((mpctx->stream->type == STREAMTYPE_DVB)
2354 && mpctx->stream->priv) {
2355 dvb_priv_t *priv = (dvb_priv_t *) mpctx->stream->priv;
2356 if (priv->is_on) {
2357 int dir;
2358 int v = cmd->args[0].v.i;
2360 mpctx->last_dvb_step = v;
2361 if (v > 0)
2362 dir = DVB_CHANNEL_HIGHER;
2363 else
2364 dir = DVB_CHANNEL_LOWER;
2367 if (dvb_step_channel(priv, dir))
2368 mpctx->eof = mpctx->dvbin_reopen = 1;
2371 #endif /* HAS_DVBIN_SUPPORT */
2372 break;
2374 case MP_CMD_TV_SET_CHANNEL:
2375 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2376 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2377 cmd->args[0].v.s);
2378 if (tv_channel_list) {
2379 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2380 MSGTR_OSDChannel, tv_channel_current->name);
2381 //vo_osd_changed(OSDTYPE_SUBTITLE);
2384 #ifdef HAVE_PVR
2385 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2386 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2387 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2388 pvr_get_current_channelname (mpctx->stream),
2389 pvr_get_current_stationname (mpctx->stream));
2391 #endif /* HAVE_PVR */
2392 break;
2394 #ifdef HAS_DVBIN_SUPPORT
2395 case MP_CMD_DVB_SET_CHANNEL:
2396 if ((mpctx->stream->type == STREAMTYPE_DVB)
2397 && mpctx->stream->priv) {
2398 dvb_priv_t *priv = (dvb_priv_t *) mpctx->stream->priv;
2399 if (priv->is_on) {
2400 if (priv->list->current <= cmd->args[0].v.i)
2401 mpctx->last_dvb_step = 1;
2402 else
2403 mpctx->last_dvb_step = -1;
2405 if (dvb_set_channel
2406 (priv, cmd->args[1].v.i, cmd->args[0].v.i))
2407 mpctx->eof = mpctx->dvbin_reopen = 1;
2410 break;
2411 #endif /* HAS_DVBIN_SUPPORT */
2413 case MP_CMD_TV_LAST_CHANNEL:
2414 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2415 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2416 if (tv_channel_list) {
2417 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2418 MSGTR_OSDChannel, tv_channel_current->name);
2419 //vo_osd_changed(OSDTYPE_SUBTITLE);
2422 #ifdef HAVE_PVR
2423 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2424 pvr_set_lastchannel (mpctx->stream);
2425 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2426 pvr_get_current_channelname (mpctx->stream),
2427 pvr_get_current_stationname (mpctx->stream));
2429 #endif /* HAVE_PVR */
2430 break;
2432 case MP_CMD_TV_STEP_NORM:
2433 if (mpctx->file_format == DEMUXER_TYPE_TV)
2434 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2435 break;
2437 case MP_CMD_TV_STEP_CHANNEL_LIST:
2438 if (mpctx->file_format == DEMUXER_TYPE_TV)
2439 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2440 break;
2441 #ifdef HAVE_TV_TELETEXT
2442 case MP_CMD_TV_TELETEXT_ADD_DEC:
2444 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2445 if (mpctx->file_format == DEMUXER_TYPE_TV)
2446 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2447 break;
2449 #endif /* HAVE_TV_TELETEXT */
2450 #endif /* USE_TV */
2452 case MP_CMD_SUB_LOAD:
2453 if (sh_video) {
2454 int n = mpctx->set_of_sub_size;
2455 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2456 if (n != mpctx->set_of_sub_size) {
2457 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2458 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2459 mpctx->global_sub_size;
2460 ++mpctx->global_sub_size;
2463 break;
2465 case MP_CMD_SUB_REMOVE:
2466 if (sh_video) {
2467 int v = cmd->args[0].v.i;
2468 sub_data *subd;
2469 if (v < 0) {
2470 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2471 subd = mpctx->set_of_subtitles[v];
2472 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2473 MSGTR_RemovedSubtitleFile, v + 1,
2474 filename_recode(subd->filename));
2475 sub_free(subd);
2476 mpctx->set_of_subtitles[v] = NULL;
2478 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2479 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2480 mpctx->set_of_sub_size = 0;
2481 if (mpctx->set_of_sub_pos >= 0) {
2482 mpctx->global_sub_pos = -2;
2483 subdata = NULL;
2484 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2486 } else if (v < mpctx->set_of_sub_size) {
2487 subd = mpctx->set_of_subtitles[v];
2488 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2489 MSGTR_RemovedSubtitleFile, v + 1,
2490 filename_recode(subd->filename));
2491 sub_free(subd);
2492 if (mpctx->set_of_sub_pos == v) {
2493 mpctx->global_sub_pos = -2;
2494 subdata = NULL;
2495 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2496 } else if (mpctx->set_of_sub_pos > v) {
2497 --mpctx->set_of_sub_pos;
2498 --mpctx->global_sub_pos;
2500 while (++v < mpctx->set_of_sub_size)
2501 mpctx->set_of_subtitles[v - 1] =
2502 mpctx->set_of_subtitles[v];
2503 --mpctx->set_of_sub_size;
2504 --mpctx->global_sub_size;
2505 if (mpctx->set_of_sub_size <= 0)
2506 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2507 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2510 break;
2512 case MP_CMD_GET_SUB_VISIBILITY:
2513 if (sh_video) {
2514 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2515 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2517 break;
2519 case MP_CMD_SCREENSHOT:
2520 if (vo_config_count) {
2521 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2522 if (CONTROL_OK !=
2523 ((vf_instance_t *) sh_video->vfilter)->
2524 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2525 &cmd->args[0].v.i))
2526 mpctx->video_out->control(VOCTRL_SCREENSHOT, NULL);
2528 break;
2530 case MP_CMD_VF_CHANGE_RECTANGLE:
2531 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2532 break;
2534 case MP_CMD_GET_TIME_LENGTH:{
2535 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2536 demuxer_get_time_length(mpctx->demuxer));
2538 break;
2540 case MP_CMD_GET_FILENAME:{
2541 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2542 get_metadata(META_NAME));
2544 break;
2546 case MP_CMD_GET_VIDEO_CODEC:{
2547 char *inf = get_metadata(META_VIDEO_CODEC);
2548 if (!inf)
2549 inf = strdup("");
2550 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2551 free(inf);
2553 break;
2555 case MP_CMD_GET_VIDEO_BITRATE:{
2556 char *inf = get_metadata(META_VIDEO_BITRATE);
2557 if (!inf)
2558 inf = strdup("");
2559 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2560 free(inf);
2562 break;
2564 case MP_CMD_GET_VIDEO_RESOLUTION:{
2565 char *inf = get_metadata(META_VIDEO_RESOLUTION);
2566 if (!inf)
2567 inf = strdup("");
2568 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2569 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
2570 free(inf);
2572 break;
2574 case MP_CMD_GET_AUDIO_CODEC:{
2575 char *inf = get_metadata(META_AUDIO_CODEC);
2576 if (!inf)
2577 inf = strdup("");
2578 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
2579 free(inf);
2581 break;
2583 case MP_CMD_GET_AUDIO_BITRATE:{
2584 char *inf = get_metadata(META_AUDIO_BITRATE);
2585 if (!inf)
2586 inf = strdup("");
2587 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
2588 free(inf);
2590 break;
2592 case MP_CMD_GET_AUDIO_SAMPLES:{
2593 char *inf = get_metadata(META_AUDIO_SAMPLES);
2594 if (!inf)
2595 inf = strdup("");
2596 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
2597 free(inf);
2599 break;
2601 case MP_CMD_GET_META_TITLE:{
2602 char *inf = get_metadata(META_INFO_TITLE);
2603 if (!inf)
2604 inf = strdup("");
2605 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
2606 free(inf);
2608 break;
2610 case MP_CMD_GET_META_ARTIST:{
2611 char *inf = get_metadata(META_INFO_ARTIST);
2612 if (!inf)
2613 inf = strdup("");
2614 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
2615 free(inf);
2617 break;
2619 case MP_CMD_GET_META_ALBUM:{
2620 char *inf = get_metadata(META_INFO_ALBUM);
2621 if (!inf)
2622 inf = strdup("");
2623 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
2624 free(inf);
2626 break;
2628 case MP_CMD_GET_META_YEAR:{
2629 char *inf = get_metadata(META_INFO_YEAR);
2630 if (!inf)
2631 inf = strdup("");
2632 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
2633 free(inf);
2635 break;
2637 case MP_CMD_GET_META_COMMENT:{
2638 char *inf = get_metadata(META_INFO_COMMENT);
2639 if (!inf)
2640 inf = strdup("");
2641 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
2642 free(inf);
2644 break;
2646 case MP_CMD_GET_META_TRACK:{
2647 char *inf = get_metadata(META_INFO_TRACK);
2648 if (!inf)
2649 inf = strdup("");
2650 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
2651 free(inf);
2653 break;
2655 case MP_CMD_GET_META_GENRE:{
2656 char *inf = get_metadata(META_INFO_GENRE);
2657 if (!inf)
2658 inf = strdup("");
2659 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
2660 free(inf);
2662 break;
2664 case MP_CMD_GET_VO_FULLSCREEN:
2665 if (mpctx->video_out && vo_config_count)
2666 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
2667 break;
2669 case MP_CMD_GET_PERCENT_POS:
2670 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
2671 demuxer_get_percent_pos(mpctx->demuxer));
2672 break;
2674 case MP_CMD_GET_TIME_POS:{
2675 float pos = 0;
2676 if (sh_video)
2677 pos = sh_video->pts;
2678 else if (sh_audio && mpctx->audio_out)
2679 pos =
2680 playing_audio_pts(sh_audio, mpctx->d_audio,
2681 mpctx->audio_out);
2682 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
2684 break;
2686 case MP_CMD_RUN:
2687 #ifndef __MINGW32__
2688 if (!fork()) {
2689 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
2690 exit(0);
2692 #endif
2693 break;
2695 case MP_CMD_KEYDOWN_EVENTS:
2696 mplayer_put_key(cmd->args[0].v.i);
2697 break;
2699 case MP_CMD_SEEK_CHAPTER:{
2700 int seek = cmd->args[0].v.i;
2701 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2702 int chap;
2703 float next_pts = 0;
2704 int num_chapters;
2705 char *chapter_name;
2707 rel_seek_secs = 0;
2708 abs_seek_pos = 0;
2709 chap =
2710 demuxer_seek_chapter(mpctx->demuxer, seek, abs,
2711 &next_pts, &num_chapters,
2712 &chapter_name);
2713 if (chap != -1) {
2714 if (next_pts > -1.0) {
2715 abs_seek_pos = 1;
2716 rel_seek_secs = next_pts;
2718 if (chapter_name) {
2719 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2720 MSGTR_OSDChapter, chap + 1, chapter_name);
2721 free(chapter_name);
2723 } else {
2724 if (seek > 0)
2725 rel_seek_secs = 1000000000.;
2726 else
2727 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2728 MSGTR_OSDChapter, 0, MSGTR_Unknown);
2730 break;
2732 break;
2734 case MP_CMD_SET_MOUSE_POS:{
2735 int button = -1, pointer_x, pointer_y;
2736 double dx, dy;
2737 pointer_x = cmd->args[0].v.i;
2738 pointer_y = cmd->args[1].v.i;
2739 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
2740 #ifdef USE_DVDNAV
2741 if (mpctx->stream->type == STREAMTYPE_DVDNAV
2742 && dx > 0.0 && dy > 0.0) {
2743 pointer_x = (int) (dx * (double) sh_video->disp_w);
2744 pointer_y = (int) (dy * (double) sh_video->disp_h);
2745 mp_dvdnav_update_mouse_pos(mpctx->stream,
2746 pointer_x, pointer_y, &button);
2747 if (button > 0)
2748 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2749 "Selected button number %d", button);
2751 #endif
2753 break;
2755 #ifdef USE_DVDNAV
2756 case MP_CMD_DVDNAV:{
2757 int button = -1;
2758 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
2759 break;
2761 if (mp_dvdnav_handle_input
2762 (mpctx->stream, cmd->args[0].v.i, &button)) {
2763 uninit_player(INITED_ALL - (INITED_STREAM | INITED_INPUT |
2764 (fixed_vo ? INITED_VO : 0)));
2765 brk_cmd = 2;
2766 } else if (button > 0)
2767 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2768 "Selected button number %d", button);
2770 break;
2771 #endif
2773 default:
2774 #ifdef HAVE_NEW_GUI
2775 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
2776 guiGetEvent(guiIEvent, (char *) cmd->id);
2777 else
2778 #endif
2779 mp_msg(MSGT_CPLAYER, MSGL_V,
2780 "Received unknown cmd %s\n", cmd->name);
2783 switch (cmd->pausing) {
2784 case 1: // "pausing"
2785 mpctx->osd_function = OSD_PAUSE;
2786 break;
2787 case 3: // "pausing_toggle"
2788 mpctx->was_paused = !mpctx->was_paused;
2789 // fall through
2790 case 2: // "pausing_keep"
2791 if (mpctx->was_paused)
2792 mpctx->osd_function = OSD_PAUSE;
2794 return brk_cmd;