Disallow subtitles without video
[mplayer.git] / command.c
blob88f0a663ddcf3ec766c05f0cac861e7515cae50b
1 #include <stdlib.h>
2 #include <inttypes.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <stdbool.h>
7 #include "config.h"
8 #include "talloc.h"
9 #include "command.h"
10 #include "input/input.h"
11 #include "stream/stream.h"
12 #include "libmpdemux/demuxer.h"
13 #include "libmpdemux/stheader.h"
14 #include "codec-cfg.h"
15 #include "mplayer.h"
16 #include "libvo/sub.h"
17 #include "m_option.h"
18 #include "m_property.h"
19 #include "help_mp.h"
20 #include "metadata.h"
21 #include "libmpcodecs/vf.h"
22 #include "libmpcodecs/vd.h"
23 #include "mp_osd.h"
24 #include "libvo/video_out.h"
25 #include "libvo/font_load.h"
26 #include "playtree.h"
27 #include "libao2/audio_out.h"
28 #include "mpcommon.h"
29 #include "mixer.h"
30 #include "libmpcodecs/dec_video.h"
31 #include "vobsub.h"
32 #include "spudec.h"
33 #include "get_path.h"
34 #ifdef CONFIG_TV
35 #include "stream/tv.h"
36 #endif
37 #ifdef CONFIG_RADIO
38 #include "stream/stream_radio.h"
39 #endif
40 #ifdef CONFIG_PVR
41 #include "stream/pvr.h"
42 #endif
43 #ifdef CONFIG_DVBIN
44 #include "stream/dvbin.h"
45 #endif
46 #ifdef CONFIG_DVDREAD
47 #include "stream/stream_dvd.h"
48 #endif
49 #ifdef CONFIG_DVDNAV
50 #include "stream/stream_dvdnav.h"
51 #endif
52 #ifdef CONFIG_ASS
53 #include "libass/ass.h"
54 #include "libass/ass_mp.h"
55 #endif
56 #ifdef CONFIG_MENU
57 #include "m_struct.h"
58 #include "libmenu/menu.h"
59 #endif
60 #ifdef CONFIG_GUI
61 #include "gui/interface.h"
62 #endif
64 #include "mp_core.h"
65 #include "mp_fifo.h"
66 #include "libavutil/avstring.h"
68 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
70 extern int use_menu;
72 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
73 double *dx, double *dy)
75 struct MPOpts *opts = &mpctx->opts;
76 struct vo *vo = mpctx->video_out;
77 //remove the borders, if any, and rescale to the range [0,1],[0,1]
78 if (vo_fs) { //we are in full-screen mode
79 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
80 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
81 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
82 iy -= (opts->vo_screenheight - vo->dheight) / 2;
84 if (ix < 0 || ix > vo->dwidth) {
85 *dx = *dy = -1.0;
86 return;
87 } //we are on one of the borders
88 if (iy < 0 || iy > vo->dheight) {
89 *dx = *dy = -1.0;
90 return;
91 } //we are on one of the borders
94 *dx = (double) ix / (double) vo->dwidth;
95 *dy = (double) iy / (double) vo->dheight;
97 mp_msg(MSGT_CPLAYER, MSGL_V,
98 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
99 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
100 vo->dheight, vo_fs);
103 static int sub_source_by_pos(MPContext *mpctx, int pos)
105 int source = -1;
106 int top = -1;
107 int i;
108 for (i = 0; i < SUB_SOURCES; i++) {
109 int j = mpctx->global_sub_indices[i];
110 if ((j >= 0) && (j > top) && (pos >= j)) {
111 source = i;
112 top = j;
115 return source;
118 static int sub_source(MPContext *mpctx)
120 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
124 * \brief Log the currently displayed subtitle to a file
126 * Logs the current or last displayed subtitle together with filename
127 * and time information to ~/.mplayer/subtitle_log
129 * Intended purpose is to allow convenient marking of bogus subtitles
130 * which need to be fixed while watching the movie.
133 static void log_sub(struct MPContext *mpctx)
135 char *fname;
136 FILE *f;
137 int i;
139 if (subdata == NULL || vo_sub_last == NULL)
140 return;
141 fname = get_path("subtitle_log");
142 f = fopen(fname, "a");
143 if (!f)
144 return;
145 fprintf(f, "----------------------------------------------------------\n");
146 if (subdata->sub_uses_time) {
147 fprintf(f,
148 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
149 mpctx->filename, vo_sub_last->start / 360000,
150 (vo_sub_last->start / 6000) % 60,
151 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
152 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
153 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
154 } else {
155 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
156 vo_sub_last->start, vo_sub_last->end);
158 for (i = 0; i < vo_sub_last->lines; i++) {
159 fprintf(f, "%s\n", vo_sub_last->text[i]);
161 fclose(f);
165 /// \defgroup Properties
166 ///@{
168 /// \defgroup GeneralProperties General properties
169 /// \ingroup Properties
170 ///@{
172 /// OSD level (RW)
173 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
174 MPContext *mpctx)
176 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
179 /// Loop (RW)
180 static int mp_property_loop(m_option_t *prop, int action, void *arg,
181 MPContext *mpctx)
183 struct MPOpts *opts = &mpctx->opts;
184 switch (action) {
185 case M_PROPERTY_PRINT:
186 if (!arg) return M_PROPERTY_ERROR;
187 if (opts->loop_times < 0)
188 *(char**)arg = strdup("off");
189 else if (opts->loop_times == 0)
190 *(char**)arg = strdup("inf");
191 else
192 break;
193 return M_PROPERTY_OK;
195 return m_property_int_range(prop, action, arg, &opts->loop_times);
198 /// Playback speed (RW)
199 static int mp_property_playback_speed(m_option_t *prop, int action,
200 void *arg, MPContext *mpctx)
202 struct MPOpts *opts = &mpctx->opts;
203 switch (action) {
204 case M_PROPERTY_SET:
205 if (!arg)
206 return M_PROPERTY_ERROR;
207 M_PROPERTY_CLAMP(prop, *(float *) arg);
208 opts->playback_speed = *(float *) arg;
209 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
210 return M_PROPERTY_OK;
211 case M_PROPERTY_STEP_UP:
212 case M_PROPERTY_STEP_DOWN:
213 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
214 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
215 M_PROPERTY_CLAMP(prop, opts->playback_speed);
216 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
217 return M_PROPERTY_OK;
219 return m_property_float_range(prop, action, arg, &opts->playback_speed);
222 /// filename with path (RO)
223 static int mp_property_path(m_option_t *prop, int action, void *arg,
224 MPContext *mpctx)
226 return m_property_string_ro(prop, action, arg, mpctx->filename);
229 /// filename without path (RO)
230 static int mp_property_filename(m_option_t *prop, int action, void *arg,
231 MPContext *mpctx)
233 char *f;
234 if (!mpctx->filename)
235 return M_PROPERTY_UNAVAILABLE;
236 if (((f = strrchr(mpctx->filename, '/'))
237 || (f = strrchr(mpctx->filename, '\\'))) && f[1])
238 f++;
239 else
240 f = mpctx->filename;
241 return m_property_string_ro(prop, action, arg, f);
244 /// Demuxer name (RO)
245 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
246 MPContext *mpctx)
248 if (!mpctx->demuxer)
249 return M_PROPERTY_UNAVAILABLE;
250 return m_property_string_ro(prop, action, arg,
251 (char *) mpctx->demuxer->desc->name);
254 /// Position in the stream (RW)
255 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
256 MPContext *mpctx)
258 if (!mpctx->demuxer || !mpctx->demuxer->stream)
259 return M_PROPERTY_UNAVAILABLE;
260 if (!arg)
261 return M_PROPERTY_ERROR;
262 switch (action) {
263 case M_PROPERTY_GET:
264 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
265 return M_PROPERTY_OK;
266 case M_PROPERTY_SET:
267 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
268 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
269 return M_PROPERTY_OK;
271 return M_PROPERTY_NOT_IMPLEMENTED;
274 /// Stream start offset (RO)
275 static int mp_property_stream_start(m_option_t *prop, int action,
276 void *arg, MPContext *mpctx)
278 if (!mpctx->demuxer || !mpctx->demuxer->stream)
279 return M_PROPERTY_UNAVAILABLE;
280 switch (action) {
281 case M_PROPERTY_GET:
282 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
283 return M_PROPERTY_OK;
285 return M_PROPERTY_NOT_IMPLEMENTED;
288 /// Stream end offset (RO)
289 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
290 MPContext *mpctx)
292 if (!mpctx->demuxer || !mpctx->demuxer->stream)
293 return M_PROPERTY_UNAVAILABLE;
294 switch (action) {
295 case M_PROPERTY_GET:
296 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
297 return M_PROPERTY_OK;
299 return M_PROPERTY_NOT_IMPLEMENTED;
302 /// Stream length (RO)
303 static int mp_property_stream_length(m_option_t *prop, int action,
304 void *arg, MPContext *mpctx)
306 if (!mpctx->demuxer || !mpctx->demuxer->stream)
307 return M_PROPERTY_UNAVAILABLE;
308 switch (action) {
309 case M_PROPERTY_GET:
310 *(off_t *) arg =
311 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
312 return M_PROPERTY_OK;
314 return M_PROPERTY_NOT_IMPLEMENTED;
317 /// Media length in seconds (RO)
318 static int mp_property_length(m_option_t *prop, int action, void *arg,
319 MPContext *mpctx)
321 double len;
323 if (!mpctx->demuxer ||
324 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
325 return M_PROPERTY_UNAVAILABLE;
327 return m_property_time_ro(prop, action, arg, len);
330 /// Current position in percent (RW)
331 static int mp_property_percent_pos(m_option_t *prop, int action,
332 void *arg, MPContext *mpctx) {
333 int pos;
335 if (!mpctx->demuxer)
336 return M_PROPERTY_UNAVAILABLE;
338 switch(action) {
339 case M_PROPERTY_SET:
340 if(!arg) return M_PROPERTY_ERROR;
341 M_PROPERTY_CLAMP(prop, *(int*)arg);
342 pos = *(int*)arg;
343 break;
344 case M_PROPERTY_STEP_UP:
345 case M_PROPERTY_STEP_DOWN:
346 pos = demuxer_get_percent_pos(mpctx->demuxer);
347 pos += (arg ? *(int*)arg : 10) *
348 (action == M_PROPERTY_STEP_UP ? 1 : -1);
349 M_PROPERTY_CLAMP(prop, pos);
350 break;
351 default:
352 return m_property_int_ro(prop, action, arg,
353 demuxer_get_percent_pos(mpctx->demuxer));
356 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
357 mpctx->rel_seek_secs = pos / 100.0;
358 return M_PROPERTY_OK;
361 /// Current position in seconds (RW)
362 static int mp_property_time_pos(m_option_t *prop, int action,
363 void *arg, MPContext *mpctx) {
364 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
365 return M_PROPERTY_UNAVAILABLE;
367 switch(action) {
368 case M_PROPERTY_SET:
369 if(!arg) return M_PROPERTY_ERROR;
370 M_PROPERTY_CLAMP(prop, *(double*)arg);
371 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
372 mpctx->rel_seek_secs = *(double*)arg;
373 return M_PROPERTY_OK;
374 case M_PROPERTY_STEP_UP:
375 case M_PROPERTY_STEP_DOWN:
376 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
377 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
378 return M_PROPERTY_OK;
380 return m_property_time_ro(prop, action, arg,
381 mpctx->sh_video ? mpctx->sh_video->pts :
382 playing_audio_pts(mpctx));
385 /// Current chapter (RW)
386 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
387 MPContext *mpctx)
389 struct MPOpts *opts = &mpctx->opts;
390 int chapter = -1;
391 int step_all;
392 char *chapter_name = NULL;
394 if (mpctx->demuxer)
395 chapter = get_current_chapter(mpctx);
396 if (chapter < 0)
397 return M_PROPERTY_UNAVAILABLE;
399 switch (action) {
400 case M_PROPERTY_GET:
401 if (!arg)
402 return M_PROPERTY_ERROR;
403 *(int *) arg = chapter;
404 return M_PROPERTY_OK;
405 case M_PROPERTY_PRINT: {
406 if (!arg)
407 return M_PROPERTY_ERROR;
408 chapter_name = chapter_display_name(mpctx, chapter);
409 if (!chapter_name)
410 return M_PROPERTY_UNAVAILABLE;
411 *(char **) arg = chapter_name;
412 return M_PROPERTY_OK;
414 case M_PROPERTY_SET:
415 if (!arg)
416 return M_PROPERTY_ERROR;
417 M_PROPERTY_CLAMP(prop, *(int*)arg);
418 step_all = *(int *)arg - (chapter + 1);
419 chapter += step_all;
420 break;
421 case M_PROPERTY_STEP_UP:
422 case M_PROPERTY_STEP_DOWN: {
423 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
424 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
425 chapter += step_all;
426 if (chapter < 0)
427 chapter = 0;
428 break;
430 default:
431 return M_PROPERTY_NOT_IMPLEMENTED;
434 double next_pts = 0;
435 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
436 mpctx->rel_seek_secs = 0;
437 mpctx->abs_seek_pos = 0;
438 if (chapter >= 0) {
439 if (next_pts > -1.0) {
440 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
441 mpctx->rel_seek_secs = next_pts;
443 if (chapter_name)
444 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
445 MSGTR_OSDChapter, chapter + 1, chapter_name);
447 else if (step_all > 0)
448 mpctx->rel_seek_secs = 1000000000.;
449 else
450 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
451 MSGTR_OSDChapter, 0, MSGTR_Unknown);
452 if (chapter_name)
453 talloc_free(chapter_name);
454 return M_PROPERTY_OK;
457 /// Number of chapters in file
458 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
459 MPContext *mpctx)
461 if (!mpctx->demuxer)
462 return M_PROPERTY_UNAVAILABLE;
463 if (mpctx->demuxer->num_chapters == 0)
464 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
465 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
468 /// Current dvd angle (RW)
469 static int mp_property_angle(m_option_t *prop, int action, void *arg,
470 MPContext *mpctx)
472 struct MPOpts *opts = &mpctx->opts;
473 int angle = -1;
474 int angles;
475 char *angle_name = NULL;
477 if (mpctx->demuxer)
478 angle = demuxer_get_current_angle(mpctx->demuxer);
479 if (angle < 0)
480 return M_PROPERTY_UNAVAILABLE;
481 angles = demuxer_angles_count(mpctx->demuxer);
482 if (angles <= 1)
483 return M_PROPERTY_UNAVAILABLE;
485 switch (action) {
486 case M_PROPERTY_GET:
487 if (!arg)
488 return M_PROPERTY_ERROR;
489 *(int *) arg = angle;
490 return M_PROPERTY_OK;
491 case M_PROPERTY_PRINT: {
492 if (!arg)
493 return M_PROPERTY_ERROR;
494 angle_name = calloc(1, 64);
495 if (!angle_name)
496 return M_PROPERTY_UNAVAILABLE;
497 snprintf(angle_name, 64, "%d/%d", angle, angles);
498 *(char **) arg = angle_name;
499 return M_PROPERTY_OK;
501 case M_PROPERTY_SET:
502 if (!arg)
503 return M_PROPERTY_ERROR;
504 angle = *(int *)arg;
505 M_PROPERTY_CLAMP(prop, angle);
506 break;
507 case M_PROPERTY_STEP_UP:
508 case M_PROPERTY_STEP_DOWN: {
509 int step = 0;
510 if(arg)
511 step = *(int*)arg;
512 if(!step)
513 step = 1;
514 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
515 angle += step;
516 if (angle < 1) //cycle
517 angle = angles;
518 break;
520 default:
521 return M_PROPERTY_NOT_IMPLEMENTED;
523 angle = demuxer_set_angle(mpctx->demuxer, angle);
524 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
525 MSGTR_OSDAngle, angle, angles);
526 if (angle_name)
527 free(angle_name);
528 return M_PROPERTY_OK;
531 /// Demuxer meta data
532 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
533 MPContext *mpctx) {
534 m_property_action_t* ka;
535 char* meta;
536 static const m_option_t key_type =
537 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
538 if (!mpctx->demuxer)
539 return M_PROPERTY_UNAVAILABLE;
541 switch(action) {
542 case M_PROPERTY_GET:
543 if(!arg) return M_PROPERTY_ERROR;
544 *(char***)arg = mpctx->demuxer->info;
545 return M_PROPERTY_OK;
546 case M_PROPERTY_KEY_ACTION:
547 if(!arg) return M_PROPERTY_ERROR;
548 ka = arg;
549 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
550 return M_PROPERTY_UNKNOWN;
551 switch(ka->action) {
552 case M_PROPERTY_GET:
553 if(!ka->arg) return M_PROPERTY_ERROR;
554 *(char**)ka->arg = meta;
555 return M_PROPERTY_OK;
556 case M_PROPERTY_GET_TYPE:
557 if(!ka->arg) return M_PROPERTY_ERROR;
558 *(m_option_t**)ka->arg = &key_type;
559 return M_PROPERTY_OK;
562 return M_PROPERTY_NOT_IMPLEMENTED;
565 static int mp_property_pause(m_option_t *prop, int action, void *arg,
566 void *ctx)
568 MPContext *mpctx = ctx;
570 switch (action) {
571 case M_PROPERTY_SET:
572 if (!arg)
573 return M_PROPERTY_ERROR;
574 if (mpctx->paused == (bool)*(int *) arg)
575 return M_PROPERTY_OK;
576 case M_PROPERTY_STEP_UP:
577 case M_PROPERTY_STEP_DOWN:
578 if (mpctx->paused) {
579 unpause_player(mpctx);
580 mpctx->osd_function = OSD_PLAY;
582 else {
583 pause_player(mpctx);
584 mpctx->osd_function = OSD_PAUSE;
586 return M_PROPERTY_OK;
587 default:
588 return m_property_flag(prop, action, arg, &mpctx->paused);
593 ///@}
595 /// \defgroup AudioProperties Audio properties
596 /// \ingroup Properties
597 ///@{
599 /// Volume (RW)
600 static int mp_property_volume(m_option_t *prop, int action, void *arg,
601 MPContext *mpctx)
604 if (!mpctx->sh_audio)
605 return M_PROPERTY_UNAVAILABLE;
607 switch (action) {
608 case M_PROPERTY_GET:
609 if (!arg)
610 return M_PROPERTY_ERROR;
611 mixer_getbothvolume(&mpctx->mixer, arg);
612 return M_PROPERTY_OK;
613 case M_PROPERTY_PRINT:{
614 float vol;
615 if (!arg)
616 return M_PROPERTY_ERROR;
617 mixer_getbothvolume(&mpctx->mixer, &vol);
618 return m_property_float_range(prop, action, arg, &vol);
620 case M_PROPERTY_STEP_UP:
621 case M_PROPERTY_STEP_DOWN:
622 case M_PROPERTY_SET:
623 break;
624 default:
625 return M_PROPERTY_NOT_IMPLEMENTED;
628 if (mpctx->edl_muted)
629 return M_PROPERTY_DISABLED;
630 mpctx->user_muted = 0;
632 switch (action) {
633 case M_PROPERTY_SET:
634 if (!arg)
635 return M_PROPERTY_ERROR;
636 M_PROPERTY_CLAMP(prop, *(float *) arg);
637 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
638 return M_PROPERTY_OK;
639 case M_PROPERTY_STEP_UP:
640 if (arg && *(float *) arg <= 0)
641 mixer_decvolume(&mpctx->mixer);
642 else
643 mixer_incvolume(&mpctx->mixer);
644 return M_PROPERTY_OK;
645 case M_PROPERTY_STEP_DOWN:
646 if (arg && *(float *) arg <= 0)
647 mixer_incvolume(&mpctx->mixer);
648 else
649 mixer_decvolume(&mpctx->mixer);
650 return M_PROPERTY_OK;
652 return M_PROPERTY_NOT_IMPLEMENTED;
655 /// Mute (RW)
656 static int mp_property_mute(m_option_t *prop, int action, void *arg,
657 MPContext *mpctx)
660 if (!mpctx->sh_audio)
661 return M_PROPERTY_UNAVAILABLE;
663 switch (action) {
664 case M_PROPERTY_SET:
665 if (mpctx->edl_muted)
666 return M_PROPERTY_DISABLED;
667 if (!arg)
668 return M_PROPERTY_ERROR;
669 if ((!!*(int *) arg) != mpctx->mixer.muted)
670 mixer_mute(&mpctx->mixer);
671 mpctx->user_muted = mpctx->mixer.muted;
672 return M_PROPERTY_OK;
673 case M_PROPERTY_STEP_UP:
674 case M_PROPERTY_STEP_DOWN:
675 if (mpctx->edl_muted)
676 return M_PROPERTY_DISABLED;
677 mixer_mute(&mpctx->mixer);
678 mpctx->user_muted = mpctx->mixer.muted;
679 return M_PROPERTY_OK;
680 case M_PROPERTY_PRINT:
681 if (!arg)
682 return M_PROPERTY_ERROR;
683 if (mpctx->edl_muted) {
684 *(char **) arg = strdup(MSGTR_EnabledEdl);
685 return M_PROPERTY_OK;
687 default:
688 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
693 /// Audio delay (RW)
694 static int mp_property_audio_delay(m_option_t *prop, int action,
695 void *arg, MPContext *mpctx)
697 if (!(mpctx->sh_audio && mpctx->sh_video))
698 return M_PROPERTY_UNAVAILABLE;
699 switch (action) {
700 case M_PROPERTY_SET:
701 case M_PROPERTY_STEP_UP:
702 case M_PROPERTY_STEP_DOWN: {
703 int ret;
704 float delay = audio_delay;
705 ret = m_property_delay(prop, action, arg, &audio_delay);
706 if (ret != M_PROPERTY_OK)
707 return ret;
708 if (mpctx->sh_audio)
709 mpctx->delay -= audio_delay - delay;
711 return M_PROPERTY_OK;
712 default:
713 return m_property_delay(prop, action, arg, &audio_delay);
717 /// Audio codec tag (RO)
718 static int mp_property_audio_format(m_option_t *prop, int action,
719 void *arg, MPContext *mpctx)
721 if (!mpctx->sh_audio)
722 return M_PROPERTY_UNAVAILABLE;
723 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
726 /// Audio codec name (RO)
727 static int mp_property_audio_codec(m_option_t *prop, int action,
728 void *arg, MPContext *mpctx)
730 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
731 return M_PROPERTY_UNAVAILABLE;
732 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
735 /// Audio bitrate (RO)
736 static int mp_property_audio_bitrate(m_option_t *prop, int action,
737 void *arg, MPContext *mpctx)
739 if (!mpctx->sh_audio)
740 return M_PROPERTY_UNAVAILABLE;
741 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
744 /// Samplerate (RO)
745 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
746 MPContext *mpctx)
748 if (!mpctx->sh_audio)
749 return M_PROPERTY_UNAVAILABLE;
750 switch(action) {
751 case M_PROPERTY_PRINT:
752 if(!arg) return M_PROPERTY_ERROR;
753 *(char**)arg = malloc(16);
754 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
755 return M_PROPERTY_OK;
757 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
760 /// Number of channels (RO)
761 static int mp_property_channels(m_option_t *prop, int action, void *arg,
762 MPContext *mpctx)
764 if (!mpctx->sh_audio)
765 return M_PROPERTY_UNAVAILABLE;
766 switch (action) {
767 case M_PROPERTY_PRINT:
768 if (!arg)
769 return M_PROPERTY_ERROR;
770 switch (mpctx->sh_audio->channels) {
771 case 1:
772 *(char **) arg = strdup("mono");
773 break;
774 case 2:
775 *(char **) arg = strdup("stereo");
776 break;
777 default:
778 *(char **) arg = malloc(32);
779 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
781 return M_PROPERTY_OK;
783 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
786 /// Balance (RW)
787 static int mp_property_balance(m_option_t *prop, int action, void *arg,
788 MPContext *mpctx)
790 float bal;
792 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
793 return M_PROPERTY_UNAVAILABLE;
795 switch (action) {
796 case M_PROPERTY_GET:
797 if (!arg)
798 return M_PROPERTY_ERROR;
799 mixer_getbalance(&mpctx->mixer, arg);
800 return M_PROPERTY_OK;
801 case M_PROPERTY_PRINT: {
802 char** str = arg;
803 if (!arg)
804 return M_PROPERTY_ERROR;
805 mixer_getbalance(&mpctx->mixer, &bal);
806 if (bal == 0.f)
807 *str = strdup("center");
808 else if (bal == -1.f)
809 *str = strdup("left only");
810 else if (bal == 1.f)
811 *str = strdup("right only");
812 else {
813 unsigned right = (bal + 1.f) / 2.f * 100.f;
814 *str = malloc(sizeof("left xxx%, right xxx%"));
815 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
817 return M_PROPERTY_OK;
819 case M_PROPERTY_STEP_UP:
820 case M_PROPERTY_STEP_DOWN:
821 mixer_getbalance(&mpctx->mixer, &bal);
822 bal += (arg ? *(float*)arg : .1f) *
823 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
824 M_PROPERTY_CLAMP(prop, bal);
825 mixer_setbalance(&mpctx->mixer, bal);
826 return M_PROPERTY_OK;
827 case M_PROPERTY_SET:
828 if (!arg)
829 return M_PROPERTY_ERROR;
830 M_PROPERTY_CLAMP(prop, *(float*)arg);
831 mixer_setbalance(&mpctx->mixer, *(float*)arg);
832 return M_PROPERTY_OK;
834 return M_PROPERTY_NOT_IMPLEMENTED;
837 /// Selected audio id (RW)
838 static int mp_property_audio(m_option_t *prop, int action, void *arg,
839 MPContext *mpctx)
841 struct MPOpts *opts = &mpctx->opts;
842 int current_id = -1, tmp;
844 switch (action) {
845 case M_PROPERTY_GET:
846 if (!mpctx->sh_audio)
847 return M_PROPERTY_UNAVAILABLE;
848 if (!arg)
849 return M_PROPERTY_ERROR;
850 *(int *) arg = opts->audio_id;
851 return M_PROPERTY_OK;
852 case M_PROPERTY_PRINT:
853 if (!mpctx->sh_audio)
854 return M_PROPERTY_UNAVAILABLE;
855 if (!arg)
856 return M_PROPERTY_ERROR;
858 if (opts->audio_id < 0)
859 *(char **) arg = strdup(MSGTR_Disabled);
860 else {
861 char lang[40] = MSGTR_Unknown;
862 sh_audio_t* sh = mpctx->sh_audio;
863 if (sh && sh->lang)
864 av_strlcpy(lang, sh->lang, 40);
865 #ifdef CONFIG_DVDREAD
866 else if (mpctx->stream->type == STREAMTYPE_DVD) {
867 int code = dvd_lang_from_aid(mpctx->stream, opts->audio_id);
868 if (code) {
869 lang[0] = code >> 8;
870 lang[1] = code;
871 lang[2] = 0;
874 #endif
876 #ifdef CONFIG_DVDNAV
877 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
878 mp_dvdnav_lang_from_aid(mpctx->stream, opts->audio_id, lang);
879 #endif
880 *(char **) arg = malloc(64);
881 snprintf(*(char **) arg, 64, "(%d) %s", opts->audio_id, lang);
883 return M_PROPERTY_OK;
885 case M_PROPERTY_STEP_UP:
886 case M_PROPERTY_SET:
887 if (!mpctx->demuxer)
888 return M_PROPERTY_UNAVAILABLE;
889 if (action == M_PROPERTY_SET && arg)
890 tmp = *((int *) arg);
891 else
892 tmp = -1;
893 current_id = mpctx->demuxer->audio->id;
894 opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
895 if (opts->audio_id == -2
896 || (opts->audio_id > -1
897 && mpctx->demuxer->audio->id != current_id && current_id != -2))
898 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
899 if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
900 sh_audio_t *sh2;
901 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
902 if (sh2) {
903 sh2->ds = mpctx->demuxer->audio;
904 mpctx->sh_audio = sh2;
905 reinit_audio_chain(mpctx);
908 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id);
909 return M_PROPERTY_OK;
910 default:
911 return M_PROPERTY_NOT_IMPLEMENTED;
916 /// Selected video id (RW)
917 static int mp_property_video(m_option_t *prop, int action, void *arg,
918 MPContext *mpctx)
920 struct MPOpts *opts = &mpctx->opts;
921 int current_id = -1, tmp;
923 switch (action) {
924 case M_PROPERTY_GET:
925 if (!mpctx->sh_video)
926 return M_PROPERTY_UNAVAILABLE;
927 if (!arg)
928 return M_PROPERTY_ERROR;
929 *(int *) arg = opts->video_id;
930 return M_PROPERTY_OK;
931 case M_PROPERTY_PRINT:
932 if (!mpctx->sh_video)
933 return M_PROPERTY_UNAVAILABLE;
934 if (!arg)
935 return M_PROPERTY_ERROR;
937 if (opts->video_id < 0)
938 *(char **) arg = strdup(MSGTR_Disabled);
939 else {
940 char lang[40] = MSGTR_Unknown;
941 *(char **) arg = malloc(64);
942 snprintf(*(char **) arg, 64, "(%d) %s", opts->video_id, lang);
944 return M_PROPERTY_OK;
946 case M_PROPERTY_STEP_UP:
947 case M_PROPERTY_SET:
948 current_id = mpctx->demuxer->video->id;
949 if (action == M_PROPERTY_SET && arg)
950 tmp = *((int *) arg);
951 else
952 tmp = -1;
953 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
954 if (opts->video_id == -2
955 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
956 && current_id != -2))
957 uninit_player(mpctx, INITIALIZED_VCODEC |
958 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
959 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
960 sh_video_t *sh2;
961 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
962 if (sh2) {
963 sh2->ds = mpctx->demuxer->video;
964 mpctx->sh_video = sh2;
965 reinit_video_chain(mpctx);
968 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
969 return M_PROPERTY_OK;
971 default:
972 return M_PROPERTY_NOT_IMPLEMENTED;
976 static int mp_property_program(m_option_t *prop, int action, void *arg,
977 MPContext *mpctx)
979 demux_program_t prog;
981 switch (action) {
982 case M_PROPERTY_STEP_UP:
983 case M_PROPERTY_SET:
984 if (action == M_PROPERTY_SET && arg)
985 prog.progid = *((int *) arg);
986 else
987 prog.progid = -1;
988 if (demux_control
989 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
990 &prog) == DEMUXER_CTRL_NOTIMPL)
991 return M_PROPERTY_ERROR;
993 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
994 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
995 return M_PROPERTY_OK;
997 default:
998 return M_PROPERTY_NOT_IMPLEMENTED;
1002 ///@}
1004 /// \defgroup VideoProperties Video properties
1005 /// \ingroup Properties
1006 ///@{
1008 /// Fullscreen state (RW)
1009 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
1010 MPContext *mpctx)
1013 if (!mpctx->video_out)
1014 return M_PROPERTY_UNAVAILABLE;
1016 switch (action) {
1017 case M_PROPERTY_SET:
1018 if (!arg)
1019 return M_PROPERTY_ERROR;
1020 M_PROPERTY_CLAMP(prop, *(int *) arg);
1021 if (vo_fs == !!*(int *) arg)
1022 return M_PROPERTY_OK;
1023 case M_PROPERTY_STEP_UP:
1024 case M_PROPERTY_STEP_DOWN:
1025 #ifdef CONFIG_GUI
1026 if (use_gui)
1027 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
1028 else
1029 #endif
1030 if (mpctx->video_out->config_ok)
1031 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1032 mpctx->opts.fullscreen = vo_fs;
1033 return M_PROPERTY_OK;
1034 default:
1035 return m_property_flag(prop, action, arg, &vo_fs);
1039 static int mp_property_deinterlace(m_option_t *prop, int action,
1040 void *arg, MPContext *mpctx)
1042 int deinterlace;
1043 vf_instance_t *vf;
1044 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1045 return M_PROPERTY_UNAVAILABLE;
1046 vf = mpctx->sh_video->vfilter;
1047 switch (action) {
1048 case M_PROPERTY_GET:
1049 if (!arg)
1050 return M_PROPERTY_ERROR;
1051 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1052 return M_PROPERTY_OK;
1053 case M_PROPERTY_SET:
1054 if (!arg)
1055 return M_PROPERTY_ERROR;
1056 M_PROPERTY_CLAMP(prop, *(int *) arg);
1057 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1058 return M_PROPERTY_OK;
1059 case M_PROPERTY_STEP_UP:
1060 case M_PROPERTY_STEP_DOWN:
1061 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1062 deinterlace = !deinterlace;
1063 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1064 return M_PROPERTY_OK;
1066 return M_PROPERTY_NOT_IMPLEMENTED;
1069 /// Panscan (RW)
1070 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1071 MPContext *mpctx)
1074 if (!mpctx->video_out
1075 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1076 return M_PROPERTY_UNAVAILABLE;
1078 switch (action) {
1079 case M_PROPERTY_SET:
1080 if (!arg)
1081 return M_PROPERTY_ERROR;
1082 M_PROPERTY_CLAMP(prop, *(float *) arg);
1083 vo_panscan = *(float *) arg;
1084 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1085 return M_PROPERTY_OK;
1086 case M_PROPERTY_STEP_UP:
1087 case M_PROPERTY_STEP_DOWN:
1088 vo_panscan += (arg ? *(float *) arg : 0.1) *
1089 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1090 if (vo_panscan > 1)
1091 vo_panscan = 1;
1092 else if (vo_panscan < 0)
1093 vo_panscan = 0;
1094 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1095 return M_PROPERTY_OK;
1096 default:
1097 return m_property_float_range(prop, action, arg, &vo_panscan);
1101 /// Helper to set vo flags.
1102 /** \ingroup PropertyImplHelper
1104 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1105 int vo_ctrl, int *vo_var, MPContext *mpctx)
1108 if (!mpctx->video_out)
1109 return M_PROPERTY_UNAVAILABLE;
1111 switch (action) {
1112 case M_PROPERTY_SET:
1113 if (!arg)
1114 return M_PROPERTY_ERROR;
1115 M_PROPERTY_CLAMP(prop, *(int *) arg);
1116 if (*vo_var == !!*(int *) arg)
1117 return M_PROPERTY_OK;
1118 case M_PROPERTY_STEP_UP:
1119 case M_PROPERTY_STEP_DOWN:
1120 if (mpctx->video_out->config_ok)
1121 vo_control(mpctx->video_out, vo_ctrl, 0);
1122 return M_PROPERTY_OK;
1123 default:
1124 return m_property_flag(prop, action, arg, vo_var);
1128 /// Window always on top (RW)
1129 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1130 MPContext *mpctx)
1132 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1133 &mpctx->opts.vo_ontop, mpctx);
1136 /// Display in the root window (RW)
1137 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1138 MPContext *mpctx)
1140 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1141 &vo_rootwin, mpctx);
1144 /// Show window borders (RW)
1145 static int mp_property_border(m_option_t *prop, int action, void *arg,
1146 MPContext *mpctx)
1148 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1149 &vo_border, mpctx);
1152 /// Framedropping state (RW)
1153 static int mp_property_framedropping(m_option_t *prop, int action,
1154 void *arg, MPContext *mpctx)
1157 if (!mpctx->sh_video)
1158 return M_PROPERTY_UNAVAILABLE;
1160 switch (action) {
1161 case M_PROPERTY_PRINT:
1162 if (!arg)
1163 return M_PROPERTY_ERROR;
1164 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1165 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1166 MSGTR_Disabled));
1167 return M_PROPERTY_OK;
1168 default:
1169 return m_property_choice(prop, action, arg, &frame_dropping);
1173 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1174 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1175 MPContext *mpctx)
1177 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1178 int r, val;
1180 if (!mpctx->sh_video)
1181 return M_PROPERTY_UNAVAILABLE;
1183 if (gamma[0] == 1000) {
1184 gamma[0] = 0;
1185 get_video_colors(mpctx->sh_video, prop->name, gamma);
1188 switch (action) {
1189 case M_PROPERTY_SET:
1190 if (!arg)
1191 return M_PROPERTY_ERROR;
1192 M_PROPERTY_CLAMP(prop, *(int *) arg);
1193 *gamma = *(int *) arg;
1194 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1195 if (r <= 0)
1196 break;
1197 return r;
1198 case M_PROPERTY_GET:
1199 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1200 if (!arg)
1201 return M_PROPERTY_ERROR;
1202 *(int *)arg = val;
1203 return M_PROPERTY_OK;
1205 break;
1206 case M_PROPERTY_STEP_UP:
1207 case M_PROPERTY_STEP_DOWN:
1208 *gamma += (arg ? *(int *) arg : 1) *
1209 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1210 M_PROPERTY_CLAMP(prop, *gamma);
1211 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1212 if (r <= 0)
1213 break;
1214 return r;
1215 default:
1216 return M_PROPERTY_NOT_IMPLEMENTED;
1219 #ifdef CONFIG_TV
1220 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1221 int l = strlen(prop->name);
1222 char tv_prop[3 + l + 1];
1223 sprintf(tv_prop, "tv_%s", prop->name);
1224 return mp_property_do(tv_prop, action, arg, mpctx);
1226 #endif
1228 return M_PROPERTY_UNAVAILABLE;
1231 /// VSync (RW)
1232 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1233 MPContext *mpctx)
1235 return m_property_flag(prop, action, arg, &vo_vsync);
1238 /// Video codec tag (RO)
1239 static int mp_property_video_format(m_option_t *prop, int action,
1240 void *arg, MPContext *mpctx)
1242 char* meta;
1243 if (!mpctx->sh_video)
1244 return M_PROPERTY_UNAVAILABLE;
1245 switch(action) {
1246 case M_PROPERTY_PRINT:
1247 if (!arg)
1248 return M_PROPERTY_ERROR;
1249 switch(mpctx->sh_video->format) {
1250 case 0x10000001:
1251 meta = strdup ("mpeg1"); break;
1252 case 0x10000002:
1253 meta = strdup ("mpeg2"); break;
1254 case 0x10000004:
1255 meta = strdup ("mpeg4"); break;
1256 case 0x10000005:
1257 meta = strdup ("h264"); break;
1258 default:
1259 if(mpctx->sh_video->format >= 0x20202020) {
1260 meta = malloc(5);
1261 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1262 } else {
1263 meta = malloc(20);
1264 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1267 *(char**)arg = meta;
1268 return M_PROPERTY_OK;
1270 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1273 /// Video codec name (RO)
1274 static int mp_property_video_codec(m_option_t *prop, int action,
1275 void *arg, MPContext *mpctx)
1277 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1278 return M_PROPERTY_UNAVAILABLE;
1279 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1283 /// Video bitrate (RO)
1284 static int mp_property_video_bitrate(m_option_t *prop, int action,
1285 void *arg, MPContext *mpctx)
1287 if (!mpctx->sh_video)
1288 return M_PROPERTY_UNAVAILABLE;
1289 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1292 /// Video display width (RO)
1293 static int mp_property_width(m_option_t *prop, int action, void *arg,
1294 MPContext *mpctx)
1296 if (!mpctx->sh_video)
1297 return M_PROPERTY_UNAVAILABLE;
1298 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1301 /// Video display height (RO)
1302 static int mp_property_height(m_option_t *prop, int action, void *arg,
1303 MPContext *mpctx)
1305 if (!mpctx->sh_video)
1306 return M_PROPERTY_UNAVAILABLE;
1307 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1310 /// Video fps (RO)
1311 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1312 MPContext *mpctx)
1314 if (!mpctx->sh_video)
1315 return M_PROPERTY_UNAVAILABLE;
1316 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1319 /// Video aspect (RO)
1320 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1321 MPContext *mpctx)
1323 if (!mpctx->sh_video)
1324 return M_PROPERTY_UNAVAILABLE;
1325 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1328 ///@}
1330 /// \defgroup SubProprties Subtitles properties
1331 /// \ingroup Properties
1332 ///@{
1334 /// Text subtitle position (RW)
1335 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1336 MPContext *mpctx)
1338 if (!mpctx->sh_video)
1339 return M_PROPERTY_UNAVAILABLE;
1341 switch (action) {
1342 case M_PROPERTY_SET:
1343 if (!arg)
1344 return M_PROPERTY_ERROR;
1345 case M_PROPERTY_STEP_UP:
1346 case M_PROPERTY_STEP_DOWN:
1347 vo_osd_changed(OSDTYPE_SUBTITLE);
1348 default:
1349 return m_property_int_range(prop, action, arg, &sub_pos);
1353 /// Selected subtitles (RW)
1354 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1355 MPContext *mpctx)
1357 struct MPOpts *opts = &mpctx->opts;
1358 demux_stream_t *const d_sub = mpctx->d_sub;
1359 const int global_sub_size = mpctx->global_sub_size;
1360 int source = -1, reset_spu = 0;
1361 char *sub_name;
1363 if (!mpctx->sh_video || global_sub_size <= 0)
1364 return M_PROPERTY_UNAVAILABLE;
1366 switch (action) {
1367 case M_PROPERTY_GET:
1368 if (!arg)
1369 return M_PROPERTY_ERROR;
1370 *(int *) arg = mpctx->global_sub_pos;
1371 return M_PROPERTY_OK;
1372 case M_PROPERTY_PRINT:
1373 if (!arg)
1374 return M_PROPERTY_ERROR;
1375 *(char **) arg = malloc(64);
1376 (*(char **) arg)[63] = 0;
1377 sub_name = 0;
1378 if (subdata)
1379 sub_name = subdata->filename;
1380 #ifdef CONFIG_ASS
1381 if (ass_track && ass_track->name)
1382 sub_name = ass_track->name;
1383 #endif
1384 if (sub_name) {
1385 char *tmp, *tmp2;
1386 tmp = sub_name;
1387 if ((tmp2 = strrchr(tmp, '/')))
1388 tmp = tmp2 + 1;
1390 snprintf(*(char **) arg, 63, "(%d) %s%s",
1391 mpctx->set_of_sub_pos + 1,
1392 strlen(tmp) < 20 ? "" : "...",
1393 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1394 return M_PROPERTY_OK;
1396 #ifdef CONFIG_DVDNAV
1397 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1398 if (vo_spudec && opts->sub_id >= 0) {
1399 unsigned char lang[3];
1400 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1401 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1402 return M_PROPERTY_OK;
1406 #endif
1408 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1409 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1410 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1411 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1412 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1413 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1414 if (!lang) lang = MSGTR_Unknown;
1415 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1416 return M_PROPERTY_OK;
1419 if (vo_vobsub && vobsub_id >= 0) {
1420 const char *language = MSGTR_Unknown;
1421 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1422 snprintf(*(char **) arg, 63, "(%d) %s",
1423 vobsub_id, language ? language : MSGTR_Unknown);
1424 return M_PROPERTY_OK;
1426 #ifdef CONFIG_DVDREAD
1427 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1428 && opts->sub_id >= 0) {
1429 char lang[3];
1430 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1431 lang[0] = code >> 8;
1432 lang[1] = code;
1433 lang[2] = 0;
1434 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1435 return M_PROPERTY_OK;
1437 #endif
1438 if (opts->sub_id >= 0) {
1439 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, MSGTR_Unknown);
1440 return M_PROPERTY_OK;
1442 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1443 return M_PROPERTY_OK;
1445 case M_PROPERTY_SET:
1446 if (!arg)
1447 return M_PROPERTY_ERROR;
1448 if (*(int *) arg < -1)
1449 *(int *) arg = -1;
1450 else if (*(int *) arg >= global_sub_size)
1451 *(int *) arg = global_sub_size - 1;
1452 mpctx->global_sub_pos = *(int *) arg;
1453 break;
1454 case M_PROPERTY_STEP_UP:
1455 mpctx->global_sub_pos += 2;
1456 mpctx->global_sub_pos =
1457 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1458 break;
1459 case M_PROPERTY_STEP_DOWN:
1460 mpctx->global_sub_pos += global_sub_size + 1;
1461 mpctx->global_sub_pos =
1462 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1463 break;
1464 default:
1465 return M_PROPERTY_NOT_IMPLEMENTED;
1468 if (mpctx->global_sub_pos >= 0)
1469 source = sub_source(mpctx);
1471 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1472 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1473 global_sub_size,
1474 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1475 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1476 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1477 mpctx->global_sub_pos, source);
1479 mpctx->set_of_sub_pos = -1;
1480 subdata = NULL;
1482 vobsub_id = -1;
1483 opts->sub_id = -1;
1484 if (d_sub) {
1485 if (d_sub->id > -2)
1486 reset_spu = 1;
1487 d_sub->id = -2;
1489 #ifdef CONFIG_ASS
1490 ass_track = 0;
1491 #endif
1493 if (source == SUB_SOURCE_VOBSUB) {
1494 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1495 } else if (source == SUB_SOURCE_SUBS) {
1496 mpctx->set_of_sub_pos =
1497 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1498 #ifdef CONFIG_ASS
1499 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1500 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1501 else
1502 #endif
1504 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1505 vo_osd_changed(OSDTYPE_SUBTITLE);
1507 } else if (source == SUB_SOURCE_DEMUX) {
1508 opts->sub_id =
1509 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1510 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1511 int i = 0;
1512 // default: assume 1:1 mapping of sid and stream id
1513 d_sub->id = opts->sub_id;
1514 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1515 ds_free_packs(d_sub);
1516 for (i = 0; i < MAX_S_STREAMS; i++) {
1517 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1518 if (sh && sh->sid == opts->sub_id) {
1519 d_sub->id = i;
1520 d_sub->sh = sh;
1521 break;
1524 if (d_sub->sh && d_sub->id >= 0) {
1525 sh_sub_t *sh = d_sub->sh;
1526 if (sh->type == 'v')
1527 init_vo_spudec(mpctx);
1528 #ifdef CONFIG_ASS
1529 else if (ass_enabled)
1530 ass_track = sh->ass_track;
1531 #endif
1532 } else {
1533 d_sub->id = -2;
1534 d_sub->sh = NULL;
1538 #ifdef CONFIG_DVDREAD
1539 if (vo_spudec
1540 && (mpctx->stream->type == STREAMTYPE_DVD
1541 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1542 && opts->sub_id < 0 && reset_spu) {
1543 opts->sub_id = -2;
1544 d_sub->id = opts->sub_id;
1546 #endif
1547 update_subtitles(mpctx->sh_video, d_sub, 0, 1);
1549 return M_PROPERTY_OK;
1552 /// Selected sub source (RW)
1553 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1554 MPContext *mpctx)
1556 int source;
1557 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1558 return M_PROPERTY_UNAVAILABLE;
1560 switch (action) {
1561 case M_PROPERTY_GET:
1562 if (!arg)
1563 return M_PROPERTY_ERROR;
1564 *(int *) arg = sub_source(mpctx);
1565 return M_PROPERTY_OK;
1566 case M_PROPERTY_PRINT:
1567 if (!arg)
1568 return M_PROPERTY_ERROR;
1569 *(char **) arg = malloc(64);
1570 (*(char **) arg)[63] = 0;
1571 switch (sub_source(mpctx))
1573 case SUB_SOURCE_SUBS:
1574 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1575 break;
1576 case SUB_SOURCE_VOBSUB:
1577 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1578 break;
1579 case SUB_SOURCE_DEMUX:
1580 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1581 break;
1582 default:
1583 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1585 return M_PROPERTY_OK;
1586 case M_PROPERTY_SET:
1587 if (!arg)
1588 return M_PROPERTY_ERROR;
1589 M_PROPERTY_CLAMP(prop, *(int*)arg);
1590 if (*(int *) arg < 0)
1591 mpctx->global_sub_pos = -1;
1592 else if (*(int *) arg != sub_source(mpctx)) {
1593 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1594 return M_PROPERTY_UNAVAILABLE;
1595 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1597 break;
1598 case M_PROPERTY_STEP_UP:
1599 case M_PROPERTY_STEP_DOWN: {
1600 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1601 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1602 int step = (step_all > 0) ? 1 : -1;
1603 int cur_source = sub_source(mpctx);
1604 source = cur_source;
1605 while (step_all) {
1606 source += step;
1607 if (source >= SUB_SOURCES)
1608 source = -1;
1609 else if (source < -1)
1610 source = SUB_SOURCES - 1;
1611 if (source == cur_source || source == -1 ||
1612 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1613 step_all -= step;
1615 if (source == cur_source)
1616 return M_PROPERTY_OK;
1617 if (source == -1)
1618 mpctx->global_sub_pos = -1;
1619 else
1620 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1621 break;
1623 default:
1624 return M_PROPERTY_NOT_IMPLEMENTED;
1626 --mpctx->global_sub_pos;
1627 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1630 /// Selected subtitles from specific source (RW)
1631 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1632 MPContext *mpctx)
1634 int source, is_cur_source, offset;
1635 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1636 return M_PROPERTY_UNAVAILABLE;
1638 if (!strcmp(prop->name, "sub_file"))
1639 source = SUB_SOURCE_SUBS;
1640 else if (!strcmp(prop->name, "sub_vob"))
1641 source = SUB_SOURCE_VOBSUB;
1642 else if (!strcmp(prop->name, "sub_demux"))
1643 source = SUB_SOURCE_DEMUX;
1644 else
1645 return M_PROPERTY_ERROR;
1647 offset = mpctx->global_sub_indices[source];
1648 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1649 return M_PROPERTY_UNAVAILABLE;
1651 is_cur_source = sub_source(mpctx) == source;
1652 switch (action) {
1653 case M_PROPERTY_GET:
1654 if (!arg)
1655 return M_PROPERTY_ERROR;
1656 if (is_cur_source) {
1657 *(int *) arg = mpctx->global_sub_pos - offset;
1658 if (source == SUB_SOURCE_VOBSUB)
1659 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1661 else
1662 *(int *) arg = -1;
1663 return M_PROPERTY_OK;
1664 case M_PROPERTY_PRINT:
1665 if (!arg)
1666 return M_PROPERTY_ERROR;
1667 if (is_cur_source)
1668 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1669 *(char **) arg = malloc(64);
1670 (*(char **) arg)[63] = 0;
1671 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1672 return M_PROPERTY_OK;
1673 case M_PROPERTY_SET:
1674 if (!arg)
1675 return M_PROPERTY_ERROR;
1676 if (*(int *) arg >= 0) {
1677 int index = *(int *)arg;
1678 if (source == SUB_SOURCE_VOBSUB)
1679 index = vobsub_get_index_by_id(vo_vobsub, index);
1680 mpctx->global_sub_pos = offset + index;
1681 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1682 || sub_source(mpctx) != source) {
1683 mpctx->global_sub_pos = -1;
1684 *(int *) arg = -1;
1687 else
1688 mpctx->global_sub_pos = -1;
1689 break;
1690 case M_PROPERTY_STEP_UP:
1691 case M_PROPERTY_STEP_DOWN: {
1692 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1693 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1694 int step = (step_all > 0) ? 1 : -1;
1695 int max_sub_pos_for_source = -1;
1696 if (!is_cur_source)
1697 mpctx->global_sub_pos = -1;
1698 while (step_all) {
1699 if (mpctx->global_sub_pos == -1) {
1700 if (step > 0)
1701 mpctx->global_sub_pos = offset;
1702 else if (max_sub_pos_for_source == -1) {
1703 // Find max pos for specific source
1704 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1705 while (mpctx->global_sub_pos >= 0
1706 && sub_source(mpctx) != source)
1707 --mpctx->global_sub_pos;
1709 else
1710 mpctx->global_sub_pos = max_sub_pos_for_source;
1712 else {
1713 mpctx->global_sub_pos += step;
1714 if (mpctx->global_sub_pos < offset ||
1715 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1716 sub_source(mpctx) != source)
1717 mpctx->global_sub_pos = -1;
1719 step_all -= step;
1721 break;
1723 default:
1724 return M_PROPERTY_NOT_IMPLEMENTED;
1726 --mpctx->global_sub_pos;
1727 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1730 /// Subtitle delay (RW)
1731 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1732 MPContext *mpctx)
1734 if (!mpctx->sh_video)
1735 return M_PROPERTY_UNAVAILABLE;
1736 return m_property_delay(prop, action, arg, &sub_delay);
1739 /// Alignment of text subtitles (RW)
1740 static int mp_property_sub_alignment(m_option_t *prop, int action,
1741 void *arg, MPContext *mpctx)
1743 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1745 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1746 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1747 return M_PROPERTY_UNAVAILABLE;
1749 switch (action) {
1750 case M_PROPERTY_PRINT:
1751 if (!arg)
1752 return M_PROPERTY_ERROR;
1753 M_PROPERTY_CLAMP(prop, sub_alignment);
1754 *(char **) arg = strdup(name[sub_alignment]);
1755 return M_PROPERTY_OK;
1756 case M_PROPERTY_SET:
1757 if (!arg)
1758 return M_PROPERTY_ERROR;
1759 case M_PROPERTY_STEP_UP:
1760 case M_PROPERTY_STEP_DOWN:
1761 vo_osd_changed(OSDTYPE_SUBTITLE);
1762 default:
1763 return m_property_choice(prop, action, arg, &sub_alignment);
1767 /// Subtitle visibility (RW)
1768 static int mp_property_sub_visibility(m_option_t *prop, int action,
1769 void *arg, MPContext *mpctx)
1771 if (!mpctx->sh_video)
1772 return M_PROPERTY_UNAVAILABLE;
1774 switch (action) {
1775 case M_PROPERTY_SET:
1776 if (!arg)
1777 return M_PROPERTY_ERROR;
1778 case M_PROPERTY_STEP_UP:
1779 case M_PROPERTY_STEP_DOWN:
1780 vo_osd_changed(OSDTYPE_SUBTITLE);
1781 if (vo_spudec)
1782 vo_osd_changed(OSDTYPE_SPU);
1783 default:
1784 return m_property_flag(prop, action, arg, &sub_visibility);
1788 #ifdef CONFIG_ASS
1789 /// Use margins for libass subtitles (RW)
1790 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1791 void *arg, MPContext *mpctx)
1793 if (!mpctx->sh_video)
1794 return M_PROPERTY_UNAVAILABLE;
1796 switch (action) {
1797 case M_PROPERTY_SET:
1798 if (!arg)
1799 return M_PROPERTY_ERROR;
1800 case M_PROPERTY_STEP_UP:
1801 case M_PROPERTY_STEP_DOWN:
1802 ass_force_reload = 1;
1803 default:
1804 return m_property_flag(prop, action, arg, &ass_use_margins);
1807 #endif
1809 /// Show only forced subtitles (RW)
1810 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1811 void *arg, MPContext *mpctx)
1813 if (!vo_spudec)
1814 return M_PROPERTY_UNAVAILABLE;
1816 switch (action) {
1817 case M_PROPERTY_SET:
1818 if (!arg)
1819 return M_PROPERTY_ERROR;
1820 case M_PROPERTY_STEP_UP:
1821 case M_PROPERTY_STEP_DOWN:
1822 m_property_flag(prop, action, arg, &forced_subs_only);
1823 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1824 return M_PROPERTY_OK;
1825 default:
1826 return m_property_flag(prop, action, arg, &forced_subs_only);
1831 #ifdef CONFIG_FREETYPE
1832 /// Subtitle scale (RW)
1833 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1834 MPContext *mpctx)
1837 switch (action) {
1838 case M_PROPERTY_SET:
1839 if (!arg)
1840 return M_PROPERTY_ERROR;
1841 M_PROPERTY_CLAMP(prop, *(float *) arg);
1842 #ifdef CONFIG_ASS
1843 if (ass_enabled) {
1844 ass_font_scale = *(float *) arg;
1845 ass_force_reload = 1;
1847 #endif
1848 text_font_scale_factor = *(float *) arg;
1849 force_load_font = 1;
1850 return M_PROPERTY_OK;
1851 case M_PROPERTY_STEP_UP:
1852 case M_PROPERTY_STEP_DOWN:
1853 #ifdef CONFIG_ASS
1854 if (ass_enabled) {
1855 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1856 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1857 M_PROPERTY_CLAMP(prop, ass_font_scale);
1858 ass_force_reload = 1;
1860 #endif
1861 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1862 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1863 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1864 force_load_font = 1;
1865 return M_PROPERTY_OK;
1866 default:
1867 #ifdef CONFIG_ASS
1868 if (ass_enabled)
1869 return m_property_float_ro(prop, action, arg, ass_font_scale);
1870 else
1871 #endif
1872 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1875 #endif
1877 ///@}
1879 /// \defgroup TVProperties TV properties
1880 /// \ingroup Properties
1881 ///@{
1883 #ifdef CONFIG_TV
1885 /// TV color settings (RW)
1886 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1887 MPContext *mpctx)
1889 int r, val;
1890 tvi_handle_t *tvh = mpctx->demuxer->priv;
1891 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1892 return M_PROPERTY_UNAVAILABLE;
1894 switch (action) {
1895 case M_PROPERTY_SET:
1896 if (!arg)
1897 return M_PROPERTY_ERROR;
1898 M_PROPERTY_CLAMP(prop, *(int *) arg);
1899 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1900 case M_PROPERTY_GET:
1901 return tv_get_color_options(tvh, (int) prop->priv, arg);
1902 case M_PROPERTY_STEP_UP:
1903 case M_PROPERTY_STEP_DOWN:
1904 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1905 if (!r)
1906 return M_PROPERTY_ERROR;
1907 val += (arg ? *(int *) arg : 1) *
1908 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1909 M_PROPERTY_CLAMP(prop, val);
1910 return tv_set_color_options(tvh, (int) prop->priv, val);
1912 return M_PROPERTY_ERROR;
1914 return M_PROPERTY_NOT_IMPLEMENTED;
1917 #endif
1919 #ifdef CONFIG_TV_TELETEXT
1920 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1921 MPContext *mpctx)
1923 int val,result;
1924 int base_ioctl=(int)prop->priv;
1926 for teletext's GET,SET,STEP ioctls this is not 0
1927 SET is GET+1
1928 STEP is GET+2
1930 tvi_handle_t *tvh = mpctx->demuxer->priv;
1931 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1932 return M_PROPERTY_UNAVAILABLE;
1933 if(!base_ioctl)
1934 return M_PROPERTY_ERROR;
1936 switch (action) {
1937 case M_PROPERTY_GET:
1938 if (!arg)
1939 return M_PROPERTY_ERROR;
1940 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1941 break;
1942 case M_PROPERTY_SET:
1943 if (!arg)
1944 return M_PROPERTY_ERROR;
1945 M_PROPERTY_CLAMP(prop, *(int *) arg);
1946 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1947 break;
1948 case M_PROPERTY_STEP_UP:
1949 case M_PROPERTY_STEP_DOWN:
1950 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1951 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1952 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1953 break;
1954 default:
1955 return M_PROPERTY_NOT_IMPLEMENTED;
1958 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1961 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
1962 MPContext *mpctx)
1964 tvi_handle_t *tvh = mpctx->demuxer->priv;
1965 int result;
1966 int val;
1968 //with tvh==NULL will fail too
1969 result=mp_property_teletext_common(prop,action,arg,mpctx);
1970 if(result!=M_PROPERTY_OK)
1971 return result;
1973 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1974 mp_input_set_section(mpctx->input, "teletext");
1975 else
1976 mp_input_set_section(mpctx->input, "tv");
1977 return M_PROPERTY_OK;
1980 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
1981 MPContext *mpctx)
1983 tvi_handle_t *tvh = mpctx->demuxer->priv;
1984 int result;
1985 int val;
1986 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1987 return M_PROPERTY_UNAVAILABLE;
1988 switch(action){
1989 case M_PROPERTY_STEP_UP:
1990 case M_PROPERTY_STEP_DOWN:
1991 //This should be handled separately
1992 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1993 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1994 break;
1995 default:
1996 result=mp_property_teletext_common(prop,action,arg,mpctx);
1998 return result;
2002 #endif /* CONFIG_TV_TELETEXT */
2004 ///@}
2006 /// All properties available in MPlayer.
2007 /** \ingroup Properties
2009 static const m_option_t mp_properties[] = {
2010 // General
2011 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2012 M_OPT_RANGE, 0, 3, NULL },
2013 { "loop", mp_property_loop, CONF_TYPE_INT,
2014 M_OPT_MIN, -1, 0, NULL },
2015 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2016 M_OPT_RANGE, 0.01, 100.0, NULL },
2017 { "filename", mp_property_filename, CONF_TYPE_STRING,
2018 0, 0, 0, NULL },
2019 { "path", mp_property_path, CONF_TYPE_STRING,
2020 0, 0, 0, NULL },
2021 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2022 0, 0, 0, NULL },
2023 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2024 M_OPT_MIN, 0, 0, NULL },
2025 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2026 M_OPT_MIN, 0, 0, NULL },
2027 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2028 M_OPT_MIN, 0, 0, NULL },
2029 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2030 M_OPT_MIN, 0, 0, NULL },
2031 { "length", mp_property_length, CONF_TYPE_TIME,
2032 M_OPT_MIN, 0, 0, NULL },
2033 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2034 M_OPT_RANGE, 0, 100, NULL },
2035 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2036 M_OPT_MIN, 0, 0, NULL },
2037 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2038 M_OPT_MIN, 1, 0, NULL },
2039 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2040 0, 0, 0, NULL },
2041 { "angle", mp_property_angle, CONF_TYPE_INT,
2042 CONF_RANGE, -2, 10, NULL },
2043 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2044 0, 0, 0, NULL },
2045 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2046 M_OPT_RANGE, 0, 1, NULL },
2048 // Audio
2049 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2050 M_OPT_RANGE, 0, 100, NULL },
2051 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2052 M_OPT_RANGE, 0, 1, NULL },
2053 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2054 M_OPT_RANGE, -100, 100, NULL },
2055 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2056 0, 0, 0, NULL },
2057 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2058 0, 0, 0, NULL },
2059 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2060 0, 0, 0, NULL },
2061 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2062 0, 0, 0, NULL },
2063 { "channels", mp_property_channels, CONF_TYPE_INT,
2064 0, 0, 0, NULL },
2065 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2066 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
2067 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2068 M_OPT_RANGE, -1, 1, NULL },
2070 // Video
2071 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2072 M_OPT_RANGE, 0, 1, NULL },
2073 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2074 M_OPT_RANGE, 0, 1, NULL },
2075 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2076 M_OPT_RANGE, 0, 1, NULL },
2077 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2078 M_OPT_RANGE, 0, 1, NULL },
2079 { "border", mp_property_border, CONF_TYPE_FLAG,
2080 M_OPT_RANGE, 0, 1, NULL },
2081 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2082 M_OPT_RANGE, 0, 2, NULL },
2083 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2084 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2085 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2086 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2087 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2088 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2089 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2090 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2091 { "hue", mp_property_gamma, CONF_TYPE_INT,
2092 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2093 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2094 M_OPT_RANGE, 0, 1, NULL },
2095 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2096 M_OPT_RANGE, 0, 1, NULL },
2097 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2098 0, 0, 0, NULL },
2099 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2100 0, 0, 0, NULL },
2101 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2102 0, 0, 0, NULL },
2103 { "width", mp_property_width, CONF_TYPE_INT,
2104 0, 0, 0, NULL },
2105 { "height", mp_property_height, CONF_TYPE_INT,
2106 0, 0, 0, NULL },
2107 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2108 0, 0, 0, NULL },
2109 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2110 0, 0, 0, NULL },
2111 { "switch_video", mp_property_video, CONF_TYPE_INT,
2112 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
2113 { "switch_program", mp_property_program, CONF_TYPE_INT,
2114 CONF_RANGE, -1, 65535, NULL },
2116 // Subs
2117 { "sub", mp_property_sub, CONF_TYPE_INT,
2118 M_OPT_MIN, -1, 0, NULL },
2119 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2120 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2121 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2122 M_OPT_MIN, -1, 0, NULL },
2123 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2124 M_OPT_MIN, -1, 0, NULL },
2125 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2126 M_OPT_MIN, -1, 0, NULL },
2127 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2128 0, 0, 0, NULL },
2129 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2130 M_OPT_RANGE, 0, 100, NULL },
2131 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2132 M_OPT_RANGE, 0, 2, NULL },
2133 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2134 M_OPT_RANGE, 0, 1, NULL },
2135 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2136 M_OPT_RANGE, 0, 1, NULL },
2137 #ifdef CONFIG_FREETYPE
2138 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2139 M_OPT_RANGE, 0, 100, NULL },
2140 #endif
2141 #ifdef CONFIG_ASS
2142 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2143 M_OPT_RANGE, 0, 1, NULL },
2144 #endif
2146 #ifdef CONFIG_TV
2147 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2148 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2149 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2150 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2151 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2152 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2153 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2154 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2155 #endif
2157 #ifdef CONFIG_TV_TELETEXT
2158 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2159 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2160 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2161 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2162 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2163 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2164 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2165 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2166 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2167 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2168 #endif
2170 { NULL, NULL, NULL, 0, 0, 0, NULL }
2174 int mp_property_do(const char *name, int action, void *val, void *ctx)
2176 return m_property_do(mp_properties, name, action, val, ctx);
2179 char* mp_property_print(const char *name, void* ctx)
2181 char* ret = NULL;
2182 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2183 return NULL;
2184 return ret;
2187 char *property_expand_string(MPContext *mpctx, char *str)
2189 return m_properties_expand_string(mp_properties, str, mpctx);
2192 void property_print_help(void)
2194 m_properties_print_help_list(mp_properties);
2198 ///@}
2199 // Properties group
2203 * \defgroup Command2Property Command to property bridge
2205 * It is used to handle most commands that just set a property
2206 * and optionally display something on the OSD.
2207 * Two kinds of commands are handled: adjust or toggle.
2209 * Adjust commands take 1 or 2 parameters: <value> <abs>
2210 * If <abs> is non-zero the property is set to the given value
2211 * otherwise it is adjusted.
2213 * Toggle commands take 0 or 1 parameters. With no parameter
2214 * or a value less than the property minimum it just steps the
2215 * property to its next value. Otherwise it sets it to the given
2216 * value.
2221 /// List of the commands that can be handled by setting a property.
2222 static struct {
2223 /// property name
2224 const char *name;
2225 /// cmd id
2226 int cmd;
2227 /// set/adjust or toggle command
2228 int toggle;
2229 /// progressbar type
2230 int osd_progbar; // -1 is special value for seek indicators
2231 /// osd msg id if it must be shared
2232 int osd_id;
2233 /// osd msg template
2234 const char *osd_msg;
2235 } set_prop_cmd[] = {
2236 // general
2237 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2238 { "chapter", MP_CMD_SEEK_CHAPTER, 0, -1, -1, NULL },
2239 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2240 { "pause", MP_CMD_PAUSE, 0, 0, -1, NULL },
2241 // audio
2242 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2243 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2244 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2245 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2246 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2247 // video
2248 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2249 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2250 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2251 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2252 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2253 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2254 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2255 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2256 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2257 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2258 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2259 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2260 // subs
2261 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2262 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2263 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2264 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2265 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2266 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2267 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2268 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2269 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2270 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2271 #ifdef CONFIG_FREETYPE
2272 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2273 #endif
2274 #ifdef CONFIG_ASS
2275 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2276 #endif
2277 #ifdef CONFIG_TV
2278 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2279 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2280 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2281 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2282 #endif
2283 { NULL, 0, 0, 0, -1, NULL }
2287 /// Handle commands that set a property.
2288 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2290 struct MPOpts *opts = &mpctx->opts;
2291 int i, r;
2292 m_option_t* prop;
2293 const char *pname;
2295 // look for the command
2296 for (i = 0; set_prop_cmd[i].name; i++)
2297 if (set_prop_cmd[i].cmd == cmd->id)
2298 break;
2299 if (!(pname = set_prop_cmd[i].name))
2300 return 0;
2302 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2303 return 0;
2305 // toggle command
2306 if (set_prop_cmd[i].toggle) {
2307 // set to value
2308 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2309 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2310 else
2311 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2312 } else if (cmd->args[1].v.i) //set
2313 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2314 else // adjust
2315 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2317 if (r <= 0)
2318 return 1;
2320 if (set_prop_cmd[i].osd_progbar == -1)
2321 mpctx->add_osd_seek_info = true;
2322 else if (set_prop_cmd[i].osd_progbar) {
2323 if (prop->type == CONF_TYPE_INT) {
2324 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2325 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2326 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2327 } else if (prop->type == CONF_TYPE_FLOAT) {
2328 float f;
2329 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2330 set_osd_bar(mpctx, set_prop_cmd[i].osd_progbar,
2331 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2332 } else
2333 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2334 "Property use an unsupported type.\n");
2335 return 1;
2338 if (set_prop_cmd[i].osd_msg) {
2339 char *val = mp_property_print(pname, mpctx);
2340 if (val) {
2341 set_osd_msg(set_prop_cmd[i].osd_id >=
2342 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2343 1, opts->osd_duration, set_prop_cmd[i].osd_msg, val);
2344 free(val);
2347 return 1;
2350 #ifdef CONFIG_DVDNAV
2351 static const struct {
2352 const char *name;
2353 const mp_command_type cmd;
2354 } mp_dvdnav_bindings[] = {
2355 { "up", MP_CMD_DVDNAV_UP },
2356 { "down", MP_CMD_DVDNAV_DOWN },
2357 { "left", MP_CMD_DVDNAV_LEFT },
2358 { "right", MP_CMD_DVDNAV_RIGHT },
2359 { "menu", MP_CMD_DVDNAV_MENU },
2360 { "select", MP_CMD_DVDNAV_SELECT },
2361 { "prev", MP_CMD_DVDNAV_PREVMENU },
2362 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2365 * keep old dvdnav sub-command options for a while in order not to
2366 * break slave-mode API too suddenly.
2368 { "1", MP_CMD_DVDNAV_UP },
2369 { "2", MP_CMD_DVDNAV_DOWN },
2370 { "3", MP_CMD_DVDNAV_LEFT },
2371 { "4", MP_CMD_DVDNAV_RIGHT },
2372 { "5", MP_CMD_DVDNAV_MENU },
2373 { "6", MP_CMD_DVDNAV_SELECT },
2374 { "7", MP_CMD_DVDNAV_PREVMENU },
2375 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2376 { NULL, 0 }
2378 #endif
2380 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2382 struct MPOpts *opts = &mpctx->opts;
2383 sh_audio_t * const sh_audio = mpctx->sh_audio;
2384 sh_video_t * const sh_video = mpctx->sh_video;
2385 int osd_duration = opts->osd_duration;
2386 if (!set_property_command(mpctx, cmd))
2387 switch (cmd->id) {
2388 case MP_CMD_SEEK:{
2389 float v;
2390 int abs;
2391 mpctx->add_osd_seek_info = true;
2392 v = cmd->args[0].v.f;
2393 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2394 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2395 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2396 if (sh_video)
2397 mpctx->osd_function =
2398 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2399 mpctx->rel_seek_secs = v;
2400 } else if (abs) { /* Absolute seek by percentage */
2401 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2402 if (sh_video)
2403 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2404 mpctx->rel_seek_secs = v / 100.0;
2405 } else {
2406 mpctx->rel_seek_secs += v;
2407 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2410 break;
2412 case MP_CMD_SET_PROPERTY:{
2413 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2414 cmd->args[1].v.s, mpctx);
2415 if (r == M_PROPERTY_UNKNOWN)
2416 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2417 "Unknown property: '%s'\n", cmd->args[0].v.s);
2418 else if (r <= 0)
2419 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2420 "Failed to set property '%s' to '%s'.\n",
2421 cmd->args[0].v.s, cmd->args[1].v.s);
2423 break;
2425 case MP_CMD_STEP_PROPERTY:{
2426 void* arg = NULL;
2427 int r,i;
2428 double d;
2429 off_t o;
2430 if (cmd->args[1].v.f) {
2431 m_option_t* prop;
2432 if((r = mp_property_do(cmd->args[0].v.s,
2433 M_PROPERTY_GET_TYPE,
2434 &prop, mpctx)) <= 0)
2435 goto step_prop_err;
2436 if(prop->type == CONF_TYPE_INT ||
2437 prop->type == CONF_TYPE_FLAG)
2438 i = cmd->args[1].v.f, arg = &i;
2439 else if(prop->type == CONF_TYPE_FLOAT)
2440 arg = &cmd->args[1].v.f;
2441 else if(prop->type == CONF_TYPE_DOUBLE ||
2442 prop->type == CONF_TYPE_TIME)
2443 d = cmd->args[1].v.f, arg = &d;
2444 else if(prop->type == CONF_TYPE_POSITION)
2445 o = cmd->args[1].v.f, arg = &o;
2446 else
2447 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2448 "Ignoring step size stepping property '%s'.\n",
2449 cmd->args[0].v.s);
2451 r = mp_property_do(cmd->args[0].v.s,
2452 cmd->args[2].v.i < 0 ?
2453 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2454 arg, mpctx);
2455 step_prop_err:
2456 if (r == M_PROPERTY_UNKNOWN)
2457 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2458 "Unknown property: '%s'\n", cmd->args[0].v.s);
2459 else if (r <= 0)
2460 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2461 "Failed to increment property '%s' by %f.\n",
2462 cmd->args[0].v.s, cmd->args[1].v.f);
2464 break;
2466 case MP_CMD_GET_PROPERTY:{
2467 char *tmp;
2468 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2469 &tmp, mpctx) <= 0) {
2470 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2471 "Failed to get value of property '%s'.\n",
2472 cmd->args[0].v.s);
2473 break;
2475 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2476 cmd->args[0].v.s, tmp);
2477 free(tmp);
2479 break;
2481 case MP_CMD_EDL_MARK:
2482 if (edl_fd) {
2483 float v = sh_video ? sh_video->pts :
2484 playing_audio_pts(mpctx);
2485 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2486 mpctx->begin_skip = v;
2487 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2488 } else {
2489 if (mpctx->begin_skip > v)
2490 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2491 else {
2492 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2493 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2495 mpctx->begin_skip = MP_NOPTS_VALUE;
2498 break;
2500 case MP_CMD_SWITCH_RATIO:
2501 if (!sh_video)
2502 break;
2503 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2504 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2505 else
2506 opts->movie_aspect = cmd->args[0].v.f;
2507 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2508 break;
2510 case MP_CMD_SPEED_INCR:{
2511 float v = cmd->args[0].v.f;
2512 opts->playback_speed += v;
2513 build_afilter_chain(mpctx, sh_audio, &ao_data);
2514 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2515 opts->playback_speed);
2516 } break;
2518 case MP_CMD_SPEED_MULT:{
2519 float v = cmd->args[0].v.f;
2520 opts->playback_speed *= v;
2521 build_afilter_chain(mpctx, sh_audio, &ao_data);
2522 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2523 opts->playback_speed);
2524 } break;
2526 case MP_CMD_SPEED_SET:{
2527 float v = cmd->args[0].v.f;
2528 opts->playback_speed = v;
2529 build_afilter_chain(mpctx, sh_audio, &ao_data);
2530 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2531 opts->playback_speed);
2532 } break;
2534 case MP_CMD_FRAME_STEP:
2535 add_step_frame(mpctx);
2536 break;
2538 case MP_CMD_FILE_FILTER:
2539 file_filter = cmd->args[0].v.i;
2540 break;
2542 case MP_CMD_QUIT:
2543 exit_player_with_rc(mpctx, EXIT_QUIT,
2544 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2546 case MP_CMD_PLAY_TREE_STEP:{
2547 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2548 int force = cmd->args[1].v.i;
2550 #ifdef CONFIG_GUI
2551 if (use_gui) {
2552 int i = 0;
2553 if (n > 0)
2554 for (i = 0; i < n; i++)
2555 mplNext();
2556 else
2557 for (i = 0; i < -1 * n; i++)
2558 mplPrev();
2559 } else
2560 #endif
2562 if (!force && mpctx->playtree_iter) {
2563 play_tree_iter_t *i =
2564 play_tree_iter_new_copy(mpctx->playtree_iter);
2565 if (play_tree_iter_step(i, n, 0) ==
2566 PLAY_TREE_ITER_ENTRY)
2567 mpctx->stop_play =
2568 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2569 play_tree_iter_free(i);
2570 } else
2571 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2572 if (mpctx->stop_play)
2573 mpctx->play_tree_step = n;
2576 break;
2578 case MP_CMD_PLAY_TREE_UP_STEP:{
2579 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2580 int force = cmd->args[1].v.i;
2582 if (!force && mpctx->playtree_iter) {
2583 play_tree_iter_t *i =
2584 play_tree_iter_new_copy(mpctx->playtree_iter);
2585 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2586 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2587 play_tree_iter_free(i);
2588 } else
2589 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2591 break;
2593 case MP_CMD_PLAY_ALT_SRC_STEP:
2594 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2595 int v = cmd->args[0].v.i;
2596 if (v > 0
2597 && mpctx->playtree_iter->file <
2598 mpctx->playtree_iter->num_files)
2599 mpctx->stop_play = PT_NEXT_SRC;
2600 else if (v < 0 && mpctx->playtree_iter->file > 1)
2601 mpctx->stop_play = PT_PREV_SRC;
2603 break;
2605 case MP_CMD_SUB_STEP:
2606 if (sh_video) {
2607 int movement = cmd->args[0].v.i;
2608 step_sub(subdata, sh_video->pts, movement);
2609 #ifdef CONFIG_ASS
2610 if (ass_track)
2611 sub_delay +=
2612 ass_step_sub(ass_track,
2613 (sh_video->pts +
2614 sub_delay) * 1000 + .5, movement) / 1000.;
2615 #endif
2616 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2617 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2619 break;
2621 case MP_CMD_SUB_LOG:
2622 log_sub(mpctx);
2623 break;
2625 case MP_CMD_OSD:{
2626 int v = cmd->args[0].v.i;
2627 int max = (term_osd
2628 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2629 if (opts->osd_level > max)
2630 opts->osd_level = max;
2631 if (v < 0)
2632 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2633 else
2634 opts->osd_level = v > max ? max : v;
2635 /* Show OSD state when disabled, but not when an explicit
2636 argument is given to the OSD command, i.e. in slave mode. */
2637 if (v == -1 && opts->osd_level <= 1)
2638 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2639 MSGTR_OSDosd,
2640 opts->osd_level ? MSGTR_OSDenabled :
2641 MSGTR_OSDdisabled);
2642 else
2643 rm_osd_msg(OSD_MSG_OSD_STATUS);
2645 break;
2647 case MP_CMD_OSD_SHOW_TEXT:
2648 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2649 (cmd->args[1].v.i <
2650 0 ? osd_duration : cmd->args[1].v.i),
2651 "%-.63s", cmd->args[0].v.s);
2652 break;
2654 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2655 char *txt = m_properties_expand_string(mp_properties,
2656 cmd->args[0].v.s,
2657 mpctx);
2658 /* if no argument supplied take default osd_duration, else <arg> ms. */
2659 if (txt) {
2660 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2661 (cmd->args[1].v.i <
2662 0 ? osd_duration : cmd->args[1].v.i),
2663 "%-.63s", txt);
2664 free(txt);
2667 break;
2669 case MP_CMD_LOADFILE:{
2670 play_tree_t *e = play_tree_new();
2671 play_tree_add_file(e, cmd->args[0].v.s);
2673 if (cmd->args[1].v.i) // append
2674 play_tree_append_entry(mpctx->playtree->child, e);
2675 else {
2676 // Go back to the starting point.
2677 while (play_tree_iter_up_step
2678 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2679 /* NOP */ ;
2680 play_tree_free_list(mpctx->playtree->child, 1);
2681 play_tree_set_child(mpctx->playtree, e);
2682 pt_iter_goto_head(mpctx->playtree_iter);
2683 mpctx->stop_play = PT_NEXT_SRC;
2686 break;
2688 case MP_CMD_LOADLIST:{
2689 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2690 if (!e)
2691 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2692 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2693 else {
2694 if (cmd->args[1].v.i) // append
2695 play_tree_append_entry(mpctx->playtree->child, e);
2696 else {
2697 // Go back to the starting point.
2698 while (play_tree_iter_up_step
2699 (mpctx->playtree_iter, 0, 1)
2700 != PLAY_TREE_ITER_END)
2701 /* NOP */ ;
2702 play_tree_free_list(mpctx->playtree->child, 1);
2703 play_tree_set_child(mpctx->playtree, e);
2704 pt_iter_goto_head(mpctx->playtree_iter);
2705 mpctx->stop_play = PT_NEXT_SRC;
2709 break;
2711 case MP_CMD_STOP:
2712 // Go back to the starting point.
2713 while (play_tree_iter_up_step
2714 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2715 /* NOP */ ;
2716 mpctx->stop_play = PT_STOP;
2717 break;
2719 #ifdef CONFIG_RADIO
2720 case MP_CMD_RADIO_STEP_CHANNEL:
2721 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2722 int v = cmd->args[0].v.i;
2723 if (v > 0)
2724 radio_step_channel(mpctx->demuxer->stream,
2725 RADIO_CHANNEL_HIGHER);
2726 else
2727 radio_step_channel(mpctx->demuxer->stream,
2728 RADIO_CHANNEL_LOWER);
2729 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2730 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2731 MSGTR_OSDChannel,
2732 radio_get_channel_name(mpctx->demuxer->stream));
2735 break;
2737 case MP_CMD_RADIO_SET_CHANNEL:
2738 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2739 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2740 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2741 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2742 MSGTR_OSDChannel,
2743 radio_get_channel_name(mpctx->demuxer->stream));
2746 break;
2748 case MP_CMD_RADIO_SET_FREQ:
2749 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2750 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2751 break;
2753 case MP_CMD_RADIO_STEP_FREQ:
2754 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2755 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2756 break;
2757 #endif
2759 #ifdef CONFIG_TV
2760 case MP_CMD_TV_START_SCAN:
2761 if (mpctx->file_format == DEMUXER_TYPE_TV)
2762 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2763 break;
2764 case MP_CMD_TV_SET_FREQ:
2765 if (mpctx->file_format == DEMUXER_TYPE_TV)
2766 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2767 cmd->args[0].v.f * 16.0);
2768 #ifdef CONFIG_PVR
2769 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2770 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2771 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2772 pvr_get_current_channelname (mpctx->stream),
2773 pvr_get_current_stationname (mpctx->stream));
2775 #endif /* CONFIG_PVR */
2776 break;
2778 case MP_CMD_TV_STEP_FREQ:
2779 if (mpctx->file_format == DEMUXER_TYPE_TV)
2780 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2781 cmd->args[0].v.f * 16.0);
2782 #ifdef CONFIG_PVR
2783 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2784 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2785 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2786 pvr_get_current_channelname (mpctx->stream),
2787 pvr_get_current_frequency (mpctx->stream));
2789 #endif /* CONFIG_PVR */
2790 break;
2792 case MP_CMD_TV_SET_NORM:
2793 if (mpctx->file_format == DEMUXER_TYPE_TV)
2794 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2795 cmd->args[0].v.s);
2796 break;
2798 case MP_CMD_TV_STEP_CHANNEL:{
2799 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2800 int v = cmd->args[0].v.i;
2801 if (v > 0) {
2802 tv_step_channel((tvi_handle_t *) (mpctx->
2803 demuxer->priv),
2804 TV_CHANNEL_HIGHER);
2805 } else {
2806 tv_step_channel((tvi_handle_t *) (mpctx->
2807 demuxer->priv),
2808 TV_CHANNEL_LOWER);
2810 if (tv_channel_list) {
2811 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2812 MSGTR_OSDChannel, tv_channel_current->name);
2813 //vo_osd_changed(OSDTYPE_SUBTITLE);
2816 #ifdef CONFIG_PVR
2817 else if (mpctx->stream &&
2818 mpctx->stream->type == STREAMTYPE_PVR) {
2819 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2820 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2821 pvr_get_current_channelname (mpctx->stream),
2822 pvr_get_current_stationname (mpctx->stream));
2824 #endif /* CONFIG_PVR */
2826 #ifdef CONFIG_DVBIN
2827 if (mpctx->stream->type == STREAMTYPE_DVB) {
2828 int dir;
2829 int v = cmd->args[0].v.i;
2831 mpctx->last_dvb_step = v;
2832 if (v > 0)
2833 dir = DVB_CHANNEL_HIGHER;
2834 else
2835 dir = DVB_CHANNEL_LOWER;
2838 if (dvb_step_channel(mpctx->stream, dir)) {
2839 mpctx->stop_play = PT_NEXT_ENTRY;
2840 mpctx->dvbin_reopen = 1;
2843 #endif /* CONFIG_DVBIN */
2844 break;
2846 case MP_CMD_TV_SET_CHANNEL:
2847 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2848 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2849 cmd->args[0].v.s);
2850 if (tv_channel_list) {
2851 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2852 MSGTR_OSDChannel, tv_channel_current->name);
2853 //vo_osd_changed(OSDTYPE_SUBTITLE);
2856 #ifdef CONFIG_PVR
2857 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2858 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2859 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2860 pvr_get_current_channelname (mpctx->stream),
2861 pvr_get_current_stationname (mpctx->stream));
2863 #endif /* CONFIG_PVR */
2864 break;
2866 #ifdef CONFIG_DVBIN
2867 case MP_CMD_DVB_SET_CHANNEL:
2868 if (mpctx->stream->type == STREAMTYPE_DVB) {
2869 mpctx->last_dvb_step = 1;
2871 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
2872 cmd->args[0].v.i)) {
2873 mpctx->stop_play = PT_NEXT_ENTRY;
2874 mpctx->dvbin_reopen = 1;
2877 break;
2878 #endif /* CONFIG_DVBIN */
2880 case MP_CMD_TV_LAST_CHANNEL:
2881 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2882 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2883 if (tv_channel_list) {
2884 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2885 MSGTR_OSDChannel, tv_channel_current->name);
2886 //vo_osd_changed(OSDTYPE_SUBTITLE);
2889 #ifdef CONFIG_PVR
2890 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2891 pvr_set_lastchannel (mpctx->stream);
2892 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2893 pvr_get_current_channelname (mpctx->stream),
2894 pvr_get_current_stationname (mpctx->stream));
2896 #endif /* CONFIG_PVR */
2897 break;
2899 case MP_CMD_TV_STEP_NORM:
2900 if (mpctx->file_format == DEMUXER_TYPE_TV)
2901 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2902 break;
2904 case MP_CMD_TV_STEP_CHANNEL_LIST:
2905 if (mpctx->file_format == DEMUXER_TYPE_TV)
2906 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2907 break;
2908 #ifdef CONFIG_TV_TELETEXT
2909 case MP_CMD_TV_TELETEXT_ADD_DEC:
2911 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2912 if (mpctx->file_format == DEMUXER_TYPE_TV)
2913 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2914 break;
2916 case MP_CMD_TV_TELETEXT_GO_LINK:
2918 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2919 if (mpctx->file_format == DEMUXER_TYPE_TV)
2920 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2921 break;
2923 #endif /* CONFIG_TV_TELETEXT */
2924 #endif /* CONFIG_TV */
2926 case MP_CMD_SUB_LOAD:
2927 if (sh_video) {
2928 int n = mpctx->set_of_sub_size;
2929 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
2930 if (n != mpctx->set_of_sub_size) {
2931 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2932 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2933 mpctx->global_sub_size;
2934 ++mpctx->global_sub_size;
2937 break;
2939 case MP_CMD_SUB_REMOVE:
2940 if (sh_video) {
2941 int v = cmd->args[0].v.i;
2942 sub_data *subd;
2943 if (v < 0) {
2944 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2945 subd = mpctx->set_of_subtitles[v];
2946 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2947 MSGTR_RemovedSubtitleFile, v + 1,
2948 filename_recode(subd->filename));
2949 sub_free(subd);
2950 mpctx->set_of_subtitles[v] = NULL;
2952 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2953 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2954 mpctx->set_of_sub_size = 0;
2955 if (mpctx->set_of_sub_pos >= 0) {
2956 mpctx->global_sub_pos = -2;
2957 subdata = NULL;
2958 mp_input_queue_cmd(mpctx->input,
2959 mp_input_parse_cmd("sub_select"));
2961 } else if (v < mpctx->set_of_sub_size) {
2962 subd = mpctx->set_of_subtitles[v];
2963 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2964 MSGTR_RemovedSubtitleFile, v + 1,
2965 filename_recode(subd->filename));
2966 sub_free(subd);
2967 if (mpctx->set_of_sub_pos == v) {
2968 mpctx->global_sub_pos = -2;
2969 subdata = NULL;
2970 mp_input_queue_cmd(mpctx->input,
2971 mp_input_parse_cmd("sub_select"));
2972 } else if (mpctx->set_of_sub_pos > v) {
2973 --mpctx->set_of_sub_pos;
2974 --mpctx->global_sub_pos;
2976 while (++v < mpctx->set_of_sub_size)
2977 mpctx->set_of_subtitles[v - 1] =
2978 mpctx->set_of_subtitles[v];
2979 --mpctx->set_of_sub_size;
2980 --mpctx->global_sub_size;
2981 if (mpctx->set_of_sub_size <= 0)
2982 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2983 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2986 break;
2988 case MP_CMD_GET_SUB_VISIBILITY:
2989 if (sh_video) {
2990 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2991 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2993 break;
2995 case MP_CMD_SCREENSHOT:
2996 if (mpctx->video_out && mpctx->video_out->config_ok) {
2997 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2998 if (CONTROL_OK !=
2999 ((vf_instance_t *) sh_video->vfilter)->
3000 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3001 &cmd->args[0].v.i))
3002 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3004 break;
3006 case MP_CMD_VF_CHANGE_RECTANGLE:
3007 if (!sh_video)
3008 break;
3009 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3010 break;
3012 case MP_CMD_GET_TIME_LENGTH:{
3013 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
3014 demuxer_get_time_length(mpctx->demuxer));
3016 break;
3018 case MP_CMD_GET_FILENAME:{
3019 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3020 get_metadata(mpctx, META_NAME));
3022 break;
3024 case MP_CMD_GET_VIDEO_CODEC:{
3025 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3026 if (!inf)
3027 inf = strdup("");
3028 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3029 free(inf);
3031 break;
3033 case MP_CMD_GET_VIDEO_BITRATE:{
3034 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3035 if (!inf)
3036 inf = strdup("");
3037 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3038 free(inf);
3040 break;
3042 case MP_CMD_GET_VIDEO_RESOLUTION:{
3043 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3044 if (!inf)
3045 inf = strdup("");
3046 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3047 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3048 free(inf);
3050 break;
3052 case MP_CMD_GET_AUDIO_CODEC:{
3053 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3054 if (!inf)
3055 inf = strdup("");
3056 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3057 free(inf);
3059 break;
3061 case MP_CMD_GET_AUDIO_BITRATE:{
3062 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3063 if (!inf)
3064 inf = strdup("");
3065 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3066 free(inf);
3068 break;
3070 case MP_CMD_GET_AUDIO_SAMPLES:{
3071 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3072 if (!inf)
3073 inf = strdup("");
3074 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3075 free(inf);
3077 break;
3079 case MP_CMD_GET_META_TITLE:{
3080 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3081 if (!inf)
3082 inf = strdup("");
3083 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3084 free(inf);
3086 break;
3088 case MP_CMD_GET_META_ARTIST:{
3089 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3090 if (!inf)
3091 inf = strdup("");
3092 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3093 free(inf);
3095 break;
3097 case MP_CMD_GET_META_ALBUM:{
3098 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3099 if (!inf)
3100 inf = strdup("");
3101 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3102 free(inf);
3104 break;
3106 case MP_CMD_GET_META_YEAR:{
3107 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3108 if (!inf)
3109 inf = strdup("");
3110 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3111 free(inf);
3113 break;
3115 case MP_CMD_GET_META_COMMENT:{
3116 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3117 if (!inf)
3118 inf = strdup("");
3119 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3120 free(inf);
3122 break;
3124 case MP_CMD_GET_META_TRACK:{
3125 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3126 if (!inf)
3127 inf = strdup("");
3128 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3129 free(inf);
3131 break;
3133 case MP_CMD_GET_META_GENRE:{
3134 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3135 if (!inf)
3136 inf = strdup("");
3137 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3138 free(inf);
3140 break;
3142 case MP_CMD_GET_VO_FULLSCREEN:
3143 if (mpctx->video_out && mpctx->video_out->config_ok)
3144 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3145 break;
3147 case MP_CMD_GET_PERCENT_POS:
3148 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3149 demuxer_get_percent_pos(mpctx->demuxer));
3150 break;
3152 case MP_CMD_GET_TIME_POS:{
3153 float pos = 0;
3154 if (sh_video)
3155 pos = sh_video->pts;
3156 else if (sh_audio && mpctx->audio_out)
3157 pos = playing_audio_pts(mpctx);
3158 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3160 break;
3162 case MP_CMD_RUN:
3163 #ifndef __MINGW32__
3164 if (!fork()) {
3165 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3166 exit(0);
3168 #endif
3169 break;
3171 case MP_CMD_KEYDOWN_EVENTS:
3172 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3173 break;
3175 case MP_CMD_SET_MOUSE_POS:{
3176 int pointer_x, pointer_y;
3177 double dx, dy;
3178 pointer_x = cmd->args[0].v.i;
3179 pointer_y = cmd->args[1].v.i;
3180 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3181 #ifdef CONFIG_DVDNAV
3182 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3183 && dx > 0.0 && dy > 0.0) {
3184 int button = -1;
3185 pointer_x = (int) (dx * (double) sh_video->disp_w);
3186 pointer_y = (int) (dy * (double) sh_video->disp_h);
3187 mp_dvdnav_update_mouse_pos(mpctx->stream,
3188 pointer_x, pointer_y, &button);
3189 if (opts->osd_level > 1 && button > 0)
3190 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3191 "Selected button number %d", button);
3193 #endif
3194 #ifdef CONFIG_MENU
3195 if (use_menu && dx >= 0.0 && dy >= 0.0)
3196 menu_update_mouse_pos(dx, dy);
3197 #endif
3199 break;
3201 #ifdef CONFIG_DVDNAV
3202 case MP_CMD_DVDNAV:{
3203 int button = -1;
3204 int i;
3205 mp_command_type command = 0;
3206 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3207 break;
3209 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3210 if (cmd->args[0].v.s &&
3211 !strcasecmp (cmd->args[0].v.s,
3212 mp_dvdnav_bindings[i].name))
3213 command = mp_dvdnav_bindings[i].cmd;
3215 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3216 if (opts->osd_level > 1 && button > 0)
3217 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3218 "Selected button number %d", button);
3220 break;
3222 case MP_CMD_SWITCH_TITLE:
3223 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3224 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3225 break;
3227 #endif
3229 default:
3230 #ifdef CONFIG_GUI
3231 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3232 guiGetEvent(guiIEvent, (char *) cmd->id);
3233 else
3234 #endif
3235 mp_msg(MSGT_CPLAYER, MSGL_V,
3236 "Received unknown cmd %s\n", cmd->name);
3239 switch (cmd->pausing) {
3240 case 1: // "pausing"
3241 pause_player(mpctx);
3242 break;
3243 case 3: // "pausing_toggle"
3244 if (mpctx->paused)
3245 unpause_player(mpctx);
3246 else
3247 pause_player(mpctx);
3248 break;