remove useless casts
[mplayer/glamo.git] / command.c
blob57e2f7a22a7bf9fb7a80e7db80a0e893e5a5dcee
1 #include <stdlib.h>
2 #include <inttypes.h>
3 #include <unistd.h>
4 #include <string.h>
6 #include "config.h"
7 #include "input/input.h"
8 #include "stream/stream.h"
9 #include "libmpdemux/demuxer.h"
10 #include "libmpdemux/stheader.h"
11 #include "codec-cfg.h"
12 #include "mplayer.h"
13 #include "libvo/sub.h"
14 #include "m_option.h"
15 #include "m_property.h"
16 #include "help_mp.h"
17 #include "metadata.h"
18 #include "libmpcodecs/mp_image.h"
19 #include "libmpcodecs/vf.h"
20 #include "libmpcodecs/vd.h"
21 #include "libvo/video_out.h"
22 #include "libvo/font_load.h"
23 #include "playtree.h"
24 #include "libao2/audio_out.h"
25 #include "mpcommon.h"
26 #include "mixer.h"
27 #include "libmpdemux/matroska.h"
28 #include "libmpcodecs/dec_video.h"
29 #include "vobsub.h"
30 #include "spudec.h"
31 #include "get_path.h"
32 #ifdef USE_TV
33 #include "stream/tv.h"
34 #endif
35 #ifdef USE_RADIO
36 #include "stream/stream_radio.h"
37 #endif
38 #ifdef HAVE_PVR
39 #include "stream/pvr.h"
40 #endif
41 #ifdef HAS_DVBIN_SUPPORT
42 #include "stream/dvbin.h"
43 #endif
44 #ifdef USE_DVDREAD
45 #include "stream/stream_dvd.h"
46 #endif
47 #ifdef USE_DVDNAV
48 #include "stream/stream_dvdnav.h"
49 #endif
50 #ifdef USE_ASS
51 #include "libass/ass.h"
52 #include "libass/ass_mp.h"
53 #endif
54 #ifdef HAVE_MENU
55 #include "m_struct.h"
56 #include "libmenu/menu.h"
57 #endif
58 #ifdef HAVE_NEW_GUI
59 #include "gui/interface.h"
60 #endif
62 #include "mp_core.h"
63 #include "mp_fifo.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 = 3;
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 = 1;
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 = 1;
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 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA)
814 demux_mkv_get_audio_lang(mpctx->demuxer, audio_id, lang, 9);
815 #ifdef USE_DVDREAD
816 else if (mpctx->stream->type == STREAMTYPE_DVD) {
817 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
818 if (code) {
819 lang[0] = code >> 8;
820 lang[1] = code;
821 lang[2] = 0;
824 #endif
826 #ifdef USE_DVDNAV
827 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
828 dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
829 #endif
830 *(char **) arg = malloc(64);
831 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
833 return M_PROPERTY_OK;
835 case M_PROPERTY_STEP_UP:
836 case M_PROPERTY_SET:
837 if (action == M_PROPERTY_SET && arg)
838 tmp = *((int *) arg);
839 else
840 tmp = -1;
841 current_id = mpctx->demuxer->audio->id;
842 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
843 if (audio_id == -2
844 || (audio_id > -1
845 && mpctx->demuxer->audio->id != current_id && current_id != -2))
846 uninit_player(INITED_AO | INITED_ACODEC);
847 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
848 sh_audio_t *sh2;
849 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
850 if (sh2) {
851 sh2->ds = mpctx->demuxer->audio;
852 mpctx->sh_audio = sh2;
853 reinit_audio_chain();
856 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
857 return M_PROPERTY_OK;
858 default:
859 return M_PROPERTY_NOT_IMPLEMENTED;
864 /// Selected video id (RW)
865 static int mp_property_video(m_option_t * prop, int action, void *arg,
866 MPContext * mpctx)
868 int current_id = -1, tmp;
870 switch (action) {
871 case M_PROPERTY_GET:
872 if (!mpctx->sh_video)
873 return M_PROPERTY_UNAVAILABLE;
874 if (!arg)
875 return M_PROPERTY_ERROR;
876 *(int *) arg = video_id;
877 return M_PROPERTY_OK;
878 case M_PROPERTY_PRINT:
879 if (!mpctx->sh_video)
880 return M_PROPERTY_UNAVAILABLE;
881 if (!arg)
882 return M_PROPERTY_ERROR;
884 if (video_id < 0)
885 *(char **) arg = strdup(MSGTR_Disabled);
886 else {
887 char lang[40] = MSGTR_Unknown;
888 *(char **) arg = malloc(64);
889 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
891 return M_PROPERTY_OK;
893 case M_PROPERTY_STEP_UP:
894 case M_PROPERTY_SET:
895 current_id = mpctx->demuxer->video->id;
896 if (action == M_PROPERTY_SET && arg)
897 tmp = *((int *) arg);
898 else
899 tmp = -1;
900 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
901 if (video_id == -2
902 || (video_id > -1 && mpctx->demuxer->video->id != current_id
903 && current_id != -2))
904 uninit_player(INITED_VCODEC |
905 (fixed_vo && video_id != -2 ? 0 : INITED_VO));
906 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
907 sh_video_t *sh2;
908 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
909 if (sh2) {
910 sh2->ds = mpctx->demuxer->video;
911 mpctx->sh_video = sh2;
912 reinit_video_chain();
915 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
916 return M_PROPERTY_OK;
918 default:
919 return M_PROPERTY_NOT_IMPLEMENTED;
923 static int mp_property_program(m_option_t * prop, int action, void *arg,
924 MPContext * mpctx)
926 demux_program_t prog;
928 switch (action) {
929 case M_PROPERTY_STEP_UP:
930 case M_PROPERTY_SET:
931 if (action == M_PROPERTY_SET && arg)
932 prog.progid = *((int *) arg);
933 else
934 prog.progid = -1;
935 if (demux_control
936 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
937 &prog) == DEMUXER_CTRL_NOTIMPL)
938 return M_PROPERTY_ERROR;
940 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
941 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
942 return M_PROPERTY_OK;
944 default:
945 return M_PROPERTY_NOT_IMPLEMENTED;
949 ///@}
951 /// \defgroup VideoProperties Video properties
952 /// \ingroup Properties
953 ///@{
955 /// Fullscreen state (RW)
956 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
957 MPContext * mpctx)
960 if (!mpctx->video_out)
961 return M_PROPERTY_UNAVAILABLE;
963 switch (action) {
964 case M_PROPERTY_SET:
965 if (!arg)
966 return M_PROPERTY_ERROR;
967 M_PROPERTY_CLAMP(prop, *(int *) arg);
968 if (vo_fs == !!*(int *) arg)
969 return M_PROPERTY_OK;
970 case M_PROPERTY_STEP_UP:
971 case M_PROPERTY_STEP_DOWN:
972 #ifdef HAVE_NEW_GUI
973 if (use_gui)
974 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
975 else
976 #endif
977 if (vo_config_count)
978 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
979 return M_PROPERTY_OK;
980 default:
981 return m_property_flag(prop, action, arg, &vo_fs);
985 static int mp_property_deinterlace(m_option_t * prop, int action,
986 void *arg, MPContext * mpctx)
988 int deinterlace;
989 vf_instance_t *vf;
990 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
991 return M_PROPERTY_UNAVAILABLE;
992 vf = mpctx->sh_video->vfilter;
993 switch (action) {
994 case M_PROPERTY_GET:
995 if (!arg)
996 return M_PROPERTY_ERROR;
997 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
998 return M_PROPERTY_OK;
999 case M_PROPERTY_SET:
1000 if (!arg)
1001 return M_PROPERTY_ERROR;
1002 M_PROPERTY_CLAMP(prop, *(int *) arg);
1003 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1004 return M_PROPERTY_OK;
1005 case M_PROPERTY_STEP_UP:
1006 case M_PROPERTY_STEP_DOWN:
1007 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1008 deinterlace = !deinterlace;
1009 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1010 return M_PROPERTY_OK;
1012 return M_PROPERTY_NOT_IMPLEMENTED;
1015 /// Panscan (RW)
1016 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
1017 MPContext * mpctx)
1020 if (!mpctx->video_out
1021 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1022 return M_PROPERTY_UNAVAILABLE;
1024 switch (action) {
1025 case M_PROPERTY_SET:
1026 if (!arg)
1027 return M_PROPERTY_ERROR;
1028 M_PROPERTY_CLAMP(prop, *(float *) arg);
1029 vo_panscan = *(float *) arg;
1030 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1031 return M_PROPERTY_OK;
1032 case M_PROPERTY_STEP_UP:
1033 case M_PROPERTY_STEP_DOWN:
1034 vo_panscan += (arg ? *(float *) arg : 0.1) *
1035 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1036 if (vo_panscan > 1)
1037 vo_panscan = 1;
1038 else if (vo_panscan < 0)
1039 vo_panscan = 0;
1040 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1041 return M_PROPERTY_OK;
1042 default:
1043 return m_property_float_range(prop, action, arg, &vo_panscan);
1047 /// Helper to set vo flags.
1048 /** \ingroup PropertyImplHelper
1050 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
1051 int vo_ctrl, int *vo_var, MPContext * mpctx)
1054 if (!mpctx->video_out)
1055 return M_PROPERTY_UNAVAILABLE;
1057 switch (action) {
1058 case M_PROPERTY_SET:
1059 if (!arg)
1060 return M_PROPERTY_ERROR;
1061 M_PROPERTY_CLAMP(prop, *(int *) arg);
1062 if (*vo_var == !!*(int *) arg)
1063 return M_PROPERTY_OK;
1064 case M_PROPERTY_STEP_UP:
1065 case M_PROPERTY_STEP_DOWN:
1066 if (vo_config_count)
1067 mpctx->video_out->control(vo_ctrl, 0);
1068 return M_PROPERTY_OK;
1069 default:
1070 return m_property_flag(prop, action, arg, vo_var);
1074 /// Window always on top (RW)
1075 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
1076 MPContext * mpctx)
1078 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
1079 mpctx);
1082 /// Display in the root window (RW)
1083 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
1084 MPContext * mpctx)
1086 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1087 &vo_rootwin, mpctx);
1090 /// Show window borders (RW)
1091 static int mp_property_border(m_option_t * prop, int action, void *arg,
1092 MPContext * mpctx)
1094 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1095 &vo_border, mpctx);
1098 /// Framedropping state (RW)
1099 static int mp_property_framedropping(m_option_t * prop, int action,
1100 void *arg, MPContext * mpctx)
1103 if (!mpctx->sh_video)
1104 return M_PROPERTY_UNAVAILABLE;
1106 switch (action) {
1107 case M_PROPERTY_PRINT:
1108 if (!arg)
1109 return M_PROPERTY_ERROR;
1110 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1111 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1112 MSGTR_Disabled));
1113 return M_PROPERTY_OK;
1114 default:
1115 return m_property_choice(prop, action, arg, &frame_dropping);
1119 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1120 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
1121 MPContext * mpctx)
1123 int *gamma = prop->priv, r, val;
1125 if (!mpctx->sh_video)
1126 return M_PROPERTY_UNAVAILABLE;
1128 if (gamma[0] == 1000) {
1129 gamma[0] = 0;
1130 get_video_colors(mpctx->sh_video, prop->name, gamma);
1133 switch (action) {
1134 case M_PROPERTY_SET:
1135 if (!arg)
1136 return M_PROPERTY_ERROR;
1137 M_PROPERTY_CLAMP(prop, *(int *) arg);
1138 *gamma = *(int *) arg;
1139 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1140 if (r <= 0)
1141 break;
1142 return r;
1143 case M_PROPERTY_GET:
1144 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1145 if (!arg)
1146 return M_PROPERTY_ERROR;
1147 *(int *)arg = val;
1148 return M_PROPERTY_OK;
1150 break;
1151 case M_PROPERTY_STEP_UP:
1152 case M_PROPERTY_STEP_DOWN:
1153 *gamma += (arg ? *(int *) arg : 1) *
1154 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1155 M_PROPERTY_CLAMP(prop, *gamma);
1156 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1157 if (r <= 0)
1158 break;
1159 return r;
1160 default:
1161 return M_PROPERTY_NOT_IMPLEMENTED;
1164 #ifdef USE_TV
1165 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1166 int l = strlen(prop->name);
1167 char tv_prop[3 + l + 1];
1168 sprintf(tv_prop, "tv_%s", prop->name);
1169 return mp_property_do(tv_prop, action, arg, mpctx);
1171 #endif
1173 return M_PROPERTY_UNAVAILABLE;
1176 /// VSync (RW)
1177 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1178 MPContext * mpctx)
1180 return m_property_flag(prop, action, arg, &vo_vsync);
1183 /// Video codec tag (RO)
1184 static int mp_property_video_format(m_option_t * prop, int action,
1185 void *arg, MPContext * mpctx)
1187 char* meta;
1188 if (!mpctx->sh_video)
1189 return M_PROPERTY_UNAVAILABLE;
1190 switch(action) {
1191 case M_PROPERTY_PRINT:
1192 if (!arg)
1193 return M_PROPERTY_ERROR;
1194 switch(mpctx->sh_video->format) {
1195 case 0x10000001:
1196 meta = strdup ("mpeg1"); break;
1197 case 0x10000002:
1198 meta = strdup ("mpeg2"); break;
1199 case 0x10000004:
1200 meta = strdup ("mpeg4"); break;
1201 case 0x10000005:
1202 meta = strdup ("h264"); break;
1203 default:
1204 if(mpctx->sh_video->format >= 0x20202020) {
1205 meta = malloc(5);
1206 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1207 } else {
1208 meta = malloc(20);
1209 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1212 *(char**)arg = meta;
1213 return M_PROPERTY_OK;
1215 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1218 /// Video codec name (RO)
1219 static int mp_property_video_codec(m_option_t * prop, int action,
1220 void *arg, MPContext * mpctx)
1222 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1223 return M_PROPERTY_UNAVAILABLE;
1224 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1228 /// Video bitrate (RO)
1229 static int mp_property_video_bitrate(m_option_t * prop, int action,
1230 void *arg, MPContext * mpctx)
1232 if (!mpctx->sh_video)
1233 return M_PROPERTY_UNAVAILABLE;
1234 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1237 /// Video display width (RO)
1238 static int mp_property_width(m_option_t * prop, int action, void *arg,
1239 MPContext * mpctx)
1241 if (!mpctx->sh_video)
1242 return M_PROPERTY_UNAVAILABLE;
1243 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1246 /// Video display height (RO)
1247 static int mp_property_height(m_option_t * prop, int action, void *arg,
1248 MPContext * mpctx)
1250 if (!mpctx->sh_video)
1251 return M_PROPERTY_UNAVAILABLE;
1252 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1255 /// Video fps (RO)
1256 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1257 MPContext * mpctx)
1259 if (!mpctx->sh_video)
1260 return M_PROPERTY_UNAVAILABLE;
1261 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1264 /// Video aspect (RO)
1265 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1266 MPContext * mpctx)
1268 if (!mpctx->sh_video)
1269 return M_PROPERTY_UNAVAILABLE;
1270 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1273 ///@}
1275 /// \defgroup SubProprties Subtitles properties
1276 /// \ingroup Properties
1277 ///@{
1279 /// Text subtitle position (RW)
1280 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1281 MPContext * mpctx)
1283 if (!mpctx->sh_video)
1284 return M_PROPERTY_UNAVAILABLE;
1286 switch (action) {
1287 case M_PROPERTY_SET:
1288 if (!arg)
1289 return M_PROPERTY_ERROR;
1290 case M_PROPERTY_STEP_UP:
1291 case M_PROPERTY_STEP_DOWN:
1292 vo_osd_changed(OSDTYPE_SUBTITLE);
1293 default:
1294 return m_property_int_range(prop, action, arg, &sub_pos);
1298 char *demux_lavf_sub_lang(demuxer_t *demuxer, int track_num);
1300 /// Selected subtitles (RW)
1301 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1302 MPContext * mpctx)
1304 demux_stream_t *const d_sub = mpctx->d_sub;
1305 const int global_sub_size = mpctx->global_sub_size;
1306 int source = -1, reset_spu = 0;
1307 char *sub_name;
1309 if (global_sub_size <= 0)
1310 return M_PROPERTY_UNAVAILABLE;
1312 switch (action) {
1313 case M_PROPERTY_GET:
1314 if (!arg)
1315 return M_PROPERTY_ERROR;
1316 *(int *) arg = mpctx->global_sub_pos;
1317 return M_PROPERTY_OK;
1318 case M_PROPERTY_PRINT:
1319 if (!arg)
1320 return M_PROPERTY_ERROR;
1321 *(char **) arg = malloc(64);
1322 (*(char **) arg)[63] = 0;
1323 sub_name = 0;
1324 if (subdata)
1325 sub_name = subdata->filename;
1326 #ifdef USE_ASS
1327 if (ass_track && ass_track->name)
1328 sub_name = ass_track->name;
1329 #endif
1330 if (sub_name) {
1331 char *tmp, *tmp2;
1332 tmp = sub_name;
1333 if ((tmp2 = strrchr(tmp, '/')))
1334 tmp = tmp2 + 1;
1336 snprintf(*(char **) arg, 63, "(%d) %s%s",
1337 mpctx->set_of_sub_pos + 1,
1338 strlen(tmp) < 20 ? "" : "...",
1339 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1340 return M_PROPERTY_OK;
1342 #ifdef USE_DVDNAV
1343 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1344 if (vo_spudec && dvdsub_id >= 0) {
1345 unsigned char lang[3];
1346 if (dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1347 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1348 return M_PROPERTY_OK;
1352 #endif
1354 #ifdef USE_LIBAVFORMAT
1355 if (mpctx->demuxer->type == DEMUXER_TYPE_LAVF && dvdsub_id >= 0) {
1356 char *lang = demux_lavf_sub_lang(mpctx->demuxer, dvdsub_id);
1357 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1358 return M_PROPERTY_OK;
1360 #endif
1361 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
1362 char lang[40] = MSGTR_Unknown;
1363 demux_mkv_get_sub_lang(mpctx->demuxer, dvdsub_id, lang, 9);
1364 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1365 return M_PROPERTY_OK;
1367 #ifdef HAVE_OGGVORBIS
1368 if (mpctx->demuxer->type == DEMUXER_TYPE_OGG && d_sub && dvdsub_id >= 0) {
1369 const char *lang = demux_ogg_sub_lang(mpctx->demuxer, dvdsub_id);
1370 if (!lang)
1371 lang = MSGTR_Unknown;
1372 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1373 return M_PROPERTY_OK;
1375 #endif
1376 if (vo_vobsub && vobsub_id >= 0) {
1377 const char *language = MSGTR_Unknown;
1378 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1379 snprintf(*(char **) arg, 63, "(%d) %s",
1380 vobsub_id, language ? language : MSGTR_Unknown);
1381 return M_PROPERTY_OK;
1383 #ifdef USE_DVDREAD
1384 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1385 && dvdsub_id >= 0) {
1386 char lang[3];
1387 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1388 lang[0] = code >> 8;
1389 lang[1] = code;
1390 lang[2] = 0;
1391 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1392 return M_PROPERTY_OK;
1394 #endif
1395 if (dvdsub_id >= 0) {
1396 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1397 return M_PROPERTY_OK;
1399 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1400 return M_PROPERTY_OK;
1402 case M_PROPERTY_SET:
1403 if (!arg)
1404 return M_PROPERTY_ERROR;
1405 if (*(int *) arg < -1)
1406 *(int *) arg = -1;
1407 else if (*(int *) arg >= global_sub_size)
1408 *(int *) arg = global_sub_size - 1;
1409 mpctx->global_sub_pos = *(int *) arg;
1410 break;
1411 case M_PROPERTY_STEP_UP:
1412 mpctx->global_sub_pos += 2;
1413 mpctx->global_sub_pos =
1414 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1415 break;
1416 case M_PROPERTY_STEP_DOWN:
1417 mpctx->global_sub_pos += global_sub_size + 1;
1418 mpctx->global_sub_pos =
1419 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1420 break;
1421 default:
1422 return M_PROPERTY_NOT_IMPLEMENTED;
1425 if (mpctx->global_sub_pos >= 0)
1426 source = sub_source(mpctx);
1428 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1429 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1430 global_sub_size,
1431 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1432 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1433 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1434 mpctx->global_sub_pos, source);
1436 mpctx->set_of_sub_pos = -1;
1437 subdata = NULL;
1439 vobsub_id = -1;
1440 dvdsub_id = -1;
1441 if (d_sub) {
1442 if (d_sub->id > -2)
1443 reset_spu = 1;
1444 d_sub->id = -2;
1446 #ifdef USE_ASS
1447 ass_track = 0;
1448 #endif
1450 if (source == SUB_SOURCE_VOBSUB) {
1451 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1452 } else if (source == SUB_SOURCE_SUBS) {
1453 mpctx->set_of_sub_pos =
1454 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1455 #ifdef USE_ASS
1456 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1457 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1458 else
1459 #endif
1461 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1462 vo_osd_changed(OSDTYPE_SUBTITLE);
1464 } else if (source == SUB_SOURCE_DEMUX) {
1465 dvdsub_id =
1466 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1467 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1468 int i = 0;
1469 // default: assume 1:1 mapping of sid and stream id
1470 d_sub->id = dvdsub_id;
1471 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1472 ds_free_packs(d_sub);
1473 for (i = 0; i < MAX_S_STREAMS; i++) {
1474 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1475 if (sh && sh->sid == dvdsub_id) {
1476 d_sub->id = i;
1477 d_sub->sh = sh;
1478 break;
1481 if (d_sub->sh && d_sub->id >= 0) {
1482 sh_sub_t *sh = d_sub->sh;
1483 if (sh->type == 'v')
1484 init_vo_spudec();
1485 #ifdef USE_ASS
1486 else if (ass_enabled && (sh->type == 'a' || sh->type == 't'))
1487 ass_track = sh->ass_track;
1488 #endif
1489 } else {
1490 d_sub->id = -2;
1491 d_sub->sh = NULL;
1495 #ifdef USE_DVDREAD
1496 if (vo_spudec
1497 && (mpctx->stream->type == STREAMTYPE_DVD
1498 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1499 && dvdsub_id < 0 && reset_spu) {
1500 dvdsub_id = -2;
1501 d_sub->id = dvdsub_id;
1503 #endif
1504 update_subtitles(mpctx->sh_video, d_sub, 1);
1506 return M_PROPERTY_OK;
1509 /// Selected sub source (RW)
1510 static int mp_property_sub_source(m_option_t * prop, int action, void *arg,
1511 MPContext * mpctx)
1513 int source;
1514 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1515 return M_PROPERTY_UNAVAILABLE;
1517 switch (action) {
1518 case M_PROPERTY_GET:
1519 if (!arg)
1520 return M_PROPERTY_ERROR;
1521 *(int *) arg = sub_source(mpctx);
1522 return M_PROPERTY_OK;
1523 case M_PROPERTY_PRINT:
1524 if (!arg)
1525 return M_PROPERTY_ERROR;
1526 *(char **) arg = malloc(64);
1527 (*(char **) arg)[63] = 0;
1528 switch (sub_source(mpctx))
1530 case SUB_SOURCE_SUBS:
1531 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1532 break;
1533 case SUB_SOURCE_VOBSUB:
1534 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1535 break;
1536 case SUB_SOURCE_DEMUX:
1537 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1538 break;
1539 default:
1540 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1542 return M_PROPERTY_OK;
1543 case M_PROPERTY_SET:
1544 if (!arg)
1545 return M_PROPERTY_ERROR;
1546 M_PROPERTY_CLAMP(prop, *(int*)arg);
1547 if (*(int *) arg < 0)
1548 mpctx->global_sub_pos = -1;
1549 else if (*(int *) arg != sub_source(mpctx)) {
1550 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1551 return M_PROPERTY_UNAVAILABLE;
1552 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1554 break;
1555 case M_PROPERTY_STEP_UP:
1556 case M_PROPERTY_STEP_DOWN: {
1557 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1558 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1559 int step = (step_all > 0) ? 1 : -1;
1560 int cur_source = sub_source(mpctx);
1561 source = cur_source;
1562 while (step_all) {
1563 source += step;
1564 if (source >= SUB_SOURCES)
1565 source = -1;
1566 else if (source < -1)
1567 source = SUB_SOURCES - 1;
1568 if (source == cur_source || source == -1 ||
1569 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1570 step_all -= step;
1572 if (source == cur_source)
1573 return M_PROPERTY_OK;
1574 if (source == -1)
1575 mpctx->global_sub_pos = -1;
1576 else
1577 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1578 break;
1580 default:
1581 return M_PROPERTY_NOT_IMPLEMENTED;
1583 --mpctx->global_sub_pos;
1584 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1587 /// Selected subtitles from specific source (RW)
1588 static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg,
1589 MPContext * mpctx)
1591 int source, is_cur_source, offset;
1592 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1593 return M_PROPERTY_UNAVAILABLE;
1595 if (!strcmp(prop->name, "sub_file"))
1596 source = SUB_SOURCE_SUBS;
1597 else if (!strcmp(prop->name, "sub_vob"))
1598 source = SUB_SOURCE_VOBSUB;
1599 else if (!strcmp(prop->name, "sub_demux"))
1600 source = SUB_SOURCE_DEMUX;
1601 else
1602 return M_PROPERTY_ERROR;
1604 offset = mpctx->global_sub_indices[source];
1605 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1606 return M_PROPERTY_UNAVAILABLE;
1608 is_cur_source = sub_source(mpctx) == source;
1609 switch (action) {
1610 case M_PROPERTY_GET:
1611 if (!arg)
1612 return M_PROPERTY_ERROR;
1613 if (is_cur_source) {
1614 *(int *) arg = mpctx->global_sub_pos - offset;
1615 if (source == SUB_SOURCE_VOBSUB)
1616 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1618 else
1619 *(int *) arg = -1;
1620 return M_PROPERTY_OK;
1621 case M_PROPERTY_PRINT:
1622 if (!arg)
1623 return M_PROPERTY_ERROR;
1624 if (is_cur_source)
1625 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1626 *(char **) arg = malloc(64);
1627 (*(char **) arg)[63] = 0;
1628 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1629 return M_PROPERTY_OK;
1630 case M_PROPERTY_SET:
1631 if (!arg)
1632 return M_PROPERTY_ERROR;
1633 if (*(int *) arg >= 0) {
1634 int index = *(int *)arg;
1635 if (source == SUB_SOURCE_VOBSUB)
1636 index = vobsub_get_index_by_id(vo_vobsub, index);
1637 mpctx->global_sub_pos = offset + index;
1638 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1639 || sub_source(mpctx) != source) {
1640 mpctx->global_sub_pos = -1;
1641 *(int *) arg = -1;
1644 else
1645 mpctx->global_sub_pos = -1;
1646 break;
1647 case M_PROPERTY_STEP_UP:
1648 case M_PROPERTY_STEP_DOWN: {
1649 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1650 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1651 int step = (step_all > 0) ? 1 : -1;
1652 int max_sub_pos_for_source = -1;
1653 if (!is_cur_source)
1654 mpctx->global_sub_pos = -1;
1655 while (step_all) {
1656 if (mpctx->global_sub_pos == -1) {
1657 if (step > 0)
1658 mpctx->global_sub_pos = offset;
1659 else if (max_sub_pos_for_source == -1) {
1660 // Find max pos for specific source
1661 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1662 while (mpctx->global_sub_pos >= 0
1663 && sub_source(mpctx) != source)
1664 --mpctx->global_sub_pos;
1666 else
1667 mpctx->global_sub_pos = max_sub_pos_for_source;
1669 else {
1670 mpctx->global_sub_pos += step;
1671 if (mpctx->global_sub_pos < offset ||
1672 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1673 sub_source(mpctx) != source)
1674 mpctx->global_sub_pos = -1;
1676 step_all -= step;
1678 break;
1680 default:
1681 return M_PROPERTY_NOT_IMPLEMENTED;
1683 --mpctx->global_sub_pos;
1684 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1687 /// Subtitle delay (RW)
1688 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1689 MPContext * mpctx)
1691 if (!mpctx->sh_video)
1692 return M_PROPERTY_UNAVAILABLE;
1693 return m_property_delay(prop, action, arg, &sub_delay);
1696 /// Alignment of text subtitles (RW)
1697 static int mp_property_sub_alignment(m_option_t * prop, int action,
1698 void *arg, MPContext * mpctx)
1700 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1702 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1703 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1704 return M_PROPERTY_UNAVAILABLE;
1706 switch (action) {
1707 case M_PROPERTY_PRINT:
1708 if (!arg)
1709 return M_PROPERTY_ERROR;
1710 M_PROPERTY_CLAMP(prop, sub_alignment);
1711 *(char **) arg = strdup(name[sub_alignment]);
1712 return M_PROPERTY_OK;
1713 case M_PROPERTY_SET:
1714 if (!arg)
1715 return M_PROPERTY_ERROR;
1716 case M_PROPERTY_STEP_UP:
1717 case M_PROPERTY_STEP_DOWN:
1718 vo_osd_changed(OSDTYPE_SUBTITLE);
1719 default:
1720 return m_property_choice(prop, action, arg, &sub_alignment);
1724 /// Subtitle visibility (RW)
1725 static int mp_property_sub_visibility(m_option_t * prop, int action,
1726 void *arg, MPContext * mpctx)
1728 if (!mpctx->sh_video)
1729 return M_PROPERTY_UNAVAILABLE;
1731 switch (action) {
1732 case M_PROPERTY_SET:
1733 if (!arg)
1734 return M_PROPERTY_ERROR;
1735 case M_PROPERTY_STEP_UP:
1736 case M_PROPERTY_STEP_DOWN:
1737 vo_osd_changed(OSDTYPE_SUBTITLE);
1738 if (vo_spudec)
1739 vo_osd_changed(OSDTYPE_SPU);
1740 default:
1741 return m_property_flag(prop, action, arg, &sub_visibility);
1745 #ifdef USE_ASS
1746 /// Use margins for libass subtitles (RW)
1747 static int mp_property_ass_use_margins(m_option_t * prop, int action,
1748 void *arg, MPContext * mpctx)
1750 if (!mpctx->sh_video)
1751 return M_PROPERTY_UNAVAILABLE;
1753 switch (action) {
1754 case M_PROPERTY_SET:
1755 if (!arg)
1756 return M_PROPERTY_ERROR;
1757 case M_PROPERTY_STEP_UP:
1758 case M_PROPERTY_STEP_DOWN:
1759 ass_force_reload = 1;
1760 default:
1761 return m_property_flag(prop, action, arg, &ass_use_margins);
1764 #endif
1766 /// Show only forced subtitles (RW)
1767 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1768 void *arg, MPContext * mpctx)
1770 if (!vo_spudec)
1771 return M_PROPERTY_UNAVAILABLE;
1773 switch (action) {
1774 case M_PROPERTY_SET:
1775 if (!arg)
1776 return M_PROPERTY_ERROR;
1777 case M_PROPERTY_STEP_UP:
1778 case M_PROPERTY_STEP_DOWN:
1779 m_property_flag(prop, action, arg, &forced_subs_only);
1780 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1781 return M_PROPERTY_OK;
1782 default:
1783 return m_property_flag(prop, action, arg, &forced_subs_only);
1788 #ifdef HAVE_FREETYPE
1789 /// Subtitle scale (RW)
1790 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1791 MPContext * mpctx)
1794 switch (action) {
1795 case M_PROPERTY_SET:
1796 if (!arg)
1797 return M_PROPERTY_ERROR;
1798 M_PROPERTY_CLAMP(prop, *(float *) arg);
1799 #ifdef USE_ASS
1800 if (ass_enabled) {
1801 ass_font_scale = *(float *) arg;
1802 ass_force_reload = 1;
1804 else {
1805 #endif
1806 text_font_scale_factor = *(float *) arg;
1807 force_load_font = 1;
1808 #ifdef USE_ASS
1810 #endif
1811 return M_PROPERTY_OK;
1812 case M_PROPERTY_STEP_UP:
1813 case M_PROPERTY_STEP_DOWN:
1814 #ifdef USE_ASS
1815 if (ass_enabled) {
1816 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1817 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1818 M_PROPERTY_CLAMP(prop, ass_font_scale);
1819 ass_force_reload = 1;
1821 else {
1822 #endif
1823 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1824 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1825 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1826 force_load_font = 1;
1827 #ifdef USE_ASS
1829 #endif
1830 return M_PROPERTY_OK;
1831 default:
1832 #ifdef USE_ASS
1833 if (ass_enabled)
1834 return m_property_float_ro(prop, action, arg, ass_font_scale);
1835 else
1836 #endif
1837 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1840 #endif
1842 ///@}
1844 /// \defgroup TVProperties TV properties
1845 /// \ingroup Properties
1846 ///@{
1848 #ifdef USE_TV
1850 /// TV color settings (RW)
1851 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1852 MPContext * mpctx)
1854 int r, val;
1855 tvi_handle_t *tvh = mpctx->demuxer->priv;
1856 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1857 return M_PROPERTY_UNAVAILABLE;
1859 switch (action) {
1860 case M_PROPERTY_SET:
1861 if (!arg)
1862 return M_PROPERTY_ERROR;
1863 M_PROPERTY_CLAMP(prop, *(int *) arg);
1864 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1865 case M_PROPERTY_GET:
1866 return tv_get_color_options(tvh, (int) prop->priv, arg);
1867 case M_PROPERTY_STEP_UP:
1868 case M_PROPERTY_STEP_DOWN:
1869 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1870 if (!r)
1871 return M_PROPERTY_ERROR;
1872 val += (arg ? *(int *) arg : 1) *
1873 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1874 M_PROPERTY_CLAMP(prop, val);
1875 return tv_set_color_options(tvh, (int) prop->priv, val);
1877 return M_PROPERTY_ERROR;
1879 return M_PROPERTY_NOT_IMPLEMENTED;
1882 #endif
1884 #ifdef HAVE_TV_TELETEXT
1885 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1886 MPContext * mpctx)
1888 int val,result;
1889 int base_ioctl=(int)prop->priv;
1891 for teletext's GET,SET,STEP ioctls this is not 0
1892 SET is GET+1
1893 STEP is GET+2
1895 tvi_handle_t *tvh = mpctx->demuxer->priv;
1896 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1897 return M_PROPERTY_UNAVAILABLE;
1898 if(!base_ioctl)
1899 return M_PROPERTY_ERROR;
1901 switch (action) {
1902 case M_PROPERTY_GET:
1903 if (!arg)
1904 return M_PROPERTY_ERROR;
1905 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1906 break;
1907 case M_PROPERTY_SET:
1908 if (!arg)
1909 return M_PROPERTY_ERROR;
1910 M_PROPERTY_CLAMP(prop, *(int *) arg);
1911 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1912 break;
1913 case M_PROPERTY_STEP_UP:
1914 case M_PROPERTY_STEP_DOWN:
1915 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1916 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1917 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1918 break;
1919 default:
1920 return M_PROPERTY_NOT_IMPLEMENTED;
1923 return (result==TVI_CONTROL_TRUE?M_PROPERTY_OK:M_PROPERTY_ERROR);
1926 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1927 MPContext * mpctx)
1929 tvi_handle_t *tvh = mpctx->demuxer->priv;
1930 int result;
1931 int val;
1933 //with tvh==NULL will fail too
1934 result=mp_property_teletext_common(prop,action,arg,mpctx);
1935 if(result!=M_PROPERTY_OK)
1936 return result;
1938 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1939 mp_input_set_section("teletext");
1940 else
1941 mp_input_set_section("tv");
1942 return M_PROPERTY_OK;
1945 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1946 MPContext * mpctx)
1948 tvi_handle_t *tvh = mpctx->demuxer->priv;
1949 int result;
1950 int val;
1951 switch(action){
1952 case M_PROPERTY_STEP_UP:
1953 case M_PROPERTY_STEP_DOWN:
1954 //This should be handled separately
1955 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1956 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1957 break;
1958 default:
1959 result=mp_property_teletext_common(prop,action,arg,mpctx);
1961 return result;
1965 #endif /* HAVE_TV_TELETEXT */
1967 ///@}
1969 /// All properties available in MPlayer.
1970 /** \ingroup Properties
1972 static const m_option_t mp_properties[] = {
1973 // General
1974 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1975 M_OPT_RANGE, 0, 3, NULL },
1976 { "loop", mp_property_loop, CONF_TYPE_INT,
1977 M_OPT_MIN, -1, 0, NULL },
1978 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1979 M_OPT_RANGE, 0.01, 100.0, NULL },
1980 { "filename", mp_property_filename, CONF_TYPE_STRING,
1981 0, 0, 0, NULL },
1982 { "path", mp_property_path, CONF_TYPE_STRING,
1983 0, 0, 0, NULL },
1984 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1985 0, 0, 0, NULL },
1986 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1987 M_OPT_MIN, 0, 0, NULL },
1988 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1989 M_OPT_MIN, 0, 0, NULL },
1990 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1991 M_OPT_MIN, 0, 0, NULL },
1992 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1993 M_OPT_MIN, 0, 0, NULL },
1994 { "length", mp_property_length, CONF_TYPE_TIME,
1995 M_OPT_MIN, 0, 0, NULL },
1996 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1997 M_OPT_RANGE, 0, 100, NULL },
1998 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1999 M_OPT_MIN, 0, 0, NULL },
2000 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2001 M_OPT_MIN, 1, 0, NULL },
2002 { "angle", mp_property_angle, CONF_TYPE_INT,
2003 CONF_RANGE, -2, 10, NULL },
2004 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2005 0, 0, 0, NULL },
2007 // Audio
2008 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2009 M_OPT_RANGE, 0, 100, NULL },
2010 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2011 M_OPT_RANGE, 0, 1, NULL },
2012 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2013 M_OPT_RANGE, -100, 100, NULL },
2014 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2015 0, 0, 0, NULL },
2016 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2017 0, 0, 0, NULL },
2018 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2019 0, 0, 0, NULL },
2020 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2021 0, 0, 0, NULL },
2022 { "channels", mp_property_channels, CONF_TYPE_INT,
2023 0, 0, 0, NULL },
2024 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2025 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
2026 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2027 M_OPT_RANGE, -1, 1, NULL },
2029 // Video
2030 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2031 M_OPT_RANGE, 0, 1, NULL },
2032 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2033 M_OPT_RANGE, 0, 1, NULL },
2034 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2035 M_OPT_RANGE, 0, 1, NULL },
2036 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2037 M_OPT_RANGE, 0, 1, NULL },
2038 { "border", mp_property_border, CONF_TYPE_FLAG,
2039 M_OPT_RANGE, 0, 1, NULL },
2040 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2041 M_OPT_RANGE, 0, 2, NULL },
2042 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2043 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2044 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2045 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2046 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2047 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2048 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2049 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2050 { "hue", mp_property_gamma, CONF_TYPE_INT,
2051 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2052 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2053 M_OPT_RANGE, 0, 1, NULL },
2054 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2055 M_OPT_RANGE, 0, 1, NULL },
2056 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2057 0, 0, 0, NULL },
2058 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2059 0, 0, 0, NULL },
2060 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2061 0, 0, 0, NULL },
2062 { "width", mp_property_width, CONF_TYPE_INT,
2063 0, 0, 0, NULL },
2064 { "height", mp_property_height, CONF_TYPE_INT,
2065 0, 0, 0, NULL },
2066 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2067 0, 0, 0, NULL },
2068 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2069 0, 0, 0, NULL },
2070 { "switch_video", mp_property_video, CONF_TYPE_INT,
2071 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
2072 { "switch_program", mp_property_program, CONF_TYPE_INT,
2073 CONF_RANGE, -1, 65535, NULL },
2075 // Subs
2076 { "sub", mp_property_sub, CONF_TYPE_INT,
2077 M_OPT_MIN, -1, 0, NULL },
2078 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2079 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2080 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2081 M_OPT_MIN, -1, 0, NULL },
2082 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2083 M_OPT_MIN, -1, 0, NULL },
2084 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2085 M_OPT_MIN, -1, 0, NULL },
2086 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2087 0, 0, 0, NULL },
2088 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2089 M_OPT_RANGE, 0, 100, NULL },
2090 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2091 M_OPT_RANGE, 0, 2, NULL },
2092 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2093 M_OPT_RANGE, 0, 1, NULL },
2094 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2095 M_OPT_RANGE, 0, 1, NULL },
2096 #ifdef HAVE_FREETYPE
2097 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2098 M_OPT_RANGE, 0, 100, NULL },
2099 #endif
2100 #ifdef USE_ASS
2101 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2102 M_OPT_RANGE, 0, 1, NULL },
2103 #endif
2105 #ifdef USE_TV
2106 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2107 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2108 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2109 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2110 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2111 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2112 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2113 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2114 #endif
2116 #ifdef HAVE_TV_TELETEXT
2117 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2118 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2119 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2120 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2121 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2122 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2123 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2124 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2125 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2126 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2127 #endif
2129 { NULL, NULL, NULL, 0, 0, 0, NULL }
2133 int mp_property_do(const char *name, int action, void *val, void *ctx)
2135 return m_property_do(mp_properties, name, action, val, ctx);
2138 char* mp_property_print(const char *name, void* ctx)
2140 char* ret = NULL;
2141 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2142 return NULL;
2143 return ret;
2146 char *property_expand_string(MPContext * mpctx, char *str)
2148 return m_properties_expand_string(mp_properties, str, mpctx);
2151 void property_print_help(void)
2153 m_properties_print_help_list(mp_properties);
2157 ///@}
2158 // Properties group
2162 * \defgroup Command2Property Command to property bridge
2164 * It is used to handle most commands that just set a property
2165 * and optionally display something on the OSD.
2166 * Two kinds of commands are handled: adjust or toggle.
2168 * Adjust commands take 1 or 2 parameters: <value> <abs>
2169 * If <abs> is non-zero the property is set to the given value
2170 * otherwise it is adjusted.
2172 * Toggle commands take 0 or 1 parameters. With no parameter
2173 * or a value less than the property minimum it just steps the
2174 * property to its next value. Otherwise it sets it to the given
2175 * value.
2180 /// List of the commands that can be handled by setting a property.
2181 static struct {
2182 /// property name
2183 const char *name;
2184 /// cmd id
2185 int cmd;
2186 /// set/adjust or toggle command
2187 int toggle;
2188 /// progressbar type
2189 int osd_progbar;
2190 /// osd msg id if it must be shared
2191 int osd_id;
2192 /// osd msg template
2193 const char *osd_msg;
2194 } set_prop_cmd[] = {
2195 // general
2196 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2197 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2198 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2199 // audio
2200 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2201 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2202 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2203 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2204 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2205 // video
2206 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2207 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2208 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2209 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2210 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2211 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2212 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2213 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2214 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2215 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2216 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2217 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2218 // subs
2219 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2220 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2221 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2222 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2223 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2224 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2225 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2226 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2227 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2228 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2229 #ifdef HAVE_FREETYPE
2230 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2231 #endif
2232 #ifdef USE_ASS
2233 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2234 #endif
2235 #ifdef USE_TV
2236 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2237 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2238 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2239 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2240 #endif
2241 { NULL, 0, 0, 0, -1, NULL }
2245 /// Handle commands that set a property.
2246 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
2248 int i, r;
2249 m_option_t* prop;
2250 const char *pname;
2252 // look for the command
2253 for (i = 0; set_prop_cmd[i].name; i++)
2254 if (set_prop_cmd[i].cmd == cmd->id)
2255 break;
2256 if (!(pname = set_prop_cmd[i].name))
2257 return 0;
2259 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2260 return 0;
2262 // toggle command
2263 if (set_prop_cmd[i].toggle) {
2264 // set to value
2265 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2266 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2267 else
2268 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2269 } else if (cmd->args[1].v.i) //set
2270 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2271 else // adjust
2272 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2274 if (r <= 0)
2275 return 1;
2277 if (set_prop_cmd[i].osd_progbar) {
2278 if (prop->type == CONF_TYPE_INT) {
2279 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2280 set_osd_bar(set_prop_cmd[i].osd_progbar,
2281 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2282 } else if (prop->type == CONF_TYPE_FLOAT) {
2283 float f;
2284 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2285 set_osd_bar(set_prop_cmd[i].osd_progbar,
2286 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2287 } else
2288 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2289 "Property use an unsupported type.\n");
2290 return 1;
2293 if (set_prop_cmd[i].osd_msg) {
2294 char *val = mp_property_print(pname, mpctx);
2295 if (val) {
2296 set_osd_msg(set_prop_cmd[i].osd_id >=
2297 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2298 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2299 free(val);
2302 return 1;
2306 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
2308 sh_audio_t * const sh_audio = mpctx->sh_audio;
2309 sh_video_t * const sh_video = mpctx->sh_video;
2310 int brk_cmd = 0;
2311 if (!set_property_command(mpctx, cmd))
2312 switch (cmd->id) {
2313 case MP_CMD_SEEK:{
2314 float v;
2315 int abs;
2316 if (sh_video)
2317 mpctx->osd_show_percentage = sh_video->fps;
2318 v = cmd->args[0].v.f;
2319 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2320 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2321 abs_seek_pos = 1;
2322 if (sh_video)
2323 mpctx->osd_function =
2324 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2325 rel_seek_secs = v;
2326 } else if (abs) { /* Absolute seek by percentage */
2327 abs_seek_pos = 3;
2328 if (sh_video)
2329 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2330 rel_seek_secs = v / 100.0;
2331 } else {
2332 rel_seek_secs += v;
2333 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2335 brk_cmd = 1;
2337 break;
2339 case MP_CMD_SET_PROPERTY:{
2340 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2341 cmd->args[1].v.s, mpctx);
2342 if (r == M_PROPERTY_UNKNOWN)
2343 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2344 "Unknown property: '%s'\n", cmd->args[0].v.s);
2345 else if (r <= 0)
2346 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2347 "Failed to set property '%s' to '%s'.\n",
2348 cmd->args[0].v.s, cmd->args[1].v.s);
2350 break;
2352 case MP_CMD_STEP_PROPERTY:{
2353 void* arg = NULL;
2354 int r,i;
2355 double d;
2356 off_t o;
2357 if (cmd->args[1].v.f) {
2358 m_option_t* prop;
2359 if((r = mp_property_do(cmd->args[0].v.s,
2360 M_PROPERTY_GET_TYPE,
2361 &prop, mpctx)) <= 0)
2362 goto step_prop_err;
2363 if(prop->type == CONF_TYPE_INT ||
2364 prop->type == CONF_TYPE_FLAG)
2365 i = cmd->args[1].v.f, arg = &i;
2366 else if(prop->type == CONF_TYPE_FLOAT)
2367 arg = &cmd->args[1].v.f;
2368 else if(prop->type == CONF_TYPE_DOUBLE ||
2369 prop->type == CONF_TYPE_TIME)
2370 d = cmd->args[1].v.f, arg = &d;
2371 else if(prop->type == CONF_TYPE_POSITION)
2372 o = cmd->args[1].v.f, arg = &o;
2373 else
2374 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2375 "Ignoring step size stepping property '%s'.\n",
2376 cmd->args[0].v.s);
2378 r = mp_property_do(cmd->args[0].v.s,
2379 cmd->args[2].v.i < 0 ?
2380 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2381 arg, mpctx);
2382 step_prop_err:
2383 if (r == M_PROPERTY_UNKNOWN)
2384 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2385 "Unknown property: '%s'\n", cmd->args[0].v.s);
2386 else if (r <= 0)
2387 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2388 "Failed to increment property '%s' by %f.\n",
2389 cmd->args[0].v.s, cmd->args[1].v.f);
2391 break;
2393 case MP_CMD_GET_PROPERTY:{
2394 char *tmp;
2395 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2396 &tmp, mpctx) <= 0) {
2397 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2398 "Failed to get value of property '%s'.\n",
2399 cmd->args[0].v.s);
2400 break;
2402 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2403 cmd->args[0].v.s, tmp);
2404 free(tmp);
2406 break;
2408 case MP_CMD_EDL_MARK:
2409 if (edl_fd) {
2410 float v = sh_video ? sh_video->pts :
2411 playing_audio_pts(sh_audio, mpctx->d_audio,
2412 mpctx->audio_out);
2414 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2415 mpctx->begin_skip = v;
2416 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2417 } else {
2418 if (mpctx->begin_skip > v)
2419 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2420 else {
2421 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2422 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2424 mpctx->begin_skip = MP_NOPTS_VALUE;
2427 break;
2429 case MP_CMD_SWITCH_RATIO:
2430 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2431 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2432 else
2433 movie_aspect = cmd->args[0].v.f;
2434 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2435 break;
2437 case MP_CMD_SPEED_INCR:{
2438 float v = cmd->args[0].v.f;
2439 playback_speed += v;
2440 build_afilter_chain(sh_audio, &ao_data);
2441 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2442 playback_speed);
2443 } break;
2445 case MP_CMD_SPEED_MULT:{
2446 float v = cmd->args[0].v.f;
2447 playback_speed *= v;
2448 build_afilter_chain(sh_audio, &ao_data);
2449 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2450 playback_speed);
2451 } break;
2453 case MP_CMD_SPEED_SET:{
2454 float v = cmd->args[0].v.f;
2455 playback_speed = v;
2456 build_afilter_chain(sh_audio, &ao_data);
2457 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2458 playback_speed);
2459 } break;
2461 case MP_CMD_FRAME_STEP:
2462 case MP_CMD_PAUSE:
2463 cmd->pausing = 1;
2464 brk_cmd = 1;
2465 break;
2467 case MP_CMD_FILE_FILTER:
2468 file_filter = cmd->args[0].v.i;
2469 break;
2471 case MP_CMD_QUIT:
2472 exit_player_with_rc(MSGTR_Exit_quit,
2473 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2475 case MP_CMD_PLAY_TREE_STEP:{
2476 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2477 int force = cmd->args[1].v.i;
2479 #ifdef HAVE_NEW_GUI
2480 if (use_gui) {
2481 int i = 0;
2482 if (n > 0)
2483 for (i = 0; i < n; i++)
2484 mplNext();
2485 else
2486 for (i = 0; i < -1 * n; i++)
2487 mplPrev();
2488 } else
2489 #endif
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_step(i, n, 0) ==
2495 PLAY_TREE_ITER_ENTRY)
2496 mpctx->eof =
2497 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2498 play_tree_iter_free(i);
2499 } else
2500 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2501 if (mpctx->eof)
2502 mpctx->play_tree_step = n;
2503 brk_cmd = 1;
2506 break;
2508 case MP_CMD_PLAY_TREE_UP_STEP:{
2509 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2510 int force = cmd->args[1].v.i;
2512 if (!force && mpctx->playtree_iter) {
2513 play_tree_iter_t *i =
2514 play_tree_iter_new_copy(mpctx->playtree_iter);
2515 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2516 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2517 play_tree_iter_free(i);
2518 } else
2519 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2520 brk_cmd = 1;
2522 break;
2524 case MP_CMD_PLAY_ALT_SRC_STEP:
2525 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2526 int v = cmd->args[0].v.i;
2527 if (v > 0
2528 && mpctx->playtree_iter->file <
2529 mpctx->playtree_iter->num_files)
2530 mpctx->eof = PT_NEXT_SRC;
2531 else if (v < 0 && mpctx->playtree_iter->file > 1)
2532 mpctx->eof = PT_PREV_SRC;
2534 brk_cmd = 1;
2535 break;
2537 case MP_CMD_SUB_STEP:
2538 if (sh_video) {
2539 int movement = cmd->args[0].v.i;
2540 step_sub(subdata, sh_video->pts, movement);
2541 #ifdef USE_ASS
2542 if (ass_track)
2543 sub_delay +=
2544 ass_step_sub(ass_track,
2545 (sh_video->pts +
2546 sub_delay) * 1000 + .5, movement) / 1000.;
2547 #endif
2548 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2549 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2551 break;
2553 case MP_CMD_SUB_LOG:
2554 log_sub();
2555 break;
2557 case MP_CMD_OSD:{
2558 int v = cmd->args[0].v.i;
2559 int max = (term_osd
2560 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2561 if (osd_level > max)
2562 osd_level = max;
2563 if (v < 0)
2564 osd_level = (osd_level + 1) % (max + 1);
2565 else
2566 osd_level = v > max ? max : v;
2567 /* Show OSD state when disabled, but not when an explicit
2568 argument is given to the OSD command, i.e. in slave mode. */
2569 if (v == -1 && osd_level <= 1)
2570 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2571 MSGTR_OSDosd,
2572 osd_level ? MSGTR_OSDenabled :
2573 MSGTR_OSDdisabled);
2574 else
2575 rm_osd_msg(OSD_MSG_OSD_STATUS);
2577 break;
2579 case MP_CMD_OSD_SHOW_TEXT:
2580 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2581 (cmd->args[1].v.i <
2582 0 ? osd_duration : cmd->args[1].v.i),
2583 "%-.63s", cmd->args[0].v.s);
2584 break;
2586 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2587 char *txt = m_properties_expand_string(mp_properties,
2588 cmd->args[0].v.s,
2589 mpctx);
2590 /* if no argument supplied take default osd_duration, else <arg> ms. */
2591 if (txt) {
2592 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2593 (cmd->args[1].v.i <
2594 0 ? osd_duration : cmd->args[1].v.i),
2595 "%-.63s", txt);
2596 free(txt);
2599 break;
2601 case MP_CMD_LOADFILE:{
2602 play_tree_t *e = play_tree_new();
2603 play_tree_add_file(e, cmd->args[0].v.s);
2605 if (cmd->args[1].v.i) // append
2606 play_tree_append_entry(mpctx->playtree, e);
2607 else {
2608 // Go back to the starting point.
2609 while (play_tree_iter_up_step
2610 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2611 /* NOP */ ;
2612 play_tree_free_list(mpctx->playtree->child, 1);
2613 play_tree_set_child(mpctx->playtree, e);
2614 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2615 mpctx->eof = PT_NEXT_SRC;
2617 brk_cmd = 1;
2619 break;
2621 case MP_CMD_LOADLIST:{
2622 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2623 if (!e)
2624 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2625 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2626 else {
2627 if (cmd->args[1].v.i) // append
2628 play_tree_append_entry(mpctx->playtree, e);
2629 else {
2630 // Go back to the starting point.
2631 while (play_tree_iter_up_step
2632 (mpctx->playtree_iter, 0, 1)
2633 != PLAY_TREE_ITER_END)
2634 /* NOP */ ;
2635 play_tree_free_list(mpctx->playtree->child, 1);
2636 play_tree_set_child(mpctx->playtree, e);
2637 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2638 mpctx->eof = PT_NEXT_SRC;
2641 brk_cmd = 1;
2643 break;
2645 #ifdef USE_RADIO
2646 case MP_CMD_RADIO_STEP_CHANNEL:
2647 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2648 int v = cmd->args[0].v.i;
2649 if (v > 0)
2650 radio_step_channel(mpctx->demuxer->stream,
2651 RADIO_CHANNEL_HIGHER);
2652 else
2653 radio_step_channel(mpctx->demuxer->stream,
2654 RADIO_CHANNEL_LOWER);
2655 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2656 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2657 MSGTR_OSDChannel,
2658 radio_get_channel_name(mpctx->demuxer->stream));
2661 break;
2663 case MP_CMD_RADIO_SET_CHANNEL:
2664 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2665 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2666 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2667 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2668 MSGTR_OSDChannel,
2669 radio_get_channel_name(mpctx->demuxer->stream));
2672 break;
2674 case MP_CMD_RADIO_SET_FREQ:
2675 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2676 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2677 break;
2679 case MP_CMD_RADIO_STEP_FREQ:
2680 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2681 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2682 break;
2683 #endif
2685 #ifdef USE_TV
2686 case MP_CMD_TV_START_SCAN:
2687 if (mpctx->file_format == DEMUXER_TYPE_TV)
2688 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2689 break;
2690 case MP_CMD_TV_SET_FREQ:
2691 if (mpctx->file_format == DEMUXER_TYPE_TV)
2692 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2693 cmd->args[0].v.f * 16.0);
2694 #ifdef HAVE_PVR
2695 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2696 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2697 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2698 pvr_get_current_channelname (mpctx->stream),
2699 pvr_get_current_stationname (mpctx->stream));
2701 #endif /* HAVE_PVR */
2702 break;
2704 case MP_CMD_TV_STEP_FREQ:
2705 if (mpctx->file_format == DEMUXER_TYPE_TV)
2706 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2707 cmd->args[0].v.f * 16.0);
2708 #ifdef HAVE_PVR
2709 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2710 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2711 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2712 pvr_get_current_channelname (mpctx->stream),
2713 pvr_get_current_frequency (mpctx->stream));
2715 #endif /* HAVE_PVR */
2716 break;
2718 case MP_CMD_TV_SET_NORM:
2719 if (mpctx->file_format == DEMUXER_TYPE_TV)
2720 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2721 cmd->args[0].v.s);
2722 break;
2724 case MP_CMD_TV_STEP_CHANNEL:{
2725 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2726 int v = cmd->args[0].v.i;
2727 if (v > 0) {
2728 tv_step_channel((tvi_handle_t *) (mpctx->
2729 demuxer->priv),
2730 TV_CHANNEL_HIGHER);
2731 } else {
2732 tv_step_channel((tvi_handle_t *) (mpctx->
2733 demuxer->priv),
2734 TV_CHANNEL_LOWER);
2736 if (tv_channel_list) {
2737 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2738 MSGTR_OSDChannel, tv_channel_current->name);
2739 //vo_osd_changed(OSDTYPE_SUBTITLE);
2742 #ifdef HAVE_PVR
2743 else if (mpctx->stream &&
2744 mpctx->stream->type == STREAMTYPE_PVR) {
2745 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2746 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2747 pvr_get_current_channelname (mpctx->stream),
2748 pvr_get_current_stationname (mpctx->stream));
2750 #endif /* HAVE_PVR */
2752 #ifdef HAS_DVBIN_SUPPORT
2753 if (mpctx->stream->type == STREAMTYPE_DVB) {
2754 int dir;
2755 int v = cmd->args[0].v.i;
2757 mpctx->last_dvb_step = v;
2758 if (v > 0)
2759 dir = DVB_CHANNEL_HIGHER;
2760 else
2761 dir = DVB_CHANNEL_LOWER;
2764 if (dvb_step_channel(mpctx->stream, dir))
2765 mpctx->eof = mpctx->dvbin_reopen = 1;
2767 #endif /* HAS_DVBIN_SUPPORT */
2768 break;
2770 case MP_CMD_TV_SET_CHANNEL:
2771 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2772 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2773 cmd->args[0].v.s);
2774 if (tv_channel_list) {
2775 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2776 MSGTR_OSDChannel, tv_channel_current->name);
2777 //vo_osd_changed(OSDTYPE_SUBTITLE);
2780 #ifdef HAVE_PVR
2781 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2782 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2783 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2784 pvr_get_current_channelname (mpctx->stream),
2785 pvr_get_current_stationname (mpctx->stream));
2787 #endif /* HAVE_PVR */
2788 break;
2790 #ifdef HAS_DVBIN_SUPPORT
2791 case MP_CMD_DVB_SET_CHANNEL:
2792 if (mpctx->stream->type == STREAMTYPE_DVB) {
2793 mpctx->last_dvb_step = 1;
2795 if (dvb_set_channel
2796 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2797 mpctx->eof = mpctx->dvbin_reopen = 1;
2799 break;
2800 #endif /* HAS_DVBIN_SUPPORT */
2802 case MP_CMD_TV_LAST_CHANNEL:
2803 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2804 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2805 if (tv_channel_list) {
2806 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2807 MSGTR_OSDChannel, tv_channel_current->name);
2808 //vo_osd_changed(OSDTYPE_SUBTITLE);
2811 #ifdef HAVE_PVR
2812 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2813 pvr_set_lastchannel (mpctx->stream);
2814 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2815 pvr_get_current_channelname (mpctx->stream),
2816 pvr_get_current_stationname (mpctx->stream));
2818 #endif /* HAVE_PVR */
2819 break;
2821 case MP_CMD_TV_STEP_NORM:
2822 if (mpctx->file_format == DEMUXER_TYPE_TV)
2823 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2824 break;
2826 case MP_CMD_TV_STEP_CHANNEL_LIST:
2827 if (mpctx->file_format == DEMUXER_TYPE_TV)
2828 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2829 break;
2830 #ifdef HAVE_TV_TELETEXT
2831 case MP_CMD_TV_TELETEXT_ADD_DEC:
2833 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2834 if (mpctx->file_format == DEMUXER_TYPE_TV)
2835 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2836 break;
2838 case MP_CMD_TV_TELETEXT_GO_LINK:
2840 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2841 if (mpctx->file_format == DEMUXER_TYPE_TV)
2842 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2843 break;
2845 #endif /* HAVE_TV_TELETEXT */
2846 #endif /* USE_TV */
2848 case MP_CMD_SUB_LOAD:
2849 if (sh_video) {
2850 int n = mpctx->set_of_sub_size;
2851 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2852 if (n != mpctx->set_of_sub_size) {
2853 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2854 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2855 mpctx->global_sub_size;
2856 ++mpctx->global_sub_size;
2859 break;
2861 case MP_CMD_SUB_REMOVE:
2862 if (sh_video) {
2863 int v = cmd->args[0].v.i;
2864 sub_data *subd;
2865 if (v < 0) {
2866 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2867 subd = mpctx->set_of_subtitles[v];
2868 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2869 MSGTR_RemovedSubtitleFile, v + 1,
2870 filename_recode(subd->filename));
2871 sub_free(subd);
2872 mpctx->set_of_subtitles[v] = NULL;
2874 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2875 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2876 mpctx->set_of_sub_size = 0;
2877 if (mpctx->set_of_sub_pos >= 0) {
2878 mpctx->global_sub_pos = -2;
2879 subdata = NULL;
2880 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2882 } else if (v < mpctx->set_of_sub_size) {
2883 subd = mpctx->set_of_subtitles[v];
2884 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2885 MSGTR_RemovedSubtitleFile, v + 1,
2886 filename_recode(subd->filename));
2887 sub_free(subd);
2888 if (mpctx->set_of_sub_pos == v) {
2889 mpctx->global_sub_pos = -2;
2890 subdata = NULL;
2891 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2892 } else if (mpctx->set_of_sub_pos > v) {
2893 --mpctx->set_of_sub_pos;
2894 --mpctx->global_sub_pos;
2896 while (++v < mpctx->set_of_sub_size)
2897 mpctx->set_of_subtitles[v - 1] =
2898 mpctx->set_of_subtitles[v];
2899 --mpctx->set_of_sub_size;
2900 --mpctx->global_sub_size;
2901 if (mpctx->set_of_sub_size <= 0)
2902 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2903 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2906 break;
2908 case MP_CMD_GET_SUB_VISIBILITY:
2909 if (sh_video) {
2910 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2911 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2913 break;
2915 case MP_CMD_SCREENSHOT:
2916 if (vo_config_count) {
2917 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2918 if (CONTROL_OK !=
2919 ((vf_instance_t *) sh_video->vfilter)->
2920 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2921 &cmd->args[0].v.i))
2922 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2924 break;
2926 case MP_CMD_VF_CHANGE_RECTANGLE:
2927 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2928 break;
2930 case MP_CMD_GET_TIME_LENGTH:{
2931 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2932 demuxer_get_time_length(mpctx->demuxer));
2934 break;
2936 case MP_CMD_GET_FILENAME:{
2937 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2938 get_metadata(META_NAME));
2940 break;
2942 case MP_CMD_GET_VIDEO_CODEC:{
2943 char *inf = get_metadata(META_VIDEO_CODEC);
2944 if (!inf)
2945 inf = strdup("");
2946 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2947 free(inf);
2949 break;
2951 case MP_CMD_GET_VIDEO_BITRATE:{
2952 char *inf = get_metadata(META_VIDEO_BITRATE);
2953 if (!inf)
2954 inf = strdup("");
2955 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2956 free(inf);
2958 break;
2960 case MP_CMD_GET_VIDEO_RESOLUTION:{
2961 char *inf = get_metadata(META_VIDEO_RESOLUTION);
2962 if (!inf)
2963 inf = strdup("");
2964 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2965 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
2966 free(inf);
2968 break;
2970 case MP_CMD_GET_AUDIO_CODEC:{
2971 char *inf = get_metadata(META_AUDIO_CODEC);
2972 if (!inf)
2973 inf = strdup("");
2974 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
2975 free(inf);
2977 break;
2979 case MP_CMD_GET_AUDIO_BITRATE:{
2980 char *inf = get_metadata(META_AUDIO_BITRATE);
2981 if (!inf)
2982 inf = strdup("");
2983 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
2984 free(inf);
2986 break;
2988 case MP_CMD_GET_AUDIO_SAMPLES:{
2989 char *inf = get_metadata(META_AUDIO_SAMPLES);
2990 if (!inf)
2991 inf = strdup("");
2992 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
2993 free(inf);
2995 break;
2997 case MP_CMD_GET_META_TITLE:{
2998 char *inf = get_metadata(META_INFO_TITLE);
2999 if (!inf)
3000 inf = strdup("");
3001 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3002 free(inf);
3004 break;
3006 case MP_CMD_GET_META_ARTIST:{
3007 char *inf = get_metadata(META_INFO_ARTIST);
3008 if (!inf)
3009 inf = strdup("");
3010 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3011 free(inf);
3013 break;
3015 case MP_CMD_GET_META_ALBUM:{
3016 char *inf = get_metadata(META_INFO_ALBUM);
3017 if (!inf)
3018 inf = strdup("");
3019 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3020 free(inf);
3022 break;
3024 case MP_CMD_GET_META_YEAR:{
3025 char *inf = get_metadata(META_INFO_YEAR);
3026 if (!inf)
3027 inf = strdup("");
3028 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3029 free(inf);
3031 break;
3033 case MP_CMD_GET_META_COMMENT:{
3034 char *inf = get_metadata(META_INFO_COMMENT);
3035 if (!inf)
3036 inf = strdup("");
3037 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3038 free(inf);
3040 break;
3042 case MP_CMD_GET_META_TRACK:{
3043 char *inf = get_metadata(META_INFO_TRACK);
3044 if (!inf)
3045 inf = strdup("");
3046 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3047 free(inf);
3049 break;
3051 case MP_CMD_GET_META_GENRE:{
3052 char *inf = get_metadata(META_INFO_GENRE);
3053 if (!inf)
3054 inf = strdup("");
3055 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3056 free(inf);
3058 break;
3060 case MP_CMD_GET_VO_FULLSCREEN:
3061 if (mpctx->video_out && vo_config_count)
3062 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3063 break;
3065 case MP_CMD_GET_PERCENT_POS:
3066 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3067 demuxer_get_percent_pos(mpctx->demuxer));
3068 break;
3070 case MP_CMD_GET_TIME_POS:{
3071 float pos = 0;
3072 if (sh_video)
3073 pos = sh_video->pts;
3074 else if (sh_audio && mpctx->audio_out)
3075 pos =
3076 playing_audio_pts(sh_audio, mpctx->d_audio,
3077 mpctx->audio_out);
3078 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3080 break;
3082 case MP_CMD_RUN:
3083 #ifndef __MINGW32__
3084 if (!fork()) {
3085 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3086 exit(0);
3088 #endif
3089 break;
3091 case MP_CMD_KEYDOWN_EVENTS:
3092 mplayer_put_key(cmd->args[0].v.i);
3093 break;
3095 case MP_CMD_SET_MOUSE_POS:{
3096 int pointer_x, pointer_y;
3097 double dx, dy;
3098 pointer_x = cmd->args[0].v.i;
3099 pointer_y = cmd->args[1].v.i;
3100 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
3101 #ifdef USE_DVDNAV
3102 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3103 && dx > 0.0 && dy > 0.0) {
3104 int button = -1;
3105 pointer_x = (int) (dx * (double) sh_video->disp_w);
3106 pointer_y = (int) (dy * (double) sh_video->disp_h);
3107 mp_dvdnav_update_mouse_pos(mpctx->stream,
3108 pointer_x, pointer_y, &button);
3109 if (button > 0)
3110 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3111 "Selected button number %d", button);
3113 #endif
3114 #ifdef HAVE_MENU
3115 if (use_menu && dx >= 0.0 && dy >= 0.0)
3116 menu_update_mouse_pos(dx, dy);
3117 #endif
3119 break;
3121 #ifdef USE_DVDNAV
3122 case MP_CMD_DVDNAV:{
3123 int button = -1;
3124 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3125 break;
3127 mp_dvdnav_handle_input(mpctx->stream,cmd->args[0].v.i,&button);
3128 if (button > 0)
3129 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3130 "Selected button number %d", button);
3132 break;
3134 case MP_CMD_SWITCH_TITLE:
3135 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3136 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3137 break;
3139 #endif
3141 default:
3142 #ifdef HAVE_NEW_GUI
3143 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3144 guiGetEvent(guiIEvent, (char *) cmd->id);
3145 else
3146 #endif
3147 mp_msg(MSGT_CPLAYER, MSGL_V,
3148 "Received unknown cmd %s\n", cmd->name);
3151 switch (cmd->pausing) {
3152 case 1: // "pausing"
3153 mpctx->osd_function = OSD_PAUSE;
3154 break;
3155 case 3: // "pausing_toggle"
3156 mpctx->was_paused = !mpctx->was_paused;
3157 if (mpctx->was_paused)
3158 mpctx->osd_function = OSD_PAUSE;
3159 else if (mpctx->osd_function == OSD_PAUSE)
3160 mpctx->osd_function = OSD_PLAY;
3161 break;
3162 case 2: // "pausing_keep"
3163 if (mpctx->was_paused)
3164 mpctx->osd_function = OSD_PAUSE;
3166 return brk_cmd;