synced with r27771
[mplayer.git] / command.c
blob25b9231b1bd413ce12ba4073a4a427bf7ef7f689
1 #include <stdlib.h>
2 #include <inttypes.h>
3 #include <unistd.h>
4 #include <string.h>
6 #include "config.h"
7 #include "command.h"
8 #include "input/input.h"
9 #include "stream/stream.h"
10 #include "libmpdemux/demuxer.h"
11 #include "libmpdemux/stheader.h"
12 #include "codec-cfg.h"
13 #include "mplayer.h"
14 #include "libvo/sub.h"
15 #include "m_option.h"
16 #include "m_property.h"
17 #include "help_mp.h"
18 #include "metadata.h"
19 #include "libmpcodecs/vf.h"
20 #include "libmpcodecs/vd.h"
21 #include "libvo/video_out.h"
22 #include "libvo/font_load.h"
23 #include "playtree.h"
24 #include "libao2/audio_out.h"
25 #include "mpcommon.h"
26 #include "mixer.h"
27 #include "libmpcodecs/dec_video.h"
28 #include "vobsub.h"
29 #include "spudec.h"
30 #include "get_path.h"
31 #ifdef CONFIG_TV
32 #include "stream/tv.h"
33 #endif
34 #ifdef CONFIG_RADIO
35 #include "stream/stream_radio.h"
36 #endif
37 #ifdef CONFIG_PVR
38 #include "stream/pvr.h"
39 #endif
40 #ifdef CONFIG_DVBIN
41 #include "stream/dvbin.h"
42 #endif
43 #ifdef CONFIG_DVDREAD
44 #include "stream/stream_dvd.h"
45 #endif
46 #ifdef CONFIG_DVDNAV
47 #include "stream/stream_dvdnav.h"
48 #endif
49 #ifdef CONFIG_ASS
50 #include "libass/ass.h"
51 #include "libass/ass_mp.h"
52 #endif
53 #ifdef CONFIG_MENU
54 #include "m_struct.h"
55 #include "libmenu/menu.h"
56 #endif
57 #ifdef CONFIG_GUI
58 #include "gui/interface.h"
59 #endif
61 #include "mp_core.h"
62 #include "mp_fifo.h"
63 #include "libavutil/avstring.h"
65 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
67 extern int use_menu;
69 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy)
71 //remove the borders, if any, and rescale to the range [0,1],[0,1]
72 if (vo_fs) { //we are in full-screen mode
73 if (vo_screenwidth > vo_dwidth) //there are borders along the x axis
74 ix -= (vo_screenwidth - vo_dwidth) / 2;
75 if (vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
76 iy -= (vo_screenheight - vo_dheight) / 2;
78 if (ix < 0 || ix > vo_dwidth) {
79 *dx = *dy = -1.0;
80 return;
81 } //we are on one of the borders
82 if (iy < 0 || iy > vo_dheight) {
83 *dx = *dy = -1.0;
84 return;
85 } //we are on one of the borders
88 *dx = (double) ix / (double) vo_dwidth;
89 *dy = (double) iy / (double) vo_dheight;
91 mp_msg(MSGT_CPLAYER, MSGL_V,
92 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
93 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth,
94 vo_dheight, vo_fs);
97 static int sub_source_by_pos(MPContext * mpctx, int pos)
99 int source = -1;
100 int top = -1;
101 int i;
102 for (i = 0; i < SUB_SOURCES; i++) {
103 int j = mpctx->global_sub_indices[i];
104 if ((j >= 0) && (j > top) && (pos >= j)) {
105 source = i;
106 top = j;
109 return source;
112 static int sub_source(MPContext * mpctx)
114 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
118 * \brief Log the currently displayed subtitle to a file
120 * Logs the current or last displayed subtitle together with filename
121 * and time information to ~/.mplayer/subtitle_log
123 * Intended purpose is to allow convenient marking of bogus subtitles
124 * which need to be fixed while watching the movie.
127 static void log_sub(void)
129 char *fname;
130 FILE *f;
131 int i;
133 if (subdata == NULL || vo_sub_last == NULL)
134 return;
135 fname = get_path("subtitle_log");
136 f = fopen(fname, "a");
137 if (!f)
138 return;
139 fprintf(f, "----------------------------------------------------------\n");
140 if (subdata->sub_uses_time) {
141 fprintf(f,
142 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
143 filename, vo_sub_last->start / 360000,
144 (vo_sub_last->start / 6000) % 60,
145 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
146 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
147 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
148 } else {
149 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start,
150 vo_sub_last->end);
152 for (i = 0; i < vo_sub_last->lines; i++) {
153 fprintf(f, "%s\n", vo_sub_last->text[i]);
155 fclose(f);
159 /// \defgroup Properties
160 ///@{
162 /// \defgroup GeneralProperties General properties
163 /// \ingroup Properties
164 ///@{
166 /// OSD level (RW)
167 static int mp_property_osdlevel(m_option_t * prop, int action, void *arg,
168 MPContext * mpctx)
170 return m_property_choice(prop, action, arg, &osd_level);
173 /// Loop (RW)
174 static int mp_property_loop(m_option_t * prop, int action, void *arg,
175 MPContext * mpctx)
177 switch (action) {
178 case M_PROPERTY_PRINT:
179 if (!arg) return M_PROPERTY_ERROR;
180 if (mpctx->loop_times < 0)
181 *(char**)arg = strdup("off");
182 else if (mpctx->loop_times == 0)
183 *(char**)arg = strdup("inf");
184 else
185 break;
186 return M_PROPERTY_OK;
188 return m_property_int_range(prop, action, arg, &mpctx->loop_times);
191 /// Playback speed (RW)
192 static int mp_property_playback_speed(m_option_t * prop, int action,
193 void *arg, MPContext * mpctx)
195 switch (action) {
196 case M_PROPERTY_SET:
197 if (!arg)
198 return M_PROPERTY_ERROR;
199 M_PROPERTY_CLAMP(prop, *(float *) arg);
200 playback_speed = *(float *) arg;
201 build_afilter_chain(mpctx->sh_audio, &ao_data);
202 return M_PROPERTY_OK;
203 case M_PROPERTY_STEP_UP:
204 case M_PROPERTY_STEP_DOWN:
205 playback_speed += (arg ? *(float *) arg : 0.1) *
206 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
207 M_PROPERTY_CLAMP(prop, playback_speed);
208 build_afilter_chain(mpctx->sh_audio, &ao_data);
209 return M_PROPERTY_OK;
211 return m_property_float_range(prop, action, arg, &playback_speed);
214 /// filename with path (RO)
215 static int mp_property_path(m_option_t * prop, int action, void *arg,
216 MPContext * mpctx)
218 return m_property_string_ro(prop, action, arg, filename);
221 /// filename without path (RO)
222 static int mp_property_filename(m_option_t * prop, int action, void *arg,
223 MPContext * mpctx)
225 char *f;
226 if (!filename)
227 return M_PROPERTY_UNAVAILABLE;
228 if (((f = strrchr(filename, '/')) || (f = strrchr(filename, '\\'))) && f[1])
229 f++;
230 else
231 f = filename;
232 return m_property_string_ro(prop, action, arg, f);
235 /// Demuxer name (RO)
236 static int mp_property_demuxer(m_option_t * prop, int action, void *arg,
237 MPContext * mpctx)
239 if (!mpctx->demuxer)
240 return M_PROPERTY_UNAVAILABLE;
241 return m_property_string_ro(prop, action, arg,
242 (char *) mpctx->demuxer->desc->name);
245 /// Position in the stream (RW)
246 static int mp_property_stream_pos(m_option_t * prop, int action, void *arg,
247 MPContext * mpctx)
249 if (!mpctx->demuxer || !mpctx->demuxer->stream)
250 return M_PROPERTY_UNAVAILABLE;
251 if (!arg)
252 return M_PROPERTY_ERROR;
253 switch (action) {
254 case M_PROPERTY_GET:
255 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
256 return M_PROPERTY_OK;
257 case M_PROPERTY_SET:
258 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
259 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
260 return M_PROPERTY_OK;
262 return M_PROPERTY_NOT_IMPLEMENTED;
265 /// Stream start offset (RO)
266 static int mp_property_stream_start(m_option_t * prop, int action,
267 void *arg, MPContext * mpctx)
269 if (!mpctx->demuxer || !mpctx->demuxer->stream)
270 return M_PROPERTY_UNAVAILABLE;
271 switch (action) {
272 case M_PROPERTY_GET:
273 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
274 return M_PROPERTY_OK;
276 return M_PROPERTY_NOT_IMPLEMENTED;
279 /// Stream end offset (RO)
280 static int mp_property_stream_end(m_option_t * prop, int action, void *arg,
281 MPContext * mpctx)
283 if (!mpctx->demuxer || !mpctx->demuxer->stream)
284 return M_PROPERTY_UNAVAILABLE;
285 switch (action) {
286 case M_PROPERTY_GET:
287 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
288 return M_PROPERTY_OK;
290 return M_PROPERTY_NOT_IMPLEMENTED;
293 /// Stream length (RO)
294 static int mp_property_stream_length(m_option_t * prop, int action,
295 void *arg, MPContext * mpctx)
297 if (!mpctx->demuxer || !mpctx->demuxer->stream)
298 return M_PROPERTY_UNAVAILABLE;
299 switch (action) {
300 case M_PROPERTY_GET:
301 *(off_t *) arg =
302 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
303 return M_PROPERTY_OK;
305 return M_PROPERTY_NOT_IMPLEMENTED;
308 /// Media length in seconds (RO)
309 static int mp_property_length(m_option_t * prop, int action, void *arg,
310 MPContext * mpctx)
312 double len;
314 if (!mpctx->demuxer ||
315 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
316 return M_PROPERTY_UNAVAILABLE;
318 return m_property_time_ro(prop, action, arg, len);
321 /// Current position in percent (RW)
322 static int mp_property_percent_pos(m_option_t * prop, int action,
323 void *arg, MPContext * mpctx) {
324 int pos;
326 if (!mpctx->demuxer)
327 return M_PROPERTY_UNAVAILABLE;
329 switch(action) {
330 case M_PROPERTY_SET:
331 if(!arg) return M_PROPERTY_ERROR;
332 M_PROPERTY_CLAMP(prop, *(int*)arg);
333 pos = *(int*)arg;
334 break;
335 case M_PROPERTY_STEP_UP:
336 case M_PROPERTY_STEP_DOWN:
337 pos = demuxer_get_percent_pos(mpctx->demuxer);
338 pos += (arg ? *(int*)arg : 10) *
339 (action == M_PROPERTY_STEP_UP ? 1 : -1);
340 M_PROPERTY_CLAMP(prop, pos);
341 break;
342 default:
343 return m_property_int_ro(prop, action, arg,
344 demuxer_get_percent_pos(mpctx->demuxer));
347 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
348 rel_seek_secs = pos / 100.0;
349 return M_PROPERTY_OK;
352 /// Current position in seconds (RW)
353 static int mp_property_time_pos(m_option_t * prop, int action,
354 void *arg, MPContext * mpctx) {
355 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
356 return M_PROPERTY_UNAVAILABLE;
358 switch(action) {
359 case M_PROPERTY_SET:
360 if(!arg) return M_PROPERTY_ERROR;
361 M_PROPERTY_CLAMP(prop, *(double*)arg);
362 abs_seek_pos = SEEK_ABSOLUTE;
363 rel_seek_secs = *(double*)arg;
364 return M_PROPERTY_OK;
365 case M_PROPERTY_STEP_UP:
366 case M_PROPERTY_STEP_DOWN:
367 rel_seek_secs += (arg ? *(double*)arg : 10.0) *
368 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
369 return M_PROPERTY_OK;
371 return m_property_time_ro(prop, action, arg,
372 mpctx->sh_video ? mpctx->sh_video->pts :
373 playing_audio_pts(mpctx->sh_audio,
374 mpctx->d_audio,
375 mpctx->audio_out));
378 /// Current chapter (RW)
379 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
380 MPContext *mpctx)
382 int chapter = -1;
383 float next_pts = 0;
384 int chapter_num;
385 int step_all;
386 char *chapter_name = NULL;
388 if (mpctx->demuxer)
389 chapter = demuxer_get_current_chapter(mpctx->demuxer);
390 if (chapter < 0)
391 return M_PROPERTY_UNAVAILABLE;
393 switch (action) {
394 case M_PROPERTY_GET:
395 if (!arg)
396 return M_PROPERTY_ERROR;
397 *(int *) arg = chapter;
398 return M_PROPERTY_OK;
399 case M_PROPERTY_PRINT: {
400 if (!arg)
401 return M_PROPERTY_ERROR;
402 chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter);
403 if (!chapter_name)
404 return M_PROPERTY_UNAVAILABLE;
405 *(char **) arg = chapter_name;
406 return M_PROPERTY_OK;
408 case M_PROPERTY_SET:
409 if (!arg)
410 return M_PROPERTY_ERROR;
411 M_PROPERTY_CLAMP(prop, *(int*)arg);
412 step_all = *(int *)arg - (chapter + 1);
413 chapter += step_all;
414 break;
415 case M_PROPERTY_STEP_UP:
416 case M_PROPERTY_STEP_DOWN: {
417 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
418 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
419 chapter += step_all;
420 if (chapter < 0)
421 chapter = 0;
422 break;
424 default:
425 return M_PROPERTY_NOT_IMPLEMENTED;
427 rel_seek_secs = 0;
428 abs_seek_pos = 0;
429 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
430 &next_pts, &chapter_num, &chapter_name);
431 if (chapter >= 0) {
432 if (next_pts > -1.0) {
433 abs_seek_pos = SEEK_ABSOLUTE;
434 rel_seek_secs = next_pts;
436 if (chapter_name)
437 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
438 MSGTR_OSDChapter, chapter + 1, chapter_name);
440 else if (step_all > 0)
441 rel_seek_secs = 1000000000.;
442 else
443 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
444 MSGTR_OSDChapter, 0, MSGTR_Unknown);
445 if (chapter_name)
446 free(chapter_name);
447 return M_PROPERTY_OK;
450 /// Number of chapters in file
451 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
452 MPContext *mpctx)
454 if (!mpctx->demuxer)
455 return M_PROPERTY_UNAVAILABLE;
456 if (mpctx->demuxer->num_chapters == 0)
457 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
458 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
461 /// Current dvd angle (RW)
462 static int mp_property_angle(m_option_t *prop, int action, void *arg,
463 MPContext *mpctx)
465 int angle = -1;
466 int angles;
467 char *angle_name = NULL;
469 if (mpctx->demuxer)
470 angle = demuxer_get_current_angle(mpctx->demuxer);
471 if (angle < 0)
472 return M_PROPERTY_UNAVAILABLE;
473 angles = demuxer_angles_count(mpctx->demuxer);
474 if (angles <= 1)
475 return M_PROPERTY_UNAVAILABLE;
477 switch (action) {
478 case M_PROPERTY_GET:
479 if (!arg)
480 return M_PROPERTY_ERROR;
481 *(int *) arg = angle;
482 return M_PROPERTY_OK;
483 case M_PROPERTY_PRINT: {
484 if (!arg)
485 return M_PROPERTY_ERROR;
486 angle_name = calloc(1, 64);
487 if (!angle_name)
488 return M_PROPERTY_UNAVAILABLE;
489 snprintf(angle_name, 64, "%d/%d", angle, angles);
490 *(char **) arg = angle_name;
491 return M_PROPERTY_OK;
493 case M_PROPERTY_SET:
494 if (!arg)
495 return M_PROPERTY_ERROR;
496 angle = *(int *)arg;
497 M_PROPERTY_CLAMP(prop, angle);
498 break;
499 case M_PROPERTY_STEP_UP:
500 case M_PROPERTY_STEP_DOWN: {
501 int step = 0;
502 if(arg)
503 step = *(int*)arg;
504 if(!step)
505 step = 1;
506 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
507 angle += step;
508 if (angle < 1) //cycle
509 angle = angles;
510 break;
512 default:
513 return M_PROPERTY_NOT_IMPLEMENTED;
515 angle = demuxer_set_angle(mpctx->demuxer, angle);
516 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
517 MSGTR_OSDAngle, angle, angles);
518 if (angle_name)
519 free(angle_name);
520 return M_PROPERTY_OK;
523 /// Demuxer meta data
524 static int mp_property_metadata(m_option_t * prop, int action, void *arg,
525 MPContext * mpctx) {
526 m_property_action_t* ka;
527 char* meta;
528 static m_option_t key_type =
529 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
530 if (!mpctx->demuxer)
531 return M_PROPERTY_UNAVAILABLE;
533 switch(action) {
534 case M_PROPERTY_GET:
535 if(!arg) return M_PROPERTY_ERROR;
536 *(char***)arg = mpctx->demuxer->info;
537 return M_PROPERTY_OK;
538 case M_PROPERTY_KEY_ACTION:
539 if(!arg) return M_PROPERTY_ERROR;
540 ka = arg;
541 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
542 return M_PROPERTY_UNKNOWN;
543 switch(ka->action) {
544 case M_PROPERTY_GET:
545 if(!ka->arg) return M_PROPERTY_ERROR;
546 *(char**)ka->arg = meta;
547 return M_PROPERTY_OK;
548 case M_PROPERTY_GET_TYPE:
549 if(!ka->arg) return M_PROPERTY_ERROR;
550 *(m_option_t**)ka->arg = &key_type;
551 return M_PROPERTY_OK;
554 return M_PROPERTY_NOT_IMPLEMENTED;
557 static int mp_property_pause(m_option_t * prop, int action, void *arg,
558 MPContext * mpctx)
560 return m_property_flag_ro(prop, action, arg, mpctx->osd_function == OSD_PAUSE);
564 ///@}
566 /// \defgroup AudioProperties Audio properties
567 /// \ingroup Properties
568 ///@{
570 /// Volume (RW)
571 static int mp_property_volume(m_option_t * prop, int action, void *arg,
572 MPContext * mpctx)
575 if (!mpctx->sh_audio)
576 return M_PROPERTY_UNAVAILABLE;
578 switch (action) {
579 case M_PROPERTY_GET:
580 if (!arg)
581 return M_PROPERTY_ERROR;
582 mixer_getbothvolume(&mpctx->mixer, arg);
583 return M_PROPERTY_OK;
584 case M_PROPERTY_PRINT:{
585 float vol;
586 if (!arg)
587 return M_PROPERTY_ERROR;
588 mixer_getbothvolume(&mpctx->mixer, &vol);
589 return m_property_float_range(prop, action, arg, &vol);
591 case M_PROPERTY_STEP_UP:
592 case M_PROPERTY_STEP_DOWN:
593 case M_PROPERTY_SET:
594 break;
595 default:
596 return M_PROPERTY_NOT_IMPLEMENTED;
599 if (mpctx->edl_muted)
600 return M_PROPERTY_DISABLED;
601 mpctx->user_muted = 0;
603 switch (action) {
604 case M_PROPERTY_SET:
605 if (!arg)
606 return M_PROPERTY_ERROR;
607 M_PROPERTY_CLAMP(prop, *(float *) arg);
608 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
609 return M_PROPERTY_OK;
610 case M_PROPERTY_STEP_UP:
611 if (arg && *(float *) arg <= 0)
612 mixer_decvolume(&mpctx->mixer);
613 else
614 mixer_incvolume(&mpctx->mixer);
615 return M_PROPERTY_OK;
616 case M_PROPERTY_STEP_DOWN:
617 if (arg && *(float *) arg <= 0)
618 mixer_incvolume(&mpctx->mixer);
619 else
620 mixer_decvolume(&mpctx->mixer);
621 return M_PROPERTY_OK;
623 return M_PROPERTY_NOT_IMPLEMENTED;
626 /// Mute (RW)
627 static int mp_property_mute(m_option_t * prop, int action, void *arg,
628 MPContext * mpctx)
631 if (!mpctx->sh_audio)
632 return M_PROPERTY_UNAVAILABLE;
634 switch (action) {
635 case M_PROPERTY_SET:
636 if (mpctx->edl_muted)
637 return M_PROPERTY_DISABLED;
638 if (!arg)
639 return M_PROPERTY_ERROR;
640 if ((!!*(int *) arg) != mpctx->mixer.muted)
641 mixer_mute(&mpctx->mixer);
642 mpctx->user_muted = mpctx->mixer.muted;
643 return M_PROPERTY_OK;
644 case M_PROPERTY_STEP_UP:
645 case M_PROPERTY_STEP_DOWN:
646 if (mpctx->edl_muted)
647 return M_PROPERTY_DISABLED;
648 mixer_mute(&mpctx->mixer);
649 mpctx->user_muted = mpctx->mixer.muted;
650 return M_PROPERTY_OK;
651 case M_PROPERTY_PRINT:
652 if (!arg)
653 return M_PROPERTY_ERROR;
654 if (mpctx->edl_muted) {
655 *(char **) arg = strdup(MSGTR_EnabledEdl);
656 return M_PROPERTY_OK;
658 default:
659 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
664 /// Audio delay (RW)
665 static int mp_property_audio_delay(m_option_t * prop, int action,
666 void *arg, MPContext * mpctx)
668 if (!(mpctx->sh_audio && mpctx->sh_video))
669 return M_PROPERTY_UNAVAILABLE;
670 switch (action) {
671 case M_PROPERTY_SET:
672 case M_PROPERTY_STEP_UP:
673 case M_PROPERTY_STEP_DOWN: {
674 int ret;
675 float delay = audio_delay;
676 ret = m_property_delay(prop, action, arg, &audio_delay);
677 if (ret != M_PROPERTY_OK)
678 return ret;
679 if (mpctx->sh_audio)
680 mpctx->delay -= audio_delay - delay;
682 return M_PROPERTY_OK;
683 default:
684 return m_property_delay(prop, action, arg, &audio_delay);
688 /// Audio codec tag (RO)
689 static int mp_property_audio_format(m_option_t * prop, int action,
690 void *arg, MPContext * mpctx)
692 if (!mpctx->sh_audio)
693 return M_PROPERTY_UNAVAILABLE;
694 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
697 /// Audio codec name (RO)
698 static int mp_property_audio_codec(m_option_t * prop, int action,
699 void *arg, MPContext * mpctx)
701 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
702 return M_PROPERTY_UNAVAILABLE;
703 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
706 /// Audio bitrate (RO)
707 static int mp_property_audio_bitrate(m_option_t * prop, int action,
708 void *arg, MPContext * mpctx)
710 if (!mpctx->sh_audio)
711 return M_PROPERTY_UNAVAILABLE;
712 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
715 /// Samplerate (RO)
716 static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
717 MPContext * mpctx)
719 if (!mpctx->sh_audio)
720 return M_PROPERTY_UNAVAILABLE;
721 switch(action) {
722 case M_PROPERTY_PRINT:
723 if(!arg) return M_PROPERTY_ERROR;
724 *(char**)arg = malloc(16);
725 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
726 return M_PROPERTY_OK;
728 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
731 /// Number of channels (RO)
732 static int mp_property_channels(m_option_t * prop, int action, void *arg,
733 MPContext * mpctx)
735 if (!mpctx->sh_audio)
736 return M_PROPERTY_UNAVAILABLE;
737 switch (action) {
738 case M_PROPERTY_PRINT:
739 if (!arg)
740 return M_PROPERTY_ERROR;
741 switch (mpctx->sh_audio->channels) {
742 case 1:
743 *(char **) arg = strdup("mono");
744 break;
745 case 2:
746 *(char **) arg = strdup("stereo");
747 break;
748 default:
749 *(char **) arg = malloc(32);
750 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
752 return M_PROPERTY_OK;
754 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
757 /// Balance (RW)
758 static int mp_property_balance(m_option_t * prop, int action, void *arg,
759 MPContext * mpctx)
761 float bal;
763 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
764 return M_PROPERTY_UNAVAILABLE;
766 switch (action) {
767 case M_PROPERTY_GET:
768 if (!arg)
769 return M_PROPERTY_ERROR;
770 mixer_getbalance(&mpctx->mixer, arg);
771 return M_PROPERTY_OK;
772 case M_PROPERTY_PRINT: {
773 char** str = arg;
774 if (!arg)
775 return M_PROPERTY_ERROR;
776 mixer_getbalance(&mpctx->mixer, &bal);
777 if (bal == 0.f)
778 *str = strdup("center");
779 else if (bal == -1.f)
780 *str = strdup("left only");
781 else if (bal == 1.f)
782 *str = strdup("right only");
783 else {
784 unsigned right = (bal + 1.f) / 2.f * 100.f;
785 *str = malloc(sizeof("left xxx%, right xxx%"));
786 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
788 return M_PROPERTY_OK;
790 case M_PROPERTY_STEP_UP:
791 case M_PROPERTY_STEP_DOWN:
792 mixer_getbalance(&mpctx->mixer, &bal);
793 bal += (arg ? *(float*)arg : .1f) *
794 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
795 M_PROPERTY_CLAMP(prop, bal);
796 mixer_setbalance(&mpctx->mixer, bal);
797 return M_PROPERTY_OK;
798 case M_PROPERTY_SET:
799 if (!arg)
800 return M_PROPERTY_ERROR;
801 M_PROPERTY_CLAMP(prop, *(float*)arg);
802 mixer_setbalance(&mpctx->mixer, *(float*)arg);
803 return M_PROPERTY_OK;
805 return M_PROPERTY_NOT_IMPLEMENTED;
808 /// Selected audio id (RW)
809 static int mp_property_audio(m_option_t * prop, int action, void *arg,
810 MPContext * mpctx)
812 int current_id = -1, tmp;
814 switch (action) {
815 case M_PROPERTY_GET:
816 if (!mpctx->sh_audio)
817 return M_PROPERTY_UNAVAILABLE;
818 if (!arg)
819 return M_PROPERTY_ERROR;
820 *(int *) arg = audio_id;
821 return M_PROPERTY_OK;
822 case M_PROPERTY_PRINT:
823 if (!mpctx->sh_audio)
824 return M_PROPERTY_UNAVAILABLE;
825 if (!arg)
826 return M_PROPERTY_ERROR;
828 if (audio_id < 0)
829 *(char **) arg = strdup(MSGTR_Disabled);
830 else {
831 char lang[40] = MSGTR_Unknown;
832 sh_audio_t* sh = mpctx->sh_audio;
833 if (sh && sh->lang)
834 av_strlcpy(lang, sh->lang, 40);
835 #ifdef CONFIG_DVDREAD
836 else if (mpctx->stream->type == STREAMTYPE_DVD) {
837 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
838 if (code) {
839 lang[0] = code >> 8;
840 lang[1] = code;
841 lang[2] = 0;
844 #endif
846 #ifdef CONFIG_DVDNAV
847 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
848 mp_dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
849 #endif
850 *(char **) arg = malloc(64);
851 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
853 return M_PROPERTY_OK;
855 case M_PROPERTY_STEP_UP:
856 case M_PROPERTY_SET:
857 if (!mpctx->demuxer)
858 return M_PROPERTY_UNAVAILABLE;
859 if (action == M_PROPERTY_SET && arg)
860 tmp = *((int *) arg);
861 else
862 tmp = -1;
863 current_id = mpctx->demuxer->audio->id;
864 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
865 if (audio_id == -2
866 || (audio_id > -1
867 && mpctx->demuxer->audio->id != current_id && current_id != -2))
868 uninit_player(INITIALIZED_AO | INITIALIZED_ACODEC);
869 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
870 sh_audio_t *sh2;
871 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
872 if (sh2) {
873 sh2->ds = mpctx->demuxer->audio;
874 mpctx->sh_audio = sh2;
875 reinit_audio_chain();
878 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
879 return M_PROPERTY_OK;
880 default:
881 return M_PROPERTY_NOT_IMPLEMENTED;
886 /// Selected video id (RW)
887 static int mp_property_video(m_option_t * prop, int action, void *arg,
888 MPContext * mpctx)
890 int current_id = -1, tmp;
892 switch (action) {
893 case M_PROPERTY_GET:
894 if (!mpctx->sh_video)
895 return M_PROPERTY_UNAVAILABLE;
896 if (!arg)
897 return M_PROPERTY_ERROR;
898 *(int *) arg = video_id;
899 return M_PROPERTY_OK;
900 case M_PROPERTY_PRINT:
901 if (!mpctx->sh_video)
902 return M_PROPERTY_UNAVAILABLE;
903 if (!arg)
904 return M_PROPERTY_ERROR;
906 if (video_id < 0)
907 *(char **) arg = strdup(MSGTR_Disabled);
908 else {
909 char lang[40] = MSGTR_Unknown;
910 *(char **) arg = malloc(64);
911 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
913 return M_PROPERTY_OK;
915 case M_PROPERTY_STEP_UP:
916 case M_PROPERTY_SET:
917 current_id = mpctx->demuxer->video->id;
918 if (action == M_PROPERTY_SET && arg)
919 tmp = *((int *) arg);
920 else
921 tmp = -1;
922 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
923 if (video_id == -2
924 || (video_id > -1 && mpctx->demuxer->video->id != current_id
925 && current_id != -2))
926 uninit_player(INITIALIZED_VCODEC |
927 (fixed_vo && video_id != -2 ? 0 : INITIALIZED_VO));
928 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
929 sh_video_t *sh2;
930 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
931 if (sh2) {
932 sh2->ds = mpctx->demuxer->video;
933 mpctx->sh_video = sh2;
934 reinit_video_chain();
937 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
938 return M_PROPERTY_OK;
940 default:
941 return M_PROPERTY_NOT_IMPLEMENTED;
945 static int mp_property_program(m_option_t * prop, int action, void *arg,
946 MPContext * mpctx)
948 demux_program_t prog;
950 switch (action) {
951 case M_PROPERTY_STEP_UP:
952 case M_PROPERTY_SET:
953 if (action == M_PROPERTY_SET && arg)
954 prog.progid = *((int *) arg);
955 else
956 prog.progid = -1;
957 if (demux_control
958 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
959 &prog) == DEMUXER_CTRL_NOTIMPL)
960 return M_PROPERTY_ERROR;
962 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
963 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
964 return M_PROPERTY_OK;
966 default:
967 return M_PROPERTY_NOT_IMPLEMENTED;
971 ///@}
973 /// \defgroup VideoProperties Video properties
974 /// \ingroup Properties
975 ///@{
977 /// Fullscreen state (RW)
978 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
979 MPContext * mpctx)
982 if (!mpctx->video_out)
983 return M_PROPERTY_UNAVAILABLE;
985 switch (action) {
986 case M_PROPERTY_SET:
987 if (!arg)
988 return M_PROPERTY_ERROR;
989 M_PROPERTY_CLAMP(prop, *(int *) arg);
990 if (vo_fs == !!*(int *) arg)
991 return M_PROPERTY_OK;
992 case M_PROPERTY_STEP_UP:
993 case M_PROPERTY_STEP_DOWN:
994 #ifdef CONFIG_GUI
995 if (use_gui)
996 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
997 else
998 #endif
999 if (vo_config_count)
1000 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
1001 return M_PROPERTY_OK;
1002 default:
1003 return m_property_flag(prop, action, arg, &vo_fs);
1007 static int mp_property_deinterlace(m_option_t * prop, int action,
1008 void *arg, MPContext * mpctx)
1010 int deinterlace;
1011 vf_instance_t *vf;
1012 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1013 return M_PROPERTY_UNAVAILABLE;
1014 vf = mpctx->sh_video->vfilter;
1015 switch (action) {
1016 case M_PROPERTY_GET:
1017 if (!arg)
1018 return M_PROPERTY_ERROR;
1019 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1020 return M_PROPERTY_OK;
1021 case M_PROPERTY_SET:
1022 if (!arg)
1023 return M_PROPERTY_ERROR;
1024 M_PROPERTY_CLAMP(prop, *(int *) arg);
1025 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1026 return M_PROPERTY_OK;
1027 case M_PROPERTY_STEP_UP:
1028 case M_PROPERTY_STEP_DOWN:
1029 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1030 deinterlace = !deinterlace;
1031 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1032 return M_PROPERTY_OK;
1034 return M_PROPERTY_NOT_IMPLEMENTED;
1037 /// Panscan (RW)
1038 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
1039 MPContext * mpctx)
1042 if (!mpctx->video_out
1043 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1044 return M_PROPERTY_UNAVAILABLE;
1046 switch (action) {
1047 case M_PROPERTY_SET:
1048 if (!arg)
1049 return M_PROPERTY_ERROR;
1050 M_PROPERTY_CLAMP(prop, *(float *) arg);
1051 vo_panscan = *(float *) arg;
1052 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1053 return M_PROPERTY_OK;
1054 case M_PROPERTY_STEP_UP:
1055 case M_PROPERTY_STEP_DOWN:
1056 vo_panscan += (arg ? *(float *) arg : 0.1) *
1057 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1058 if (vo_panscan > 1)
1059 vo_panscan = 1;
1060 else if (vo_panscan < 0)
1061 vo_panscan = 0;
1062 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1063 return M_PROPERTY_OK;
1064 default:
1065 return m_property_float_range(prop, action, arg, &vo_panscan);
1069 /// Helper to set vo flags.
1070 /** \ingroup PropertyImplHelper
1072 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
1073 int vo_ctrl, int *vo_var, MPContext * mpctx)
1076 if (!mpctx->video_out)
1077 return M_PROPERTY_UNAVAILABLE;
1079 switch (action) {
1080 case M_PROPERTY_SET:
1081 if (!arg)
1082 return M_PROPERTY_ERROR;
1083 M_PROPERTY_CLAMP(prop, *(int *) arg);
1084 if (*vo_var == !!*(int *) arg)
1085 return M_PROPERTY_OK;
1086 case M_PROPERTY_STEP_UP:
1087 case M_PROPERTY_STEP_DOWN:
1088 if (vo_config_count)
1089 mpctx->video_out->control(vo_ctrl, 0);
1090 return M_PROPERTY_OK;
1091 default:
1092 return m_property_flag(prop, action, arg, vo_var);
1096 /// Window always on top (RW)
1097 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
1098 MPContext * mpctx)
1100 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
1101 mpctx);
1104 /// Display in the root window (RW)
1105 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
1106 MPContext * mpctx)
1108 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1109 &vo_rootwin, mpctx);
1112 /// Show window borders (RW)
1113 static int mp_property_border(m_option_t * prop, int action, void *arg,
1114 MPContext * mpctx)
1116 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1117 &vo_border, mpctx);
1120 /// Framedropping state (RW)
1121 static int mp_property_framedropping(m_option_t * prop, int action,
1122 void *arg, MPContext * mpctx)
1125 if (!mpctx->sh_video)
1126 return M_PROPERTY_UNAVAILABLE;
1128 switch (action) {
1129 case M_PROPERTY_PRINT:
1130 if (!arg)
1131 return M_PROPERTY_ERROR;
1132 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1133 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1134 MSGTR_Disabled));
1135 return M_PROPERTY_OK;
1136 default:
1137 return m_property_choice(prop, action, arg, &frame_dropping);
1141 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1142 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
1143 MPContext * mpctx)
1145 int *gamma = prop->priv, r, val;
1147 if (!mpctx->sh_video)
1148 return M_PROPERTY_UNAVAILABLE;
1150 if (gamma[0] == 1000) {
1151 gamma[0] = 0;
1152 get_video_colors(mpctx->sh_video, prop->name, gamma);
1155 switch (action) {
1156 case M_PROPERTY_SET:
1157 if (!arg)
1158 return M_PROPERTY_ERROR;
1159 M_PROPERTY_CLAMP(prop, *(int *) arg);
1160 *gamma = *(int *) arg;
1161 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1162 if (r <= 0)
1163 break;
1164 return r;
1165 case M_PROPERTY_GET:
1166 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1167 if (!arg)
1168 return M_PROPERTY_ERROR;
1169 *(int *)arg = val;
1170 return M_PROPERTY_OK;
1172 break;
1173 case M_PROPERTY_STEP_UP:
1174 case M_PROPERTY_STEP_DOWN:
1175 *gamma += (arg ? *(int *) arg : 1) *
1176 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1177 M_PROPERTY_CLAMP(prop, *gamma);
1178 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1179 if (r <= 0)
1180 break;
1181 return r;
1182 default:
1183 return M_PROPERTY_NOT_IMPLEMENTED;
1186 #ifdef CONFIG_TV
1187 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1188 int l = strlen(prop->name);
1189 char tv_prop[3 + l + 1];
1190 sprintf(tv_prop, "tv_%s", prop->name);
1191 return mp_property_do(tv_prop, action, arg, mpctx);
1193 #endif
1195 return M_PROPERTY_UNAVAILABLE;
1198 /// VSync (RW)
1199 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1200 MPContext * mpctx)
1202 return m_property_flag(prop, action, arg, &vo_vsync);
1205 /// Video codec tag (RO)
1206 static int mp_property_video_format(m_option_t * prop, int action,
1207 void *arg, MPContext * mpctx)
1209 char* meta;
1210 if (!mpctx->sh_video)
1211 return M_PROPERTY_UNAVAILABLE;
1212 switch(action) {
1213 case M_PROPERTY_PRINT:
1214 if (!arg)
1215 return M_PROPERTY_ERROR;
1216 switch(mpctx->sh_video->format) {
1217 case 0x10000001:
1218 meta = strdup ("mpeg1"); break;
1219 case 0x10000002:
1220 meta = strdup ("mpeg2"); break;
1221 case 0x10000004:
1222 meta = strdup ("mpeg4"); break;
1223 case 0x10000005:
1224 meta = strdup ("h264"); break;
1225 default:
1226 if(mpctx->sh_video->format >= 0x20202020) {
1227 meta = malloc(5);
1228 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1229 } else {
1230 meta = malloc(20);
1231 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1234 *(char**)arg = meta;
1235 return M_PROPERTY_OK;
1237 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1240 /// Video codec name (RO)
1241 static int mp_property_video_codec(m_option_t * prop, int action,
1242 void *arg, MPContext * mpctx)
1244 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1245 return M_PROPERTY_UNAVAILABLE;
1246 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1250 /// Video bitrate (RO)
1251 static int mp_property_video_bitrate(m_option_t * prop, int action,
1252 void *arg, MPContext * mpctx)
1254 if (!mpctx->sh_video)
1255 return M_PROPERTY_UNAVAILABLE;
1256 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1259 /// Video display width (RO)
1260 static int mp_property_width(m_option_t * prop, int action, void *arg,
1261 MPContext * mpctx)
1263 if (!mpctx->sh_video)
1264 return M_PROPERTY_UNAVAILABLE;
1265 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1268 /// Video display height (RO)
1269 static int mp_property_height(m_option_t * prop, int action, void *arg,
1270 MPContext * mpctx)
1272 if (!mpctx->sh_video)
1273 return M_PROPERTY_UNAVAILABLE;
1274 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1277 /// Video fps (RO)
1278 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1279 MPContext * mpctx)
1281 if (!mpctx->sh_video)
1282 return M_PROPERTY_UNAVAILABLE;
1283 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1286 /// Video aspect (RO)
1287 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1288 MPContext * mpctx)
1290 if (!mpctx->sh_video)
1291 return M_PROPERTY_UNAVAILABLE;
1292 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1295 ///@}
1297 /// \defgroup SubProprties Subtitles properties
1298 /// \ingroup Properties
1299 ///@{
1301 /// Text subtitle position (RW)
1302 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1303 MPContext * mpctx)
1305 if (!mpctx->sh_video)
1306 return M_PROPERTY_UNAVAILABLE;
1308 switch (action) {
1309 case M_PROPERTY_SET:
1310 if (!arg)
1311 return M_PROPERTY_ERROR;
1312 case M_PROPERTY_STEP_UP:
1313 case M_PROPERTY_STEP_DOWN:
1314 vo_osd_changed(OSDTYPE_SUBTITLE);
1315 default:
1316 return m_property_int_range(prop, action, arg, &sub_pos);
1320 /// Selected subtitles (RW)
1321 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1322 MPContext * mpctx)
1324 demux_stream_t *const d_sub = mpctx->d_sub;
1325 const int global_sub_size = mpctx->global_sub_size;
1326 int source = -1, reset_spu = 0;
1327 char *sub_name;
1329 if (global_sub_size <= 0)
1330 return M_PROPERTY_UNAVAILABLE;
1332 switch (action) {
1333 case M_PROPERTY_GET:
1334 if (!arg)
1335 return M_PROPERTY_ERROR;
1336 *(int *) arg = mpctx->global_sub_pos;
1337 return M_PROPERTY_OK;
1338 case M_PROPERTY_PRINT:
1339 if (!arg)
1340 return M_PROPERTY_ERROR;
1341 *(char **) arg = malloc(64);
1342 (*(char **) arg)[63] = 0;
1343 sub_name = 0;
1344 if (subdata)
1345 sub_name = subdata->filename;
1346 #ifdef CONFIG_ASS
1347 if (ass_track && ass_track->name)
1348 sub_name = ass_track->name;
1349 #endif
1350 if (sub_name) {
1351 char *tmp, *tmp2;
1352 tmp = sub_name;
1353 if ((tmp2 = strrchr(tmp, '/')))
1354 tmp = tmp2 + 1;
1356 snprintf(*(char **) arg, 63, "(%d) %s%s",
1357 mpctx->set_of_sub_pos + 1,
1358 strlen(tmp) < 20 ? "" : "...",
1359 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1360 return M_PROPERTY_OK;
1362 #ifdef CONFIG_DVDNAV
1363 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1364 if (vo_spudec && dvdsub_id >= 0) {
1365 unsigned char lang[3];
1366 if (mp_dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1367 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1368 return M_PROPERTY_OK;
1372 #endif
1374 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1375 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1376 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1377 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1378 && d_sub && d_sub->sh && dvdsub_id >= 0) {
1379 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1380 if (!lang) lang = MSGTR_Unknown;
1381 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1382 return M_PROPERTY_OK;
1385 if (vo_vobsub && vobsub_id >= 0) {
1386 const char *language = MSGTR_Unknown;
1387 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1388 snprintf(*(char **) arg, 63, "(%d) %s",
1389 vobsub_id, language ? language : MSGTR_Unknown);
1390 return M_PROPERTY_OK;
1392 #ifdef CONFIG_DVDREAD
1393 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1394 && dvdsub_id >= 0) {
1395 char lang[3];
1396 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1397 lang[0] = code >> 8;
1398 lang[1] = code;
1399 lang[2] = 0;
1400 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1401 return M_PROPERTY_OK;
1403 #endif
1404 if (dvdsub_id >= 0) {
1405 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1406 return M_PROPERTY_OK;
1408 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1409 return M_PROPERTY_OK;
1411 case M_PROPERTY_SET:
1412 if (!arg)
1413 return M_PROPERTY_ERROR;
1414 if (*(int *) arg < -1)
1415 *(int *) arg = -1;
1416 else if (*(int *) arg >= global_sub_size)
1417 *(int *) arg = global_sub_size - 1;
1418 mpctx->global_sub_pos = *(int *) arg;
1419 break;
1420 case M_PROPERTY_STEP_UP:
1421 mpctx->global_sub_pos += 2;
1422 mpctx->global_sub_pos =
1423 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1424 break;
1425 case M_PROPERTY_STEP_DOWN:
1426 mpctx->global_sub_pos += global_sub_size + 1;
1427 mpctx->global_sub_pos =
1428 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1429 break;
1430 default:
1431 return M_PROPERTY_NOT_IMPLEMENTED;
1434 if (mpctx->global_sub_pos >= 0)
1435 source = sub_source(mpctx);
1437 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1438 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1439 global_sub_size,
1440 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1441 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1442 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1443 mpctx->global_sub_pos, source);
1445 mpctx->set_of_sub_pos = -1;
1446 subdata = NULL;
1448 vobsub_id = -1;
1449 dvdsub_id = -1;
1450 if (d_sub) {
1451 if (d_sub->id > -2)
1452 reset_spu = 1;
1453 d_sub->id = -2;
1455 #ifdef CONFIG_ASS
1456 ass_track = 0;
1457 #endif
1459 if (source == SUB_SOURCE_VOBSUB) {
1460 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1461 } else if (source == SUB_SOURCE_SUBS) {
1462 mpctx->set_of_sub_pos =
1463 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1464 #ifdef CONFIG_ASS
1465 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1466 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1467 else
1468 #endif
1470 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1471 vo_osd_changed(OSDTYPE_SUBTITLE);
1473 } else if (source == SUB_SOURCE_DEMUX) {
1474 dvdsub_id =
1475 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1476 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1477 int i = 0;
1478 // default: assume 1:1 mapping of sid and stream id
1479 d_sub->id = dvdsub_id;
1480 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1481 ds_free_packs(d_sub);
1482 for (i = 0; i < MAX_S_STREAMS; i++) {
1483 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1484 if (sh && sh->sid == dvdsub_id) {
1485 d_sub->id = i;
1486 d_sub->sh = sh;
1487 break;
1490 if (d_sub->sh && d_sub->id >= 0) {
1491 sh_sub_t *sh = d_sub->sh;
1492 if (sh->type == 'v')
1493 init_vo_spudec();
1494 #ifdef CONFIG_ASS
1495 else if (ass_enabled)
1496 ass_track = sh->ass_track;
1497 #endif
1498 } else {
1499 d_sub->id = -2;
1500 d_sub->sh = NULL;
1504 #ifdef CONFIG_DVDREAD
1505 if (vo_spudec
1506 && (mpctx->stream->type == STREAMTYPE_DVD
1507 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1508 && dvdsub_id < 0 && reset_spu) {
1509 dvdsub_id = -2;
1510 d_sub->id = dvdsub_id;
1512 #endif
1513 update_subtitles(mpctx->sh_video, d_sub, 1);
1515 return M_PROPERTY_OK;
1518 /// Selected sub source (RW)
1519 static int mp_property_sub_source(m_option_t * prop, int action, void *arg,
1520 MPContext * mpctx)
1522 int source;
1523 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1524 return M_PROPERTY_UNAVAILABLE;
1526 switch (action) {
1527 case M_PROPERTY_GET:
1528 if (!arg)
1529 return M_PROPERTY_ERROR;
1530 *(int *) arg = sub_source(mpctx);
1531 return M_PROPERTY_OK;
1532 case M_PROPERTY_PRINT:
1533 if (!arg)
1534 return M_PROPERTY_ERROR;
1535 *(char **) arg = malloc(64);
1536 (*(char **) arg)[63] = 0;
1537 switch (sub_source(mpctx))
1539 case SUB_SOURCE_SUBS:
1540 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1541 break;
1542 case SUB_SOURCE_VOBSUB:
1543 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1544 break;
1545 case SUB_SOURCE_DEMUX:
1546 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1547 break;
1548 default:
1549 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1551 return M_PROPERTY_OK;
1552 case M_PROPERTY_SET:
1553 if (!arg)
1554 return M_PROPERTY_ERROR;
1555 M_PROPERTY_CLAMP(prop, *(int*)arg);
1556 if (*(int *) arg < 0)
1557 mpctx->global_sub_pos = -1;
1558 else if (*(int *) arg != sub_source(mpctx)) {
1559 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1560 return M_PROPERTY_UNAVAILABLE;
1561 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1563 break;
1564 case M_PROPERTY_STEP_UP:
1565 case M_PROPERTY_STEP_DOWN: {
1566 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1567 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1568 int step = (step_all > 0) ? 1 : -1;
1569 int cur_source = sub_source(mpctx);
1570 source = cur_source;
1571 while (step_all) {
1572 source += step;
1573 if (source >= SUB_SOURCES)
1574 source = -1;
1575 else if (source < -1)
1576 source = SUB_SOURCES - 1;
1577 if (source == cur_source || source == -1 ||
1578 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1579 step_all -= step;
1581 if (source == cur_source)
1582 return M_PROPERTY_OK;
1583 if (source == -1)
1584 mpctx->global_sub_pos = -1;
1585 else
1586 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1587 break;
1589 default:
1590 return M_PROPERTY_NOT_IMPLEMENTED;
1592 --mpctx->global_sub_pos;
1593 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1596 /// Selected subtitles from specific source (RW)
1597 static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg,
1598 MPContext * mpctx)
1600 int source, is_cur_source, offset;
1601 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1602 return M_PROPERTY_UNAVAILABLE;
1604 if (!strcmp(prop->name, "sub_file"))
1605 source = SUB_SOURCE_SUBS;
1606 else if (!strcmp(prop->name, "sub_vob"))
1607 source = SUB_SOURCE_VOBSUB;
1608 else if (!strcmp(prop->name, "sub_demux"))
1609 source = SUB_SOURCE_DEMUX;
1610 else
1611 return M_PROPERTY_ERROR;
1613 offset = mpctx->global_sub_indices[source];
1614 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1615 return M_PROPERTY_UNAVAILABLE;
1617 is_cur_source = sub_source(mpctx) == source;
1618 switch (action) {
1619 case M_PROPERTY_GET:
1620 if (!arg)
1621 return M_PROPERTY_ERROR;
1622 if (is_cur_source) {
1623 *(int *) arg = mpctx->global_sub_pos - offset;
1624 if (source == SUB_SOURCE_VOBSUB)
1625 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1627 else
1628 *(int *) arg = -1;
1629 return M_PROPERTY_OK;
1630 case M_PROPERTY_PRINT:
1631 if (!arg)
1632 return M_PROPERTY_ERROR;
1633 if (is_cur_source)
1634 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1635 *(char **) arg = malloc(64);
1636 (*(char **) arg)[63] = 0;
1637 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1638 return M_PROPERTY_OK;
1639 case M_PROPERTY_SET:
1640 if (!arg)
1641 return M_PROPERTY_ERROR;
1642 if (*(int *) arg >= 0) {
1643 int index = *(int *)arg;
1644 if (source == SUB_SOURCE_VOBSUB)
1645 index = vobsub_get_index_by_id(vo_vobsub, index);
1646 mpctx->global_sub_pos = offset + index;
1647 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1648 || sub_source(mpctx) != source) {
1649 mpctx->global_sub_pos = -1;
1650 *(int *) arg = -1;
1653 else
1654 mpctx->global_sub_pos = -1;
1655 break;
1656 case M_PROPERTY_STEP_UP:
1657 case M_PROPERTY_STEP_DOWN: {
1658 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1659 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1660 int step = (step_all > 0) ? 1 : -1;
1661 int max_sub_pos_for_source = -1;
1662 if (!is_cur_source)
1663 mpctx->global_sub_pos = -1;
1664 while (step_all) {
1665 if (mpctx->global_sub_pos == -1) {
1666 if (step > 0)
1667 mpctx->global_sub_pos = offset;
1668 else if (max_sub_pos_for_source == -1) {
1669 // Find max pos for specific source
1670 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1671 while (mpctx->global_sub_pos >= 0
1672 && sub_source(mpctx) != source)
1673 --mpctx->global_sub_pos;
1675 else
1676 mpctx->global_sub_pos = max_sub_pos_for_source;
1678 else {
1679 mpctx->global_sub_pos += step;
1680 if (mpctx->global_sub_pos < offset ||
1681 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1682 sub_source(mpctx) != source)
1683 mpctx->global_sub_pos = -1;
1685 step_all -= step;
1687 break;
1689 default:
1690 return M_PROPERTY_NOT_IMPLEMENTED;
1692 --mpctx->global_sub_pos;
1693 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1696 /// Subtitle delay (RW)
1697 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1698 MPContext * mpctx)
1700 if (!mpctx->sh_video)
1701 return M_PROPERTY_UNAVAILABLE;
1702 return m_property_delay(prop, action, arg, &sub_delay);
1705 /// Alignment of text subtitles (RW)
1706 static int mp_property_sub_alignment(m_option_t * prop, int action,
1707 void *arg, MPContext * mpctx)
1709 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1711 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1712 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1713 return M_PROPERTY_UNAVAILABLE;
1715 switch (action) {
1716 case M_PROPERTY_PRINT:
1717 if (!arg)
1718 return M_PROPERTY_ERROR;
1719 M_PROPERTY_CLAMP(prop, sub_alignment);
1720 *(char **) arg = strdup(name[sub_alignment]);
1721 return M_PROPERTY_OK;
1722 case M_PROPERTY_SET:
1723 if (!arg)
1724 return M_PROPERTY_ERROR;
1725 case M_PROPERTY_STEP_UP:
1726 case M_PROPERTY_STEP_DOWN:
1727 vo_osd_changed(OSDTYPE_SUBTITLE);
1728 default:
1729 return m_property_choice(prop, action, arg, &sub_alignment);
1733 /// Subtitle visibility (RW)
1734 static int mp_property_sub_visibility(m_option_t * prop, int action,
1735 void *arg, MPContext * mpctx)
1737 if (!mpctx->sh_video)
1738 return M_PROPERTY_UNAVAILABLE;
1740 switch (action) {
1741 case M_PROPERTY_SET:
1742 if (!arg)
1743 return M_PROPERTY_ERROR;
1744 case M_PROPERTY_STEP_UP:
1745 case M_PROPERTY_STEP_DOWN:
1746 vo_osd_changed(OSDTYPE_SUBTITLE);
1747 if (vo_spudec)
1748 vo_osd_changed(OSDTYPE_SPU);
1749 default:
1750 return m_property_flag(prop, action, arg, &sub_visibility);
1754 #ifdef CONFIG_ASS
1755 /// Use margins for libass subtitles (RW)
1756 static int mp_property_ass_use_margins(m_option_t * prop, int action,
1757 void *arg, MPContext * mpctx)
1759 if (!mpctx->sh_video)
1760 return M_PROPERTY_UNAVAILABLE;
1762 switch (action) {
1763 case M_PROPERTY_SET:
1764 if (!arg)
1765 return M_PROPERTY_ERROR;
1766 case M_PROPERTY_STEP_UP:
1767 case M_PROPERTY_STEP_DOWN:
1768 ass_force_reload = 1;
1769 default:
1770 return m_property_flag(prop, action, arg, &ass_use_margins);
1773 #endif
1775 /// Show only forced subtitles (RW)
1776 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1777 void *arg, MPContext * mpctx)
1779 if (!vo_spudec)
1780 return M_PROPERTY_UNAVAILABLE;
1782 switch (action) {
1783 case M_PROPERTY_SET:
1784 if (!arg)
1785 return M_PROPERTY_ERROR;
1786 case M_PROPERTY_STEP_UP:
1787 case M_PROPERTY_STEP_DOWN:
1788 m_property_flag(prop, action, arg, &forced_subs_only);
1789 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1790 return M_PROPERTY_OK;
1791 default:
1792 return m_property_flag(prop, action, arg, &forced_subs_only);
1797 #ifdef CONFIG_FREETYPE
1798 /// Subtitle scale (RW)
1799 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1800 MPContext * mpctx)
1803 switch (action) {
1804 case M_PROPERTY_SET:
1805 if (!arg)
1806 return M_PROPERTY_ERROR;
1807 M_PROPERTY_CLAMP(prop, *(float *) arg);
1808 #ifdef CONFIG_ASS
1809 if (ass_enabled) {
1810 ass_font_scale = *(float *) arg;
1811 ass_force_reload = 1;
1813 #endif
1814 text_font_scale_factor = *(float *) arg;
1815 force_load_font = 1;
1816 return M_PROPERTY_OK;
1817 case M_PROPERTY_STEP_UP:
1818 case M_PROPERTY_STEP_DOWN:
1819 #ifdef CONFIG_ASS
1820 if (ass_enabled) {
1821 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1822 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1823 M_PROPERTY_CLAMP(prop, ass_font_scale);
1824 ass_force_reload = 1;
1826 #endif
1827 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1828 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1829 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1830 force_load_font = 1;
1831 return M_PROPERTY_OK;
1832 default:
1833 #ifdef CONFIG_ASS
1834 if (ass_enabled)
1835 return m_property_float_ro(prop, action, arg, ass_font_scale);
1836 else
1837 #endif
1838 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1841 #endif
1843 ///@}
1845 /// \defgroup TVProperties TV properties
1846 /// \ingroup Properties
1847 ///@{
1849 #ifdef CONFIG_TV
1851 /// TV color settings (RW)
1852 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1853 MPContext * mpctx)
1855 int r, val;
1856 tvi_handle_t *tvh = mpctx->demuxer->priv;
1857 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1858 return M_PROPERTY_UNAVAILABLE;
1860 switch (action) {
1861 case M_PROPERTY_SET:
1862 if (!arg)
1863 return M_PROPERTY_ERROR;
1864 M_PROPERTY_CLAMP(prop, *(int *) arg);
1865 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1866 case M_PROPERTY_GET:
1867 return tv_get_color_options(tvh, (int) prop->priv, arg);
1868 case M_PROPERTY_STEP_UP:
1869 case M_PROPERTY_STEP_DOWN:
1870 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1871 if (!r)
1872 return M_PROPERTY_ERROR;
1873 val += (arg ? *(int *) arg : 1) *
1874 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1875 M_PROPERTY_CLAMP(prop, val);
1876 return tv_set_color_options(tvh, (int) prop->priv, val);
1878 return M_PROPERTY_ERROR;
1880 return M_PROPERTY_NOT_IMPLEMENTED;
1883 #endif
1885 #ifdef CONFIG_TV_TELETEXT
1886 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1887 MPContext * mpctx)
1889 int val,result;
1890 int base_ioctl=(int)prop->priv;
1892 for teletext's GET,SET,STEP ioctls this is not 0
1893 SET is GET+1
1894 STEP is GET+2
1896 tvi_handle_t *tvh = mpctx->demuxer->priv;
1897 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1898 return M_PROPERTY_UNAVAILABLE;
1899 if(!base_ioctl)
1900 return M_PROPERTY_ERROR;
1902 switch (action) {
1903 case M_PROPERTY_GET:
1904 if (!arg)
1905 return M_PROPERTY_ERROR;
1906 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1907 break;
1908 case M_PROPERTY_SET:
1909 if (!arg)
1910 return M_PROPERTY_ERROR;
1911 M_PROPERTY_CLAMP(prop, *(int *) arg);
1912 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1913 break;
1914 case M_PROPERTY_STEP_UP:
1915 case M_PROPERTY_STEP_DOWN:
1916 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1917 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1918 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1919 break;
1920 default:
1921 return M_PROPERTY_NOT_IMPLEMENTED;
1924 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1927 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1928 MPContext * mpctx)
1930 tvi_handle_t *tvh = mpctx->demuxer->priv;
1931 int result;
1932 int val;
1934 //with tvh==NULL will fail too
1935 result=mp_property_teletext_common(prop,action,arg,mpctx);
1936 if(result!=M_PROPERTY_OK)
1937 return result;
1939 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1940 mp_input_set_section("teletext");
1941 else
1942 mp_input_set_section("tv");
1943 return M_PROPERTY_OK;
1946 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1947 MPContext * mpctx)
1949 tvi_handle_t *tvh = mpctx->demuxer->priv;
1950 int result;
1951 int val;
1952 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1953 return M_PROPERTY_UNAVAILABLE;
1954 switch(action){
1955 case M_PROPERTY_STEP_UP:
1956 case M_PROPERTY_STEP_DOWN:
1957 //This should be handled separately
1958 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1959 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1960 break;
1961 default:
1962 result=mp_property_teletext_common(prop,action,arg,mpctx);
1964 return result;
1968 #endif /* CONFIG_TV_TELETEXT */
1970 ///@}
1972 /// All properties available in MPlayer.
1973 /** \ingroup Properties
1975 static const m_option_t mp_properties[] = {
1976 // General
1977 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1978 M_OPT_RANGE, 0, 3, NULL },
1979 { "loop", mp_property_loop, CONF_TYPE_INT,
1980 M_OPT_MIN, -1, 0, NULL },
1981 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1982 M_OPT_RANGE, 0.01, 100.0, NULL },
1983 { "filename", mp_property_filename, CONF_TYPE_STRING,
1984 0, 0, 0, NULL },
1985 { "path", mp_property_path, CONF_TYPE_STRING,
1986 0, 0, 0, NULL },
1987 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1988 0, 0, 0, NULL },
1989 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1990 M_OPT_MIN, 0, 0, NULL },
1991 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1992 M_OPT_MIN, 0, 0, NULL },
1993 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1994 M_OPT_MIN, 0, 0, NULL },
1995 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1996 M_OPT_MIN, 0, 0, NULL },
1997 { "length", mp_property_length, CONF_TYPE_TIME,
1998 M_OPT_MIN, 0, 0, NULL },
1999 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2000 M_OPT_RANGE, 0, 100, NULL },
2001 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2002 M_OPT_MIN, 0, 0, NULL },
2003 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2004 M_OPT_MIN, 1, 0, NULL },
2005 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2006 0, 0, 0, NULL },
2007 { "angle", mp_property_angle, CONF_TYPE_INT,
2008 CONF_RANGE, -2, 10, NULL },
2009 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2010 0, 0, 0, NULL },
2011 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2012 M_OPT_RANGE, 0, 1, NULL },
2014 // Audio
2015 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2016 M_OPT_RANGE, 0, 100, NULL },
2017 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2018 M_OPT_RANGE, 0, 1, NULL },
2019 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2020 M_OPT_RANGE, -100, 100, NULL },
2021 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2022 0, 0, 0, NULL },
2023 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2024 0, 0, 0, NULL },
2025 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2026 0, 0, 0, NULL },
2027 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2028 0, 0, 0, NULL },
2029 { "channels", mp_property_channels, CONF_TYPE_INT,
2030 0, 0, 0, NULL },
2031 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2032 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
2033 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2034 M_OPT_RANGE, -1, 1, NULL },
2036 // Video
2037 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2038 M_OPT_RANGE, 0, 1, NULL },
2039 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2040 M_OPT_RANGE, 0, 1, NULL },
2041 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2042 M_OPT_RANGE, 0, 1, NULL },
2043 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2044 M_OPT_RANGE, 0, 1, NULL },
2045 { "border", mp_property_border, CONF_TYPE_FLAG,
2046 M_OPT_RANGE, 0, 1, NULL },
2047 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2048 M_OPT_RANGE, 0, 2, NULL },
2049 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2050 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2051 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2052 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2053 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2054 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2055 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2056 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2057 { "hue", mp_property_gamma, CONF_TYPE_INT,
2058 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2059 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2060 M_OPT_RANGE, 0, 1, NULL },
2061 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2062 M_OPT_RANGE, 0, 1, NULL },
2063 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2064 0, 0, 0, NULL },
2065 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2066 0, 0, 0, NULL },
2067 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2068 0, 0, 0, NULL },
2069 { "width", mp_property_width, CONF_TYPE_INT,
2070 0, 0, 0, NULL },
2071 { "height", mp_property_height, CONF_TYPE_INT,
2072 0, 0, 0, NULL },
2073 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2074 0, 0, 0, NULL },
2075 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2076 0, 0, 0, NULL },
2077 { "switch_video", mp_property_video, CONF_TYPE_INT,
2078 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
2079 { "switch_program", mp_property_program, CONF_TYPE_INT,
2080 CONF_RANGE, -1, 65535, NULL },
2082 // Subs
2083 { "sub", mp_property_sub, CONF_TYPE_INT,
2084 M_OPT_MIN, -1, 0, NULL },
2085 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2086 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2087 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2088 M_OPT_MIN, -1, 0, NULL },
2089 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2090 M_OPT_MIN, -1, 0, NULL },
2091 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2092 M_OPT_MIN, -1, 0, NULL },
2093 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2094 0, 0, 0, NULL },
2095 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2096 M_OPT_RANGE, 0, 100, NULL },
2097 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2098 M_OPT_RANGE, 0, 2, NULL },
2099 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2100 M_OPT_RANGE, 0, 1, NULL },
2101 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2102 M_OPT_RANGE, 0, 1, NULL },
2103 #ifdef CONFIG_FREETYPE
2104 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2105 M_OPT_RANGE, 0, 100, NULL },
2106 #endif
2107 #ifdef CONFIG_ASS
2108 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2109 M_OPT_RANGE, 0, 1, NULL },
2110 #endif
2112 #ifdef CONFIG_TV
2113 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2114 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2115 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2116 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2117 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2118 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2119 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2120 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2121 #endif
2123 #ifdef CONFIG_TV_TELETEXT
2124 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2125 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2126 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2127 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2128 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2129 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2130 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2131 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2132 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2133 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2134 #endif
2136 { NULL, NULL, NULL, 0, 0, 0, NULL }
2140 int mp_property_do(const char *name, int action, void *val, void *ctx)
2142 return m_property_do(mp_properties, name, action, val, ctx);
2145 char* mp_property_print(const char *name, void* ctx)
2147 char* ret = NULL;
2148 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2149 return NULL;
2150 return ret;
2153 char *property_expand_string(MPContext * mpctx, char *str)
2155 return m_properties_expand_string(mp_properties, str, mpctx);
2158 void property_print_help(void)
2160 m_properties_print_help_list(mp_properties);
2164 ///@}
2165 // Properties group
2169 * \defgroup Command2Property Command to property bridge
2171 * It is used to handle most commands that just set a property
2172 * and optionally display something on the OSD.
2173 * Two kinds of commands are handled: adjust or toggle.
2175 * Adjust commands take 1 or 2 parameters: <value> <abs>
2176 * If <abs> is non-zero the property is set to the given value
2177 * otherwise it is adjusted.
2179 * Toggle commands take 0 or 1 parameters. With no parameter
2180 * or a value less than the property minimum it just steps the
2181 * property to its next value. Otherwise it sets it to the given
2182 * value.
2187 /// List of the commands that can be handled by setting a property.
2188 static struct {
2189 /// property name
2190 const char *name;
2191 /// cmd id
2192 int cmd;
2193 /// set/adjust or toggle command
2194 int toggle;
2195 /// progressbar type
2196 int osd_progbar;
2197 /// osd msg id if it must be shared
2198 int osd_id;
2199 /// osd msg template
2200 const char *osd_msg;
2201 } set_prop_cmd[] = {
2202 // general
2203 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2204 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2205 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2206 // audio
2207 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2208 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2209 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2210 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2211 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2212 // video
2213 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2214 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2215 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2216 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2217 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2218 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2219 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2220 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2221 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2222 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2223 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2224 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2225 // subs
2226 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2227 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2228 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2229 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2230 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2231 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2232 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2233 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2234 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2235 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2236 #ifdef CONFIG_FREETYPE
2237 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2238 #endif
2239 #ifdef CONFIG_ASS
2240 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2241 #endif
2242 #ifdef CONFIG_TV
2243 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2244 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2245 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2246 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2247 #endif
2248 { NULL, 0, 0, 0, -1, NULL }
2252 /// Handle commands that set a property.
2253 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
2255 int i, r;
2256 m_option_t* prop;
2257 const char *pname;
2259 // look for the command
2260 for (i = 0; set_prop_cmd[i].name; i++)
2261 if (set_prop_cmd[i].cmd == cmd->id)
2262 break;
2263 if (!(pname = set_prop_cmd[i].name))
2264 return 0;
2266 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2267 return 0;
2269 // toggle command
2270 if (set_prop_cmd[i].toggle) {
2271 // set to value
2272 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2273 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2274 else
2275 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2276 } else if (cmd->args[1].v.i) //set
2277 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2278 else // adjust
2279 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2281 if (r <= 0)
2282 return 1;
2284 if (set_prop_cmd[i].osd_progbar) {
2285 if (prop->type == CONF_TYPE_INT) {
2286 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2287 set_osd_bar(set_prop_cmd[i].osd_progbar,
2288 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2289 } else if (prop->type == CONF_TYPE_FLOAT) {
2290 float f;
2291 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2292 set_osd_bar(set_prop_cmd[i].osd_progbar,
2293 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2294 } else
2295 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2296 "Property use an unsupported type.\n");
2297 return 1;
2300 if (set_prop_cmd[i].osd_msg) {
2301 char *val = mp_property_print(pname, mpctx);
2302 if (val) {
2303 set_osd_msg(set_prop_cmd[i].osd_id >=
2304 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2305 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2306 free(val);
2309 return 1;
2312 #ifdef CONFIG_DVDNAV
2313 static const struct {
2314 const char *name;
2315 const mp_command_type cmd;
2316 } mp_dvdnav_bindings[] = {
2317 { "up", MP_CMD_DVDNAV_UP },
2318 { "down", MP_CMD_DVDNAV_DOWN },
2319 { "left", MP_CMD_DVDNAV_LEFT },
2320 { "right", MP_CMD_DVDNAV_RIGHT },
2321 { "menu", MP_CMD_DVDNAV_MENU },
2322 { "select", MP_CMD_DVDNAV_SELECT },
2323 { "prev", MP_CMD_DVDNAV_PREVMENU },
2324 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2327 * keep old dvdnav sub-command options for a while in order not to
2328 * break slave-mode API too suddenly.
2330 { "1", MP_CMD_DVDNAV_UP },
2331 { "2", MP_CMD_DVDNAV_DOWN },
2332 { "3", MP_CMD_DVDNAV_LEFT },
2333 { "4", MP_CMD_DVDNAV_RIGHT },
2334 { "5", MP_CMD_DVDNAV_MENU },
2335 { "6", MP_CMD_DVDNAV_SELECT },
2336 { "7", MP_CMD_DVDNAV_PREVMENU },
2337 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2338 { NULL, 0 }
2340 #endif
2342 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
2344 sh_audio_t * const sh_audio = mpctx->sh_audio;
2345 sh_video_t * const sh_video = mpctx->sh_video;
2346 int brk_cmd = 0;
2347 if (!set_property_command(mpctx, cmd))
2348 switch (cmd->id) {
2349 case MP_CMD_SEEK:{
2350 float v;
2351 int abs;
2352 if (sh_video)
2353 mpctx->osd_show_percentage = sh_video->fps;
2354 v = cmd->args[0].v.f;
2355 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2356 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2357 abs_seek_pos = SEEK_ABSOLUTE;
2358 if (sh_video)
2359 mpctx->osd_function =
2360 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2361 rel_seek_secs = v;
2362 } else if (abs) { /* Absolute seek by percentage */
2363 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2364 if (sh_video)
2365 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2366 rel_seek_secs = v / 100.0;
2367 } else {
2368 rel_seek_secs += v;
2369 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2371 brk_cmd = 1;
2373 break;
2375 case MP_CMD_SET_PROPERTY:{
2376 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2377 cmd->args[1].v.s, mpctx);
2378 if (r == M_PROPERTY_UNKNOWN)
2379 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2380 "Unknown property: '%s'\n", cmd->args[0].v.s);
2381 else if (r <= 0)
2382 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2383 "Failed to set property '%s' to '%s'.\n",
2384 cmd->args[0].v.s, cmd->args[1].v.s);
2386 break;
2388 case MP_CMD_STEP_PROPERTY:{
2389 void* arg = NULL;
2390 int r,i;
2391 double d;
2392 off_t o;
2393 if (cmd->args[1].v.f) {
2394 m_option_t* prop;
2395 if((r = mp_property_do(cmd->args[0].v.s,
2396 M_PROPERTY_GET_TYPE,
2397 &prop, mpctx)) <= 0)
2398 goto step_prop_err;
2399 if(prop->type == CONF_TYPE_INT ||
2400 prop->type == CONF_TYPE_FLAG)
2401 i = cmd->args[1].v.f, arg = &i;
2402 else if(prop->type == CONF_TYPE_FLOAT)
2403 arg = &cmd->args[1].v.f;
2404 else if(prop->type == CONF_TYPE_DOUBLE ||
2405 prop->type == CONF_TYPE_TIME)
2406 d = cmd->args[1].v.f, arg = &d;
2407 else if(prop->type == CONF_TYPE_POSITION)
2408 o = cmd->args[1].v.f, arg = &o;
2409 else
2410 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2411 "Ignoring step size stepping property '%s'.\n",
2412 cmd->args[0].v.s);
2414 r = mp_property_do(cmd->args[0].v.s,
2415 cmd->args[2].v.i < 0 ?
2416 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2417 arg, mpctx);
2418 step_prop_err:
2419 if (r == M_PROPERTY_UNKNOWN)
2420 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2421 "Unknown property: '%s'\n", cmd->args[0].v.s);
2422 else if (r <= 0)
2423 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2424 "Failed to increment property '%s' by %f.\n",
2425 cmd->args[0].v.s, cmd->args[1].v.f);
2427 break;
2429 case MP_CMD_GET_PROPERTY:{
2430 char *tmp;
2431 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2432 &tmp, mpctx) <= 0) {
2433 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2434 "Failed to get value of property '%s'.\n",
2435 cmd->args[0].v.s);
2436 break;
2438 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2439 cmd->args[0].v.s, tmp);
2440 free(tmp);
2442 break;
2444 case MP_CMD_EDL_MARK:
2445 if (edl_fd) {
2446 float v = sh_video ? sh_video->pts :
2447 playing_audio_pts(sh_audio, mpctx->d_audio,
2448 mpctx->audio_out);
2450 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2451 mpctx->begin_skip = v;
2452 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2453 } else {
2454 if (mpctx->begin_skip > v)
2455 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2456 else {
2457 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2458 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2460 mpctx->begin_skip = MP_NOPTS_VALUE;
2463 break;
2465 case MP_CMD_SWITCH_RATIO:
2466 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2467 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2468 else
2469 movie_aspect = cmd->args[0].v.f;
2470 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2471 break;
2473 case MP_CMD_SPEED_INCR:{
2474 float v = cmd->args[0].v.f;
2475 playback_speed += v;
2476 build_afilter_chain(sh_audio, &ao_data);
2477 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2478 playback_speed);
2479 } break;
2481 case MP_CMD_SPEED_MULT:{
2482 float v = cmd->args[0].v.f;
2483 playback_speed *= v;
2484 build_afilter_chain(sh_audio, &ao_data);
2485 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2486 playback_speed);
2487 } break;
2489 case MP_CMD_SPEED_SET:{
2490 float v = cmd->args[0].v.f;
2491 playback_speed = v;
2492 build_afilter_chain(sh_audio, &ao_data);
2493 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2494 playback_speed);
2495 } break;
2497 case MP_CMD_FRAME_STEP:
2498 case MP_CMD_PAUSE:
2499 cmd->pausing = 1;
2500 brk_cmd = 1;
2501 break;
2503 case MP_CMD_FILE_FILTER:
2504 file_filter = cmd->args[0].v.i;
2505 break;
2507 case MP_CMD_QUIT:
2508 exit_player_with_rc(MSGTR_Exit_quit,
2509 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2511 case MP_CMD_PLAY_TREE_STEP:{
2512 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2513 int force = cmd->args[1].v.i;
2515 #ifdef CONFIG_GUI
2516 if (use_gui) {
2517 int i = 0;
2518 if (n > 0)
2519 for (i = 0; i < n; i++)
2520 mplNext();
2521 else
2522 for (i = 0; i < -1 * n; i++)
2523 mplPrev();
2524 } else
2525 #endif
2527 if (!force && mpctx->playtree_iter) {
2528 play_tree_iter_t *i =
2529 play_tree_iter_new_copy(mpctx->playtree_iter);
2530 if (play_tree_iter_step(i, n, 0) ==
2531 PLAY_TREE_ITER_ENTRY)
2532 mpctx->eof =
2533 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2534 play_tree_iter_free(i);
2535 } else
2536 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2537 if (mpctx->eof)
2538 mpctx->play_tree_step = n;
2539 brk_cmd = 1;
2542 break;
2544 case MP_CMD_PLAY_TREE_UP_STEP:{
2545 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2546 int force = cmd->args[1].v.i;
2548 if (!force && mpctx->playtree_iter) {
2549 play_tree_iter_t *i =
2550 play_tree_iter_new_copy(mpctx->playtree_iter);
2551 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2552 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2553 play_tree_iter_free(i);
2554 } else
2555 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2556 brk_cmd = 1;
2558 break;
2560 case MP_CMD_PLAY_ALT_SRC_STEP:
2561 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2562 int v = cmd->args[0].v.i;
2563 if (v > 0
2564 && mpctx->playtree_iter->file <
2565 mpctx->playtree_iter->num_files)
2566 mpctx->eof = PT_NEXT_SRC;
2567 else if (v < 0 && mpctx->playtree_iter->file > 1)
2568 mpctx->eof = PT_PREV_SRC;
2570 brk_cmd = 1;
2571 break;
2573 case MP_CMD_SUB_STEP:
2574 if (sh_video) {
2575 int movement = cmd->args[0].v.i;
2576 step_sub(subdata, sh_video->pts, movement);
2577 #ifdef CONFIG_ASS
2578 if (ass_track)
2579 sub_delay +=
2580 ass_step_sub(ass_track,
2581 (sh_video->pts +
2582 sub_delay) * 1000 + .5, movement) / 1000.;
2583 #endif
2584 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2585 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2587 break;
2589 case MP_CMD_SUB_LOG:
2590 log_sub();
2591 break;
2593 case MP_CMD_OSD:{
2594 int v = cmd->args[0].v.i;
2595 int max = (term_osd
2596 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2597 if (osd_level > max)
2598 osd_level = max;
2599 if (v < 0)
2600 osd_level = (osd_level + 1) % (max + 1);
2601 else
2602 osd_level = v > max ? max : v;
2603 /* Show OSD state when disabled, but not when an explicit
2604 argument is given to the OSD command, i.e. in slave mode. */
2605 if (v == -1 && osd_level <= 1)
2606 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2607 MSGTR_OSDosd,
2608 osd_level ? MSGTR_OSDenabled :
2609 MSGTR_OSDdisabled);
2610 else
2611 rm_osd_msg(OSD_MSG_OSD_STATUS);
2613 break;
2615 case MP_CMD_OSD_SHOW_TEXT:
2616 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2617 (cmd->args[1].v.i <
2618 0 ? osd_duration : cmd->args[1].v.i),
2619 "%-.63s", cmd->args[0].v.s);
2620 break;
2622 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2623 char *txt = m_properties_expand_string(mp_properties,
2624 cmd->args[0].v.s,
2625 mpctx);
2626 /* if no argument supplied take default osd_duration, else <arg> ms. */
2627 if (txt) {
2628 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2629 (cmd->args[1].v.i <
2630 0 ? osd_duration : cmd->args[1].v.i),
2631 "%-.63s", txt);
2632 free(txt);
2635 break;
2637 case MP_CMD_LOADFILE:{
2638 play_tree_t *e = play_tree_new();
2639 play_tree_add_file(e, cmd->args[0].v.s);
2641 if (cmd->args[1].v.i) // append
2642 play_tree_append_entry(mpctx->playtree->child, e);
2643 else {
2644 // Go back to the starting point.
2645 while (play_tree_iter_up_step
2646 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2647 /* NOP */ ;
2648 play_tree_free_list(mpctx->playtree->child, 1);
2649 play_tree_set_child(mpctx->playtree, e);
2650 pt_iter_goto_head(mpctx->playtree_iter);
2651 mpctx->eof = PT_NEXT_SRC;
2653 brk_cmd = 1;
2655 break;
2657 case MP_CMD_LOADLIST:{
2658 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2659 if (!e)
2660 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2661 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2662 else {
2663 if (cmd->args[1].v.i) // append
2664 play_tree_append_entry(mpctx->playtree->child, e);
2665 else {
2666 // Go back to the starting point.
2667 while (play_tree_iter_up_step
2668 (mpctx->playtree_iter, 0, 1)
2669 != PLAY_TREE_ITER_END)
2670 /* NOP */ ;
2671 play_tree_free_list(mpctx->playtree->child, 1);
2672 play_tree_set_child(mpctx->playtree, e);
2673 pt_iter_goto_head(mpctx->playtree_iter);
2674 mpctx->eof = PT_NEXT_SRC;
2677 brk_cmd = 1;
2679 break;
2681 case MP_CMD_STOP:
2682 // Go back to the starting point.
2683 while (play_tree_iter_up_step
2684 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2685 /* NOP */ ;
2686 mpctx->eof = PT_STOP;
2687 brk_cmd = 1;
2688 break;
2690 #ifdef CONFIG_RADIO
2691 case MP_CMD_RADIO_STEP_CHANNEL:
2692 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2693 int v = cmd->args[0].v.i;
2694 if (v > 0)
2695 radio_step_channel(mpctx->demuxer->stream,
2696 RADIO_CHANNEL_HIGHER);
2697 else
2698 radio_step_channel(mpctx->demuxer->stream,
2699 RADIO_CHANNEL_LOWER);
2700 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2701 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2702 MSGTR_OSDChannel,
2703 radio_get_channel_name(mpctx->demuxer->stream));
2706 break;
2708 case MP_CMD_RADIO_SET_CHANNEL:
2709 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2710 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2711 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2712 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2713 MSGTR_OSDChannel,
2714 radio_get_channel_name(mpctx->demuxer->stream));
2717 break;
2719 case MP_CMD_RADIO_SET_FREQ:
2720 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2721 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2722 break;
2724 case MP_CMD_RADIO_STEP_FREQ:
2725 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2726 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2727 break;
2728 #endif
2730 #ifdef CONFIG_TV
2731 case MP_CMD_TV_START_SCAN:
2732 if (mpctx->file_format == DEMUXER_TYPE_TV)
2733 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2734 break;
2735 case MP_CMD_TV_SET_FREQ:
2736 if (mpctx->file_format == DEMUXER_TYPE_TV)
2737 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2738 cmd->args[0].v.f * 16.0);
2739 #ifdef CONFIG_PVR
2740 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2741 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2742 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2743 pvr_get_current_channelname (mpctx->stream),
2744 pvr_get_current_stationname (mpctx->stream));
2746 #endif /* CONFIG_PVR */
2747 break;
2749 case MP_CMD_TV_STEP_FREQ:
2750 if (mpctx->file_format == DEMUXER_TYPE_TV)
2751 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2752 cmd->args[0].v.f * 16.0);
2753 #ifdef CONFIG_PVR
2754 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2755 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2756 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2757 pvr_get_current_channelname (mpctx->stream),
2758 pvr_get_current_frequency (mpctx->stream));
2760 #endif /* CONFIG_PVR */
2761 break;
2763 case MP_CMD_TV_SET_NORM:
2764 if (mpctx->file_format == DEMUXER_TYPE_TV)
2765 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2766 cmd->args[0].v.s);
2767 break;
2769 case MP_CMD_TV_STEP_CHANNEL:{
2770 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2771 int v = cmd->args[0].v.i;
2772 if (v > 0) {
2773 tv_step_channel((tvi_handle_t *) (mpctx->
2774 demuxer->priv),
2775 TV_CHANNEL_HIGHER);
2776 } else {
2777 tv_step_channel((tvi_handle_t *) (mpctx->
2778 demuxer->priv),
2779 TV_CHANNEL_LOWER);
2781 if (tv_channel_list) {
2782 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2783 MSGTR_OSDChannel, tv_channel_current->name);
2784 //vo_osd_changed(OSDTYPE_SUBTITLE);
2787 #ifdef CONFIG_PVR
2788 else if (mpctx->stream &&
2789 mpctx->stream->type == STREAMTYPE_PVR) {
2790 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2791 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2792 pvr_get_current_channelname (mpctx->stream),
2793 pvr_get_current_stationname (mpctx->stream));
2795 #endif /* CONFIG_PVR */
2797 #ifdef CONFIG_DVBIN
2798 if (mpctx->stream->type == STREAMTYPE_DVB) {
2799 int dir;
2800 int v = cmd->args[0].v.i;
2802 mpctx->last_dvb_step = v;
2803 if (v > 0)
2804 dir = DVB_CHANNEL_HIGHER;
2805 else
2806 dir = DVB_CHANNEL_LOWER;
2809 if (dvb_step_channel(mpctx->stream, dir))
2810 mpctx->eof = mpctx->dvbin_reopen = 1;
2812 #endif /* CONFIG_DVBIN */
2813 break;
2815 case MP_CMD_TV_SET_CHANNEL:
2816 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2817 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2818 cmd->args[0].v.s);
2819 if (tv_channel_list) {
2820 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2821 MSGTR_OSDChannel, tv_channel_current->name);
2822 //vo_osd_changed(OSDTYPE_SUBTITLE);
2825 #ifdef CONFIG_PVR
2826 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2827 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2828 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2829 pvr_get_current_channelname (mpctx->stream),
2830 pvr_get_current_stationname (mpctx->stream));
2832 #endif /* CONFIG_PVR */
2833 break;
2835 #ifdef CONFIG_DVBIN
2836 case MP_CMD_DVB_SET_CHANNEL:
2837 if (mpctx->stream->type == STREAMTYPE_DVB) {
2838 mpctx->last_dvb_step = 1;
2840 if (dvb_set_channel
2841 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2842 mpctx->eof = mpctx->dvbin_reopen = 1;
2844 break;
2845 #endif /* CONFIG_DVBIN */
2847 case MP_CMD_TV_LAST_CHANNEL:
2848 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2849 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2850 if (tv_channel_list) {
2851 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2852 MSGTR_OSDChannel, tv_channel_current->name);
2853 //vo_osd_changed(OSDTYPE_SUBTITLE);
2856 #ifdef CONFIG_PVR
2857 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2858 pvr_set_lastchannel (mpctx->stream);
2859 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2860 pvr_get_current_channelname (mpctx->stream),
2861 pvr_get_current_stationname (mpctx->stream));
2863 #endif /* CONFIG_PVR */
2864 break;
2866 case MP_CMD_TV_STEP_NORM:
2867 if (mpctx->file_format == DEMUXER_TYPE_TV)
2868 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2869 break;
2871 case MP_CMD_TV_STEP_CHANNEL_LIST:
2872 if (mpctx->file_format == DEMUXER_TYPE_TV)
2873 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2874 break;
2875 #ifdef CONFIG_TV_TELETEXT
2876 case MP_CMD_TV_TELETEXT_ADD_DEC:
2878 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2879 if (mpctx->file_format == DEMUXER_TYPE_TV)
2880 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2881 break;
2883 case MP_CMD_TV_TELETEXT_GO_LINK:
2885 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2886 if (mpctx->file_format == DEMUXER_TYPE_TV)
2887 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2888 break;
2890 #endif /* CONFIG_TV_TELETEXT */
2891 #endif /* CONFIG_TV */
2893 case MP_CMD_SUB_LOAD:
2894 if (sh_video) {
2895 int n = mpctx->set_of_sub_size;
2896 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2897 if (n != mpctx->set_of_sub_size) {
2898 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2899 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2900 mpctx->global_sub_size;
2901 ++mpctx->global_sub_size;
2904 break;
2906 case MP_CMD_SUB_REMOVE:
2907 if (sh_video) {
2908 int v = cmd->args[0].v.i;
2909 sub_data *subd;
2910 if (v < 0) {
2911 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2912 subd = mpctx->set_of_subtitles[v];
2913 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2914 MSGTR_RemovedSubtitleFile, v + 1,
2915 filename_recode(subd->filename));
2916 sub_free(subd);
2917 mpctx->set_of_subtitles[v] = NULL;
2919 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2920 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2921 mpctx->set_of_sub_size = 0;
2922 if (mpctx->set_of_sub_pos >= 0) {
2923 mpctx->global_sub_pos = -2;
2924 subdata = NULL;
2925 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2927 } else if (v < mpctx->set_of_sub_size) {
2928 subd = mpctx->set_of_subtitles[v];
2929 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2930 MSGTR_RemovedSubtitleFile, v + 1,
2931 filename_recode(subd->filename));
2932 sub_free(subd);
2933 if (mpctx->set_of_sub_pos == v) {
2934 mpctx->global_sub_pos = -2;
2935 subdata = NULL;
2936 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2937 } else if (mpctx->set_of_sub_pos > v) {
2938 --mpctx->set_of_sub_pos;
2939 --mpctx->global_sub_pos;
2941 while (++v < mpctx->set_of_sub_size)
2942 mpctx->set_of_subtitles[v - 1] =
2943 mpctx->set_of_subtitles[v];
2944 --mpctx->set_of_sub_size;
2945 --mpctx->global_sub_size;
2946 if (mpctx->set_of_sub_size <= 0)
2947 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2948 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2951 break;
2953 case MP_CMD_GET_SUB_VISIBILITY:
2954 if (sh_video) {
2955 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2956 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2958 break;
2960 case MP_CMD_SCREENSHOT:
2961 if (vo_config_count) {
2962 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2963 if (CONTROL_OK !=
2964 ((vf_instance_t *) sh_video->vfilter)->
2965 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2966 &cmd->args[0].v.i))
2967 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2969 break;
2971 case MP_CMD_VF_CHANGE_RECTANGLE:
2972 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2973 break;
2975 case MP_CMD_GET_TIME_LENGTH:{
2976 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2977 demuxer_get_time_length(mpctx->demuxer));
2979 break;
2981 case MP_CMD_GET_FILENAME:{
2982 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2983 get_metadata(META_NAME));
2985 break;
2987 case MP_CMD_GET_VIDEO_CODEC:{
2988 char *inf = get_metadata(META_VIDEO_CODEC);
2989 if (!inf)
2990 inf = strdup("");
2991 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2992 free(inf);
2994 break;
2996 case MP_CMD_GET_VIDEO_BITRATE:{
2997 char *inf = get_metadata(META_VIDEO_BITRATE);
2998 if (!inf)
2999 inf = strdup("");
3000 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3001 free(inf);
3003 break;
3005 case MP_CMD_GET_VIDEO_RESOLUTION:{
3006 char *inf = get_metadata(META_VIDEO_RESOLUTION);
3007 if (!inf)
3008 inf = strdup("");
3009 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3010 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3011 free(inf);
3013 break;
3015 case MP_CMD_GET_AUDIO_CODEC:{
3016 char *inf = get_metadata(META_AUDIO_CODEC);
3017 if (!inf)
3018 inf = strdup("");
3019 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3020 free(inf);
3022 break;
3024 case MP_CMD_GET_AUDIO_BITRATE:{
3025 char *inf = get_metadata(META_AUDIO_BITRATE);
3026 if (!inf)
3027 inf = strdup("");
3028 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3029 free(inf);
3031 break;
3033 case MP_CMD_GET_AUDIO_SAMPLES:{
3034 char *inf = get_metadata(META_AUDIO_SAMPLES);
3035 if (!inf)
3036 inf = strdup("");
3037 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3038 free(inf);
3040 break;
3042 case MP_CMD_GET_META_TITLE:{
3043 char *inf = get_metadata(META_INFO_TITLE);
3044 if (!inf)
3045 inf = strdup("");
3046 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3047 free(inf);
3049 break;
3051 case MP_CMD_GET_META_ARTIST:{
3052 char *inf = get_metadata(META_INFO_ARTIST);
3053 if (!inf)
3054 inf = strdup("");
3055 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3056 free(inf);
3058 break;
3060 case MP_CMD_GET_META_ALBUM:{
3061 char *inf = get_metadata(META_INFO_ALBUM);
3062 if (!inf)
3063 inf = strdup("");
3064 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3065 free(inf);
3067 break;
3069 case MP_CMD_GET_META_YEAR:{
3070 char *inf = get_metadata(META_INFO_YEAR);
3071 if (!inf)
3072 inf = strdup("");
3073 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3074 free(inf);
3076 break;
3078 case MP_CMD_GET_META_COMMENT:{
3079 char *inf = get_metadata(META_INFO_COMMENT);
3080 if (!inf)
3081 inf = strdup("");
3082 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3083 free(inf);
3085 break;
3087 case MP_CMD_GET_META_TRACK:{
3088 char *inf = get_metadata(META_INFO_TRACK);
3089 if (!inf)
3090 inf = strdup("");
3091 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3092 free(inf);
3094 break;
3096 case MP_CMD_GET_META_GENRE:{
3097 char *inf = get_metadata(META_INFO_GENRE);
3098 if (!inf)
3099 inf = strdup("");
3100 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3101 free(inf);
3103 break;
3105 case MP_CMD_GET_VO_FULLSCREEN:
3106 if (mpctx->video_out && vo_config_count)
3107 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3108 break;
3110 case MP_CMD_GET_PERCENT_POS:
3111 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3112 demuxer_get_percent_pos(mpctx->demuxer));
3113 break;
3115 case MP_CMD_GET_TIME_POS:{
3116 float pos = 0;
3117 if (sh_video)
3118 pos = sh_video->pts;
3119 else if (sh_audio && mpctx->audio_out)
3120 pos =
3121 playing_audio_pts(sh_audio, mpctx->d_audio,
3122 mpctx->audio_out);
3123 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3125 break;
3127 case MP_CMD_RUN:
3128 #ifndef __MINGW32__
3129 if (!fork()) {
3130 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3131 exit(0);
3133 #endif
3134 break;
3136 case MP_CMD_KEYDOWN_EVENTS:
3137 mplayer_put_key(cmd->args[0].v.i);
3138 break;
3140 case MP_CMD_SET_MOUSE_POS:{
3141 int pointer_x, pointer_y;
3142 double dx, dy;
3143 pointer_x = cmd->args[0].v.i;
3144 pointer_y = cmd->args[1].v.i;
3145 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
3146 #ifdef CONFIG_DVDNAV
3147 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3148 && dx > 0.0 && dy > 0.0) {
3149 int button = -1;
3150 pointer_x = (int) (dx * (double) sh_video->disp_w);
3151 pointer_y = (int) (dy * (double) sh_video->disp_h);
3152 mp_dvdnav_update_mouse_pos(mpctx->stream,
3153 pointer_x, pointer_y, &button);
3154 if (osd_level > 1 && button > 0)
3155 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3156 "Selected button number %d", button);
3158 #endif
3159 #ifdef CONFIG_MENU
3160 if (use_menu && dx >= 0.0 && dy >= 0.0)
3161 menu_update_mouse_pos(dx, dy);
3162 #endif
3164 break;
3166 #ifdef CONFIG_DVDNAV
3167 case MP_CMD_DVDNAV:{
3168 int button = -1;
3169 int i;
3170 mp_command_type command = 0;
3171 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3172 break;
3174 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3175 if (cmd->args[0].v.s &&
3176 !strcasecmp (cmd->args[0].v.s,
3177 mp_dvdnav_bindings[i].name))
3178 command = mp_dvdnav_bindings[i].cmd;
3180 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3181 if (osd_level > 1 && button > 0)
3182 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3183 "Selected button number %d", button);
3185 break;
3187 case MP_CMD_SWITCH_TITLE:
3188 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3189 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3190 break;
3192 #endif
3194 default:
3195 #ifdef CONFIG_GUI
3196 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3197 guiGetEvent(guiIEvent, (char *) cmd->id);
3198 else
3199 #endif
3200 mp_msg(MSGT_CPLAYER, MSGL_V,
3201 "Received unknown cmd %s\n", cmd->name);
3204 switch (cmd->pausing) {
3205 case 1: // "pausing"
3206 mpctx->osd_function = OSD_PAUSE;
3207 break;
3208 case 3: // "pausing_toggle"
3209 mpctx->was_paused = !mpctx->was_paused;
3210 if (mpctx->was_paused)
3211 mpctx->osd_function = OSD_PAUSE;
3212 else if (mpctx->osd_function == OSD_PAUSE)
3213 mpctx->osd_function = OSD_PLAY;
3214 break;
3215 case 2: // "pausing_keep"
3216 if (mpctx->was_paused)
3217 mpctx->osd_function = OSD_PAUSE;
3219 return brk_cmd;