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"
13 #include "libvo/sub.h"
15 #include "m_property.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"
24 #include "libao2/audio_out.h"
27 #include "libmpdemux/matroska.h"
28 #include "libmpcodecs/dec_video.h"
33 #include "stream/tv.h"
36 #include "stream/stream_radio.h"
39 #include "stream/pvr.h"
41 #ifdef HAS_DVBIN_SUPPORT
42 #include "stream/dvbin.h"
45 #include "stream/stream_dvd.h"
48 #include "stream/stream_dvdnav.h"
51 #include "libass/ass.h"
52 #include "libass/ass_mp.h"
55 #include "gui/interface.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
) {
75 } //we are on one of the borders
76 if (iy
< 0 || iy
> vo_dheight
) {
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
,
91 static int sub_source_by_pos(MPContext
* mpctx
, int pos
)
96 for (i
= 0; i
< SUB_SOURCES
; i
++) {
97 int j
= mpctx
->global_sub_indices
[i
];
98 if ((j
>= 0) && (j
> top
) && (pos
>= j
)) {
106 static int sub_source(MPContext
* mpctx
)
108 return sub_source_by_pos(mpctx
, mpctx
->global_sub_pos
);
112 * \brief Log the currently displayed subtitle to a file
114 * Logs the current or last displayed subtitle together with filename
115 * and time information to ~/.mplayer/subtitle_log
117 * Intended purpose is to allow convenient marking of bogus subtitles
118 * which need to be fixed while watching the movie.
121 static void log_sub(void)
127 if (subdata
== NULL
|| vo_sub_last
== NULL
)
129 fname
= get_path("subtitle_log");
130 f
= fopen(fname
, "a");
133 fprintf(f
, "----------------------------------------------------------\n");
134 if (subdata
->sub_uses_time
) {
136 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
137 filename
, vo_sub_last
->start
/ 360000,
138 (vo_sub_last
->start
/ 6000) % 60,
139 (vo_sub_last
->start
/ 100) % 60, vo_sub_last
->start
% 100,
140 vo_sub_last
->end
/ 360000, (vo_sub_last
->end
/ 6000) % 60,
141 (vo_sub_last
->end
/ 100) % 60, vo_sub_last
->end
% 100);
143 fprintf(f
, "N: %s S: %ld E: %ld\n", filename
, vo_sub_last
->start
,
146 for (i
= 0; i
< vo_sub_last
->lines
; i
++) {
147 fprintf(f
, "%s\n", vo_sub_last
->text
[i
]);
153 /// \defgroup Properties
156 /// \defgroup GeneralProperties General properties
157 /// \ingroup Properties
161 static int mp_property_osdlevel(m_option_t
* prop
, int action
, void *arg
,
164 return m_property_choice(prop
, action
, arg
, &osd_level
);
168 static int mp_property_loop(m_option_t
* prop
, int action
, void *arg
,
172 case M_PROPERTY_PRINT
:
173 if (!arg
) return M_PROPERTY_ERROR
;
174 if (mpctx
->loop_times
< 0)
175 *(char**)arg
= strdup("off");
176 else if (mpctx
->loop_times
== 0)
177 *(char**)arg
= strdup("inf");
180 return M_PROPERTY_OK
;
182 return m_property_int_range(prop
, action
, arg
, &mpctx
->loop_times
);
185 /// Playback speed (RW)
186 static int mp_property_playback_speed(m_option_t
* prop
, int action
,
187 void *arg
, MPContext
* mpctx
)
192 return M_PROPERTY_ERROR
;
193 M_PROPERTY_CLAMP(prop
, *(float *) arg
);
194 playback_speed
= *(float *) arg
;
195 build_afilter_chain(mpctx
->sh_audio
, &ao_data
);
196 return M_PROPERTY_OK
;
197 case M_PROPERTY_STEP_UP
:
198 case M_PROPERTY_STEP_DOWN
:
199 playback_speed
+= (arg
? *(float *) arg
: 0.1) *
200 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
201 M_PROPERTY_CLAMP(prop
, playback_speed
);
202 build_afilter_chain(mpctx
->sh_audio
, &ao_data
);
203 return M_PROPERTY_OK
;
205 return m_property_float_range(prop
, action
, arg
, &playback_speed
);
208 /// filename with path (RO)
209 static int mp_property_path(m_option_t
* prop
, int action
, void *arg
,
212 return m_property_string_ro(prop
, action
, arg
, filename
);
215 /// filename without path (RO)
216 static int mp_property_filename(m_option_t
* prop
, int action
, void *arg
,
221 return M_PROPERTY_UNAVAILABLE
;
222 if (((f
= strrchr(filename
, '/')) || (f
= strrchr(filename
, '\\'))) && f
[1])
226 return m_property_string_ro(prop
, action
, arg
, f
);
229 /// Demuxer name (RO)
230 static int mp_property_demuxer(m_option_t
* prop
, int action
, void *arg
,
234 return M_PROPERTY_UNAVAILABLE
;
235 return m_property_string_ro(prop
, action
, arg
,
236 (char *) mpctx
->demuxer
->desc
->name
);
239 /// Position in the stream (RW)
240 static int mp_property_stream_pos(m_option_t
* prop
, int action
, void *arg
,
243 if (!mpctx
->demuxer
|| !mpctx
->demuxer
->stream
)
244 return M_PROPERTY_UNAVAILABLE
;
246 return M_PROPERTY_ERROR
;
249 *(off_t
*) arg
= stream_tell(mpctx
->demuxer
->stream
);
250 return M_PROPERTY_OK
;
252 M_PROPERTY_CLAMP(prop
, *(off_t
*) arg
);
253 stream_seek(mpctx
->demuxer
->stream
, *(off_t
*) arg
);
254 return M_PROPERTY_OK
;
256 return M_PROPERTY_NOT_IMPLEMENTED
;
259 /// Stream start offset (RO)
260 static int mp_property_stream_start(m_option_t
* prop
, int action
,
261 void *arg
, MPContext
* mpctx
)
263 if (!mpctx
->demuxer
|| !mpctx
->demuxer
->stream
)
264 return M_PROPERTY_UNAVAILABLE
;
267 *(off_t
*) arg
= mpctx
->demuxer
->stream
->start_pos
;
268 return M_PROPERTY_OK
;
270 return M_PROPERTY_NOT_IMPLEMENTED
;
273 /// Stream end offset (RO)
274 static int mp_property_stream_end(m_option_t
* prop
, int action
, void *arg
,
277 if (!mpctx
->demuxer
|| !mpctx
->demuxer
->stream
)
278 return M_PROPERTY_UNAVAILABLE
;
281 *(off_t
*) arg
= mpctx
->demuxer
->stream
->end_pos
;
282 return M_PROPERTY_OK
;
284 return M_PROPERTY_NOT_IMPLEMENTED
;
287 /// Stream length (RO)
288 static int mp_property_stream_length(m_option_t
* prop
, int action
,
289 void *arg
, MPContext
* mpctx
)
291 if (!mpctx
->demuxer
|| !mpctx
->demuxer
->stream
)
292 return M_PROPERTY_UNAVAILABLE
;
296 mpctx
->demuxer
->stream
->end_pos
- mpctx
->demuxer
->stream
->start_pos
;
297 return M_PROPERTY_OK
;
299 return M_PROPERTY_NOT_IMPLEMENTED
;
302 /// Media length in seconds (RO)
303 static int mp_property_length(m_option_t
* prop
, int action
, void *arg
,
308 if (!mpctx
->demuxer
||
309 !(int) (len
= demuxer_get_time_length(mpctx
->demuxer
)))
310 return M_PROPERTY_UNAVAILABLE
;
312 return m_property_time_ro(prop
, action
, arg
, len
);
315 /// Current position in percent (RW)
316 static int mp_property_percent_pos(m_option_t
* prop
, int action
,
317 void *arg
, MPContext
* mpctx
) {
321 return M_PROPERTY_UNAVAILABLE
;
325 if(!arg
) return M_PROPERTY_ERROR
;
326 M_PROPERTY_CLAMP(prop
, *(int*)arg
);
329 case M_PROPERTY_STEP_UP
:
330 case M_PROPERTY_STEP_DOWN
:
331 pos
= demuxer_get_percent_pos(mpctx
->demuxer
);
332 pos
+= (arg
? *(int*)arg
: 10) *
333 (action
== M_PROPERTY_STEP_UP
? 1 : -1);
334 M_PROPERTY_CLAMP(prop
, pos
);
337 return m_property_int_ro(prop
, action
, arg
,
338 demuxer_get_percent_pos(mpctx
->demuxer
));
342 rel_seek_secs
= pos
/ 100.0;
343 return M_PROPERTY_OK
;
346 /// Current position in seconds (RW)
347 static int mp_property_time_pos(m_option_t
* prop
, int action
,
348 void *arg
, MPContext
* mpctx
) {
349 if (!(mpctx
->sh_video
|| (mpctx
->sh_audio
&& mpctx
->audio_out
)))
350 return M_PROPERTY_UNAVAILABLE
;
354 if(!arg
) return M_PROPERTY_ERROR
;
355 M_PROPERTY_CLAMP(prop
, *(double*)arg
);
357 rel_seek_secs
= *(double*)arg
;
358 return M_PROPERTY_OK
;
359 case M_PROPERTY_STEP_UP
:
360 case M_PROPERTY_STEP_DOWN
:
361 rel_seek_secs
+= (arg
? *(double*)arg
: 10.0) *
362 (action
== M_PROPERTY_STEP_UP
? 1.0 : -1.0);
363 return M_PROPERTY_OK
;
365 return m_property_time_ro(prop
, action
, arg
,
366 mpctx
->sh_video
? mpctx
->sh_video
->pts
:
367 playing_audio_pts(mpctx
->sh_audio
,
372 /// Current chapter (RW)
373 static int mp_property_chapter(m_option_t
*prop
, int action
, void *arg
,
380 char *chapter_name
= NULL
;
385 return M_PROPERTY_ERROR
;
386 *(int *) arg
= demuxer_get_current_chapter(mpctx
->demuxer
);
387 return M_PROPERTY_OK
;
388 case M_PROPERTY_PRINT
: {
390 return M_PROPERTY_ERROR
;
391 chapter
= demuxer_get_current_chapter(mpctx
->demuxer
);
393 return M_PROPERTY_UNAVAILABLE
;
394 chapter_name
= demuxer_chapter_display_name(mpctx
->demuxer
, chapter
);
396 return M_PROPERTY_UNAVAILABLE
;
397 *(char **) arg
= chapter_name
;
398 return M_PROPERTY_OK
;
402 return M_PROPERTY_ERROR
;
403 M_PROPERTY_CLAMP(prop
, *(int*)arg
);
404 chapter
= demuxer_get_current_chapter(mpctx
->demuxer
);
406 return M_PROPERTY_UNAVAILABLE
;
407 step_all
= *(int *)arg
- (chapter
+ 1);
410 case M_PROPERTY_STEP_UP
:
411 case M_PROPERTY_STEP_DOWN
: {
412 step_all
= (arg
&& *(int*)arg
!= 0 ? *(int*)arg
: 1)
413 * (action
== M_PROPERTY_STEP_UP
? 1 : -1);
414 chapter
= demuxer_get_current_chapter(mpctx
->demuxer
);
416 return M_PROPERTY_UNAVAILABLE
;
423 return M_PROPERTY_NOT_IMPLEMENTED
;
427 chapter
= demuxer_seek_chapter(mpctx
->demuxer
, chapter
, 1,
428 &next_pts
, &chapter_num
, &chapter_name
);
430 if (next_pts
> -1.0) {
432 rel_seek_secs
= next_pts
;
435 set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
,
436 MSGTR_OSDChapter
, chapter
+ 1, chapter_name
);
438 else if (step_all
> 0)
439 rel_seek_secs
= 1000000000.;
441 set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
,
442 MSGTR_OSDChapter
, 0, MSGTR_Unknown
);
445 return M_PROPERTY_OK
;
448 /// Demuxer meta data
449 static int mp_property_metadata(m_option_t
* prop
, int action
, void *arg
,
451 m_property_action_t
* ka
;
453 static m_option_t key_type
=
454 { "metadata", NULL
, CONF_TYPE_STRING
, 0, 0, 0, NULL
};
456 return M_PROPERTY_UNAVAILABLE
;
460 if(!arg
) return M_PROPERTY_ERROR
;
461 *(char***)arg
= mpctx
->demuxer
->info
;
462 return M_PROPERTY_OK
;
463 case M_PROPERTY_KEY_ACTION
:
464 if(!arg
) return M_PROPERTY_ERROR
;
466 if(!(meta
= demux_info_get(mpctx
->demuxer
,ka
->key
)))
467 return M_PROPERTY_UNKNOWN
;
470 if(!ka
->arg
) return M_PROPERTY_ERROR
;
471 *(char**)ka
->arg
= meta
;
472 return M_PROPERTY_OK
;
473 case M_PROPERTY_GET_TYPE
:
474 if(!ka
->arg
) return M_PROPERTY_ERROR
;
475 *(m_option_t
**)ka
->arg
= &key_type
;
476 return M_PROPERTY_OK
;
479 return M_PROPERTY_NOT_IMPLEMENTED
;
485 /// \defgroup AudioProperties Audio properties
486 /// \ingroup Properties
490 static int mp_property_volume(m_option_t
* prop
, int action
, void *arg
,
494 if (!mpctx
->sh_audio
)
495 return M_PROPERTY_UNAVAILABLE
;
500 return M_PROPERTY_ERROR
;
501 mixer_getbothvolume(&mpctx
->mixer
, arg
);
502 return M_PROPERTY_OK
;
503 case M_PROPERTY_PRINT
:{
506 return M_PROPERTY_ERROR
;
507 mixer_getbothvolume(&mpctx
->mixer
, &vol
);
508 return m_property_float_range(prop
, action
, arg
, &vol
);
510 case M_PROPERTY_STEP_UP
:
511 case M_PROPERTY_STEP_DOWN
:
515 return M_PROPERTY_NOT_IMPLEMENTED
;
518 if (mpctx
->edl_muted
)
519 return M_PROPERTY_DISABLED
;
520 mpctx
->user_muted
= 0;
525 return M_PROPERTY_ERROR
;
526 M_PROPERTY_CLAMP(prop
, *(float *) arg
);
527 mixer_setvolume(&mpctx
->mixer
, *(float *) arg
, *(float *) arg
);
528 return M_PROPERTY_OK
;
529 case M_PROPERTY_STEP_UP
:
530 if (arg
&& *(float *) arg
<= 0)
531 mixer_decvolume(&mpctx
->mixer
);
533 mixer_incvolume(&mpctx
->mixer
);
534 return M_PROPERTY_OK
;
535 case M_PROPERTY_STEP_DOWN
:
536 if (arg
&& *(float *) arg
<= 0)
537 mixer_incvolume(&mpctx
->mixer
);
539 mixer_decvolume(&mpctx
->mixer
);
540 return M_PROPERTY_OK
;
542 return M_PROPERTY_NOT_IMPLEMENTED
;
546 static int mp_property_mute(m_option_t
* prop
, int action
, void *arg
,
550 if (!mpctx
->sh_audio
)
551 return M_PROPERTY_UNAVAILABLE
;
555 if (mpctx
->edl_muted
)
556 return M_PROPERTY_DISABLED
;
558 return M_PROPERTY_ERROR
;
559 if ((!!*(int *) arg
) != mpctx
->mixer
.muted
)
560 mixer_mute(&mpctx
->mixer
);
561 mpctx
->user_muted
= mpctx
->mixer
.muted
;
562 return M_PROPERTY_OK
;
563 case M_PROPERTY_STEP_UP
:
564 case M_PROPERTY_STEP_DOWN
:
565 if (mpctx
->edl_muted
)
566 return M_PROPERTY_DISABLED
;
567 mixer_mute(&mpctx
->mixer
);
568 mpctx
->user_muted
= mpctx
->mixer
.muted
;
569 return M_PROPERTY_OK
;
570 case M_PROPERTY_PRINT
:
572 return M_PROPERTY_ERROR
;
573 if (mpctx
->edl_muted
) {
574 *(char **) arg
= strdup(MSGTR_EnabledEdl
);
575 return M_PROPERTY_OK
;
578 return m_property_flag(prop
, action
, arg
, &mpctx
->mixer
.muted
);
584 static int mp_property_audio_delay(m_option_t
* prop
, int action
,
585 void *arg
, MPContext
* mpctx
)
587 if (!(mpctx
->sh_audio
&& mpctx
->sh_video
))
588 return M_PROPERTY_UNAVAILABLE
;
591 case M_PROPERTY_STEP_UP
:
592 case M_PROPERTY_STEP_DOWN
:
594 return M_PROPERTY_ERROR
;
596 float delay
= audio_delay
;
597 m_property_delay(prop
, action
, arg
, &audio_delay
);
599 mpctx
->delay
-= audio_delay
- delay
;
601 return M_PROPERTY_OK
;
603 return m_property_delay(prop
, action
, arg
, &audio_delay
);
607 /// Audio codec tag (RO)
608 static int mp_property_audio_format(m_option_t
* prop
, int action
,
609 void *arg
, MPContext
* mpctx
)
611 if (!mpctx
->sh_audio
)
612 return M_PROPERTY_UNAVAILABLE
;
613 return m_property_int_ro(prop
, action
, arg
, mpctx
->sh_audio
->format
);
616 /// Audio codec name (RO)
617 static int mp_property_audio_codec(m_option_t
* prop
, int action
,
618 void *arg
, MPContext
* mpctx
)
620 if (!mpctx
->sh_audio
|| !mpctx
->sh_audio
->codec
)
621 return M_PROPERTY_UNAVAILABLE
;
622 return m_property_string_ro(prop
, action
, arg
, mpctx
->sh_audio
->codec
->name
);
625 /// Audio bitrate (RO)
626 static int mp_property_audio_bitrate(m_option_t
* prop
, int action
,
627 void *arg
, MPContext
* mpctx
)
629 if (!mpctx
->sh_audio
)
630 return M_PROPERTY_UNAVAILABLE
;
631 return m_property_bitrate(prop
, action
, arg
, mpctx
->sh_audio
->i_bps
);
635 static int mp_property_samplerate(m_option_t
* prop
, int action
, void *arg
,
638 if (!mpctx
->sh_audio
)
639 return M_PROPERTY_UNAVAILABLE
;
641 case M_PROPERTY_PRINT
:
642 if(!arg
) return M_PROPERTY_ERROR
;
643 *(char**)arg
= malloc(16);
644 sprintf(*(char**)arg
,"%d kHz",mpctx
->sh_audio
->samplerate
/1000);
645 return M_PROPERTY_OK
;
647 return m_property_int_ro(prop
, action
, arg
, mpctx
->sh_audio
->samplerate
);
650 /// Number of channels (RO)
651 static int mp_property_channels(m_option_t
* prop
, int action
, void *arg
,
654 if (!mpctx
->sh_audio
)
655 return M_PROPERTY_UNAVAILABLE
;
657 case M_PROPERTY_PRINT
:
659 return M_PROPERTY_ERROR
;
660 switch (mpctx
->sh_audio
->channels
) {
662 *(char **) arg
= strdup("mono");
665 *(char **) arg
= strdup("stereo");
668 *(char **) arg
= malloc(32);
669 sprintf(*(char **) arg
, "%d channels", mpctx
->sh_audio
->channels
);
671 return M_PROPERTY_OK
;
673 return m_property_int_ro(prop
, action
, arg
, mpctx
->sh_audio
->channels
);
677 static int mp_property_balance(m_option_t
* prop
, int action
, void *arg
,
682 if (!mpctx
->sh_audio
|| mpctx
->sh_audio
->channels
< 2)
683 return M_PROPERTY_UNAVAILABLE
;
688 return M_PROPERTY_ERROR
;
689 mixer_getbalance(&mpctx
->mixer
, arg
);
690 return M_PROPERTY_OK
;
691 case M_PROPERTY_PRINT
: {
694 return M_PROPERTY_ERROR
;
695 mixer_getbalance(&mpctx
->mixer
, &bal
);
697 *str
= strdup("center");
698 else if (bal
== -1.f
)
699 *str
= strdup("left only");
701 *str
= strdup("right only");
703 unsigned right
= (bal
+ 1.f
) / 2.f
* 100.f
;
704 *str
= malloc(sizeof("left xxx%, right xxx%"));
705 sprintf(*str
, "left %d%%, right %d%%", 100 - right
, right
);
707 return M_PROPERTY_OK
;
709 case M_PROPERTY_STEP_UP
:
710 case M_PROPERTY_STEP_DOWN
:
711 mixer_getbalance(&mpctx
->mixer
, &bal
);
712 bal
+= (arg
? *(float*)arg
: .1f
) *
713 (action
== M_PROPERTY_STEP_UP
? 1.f
: -1.f
);
714 M_PROPERTY_CLAMP(prop
, bal
);
715 mixer_setbalance(&mpctx
->mixer
, bal
);
716 return M_PROPERTY_OK
;
719 return M_PROPERTY_ERROR
;
720 M_PROPERTY_CLAMP(prop
, *(float*)arg
);
721 mixer_setbalance(&mpctx
->mixer
, *(float*)arg
);
722 return M_PROPERTY_OK
;
724 return M_PROPERTY_NOT_IMPLEMENTED
;
727 /// Selected audio id (RW)
728 static int mp_property_audio(m_option_t
* prop
, int action
, void *arg
,
731 int current_id
= -1, tmp
;
735 if (!mpctx
->sh_audio
)
736 return M_PROPERTY_UNAVAILABLE
;
738 return M_PROPERTY_ERROR
;
739 *(int *) arg
= audio_id
;
740 return M_PROPERTY_OK
;
741 case M_PROPERTY_PRINT
:
742 if (!mpctx
->sh_audio
)
743 return M_PROPERTY_UNAVAILABLE
;
745 return M_PROPERTY_ERROR
;
748 *(char **) arg
= strdup(MSGTR_Disabled
);
750 char lang
[40] = MSGTR_Unknown
;
751 if (mpctx
->demuxer
->type
== DEMUXER_TYPE_MATROSKA
)
752 demux_mkv_get_audio_lang(mpctx
->demuxer
, audio_id
, lang
, 9);
754 else if (mpctx
->stream
->type
== STREAMTYPE_DVD
) {
755 int code
= dvd_lang_from_aid(mpctx
->stream
, audio_id
);
765 else if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
)
766 dvdnav_lang_from_aid(mpctx
->stream
, audio_id
, lang
);
768 *(char **) arg
= malloc(64);
769 snprintf(*(char **) arg
, 64, "(%d) %s", audio_id
, lang
);
771 return M_PROPERTY_OK
;
773 case M_PROPERTY_STEP_UP
:
775 if (action
== M_PROPERTY_SET
&& arg
)
776 tmp
= *((int *) arg
);
779 current_id
= mpctx
->demuxer
->audio
->id
;
780 audio_id
= demuxer_switch_audio(mpctx
->demuxer
, tmp
);
783 && mpctx
->demuxer
->audio
->id
!= current_id
&& current_id
!= -2))
784 uninit_player(INITED_AO
| INITED_ACODEC
);
785 if (audio_id
> -1 && mpctx
->demuxer
->audio
->id
!= current_id
) {
787 sh2
= mpctx
->demuxer
->a_streams
[mpctx
->demuxer
->audio
->id
];
789 sh2
->ds
= mpctx
->demuxer
->audio
;
790 mpctx
->sh_audio
= sh2
;
791 reinit_audio_chain();
794 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_AUDIO_TRACK=%d\n", audio_id
);
795 return M_PROPERTY_OK
;
797 return M_PROPERTY_NOT_IMPLEMENTED
;
802 /// Selected video id (RW)
803 static int mp_property_video(m_option_t
* prop
, int action
, void *arg
,
806 int current_id
= -1, tmp
;
810 if (!mpctx
->sh_video
)
811 return M_PROPERTY_UNAVAILABLE
;
813 return M_PROPERTY_ERROR
;
814 *(int *) arg
= video_id
;
815 return M_PROPERTY_OK
;
816 case M_PROPERTY_PRINT
:
817 if (!mpctx
->sh_video
)
818 return M_PROPERTY_UNAVAILABLE
;
820 return M_PROPERTY_ERROR
;
823 *(char **) arg
= strdup(MSGTR_Disabled
);
825 char lang
[40] = MSGTR_Unknown
;
826 *(char **) arg
= malloc(64);
827 snprintf(*(char **) arg
, 64, "(%d) %s", video_id
, lang
);
829 return M_PROPERTY_OK
;
831 case M_PROPERTY_STEP_UP
:
833 current_id
= mpctx
->demuxer
->video
->id
;
834 if (action
== M_PROPERTY_SET
&& arg
)
835 tmp
= *((int *) arg
);
838 video_id
= demuxer_switch_video(mpctx
->demuxer
, tmp
);
840 || (video_id
> -1 && mpctx
->demuxer
->video
->id
!= current_id
841 && current_id
!= -2))
842 uninit_player(INITED_VCODEC
|
843 (fixed_vo
&& video_id
!= -2 ? 0 : INITED_VO
));
844 if (video_id
> -1 && mpctx
->demuxer
->video
->id
!= current_id
) {
846 sh2
= mpctx
->demuxer
->v_streams
[mpctx
->demuxer
->video
->id
];
848 sh2
->ds
= mpctx
->demuxer
->video
;
849 mpctx
->sh_video
= sh2
;
850 reinit_video_chain();
853 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_TRACK=%d\n", video_id
);
854 return M_PROPERTY_OK
;
857 return M_PROPERTY_NOT_IMPLEMENTED
;
861 static int mp_property_program(m_option_t
* prop
, int action
, void *arg
,
864 demux_program_t prog
;
867 case M_PROPERTY_STEP_UP
:
869 if (action
== M_PROPERTY_SET
&& arg
)
870 prog
.progid
= *((int *) arg
);
874 (mpctx
->demuxer
, DEMUXER_CTRL_IDENTIFY_PROGRAM
,
875 &prog
) == DEMUXER_CTRL_NOTIMPL
)
876 return M_PROPERTY_ERROR
;
878 mp_property_do("switch_audio", M_PROPERTY_SET
, &prog
.aid
, mpctx
);
879 mp_property_do("switch_video", M_PROPERTY_SET
, &prog
.vid
, mpctx
);
880 return M_PROPERTY_OK
;
883 return M_PROPERTY_NOT_IMPLEMENTED
;
889 /// \defgroup VideoProperties Video properties
890 /// \ingroup Properties
893 /// Fullscreen state (RW)
894 static int mp_property_fullscreen(m_option_t
* prop
, int action
, void *arg
,
898 if (!mpctx
->video_out
)
899 return M_PROPERTY_UNAVAILABLE
;
904 return M_PROPERTY_ERROR
;
905 M_PROPERTY_CLAMP(prop
, *(int *) arg
);
906 if (vo_fs
== !!*(int *) arg
)
907 return M_PROPERTY_OK
;
908 case M_PROPERTY_STEP_UP
:
909 case M_PROPERTY_STEP_DOWN
:
912 guiGetEvent(guiIEvent
, (char *) MP_CMD_GUI_FULLSCREEN
);
916 mpctx
->video_out
->control(VOCTRL_FULLSCREEN
, 0);
917 return M_PROPERTY_OK
;
919 return m_property_flag(prop
, action
, arg
, &vo_fs
);
923 static int mp_property_deinterlace(m_option_t
* prop
, int action
,
924 void *arg
, MPContext
* mpctx
)
928 if (!mpctx
->sh_video
|| !mpctx
->sh_video
->vfilter
)
929 return M_PROPERTY_UNAVAILABLE
;
930 vf
= mpctx
->sh_video
->vfilter
;
934 return M_PROPERTY_ERROR
;
935 vf
->control(vf
, VFCTRL_GET_DEINTERLACE
, arg
);
936 return M_PROPERTY_OK
;
939 return M_PROPERTY_ERROR
;
940 M_PROPERTY_CLAMP(prop
, *(int *) arg
);
941 vf
->control(vf
, VFCTRL_SET_DEINTERLACE
, arg
);
942 return M_PROPERTY_OK
;
943 case M_PROPERTY_STEP_UP
:
944 case M_PROPERTY_STEP_DOWN
:
945 vf
->control(vf
, VFCTRL_GET_DEINTERLACE
, &deinterlace
);
946 deinterlace
= !deinterlace
;
947 vf
->control(vf
, VFCTRL_SET_DEINTERLACE
, &deinterlace
);
948 return M_PROPERTY_OK
;
950 return M_PROPERTY_NOT_IMPLEMENTED
;
954 static int mp_property_panscan(m_option_t
* prop
, int action
, void *arg
,
958 if (!mpctx
->video_out
959 || mpctx
->video_out
->control(VOCTRL_GET_PANSCAN
, NULL
) != VO_TRUE
)
960 return M_PROPERTY_UNAVAILABLE
;
965 return M_PROPERTY_ERROR
;
966 M_PROPERTY_CLAMP(prop
, *(float *) arg
);
967 vo_panscan
= *(float *) arg
;
968 mpctx
->video_out
->control(VOCTRL_SET_PANSCAN
, NULL
);
969 return M_PROPERTY_OK
;
970 case M_PROPERTY_STEP_UP
:
971 case M_PROPERTY_STEP_DOWN
:
972 vo_panscan
+= (arg
? *(float *) arg
: 0.1) *
973 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
976 else if (vo_panscan
< 0)
978 mpctx
->video_out
->control(VOCTRL_SET_PANSCAN
, NULL
);
979 return M_PROPERTY_OK
;
981 return m_property_float_range(prop
, action
, arg
, &vo_panscan
);
985 /// Helper to set vo flags.
986 /** \ingroup PropertyImplHelper
988 static int mp_property_vo_flag(m_option_t
* prop
, int action
, void *arg
,
989 int vo_ctrl
, int *vo_var
, MPContext
* mpctx
)
992 if (!mpctx
->video_out
)
993 return M_PROPERTY_UNAVAILABLE
;
998 return M_PROPERTY_ERROR
;
999 M_PROPERTY_CLAMP(prop
, *(int *) arg
);
1000 if (*vo_var
== !!*(int *) arg
)
1001 return M_PROPERTY_OK
;
1002 case M_PROPERTY_STEP_UP
:
1003 case M_PROPERTY_STEP_DOWN
:
1004 if (vo_config_count
)
1005 mpctx
->video_out
->control(vo_ctrl
, 0);
1006 return M_PROPERTY_OK
;
1008 return m_property_flag(prop
, action
, arg
, vo_var
);
1012 /// Window always on top (RW)
1013 static int mp_property_ontop(m_option_t
* prop
, int action
, void *arg
,
1016 return mp_property_vo_flag(prop
, action
, arg
, VOCTRL_ONTOP
, &vo_ontop
,
1020 /// Display in the root window (RW)
1021 static int mp_property_rootwin(m_option_t
* prop
, int action
, void *arg
,
1024 return mp_property_vo_flag(prop
, action
, arg
, VOCTRL_ROOTWIN
,
1025 &vo_rootwin
, mpctx
);
1028 /// Show window borders (RW)
1029 static int mp_property_border(m_option_t
* prop
, int action
, void *arg
,
1032 return mp_property_vo_flag(prop
, action
, arg
, VOCTRL_BORDER
,
1036 /// Framedropping state (RW)
1037 static int mp_property_framedropping(m_option_t
* prop
, int action
,
1038 void *arg
, MPContext
* mpctx
)
1041 if (!mpctx
->sh_video
)
1042 return M_PROPERTY_UNAVAILABLE
;
1045 case M_PROPERTY_PRINT
:
1047 return M_PROPERTY_ERROR
;
1048 *(char **) arg
= strdup(frame_dropping
== 1 ? MSGTR_Enabled
:
1049 (frame_dropping
== 2 ? MSGTR_HardFrameDrop
:
1051 return M_PROPERTY_OK
;
1053 return m_property_choice(prop
, action
, arg
, &frame_dropping
);
1057 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1058 static int mp_property_gamma(m_option_t
* prop
, int action
, void *arg
,
1061 int *gamma
= prop
->priv
, r
;
1063 if (!mpctx
->sh_video
)
1064 return M_PROPERTY_UNAVAILABLE
;
1066 if (gamma
[0] == 1000) {
1068 get_video_colors(mpctx
->sh_video
, prop
->name
, gamma
);
1072 case M_PROPERTY_SET
:
1074 return M_PROPERTY_ERROR
;
1075 M_PROPERTY_CLAMP(prop
, *(int *) arg
);
1076 *gamma
= *(int *) arg
;
1077 r
= set_video_colors(mpctx
->sh_video
, prop
->name
, *gamma
);
1081 case M_PROPERTY_GET
:
1083 return M_PROPERTY_ERROR
;
1084 r
= get_video_colors(mpctx
->sh_video
, prop
->name
, arg
);
1088 case M_PROPERTY_STEP_UP
:
1089 case M_PROPERTY_STEP_DOWN
:
1090 *gamma
+= (arg
? *(int *) arg
: 1) *
1091 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1092 M_PROPERTY_CLAMP(prop
, *gamma
);
1093 r
= set_video_colors(mpctx
->sh_video
, prop
->name
, *gamma
);
1098 return M_PROPERTY_NOT_IMPLEMENTED
;
1102 if (mpctx
->demuxer
->type
== DEMUXER_TYPE_TV
) {
1103 int l
= strlen(prop
->name
);
1104 char tv_prop
[3 + l
+ 1];
1105 sprintf(tv_prop
, "tv_%s", prop
->name
);
1106 return mp_property_do(tv_prop
, action
, arg
, mpctx
);
1110 return M_PROPERTY_UNAVAILABLE
;
1114 static int mp_property_vsync(m_option_t
* prop
, int action
, void *arg
,
1117 return m_property_flag(prop
, action
, arg
, &vo_vsync
);
1120 /// Video codec tag (RO)
1121 static int mp_property_video_format(m_option_t
* prop
, int action
,
1122 void *arg
, MPContext
* mpctx
)
1125 if (!mpctx
->sh_video
)
1126 return M_PROPERTY_UNAVAILABLE
;
1128 case M_PROPERTY_PRINT
:
1130 return M_PROPERTY_ERROR
;
1131 switch(mpctx
->sh_video
->format
) {
1133 meta
= strdup ("mpeg1"); break;
1135 meta
= strdup ("mpeg2"); break;
1137 meta
= strdup ("mpeg4"); break;
1139 meta
= strdup ("h264"); break;
1141 if(mpctx
->sh_video
->format
>= 0x20202020) {
1143 sprintf (meta
, "%.4s", (char *) &mpctx
->sh_video
->format
);
1146 sprintf (meta
, "0x%08X", mpctx
->sh_video
->format
);
1149 *(char**)arg
= meta
;
1150 return M_PROPERTY_OK
;
1152 return m_property_int_ro(prop
, action
, arg
, mpctx
->sh_video
->format
);
1155 /// Video codec name (RO)
1156 static int mp_property_video_codec(m_option_t
* prop
, int action
,
1157 void *arg
, MPContext
* mpctx
)
1159 if (!mpctx
->sh_video
|| !mpctx
->sh_video
->codec
)
1160 return M_PROPERTY_UNAVAILABLE
;
1161 return m_property_string_ro(prop
, action
, arg
, mpctx
->sh_video
->codec
->name
);
1165 /// Video bitrate (RO)
1166 static int mp_property_video_bitrate(m_option_t
* prop
, int action
,
1167 void *arg
, MPContext
* mpctx
)
1169 if (!mpctx
->sh_video
)
1170 return M_PROPERTY_UNAVAILABLE
;
1171 return m_property_bitrate(prop
, action
, arg
, mpctx
->sh_video
->i_bps
);
1174 /// Video display width (RO)
1175 static int mp_property_width(m_option_t
* prop
, int action
, void *arg
,
1178 if (!mpctx
->sh_video
)
1179 return M_PROPERTY_UNAVAILABLE
;
1180 return m_property_int_ro(prop
, action
, arg
, mpctx
->sh_video
->disp_w
);
1183 /// Video display height (RO)
1184 static int mp_property_height(m_option_t
* prop
, int action
, void *arg
,
1187 if (!mpctx
->sh_video
)
1188 return M_PROPERTY_UNAVAILABLE
;
1189 return m_property_int_ro(prop
, action
, arg
, mpctx
->sh_video
->disp_h
);
1193 static int mp_property_fps(m_option_t
* prop
, int action
, void *arg
,
1196 if (!mpctx
->sh_video
)
1197 return M_PROPERTY_UNAVAILABLE
;
1198 return m_property_float_ro(prop
, action
, arg
, mpctx
->sh_video
->fps
);
1201 /// Video aspect (RO)
1202 static int mp_property_aspect(m_option_t
* prop
, int action
, void *arg
,
1205 if (!mpctx
->sh_video
)
1206 return M_PROPERTY_UNAVAILABLE
;
1207 return m_property_float_ro(prop
, action
, arg
, mpctx
->sh_video
->aspect
);
1212 /// \defgroup SubProprties Subtitles properties
1213 /// \ingroup Properties
1216 /// Text subtitle position (RW)
1217 static int mp_property_sub_pos(m_option_t
* prop
, int action
, void *arg
,
1220 if (!mpctx
->sh_video
)
1221 return M_PROPERTY_UNAVAILABLE
;
1224 case M_PROPERTY_SET
:
1226 return M_PROPERTY_ERROR
;
1227 case M_PROPERTY_STEP_UP
:
1228 case M_PROPERTY_STEP_DOWN
:
1229 vo_osd_changed(OSDTYPE_SUBTITLE
);
1231 return m_property_int_range(prop
, action
, arg
, &sub_pos
);
1235 char *demux_lavf_sub_lang(demuxer_t
*demuxer
, int track_num
);
1237 /// Selected subtitles (RW)
1238 static int mp_property_sub(m_option_t
* prop
, int action
, void *arg
,
1241 demux_stream_t
*const d_sub
= mpctx
->d_sub
;
1242 const int global_sub_size
= mpctx
->global_sub_size
;
1243 int source
= -1, reset_spu
= 0;
1246 if (global_sub_size
<= 0)
1247 return M_PROPERTY_UNAVAILABLE
;
1250 case M_PROPERTY_GET
:
1252 return M_PROPERTY_ERROR
;
1253 *(int *) arg
= mpctx
->global_sub_pos
;
1254 return M_PROPERTY_OK
;
1255 case M_PROPERTY_PRINT
:
1257 return M_PROPERTY_ERROR
;
1258 *(char **) arg
= malloc(64);
1259 (*(char **) arg
)[63] = 0;
1262 sub_name
= subdata
->filename
;
1264 if (ass_track
&& ass_track
->name
)
1265 sub_name
= ass_track
->name
;
1270 if ((tmp2
= strrchr(tmp
, '/')))
1273 snprintf(*(char **) arg
, 63, "(%d) %s%s",
1274 mpctx
->set_of_sub_pos
+ 1,
1275 strlen(tmp
) < 20 ? "" : "...",
1276 strlen(tmp
) < 20 ? tmp
: tmp
+ strlen(tmp
) - 19);
1277 return M_PROPERTY_OK
;
1280 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
) {
1281 if (vo_spudec
&& dvdsub_id
>= 0) {
1282 unsigned char lang
[3];
1283 if (dvdnav_lang_from_sid(mpctx
->stream
, dvdsub_id
, lang
)) {
1284 snprintf(*(char **) arg
, 63, "(%d) %s", dvdsub_id
, lang
);
1285 return M_PROPERTY_OK
;
1291 #ifdef USE_LIBAVFORMAT
1292 if (mpctx
->demuxer
->type
== DEMUXER_TYPE_LAVF
&& dvdsub_id
>= 0) {
1293 char *lang
= demux_lavf_sub_lang(mpctx
->demuxer
, dvdsub_id
);
1294 snprintf(*(char **) arg
, 63, "(%d) %s", dvdsub_id
, lang
);
1295 return M_PROPERTY_OK
;
1298 if (mpctx
->demuxer
->type
== DEMUXER_TYPE_MATROSKA
&& dvdsub_id
>= 0) {
1299 char lang
[40] = MSGTR_Unknown
;
1300 demux_mkv_get_sub_lang(mpctx
->demuxer
, dvdsub_id
, lang
, 9);
1301 snprintf(*(char **) arg
, 63, "(%d) %s", dvdsub_id
, lang
);
1302 return M_PROPERTY_OK
;
1304 #ifdef HAVE_OGGVORBIS
1305 if (mpctx
->demuxer
->type
== DEMUXER_TYPE_OGG
&& d_sub
&& dvdsub_id
>= 0) {
1306 char *lang
= demux_ogg_sub_lang(mpctx
->demuxer
, dvdsub_id
);
1308 lang
= MSGTR_Unknown
;
1309 snprintf(*(char **) arg
, 63, "(%d) %s", dvdsub_id
, lang
);
1310 return M_PROPERTY_OK
;
1313 if (vo_vobsub
&& vobsub_id
>= 0) {
1314 const char *language
= MSGTR_Unknown
;
1315 language
= vobsub_get_id(vo_vobsub
, (unsigned int) vobsub_id
);
1316 snprintf(*(char **) arg
, 63, "(%d) %s",
1317 vobsub_id
, language
? language
: MSGTR_Unknown
);
1318 return M_PROPERTY_OK
;
1321 if (vo_spudec
&& mpctx
->stream
->type
== STREAMTYPE_DVD
1322 && dvdsub_id
>= 0) {
1324 int code
= dvd_lang_from_sid(mpctx
->stream
, dvdsub_id
);
1325 lang
[0] = code
>> 8;
1328 snprintf(*(char **) arg
, 63, "(%d) %s", dvdsub_id
, lang
);
1329 return M_PROPERTY_OK
;
1332 if (dvdsub_id
>= 0) {
1333 snprintf(*(char **) arg
, 63, "(%d) %s", dvdsub_id
, MSGTR_Unknown
);
1334 return M_PROPERTY_OK
;
1336 snprintf(*(char **) arg
, 63, MSGTR_Disabled
);
1337 return M_PROPERTY_OK
;
1339 case M_PROPERTY_SET
:
1341 return M_PROPERTY_ERROR
;
1342 if (*(int *) arg
< -1)
1344 else if (*(int *) arg
>= global_sub_size
)
1345 *(int *) arg
= global_sub_size
- 1;
1346 mpctx
->global_sub_pos
= *(int *) arg
;
1348 case M_PROPERTY_STEP_UP
:
1349 mpctx
->global_sub_pos
+= 2;
1350 mpctx
->global_sub_pos
=
1351 (mpctx
->global_sub_pos
% (global_sub_size
+ 1)) - 1;
1353 case M_PROPERTY_STEP_DOWN
:
1354 mpctx
->global_sub_pos
+= global_sub_size
+ 1;
1355 mpctx
->global_sub_pos
=
1356 (mpctx
->global_sub_pos
% (global_sub_size
+ 1)) - 1;
1359 return M_PROPERTY_NOT_IMPLEMENTED
;
1362 if (mpctx
->global_sub_pos
>= 0)
1363 source
= sub_source(mpctx
);
1365 mp_msg(MSGT_CPLAYER
, MSGL_DBG3
,
1366 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1368 mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
],
1369 mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
],
1370 mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
],
1371 mpctx
->global_sub_pos
, source
);
1373 mpctx
->set_of_sub_pos
= -1;
1387 if (source
== SUB_SOURCE_VOBSUB
) {
1388 vobsub_id
= vobsub_get_id_by_index(vo_vobsub
, mpctx
->global_sub_pos
- mpctx
->global_sub_indices
[SUB_SOURCE_VOBSUB
]);
1389 } else if (source
== SUB_SOURCE_SUBS
) {
1390 mpctx
->set_of_sub_pos
=
1391 mpctx
->global_sub_pos
- mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
];
1393 if (ass_enabled
&& mpctx
->set_of_ass_tracks
[mpctx
->set_of_sub_pos
])
1394 ass_track
= mpctx
->set_of_ass_tracks
[mpctx
->set_of_sub_pos
];
1398 subdata
= mpctx
->set_of_subtitles
[mpctx
->set_of_sub_pos
];
1399 vo_osd_changed(OSDTYPE_SUBTITLE
);
1401 } else if (source
== SUB_SOURCE_DEMUX
) {
1403 mpctx
->global_sub_pos
- mpctx
->global_sub_indices
[SUB_SOURCE_DEMUX
];
1404 if (d_sub
&& dvdsub_id
< MAX_S_STREAMS
) {
1406 // default: assume 1:1 mapping of sid and stream id
1407 d_sub
->id
= dvdsub_id
;
1408 d_sub
->sh
= mpctx
->demuxer
->s_streams
[d_sub
->id
];
1409 for (i
= 0; i
< MAX_S_STREAMS
; i
++) {
1410 sh_sub_t
*sh
= mpctx
->demuxer
->s_streams
[i
];
1411 if (sh
&& sh
->sid
== dvdsub_id
) {
1417 if (d_sub
->sh
&& d_sub
->id
>= 0) {
1418 sh_sub_t
*sh
= d_sub
->sh
;
1419 if (sh
->type
== 'v')
1422 else if (ass_enabled
&& sh
->type
== 'a')
1423 ass_track
= sh
->ass_track
;
1433 && (mpctx
->stream
->type
== STREAMTYPE_DVD
1434 || mpctx
->stream
->type
== STREAMTYPE_DVDNAV
)
1435 && dvdsub_id
< 0 && reset_spu
) {
1437 d_sub
->id
= dvdsub_id
;
1440 update_subtitles(mpctx
->sh_video
, d_sub
, 1);
1442 return M_PROPERTY_OK
;
1445 /// Selected sub source (RW)
1446 static int mp_property_sub_source(m_option_t
* prop
, int action
, void *arg
,
1450 if (!mpctx
->sh_video
|| mpctx
->global_sub_size
<= 0)
1451 return M_PROPERTY_UNAVAILABLE
;
1454 case M_PROPERTY_GET
:
1456 return M_PROPERTY_ERROR
;
1457 *(int *) arg
= sub_source(mpctx
);
1458 return M_PROPERTY_OK
;
1459 case M_PROPERTY_PRINT
:
1461 return M_PROPERTY_ERROR
;
1462 *(char **) arg
= malloc(64);
1463 (*(char **) arg
)[63] = 0;
1464 switch (sub_source(mpctx
))
1466 case SUB_SOURCE_SUBS
:
1467 snprintf(*(char **) arg
, 63, MSGTR_SubSourceFile
);
1469 case SUB_SOURCE_VOBSUB
:
1470 snprintf(*(char **) arg
, 63, MSGTR_SubSourceVobsub
);
1472 case SUB_SOURCE_DEMUX
:
1473 snprintf(*(char **) arg
, 63, MSGTR_SubSourceDemux
);
1476 snprintf(*(char **) arg
, 63, MSGTR_Disabled
);
1478 return M_PROPERTY_OK
;
1479 case M_PROPERTY_SET
:
1481 return M_PROPERTY_ERROR
;
1482 M_PROPERTY_CLAMP(prop
, *(int*)arg
);
1483 if (*(int *) arg
< 0)
1484 mpctx
->global_sub_pos
= -1;
1485 else if (*(int *) arg
!= sub_source(mpctx
)) {
1486 if (*(int *) arg
!= sub_source_by_pos(mpctx
, mpctx
->global_sub_indices
[*(int *) arg
]))
1487 return M_PROPERTY_UNAVAILABLE
;
1488 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[*(int *) arg
];
1491 case M_PROPERTY_STEP_UP
:
1492 case M_PROPERTY_STEP_DOWN
: {
1493 int step_all
= (arg
&& *(int*)arg
!= 0 ? *(int*)arg
: 1)
1494 * (action
== M_PROPERTY_STEP_UP
? 1 : -1);
1495 int step
= (step_all
> 0) ? 1 : -1;
1496 int cur_source
= sub_source(mpctx
);
1497 source
= cur_source
;
1500 if (source
>= SUB_SOURCES
)
1502 else if (source
< -1)
1503 source
= SUB_SOURCES
- 1;
1504 if (source
== cur_source
|| source
== -1 ||
1505 source
== sub_source_by_pos(mpctx
, mpctx
->global_sub_indices
[source
]))
1508 if (source
== cur_source
)
1509 return M_PROPERTY_OK
;
1511 mpctx
->global_sub_pos
= -1;
1513 mpctx
->global_sub_pos
= mpctx
->global_sub_indices
[source
];
1517 return M_PROPERTY_NOT_IMPLEMENTED
;
1519 --mpctx
->global_sub_pos
;
1520 return mp_property_sub(prop
, M_PROPERTY_STEP_UP
, NULL
, mpctx
);
1523 /// Selected subtitles from specific source (RW)
1524 static int mp_property_sub_by_type(m_option_t
* prop
, int action
, void *arg
,
1527 int source
, is_cur_source
, offset
;
1528 if (!mpctx
->sh_video
|| mpctx
->global_sub_size
<= 0)
1529 return M_PROPERTY_UNAVAILABLE
;
1531 if (!strcmp(prop
->name
, "sub_file"))
1532 source
= SUB_SOURCE_SUBS
;
1533 else if (!strcmp(prop
->name
, "sub_vob"))
1534 source
= SUB_SOURCE_VOBSUB
;
1535 else if (!strcmp(prop
->name
, "sub_demux"))
1536 source
= SUB_SOURCE_DEMUX
;
1538 return M_PROPERTY_ERROR
;
1540 offset
= mpctx
->global_sub_indices
[source
];
1541 if (offset
< 0 || source
!= sub_source_by_pos(mpctx
, offset
))
1542 return M_PROPERTY_UNAVAILABLE
;
1544 is_cur_source
= sub_source(mpctx
) == source
;
1546 case M_PROPERTY_GET
:
1548 return M_PROPERTY_ERROR
;
1549 if (is_cur_source
) {
1550 *(int *) arg
= mpctx
->global_sub_pos
- offset
;
1551 if (source
== SUB_SOURCE_VOBSUB
)
1552 *(int *) arg
= vobsub_get_id_by_index(vo_vobsub
, *(int *) arg
);
1556 return M_PROPERTY_OK
;
1557 case M_PROPERTY_PRINT
:
1559 return M_PROPERTY_ERROR
;
1561 return mp_property_sub(prop
, M_PROPERTY_PRINT
, arg
, mpctx
);
1562 *(char **) arg
= malloc(64);
1563 (*(char **) arg
)[63] = 0;
1564 snprintf(*(char **) arg
, 63, MSGTR_Disabled
);
1565 return M_PROPERTY_OK
;
1566 case M_PROPERTY_SET
:
1568 return M_PROPERTY_ERROR
;
1569 if (*(int *) arg
>= 0) {
1570 int index
= *(int *)arg
;
1571 if (source
== SUB_SOURCE_VOBSUB
)
1572 index
= vobsub_get_index_by_id(vo_vobsub
, index
);
1573 mpctx
->global_sub_pos
= offset
+ index
;
1574 if (index
< 0 || mpctx
->global_sub_pos
>= mpctx
->global_sub_size
1575 || sub_source(mpctx
) != source
) {
1576 mpctx
->global_sub_pos
= -1;
1581 mpctx
->global_sub_pos
= -1;
1583 case M_PROPERTY_STEP_UP
:
1584 case M_PROPERTY_STEP_DOWN
: {
1585 int step_all
= (arg
&& *(int*)arg
!= 0 ? *(int*)arg
: 1)
1586 * (action
== M_PROPERTY_STEP_UP
? 1 : -1);
1587 int step
= (step_all
> 0) ? 1 : -1;
1588 int max_sub_pos_for_source
= -1;
1590 mpctx
->global_sub_pos
= -1;
1592 if (mpctx
->global_sub_pos
== -1) {
1594 mpctx
->global_sub_pos
= offset
;
1595 else if (max_sub_pos_for_source
== -1) {
1596 // Find max pos for specific source
1597 mpctx
->global_sub_pos
= mpctx
->global_sub_size
- 1;
1598 while (mpctx
->global_sub_pos
>= 0
1599 && sub_source(mpctx
) != source
)
1600 --mpctx
->global_sub_pos
;
1603 mpctx
->global_sub_pos
= max_sub_pos_for_source
;
1606 mpctx
->global_sub_pos
+= step
;
1607 if (mpctx
->global_sub_pos
< offset
||
1608 mpctx
->global_sub_pos
>= mpctx
->global_sub_size
||
1609 sub_source(mpctx
) != source
)
1610 mpctx
->global_sub_pos
= -1;
1617 return M_PROPERTY_NOT_IMPLEMENTED
;
1619 --mpctx
->global_sub_pos
;
1620 return mp_property_sub(prop
, M_PROPERTY_STEP_UP
, NULL
, mpctx
);
1623 /// Subtitle delay (RW)
1624 static int mp_property_sub_delay(m_option_t
* prop
, int action
, void *arg
,
1627 if (!mpctx
->sh_video
)
1628 return M_PROPERTY_UNAVAILABLE
;
1629 return m_property_delay(prop
, action
, arg
, &sub_delay
);
1632 /// Alignment of text subtitles (RW)
1633 static int mp_property_sub_alignment(m_option_t
* prop
, int action
,
1634 void *arg
, MPContext
* mpctx
)
1636 char *name
[] = { MSGTR_Top
, MSGTR_Center
, MSGTR_Bottom
};
1638 if (!mpctx
->sh_video
|| mpctx
->global_sub_pos
< 0
1639 || sub_source(mpctx
) != SUB_SOURCE_SUBS
)
1640 return M_PROPERTY_UNAVAILABLE
;
1643 case M_PROPERTY_PRINT
:
1645 return M_PROPERTY_ERROR
;
1646 M_PROPERTY_CLAMP(prop
, sub_alignment
);
1647 *(char **) arg
= strdup(name
[sub_alignment
]);
1648 return M_PROPERTY_OK
;
1649 case M_PROPERTY_SET
:
1651 return M_PROPERTY_ERROR
;
1652 case M_PROPERTY_STEP_UP
:
1653 case M_PROPERTY_STEP_DOWN
:
1654 vo_osd_changed(OSDTYPE_SUBTITLE
);
1656 return m_property_choice(prop
, action
, arg
, &sub_alignment
);
1660 /// Subtitle visibility (RW)
1661 static int mp_property_sub_visibility(m_option_t
* prop
, int action
,
1662 void *arg
, MPContext
* mpctx
)
1664 if (!mpctx
->sh_video
)
1665 return M_PROPERTY_UNAVAILABLE
;
1668 case M_PROPERTY_SET
:
1670 return M_PROPERTY_ERROR
;
1671 case M_PROPERTY_STEP_UP
:
1672 case M_PROPERTY_STEP_DOWN
:
1673 vo_osd_changed(OSDTYPE_SUBTITLE
);
1675 vo_osd_changed(OSDTYPE_SPU
);
1677 return m_property_flag(prop
, action
, arg
, &sub_visibility
);
1681 /// Show only forced subtitles (RW)
1682 static int mp_property_sub_forced_only(m_option_t
* prop
, int action
,
1683 void *arg
, MPContext
* mpctx
)
1686 return M_PROPERTY_UNAVAILABLE
;
1689 case M_PROPERTY_SET
:
1691 return M_PROPERTY_ERROR
;
1692 case M_PROPERTY_STEP_UP
:
1693 case M_PROPERTY_STEP_DOWN
:
1694 m_property_flag(prop
, action
, arg
, &forced_subs_only
);
1695 spudec_set_forced_subs_only(vo_spudec
, forced_subs_only
);
1696 return M_PROPERTY_OK
;
1698 return m_property_flag(prop
, action
, arg
, &forced_subs_only
);
1703 #ifdef HAVE_FREETYPE
1704 /// Subtitle scale (RW)
1705 static int mp_property_sub_scale(m_option_t
* prop
, int action
, void *arg
,
1710 case M_PROPERTY_SET
:
1712 return M_PROPERTY_ERROR
;
1713 M_PROPERTY_CLAMP(prop
, *(float *) arg
);
1714 text_font_scale_factor
= *(float *) arg
;
1715 force_load_font
= 1;
1716 return M_PROPERTY_OK
;
1717 case M_PROPERTY_STEP_UP
:
1718 case M_PROPERTY_STEP_DOWN
:
1719 text_font_scale_factor
+= (arg
? *(float *) arg
: 0.1)*
1720 (action
== M_PROPERTY_STEP_UP
? 1.0 : -1.0);
1721 M_PROPERTY_CLAMP(prop
, text_font_scale_factor
);
1722 force_load_font
= 1;
1723 return M_PROPERTY_OK
;
1725 return m_property_float_ro(prop
, action
, arg
, text_font_scale_factor
);
1732 /// \defgroup TVProperties TV properties
1733 /// \ingroup Properties
1738 /// TV color settings (RW)
1739 static int mp_property_tv_color(m_option_t
* prop
, int action
, void *arg
,
1743 tvi_handle_t
*tvh
= mpctx
->demuxer
->priv
;
1744 if (mpctx
->demuxer
->type
!= DEMUXER_TYPE_TV
|| !tvh
)
1745 return M_PROPERTY_UNAVAILABLE
;
1748 case M_PROPERTY_SET
:
1750 return M_PROPERTY_ERROR
;
1751 M_PROPERTY_CLAMP(prop
, *(int *) arg
);
1752 return tv_set_color_options(tvh
, (int) prop
->priv
, *(int *) arg
);
1753 case M_PROPERTY_GET
:
1754 return tv_get_color_options(tvh
, (int) prop
->priv
, arg
);
1755 case M_PROPERTY_STEP_UP
:
1756 case M_PROPERTY_STEP_DOWN
:
1757 if ((r
= tv_get_color_options(tvh
, (int) prop
->priv
, &val
)) >= 0) {
1759 return M_PROPERTY_ERROR
;
1760 val
+= (arg
? *(int *) arg
: 1) *
1761 (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1762 M_PROPERTY_CLAMP(prop
, val
);
1763 return tv_set_color_options(tvh
, (int) prop
->priv
, val
);
1765 return M_PROPERTY_ERROR
;
1767 return M_PROPERTY_NOT_IMPLEMENTED
;
1772 #ifdef HAVE_TV_TELETEXT
1773 static int mp_property_teletext_common(m_option_t
* prop
, int action
, void *arg
,
1777 int base_ioctl
=(int)prop
->priv
;
1779 for teletext's GET,SET,STEP ioctls this is not 0
1783 tvi_handle_t
*tvh
= mpctx
->demuxer
->priv
;
1784 if (mpctx
->demuxer
->type
!= DEMUXER_TYPE_TV
|| !tvh
)
1785 return M_PROPERTY_UNAVAILABLE
;
1787 return M_PROPERTY_ERROR
;
1790 case M_PROPERTY_GET
:
1792 return M_PROPERTY_ERROR
;
1793 result
=tvh
->functions
->control(tvh
->priv
, base_ioctl
, arg
);
1795 case M_PROPERTY_SET
:
1797 return M_PROPERTY_ERROR
;
1798 M_PROPERTY_CLAMP(prop
, *(int *) arg
);
1799 result
=tvh
->functions
->control(tvh
->priv
, base_ioctl
+1, arg
);
1801 case M_PROPERTY_STEP_UP
:
1802 case M_PROPERTY_STEP_DOWN
:
1803 result
=tvh
->functions
->control(tvh
->priv
, base_ioctl
, &val
);
1804 val
+= (arg
? *(int *) arg
: 1) * (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1805 result
=tvh
->functions
->control(tvh
->priv
, base_ioctl
+1, &val
);
1808 return M_PROPERTY_NOT_IMPLEMENTED
;
1811 return (result
==TVI_CONTROL_TRUE
?M_PROPERTY_OK
:M_PROPERTY_ERROR
);
1814 static int mp_property_teletext_mode(m_option_t
* prop
, int action
, void *arg
,
1817 tvi_handle_t
*tvh
= mpctx
->demuxer
->priv
;
1821 //with tvh==NULL will fail too
1822 result
=mp_property_teletext_common(prop
,action
,arg
,mpctx
);
1823 if(result
!=M_PROPERTY_OK
)
1826 if(tvh
->functions
->control(tvh
->priv
, prop
->priv
, &val
)==TVI_CONTROL_TRUE
&& val
)
1827 mp_input_set_section("teletext");
1829 mp_input_set_section("tv");
1830 return M_PROPERTY_OK
;
1833 static int mp_property_teletext_page(m_option_t
* prop
, int action
, void *arg
,
1836 tvi_handle_t
*tvh
= mpctx
->demuxer
->priv
;
1840 case M_PROPERTY_STEP_UP
:
1841 case M_PROPERTY_STEP_DOWN
:
1842 //This should be handled separately
1843 val
= (arg
? *(int *) arg
: 1) * (action
== M_PROPERTY_STEP_DOWN
? -1 : 1);
1844 result
=tvh
->functions
->control(tvh
->priv
, TV_VBI_CONTROL_STEP_PAGE
, &val
);
1847 result
=mp_property_teletext_common(prop
,action
,arg
,mpctx
);
1853 #endif /* HAVE_TV_TELETEXT */
1857 /// All properties available in MPlayer.
1858 /** \ingroup Properties
1860 static m_option_t mp_properties
[] = {
1862 { "osdlevel", mp_property_osdlevel
, CONF_TYPE_INT
,
1863 M_OPT_RANGE
, 0, 3, NULL
},
1864 { "loop", mp_property_loop
, CONF_TYPE_INT
,
1865 M_OPT_MIN
, -1, 0, NULL
},
1866 { "speed", mp_property_playback_speed
, CONF_TYPE_FLOAT
,
1867 M_OPT_RANGE
, 0.01, 100.0, NULL
},
1868 { "filename", mp_property_filename
, CONF_TYPE_STRING
,
1870 { "path", mp_property_path
, CONF_TYPE_STRING
,
1872 { "demuxer", mp_property_demuxer
, CONF_TYPE_STRING
,
1874 { "stream_pos", mp_property_stream_pos
, CONF_TYPE_POSITION
,
1875 M_OPT_MIN
, 0, 0, NULL
},
1876 { "stream_start", mp_property_stream_start
, CONF_TYPE_POSITION
,
1877 M_OPT_MIN
, 0, 0, NULL
},
1878 { "stream_end", mp_property_stream_end
, CONF_TYPE_POSITION
,
1879 M_OPT_MIN
, 0, 0, NULL
},
1880 { "stream_length", mp_property_stream_length
, CONF_TYPE_POSITION
,
1881 M_OPT_MIN
, 0, 0, NULL
},
1882 { "length", mp_property_length
, CONF_TYPE_TIME
,
1883 M_OPT_MIN
, 0, 0, NULL
},
1884 { "percent_pos", mp_property_percent_pos
, CONF_TYPE_INT
,
1885 M_OPT_RANGE
, 0, 100, NULL
},
1886 { "time_pos", mp_property_time_pos
, CONF_TYPE_TIME
,
1887 M_OPT_MIN
, 0, 0, NULL
},
1888 { "chapter", mp_property_chapter
, CONF_TYPE_INT
,
1889 M_OPT_MIN
, 1, 0, NULL
},
1890 { "metadata", mp_property_metadata
, CONF_TYPE_STRING_LIST
,
1894 { "volume", mp_property_volume
, CONF_TYPE_FLOAT
,
1895 M_OPT_RANGE
, 0, 100, NULL
},
1896 { "mute", mp_property_mute
, CONF_TYPE_FLAG
,
1897 M_OPT_RANGE
, 0, 1, NULL
},
1898 { "audio_delay", mp_property_audio_delay
, CONF_TYPE_FLOAT
,
1899 M_OPT_RANGE
, -100, 100, NULL
},
1900 { "audio_format", mp_property_audio_format
, CONF_TYPE_INT
,
1902 { "audio_codec", mp_property_audio_codec
, CONF_TYPE_STRING
,
1904 { "audio_bitrate", mp_property_audio_bitrate
, CONF_TYPE_INT
,
1906 { "samplerate", mp_property_samplerate
, CONF_TYPE_INT
,
1908 { "channels", mp_property_channels
, CONF_TYPE_INT
,
1910 { "switch_audio", mp_property_audio
, CONF_TYPE_INT
,
1911 CONF_RANGE
, -2, MAX_A_STREAMS
- 1, NULL
},
1912 { "balance", mp_property_balance
, CONF_TYPE_FLOAT
,
1913 M_OPT_RANGE
, -1, 1, NULL
},
1916 { "fullscreen", mp_property_fullscreen
, CONF_TYPE_FLAG
,
1917 M_OPT_RANGE
, 0, 1, NULL
},
1918 { "deinterlace", mp_property_deinterlace
, CONF_TYPE_FLAG
,
1919 M_OPT_RANGE
, 0, 1, NULL
},
1920 { "ontop", mp_property_ontop
, CONF_TYPE_FLAG
,
1921 M_OPT_RANGE
, 0, 1, NULL
},
1922 { "rootwin", mp_property_rootwin
, CONF_TYPE_FLAG
,
1923 M_OPT_RANGE
, 0, 1, NULL
},
1924 { "border", mp_property_border
, CONF_TYPE_FLAG
,
1925 M_OPT_RANGE
, 0, 1, NULL
},
1926 { "framedropping", mp_property_framedropping
, CONF_TYPE_INT
,
1927 M_OPT_RANGE
, 0, 2, NULL
},
1928 { "gamma", mp_property_gamma
, CONF_TYPE_INT
,
1929 M_OPT_RANGE
, -100, 100, &vo_gamma_gamma
},
1930 { "brightness", mp_property_gamma
, CONF_TYPE_INT
,
1931 M_OPT_RANGE
, -100, 100, &vo_gamma_brightness
},
1932 { "contrast", mp_property_gamma
, CONF_TYPE_INT
,
1933 M_OPT_RANGE
, -100, 100, &vo_gamma_contrast
},
1934 { "saturation", mp_property_gamma
, CONF_TYPE_INT
,
1935 M_OPT_RANGE
, -100, 100, &vo_gamma_saturation
},
1936 { "hue", mp_property_gamma
, CONF_TYPE_INT
,
1937 M_OPT_RANGE
, -100, 100, &vo_gamma_hue
},
1938 { "panscan", mp_property_panscan
, CONF_TYPE_FLOAT
,
1939 M_OPT_RANGE
, 0, 1, NULL
},
1940 { "vsync", mp_property_vsync
, CONF_TYPE_FLAG
,
1941 M_OPT_RANGE
, 0, 1, NULL
},
1942 { "video_format", mp_property_video_format
, CONF_TYPE_INT
,
1944 { "video_codec", mp_property_video_codec
, CONF_TYPE_STRING
,
1946 { "video_bitrate", mp_property_video_bitrate
, CONF_TYPE_INT
,
1948 { "width", mp_property_width
, CONF_TYPE_INT
,
1950 { "height", mp_property_height
, CONF_TYPE_INT
,
1952 { "fps", mp_property_fps
, CONF_TYPE_FLOAT
,
1954 { "aspect", mp_property_aspect
, CONF_TYPE_FLOAT
,
1956 { "switch_video", mp_property_video
, CONF_TYPE_INT
,
1957 CONF_RANGE
, -2, MAX_V_STREAMS
- 1, NULL
},
1958 { "switch_program", mp_property_program
, CONF_TYPE_INT
,
1959 CONF_RANGE
, -1, 65535, NULL
},
1962 { "sub", mp_property_sub
, CONF_TYPE_INT
,
1963 M_OPT_MIN
, -1, 0, NULL
},
1964 { "sub_source", mp_property_sub_source
, CONF_TYPE_INT
,
1965 M_OPT_RANGE
, -1, SUB_SOURCES
- 1, NULL
},
1966 { "sub_vob", mp_property_sub_by_type
, CONF_TYPE_INT
,
1967 M_OPT_MIN
, -1, 0, NULL
},
1968 { "sub_demux", mp_property_sub_by_type
, CONF_TYPE_INT
,
1969 M_OPT_MIN
, -1, 0, NULL
},
1970 { "sub_file", mp_property_sub_by_type
, CONF_TYPE_INT
,
1971 M_OPT_MIN
, -1, 0, NULL
},
1972 { "sub_delay", mp_property_sub_delay
, CONF_TYPE_FLOAT
,
1974 { "sub_pos", mp_property_sub_pos
, CONF_TYPE_INT
,
1975 M_OPT_RANGE
, 0, 100, NULL
},
1976 { "sub_alignment", mp_property_sub_alignment
, CONF_TYPE_INT
,
1977 M_OPT_RANGE
, 0, 2, NULL
},
1978 { "sub_visibility", mp_property_sub_visibility
, CONF_TYPE_FLAG
,
1979 M_OPT_RANGE
, 0, 1, NULL
},
1980 { "sub_forced_only", mp_property_sub_forced_only
, CONF_TYPE_FLAG
,
1981 M_OPT_RANGE
, 0, 1, NULL
},
1982 #ifdef HAVE_FREETYPE
1983 { "sub_scale", mp_property_sub_scale
, CONF_TYPE_FLOAT
,
1984 M_OPT_RANGE
, 0, 100, NULL
},
1988 { "tv_brightness", mp_property_tv_color
, CONF_TYPE_INT
,
1989 M_OPT_RANGE
, -100, 100, (void *) TV_COLOR_BRIGHTNESS
},
1990 { "tv_contrast", mp_property_tv_color
, CONF_TYPE_INT
,
1991 M_OPT_RANGE
, -100, 100, (void *) TV_COLOR_CONTRAST
},
1992 { "tv_saturation", mp_property_tv_color
, CONF_TYPE_INT
,
1993 M_OPT_RANGE
, -100, 100, (void *) TV_COLOR_SATURATION
},
1994 { "tv_hue", mp_property_tv_color
, CONF_TYPE_INT
,
1995 M_OPT_RANGE
, -100, 100, (void *) TV_COLOR_HUE
},
1998 #ifdef HAVE_TV_TELETEXT
1999 { "teletext_page", mp_property_teletext_page
, CONF_TYPE_INT
,
2000 M_OPT_RANGE
, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE
},
2001 { "teletext_subpage", mp_property_teletext_common
, CONF_TYPE_INT
,
2002 M_OPT_RANGE
, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE
},
2003 { "teletext_mode", mp_property_teletext_mode
, CONF_TYPE_FLAG
,
2004 M_OPT_RANGE
, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE
},
2005 { "teletext_format", mp_property_teletext_common
, CONF_TYPE_INT
,
2006 M_OPT_RANGE
, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT
},
2007 { "teletext_half_page", mp_property_teletext_common
, CONF_TYPE_INT
,
2008 M_OPT_RANGE
, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE
},
2011 { NULL
, NULL
, NULL
, 0, 0, 0, NULL
}
2015 int mp_property_do(const char *name
, int action
, void *val
, void *ctx
)
2017 return m_property_do(mp_properties
, name
, action
, val
, ctx
);
2020 char* mp_property_print(const char *name
, void* ctx
)
2023 if(mp_property_do(name
,M_PROPERTY_PRINT
,&ret
,ctx
) <= 0)
2028 char *property_expand_string(MPContext
* mpctx
, char *str
)
2030 return m_properties_expand_string(mp_properties
, str
, mpctx
);
2033 void property_print_help(void)
2035 m_properties_print_help_list(mp_properties
);
2044 * \defgroup Command2Property Command to property bridge
2046 * It is used to handle most commands that just set a property
2047 * and optionally display something on the OSD.
2048 * Two kinds of commands are handled: adjust or toggle.
2050 * Adjust commands take 1 or 2 parameters: <value> <abs>
2051 * If <abs> is non-zero the property is set to the given value
2052 * otherwise it is adjusted.
2054 * Toggle commands take 0 or 1 parameters. With no parameter
2055 * or a value less than the property minimum it just steps the
2056 * property to its next value. Otherwise it sets it to the given
2062 /// List of the commands that can be handled by setting a property.
2068 /// set/adjust or toggle command
2070 /// progressbar type
2072 /// osd msg id if it must be shared
2074 /// osd msg template
2075 const char *osd_msg
;
2076 } set_prop_cmd
[] = {
2078 { "loop", MP_CMD_LOOP
, 0, 0, -1, MSGTR_LoopStatus
},
2079 { "chapter", MP_CMD_SEEK_CHAPTER
, 0, 0, -1, NULL
},
2081 { "volume", MP_CMD_VOLUME
, 0, OSD_VOLUME
, -1, MSGTR_Volume
},
2082 { "mute", MP_CMD_MUTE
, 1, 0, -1, MSGTR_MuteStatus
},
2083 { "audio_delay", MP_CMD_AUDIO_DELAY
, 0, 0, -1, MSGTR_AVDelayStatus
},
2084 { "switch_audio", MP_CMD_SWITCH_AUDIO
, 1, 0, -1, MSGTR_OSDAudio
},
2085 { "balance", MP_CMD_BALANCE
, 0, OSD_BALANCE
, -1, MSGTR_Balance
},
2087 { "fullscreen", MP_CMD_VO_FULLSCREEN
, 1, 0, -1, NULL
},
2088 { "panscan", MP_CMD_PANSCAN
, 0, OSD_PANSCAN
, -1, MSGTR_Panscan
},
2089 { "ontop", MP_CMD_VO_ONTOP
, 1, 0, -1, MSGTR_OnTopStatus
},
2090 { "rootwin", MP_CMD_VO_ROOTWIN
, 1, 0, -1, MSGTR_RootwinStatus
},
2091 { "border", MP_CMD_VO_BORDER
, 1, 0, -1, MSGTR_BorderStatus
},
2092 { "framedropping", MP_CMD_FRAMEDROPPING
, 1, 0, -1, MSGTR_FramedroppingStatus
},
2093 { "gamma", MP_CMD_GAMMA
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Gamma
},
2094 { "brightness", MP_CMD_BRIGHTNESS
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Brightness
},
2095 { "contrast", MP_CMD_CONTRAST
, 0, OSD_CONTRAST
, -1, MSGTR_Contrast
},
2096 { "saturation", MP_CMD_SATURATION
, 0, OSD_SATURATION
, -1, MSGTR_Saturation
},
2097 { "hue", MP_CMD_HUE
, 0, OSD_HUE
, -1, MSGTR_Hue
},
2098 { "vsync", MP_CMD_SWITCH_VSYNC
, 1, 0, -1, MSGTR_VSyncStatus
},
2100 { "sub", MP_CMD_SUB_SELECT
, 1, 0, -1, MSGTR_SubSelectStatus
},
2101 { "sub_source", MP_CMD_SUB_SOURCE
, 1, 0, -1, MSGTR_SubSourceStatus
},
2102 { "sub_vob", MP_CMD_SUB_VOB
, 1, 0, -1, MSGTR_SubSelectStatus
},
2103 { "sub_demux", MP_CMD_SUB_DEMUX
, 1, 0, -1, MSGTR_SubSelectStatus
},
2104 { "sub_file", MP_CMD_SUB_FILE
, 1, 0, -1, MSGTR_SubSelectStatus
},
2105 { "sub_pos", MP_CMD_SUB_POS
, 0, 0, -1, MSGTR_SubPosStatus
},
2106 { "sub_alignment", MP_CMD_SUB_ALIGNMENT
, 1, 0, -1, MSGTR_SubAlignStatus
},
2107 { "sub_delay", MP_CMD_SUB_DELAY
, 0, 0, OSD_MSG_SUB_DELAY
, MSGTR_SubDelayStatus
},
2108 { "sub_visibility", MP_CMD_SUB_VISIBILITY
, 1, 0, -1, MSGTR_SubVisibleStatus
},
2109 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY
, 1, 0, -1, MSGTR_SubForcedOnlyStatus
},
2110 #ifdef HAVE_FREETYPE
2111 { "sub_scale", MP_CMD_SUB_SCALE
, 0, 0, -1, MSGTR_SubScale
},
2114 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS
, 0, OSD_BRIGHTNESS
, -1, MSGTR_Brightness
},
2115 { "tv_hue", MP_CMD_TV_SET_HUE
, 0, OSD_HUE
, -1, MSGTR_Hue
},
2116 { "tv_saturation", MP_CMD_TV_SET_SATURATION
, 0, OSD_SATURATION
, -1, MSGTR_Saturation
},
2117 { "tv_contrast", MP_CMD_TV_SET_CONTRAST
, 0, OSD_CONTRAST
, -1, MSGTR_Contrast
},
2119 { NULL
, 0, 0, 0, -1, NULL
}
2123 /// Handle commands that set a property.
2124 static int set_property_command(MPContext
* mpctx
, mp_cmd_t
* cmd
)
2130 // look for the command
2131 for (i
= 0; set_prop_cmd
[i
].name
; i
++)
2132 if (set_prop_cmd
[i
].cmd
== cmd
->id
)
2134 if (!(pname
= set_prop_cmd
[i
].name
))
2137 if (mp_property_do(pname
,M_PROPERTY_GET_TYPE
,&prop
,mpctx
) <= 0 || !prop
)
2141 if (set_prop_cmd
[i
].toggle
) {
2143 if (cmd
->nargs
> 0 && cmd
->args
[0].v
.i
>= prop
->min
)
2144 r
= mp_property_do(pname
, M_PROPERTY_SET
, &cmd
->args
[0].v
.i
, mpctx
);
2146 r
= mp_property_do(pname
, M_PROPERTY_STEP_UP
, NULL
, mpctx
);
2147 } else if (cmd
->args
[1].v
.i
) //set
2148 r
= mp_property_do(pname
, M_PROPERTY_SET
, &cmd
->args
[0].v
, mpctx
);
2150 r
= mp_property_do(pname
, M_PROPERTY_STEP_UP
, &cmd
->args
[0].v
, mpctx
);
2155 if (set_prop_cmd
[i
].osd_progbar
) {
2156 if (prop
->type
== CONF_TYPE_INT
) {
2157 if (mp_property_do(pname
, M_PROPERTY_GET
, &r
, mpctx
) > 0)
2158 set_osd_bar(set_prop_cmd
[i
].osd_progbar
,
2159 set_prop_cmd
[i
].osd_msg
, prop
->min
, prop
->max
, r
);
2160 } else if (prop
->type
== CONF_TYPE_FLOAT
) {
2162 if (mp_property_do(pname
, M_PROPERTY_GET
, &f
, mpctx
) > 0)
2163 set_osd_bar(set_prop_cmd
[i
].osd_progbar
,
2164 set_prop_cmd
[i
].osd_msg
, prop
->min
, prop
->max
, f
);
2166 mp_msg(MSGT_CPLAYER
, MSGL_ERR
,
2167 "Property use an unsupported type.\n");
2171 if (set_prop_cmd
[i
].osd_msg
) {
2172 char *val
= mp_property_print(pname
, mpctx
);
2174 set_osd_msg(set_prop_cmd
[i
].osd_id
>=
2175 0 ? set_prop_cmd
[i
].osd_id
: OSD_MSG_PROPERTY
+ i
,
2176 1, osd_duration
, set_prop_cmd
[i
].osd_msg
, val
);
2184 int run_command(MPContext
* mpctx
, mp_cmd_t
* cmd
)
2186 sh_audio_t
* const sh_audio
= mpctx
->sh_audio
;
2187 sh_video_t
* const sh_video
= mpctx
->sh_video
;
2189 if (!set_property_command(mpctx
, cmd
))
2195 mpctx
->osd_show_percentage
= sh_video
->fps
;
2196 v
= cmd
->args
[0].v
.f
;
2197 abs
= (cmd
->nargs
> 1) ? cmd
->args
[1].v
.i
: 0;
2198 if (abs
== 2) { /* Absolute seek to a specific timestamp in seconds */
2201 mpctx
->osd_function
=
2202 (v
> sh_video
->pts
) ? OSD_FFW
: OSD_REW
;
2204 } else if (abs
) { /* Absolute seek by percentage */
2207 mpctx
->osd_function
= OSD_FFW
; // Direction isn't set correctly
2208 rel_seek_secs
= v
/ 100.0;
2211 mpctx
->osd_function
= (v
> 0) ? OSD_FFW
: OSD_REW
;
2217 case MP_CMD_SET_PROPERTY
:{
2218 int r
= mp_property_do(cmd
->args
[0].v
.s
, M_PROPERTY_PARSE
,
2219 cmd
->args
[1].v
.s
, mpctx
);
2220 if (r
== M_PROPERTY_UNKNOWN
)
2221 mp_msg(MSGT_CPLAYER
, MSGL_WARN
,
2222 "Unknown property: '%s'\n", cmd
->args
[0].v
.s
);
2224 mp_msg(MSGT_CPLAYER
, MSGL_WARN
,
2225 "Failed to set property '%s' to '%s'.\n",
2226 cmd
->args
[0].v
.s
, cmd
->args
[1].v
.s
);
2230 case MP_CMD_STEP_PROPERTY
:{
2235 if (cmd
->args
[1].v
.f
) {
2237 if((r
= mp_property_do(cmd
->args
[0].v
.s
,
2238 M_PROPERTY_GET_TYPE
,
2239 &prop
, mpctx
)) <= 0)
2241 if(prop
->type
== CONF_TYPE_INT
||
2242 prop
->type
== CONF_TYPE_FLAG
)
2243 i
= cmd
->args
[1].v
.f
, arg
= &i
;
2244 else if(prop
->type
== CONF_TYPE_FLOAT
)
2245 arg
= &cmd
->args
[1].v
.f
;
2246 else if(prop
->type
== CONF_TYPE_DOUBLE
||
2247 prop
->type
== CONF_TYPE_TIME
)
2248 d
= cmd
->args
[1].v
.f
, arg
= &d
;
2249 else if(prop
->type
== CONF_TYPE_POSITION
)
2250 o
= cmd
->args
[1].v
.f
, arg
= &o
;
2252 mp_msg(MSGT_CPLAYER
, MSGL_WARN
,
2253 "Ignoring step size stepping property '%s'.\n",
2256 r
= mp_property_do(cmd
->args
[0].v
.s
,
2257 cmd
->args
[2].v
.i
< 0 ?
2258 M_PROPERTY_STEP_DOWN
: M_PROPERTY_STEP_UP
,
2261 if (r
== M_PROPERTY_UNKNOWN
)
2262 mp_msg(MSGT_CPLAYER
, MSGL_WARN
,
2263 "Unknown property: '%s'\n", cmd
->args
[0].v
.s
);
2265 mp_msg(MSGT_CPLAYER
, MSGL_WARN
,
2266 "Failed to increment property '%s' by %f.\n",
2267 cmd
->args
[0].v
.s
, cmd
->args
[1].v
.f
);
2271 case MP_CMD_GET_PROPERTY
:{
2273 if (mp_property_do(cmd
->args
[0].v
.s
, M_PROPERTY_TO_STRING
,
2274 &tmp
, mpctx
) <= 0) {
2275 mp_msg(MSGT_CPLAYER
, MSGL_WARN
,
2276 "Failed to get value of property '%s'.\n",
2280 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_%s=%s\n",
2281 cmd
->args
[0].v
.s
, tmp
);
2286 case MP_CMD_EDL_MARK
:
2288 float v
= sh_video
? sh_video
->pts
:
2289 playing_audio_pts(sh_audio
, mpctx
->d_audio
,
2292 if (mpctx
->begin_skip
== MP_NOPTS_VALUE
) {
2293 mpctx
->begin_skip
= v
;
2294 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_EdloutStartSkip
);
2296 if (mpctx
->begin_skip
> v
)
2297 mp_msg(MSGT_CPLAYER
, MSGL_WARN
, MSGTR_EdloutBadStop
);
2299 fprintf(edl_fd
, "%f %f %d\n", mpctx
->begin_skip
, v
, 0);
2300 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, MSGTR_EdloutEndSkip
);
2302 mpctx
->begin_skip
= MP_NOPTS_VALUE
;
2307 case MP_CMD_SWITCH_RATIO
:
2308 if (cmd
->nargs
== 0 || cmd
->args
[0].v
.f
== -1)
2309 movie_aspect
= (float) sh_video
->disp_w
/ sh_video
->disp_h
;
2311 movie_aspect
= cmd
->args
[0].v
.f
;
2312 mpcodecs_config_vo(sh_video
, sh_video
->disp_w
, sh_video
->disp_h
, 0);
2315 case MP_CMD_SPEED_INCR
:{
2316 float v
= cmd
->args
[0].v
.f
;
2317 playback_speed
+= v
;
2318 build_afilter_chain(sh_audio
, &ao_data
);
2319 set_osd_msg(OSD_MSG_SPEED
, 1, osd_duration
, MSGTR_OSDSpeed
,
2323 case MP_CMD_SPEED_MULT
:{
2324 float v
= cmd
->args
[0].v
.f
;
2325 playback_speed
*= v
;
2326 build_afilter_chain(sh_audio
, &ao_data
);
2327 set_osd_msg(OSD_MSG_SPEED
, 1, osd_duration
, MSGTR_OSDSpeed
,
2331 case MP_CMD_SPEED_SET
:{
2332 float v
= cmd
->args
[0].v
.f
;
2334 build_afilter_chain(sh_audio
, &ao_data
);
2335 set_osd_msg(OSD_MSG_SPEED
, 1, osd_duration
, MSGTR_OSDSpeed
,
2339 case MP_CMD_FRAME_STEP
:
2345 case MP_CMD_FILE_FILTER
:
2346 file_filter
= cmd
->args
[0].v
.i
;
2350 exit_player_with_rc(MSGTR_Exit_quit
,
2351 (cmd
->nargs
> 0) ? cmd
->args
[0].v
.i
: 0);
2353 case MP_CMD_PLAY_TREE_STEP
:{
2354 int n
= cmd
->args
[0].v
.i
== 0 ? 1 : cmd
->args
[0].v
.i
;
2355 int force
= cmd
->args
[1].v
.i
;
2361 for (i
= 0; i
< n
; i
++)
2364 for (i
= 0; i
< -1 * n
; i
++)
2369 if (!force
&& mpctx
->playtree_iter
) {
2370 play_tree_iter_t
*i
=
2371 play_tree_iter_new_copy(mpctx
->playtree_iter
);
2372 if (play_tree_iter_step(i
, n
, 0) ==
2373 PLAY_TREE_ITER_ENTRY
)
2375 (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
2376 play_tree_iter_free(i
);
2378 mpctx
->eof
= (n
> 0) ? PT_NEXT_ENTRY
: PT_PREV_ENTRY
;
2380 mpctx
->play_tree_step
= n
;
2386 case MP_CMD_PLAY_TREE_UP_STEP
:{
2387 int n
= cmd
->args
[0].v
.i
> 0 ? 1 : -1;
2388 int force
= cmd
->args
[1].v
.i
;
2390 if (!force
&& mpctx
->playtree_iter
) {
2391 play_tree_iter_t
*i
=
2392 play_tree_iter_new_copy(mpctx
->playtree_iter
);
2393 if (play_tree_iter_up_step(i
, n
, 0) == PLAY_TREE_ITER_ENTRY
)
2394 mpctx
->eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
2395 play_tree_iter_free(i
);
2397 mpctx
->eof
= (n
> 0) ? PT_UP_NEXT
: PT_UP_PREV
;
2402 case MP_CMD_PLAY_ALT_SRC_STEP
:
2403 if (mpctx
->playtree_iter
&& mpctx
->playtree_iter
->num_files
> 1) {
2404 int v
= cmd
->args
[0].v
.i
;
2406 && mpctx
->playtree_iter
->file
<
2407 mpctx
->playtree_iter
->num_files
)
2408 mpctx
->eof
= PT_NEXT_SRC
;
2409 else if (v
< 0 && mpctx
->playtree_iter
->file
> 1)
2410 mpctx
->eof
= PT_PREV_SRC
;
2415 case MP_CMD_SUB_STEP
:
2417 int movement
= cmd
->args
[0].v
.i
;
2418 step_sub(subdata
, sh_video
->pts
, movement
);
2422 ass_step_sub(ass_track
,
2424 sub_delay
) * 1000 + .5, movement
) / 1000.;
2426 set_osd_msg(OSD_MSG_SUB_DELAY
, 1, osd_duration
,
2427 MSGTR_OSDSubDelay
, ROUND(sub_delay
* 1000));
2431 case MP_CMD_SUB_LOG
:
2436 int v
= cmd
->args
[0].v
.i
;
2438 && !sh_video
) ? MAX_TERM_OSD_LEVEL
: MAX_OSD_LEVEL
;
2439 if (osd_level
> max
)
2442 osd_level
= (osd_level
+ 1) % (max
+ 1);
2444 osd_level
= v
> max
? max
: v
;
2445 /* Show OSD state when disabled, but not when an explicit
2446 argument is given to the OSD command, i.e. in slave mode. */
2447 if (v
== -1 && osd_level
<= 1)
2448 set_osd_msg(OSD_MSG_OSD_STATUS
, 0, osd_duration
,
2450 osd_level
? MSGTR_OSDenabled
:
2453 rm_osd_msg(OSD_MSG_OSD_STATUS
);
2457 case MP_CMD_OSD_SHOW_TEXT
:
2458 set_osd_msg(OSD_MSG_TEXT
, cmd
->args
[2].v
.i
,
2460 0 ? osd_duration
: cmd
->args
[1].v
.i
),
2461 "%-.63s", cmd
->args
[0].v
.s
);
2464 case MP_CMD_OSD_SHOW_PROPERTY_TEXT
:{
2465 char *txt
= m_properties_expand_string(mp_properties
,
2468 /* if no argument supplied take default osd_duration, else <arg> ms. */
2470 set_osd_msg(OSD_MSG_TEXT
, cmd
->args
[2].v
.i
,
2472 0 ? osd_duration
: cmd
->args
[1].v
.i
),
2479 case MP_CMD_LOADFILE
:{
2480 play_tree_t
*e
= play_tree_new();
2481 play_tree_add_file(e
, cmd
->args
[0].v
.s
);
2483 if (cmd
->args
[1].v
.i
) // append
2484 play_tree_append_entry(mpctx
->playtree
, e
);
2486 // Go back to the starting point.
2487 while (play_tree_iter_up_step
2488 (mpctx
->playtree_iter
, 0, 1) != PLAY_TREE_ITER_END
)
2490 play_tree_free_list(mpctx
->playtree
->child
, 1);
2491 play_tree_set_child(mpctx
->playtree
, e
);
2492 play_tree_iter_step(mpctx
->playtree_iter
, 0, 0);
2493 mpctx
->eof
= PT_NEXT_SRC
;
2499 case MP_CMD_LOADLIST
:{
2500 play_tree_t
*e
= parse_playlist_file(cmd
->args
[0].v
.s
);
2502 mp_msg(MSGT_CPLAYER
, MSGL_ERR
,
2503 MSGTR_PlaylistLoadUnable
, cmd
->args
[0].v
.s
);
2505 if (cmd
->args
[1].v
.i
) // append
2506 play_tree_append_entry(mpctx
->playtree
, e
);
2508 // Go back to the starting point.
2509 while (play_tree_iter_up_step
2510 (mpctx
->playtree_iter
, 0, 1)
2511 != PLAY_TREE_ITER_END
)
2513 play_tree_free_list(mpctx
->playtree
->child
, 1);
2514 play_tree_set_child(mpctx
->playtree
, e
);
2515 play_tree_iter_step(mpctx
->playtree_iter
, 0, 0);
2516 mpctx
->eof
= PT_NEXT_SRC
;
2524 case MP_CMD_RADIO_STEP_CHANNEL
:
2525 if (mpctx
->demuxer
->stream
->type
== STREAMTYPE_RADIO
) {
2526 int v
= cmd
->args
[0].v
.i
;
2528 radio_step_channel(mpctx
->demuxer
->stream
,
2529 RADIO_CHANNEL_HIGHER
);
2531 radio_step_channel(mpctx
->demuxer
->stream
,
2532 RADIO_CHANNEL_LOWER
);
2533 if (radio_get_channel_name(mpctx
->demuxer
->stream
)) {
2534 set_osd_msg(OSD_MSG_RADIO_CHANNEL
, 1, osd_duration
,
2536 radio_get_channel_name(mpctx
->demuxer
->stream
));
2541 case MP_CMD_RADIO_SET_CHANNEL
:
2542 if (mpctx
->demuxer
->stream
->type
== STREAMTYPE_RADIO
) {
2543 radio_set_channel(mpctx
->demuxer
->stream
, cmd
->args
[0].v
.s
);
2544 if (radio_get_channel_name(mpctx
->demuxer
->stream
)) {
2545 set_osd_msg(OSD_MSG_RADIO_CHANNEL
, 1, osd_duration
,
2547 radio_get_channel_name(mpctx
->demuxer
->stream
));
2552 case MP_CMD_RADIO_SET_FREQ
:
2553 if (mpctx
->demuxer
->stream
->type
== STREAMTYPE_RADIO
)
2554 radio_set_freq(mpctx
->demuxer
->stream
, cmd
->args
[0].v
.f
);
2557 case MP_CMD_RADIO_STEP_FREQ
:
2558 if (mpctx
->demuxer
->stream
->type
== STREAMTYPE_RADIO
)
2559 radio_step_freq(mpctx
->demuxer
->stream
, cmd
->args
[0].v
.f
);
2564 case MP_CMD_TV_START_SCAN
:
2565 if (mpctx
->file_format
== DEMUXER_TYPE_TV
)
2566 tv_start_scan((tvi_handle_t
*) (mpctx
->demuxer
->priv
),1);
2568 case MP_CMD_TV_SET_FREQ
:
2569 if (mpctx
->file_format
== DEMUXER_TYPE_TV
)
2570 tv_set_freq((tvi_handle_t
*) (mpctx
->demuxer
->priv
),
2571 cmd
->args
[0].v
.f
* 16.0);
2573 else if (mpctx
->stream
&& mpctx
->stream
->type
== STREAMTYPE_PVR
) {
2574 pvr_set_freq (mpctx
->stream
, ROUND (cmd
->args
[0].v
.f
));
2575 set_osd_msg (OSD_MSG_TV_CHANNEL
, 1, osd_duration
, "%s: %s",
2576 pvr_get_current_channelname (mpctx
->stream
),
2577 pvr_get_current_stationname (mpctx
->stream
));
2579 #endif /* HAVE_PVR */
2582 case MP_CMD_TV_STEP_FREQ
:
2583 if (mpctx
->file_format
== DEMUXER_TYPE_TV
)
2584 tv_step_freq((tvi_handle_t
*) (mpctx
->demuxer
->priv
),
2585 cmd
->args
[0].v
.f
* 16.0);
2587 else if (mpctx
->stream
&& mpctx
->stream
->type
== STREAMTYPE_PVR
) {
2588 pvr_force_freq_step (mpctx
->stream
, ROUND (cmd
->args
[0].v
.f
));
2589 set_osd_msg (OSD_MSG_TV_CHANNEL
, 1, osd_duration
, "%s: f %d",
2590 pvr_get_current_channelname (mpctx
->stream
),
2591 pvr_get_current_frequency (mpctx
->stream
));
2593 #endif /* HAVE_PVR */
2596 case MP_CMD_TV_SET_NORM
:
2597 if (mpctx
->file_format
== DEMUXER_TYPE_TV
)
2598 tv_set_norm((tvi_handle_t
*) (mpctx
->demuxer
->priv
),
2602 case MP_CMD_TV_STEP_CHANNEL
:{
2603 if (mpctx
->file_format
== DEMUXER_TYPE_TV
) {
2604 int v
= cmd
->args
[0].v
.i
;
2606 tv_step_channel((tvi_handle_t
*) (mpctx
->
2610 tv_step_channel((tvi_handle_t
*) (mpctx
->
2614 if (tv_channel_list
) {
2615 set_osd_msg(OSD_MSG_TV_CHANNEL
, 1, osd_duration
,
2616 MSGTR_OSDChannel
, tv_channel_current
->name
);
2617 //vo_osd_changed(OSDTYPE_SUBTITLE);
2621 else if (mpctx
->stream
&&
2622 mpctx
->stream
->type
== STREAMTYPE_PVR
) {
2623 pvr_set_channel_step (mpctx
->stream
, cmd
->args
[0].v
.i
);
2624 set_osd_msg (OSD_MSG_TV_CHANNEL
, 1, osd_duration
, "%s: %s",
2625 pvr_get_current_channelname (mpctx
->stream
),
2626 pvr_get_current_stationname (mpctx
->stream
));
2628 #endif /* HAVE_PVR */
2630 #ifdef HAS_DVBIN_SUPPORT
2631 if (mpctx
->stream
->type
== STREAMTYPE_DVB
) {
2633 int v
= cmd
->args
[0].v
.i
;
2635 mpctx
->last_dvb_step
= v
;
2637 dir
= DVB_CHANNEL_HIGHER
;
2639 dir
= DVB_CHANNEL_LOWER
;
2642 if (dvb_step_channel(mpctx
->stream
, dir
))
2643 mpctx
->eof
= mpctx
->dvbin_reopen
= 1;
2645 #endif /* HAS_DVBIN_SUPPORT */
2648 case MP_CMD_TV_SET_CHANNEL
:
2649 if (mpctx
->file_format
== DEMUXER_TYPE_TV
) {
2650 tv_set_channel((tvi_handle_t
*) (mpctx
->demuxer
->priv
),
2652 if (tv_channel_list
) {
2653 set_osd_msg(OSD_MSG_TV_CHANNEL
, 1, osd_duration
,
2654 MSGTR_OSDChannel
, tv_channel_current
->name
);
2655 //vo_osd_changed(OSDTYPE_SUBTITLE);
2659 else if (mpctx
->stream
&& mpctx
->stream
->type
== STREAMTYPE_PVR
) {
2660 pvr_set_channel (mpctx
->stream
, cmd
->args
[0].v
.s
);
2661 set_osd_msg (OSD_MSG_TV_CHANNEL
, 1, osd_duration
, "%s: %s",
2662 pvr_get_current_channelname (mpctx
->stream
),
2663 pvr_get_current_stationname (mpctx
->stream
));
2665 #endif /* HAVE_PVR */
2668 #ifdef HAS_DVBIN_SUPPORT
2669 case MP_CMD_DVB_SET_CHANNEL
:
2670 if (mpctx
->stream
->type
== STREAMTYPE_DVB
) {
2671 mpctx
->last_dvb_step
= 1;
2674 (mpctx
->stream
, cmd
->args
[1].v
.i
, cmd
->args
[0].v
.i
))
2675 mpctx
->eof
= mpctx
->dvbin_reopen
= 1;
2678 #endif /* HAS_DVBIN_SUPPORT */
2680 case MP_CMD_TV_LAST_CHANNEL
:
2681 if (mpctx
->file_format
== DEMUXER_TYPE_TV
) {
2682 tv_last_channel((tvi_handle_t
*) (mpctx
->demuxer
->priv
));
2683 if (tv_channel_list
) {
2684 set_osd_msg(OSD_MSG_TV_CHANNEL
, 1, osd_duration
,
2685 MSGTR_OSDChannel
, tv_channel_current
->name
);
2686 //vo_osd_changed(OSDTYPE_SUBTITLE);
2690 else if (mpctx
->stream
&& mpctx
->stream
->type
== STREAMTYPE_PVR
) {
2691 pvr_set_lastchannel (mpctx
->stream
);
2692 set_osd_msg (OSD_MSG_TV_CHANNEL
, 1, osd_duration
, "%s: %s",
2693 pvr_get_current_channelname (mpctx
->stream
),
2694 pvr_get_current_stationname (mpctx
->stream
));
2696 #endif /* HAVE_PVR */
2699 case MP_CMD_TV_STEP_NORM
:
2700 if (mpctx
->file_format
== DEMUXER_TYPE_TV
)
2701 tv_step_norm((tvi_handle_t
*) (mpctx
->demuxer
->priv
));
2704 case MP_CMD_TV_STEP_CHANNEL_LIST
:
2705 if (mpctx
->file_format
== DEMUXER_TYPE_TV
)
2706 tv_step_chanlist((tvi_handle_t
*) (mpctx
->demuxer
->priv
));
2708 #ifdef HAVE_TV_TELETEXT
2709 case MP_CMD_TV_TELETEXT_ADD_DEC
:
2711 tvi_handle_t
* tvh
=(tvi_handle_t
*)(mpctx
->demuxer
->priv
);
2712 if (mpctx
->file_format
== DEMUXER_TYPE_TV
)
2713 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_ADD_DEC
,&(cmd
->args
[0].v
.s
));
2716 case MP_CMD_TV_TELETEXT_GO_LINK
:
2718 tvi_handle_t
* tvh
=(tvi_handle_t
*)(mpctx
->demuxer
->priv
);
2719 if (mpctx
->file_format
== DEMUXER_TYPE_TV
)
2720 tvh
->functions
->control(tvh
->priv
,TV_VBI_CONTROL_GO_LINK
,&(cmd
->args
[0].v
.i
));
2723 #endif /* HAVE_TV_TELETEXT */
2726 case MP_CMD_SUB_LOAD
:
2728 int n
= mpctx
->set_of_sub_size
;
2729 add_subtitles(cmd
->args
[0].v
.s
, sh_video
->fps
, 0);
2730 if (n
!= mpctx
->set_of_sub_size
) {
2731 if (mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] < 0)
2732 mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] =
2733 mpctx
->global_sub_size
;
2734 ++mpctx
->global_sub_size
;
2739 case MP_CMD_SUB_REMOVE
:
2741 int v
= cmd
->args
[0].v
.i
;
2744 for (v
= 0; v
< mpctx
->set_of_sub_size
; ++v
) {
2745 subd
= mpctx
->set_of_subtitles
[v
];
2746 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
,
2747 MSGTR_RemovedSubtitleFile
, v
+ 1,
2748 filename_recode(subd
->filename
));
2750 mpctx
->set_of_subtitles
[v
] = NULL
;
2752 mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
2753 mpctx
->global_sub_size
-= mpctx
->set_of_sub_size
;
2754 mpctx
->set_of_sub_size
= 0;
2755 if (mpctx
->set_of_sub_pos
>= 0) {
2756 mpctx
->global_sub_pos
= -2;
2758 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2760 } else if (v
< mpctx
->set_of_sub_size
) {
2761 subd
= mpctx
->set_of_subtitles
[v
];
2762 mp_msg(MSGT_CPLAYER
, MSGL_STATUS
,
2763 MSGTR_RemovedSubtitleFile
, v
+ 1,
2764 filename_recode(subd
->filename
));
2766 if (mpctx
->set_of_sub_pos
== v
) {
2767 mpctx
->global_sub_pos
= -2;
2769 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2770 } else if (mpctx
->set_of_sub_pos
> v
) {
2771 --mpctx
->set_of_sub_pos
;
2772 --mpctx
->global_sub_pos
;
2774 while (++v
< mpctx
->set_of_sub_size
)
2775 mpctx
->set_of_subtitles
[v
- 1] =
2776 mpctx
->set_of_subtitles
[v
];
2777 --mpctx
->set_of_sub_size
;
2778 --mpctx
->global_sub_size
;
2779 if (mpctx
->set_of_sub_size
<= 0)
2780 mpctx
->global_sub_indices
[SUB_SOURCE_SUBS
] = -1;
2781 mpctx
->set_of_subtitles
[mpctx
->set_of_sub_size
] = NULL
;
2786 case MP_CMD_GET_SUB_VISIBILITY
:
2788 mp_msg(MSGT_GLOBAL
, MSGL_INFO
,
2789 "ANS_SUB_VISIBILITY=%d\n", sub_visibility
);
2793 case MP_CMD_SCREENSHOT
:
2794 if (vo_config_count
) {
2795 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "sending VFCTRL_SCREENSHOT!\n");
2797 ((vf_instance_t
*) sh_video
->vfilter
)->
2798 control(sh_video
->vfilter
, VFCTRL_SCREENSHOT
,
2800 mp_msg(MSGT_CPLAYER
, MSGL_INFO
, "failed (forgot -vf screenshot?)\n");
2804 case MP_CMD_VF_CHANGE_RECTANGLE
:
2805 set_rectangle(sh_video
, cmd
->args
[0].v
.i
, cmd
->args
[1].v
.i
);
2808 case MP_CMD_GET_TIME_LENGTH
:{
2809 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_LENGTH=%.2lf\n",
2810 demuxer_get_time_length(mpctx
->demuxer
));
2814 case MP_CMD_GET_FILENAME
:{
2815 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_FILENAME='%s'\n",
2816 get_metadata(META_NAME
));
2820 case MP_CMD_GET_VIDEO_CODEC
:{
2821 char *inf
= get_metadata(META_VIDEO_CODEC
);
2824 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_VIDEO_CODEC='%s'\n", inf
);
2829 case MP_CMD_GET_VIDEO_BITRATE
:{
2830 char *inf
= get_metadata(META_VIDEO_BITRATE
);
2833 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_VIDEO_BITRATE='%s'\n", inf
);
2838 case MP_CMD_GET_VIDEO_RESOLUTION
:{
2839 char *inf
= get_metadata(META_VIDEO_RESOLUTION
);
2842 mp_msg(MSGT_GLOBAL
, MSGL_INFO
,
2843 "ANS_VIDEO_RESOLUTION='%s'\n", inf
);
2848 case MP_CMD_GET_AUDIO_CODEC
:{
2849 char *inf
= get_metadata(META_AUDIO_CODEC
);
2852 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_AUDIO_CODEC='%s'\n", inf
);
2857 case MP_CMD_GET_AUDIO_BITRATE
:{
2858 char *inf
= get_metadata(META_AUDIO_BITRATE
);
2861 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_AUDIO_BITRATE='%s'\n", inf
);
2866 case MP_CMD_GET_AUDIO_SAMPLES
:{
2867 char *inf
= get_metadata(META_AUDIO_SAMPLES
);
2870 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_AUDIO_SAMPLES='%s'\n", inf
);
2875 case MP_CMD_GET_META_TITLE
:{
2876 char *inf
= get_metadata(META_INFO_TITLE
);
2879 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_META_TITLE='%s'\n", inf
);
2884 case MP_CMD_GET_META_ARTIST
:{
2885 char *inf
= get_metadata(META_INFO_ARTIST
);
2888 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_META_ARTIST='%s'\n", inf
);
2893 case MP_CMD_GET_META_ALBUM
:{
2894 char *inf
= get_metadata(META_INFO_ALBUM
);
2897 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_META_ALBUM='%s'\n", inf
);
2902 case MP_CMD_GET_META_YEAR
:{
2903 char *inf
= get_metadata(META_INFO_YEAR
);
2906 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_META_YEAR='%s'\n", inf
);
2911 case MP_CMD_GET_META_COMMENT
:{
2912 char *inf
= get_metadata(META_INFO_COMMENT
);
2915 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_META_COMMENT='%s'\n", inf
);
2920 case MP_CMD_GET_META_TRACK
:{
2921 char *inf
= get_metadata(META_INFO_TRACK
);
2924 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_META_TRACK='%s'\n", inf
);
2929 case MP_CMD_GET_META_GENRE
:{
2930 char *inf
= get_metadata(META_INFO_GENRE
);
2933 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_META_GENRE='%s'\n", inf
);
2938 case MP_CMD_GET_VO_FULLSCREEN
:
2939 if (mpctx
->video_out
&& vo_config_count
)
2940 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_VO_FULLSCREEN=%d\n", vo_fs
);
2943 case MP_CMD_GET_PERCENT_POS
:
2944 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_PERCENT_POSITION=%d\n",
2945 demuxer_get_percent_pos(mpctx
->demuxer
));
2948 case MP_CMD_GET_TIME_POS
:{
2951 pos
= sh_video
->pts
;
2952 else if (sh_audio
&& mpctx
->audio_out
)
2954 playing_audio_pts(sh_audio
, mpctx
->d_audio
,
2956 mp_msg(MSGT_GLOBAL
, MSGL_INFO
, "ANS_TIME_POSITION=%.1f\n", pos
);
2963 execl("/bin/sh", "sh", "-c", cmd
->args
[0].v
.s
, NULL
);
2969 case MP_CMD_KEYDOWN_EVENTS
:
2970 mplayer_put_key(cmd
->args
[0].v
.i
);
2973 case MP_CMD_SET_MOUSE_POS
:{
2974 int pointer_x
, pointer_y
;
2976 pointer_x
= cmd
->args
[0].v
.i
;
2977 pointer_y
= cmd
->args
[1].v
.i
;
2978 rescale_input_coordinates(pointer_x
, pointer_y
, &dx
, &dy
);
2980 if (mpctx
->stream
->type
== STREAMTYPE_DVDNAV
2981 && dx
> 0.0 && dy
> 0.0) {
2983 pointer_x
= (int) (dx
* (double) sh_video
->disp_w
);
2984 pointer_y
= (int) (dy
* (double) sh_video
->disp_h
);
2985 mp_dvdnav_update_mouse_pos(mpctx
->stream
,
2986 pointer_x
, pointer_y
, &button
);
2988 set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
,
2989 "Selected button number %d", button
);
2996 case MP_CMD_DVDNAV
:{
2998 if (mpctx
->stream
->type
!= STREAMTYPE_DVDNAV
)
3001 if (mp_dvdnav_handle_input
3002 (mpctx
->stream
, cmd
->args
[0].v
.i
, &button
)) {
3003 uninit_player(INITED_ALL
- (INITED_STREAM
| INITED_INPUT
|
3004 (fixed_vo
? INITED_VO
: 0)));
3006 } else if (button
> 0)
3007 set_osd_msg(OSD_MSG_TEXT
, 1, osd_duration
,
3008 "Selected button number %d", button
);
3015 if ((use_gui
) && (cmd
->id
> MP_CMD_GUI_EVENTS
))
3016 guiGetEvent(guiIEvent
, (char *) cmd
->id
);
3019 mp_msg(MSGT_CPLAYER
, MSGL_V
,
3020 "Received unknown cmd %s\n", cmd
->name
);
3023 switch (cmd
->pausing
) {
3024 case 1: // "pausing"
3025 mpctx
->osd_function
= OSD_PAUSE
;
3027 case 3: // "pausing_toggle"
3028 mpctx
->was_paused
= !mpctx
->was_paused
;
3029 if (mpctx
->was_paused
)
3030 mpctx
->osd_function
= OSD_PAUSE
;
3031 else if (mpctx
->osd_function
== OSD_PAUSE
)
3032 mpctx
->osd_function
= OSD_PLAY
;
3034 case 2: // "pausing_keep"
3035 if (mpctx
->was_paused
)
3036 mpctx
->osd_function
= OSD_PAUSE
;