synced with r26729
[mplayer/greg.git] / command.c
blob7ccd0ec9de208de9d48e8d12231d9482f3328ba9
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 USE_TV
32 #include "stream/tv.h"
33 #endif
34 #ifdef USE_RADIO
35 #include "stream/stream_radio.h"
36 #endif
37 #ifdef HAVE_PVR
38 #include "stream/pvr.h"
39 #endif
40 #ifdef HAS_DVBIN_SUPPORT
41 #include "stream/dvbin.h"
42 #endif
43 #ifdef USE_DVDREAD
44 #include "stream/stream_dvd.h"
45 #endif
46 #ifdef USE_DVDNAV
47 #include "stream/stream_dvdnav.h"
48 #endif
49 #ifdef USE_ASS
50 #include "libass/ass.h"
51 #include "libass/ass_mp.h"
52 #endif
53 #ifdef HAVE_MENU
54 #include "m_struct.h"
55 #include "libmenu/menu.h"
56 #endif
57 #ifdef HAVE_NEW_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;
383 float next_pts = 0;
384 int chapter_num;
385 int step_all;
386 char *chapter_name = NULL;
388 chapter = demuxer_get_current_chapter(mpctx->demuxer);
389 if (chapter < 0)
390 return M_PROPERTY_UNAVAILABLE;
392 switch (action) {
393 case M_PROPERTY_GET:
394 if (!arg)
395 return M_PROPERTY_ERROR;
396 *(int *) arg = chapter;
397 return M_PROPERTY_OK;
398 case M_PROPERTY_PRINT: {
399 if (!arg)
400 return M_PROPERTY_ERROR;
401 chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter);
402 if (!chapter_name)
403 return M_PROPERTY_UNAVAILABLE;
404 *(char **) arg = chapter_name;
405 return M_PROPERTY_OK;
407 case M_PROPERTY_SET:
408 if (!arg)
409 return M_PROPERTY_ERROR;
410 M_PROPERTY_CLAMP(prop, *(int*)arg);
411 step_all = *(int *)arg - (chapter + 1);
412 chapter += step_all;
413 break;
414 case M_PROPERTY_STEP_UP:
415 case M_PROPERTY_STEP_DOWN: {
416 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
417 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
418 chapter += step_all;
419 if (chapter < 0)
420 chapter = 0;
421 break;
423 default:
424 return M_PROPERTY_NOT_IMPLEMENTED;
426 rel_seek_secs = 0;
427 abs_seek_pos = 0;
428 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
429 &next_pts, &chapter_num, &chapter_name);
430 if (chapter >= 0) {
431 if (next_pts > -1.0) {
432 abs_seek_pos = SEEK_ABSOLUTE;
433 rel_seek_secs = next_pts;
435 if (chapter_name)
436 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
437 MSGTR_OSDChapter, chapter + 1, chapter_name);
439 else if (step_all > 0)
440 rel_seek_secs = 1000000000.;
441 else
442 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
443 MSGTR_OSDChapter, 0, MSGTR_Unknown);
444 if (chapter_name)
445 free(chapter_name);
446 return M_PROPERTY_OK;
449 /// Current dvd angle (RW)
450 static int mp_property_angle(m_option_t *prop, int action, void *arg,
451 MPContext *mpctx)
453 int angle;
454 int angles;
455 char *angle_name = NULL;
457 angle = demuxer_get_current_angle(mpctx->demuxer);
458 if (angle < 0)
459 return M_PROPERTY_UNAVAILABLE;
460 angles = demuxer_angles_count(mpctx->demuxer);
461 if (angles <= 1)
462 return M_PROPERTY_UNAVAILABLE;
464 switch (action) {
465 case M_PROPERTY_GET:
466 if (!arg)
467 return M_PROPERTY_ERROR;
468 *(int *) arg = angle;
469 return M_PROPERTY_OK;
470 case M_PROPERTY_PRINT: {
471 if (!arg)
472 return M_PROPERTY_ERROR;
473 angle_name = calloc(1, 64);
474 if (!angle_name)
475 return M_PROPERTY_UNAVAILABLE;
476 snprintf(angle_name, 64, "%d/%d", angle, angles);
477 *(char **) arg = angle_name;
478 return M_PROPERTY_OK;
480 case M_PROPERTY_SET:
481 if (!arg)
482 return M_PROPERTY_ERROR;
483 angle = *(int *)arg;
484 M_PROPERTY_CLAMP(prop, angle);
485 break;
486 case M_PROPERTY_STEP_UP:
487 case M_PROPERTY_STEP_DOWN: {
488 int step = 0;
489 if(arg)
490 step = *(int*)arg;
491 if(!step)
492 step = 1;
493 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
494 angle += step;
495 if (angle < 1) //cycle
496 angle = angles;
497 break;
499 default:
500 return M_PROPERTY_NOT_IMPLEMENTED;
502 angle = demuxer_set_angle(mpctx->demuxer, angle);
503 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
504 MSGTR_OSDAngle, angle, angles);
505 if (angle_name)
506 free(angle_name);
507 return M_PROPERTY_OK;
510 /// Demuxer meta data
511 static int mp_property_metadata(m_option_t * prop, int action, void *arg,
512 MPContext * mpctx) {
513 m_property_action_t* ka;
514 char* meta;
515 static m_option_t key_type =
516 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
517 if (!mpctx->demuxer)
518 return M_PROPERTY_UNAVAILABLE;
520 switch(action) {
521 case M_PROPERTY_GET:
522 if(!arg) return M_PROPERTY_ERROR;
523 *(char***)arg = mpctx->demuxer->info;
524 return M_PROPERTY_OK;
525 case M_PROPERTY_KEY_ACTION:
526 if(!arg) return M_PROPERTY_ERROR;
527 ka = arg;
528 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
529 return M_PROPERTY_UNKNOWN;
530 switch(ka->action) {
531 case M_PROPERTY_GET:
532 if(!ka->arg) return M_PROPERTY_ERROR;
533 *(char**)ka->arg = meta;
534 return M_PROPERTY_OK;
535 case M_PROPERTY_GET_TYPE:
536 if(!ka->arg) return M_PROPERTY_ERROR;
537 *(m_option_t**)ka->arg = &key_type;
538 return M_PROPERTY_OK;
541 return M_PROPERTY_NOT_IMPLEMENTED;
545 ///@}
547 /// \defgroup AudioProperties Audio properties
548 /// \ingroup Properties
549 ///@{
551 /// Volume (RW)
552 static int mp_property_volume(m_option_t * prop, int action, void *arg,
553 MPContext * mpctx)
556 if (!mpctx->sh_audio)
557 return M_PROPERTY_UNAVAILABLE;
559 switch (action) {
560 case M_PROPERTY_GET:
561 if (!arg)
562 return M_PROPERTY_ERROR;
563 mixer_getbothvolume(&mpctx->mixer, arg);
564 return M_PROPERTY_OK;
565 case M_PROPERTY_PRINT:{
566 float vol;
567 if (!arg)
568 return M_PROPERTY_ERROR;
569 mixer_getbothvolume(&mpctx->mixer, &vol);
570 return m_property_float_range(prop, action, arg, &vol);
572 case M_PROPERTY_STEP_UP:
573 case M_PROPERTY_STEP_DOWN:
574 case M_PROPERTY_SET:
575 break;
576 default:
577 return M_PROPERTY_NOT_IMPLEMENTED;
580 if (mpctx->edl_muted)
581 return M_PROPERTY_DISABLED;
582 mpctx->user_muted = 0;
584 switch (action) {
585 case M_PROPERTY_SET:
586 if (!arg)
587 return M_PROPERTY_ERROR;
588 M_PROPERTY_CLAMP(prop, *(float *) arg);
589 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
590 return M_PROPERTY_OK;
591 case M_PROPERTY_STEP_UP:
592 if (arg && *(float *) arg <= 0)
593 mixer_decvolume(&mpctx->mixer);
594 else
595 mixer_incvolume(&mpctx->mixer);
596 return M_PROPERTY_OK;
597 case M_PROPERTY_STEP_DOWN:
598 if (arg && *(float *) arg <= 0)
599 mixer_incvolume(&mpctx->mixer);
600 else
601 mixer_decvolume(&mpctx->mixer);
602 return M_PROPERTY_OK;
604 return M_PROPERTY_NOT_IMPLEMENTED;
607 /// Mute (RW)
608 static int mp_property_mute(m_option_t * prop, int action, void *arg,
609 MPContext * mpctx)
612 if (!mpctx->sh_audio)
613 return M_PROPERTY_UNAVAILABLE;
615 switch (action) {
616 case M_PROPERTY_SET:
617 if (mpctx->edl_muted)
618 return M_PROPERTY_DISABLED;
619 if (!arg)
620 return M_PROPERTY_ERROR;
621 if ((!!*(int *) arg) != mpctx->mixer.muted)
622 mixer_mute(&mpctx->mixer);
623 mpctx->user_muted = mpctx->mixer.muted;
624 return M_PROPERTY_OK;
625 case M_PROPERTY_STEP_UP:
626 case M_PROPERTY_STEP_DOWN:
627 if (mpctx->edl_muted)
628 return M_PROPERTY_DISABLED;
629 mixer_mute(&mpctx->mixer);
630 mpctx->user_muted = mpctx->mixer.muted;
631 return M_PROPERTY_OK;
632 case M_PROPERTY_PRINT:
633 if (!arg)
634 return M_PROPERTY_ERROR;
635 if (mpctx->edl_muted) {
636 *(char **) arg = strdup(MSGTR_EnabledEdl);
637 return M_PROPERTY_OK;
639 default:
640 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
645 /// Audio delay (RW)
646 static int mp_property_audio_delay(m_option_t * prop, int action,
647 void *arg, MPContext * mpctx)
649 if (!(mpctx->sh_audio && mpctx->sh_video))
650 return M_PROPERTY_UNAVAILABLE;
651 switch (action) {
652 case M_PROPERTY_SET:
653 case M_PROPERTY_STEP_UP:
654 case M_PROPERTY_STEP_DOWN: {
655 int ret;
656 float delay = audio_delay;
657 ret = m_property_delay(prop, action, arg, &audio_delay);
658 if (ret != M_PROPERTY_OK)
659 return ret;
660 if (mpctx->sh_audio)
661 mpctx->delay -= audio_delay - delay;
663 return M_PROPERTY_OK;
664 default:
665 return m_property_delay(prop, action, arg, &audio_delay);
669 /// Audio codec tag (RO)
670 static int mp_property_audio_format(m_option_t * prop, int action,
671 void *arg, MPContext * mpctx)
673 if (!mpctx->sh_audio)
674 return M_PROPERTY_UNAVAILABLE;
675 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
678 /// Audio codec name (RO)
679 static int mp_property_audio_codec(m_option_t * prop, int action,
680 void *arg, MPContext * mpctx)
682 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
683 return M_PROPERTY_UNAVAILABLE;
684 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
687 /// Audio bitrate (RO)
688 static int mp_property_audio_bitrate(m_option_t * prop, int action,
689 void *arg, MPContext * mpctx)
691 if (!mpctx->sh_audio)
692 return M_PROPERTY_UNAVAILABLE;
693 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
696 /// Samplerate (RO)
697 static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
698 MPContext * mpctx)
700 if (!mpctx->sh_audio)
701 return M_PROPERTY_UNAVAILABLE;
702 switch(action) {
703 case M_PROPERTY_PRINT:
704 if(!arg) return M_PROPERTY_ERROR;
705 *(char**)arg = malloc(16);
706 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
707 return M_PROPERTY_OK;
709 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
712 /// Number of channels (RO)
713 static int mp_property_channels(m_option_t * prop, int action, void *arg,
714 MPContext * mpctx)
716 if (!mpctx->sh_audio)
717 return M_PROPERTY_UNAVAILABLE;
718 switch (action) {
719 case M_PROPERTY_PRINT:
720 if (!arg)
721 return M_PROPERTY_ERROR;
722 switch (mpctx->sh_audio->channels) {
723 case 1:
724 *(char **) arg = strdup("mono");
725 break;
726 case 2:
727 *(char **) arg = strdup("stereo");
728 break;
729 default:
730 *(char **) arg = malloc(32);
731 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
733 return M_PROPERTY_OK;
735 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
738 /// Balance (RW)
739 static int mp_property_balance(m_option_t * prop, int action, void *arg,
740 MPContext * mpctx)
742 float bal;
744 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
745 return M_PROPERTY_UNAVAILABLE;
747 switch (action) {
748 case M_PROPERTY_GET:
749 if (!arg)
750 return M_PROPERTY_ERROR;
751 mixer_getbalance(&mpctx->mixer, arg);
752 return M_PROPERTY_OK;
753 case M_PROPERTY_PRINT: {
754 char** str = arg;
755 if (!arg)
756 return M_PROPERTY_ERROR;
757 mixer_getbalance(&mpctx->mixer, &bal);
758 if (bal == 0.f)
759 *str = strdup("center");
760 else if (bal == -1.f)
761 *str = strdup("left only");
762 else if (bal == 1.f)
763 *str = strdup("right only");
764 else {
765 unsigned right = (bal + 1.f) / 2.f * 100.f;
766 *str = malloc(sizeof("left xxx%, right xxx%"));
767 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
769 return M_PROPERTY_OK;
771 case M_PROPERTY_STEP_UP:
772 case M_PROPERTY_STEP_DOWN:
773 mixer_getbalance(&mpctx->mixer, &bal);
774 bal += (arg ? *(float*)arg : .1f) *
775 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
776 M_PROPERTY_CLAMP(prop, bal);
777 mixer_setbalance(&mpctx->mixer, bal);
778 return M_PROPERTY_OK;
779 case M_PROPERTY_SET:
780 if (!arg)
781 return M_PROPERTY_ERROR;
782 M_PROPERTY_CLAMP(prop, *(float*)arg);
783 mixer_setbalance(&mpctx->mixer, *(float*)arg);
784 return M_PROPERTY_OK;
786 return M_PROPERTY_NOT_IMPLEMENTED;
789 /// Selected audio id (RW)
790 static int mp_property_audio(m_option_t * prop, int action, void *arg,
791 MPContext * mpctx)
793 int current_id = -1, tmp;
795 switch (action) {
796 case M_PROPERTY_GET:
797 if (!mpctx->sh_audio)
798 return M_PROPERTY_UNAVAILABLE;
799 if (!arg)
800 return M_PROPERTY_ERROR;
801 *(int *) arg = audio_id;
802 return M_PROPERTY_OK;
803 case M_PROPERTY_PRINT:
804 if (!mpctx->sh_audio)
805 return M_PROPERTY_UNAVAILABLE;
806 if (!arg)
807 return M_PROPERTY_ERROR;
809 if (audio_id < 0)
810 *(char **) arg = strdup(MSGTR_Disabled);
811 else {
812 char lang[40] = MSGTR_Unknown;
813 sh_audio_t* sh = mpctx->sh_audio;
814 if (sh && sh->lang)
815 av_strlcpy(lang, sh->lang, 40);
816 #ifdef USE_DVDREAD
817 else if (mpctx->stream->type == STREAMTYPE_DVD) {
818 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
819 if (code) {
820 lang[0] = code >> 8;
821 lang[1] = code;
822 lang[2] = 0;
825 #endif
827 #ifdef USE_DVDNAV
828 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
829 dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
830 #endif
831 *(char **) arg = malloc(64);
832 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
834 return M_PROPERTY_OK;
836 case M_PROPERTY_STEP_UP:
837 case M_PROPERTY_SET:
838 if (action == M_PROPERTY_SET && arg)
839 tmp = *((int *) arg);
840 else
841 tmp = -1;
842 current_id = mpctx->demuxer->audio->id;
843 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
844 if (audio_id == -2
845 || (audio_id > -1
846 && mpctx->demuxer->audio->id != current_id && current_id != -2))
847 uninit_player(INITIALIZED_AO | INITIALIZED_ACODEC);
848 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
849 sh_audio_t *sh2;
850 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
851 if (sh2) {
852 sh2->ds = mpctx->demuxer->audio;
853 mpctx->sh_audio = sh2;
854 reinit_audio_chain();
857 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
858 return M_PROPERTY_OK;
859 default:
860 return M_PROPERTY_NOT_IMPLEMENTED;
865 /// Selected video id (RW)
866 static int mp_property_video(m_option_t * prop, int action, void *arg,
867 MPContext * mpctx)
869 int current_id = -1, tmp;
871 switch (action) {
872 case M_PROPERTY_GET:
873 if (!mpctx->sh_video)
874 return M_PROPERTY_UNAVAILABLE;
875 if (!arg)
876 return M_PROPERTY_ERROR;
877 *(int *) arg = video_id;
878 return M_PROPERTY_OK;
879 case M_PROPERTY_PRINT:
880 if (!mpctx->sh_video)
881 return M_PROPERTY_UNAVAILABLE;
882 if (!arg)
883 return M_PROPERTY_ERROR;
885 if (video_id < 0)
886 *(char **) arg = strdup(MSGTR_Disabled);
887 else {
888 char lang[40] = MSGTR_Unknown;
889 *(char **) arg = malloc(64);
890 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
892 return M_PROPERTY_OK;
894 case M_PROPERTY_STEP_UP:
895 case M_PROPERTY_SET:
896 current_id = mpctx->demuxer->video->id;
897 if (action == M_PROPERTY_SET && arg)
898 tmp = *((int *) arg);
899 else
900 tmp = -1;
901 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
902 if (video_id == -2
903 || (video_id > -1 && mpctx->demuxer->video->id != current_id
904 && current_id != -2))
905 uninit_player(INITIALIZED_VCODEC |
906 (fixed_vo && video_id != -2 ? 0 : INITIALIZED_VO));
907 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
908 sh_video_t *sh2;
909 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
910 if (sh2) {
911 sh2->ds = mpctx->demuxer->video;
912 mpctx->sh_video = sh2;
913 reinit_video_chain();
916 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
917 return M_PROPERTY_OK;
919 default:
920 return M_PROPERTY_NOT_IMPLEMENTED;
924 static int mp_property_program(m_option_t * prop, int action, void *arg,
925 MPContext * mpctx)
927 demux_program_t prog;
929 switch (action) {
930 case M_PROPERTY_STEP_UP:
931 case M_PROPERTY_SET:
932 if (action == M_PROPERTY_SET && arg)
933 prog.progid = *((int *) arg);
934 else
935 prog.progid = -1;
936 if (demux_control
937 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
938 &prog) == DEMUXER_CTRL_NOTIMPL)
939 return M_PROPERTY_ERROR;
941 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
942 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
943 return M_PROPERTY_OK;
945 default:
946 return M_PROPERTY_NOT_IMPLEMENTED;
950 ///@}
952 /// \defgroup VideoProperties Video properties
953 /// \ingroup Properties
954 ///@{
956 /// Fullscreen state (RW)
957 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
958 MPContext * mpctx)
961 if (!mpctx->video_out)
962 return M_PROPERTY_UNAVAILABLE;
964 switch (action) {
965 case M_PROPERTY_SET:
966 if (!arg)
967 return M_PROPERTY_ERROR;
968 M_PROPERTY_CLAMP(prop, *(int *) arg);
969 if (vo_fs == !!*(int *) arg)
970 return M_PROPERTY_OK;
971 case M_PROPERTY_STEP_UP:
972 case M_PROPERTY_STEP_DOWN:
973 #ifdef HAVE_NEW_GUI
974 if (use_gui)
975 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
976 else
977 #endif
978 if (vo_config_count)
979 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
980 return M_PROPERTY_OK;
981 default:
982 return m_property_flag(prop, action, arg, &vo_fs);
986 static int mp_property_deinterlace(m_option_t * prop, int action,
987 void *arg, MPContext * mpctx)
989 int deinterlace;
990 vf_instance_t *vf;
991 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
992 return M_PROPERTY_UNAVAILABLE;
993 vf = mpctx->sh_video->vfilter;
994 switch (action) {
995 case M_PROPERTY_GET:
996 if (!arg)
997 return M_PROPERTY_ERROR;
998 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
999 return M_PROPERTY_OK;
1000 case M_PROPERTY_SET:
1001 if (!arg)
1002 return M_PROPERTY_ERROR;
1003 M_PROPERTY_CLAMP(prop, *(int *) arg);
1004 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1005 return M_PROPERTY_OK;
1006 case M_PROPERTY_STEP_UP:
1007 case M_PROPERTY_STEP_DOWN:
1008 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1009 deinterlace = !deinterlace;
1010 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1011 return M_PROPERTY_OK;
1013 return M_PROPERTY_NOT_IMPLEMENTED;
1016 /// Panscan (RW)
1017 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
1018 MPContext * mpctx)
1021 if (!mpctx->video_out
1022 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1023 return M_PROPERTY_UNAVAILABLE;
1025 switch (action) {
1026 case M_PROPERTY_SET:
1027 if (!arg)
1028 return M_PROPERTY_ERROR;
1029 M_PROPERTY_CLAMP(prop, *(float *) arg);
1030 vo_panscan = *(float *) arg;
1031 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1032 return M_PROPERTY_OK;
1033 case M_PROPERTY_STEP_UP:
1034 case M_PROPERTY_STEP_DOWN:
1035 vo_panscan += (arg ? *(float *) arg : 0.1) *
1036 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1037 if (vo_panscan > 1)
1038 vo_panscan = 1;
1039 else if (vo_panscan < 0)
1040 vo_panscan = 0;
1041 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1042 return M_PROPERTY_OK;
1043 default:
1044 return m_property_float_range(prop, action, arg, &vo_panscan);
1048 /// Helper to set vo flags.
1049 /** \ingroup PropertyImplHelper
1051 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
1052 int vo_ctrl, int *vo_var, MPContext * mpctx)
1055 if (!mpctx->video_out)
1056 return M_PROPERTY_UNAVAILABLE;
1058 switch (action) {
1059 case M_PROPERTY_SET:
1060 if (!arg)
1061 return M_PROPERTY_ERROR;
1062 M_PROPERTY_CLAMP(prop, *(int *) arg);
1063 if (*vo_var == !!*(int *) arg)
1064 return M_PROPERTY_OK;
1065 case M_PROPERTY_STEP_UP:
1066 case M_PROPERTY_STEP_DOWN:
1067 if (vo_config_count)
1068 mpctx->video_out->control(vo_ctrl, 0);
1069 return M_PROPERTY_OK;
1070 default:
1071 return m_property_flag(prop, action, arg, vo_var);
1075 /// Window always on top (RW)
1076 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
1077 MPContext * mpctx)
1079 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
1080 mpctx);
1083 /// Display in the root window (RW)
1084 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
1085 MPContext * mpctx)
1087 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1088 &vo_rootwin, mpctx);
1091 /// Show window borders (RW)
1092 static int mp_property_border(m_option_t * prop, int action, void *arg,
1093 MPContext * mpctx)
1095 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1096 &vo_border, mpctx);
1099 /// Framedropping state (RW)
1100 static int mp_property_framedropping(m_option_t * prop, int action,
1101 void *arg, MPContext * mpctx)
1104 if (!mpctx->sh_video)
1105 return M_PROPERTY_UNAVAILABLE;
1107 switch (action) {
1108 case M_PROPERTY_PRINT:
1109 if (!arg)
1110 return M_PROPERTY_ERROR;
1111 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1112 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1113 MSGTR_Disabled));
1114 return M_PROPERTY_OK;
1115 default:
1116 return m_property_choice(prop, action, arg, &frame_dropping);
1120 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1121 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
1122 MPContext * mpctx)
1124 int *gamma = prop->priv, r, val;
1126 if (!mpctx->sh_video)
1127 return M_PROPERTY_UNAVAILABLE;
1129 if (gamma[0] == 1000) {
1130 gamma[0] = 0;
1131 get_video_colors(mpctx->sh_video, prop->name, gamma);
1134 switch (action) {
1135 case M_PROPERTY_SET:
1136 if (!arg)
1137 return M_PROPERTY_ERROR;
1138 M_PROPERTY_CLAMP(prop, *(int *) arg);
1139 *gamma = *(int *) arg;
1140 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1141 if (r <= 0)
1142 break;
1143 return r;
1144 case M_PROPERTY_GET:
1145 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1146 if (!arg)
1147 return M_PROPERTY_ERROR;
1148 *(int *)arg = val;
1149 return M_PROPERTY_OK;
1151 break;
1152 case M_PROPERTY_STEP_UP:
1153 case M_PROPERTY_STEP_DOWN:
1154 *gamma += (arg ? *(int *) arg : 1) *
1155 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1156 M_PROPERTY_CLAMP(prop, *gamma);
1157 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1158 if (r <= 0)
1159 break;
1160 return r;
1161 default:
1162 return M_PROPERTY_NOT_IMPLEMENTED;
1165 #ifdef USE_TV
1166 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1167 int l = strlen(prop->name);
1168 char tv_prop[3 + l + 1];
1169 sprintf(tv_prop, "tv_%s", prop->name);
1170 return mp_property_do(tv_prop, action, arg, mpctx);
1172 #endif
1174 return M_PROPERTY_UNAVAILABLE;
1177 /// VSync (RW)
1178 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1179 MPContext * mpctx)
1181 return m_property_flag(prop, action, arg, &vo_vsync);
1184 /// Video codec tag (RO)
1185 static int mp_property_video_format(m_option_t * prop, int action,
1186 void *arg, MPContext * mpctx)
1188 char* meta;
1189 if (!mpctx->sh_video)
1190 return M_PROPERTY_UNAVAILABLE;
1191 switch(action) {
1192 case M_PROPERTY_PRINT:
1193 if (!arg)
1194 return M_PROPERTY_ERROR;
1195 switch(mpctx->sh_video->format) {
1196 case 0x10000001:
1197 meta = strdup ("mpeg1"); break;
1198 case 0x10000002:
1199 meta = strdup ("mpeg2"); break;
1200 case 0x10000004:
1201 meta = strdup ("mpeg4"); break;
1202 case 0x10000005:
1203 meta = strdup ("h264"); break;
1204 default:
1205 if(mpctx->sh_video->format >= 0x20202020) {
1206 meta = malloc(5);
1207 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1208 } else {
1209 meta = malloc(20);
1210 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1213 *(char**)arg = meta;
1214 return M_PROPERTY_OK;
1216 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1219 /// Video codec name (RO)
1220 static int mp_property_video_codec(m_option_t * prop, int action,
1221 void *arg, MPContext * mpctx)
1223 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1224 return M_PROPERTY_UNAVAILABLE;
1225 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1229 /// Video bitrate (RO)
1230 static int mp_property_video_bitrate(m_option_t * prop, int action,
1231 void *arg, MPContext * mpctx)
1233 if (!mpctx->sh_video)
1234 return M_PROPERTY_UNAVAILABLE;
1235 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1238 /// Video display width (RO)
1239 static int mp_property_width(m_option_t * prop, int action, void *arg,
1240 MPContext * mpctx)
1242 if (!mpctx->sh_video)
1243 return M_PROPERTY_UNAVAILABLE;
1244 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1247 /// Video display height (RO)
1248 static int mp_property_height(m_option_t * prop, int action, void *arg,
1249 MPContext * mpctx)
1251 if (!mpctx->sh_video)
1252 return M_PROPERTY_UNAVAILABLE;
1253 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1256 /// Video fps (RO)
1257 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1258 MPContext * mpctx)
1260 if (!mpctx->sh_video)
1261 return M_PROPERTY_UNAVAILABLE;
1262 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1265 /// Video aspect (RO)
1266 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1267 MPContext * mpctx)
1269 if (!mpctx->sh_video)
1270 return M_PROPERTY_UNAVAILABLE;
1271 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1274 ///@}
1276 /// \defgroup SubProprties Subtitles properties
1277 /// \ingroup Properties
1278 ///@{
1280 /// Text subtitle position (RW)
1281 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1282 MPContext * mpctx)
1284 if (!mpctx->sh_video)
1285 return M_PROPERTY_UNAVAILABLE;
1287 switch (action) {
1288 case M_PROPERTY_SET:
1289 if (!arg)
1290 return M_PROPERTY_ERROR;
1291 case M_PROPERTY_STEP_UP:
1292 case M_PROPERTY_STEP_DOWN:
1293 vo_osd_changed(OSDTYPE_SUBTITLE);
1294 default:
1295 return m_property_int_range(prop, action, arg, &sub_pos);
1299 /// Selected subtitles (RW)
1300 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1301 MPContext * mpctx)
1303 demux_stream_t *const d_sub = mpctx->d_sub;
1304 const int global_sub_size = mpctx->global_sub_size;
1305 int source = -1, reset_spu = 0;
1306 char *sub_name;
1308 if (global_sub_size <= 0)
1309 return M_PROPERTY_UNAVAILABLE;
1311 switch (action) {
1312 case M_PROPERTY_GET:
1313 if (!arg)
1314 return M_PROPERTY_ERROR;
1315 *(int *) arg = mpctx->global_sub_pos;
1316 return M_PROPERTY_OK;
1317 case M_PROPERTY_PRINT:
1318 if (!arg)
1319 return M_PROPERTY_ERROR;
1320 *(char **) arg = malloc(64);
1321 (*(char **) arg)[63] = 0;
1322 sub_name = 0;
1323 if (subdata)
1324 sub_name = subdata->filename;
1325 #ifdef USE_ASS
1326 if (ass_track && ass_track->name)
1327 sub_name = ass_track->name;
1328 #endif
1329 if (sub_name) {
1330 char *tmp, *tmp2;
1331 tmp = sub_name;
1332 if ((tmp2 = strrchr(tmp, '/')))
1333 tmp = tmp2 + 1;
1335 snprintf(*(char **) arg, 63, "(%d) %s%s",
1336 mpctx->set_of_sub_pos + 1,
1337 strlen(tmp) < 20 ? "" : "...",
1338 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1339 return M_PROPERTY_OK;
1341 #ifdef USE_DVDNAV
1342 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1343 if (vo_spudec && dvdsub_id >= 0) {
1344 unsigned char lang[3];
1345 if (dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1346 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1347 return M_PROPERTY_OK;
1351 #endif
1353 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1354 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1355 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1356 && d_sub && d_sub->sh && dvdsub_id >= 0) {
1357 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1358 if (!lang) lang = MSGTR_Unknown;
1359 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1360 return M_PROPERTY_OK;
1363 if (vo_vobsub && vobsub_id >= 0) {
1364 const char *language = MSGTR_Unknown;
1365 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1366 snprintf(*(char **) arg, 63, "(%d) %s",
1367 vobsub_id, language ? language : MSGTR_Unknown);
1368 return M_PROPERTY_OK;
1370 #ifdef USE_DVDREAD
1371 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1372 && dvdsub_id >= 0) {
1373 char lang[3];
1374 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1375 lang[0] = code >> 8;
1376 lang[1] = code;
1377 lang[2] = 0;
1378 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1379 return M_PROPERTY_OK;
1381 #endif
1382 if (dvdsub_id >= 0) {
1383 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1384 return M_PROPERTY_OK;
1386 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1387 return M_PROPERTY_OK;
1389 case M_PROPERTY_SET:
1390 if (!arg)
1391 return M_PROPERTY_ERROR;
1392 if (*(int *) arg < -1)
1393 *(int *) arg = -1;
1394 else if (*(int *) arg >= global_sub_size)
1395 *(int *) arg = global_sub_size - 1;
1396 mpctx->global_sub_pos = *(int *) arg;
1397 break;
1398 case M_PROPERTY_STEP_UP:
1399 mpctx->global_sub_pos += 2;
1400 mpctx->global_sub_pos =
1401 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1402 break;
1403 case M_PROPERTY_STEP_DOWN:
1404 mpctx->global_sub_pos += global_sub_size + 1;
1405 mpctx->global_sub_pos =
1406 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1407 break;
1408 default:
1409 return M_PROPERTY_NOT_IMPLEMENTED;
1412 if (mpctx->global_sub_pos >= 0)
1413 source = sub_source(mpctx);
1415 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1416 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1417 global_sub_size,
1418 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1419 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1420 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1421 mpctx->global_sub_pos, source);
1423 mpctx->set_of_sub_pos = -1;
1424 subdata = NULL;
1426 vobsub_id = -1;
1427 dvdsub_id = -1;
1428 if (d_sub) {
1429 if (d_sub->id > -2)
1430 reset_spu = 1;
1431 d_sub->id = -2;
1433 #ifdef USE_ASS
1434 ass_track = 0;
1435 #endif
1437 if (source == SUB_SOURCE_VOBSUB) {
1438 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1439 } else if (source == SUB_SOURCE_SUBS) {
1440 mpctx->set_of_sub_pos =
1441 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1442 #ifdef USE_ASS
1443 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1444 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1445 else
1446 #endif
1448 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1449 vo_osd_changed(OSDTYPE_SUBTITLE);
1451 } else if (source == SUB_SOURCE_DEMUX) {
1452 dvdsub_id =
1453 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1454 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1455 int i = 0;
1456 // default: assume 1:1 mapping of sid and stream id
1457 d_sub->id = dvdsub_id;
1458 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1459 ds_free_packs(d_sub);
1460 for (i = 0; i < MAX_S_STREAMS; i++) {
1461 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1462 if (sh && sh->sid == dvdsub_id) {
1463 d_sub->id = i;
1464 d_sub->sh = sh;
1465 break;
1468 if (d_sub->sh && d_sub->id >= 0) {
1469 sh_sub_t *sh = d_sub->sh;
1470 if (sh->type == 'v')
1471 init_vo_spudec();
1472 #ifdef USE_ASS
1473 else if (ass_enabled)
1474 ass_track = sh->ass_track;
1475 #endif
1476 } else {
1477 d_sub->id = -2;
1478 d_sub->sh = NULL;
1482 #ifdef USE_DVDREAD
1483 if (vo_spudec
1484 && (mpctx->stream->type == STREAMTYPE_DVD
1485 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1486 && dvdsub_id < 0 && reset_spu) {
1487 dvdsub_id = -2;
1488 d_sub->id = dvdsub_id;
1490 #endif
1491 update_subtitles(mpctx->sh_video, d_sub, 1);
1493 return M_PROPERTY_OK;
1496 /// Selected sub source (RW)
1497 static int mp_property_sub_source(m_option_t * prop, int action, void *arg,
1498 MPContext * mpctx)
1500 int source;
1501 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1502 return M_PROPERTY_UNAVAILABLE;
1504 switch (action) {
1505 case M_PROPERTY_GET:
1506 if (!arg)
1507 return M_PROPERTY_ERROR;
1508 *(int *) arg = sub_source(mpctx);
1509 return M_PROPERTY_OK;
1510 case M_PROPERTY_PRINT:
1511 if (!arg)
1512 return M_PROPERTY_ERROR;
1513 *(char **) arg = malloc(64);
1514 (*(char **) arg)[63] = 0;
1515 switch (sub_source(mpctx))
1517 case SUB_SOURCE_SUBS:
1518 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1519 break;
1520 case SUB_SOURCE_VOBSUB:
1521 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1522 break;
1523 case SUB_SOURCE_DEMUX:
1524 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1525 break;
1526 default:
1527 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1529 return M_PROPERTY_OK;
1530 case M_PROPERTY_SET:
1531 if (!arg)
1532 return M_PROPERTY_ERROR;
1533 M_PROPERTY_CLAMP(prop, *(int*)arg);
1534 if (*(int *) arg < 0)
1535 mpctx->global_sub_pos = -1;
1536 else if (*(int *) arg != sub_source(mpctx)) {
1537 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1538 return M_PROPERTY_UNAVAILABLE;
1539 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1541 break;
1542 case M_PROPERTY_STEP_UP:
1543 case M_PROPERTY_STEP_DOWN: {
1544 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1545 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1546 int step = (step_all > 0) ? 1 : -1;
1547 int cur_source = sub_source(mpctx);
1548 source = cur_source;
1549 while (step_all) {
1550 source += step;
1551 if (source >= SUB_SOURCES)
1552 source = -1;
1553 else if (source < -1)
1554 source = SUB_SOURCES - 1;
1555 if (source == cur_source || source == -1 ||
1556 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1557 step_all -= step;
1559 if (source == cur_source)
1560 return M_PROPERTY_OK;
1561 if (source == -1)
1562 mpctx->global_sub_pos = -1;
1563 else
1564 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1565 break;
1567 default:
1568 return M_PROPERTY_NOT_IMPLEMENTED;
1570 --mpctx->global_sub_pos;
1571 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1574 /// Selected subtitles from specific source (RW)
1575 static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg,
1576 MPContext * mpctx)
1578 int source, is_cur_source, offset;
1579 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1580 return M_PROPERTY_UNAVAILABLE;
1582 if (!strcmp(prop->name, "sub_file"))
1583 source = SUB_SOURCE_SUBS;
1584 else if (!strcmp(prop->name, "sub_vob"))
1585 source = SUB_SOURCE_VOBSUB;
1586 else if (!strcmp(prop->name, "sub_demux"))
1587 source = SUB_SOURCE_DEMUX;
1588 else
1589 return M_PROPERTY_ERROR;
1591 offset = mpctx->global_sub_indices[source];
1592 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1593 return M_PROPERTY_UNAVAILABLE;
1595 is_cur_source = sub_source(mpctx) == source;
1596 switch (action) {
1597 case M_PROPERTY_GET:
1598 if (!arg)
1599 return M_PROPERTY_ERROR;
1600 if (is_cur_source) {
1601 *(int *) arg = mpctx->global_sub_pos - offset;
1602 if (source == SUB_SOURCE_VOBSUB)
1603 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1605 else
1606 *(int *) arg = -1;
1607 return M_PROPERTY_OK;
1608 case M_PROPERTY_PRINT:
1609 if (!arg)
1610 return M_PROPERTY_ERROR;
1611 if (is_cur_source)
1612 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1613 *(char **) arg = malloc(64);
1614 (*(char **) arg)[63] = 0;
1615 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1616 return M_PROPERTY_OK;
1617 case M_PROPERTY_SET:
1618 if (!arg)
1619 return M_PROPERTY_ERROR;
1620 if (*(int *) arg >= 0) {
1621 int index = *(int *)arg;
1622 if (source == SUB_SOURCE_VOBSUB)
1623 index = vobsub_get_index_by_id(vo_vobsub, index);
1624 mpctx->global_sub_pos = offset + index;
1625 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1626 || sub_source(mpctx) != source) {
1627 mpctx->global_sub_pos = -1;
1628 *(int *) arg = -1;
1631 else
1632 mpctx->global_sub_pos = -1;
1633 break;
1634 case M_PROPERTY_STEP_UP:
1635 case M_PROPERTY_STEP_DOWN: {
1636 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1637 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1638 int step = (step_all > 0) ? 1 : -1;
1639 int max_sub_pos_for_source = -1;
1640 if (!is_cur_source)
1641 mpctx->global_sub_pos = -1;
1642 while (step_all) {
1643 if (mpctx->global_sub_pos == -1) {
1644 if (step > 0)
1645 mpctx->global_sub_pos = offset;
1646 else if (max_sub_pos_for_source == -1) {
1647 // Find max pos for specific source
1648 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1649 while (mpctx->global_sub_pos >= 0
1650 && sub_source(mpctx) != source)
1651 --mpctx->global_sub_pos;
1653 else
1654 mpctx->global_sub_pos = max_sub_pos_for_source;
1656 else {
1657 mpctx->global_sub_pos += step;
1658 if (mpctx->global_sub_pos < offset ||
1659 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1660 sub_source(mpctx) != source)
1661 mpctx->global_sub_pos = -1;
1663 step_all -= step;
1665 break;
1667 default:
1668 return M_PROPERTY_NOT_IMPLEMENTED;
1670 --mpctx->global_sub_pos;
1671 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1674 /// Subtitle delay (RW)
1675 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1676 MPContext * mpctx)
1678 if (!mpctx->sh_video)
1679 return M_PROPERTY_UNAVAILABLE;
1680 return m_property_delay(prop, action, arg, &sub_delay);
1683 /// Alignment of text subtitles (RW)
1684 static int mp_property_sub_alignment(m_option_t * prop, int action,
1685 void *arg, MPContext * mpctx)
1687 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1689 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1690 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1691 return M_PROPERTY_UNAVAILABLE;
1693 switch (action) {
1694 case M_PROPERTY_PRINT:
1695 if (!arg)
1696 return M_PROPERTY_ERROR;
1697 M_PROPERTY_CLAMP(prop, sub_alignment);
1698 *(char **) arg = strdup(name[sub_alignment]);
1699 return M_PROPERTY_OK;
1700 case M_PROPERTY_SET:
1701 if (!arg)
1702 return M_PROPERTY_ERROR;
1703 case M_PROPERTY_STEP_UP:
1704 case M_PROPERTY_STEP_DOWN:
1705 vo_osd_changed(OSDTYPE_SUBTITLE);
1706 default:
1707 return m_property_choice(prop, action, arg, &sub_alignment);
1711 /// Subtitle visibility (RW)
1712 static int mp_property_sub_visibility(m_option_t * prop, int action,
1713 void *arg, MPContext * mpctx)
1715 if (!mpctx->sh_video)
1716 return M_PROPERTY_UNAVAILABLE;
1718 switch (action) {
1719 case M_PROPERTY_SET:
1720 if (!arg)
1721 return M_PROPERTY_ERROR;
1722 case M_PROPERTY_STEP_UP:
1723 case M_PROPERTY_STEP_DOWN:
1724 vo_osd_changed(OSDTYPE_SUBTITLE);
1725 if (vo_spudec)
1726 vo_osd_changed(OSDTYPE_SPU);
1727 default:
1728 return m_property_flag(prop, action, arg, &sub_visibility);
1732 #ifdef USE_ASS
1733 /// Use margins for libass subtitles (RW)
1734 static int mp_property_ass_use_margins(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 ass_force_reload = 1;
1747 default:
1748 return m_property_flag(prop, action, arg, &ass_use_margins);
1751 #endif
1753 /// Show only forced subtitles (RW)
1754 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1755 void *arg, MPContext * mpctx)
1757 if (!vo_spudec)
1758 return M_PROPERTY_UNAVAILABLE;
1760 switch (action) {
1761 case M_PROPERTY_SET:
1762 if (!arg)
1763 return M_PROPERTY_ERROR;
1764 case M_PROPERTY_STEP_UP:
1765 case M_PROPERTY_STEP_DOWN:
1766 m_property_flag(prop, action, arg, &forced_subs_only);
1767 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1768 return M_PROPERTY_OK;
1769 default:
1770 return m_property_flag(prop, action, arg, &forced_subs_only);
1775 #ifdef HAVE_FREETYPE
1776 /// Subtitle scale (RW)
1777 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1778 MPContext * mpctx)
1781 switch (action) {
1782 case M_PROPERTY_SET:
1783 if (!arg)
1784 return M_PROPERTY_ERROR;
1785 M_PROPERTY_CLAMP(prop, *(float *) arg);
1786 #ifdef USE_ASS
1787 if (ass_enabled) {
1788 ass_font_scale = *(float *) arg;
1789 ass_force_reload = 1;
1791 #endif
1792 text_font_scale_factor = *(float *) arg;
1793 force_load_font = 1;
1794 return M_PROPERTY_OK;
1795 case M_PROPERTY_STEP_UP:
1796 case M_PROPERTY_STEP_DOWN:
1797 #ifdef USE_ASS
1798 if (ass_enabled) {
1799 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1800 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1801 M_PROPERTY_CLAMP(prop, ass_font_scale);
1802 ass_force_reload = 1;
1804 #endif
1805 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1806 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1807 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1808 force_load_font = 1;
1809 return M_PROPERTY_OK;
1810 default:
1811 #ifdef USE_ASS
1812 if (ass_enabled)
1813 return m_property_float_ro(prop, action, arg, ass_font_scale);
1814 else
1815 #endif
1816 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1819 #endif
1821 ///@}
1823 /// \defgroup TVProperties TV properties
1824 /// \ingroup Properties
1825 ///@{
1827 #ifdef USE_TV
1829 /// TV color settings (RW)
1830 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1831 MPContext * mpctx)
1833 int r, val;
1834 tvi_handle_t *tvh = mpctx->demuxer->priv;
1835 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1836 return M_PROPERTY_UNAVAILABLE;
1838 switch (action) {
1839 case M_PROPERTY_SET:
1840 if (!arg)
1841 return M_PROPERTY_ERROR;
1842 M_PROPERTY_CLAMP(prop, *(int *) arg);
1843 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1844 case M_PROPERTY_GET:
1845 return tv_get_color_options(tvh, (int) prop->priv, arg);
1846 case M_PROPERTY_STEP_UP:
1847 case M_PROPERTY_STEP_DOWN:
1848 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1849 if (!r)
1850 return M_PROPERTY_ERROR;
1851 val += (arg ? *(int *) arg : 1) *
1852 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1853 M_PROPERTY_CLAMP(prop, val);
1854 return tv_set_color_options(tvh, (int) prop->priv, val);
1856 return M_PROPERTY_ERROR;
1858 return M_PROPERTY_NOT_IMPLEMENTED;
1861 #endif
1863 #ifdef HAVE_TV_TELETEXT
1864 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1865 MPContext * mpctx)
1867 int val,result;
1868 int base_ioctl=(int)prop->priv;
1870 for teletext's GET,SET,STEP ioctls this is not 0
1871 SET is GET+1
1872 STEP is GET+2
1874 tvi_handle_t *tvh = mpctx->demuxer->priv;
1875 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1876 return M_PROPERTY_UNAVAILABLE;
1877 if(!base_ioctl)
1878 return M_PROPERTY_ERROR;
1880 switch (action) {
1881 case M_PROPERTY_GET:
1882 if (!arg)
1883 return M_PROPERTY_ERROR;
1884 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1885 break;
1886 case M_PROPERTY_SET:
1887 if (!arg)
1888 return M_PROPERTY_ERROR;
1889 M_PROPERTY_CLAMP(prop, *(int *) arg);
1890 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1891 break;
1892 case M_PROPERTY_STEP_UP:
1893 case M_PROPERTY_STEP_DOWN:
1894 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1895 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1896 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1897 break;
1898 default:
1899 return M_PROPERTY_NOT_IMPLEMENTED;
1902 return (result==TVI_CONTROL_TRUE?M_PROPERTY_OK:M_PROPERTY_ERROR);
1905 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1906 MPContext * mpctx)
1908 tvi_handle_t *tvh = mpctx->demuxer->priv;
1909 int result;
1910 int val;
1912 //with tvh==NULL will fail too
1913 result=mp_property_teletext_common(prop,action,arg,mpctx);
1914 if(result!=M_PROPERTY_OK)
1915 return result;
1917 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1918 mp_input_set_section("teletext");
1919 else
1920 mp_input_set_section("tv");
1921 return M_PROPERTY_OK;
1924 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1925 MPContext * mpctx)
1927 tvi_handle_t *tvh = mpctx->demuxer->priv;
1928 int result;
1929 int val;
1930 switch(action){
1931 case M_PROPERTY_STEP_UP:
1932 case M_PROPERTY_STEP_DOWN:
1933 //This should be handled separately
1934 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1935 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1936 break;
1937 default:
1938 result=mp_property_teletext_common(prop,action,arg,mpctx);
1940 return result;
1944 #endif /* HAVE_TV_TELETEXT */
1946 ///@}
1948 /// All properties available in MPlayer.
1949 /** \ingroup Properties
1951 static const m_option_t mp_properties[] = {
1952 // General
1953 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1954 M_OPT_RANGE, 0, 3, NULL },
1955 { "loop", mp_property_loop, CONF_TYPE_INT,
1956 M_OPT_MIN, -1, 0, NULL },
1957 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1958 M_OPT_RANGE, 0.01, 100.0, NULL },
1959 { "filename", mp_property_filename, CONF_TYPE_STRING,
1960 0, 0, 0, NULL },
1961 { "path", mp_property_path, CONF_TYPE_STRING,
1962 0, 0, 0, NULL },
1963 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1964 0, 0, 0, NULL },
1965 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1966 M_OPT_MIN, 0, 0, NULL },
1967 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1968 M_OPT_MIN, 0, 0, NULL },
1969 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1970 M_OPT_MIN, 0, 0, NULL },
1971 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1972 M_OPT_MIN, 0, 0, NULL },
1973 { "length", mp_property_length, CONF_TYPE_TIME,
1974 M_OPT_MIN, 0, 0, NULL },
1975 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1976 M_OPT_RANGE, 0, 100, NULL },
1977 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1978 M_OPT_MIN, 0, 0, NULL },
1979 { "chapter", mp_property_chapter, CONF_TYPE_INT,
1980 M_OPT_MIN, 1, 0, NULL },
1981 { "angle", mp_property_angle, CONF_TYPE_INT,
1982 CONF_RANGE, -2, 10, NULL },
1983 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
1984 0, 0, 0, NULL },
1986 // Audio
1987 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
1988 M_OPT_RANGE, 0, 100, NULL },
1989 { "mute", mp_property_mute, CONF_TYPE_FLAG,
1990 M_OPT_RANGE, 0, 1, NULL },
1991 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
1992 M_OPT_RANGE, -100, 100, NULL },
1993 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
1994 0, 0, 0, NULL },
1995 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
1996 0, 0, 0, NULL },
1997 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
1998 0, 0, 0, NULL },
1999 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2000 0, 0, 0, NULL },
2001 { "channels", mp_property_channels, CONF_TYPE_INT,
2002 0, 0, 0, NULL },
2003 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2004 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
2005 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2006 M_OPT_RANGE, -1, 1, NULL },
2008 // Video
2009 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2010 M_OPT_RANGE, 0, 1, NULL },
2011 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2012 M_OPT_RANGE, 0, 1, NULL },
2013 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2014 M_OPT_RANGE, 0, 1, NULL },
2015 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2016 M_OPT_RANGE, 0, 1, NULL },
2017 { "border", mp_property_border, CONF_TYPE_FLAG,
2018 M_OPT_RANGE, 0, 1, NULL },
2019 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2020 M_OPT_RANGE, 0, 2, NULL },
2021 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2022 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2023 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2024 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2025 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2026 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2027 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2028 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2029 { "hue", mp_property_gamma, CONF_TYPE_INT,
2030 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2031 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2032 M_OPT_RANGE, 0, 1, NULL },
2033 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2034 M_OPT_RANGE, 0, 1, NULL },
2035 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2036 0, 0, 0, NULL },
2037 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2038 0, 0, 0, NULL },
2039 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2040 0, 0, 0, NULL },
2041 { "width", mp_property_width, CONF_TYPE_INT,
2042 0, 0, 0, NULL },
2043 { "height", mp_property_height, CONF_TYPE_INT,
2044 0, 0, 0, NULL },
2045 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2046 0, 0, 0, NULL },
2047 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2048 0, 0, 0, NULL },
2049 { "switch_video", mp_property_video, CONF_TYPE_INT,
2050 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
2051 { "switch_program", mp_property_program, CONF_TYPE_INT,
2052 CONF_RANGE, -1, 65535, NULL },
2054 // Subs
2055 { "sub", mp_property_sub, CONF_TYPE_INT,
2056 M_OPT_MIN, -1, 0, NULL },
2057 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2058 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2059 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2060 M_OPT_MIN, -1, 0, NULL },
2061 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2062 M_OPT_MIN, -1, 0, NULL },
2063 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2064 M_OPT_MIN, -1, 0, NULL },
2065 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2066 0, 0, 0, NULL },
2067 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2068 M_OPT_RANGE, 0, 100, NULL },
2069 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2070 M_OPT_RANGE, 0, 2, NULL },
2071 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2072 M_OPT_RANGE, 0, 1, NULL },
2073 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2074 M_OPT_RANGE, 0, 1, NULL },
2075 #ifdef HAVE_FREETYPE
2076 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2077 M_OPT_RANGE, 0, 100, NULL },
2078 #endif
2079 #ifdef USE_ASS
2080 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2081 M_OPT_RANGE, 0, 1, NULL },
2082 #endif
2084 #ifdef USE_TV
2085 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2086 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2087 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2088 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2089 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2090 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2091 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2092 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2093 #endif
2095 #ifdef HAVE_TV_TELETEXT
2096 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2097 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2098 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2099 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2100 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2101 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2102 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2103 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2104 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2105 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2106 #endif
2108 { NULL, NULL, NULL, 0, 0, 0, NULL }
2112 int mp_property_do(const char *name, int action, void *val, void *ctx)
2114 return m_property_do(mp_properties, name, action, val, ctx);
2117 char* mp_property_print(const char *name, void* ctx)
2119 char* ret = NULL;
2120 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2121 return NULL;
2122 return ret;
2125 char *property_expand_string(MPContext * mpctx, char *str)
2127 return m_properties_expand_string(mp_properties, str, mpctx);
2130 void property_print_help(void)
2132 m_properties_print_help_list(mp_properties);
2136 ///@}
2137 // Properties group
2141 * \defgroup Command2Property Command to property bridge
2143 * It is used to handle most commands that just set a property
2144 * and optionally display something on the OSD.
2145 * Two kinds of commands are handled: adjust or toggle.
2147 * Adjust commands take 1 or 2 parameters: <value> <abs>
2148 * If <abs> is non-zero the property is set to the given value
2149 * otherwise it is adjusted.
2151 * Toggle commands take 0 or 1 parameters. With no parameter
2152 * or a value less than the property minimum it just steps the
2153 * property to its next value. Otherwise it sets it to the given
2154 * value.
2159 /// List of the commands that can be handled by setting a property.
2160 static struct {
2161 /// property name
2162 const char *name;
2163 /// cmd id
2164 int cmd;
2165 /// set/adjust or toggle command
2166 int toggle;
2167 /// progressbar type
2168 int osd_progbar;
2169 /// osd msg id if it must be shared
2170 int osd_id;
2171 /// osd msg template
2172 const char *osd_msg;
2173 } set_prop_cmd[] = {
2174 // general
2175 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2176 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2177 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2178 // audio
2179 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2180 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2181 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2182 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2183 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2184 // video
2185 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2186 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2187 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2188 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2189 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2190 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2191 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2192 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2193 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2194 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2195 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2196 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2197 // subs
2198 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2199 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2200 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2201 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2202 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2203 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2204 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2205 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2206 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2207 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2208 #ifdef HAVE_FREETYPE
2209 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2210 #endif
2211 #ifdef USE_ASS
2212 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2213 #endif
2214 #ifdef USE_TV
2215 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2216 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2217 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2218 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2219 #endif
2220 { NULL, 0, 0, 0, -1, NULL }
2224 /// Handle commands that set a property.
2225 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
2227 int i, r;
2228 m_option_t* prop;
2229 const char *pname;
2231 // look for the command
2232 for (i = 0; set_prop_cmd[i].name; i++)
2233 if (set_prop_cmd[i].cmd == cmd->id)
2234 break;
2235 if (!(pname = set_prop_cmd[i].name))
2236 return 0;
2238 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2239 return 0;
2241 // toggle command
2242 if (set_prop_cmd[i].toggle) {
2243 // set to value
2244 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2245 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2246 else
2247 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2248 } else if (cmd->args[1].v.i) //set
2249 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2250 else // adjust
2251 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2253 if (r <= 0)
2254 return 1;
2256 if (set_prop_cmd[i].osd_progbar) {
2257 if (prop->type == CONF_TYPE_INT) {
2258 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2259 set_osd_bar(set_prop_cmd[i].osd_progbar,
2260 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2261 } else if (prop->type == CONF_TYPE_FLOAT) {
2262 float f;
2263 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2264 set_osd_bar(set_prop_cmd[i].osd_progbar,
2265 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2266 } else
2267 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2268 "Property use an unsupported type.\n");
2269 return 1;
2272 if (set_prop_cmd[i].osd_msg) {
2273 char *val = mp_property_print(pname, mpctx);
2274 if (val) {
2275 set_osd_msg(set_prop_cmd[i].osd_id >=
2276 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2277 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2278 free(val);
2281 return 1;
2285 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
2287 sh_audio_t * const sh_audio = mpctx->sh_audio;
2288 sh_video_t * const sh_video = mpctx->sh_video;
2289 int brk_cmd = 0;
2290 if (!set_property_command(mpctx, cmd))
2291 switch (cmd->id) {
2292 case MP_CMD_SEEK:{
2293 float v;
2294 int abs;
2295 if (sh_video)
2296 mpctx->osd_show_percentage = sh_video->fps;
2297 v = cmd->args[0].v.f;
2298 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2299 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2300 abs_seek_pos = SEEK_ABSOLUTE;
2301 if (sh_video)
2302 mpctx->osd_function =
2303 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2304 rel_seek_secs = v;
2305 } else if (abs) { /* Absolute seek by percentage */
2306 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2307 if (sh_video)
2308 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2309 rel_seek_secs = v / 100.0;
2310 } else {
2311 rel_seek_secs += v;
2312 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2314 brk_cmd = 1;
2316 break;
2318 case MP_CMD_SET_PROPERTY:{
2319 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2320 cmd->args[1].v.s, mpctx);
2321 if (r == M_PROPERTY_UNKNOWN)
2322 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2323 "Unknown property: '%s'\n", cmd->args[0].v.s);
2324 else if (r <= 0)
2325 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2326 "Failed to set property '%s' to '%s'.\n",
2327 cmd->args[0].v.s, cmd->args[1].v.s);
2329 break;
2331 case MP_CMD_STEP_PROPERTY:{
2332 void* arg = NULL;
2333 int r,i;
2334 double d;
2335 off_t o;
2336 if (cmd->args[1].v.f) {
2337 m_option_t* prop;
2338 if((r = mp_property_do(cmd->args[0].v.s,
2339 M_PROPERTY_GET_TYPE,
2340 &prop, mpctx)) <= 0)
2341 goto step_prop_err;
2342 if(prop->type == CONF_TYPE_INT ||
2343 prop->type == CONF_TYPE_FLAG)
2344 i = cmd->args[1].v.f, arg = &i;
2345 else if(prop->type == CONF_TYPE_FLOAT)
2346 arg = &cmd->args[1].v.f;
2347 else if(prop->type == CONF_TYPE_DOUBLE ||
2348 prop->type == CONF_TYPE_TIME)
2349 d = cmd->args[1].v.f, arg = &d;
2350 else if(prop->type == CONF_TYPE_POSITION)
2351 o = cmd->args[1].v.f, arg = &o;
2352 else
2353 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2354 "Ignoring step size stepping property '%s'.\n",
2355 cmd->args[0].v.s);
2357 r = mp_property_do(cmd->args[0].v.s,
2358 cmd->args[2].v.i < 0 ?
2359 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2360 arg, mpctx);
2361 step_prop_err:
2362 if (r == M_PROPERTY_UNKNOWN)
2363 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2364 "Unknown property: '%s'\n", cmd->args[0].v.s);
2365 else if (r <= 0)
2366 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2367 "Failed to increment property '%s' by %f.\n",
2368 cmd->args[0].v.s, cmd->args[1].v.f);
2370 break;
2372 case MP_CMD_GET_PROPERTY:{
2373 char *tmp;
2374 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2375 &tmp, mpctx) <= 0) {
2376 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2377 "Failed to get value of property '%s'.\n",
2378 cmd->args[0].v.s);
2379 break;
2381 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2382 cmd->args[0].v.s, tmp);
2383 free(tmp);
2385 break;
2387 case MP_CMD_EDL_MARK:
2388 if (edl_fd) {
2389 float v = sh_video ? sh_video->pts :
2390 playing_audio_pts(sh_audio, mpctx->d_audio,
2391 mpctx->audio_out);
2393 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2394 mpctx->begin_skip = v;
2395 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2396 } else {
2397 if (mpctx->begin_skip > v)
2398 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2399 else {
2400 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2401 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2403 mpctx->begin_skip = MP_NOPTS_VALUE;
2406 break;
2408 case MP_CMD_SWITCH_RATIO:
2409 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2410 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2411 else
2412 movie_aspect = cmd->args[0].v.f;
2413 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2414 break;
2416 case MP_CMD_SPEED_INCR:{
2417 float v = cmd->args[0].v.f;
2418 playback_speed += v;
2419 build_afilter_chain(sh_audio, &ao_data);
2420 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2421 playback_speed);
2422 } break;
2424 case MP_CMD_SPEED_MULT:{
2425 float v = cmd->args[0].v.f;
2426 playback_speed *= v;
2427 build_afilter_chain(sh_audio, &ao_data);
2428 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2429 playback_speed);
2430 } break;
2432 case MP_CMD_SPEED_SET:{
2433 float v = cmd->args[0].v.f;
2434 playback_speed = v;
2435 build_afilter_chain(sh_audio, &ao_data);
2436 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2437 playback_speed);
2438 } break;
2440 case MP_CMD_FRAME_STEP:
2441 case MP_CMD_PAUSE:
2442 cmd->pausing = 1;
2443 brk_cmd = 1;
2444 break;
2446 case MP_CMD_FILE_FILTER:
2447 file_filter = cmd->args[0].v.i;
2448 break;
2450 case MP_CMD_QUIT:
2451 exit_player_with_rc(MSGTR_Exit_quit,
2452 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2454 case MP_CMD_PLAY_TREE_STEP:{
2455 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2456 int force = cmd->args[1].v.i;
2458 #ifdef HAVE_NEW_GUI
2459 if (use_gui) {
2460 int i = 0;
2461 if (n > 0)
2462 for (i = 0; i < n; i++)
2463 mplNext();
2464 else
2465 for (i = 0; i < -1 * n; i++)
2466 mplPrev();
2467 } else
2468 #endif
2470 if (!force && mpctx->playtree_iter) {
2471 play_tree_iter_t *i =
2472 play_tree_iter_new_copy(mpctx->playtree_iter);
2473 if (play_tree_iter_step(i, n, 0) ==
2474 PLAY_TREE_ITER_ENTRY)
2475 mpctx->eof =
2476 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2477 play_tree_iter_free(i);
2478 } else
2479 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2480 if (mpctx->eof)
2481 mpctx->play_tree_step = n;
2482 brk_cmd = 1;
2485 break;
2487 case MP_CMD_PLAY_TREE_UP_STEP:{
2488 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2489 int force = cmd->args[1].v.i;
2491 if (!force && mpctx->playtree_iter) {
2492 play_tree_iter_t *i =
2493 play_tree_iter_new_copy(mpctx->playtree_iter);
2494 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2495 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2496 play_tree_iter_free(i);
2497 } else
2498 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2499 brk_cmd = 1;
2501 break;
2503 case MP_CMD_PLAY_ALT_SRC_STEP:
2504 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2505 int v = cmd->args[0].v.i;
2506 if (v > 0
2507 && mpctx->playtree_iter->file <
2508 mpctx->playtree_iter->num_files)
2509 mpctx->eof = PT_NEXT_SRC;
2510 else if (v < 0 && mpctx->playtree_iter->file > 1)
2511 mpctx->eof = PT_PREV_SRC;
2513 brk_cmd = 1;
2514 break;
2516 case MP_CMD_SUB_STEP:
2517 if (sh_video) {
2518 int movement = cmd->args[0].v.i;
2519 step_sub(subdata, sh_video->pts, movement);
2520 #ifdef USE_ASS
2521 if (ass_track)
2522 sub_delay +=
2523 ass_step_sub(ass_track,
2524 (sh_video->pts +
2525 sub_delay) * 1000 + .5, movement) / 1000.;
2526 #endif
2527 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2528 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2530 break;
2532 case MP_CMD_SUB_LOG:
2533 log_sub();
2534 break;
2536 case MP_CMD_OSD:{
2537 int v = cmd->args[0].v.i;
2538 int max = (term_osd
2539 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2540 if (osd_level > max)
2541 osd_level = max;
2542 if (v < 0)
2543 osd_level = (osd_level + 1) % (max + 1);
2544 else
2545 osd_level = v > max ? max : v;
2546 /* Show OSD state when disabled, but not when an explicit
2547 argument is given to the OSD command, i.e. in slave mode. */
2548 if (v == -1 && osd_level <= 1)
2549 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2550 MSGTR_OSDosd,
2551 osd_level ? MSGTR_OSDenabled :
2552 MSGTR_OSDdisabled);
2553 else
2554 rm_osd_msg(OSD_MSG_OSD_STATUS);
2556 break;
2558 case MP_CMD_OSD_SHOW_TEXT:
2559 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2560 (cmd->args[1].v.i <
2561 0 ? osd_duration : cmd->args[1].v.i),
2562 "%-.63s", cmd->args[0].v.s);
2563 break;
2565 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2566 char *txt = m_properties_expand_string(mp_properties,
2567 cmd->args[0].v.s,
2568 mpctx);
2569 /* if no argument supplied take default osd_duration, else <arg> ms. */
2570 if (txt) {
2571 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2572 (cmd->args[1].v.i <
2573 0 ? osd_duration : cmd->args[1].v.i),
2574 "%-.63s", txt);
2575 free(txt);
2578 break;
2580 case MP_CMD_LOADFILE:{
2581 play_tree_t *e = play_tree_new();
2582 play_tree_add_file(e, cmd->args[0].v.s);
2584 if (cmd->args[1].v.i) // append
2585 play_tree_append_entry(mpctx->playtree, e);
2586 else {
2587 // Go back to the starting point.
2588 while (play_tree_iter_up_step
2589 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2590 /* NOP */ ;
2591 play_tree_free_list(mpctx->playtree->child, 1);
2592 play_tree_set_child(mpctx->playtree, e);
2593 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2594 mpctx->eof = PT_NEXT_SRC;
2596 brk_cmd = 1;
2598 break;
2600 case MP_CMD_LOADLIST:{
2601 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2602 if (!e)
2603 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2604 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2605 else {
2606 if (cmd->args[1].v.i) // append
2607 play_tree_append_entry(mpctx->playtree, e);
2608 else {
2609 // Go back to the starting point.
2610 while (play_tree_iter_up_step
2611 (mpctx->playtree_iter, 0, 1)
2612 != PLAY_TREE_ITER_END)
2613 /* NOP */ ;
2614 play_tree_free_list(mpctx->playtree->child, 1);
2615 play_tree_set_child(mpctx->playtree, e);
2616 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2617 mpctx->eof = PT_NEXT_SRC;
2620 brk_cmd = 1;
2622 break;
2624 #ifdef USE_RADIO
2625 case MP_CMD_RADIO_STEP_CHANNEL:
2626 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2627 int v = cmd->args[0].v.i;
2628 if (v > 0)
2629 radio_step_channel(mpctx->demuxer->stream,
2630 RADIO_CHANNEL_HIGHER);
2631 else
2632 radio_step_channel(mpctx->demuxer->stream,
2633 RADIO_CHANNEL_LOWER);
2634 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2635 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2636 MSGTR_OSDChannel,
2637 radio_get_channel_name(mpctx->demuxer->stream));
2640 break;
2642 case MP_CMD_RADIO_SET_CHANNEL:
2643 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2644 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2645 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2646 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2647 MSGTR_OSDChannel,
2648 radio_get_channel_name(mpctx->demuxer->stream));
2651 break;
2653 case MP_CMD_RADIO_SET_FREQ:
2654 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2655 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2656 break;
2658 case MP_CMD_RADIO_STEP_FREQ:
2659 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2660 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2661 break;
2662 #endif
2664 #ifdef USE_TV
2665 case MP_CMD_TV_START_SCAN:
2666 if (mpctx->file_format == DEMUXER_TYPE_TV)
2667 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2668 break;
2669 case MP_CMD_TV_SET_FREQ:
2670 if (mpctx->file_format == DEMUXER_TYPE_TV)
2671 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2672 cmd->args[0].v.f * 16.0);
2673 #ifdef HAVE_PVR
2674 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2675 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2676 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2677 pvr_get_current_channelname (mpctx->stream),
2678 pvr_get_current_stationname (mpctx->stream));
2680 #endif /* HAVE_PVR */
2681 break;
2683 case MP_CMD_TV_STEP_FREQ:
2684 if (mpctx->file_format == DEMUXER_TYPE_TV)
2685 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2686 cmd->args[0].v.f * 16.0);
2687 #ifdef HAVE_PVR
2688 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2689 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2690 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2691 pvr_get_current_channelname (mpctx->stream),
2692 pvr_get_current_frequency (mpctx->stream));
2694 #endif /* HAVE_PVR */
2695 break;
2697 case MP_CMD_TV_SET_NORM:
2698 if (mpctx->file_format == DEMUXER_TYPE_TV)
2699 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2700 cmd->args[0].v.s);
2701 break;
2703 case MP_CMD_TV_STEP_CHANNEL:{
2704 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2705 int v = cmd->args[0].v.i;
2706 if (v > 0) {
2707 tv_step_channel((tvi_handle_t *) (mpctx->
2708 demuxer->priv),
2709 TV_CHANNEL_HIGHER);
2710 } else {
2711 tv_step_channel((tvi_handle_t *) (mpctx->
2712 demuxer->priv),
2713 TV_CHANNEL_LOWER);
2715 if (tv_channel_list) {
2716 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2717 MSGTR_OSDChannel, tv_channel_current->name);
2718 //vo_osd_changed(OSDTYPE_SUBTITLE);
2721 #ifdef HAVE_PVR
2722 else if (mpctx->stream &&
2723 mpctx->stream->type == STREAMTYPE_PVR) {
2724 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2725 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2726 pvr_get_current_channelname (mpctx->stream),
2727 pvr_get_current_stationname (mpctx->stream));
2729 #endif /* HAVE_PVR */
2731 #ifdef HAS_DVBIN_SUPPORT
2732 if (mpctx->stream->type == STREAMTYPE_DVB) {
2733 int dir;
2734 int v = cmd->args[0].v.i;
2736 mpctx->last_dvb_step = v;
2737 if (v > 0)
2738 dir = DVB_CHANNEL_HIGHER;
2739 else
2740 dir = DVB_CHANNEL_LOWER;
2743 if (dvb_step_channel(mpctx->stream, dir))
2744 mpctx->eof = mpctx->dvbin_reopen = 1;
2746 #endif /* HAS_DVBIN_SUPPORT */
2747 break;
2749 case MP_CMD_TV_SET_CHANNEL:
2750 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2751 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2752 cmd->args[0].v.s);
2753 if (tv_channel_list) {
2754 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2755 MSGTR_OSDChannel, tv_channel_current->name);
2756 //vo_osd_changed(OSDTYPE_SUBTITLE);
2759 #ifdef HAVE_PVR
2760 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2761 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2762 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2763 pvr_get_current_channelname (mpctx->stream),
2764 pvr_get_current_stationname (mpctx->stream));
2766 #endif /* HAVE_PVR */
2767 break;
2769 #ifdef HAS_DVBIN_SUPPORT
2770 case MP_CMD_DVB_SET_CHANNEL:
2771 if (mpctx->stream->type == STREAMTYPE_DVB) {
2772 mpctx->last_dvb_step = 1;
2774 if (dvb_set_channel
2775 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2776 mpctx->eof = mpctx->dvbin_reopen = 1;
2778 break;
2779 #endif /* HAS_DVBIN_SUPPORT */
2781 case MP_CMD_TV_LAST_CHANNEL:
2782 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2783 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2784 if (tv_channel_list) {
2785 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2786 MSGTR_OSDChannel, tv_channel_current->name);
2787 //vo_osd_changed(OSDTYPE_SUBTITLE);
2790 #ifdef HAVE_PVR
2791 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2792 pvr_set_lastchannel (mpctx->stream);
2793 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2794 pvr_get_current_channelname (mpctx->stream),
2795 pvr_get_current_stationname (mpctx->stream));
2797 #endif /* HAVE_PVR */
2798 break;
2800 case MP_CMD_TV_STEP_NORM:
2801 if (mpctx->file_format == DEMUXER_TYPE_TV)
2802 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2803 break;
2805 case MP_CMD_TV_STEP_CHANNEL_LIST:
2806 if (mpctx->file_format == DEMUXER_TYPE_TV)
2807 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2808 break;
2809 #ifdef HAVE_TV_TELETEXT
2810 case MP_CMD_TV_TELETEXT_ADD_DEC:
2812 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2813 if (mpctx->file_format == DEMUXER_TYPE_TV)
2814 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2815 break;
2817 case MP_CMD_TV_TELETEXT_GO_LINK:
2819 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2820 if (mpctx->file_format == DEMUXER_TYPE_TV)
2821 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2822 break;
2824 #endif /* HAVE_TV_TELETEXT */
2825 #endif /* USE_TV */
2827 case MP_CMD_SUB_LOAD:
2828 if (sh_video) {
2829 int n = mpctx->set_of_sub_size;
2830 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2831 if (n != mpctx->set_of_sub_size) {
2832 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2833 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2834 mpctx->global_sub_size;
2835 ++mpctx->global_sub_size;
2838 break;
2840 case MP_CMD_SUB_REMOVE:
2841 if (sh_video) {
2842 int v = cmd->args[0].v.i;
2843 sub_data *subd;
2844 if (v < 0) {
2845 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2846 subd = mpctx->set_of_subtitles[v];
2847 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2848 MSGTR_RemovedSubtitleFile, v + 1,
2849 filename_recode(subd->filename));
2850 sub_free(subd);
2851 mpctx->set_of_subtitles[v] = NULL;
2853 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2854 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2855 mpctx->set_of_sub_size = 0;
2856 if (mpctx->set_of_sub_pos >= 0) {
2857 mpctx->global_sub_pos = -2;
2858 subdata = NULL;
2859 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2861 } else if (v < mpctx->set_of_sub_size) {
2862 subd = mpctx->set_of_subtitles[v];
2863 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2864 MSGTR_RemovedSubtitleFile, v + 1,
2865 filename_recode(subd->filename));
2866 sub_free(subd);
2867 if (mpctx->set_of_sub_pos == v) {
2868 mpctx->global_sub_pos = -2;
2869 subdata = NULL;
2870 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2871 } else if (mpctx->set_of_sub_pos > v) {
2872 --mpctx->set_of_sub_pos;
2873 --mpctx->global_sub_pos;
2875 while (++v < mpctx->set_of_sub_size)
2876 mpctx->set_of_subtitles[v - 1] =
2877 mpctx->set_of_subtitles[v];
2878 --mpctx->set_of_sub_size;
2879 --mpctx->global_sub_size;
2880 if (mpctx->set_of_sub_size <= 0)
2881 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2882 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2885 break;
2887 case MP_CMD_GET_SUB_VISIBILITY:
2888 if (sh_video) {
2889 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2890 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2892 break;
2894 case MP_CMD_SCREENSHOT:
2895 if (vo_config_count) {
2896 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2897 if (CONTROL_OK !=
2898 ((vf_instance_t *) sh_video->vfilter)->
2899 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2900 &cmd->args[0].v.i))
2901 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2903 break;
2905 case MP_CMD_VF_CHANGE_RECTANGLE:
2906 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2907 break;
2909 case MP_CMD_GET_TIME_LENGTH:{
2910 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2911 demuxer_get_time_length(mpctx->demuxer));
2913 break;
2915 case MP_CMD_GET_FILENAME:{
2916 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2917 get_metadata(META_NAME));
2919 break;
2921 case MP_CMD_GET_VIDEO_CODEC:{
2922 char *inf = get_metadata(META_VIDEO_CODEC);
2923 if (!inf)
2924 inf = strdup("");
2925 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2926 free(inf);
2928 break;
2930 case MP_CMD_GET_VIDEO_BITRATE:{
2931 char *inf = get_metadata(META_VIDEO_BITRATE);
2932 if (!inf)
2933 inf = strdup("");
2934 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2935 free(inf);
2937 break;
2939 case MP_CMD_GET_VIDEO_RESOLUTION:{
2940 char *inf = get_metadata(META_VIDEO_RESOLUTION);
2941 if (!inf)
2942 inf = strdup("");
2943 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2944 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
2945 free(inf);
2947 break;
2949 case MP_CMD_GET_AUDIO_CODEC:{
2950 char *inf = get_metadata(META_AUDIO_CODEC);
2951 if (!inf)
2952 inf = strdup("");
2953 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
2954 free(inf);
2956 break;
2958 case MP_CMD_GET_AUDIO_BITRATE:{
2959 char *inf = get_metadata(META_AUDIO_BITRATE);
2960 if (!inf)
2961 inf = strdup("");
2962 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
2963 free(inf);
2965 break;
2967 case MP_CMD_GET_AUDIO_SAMPLES:{
2968 char *inf = get_metadata(META_AUDIO_SAMPLES);
2969 if (!inf)
2970 inf = strdup("");
2971 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
2972 free(inf);
2974 break;
2976 case MP_CMD_GET_META_TITLE:{
2977 char *inf = get_metadata(META_INFO_TITLE);
2978 if (!inf)
2979 inf = strdup("");
2980 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
2981 free(inf);
2983 break;
2985 case MP_CMD_GET_META_ARTIST:{
2986 char *inf = get_metadata(META_INFO_ARTIST);
2987 if (!inf)
2988 inf = strdup("");
2989 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
2990 free(inf);
2992 break;
2994 case MP_CMD_GET_META_ALBUM:{
2995 char *inf = get_metadata(META_INFO_ALBUM);
2996 if (!inf)
2997 inf = strdup("");
2998 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
2999 free(inf);
3001 break;
3003 case MP_CMD_GET_META_YEAR:{
3004 char *inf = get_metadata(META_INFO_YEAR);
3005 if (!inf)
3006 inf = strdup("");
3007 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3008 free(inf);
3010 break;
3012 case MP_CMD_GET_META_COMMENT:{
3013 char *inf = get_metadata(META_INFO_COMMENT);
3014 if (!inf)
3015 inf = strdup("");
3016 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3017 free(inf);
3019 break;
3021 case MP_CMD_GET_META_TRACK:{
3022 char *inf = get_metadata(META_INFO_TRACK);
3023 if (!inf)
3024 inf = strdup("");
3025 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3026 free(inf);
3028 break;
3030 case MP_CMD_GET_META_GENRE:{
3031 char *inf = get_metadata(META_INFO_GENRE);
3032 if (!inf)
3033 inf = strdup("");
3034 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3035 free(inf);
3037 break;
3039 case MP_CMD_GET_VO_FULLSCREEN:
3040 if (mpctx->video_out && vo_config_count)
3041 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3042 break;
3044 case MP_CMD_GET_PERCENT_POS:
3045 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3046 demuxer_get_percent_pos(mpctx->demuxer));
3047 break;
3049 case MP_CMD_GET_TIME_POS:{
3050 float pos = 0;
3051 if (sh_video)
3052 pos = sh_video->pts;
3053 else if (sh_audio && mpctx->audio_out)
3054 pos =
3055 playing_audio_pts(sh_audio, mpctx->d_audio,
3056 mpctx->audio_out);
3057 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3059 break;
3061 case MP_CMD_RUN:
3062 #ifndef __MINGW32__
3063 if (!fork()) {
3064 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3065 exit(0);
3067 #endif
3068 break;
3070 case MP_CMD_KEYDOWN_EVENTS:
3071 mplayer_put_key(cmd->args[0].v.i);
3072 break;
3074 case MP_CMD_SET_MOUSE_POS:{
3075 int pointer_x, pointer_y;
3076 double dx, dy;
3077 pointer_x = cmd->args[0].v.i;
3078 pointer_y = cmd->args[1].v.i;
3079 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
3080 #ifdef USE_DVDNAV
3081 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3082 && dx > 0.0 && dy > 0.0) {
3083 int button = -1;
3084 pointer_x = (int) (dx * (double) sh_video->disp_w);
3085 pointer_y = (int) (dy * (double) sh_video->disp_h);
3086 mp_dvdnav_update_mouse_pos(mpctx->stream,
3087 pointer_x, pointer_y, &button);
3088 if (osd_level > 1 && button > 0)
3089 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3090 "Selected button number %d", button);
3092 #endif
3093 #ifdef HAVE_MENU
3094 if (use_menu && dx >= 0.0 && dy >= 0.0)
3095 menu_update_mouse_pos(dx, dy);
3096 #endif
3098 break;
3100 #ifdef USE_DVDNAV
3101 case MP_CMD_DVDNAV:{
3102 int button = -1;
3103 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3104 break;
3106 mp_dvdnav_handle_input(mpctx->stream,cmd->args[0].v.i,&button);
3107 if (osd_level > 1 && button > 0)
3108 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3109 "Selected button number %d", button);
3111 break;
3113 case MP_CMD_SWITCH_TITLE:
3114 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3115 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3116 break;
3118 #endif
3120 default:
3121 #ifdef HAVE_NEW_GUI
3122 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3123 guiGetEvent(guiIEvent, (char *) cmd->id);
3124 else
3125 #endif
3126 mp_msg(MSGT_CPLAYER, MSGL_V,
3127 "Received unknown cmd %s\n", cmd->name);
3130 switch (cmd->pausing) {
3131 case 1: // "pausing"
3132 mpctx->osd_function = OSD_PAUSE;
3133 break;
3134 case 3: // "pausing_toggle"
3135 mpctx->was_paused = !mpctx->was_paused;
3136 if (mpctx->was_paused)
3137 mpctx->osd_function = OSD_PAUSE;
3138 else if (mpctx->osd_function == OSD_PAUSE)
3139 mpctx->osd_function = OSD_PLAY;
3140 break;
3141 case 2: // "pausing_keep"
3142 if (mpctx->was_paused)
3143 mpctx->osd_function = OSD_PAUSE;
3145 return brk_cmd;