synced with r22428
[mplayer/greg.git] / command.c
blob7b1e91081117adf05fbd54f7edb218d856da767c
1 #include <stdlib.h>
2 #include <inttypes.h>
3 #include <unistd.h>
5 #include "config.h"
6 #include "input/input.h"
7 #include "stream/stream.h"
8 #include "libmpdemux/demuxer.h"
9 #include "libmpdemux/stheader.h"
10 #include "mplayer.h"
11 #include "libvo/sub.h"
12 #include "m_option.h"
13 #include "m_property.h"
14 #include "help_mp.h"
15 #include "metadata.h"
16 #include "libmpcodecs/mp_image.h"
17 #include "libmpcodecs/vf.h"
18 #include "libmpcodecs/vd.h"
19 #include "libvo/video_out.h"
20 #include "playtree.h"
21 #include "libao2/audio_out.h"
22 #include "mpcommon.h"
23 #include "mixer.h"
24 #include "libmpdemux/matroska.h"
25 #include "libmpcodecs/dec_video.h"
26 #include "vobsub.h"
27 #include "spudec.h"
28 #ifdef USE_TV
29 #include "stream/tv.h"
30 #endif
31 #ifdef USE_RADIO
32 #include "stream/stream_radio.h"
33 #endif
34 #ifdef HAS_DVBIN_SUPPORT
35 #include "stream/dvbin.h"
36 #endif
37 #ifdef USE_DVDREAD
38 #include "stream/stream_dvd.h"
39 #endif
40 #ifdef USE_DVDNAV
41 #include "stream/stream_dvdnav.h"
42 #endif
43 #ifdef USE_ASS
44 #include "libass/ass.h"
45 #include "libass/ass_mp.h"
46 #endif
47 #ifdef HAVE_NEW_GUI
48 #include "Gui/interface.h"
49 #endif
51 #include "mp_core.h"
53 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
55 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy)
57 //remove the borders, if any, and rescale to the range [0,1],[0,1]
58 if (vo_fs) { //we are in full-screen mode
59 if (vo_screenwidth > vo_dwidth) //there are borders along the x axis
60 ix -= (vo_screenwidth - vo_dwidth) / 2;
61 if (vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
62 iy -= (vo_screenheight - vo_dheight) / 2;
64 if (ix < 0 || ix > vo_dwidth) {
65 *dx = *dy = -1.0;
66 return;
67 } //we are on one of the borders
68 if (iy < 0 || iy > vo_dheight) {
69 *dx = *dy = -1.0;
70 return;
71 } //we are on one of the borders
74 *dx = (double) ix / (double) vo_dwidth;
75 *dy = (double) iy / (double) vo_dheight;
77 mp_msg(MSGT_CPLAYER, MSGL_V,
78 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
79 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth,
80 vo_dheight, vo_fs);
83 static int sub_source(MPContext * mpctx)
85 int source = -1;
86 int top = -1;
87 int i;
88 for (i = 0; i < SUB_SOURCES; i++) {
89 int j = mpctx->global_sub_indices[i];
90 if ((j >= 0) && (j > top) && (mpctx->global_sub_pos >= j)) {
91 source = i;
92 top = j;
95 return source;
98 /**
99 * \brief Log the currently displayed subtitle to a file
101 * Logs the current or last displayed subtitle together with filename
102 * and time information to ~/.mplayer/subtitle_log
104 * Intended purpose is to allow convenient marking of bogus subtitles
105 * which need to be fixed while watching the movie.
108 static void log_sub(void)
110 char *fname;
111 FILE *f;
112 int i;
114 if (subdata == NULL || vo_sub_last == NULL)
115 return;
116 fname = get_path("subtitle_log");
117 f = fopen(fname, "a");
118 if (!f)
119 return;
120 fprintf(f, "----------------------------------------------------------\n");
121 if (subdata->sub_uses_time) {
122 fprintf(f,
123 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
124 filename, vo_sub_last->start / 360000,
125 (vo_sub_last->start / 6000) % 60,
126 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
127 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
128 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
129 } else {
130 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start,
131 vo_sub_last->end);
133 for (i = 0; i < vo_sub_last->lines; i++) {
134 fprintf(f, "%s\n", vo_sub_last->text[i]);
136 fclose(f);
140 /// \defgroup Properties
141 ///@{
143 /// \defgroup GeneralProperties General properties
144 /// \ingroup Properties
145 ///@{
147 /// OSD level (RW)
148 static int mp_property_osdlevel(m_option_t * prop, int action, void *arg,
149 MPContext * mpctx)
151 return m_property_choice(prop, action, arg, &osd_level);
154 /// Playback speed (RW)
155 static int mp_property_playback_speed(m_option_t * prop, int action,
156 void *arg, MPContext * mpctx)
158 switch (action) {
159 case M_PROPERTY_SET:
160 if (!arg)
161 return M_PROPERTY_ERROR;
162 M_PROPERTY_CLAMP(prop, *(float *) arg);
163 playback_speed = *(float *) arg;
164 build_afilter_chain(mpctx->sh_audio, &ao_data);
165 return M_PROPERTY_OK;
166 case M_PROPERTY_STEP_UP:
167 case M_PROPERTY_STEP_DOWN:
168 playback_speed += (arg ? *(float *) arg : 0.1) *
169 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
170 M_PROPERTY_CLAMP(prop, playback_speed);
171 build_afilter_chain(mpctx->sh_audio, &ao_data);
172 return M_PROPERTY_OK;
174 return m_property_float_range(prop, action, arg, &playback_speed);
177 /// filename with path (RO)
178 static int mp_property_path(m_option_t * prop, int action, void *arg,
179 MPContext * mpctx)
181 return m_property_string_ro(prop, action, arg, filename);
184 /// filename without path (RO)
185 static int mp_property_filename(m_option_t * prop, int action, void *arg,
186 MPContext * mpctx)
188 char *f;
189 if (!filename)
190 return M_PROPERTY_UNAVAILABLE;
191 if (((f = strrchr(filename, '/')) || (f = strrchr(filename, '\\'))) && f[1])
192 f++;
193 else
194 f = filename;
195 return m_property_string_ro(prop, action, arg, f);
198 /// Demuxer name (RO)
199 static int mp_property_demuxer(m_option_t * prop, int action, void *arg,
200 MPContext * mpctx)
202 if (!mpctx->demuxer)
203 return M_PROPERTY_UNAVAILABLE;
204 return m_property_string_ro(prop, action, arg,
205 (char *) mpctx->demuxer->desc->name);
208 /// Position in the stream (RW)
209 static int mp_property_stream_pos(m_option_t * prop, int action, void *arg,
210 MPContext * mpctx)
212 if (!mpctx->demuxer || !mpctx->demuxer->stream)
213 return M_PROPERTY_UNAVAILABLE;
214 if (!arg)
215 return M_PROPERTY_ERROR;
216 switch (action) {
217 case M_PROPERTY_GET:
218 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
219 return M_PROPERTY_OK;
220 case M_PROPERTY_SET:
221 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
222 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
223 return M_PROPERTY_OK;
225 return M_PROPERTY_NOT_IMPLEMENTED;
228 /// Stream start offset (RO)
229 static int mp_property_stream_start(m_option_t * prop, int action,
230 void *arg, MPContext * mpctx)
232 if (!mpctx->demuxer || !mpctx->demuxer->stream)
233 return M_PROPERTY_UNAVAILABLE;
234 switch (action) {
235 case M_PROPERTY_GET:
236 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
237 return M_PROPERTY_OK;
239 return M_PROPERTY_NOT_IMPLEMENTED;
242 /// Stream end offset (RO)
243 static int mp_property_stream_end(m_option_t * prop, int action, void *arg,
244 MPContext * mpctx)
246 if (!mpctx->demuxer || !mpctx->demuxer->stream)
247 return M_PROPERTY_UNAVAILABLE;
248 switch (action) {
249 case M_PROPERTY_GET:
250 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
251 return M_PROPERTY_OK;
253 return M_PROPERTY_NOT_IMPLEMENTED;
256 /// Stream length (RO)
257 static int mp_property_stream_length(m_option_t * prop, int action,
258 void *arg, MPContext * mpctx)
260 if (!mpctx->demuxer || !mpctx->demuxer->stream)
261 return M_PROPERTY_UNAVAILABLE;
262 switch (action) {
263 case M_PROPERTY_GET:
264 *(off_t *) arg =
265 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
266 return M_PROPERTY_OK;
268 return M_PROPERTY_NOT_IMPLEMENTED;
271 /// Media length in seconds (RO)
272 static int mp_property_length(m_option_t * prop, int action, void *arg,
273 MPContext * mpctx)
275 double len;
277 if (!mpctx->demuxer ||
278 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
279 return M_PROPERTY_UNAVAILABLE;
281 switch (action) {
282 case M_PROPERTY_PRINT:
283 if (!arg)
284 return M_PROPERTY_ERROR;
285 else {
286 int h, m, s = len;
287 h = s / 3600;
288 s -= h * 3600;
289 m = s / 60;
290 s -= m * 60;
291 *(char **) arg = malloc(20);
292 if (h > 0)
293 sprintf(*(char **) arg, "%d:%02d:%02d", h, m, s);
294 else if (m > 0)
295 sprintf(*(char **) arg, "%d:%02d", m, s);
296 else
297 sprintf(*(char **) arg, "%d", s);
298 return M_PROPERTY_OK;
300 break;
302 return m_property_double_ro(prop, action, arg, len);
305 ///@}
307 /// \defgroup AudioProperties Audio properties
308 /// \ingroup Properties
309 ///@{
311 /// Volume (RW)
312 static int mp_property_volume(m_option_t * prop, int action, void *arg,
313 MPContext * mpctx)
316 if (!mpctx->sh_audio)
317 return M_PROPERTY_UNAVAILABLE;
319 switch (action) {
320 case M_PROPERTY_GET:
321 if (!arg)
322 return M_PROPERTY_ERROR;
323 mixer_getbothvolume(&mpctx->mixer, arg);
324 return M_PROPERTY_OK;
325 case M_PROPERTY_PRINT:{
326 float vol;
327 if (!arg)
328 return M_PROPERTY_ERROR;
329 mixer_getbothvolume(&mpctx->mixer, &vol);
330 return m_property_float_range(prop, action, arg, &vol);
332 case M_PROPERTY_STEP_UP:
333 case M_PROPERTY_STEP_DOWN:
334 case M_PROPERTY_SET:
335 break;
336 default:
337 return M_PROPERTY_NOT_IMPLEMENTED;
340 if (mpctx->edl_muted)
341 return M_PROPERTY_DISABLED;
342 mpctx->user_muted = 0;
344 switch (action) {
345 case M_PROPERTY_SET:
346 if (!arg)
347 return M_PROPERTY_ERROR;
348 M_PROPERTY_CLAMP(prop, *(float *) arg);
349 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
350 return M_PROPERTY_OK;
351 case M_PROPERTY_STEP_UP:
352 if (arg && *(float *) arg <= 0)
353 mixer_decvolume(&mpctx->mixer);
354 else
355 mixer_incvolume(&mpctx->mixer);
356 return M_PROPERTY_OK;
357 case M_PROPERTY_STEP_DOWN:
358 if (arg && *(float *) arg <= 0)
359 mixer_incvolume(&mpctx->mixer);
360 else
361 mixer_decvolume(&mpctx->mixer);
362 return M_PROPERTY_OK;
364 return M_PROPERTY_NOT_IMPLEMENTED;
367 /// Mute (RW)
368 static int mp_property_mute(m_option_t * prop, int action, void *arg,
369 MPContext * mpctx)
372 if (!mpctx->sh_audio)
373 return M_PROPERTY_UNAVAILABLE;
375 switch (action) {
376 case M_PROPERTY_SET:
377 if (mpctx->edl_muted)
378 return M_PROPERTY_DISABLED;
379 if (!arg)
380 return M_PROPERTY_ERROR;
381 if ((!!*(int *) arg) != mpctx->mixer.muted)
382 mixer_mute(&mpctx->mixer);
383 mpctx->user_muted = mpctx->mixer.muted;
384 return M_PROPERTY_OK;
385 case M_PROPERTY_STEP_UP:
386 case M_PROPERTY_STEP_DOWN:
387 if (mpctx->edl_muted)
388 return M_PROPERTY_DISABLED;
389 mixer_mute(&mpctx->mixer);
390 mpctx->user_muted = mpctx->mixer.muted;
391 return M_PROPERTY_OK;
392 case M_PROPERTY_PRINT:
393 if (!arg)
394 return M_PROPERTY_ERROR;
395 if (mpctx->edl_muted) {
396 *(char **) arg = strdup(MSGTR_EnabledEdl);
397 return M_PROPERTY_OK;
399 default:
400 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
405 /// Audio delay (RW)
406 static int mp_property_audio_delay(m_option_t * prop, int action,
407 void *arg, MPContext * mpctx)
409 if (!(mpctx->sh_audio && mpctx->sh_video))
410 return M_PROPERTY_UNAVAILABLE;
411 switch (action) {
412 case M_PROPERTY_SET:
413 case M_PROPERTY_STEP_UP:
414 case M_PROPERTY_STEP_DOWN:
415 if (!arg)
416 return M_PROPERTY_ERROR;
417 else {
418 float delay = audio_delay;
419 m_property_delay(prop, action, arg, &audio_delay);
420 if (mpctx->sh_audio)
421 mpctx->sh_audio->delay -= audio_delay - delay;
423 return M_PROPERTY_OK;
424 default:
425 return m_property_delay(prop, action, arg, &audio_delay);
429 /// Audio codec tag (RO)
430 static int mp_property_audio_format(m_option_t * prop, int action,
431 void *arg, MPContext * mpctx)
433 if (!mpctx->sh_audio)
434 return M_PROPERTY_UNAVAILABLE;
435 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
438 /// Audio bitrate (RO)
439 static int mp_property_audio_bitrate(m_option_t * prop, int action,
440 void *arg, MPContext * mpctx)
442 if (!mpctx->sh_audio)
443 return M_PROPERTY_UNAVAILABLE;
444 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->i_bps);
447 /// Samplerate (RO)
448 static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
449 MPContext * mpctx)
451 if (!mpctx->sh_audio)
452 return M_PROPERTY_UNAVAILABLE;
453 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
456 /// Number of channels (RO)
457 static int mp_property_channels(m_option_t * prop, int action, void *arg,
458 MPContext * mpctx)
460 if (!mpctx->sh_audio)
461 return M_PROPERTY_UNAVAILABLE;
462 switch (action) {
463 case M_PROPERTY_PRINT:
464 if (!arg)
465 return M_PROPERTY_ERROR;
466 switch (mpctx->sh_audio->channels) {
467 case 1:
468 *(char **) arg = strdup("mono");
469 break;
470 case 2:
471 *(char **) arg = strdup("stereo");
472 break;
473 default:
474 *(char **) arg = malloc(32);
475 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
477 return M_PROPERTY_OK;
479 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
482 /// Selected audio id (RW)
483 static int mp_property_audio(m_option_t * prop, int action, void *arg,
484 MPContext * mpctx)
486 int current_id = -1, tmp;
488 switch (action) {
489 case M_PROPERTY_GET:
490 if (!mpctx->sh_audio)
491 return M_PROPERTY_UNAVAILABLE;
492 if (!arg)
493 return M_PROPERTY_ERROR;
494 *(int *) arg = audio_id;
495 return M_PROPERTY_OK;
496 case M_PROPERTY_PRINT:
497 if (!mpctx->sh_audio)
498 return M_PROPERTY_UNAVAILABLE;
499 if (!arg)
500 return M_PROPERTY_ERROR;
502 if (audio_id < 0)
503 *(char **) arg = strdup(MSGTR_Disabled);
504 else {
505 char lang[40] = MSGTR_Unknown;
506 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA)
507 demux_mkv_get_audio_lang(mpctx->demuxer, audio_id, lang, 9);
508 #ifdef USE_DVDREAD
509 else if (mpctx->stream->type == STREAMTYPE_DVD) {
510 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
511 if (code) {
512 lang[0] = code >> 8;
513 lang[1] = code;
514 lang[2] = 0;
517 #endif
519 #ifdef USE_DVDNAV
520 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
521 dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
522 #endif
523 *(char **) arg = malloc(64);
524 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
526 return M_PROPERTY_OK;
528 case M_PROPERTY_STEP_UP:
529 case M_PROPERTY_SET:
530 if (action == M_PROPERTY_SET && arg)
531 tmp = *((int *) arg);
532 else
533 tmp = -1;
534 current_id = mpctx->demuxer->audio->id;
535 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
536 if (audio_id == -2
537 || (audio_id > -1
538 && mpctx->demuxer->audio->id != current_id && current_id != -2))
539 uninit_player(INITED_AO | INITED_ACODEC);
540 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
541 sh_audio_t *sh2;
542 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
543 if (sh2) {
544 sh2->ds = mpctx->demuxer->audio;
545 mpctx->sh_audio = sh2;
546 reinit_audio_chain();
549 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
550 return M_PROPERTY_OK;
551 default:
552 return M_PROPERTY_NOT_IMPLEMENTED;
557 /// Selected video id (RW)
558 static int mp_property_video(m_option_t * prop, int action, void *arg,
559 MPContext * mpctx)
561 int current_id = -1, tmp;
563 switch (action) {
564 case M_PROPERTY_GET:
565 if (!mpctx->sh_video)
566 return M_PROPERTY_UNAVAILABLE;
567 if (!arg)
568 return M_PROPERTY_ERROR;
569 *(int *) arg = video_id;
570 return M_PROPERTY_OK;
571 case M_PROPERTY_PRINT:
572 if (!mpctx->sh_video)
573 return M_PROPERTY_UNAVAILABLE;
574 if (!arg)
575 return M_PROPERTY_ERROR;
577 if (video_id < 0)
578 *(char **) arg = strdup(MSGTR_Disabled);
579 else {
580 char lang[40] = MSGTR_Unknown;
581 *(char **) arg = malloc(64);
582 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
584 return M_PROPERTY_OK;
586 case M_PROPERTY_STEP_UP:
587 case M_PROPERTY_SET:
588 current_id = mpctx->demuxer->video->id;
589 if (action == M_PROPERTY_SET && arg)
590 tmp = *((int *) arg);
591 else
592 tmp = -1;
593 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
594 if (video_id == -2
595 || (video_id > -1 && mpctx->demuxer->video->id != current_id
596 && current_id != -2))
597 uninit_player(INITED_VCODEC |
598 (fixed_vo && video_id != -2 ? 0 : INITED_VO));
599 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
600 sh_video_t *sh2;
601 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
602 if (sh2) {
603 sh2->ds = mpctx->demuxer->video;
604 mpctx->sh_video = sh2;
605 reinit_video_chain();
608 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
609 return M_PROPERTY_OK;
611 default:
612 return M_PROPERTY_NOT_IMPLEMENTED;
616 static int mp_property_program(m_option_t * prop, int action, void *arg,
617 MPContext * mpctx)
619 demux_program_t prog;
621 switch (action) {
622 case M_PROPERTY_STEP_UP:
623 case M_PROPERTY_SET:
624 if (action == M_PROPERTY_SET && arg)
625 prog.progid = *((int *) arg);
626 else
627 prog.progid = -1;
628 if (demux_control
629 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
630 &prog) == DEMUXER_CTRL_NOTIMPL)
631 return M_PROPERTY_ERROR;
633 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
634 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
635 return M_PROPERTY_OK;
637 default:
638 return M_PROPERTY_NOT_IMPLEMENTED;
642 ///@}
644 /// \defgroup VideoProperties Video properties
645 /// \ingroup Properties
646 ///@{
648 /// Fullscreen state (RW)
649 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
650 MPContext * mpctx)
653 if (!mpctx->video_out)
654 return M_PROPERTY_UNAVAILABLE;
656 switch (action) {
657 case M_PROPERTY_SET:
658 if (!arg)
659 return M_PROPERTY_ERROR;
660 M_PROPERTY_CLAMP(prop, *(int *) arg);
661 if (vo_fs == !!*(int *) arg)
662 return M_PROPERTY_OK;
663 case M_PROPERTY_STEP_UP:
664 case M_PROPERTY_STEP_DOWN:
665 #ifdef HAVE_NEW_GUI
666 if (use_gui)
667 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
668 else
669 #endif
670 if (vo_config_count)
671 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
672 return M_PROPERTY_OK;
673 default:
674 return m_property_flag(prop, action, arg, &vo_fs);
678 static int mp_property_deinterlace(m_option_t * prop, int action,
679 void *arg, MPContext * mpctx)
681 int deinterlace;
682 vf_instance_t *vf;
683 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
684 return M_PROPERTY_UNAVAILABLE;
685 vf = mpctx->sh_video->vfilter;
686 switch (action) {
687 case M_PROPERTY_GET:
688 if (!arg)
689 return M_PROPERTY_ERROR;
690 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
691 return M_PROPERTY_OK;
692 case M_PROPERTY_SET:
693 if (!arg)
694 return M_PROPERTY_ERROR;
695 M_PROPERTY_CLAMP(prop, *(int *) arg);
696 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
697 return M_PROPERTY_OK;
698 case M_PROPERTY_STEP_UP:
699 case M_PROPERTY_STEP_DOWN:
700 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
701 deinterlace = !deinterlace;
702 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
703 return M_PROPERTY_OK;
705 return M_PROPERTY_NOT_IMPLEMENTED;
708 /// Panscan (RW)
709 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
710 MPContext * mpctx)
713 if (!mpctx->video_out
714 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
715 return M_PROPERTY_UNAVAILABLE;
717 switch (action) {
718 case M_PROPERTY_SET:
719 if (!arg)
720 return M_PROPERTY_ERROR;
721 M_PROPERTY_CLAMP(prop, *(float *) arg);
722 vo_panscan = *(float *) arg;
723 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
724 return M_PROPERTY_OK;
725 case M_PROPERTY_STEP_UP:
726 case M_PROPERTY_STEP_DOWN:
727 vo_panscan += (arg ? *(float *) arg : 0.1) *
728 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
729 if (vo_panscan > 1)
730 vo_panscan = 1;
731 else if (vo_panscan < 0)
732 vo_panscan = 0;
733 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
734 return M_PROPERTY_OK;
735 default:
736 return m_property_float_range(prop, action, arg, &vo_panscan);
740 /// Helper to set vo flags.
741 /** \ingroup PropertyImplHelper
743 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
744 int vo_ctrl, int *vo_var, MPContext * mpctx)
747 if (!mpctx->video_out)
748 return M_PROPERTY_UNAVAILABLE;
750 switch (action) {
751 case M_PROPERTY_SET:
752 if (!arg)
753 return M_PROPERTY_ERROR;
754 M_PROPERTY_CLAMP(prop, *(int *) arg);
755 if (*vo_var == !!*(int *) arg)
756 return M_PROPERTY_OK;
757 case M_PROPERTY_STEP_UP:
758 case M_PROPERTY_STEP_DOWN:
759 if (vo_config_count)
760 mpctx->video_out->control(vo_ctrl, 0);
761 return M_PROPERTY_OK;
762 default:
763 return m_property_flag(prop, action, arg, vo_var);
767 /// Window always on top (RW)
768 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
769 MPContext * mpctx)
771 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
772 mpctx);
775 /// Display in the root window (RW)
776 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
777 MPContext * mpctx)
779 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
780 &vo_rootwin, mpctx);
783 /// Show window borders (RW)
784 static int mp_property_border(m_option_t * prop, int action, void *arg,
785 MPContext * mpctx)
787 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
788 &vo_border, mpctx);
791 /// Framedropping state (RW)
792 static int mp_property_framedropping(m_option_t * prop, int action,
793 void *arg, MPContext * mpctx)
796 if (!mpctx->sh_video)
797 return M_PROPERTY_UNAVAILABLE;
799 switch (action) {
800 case M_PROPERTY_PRINT:
801 if (!arg)
802 return M_PROPERTY_ERROR;
803 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
804 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
805 MSGTR_Disabled));
806 return M_PROPERTY_OK;
807 default:
808 return m_property_choice(prop, action, arg, &frame_dropping);
812 /// Color settings, try to use vf/vo then fall back on TV. (RW)
813 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
814 MPContext * mpctx)
816 int *gamma = prop->priv, r;
818 if (!mpctx->sh_video)
819 return M_PROPERTY_UNAVAILABLE;
821 if (gamma[0] == 1000) {
822 gamma[0] = 0;
823 get_video_colors(mpctx->sh_video, prop->name, gamma);
826 switch (action) {
827 case M_PROPERTY_SET:
828 if (!arg)
829 return M_PROPERTY_ERROR;
830 M_PROPERTY_CLAMP(prop, *(int *) arg);
831 *gamma = *(int *) arg;
832 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
833 if (r <= 0)
834 break;
835 return r;
836 case M_PROPERTY_GET:
837 if (!arg)
838 return M_PROPERTY_ERROR;
839 r = get_video_colors(mpctx->sh_video, prop->name, arg);
840 if (r <= 0)
841 break;
842 return r;
843 case M_PROPERTY_STEP_UP:
844 case M_PROPERTY_STEP_DOWN:
845 *gamma += (arg ? *(int *) arg : 1) *
846 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
847 M_PROPERTY_CLAMP(prop, *gamma);
848 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
849 if (r <= 0)
850 break;
851 return r;
852 default:
853 return M_PROPERTY_NOT_IMPLEMENTED;
856 #ifdef USE_TV
857 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
858 int l = strlen(prop->name);
859 char tv_prop[3 + l + 1];
860 sprintf(tv_prop, "tv_%s", prop->name);
861 return mp_property_do(tv_prop, action, arg, mpctx);
863 #endif
865 return M_PROPERTY_UNAVAILABLE;
868 /// VSync (RW)
869 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
870 MPContext * mpctx)
872 return m_property_flag(prop, action, arg, &vo_vsync);
875 /// Video codec tag (RO)
876 static int mp_property_video_format(m_option_t * prop, int action,
877 void *arg, MPContext * mpctx)
879 if (!mpctx->sh_video)
880 return M_PROPERTY_UNAVAILABLE;
881 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
884 /// Video bitrate (RO)
885 static int mp_property_video_bitrate(m_option_t * prop, int action,
886 void *arg, MPContext * mpctx)
888 if (!mpctx->sh_video)
889 return M_PROPERTY_UNAVAILABLE;
890 return m_property_int_ro(prop, action, arg, mpctx->sh_video->i_bps);
893 /// Video display width (RO)
894 static int mp_property_width(m_option_t * prop, int action, void *arg,
895 MPContext * mpctx)
897 if (!mpctx->sh_video)
898 return M_PROPERTY_UNAVAILABLE;
899 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
902 /// Video display height (RO)
903 static int mp_property_height(m_option_t * prop, int action, void *arg,
904 MPContext * mpctx)
906 if (!mpctx->sh_video)
907 return M_PROPERTY_UNAVAILABLE;
908 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
911 /// Video fps (RO)
912 static int mp_property_fps(m_option_t * prop, int action, void *arg,
913 MPContext * mpctx)
915 if (!mpctx->sh_video)
916 return M_PROPERTY_UNAVAILABLE;
917 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
920 /// Video aspect (RO)
921 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
922 MPContext * mpctx)
924 if (!mpctx->sh_video)
925 return M_PROPERTY_UNAVAILABLE;
926 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
929 ///@}
931 /// \defgroup SubProprties Subtitles properties
932 /// \ingroup Properties
933 ///@{
935 /// Text subtitle position (RW)
936 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
937 MPContext * mpctx)
939 if (!mpctx->sh_video)
940 return M_PROPERTY_UNAVAILABLE;
942 switch (action) {
943 case M_PROPERTY_SET:
944 if (!arg)
945 return M_PROPERTY_ERROR;
946 case M_PROPERTY_STEP_UP:
947 case M_PROPERTY_STEP_DOWN:
948 vo_osd_changed(OSDTYPE_SUBTITLE);
949 default:
950 return m_property_int_range(prop, action, arg, &sub_pos);
954 /// Selected subtitles (RW)
955 static int mp_property_sub(m_option_t * prop, int action, void *arg,
956 MPContext * mpctx)
958 demux_stream_t *const d_sub = mpctx->d_sub;
959 const int global_sub_size = mpctx->global_sub_size;
960 int source = -1, reset_spu = 0;
961 char *sub_name;
963 if (global_sub_size <= 0)
964 return M_PROPERTY_UNAVAILABLE;
966 switch (action) {
967 case M_PROPERTY_GET:
968 if (!arg)
969 return M_PROPERTY_ERROR;
970 *(int *) arg = mpctx->global_sub_pos;
971 return M_PROPERTY_OK;
972 case M_PROPERTY_PRINT:
973 if (!arg)
974 return M_PROPERTY_ERROR;
975 *(char **) arg = malloc(64);
976 (*(char **) arg)[63] = 0;
977 sub_name = 0;
978 if (subdata)
979 sub_name = subdata->filename;
980 #ifdef USE_ASS
981 if (ass_track && ass_track->name)
982 sub_name = ass_track->name;
983 #endif
984 if (sub_name) {
985 char *tmp, *tmp2;
986 tmp = sub_name;
987 if ((tmp2 = strrchr(tmp, '/')))
988 tmp = tmp2 + 1;
990 snprintf(*(char **) arg, 63, "(%d) %s%s",
991 mpctx->set_of_sub_pos + 1,
992 strlen(tmp) < 20 ? "" : "...",
993 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
994 return M_PROPERTY_OK;
996 #ifdef USE_DVDNAV
997 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
998 if (vo_spudec && dvdsub_id >= 0) {
999 unsigned char lang[3];
1000 if (dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1001 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1002 return M_PROPERTY_OK;
1006 #endif
1008 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
1009 char lang[40] = MSGTR_Unknown;
1010 demux_mkv_get_sub_lang(mpctx->demuxer, dvdsub_id, lang, 9);
1011 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1012 return M_PROPERTY_OK;
1014 #ifdef HAVE_OGGVORBIS
1015 if (mpctx->demuxer->type == DEMUXER_TYPE_OGG && d_sub && dvdsub_id >= 0) {
1016 char *lang = demux_ogg_sub_lang(mpctx->demuxer, dvdsub_id);
1017 if (!lang)
1018 lang = MSGTR_Unknown;
1019 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1020 return M_PROPERTY_OK;
1022 #endif
1023 if (vo_vobsub && vobsub_id >= 0) {
1024 const char *language = MSGTR_Unknown;
1025 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1026 snprintf(*(char **) arg, 63, "(%d) %s",
1027 vobsub_id, language ? language : MSGTR_Unknown);
1028 return M_PROPERTY_OK;
1030 #ifdef USE_DVDREAD
1031 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1032 && dvdsub_id >= 0) {
1033 char lang[3];
1034 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1035 lang[0] = code >> 8;
1036 lang[1] = code;
1037 lang[2] = 0;
1038 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1039 return M_PROPERTY_OK;
1041 #endif
1042 if (dvdsub_id >= 0) {
1043 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1044 return M_PROPERTY_OK;
1046 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1047 return M_PROPERTY_OK;
1049 case M_PROPERTY_SET:
1050 if (!arg)
1051 return M_PROPERTY_ERROR;
1052 if (*(int *) arg < -1)
1053 *(int *) arg = -1;
1054 else if (*(int *) arg >= global_sub_size)
1055 *(int *) arg = global_sub_size - 1;
1056 mpctx->global_sub_pos = *(int *) arg;
1057 break;
1058 case M_PROPERTY_STEP_UP:
1059 mpctx->global_sub_pos += 2;
1060 mpctx->global_sub_pos =
1061 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1062 break;
1063 case M_PROPERTY_STEP_DOWN:
1064 mpctx->global_sub_pos += global_sub_size + 1;
1065 mpctx->global_sub_pos =
1066 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1067 break;
1068 default:
1069 return M_PROPERTY_NOT_IMPLEMENTED;
1072 if (mpctx->global_sub_pos >= 0)
1073 source = sub_source(mpctx);
1075 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1076 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1077 global_sub_size,
1078 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1079 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1080 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1081 mpctx->global_sub_pos, source);
1083 mpctx->set_of_sub_pos = -1;
1084 subdata = NULL;
1085 vo_sub_last = vo_sub = NULL;
1087 vobsub_id = -1;
1088 dvdsub_id = -1;
1089 if (d_sub) {
1090 if (d_sub->id > -2)
1091 reset_spu = 1;
1092 d_sub->id = -2;
1094 #ifdef USE_ASS
1095 ass_track = 0;
1096 #endif
1098 if (source == SUB_SOURCE_VOBSUB) {
1099 vobsub_id =
1100 mpctx->global_sub_pos -
1101 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB];
1102 } else if (source == SUB_SOURCE_SUBS) {
1103 mpctx->set_of_sub_pos =
1104 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1105 #ifdef USE_ASS
1106 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1107 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1108 else
1109 #endif
1111 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1112 vo_osd_changed(OSDTYPE_SUBTITLE);
1114 } else if (source == SUB_SOURCE_DEMUX) {
1115 dvdsub_id =
1116 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1117 if (d_sub) {
1118 #ifdef USE_DVDREAD
1119 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD) {
1120 d_sub->id = dvdsub_id;
1122 #endif
1124 #ifdef USE_DVDNAV
1125 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVDNAV) {
1126 d_sub->id = dvdsub_id;
1128 #endif
1129 if (mpctx->stream->type != STREAMTYPE_DVD
1130 && mpctx->stream->type != STREAMTYPE_DVDNAV) {
1131 int i = 0;
1132 for (d_sub->id = 0; d_sub->id < MAX_S_STREAMS; d_sub->id++) {
1133 if (mpctx->demuxer->s_streams[d_sub->id]) {
1134 if (i == dvdsub_id)
1135 break;
1136 i++;
1139 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1141 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA)
1142 d_sub->id = demux_mkv_change_subs(mpctx->demuxer, dvdsub_id);
1143 if (d_sub->sh && d_sub->id >= 0) {
1144 sh_sub_t *sh = d_sub->sh;
1145 if (sh->type == 'v')
1146 init_vo_spudec();
1147 #ifdef USE_ASS
1148 else if (ass_enabled && sh->type == 'a')
1149 ass_track = sh->ass_track;
1150 #endif
1154 #ifdef USE_DVDREAD
1155 if (vo_spudec
1156 && (mpctx->stream->type == STREAMTYPE_DVD
1157 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1158 && dvdsub_id < 0 && reset_spu) {
1159 dvdsub_id = -2;
1160 d_sub->id = dvdsub_id;
1162 #endif
1163 update_subtitles(mpctx->sh_video, d_sub, 1);
1165 return M_PROPERTY_OK;
1168 /// Subtitle delay (RW)
1169 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1170 MPContext * mpctx)
1172 if (!mpctx->sh_video)
1173 return M_PROPERTY_UNAVAILABLE;
1174 return m_property_delay(prop, action, arg, &sub_delay);
1177 /// Alignment of text subtitles (RW)
1178 static int mp_property_sub_alignment(m_option_t * prop, int action,
1179 void *arg, MPContext * mpctx)
1181 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1183 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1184 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1185 return M_PROPERTY_UNAVAILABLE;
1187 switch (action) {
1188 case M_PROPERTY_PRINT:
1189 if (!arg)
1190 return M_PROPERTY_ERROR;
1191 M_PROPERTY_CLAMP(prop, sub_alignment);
1192 *(char **) arg = strdup(name[sub_alignment]);
1193 return M_PROPERTY_OK;
1194 case M_PROPERTY_SET:
1195 if (!arg)
1196 return M_PROPERTY_ERROR;
1197 case M_PROPERTY_STEP_UP:
1198 case M_PROPERTY_STEP_DOWN:
1199 vo_osd_changed(OSDTYPE_SUBTITLE);
1200 default:
1201 return m_property_choice(prop, action, arg, &sub_alignment);
1205 /// Subtitle visibility (RW)
1206 static int mp_property_sub_visibility(m_option_t * prop, int action,
1207 void *arg, MPContext * mpctx)
1209 if (!mpctx->sh_video)
1210 return M_PROPERTY_UNAVAILABLE;
1212 switch (action) {
1213 case M_PROPERTY_SET:
1214 if (!arg)
1215 return M_PROPERTY_ERROR;
1216 case M_PROPERTY_STEP_UP:
1217 case M_PROPERTY_STEP_DOWN:
1218 vo_osd_changed(OSDTYPE_SUBTITLE);
1219 if (vo_spudec)
1220 vo_osd_changed(OSDTYPE_SPU);
1221 default:
1222 return m_property_flag(prop, action, arg, &sub_visibility);
1226 /// Show only forced subtitles (RW)
1227 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1228 void *arg, MPContext * mpctx)
1230 if (!vo_spudec)
1231 return M_PROPERTY_UNAVAILABLE;
1233 switch (action) {
1234 case M_PROPERTY_SET:
1235 if (!arg)
1236 return M_PROPERTY_ERROR;
1237 case M_PROPERTY_STEP_UP:
1238 case M_PROPERTY_STEP_DOWN:
1239 m_property_flag(prop, action, arg, &forced_subs_only);
1240 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1241 return M_PROPERTY_OK;
1242 default:
1243 return m_property_flag(prop, action, arg, &forced_subs_only);
1248 ///@}
1250 /// \defgroup TVProperties TV properties
1251 /// \ingroup Properties
1252 ///@{
1254 #ifdef USE_TV
1256 /// TV color settings (RW)
1257 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1258 MPContext * mpctx)
1260 int r, val;
1261 tvi_handle_t *tvh = mpctx->demuxer->priv;
1262 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1263 return M_PROPERTY_UNAVAILABLE;
1265 switch (action) {
1266 case M_PROPERTY_SET:
1267 if (!arg)
1268 return M_PROPERTY_ERROR;
1269 M_PROPERTY_CLAMP(prop, *(int *) arg);
1270 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1271 case M_PROPERTY_GET:
1272 return tv_get_color_options(tvh, (int) prop->priv, arg);
1273 case M_PROPERTY_STEP_UP:
1274 case M_PROPERTY_STEP_DOWN:
1275 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1276 if (!r)
1277 return M_PROPERTY_ERROR;
1278 val += (arg ? *(int *) arg : 1) *
1279 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1280 M_PROPERTY_CLAMP(prop, val);
1281 return tv_set_color_options(tvh, (int) prop->priv, val);
1283 return M_PROPERTY_ERROR;
1285 return M_PROPERTY_NOT_IMPLEMENTED;
1288 #endif
1290 ///@}
1292 /// All properties available in MPlayer.
1293 /** \ingroup Properties
1295 static m_option_t mp_properties[] = {
1296 // General
1297 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1298 M_OPT_RANGE, 0, 3, NULL },
1299 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1300 M_OPT_RANGE, 0.01, 100.0, NULL },
1301 { "filename", mp_property_filename, CONF_TYPE_STRING,
1302 0, 0, 0, NULL },
1303 { "path", mp_property_path, CONF_TYPE_STRING,
1304 0, 0, 0, NULL },
1305 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1306 0, 0, 0, NULL },
1307 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1308 M_OPT_MIN, 0, 0, NULL },
1309 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1310 M_OPT_MIN, 0, 0, NULL },
1311 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1312 M_OPT_MIN, 0, 0, NULL },
1313 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1314 M_OPT_MIN, 0, 0, NULL },
1315 { "length", mp_property_length, CONF_TYPE_DOUBLE,
1316 0, 0, 0, NULL },
1318 // Audio
1319 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
1320 M_OPT_RANGE, 0, 100, NULL },
1321 { "mute", mp_property_mute, CONF_TYPE_FLAG,
1322 M_OPT_RANGE, 0, 1, NULL },
1323 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
1324 M_OPT_RANGE, -100, 100, NULL },
1325 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
1326 0, 0, 0, NULL },
1327 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
1328 0, 0, 0, NULL },
1329 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
1330 0, 0, 0, NULL },
1331 { "channels", mp_property_channels, CONF_TYPE_INT,
1332 0, 0, 0, NULL },
1333 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
1334 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
1336 // Video
1337 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
1338 M_OPT_RANGE, 0, 1, NULL },
1339 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
1340 M_OPT_RANGE, 0, 1, NULL },
1341 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
1342 M_OPT_RANGE, 0, 1, NULL },
1343 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
1344 M_OPT_RANGE, 0, 1, NULL },
1345 { "border", mp_property_border, CONF_TYPE_FLAG,
1346 M_OPT_RANGE, 0, 1, NULL },
1347 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
1348 M_OPT_RANGE, 0, 2, NULL },
1349 { "gamma", mp_property_gamma, CONF_TYPE_INT,
1350 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
1351 { "brightness", mp_property_gamma, CONF_TYPE_INT,
1352 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
1353 { "contrast", mp_property_gamma, CONF_TYPE_INT,
1354 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
1355 { "saturation", mp_property_gamma, CONF_TYPE_INT,
1356 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
1357 { "hue", mp_property_gamma, CONF_TYPE_INT,
1358 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
1359 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
1360 M_OPT_RANGE, 0, 1, NULL },
1361 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
1362 M_OPT_RANGE, 0, 1, NULL },
1363 { "video_format", mp_property_video_format, CONF_TYPE_INT,
1364 0, 0, 0, NULL },
1365 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
1366 0, 0, 0, NULL },
1367 { "width", mp_property_width, CONF_TYPE_INT,
1368 0, 0, 0, NULL },
1369 { "height", mp_property_height, CONF_TYPE_INT,
1370 0, 0, 0, NULL },
1371 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
1372 0, 0, 0, NULL },
1373 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
1374 0, 0, 0, NULL },
1375 { "switch_video", mp_property_video, CONF_TYPE_INT,
1376 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
1377 { "switch_program", mp_property_program, CONF_TYPE_INT,
1378 CONF_RANGE, -1, 65535, NULL },
1380 // Subs
1381 { "sub", mp_property_sub, CONF_TYPE_INT,
1382 M_OPT_MIN, -1, 0, NULL },
1383 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
1384 0, 0, 0, NULL },
1385 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
1386 M_OPT_RANGE, 0, 100, NULL },
1387 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
1388 M_OPT_RANGE, 0, 2, NULL },
1389 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
1390 M_OPT_RANGE, 0, 1, NULL },
1391 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
1392 M_OPT_RANGE, 0, 1, NULL },
1394 #ifdef USE_TV
1395 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
1396 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
1397 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
1398 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
1399 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
1400 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
1401 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
1402 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
1403 #endif
1405 { NULL, NULL, NULL, 0, 0, 0, NULL }
1409 m_option_t *mp_property_find(const char *name)
1411 return m_option_list_find(mp_properties, name);
1414 int mp_property_do(const char *name, int action, void *val, void *ctx)
1416 m_option_t *p = mp_property_find(name);
1417 if (!p)
1418 return M_PROPERTY_UNAVAILABLE;
1419 return m_property_do(p, action, val, ctx);
1422 char *property_expand_string(MPContext * mpctx, char *str)
1424 return m_properties_expand_string(mp_properties, str, mpctx);
1427 void property_print_help(void)
1429 m_properties_print_help_list(mp_properties);
1433 ///@}
1434 // Properties group
1438 * \defgroup Command2Property Command to property bridge
1440 * It is used to handle most commands that just set a property
1441 * and optionally display something on the OSD.
1442 * Two kinds of commands are handled: adjust or toggle.
1444 * Adjust commands take 1 or 2 parameters: <value> <abs>
1445 * If <abs> is non-zero the property is set to the given value
1446 * otherwise it is adjusted.
1448 * Toggle commands take 0 or 1 parameters. With no parameter
1449 * or a value less than the property minimum it just steps the
1450 * property to its next value. Otherwise it sets it to the given
1451 * value.
1456 /// List of the commands that can be handled by setting a property.
1457 static struct {
1458 /// property name
1459 const char *name;
1460 /// cmd id
1461 int cmd;
1462 /// set/adjust or toggle command
1463 int toggle;
1464 /// progressbar type
1465 int osd_progbar;
1466 /// osd msg id if it must be shared
1467 int osd_id;
1468 /// osd msg template
1469 const char *osd_msg;
1470 } set_prop_cmd[] = {
1471 // audio
1472 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
1473 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
1474 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
1475 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
1476 // video
1477 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
1478 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
1479 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
1480 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
1481 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
1482 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
1483 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
1484 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
1485 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
1486 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
1487 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
1488 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
1489 // subs
1490 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
1491 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
1492 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
1493 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
1494 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
1495 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
1496 #ifdef USE_TV
1497 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
1498 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
1499 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
1500 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
1501 #endif
1502 { NULL, 0, 0, 0, -1, NULL }
1506 /// Handle commands that set a property.
1507 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
1509 int i, r;
1510 m_option_t *prop;
1512 // look for the command
1513 for (i = 0; set_prop_cmd[i].name; i++)
1514 if (set_prop_cmd[i].cmd == cmd->id)
1515 break;
1516 if (!set_prop_cmd[i].name)
1517 return 0;
1519 // get the property
1520 prop = mp_property_find(set_prop_cmd[i].name);
1521 if (!prop)
1522 return 0;
1524 // toggle command
1525 if (set_prop_cmd[i].toggle) {
1526 // set to value
1527 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
1528 r = m_property_do(prop, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
1529 else
1530 r = m_property_do(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1531 } else if (cmd->args[1].v.i) //set
1532 r = m_property_do(prop, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
1533 else // adjust
1534 r = m_property_do(prop, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
1536 if (r <= 0)
1537 return 1;
1539 if (set_prop_cmd[i].osd_progbar) {
1540 if (prop->type == CONF_TYPE_INT) {
1541 if (m_property_do(prop, M_PROPERTY_GET, &r, mpctx) > 0)
1542 set_osd_bar(set_prop_cmd[i].osd_progbar,
1543 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
1544 } else if (prop->type == CONF_TYPE_FLOAT) {
1545 float f;
1546 if (m_property_do(prop, M_PROPERTY_GET, &f, mpctx) > 0)
1547 set_osd_bar(set_prop_cmd[i].osd_progbar,
1548 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
1549 } else
1550 mp_msg(MSGT_CPLAYER, MSGL_ERR,
1551 "Property use an unsupported type.\n");
1552 return 1;
1555 if (set_prop_cmd[i].osd_msg) {
1556 char *val = m_property_print(prop, mpctx);
1557 if (val) {
1558 set_osd_msg(set_prop_cmd[i].osd_id >=
1559 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
1560 1, osd_duration, set_prop_cmd[i].osd_msg, val);
1561 free(val);
1564 return 1;
1568 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
1570 sh_audio_t * const sh_audio = mpctx->sh_audio;
1571 sh_video_t * const sh_video = mpctx->sh_video;
1572 int brk_cmd = 0;
1573 if (!set_property_command(mpctx, cmd))
1574 switch (cmd->id) {
1575 case MP_CMD_SEEK:{
1576 float v;
1577 int abs;
1578 if (sh_video)
1579 mpctx->osd_show_percentage = sh_video->fps;
1580 v = cmd->args[0].v.f;
1581 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
1582 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
1583 abs_seek_pos = 1;
1584 if (sh_video)
1585 mpctx->osd_function =
1586 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
1587 rel_seek_secs = v;
1588 } else if (abs) { /* Absolute seek by percentage */
1589 abs_seek_pos = 3;
1590 if (sh_video)
1591 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
1592 rel_seek_secs = v / 100.0;
1593 } else {
1594 rel_seek_secs += v;
1595 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
1597 brk_cmd = 1;
1599 break;
1601 case MP_CMD_SET_PROPERTY:{
1602 m_option_t *prop = mp_property_find(cmd->args[0].v.s);
1603 if (!prop)
1604 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1605 "Unknown property: '%s'\n", cmd->args[0].v.s);
1606 else if (m_property_parse(prop, cmd->args[1].v.s, mpctx) <= 0)
1607 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1608 "Failed to set property '%s' to '%s'.\n",
1609 cmd->args[0].v.s, cmd->args[1].v.s);
1611 break;
1613 case MP_CMD_STEP_PROPERTY:{
1614 m_option_t *prop = mp_property_find(cmd->args[0].v.s);
1615 float arg = cmd->args[1].v.f;
1616 if (!prop)
1617 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1618 "Unknown property: '%s'\n", cmd->args[0].v.s);
1619 else if (m_property_do
1620 (prop, M_PROPERTY_STEP_UP,
1621 arg ? &arg : NULL, mpctx) <= 0)
1622 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1623 "Failed to increment property '%s' by %f.\n",
1624 cmd->args[0].v.s, arg);
1626 break;
1628 case MP_CMD_GET_PROPERTY:{
1629 m_option_t *prop;
1630 void *val;
1631 char *tmp;
1632 prop = mp_property_find(cmd->args[0].v.s);
1633 if (!prop) {
1634 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1635 "Unknown property: '%s'\n", cmd->args[0].v.s);
1636 break;
1638 /* Use m_option_print directly to get easily parseable values. */
1639 val = calloc(1, prop->type->size);
1640 if (m_property_do(prop, M_PROPERTY_GET, val, mpctx) <= 0) {
1641 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1642 "Failed to get value of property '%s'.\n",
1643 cmd->args[0].v.s);
1644 break;
1646 tmp = m_option_print(prop, val);
1647 if (!tmp || tmp == (char *) -1) {
1648 mp_msg(MSGT_CPLAYER, MSGL_WARN,
1649 "Failed to print value of property '%s'.\n",
1650 cmd->args[0].v.s);
1651 break;
1653 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
1654 cmd->args[0].v.s, tmp);
1655 free(tmp);
1657 break;
1659 case MP_CMD_EDL_MARK:
1660 if (edl_fd) {
1661 float v = sh_video ? sh_video->pts :
1662 playing_audio_pts(sh_audio, mpctx->d_audio,
1663 mpctx->audio_out);
1665 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
1666 mpctx->begin_skip = v;
1667 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
1668 } else {
1669 if (mpctx->begin_skip > v)
1670 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
1671 else {
1672 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
1673 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
1675 mpctx->begin_skip = MP_NOPTS_VALUE;
1678 break;
1680 case MP_CMD_SWITCH_RATIO:
1681 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
1682 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
1683 else
1684 movie_aspect = cmd->args[0].v.f;
1685 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
1686 break;
1688 case MP_CMD_SPEED_INCR:{
1689 float v = cmd->args[0].v.f;
1690 playback_speed += v;
1691 build_afilter_chain(sh_audio, &ao_data);
1692 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
1693 playback_speed);
1694 } break;
1696 case MP_CMD_SPEED_MULT:{
1697 float v = cmd->args[0].v.f;
1698 playback_speed *= v;
1699 build_afilter_chain(sh_audio, &ao_data);
1700 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
1701 playback_speed);
1702 } break;
1704 case MP_CMD_SPEED_SET:{
1705 float v = cmd->args[0].v.f;
1706 playback_speed = v;
1707 build_afilter_chain(sh_audio, &ao_data);
1708 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
1709 playback_speed);
1710 } break;
1712 case MP_CMD_FRAME_STEP:
1713 case MP_CMD_PAUSE:
1714 cmd->pausing = 1;
1715 brk_cmd = 1;
1716 break;
1718 case MP_CMD_FILE_FILTER:
1719 file_filter = cmd->args[0].v.i;
1720 break;
1722 case MP_CMD_QUIT:
1723 exit_player_with_rc(MSGTR_Exit_quit,
1724 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
1726 case MP_CMD_PLAY_TREE_STEP:{
1727 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
1728 int force = cmd->args[1].v.i;
1730 #ifdef HAVE_NEW_GUI
1731 if (use_gui) {
1732 int i = 0;
1733 if (n > 0)
1734 for (i = 0; i < n; i++)
1735 mplNext();
1736 else
1737 for (i = 0; i < -1 * n; i++)
1738 mplPrev();
1739 } else
1740 #endif
1742 if (!force && mpctx->playtree_iter) {
1743 play_tree_iter_t *i =
1744 play_tree_iter_new_copy(mpctx->playtree_iter);
1745 if (play_tree_iter_step(i, n, 0) ==
1746 PLAY_TREE_ITER_ENTRY)
1747 mpctx->eof =
1748 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
1749 play_tree_iter_free(i);
1750 } else
1751 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
1752 if (mpctx->eof)
1753 mpctx->play_tree_step = n;
1754 brk_cmd = 1;
1757 break;
1759 case MP_CMD_PLAY_TREE_UP_STEP:{
1760 int n = cmd->args[0].v.i > 0 ? 1 : -1;
1761 int force = cmd->args[1].v.i;
1763 if (!force && mpctx->playtree_iter) {
1764 play_tree_iter_t *i =
1765 play_tree_iter_new_copy(mpctx->playtree_iter);
1766 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
1767 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
1768 play_tree_iter_free(i);
1769 } else
1770 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
1771 brk_cmd = 1;
1773 break;
1775 case MP_CMD_PLAY_ALT_SRC_STEP:
1776 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
1777 int v = cmd->args[0].v.i;
1778 if (v > 0
1779 && mpctx->playtree_iter->file <
1780 mpctx->playtree_iter->num_files)
1781 mpctx->eof = PT_NEXT_SRC;
1782 else if (v < 0 && mpctx->playtree_iter->file > 1)
1783 mpctx->eof = PT_PREV_SRC;
1785 brk_cmd = 1;
1786 break;
1788 case MP_CMD_SUB_STEP:
1789 if (sh_video) {
1790 int movement = cmd->args[0].v.i;
1791 step_sub(subdata, sh_video->pts, movement);
1792 #ifdef USE_ASS
1793 if (ass_track)
1794 sub_delay +=
1795 ass_step_sub(ass_track,
1796 (sh_video->pts +
1797 sub_delay) * 1000 + .5, movement) / 1000.;
1798 #endif
1799 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
1800 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
1802 break;
1804 case MP_CMD_SUB_LOG:
1805 log_sub();
1806 break;
1808 case MP_CMD_OSD:{
1809 int v = cmd->args[0].v.i;
1810 int max = (term_osd
1811 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
1812 if (osd_level > max)
1813 osd_level = max;
1814 if (v < 0)
1815 osd_level = (osd_level + 1) % (max + 1);
1816 else
1817 osd_level = v > max ? max : v;
1818 /* Show OSD state when disabled, but not when an explicit
1819 argument is given to the OSD command, i.e. in slave mode. */
1820 if (v == -1 && osd_level <= 1)
1821 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
1822 MSGTR_OSDosd,
1823 osd_level ? MSGTR_OSDenabled :
1824 MSGTR_OSDdisabled);
1825 else
1826 rm_osd_msg(OSD_MSG_OSD_STATUS);
1828 break;
1830 case MP_CMD_OSD_SHOW_TEXT:
1831 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
1832 (cmd->args[1].v.i <
1833 0 ? osd_duration : cmd->args[1].v.i),
1834 "%-.63s", cmd->args[0].v.s);
1835 break;
1837 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
1838 char *txt = m_properties_expand_string(mp_properties,
1839 cmd->args[0].v.s,
1840 mpctx);
1841 /* if no argument supplied take default osd_duration, else <arg> ms. */
1842 if (txt) {
1843 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
1844 (cmd->args[1].v.i <
1845 0 ? osd_duration : cmd->args[1].v.i),
1846 "%-.63s", txt);
1847 free(txt);
1850 break;
1852 case MP_CMD_LOADFILE:{
1853 play_tree_t *e = play_tree_new();
1854 play_tree_add_file(e, cmd->args[0].v.s);
1856 if (cmd->args[1].v.i) // append
1857 play_tree_append_entry(mpctx->playtree, e);
1858 else {
1859 // Go back to the starting point.
1860 while (play_tree_iter_up_step
1861 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
1862 /* NOP */ ;
1863 play_tree_free_list(mpctx->playtree->child, 1);
1864 play_tree_set_child(mpctx->playtree, e);
1865 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
1866 mpctx->eof = PT_NEXT_SRC;
1868 brk_cmd = 1;
1870 break;
1872 case MP_CMD_LOADLIST:{
1873 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
1874 if (!e)
1875 mp_msg(MSGT_CPLAYER, MSGL_ERR,
1876 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
1877 else {
1878 if (cmd->args[1].v.i) // append
1879 play_tree_append_entry(mpctx->playtree, e);
1880 else {
1881 // Go back to the starting point.
1882 while (play_tree_iter_up_step
1883 (mpctx->playtree_iter, 0, 1)
1884 != PLAY_TREE_ITER_END)
1885 /* NOP */ ;
1886 play_tree_free_list(mpctx->playtree->child, 1);
1887 play_tree_set_child(mpctx->playtree, e);
1888 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
1889 mpctx->eof = PT_NEXT_SRC;
1892 brk_cmd = 1;
1894 break;
1896 #ifdef USE_RADIO
1897 case MP_CMD_RADIO_STEP_CHANNEL:
1898 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
1899 int v = cmd->args[0].v.i;
1900 if (v > 0)
1901 radio_step_channel(mpctx->demuxer->stream,
1902 RADIO_CHANNEL_HIGHER);
1903 else
1904 radio_step_channel(mpctx->demuxer->stream,
1905 RADIO_CHANNEL_LOWER);
1906 if (radio_get_channel_name(mpctx->demuxer->stream)) {
1907 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
1908 MSGTR_OSDChannel,
1909 radio_get_channel_name(mpctx->demuxer->stream));
1912 break;
1914 case MP_CMD_RADIO_SET_CHANNEL:
1915 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
1916 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
1917 if (radio_get_channel_name(mpctx->demuxer->stream)) {
1918 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
1919 MSGTR_OSDChannel,
1920 radio_get_channel_name(mpctx->demuxer->stream));
1923 break;
1925 case MP_CMD_RADIO_SET_FREQ:
1926 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
1927 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
1928 break;
1930 case MP_CMD_RADIO_STEP_FREQ:
1931 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
1932 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
1933 break;
1934 #endif
1936 #ifdef USE_TV
1937 case MP_CMD_TV_SET_FREQ:
1938 if (mpctx->file_format == DEMUXER_TYPE_TV)
1939 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
1940 cmd->args[0].v.f * 16.0);
1941 break;
1943 case MP_CMD_TV_SET_NORM:
1944 if (mpctx->file_format == DEMUXER_TYPE_TV)
1945 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
1946 cmd->args[0].v.s);
1947 break;
1949 case MP_CMD_TV_STEP_CHANNEL:{
1950 if (mpctx->file_format == DEMUXER_TYPE_TV) {
1951 int v = cmd->args[0].v.i;
1952 if (v > 0) {
1953 tv_step_channel((tvi_handle_t *) (mpctx->
1954 demuxer->priv),
1955 TV_CHANNEL_HIGHER);
1956 } else {
1957 tv_step_channel((tvi_handle_t *) (mpctx->
1958 demuxer->priv),
1959 TV_CHANNEL_LOWER);
1961 if (tv_channel_list) {
1962 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
1963 MSGTR_OSDChannel, tv_channel_current->name);
1964 //vo_osd_changed(OSDTYPE_SUBTITLE);
1968 #ifdef HAS_DVBIN_SUPPORT
1969 if ((mpctx->stream->type == STREAMTYPE_DVB)
1970 && mpctx->stream->priv) {
1971 dvb_priv_t *priv = (dvb_priv_t *) mpctx->stream->priv;
1972 if (priv->is_on) {
1973 int dir;
1974 int v = cmd->args[0].v.i;
1976 mpctx->last_dvb_step = v;
1977 if (v > 0)
1978 dir = DVB_CHANNEL_HIGHER;
1979 else
1980 dir = DVB_CHANNEL_LOWER;
1983 if (dvb_step_channel(priv, dir))
1984 mpctx->eof = mpctx->dvbin_reopen = 1;
1987 #endif /* HAS_DVBIN_SUPPORT */
1988 break;
1990 case MP_CMD_TV_SET_CHANNEL:
1991 if (mpctx->file_format == DEMUXER_TYPE_TV) {
1992 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
1993 cmd->args[0].v.s);
1994 if (tv_channel_list) {
1995 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
1996 MSGTR_OSDChannel, tv_channel_current->name);
1997 //vo_osd_changed(OSDTYPE_SUBTITLE);
2000 break;
2002 #ifdef HAS_DVBIN_SUPPORT
2003 case MP_CMD_DVB_SET_CHANNEL:
2004 if ((mpctx->stream->type == STREAMTYPE_DVB)
2005 && mpctx->stream->priv) {
2006 dvb_priv_t *priv = (dvb_priv_t *) mpctx->stream->priv;
2007 if (priv->is_on) {
2008 if (priv->list->current <= cmd->args[0].v.i)
2009 mpctx->last_dvb_step = 1;
2010 else
2011 mpctx->last_dvb_step = -1;
2013 if (dvb_set_channel
2014 (priv, cmd->args[1].v.i, cmd->args[0].v.i))
2015 mpctx->eof = mpctx->dvbin_reopen = 1;
2018 break;
2019 #endif /* HAS_DVBIN_SUPPORT */
2021 case MP_CMD_TV_LAST_CHANNEL:
2022 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2023 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2024 if (tv_channel_list) {
2025 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2026 MSGTR_OSDChannel, tv_channel_current->name);
2027 //vo_osd_changed(OSDTYPE_SUBTITLE);
2030 break;
2032 case MP_CMD_TV_STEP_NORM:
2033 if (mpctx->file_format == DEMUXER_TYPE_TV)
2034 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2035 break;
2037 case MP_CMD_TV_STEP_CHANNEL_LIST:
2038 if (mpctx->file_format == DEMUXER_TYPE_TV)
2039 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2040 break;
2041 #endif /* USE_TV */
2043 case MP_CMD_SUB_LOAD:
2044 if (sh_video) {
2045 int n = mpctx->set_of_sub_size;
2046 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2047 if (n != mpctx->set_of_sub_size) {
2048 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2049 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2050 mpctx->global_sub_size;
2051 ++mpctx->global_sub_size;
2054 break;
2056 case MP_CMD_SUB_REMOVE:
2057 if (sh_video) {
2058 int v = cmd->args[0].v.i;
2059 sub_data *subd;
2060 if (v < 0) {
2061 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2062 subd = mpctx->set_of_subtitles[v];
2063 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2064 MSGTR_RemovedSubtitleFile, v + 1,
2065 filename_recode(subd->filename));
2066 sub_free(subd);
2067 mpctx->set_of_subtitles[v] = NULL;
2069 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2070 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2071 mpctx->set_of_sub_size = 0;
2072 if (mpctx->set_of_sub_pos >= 0) {
2073 mpctx->global_sub_pos = -2;
2074 vo_sub_last = vo_sub = NULL;
2075 vo_osd_changed(OSDTYPE_SUBTITLE);
2076 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
2077 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2079 } else if (v < mpctx->set_of_sub_size) {
2080 subd = mpctx->set_of_subtitles[v];
2081 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2082 MSGTR_RemovedSubtitleFile, v + 1,
2083 filename_recode(subd->filename));
2084 sub_free(subd);
2085 if (mpctx->set_of_sub_pos == v) {
2086 mpctx->global_sub_pos = -2;
2087 vo_sub_last = vo_sub = NULL;
2088 vo_osd_changed(OSDTYPE_SUBTITLE);
2089 vo_update_osd(sh_video->disp_w, sh_video->disp_h);
2090 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2091 } else if (mpctx->set_of_sub_pos > v) {
2092 --mpctx->set_of_sub_pos;
2093 --mpctx->global_sub_pos;
2095 while (++v < mpctx->set_of_sub_size)
2096 mpctx->set_of_subtitles[v - 1] =
2097 mpctx->set_of_subtitles[v];
2098 --mpctx->set_of_sub_size;
2099 --mpctx->global_sub_size;
2100 if (mpctx->set_of_sub_size <= 0)
2101 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2102 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2105 break;
2107 case MP_CMD_GET_SUB_VISIBILITY:
2108 if (sh_video) {
2109 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2110 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2112 break;
2114 case MP_CMD_SCREENSHOT:
2115 if (vo_config_count) {
2116 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2117 if (CONTROL_OK !=
2118 ((vf_instance_t *) sh_video->vfilter)->
2119 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2120 &cmd->args[0].v.i))
2121 mpctx->video_out->control(VOCTRL_SCREENSHOT, NULL);
2123 break;
2125 case MP_CMD_VF_CHANGE_RECTANGLE:
2126 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2127 break;
2129 case MP_CMD_GET_TIME_LENGTH:{
2130 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2131 demuxer_get_time_length(mpctx->demuxer));
2133 break;
2135 case MP_CMD_GET_FILENAME:{
2136 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2137 get_metadata(META_NAME));
2139 break;
2141 case MP_CMD_GET_VIDEO_CODEC:{
2142 char *inf = get_metadata(META_VIDEO_CODEC);
2143 if (!inf)
2144 inf = strdup("");
2145 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2146 free(inf);
2148 break;
2150 case MP_CMD_GET_VIDEO_BITRATE:{
2151 char *inf = get_metadata(META_VIDEO_BITRATE);
2152 if (!inf)
2153 inf = strdup("");
2154 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2155 free(inf);
2157 break;
2159 case MP_CMD_GET_VIDEO_RESOLUTION:{
2160 char *inf = get_metadata(META_VIDEO_RESOLUTION);
2161 if (!inf)
2162 inf = strdup("");
2163 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2164 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
2165 free(inf);
2167 break;
2169 case MP_CMD_GET_AUDIO_CODEC:{
2170 char *inf = get_metadata(META_AUDIO_CODEC);
2171 if (!inf)
2172 inf = strdup("");
2173 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
2174 free(inf);
2176 break;
2178 case MP_CMD_GET_AUDIO_BITRATE:{
2179 char *inf = get_metadata(META_AUDIO_BITRATE);
2180 if (!inf)
2181 inf = strdup("");
2182 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
2183 free(inf);
2185 break;
2187 case MP_CMD_GET_AUDIO_SAMPLES:{
2188 char *inf = get_metadata(META_AUDIO_SAMPLES);
2189 if (!inf)
2190 inf = strdup("");
2191 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
2192 free(inf);
2194 break;
2196 case MP_CMD_GET_META_TITLE:{
2197 char *inf = get_metadata(META_INFO_TITLE);
2198 if (!inf)
2199 inf = strdup("");
2200 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
2201 free(inf);
2203 break;
2205 case MP_CMD_GET_META_ARTIST:{
2206 char *inf = get_metadata(META_INFO_ARTIST);
2207 if (!inf)
2208 inf = strdup("");
2209 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
2210 free(inf);
2212 break;
2214 case MP_CMD_GET_META_ALBUM:{
2215 char *inf = get_metadata(META_INFO_ALBUM);
2216 if (!inf)
2217 inf = strdup("");
2218 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
2219 free(inf);
2221 break;
2223 case MP_CMD_GET_META_YEAR:{
2224 char *inf = get_metadata(META_INFO_YEAR);
2225 if (!inf)
2226 inf = strdup("");
2227 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
2228 free(inf);
2230 break;
2232 case MP_CMD_GET_META_COMMENT:{
2233 char *inf = get_metadata(META_INFO_COMMENT);
2234 if (!inf)
2235 inf = strdup("");
2236 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
2237 free(inf);
2239 break;
2241 case MP_CMD_GET_META_TRACK:{
2242 char *inf = get_metadata(META_INFO_TRACK);
2243 if (!inf)
2244 inf = strdup("");
2245 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
2246 free(inf);
2248 break;
2250 case MP_CMD_GET_META_GENRE:{
2251 char *inf = get_metadata(META_INFO_GENRE);
2252 if (!inf)
2253 inf = strdup("");
2254 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
2255 free(inf);
2257 break;
2259 case MP_CMD_GET_VO_FULLSCREEN:
2260 if (mpctx->video_out && vo_config_count)
2261 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
2262 break;
2264 case MP_CMD_GET_PERCENT_POS:
2265 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
2266 demuxer_get_percent_pos(mpctx->demuxer));
2267 break;
2269 case MP_CMD_GET_TIME_POS:{
2270 float pos = 0;
2271 if (sh_video)
2272 pos = sh_video->pts;
2273 else if (sh_audio && mpctx->audio_out)
2274 pos =
2275 playing_audio_pts(sh_audio, mpctx->d_audio,
2276 mpctx->audio_out);
2277 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
2279 break;
2281 case MP_CMD_RUN:
2282 #ifndef __MINGW32__
2283 if (!fork()) {
2284 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
2285 exit(0);
2287 #endif
2288 break;
2290 case MP_CMD_KEYDOWN_EVENTS:
2291 mplayer_put_key(cmd->args[0].v.i);
2292 break;
2294 case MP_CMD_SEEK_CHAPTER:{
2295 int seek = cmd->args[0].v.i;
2296 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2297 int chap;
2298 float next_pts = 0;
2299 int num_chapters;
2300 char *chapter_name;
2302 rel_seek_secs = 0;
2303 abs_seek_pos = 0;
2304 chap =
2305 demuxer_seek_chapter(mpctx->demuxer, seek, abs,
2306 &next_pts, &num_chapters,
2307 &chapter_name);
2308 if (chap != -1) {
2309 if (next_pts > -1.0) {
2310 abs_seek_pos = 1;
2311 rel_seek_secs = next_pts;
2313 if (chapter_name) {
2314 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2315 MSGTR_OSDChapter, chap + 1, chapter_name);
2316 free(chapter_name);
2318 } else {
2319 if (seek > 0)
2320 rel_seek_secs = 1000000000.;
2321 else
2322 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2323 MSGTR_OSDChapter, 0, MSGTR_Unknown);
2325 break;
2327 break;
2329 case MP_CMD_SET_MOUSE_POS:{
2330 int button = -1, pointer_x, pointer_y;
2331 double dx, dy;
2332 pointer_x = cmd->args[0].v.i;
2333 pointer_y = cmd->args[1].v.i;
2334 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
2335 #ifdef USE_DVDNAV
2336 if (mpctx->stream->type == STREAMTYPE_DVDNAV
2337 && dx > 0.0 && dy > 0.0) {
2338 pointer_x = (int) (dx * (double) sh_video->disp_w);
2339 pointer_y = (int) (dy * (double) sh_video->disp_h);
2340 mp_dvdnav_update_mouse_pos(mpctx->stream,
2341 pointer_x, pointer_y, &button);
2342 if (button > 0)
2343 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2344 "Selected button number %d", button);
2346 #endif
2348 break;
2350 #ifdef USE_DVDNAV
2351 case MP_CMD_DVDNAV:{
2352 int button = -1;
2353 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
2354 break;
2356 if (mp_dvdnav_handle_input
2357 (mpctx->stream, cmd->args[0].v.i, &button)) {
2358 uninit_player(INITED_ALL - (INITED_STREAM | INITED_INPUT |
2359 (fixed_vo ? INITED_VO : 0)));
2360 brk_cmd = 2;
2361 } else if (button > 0)
2362 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
2363 "Selected button number %d", button);
2365 break;
2366 #endif
2368 default:
2369 #ifdef HAVE_NEW_GUI
2370 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
2371 guiGetEvent(guiIEvent, (char *) cmd->id);
2372 else
2373 #endif
2374 mp_msg(MSGT_CPLAYER, MSGL_V,
2375 "Received unknown cmd %s\n", cmd->name);
2378 switch (cmd->pausing) {
2379 case 1: // "pausing"
2380 mpctx->osd_function = OSD_PAUSE;
2381 break;
2382 case 3: // "pausing_toggle"
2383 mpctx->was_paused = !mpctx->was_paused;
2384 // fall through
2385 case 2: // "pausing_keep"
2386 if (mpctx->was_paused)
2387 mpctx->osd_function = OSD_PAUSE;
2389 return brk_cmd;