Merge svn changes up to r27682
[mplayer.git] / command.c
blobc1559c2d86b6173f5d64b7eb5fcb24433602dca8
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 /// Number of chapters in file
456 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
457 MPContext *mpctx)
459 if (!mpctx->demuxer)
460 return M_PROPERTY_UNAVAILABLE;
461 if (mpctx->demuxer->num_chapters == 0)
462 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
463 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
466 /// Current dvd angle (RW)
467 static int mp_property_angle(m_option_t *prop, int action, void *arg,
468 MPContext *mpctx)
470 int angle = -1;
471 int angles;
472 char *angle_name = NULL;
474 if (mpctx->demuxer)
475 angle = demuxer_get_current_angle(mpctx->demuxer);
476 if (angle < 0)
477 return M_PROPERTY_UNAVAILABLE;
478 angles = demuxer_angles_count(mpctx->demuxer);
479 if (angles <= 1)
480 return M_PROPERTY_UNAVAILABLE;
482 switch (action) {
483 case M_PROPERTY_GET:
484 if (!arg)
485 return M_PROPERTY_ERROR;
486 *(int *) arg = angle;
487 return M_PROPERTY_OK;
488 case M_PROPERTY_PRINT: {
489 if (!arg)
490 return M_PROPERTY_ERROR;
491 angle_name = calloc(1, 64);
492 if (!angle_name)
493 return M_PROPERTY_UNAVAILABLE;
494 snprintf(angle_name, 64, "%d/%d", angle, angles);
495 *(char **) arg = angle_name;
496 return M_PROPERTY_OK;
498 case M_PROPERTY_SET:
499 if (!arg)
500 return M_PROPERTY_ERROR;
501 angle = *(int *)arg;
502 M_PROPERTY_CLAMP(prop, angle);
503 break;
504 case M_PROPERTY_STEP_UP:
505 case M_PROPERTY_STEP_DOWN: {
506 int step = 0;
507 if(arg)
508 step = *(int*)arg;
509 if(!step)
510 step = 1;
511 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
512 angle += step;
513 if (angle < 1) //cycle
514 angle = angles;
515 break;
517 default:
518 return M_PROPERTY_NOT_IMPLEMENTED;
520 angle = demuxer_set_angle(mpctx->demuxer, angle);
521 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
522 MSGTR_OSDAngle, angle, angles);
523 if (angle_name)
524 free(angle_name);
525 return M_PROPERTY_OK;
528 /// Demuxer meta data
529 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
530 MPContext *mpctx) {
531 m_property_action_t* ka;
532 char* meta;
533 static const m_option_t key_type =
534 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
535 if (!mpctx->demuxer)
536 return M_PROPERTY_UNAVAILABLE;
538 switch(action) {
539 case M_PROPERTY_GET:
540 if(!arg) return M_PROPERTY_ERROR;
541 *(char***)arg = mpctx->demuxer->info;
542 return M_PROPERTY_OK;
543 case M_PROPERTY_KEY_ACTION:
544 if(!arg) return M_PROPERTY_ERROR;
545 ka = arg;
546 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
547 return M_PROPERTY_UNKNOWN;
548 switch(ka->action) {
549 case M_PROPERTY_GET:
550 if(!ka->arg) return M_PROPERTY_ERROR;
551 *(char**)ka->arg = meta;
552 return M_PROPERTY_OK;
553 case M_PROPERTY_GET_TYPE:
554 if(!ka->arg) return M_PROPERTY_ERROR;
555 *(m_option_t**)ka->arg = &key_type;
556 return M_PROPERTY_OK;
559 return M_PROPERTY_NOT_IMPLEMENTED;
562 static int mp_property_pause(m_option_t * prop, int action, void *arg,
563 MPContext * mpctx)
565 return m_property_flag_ro(prop, action, arg, mpctx->osd_function == OSD_PAUSE);
569 ///@}
571 /// \defgroup AudioProperties Audio properties
572 /// \ingroup Properties
573 ///@{
575 /// Volume (RW)
576 static int mp_property_volume(m_option_t *prop, int action, void *arg,
577 MPContext *mpctx)
580 if (!mpctx->sh_audio)
581 return M_PROPERTY_UNAVAILABLE;
583 switch (action) {
584 case M_PROPERTY_GET:
585 if (!arg)
586 return M_PROPERTY_ERROR;
587 mixer_getbothvolume(&mpctx->mixer, arg);
588 return M_PROPERTY_OK;
589 case M_PROPERTY_PRINT:{
590 float vol;
591 if (!arg)
592 return M_PROPERTY_ERROR;
593 mixer_getbothvolume(&mpctx->mixer, &vol);
594 return m_property_float_range(prop, action, arg, &vol);
596 case M_PROPERTY_STEP_UP:
597 case M_PROPERTY_STEP_DOWN:
598 case M_PROPERTY_SET:
599 break;
600 default:
601 return M_PROPERTY_NOT_IMPLEMENTED;
604 if (mpctx->edl_muted)
605 return M_PROPERTY_DISABLED;
606 mpctx->user_muted = 0;
608 switch (action) {
609 case M_PROPERTY_SET:
610 if (!arg)
611 return M_PROPERTY_ERROR;
612 M_PROPERTY_CLAMP(prop, *(float *) arg);
613 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
614 return M_PROPERTY_OK;
615 case M_PROPERTY_STEP_UP:
616 if (arg && *(float *) arg <= 0)
617 mixer_decvolume(&mpctx->mixer);
618 else
619 mixer_incvolume(&mpctx->mixer);
620 return M_PROPERTY_OK;
621 case M_PROPERTY_STEP_DOWN:
622 if (arg && *(float *) arg <= 0)
623 mixer_incvolume(&mpctx->mixer);
624 else
625 mixer_decvolume(&mpctx->mixer);
626 return M_PROPERTY_OK;
628 return M_PROPERTY_NOT_IMPLEMENTED;
631 /// Mute (RW)
632 static int mp_property_mute(m_option_t *prop, int action, void *arg,
633 MPContext *mpctx)
636 if (!mpctx->sh_audio)
637 return M_PROPERTY_UNAVAILABLE;
639 switch (action) {
640 case M_PROPERTY_SET:
641 if (mpctx->edl_muted)
642 return M_PROPERTY_DISABLED;
643 if (!arg)
644 return M_PROPERTY_ERROR;
645 if ((!!*(int *) arg) != mpctx->mixer.muted)
646 mixer_mute(&mpctx->mixer);
647 mpctx->user_muted = mpctx->mixer.muted;
648 return M_PROPERTY_OK;
649 case M_PROPERTY_STEP_UP:
650 case M_PROPERTY_STEP_DOWN:
651 if (mpctx->edl_muted)
652 return M_PROPERTY_DISABLED;
653 mixer_mute(&mpctx->mixer);
654 mpctx->user_muted = mpctx->mixer.muted;
655 return M_PROPERTY_OK;
656 case M_PROPERTY_PRINT:
657 if (!arg)
658 return M_PROPERTY_ERROR;
659 if (mpctx->edl_muted) {
660 *(char **) arg = strdup(MSGTR_EnabledEdl);
661 return M_PROPERTY_OK;
663 default:
664 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
669 /// Audio delay (RW)
670 static int mp_property_audio_delay(m_option_t *prop, int action,
671 void *arg, MPContext *mpctx)
673 if (!(mpctx->sh_audio && mpctx->sh_video))
674 return M_PROPERTY_UNAVAILABLE;
675 switch (action) {
676 case M_PROPERTY_SET:
677 case M_PROPERTY_STEP_UP:
678 case M_PROPERTY_STEP_DOWN: {
679 int ret;
680 float delay = audio_delay;
681 ret = m_property_delay(prop, action, arg, &audio_delay);
682 if (ret != M_PROPERTY_OK)
683 return ret;
684 if (mpctx->sh_audio)
685 mpctx->delay -= audio_delay - delay;
687 return M_PROPERTY_OK;
688 default:
689 return m_property_delay(prop, action, arg, &audio_delay);
693 /// Audio codec tag (RO)
694 static int mp_property_audio_format(m_option_t *prop, int action,
695 void *arg, MPContext *mpctx)
697 if (!mpctx->sh_audio)
698 return M_PROPERTY_UNAVAILABLE;
699 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
702 /// Audio codec name (RO)
703 static int mp_property_audio_codec(m_option_t *prop, int action,
704 void *arg, MPContext *mpctx)
706 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
707 return M_PROPERTY_UNAVAILABLE;
708 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
711 /// Audio bitrate (RO)
712 static int mp_property_audio_bitrate(m_option_t *prop, int action,
713 void *arg, MPContext *mpctx)
715 if (!mpctx->sh_audio)
716 return M_PROPERTY_UNAVAILABLE;
717 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
720 /// Samplerate (RO)
721 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
722 MPContext *mpctx)
724 if (!mpctx->sh_audio)
725 return M_PROPERTY_UNAVAILABLE;
726 switch(action) {
727 case M_PROPERTY_PRINT:
728 if(!arg) return M_PROPERTY_ERROR;
729 *(char**)arg = malloc(16);
730 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
731 return M_PROPERTY_OK;
733 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
736 /// Number of channels (RO)
737 static int mp_property_channels(m_option_t *prop, int action, void *arg,
738 MPContext *mpctx)
740 if (!mpctx->sh_audio)
741 return M_PROPERTY_UNAVAILABLE;
742 switch (action) {
743 case M_PROPERTY_PRINT:
744 if (!arg)
745 return M_PROPERTY_ERROR;
746 switch (mpctx->sh_audio->channels) {
747 case 1:
748 *(char **) arg = strdup("mono");
749 break;
750 case 2:
751 *(char **) arg = strdup("stereo");
752 break;
753 default:
754 *(char **) arg = malloc(32);
755 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
757 return M_PROPERTY_OK;
759 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
762 /// Balance (RW)
763 static int mp_property_balance(m_option_t *prop, int action, void *arg,
764 MPContext *mpctx)
766 float bal;
768 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
769 return M_PROPERTY_UNAVAILABLE;
771 switch (action) {
772 case M_PROPERTY_GET:
773 if (!arg)
774 return M_PROPERTY_ERROR;
775 mixer_getbalance(&mpctx->mixer, arg);
776 return M_PROPERTY_OK;
777 case M_PROPERTY_PRINT: {
778 char** str = arg;
779 if (!arg)
780 return M_PROPERTY_ERROR;
781 mixer_getbalance(&mpctx->mixer, &bal);
782 if (bal == 0.f)
783 *str = strdup("center");
784 else if (bal == -1.f)
785 *str = strdup("left only");
786 else if (bal == 1.f)
787 *str = strdup("right only");
788 else {
789 unsigned right = (bal + 1.f) / 2.f * 100.f;
790 *str = malloc(sizeof("left xxx%, right xxx%"));
791 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
793 return M_PROPERTY_OK;
795 case M_PROPERTY_STEP_UP:
796 case M_PROPERTY_STEP_DOWN:
797 mixer_getbalance(&mpctx->mixer, &bal);
798 bal += (arg ? *(float*)arg : .1f) *
799 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
800 M_PROPERTY_CLAMP(prop, bal);
801 mixer_setbalance(&mpctx->mixer, bal);
802 return M_PROPERTY_OK;
803 case M_PROPERTY_SET:
804 if (!arg)
805 return M_PROPERTY_ERROR;
806 M_PROPERTY_CLAMP(prop, *(float*)arg);
807 mixer_setbalance(&mpctx->mixer, *(float*)arg);
808 return M_PROPERTY_OK;
810 return M_PROPERTY_NOT_IMPLEMENTED;
813 /// Selected audio id (RW)
814 static int mp_property_audio(m_option_t *prop, int action, void *arg,
815 MPContext *mpctx)
817 struct MPOpts *opts = &mpctx->opts;
818 int current_id = -1, tmp;
820 switch (action) {
821 case M_PROPERTY_GET:
822 if (!mpctx->sh_audio)
823 return M_PROPERTY_UNAVAILABLE;
824 if (!arg)
825 return M_PROPERTY_ERROR;
826 *(int *) arg = opts->audio_id;
827 return M_PROPERTY_OK;
828 case M_PROPERTY_PRINT:
829 if (!mpctx->sh_audio)
830 return M_PROPERTY_UNAVAILABLE;
831 if (!arg)
832 return M_PROPERTY_ERROR;
834 if (opts->audio_id < 0)
835 *(char **) arg = strdup(MSGTR_Disabled);
836 else {
837 char lang[40] = MSGTR_Unknown;
838 sh_audio_t* sh = mpctx->sh_audio;
839 if (sh && sh->lang)
840 av_strlcpy(lang, sh->lang, 40);
841 #ifdef CONFIG_DVDREAD
842 else if (mpctx->stream->type == STREAMTYPE_DVD) {
843 int code = dvd_lang_from_aid(mpctx->stream, opts->audio_id);
844 if (code) {
845 lang[0] = code >> 8;
846 lang[1] = code;
847 lang[2] = 0;
850 #endif
852 #ifdef CONFIG_DVDNAV
853 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
854 mp_dvdnav_lang_from_aid(mpctx->stream, opts->audio_id, lang);
855 #endif
856 *(char **) arg = malloc(64);
857 snprintf(*(char **) arg, 64, "(%d) %s", opts->audio_id, lang);
859 return M_PROPERTY_OK;
861 case M_PROPERTY_STEP_UP:
862 case M_PROPERTY_SET:
863 if (!mpctx->demuxer)
864 return M_PROPERTY_UNAVAILABLE;
865 if (action == M_PROPERTY_SET && arg)
866 tmp = *((int *) arg);
867 else
868 tmp = -1;
869 current_id = mpctx->demuxer->audio->id;
870 opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
871 if (opts->audio_id == -2
872 || (opts->audio_id > -1
873 && mpctx->demuxer->audio->id != current_id && current_id != -2))
874 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
875 if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
876 sh_audio_t *sh2;
877 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
878 if (sh2) {
879 sh2->ds = mpctx->demuxer->audio;
880 mpctx->sh_audio = sh2;
881 reinit_audio_chain(mpctx);
884 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id);
885 return M_PROPERTY_OK;
886 default:
887 return M_PROPERTY_NOT_IMPLEMENTED;
892 /// Selected video id (RW)
893 static int mp_property_video(m_option_t *prop, int action, void *arg,
894 MPContext *mpctx)
896 struct MPOpts *opts = &mpctx->opts;
897 int current_id = -1, tmp;
899 switch (action) {
900 case M_PROPERTY_GET:
901 if (!mpctx->sh_video)
902 return M_PROPERTY_UNAVAILABLE;
903 if (!arg)
904 return M_PROPERTY_ERROR;
905 *(int *) arg = opts->video_id;
906 return M_PROPERTY_OK;
907 case M_PROPERTY_PRINT:
908 if (!mpctx->sh_video)
909 return M_PROPERTY_UNAVAILABLE;
910 if (!arg)
911 return M_PROPERTY_ERROR;
913 if (opts->video_id < 0)
914 *(char **) arg = strdup(MSGTR_Disabled);
915 else {
916 char lang[40] = MSGTR_Unknown;
917 *(char **) arg = malloc(64);
918 snprintf(*(char **) arg, 64, "(%d) %s", opts->video_id, lang);
920 return M_PROPERTY_OK;
922 case M_PROPERTY_STEP_UP:
923 case M_PROPERTY_SET:
924 current_id = mpctx->demuxer->video->id;
925 if (action == M_PROPERTY_SET && arg)
926 tmp = *((int *) arg);
927 else
928 tmp = -1;
929 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
930 if (opts->video_id == -2
931 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
932 && current_id != -2))
933 uninit_player(mpctx, INITIALIZED_VCODEC |
934 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
935 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
936 sh_video_t *sh2;
937 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
938 if (sh2) {
939 sh2->ds = mpctx->demuxer->video;
940 mpctx->sh_video = sh2;
941 reinit_video_chain(mpctx);
944 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
945 return M_PROPERTY_OK;
947 default:
948 return M_PROPERTY_NOT_IMPLEMENTED;
952 static int mp_property_program(m_option_t *prop, int action, void *arg,
953 MPContext *mpctx)
955 demux_program_t prog;
957 switch (action) {
958 case M_PROPERTY_STEP_UP:
959 case M_PROPERTY_SET:
960 if (action == M_PROPERTY_SET && arg)
961 prog.progid = *((int *) arg);
962 else
963 prog.progid = -1;
964 if (demux_control
965 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
966 &prog) == DEMUXER_CTRL_NOTIMPL)
967 return M_PROPERTY_ERROR;
969 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
970 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
971 return M_PROPERTY_OK;
973 default:
974 return M_PROPERTY_NOT_IMPLEMENTED;
978 ///@}
980 /// \defgroup VideoProperties Video properties
981 /// \ingroup Properties
982 ///@{
984 /// Fullscreen state (RW)
985 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
986 MPContext *mpctx)
989 if (!mpctx->video_out)
990 return M_PROPERTY_UNAVAILABLE;
992 switch (action) {
993 case M_PROPERTY_SET:
994 if (!arg)
995 return M_PROPERTY_ERROR;
996 M_PROPERTY_CLAMP(prop, *(int *) arg);
997 if (vo_fs == !!*(int *) arg)
998 return M_PROPERTY_OK;
999 case M_PROPERTY_STEP_UP:
1000 case M_PROPERTY_STEP_DOWN:
1001 #ifdef CONFIG_GUI
1002 if (use_gui)
1003 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
1004 else
1005 #endif
1006 if (mpctx->video_out->config_ok)
1007 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1008 return M_PROPERTY_OK;
1009 default:
1010 return m_property_flag(prop, action, arg, &vo_fs);
1014 static int mp_property_deinterlace(m_option_t *prop, int action,
1015 void *arg, MPContext *mpctx)
1017 int deinterlace;
1018 vf_instance_t *vf;
1019 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1020 return M_PROPERTY_UNAVAILABLE;
1021 vf = mpctx->sh_video->vfilter;
1022 switch (action) {
1023 case M_PROPERTY_GET:
1024 if (!arg)
1025 return M_PROPERTY_ERROR;
1026 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1027 return M_PROPERTY_OK;
1028 case M_PROPERTY_SET:
1029 if (!arg)
1030 return M_PROPERTY_ERROR;
1031 M_PROPERTY_CLAMP(prop, *(int *) arg);
1032 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1033 return M_PROPERTY_OK;
1034 case M_PROPERTY_STEP_UP:
1035 case M_PROPERTY_STEP_DOWN:
1036 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1037 deinterlace = !deinterlace;
1038 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1039 return M_PROPERTY_OK;
1041 return M_PROPERTY_NOT_IMPLEMENTED;
1044 /// Panscan (RW)
1045 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1046 MPContext *mpctx)
1049 if (!mpctx->video_out
1050 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1051 return M_PROPERTY_UNAVAILABLE;
1053 switch (action) {
1054 case M_PROPERTY_SET:
1055 if (!arg)
1056 return M_PROPERTY_ERROR;
1057 M_PROPERTY_CLAMP(prop, *(float *) arg);
1058 vo_panscan = *(float *) arg;
1059 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1060 return M_PROPERTY_OK;
1061 case M_PROPERTY_STEP_UP:
1062 case M_PROPERTY_STEP_DOWN:
1063 vo_panscan += (arg ? *(float *) arg : 0.1) *
1064 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1065 if (vo_panscan > 1)
1066 vo_panscan = 1;
1067 else if (vo_panscan < 0)
1068 vo_panscan = 0;
1069 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1070 return M_PROPERTY_OK;
1071 default:
1072 return m_property_float_range(prop, action, arg, &vo_panscan);
1076 /// Helper to set vo flags.
1077 /** \ingroup PropertyImplHelper
1079 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1080 int vo_ctrl, int *vo_var, MPContext *mpctx)
1083 if (!mpctx->video_out)
1084 return M_PROPERTY_UNAVAILABLE;
1086 switch (action) {
1087 case M_PROPERTY_SET:
1088 if (!arg)
1089 return M_PROPERTY_ERROR;
1090 M_PROPERTY_CLAMP(prop, *(int *) arg);
1091 if (*vo_var == !!*(int *) arg)
1092 return M_PROPERTY_OK;
1093 case M_PROPERTY_STEP_UP:
1094 case M_PROPERTY_STEP_DOWN:
1095 if (mpctx->video_out->config_ok)
1096 vo_control(mpctx->video_out, vo_ctrl, 0);
1097 return M_PROPERTY_OK;
1098 default:
1099 return m_property_flag(prop, action, arg, vo_var);
1103 /// Window always on top (RW)
1104 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1105 MPContext *mpctx)
1107 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1108 &mpctx->opts.vo_ontop, mpctx);
1111 /// Display in the root window (RW)
1112 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1113 MPContext *mpctx)
1115 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1116 &vo_rootwin, mpctx);
1119 /// Show window borders (RW)
1120 static int mp_property_border(m_option_t *prop, int action, void *arg,
1121 MPContext *mpctx)
1123 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1124 &vo_border, mpctx);
1127 /// Framedropping state (RW)
1128 static int mp_property_framedropping(m_option_t *prop, int action,
1129 void *arg, MPContext *mpctx)
1132 if (!mpctx->sh_video)
1133 return M_PROPERTY_UNAVAILABLE;
1135 switch (action) {
1136 case M_PROPERTY_PRINT:
1137 if (!arg)
1138 return M_PROPERTY_ERROR;
1139 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1140 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1141 MSGTR_Disabled));
1142 return M_PROPERTY_OK;
1143 default:
1144 return m_property_choice(prop, action, arg, &frame_dropping);
1148 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1149 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1150 MPContext *mpctx)
1152 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1153 int r, val;
1155 if (!mpctx->sh_video)
1156 return M_PROPERTY_UNAVAILABLE;
1158 if (gamma[0] == 1000) {
1159 gamma[0] = 0;
1160 get_video_colors(mpctx->sh_video, prop->name, gamma);
1163 switch (action) {
1164 case M_PROPERTY_SET:
1165 if (!arg)
1166 return M_PROPERTY_ERROR;
1167 M_PROPERTY_CLAMP(prop, *(int *) arg);
1168 *gamma = *(int *) arg;
1169 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1170 if (r <= 0)
1171 break;
1172 return r;
1173 case M_PROPERTY_GET:
1174 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1175 if (!arg)
1176 return M_PROPERTY_ERROR;
1177 *(int *)arg = val;
1178 return M_PROPERTY_OK;
1180 break;
1181 case M_PROPERTY_STEP_UP:
1182 case M_PROPERTY_STEP_DOWN:
1183 *gamma += (arg ? *(int *) arg : 1) *
1184 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1185 M_PROPERTY_CLAMP(prop, *gamma);
1186 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1187 if (r <= 0)
1188 break;
1189 return r;
1190 default:
1191 return M_PROPERTY_NOT_IMPLEMENTED;
1194 #ifdef CONFIG_TV
1195 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1196 int l = strlen(prop->name);
1197 char tv_prop[3 + l + 1];
1198 sprintf(tv_prop, "tv_%s", prop->name);
1199 return mp_property_do(tv_prop, action, arg, mpctx);
1201 #endif
1203 return M_PROPERTY_UNAVAILABLE;
1206 /// VSync (RW)
1207 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1208 MPContext *mpctx)
1210 return m_property_flag(prop, action, arg, &vo_vsync);
1213 /// Video codec tag (RO)
1214 static int mp_property_video_format(m_option_t *prop, int action,
1215 void *arg, MPContext *mpctx)
1217 char* meta;
1218 if (!mpctx->sh_video)
1219 return M_PROPERTY_UNAVAILABLE;
1220 switch(action) {
1221 case M_PROPERTY_PRINT:
1222 if (!arg)
1223 return M_PROPERTY_ERROR;
1224 switch(mpctx->sh_video->format) {
1225 case 0x10000001:
1226 meta = strdup ("mpeg1"); break;
1227 case 0x10000002:
1228 meta = strdup ("mpeg2"); break;
1229 case 0x10000004:
1230 meta = strdup ("mpeg4"); break;
1231 case 0x10000005:
1232 meta = strdup ("h264"); break;
1233 default:
1234 if(mpctx->sh_video->format >= 0x20202020) {
1235 meta = malloc(5);
1236 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1237 } else {
1238 meta = malloc(20);
1239 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1242 *(char**)arg = meta;
1243 return M_PROPERTY_OK;
1245 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1248 /// Video codec name (RO)
1249 static int mp_property_video_codec(m_option_t *prop, int action,
1250 void *arg, MPContext *mpctx)
1252 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1253 return M_PROPERTY_UNAVAILABLE;
1254 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1258 /// Video bitrate (RO)
1259 static int mp_property_video_bitrate(m_option_t *prop, int action,
1260 void *arg, MPContext *mpctx)
1262 if (!mpctx->sh_video)
1263 return M_PROPERTY_UNAVAILABLE;
1264 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1267 /// Video display width (RO)
1268 static int mp_property_width(m_option_t *prop, int action, void *arg,
1269 MPContext *mpctx)
1271 if (!mpctx->sh_video)
1272 return M_PROPERTY_UNAVAILABLE;
1273 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1276 /// Video display height (RO)
1277 static int mp_property_height(m_option_t *prop, int action, void *arg,
1278 MPContext *mpctx)
1280 if (!mpctx->sh_video)
1281 return M_PROPERTY_UNAVAILABLE;
1282 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1285 /// Video fps (RO)
1286 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1287 MPContext *mpctx)
1289 if (!mpctx->sh_video)
1290 return M_PROPERTY_UNAVAILABLE;
1291 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1294 /// Video aspect (RO)
1295 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1296 MPContext *mpctx)
1298 if (!mpctx->sh_video)
1299 return M_PROPERTY_UNAVAILABLE;
1300 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1303 ///@}
1305 /// \defgroup SubProprties Subtitles properties
1306 /// \ingroup Properties
1307 ///@{
1309 /// Text subtitle position (RW)
1310 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1311 MPContext *mpctx)
1313 if (!mpctx->sh_video)
1314 return M_PROPERTY_UNAVAILABLE;
1316 switch (action) {
1317 case M_PROPERTY_SET:
1318 if (!arg)
1319 return M_PROPERTY_ERROR;
1320 case M_PROPERTY_STEP_UP:
1321 case M_PROPERTY_STEP_DOWN:
1322 vo_osd_changed(OSDTYPE_SUBTITLE);
1323 default:
1324 return m_property_int_range(prop, action, arg, &sub_pos);
1328 /// Selected subtitles (RW)
1329 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1330 MPContext *mpctx)
1332 struct MPOpts *opts = &mpctx->opts;
1333 demux_stream_t *const d_sub = mpctx->d_sub;
1334 const int global_sub_size = mpctx->global_sub_size;
1335 int source = -1, reset_spu = 0;
1336 char *sub_name;
1338 if (global_sub_size <= 0)
1339 return M_PROPERTY_UNAVAILABLE;
1341 switch (action) {
1342 case M_PROPERTY_GET:
1343 if (!arg)
1344 return M_PROPERTY_ERROR;
1345 *(int *) arg = mpctx->global_sub_pos;
1346 return M_PROPERTY_OK;
1347 case M_PROPERTY_PRINT:
1348 if (!arg)
1349 return M_PROPERTY_ERROR;
1350 *(char **) arg = malloc(64);
1351 (*(char **) arg)[63] = 0;
1352 sub_name = 0;
1353 if (subdata)
1354 sub_name = subdata->filename;
1355 #ifdef CONFIG_ASS
1356 if (ass_track && ass_track->name)
1357 sub_name = ass_track->name;
1358 #endif
1359 if (sub_name) {
1360 char *tmp, *tmp2;
1361 tmp = sub_name;
1362 if ((tmp2 = strrchr(tmp, '/')))
1363 tmp = tmp2 + 1;
1365 snprintf(*(char **) arg, 63, "(%d) %s%s",
1366 mpctx->set_of_sub_pos + 1,
1367 strlen(tmp) < 20 ? "" : "...",
1368 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1369 return M_PROPERTY_OK;
1371 #ifdef CONFIG_DVDNAV
1372 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1373 if (vo_spudec && opts->sub_id >= 0) {
1374 unsigned char lang[3];
1375 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1376 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1377 return M_PROPERTY_OK;
1381 #endif
1383 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1384 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1385 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1386 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1387 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1388 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1389 if (!lang) lang = MSGTR_Unknown;
1390 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1391 return M_PROPERTY_OK;
1394 if (vo_vobsub && vobsub_id >= 0) {
1395 const char *language = MSGTR_Unknown;
1396 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1397 snprintf(*(char **) arg, 63, "(%d) %s",
1398 vobsub_id, language ? language : MSGTR_Unknown);
1399 return M_PROPERTY_OK;
1401 #ifdef CONFIG_DVDREAD
1402 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1403 && opts->sub_id >= 0) {
1404 char lang[3];
1405 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1406 lang[0] = code >> 8;
1407 lang[1] = code;
1408 lang[2] = 0;
1409 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1410 return M_PROPERTY_OK;
1412 #endif
1413 if (opts->sub_id >= 0) {
1414 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, MSGTR_Unknown);
1415 return M_PROPERTY_OK;
1417 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1418 return M_PROPERTY_OK;
1420 case M_PROPERTY_SET:
1421 if (!arg)
1422 return M_PROPERTY_ERROR;
1423 if (*(int *) arg < -1)
1424 *(int *) arg = -1;
1425 else if (*(int *) arg >= global_sub_size)
1426 *(int *) arg = global_sub_size - 1;
1427 mpctx->global_sub_pos = *(int *) arg;
1428 break;
1429 case M_PROPERTY_STEP_UP:
1430 mpctx->global_sub_pos += 2;
1431 mpctx->global_sub_pos =
1432 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1433 break;
1434 case M_PROPERTY_STEP_DOWN:
1435 mpctx->global_sub_pos += global_sub_size + 1;
1436 mpctx->global_sub_pos =
1437 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1438 break;
1439 default:
1440 return M_PROPERTY_NOT_IMPLEMENTED;
1443 if (mpctx->global_sub_pos >= 0)
1444 source = sub_source(mpctx);
1446 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1447 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1448 global_sub_size,
1449 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1450 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1451 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1452 mpctx->global_sub_pos, source);
1454 mpctx->set_of_sub_pos = -1;
1455 subdata = NULL;
1457 vobsub_id = -1;
1458 opts->sub_id = -1;
1459 if (d_sub) {
1460 if (d_sub->id > -2)
1461 reset_spu = 1;
1462 d_sub->id = -2;
1464 #ifdef CONFIG_ASS
1465 ass_track = 0;
1466 #endif
1468 if (source == SUB_SOURCE_VOBSUB) {
1469 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1470 } else if (source == SUB_SOURCE_SUBS) {
1471 mpctx->set_of_sub_pos =
1472 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1473 #ifdef CONFIG_ASS
1474 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1475 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1476 else
1477 #endif
1479 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1480 vo_osd_changed(OSDTYPE_SUBTITLE);
1482 } else if (source == SUB_SOURCE_DEMUX) {
1483 opts->sub_id =
1484 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1485 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1486 int i = 0;
1487 // default: assume 1:1 mapping of sid and stream id
1488 d_sub->id = opts->sub_id;
1489 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1490 ds_free_packs(d_sub);
1491 for (i = 0; i < MAX_S_STREAMS; i++) {
1492 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1493 if (sh && sh->sid == opts->sub_id) {
1494 d_sub->id = i;
1495 d_sub->sh = sh;
1496 break;
1499 if (d_sub->sh && d_sub->id >= 0) {
1500 sh_sub_t *sh = d_sub->sh;
1501 if (sh->type == 'v')
1502 init_vo_spudec(mpctx);
1503 #ifdef CONFIG_ASS
1504 else if (ass_enabled)
1505 ass_track = sh->ass_track;
1506 #endif
1507 } else {
1508 d_sub->id = -2;
1509 d_sub->sh = NULL;
1513 #ifdef CONFIG_DVDREAD
1514 if (vo_spudec
1515 && (mpctx->stream->type == STREAMTYPE_DVD
1516 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1517 && opts->sub_id < 0 && reset_spu) {
1518 opts->sub_id = -2;
1519 d_sub->id = opts->sub_id;
1521 #endif
1522 update_subtitles(mpctx->sh_video, d_sub, 1);
1524 return M_PROPERTY_OK;
1527 /// Selected sub source (RW)
1528 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1529 MPContext *mpctx)
1531 int source;
1532 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1533 return M_PROPERTY_UNAVAILABLE;
1535 switch (action) {
1536 case M_PROPERTY_GET:
1537 if (!arg)
1538 return M_PROPERTY_ERROR;
1539 *(int *) arg = sub_source(mpctx);
1540 return M_PROPERTY_OK;
1541 case M_PROPERTY_PRINT:
1542 if (!arg)
1543 return M_PROPERTY_ERROR;
1544 *(char **) arg = malloc(64);
1545 (*(char **) arg)[63] = 0;
1546 switch (sub_source(mpctx))
1548 case SUB_SOURCE_SUBS:
1549 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1550 break;
1551 case SUB_SOURCE_VOBSUB:
1552 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1553 break;
1554 case SUB_SOURCE_DEMUX:
1555 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1556 break;
1557 default:
1558 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1560 return M_PROPERTY_OK;
1561 case M_PROPERTY_SET:
1562 if (!arg)
1563 return M_PROPERTY_ERROR;
1564 M_PROPERTY_CLAMP(prop, *(int*)arg);
1565 if (*(int *) arg < 0)
1566 mpctx->global_sub_pos = -1;
1567 else if (*(int *) arg != sub_source(mpctx)) {
1568 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1569 return M_PROPERTY_UNAVAILABLE;
1570 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1572 break;
1573 case M_PROPERTY_STEP_UP:
1574 case M_PROPERTY_STEP_DOWN: {
1575 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1576 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1577 int step = (step_all > 0) ? 1 : -1;
1578 int cur_source = sub_source(mpctx);
1579 source = cur_source;
1580 while (step_all) {
1581 source += step;
1582 if (source >= SUB_SOURCES)
1583 source = -1;
1584 else if (source < -1)
1585 source = SUB_SOURCES - 1;
1586 if (source == cur_source || source == -1 ||
1587 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1588 step_all -= step;
1590 if (source == cur_source)
1591 return M_PROPERTY_OK;
1592 if (source == -1)
1593 mpctx->global_sub_pos = -1;
1594 else
1595 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1596 break;
1598 default:
1599 return M_PROPERTY_NOT_IMPLEMENTED;
1601 --mpctx->global_sub_pos;
1602 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1605 /// Selected subtitles from specific source (RW)
1606 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1607 MPContext *mpctx)
1609 int source, is_cur_source, offset;
1610 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1611 return M_PROPERTY_UNAVAILABLE;
1613 if (!strcmp(prop->name, "sub_file"))
1614 source = SUB_SOURCE_SUBS;
1615 else if (!strcmp(prop->name, "sub_vob"))
1616 source = SUB_SOURCE_VOBSUB;
1617 else if (!strcmp(prop->name, "sub_demux"))
1618 source = SUB_SOURCE_DEMUX;
1619 else
1620 return M_PROPERTY_ERROR;
1622 offset = mpctx->global_sub_indices[source];
1623 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1624 return M_PROPERTY_UNAVAILABLE;
1626 is_cur_source = sub_source(mpctx) == source;
1627 switch (action) {
1628 case M_PROPERTY_GET:
1629 if (!arg)
1630 return M_PROPERTY_ERROR;
1631 if (is_cur_source) {
1632 *(int *) arg = mpctx->global_sub_pos - offset;
1633 if (source == SUB_SOURCE_VOBSUB)
1634 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1636 else
1637 *(int *) arg = -1;
1638 return M_PROPERTY_OK;
1639 case M_PROPERTY_PRINT:
1640 if (!arg)
1641 return M_PROPERTY_ERROR;
1642 if (is_cur_source)
1643 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1644 *(char **) arg = malloc(64);
1645 (*(char **) arg)[63] = 0;
1646 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1647 return M_PROPERTY_OK;
1648 case M_PROPERTY_SET:
1649 if (!arg)
1650 return M_PROPERTY_ERROR;
1651 if (*(int *) arg >= 0) {
1652 int index = *(int *)arg;
1653 if (source == SUB_SOURCE_VOBSUB)
1654 index = vobsub_get_index_by_id(vo_vobsub, index);
1655 mpctx->global_sub_pos = offset + index;
1656 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1657 || sub_source(mpctx) != source) {
1658 mpctx->global_sub_pos = -1;
1659 *(int *) arg = -1;
1662 else
1663 mpctx->global_sub_pos = -1;
1664 break;
1665 case M_PROPERTY_STEP_UP:
1666 case M_PROPERTY_STEP_DOWN: {
1667 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1668 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1669 int step = (step_all > 0) ? 1 : -1;
1670 int max_sub_pos_for_source = -1;
1671 if (!is_cur_source)
1672 mpctx->global_sub_pos = -1;
1673 while (step_all) {
1674 if (mpctx->global_sub_pos == -1) {
1675 if (step > 0)
1676 mpctx->global_sub_pos = offset;
1677 else if (max_sub_pos_for_source == -1) {
1678 // Find max pos for specific source
1679 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1680 while (mpctx->global_sub_pos >= 0
1681 && sub_source(mpctx) != source)
1682 --mpctx->global_sub_pos;
1684 else
1685 mpctx->global_sub_pos = max_sub_pos_for_source;
1687 else {
1688 mpctx->global_sub_pos += step;
1689 if (mpctx->global_sub_pos < offset ||
1690 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1691 sub_source(mpctx) != source)
1692 mpctx->global_sub_pos = -1;
1694 step_all -= step;
1696 break;
1698 default:
1699 return M_PROPERTY_NOT_IMPLEMENTED;
1701 --mpctx->global_sub_pos;
1702 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1705 /// Subtitle delay (RW)
1706 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1707 MPContext *mpctx)
1709 if (!mpctx->sh_video)
1710 return M_PROPERTY_UNAVAILABLE;
1711 return m_property_delay(prop, action, arg, &sub_delay);
1714 /// Alignment of text subtitles (RW)
1715 static int mp_property_sub_alignment(m_option_t *prop, int action,
1716 void *arg, MPContext *mpctx)
1718 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1720 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1721 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1722 return M_PROPERTY_UNAVAILABLE;
1724 switch (action) {
1725 case M_PROPERTY_PRINT:
1726 if (!arg)
1727 return M_PROPERTY_ERROR;
1728 M_PROPERTY_CLAMP(prop, sub_alignment);
1729 *(char **) arg = strdup(name[sub_alignment]);
1730 return M_PROPERTY_OK;
1731 case M_PROPERTY_SET:
1732 if (!arg)
1733 return M_PROPERTY_ERROR;
1734 case M_PROPERTY_STEP_UP:
1735 case M_PROPERTY_STEP_DOWN:
1736 vo_osd_changed(OSDTYPE_SUBTITLE);
1737 default:
1738 return m_property_choice(prop, action, arg, &sub_alignment);
1742 /// Subtitle visibility (RW)
1743 static int mp_property_sub_visibility(m_option_t *prop, int action,
1744 void *arg, MPContext *mpctx)
1746 if (!mpctx->sh_video)
1747 return M_PROPERTY_UNAVAILABLE;
1749 switch (action) {
1750 case M_PROPERTY_SET:
1751 if (!arg)
1752 return M_PROPERTY_ERROR;
1753 case M_PROPERTY_STEP_UP:
1754 case M_PROPERTY_STEP_DOWN:
1755 vo_osd_changed(OSDTYPE_SUBTITLE);
1756 if (vo_spudec)
1757 vo_osd_changed(OSDTYPE_SPU);
1758 default:
1759 return m_property_flag(prop, action, arg, &sub_visibility);
1763 #ifdef CONFIG_ASS
1764 /// Use margins for libass subtitles (RW)
1765 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1766 void *arg, MPContext *mpctx)
1768 if (!mpctx->sh_video)
1769 return M_PROPERTY_UNAVAILABLE;
1771 switch (action) {
1772 case M_PROPERTY_SET:
1773 if (!arg)
1774 return M_PROPERTY_ERROR;
1775 case M_PROPERTY_STEP_UP:
1776 case M_PROPERTY_STEP_DOWN:
1777 ass_force_reload = 1;
1778 default:
1779 return m_property_flag(prop, action, arg, &ass_use_margins);
1782 #endif
1784 /// Show only forced subtitles (RW)
1785 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1786 void *arg, MPContext *mpctx)
1788 if (!vo_spudec)
1789 return M_PROPERTY_UNAVAILABLE;
1791 switch (action) {
1792 case M_PROPERTY_SET:
1793 if (!arg)
1794 return M_PROPERTY_ERROR;
1795 case M_PROPERTY_STEP_UP:
1796 case M_PROPERTY_STEP_DOWN:
1797 m_property_flag(prop, action, arg, &forced_subs_only);
1798 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1799 return M_PROPERTY_OK;
1800 default:
1801 return m_property_flag(prop, action, arg, &forced_subs_only);
1806 #ifdef CONFIG_FREETYPE
1807 /// Subtitle scale (RW)
1808 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1809 MPContext *mpctx)
1812 switch (action) {
1813 case M_PROPERTY_SET:
1814 if (!arg)
1815 return M_PROPERTY_ERROR;
1816 M_PROPERTY_CLAMP(prop, *(float *) arg);
1817 #ifdef CONFIG_ASS
1818 if (ass_enabled) {
1819 ass_font_scale = *(float *) arg;
1820 ass_force_reload = 1;
1822 #endif
1823 text_font_scale_factor = *(float *) arg;
1824 force_load_font = 1;
1825 return M_PROPERTY_OK;
1826 case M_PROPERTY_STEP_UP:
1827 case M_PROPERTY_STEP_DOWN:
1828 #ifdef CONFIG_ASS
1829 if (ass_enabled) {
1830 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1831 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1832 M_PROPERTY_CLAMP(prop, ass_font_scale);
1833 ass_force_reload = 1;
1835 #endif
1836 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1837 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1838 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1839 force_load_font = 1;
1840 return M_PROPERTY_OK;
1841 default:
1842 #ifdef CONFIG_ASS
1843 if (ass_enabled)
1844 return m_property_float_ro(prop, action, arg, ass_font_scale);
1845 else
1846 #endif
1847 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1850 #endif
1852 ///@}
1854 /// \defgroup TVProperties TV properties
1855 /// \ingroup Properties
1856 ///@{
1858 #ifdef CONFIG_TV
1860 /// TV color settings (RW)
1861 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1862 MPContext *mpctx)
1864 int r, val;
1865 tvi_handle_t *tvh = mpctx->demuxer->priv;
1866 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1867 return M_PROPERTY_UNAVAILABLE;
1869 switch (action) {
1870 case M_PROPERTY_SET:
1871 if (!arg)
1872 return M_PROPERTY_ERROR;
1873 M_PROPERTY_CLAMP(prop, *(int *) arg);
1874 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1875 case M_PROPERTY_GET:
1876 return tv_get_color_options(tvh, (int) prop->priv, arg);
1877 case M_PROPERTY_STEP_UP:
1878 case M_PROPERTY_STEP_DOWN:
1879 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1880 if (!r)
1881 return M_PROPERTY_ERROR;
1882 val += (arg ? *(int *) arg : 1) *
1883 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1884 M_PROPERTY_CLAMP(prop, val);
1885 return tv_set_color_options(tvh, (int) prop->priv, val);
1887 return M_PROPERTY_ERROR;
1889 return M_PROPERTY_NOT_IMPLEMENTED;
1892 #endif
1894 #ifdef CONFIG_TV_TELETEXT
1895 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1896 MPContext *mpctx)
1898 int val,result;
1899 int base_ioctl=(int)prop->priv;
1901 for teletext's GET,SET,STEP ioctls this is not 0
1902 SET is GET+1
1903 STEP is GET+2
1905 tvi_handle_t *tvh = mpctx->demuxer->priv;
1906 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1907 return M_PROPERTY_UNAVAILABLE;
1908 if(!base_ioctl)
1909 return M_PROPERTY_ERROR;
1911 switch (action) {
1912 case M_PROPERTY_GET:
1913 if (!arg)
1914 return M_PROPERTY_ERROR;
1915 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1916 break;
1917 case M_PROPERTY_SET:
1918 if (!arg)
1919 return M_PROPERTY_ERROR;
1920 M_PROPERTY_CLAMP(prop, *(int *) arg);
1921 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1922 break;
1923 case M_PROPERTY_STEP_UP:
1924 case M_PROPERTY_STEP_DOWN:
1925 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1926 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1927 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1928 break;
1929 default:
1930 return M_PROPERTY_NOT_IMPLEMENTED;
1933 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1936 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
1937 MPContext *mpctx)
1939 tvi_handle_t *tvh = mpctx->demuxer->priv;
1940 int result;
1941 int val;
1943 //with tvh==NULL will fail too
1944 result=mp_property_teletext_common(prop,action,arg,mpctx);
1945 if(result!=M_PROPERTY_OK)
1946 return result;
1948 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1949 mp_input_set_section(mpctx->input, "teletext");
1950 else
1951 mp_input_set_section(mpctx->input, "tv");
1952 return M_PROPERTY_OK;
1955 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
1956 MPContext *mpctx)
1958 tvi_handle_t *tvh = mpctx->demuxer->priv;
1959 int result;
1960 int val;
1961 switch(action){
1962 case M_PROPERTY_STEP_UP:
1963 case M_PROPERTY_STEP_DOWN:
1964 //This should be handled separately
1965 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1966 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1967 break;
1968 default:
1969 result=mp_property_teletext_common(prop,action,arg,mpctx);
1971 return result;
1975 #endif /* CONFIG_TV_TELETEXT */
1977 ///@}
1979 /// All properties available in MPlayer.
1980 /** \ingroup Properties
1982 static const m_option_t mp_properties[] = {
1983 // General
1984 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1985 M_OPT_RANGE, 0, 3, NULL },
1986 { "loop", mp_property_loop, CONF_TYPE_INT,
1987 M_OPT_MIN, -1, 0, NULL },
1988 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1989 M_OPT_RANGE, 0.01, 100.0, NULL },
1990 { "filename", mp_property_filename, CONF_TYPE_STRING,
1991 0, 0, 0, NULL },
1992 { "path", mp_property_path, CONF_TYPE_STRING,
1993 0, 0, 0, NULL },
1994 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1995 0, 0, 0, NULL },
1996 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1997 M_OPT_MIN, 0, 0, NULL },
1998 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1999 M_OPT_MIN, 0, 0, NULL },
2000 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2001 M_OPT_MIN, 0, 0, NULL },
2002 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2003 M_OPT_MIN, 0, 0, NULL },
2004 { "length", mp_property_length, CONF_TYPE_TIME,
2005 M_OPT_MIN, 0, 0, NULL },
2006 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2007 M_OPT_RANGE, 0, 100, NULL },
2008 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2009 M_OPT_MIN, 0, 0, NULL },
2010 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2011 M_OPT_MIN, 1, 0, NULL },
2012 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2013 0, 0, 0, NULL },
2014 { "angle", mp_property_angle, CONF_TYPE_INT,
2015 CONF_RANGE, -2, 10, NULL },
2016 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2017 0, 0, 0, NULL },
2018 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2019 M_OPT_RANGE, 0, 1, NULL },
2021 // Audio
2022 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2023 M_OPT_RANGE, 0, 100, NULL },
2024 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2025 M_OPT_RANGE, 0, 1, NULL },
2026 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2027 M_OPT_RANGE, -100, 100, NULL },
2028 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2029 0, 0, 0, NULL },
2030 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2031 0, 0, 0, NULL },
2032 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2033 0, 0, 0, NULL },
2034 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2035 0, 0, 0, NULL },
2036 { "channels", mp_property_channels, CONF_TYPE_INT,
2037 0, 0, 0, NULL },
2038 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2039 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
2040 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2041 M_OPT_RANGE, -1, 1, NULL },
2043 // Video
2044 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2045 M_OPT_RANGE, 0, 1, NULL },
2046 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2047 M_OPT_RANGE, 0, 1, NULL },
2048 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2049 M_OPT_RANGE, 0, 1, NULL },
2050 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2051 M_OPT_RANGE, 0, 1, NULL },
2052 { "border", mp_property_border, CONF_TYPE_FLAG,
2053 M_OPT_RANGE, 0, 1, NULL },
2054 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2055 M_OPT_RANGE, 0, 2, NULL },
2056 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2057 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2058 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2059 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2060 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2061 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2062 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2063 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2064 { "hue", mp_property_gamma, CONF_TYPE_INT,
2065 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2066 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2067 M_OPT_RANGE, 0, 1, NULL },
2068 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2069 M_OPT_RANGE, 0, 1, NULL },
2070 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2071 0, 0, 0, NULL },
2072 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2073 0, 0, 0, NULL },
2074 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2075 0, 0, 0, NULL },
2076 { "width", mp_property_width, CONF_TYPE_INT,
2077 0, 0, 0, NULL },
2078 { "height", mp_property_height, CONF_TYPE_INT,
2079 0, 0, 0, NULL },
2080 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2081 0, 0, 0, NULL },
2082 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2083 0, 0, 0, NULL },
2084 { "switch_video", mp_property_video, CONF_TYPE_INT,
2085 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
2086 { "switch_program", mp_property_program, CONF_TYPE_INT,
2087 CONF_RANGE, -1, 65535, NULL },
2089 // Subs
2090 { "sub", mp_property_sub, CONF_TYPE_INT,
2091 M_OPT_MIN, -1, 0, NULL },
2092 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2093 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2094 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2095 M_OPT_MIN, -1, 0, NULL },
2096 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2097 M_OPT_MIN, -1, 0, NULL },
2098 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2099 M_OPT_MIN, -1, 0, NULL },
2100 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2101 0, 0, 0, NULL },
2102 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2103 M_OPT_RANGE, 0, 100, NULL },
2104 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2105 M_OPT_RANGE, 0, 2, NULL },
2106 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2107 M_OPT_RANGE, 0, 1, NULL },
2108 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2109 M_OPT_RANGE, 0, 1, NULL },
2110 #ifdef CONFIG_FREETYPE
2111 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2112 M_OPT_RANGE, 0, 100, NULL },
2113 #endif
2114 #ifdef CONFIG_ASS
2115 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2116 M_OPT_RANGE, 0, 1, NULL },
2117 #endif
2119 #ifdef CONFIG_TV
2120 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2121 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2122 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2123 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2124 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2125 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2126 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2127 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2128 #endif
2130 #ifdef CONFIG_TV_TELETEXT
2131 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2132 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2133 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2134 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2135 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2136 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2137 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2138 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2139 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2140 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2141 #endif
2143 { NULL, NULL, NULL, 0, 0, 0, NULL }
2147 int mp_property_do(const char *name, int action, void *val, void *ctx)
2149 return m_property_do(mp_properties, name, action, val, ctx);
2152 char* mp_property_print(const char *name, void* ctx)
2154 char* ret = NULL;
2155 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2156 return NULL;
2157 return ret;
2160 char *property_expand_string(MPContext *mpctx, char *str)
2162 return m_properties_expand_string(mp_properties, str, mpctx);
2165 void property_print_help(void)
2167 m_properties_print_help_list(mp_properties);
2171 ///@}
2172 // Properties group
2176 * \defgroup Command2Property Command to property bridge
2178 * It is used to handle most commands that just set a property
2179 * and optionally display something on the OSD.
2180 * Two kinds of commands are handled: adjust or toggle.
2182 * Adjust commands take 1 or 2 parameters: <value> <abs>
2183 * If <abs> is non-zero the property is set to the given value
2184 * otherwise it is adjusted.
2186 * Toggle commands take 0 or 1 parameters. With no parameter
2187 * or a value less than the property minimum it just steps the
2188 * property to its next value. Otherwise it sets it to the given
2189 * value.
2194 /// List of the commands that can be handled by setting a property.
2195 static struct {
2196 /// property name
2197 const char *name;
2198 /// cmd id
2199 int cmd;
2200 /// set/adjust or toggle command
2201 int toggle;
2202 /// progressbar type
2203 int osd_progbar;
2204 /// osd msg id if it must be shared
2205 int osd_id;
2206 /// osd msg template
2207 const char *osd_msg;
2208 } set_prop_cmd[] = {
2209 // general
2210 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2211 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2212 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2213 // audio
2214 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2215 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2216 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2217 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2218 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2219 // video
2220 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2221 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2222 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2223 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2224 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2225 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2226 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2227 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2228 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2229 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2230 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2231 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2232 // subs
2233 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2234 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2235 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2236 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2237 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2238 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2239 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2240 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2241 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2242 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2243 #ifdef CONFIG_FREETYPE
2244 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2245 #endif
2246 #ifdef CONFIG_ASS
2247 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2248 #endif
2249 #ifdef CONFIG_TV
2250 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2251 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2252 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2253 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2254 #endif
2255 { NULL, 0, 0, 0, -1, NULL }
2259 /// Handle commands that set a property.
2260 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2262 int i, r;
2263 m_option_t* prop;
2264 const char *pname;
2266 // look for the command
2267 for (i = 0; set_prop_cmd[i].name; i++)
2268 if (set_prop_cmd[i].cmd == cmd->id)
2269 break;
2270 if (!(pname = set_prop_cmd[i].name))
2271 return 0;
2273 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2274 return 0;
2276 // toggle command
2277 if (set_prop_cmd[i].toggle) {
2278 // set to value
2279 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2280 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2281 else
2282 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2283 } else if (cmd->args[1].v.i) //set
2284 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2285 else // adjust
2286 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2288 if (r <= 0)
2289 return 1;
2291 if (set_prop_cmd[i].osd_progbar) {
2292 if (prop->type == CONF_TYPE_INT) {
2293 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2294 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2295 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2296 } else if (prop->type == CONF_TYPE_FLOAT) {
2297 float f;
2298 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2299 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2300 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2301 } else
2302 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2303 "Property use an unsupported type.\n");
2304 return 1;
2307 if (set_prop_cmd[i].osd_msg) {
2308 char *val = mp_property_print(pname, mpctx);
2309 if (val) {
2310 set_osd_msg(set_prop_cmd[i].osd_id >=
2311 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2312 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2313 free(val);
2316 return 1;
2319 #ifdef CONFIG_DVDNAV
2320 static const struct {
2321 const char *name;
2322 const mp_command_type cmd;
2323 } mp_dvdnav_bindings[] = {
2324 { "up", MP_CMD_DVDNAV_UP },
2325 { "down", MP_CMD_DVDNAV_DOWN },
2326 { "left", MP_CMD_DVDNAV_LEFT },
2327 { "right", MP_CMD_DVDNAV_RIGHT },
2328 { "menu", MP_CMD_DVDNAV_MENU },
2329 { "select", MP_CMD_DVDNAV_SELECT },
2330 { "prev", MP_CMD_DVDNAV_PREVMENU },
2331 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2334 * keep old dvdnav sub-command options for a while in order not to
2335 * break slave-mode API too suddenly.
2337 { "1", MP_CMD_DVDNAV_UP },
2338 { "2", MP_CMD_DVDNAV_DOWN },
2339 { "3", MP_CMD_DVDNAV_LEFT },
2340 { "4", MP_CMD_DVDNAV_RIGHT },
2341 { "5", MP_CMD_DVDNAV_MENU },
2342 { "6", MP_CMD_DVDNAV_SELECT },
2343 { "7", MP_CMD_DVDNAV_PREVMENU },
2344 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2345 { NULL, 0 }
2347 #endif
2349 int run_command(MPContext *mpctx, mp_cmd_t *cmd)
2351 struct MPOpts *opts = &mpctx->opts;
2352 sh_audio_t * const sh_audio = mpctx->sh_audio;
2353 sh_video_t * const sh_video = mpctx->sh_video;
2354 int brk_cmd = 0;
2355 if (!set_property_command(mpctx, cmd))
2356 switch (cmd->id) {
2357 case MP_CMD_SEEK:{
2358 float v;
2359 int abs;
2360 if (sh_video)
2361 mpctx->osd_show_percentage = sh_video->fps;
2362 v = cmd->args[0].v.f;
2363 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2364 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2365 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2366 if (sh_video)
2367 mpctx->osd_function =
2368 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2369 mpctx->rel_seek_secs = v;
2370 } else if (abs) { /* Absolute seek by percentage */
2371 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2372 if (sh_video)
2373 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2374 mpctx->rel_seek_secs = v / 100.0;
2375 } else {
2376 mpctx->rel_seek_secs += v;
2377 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2379 brk_cmd = 1;
2381 break;
2383 case MP_CMD_SET_PROPERTY:{
2384 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2385 cmd->args[1].v.s, mpctx);
2386 if (r == M_PROPERTY_UNKNOWN)
2387 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2388 "Unknown property: '%s'\n", cmd->args[0].v.s);
2389 else if (r <= 0)
2390 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2391 "Failed to set property '%s' to '%s'.\n",
2392 cmd->args[0].v.s, cmd->args[1].v.s);
2394 break;
2396 case MP_CMD_STEP_PROPERTY:{
2397 void* arg = NULL;
2398 int r,i;
2399 double d;
2400 off_t o;
2401 if (cmd->args[1].v.f) {
2402 m_option_t* prop;
2403 if((r = mp_property_do(cmd->args[0].v.s,
2404 M_PROPERTY_GET_TYPE,
2405 &prop, mpctx)) <= 0)
2406 goto step_prop_err;
2407 if(prop->type == CONF_TYPE_INT ||
2408 prop->type == CONF_TYPE_FLAG)
2409 i = cmd->args[1].v.f, arg = &i;
2410 else if(prop->type == CONF_TYPE_FLOAT)
2411 arg = &cmd->args[1].v.f;
2412 else if(prop->type == CONF_TYPE_DOUBLE ||
2413 prop->type == CONF_TYPE_TIME)
2414 d = cmd->args[1].v.f, arg = &d;
2415 else if(prop->type == CONF_TYPE_POSITION)
2416 o = cmd->args[1].v.f, arg = &o;
2417 else
2418 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2419 "Ignoring step size stepping property '%s'.\n",
2420 cmd->args[0].v.s);
2422 r = mp_property_do(cmd->args[0].v.s,
2423 cmd->args[2].v.i < 0 ?
2424 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2425 arg, mpctx);
2426 step_prop_err:
2427 if (r == M_PROPERTY_UNKNOWN)
2428 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2429 "Unknown property: '%s'\n", cmd->args[0].v.s);
2430 else if (r <= 0)
2431 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2432 "Failed to increment property '%s' by %f.\n",
2433 cmd->args[0].v.s, cmd->args[1].v.f);
2435 break;
2437 case MP_CMD_GET_PROPERTY:{
2438 char *tmp;
2439 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2440 &tmp, mpctx) <= 0) {
2441 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2442 "Failed to get value of property '%s'.\n",
2443 cmd->args[0].v.s);
2444 break;
2446 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2447 cmd->args[0].v.s, tmp);
2448 free(tmp);
2450 break;
2452 case MP_CMD_EDL_MARK:
2453 if (edl_fd) {
2454 float v = sh_video ? sh_video->pts :
2455 playing_audio_pts(mpctx);
2456 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2457 mpctx->begin_skip = v;
2458 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2459 } else {
2460 if (mpctx->begin_skip > v)
2461 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2462 else {
2463 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2464 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2466 mpctx->begin_skip = MP_NOPTS_VALUE;
2469 break;
2471 case MP_CMD_SWITCH_RATIO:
2472 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2473 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2474 else
2475 opts->movie_aspect = cmd->args[0].v.f;
2476 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2477 break;
2479 case MP_CMD_SPEED_INCR:{
2480 float v = cmd->args[0].v.f;
2481 opts->playback_speed += v;
2482 build_afilter_chain(mpctx, sh_audio, &ao_data);
2483 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2484 opts->playback_speed);
2485 } break;
2487 case MP_CMD_SPEED_MULT:{
2488 float v = cmd->args[0].v.f;
2489 opts->playback_speed *= v;
2490 build_afilter_chain(mpctx, sh_audio, &ao_data);
2491 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2492 opts->playback_speed);
2493 } break;
2495 case MP_CMD_SPEED_SET:{
2496 float v = cmd->args[0].v.f;
2497 opts->playback_speed = v;
2498 build_afilter_chain(mpctx, sh_audio, &ao_data);
2499 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2500 opts->playback_speed);
2501 } break;
2503 case MP_CMD_FRAME_STEP:
2504 case MP_CMD_PAUSE:
2505 cmd->pausing = 1;
2506 brk_cmd = 1;
2507 break;
2509 case MP_CMD_FILE_FILTER:
2510 file_filter = cmd->args[0].v.i;
2511 break;
2513 case MP_CMD_QUIT:
2514 exit_player_with_rc(mpctx, MSGTR_Exit_quit,
2515 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2517 case MP_CMD_PLAY_TREE_STEP:{
2518 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2519 int force = cmd->args[1].v.i;
2521 #ifdef CONFIG_GUI
2522 if (use_gui) {
2523 int i = 0;
2524 if (n > 0)
2525 for (i = 0; i < n; i++)
2526 mplNext();
2527 else
2528 for (i = 0; i < -1 * n; i++)
2529 mplPrev();
2530 } else
2531 #endif
2533 if (!force && mpctx->playtree_iter) {
2534 play_tree_iter_t *i =
2535 play_tree_iter_new_copy(mpctx->playtree_iter);
2536 if (play_tree_iter_step(i, n, 0) ==
2537 PLAY_TREE_ITER_ENTRY)
2538 mpctx->stop_play =
2539 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2540 play_tree_iter_free(i);
2541 } else
2542 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2543 if (mpctx->stop_play)
2544 mpctx->play_tree_step = n;
2545 brk_cmd = 1;
2548 break;
2550 case MP_CMD_PLAY_TREE_UP_STEP:{
2551 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2552 int force = cmd->args[1].v.i;
2554 if (!force && mpctx->playtree_iter) {
2555 play_tree_iter_t *i =
2556 play_tree_iter_new_copy(mpctx->playtree_iter);
2557 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2558 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2559 play_tree_iter_free(i);
2560 } else
2561 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2562 brk_cmd = 1;
2564 break;
2566 case MP_CMD_PLAY_ALT_SRC_STEP:
2567 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2568 int v = cmd->args[0].v.i;
2569 if (v > 0
2570 && mpctx->playtree_iter->file <
2571 mpctx->playtree_iter->num_files)
2572 mpctx->stop_play = PT_NEXT_SRC;
2573 else if (v < 0 && mpctx->playtree_iter->file > 1)
2574 mpctx->stop_play = PT_PREV_SRC;
2576 brk_cmd = 1;
2577 break;
2579 case MP_CMD_SUB_STEP:
2580 if (sh_video) {
2581 int movement = cmd->args[0].v.i;
2582 step_sub(subdata, sh_video->pts, movement);
2583 #ifdef CONFIG_ASS
2584 if (ass_track)
2585 sub_delay +=
2586 ass_step_sub(ass_track,
2587 (sh_video->pts +
2588 sub_delay) * 1000 + .5, movement) / 1000.;
2589 #endif
2590 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2591 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2593 break;
2595 case MP_CMD_SUB_LOG:
2596 log_sub(mpctx);
2597 break;
2599 case MP_CMD_OSD:{
2600 int v = cmd->args[0].v.i;
2601 int max = (term_osd
2602 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2603 if (osd_level > max)
2604 osd_level = max;
2605 if (v < 0)
2606 osd_level = (osd_level + 1) % (max + 1);
2607 else
2608 osd_level = v > max ? max : v;
2609 /* Show OSD state when disabled, but not when an explicit
2610 argument is given to the OSD command, i.e. in slave mode. */
2611 if (v == -1 && osd_level <= 1)
2612 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2613 MSGTR_OSDosd,
2614 osd_level ? MSGTR_OSDenabled :
2615 MSGTR_OSDdisabled);
2616 else
2617 rm_osd_msg(OSD_MSG_OSD_STATUS);
2619 break;
2621 case MP_CMD_OSD_SHOW_TEXT:
2622 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2623 (cmd->args[1].v.i <
2624 0 ? osd_duration : cmd->args[1].v.i),
2625 "%-.63s", cmd->args[0].v.s);
2626 break;
2628 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2629 char *txt = m_properties_expand_string(mp_properties,
2630 cmd->args[0].v.s,
2631 mpctx);
2632 /* if no argument supplied take default osd_duration, else <arg> ms. */
2633 if (txt) {
2634 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2635 (cmd->args[1].v.i <
2636 0 ? osd_duration : cmd->args[1].v.i),
2637 "%-.63s", txt);
2638 free(txt);
2641 break;
2643 case MP_CMD_LOADFILE:{
2644 play_tree_t *e = play_tree_new();
2645 play_tree_add_file(e, cmd->args[0].v.s);
2647 if (cmd->args[1].v.i) // append
2648 play_tree_append_entry(mpctx->playtree->child, e);
2649 else {
2650 // Go back to the starting point.
2651 while (play_tree_iter_up_step
2652 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2653 /* NOP */ ;
2654 play_tree_free_list(mpctx->playtree->child, 1);
2655 play_tree_set_child(mpctx->playtree, e);
2656 pt_iter_goto_head(mpctx->playtree_iter);
2657 mpctx->stop_play = PT_NEXT_SRC;
2659 brk_cmd = 1;
2661 break;
2663 case MP_CMD_LOADLIST:{
2664 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2665 if (!e)
2666 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2667 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2668 else {
2669 if (cmd->args[1].v.i) // append
2670 play_tree_append_entry(mpctx->playtree->child, e);
2671 else {
2672 // Go back to the starting point.
2673 while (play_tree_iter_up_step
2674 (mpctx->playtree_iter, 0, 1)
2675 != PLAY_TREE_ITER_END)
2676 /* NOP */ ;
2677 play_tree_free_list(mpctx->playtree->child, 1);
2678 play_tree_set_child(mpctx->playtree, e);
2679 pt_iter_goto_head(mpctx->playtree_iter);
2680 mpctx->stop_play = PT_NEXT_SRC;
2683 brk_cmd = 1;
2685 break;
2687 case MP_CMD_STOP:
2688 // Go back to the starting point.
2689 while (play_tree_iter_up_step
2690 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2691 /* NOP */ ;
2692 mpctx->stop_play = PT_STOP;
2693 brk_cmd = 1;
2694 break;
2696 #ifdef CONFIG_RADIO
2697 case MP_CMD_RADIO_STEP_CHANNEL:
2698 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2699 int v = cmd->args[0].v.i;
2700 if (v > 0)
2701 radio_step_channel(mpctx->demuxer->stream,
2702 RADIO_CHANNEL_HIGHER);
2703 else
2704 radio_step_channel(mpctx->demuxer->stream,
2705 RADIO_CHANNEL_LOWER);
2706 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2707 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2708 MSGTR_OSDChannel,
2709 radio_get_channel_name(mpctx->demuxer->stream));
2712 break;
2714 case MP_CMD_RADIO_SET_CHANNEL:
2715 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2716 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2717 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2718 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2719 MSGTR_OSDChannel,
2720 radio_get_channel_name(mpctx->demuxer->stream));
2723 break;
2725 case MP_CMD_RADIO_SET_FREQ:
2726 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2727 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2728 break;
2730 case MP_CMD_RADIO_STEP_FREQ:
2731 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2732 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2733 break;
2734 #endif
2736 #ifdef CONFIG_TV
2737 case MP_CMD_TV_START_SCAN:
2738 if (mpctx->file_format == DEMUXER_TYPE_TV)
2739 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2740 break;
2741 case MP_CMD_TV_SET_FREQ:
2742 if (mpctx->file_format == DEMUXER_TYPE_TV)
2743 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2744 cmd->args[0].v.f * 16.0);
2745 #ifdef CONFIG_PVR
2746 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2747 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2748 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2749 pvr_get_current_channelname (mpctx->stream),
2750 pvr_get_current_stationname (mpctx->stream));
2752 #endif /* CONFIG_PVR */
2753 break;
2755 case MP_CMD_TV_STEP_FREQ:
2756 if (mpctx->file_format == DEMUXER_TYPE_TV)
2757 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2758 cmd->args[0].v.f * 16.0);
2759 #ifdef CONFIG_PVR
2760 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2761 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2762 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2763 pvr_get_current_channelname (mpctx->stream),
2764 pvr_get_current_frequency (mpctx->stream));
2766 #endif /* CONFIG_PVR */
2767 break;
2769 case MP_CMD_TV_SET_NORM:
2770 if (mpctx->file_format == DEMUXER_TYPE_TV)
2771 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2772 cmd->args[0].v.s);
2773 break;
2775 case MP_CMD_TV_STEP_CHANNEL:{
2776 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2777 int v = cmd->args[0].v.i;
2778 if (v > 0) {
2779 tv_step_channel((tvi_handle_t *) (mpctx->
2780 demuxer->priv),
2781 TV_CHANNEL_HIGHER);
2782 } else {
2783 tv_step_channel((tvi_handle_t *) (mpctx->
2784 demuxer->priv),
2785 TV_CHANNEL_LOWER);
2787 if (tv_channel_list) {
2788 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2789 MSGTR_OSDChannel, tv_channel_current->name);
2790 //vo_osd_changed(OSDTYPE_SUBTITLE);
2793 #ifdef CONFIG_PVR
2794 else if (mpctx->stream &&
2795 mpctx->stream->type == STREAMTYPE_PVR) {
2796 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2797 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2798 pvr_get_current_channelname (mpctx->stream),
2799 pvr_get_current_stationname (mpctx->stream));
2801 #endif /* CONFIG_PVR */
2803 #ifdef CONFIG_DVBIN
2804 if (mpctx->stream->type == STREAMTYPE_DVB) {
2805 int dir;
2806 int v = cmd->args[0].v.i;
2808 mpctx->last_dvb_step = v;
2809 if (v > 0)
2810 dir = DVB_CHANNEL_HIGHER;
2811 else
2812 dir = DVB_CHANNEL_LOWER;
2815 if (dvb_step_channel(mpctx->stream, dir)) {
2816 mpctx->stop_play = PT_NEXT_ENTRY;
2817 mpctx->dvbin_reopen = 1;
2820 #endif /* CONFIG_DVBIN */
2821 break;
2823 case MP_CMD_TV_SET_CHANNEL:
2824 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2825 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2826 cmd->args[0].v.s);
2827 if (tv_channel_list) {
2828 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2829 MSGTR_OSDChannel, tv_channel_current->name);
2830 //vo_osd_changed(OSDTYPE_SUBTITLE);
2833 #ifdef CONFIG_PVR
2834 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2835 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2836 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2837 pvr_get_current_channelname (mpctx->stream),
2838 pvr_get_current_stationname (mpctx->stream));
2840 #endif /* CONFIG_PVR */
2841 break;
2843 #ifdef CONFIG_DVBIN
2844 case MP_CMD_DVB_SET_CHANNEL:
2845 if (mpctx->stream->type == STREAMTYPE_DVB) {
2846 mpctx->last_dvb_step = 1;
2848 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
2849 cmd->args[0].v.i)) {
2850 mpctx->stop_play = PT_NEXT_ENTRY;
2851 mpctx->dvbin_reopen = 1;
2854 break;
2855 #endif /* CONFIG_DVBIN */
2857 case MP_CMD_TV_LAST_CHANNEL:
2858 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2859 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2860 if (tv_channel_list) {
2861 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2862 MSGTR_OSDChannel, tv_channel_current->name);
2863 //vo_osd_changed(OSDTYPE_SUBTITLE);
2866 #ifdef CONFIG_PVR
2867 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2868 pvr_set_lastchannel (mpctx->stream);
2869 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2870 pvr_get_current_channelname (mpctx->stream),
2871 pvr_get_current_stationname (mpctx->stream));
2873 #endif /* CONFIG_PVR */
2874 break;
2876 case MP_CMD_TV_STEP_NORM:
2877 if (mpctx->file_format == DEMUXER_TYPE_TV)
2878 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2879 break;
2881 case MP_CMD_TV_STEP_CHANNEL_LIST:
2882 if (mpctx->file_format == DEMUXER_TYPE_TV)
2883 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2884 break;
2885 #ifdef CONFIG_TV_TELETEXT
2886 case MP_CMD_TV_TELETEXT_ADD_DEC:
2888 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2889 if (mpctx->file_format == DEMUXER_TYPE_TV)
2890 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2891 break;
2893 case MP_CMD_TV_TELETEXT_GO_LINK:
2895 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2896 if (mpctx->file_format == DEMUXER_TYPE_TV)
2897 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2898 break;
2900 #endif /* CONFIG_TV_TELETEXT */
2901 #endif /* CONFIG_TV */
2903 case MP_CMD_SUB_LOAD:
2904 if (sh_video) {
2905 int n = mpctx->set_of_sub_size;
2906 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
2907 if (n != mpctx->set_of_sub_size) {
2908 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2909 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2910 mpctx->global_sub_size;
2911 ++mpctx->global_sub_size;
2914 break;
2916 case MP_CMD_SUB_REMOVE:
2917 if (sh_video) {
2918 int v = cmd->args[0].v.i;
2919 sub_data *subd;
2920 if (v < 0) {
2921 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2922 subd = mpctx->set_of_subtitles[v];
2923 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2924 MSGTR_RemovedSubtitleFile, v + 1,
2925 filename_recode(subd->filename));
2926 sub_free(subd);
2927 mpctx->set_of_subtitles[v] = NULL;
2929 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2930 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2931 mpctx->set_of_sub_size = 0;
2932 if (mpctx->set_of_sub_pos >= 0) {
2933 mpctx->global_sub_pos = -2;
2934 subdata = NULL;
2935 mp_input_queue_cmd(mpctx->input,
2936 mp_input_parse_cmd("sub_select"));
2938 } else if (v < mpctx->set_of_sub_size) {
2939 subd = mpctx->set_of_subtitles[v];
2940 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2941 MSGTR_RemovedSubtitleFile, v + 1,
2942 filename_recode(subd->filename));
2943 sub_free(subd);
2944 if (mpctx->set_of_sub_pos == v) {
2945 mpctx->global_sub_pos = -2;
2946 subdata = NULL;
2947 mp_input_queue_cmd(mpctx->input,
2948 mp_input_parse_cmd("sub_select"));
2949 } else if (mpctx->set_of_sub_pos > v) {
2950 --mpctx->set_of_sub_pos;
2951 --mpctx->global_sub_pos;
2953 while (++v < mpctx->set_of_sub_size)
2954 mpctx->set_of_subtitles[v - 1] =
2955 mpctx->set_of_subtitles[v];
2956 --mpctx->set_of_sub_size;
2957 --mpctx->global_sub_size;
2958 if (mpctx->set_of_sub_size <= 0)
2959 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2960 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2963 break;
2965 case MP_CMD_GET_SUB_VISIBILITY:
2966 if (sh_video) {
2967 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2968 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2970 break;
2972 case MP_CMD_SCREENSHOT:
2973 if (mpctx->video_out && mpctx->video_out->config_ok) {
2974 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2975 if (CONTROL_OK !=
2976 ((vf_instance_t *) sh_video->vfilter)->
2977 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2978 &cmd->args[0].v.i))
2979 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2981 break;
2983 case MP_CMD_VF_CHANGE_RECTANGLE:
2984 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2985 break;
2987 case MP_CMD_GET_TIME_LENGTH:{
2988 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2989 demuxer_get_time_length(mpctx->demuxer));
2991 break;
2993 case MP_CMD_GET_FILENAME:{
2994 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2995 get_metadata(mpctx, META_NAME));
2997 break;
2999 case MP_CMD_GET_VIDEO_CODEC:{
3000 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3001 if (!inf)
3002 inf = strdup("");
3003 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3004 free(inf);
3006 break;
3008 case MP_CMD_GET_VIDEO_BITRATE:{
3009 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3010 if (!inf)
3011 inf = strdup("");
3012 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3013 free(inf);
3015 break;
3017 case MP_CMD_GET_VIDEO_RESOLUTION:{
3018 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3019 if (!inf)
3020 inf = strdup("");
3021 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3022 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3023 free(inf);
3025 break;
3027 case MP_CMD_GET_AUDIO_CODEC:{
3028 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3029 if (!inf)
3030 inf = strdup("");
3031 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3032 free(inf);
3034 break;
3036 case MP_CMD_GET_AUDIO_BITRATE:{
3037 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3038 if (!inf)
3039 inf = strdup("");
3040 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3041 free(inf);
3043 break;
3045 case MP_CMD_GET_AUDIO_SAMPLES:{
3046 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3047 if (!inf)
3048 inf = strdup("");
3049 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3050 free(inf);
3052 break;
3054 case MP_CMD_GET_META_TITLE:{
3055 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3056 if (!inf)
3057 inf = strdup("");
3058 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3059 free(inf);
3061 break;
3063 case MP_CMD_GET_META_ARTIST:{
3064 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3065 if (!inf)
3066 inf = strdup("");
3067 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3068 free(inf);
3070 break;
3072 case MP_CMD_GET_META_ALBUM:{
3073 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3074 if (!inf)
3075 inf = strdup("");
3076 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3077 free(inf);
3079 break;
3081 case MP_CMD_GET_META_YEAR:{
3082 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3083 if (!inf)
3084 inf = strdup("");
3085 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3086 free(inf);
3088 break;
3090 case MP_CMD_GET_META_COMMENT:{
3091 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3092 if (!inf)
3093 inf = strdup("");
3094 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3095 free(inf);
3097 break;
3099 case MP_CMD_GET_META_TRACK:{
3100 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3101 if (!inf)
3102 inf = strdup("");
3103 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3104 free(inf);
3106 break;
3108 case MP_CMD_GET_META_GENRE:{
3109 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3110 if (!inf)
3111 inf = strdup("");
3112 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3113 free(inf);
3115 break;
3117 case MP_CMD_GET_VO_FULLSCREEN:
3118 if (mpctx->video_out && mpctx->video_out->config_ok)
3119 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3120 break;
3122 case MP_CMD_GET_PERCENT_POS:
3123 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3124 demuxer_get_percent_pos(mpctx->demuxer));
3125 break;
3127 case MP_CMD_GET_TIME_POS:{
3128 float pos = 0;
3129 if (sh_video)
3130 pos = sh_video->pts;
3131 else if (sh_audio && mpctx->audio_out)
3132 pos = playing_audio_pts(mpctx);
3133 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3135 break;
3137 case MP_CMD_RUN:
3138 #ifndef __MINGW32__
3139 if (!fork()) {
3140 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3141 exit(0);
3143 #endif
3144 break;
3146 case MP_CMD_KEYDOWN_EVENTS:
3147 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3148 break;
3150 case MP_CMD_SET_MOUSE_POS:{
3151 int pointer_x, pointer_y;
3152 double dx, dy;
3153 pointer_x = cmd->args[0].v.i;
3154 pointer_y = cmd->args[1].v.i;
3155 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3156 #ifdef CONFIG_DVDNAV
3157 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3158 && dx > 0.0 && dy > 0.0) {
3159 int button = -1;
3160 pointer_x = (int) (dx * (double) sh_video->disp_w);
3161 pointer_y = (int) (dy * (double) sh_video->disp_h);
3162 mp_dvdnav_update_mouse_pos(mpctx->stream,
3163 pointer_x, pointer_y, &button);
3164 if (osd_level > 1 && button > 0)
3165 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3166 "Selected button number %d", button);
3168 #endif
3169 #ifdef CONFIG_MENU
3170 if (use_menu && dx >= 0.0 && dy >= 0.0)
3171 menu_update_mouse_pos(dx, dy);
3172 #endif
3174 break;
3176 #ifdef CONFIG_DVDNAV
3177 case MP_CMD_DVDNAV:{
3178 int button = -1;
3179 int i;
3180 mp_command_type command = 0;
3181 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3182 break;
3184 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3185 if (cmd->args[0].v.s &&
3186 !strcasecmp (cmd->args[0].v.s,
3187 mp_dvdnav_bindings[i].name))
3188 command = mp_dvdnav_bindings[i].cmd;
3190 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3191 if (osd_level > 1 && button > 0)
3192 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3193 "Selected button number %d", button);
3195 break;
3197 case MP_CMD_SWITCH_TITLE:
3198 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3199 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3200 break;
3202 #endif
3204 default:
3205 #ifdef CONFIG_GUI
3206 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3207 guiGetEvent(guiIEvent, (char *) cmd->id);
3208 else
3209 #endif
3210 mp_msg(MSGT_CPLAYER, MSGL_V,
3211 "Received unknown cmd %s\n", cmd->name);
3214 switch (cmd->pausing) {
3215 case 1: // "pausing"
3216 mpctx->osd_function = OSD_PAUSE;
3217 break;
3218 case 3: // "pausing_toggle"
3219 mpctx->was_paused = !mpctx->was_paused;
3220 if (mpctx->was_paused)
3221 mpctx->osd_function = OSD_PAUSE;
3222 else if (mpctx->osd_function == OSD_PAUSE)
3223 mpctx->osd_function = OSD_PLAY;
3224 break;
3225 case 2: // "pausing_keep"
3226 if (mpctx->was_paused)
3227 mpctx->osd_function = OSD_PAUSE;
3229 return brk_cmd;