Merge svn changes up to r27441
[mplayer.git] / command.c
blob418e30b84f01411bf1e386c4e6ee78499382eb49
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 "mp_osd.h"
22 #include "libvo/video_out.h"
23 #include "libvo/font_load.h"
24 #include "playtree.h"
25 #include "libao2/audio_out.h"
26 #include "mpcommon.h"
27 #include "mixer.h"
28 #include "libmpcodecs/dec_video.h"
29 #include "vobsub.h"
30 #include "spudec.h"
31 #include "get_path.h"
32 #ifdef CONFIG_TV
33 #include "stream/tv.h"
34 #endif
35 #ifdef CONFIG_RADIO
36 #include "stream/stream_radio.h"
37 #endif
38 #ifdef CONFIG_PVR
39 #include "stream/pvr.h"
40 #endif
41 #ifdef CONFIG_DVBIN
42 #include "stream/dvbin.h"
43 #endif
44 #ifdef CONFIG_DVDREAD
45 #include "stream/stream_dvd.h"
46 #endif
47 #ifdef CONFIG_DVDNAV
48 #include "stream/stream_dvdnav.h"
49 #endif
50 #ifdef CONFIG_ASS
51 #include "libass/ass.h"
52 #include "libass/ass_mp.h"
53 #endif
54 #ifdef CONFIG_MENU
55 #include "m_struct.h"
56 #include "libmenu/menu.h"
57 #endif
58 #ifdef CONFIG_GUI
59 #include "gui/interface.h"
60 #endif
62 #include "mp_core.h"
63 #include "mp_fifo.h"
64 #include "libavutil/avstring.h"
66 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
68 extern int use_menu;
70 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
71 double *dx, double *dy)
73 struct MPOpts *opts = &mpctx->opts;
74 struct vo *vo = mpctx->video_out;
75 //remove the borders, if any, and rescale to the range [0,1],[0,1]
76 if (vo_fs) { //we are in full-screen mode
77 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
78 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
79 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
80 iy -= (opts->vo_screenheight - vo->dheight) / 2;
82 if (ix < 0 || ix > vo->dwidth) {
83 *dx = *dy = -1.0;
84 return;
85 } //we are on one of the borders
86 if (iy < 0 || iy > vo->dheight) {
87 *dx = *dy = -1.0;
88 return;
89 } //we are on one of the borders
92 *dx = (double) ix / (double) vo->dwidth;
93 *dy = (double) iy / (double) vo->dheight;
95 mp_msg(MSGT_CPLAYER, MSGL_V,
96 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
97 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
98 vo->dheight, vo_fs);
101 static int sub_source_by_pos(MPContext *mpctx, int pos)
103 int source = -1;
104 int top = -1;
105 int i;
106 for (i = 0; i < SUB_SOURCES; i++) {
107 int j = mpctx->global_sub_indices[i];
108 if ((j >= 0) && (j > top) && (pos >= j)) {
109 source = i;
110 top = j;
113 return source;
116 static int sub_source(MPContext *mpctx)
118 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
122 * \brief Log the currently displayed subtitle to a file
124 * Logs the current or last displayed subtitle together with filename
125 * and time information to ~/.mplayer/subtitle_log
127 * Intended purpose is to allow convenient marking of bogus subtitles
128 * which need to be fixed while watching the movie.
131 static void log_sub(struct MPContext *mpctx)
133 char *fname;
134 FILE *f;
135 int i;
137 if (subdata == NULL || vo_sub_last == NULL)
138 return;
139 fname = get_path("subtitle_log");
140 f = fopen(fname, "a");
141 if (!f)
142 return;
143 fprintf(f, "----------------------------------------------------------\n");
144 if (subdata->sub_uses_time) {
145 fprintf(f,
146 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
147 mpctx->filename, vo_sub_last->start / 360000,
148 (vo_sub_last->start / 6000) % 60,
149 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
150 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
151 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
152 } else {
153 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
154 vo_sub_last->start, vo_sub_last->end);
156 for (i = 0; i < vo_sub_last->lines; i++) {
157 fprintf(f, "%s\n", vo_sub_last->text[i]);
159 fclose(f);
163 /// \defgroup Properties
164 ///@{
166 /// \defgroup GeneralProperties General properties
167 /// \ingroup Properties
168 ///@{
170 /// OSD level (RW)
171 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
172 MPContext *mpctx)
174 return m_property_choice(prop, action, arg, &osd_level);
177 /// Loop (RW)
178 static int mp_property_loop(m_option_t *prop, int action, void *arg,
179 MPContext *mpctx)
181 struct MPOpts *opts = &mpctx->opts;
182 switch (action) {
183 case M_PROPERTY_PRINT:
184 if (!arg) return M_PROPERTY_ERROR;
185 if (opts->loop_times < 0)
186 *(char**)arg = strdup("off");
187 else if (opts->loop_times == 0)
188 *(char**)arg = strdup("inf");
189 else
190 break;
191 return M_PROPERTY_OK;
193 return m_property_int_range(prop, action, arg, &opts->loop_times);
196 /// Playback speed (RW)
197 static int mp_property_playback_speed(m_option_t *prop, int action,
198 void *arg, MPContext *mpctx)
200 struct MPOpts *opts = &mpctx->opts;
201 switch (action) {
202 case M_PROPERTY_SET:
203 if (!arg)
204 return M_PROPERTY_ERROR;
205 M_PROPERTY_CLAMP(prop, *(float *) arg);
206 opts->playback_speed = *(float *) arg;
207 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
208 return M_PROPERTY_OK;
209 case M_PROPERTY_STEP_UP:
210 case M_PROPERTY_STEP_DOWN:
211 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
212 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
213 M_PROPERTY_CLAMP(prop, opts->playback_speed);
214 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
215 return M_PROPERTY_OK;
217 return m_property_float_range(prop, action, arg, &opts->playback_speed);
220 /// filename with path (RO)
221 static int mp_property_path(m_option_t *prop, int action, void *arg,
222 MPContext *mpctx)
224 return m_property_string_ro(prop, action, arg, mpctx->filename);
227 /// filename without path (RO)
228 static int mp_property_filename(m_option_t *prop, int action, void *arg,
229 MPContext *mpctx)
231 char *f;
232 if (!mpctx->filename)
233 return M_PROPERTY_UNAVAILABLE;
234 if (((f = strrchr(mpctx->filename, '/'))
235 || (f = strrchr(mpctx->filename, '\\'))) && f[1])
236 f++;
237 else
238 f = mpctx->filename;
239 return m_property_string_ro(prop, action, arg, f);
242 /// Demuxer name (RO)
243 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
244 MPContext *mpctx)
246 if (!mpctx->demuxer)
247 return M_PROPERTY_UNAVAILABLE;
248 return m_property_string_ro(prop, action, arg,
249 (char *) mpctx->demuxer->desc->name);
252 /// Position in the stream (RW)
253 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
254 MPContext *mpctx)
256 if (!mpctx->demuxer || !mpctx->demuxer->stream)
257 return M_PROPERTY_UNAVAILABLE;
258 if (!arg)
259 return M_PROPERTY_ERROR;
260 switch (action) {
261 case M_PROPERTY_GET:
262 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
263 return M_PROPERTY_OK;
264 case M_PROPERTY_SET:
265 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
266 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
267 return M_PROPERTY_OK;
269 return M_PROPERTY_NOT_IMPLEMENTED;
272 /// Stream start offset (RO)
273 static int mp_property_stream_start(m_option_t *prop, int action,
274 void *arg, MPContext *mpctx)
276 if (!mpctx->demuxer || !mpctx->demuxer->stream)
277 return M_PROPERTY_UNAVAILABLE;
278 switch (action) {
279 case M_PROPERTY_GET:
280 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
281 return M_PROPERTY_OK;
283 return M_PROPERTY_NOT_IMPLEMENTED;
286 /// Stream end offset (RO)
287 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
288 MPContext *mpctx)
290 if (!mpctx->demuxer || !mpctx->demuxer->stream)
291 return M_PROPERTY_UNAVAILABLE;
292 switch (action) {
293 case M_PROPERTY_GET:
294 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
295 return M_PROPERTY_OK;
297 return M_PROPERTY_NOT_IMPLEMENTED;
300 /// Stream length (RO)
301 static int mp_property_stream_length(m_option_t *prop, int action,
302 void *arg, MPContext *mpctx)
304 if (!mpctx->demuxer || !mpctx->demuxer->stream)
305 return M_PROPERTY_UNAVAILABLE;
306 switch (action) {
307 case M_PROPERTY_GET:
308 *(off_t *) arg =
309 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
310 return M_PROPERTY_OK;
312 return M_PROPERTY_NOT_IMPLEMENTED;
315 /// Media length in seconds (RO)
316 static int mp_property_length(m_option_t *prop, int action, void *arg,
317 MPContext *mpctx)
319 double len;
321 if (!mpctx->demuxer ||
322 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
323 return M_PROPERTY_UNAVAILABLE;
325 return m_property_time_ro(prop, action, arg, len);
328 /// Current position in percent (RW)
329 static int mp_property_percent_pos(m_option_t *prop, int action,
330 void *arg, MPContext *mpctx) {
331 int pos;
333 if (!mpctx->demuxer)
334 return M_PROPERTY_UNAVAILABLE;
336 switch(action) {
337 case M_PROPERTY_SET:
338 if(!arg) return M_PROPERTY_ERROR;
339 M_PROPERTY_CLAMP(prop, *(int*)arg);
340 pos = *(int*)arg;
341 break;
342 case M_PROPERTY_STEP_UP:
343 case M_PROPERTY_STEP_DOWN:
344 pos = demuxer_get_percent_pos(mpctx->demuxer);
345 pos += (arg ? *(int*)arg : 10) *
346 (action == M_PROPERTY_STEP_UP ? 1 : -1);
347 M_PROPERTY_CLAMP(prop, pos);
348 break;
349 default:
350 return m_property_int_ro(prop, action, arg,
351 demuxer_get_percent_pos(mpctx->demuxer));
354 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
355 mpctx->rel_seek_secs = pos / 100.0;
356 return M_PROPERTY_OK;
359 /// Current position in seconds (RW)
360 static int mp_property_time_pos(m_option_t *prop, int action,
361 void *arg, MPContext *mpctx) {
362 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
363 return M_PROPERTY_UNAVAILABLE;
365 switch(action) {
366 case M_PROPERTY_SET:
367 if(!arg) return M_PROPERTY_ERROR;
368 M_PROPERTY_CLAMP(prop, *(double*)arg);
369 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
370 mpctx->rel_seek_secs = *(double*)arg;
371 return M_PROPERTY_OK;
372 case M_PROPERTY_STEP_UP:
373 case M_PROPERTY_STEP_DOWN:
374 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
375 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
376 return M_PROPERTY_OK;
378 return m_property_time_ro(prop, action, arg,
379 mpctx->sh_video ? mpctx->sh_video->pts :
380 playing_audio_pts(mpctx));
383 /// Current chapter (RW)
384 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
385 MPContext *mpctx)
387 int chapter = -1;
388 float next_pts = 0;
389 int chapter_num;
390 int step_all;
391 char *chapter_name = NULL;
393 if (mpctx->demuxer)
394 chapter = demuxer_get_current_chapter(mpctx->demuxer);
395 if (chapter < 0)
396 return M_PROPERTY_UNAVAILABLE;
398 switch (action) {
399 case M_PROPERTY_GET:
400 if (!arg)
401 return M_PROPERTY_ERROR;
402 *(int *) arg = chapter;
403 return M_PROPERTY_OK;
404 case M_PROPERTY_PRINT: {
405 if (!arg)
406 return M_PROPERTY_ERROR;
407 chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter);
408 if (!chapter_name)
409 return M_PROPERTY_UNAVAILABLE;
410 *(char **) arg = chapter_name;
411 return M_PROPERTY_OK;
413 case M_PROPERTY_SET:
414 if (!arg)
415 return M_PROPERTY_ERROR;
416 M_PROPERTY_CLAMP(prop, *(int*)arg);
417 step_all = *(int *)arg - (chapter + 1);
418 chapter += step_all;
419 break;
420 case M_PROPERTY_STEP_UP:
421 case M_PROPERTY_STEP_DOWN: {
422 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
423 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
424 chapter += step_all;
425 if (chapter < 0)
426 chapter = 0;
427 break;
429 default:
430 return M_PROPERTY_NOT_IMPLEMENTED;
432 mpctx->rel_seek_secs = 0;
433 mpctx->abs_seek_pos = 0;
434 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
435 &next_pts, &chapter_num, &chapter_name);
436 if (chapter >= 0) {
437 if (next_pts > -1.0) {
438 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
439 mpctx->rel_seek_secs = next_pts;
441 if (chapter_name)
442 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
443 MSGTR_OSDChapter, chapter + 1, chapter_name);
445 else if (step_all > 0)
446 mpctx->rel_seek_secs = 1000000000.;
447 else
448 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
449 MSGTR_OSDChapter, 0, MSGTR_Unknown);
450 if (chapter_name)
451 free(chapter_name);
452 return M_PROPERTY_OK;
455 /// Current dvd angle (RW)
456 static int mp_property_angle(m_option_t *prop, int action, void *arg,
457 MPContext *mpctx)
459 int angle = -1;
460 int angles;
461 char *angle_name = NULL;
463 if (mpctx->demuxer)
464 angle = demuxer_get_current_angle(mpctx->demuxer);
465 if (angle < 0)
466 return M_PROPERTY_UNAVAILABLE;
467 angles = demuxer_angles_count(mpctx->demuxer);
468 if (angles <= 1)
469 return M_PROPERTY_UNAVAILABLE;
471 switch (action) {
472 case M_PROPERTY_GET:
473 if (!arg)
474 return M_PROPERTY_ERROR;
475 *(int *) arg = angle;
476 return M_PROPERTY_OK;
477 case M_PROPERTY_PRINT: {
478 if (!arg)
479 return M_PROPERTY_ERROR;
480 angle_name = calloc(1, 64);
481 if (!angle_name)
482 return M_PROPERTY_UNAVAILABLE;
483 snprintf(angle_name, 64, "%d/%d", angle, angles);
484 *(char **) arg = angle_name;
485 return M_PROPERTY_OK;
487 case M_PROPERTY_SET:
488 if (!arg)
489 return M_PROPERTY_ERROR;
490 angle = *(int *)arg;
491 M_PROPERTY_CLAMP(prop, angle);
492 break;
493 case M_PROPERTY_STEP_UP:
494 case M_PROPERTY_STEP_DOWN: {
495 int step = 0;
496 if(arg)
497 step = *(int*)arg;
498 if(!step)
499 step = 1;
500 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
501 angle += step;
502 if (angle < 1) //cycle
503 angle = angles;
504 break;
506 default:
507 return M_PROPERTY_NOT_IMPLEMENTED;
509 angle = demuxer_set_angle(mpctx->demuxer, angle);
510 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
511 MSGTR_OSDAngle, angle, angles);
512 if (angle_name)
513 free(angle_name);
514 return M_PROPERTY_OK;
517 /// Demuxer meta data
518 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
519 MPContext *mpctx) {
520 m_property_action_t* ka;
521 char* meta;
522 static const m_option_t key_type =
523 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
524 if (!mpctx->demuxer)
525 return M_PROPERTY_UNAVAILABLE;
527 switch(action) {
528 case M_PROPERTY_GET:
529 if(!arg) return M_PROPERTY_ERROR;
530 *(char***)arg = mpctx->demuxer->info;
531 return M_PROPERTY_OK;
532 case M_PROPERTY_KEY_ACTION:
533 if(!arg) return M_PROPERTY_ERROR;
534 ka = arg;
535 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
536 return M_PROPERTY_UNKNOWN;
537 switch(ka->action) {
538 case M_PROPERTY_GET:
539 if(!ka->arg) return M_PROPERTY_ERROR;
540 *(char**)ka->arg = meta;
541 return M_PROPERTY_OK;
542 case M_PROPERTY_GET_TYPE:
543 if(!ka->arg) return M_PROPERTY_ERROR;
544 *(m_option_t**)ka->arg = &key_type;
545 return M_PROPERTY_OK;
548 return M_PROPERTY_NOT_IMPLEMENTED;
552 ///@}
554 /// \defgroup AudioProperties Audio properties
555 /// \ingroup Properties
556 ///@{
558 /// Volume (RW)
559 static int mp_property_volume(m_option_t *prop, int action, void *arg,
560 MPContext *mpctx)
563 if (!mpctx->sh_audio)
564 return M_PROPERTY_UNAVAILABLE;
566 switch (action) {
567 case M_PROPERTY_GET:
568 if (!arg)
569 return M_PROPERTY_ERROR;
570 mixer_getbothvolume(&mpctx->mixer, arg);
571 return M_PROPERTY_OK;
572 case M_PROPERTY_PRINT:{
573 float vol;
574 if (!arg)
575 return M_PROPERTY_ERROR;
576 mixer_getbothvolume(&mpctx->mixer, &vol);
577 return m_property_float_range(prop, action, arg, &vol);
579 case M_PROPERTY_STEP_UP:
580 case M_PROPERTY_STEP_DOWN:
581 case M_PROPERTY_SET:
582 break;
583 default:
584 return M_PROPERTY_NOT_IMPLEMENTED;
587 if (mpctx->edl_muted)
588 return M_PROPERTY_DISABLED;
589 mpctx->user_muted = 0;
591 switch (action) {
592 case M_PROPERTY_SET:
593 if (!arg)
594 return M_PROPERTY_ERROR;
595 M_PROPERTY_CLAMP(prop, *(float *) arg);
596 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
597 return M_PROPERTY_OK;
598 case M_PROPERTY_STEP_UP:
599 if (arg && *(float *) arg <= 0)
600 mixer_decvolume(&mpctx->mixer);
601 else
602 mixer_incvolume(&mpctx->mixer);
603 return M_PROPERTY_OK;
604 case M_PROPERTY_STEP_DOWN:
605 if (arg && *(float *) arg <= 0)
606 mixer_incvolume(&mpctx->mixer);
607 else
608 mixer_decvolume(&mpctx->mixer);
609 return M_PROPERTY_OK;
611 return M_PROPERTY_NOT_IMPLEMENTED;
614 /// Mute (RW)
615 static int mp_property_mute(m_option_t *prop, int action, void *arg,
616 MPContext *mpctx)
619 if (!mpctx->sh_audio)
620 return M_PROPERTY_UNAVAILABLE;
622 switch (action) {
623 case M_PROPERTY_SET:
624 if (mpctx->edl_muted)
625 return M_PROPERTY_DISABLED;
626 if (!arg)
627 return M_PROPERTY_ERROR;
628 if ((!!*(int *) arg) != mpctx->mixer.muted)
629 mixer_mute(&mpctx->mixer);
630 mpctx->user_muted = mpctx->mixer.muted;
631 return M_PROPERTY_OK;
632 case M_PROPERTY_STEP_UP:
633 case M_PROPERTY_STEP_DOWN:
634 if (mpctx->edl_muted)
635 return M_PROPERTY_DISABLED;
636 mixer_mute(&mpctx->mixer);
637 mpctx->user_muted = mpctx->mixer.muted;
638 return M_PROPERTY_OK;
639 case M_PROPERTY_PRINT:
640 if (!arg)
641 return M_PROPERTY_ERROR;
642 if (mpctx->edl_muted) {
643 *(char **) arg = strdup(MSGTR_EnabledEdl);
644 return M_PROPERTY_OK;
646 default:
647 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
652 /// Audio delay (RW)
653 static int mp_property_audio_delay(m_option_t *prop, int action,
654 void *arg, MPContext *mpctx)
656 if (!(mpctx->sh_audio && mpctx->sh_video))
657 return M_PROPERTY_UNAVAILABLE;
658 switch (action) {
659 case M_PROPERTY_SET:
660 case M_PROPERTY_STEP_UP:
661 case M_PROPERTY_STEP_DOWN: {
662 int ret;
663 float delay = audio_delay;
664 ret = m_property_delay(prop, action, arg, &audio_delay);
665 if (ret != M_PROPERTY_OK)
666 return ret;
667 if (mpctx->sh_audio)
668 mpctx->delay -= audio_delay - delay;
670 return M_PROPERTY_OK;
671 default:
672 return m_property_delay(prop, action, arg, &audio_delay);
676 /// Audio codec tag (RO)
677 static int mp_property_audio_format(m_option_t *prop, int action,
678 void *arg, MPContext *mpctx)
680 if (!mpctx->sh_audio)
681 return M_PROPERTY_UNAVAILABLE;
682 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
685 /// Audio codec name (RO)
686 static int mp_property_audio_codec(m_option_t *prop, int action,
687 void *arg, MPContext *mpctx)
689 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
690 return M_PROPERTY_UNAVAILABLE;
691 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
694 /// Audio bitrate (RO)
695 static int mp_property_audio_bitrate(m_option_t *prop, int action,
696 void *arg, MPContext *mpctx)
698 if (!mpctx->sh_audio)
699 return M_PROPERTY_UNAVAILABLE;
700 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
703 /// Samplerate (RO)
704 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
705 MPContext *mpctx)
707 if (!mpctx->sh_audio)
708 return M_PROPERTY_UNAVAILABLE;
709 switch(action) {
710 case M_PROPERTY_PRINT:
711 if(!arg) return M_PROPERTY_ERROR;
712 *(char**)arg = malloc(16);
713 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
714 return M_PROPERTY_OK;
716 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
719 /// Number of channels (RO)
720 static int mp_property_channels(m_option_t *prop, int action, void *arg,
721 MPContext *mpctx)
723 if (!mpctx->sh_audio)
724 return M_PROPERTY_UNAVAILABLE;
725 switch (action) {
726 case M_PROPERTY_PRINT:
727 if (!arg)
728 return M_PROPERTY_ERROR;
729 switch (mpctx->sh_audio->channels) {
730 case 1:
731 *(char **) arg = strdup("mono");
732 break;
733 case 2:
734 *(char **) arg = strdup("stereo");
735 break;
736 default:
737 *(char **) arg = malloc(32);
738 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
740 return M_PROPERTY_OK;
742 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
745 /// Balance (RW)
746 static int mp_property_balance(m_option_t *prop, int action, void *arg,
747 MPContext *mpctx)
749 float bal;
751 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
752 return M_PROPERTY_UNAVAILABLE;
754 switch (action) {
755 case M_PROPERTY_GET:
756 if (!arg)
757 return M_PROPERTY_ERROR;
758 mixer_getbalance(&mpctx->mixer, arg);
759 return M_PROPERTY_OK;
760 case M_PROPERTY_PRINT: {
761 char** str = arg;
762 if (!arg)
763 return M_PROPERTY_ERROR;
764 mixer_getbalance(&mpctx->mixer, &bal);
765 if (bal == 0.f)
766 *str = strdup("center");
767 else if (bal == -1.f)
768 *str = strdup("left only");
769 else if (bal == 1.f)
770 *str = strdup("right only");
771 else {
772 unsigned right = (bal + 1.f) / 2.f * 100.f;
773 *str = malloc(sizeof("left xxx%, right xxx%"));
774 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
776 return M_PROPERTY_OK;
778 case M_PROPERTY_STEP_UP:
779 case M_PROPERTY_STEP_DOWN:
780 mixer_getbalance(&mpctx->mixer, &bal);
781 bal += (arg ? *(float*)arg : .1f) *
782 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
783 M_PROPERTY_CLAMP(prop, bal);
784 mixer_setbalance(&mpctx->mixer, bal);
785 return M_PROPERTY_OK;
786 case M_PROPERTY_SET:
787 if (!arg)
788 return M_PROPERTY_ERROR;
789 M_PROPERTY_CLAMP(prop, *(float*)arg);
790 mixer_setbalance(&mpctx->mixer, *(float*)arg);
791 return M_PROPERTY_OK;
793 return M_PROPERTY_NOT_IMPLEMENTED;
796 /// Selected audio id (RW)
797 static int mp_property_audio(m_option_t *prop, int action, void *arg,
798 MPContext *mpctx)
800 struct MPOpts *opts = &mpctx->opts;
801 int current_id = -1, tmp;
803 switch (action) {
804 case M_PROPERTY_GET:
805 if (!mpctx->sh_audio)
806 return M_PROPERTY_UNAVAILABLE;
807 if (!arg)
808 return M_PROPERTY_ERROR;
809 *(int *) arg = opts->audio_id;
810 return M_PROPERTY_OK;
811 case M_PROPERTY_PRINT:
812 if (!mpctx->sh_audio)
813 return M_PROPERTY_UNAVAILABLE;
814 if (!arg)
815 return M_PROPERTY_ERROR;
817 if (opts->audio_id < 0)
818 *(char **) arg = strdup(MSGTR_Disabled);
819 else {
820 char lang[40] = MSGTR_Unknown;
821 sh_audio_t* sh = mpctx->sh_audio;
822 if (sh && sh->lang)
823 av_strlcpy(lang, sh->lang, 40);
824 #ifdef CONFIG_DVDREAD
825 else if (mpctx->stream->type == STREAMTYPE_DVD) {
826 int code = dvd_lang_from_aid(mpctx->stream, opts->audio_id);
827 if (code) {
828 lang[0] = code >> 8;
829 lang[1] = code;
830 lang[2] = 0;
833 #endif
835 #ifdef CONFIG_DVDNAV
836 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
837 mp_dvdnav_lang_from_aid(mpctx->stream, opts->audio_id, lang);
838 #endif
839 *(char **) arg = malloc(64);
840 snprintf(*(char **) arg, 64, "(%d) %s", opts->audio_id, lang);
842 return M_PROPERTY_OK;
844 case M_PROPERTY_STEP_UP:
845 case M_PROPERTY_SET:
846 if (!mpctx->demuxer)
847 return M_PROPERTY_UNAVAILABLE;
848 if (action == M_PROPERTY_SET && arg)
849 tmp = *((int *) arg);
850 else
851 tmp = -1;
852 current_id = mpctx->demuxer->audio->id;
853 opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
854 if (opts->audio_id == -2
855 || (opts->audio_id > -1
856 && mpctx->demuxer->audio->id != current_id && current_id != -2))
857 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
858 if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
859 sh_audio_t *sh2;
860 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
861 if (sh2) {
862 sh2->ds = mpctx->demuxer->audio;
863 mpctx->sh_audio = sh2;
864 reinit_audio_chain(mpctx);
867 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id);
868 return M_PROPERTY_OK;
869 default:
870 return M_PROPERTY_NOT_IMPLEMENTED;
875 /// Selected video id (RW)
876 static int mp_property_video(m_option_t *prop, int action, void *arg,
877 MPContext *mpctx)
879 struct MPOpts *opts = &mpctx->opts;
880 int current_id = -1, tmp;
882 switch (action) {
883 case M_PROPERTY_GET:
884 if (!mpctx->sh_video)
885 return M_PROPERTY_UNAVAILABLE;
886 if (!arg)
887 return M_PROPERTY_ERROR;
888 *(int *) arg = opts->video_id;
889 return M_PROPERTY_OK;
890 case M_PROPERTY_PRINT:
891 if (!mpctx->sh_video)
892 return M_PROPERTY_UNAVAILABLE;
893 if (!arg)
894 return M_PROPERTY_ERROR;
896 if (opts->video_id < 0)
897 *(char **) arg = strdup(MSGTR_Disabled);
898 else {
899 char lang[40] = MSGTR_Unknown;
900 *(char **) arg = malloc(64);
901 snprintf(*(char **) arg, 64, "(%d) %s", opts->video_id, lang);
903 return M_PROPERTY_OK;
905 case M_PROPERTY_STEP_UP:
906 case M_PROPERTY_SET:
907 current_id = mpctx->demuxer->video->id;
908 if (action == M_PROPERTY_SET && arg)
909 tmp = *((int *) arg);
910 else
911 tmp = -1;
912 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
913 if (opts->video_id == -2
914 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
915 && current_id != -2))
916 uninit_player(mpctx, INITIALIZED_VCODEC |
917 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
918 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
919 sh_video_t *sh2;
920 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
921 if (sh2) {
922 sh2->ds = mpctx->demuxer->video;
923 mpctx->sh_video = sh2;
924 reinit_video_chain(mpctx);
927 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
928 return M_PROPERTY_OK;
930 default:
931 return M_PROPERTY_NOT_IMPLEMENTED;
935 static int mp_property_program(m_option_t *prop, int action, void *arg,
936 MPContext *mpctx)
938 demux_program_t prog;
940 switch (action) {
941 case M_PROPERTY_STEP_UP:
942 case M_PROPERTY_SET:
943 if (action == M_PROPERTY_SET && arg)
944 prog.progid = *((int *) arg);
945 else
946 prog.progid = -1;
947 if (demux_control
948 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
949 &prog) == DEMUXER_CTRL_NOTIMPL)
950 return M_PROPERTY_ERROR;
952 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
953 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
954 return M_PROPERTY_OK;
956 default:
957 return M_PROPERTY_NOT_IMPLEMENTED;
961 ///@}
963 /// \defgroup VideoProperties Video properties
964 /// \ingroup Properties
965 ///@{
967 /// Fullscreen state (RW)
968 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
969 MPContext *mpctx)
972 if (!mpctx->video_out)
973 return M_PROPERTY_UNAVAILABLE;
975 switch (action) {
976 case M_PROPERTY_SET:
977 if (!arg)
978 return M_PROPERTY_ERROR;
979 M_PROPERTY_CLAMP(prop, *(int *) arg);
980 if (vo_fs == !!*(int *) arg)
981 return M_PROPERTY_OK;
982 case M_PROPERTY_STEP_UP:
983 case M_PROPERTY_STEP_DOWN:
984 #ifdef CONFIG_GUI
985 if (use_gui)
986 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
987 else
988 #endif
989 if (mpctx->video_out->config_ok)
990 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
991 return M_PROPERTY_OK;
992 default:
993 return m_property_flag(prop, action, arg, &vo_fs);
997 static int mp_property_deinterlace(m_option_t *prop, int action,
998 void *arg, MPContext *mpctx)
1000 int deinterlace;
1001 vf_instance_t *vf;
1002 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1003 return M_PROPERTY_UNAVAILABLE;
1004 vf = mpctx->sh_video->vfilter;
1005 switch (action) {
1006 case M_PROPERTY_GET:
1007 if (!arg)
1008 return M_PROPERTY_ERROR;
1009 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1010 return M_PROPERTY_OK;
1011 case M_PROPERTY_SET:
1012 if (!arg)
1013 return M_PROPERTY_ERROR;
1014 M_PROPERTY_CLAMP(prop, *(int *) arg);
1015 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1016 return M_PROPERTY_OK;
1017 case M_PROPERTY_STEP_UP:
1018 case M_PROPERTY_STEP_DOWN:
1019 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1020 deinterlace = !deinterlace;
1021 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1022 return M_PROPERTY_OK;
1024 return M_PROPERTY_NOT_IMPLEMENTED;
1027 /// Panscan (RW)
1028 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1029 MPContext *mpctx)
1032 if (!mpctx->video_out
1033 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1034 return M_PROPERTY_UNAVAILABLE;
1036 switch (action) {
1037 case M_PROPERTY_SET:
1038 if (!arg)
1039 return M_PROPERTY_ERROR;
1040 M_PROPERTY_CLAMP(prop, *(float *) arg);
1041 vo_panscan = *(float *) arg;
1042 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1043 return M_PROPERTY_OK;
1044 case M_PROPERTY_STEP_UP:
1045 case M_PROPERTY_STEP_DOWN:
1046 vo_panscan += (arg ? *(float *) arg : 0.1) *
1047 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1048 if (vo_panscan > 1)
1049 vo_panscan = 1;
1050 else if (vo_panscan < 0)
1051 vo_panscan = 0;
1052 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1053 return M_PROPERTY_OK;
1054 default:
1055 return m_property_float_range(prop, action, arg, &vo_panscan);
1059 /// Helper to set vo flags.
1060 /** \ingroup PropertyImplHelper
1062 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1063 int vo_ctrl, int *vo_var, MPContext *mpctx)
1066 if (!mpctx->video_out)
1067 return M_PROPERTY_UNAVAILABLE;
1069 switch (action) {
1070 case M_PROPERTY_SET:
1071 if (!arg)
1072 return M_PROPERTY_ERROR;
1073 M_PROPERTY_CLAMP(prop, *(int *) arg);
1074 if (*vo_var == !!*(int *) arg)
1075 return M_PROPERTY_OK;
1076 case M_PROPERTY_STEP_UP:
1077 case M_PROPERTY_STEP_DOWN:
1078 if (mpctx->video_out->config_ok)
1079 vo_control(mpctx->video_out, vo_ctrl, 0);
1080 return M_PROPERTY_OK;
1081 default:
1082 return m_property_flag(prop, action, arg, vo_var);
1086 /// Window always on top (RW)
1087 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1088 MPContext *mpctx)
1090 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1091 &mpctx->opts.vo_ontop, mpctx);
1094 /// Display in the root window (RW)
1095 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1096 MPContext *mpctx)
1098 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1099 &vo_rootwin, mpctx);
1102 /// Show window borders (RW)
1103 static int mp_property_border(m_option_t *prop, int action, void *arg,
1104 MPContext *mpctx)
1106 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1107 &vo_border, mpctx);
1110 /// Framedropping state (RW)
1111 static int mp_property_framedropping(m_option_t *prop, int action,
1112 void *arg, MPContext *mpctx)
1115 if (!mpctx->sh_video)
1116 return M_PROPERTY_UNAVAILABLE;
1118 switch (action) {
1119 case M_PROPERTY_PRINT:
1120 if (!arg)
1121 return M_PROPERTY_ERROR;
1122 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1123 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1124 MSGTR_Disabled));
1125 return M_PROPERTY_OK;
1126 default:
1127 return m_property_choice(prop, action, arg, &frame_dropping);
1131 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1132 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1133 MPContext *mpctx)
1135 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1136 int r, val;
1138 if (!mpctx->sh_video)
1139 return M_PROPERTY_UNAVAILABLE;
1141 if (gamma[0] == 1000) {
1142 gamma[0] = 0;
1143 get_video_colors(mpctx->sh_video, prop->name, gamma);
1146 switch (action) {
1147 case M_PROPERTY_SET:
1148 if (!arg)
1149 return M_PROPERTY_ERROR;
1150 M_PROPERTY_CLAMP(prop, *(int *) arg);
1151 *gamma = *(int *) arg;
1152 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1153 if (r <= 0)
1154 break;
1155 return r;
1156 case M_PROPERTY_GET:
1157 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1158 if (!arg)
1159 return M_PROPERTY_ERROR;
1160 *(int *)arg = val;
1161 return M_PROPERTY_OK;
1163 break;
1164 case M_PROPERTY_STEP_UP:
1165 case M_PROPERTY_STEP_DOWN:
1166 *gamma += (arg ? *(int *) arg : 1) *
1167 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1168 M_PROPERTY_CLAMP(prop, *gamma);
1169 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1170 if (r <= 0)
1171 break;
1172 return r;
1173 default:
1174 return M_PROPERTY_NOT_IMPLEMENTED;
1177 #ifdef CONFIG_TV
1178 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1179 int l = strlen(prop->name);
1180 char tv_prop[3 + l + 1];
1181 sprintf(tv_prop, "tv_%s", prop->name);
1182 return mp_property_do(tv_prop, action, arg, mpctx);
1184 #endif
1186 return M_PROPERTY_UNAVAILABLE;
1189 /// VSync (RW)
1190 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1191 MPContext *mpctx)
1193 return m_property_flag(prop, action, arg, &vo_vsync);
1196 /// Video codec tag (RO)
1197 static int mp_property_video_format(m_option_t *prop, int action,
1198 void *arg, MPContext *mpctx)
1200 char* meta;
1201 if (!mpctx->sh_video)
1202 return M_PROPERTY_UNAVAILABLE;
1203 switch(action) {
1204 case M_PROPERTY_PRINT:
1205 if (!arg)
1206 return M_PROPERTY_ERROR;
1207 switch(mpctx->sh_video->format) {
1208 case 0x10000001:
1209 meta = strdup ("mpeg1"); break;
1210 case 0x10000002:
1211 meta = strdup ("mpeg2"); break;
1212 case 0x10000004:
1213 meta = strdup ("mpeg4"); break;
1214 case 0x10000005:
1215 meta = strdup ("h264"); break;
1216 default:
1217 if(mpctx->sh_video->format >= 0x20202020) {
1218 meta = malloc(5);
1219 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1220 } else {
1221 meta = malloc(20);
1222 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1225 *(char**)arg = meta;
1226 return M_PROPERTY_OK;
1228 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1231 /// Video codec name (RO)
1232 static int mp_property_video_codec(m_option_t *prop, int action,
1233 void *arg, MPContext *mpctx)
1235 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1236 return M_PROPERTY_UNAVAILABLE;
1237 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1241 /// Video bitrate (RO)
1242 static int mp_property_video_bitrate(m_option_t *prop, int action,
1243 void *arg, MPContext *mpctx)
1245 if (!mpctx->sh_video)
1246 return M_PROPERTY_UNAVAILABLE;
1247 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1250 /// Video display width (RO)
1251 static int mp_property_width(m_option_t *prop, int action, void *arg,
1252 MPContext *mpctx)
1254 if (!mpctx->sh_video)
1255 return M_PROPERTY_UNAVAILABLE;
1256 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1259 /// Video display height (RO)
1260 static int mp_property_height(m_option_t *prop, int action, void *arg,
1261 MPContext *mpctx)
1263 if (!mpctx->sh_video)
1264 return M_PROPERTY_UNAVAILABLE;
1265 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1268 /// Video fps (RO)
1269 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1270 MPContext *mpctx)
1272 if (!mpctx->sh_video)
1273 return M_PROPERTY_UNAVAILABLE;
1274 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1277 /// Video aspect (RO)
1278 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1279 MPContext *mpctx)
1281 if (!mpctx->sh_video)
1282 return M_PROPERTY_UNAVAILABLE;
1283 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1286 ///@}
1288 /// \defgroup SubProprties Subtitles properties
1289 /// \ingroup Properties
1290 ///@{
1292 /// Text subtitle position (RW)
1293 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1294 MPContext *mpctx)
1296 if (!mpctx->sh_video)
1297 return M_PROPERTY_UNAVAILABLE;
1299 switch (action) {
1300 case M_PROPERTY_SET:
1301 if (!arg)
1302 return M_PROPERTY_ERROR;
1303 case M_PROPERTY_STEP_UP:
1304 case M_PROPERTY_STEP_DOWN:
1305 vo_osd_changed(OSDTYPE_SUBTITLE);
1306 default:
1307 return m_property_int_range(prop, action, arg, &sub_pos);
1311 /// Selected subtitles (RW)
1312 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1313 MPContext *mpctx)
1315 struct MPOpts *opts = &mpctx->opts;
1316 demux_stream_t *const d_sub = mpctx->d_sub;
1317 const int global_sub_size = mpctx->global_sub_size;
1318 int source = -1, reset_spu = 0;
1319 char *sub_name;
1321 if (global_sub_size <= 0)
1322 return M_PROPERTY_UNAVAILABLE;
1324 switch (action) {
1325 case M_PROPERTY_GET:
1326 if (!arg)
1327 return M_PROPERTY_ERROR;
1328 *(int *) arg = mpctx->global_sub_pos;
1329 return M_PROPERTY_OK;
1330 case M_PROPERTY_PRINT:
1331 if (!arg)
1332 return M_PROPERTY_ERROR;
1333 *(char **) arg = malloc(64);
1334 (*(char **) arg)[63] = 0;
1335 sub_name = 0;
1336 if (subdata)
1337 sub_name = subdata->filename;
1338 #ifdef CONFIG_ASS
1339 if (ass_track && ass_track->name)
1340 sub_name = ass_track->name;
1341 #endif
1342 if (sub_name) {
1343 char *tmp, *tmp2;
1344 tmp = sub_name;
1345 if ((tmp2 = strrchr(tmp, '/')))
1346 tmp = tmp2 + 1;
1348 snprintf(*(char **) arg, 63, "(%d) %s%s",
1349 mpctx->set_of_sub_pos + 1,
1350 strlen(tmp) < 20 ? "" : "...",
1351 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1352 return M_PROPERTY_OK;
1354 #ifdef CONFIG_DVDNAV
1355 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1356 if (vo_spudec && opts->sub_id >= 0) {
1357 unsigned char lang[3];
1358 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1359 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1360 return M_PROPERTY_OK;
1364 #endif
1366 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1367 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1368 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1369 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1370 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1371 if (!lang) lang = MSGTR_Unknown;
1372 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1373 return M_PROPERTY_OK;
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 CONFIG_DVDREAD
1384 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1385 && opts->sub_id >= 0) {
1386 char lang[3];
1387 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1388 lang[0] = code >> 8;
1389 lang[1] = code;
1390 lang[2] = 0;
1391 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1392 return M_PROPERTY_OK;
1394 #endif
1395 if (opts->sub_id >= 0) {
1396 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_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 opts->sub_id = -1;
1441 if (d_sub) {
1442 if (d_sub->id > -2)
1443 reset_spu = 1;
1444 d_sub->id = -2;
1446 #ifdef CONFIG_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 CONFIG_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 opts->sub_id =
1466 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1467 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1468 int i = 0;
1469 // default: assume 1:1 mapping of sid and stream id
1470 d_sub->id = opts->sub_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 == opts->sub_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(mpctx);
1485 #ifdef CONFIG_ASS
1486 else if (ass_enabled)
1487 ass_track = sh->ass_track;
1488 #endif
1489 } else {
1490 d_sub->id = -2;
1491 d_sub->sh = NULL;
1495 #ifdef CONFIG_DVDREAD
1496 if (vo_spudec
1497 && (mpctx->stream->type == STREAMTYPE_DVD
1498 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1499 && opts->sub_id < 0 && reset_spu) {
1500 opts->sub_id = -2;
1501 d_sub->id = opts->sub_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 CONFIG_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 CONFIG_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 CONFIG_ASS
1800 if (ass_enabled) {
1801 ass_font_scale = *(float *) arg;
1802 ass_force_reload = 1;
1804 #endif
1805 text_font_scale_factor = *(float *) arg;
1806 force_load_font = 1;
1807 return M_PROPERTY_OK;
1808 case M_PROPERTY_STEP_UP:
1809 case M_PROPERTY_STEP_DOWN:
1810 #ifdef CONFIG_ASS
1811 if (ass_enabled) {
1812 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1813 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1814 M_PROPERTY_CLAMP(prop, ass_font_scale);
1815 ass_force_reload = 1;
1817 #endif
1818 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1819 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1820 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1821 force_load_font = 1;
1822 return M_PROPERTY_OK;
1823 default:
1824 #ifdef CONFIG_ASS
1825 if (ass_enabled)
1826 return m_property_float_ro(prop, action, arg, ass_font_scale);
1827 else
1828 #endif
1829 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1832 #endif
1834 ///@}
1836 /// \defgroup TVProperties TV properties
1837 /// \ingroup Properties
1838 ///@{
1840 #ifdef CONFIG_TV
1842 /// TV color settings (RW)
1843 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1844 MPContext *mpctx)
1846 int r, val;
1847 tvi_handle_t *tvh = mpctx->demuxer->priv;
1848 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1849 return M_PROPERTY_UNAVAILABLE;
1851 switch (action) {
1852 case M_PROPERTY_SET:
1853 if (!arg)
1854 return M_PROPERTY_ERROR;
1855 M_PROPERTY_CLAMP(prop, *(int *) arg);
1856 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1857 case M_PROPERTY_GET:
1858 return tv_get_color_options(tvh, (int) prop->priv, arg);
1859 case M_PROPERTY_STEP_UP:
1860 case M_PROPERTY_STEP_DOWN:
1861 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1862 if (!r)
1863 return M_PROPERTY_ERROR;
1864 val += (arg ? *(int *) arg : 1) *
1865 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1866 M_PROPERTY_CLAMP(prop, val);
1867 return tv_set_color_options(tvh, (int) prop->priv, val);
1869 return M_PROPERTY_ERROR;
1871 return M_PROPERTY_NOT_IMPLEMENTED;
1874 #endif
1876 #ifdef CONFIG_TV_TELETEXT
1877 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1878 MPContext *mpctx)
1880 int val,result;
1881 int base_ioctl=(int)prop->priv;
1883 for teletext's GET,SET,STEP ioctls this is not 0
1884 SET is GET+1
1885 STEP is GET+2
1887 tvi_handle_t *tvh = mpctx->demuxer->priv;
1888 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1889 return M_PROPERTY_UNAVAILABLE;
1890 if(!base_ioctl)
1891 return M_PROPERTY_ERROR;
1893 switch (action) {
1894 case M_PROPERTY_GET:
1895 if (!arg)
1896 return M_PROPERTY_ERROR;
1897 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1898 break;
1899 case M_PROPERTY_SET:
1900 if (!arg)
1901 return M_PROPERTY_ERROR;
1902 M_PROPERTY_CLAMP(prop, *(int *) arg);
1903 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1904 break;
1905 case M_PROPERTY_STEP_UP:
1906 case M_PROPERTY_STEP_DOWN:
1907 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1908 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1909 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1910 break;
1911 default:
1912 return M_PROPERTY_NOT_IMPLEMENTED;
1915 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1918 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
1919 MPContext *mpctx)
1921 tvi_handle_t *tvh = mpctx->demuxer->priv;
1922 int result;
1923 int val;
1925 //with tvh==NULL will fail too
1926 result=mp_property_teletext_common(prop,action,arg,mpctx);
1927 if(result!=M_PROPERTY_OK)
1928 return result;
1930 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1931 mp_input_set_section(mpctx->input, "teletext");
1932 else
1933 mp_input_set_section(mpctx->input, "tv");
1934 return M_PROPERTY_OK;
1937 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
1938 MPContext *mpctx)
1940 tvi_handle_t *tvh = mpctx->demuxer->priv;
1941 int result;
1942 int val;
1943 switch(action){
1944 case M_PROPERTY_STEP_UP:
1945 case M_PROPERTY_STEP_DOWN:
1946 //This should be handled separately
1947 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1948 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1949 break;
1950 default:
1951 result=mp_property_teletext_common(prop,action,arg,mpctx);
1953 return result;
1957 #endif /* CONFIG_TV_TELETEXT */
1959 ///@}
1961 /// All properties available in MPlayer.
1962 /** \ingroup Properties
1964 static const m_option_t mp_properties[] = {
1965 // General
1966 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1967 M_OPT_RANGE, 0, 3, NULL },
1968 { "loop", mp_property_loop, CONF_TYPE_INT,
1969 M_OPT_MIN, -1, 0, NULL },
1970 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1971 M_OPT_RANGE, 0.01, 100.0, NULL },
1972 { "filename", mp_property_filename, CONF_TYPE_STRING,
1973 0, 0, 0, NULL },
1974 { "path", mp_property_path, CONF_TYPE_STRING,
1975 0, 0, 0, NULL },
1976 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1977 0, 0, 0, NULL },
1978 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1979 M_OPT_MIN, 0, 0, NULL },
1980 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1981 M_OPT_MIN, 0, 0, NULL },
1982 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1983 M_OPT_MIN, 0, 0, NULL },
1984 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1985 M_OPT_MIN, 0, 0, NULL },
1986 { "length", mp_property_length, CONF_TYPE_TIME,
1987 M_OPT_MIN, 0, 0, NULL },
1988 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1989 M_OPT_RANGE, 0, 100, NULL },
1990 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1991 M_OPT_MIN, 0, 0, NULL },
1992 { "chapter", mp_property_chapter, CONF_TYPE_INT,
1993 M_OPT_MIN, 1, 0, NULL },
1994 { "angle", mp_property_angle, CONF_TYPE_INT,
1995 CONF_RANGE, -2, 10, NULL },
1996 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
1997 0, 0, 0, NULL },
1999 // Audio
2000 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2001 M_OPT_RANGE, 0, 100, NULL },
2002 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2003 M_OPT_RANGE, 0, 1, NULL },
2004 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2005 M_OPT_RANGE, -100, 100, NULL },
2006 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2007 0, 0, 0, NULL },
2008 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2009 0, 0, 0, NULL },
2010 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2011 0, 0, 0, NULL },
2012 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2013 0, 0, 0, NULL },
2014 { "channels", mp_property_channels, CONF_TYPE_INT,
2015 0, 0, 0, NULL },
2016 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2017 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
2018 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2019 M_OPT_RANGE, -1, 1, NULL },
2021 // Video
2022 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2023 M_OPT_RANGE, 0, 1, NULL },
2024 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2025 M_OPT_RANGE, 0, 1, NULL },
2026 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2027 M_OPT_RANGE, 0, 1, NULL },
2028 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2029 M_OPT_RANGE, 0, 1, NULL },
2030 { "border", mp_property_border, CONF_TYPE_FLAG,
2031 M_OPT_RANGE, 0, 1, NULL },
2032 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2033 M_OPT_RANGE, 0, 2, NULL },
2034 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2035 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2036 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2037 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2038 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2039 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2040 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2041 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2042 { "hue", mp_property_gamma, CONF_TYPE_INT,
2043 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2044 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2045 M_OPT_RANGE, 0, 1, NULL },
2046 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2047 M_OPT_RANGE, 0, 1, NULL },
2048 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2049 0, 0, 0, NULL },
2050 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2051 0, 0, 0, NULL },
2052 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2053 0, 0, 0, NULL },
2054 { "width", mp_property_width, CONF_TYPE_INT,
2055 0, 0, 0, NULL },
2056 { "height", mp_property_height, CONF_TYPE_INT,
2057 0, 0, 0, NULL },
2058 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2059 0, 0, 0, NULL },
2060 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2061 0, 0, 0, NULL },
2062 { "switch_video", mp_property_video, CONF_TYPE_INT,
2063 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
2064 { "switch_program", mp_property_program, CONF_TYPE_INT,
2065 CONF_RANGE, -1, 65535, NULL },
2067 // Subs
2068 { "sub", mp_property_sub, CONF_TYPE_INT,
2069 M_OPT_MIN, -1, 0, NULL },
2070 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2071 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2072 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2073 M_OPT_MIN, -1, 0, NULL },
2074 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2075 M_OPT_MIN, -1, 0, NULL },
2076 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2077 M_OPT_MIN, -1, 0, NULL },
2078 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2079 0, 0, 0, NULL },
2080 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2081 M_OPT_RANGE, 0, 100, NULL },
2082 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2083 M_OPT_RANGE, 0, 2, NULL },
2084 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2085 M_OPT_RANGE, 0, 1, NULL },
2086 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2087 M_OPT_RANGE, 0, 1, NULL },
2088 #ifdef CONFIG_FREETYPE
2089 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2090 M_OPT_RANGE, 0, 100, NULL },
2091 #endif
2092 #ifdef CONFIG_ASS
2093 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2094 M_OPT_RANGE, 0, 1, NULL },
2095 #endif
2097 #ifdef CONFIG_TV
2098 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2099 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2100 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2101 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2102 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2103 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2104 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2105 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2106 #endif
2108 #ifdef CONFIG_TV_TELETEXT
2109 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2110 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2111 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2112 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2113 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2114 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2115 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2116 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2117 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2118 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2119 #endif
2121 { NULL, NULL, NULL, 0, 0, 0, NULL }
2125 int mp_property_do(const char *name, int action, void *val, void *ctx)
2127 return m_property_do(mp_properties, name, action, val, ctx);
2130 char* mp_property_print(const char *name, void* ctx)
2132 char* ret = NULL;
2133 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2134 return NULL;
2135 return ret;
2138 char *property_expand_string(MPContext *mpctx, char *str)
2140 return m_properties_expand_string(mp_properties, str, mpctx);
2143 void property_print_help(void)
2145 m_properties_print_help_list(mp_properties);
2149 ///@}
2150 // Properties group
2154 * \defgroup Command2Property Command to property bridge
2156 * It is used to handle most commands that just set a property
2157 * and optionally display something on the OSD.
2158 * Two kinds of commands are handled: adjust or toggle.
2160 * Adjust commands take 1 or 2 parameters: <value> <abs>
2161 * If <abs> is non-zero the property is set to the given value
2162 * otherwise it is adjusted.
2164 * Toggle commands take 0 or 1 parameters. With no parameter
2165 * or a value less than the property minimum it just steps the
2166 * property to its next value. Otherwise it sets it to the given
2167 * value.
2172 /// List of the commands that can be handled by setting a property.
2173 static struct {
2174 /// property name
2175 const char *name;
2176 /// cmd id
2177 int cmd;
2178 /// set/adjust or toggle command
2179 int toggle;
2180 /// progressbar type
2181 int osd_progbar;
2182 /// osd msg id if it must be shared
2183 int osd_id;
2184 /// osd msg template
2185 const char *osd_msg;
2186 } set_prop_cmd[] = {
2187 // general
2188 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2189 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2190 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2191 // audio
2192 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2193 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2194 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2195 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2196 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2197 // video
2198 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2199 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2200 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2201 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2202 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2203 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2204 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2205 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2206 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2207 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2208 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2209 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2210 // subs
2211 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2212 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2213 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2214 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2215 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2216 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2217 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2218 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2219 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2220 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2221 #ifdef CONFIG_FREETYPE
2222 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2223 #endif
2224 #ifdef CONFIG_ASS
2225 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2226 #endif
2227 #ifdef CONFIG_TV
2228 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2229 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2230 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2231 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2232 #endif
2233 { NULL, 0, 0, 0, -1, NULL }
2237 /// Handle commands that set a property.
2238 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2240 int i, r;
2241 m_option_t* prop;
2242 const char *pname;
2244 // look for the command
2245 for (i = 0; set_prop_cmd[i].name; i++)
2246 if (set_prop_cmd[i].cmd == cmd->id)
2247 break;
2248 if (!(pname = set_prop_cmd[i].name))
2249 return 0;
2251 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2252 return 0;
2254 // toggle command
2255 if (set_prop_cmd[i].toggle) {
2256 // set to value
2257 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2258 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2259 else
2260 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2261 } else if (cmd->args[1].v.i) //set
2262 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2263 else // adjust
2264 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2266 if (r <= 0)
2267 return 1;
2269 if (set_prop_cmd[i].osd_progbar) {
2270 if (prop->type == CONF_TYPE_INT) {
2271 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2272 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2273 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2274 } else if (prop->type == CONF_TYPE_FLOAT) {
2275 float f;
2276 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2277 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2278 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2279 } else
2280 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2281 "Property use an unsupported type.\n");
2282 return 1;
2285 if (set_prop_cmd[i].osd_msg) {
2286 char *val = mp_property_print(pname, mpctx);
2287 if (val) {
2288 set_osd_msg(set_prop_cmd[i].osd_id >=
2289 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2290 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2291 free(val);
2294 return 1;
2297 #ifdef CONFIG_DVDNAV
2298 static const struct {
2299 const char *name;
2300 const mp_command_type cmd;
2301 } mp_dvdnav_bindings[] = {
2302 { "up", MP_CMD_DVDNAV_UP },
2303 { "down", MP_CMD_DVDNAV_DOWN },
2304 { "left", MP_CMD_DVDNAV_LEFT },
2305 { "right", MP_CMD_DVDNAV_RIGHT },
2306 { "menu", MP_CMD_DVDNAV_MENU },
2307 { "select", MP_CMD_DVDNAV_SELECT },
2308 { "prev", MP_CMD_DVDNAV_PREVMENU },
2309 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2312 * keep old dvdnav sub-command options for a while in order not to
2313 * break slave-mode API too suddenly.
2315 { "1", MP_CMD_DVDNAV_UP },
2316 { "2", MP_CMD_DVDNAV_DOWN },
2317 { "3", MP_CMD_DVDNAV_LEFT },
2318 { "4", MP_CMD_DVDNAV_RIGHT },
2319 { "5", MP_CMD_DVDNAV_MENU },
2320 { "6", MP_CMD_DVDNAV_SELECT },
2321 { "7", MP_CMD_DVDNAV_PREVMENU },
2322 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2323 { NULL, 0 }
2325 #endif
2327 int run_command(MPContext *mpctx, mp_cmd_t *cmd)
2329 struct MPOpts *opts = &mpctx->opts;
2330 sh_audio_t * const sh_audio = mpctx->sh_audio;
2331 sh_video_t * const sh_video = mpctx->sh_video;
2332 int brk_cmd = 0;
2333 if (!set_property_command(mpctx, cmd))
2334 switch (cmd->id) {
2335 case MP_CMD_SEEK:{
2336 float v;
2337 int abs;
2338 if (sh_video)
2339 mpctx->osd_show_percentage = sh_video->fps;
2340 v = cmd->args[0].v.f;
2341 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2342 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2343 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2344 if (sh_video)
2345 mpctx->osd_function =
2346 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2347 mpctx->rel_seek_secs = v;
2348 } else if (abs) { /* Absolute seek by percentage */
2349 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2350 if (sh_video)
2351 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2352 mpctx->rel_seek_secs = v / 100.0;
2353 } else {
2354 mpctx->rel_seek_secs += v;
2355 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2357 brk_cmd = 1;
2359 break;
2361 case MP_CMD_SET_PROPERTY:{
2362 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2363 cmd->args[1].v.s, mpctx);
2364 if (r == M_PROPERTY_UNKNOWN)
2365 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2366 "Unknown property: '%s'\n", cmd->args[0].v.s);
2367 else if (r <= 0)
2368 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2369 "Failed to set property '%s' to '%s'.\n",
2370 cmd->args[0].v.s, cmd->args[1].v.s);
2372 break;
2374 case MP_CMD_STEP_PROPERTY:{
2375 void* arg = NULL;
2376 int r,i;
2377 double d;
2378 off_t o;
2379 if (cmd->args[1].v.f) {
2380 m_option_t* prop;
2381 if((r = mp_property_do(cmd->args[0].v.s,
2382 M_PROPERTY_GET_TYPE,
2383 &prop, mpctx)) <= 0)
2384 goto step_prop_err;
2385 if(prop->type == CONF_TYPE_INT ||
2386 prop->type == CONF_TYPE_FLAG)
2387 i = cmd->args[1].v.f, arg = &i;
2388 else if(prop->type == CONF_TYPE_FLOAT)
2389 arg = &cmd->args[1].v.f;
2390 else if(prop->type == CONF_TYPE_DOUBLE ||
2391 prop->type == CONF_TYPE_TIME)
2392 d = cmd->args[1].v.f, arg = &d;
2393 else if(prop->type == CONF_TYPE_POSITION)
2394 o = cmd->args[1].v.f, arg = &o;
2395 else
2396 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2397 "Ignoring step size stepping property '%s'.\n",
2398 cmd->args[0].v.s);
2400 r = mp_property_do(cmd->args[0].v.s,
2401 cmd->args[2].v.i < 0 ?
2402 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2403 arg, mpctx);
2404 step_prop_err:
2405 if (r == M_PROPERTY_UNKNOWN)
2406 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2407 "Unknown property: '%s'\n", cmd->args[0].v.s);
2408 else if (r <= 0)
2409 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2410 "Failed to increment property '%s' by %f.\n",
2411 cmd->args[0].v.s, cmd->args[1].v.f);
2413 break;
2415 case MP_CMD_GET_PROPERTY:{
2416 char *tmp;
2417 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2418 &tmp, mpctx) <= 0) {
2419 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2420 "Failed to get value of property '%s'.\n",
2421 cmd->args[0].v.s);
2422 break;
2424 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2425 cmd->args[0].v.s, tmp);
2426 free(tmp);
2428 break;
2430 case MP_CMD_EDL_MARK:
2431 if (edl_fd) {
2432 float v = sh_video ? sh_video->pts :
2433 playing_audio_pts(mpctx);
2434 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2435 mpctx->begin_skip = v;
2436 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2437 } else {
2438 if (mpctx->begin_skip > v)
2439 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2440 else {
2441 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2442 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2444 mpctx->begin_skip = MP_NOPTS_VALUE;
2447 break;
2449 case MP_CMD_SWITCH_RATIO:
2450 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2451 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2452 else
2453 opts->movie_aspect = cmd->args[0].v.f;
2454 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2455 break;
2457 case MP_CMD_SPEED_INCR:{
2458 float v = cmd->args[0].v.f;
2459 opts->playback_speed += v;
2460 build_afilter_chain(mpctx, sh_audio, &ao_data);
2461 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2462 opts->playback_speed);
2463 } break;
2465 case MP_CMD_SPEED_MULT:{
2466 float v = cmd->args[0].v.f;
2467 opts->playback_speed *= v;
2468 build_afilter_chain(mpctx, sh_audio, &ao_data);
2469 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2470 opts->playback_speed);
2471 } break;
2473 case MP_CMD_SPEED_SET:{
2474 float v = cmd->args[0].v.f;
2475 opts->playback_speed = v;
2476 build_afilter_chain(mpctx, sh_audio, &ao_data);
2477 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2478 opts->playback_speed);
2479 } break;
2481 case MP_CMD_FRAME_STEP:
2482 case MP_CMD_PAUSE:
2483 cmd->pausing = 1;
2484 brk_cmd = 1;
2485 break;
2487 case MP_CMD_FILE_FILTER:
2488 file_filter = cmd->args[0].v.i;
2489 break;
2491 case MP_CMD_QUIT:
2492 exit_player_with_rc(mpctx, MSGTR_Exit_quit,
2493 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2495 case MP_CMD_PLAY_TREE_STEP:{
2496 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2497 int force = cmd->args[1].v.i;
2499 #ifdef CONFIG_GUI
2500 if (use_gui) {
2501 int i = 0;
2502 if (n > 0)
2503 for (i = 0; i < n; i++)
2504 mplNext();
2505 else
2506 for (i = 0; i < -1 * n; i++)
2507 mplPrev();
2508 } else
2509 #endif
2511 if (!force && mpctx->playtree_iter) {
2512 play_tree_iter_t *i =
2513 play_tree_iter_new_copy(mpctx->playtree_iter);
2514 if (play_tree_iter_step(i, n, 0) ==
2515 PLAY_TREE_ITER_ENTRY)
2516 mpctx->eof =
2517 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2518 play_tree_iter_free(i);
2519 } else
2520 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2521 if (mpctx->eof)
2522 mpctx->play_tree_step = n;
2523 brk_cmd = 1;
2526 break;
2528 case MP_CMD_PLAY_TREE_UP_STEP:{
2529 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2530 int force = cmd->args[1].v.i;
2532 if (!force && mpctx->playtree_iter) {
2533 play_tree_iter_t *i =
2534 play_tree_iter_new_copy(mpctx->playtree_iter);
2535 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2536 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2537 play_tree_iter_free(i);
2538 } else
2539 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2540 brk_cmd = 1;
2542 break;
2544 case MP_CMD_PLAY_ALT_SRC_STEP:
2545 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2546 int v = cmd->args[0].v.i;
2547 if (v > 0
2548 && mpctx->playtree_iter->file <
2549 mpctx->playtree_iter->num_files)
2550 mpctx->eof = PT_NEXT_SRC;
2551 else if (v < 0 && mpctx->playtree_iter->file > 1)
2552 mpctx->eof = PT_PREV_SRC;
2554 brk_cmd = 1;
2555 break;
2557 case MP_CMD_SUB_STEP:
2558 if (sh_video) {
2559 int movement = cmd->args[0].v.i;
2560 step_sub(subdata, sh_video->pts, movement);
2561 #ifdef CONFIG_ASS
2562 if (ass_track)
2563 sub_delay +=
2564 ass_step_sub(ass_track,
2565 (sh_video->pts +
2566 sub_delay) * 1000 + .5, movement) / 1000.;
2567 #endif
2568 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2569 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2571 break;
2573 case MP_CMD_SUB_LOG:
2574 log_sub(mpctx);
2575 break;
2577 case MP_CMD_OSD:{
2578 int v = cmd->args[0].v.i;
2579 int max = (term_osd
2580 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2581 if (osd_level > max)
2582 osd_level = max;
2583 if (v < 0)
2584 osd_level = (osd_level + 1) % (max + 1);
2585 else
2586 osd_level = v > max ? max : v;
2587 /* Show OSD state when disabled, but not when an explicit
2588 argument is given to the OSD command, i.e. in slave mode. */
2589 if (v == -1 && osd_level <= 1)
2590 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2591 MSGTR_OSDosd,
2592 osd_level ? MSGTR_OSDenabled :
2593 MSGTR_OSDdisabled);
2594 else
2595 rm_osd_msg(OSD_MSG_OSD_STATUS);
2597 break;
2599 case MP_CMD_OSD_SHOW_TEXT:
2600 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2601 (cmd->args[1].v.i <
2602 0 ? osd_duration : cmd->args[1].v.i),
2603 "%-.63s", cmd->args[0].v.s);
2604 break;
2606 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2607 char *txt = m_properties_expand_string(mp_properties,
2608 cmd->args[0].v.s,
2609 mpctx);
2610 /* if no argument supplied take default osd_duration, else <arg> ms. */
2611 if (txt) {
2612 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2613 (cmd->args[1].v.i <
2614 0 ? osd_duration : cmd->args[1].v.i),
2615 "%-.63s", txt);
2616 free(txt);
2619 break;
2621 case MP_CMD_LOADFILE:{
2622 play_tree_t *e = play_tree_new();
2623 play_tree_add_file(e, cmd->args[0].v.s);
2625 if (cmd->args[1].v.i) // append
2626 play_tree_append_entry(mpctx->playtree, e);
2627 else {
2628 // Go back to the starting point.
2629 while (play_tree_iter_up_step
2630 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2631 /* NOP */ ;
2632 play_tree_free_list(mpctx->playtree->child, 1);
2633 play_tree_set_child(mpctx->playtree, e);
2634 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2635 mpctx->eof = PT_NEXT_SRC;
2637 brk_cmd = 1;
2639 break;
2641 case MP_CMD_LOADLIST:{
2642 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2643 if (!e)
2644 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2645 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2646 else {
2647 if (cmd->args[1].v.i) // append
2648 play_tree_append_entry(mpctx->playtree, e);
2649 else {
2650 // Go back to the starting point.
2651 while (play_tree_iter_up_step
2652 (mpctx->playtree_iter, 0, 1)
2653 != PLAY_TREE_ITER_END)
2654 /* NOP */ ;
2655 play_tree_free_list(mpctx->playtree->child, 1);
2656 play_tree_set_child(mpctx->playtree, e);
2657 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2658 mpctx->eof = PT_NEXT_SRC;
2661 brk_cmd = 1;
2663 break;
2665 case MP_CMD_STOP:
2666 // Go back to the starting point.
2667 while (play_tree_iter_up_step
2668 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2669 /* NOP */ ;
2670 mpctx->eof = PT_STOP;
2671 brk_cmd = 1;
2672 break;
2674 #ifdef CONFIG_RADIO
2675 case MP_CMD_RADIO_STEP_CHANNEL:
2676 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2677 int v = cmd->args[0].v.i;
2678 if (v > 0)
2679 radio_step_channel(mpctx->demuxer->stream,
2680 RADIO_CHANNEL_HIGHER);
2681 else
2682 radio_step_channel(mpctx->demuxer->stream,
2683 RADIO_CHANNEL_LOWER);
2684 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2685 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2686 MSGTR_OSDChannel,
2687 radio_get_channel_name(mpctx->demuxer->stream));
2690 break;
2692 case MP_CMD_RADIO_SET_CHANNEL:
2693 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2694 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2695 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2696 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2697 MSGTR_OSDChannel,
2698 radio_get_channel_name(mpctx->demuxer->stream));
2701 break;
2703 case MP_CMD_RADIO_SET_FREQ:
2704 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2705 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2706 break;
2708 case MP_CMD_RADIO_STEP_FREQ:
2709 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2710 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2711 break;
2712 #endif
2714 #ifdef CONFIG_TV
2715 case MP_CMD_TV_START_SCAN:
2716 if (mpctx->file_format == DEMUXER_TYPE_TV)
2717 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2718 break;
2719 case MP_CMD_TV_SET_FREQ:
2720 if (mpctx->file_format == DEMUXER_TYPE_TV)
2721 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2722 cmd->args[0].v.f * 16.0);
2723 #ifdef CONFIG_PVR
2724 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2725 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2726 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2727 pvr_get_current_channelname (mpctx->stream),
2728 pvr_get_current_stationname (mpctx->stream));
2730 #endif /* CONFIG_PVR */
2731 break;
2733 case MP_CMD_TV_STEP_FREQ:
2734 if (mpctx->file_format == DEMUXER_TYPE_TV)
2735 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2736 cmd->args[0].v.f * 16.0);
2737 #ifdef CONFIG_PVR
2738 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2739 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2740 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2741 pvr_get_current_channelname (mpctx->stream),
2742 pvr_get_current_frequency (mpctx->stream));
2744 #endif /* CONFIG_PVR */
2745 break;
2747 case MP_CMD_TV_SET_NORM:
2748 if (mpctx->file_format == DEMUXER_TYPE_TV)
2749 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2750 cmd->args[0].v.s);
2751 break;
2753 case MP_CMD_TV_STEP_CHANNEL:{
2754 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2755 int v = cmd->args[0].v.i;
2756 if (v > 0) {
2757 tv_step_channel((tvi_handle_t *) (mpctx->
2758 demuxer->priv),
2759 TV_CHANNEL_HIGHER);
2760 } else {
2761 tv_step_channel((tvi_handle_t *) (mpctx->
2762 demuxer->priv),
2763 TV_CHANNEL_LOWER);
2765 if (tv_channel_list) {
2766 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2767 MSGTR_OSDChannel, tv_channel_current->name);
2768 //vo_osd_changed(OSDTYPE_SUBTITLE);
2771 #ifdef CONFIG_PVR
2772 else if (mpctx->stream &&
2773 mpctx->stream->type == STREAMTYPE_PVR) {
2774 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2775 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2776 pvr_get_current_channelname (mpctx->stream),
2777 pvr_get_current_stationname (mpctx->stream));
2779 #endif /* CONFIG_PVR */
2781 #ifdef CONFIG_DVBIN
2782 if (mpctx->stream->type == STREAMTYPE_DVB) {
2783 int dir;
2784 int v = cmd->args[0].v.i;
2786 mpctx->last_dvb_step = v;
2787 if (v > 0)
2788 dir = DVB_CHANNEL_HIGHER;
2789 else
2790 dir = DVB_CHANNEL_LOWER;
2793 if (dvb_step_channel(mpctx->stream, dir))
2794 mpctx->eof = mpctx->dvbin_reopen = 1;
2796 #endif /* CONFIG_DVBIN */
2797 break;
2799 case MP_CMD_TV_SET_CHANNEL:
2800 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2801 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2802 cmd->args[0].v.s);
2803 if (tv_channel_list) {
2804 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2805 MSGTR_OSDChannel, tv_channel_current->name);
2806 //vo_osd_changed(OSDTYPE_SUBTITLE);
2809 #ifdef CONFIG_PVR
2810 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2811 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2812 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2813 pvr_get_current_channelname (mpctx->stream),
2814 pvr_get_current_stationname (mpctx->stream));
2816 #endif /* CONFIG_PVR */
2817 break;
2819 #ifdef CONFIG_DVBIN
2820 case MP_CMD_DVB_SET_CHANNEL:
2821 if (mpctx->stream->type == STREAMTYPE_DVB) {
2822 mpctx->last_dvb_step = 1;
2824 if (dvb_set_channel
2825 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2826 mpctx->eof = mpctx->dvbin_reopen = 1;
2828 break;
2829 #endif /* CONFIG_DVBIN */
2831 case MP_CMD_TV_LAST_CHANNEL:
2832 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2833 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2834 if (tv_channel_list) {
2835 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2836 MSGTR_OSDChannel, tv_channel_current->name);
2837 //vo_osd_changed(OSDTYPE_SUBTITLE);
2840 #ifdef CONFIG_PVR
2841 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2842 pvr_set_lastchannel (mpctx->stream);
2843 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2844 pvr_get_current_channelname (mpctx->stream),
2845 pvr_get_current_stationname (mpctx->stream));
2847 #endif /* CONFIG_PVR */
2848 break;
2850 case MP_CMD_TV_STEP_NORM:
2851 if (mpctx->file_format == DEMUXER_TYPE_TV)
2852 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2853 break;
2855 case MP_CMD_TV_STEP_CHANNEL_LIST:
2856 if (mpctx->file_format == DEMUXER_TYPE_TV)
2857 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2858 break;
2859 #ifdef CONFIG_TV_TELETEXT
2860 case MP_CMD_TV_TELETEXT_ADD_DEC:
2862 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2863 if (mpctx->file_format == DEMUXER_TYPE_TV)
2864 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2865 break;
2867 case MP_CMD_TV_TELETEXT_GO_LINK:
2869 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2870 if (mpctx->file_format == DEMUXER_TYPE_TV)
2871 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2872 break;
2874 #endif /* CONFIG_TV_TELETEXT */
2875 #endif /* CONFIG_TV */
2877 case MP_CMD_SUB_LOAD:
2878 if (sh_video) {
2879 int n = mpctx->set_of_sub_size;
2880 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
2881 if (n != mpctx->set_of_sub_size) {
2882 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2883 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2884 mpctx->global_sub_size;
2885 ++mpctx->global_sub_size;
2888 break;
2890 case MP_CMD_SUB_REMOVE:
2891 if (sh_video) {
2892 int v = cmd->args[0].v.i;
2893 sub_data *subd;
2894 if (v < 0) {
2895 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2896 subd = mpctx->set_of_subtitles[v];
2897 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2898 MSGTR_RemovedSubtitleFile, v + 1,
2899 filename_recode(subd->filename));
2900 sub_free(subd);
2901 mpctx->set_of_subtitles[v] = NULL;
2903 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2904 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2905 mpctx->set_of_sub_size = 0;
2906 if (mpctx->set_of_sub_pos >= 0) {
2907 mpctx->global_sub_pos = -2;
2908 subdata = NULL;
2909 mp_input_queue_cmd(mpctx->input,
2910 mp_input_parse_cmd("sub_select"));
2912 } else if (v < mpctx->set_of_sub_size) {
2913 subd = mpctx->set_of_subtitles[v];
2914 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2915 MSGTR_RemovedSubtitleFile, v + 1,
2916 filename_recode(subd->filename));
2917 sub_free(subd);
2918 if (mpctx->set_of_sub_pos == v) {
2919 mpctx->global_sub_pos = -2;
2920 subdata = NULL;
2921 mp_input_queue_cmd(mpctx->input,
2922 mp_input_parse_cmd("sub_select"));
2923 } else if (mpctx->set_of_sub_pos > v) {
2924 --mpctx->set_of_sub_pos;
2925 --mpctx->global_sub_pos;
2927 while (++v < mpctx->set_of_sub_size)
2928 mpctx->set_of_subtitles[v - 1] =
2929 mpctx->set_of_subtitles[v];
2930 --mpctx->set_of_sub_size;
2931 --mpctx->global_sub_size;
2932 if (mpctx->set_of_sub_size <= 0)
2933 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2934 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2937 break;
2939 case MP_CMD_GET_SUB_VISIBILITY:
2940 if (sh_video) {
2941 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2942 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2944 break;
2946 case MP_CMD_SCREENSHOT:
2947 if (mpctx->video_out && mpctx->video_out->config_ok) {
2948 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2949 if (CONTROL_OK !=
2950 ((vf_instance_t *) sh_video->vfilter)->
2951 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2952 &cmd->args[0].v.i))
2953 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2955 break;
2957 case MP_CMD_VF_CHANGE_RECTANGLE:
2958 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2959 break;
2961 case MP_CMD_GET_TIME_LENGTH:{
2962 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2963 demuxer_get_time_length(mpctx->demuxer));
2965 break;
2967 case MP_CMD_GET_FILENAME:{
2968 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2969 get_metadata(mpctx, META_NAME));
2971 break;
2973 case MP_CMD_GET_VIDEO_CODEC:{
2974 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
2975 if (!inf)
2976 inf = strdup("");
2977 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2978 free(inf);
2980 break;
2982 case MP_CMD_GET_VIDEO_BITRATE:{
2983 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
2984 if (!inf)
2985 inf = strdup("");
2986 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2987 free(inf);
2989 break;
2991 case MP_CMD_GET_VIDEO_RESOLUTION:{
2992 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
2993 if (!inf)
2994 inf = strdup("");
2995 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2996 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
2997 free(inf);
2999 break;
3001 case MP_CMD_GET_AUDIO_CODEC:{
3002 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3003 if (!inf)
3004 inf = strdup("");
3005 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3006 free(inf);
3008 break;
3010 case MP_CMD_GET_AUDIO_BITRATE:{
3011 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3012 if (!inf)
3013 inf = strdup("");
3014 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3015 free(inf);
3017 break;
3019 case MP_CMD_GET_AUDIO_SAMPLES:{
3020 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3021 if (!inf)
3022 inf = strdup("");
3023 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3024 free(inf);
3026 break;
3028 case MP_CMD_GET_META_TITLE:{
3029 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3030 if (!inf)
3031 inf = strdup("");
3032 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3033 free(inf);
3035 break;
3037 case MP_CMD_GET_META_ARTIST:{
3038 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3039 if (!inf)
3040 inf = strdup("");
3041 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3042 free(inf);
3044 break;
3046 case MP_CMD_GET_META_ALBUM:{
3047 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3048 if (!inf)
3049 inf = strdup("");
3050 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3051 free(inf);
3053 break;
3055 case MP_CMD_GET_META_YEAR:{
3056 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3057 if (!inf)
3058 inf = strdup("");
3059 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3060 free(inf);
3062 break;
3064 case MP_CMD_GET_META_COMMENT:{
3065 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3066 if (!inf)
3067 inf = strdup("");
3068 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3069 free(inf);
3071 break;
3073 case MP_CMD_GET_META_TRACK:{
3074 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3075 if (!inf)
3076 inf = strdup("");
3077 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3078 free(inf);
3080 break;
3082 case MP_CMD_GET_META_GENRE:{
3083 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3084 if (!inf)
3085 inf = strdup("");
3086 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3087 free(inf);
3089 break;
3091 case MP_CMD_GET_VO_FULLSCREEN:
3092 if (mpctx->video_out && mpctx->video_out->config_ok)
3093 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3094 break;
3096 case MP_CMD_GET_PERCENT_POS:
3097 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3098 demuxer_get_percent_pos(mpctx->demuxer));
3099 break;
3101 case MP_CMD_GET_TIME_POS:{
3102 float pos = 0;
3103 if (sh_video)
3104 pos = sh_video->pts;
3105 else if (sh_audio && mpctx->audio_out)
3106 pos = playing_audio_pts(mpctx);
3107 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3109 break;
3111 case MP_CMD_RUN:
3112 #ifndef __MINGW32__
3113 if (!fork()) {
3114 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3115 exit(0);
3117 #endif
3118 break;
3120 case MP_CMD_KEYDOWN_EVENTS:
3121 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3122 break;
3124 case MP_CMD_SET_MOUSE_POS:{
3125 int pointer_x, pointer_y;
3126 double dx, dy;
3127 pointer_x = cmd->args[0].v.i;
3128 pointer_y = cmd->args[1].v.i;
3129 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3130 #ifdef CONFIG_DVDNAV
3131 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3132 && dx > 0.0 && dy > 0.0) {
3133 int button = -1;
3134 pointer_x = (int) (dx * (double) sh_video->disp_w);
3135 pointer_y = (int) (dy * (double) sh_video->disp_h);
3136 mp_dvdnav_update_mouse_pos(mpctx->stream,
3137 pointer_x, pointer_y, &button);
3138 if (osd_level > 1 && button > 0)
3139 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3140 "Selected button number %d", button);
3142 #endif
3143 #ifdef CONFIG_MENU
3144 if (use_menu && dx >= 0.0 && dy >= 0.0)
3145 menu_update_mouse_pos(dx, dy);
3146 #endif
3148 break;
3150 #ifdef CONFIG_DVDNAV
3151 case MP_CMD_DVDNAV:{
3152 int button = -1;
3153 int i;
3154 mp_command_type command = 0;
3155 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3156 break;
3158 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3159 if (cmd->args[0].v.s &&
3160 !strcasecmp (cmd->args[0].v.s,
3161 mp_dvdnav_bindings[i].name))
3162 command = mp_dvdnav_bindings[i].cmd;
3164 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3165 if (osd_level > 1 && button > 0)
3166 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3167 "Selected button number %d", button);
3169 break;
3171 case MP_CMD_SWITCH_TITLE:
3172 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3173 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3174 break;
3176 #endif
3178 default:
3179 #ifdef CONFIG_GUI
3180 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3181 guiGetEvent(guiIEvent, (char *) cmd->id);
3182 else
3183 #endif
3184 mp_msg(MSGT_CPLAYER, MSGL_V,
3185 "Received unknown cmd %s\n", cmd->name);
3188 switch (cmd->pausing) {
3189 case 1: // "pausing"
3190 mpctx->osd_function = OSD_PAUSE;
3191 break;
3192 case 3: // "pausing_toggle"
3193 mpctx->was_paused = !mpctx->was_paused;
3194 if (mpctx->was_paused)
3195 mpctx->osd_function = OSD_PAUSE;
3196 else if (mpctx->osd_function == OSD_PAUSE)
3197 mpctx->osd_function = OSD_PLAY;
3198 break;
3199 case 2: // "pausing_keep"
3200 if (mpctx->was_paused)
3201 mpctx->osd_function = OSD_PAUSE;
3203 return brk_cmd;