Warning fixes:
[mplayer/greg.git] / command.c
blob97c646cc703a08b32bb33e76c31ddc4e66d88330
1 #include <stdlib.h>
2 #include <inttypes.h>
3 #include <unistd.h>
4 #include <string.h>
6 #include "config.h"
7 #include "input/input.h"
8 #include "stream/stream.h"
9 #include "libmpdemux/demuxer.h"
10 #include "libmpdemux/stheader.h"
11 #include "codec-cfg.h"
12 #include "mplayer.h"
13 #include "libvo/sub.h"
14 #include "m_option.h"
15 #include "m_property.h"
16 #include "help_mp.h"
17 #include "metadata.h"
18 #include "libmpcodecs/mp_image.h"
19 #include "libmpcodecs/vf.h"
20 #include "libmpcodecs/vd.h"
21 #include "libvo/video_out.h"
22 #include "libvo/font_load.h"
23 #include "playtree.h"
24 #include "libao2/audio_out.h"
25 #include "mpcommon.h"
26 #include "mixer.h"
27 #include "libmpdemux/matroska.h"
28 #include "libmpcodecs/dec_video.h"
29 #include "vobsub.h"
30 #include "spudec.h"
31 #include "get_path.h"
32 #ifdef USE_TV
33 #include "stream/tv.h"
34 #endif
35 #ifdef USE_RADIO
36 #include "stream/stream_radio.h"
37 #endif
38 #ifdef HAVE_PVR
39 #include "stream/pvr.h"
40 #endif
41 #ifdef HAS_DVBIN_SUPPORT
42 #include "stream/dvbin.h"
43 #endif
44 #ifdef USE_DVDREAD
45 #include "stream/stream_dvd.h"
46 #endif
47 #ifdef USE_DVDNAV
48 #include "stream/stream_dvdnav.h"
49 #endif
50 #ifdef USE_ASS
51 #include "libass/ass.h"
52 #include "libass/ass_mp.h"
53 #endif
54 #ifdef HAVE_NEW_GUI
55 #include "gui/interface.h"
56 #endif
58 #include "mp_core.h"
59 #include "mp_fifo.h"
61 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
63 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy)
65 //remove the borders, if any, and rescale to the range [0,1],[0,1]
66 if (vo_fs) { //we are in full-screen mode
67 if (vo_screenwidth > vo_dwidth) //there are borders along the x axis
68 ix -= (vo_screenwidth - vo_dwidth) / 2;
69 if (vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
70 iy -= (vo_screenheight - vo_dheight) / 2;
72 if (ix < 0 || ix > vo_dwidth) {
73 *dx = *dy = -1.0;
74 return;
75 } //we are on one of the borders
76 if (iy < 0 || iy > vo_dheight) {
77 *dx = *dy = -1.0;
78 return;
79 } //we are on one of the borders
82 *dx = (double) ix / (double) vo_dwidth;
83 *dy = (double) iy / (double) vo_dheight;
85 mp_msg(MSGT_CPLAYER, MSGL_V,
86 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
87 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth,
88 vo_dheight, vo_fs);
91 static int sub_source(MPContext * mpctx)
93 int source = -1;
94 int top = -1;
95 int i;
96 for (i = 0; i < SUB_SOURCES; i++) {
97 int j = mpctx->global_sub_indices[i];
98 if ((j >= 0) && (j > top) && (mpctx->global_sub_pos >= j)) {
99 source = i;
100 top = j;
103 return source;
107 * \brief Log the currently displayed subtitle to a file
109 * Logs the current or last displayed subtitle together with filename
110 * and time information to ~/.mplayer/subtitle_log
112 * Intended purpose is to allow convenient marking of bogus subtitles
113 * which need to be fixed while watching the movie.
116 static void log_sub(void)
118 char *fname;
119 FILE *f;
120 int i;
122 if (subdata == NULL || vo_sub_last == NULL)
123 return;
124 fname = get_path("subtitle_log");
125 f = fopen(fname, "a");
126 if (!f)
127 return;
128 fprintf(f, "----------------------------------------------------------\n");
129 if (subdata->sub_uses_time) {
130 fprintf(f,
131 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
132 filename, vo_sub_last->start / 360000,
133 (vo_sub_last->start / 6000) % 60,
134 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
135 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
136 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
137 } else {
138 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start,
139 vo_sub_last->end);
141 for (i = 0; i < vo_sub_last->lines; i++) {
142 fprintf(f, "%s\n", vo_sub_last->text[i]);
144 fclose(f);
148 /// \defgroup Properties
149 ///@{
151 /// \defgroup GeneralProperties General properties
152 /// \ingroup Properties
153 ///@{
155 /// OSD level (RW)
156 static int mp_property_osdlevel(m_option_t * prop, int action, void *arg,
157 MPContext * mpctx)
159 return m_property_choice(prop, action, arg, &osd_level);
162 /// Loop (RW)
163 static int mp_property_loop(m_option_t * prop, int action, void *arg,
164 MPContext * mpctx)
166 switch (action) {
167 case M_PROPERTY_PRINT:
168 if (!arg) return M_PROPERTY_ERROR;
169 if (mpctx->loop_times < 0)
170 *(char**)arg = strdup("off");
171 else if (mpctx->loop_times == 0)
172 *(char**)arg = strdup("inf");
173 else
174 break;
175 return M_PROPERTY_OK;
177 return m_property_int_range(prop, action, arg, &mpctx->loop_times);
180 /// Playback speed (RW)
181 static int mp_property_playback_speed(m_option_t * prop, int action,
182 void *arg, MPContext * mpctx)
184 switch (action) {
185 case M_PROPERTY_SET:
186 if (!arg)
187 return M_PROPERTY_ERROR;
188 M_PROPERTY_CLAMP(prop, *(float *) arg);
189 playback_speed = *(float *) arg;
190 build_afilter_chain(mpctx->sh_audio, &ao_data);
191 return M_PROPERTY_OK;
192 case M_PROPERTY_STEP_UP:
193 case M_PROPERTY_STEP_DOWN:
194 playback_speed += (arg ? *(float *) arg : 0.1) *
195 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
196 M_PROPERTY_CLAMP(prop, playback_speed);
197 build_afilter_chain(mpctx->sh_audio, &ao_data);
198 return M_PROPERTY_OK;
200 return m_property_float_range(prop, action, arg, &playback_speed);
203 /// filename with path (RO)
204 static int mp_property_path(m_option_t * prop, int action, void *arg,
205 MPContext * mpctx)
207 return m_property_string_ro(prop, action, arg, filename);
210 /// filename without path (RO)
211 static int mp_property_filename(m_option_t * prop, int action, void *arg,
212 MPContext * mpctx)
214 char *f;
215 if (!filename)
216 return M_PROPERTY_UNAVAILABLE;
217 if (((f = strrchr(filename, '/')) || (f = strrchr(filename, '\\'))) && f[1])
218 f++;
219 else
220 f = filename;
221 return m_property_string_ro(prop, action, arg, f);
224 /// Demuxer name (RO)
225 static int mp_property_demuxer(m_option_t * prop, int action, void *arg,
226 MPContext * mpctx)
228 if (!mpctx->demuxer)
229 return M_PROPERTY_UNAVAILABLE;
230 return m_property_string_ro(prop, action, arg,
231 (char *) mpctx->demuxer->desc->name);
234 /// Position in the stream (RW)
235 static int mp_property_stream_pos(m_option_t * prop, int action, void *arg,
236 MPContext * mpctx)
238 if (!mpctx->demuxer || !mpctx->demuxer->stream)
239 return M_PROPERTY_UNAVAILABLE;
240 if (!arg)
241 return M_PROPERTY_ERROR;
242 switch (action) {
243 case M_PROPERTY_GET:
244 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
245 return M_PROPERTY_OK;
246 case M_PROPERTY_SET:
247 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
248 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
249 return M_PROPERTY_OK;
251 return M_PROPERTY_NOT_IMPLEMENTED;
254 /// Stream start offset (RO)
255 static int mp_property_stream_start(m_option_t * prop, int action,
256 void *arg, MPContext * mpctx)
258 if (!mpctx->demuxer || !mpctx->demuxer->stream)
259 return M_PROPERTY_UNAVAILABLE;
260 switch (action) {
261 case M_PROPERTY_GET:
262 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
263 return M_PROPERTY_OK;
265 return M_PROPERTY_NOT_IMPLEMENTED;
268 /// Stream end offset (RO)
269 static int mp_property_stream_end(m_option_t * prop, int action, void *arg,
270 MPContext * mpctx)
272 if (!mpctx->demuxer || !mpctx->demuxer->stream)
273 return M_PROPERTY_UNAVAILABLE;
274 switch (action) {
275 case M_PROPERTY_GET:
276 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
277 return M_PROPERTY_OK;
279 return M_PROPERTY_NOT_IMPLEMENTED;
282 /// Stream length (RO)
283 static int mp_property_stream_length(m_option_t * prop, int action,
284 void *arg, MPContext * mpctx)
286 if (!mpctx->demuxer || !mpctx->demuxer->stream)
287 return M_PROPERTY_UNAVAILABLE;
288 switch (action) {
289 case M_PROPERTY_GET:
290 *(off_t *) arg =
291 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
292 return M_PROPERTY_OK;
294 return M_PROPERTY_NOT_IMPLEMENTED;
297 /// Media length in seconds (RO)
298 static int mp_property_length(m_option_t * prop, int action, void *arg,
299 MPContext * mpctx)
301 double len;
303 if (!mpctx->demuxer ||
304 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
305 return M_PROPERTY_UNAVAILABLE;
307 return m_property_time_ro(prop, action, arg, len);
310 /// Current position in percent (RW)
311 static int mp_property_percent_pos(m_option_t * prop, int action,
312 void *arg, MPContext * mpctx) {
313 int pos;
315 if (!mpctx->demuxer)
316 return M_PROPERTY_UNAVAILABLE;
318 switch(action) {
319 case M_PROPERTY_SET:
320 if(!arg) return M_PROPERTY_ERROR;
321 M_PROPERTY_CLAMP(prop, *(int*)arg);
322 pos = *(int*)arg;
323 break;
324 case M_PROPERTY_STEP_UP:
325 case M_PROPERTY_STEP_DOWN:
326 pos = demuxer_get_percent_pos(mpctx->demuxer);
327 pos += (arg ? *(int*)arg : 10) *
328 (action == M_PROPERTY_STEP_UP ? 1 : -1);
329 M_PROPERTY_CLAMP(prop, pos);
330 break;
331 default:
332 return m_property_int_ro(prop, action, arg,
333 demuxer_get_percent_pos(mpctx->demuxer));
336 abs_seek_pos = 3;
337 rel_seek_secs = pos / 100.0;
338 return M_PROPERTY_OK;
341 /// Current position in seconds (RW)
342 static int mp_property_time_pos(m_option_t * prop, int action,
343 void *arg, MPContext * mpctx) {
344 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
345 return M_PROPERTY_UNAVAILABLE;
347 switch(action) {
348 case M_PROPERTY_SET:
349 if(!arg) return M_PROPERTY_ERROR;
350 M_PROPERTY_CLAMP(prop, *(double*)arg);
351 abs_seek_pos = 1;
352 rel_seek_secs = *(double*)arg;
353 return M_PROPERTY_OK;
354 case M_PROPERTY_STEP_UP:
355 case M_PROPERTY_STEP_DOWN:
356 rel_seek_secs += (arg ? *(double*)arg : 10.0) *
357 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
358 return M_PROPERTY_OK;
360 return m_property_time_ro(prop, action, arg,
361 mpctx->sh_video ? mpctx->sh_video->pts :
362 playing_audio_pts(mpctx->sh_audio,
363 mpctx->d_audio,
364 mpctx->audio_out));
367 /// Demuxer meta data
368 static int mp_property_metadata(m_option_t * prop, int action, void *arg,
369 MPContext * mpctx) {
370 m_property_action_t* ka;
371 char* meta;
372 static m_option_t key_type =
373 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
374 if (!mpctx->demuxer)
375 return M_PROPERTY_UNAVAILABLE;
377 switch(action) {
378 case M_PROPERTY_GET:
379 if(!arg) return M_PROPERTY_ERROR;
380 *(char***)arg = mpctx->demuxer->info;
381 return M_PROPERTY_OK;
382 case M_PROPERTY_KEY_ACTION:
383 if(!arg) return M_PROPERTY_ERROR;
384 ka = arg;
385 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
386 return M_PROPERTY_UNKNOWN;
387 switch(ka->action) {
388 case M_PROPERTY_GET:
389 if(!ka->arg) return M_PROPERTY_ERROR;
390 *(char**)ka->arg = meta;
391 return M_PROPERTY_OK;
392 case M_PROPERTY_GET_TYPE:
393 if(!ka->arg) return M_PROPERTY_ERROR;
394 *(m_option_t**)ka->arg = &key_type;
395 return M_PROPERTY_OK;
398 return M_PROPERTY_NOT_IMPLEMENTED;
402 ///@}
404 /// \defgroup AudioProperties Audio properties
405 /// \ingroup Properties
406 ///@{
408 /// Volume (RW)
409 static int mp_property_volume(m_option_t * prop, int action, void *arg,
410 MPContext * mpctx)
413 if (!mpctx->sh_audio)
414 return M_PROPERTY_UNAVAILABLE;
416 switch (action) {
417 case M_PROPERTY_GET:
418 if (!arg)
419 return M_PROPERTY_ERROR;
420 mixer_getbothvolume(&mpctx->mixer, arg);
421 return M_PROPERTY_OK;
422 case M_PROPERTY_PRINT:{
423 float vol;
424 if (!arg)
425 return M_PROPERTY_ERROR;
426 mixer_getbothvolume(&mpctx->mixer, &vol);
427 return m_property_float_range(prop, action, arg, &vol);
429 case M_PROPERTY_STEP_UP:
430 case M_PROPERTY_STEP_DOWN:
431 case M_PROPERTY_SET:
432 break;
433 default:
434 return M_PROPERTY_NOT_IMPLEMENTED;
437 if (mpctx->edl_muted)
438 return M_PROPERTY_DISABLED;
439 mpctx->user_muted = 0;
441 switch (action) {
442 case M_PROPERTY_SET:
443 if (!arg)
444 return M_PROPERTY_ERROR;
445 M_PROPERTY_CLAMP(prop, *(float *) arg);
446 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
447 return M_PROPERTY_OK;
448 case M_PROPERTY_STEP_UP:
449 if (arg && *(float *) arg <= 0)
450 mixer_decvolume(&mpctx->mixer);
451 else
452 mixer_incvolume(&mpctx->mixer);
453 return M_PROPERTY_OK;
454 case M_PROPERTY_STEP_DOWN:
455 if (arg && *(float *) arg <= 0)
456 mixer_incvolume(&mpctx->mixer);
457 else
458 mixer_decvolume(&mpctx->mixer);
459 return M_PROPERTY_OK;
461 return M_PROPERTY_NOT_IMPLEMENTED;
464 /// Mute (RW)
465 static int mp_property_mute(m_option_t * prop, int action, void *arg,
466 MPContext * mpctx)
469 if (!mpctx->sh_audio)
470 return M_PROPERTY_UNAVAILABLE;
472 switch (action) {
473 case M_PROPERTY_SET:
474 if (mpctx->edl_muted)
475 return M_PROPERTY_DISABLED;
476 if (!arg)
477 return M_PROPERTY_ERROR;
478 if ((!!*(int *) arg) != mpctx->mixer.muted)
479 mixer_mute(&mpctx->mixer);
480 mpctx->user_muted = mpctx->mixer.muted;
481 return M_PROPERTY_OK;
482 case M_PROPERTY_STEP_UP:
483 case M_PROPERTY_STEP_DOWN:
484 if (mpctx->edl_muted)
485 return M_PROPERTY_DISABLED;
486 mixer_mute(&mpctx->mixer);
487 mpctx->user_muted = mpctx->mixer.muted;
488 return M_PROPERTY_OK;
489 case M_PROPERTY_PRINT:
490 if (!arg)
491 return M_PROPERTY_ERROR;
492 if (mpctx->edl_muted) {
493 *(char **) arg = strdup(MSGTR_EnabledEdl);
494 return M_PROPERTY_OK;
496 default:
497 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
502 /// Audio delay (RW)
503 static int mp_property_audio_delay(m_option_t * prop, int action,
504 void *arg, MPContext * mpctx)
506 if (!(mpctx->sh_audio && mpctx->sh_video))
507 return M_PROPERTY_UNAVAILABLE;
508 switch (action) {
509 case M_PROPERTY_SET:
510 case M_PROPERTY_STEP_UP:
511 case M_PROPERTY_STEP_DOWN:
512 if (!arg)
513 return M_PROPERTY_ERROR;
514 else {
515 float delay = audio_delay;
516 m_property_delay(prop, action, arg, &audio_delay);
517 if (mpctx->sh_audio)
518 mpctx->delay -= audio_delay - delay;
520 return M_PROPERTY_OK;
521 default:
522 return m_property_delay(prop, action, arg, &audio_delay);
526 /// Audio codec tag (RO)
527 static int mp_property_audio_format(m_option_t * prop, int action,
528 void *arg, MPContext * mpctx)
530 if (!mpctx->sh_audio)
531 return M_PROPERTY_UNAVAILABLE;
532 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
535 /// Audio codec name (RO)
536 static int mp_property_audio_codec(m_option_t * prop, int action,
537 void *arg, MPContext * mpctx)
539 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
540 return M_PROPERTY_UNAVAILABLE;
541 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
544 /// Audio bitrate (RO)
545 static int mp_property_audio_bitrate(m_option_t * prop, int action,
546 void *arg, MPContext * mpctx)
548 if (!mpctx->sh_audio)
549 return M_PROPERTY_UNAVAILABLE;
550 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
553 /// Samplerate (RO)
554 static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
555 MPContext * mpctx)
557 if (!mpctx->sh_audio)
558 return M_PROPERTY_UNAVAILABLE;
559 switch(action) {
560 case M_PROPERTY_PRINT:
561 if(!arg) return M_PROPERTY_ERROR;
562 *(char**)arg = malloc(16);
563 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
564 return M_PROPERTY_OK;
566 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
569 /// Number of channels (RO)
570 static int mp_property_channels(m_option_t * prop, int action, void *arg,
571 MPContext * mpctx)
573 if (!mpctx->sh_audio)
574 return M_PROPERTY_UNAVAILABLE;
575 switch (action) {
576 case M_PROPERTY_PRINT:
577 if (!arg)
578 return M_PROPERTY_ERROR;
579 switch (mpctx->sh_audio->channels) {
580 case 1:
581 *(char **) arg = strdup("mono");
582 break;
583 case 2:
584 *(char **) arg = strdup("stereo");
585 break;
586 default:
587 *(char **) arg = malloc(32);
588 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
590 return M_PROPERTY_OK;
592 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
595 /// Balance (RW)
596 static int mp_property_balance(m_option_t * prop, int action, void *arg,
597 MPContext * mpctx)
599 float bal;
601 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
602 return M_PROPERTY_UNAVAILABLE;
604 switch (action) {
605 case M_PROPERTY_GET:
606 if (!arg)
607 return M_PROPERTY_ERROR;
608 mixer_getbalance(&mpctx->mixer, arg);
609 return M_PROPERTY_OK;
610 case M_PROPERTY_PRINT: {
611 char** str = arg;
612 if (!arg)
613 return M_PROPERTY_ERROR;
614 mixer_getbalance(&mpctx->mixer, &bal);
615 if (bal == 0.f)
616 *str = strdup("center");
617 else if (bal == -1.f)
618 *str = strdup("left only");
619 else if (bal == 1.f)
620 *str = strdup("right only");
621 else {
622 unsigned right = (bal + 1.f) / 2.f * 100.f;
623 *str = malloc(sizeof("left xxx%, right xxx%"));
624 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
626 return M_PROPERTY_OK;
628 case M_PROPERTY_STEP_UP:
629 case M_PROPERTY_STEP_DOWN:
630 mixer_getbalance(&mpctx->mixer, &bal);
631 bal += (arg ? *(float*)arg : .1f) *
632 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
633 M_PROPERTY_CLAMP(prop, bal);
634 mixer_setbalance(&mpctx->mixer, bal);
635 return M_PROPERTY_OK;
636 case M_PROPERTY_SET:
637 if (!arg)
638 return M_PROPERTY_ERROR;
639 M_PROPERTY_CLAMP(prop, *(float*)arg);
640 mixer_setbalance(&mpctx->mixer, *(float*)arg);
641 return M_PROPERTY_OK;
643 return M_PROPERTY_NOT_IMPLEMENTED;
646 /// Selected audio id (RW)
647 static int mp_property_audio(m_option_t * prop, int action, void *arg,
648 MPContext * mpctx)
650 int current_id = -1, tmp;
652 switch (action) {
653 case M_PROPERTY_GET:
654 if (!mpctx->sh_audio)
655 return M_PROPERTY_UNAVAILABLE;
656 if (!arg)
657 return M_PROPERTY_ERROR;
658 *(int *) arg = audio_id;
659 return M_PROPERTY_OK;
660 case M_PROPERTY_PRINT:
661 if (!mpctx->sh_audio)
662 return M_PROPERTY_UNAVAILABLE;
663 if (!arg)
664 return M_PROPERTY_ERROR;
666 if (audio_id < 0)
667 *(char **) arg = strdup(MSGTR_Disabled);
668 else {
669 char lang[40] = MSGTR_Unknown;
670 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA)
671 demux_mkv_get_audio_lang(mpctx->demuxer, audio_id, lang, 9);
672 #ifdef USE_DVDREAD
673 else if (mpctx->stream->type == STREAMTYPE_DVD) {
674 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
675 if (code) {
676 lang[0] = code >> 8;
677 lang[1] = code;
678 lang[2] = 0;
681 #endif
683 #ifdef USE_DVDNAV
684 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
685 dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
686 #endif
687 *(char **) arg = malloc(64);
688 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
690 return M_PROPERTY_OK;
692 case M_PROPERTY_STEP_UP:
693 case M_PROPERTY_SET:
694 if (action == M_PROPERTY_SET && arg)
695 tmp = *((int *) arg);
696 else
697 tmp = -1;
698 current_id = mpctx->demuxer->audio->id;
699 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
700 if (audio_id == -2
701 || (audio_id > -1
702 && mpctx->demuxer->audio->id != current_id && current_id != -2))
703 uninit_player(INITED_AO | INITED_ACODEC);
704 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
705 sh_audio_t *sh2;
706 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
707 if (sh2) {
708 sh2->ds = mpctx->demuxer->audio;
709 mpctx->sh_audio = sh2;
710 reinit_audio_chain();
713 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
714 return M_PROPERTY_OK;
715 default:
716 return M_PROPERTY_NOT_IMPLEMENTED;
721 /// Selected video id (RW)
722 static int mp_property_video(m_option_t * prop, int action, void *arg,
723 MPContext * mpctx)
725 int current_id = -1, tmp;
727 switch (action) {
728 case M_PROPERTY_GET:
729 if (!mpctx->sh_video)
730 return M_PROPERTY_UNAVAILABLE;
731 if (!arg)
732 return M_PROPERTY_ERROR;
733 *(int *) arg = video_id;
734 return M_PROPERTY_OK;
735 case M_PROPERTY_PRINT:
736 if (!mpctx->sh_video)
737 return M_PROPERTY_UNAVAILABLE;
738 if (!arg)
739 return M_PROPERTY_ERROR;
741 if (video_id < 0)
742 *(char **) arg = strdup(MSGTR_Disabled);
743 else {
744 char lang[40] = MSGTR_Unknown;
745 *(char **) arg = malloc(64);
746 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
748 return M_PROPERTY_OK;
750 case M_PROPERTY_STEP_UP:
751 case M_PROPERTY_SET:
752 current_id = mpctx->demuxer->video->id;
753 if (action == M_PROPERTY_SET && arg)
754 tmp = *((int *) arg);
755 else
756 tmp = -1;
757 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
758 if (video_id == -2
759 || (video_id > -1 && mpctx->demuxer->video->id != current_id
760 && current_id != -2))
761 uninit_player(INITED_VCODEC |
762 (fixed_vo && video_id != -2 ? 0 : INITED_VO));
763 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
764 sh_video_t *sh2;
765 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
766 if (sh2) {
767 sh2->ds = mpctx->demuxer->video;
768 mpctx->sh_video = sh2;
769 reinit_video_chain();
772 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
773 return M_PROPERTY_OK;
775 default:
776 return M_PROPERTY_NOT_IMPLEMENTED;
780 static int mp_property_program(m_option_t * prop, int action, void *arg,
781 MPContext * mpctx)
783 demux_program_t prog;
785 switch (action) {
786 case M_PROPERTY_STEP_UP:
787 case M_PROPERTY_SET:
788 if (action == M_PROPERTY_SET && arg)
789 prog.progid = *((int *) arg);
790 else
791 prog.progid = -1;
792 if (demux_control
793 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
794 &prog) == DEMUXER_CTRL_NOTIMPL)
795 return M_PROPERTY_ERROR;
797 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
798 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
799 return M_PROPERTY_OK;
801 default:
802 return M_PROPERTY_NOT_IMPLEMENTED;
806 ///@}
808 /// \defgroup VideoProperties Video properties
809 /// \ingroup Properties
810 ///@{
812 /// Fullscreen state (RW)
813 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
814 MPContext * mpctx)
817 if (!mpctx->video_out)
818 return M_PROPERTY_UNAVAILABLE;
820 switch (action) {
821 case M_PROPERTY_SET:
822 if (!arg)
823 return M_PROPERTY_ERROR;
824 M_PROPERTY_CLAMP(prop, *(int *) arg);
825 if (vo_fs == !!*(int *) arg)
826 return M_PROPERTY_OK;
827 case M_PROPERTY_STEP_UP:
828 case M_PROPERTY_STEP_DOWN:
829 #ifdef HAVE_NEW_GUI
830 if (use_gui)
831 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
832 else
833 #endif
834 if (vo_config_count)
835 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
836 return M_PROPERTY_OK;
837 default:
838 return m_property_flag(prop, action, arg, &vo_fs);
842 static int mp_property_deinterlace(m_option_t * prop, int action,
843 void *arg, MPContext * mpctx)
845 int deinterlace;
846 vf_instance_t *vf;
847 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
848 return M_PROPERTY_UNAVAILABLE;
849 vf = mpctx->sh_video->vfilter;
850 switch (action) {
851 case M_PROPERTY_GET:
852 if (!arg)
853 return M_PROPERTY_ERROR;
854 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
855 return M_PROPERTY_OK;
856 case M_PROPERTY_SET:
857 if (!arg)
858 return M_PROPERTY_ERROR;
859 M_PROPERTY_CLAMP(prop, *(int *) arg);
860 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
861 return M_PROPERTY_OK;
862 case M_PROPERTY_STEP_UP:
863 case M_PROPERTY_STEP_DOWN:
864 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
865 deinterlace = !deinterlace;
866 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
867 return M_PROPERTY_OK;
869 return M_PROPERTY_NOT_IMPLEMENTED;
872 /// Panscan (RW)
873 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
874 MPContext * mpctx)
877 if (!mpctx->video_out
878 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
879 return M_PROPERTY_UNAVAILABLE;
881 switch (action) {
882 case M_PROPERTY_SET:
883 if (!arg)
884 return M_PROPERTY_ERROR;
885 M_PROPERTY_CLAMP(prop, *(float *) arg);
886 vo_panscan = *(float *) arg;
887 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
888 return M_PROPERTY_OK;
889 case M_PROPERTY_STEP_UP:
890 case M_PROPERTY_STEP_DOWN:
891 vo_panscan += (arg ? *(float *) arg : 0.1) *
892 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
893 if (vo_panscan > 1)
894 vo_panscan = 1;
895 else if (vo_panscan < 0)
896 vo_panscan = 0;
897 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
898 return M_PROPERTY_OK;
899 default:
900 return m_property_float_range(prop, action, arg, &vo_panscan);
904 /// Helper to set vo flags.
905 /** \ingroup PropertyImplHelper
907 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
908 int vo_ctrl, int *vo_var, MPContext * mpctx)
911 if (!mpctx->video_out)
912 return M_PROPERTY_UNAVAILABLE;
914 switch (action) {
915 case M_PROPERTY_SET:
916 if (!arg)
917 return M_PROPERTY_ERROR;
918 M_PROPERTY_CLAMP(prop, *(int *) arg);
919 if (*vo_var == !!*(int *) arg)
920 return M_PROPERTY_OK;
921 case M_PROPERTY_STEP_UP:
922 case M_PROPERTY_STEP_DOWN:
923 if (vo_config_count)
924 mpctx->video_out->control(vo_ctrl, 0);
925 return M_PROPERTY_OK;
926 default:
927 return m_property_flag(prop, action, arg, vo_var);
931 /// Window always on top (RW)
932 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
933 MPContext * mpctx)
935 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
936 mpctx);
939 /// Display in the root window (RW)
940 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
941 MPContext * mpctx)
943 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
944 &vo_rootwin, mpctx);
947 /// Show window borders (RW)
948 static int mp_property_border(m_option_t * prop, int action, void *arg,
949 MPContext * mpctx)
951 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
952 &vo_border, mpctx);
955 /// Framedropping state (RW)
956 static int mp_property_framedropping(m_option_t * prop, int action,
957 void *arg, MPContext * mpctx)
960 if (!mpctx->sh_video)
961 return M_PROPERTY_UNAVAILABLE;
963 switch (action) {
964 case M_PROPERTY_PRINT:
965 if (!arg)
966 return M_PROPERTY_ERROR;
967 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
968 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
969 MSGTR_Disabled));
970 return M_PROPERTY_OK;
971 default:
972 return m_property_choice(prop, action, arg, &frame_dropping);
976 /// Color settings, try to use vf/vo then fall back on TV. (RW)
977 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
978 MPContext * mpctx)
980 int *gamma = prop->priv, r;
982 if (!mpctx->sh_video)
983 return M_PROPERTY_UNAVAILABLE;
985 if (gamma[0] == 1000) {
986 gamma[0] = 0;
987 get_video_colors(mpctx->sh_video, prop->name, gamma);
990 switch (action) {
991 case M_PROPERTY_SET:
992 if (!arg)
993 return M_PROPERTY_ERROR;
994 M_PROPERTY_CLAMP(prop, *(int *) arg);
995 *gamma = *(int *) arg;
996 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
997 if (r <= 0)
998 break;
999 return r;
1000 case M_PROPERTY_GET:
1001 if (!arg)
1002 return M_PROPERTY_ERROR;
1003 r = get_video_colors(mpctx->sh_video, prop->name, arg);
1004 if (r <= 0)
1005 break;
1006 return r;
1007 case M_PROPERTY_STEP_UP:
1008 case M_PROPERTY_STEP_DOWN:
1009 *gamma += (arg ? *(int *) arg : 1) *
1010 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1011 M_PROPERTY_CLAMP(prop, *gamma);
1012 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1013 if (r <= 0)
1014 break;
1015 return r;
1016 default:
1017 return M_PROPERTY_NOT_IMPLEMENTED;
1020 #ifdef USE_TV
1021 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1022 int l = strlen(prop->name);
1023 char tv_prop[3 + l + 1];
1024 sprintf(tv_prop, "tv_%s", prop->name);
1025 return mp_property_do(tv_prop, action, arg, mpctx);
1027 #endif
1029 return M_PROPERTY_UNAVAILABLE;
1032 /// VSync (RW)
1033 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1034 MPContext * mpctx)
1036 return m_property_flag(prop, action, arg, &vo_vsync);
1039 /// Video codec tag (RO)
1040 static int mp_property_video_format(m_option_t * prop, int action,
1041 void *arg, MPContext * mpctx)
1043 char* meta;
1044 if (!mpctx->sh_video)
1045 return M_PROPERTY_UNAVAILABLE;
1046 switch(action) {
1047 case M_PROPERTY_PRINT:
1048 if (!arg)
1049 return M_PROPERTY_ERROR;
1050 switch(mpctx->sh_video->format) {
1051 case 0x10000001:
1052 meta = strdup ("mpeg1"); break;
1053 case 0x10000002:
1054 meta = strdup ("mpeg2"); break;
1055 case 0x10000004:
1056 meta = strdup ("mpeg4"); break;
1057 case 0x10000005:
1058 meta = strdup ("h264"); break;
1059 default:
1060 if(mpctx->sh_video->format >= 0x20202020) {
1061 meta = malloc(5);
1062 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1063 } else {
1064 meta = malloc(20);
1065 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1068 *(char**)arg = meta;
1069 return M_PROPERTY_OK;
1071 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1074 /// Video codec name (RO)
1075 static int mp_property_video_codec(m_option_t * prop, int action,
1076 void *arg, MPContext * mpctx)
1078 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1079 return M_PROPERTY_UNAVAILABLE;
1080 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1084 /// Video bitrate (RO)
1085 static int mp_property_video_bitrate(m_option_t * prop, int action,
1086 void *arg, MPContext * mpctx)
1088 if (!mpctx->sh_video)
1089 return M_PROPERTY_UNAVAILABLE;
1090 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1093 /// Video display width (RO)
1094 static int mp_property_width(m_option_t * prop, int action, void *arg,
1095 MPContext * mpctx)
1097 if (!mpctx->sh_video)
1098 return M_PROPERTY_UNAVAILABLE;
1099 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1102 /// Video display height (RO)
1103 static int mp_property_height(m_option_t * prop, int action, void *arg,
1104 MPContext * mpctx)
1106 if (!mpctx->sh_video)
1107 return M_PROPERTY_UNAVAILABLE;
1108 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1111 /// Video fps (RO)
1112 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1113 MPContext * mpctx)
1115 if (!mpctx->sh_video)
1116 return M_PROPERTY_UNAVAILABLE;
1117 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1120 /// Video aspect (RO)
1121 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1122 MPContext * mpctx)
1124 if (!mpctx->sh_video)
1125 return M_PROPERTY_UNAVAILABLE;
1126 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1129 ///@}
1131 /// \defgroup SubProprties Subtitles properties
1132 /// \ingroup Properties
1133 ///@{
1135 /// Text subtitle position (RW)
1136 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1137 MPContext * mpctx)
1139 if (!mpctx->sh_video)
1140 return M_PROPERTY_UNAVAILABLE;
1142 switch (action) {
1143 case M_PROPERTY_SET:
1144 if (!arg)
1145 return M_PROPERTY_ERROR;
1146 case M_PROPERTY_STEP_UP:
1147 case M_PROPERTY_STEP_DOWN:
1148 vo_osd_changed(OSDTYPE_SUBTITLE);
1149 default:
1150 return m_property_int_range(prop, action, arg, &sub_pos);
1154 char *demux_lavf_sub_lang(demuxer_t *demuxer, int track_num);
1156 /// Selected subtitles (RW)
1157 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1158 MPContext * mpctx)
1160 demux_stream_t *const d_sub = mpctx->d_sub;
1161 const int global_sub_size = mpctx->global_sub_size;
1162 int source = -1, reset_spu = 0;
1163 char *sub_name;
1165 if (global_sub_size <= 0)
1166 return M_PROPERTY_UNAVAILABLE;
1168 switch (action) {
1169 case M_PROPERTY_GET:
1170 if (!arg)
1171 return M_PROPERTY_ERROR;
1172 *(int *) arg = mpctx->global_sub_pos;
1173 return M_PROPERTY_OK;
1174 case M_PROPERTY_PRINT:
1175 if (!arg)
1176 return M_PROPERTY_ERROR;
1177 *(char **) arg = malloc(64);
1178 (*(char **) arg)[63] = 0;
1179 sub_name = 0;
1180 if (subdata)
1181 sub_name = subdata->filename;
1182 #ifdef USE_ASS
1183 if (ass_track && ass_track->name)
1184 sub_name = ass_track->name;
1185 #endif
1186 if (sub_name) {
1187 char *tmp, *tmp2;
1188 tmp = sub_name;
1189 if ((tmp2 = strrchr(tmp, '/')))
1190 tmp = tmp2 + 1;
1192 snprintf(*(char **) arg, 63, "(%d) %s%s",
1193 mpctx->set_of_sub_pos + 1,
1194 strlen(tmp) < 20 ? "" : "...",
1195 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1196 return M_PROPERTY_OK;
1198 #ifdef USE_DVDNAV
1199 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1200 if (vo_spudec && dvdsub_id >= 0) {
1201 unsigned char lang[3];
1202 if (dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1203 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1204 return M_PROPERTY_OK;
1208 #endif
1210 #ifdef USE_LIBAVFORMAT
1211 if (mpctx->demuxer->type == DEMUXER_TYPE_LAVF && dvdsub_id >= 0) {
1212 char *lang = demux_lavf_sub_lang(mpctx->demuxer, dvdsub_id);
1213 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1214 return M_PROPERTY_OK;
1216 #endif
1217 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
1218 char lang[40] = MSGTR_Unknown;
1219 demux_mkv_get_sub_lang(mpctx->demuxer, dvdsub_id, lang, 9);
1220 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1221 return M_PROPERTY_OK;
1223 #ifdef HAVE_OGGVORBIS
1224 if (mpctx->demuxer->type == DEMUXER_TYPE_OGG && d_sub && dvdsub_id >= 0) {
1225 char *lang = demux_ogg_sub_lang(mpctx->demuxer, dvdsub_id);
1226 if (!lang)
1227 lang = MSGTR_Unknown;
1228 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1229 return M_PROPERTY_OK;
1231 #endif
1232 if (vo_vobsub && vobsub_id >= 0) {
1233 const char *language = MSGTR_Unknown;
1234 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1235 snprintf(*(char **) arg, 63, "(%d) %s",
1236 vobsub_id, language ? language : MSGTR_Unknown);
1237 return M_PROPERTY_OK;
1239 #ifdef USE_DVDREAD
1240 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1241 && dvdsub_id >= 0) {
1242 char lang[3];
1243 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1244 lang[0] = code >> 8;
1245 lang[1] = code;
1246 lang[2] = 0;
1247 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1248 return M_PROPERTY_OK;
1250 #endif
1251 if (dvdsub_id >= 0) {
1252 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1253 return M_PROPERTY_OK;
1255 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1256 return M_PROPERTY_OK;
1258 case M_PROPERTY_SET:
1259 if (!arg)
1260 return M_PROPERTY_ERROR;
1261 if (*(int *) arg < -1)
1262 *(int *) arg = -1;
1263 else if (*(int *) arg >= global_sub_size)
1264 *(int *) arg = global_sub_size - 1;
1265 mpctx->global_sub_pos = *(int *) arg;
1266 break;
1267 case M_PROPERTY_STEP_UP:
1268 mpctx->global_sub_pos += 2;
1269 mpctx->global_sub_pos =
1270 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1271 break;
1272 case M_PROPERTY_STEP_DOWN:
1273 mpctx->global_sub_pos += global_sub_size + 1;
1274 mpctx->global_sub_pos =
1275 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1276 break;
1277 default:
1278 return M_PROPERTY_NOT_IMPLEMENTED;
1281 if (mpctx->global_sub_pos >= 0)
1282 source = sub_source(mpctx);
1284 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1285 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1286 global_sub_size,
1287 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1288 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1289 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1290 mpctx->global_sub_pos, source);
1292 mpctx->set_of_sub_pos = -1;
1293 subdata = NULL;
1295 vobsub_id = -1;
1296 dvdsub_id = -1;
1297 if (d_sub) {
1298 if (d_sub->id > -2)
1299 reset_spu = 1;
1300 d_sub->id = -2;
1302 #ifdef USE_ASS
1303 ass_track = 0;
1304 #endif
1306 if (source == SUB_SOURCE_VOBSUB) {
1307 vobsub_id =
1308 mpctx->global_sub_pos -
1309 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB];
1310 } else if (source == SUB_SOURCE_SUBS) {
1311 mpctx->set_of_sub_pos =
1312 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1313 #ifdef USE_ASS
1314 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1315 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1316 else
1317 #endif
1319 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1320 vo_osd_changed(OSDTYPE_SUBTITLE);
1322 } else if (source == SUB_SOURCE_DEMUX) {
1323 dvdsub_id =
1324 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1325 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1326 int i = 0;
1327 // default: assume 1:1 mapping of sid and stream id
1328 d_sub->id = dvdsub_id;
1329 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1330 for (i = 0; i < MAX_S_STREAMS; i++) {
1331 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1332 if (sh && sh->sid == dvdsub_id) {
1333 d_sub->id = i;
1334 d_sub->sh = sh;
1335 break;
1338 if (d_sub->sh && d_sub->id >= 0) {
1339 sh_sub_t *sh = d_sub->sh;
1340 if (sh->type == 'v')
1341 init_vo_spudec();
1342 #ifdef USE_ASS
1343 else if (ass_enabled && sh->type == 'a')
1344 ass_track = sh->ass_track;
1345 #endif
1346 } else {
1347 d_sub->id = -2;
1348 d_sub->sh = NULL;
1352 #ifdef USE_DVDREAD
1353 if (vo_spudec
1354 && (mpctx->stream->type == STREAMTYPE_DVD
1355 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1356 && dvdsub_id < 0 && reset_spu) {
1357 dvdsub_id = -2;
1358 d_sub->id = dvdsub_id;
1360 #endif
1361 update_subtitles(mpctx->sh_video, d_sub, 1);
1363 return M_PROPERTY_OK;
1366 /// Subtitle delay (RW)
1367 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1368 MPContext * mpctx)
1370 if (!mpctx->sh_video)
1371 return M_PROPERTY_UNAVAILABLE;
1372 return m_property_delay(prop, action, arg, &sub_delay);
1375 /// Alignment of text subtitles (RW)
1376 static int mp_property_sub_alignment(m_option_t * prop, int action,
1377 void *arg, MPContext * mpctx)
1379 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1381 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1382 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1383 return M_PROPERTY_UNAVAILABLE;
1385 switch (action) {
1386 case M_PROPERTY_PRINT:
1387 if (!arg)
1388 return M_PROPERTY_ERROR;
1389 M_PROPERTY_CLAMP(prop, sub_alignment);
1390 *(char **) arg = strdup(name[sub_alignment]);
1391 return M_PROPERTY_OK;
1392 case M_PROPERTY_SET:
1393 if (!arg)
1394 return M_PROPERTY_ERROR;
1395 case M_PROPERTY_STEP_UP:
1396 case M_PROPERTY_STEP_DOWN:
1397 vo_osd_changed(OSDTYPE_SUBTITLE);
1398 default:
1399 return m_property_choice(prop, action, arg, &sub_alignment);
1403 /// Subtitle visibility (RW)
1404 static int mp_property_sub_visibility(m_option_t * prop, int action,
1405 void *arg, MPContext * mpctx)
1407 if (!mpctx->sh_video)
1408 return M_PROPERTY_UNAVAILABLE;
1410 switch (action) {
1411 case M_PROPERTY_SET:
1412 if (!arg)
1413 return M_PROPERTY_ERROR;
1414 case M_PROPERTY_STEP_UP:
1415 case M_PROPERTY_STEP_DOWN:
1416 vo_osd_changed(OSDTYPE_SUBTITLE);
1417 if (vo_spudec)
1418 vo_osd_changed(OSDTYPE_SPU);
1419 default:
1420 return m_property_flag(prop, action, arg, &sub_visibility);
1424 /// Show only forced subtitles (RW)
1425 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1426 void *arg, MPContext * mpctx)
1428 if (!vo_spudec)
1429 return M_PROPERTY_UNAVAILABLE;
1431 switch (action) {
1432 case M_PROPERTY_SET:
1433 if (!arg)
1434 return M_PROPERTY_ERROR;
1435 case M_PROPERTY_STEP_UP:
1436 case M_PROPERTY_STEP_DOWN:
1437 m_property_flag(prop, action, arg, &forced_subs_only);
1438 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1439 return M_PROPERTY_OK;
1440 default:
1441 return m_property_flag(prop, action, arg, &forced_subs_only);
1446 #ifdef HAVE_FREETYPE
1447 /// Subtitle scale (RW)
1448 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1449 MPContext * mpctx)
1452 switch (action) {
1453 case M_PROPERTY_SET:
1454 if (!arg)
1455 return M_PROPERTY_ERROR;
1456 M_PROPERTY_CLAMP(prop, *(float *) arg);
1457 text_font_scale_factor = *(float *) arg;
1458 force_load_font = 1;
1459 return M_PROPERTY_OK;
1460 case M_PROPERTY_STEP_UP:
1461 case M_PROPERTY_STEP_DOWN:
1462 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1463 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1464 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1465 force_load_font = 1;
1466 return M_PROPERTY_OK;
1467 default:
1468 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1471 #endif
1473 ///@}
1475 /// \defgroup TVProperties TV properties
1476 /// \ingroup Properties
1477 ///@{
1479 #ifdef USE_TV
1481 /// TV color settings (RW)
1482 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1483 MPContext * mpctx)
1485 int r, val;
1486 tvi_handle_t *tvh = mpctx->demuxer->priv;
1487 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1488 return M_PROPERTY_UNAVAILABLE;
1490 switch (action) {
1491 case M_PROPERTY_SET:
1492 if (!arg)
1493 return M_PROPERTY_ERROR;
1494 M_PROPERTY_CLAMP(prop, *(int *) arg);
1495 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1496 case M_PROPERTY_GET:
1497 return tv_get_color_options(tvh, (int) prop->priv, arg);
1498 case M_PROPERTY_STEP_UP:
1499 case M_PROPERTY_STEP_DOWN:
1500 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1501 if (!r)
1502 return M_PROPERTY_ERROR;
1503 val += (arg ? *(int *) arg : 1) *
1504 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1505 M_PROPERTY_CLAMP(prop, val);
1506 return tv_set_color_options(tvh, (int) prop->priv, val);
1508 return M_PROPERTY_ERROR;
1510 return M_PROPERTY_NOT_IMPLEMENTED;
1513 #endif
1515 #ifdef HAVE_TV_TELETEXT
1516 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1517 MPContext * mpctx)
1519 int val,result;
1520 int base_ioctl=(int)prop->priv;
1522 for teletext's GET,SET,STEP ioctls this is not 0
1523 SET is GET+1
1524 STEP is GET+2
1526 tvi_handle_t *tvh = mpctx->demuxer->priv;
1527 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1528 return M_PROPERTY_UNAVAILABLE;
1529 if(!base_ioctl)
1530 return M_PROPERTY_ERROR;
1532 switch (action) {
1533 case M_PROPERTY_GET:
1534 if (!arg)
1535 return M_PROPERTY_ERROR;
1536 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1537 break;
1538 case M_PROPERTY_SET:
1539 if (!arg)
1540 return M_PROPERTY_ERROR;
1541 M_PROPERTY_CLAMP(prop, *(int *) arg);
1542 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1543 break;
1544 case M_PROPERTY_STEP_UP:
1545 case M_PROPERTY_STEP_DOWN:
1546 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1547 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1548 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1549 break;
1550 default:
1551 return M_PROPERTY_NOT_IMPLEMENTED;
1554 return (result==TVI_CONTROL_TRUE?M_PROPERTY_OK:M_PROPERTY_ERROR);
1557 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1558 MPContext * mpctx)
1560 tvi_handle_t *tvh = mpctx->demuxer->priv;
1561 int result;
1562 int val;
1564 //with tvh==NULL will fail too
1565 result=mp_property_teletext_common(prop,action,arg,mpctx);
1566 if(result!=M_PROPERTY_OK)
1567 return result;
1569 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1570 mp_input_set_section("teletext");
1571 else
1572 mp_input_set_section("tv");
1573 return M_PROPERTY_OK;
1576 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1577 MPContext * mpctx)
1579 tvi_handle_t *tvh = mpctx->demuxer->priv;
1580 int result;
1581 int val;
1582 switch(action){
1583 case M_PROPERTY_STEP_UP:
1584 case M_PROPERTY_STEP_DOWN:
1585 //This should be handled separately
1586 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1587 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1588 break;
1589 default:
1590 result=mp_property_teletext_common(prop,action,arg,mpctx);
1592 return result;
1596 #endif /* HAVE_TV_TELETEXT */
1598 ///@}
1600 /// All properties available in MPlayer.
1601 /** \ingroup Properties
1603 static m_option_t mp_properties[] = {
1604 // General
1605 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1606 M_OPT_RANGE, 0, 3, NULL },
1607 { "loop", mp_property_loop, CONF_TYPE_INT,
1608 M_OPT_MIN, -1, 0, NULL },
1609 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1610 M_OPT_RANGE, 0.01, 100.0, NULL },
1611 { "filename", mp_property_filename, CONF_TYPE_STRING,
1612 0, 0, 0, NULL },
1613 { "path", mp_property_path, CONF_TYPE_STRING,
1614 0, 0, 0, NULL },
1615 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1616 0, 0, 0, NULL },
1617 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1618 M_OPT_MIN, 0, 0, NULL },
1619 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1620 M_OPT_MIN, 0, 0, NULL },
1621 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1622 M_OPT_MIN, 0, 0, NULL },
1623 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1624 M_OPT_MIN, 0, 0, NULL },
1625 { "length", mp_property_length, CONF_TYPE_TIME,
1626 M_OPT_MIN, 0, 0, NULL },
1627 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1628 M_OPT_RANGE, 0, 100, NULL },
1629 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1630 M_OPT_MIN, 0, 0, NULL },
1631 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
1632 0, 0, 0, NULL },
1634 // Audio
1635 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
1636 M_OPT_RANGE, 0, 100, NULL },
1637 { "mute", mp_property_mute, CONF_TYPE_FLAG,
1638 M_OPT_RANGE, 0, 1, NULL },
1639 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
1640 M_OPT_RANGE, -100, 100, NULL },
1641 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
1642 0, 0, 0, NULL },
1643 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
1644 0, 0, 0, NULL },
1645 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
1646 0, 0, 0, NULL },
1647 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
1648 0, 0, 0, NULL },
1649 { "channels", mp_property_channels, CONF_TYPE_INT,
1650 0, 0, 0, NULL },
1651 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
1652 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
1653 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
1654 M_OPT_RANGE, -1, 1, NULL },
1656 // Video
1657 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
1658 M_OPT_RANGE, 0, 1, NULL },
1659 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
1660 M_OPT_RANGE, 0, 1, NULL },
1661 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
1662 M_OPT_RANGE, 0, 1, NULL },
1663 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
1664 M_OPT_RANGE, 0, 1, NULL },
1665 { "border", mp_property_border, CONF_TYPE_FLAG,
1666 M_OPT_RANGE, 0, 1, NULL },
1667 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
1668 M_OPT_RANGE, 0, 2, NULL },
1669 { "gamma", mp_property_gamma, CONF_TYPE_INT,
1670 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
1671 { "brightness", mp_property_gamma, CONF_TYPE_INT,
1672 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
1673 { "contrast", mp_property_gamma, CONF_TYPE_INT,
1674 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
1675 { "saturation", mp_property_gamma, CONF_TYPE_INT,
1676 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
1677 { "hue", mp_property_gamma, CONF_TYPE_INT,
1678 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
1679 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
1680 M_OPT_RANGE, 0, 1, NULL },
1681 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
1682 M_OPT_RANGE, 0, 1, NULL },
1683 { "video_format", mp_property_video_format, CONF_TYPE_INT,
1684 0, 0, 0, NULL },
1685 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
1686 0, 0, 0, NULL },
1687 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
1688 0, 0, 0, NULL },
1689 { "width", mp_property_width, CONF_TYPE_INT,
1690 0, 0, 0, NULL },
1691 { "height", mp_property_height, CONF_TYPE_INT,
1692 0, 0, 0, NULL },
1693 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
1694 0, 0, 0, NULL },
1695 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
1696 0, 0, 0, NULL },
1697 { "switch_video", mp_property_video, CONF_TYPE_INT,
1698 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
1699 { "switch_program", mp_property_program, CONF_TYPE_INT,
1700 CONF_RANGE, -1, 65535, NULL },
1702 // Subs
1703 { "sub", mp_property_sub, CONF_TYPE_INT,
1704 M_OPT_MIN, -1, 0, NULL },
1705 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
1706 0, 0, 0, NULL },
1707 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
1708 M_OPT_RANGE, 0, 100, NULL },
1709 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
1710 M_OPT_RANGE, 0, 2, NULL },
1711 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
1712 M_OPT_RANGE, 0, 1, NULL },
1713 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
1714 M_OPT_RANGE, 0, 1, NULL },
1715 #ifdef HAVE_FREETYPE
1716 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
1717 M_OPT_RANGE, 0, 100, NULL },
1718 #endif
1720 #ifdef USE_TV
1721 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
1722 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
1723 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
1724 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
1725 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
1726 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
1727 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
1728 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
1729 #endif
1731 #ifdef HAVE_TV_TELETEXT
1732 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
1733 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
1734 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
1735 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
1736 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
1737 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
1738 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
1739 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
1740 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
1741 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
1742 #endif
1744 { NULL, NULL, NULL, 0, 0, 0, NULL }
1748 int mp_property_do(const char *name, int action, void *val, void *ctx)
1750 return m_property_do(mp_properties, name, action, val, ctx);
1753 char* mp_property_print(const char *name, void* ctx)
1755 char* ret = NULL;
1756 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
1757 return NULL;
1758 return ret;
1761 char *property_expand_string(MPContext * mpctx, char *str)
1763 return m_properties_expand_string(mp_properties, str, mpctx);
1766 void property_print_help(void)
1768 m_properties_print_help_list(mp_properties);
1772 ///@}
1773 // Properties group
1777 * \defgroup Command2Property Command to property bridge
1779 * It is used to handle most commands that just set a property
1780 * and optionally display something on the OSD.
1781 * Two kinds of commands are handled: adjust or toggle.
1783 * Adjust commands take 1 or 2 parameters: <value> <abs>
1784 * If <abs> is non-zero the property is set to the given value
1785 * otherwise it is adjusted.
1787 * Toggle commands take 0 or 1 parameters. With no parameter
1788 * or a value less than the property minimum it just steps the
1789 * property to its next value. Otherwise it sets it to the given
1790 * value.
1795 /// List of the commands that can be handled by setting a property.
1796 static struct {
1797 /// property name
1798 const char *name;
1799 /// cmd id
1800 int cmd;
1801 /// set/adjust or toggle command
1802 int toggle;
1803 /// progressbar type
1804 int osd_progbar;
1805 /// osd msg id if it must be shared
1806 int osd_id;
1807 /// osd msg template
1808 const char *osd_msg;
1809 } set_prop_cmd[] = {
1810 // general
1811 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
1812 // audio
1813 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
1814 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
1815 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
1816 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
1817 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
1818 // video
1819 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
1820 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
1821 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
1822 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
1823 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
1824 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
1825 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
1826 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
1827 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
1828 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
1829 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
1830 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
1831 // subs
1832 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
1833 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
1834 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
1835 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
1836 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
1837 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
1838 #ifdef HAVE_FREETYPE
1839 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
1840 #endif
1841 #ifdef USE_TV
1842 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
1843 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
1844 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
1845 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
1846 #endif
1847 { NULL, 0, 0, 0, -1, NULL }
1851 /// Handle commands that set a property.
1852 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
1854 int i, r;
1855 m_option_t* prop;
1856 const char *pname;
1858 // look for the command
1859 for (i = 0; set_prop_cmd[i].name; i++)
1860 if (set_prop_cmd[i].cmd == cmd->id)
1861 break;
1862 if (!(pname = set_prop_cmd[i].name))
1863 return 0;
1865 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
1866 return 0;
1868 // toggle command
1869 if (set_prop_cmd[i].toggle) {
1870 // set to value
1871 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
1872 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
1873 else
1874 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
1875 } else if (cmd->args[1].v.i) //set
1876 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
1877 else // adjust
1878 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
1880 if (r <= 0)
1881 return 1;
1883 if (set_prop_cmd[i].osd_progbar) {
1884 if (prop->type == CONF_TYPE_INT) {
1885 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
1886 set_osd_bar(set_prop_cmd[i].osd_progbar,
1887 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
1888 } else if (prop->type == CONF_TYPE_FLOAT) {
1889 float f;
1890 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
1891 set_osd_bar(set_prop_cmd[i].osd_progbar,
1892 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
1893 } else
1894 mp_msg(MSGT_CPLAYER, MSGL_ERR,
1895 "Property use an unsupported type.\n");
1896 return 1;
1899 if (set_prop_cmd[i].osd_msg) {
1900 char *val = mp_property_print(pname, mpctx);
1901 if (val) {
1902 set_osd_msg(set_prop_cmd[i].osd_id >=
1903 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
1904 1, osd_duration, set_prop_cmd[i].osd_msg, val);
1905 free(val);
1908 return 1;
1912 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
1914 sh_audio_t * const sh_audio = mpctx->sh_audio;
1915 sh_video_t * const sh_video = mpctx->sh_video;
1916 int brk_cmd = 0;
1917 if (!set_property_command(mpctx, cmd))
1918 switch (cmd->id) {
1919 case MP_CMD_SEEK:{
1920 float v;
1921 int abs;
1922 if (sh_video)
1923 mpctx->osd_show_percentage = sh_video->fps;
1924 v = cmd->args[0].v.f;
1925 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
1926 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
1927 abs_seek_pos = 1;
1928 if (sh_video)
1929 mpctx->osd_function =
1930 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
1931 rel_seek_secs = v;
1932 } else if (abs) { /* Absolute seek by percentage */
1933 abs_seek_pos = 3;
1934 if (sh_video)
1935 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
1936 rel_seek_secs = v / 100.0;
1937 } else {
1938 rel_seek_secs += v;
1939 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
1941 brk_cmd = 1;
1943 break;
1945 case MP_CMD_SET_PROPERTY:{
1946 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
1947 cmd->args[1].v.s, mpctx);
1948 if (r == M_PROPERTY_UNKNOWN)
1949 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1950 "Unknown property: '%s'\n", cmd->args[0].v.s);
1951 else if (r <= 0)
1952 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1953 "Failed to set property '%s' to '%s'.\n",
1954 cmd->args[0].v.s, cmd->args[1].v.s);
1956 break;
1958 case MP_CMD_STEP_PROPERTY:{
1959 void* arg = NULL;
1960 int r,i;
1961 double d;
1962 off_t o;
1963 if (cmd->args[1].v.f) {
1964 m_option_t* prop;
1965 if((r = mp_property_do(cmd->args[0].v.s,
1966 M_PROPERTY_GET_TYPE,
1967 &prop, mpctx)) <= 0)
1968 goto step_prop_err;
1969 if(prop->type == CONF_TYPE_INT ||
1970 prop->type == CONF_TYPE_FLAG)
1971 i = cmd->args[1].v.f, arg = &i;
1972 else if(prop->type == CONF_TYPE_FLOAT)
1973 arg = &cmd->args[1].v.f;
1974 else if(prop->type == CONF_TYPE_DOUBLE ||
1975 prop->type == CONF_TYPE_TIME)
1976 d = cmd->args[1].v.f, arg = &d;
1977 else if(prop->type == CONF_TYPE_POSITION)
1978 o = cmd->args[1].v.f, arg = &o;
1979 else
1980 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1981 "Ignoring step size stepping property '%s'.\n",
1982 cmd->args[0].v.s);
1984 r = mp_property_do(cmd->args[0].v.s,
1985 cmd->args[2].v.i < 0 ?
1986 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
1987 arg, mpctx);
1988 step_prop_err:
1989 if (r == M_PROPERTY_UNKNOWN)
1990 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1991 "Unknown property: '%s'\n", cmd->args[0].v.s);
1992 else if (r <= 0)
1993 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1994 "Failed to increment property '%s' by %f.\n",
1995 cmd->args[0].v.s, cmd->args[1].v.f);
1997 break;
1999 case MP_CMD_GET_PROPERTY:{
2000 char *tmp;
2001 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2002 &tmp, mpctx) <= 0) {
2003 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2004 "Failed to get value of property '%s'.\n",
2005 cmd->args[0].v.s);
2006 break;
2008 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2009 cmd->args[0].v.s, tmp);
2010 free(tmp);
2012 break;
2014 case MP_CMD_EDL_MARK:
2015 if (edl_fd) {
2016 float v = sh_video ? sh_video->pts :
2017 playing_audio_pts(sh_audio, mpctx->d_audio,
2018 mpctx->audio_out);
2020 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2021 mpctx->begin_skip = v;
2022 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2023 } else {
2024 if (mpctx->begin_skip > v)
2025 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2026 else {
2027 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2028 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2030 mpctx->begin_skip = MP_NOPTS_VALUE;
2033 break;
2035 case MP_CMD_SWITCH_RATIO:
2036 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2037 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2038 else
2039 movie_aspect = cmd->args[0].v.f;
2040 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2041 break;
2043 case MP_CMD_SPEED_INCR:{
2044 float v = cmd->args[0].v.f;
2045 playback_speed += v;
2046 build_afilter_chain(sh_audio, &ao_data);
2047 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2048 playback_speed);
2049 } break;
2051 case MP_CMD_SPEED_MULT:{
2052 float v = cmd->args[0].v.f;
2053 playback_speed *= v;
2054 build_afilter_chain(sh_audio, &ao_data);
2055 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2056 playback_speed);
2057 } break;
2059 case MP_CMD_SPEED_SET:{
2060 float v = cmd->args[0].v.f;
2061 playback_speed = v;
2062 build_afilter_chain(sh_audio, &ao_data);
2063 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2064 playback_speed);
2065 } break;
2067 case MP_CMD_FRAME_STEP:
2068 case MP_CMD_PAUSE:
2069 cmd->pausing = 1;
2070 brk_cmd = 1;
2071 break;
2073 case MP_CMD_FILE_FILTER:
2074 file_filter = cmd->args[0].v.i;
2075 break;
2077 case MP_CMD_QUIT:
2078 exit_player_with_rc(MSGTR_Exit_quit,
2079 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2081 case MP_CMD_PLAY_TREE_STEP:{
2082 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2083 int force = cmd->args[1].v.i;
2085 #ifdef HAVE_NEW_GUI
2086 if (use_gui) {
2087 int i = 0;
2088 if (n > 0)
2089 for (i = 0; i < n; i++)
2090 mplNext();
2091 else
2092 for (i = 0; i < -1 * n; i++)
2093 mplPrev();
2094 } else
2095 #endif
2097 if (!force && mpctx->playtree_iter) {
2098 play_tree_iter_t *i =
2099 play_tree_iter_new_copy(mpctx->playtree_iter);
2100 if (play_tree_iter_step(i, n, 0) ==
2101 PLAY_TREE_ITER_ENTRY)
2102 mpctx->eof =
2103 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2104 play_tree_iter_free(i);
2105 } else
2106 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2107 if (mpctx->eof)
2108 mpctx->play_tree_step = n;
2109 brk_cmd = 1;
2112 break;
2114 case MP_CMD_PLAY_TREE_UP_STEP:{
2115 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2116 int force = cmd->args[1].v.i;
2118 if (!force && mpctx->playtree_iter) {
2119 play_tree_iter_t *i =
2120 play_tree_iter_new_copy(mpctx->playtree_iter);
2121 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2122 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2123 play_tree_iter_free(i);
2124 } else
2125 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2126 brk_cmd = 1;
2128 break;
2130 case MP_CMD_PLAY_ALT_SRC_STEP:
2131 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2132 int v = cmd->args[0].v.i;
2133 if (v > 0
2134 && mpctx->playtree_iter->file <
2135 mpctx->playtree_iter->num_files)
2136 mpctx->eof = PT_NEXT_SRC;
2137 else if (v < 0 && mpctx->playtree_iter->file > 1)
2138 mpctx->eof = PT_PREV_SRC;
2140 brk_cmd = 1;
2141 break;
2143 case MP_CMD_SUB_STEP:
2144 if (sh_video) {
2145 int movement = cmd->args[0].v.i;
2146 step_sub(subdata, sh_video->pts, movement);
2147 #ifdef USE_ASS
2148 if (ass_track)
2149 sub_delay +=
2150 ass_step_sub(ass_track,
2151 (sh_video->pts +
2152 sub_delay) * 1000 + .5, movement) / 1000.;
2153 #endif
2154 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2155 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2157 break;
2159 case MP_CMD_SUB_LOG:
2160 log_sub();
2161 break;
2163 case MP_CMD_OSD:{
2164 int v = cmd->args[0].v.i;
2165 int max = (term_osd
2166 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2167 if (osd_level > max)
2168 osd_level = max;
2169 if (v < 0)
2170 osd_level = (osd_level + 1) % (max + 1);
2171 else
2172 osd_level = v > max ? max : v;
2173 /* Show OSD state when disabled, but not when an explicit
2174 argument is given to the OSD command, i.e. in slave mode. */
2175 if (v == -1 && osd_level <= 1)
2176 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2177 MSGTR_OSDosd,
2178 osd_level ? MSGTR_OSDenabled :
2179 MSGTR_OSDdisabled);
2180 else
2181 rm_osd_msg(OSD_MSG_OSD_STATUS);
2183 break;
2185 case MP_CMD_OSD_SHOW_TEXT:
2186 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2187 (cmd->args[1].v.i <
2188 0 ? osd_duration : cmd->args[1].v.i),
2189 "%-.63s", cmd->args[0].v.s);
2190 break;
2192 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2193 char *txt = m_properties_expand_string(mp_properties,
2194 cmd->args[0].v.s,
2195 mpctx);
2196 /* if no argument supplied take default osd_duration, else <arg> ms. */
2197 if (txt) {
2198 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2199 (cmd->args[1].v.i <
2200 0 ? osd_duration : cmd->args[1].v.i),
2201 "%-.63s", txt);
2202 free(txt);
2205 break;
2207 case MP_CMD_LOADFILE:{
2208 play_tree_t *e = play_tree_new();
2209 play_tree_add_file(e, cmd->args[0].v.s);
2211 if (cmd->args[1].v.i) // append
2212 play_tree_append_entry(mpctx->playtree, e);
2213 else {
2214 // Go back to the starting point.
2215 while (play_tree_iter_up_step
2216 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2217 /* NOP */ ;
2218 play_tree_free_list(mpctx->playtree->child, 1);
2219 play_tree_set_child(mpctx->playtree, e);
2220 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2221 mpctx->eof = PT_NEXT_SRC;
2223 brk_cmd = 1;
2225 break;
2227 case MP_CMD_LOADLIST:{
2228 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2229 if (!e)
2230 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2231 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2232 else {
2233 if (cmd->args[1].v.i) // append
2234 play_tree_append_entry(mpctx->playtree, e);
2235 else {
2236 // Go back to the starting point.
2237 while (play_tree_iter_up_step
2238 (mpctx->playtree_iter, 0, 1)
2239 != PLAY_TREE_ITER_END)
2240 /* NOP */ ;
2241 play_tree_free_list(mpctx->playtree->child, 1);
2242 play_tree_set_child(mpctx->playtree, e);
2243 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2244 mpctx->eof = PT_NEXT_SRC;
2247 brk_cmd = 1;
2249 break;
2251 #ifdef USE_RADIO
2252 case MP_CMD_RADIO_STEP_CHANNEL:
2253 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2254 int v = cmd->args[0].v.i;
2255 if (v > 0)
2256 radio_step_channel(mpctx->demuxer->stream,
2257 RADIO_CHANNEL_HIGHER);
2258 else
2259 radio_step_channel(mpctx->demuxer->stream,
2260 RADIO_CHANNEL_LOWER);
2261 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2262 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2263 MSGTR_OSDChannel,
2264 radio_get_channel_name(mpctx->demuxer->stream));
2267 break;
2269 case MP_CMD_RADIO_SET_CHANNEL:
2270 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2271 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2272 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2273 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2274 MSGTR_OSDChannel,
2275 radio_get_channel_name(mpctx->demuxer->stream));
2278 break;
2280 case MP_CMD_RADIO_SET_FREQ:
2281 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2282 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2283 break;
2285 case MP_CMD_RADIO_STEP_FREQ:
2286 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2287 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2288 break;
2289 #endif
2291 #ifdef USE_TV
2292 case MP_CMD_TV_START_SCAN:
2293 if (mpctx->file_format == DEMUXER_TYPE_TV)
2294 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2295 break;
2296 case MP_CMD_TV_SET_FREQ:
2297 if (mpctx->file_format == DEMUXER_TYPE_TV)
2298 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2299 cmd->args[0].v.f * 16.0);
2300 #ifdef HAVE_PVR
2301 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2302 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2303 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2304 pvr_get_current_channelname (mpctx->stream),
2305 pvr_get_current_stationname (mpctx->stream));
2307 #endif /* HAVE_PVR */
2308 break;
2310 case MP_CMD_TV_STEP_FREQ:
2311 if (mpctx->file_format == DEMUXER_TYPE_TV)
2312 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2313 cmd->args[0].v.f * 16.0);
2314 #ifdef HAVE_PVR
2315 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2316 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2317 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2318 pvr_get_current_channelname (mpctx->stream),
2319 pvr_get_current_frequency (mpctx->stream));
2321 #endif /* HAVE_PVR */
2322 break;
2324 case MP_CMD_TV_SET_NORM:
2325 if (mpctx->file_format == DEMUXER_TYPE_TV)
2326 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2327 cmd->args[0].v.s);
2328 break;
2330 case MP_CMD_TV_STEP_CHANNEL:{
2331 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2332 int v = cmd->args[0].v.i;
2333 if (v > 0) {
2334 tv_step_channel((tvi_handle_t *) (mpctx->
2335 demuxer->priv),
2336 TV_CHANNEL_HIGHER);
2337 } else {
2338 tv_step_channel((tvi_handle_t *) (mpctx->
2339 demuxer->priv),
2340 TV_CHANNEL_LOWER);
2342 if (tv_channel_list) {
2343 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2344 MSGTR_OSDChannel, tv_channel_current->name);
2345 //vo_osd_changed(OSDTYPE_SUBTITLE);
2348 #ifdef HAVE_PVR
2349 else if (mpctx->stream &&
2350 mpctx->stream->type == STREAMTYPE_PVR) {
2351 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2352 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2353 pvr_get_current_channelname (mpctx->stream),
2354 pvr_get_current_stationname (mpctx->stream));
2356 #endif /* HAVE_PVR */
2358 #ifdef HAS_DVBIN_SUPPORT
2359 if ((mpctx->stream->type == STREAMTYPE_DVB)
2360 && mpctx->stream->priv) {
2361 dvb_priv_t *priv = (dvb_priv_t *) mpctx->stream->priv;
2362 if (priv->is_on) {
2363 int dir;
2364 int v = cmd->args[0].v.i;
2366 mpctx->last_dvb_step = v;
2367 if (v > 0)
2368 dir = DVB_CHANNEL_HIGHER;
2369 else
2370 dir = DVB_CHANNEL_LOWER;
2373 if (dvb_step_channel(priv, dir))
2374 mpctx->eof = mpctx->dvbin_reopen = 1;
2377 #endif /* HAS_DVBIN_SUPPORT */
2378 break;
2380 case MP_CMD_TV_SET_CHANNEL:
2381 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2382 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2383 cmd->args[0].v.s);
2384 if (tv_channel_list) {
2385 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2386 MSGTR_OSDChannel, tv_channel_current->name);
2387 //vo_osd_changed(OSDTYPE_SUBTITLE);
2390 #ifdef HAVE_PVR
2391 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2392 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2393 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2394 pvr_get_current_channelname (mpctx->stream),
2395 pvr_get_current_stationname (mpctx->stream));
2397 #endif /* HAVE_PVR */
2398 break;
2400 #ifdef HAS_DVBIN_SUPPORT
2401 case MP_CMD_DVB_SET_CHANNEL:
2402 if ((mpctx->stream->type == STREAMTYPE_DVB)
2403 && mpctx->stream->priv) {
2404 dvb_priv_t *priv = (dvb_priv_t *) mpctx->stream->priv;
2405 if (priv->is_on) {
2406 if (priv->list->current <= cmd->args[0].v.i)
2407 mpctx->last_dvb_step = 1;
2408 else
2409 mpctx->last_dvb_step = -1;
2411 if (dvb_set_channel
2412 (priv, cmd->args[1].v.i, cmd->args[0].v.i))
2413 mpctx->eof = mpctx->dvbin_reopen = 1;
2416 break;
2417 #endif /* HAS_DVBIN_SUPPORT */
2419 case MP_CMD_TV_LAST_CHANNEL:
2420 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2421 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2422 if (tv_channel_list) {
2423 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2424 MSGTR_OSDChannel, tv_channel_current->name);
2425 //vo_osd_changed(OSDTYPE_SUBTITLE);
2428 #ifdef HAVE_PVR
2429 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2430 pvr_set_lastchannel (mpctx->stream);
2431 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2432 pvr_get_current_channelname (mpctx->stream),
2433 pvr_get_current_stationname (mpctx->stream));
2435 #endif /* HAVE_PVR */
2436 break;
2438 case MP_CMD_TV_STEP_NORM:
2439 if (mpctx->file_format == DEMUXER_TYPE_TV)
2440 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2441 break;
2443 case MP_CMD_TV_STEP_CHANNEL_LIST:
2444 if (mpctx->file_format == DEMUXER_TYPE_TV)
2445 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2446 break;
2447 #ifdef HAVE_TV_TELETEXT
2448 case MP_CMD_TV_TELETEXT_ADD_DEC:
2450 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2451 if (mpctx->file_format == DEMUXER_TYPE_TV)
2452 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2453 break;
2455 case MP_CMD_TV_TELETEXT_GO_LINK:
2457 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2458 if (mpctx->file_format == DEMUXER_TYPE_TV)
2459 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2460 break;
2462 #endif /* HAVE_TV_TELETEXT */
2463 #endif /* USE_TV */
2465 case MP_CMD_SUB_LOAD:
2466 if (sh_video) {
2467 int n = mpctx->set_of_sub_size;
2468 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2469 if (n != mpctx->set_of_sub_size) {
2470 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2471 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2472 mpctx->global_sub_size;
2473 ++mpctx->global_sub_size;
2476 break;
2478 case MP_CMD_SUB_REMOVE:
2479 if (sh_video) {
2480 int v = cmd->args[0].v.i;
2481 sub_data *subd;
2482 if (v < 0) {
2483 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2484 subd = mpctx->set_of_subtitles[v];
2485 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2486 MSGTR_RemovedSubtitleFile, v + 1,
2487 filename_recode(subd->filename));
2488 sub_free(subd);
2489 mpctx->set_of_subtitles[v] = NULL;
2491 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2492 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2493 mpctx->set_of_sub_size = 0;
2494 if (mpctx->set_of_sub_pos >= 0) {
2495 mpctx->global_sub_pos = -2;
2496 subdata = NULL;
2497 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2499 } else if (v < mpctx->set_of_sub_size) {
2500 subd = mpctx->set_of_subtitles[v];
2501 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2502 MSGTR_RemovedSubtitleFile, v + 1,
2503 filename_recode(subd->filename));
2504 sub_free(subd);
2505 if (mpctx->set_of_sub_pos == v) {
2506 mpctx->global_sub_pos = -2;
2507 subdata = NULL;
2508 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2509 } else if (mpctx->set_of_sub_pos > v) {
2510 --mpctx->set_of_sub_pos;
2511 --mpctx->global_sub_pos;
2513 while (++v < mpctx->set_of_sub_size)
2514 mpctx->set_of_subtitles[v - 1] =
2515 mpctx->set_of_subtitles[v];
2516 --mpctx->set_of_sub_size;
2517 --mpctx->global_sub_size;
2518 if (mpctx->set_of_sub_size <= 0)
2519 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2520 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2523 break;
2525 case MP_CMD_GET_SUB_VISIBILITY:
2526 if (sh_video) {
2527 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2528 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2530 break;
2532 case MP_CMD_SCREENSHOT:
2533 if (vo_config_count) {
2534 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2535 if (CONTROL_OK !=
2536 ((vf_instance_t *) sh_video->vfilter)->
2537 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2538 &cmd->args[0].v.i))
2539 mpctx->video_out->control(VOCTRL_SCREENSHOT, NULL);
2541 break;
2543 case MP_CMD_VF_CHANGE_RECTANGLE:
2544 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2545 break;
2547 case MP_CMD_GET_TIME_LENGTH:{
2548 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2549 demuxer_get_time_length(mpctx->demuxer));
2551 break;
2553 case MP_CMD_GET_FILENAME:{
2554 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2555 get_metadata(META_NAME));
2557 break;
2559 case MP_CMD_GET_VIDEO_CODEC:{
2560 char *inf = get_metadata(META_VIDEO_CODEC);
2561 if (!inf)
2562 inf = strdup("");
2563 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2564 free(inf);
2566 break;
2568 case MP_CMD_GET_VIDEO_BITRATE:{
2569 char *inf = get_metadata(META_VIDEO_BITRATE);
2570 if (!inf)
2571 inf = strdup("");
2572 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2573 free(inf);
2575 break;
2577 case MP_CMD_GET_VIDEO_RESOLUTION:{
2578 char *inf = get_metadata(META_VIDEO_RESOLUTION);
2579 if (!inf)
2580 inf = strdup("");
2581 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2582 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
2583 free(inf);
2585 break;
2587 case MP_CMD_GET_AUDIO_CODEC:{
2588 char *inf = get_metadata(META_AUDIO_CODEC);
2589 if (!inf)
2590 inf = strdup("");
2591 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
2592 free(inf);
2594 break;
2596 case MP_CMD_GET_AUDIO_BITRATE:{
2597 char *inf = get_metadata(META_AUDIO_BITRATE);
2598 if (!inf)
2599 inf = strdup("");
2600 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
2601 free(inf);
2603 break;
2605 case MP_CMD_GET_AUDIO_SAMPLES:{
2606 char *inf = get_metadata(META_AUDIO_SAMPLES);
2607 if (!inf)
2608 inf = strdup("");
2609 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
2610 free(inf);
2612 break;
2614 case MP_CMD_GET_META_TITLE:{
2615 char *inf = get_metadata(META_INFO_TITLE);
2616 if (!inf)
2617 inf = strdup("");
2618 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
2619 free(inf);
2621 break;
2623 case MP_CMD_GET_META_ARTIST:{
2624 char *inf = get_metadata(META_INFO_ARTIST);
2625 if (!inf)
2626 inf = strdup("");
2627 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
2628 free(inf);
2630 break;
2632 case MP_CMD_GET_META_ALBUM:{
2633 char *inf = get_metadata(META_INFO_ALBUM);
2634 if (!inf)
2635 inf = strdup("");
2636 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
2637 free(inf);
2639 break;
2641 case MP_CMD_GET_META_YEAR:{
2642 char *inf = get_metadata(META_INFO_YEAR);
2643 if (!inf)
2644 inf = strdup("");
2645 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
2646 free(inf);
2648 break;
2650 case MP_CMD_GET_META_COMMENT:{
2651 char *inf = get_metadata(META_INFO_COMMENT);
2652 if (!inf)
2653 inf = strdup("");
2654 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
2655 free(inf);
2657 break;
2659 case MP_CMD_GET_META_TRACK:{
2660 char *inf = get_metadata(META_INFO_TRACK);
2661 if (!inf)
2662 inf = strdup("");
2663 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
2664 free(inf);
2666 break;
2668 case MP_CMD_GET_META_GENRE:{
2669 char *inf = get_metadata(META_INFO_GENRE);
2670 if (!inf)
2671 inf = strdup("");
2672 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
2673 free(inf);
2675 break;
2677 case MP_CMD_GET_VO_FULLSCREEN:
2678 if (mpctx->video_out && vo_config_count)
2679 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
2680 break;
2682 case MP_CMD_GET_PERCENT_POS:
2683 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
2684 demuxer_get_percent_pos(mpctx->demuxer));
2685 break;
2687 case MP_CMD_GET_TIME_POS:{
2688 float pos = 0;
2689 if (sh_video)
2690 pos = sh_video->pts;
2691 else if (sh_audio && mpctx->audio_out)
2692 pos =
2693 playing_audio_pts(sh_audio, mpctx->d_audio,
2694 mpctx->audio_out);
2695 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
2697 break;
2699 case MP_CMD_RUN:
2700 #ifndef __MINGW32__
2701 if (!fork()) {
2702 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
2703 exit(0);
2705 #endif
2706 break;
2708 case MP_CMD_KEYDOWN_EVENTS:
2709 mplayer_put_key(cmd->args[0].v.i);
2710 break;
2712 case MP_CMD_SEEK_CHAPTER:{
2713 int seek = cmd->args[0].v.i;
2714 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2715 int chap;
2716 float next_pts = 0;
2717 int num_chapters;
2718 char *chapter_name;
2720 rel_seek_secs = 0;
2721 abs_seek_pos = 0;
2722 chap =
2723 demuxer_seek_chapter(mpctx->demuxer, seek, abs,
2724 &next_pts, &num_chapters,
2725 &chapter_name);
2726 if (chap != -1) {
2727 if (next_pts > -1.0) {
2728 abs_seek_pos = 1;
2729 rel_seek_secs = next_pts;
2731 if (chapter_name) {
2732 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2733 MSGTR_OSDChapter, chap + 1, chapter_name);
2734 free(chapter_name);
2736 } else {
2737 if (seek > 0)
2738 rel_seek_secs = 1000000000.;
2739 else
2740 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2741 MSGTR_OSDChapter, 0, MSGTR_Unknown);
2743 break;
2745 break;
2747 case MP_CMD_SET_MOUSE_POS:{
2748 int pointer_x, pointer_y;
2749 double dx, dy;
2750 pointer_x = cmd->args[0].v.i;
2751 pointer_y = cmd->args[1].v.i;
2752 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
2753 #ifdef USE_DVDNAV
2754 if (mpctx->stream->type == STREAMTYPE_DVDNAV
2755 && dx > 0.0 && dy > 0.0) {
2756 int button = -1;
2757 pointer_x = (int) (dx * (double) sh_video->disp_w);
2758 pointer_y = (int) (dy * (double) sh_video->disp_h);
2759 mp_dvdnav_update_mouse_pos(mpctx->stream,
2760 pointer_x, pointer_y, &button);
2761 if (button > 0)
2762 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2763 "Selected button number %d", button);
2765 #endif
2767 break;
2769 #ifdef USE_DVDNAV
2770 case MP_CMD_DVDNAV:{
2771 int button = -1;
2772 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
2773 break;
2775 if (mp_dvdnav_handle_input
2776 (mpctx->stream, cmd->args[0].v.i, &button)) {
2777 uninit_player(INITED_ALL - (INITED_STREAM | INITED_INPUT |
2778 (fixed_vo ? INITED_VO : 0)));
2779 brk_cmd = 2;
2780 } else if (button > 0)
2781 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2782 "Selected button number %d", button);
2784 break;
2785 #endif
2787 default:
2788 #ifdef HAVE_NEW_GUI
2789 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
2790 guiGetEvent(guiIEvent, (char *) cmd->id);
2791 else
2792 #endif
2793 mp_msg(MSGT_CPLAYER, MSGL_V,
2794 "Received unknown cmd %s\n", cmd->name);
2797 switch (cmd->pausing) {
2798 case 1: // "pausing"
2799 mpctx->osd_function = OSD_PAUSE;
2800 break;
2801 case 3: // "pausing_toggle"
2802 mpctx->was_paused = !mpctx->was_paused;
2803 // fall through
2804 case 2: // "pausing_keep"
2805 if (mpctx->was_paused)
2806 mpctx->osd_function = OSD_PAUSE;
2808 return brk_cmd;