Fix the clean script (again)
[mplayer/kovensky.git] / command.c
blob6b5a442b1dc498edbf722556b7565fd572e89a66
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 #include "ass_mp.h"
35 #include "stream/tv.h"
36 #include "stream/stream_radio.h"
37 #include "stream/pvr.h"
38 #ifdef CONFIG_DVBIN
39 #include "stream/dvbin.h"
40 #endif
41 #ifdef CONFIG_DVDREAD
42 #include "stream/stream_dvd.h"
43 #endif
44 #include "stream/stream_dvdnav.h"
45 #include "m_struct.h"
46 #include "libmenu/menu.h"
48 #include "mp_core.h"
49 #include "mp_fifo.h"
50 #include "libavutil/avstring.h"
52 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
54 extern int use_menu;
56 static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
57 double *dx, double *dy)
59 struct MPOpts *opts = &mpctx->opts;
60 struct vo *vo = mpctx->video_out;
61 //remove the borders, if any, and rescale to the range [0,1],[0,1]
62 if (vo_fs) { //we are in full-screen mode
63 if (opts->vo_screenwidth > vo->dwidth) //there are borders along the x axis
64 ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
65 if (opts->vo_screenheight > vo->dheight) //there are borders along the y axis (usual way)
66 iy -= (opts->vo_screenheight - vo->dheight) / 2;
68 if (ix < 0 || ix > vo->dwidth) {
69 *dx = *dy = -1.0;
70 return;
71 } //we are on one of the borders
72 if (iy < 0 || iy > vo->dheight) {
73 *dx = *dy = -1.0;
74 return;
75 } //we are on one of the borders
78 *dx = (double) ix / (double) vo->dwidth;
79 *dy = (double) iy / (double) vo->dheight;
81 mp_msg(MSGT_CPLAYER, MSGL_V,
82 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
83 *dx, *dy, opts->vo_screenwidth, opts->vo_screenheight, vo->dwidth,
84 vo->dheight, vo_fs);
87 static int sub_source_by_pos(MPContext *mpctx, int pos)
89 int source = -1;
90 int top = -1;
91 int i;
92 for (i = 0; i < SUB_SOURCES; i++) {
93 int j = mpctx->global_sub_indices[i];
94 if ((j >= 0) && (j > top) && (pos >= j)) {
95 source = i;
96 top = j;
99 return source;
102 static int sub_source(MPContext *mpctx)
104 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
108 * \brief Log the currently displayed subtitle to a file
110 * Logs the current or last displayed subtitle together with filename
111 * and time information to ~/.mplayer/subtitle_log
113 * Intended purpose is to allow convenient marking of bogus subtitles
114 * which need to be fixed while watching the movie.
117 static void log_sub(struct MPContext *mpctx)
119 char *fname;
120 FILE *f;
121 int i;
123 if (subdata == NULL || vo_sub_last == NULL)
124 return;
125 fname = get_path("subtitle_log");
126 f = fopen(fname, "a");
127 if (!f)
128 return;
129 fprintf(f, "----------------------------------------------------------\n");
130 if (subdata->sub_uses_time) {
131 fprintf(f,
132 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
133 mpctx->filename, vo_sub_last->start / 360000,
134 (vo_sub_last->start / 6000) % 60,
135 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
136 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
137 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
138 } else {
139 fprintf(f, "N: %s S: %ld E: %ld\n", mpctx->filename,
140 vo_sub_last->start, vo_sub_last->end);
142 for (i = 0; i < vo_sub_last->lines; i++) {
143 fprintf(f, "%s\n", vo_sub_last->text[i]);
145 fclose(f);
149 /// \defgroup Properties
150 ///@{
152 /// \defgroup GeneralProperties General properties
153 /// \ingroup Properties
154 ///@{
156 /// OSD level (RW)
157 static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
158 MPContext *mpctx)
160 return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
163 /// Loop (RW)
164 static int mp_property_loop(m_option_t *prop, int action, void *arg,
165 MPContext *mpctx)
167 struct MPOpts *opts = &mpctx->opts;
168 switch (action) {
169 case M_PROPERTY_PRINT:
170 if (!arg) return M_PROPERTY_ERROR;
171 if (opts->loop_times < 0)
172 *(char**)arg = strdup("off");
173 else if (opts->loop_times == 0)
174 *(char**)arg = strdup("inf");
175 else
176 break;
177 return M_PROPERTY_OK;
179 return m_property_int_range(prop, action, arg, &opts->loop_times);
182 /// Playback speed (RW)
183 static int mp_property_playback_speed(m_option_t *prop, int action,
184 void *arg, MPContext *mpctx)
186 struct MPOpts *opts = &mpctx->opts;
187 switch (action) {
188 case M_PROPERTY_SET:
189 if (!arg)
190 return M_PROPERTY_ERROR;
191 M_PROPERTY_CLAMP(prop, *(float *) arg);
192 opts->playback_speed = *(float *) arg;
193 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
194 return M_PROPERTY_OK;
195 case M_PROPERTY_STEP_UP:
196 case M_PROPERTY_STEP_DOWN:
197 opts->playback_speed += (arg ? *(float *) arg : 0.1) *
198 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
199 M_PROPERTY_CLAMP(prop, opts->playback_speed);
200 build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data);
201 return M_PROPERTY_OK;
203 return m_property_float_range(prop, action, arg, &opts->playback_speed);
206 /// filename with path (RO)
207 static int mp_property_path(m_option_t *prop, int action, void *arg,
208 MPContext *mpctx)
210 return m_property_string_ro(prop, action, arg, mpctx->filename);
213 /// filename without path (RO)
214 static int mp_property_filename(m_option_t *prop, int action, void *arg,
215 MPContext *mpctx)
217 char *f;
218 if (!mpctx->filename)
219 return M_PROPERTY_UNAVAILABLE;
220 if (((f = strrchr(mpctx->filename, '/'))
221 || (f = strrchr(mpctx->filename, '\\'))) && f[1])
222 f++;
223 else
224 f = mpctx->filename;
225 return m_property_string_ro(prop, action, arg, f);
228 /// Demuxer name (RO)
229 static int mp_property_demuxer(m_option_t *prop, int action, void *arg,
230 MPContext *mpctx)
232 if (!mpctx->demuxer)
233 return M_PROPERTY_UNAVAILABLE;
234 return m_property_string_ro(prop, action, arg,
235 (char *) mpctx->demuxer->desc->name);
238 /// Position in the stream (RW)
239 static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
240 MPContext *mpctx)
242 if (!mpctx->demuxer || !mpctx->demuxer->stream)
243 return M_PROPERTY_UNAVAILABLE;
244 if (!arg)
245 return M_PROPERTY_ERROR;
246 switch (action) {
247 case M_PROPERTY_GET:
248 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
249 return M_PROPERTY_OK;
250 case M_PROPERTY_SET:
251 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
252 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
253 return M_PROPERTY_OK;
255 return M_PROPERTY_NOT_IMPLEMENTED;
258 /// Stream start offset (RO)
259 static int mp_property_stream_start(m_option_t *prop, int action,
260 void *arg, MPContext *mpctx)
262 if (!mpctx->demuxer || !mpctx->demuxer->stream)
263 return M_PROPERTY_UNAVAILABLE;
264 switch (action) {
265 case M_PROPERTY_GET:
266 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
267 return M_PROPERTY_OK;
269 return M_PROPERTY_NOT_IMPLEMENTED;
272 /// Stream end offset (RO)
273 static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
274 MPContext *mpctx)
276 if (!mpctx->demuxer || !mpctx->demuxer->stream)
277 return M_PROPERTY_UNAVAILABLE;
278 switch (action) {
279 case M_PROPERTY_GET:
280 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
281 return M_PROPERTY_OK;
283 return M_PROPERTY_NOT_IMPLEMENTED;
286 /// Stream length (RO)
287 static int mp_property_stream_length(m_option_t *prop, int action,
288 void *arg, MPContext *mpctx)
290 if (!mpctx->demuxer || !mpctx->demuxer->stream)
291 return M_PROPERTY_UNAVAILABLE;
292 switch (action) {
293 case M_PROPERTY_GET:
294 *(off_t *) arg =
295 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
296 return M_PROPERTY_OK;
298 return M_PROPERTY_NOT_IMPLEMENTED;
301 /// Media length in seconds (RO)
302 static int mp_property_length(m_option_t *prop, int action, void *arg,
303 MPContext *mpctx)
305 double len;
307 if (!mpctx->demuxer ||
308 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
309 return M_PROPERTY_UNAVAILABLE;
311 return m_property_time_ro(prop, action, arg, len);
314 /// Current position in percent (RW)
315 static int mp_property_percent_pos(m_option_t *prop, int action,
316 void *arg, MPContext *mpctx) {
317 int pos;
319 if (!mpctx->demuxer)
320 return M_PROPERTY_UNAVAILABLE;
322 switch(action) {
323 case M_PROPERTY_SET:
324 if(!arg) return M_PROPERTY_ERROR;
325 M_PROPERTY_CLAMP(prop, *(int*)arg);
326 pos = *(int*)arg;
327 break;
328 case M_PROPERTY_STEP_UP:
329 case M_PROPERTY_STEP_DOWN:
330 pos = demuxer_get_percent_pos(mpctx->demuxer);
331 pos += (arg ? *(int*)arg : 10) *
332 (action == M_PROPERTY_STEP_UP ? 1 : -1);
333 M_PROPERTY_CLAMP(prop, pos);
334 break;
335 default:
336 return m_property_int_ro(prop, action, arg,
337 demuxer_get_percent_pos(mpctx->demuxer));
340 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
341 mpctx->rel_seek_secs = pos / 100.0;
342 return M_PROPERTY_OK;
345 /// Current position in seconds (RW)
346 static int mp_property_time_pos(m_option_t *prop, int action,
347 void *arg, MPContext *mpctx) {
348 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
349 return M_PROPERTY_UNAVAILABLE;
351 switch(action) {
352 case M_PROPERTY_SET:
353 if(!arg) return M_PROPERTY_ERROR;
354 M_PROPERTY_CLAMP(prop, *(double*)arg);
355 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
356 mpctx->rel_seek_secs = *(double*)arg;
357 return M_PROPERTY_OK;
358 case M_PROPERTY_STEP_UP:
359 case M_PROPERTY_STEP_DOWN:
360 mpctx->rel_seek_secs += (arg ? *(double*)arg : 10.0) *
361 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
362 return M_PROPERTY_OK;
364 return m_property_time_ro(prop, action, arg,
365 mpctx->sh_video ? mpctx->sh_video->pts :
366 playing_audio_pts(mpctx));
369 /// Current chapter (RW)
370 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
371 MPContext *mpctx)
373 struct MPOpts *opts = &mpctx->opts;
374 int chapter = -1;
375 int step_all;
376 char *chapter_name = NULL;
378 if (mpctx->demuxer)
379 chapter = get_current_chapter(mpctx);
380 if (chapter < 0)
381 return M_PROPERTY_UNAVAILABLE;
383 switch (action) {
384 case M_PROPERTY_GET:
385 if (!arg)
386 return M_PROPERTY_ERROR;
387 *(int *) arg = chapter;
388 return M_PROPERTY_OK;
389 case M_PROPERTY_PRINT: {
390 if (!arg)
391 return M_PROPERTY_ERROR;
392 chapter_name = chapter_display_name(mpctx, chapter);
393 if (!chapter_name)
394 return M_PROPERTY_UNAVAILABLE;
395 *(char **) arg = chapter_name;
396 return M_PROPERTY_OK;
398 case M_PROPERTY_SET:
399 if (!arg)
400 return M_PROPERTY_ERROR;
401 M_PROPERTY_CLAMP(prop, *(int*)arg);
402 step_all = *(int *)arg - chapter;
403 chapter += step_all;
404 break;
405 case M_PROPERTY_STEP_UP:
406 case M_PROPERTY_STEP_DOWN: {
407 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
408 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
409 chapter += step_all;
410 if (chapter < 0)
411 chapter = 0;
412 break;
414 default:
415 return M_PROPERTY_NOT_IMPLEMENTED;
418 double next_pts = 0;
419 chapter = seek_chapter(mpctx, chapter, &next_pts, &chapter_name);
420 mpctx->rel_seek_secs = 0;
421 mpctx->abs_seek_pos = 0;
422 if (chapter >= 0) {
423 if (next_pts > -1.0) {
424 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
425 mpctx->rel_seek_secs = next_pts;
427 if (chapter_name)
428 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
429 _("Chapter: (%d) %s"), chapter + 1, chapter_name);
431 else if (step_all > 0)
432 mpctx->rel_seek_secs = 1000000000.;
433 else
434 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
435 _("Chapter: (%d) %s"), 0, _("unknown"));
436 if (chapter_name)
437 talloc_free(chapter_name);
438 return M_PROPERTY_OK;
441 /// Number of chapters in file
442 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
443 MPContext *mpctx)
445 if (!mpctx->demuxer)
446 return M_PROPERTY_UNAVAILABLE;
447 if (mpctx->demuxer->num_chapters == 0)
448 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
449 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
452 /// Current dvd angle (RW)
453 static int mp_property_angle(m_option_t *prop, int action, void *arg,
454 MPContext *mpctx)
456 struct MPOpts *opts = &mpctx->opts;
457 int angle = -1;
458 int angles;
459 char *angle_name = NULL;
461 if (mpctx->demuxer)
462 angle = demuxer_get_current_angle(mpctx->demuxer);
463 if (angle < 0)
464 return M_PROPERTY_UNAVAILABLE;
465 angles = demuxer_angles_count(mpctx->demuxer);
466 if (angles <= 1)
467 return M_PROPERTY_UNAVAILABLE;
469 switch (action) {
470 case M_PROPERTY_GET:
471 if (!arg)
472 return M_PROPERTY_ERROR;
473 *(int *) arg = angle;
474 return M_PROPERTY_OK;
475 case M_PROPERTY_PRINT: {
476 if (!arg)
477 return M_PROPERTY_ERROR;
478 angle_name = calloc(1, 64);
479 if (!angle_name)
480 return M_PROPERTY_UNAVAILABLE;
481 snprintf(angle_name, 64, "%d/%d", angle, angles);
482 *(char **) arg = angle_name;
483 return M_PROPERTY_OK;
485 case M_PROPERTY_SET:
486 if (!arg)
487 return M_PROPERTY_ERROR;
488 angle = *(int *)arg;
489 M_PROPERTY_CLAMP(prop, angle);
490 break;
491 case M_PROPERTY_STEP_UP:
492 case M_PROPERTY_STEP_DOWN: {
493 int step = 0;
494 if(arg)
495 step = *(int*)arg;
496 if(!step)
497 step = 1;
498 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
499 angle += step;
500 if (angle < 1) //cycle
501 angle = angles;
502 break;
504 default:
505 return M_PROPERTY_NOT_IMPLEMENTED;
507 angle = demuxer_set_angle(mpctx->demuxer, angle);
508 set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
509 _("Angle: %d/%d"), angle, angles);
510 if (angle_name)
511 free(angle_name);
512 return M_PROPERTY_OK;
515 /// Demuxer meta data
516 static int mp_property_metadata(m_option_t *prop, int action, void *arg,
517 MPContext *mpctx) {
518 m_property_action_t* ka;
519 char* meta;
520 static const m_option_t key_type =
521 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
522 if (!mpctx->demuxer)
523 return M_PROPERTY_UNAVAILABLE;
525 switch(action) {
526 case M_PROPERTY_GET:
527 if(!arg) return M_PROPERTY_ERROR;
528 *(char***)arg = mpctx->demuxer->info;
529 return M_PROPERTY_OK;
530 case M_PROPERTY_KEY_ACTION:
531 if(!arg) return M_PROPERTY_ERROR;
532 ka = arg;
533 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
534 return M_PROPERTY_UNKNOWN;
535 switch(ka->action) {
536 case M_PROPERTY_GET:
537 if(!ka->arg) return M_PROPERTY_ERROR;
538 *(char**)ka->arg = meta;
539 return M_PROPERTY_OK;
540 case M_PROPERTY_GET_TYPE:
541 if(!ka->arg) return M_PROPERTY_ERROR;
542 *(m_option_t**)ka->arg = &key_type;
543 return M_PROPERTY_OK;
546 return M_PROPERTY_NOT_IMPLEMENTED;
549 static int mp_property_pause(m_option_t *prop, int action, void *arg,
550 void *ctx)
552 MPContext *mpctx = ctx;
554 switch (action) {
555 case M_PROPERTY_SET:
556 if (!arg)
557 return M_PROPERTY_ERROR;
558 if (mpctx->paused == (bool)*(int *) arg)
559 return M_PROPERTY_OK;
560 case M_PROPERTY_STEP_UP:
561 case M_PROPERTY_STEP_DOWN:
562 if (mpctx->paused) {
563 unpause_player(mpctx);
564 mpctx->osd_function = OSD_PLAY;
566 else {
567 pause_player(mpctx);
568 mpctx->osd_function = OSD_PAUSE;
570 return M_PROPERTY_OK;
571 default:
572 return m_property_flag(prop, action, arg, &mpctx->paused);
577 ///@}
579 /// \defgroup AudioProperties Audio properties
580 /// \ingroup Properties
581 ///@{
583 /// Volume (RW)
584 static int mp_property_volume(m_option_t *prop, int action, void *arg,
585 MPContext *mpctx)
588 if (!mpctx->sh_audio)
589 return M_PROPERTY_UNAVAILABLE;
591 switch (action) {
592 case M_PROPERTY_GET:
593 if (!arg)
594 return M_PROPERTY_ERROR;
595 mixer_getbothvolume(&mpctx->mixer, arg);
596 return M_PROPERTY_OK;
597 case M_PROPERTY_PRINT:{
598 float vol;
599 if (!arg)
600 return M_PROPERTY_ERROR;
601 mixer_getbothvolume(&mpctx->mixer, &vol);
602 return m_property_float_range(prop, action, arg, &vol);
604 case M_PROPERTY_STEP_UP:
605 case M_PROPERTY_STEP_DOWN:
606 case M_PROPERTY_SET:
607 break;
608 default:
609 return M_PROPERTY_NOT_IMPLEMENTED;
612 if (mpctx->edl_muted)
613 return M_PROPERTY_DISABLED;
614 mpctx->user_muted = 0;
616 switch (action) {
617 case M_PROPERTY_SET:
618 if (!arg)
619 return M_PROPERTY_ERROR;
620 M_PROPERTY_CLAMP(prop, *(float *) arg);
621 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
622 return M_PROPERTY_OK;
623 case M_PROPERTY_STEP_UP:
624 if (arg && *(float *) arg <= 0)
625 mixer_decvolume(&mpctx->mixer);
626 else
627 mixer_incvolume(&mpctx->mixer);
628 return M_PROPERTY_OK;
629 case M_PROPERTY_STEP_DOWN:
630 if (arg && *(float *) arg <= 0)
631 mixer_incvolume(&mpctx->mixer);
632 else
633 mixer_decvolume(&mpctx->mixer);
634 return M_PROPERTY_OK;
636 return M_PROPERTY_NOT_IMPLEMENTED;
639 /// Mute (RW)
640 static int mp_property_mute(m_option_t *prop, int action, void *arg,
641 MPContext *mpctx)
644 if (!mpctx->sh_audio)
645 return M_PROPERTY_UNAVAILABLE;
647 switch (action) {
648 case M_PROPERTY_SET:
649 if (mpctx->edl_muted)
650 return M_PROPERTY_DISABLED;
651 if (!arg)
652 return M_PROPERTY_ERROR;
653 if ((!!*(int *) arg) != mpctx->mixer.muted)
654 mixer_mute(&mpctx->mixer);
655 mpctx->user_muted = mpctx->mixer.muted;
656 return M_PROPERTY_OK;
657 case M_PROPERTY_STEP_UP:
658 case M_PROPERTY_STEP_DOWN:
659 if (mpctx->edl_muted)
660 return M_PROPERTY_DISABLED;
661 mixer_mute(&mpctx->mixer);
662 mpctx->user_muted = mpctx->mixer.muted;
663 return M_PROPERTY_OK;
664 case M_PROPERTY_PRINT:
665 if (!arg)
666 return M_PROPERTY_ERROR;
667 if (mpctx->edl_muted) {
668 *(char **) arg = strdup(_("enabled (EDL)"));
669 return M_PROPERTY_OK;
671 default:
672 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
677 /// Audio delay (RW)
678 static int mp_property_audio_delay(m_option_t *prop, int action,
679 void *arg, MPContext *mpctx)
681 if (!(mpctx->sh_audio && mpctx->sh_video))
682 return M_PROPERTY_UNAVAILABLE;
683 switch (action) {
684 case M_PROPERTY_SET:
685 case M_PROPERTY_STEP_UP:
686 case M_PROPERTY_STEP_DOWN: {
687 int ret;
688 float delay = audio_delay;
689 ret = m_property_delay(prop, action, arg, &audio_delay);
690 if (ret != M_PROPERTY_OK)
691 return ret;
692 if (mpctx->sh_audio)
693 mpctx->delay -= audio_delay - delay;
695 return M_PROPERTY_OK;
696 default:
697 return m_property_delay(prop, action, arg, &audio_delay);
701 /// Audio codec tag (RO)
702 static int mp_property_audio_format(m_option_t *prop, int action,
703 void *arg, MPContext *mpctx)
705 if (!mpctx->sh_audio)
706 return M_PROPERTY_UNAVAILABLE;
707 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
710 /// Audio codec name (RO)
711 static int mp_property_audio_codec(m_option_t *prop, int action,
712 void *arg, MPContext *mpctx)
714 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
715 return M_PROPERTY_UNAVAILABLE;
716 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
719 /// Audio bitrate (RO)
720 static int mp_property_audio_bitrate(m_option_t *prop, int action,
721 void *arg, MPContext *mpctx)
723 if (!mpctx->sh_audio)
724 return M_PROPERTY_UNAVAILABLE;
725 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
728 /// Samplerate (RO)
729 static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
730 MPContext *mpctx)
732 if (!mpctx->sh_audio)
733 return M_PROPERTY_UNAVAILABLE;
734 switch(action) {
735 case M_PROPERTY_PRINT:
736 if(!arg) return M_PROPERTY_ERROR;
737 *(char**)arg = malloc(16);
738 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
739 return M_PROPERTY_OK;
741 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
744 /// Number of channels (RO)
745 static int mp_property_channels(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)
753 return M_PROPERTY_ERROR;
754 switch (mpctx->sh_audio->channels) {
755 case 1:
756 *(char **) arg = strdup("mono");
757 break;
758 case 2:
759 *(char **) arg = strdup("stereo");
760 break;
761 default:
762 *(char **) arg = malloc(32);
763 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
765 return M_PROPERTY_OK;
767 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
770 /// Balance (RW)
771 static int mp_property_balance(m_option_t *prop, int action, void *arg,
772 MPContext *mpctx)
774 float bal;
776 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
777 return M_PROPERTY_UNAVAILABLE;
779 switch (action) {
780 case M_PROPERTY_GET:
781 if (!arg)
782 return M_PROPERTY_ERROR;
783 mixer_getbalance(&mpctx->mixer, arg);
784 return M_PROPERTY_OK;
785 case M_PROPERTY_PRINT: {
786 char** str = arg;
787 if (!arg)
788 return M_PROPERTY_ERROR;
789 mixer_getbalance(&mpctx->mixer, &bal);
790 if (bal == 0.f)
791 *str = strdup("center");
792 else if (bal == -1.f)
793 *str = strdup("left only");
794 else if (bal == 1.f)
795 *str = strdup("right only");
796 else {
797 unsigned right = (bal + 1.f) / 2.f * 100.f;
798 *str = malloc(sizeof("left xxx%, right xxx%"));
799 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
801 return M_PROPERTY_OK;
803 case M_PROPERTY_STEP_UP:
804 case M_PROPERTY_STEP_DOWN:
805 mixer_getbalance(&mpctx->mixer, &bal);
806 bal += (arg ? *(float*)arg : .1f) *
807 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
808 M_PROPERTY_CLAMP(prop, bal);
809 mixer_setbalance(&mpctx->mixer, bal);
810 return M_PROPERTY_OK;
811 case M_PROPERTY_SET:
812 if (!arg)
813 return M_PROPERTY_ERROR;
814 M_PROPERTY_CLAMP(prop, *(float*)arg);
815 mixer_setbalance(&mpctx->mixer, *(float*)arg);
816 return M_PROPERTY_OK;
818 return M_PROPERTY_NOT_IMPLEMENTED;
821 /// Selected audio id (RW)
822 static int mp_property_audio(m_option_t *prop, int action, void *arg,
823 MPContext *mpctx)
825 struct MPOpts *opts = &mpctx->opts;
826 int current_id = -1, tmp;
828 switch (action) {
829 case M_PROPERTY_GET:
830 if (!mpctx->sh_audio)
831 return M_PROPERTY_UNAVAILABLE;
832 if (!arg)
833 return M_PROPERTY_ERROR;
834 *(int *) arg = opts->audio_id;
835 return M_PROPERTY_OK;
836 case M_PROPERTY_PRINT:
837 if (!mpctx->sh_audio)
838 return M_PROPERTY_UNAVAILABLE;
839 if (!arg)
840 return M_PROPERTY_ERROR;
842 if (opts->audio_id < 0)
843 *(char **) arg = strdup(_("disabled"));
844 else {
845 char lang[40] = _("unknown");
846 sh_audio_t* sh = mpctx->sh_audio;
847 if (sh && sh->lang)
848 av_strlcpy(lang, sh->lang, 40);
849 #ifdef CONFIG_DVDREAD
850 else if (mpctx->stream->type == STREAMTYPE_DVD) {
851 int code = dvd_lang_from_aid(mpctx->stream, opts->audio_id);
852 if (code) {
853 lang[0] = code >> 8;
854 lang[1] = code;
855 lang[2] = 0;
858 #endif
860 #ifdef CONFIG_DVDNAV
861 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
862 mp_dvdnav_lang_from_aid(mpctx->stream, opts->audio_id, lang);
863 #endif
864 *(char **) arg = malloc(64);
865 snprintf(*(char **) arg, 64, "(%d) %s", opts->audio_id, lang);
867 return M_PROPERTY_OK;
869 case M_PROPERTY_STEP_UP:
870 case M_PROPERTY_SET:
871 if (!mpctx->demuxer)
872 return M_PROPERTY_UNAVAILABLE;
873 if (action == M_PROPERTY_SET && arg)
874 tmp = *((int *) arg);
875 else
876 tmp = -1;
877 current_id = mpctx->demuxer->audio->id;
878 opts->audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
879 if (opts->audio_id == -2
880 || (opts->audio_id > -1
881 && mpctx->demuxer->audio->id != current_id && current_id != -2))
882 uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
883 if (opts->audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
884 sh_audio_t *sh2;
885 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
886 if (sh2) {
887 sh2->ds = mpctx->demuxer->audio;
888 mpctx->sh_audio = sh2;
889 reinit_audio_chain(mpctx);
892 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", opts->audio_id);
893 return M_PROPERTY_OK;
894 default:
895 return M_PROPERTY_NOT_IMPLEMENTED;
900 /// Selected video id (RW)
901 static int mp_property_video(m_option_t *prop, int action, void *arg,
902 MPContext *mpctx)
904 struct MPOpts *opts = &mpctx->opts;
905 int current_id = -1, tmp;
907 switch (action) {
908 case M_PROPERTY_GET:
909 if (!mpctx->sh_video)
910 return M_PROPERTY_UNAVAILABLE;
911 if (!arg)
912 return M_PROPERTY_ERROR;
913 *(int *) arg = opts->video_id;
914 return M_PROPERTY_OK;
915 case M_PROPERTY_PRINT:
916 if (!mpctx->sh_video)
917 return M_PROPERTY_UNAVAILABLE;
918 if (!arg)
919 return M_PROPERTY_ERROR;
921 if (opts->video_id < 0)
922 *(char **) arg = strdup(_("disabled"));
923 else {
924 char lang[40] = _("unknown");
925 *(char **) arg = malloc(64);
926 snprintf(*(char **) arg, 64, "(%d) %s", opts->video_id, lang);
928 return M_PROPERTY_OK;
930 case M_PROPERTY_STEP_UP:
931 case M_PROPERTY_SET:
932 current_id = mpctx->demuxer->video->id;
933 if (action == M_PROPERTY_SET && arg)
934 tmp = *((int *) arg);
935 else
936 tmp = -1;
937 opts->video_id = demuxer_switch_video(mpctx->demuxer, tmp);
938 if (opts->video_id == -2
939 || (opts->video_id > -1 && mpctx->demuxer->video->id != current_id
940 && current_id != -2))
941 uninit_player(mpctx, INITIALIZED_VCODEC |
942 (mpctx->opts.fixed_vo && opts->video_id != -2 ? 0 : INITIALIZED_VO));
943 if (opts->video_id > -1 && mpctx->demuxer->video->id != current_id) {
944 sh_video_t *sh2;
945 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
946 if (sh2) {
947 sh2->ds = mpctx->demuxer->video;
948 mpctx->sh_video = sh2;
949 reinit_video_chain(mpctx);
952 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", opts->video_id);
953 return M_PROPERTY_OK;
955 default:
956 return M_PROPERTY_NOT_IMPLEMENTED;
960 static int mp_property_program(m_option_t *prop, int action, void *arg,
961 MPContext *mpctx)
963 demux_program_t prog;
965 switch (action) {
966 case M_PROPERTY_STEP_UP:
967 case M_PROPERTY_SET:
968 if (action == M_PROPERTY_SET && arg)
969 prog.progid = *((int *) arg);
970 else
971 prog.progid = -1;
972 if (demux_control
973 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
974 &prog) == DEMUXER_CTRL_NOTIMPL)
975 return M_PROPERTY_ERROR;
977 if (prog.aid < 0 && prog.vid < 0) {
978 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
979 return M_PROPERTY_ERROR;
981 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
982 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
983 return M_PROPERTY_OK;
985 default:
986 return M_PROPERTY_NOT_IMPLEMENTED;
990 ///@}
992 /// \defgroup VideoProperties Video properties
993 /// \ingroup Properties
994 ///@{
996 /// Fullscreen state (RW)
997 static int mp_property_fullscreen(m_option_t *prop, int action, void *arg,
998 MPContext *mpctx)
1001 if (!mpctx->video_out)
1002 return M_PROPERTY_UNAVAILABLE;
1004 switch (action) {
1005 case M_PROPERTY_SET:
1006 if (!arg)
1007 return M_PROPERTY_ERROR;
1008 M_PROPERTY_CLAMP(prop, *(int *) arg);
1009 if (vo_fs == !!*(int *) arg)
1010 return M_PROPERTY_OK;
1011 case M_PROPERTY_STEP_UP:
1012 case M_PROPERTY_STEP_DOWN:
1013 if (mpctx->video_out->config_ok)
1014 vo_control(mpctx->video_out, VOCTRL_FULLSCREEN, 0);
1015 mpctx->opts.fullscreen = vo_fs;
1016 return M_PROPERTY_OK;
1017 default:
1018 return m_property_flag(prop, action, arg, &vo_fs);
1022 static int mp_property_deinterlace(m_option_t *prop, int action,
1023 void *arg, MPContext *mpctx)
1025 int deinterlace;
1026 vf_instance_t *vf;
1027 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1028 return M_PROPERTY_UNAVAILABLE;
1029 vf = mpctx->sh_video->vfilter;
1030 switch (action) {
1031 case M_PROPERTY_GET:
1032 if (!arg)
1033 return M_PROPERTY_ERROR;
1034 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1035 return M_PROPERTY_OK;
1036 case M_PROPERTY_SET:
1037 if (!arg)
1038 return M_PROPERTY_ERROR;
1039 M_PROPERTY_CLAMP(prop, *(int *) arg);
1040 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1041 return M_PROPERTY_OK;
1042 case M_PROPERTY_STEP_UP:
1043 case M_PROPERTY_STEP_DOWN:
1044 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1045 deinterlace = !deinterlace;
1046 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1047 return M_PROPERTY_OK;
1049 int value = 0;
1050 vf->control(vf, VFCTRL_GET_DEINTERLACE, &value);
1051 return m_property_flag_ro(prop, action, arg, value);
1054 /// Panscan (RW)
1055 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1056 MPContext *mpctx)
1059 if (!mpctx->video_out
1060 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1061 return M_PROPERTY_UNAVAILABLE;
1063 switch (action) {
1064 case M_PROPERTY_SET:
1065 if (!arg)
1066 return M_PROPERTY_ERROR;
1067 M_PROPERTY_CLAMP(prop, *(float *) arg);
1068 vo_panscan = *(float *) arg;
1069 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1070 return M_PROPERTY_OK;
1071 case M_PROPERTY_STEP_UP:
1072 case M_PROPERTY_STEP_DOWN:
1073 vo_panscan += (arg ? *(float *) arg : 0.1) *
1074 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1075 if (vo_panscan > 1)
1076 vo_panscan = 1;
1077 else if (vo_panscan < 0)
1078 vo_panscan = 0;
1079 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1080 return M_PROPERTY_OK;
1081 default:
1082 return m_property_float_range(prop, action, arg, &vo_panscan);
1086 /// Helper to set vo flags.
1087 /** \ingroup PropertyImplHelper
1089 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1090 int vo_ctrl, int *vo_var, MPContext *mpctx)
1093 if (!mpctx->video_out)
1094 return M_PROPERTY_UNAVAILABLE;
1096 switch (action) {
1097 case M_PROPERTY_SET:
1098 if (!arg)
1099 return M_PROPERTY_ERROR;
1100 M_PROPERTY_CLAMP(prop, *(int *) arg);
1101 if (*vo_var == !!*(int *) arg)
1102 return M_PROPERTY_OK;
1103 case M_PROPERTY_STEP_UP:
1104 case M_PROPERTY_STEP_DOWN:
1105 if (mpctx->video_out->config_ok)
1106 vo_control(mpctx->video_out, vo_ctrl, 0);
1107 return M_PROPERTY_OK;
1108 default:
1109 return m_property_flag(prop, action, arg, vo_var);
1113 /// Window always on top (RW)
1114 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1115 MPContext *mpctx)
1117 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1118 &mpctx->opts.vo_ontop, mpctx);
1121 /// Display in the root window (RW)
1122 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1123 MPContext *mpctx)
1125 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1126 &vo_rootwin, mpctx);
1129 /// Show window borders (RW)
1130 static int mp_property_border(m_option_t *prop, int action, void *arg,
1131 MPContext *mpctx)
1133 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1134 &vo_border, mpctx);
1137 /// Framedropping state (RW)
1138 static int mp_property_framedropping(m_option_t *prop, int action,
1139 void *arg, MPContext *mpctx)
1142 if (!mpctx->sh_video)
1143 return M_PROPERTY_UNAVAILABLE;
1145 switch (action) {
1146 case M_PROPERTY_PRINT:
1147 if (!arg)
1148 return M_PROPERTY_ERROR;
1149 *(char **) arg = strdup(frame_dropping == 1 ? _("enabled") :
1150 (frame_dropping == 2 ? _("hard") :
1151 _("disabled")));
1152 return M_PROPERTY_OK;
1153 default:
1154 return m_property_choice(prop, action, arg, &frame_dropping);
1158 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1159 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1160 MPContext *mpctx)
1162 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1163 int r, val;
1165 if (!mpctx->sh_video)
1166 return M_PROPERTY_UNAVAILABLE;
1168 if (gamma[0] == 1000) {
1169 gamma[0] = 0;
1170 get_video_colors(mpctx->sh_video, prop->name, gamma);
1173 switch (action) {
1174 case M_PROPERTY_SET:
1175 if (!arg)
1176 return M_PROPERTY_ERROR;
1177 M_PROPERTY_CLAMP(prop, *(int *) arg);
1178 *gamma = *(int *) arg;
1179 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1180 if (r <= 0)
1181 break;
1182 return r;
1183 case M_PROPERTY_GET:
1184 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1185 if (!arg)
1186 return M_PROPERTY_ERROR;
1187 *(int *)arg = val;
1188 return M_PROPERTY_OK;
1190 break;
1191 case M_PROPERTY_STEP_UP:
1192 case M_PROPERTY_STEP_DOWN:
1193 *gamma += (arg ? *(int *) arg : 1) *
1194 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1195 M_PROPERTY_CLAMP(prop, *gamma);
1196 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1197 if (r <= 0)
1198 break;
1199 return r;
1200 default:
1201 return M_PROPERTY_NOT_IMPLEMENTED;
1204 #ifdef CONFIG_TV
1205 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1206 int l = strlen(prop->name);
1207 char tv_prop[3 + l + 1];
1208 sprintf(tv_prop, "tv_%s", prop->name);
1209 return mp_property_do(tv_prop, action, arg, mpctx);
1211 #endif
1213 return M_PROPERTY_UNAVAILABLE;
1216 /// VSync (RW)
1217 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1218 MPContext *mpctx)
1220 return m_property_flag(prop, action, arg, &vo_vsync);
1223 /// Video codec tag (RO)
1224 static int mp_property_video_format(m_option_t *prop, int action,
1225 void *arg, MPContext *mpctx)
1227 char* meta;
1228 if (!mpctx->sh_video)
1229 return M_PROPERTY_UNAVAILABLE;
1230 switch(action) {
1231 case M_PROPERTY_PRINT:
1232 if (!arg)
1233 return M_PROPERTY_ERROR;
1234 switch(mpctx->sh_video->format) {
1235 case 0x10000001:
1236 meta = strdup ("mpeg1"); break;
1237 case 0x10000002:
1238 meta = strdup ("mpeg2"); break;
1239 case 0x10000004:
1240 meta = strdup ("mpeg4"); break;
1241 case 0x10000005:
1242 meta = strdup ("h264"); break;
1243 default:
1244 if(mpctx->sh_video->format >= 0x20202020) {
1245 meta = malloc(5);
1246 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1247 } else {
1248 meta = malloc(20);
1249 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1252 *(char**)arg = meta;
1253 return M_PROPERTY_OK;
1255 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1258 /// Video codec name (RO)
1259 static int mp_property_video_codec(m_option_t *prop, int action,
1260 void *arg, MPContext *mpctx)
1262 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1263 return M_PROPERTY_UNAVAILABLE;
1264 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1268 /// Video bitrate (RO)
1269 static int mp_property_video_bitrate(m_option_t *prop, int action,
1270 void *arg, MPContext *mpctx)
1272 if (!mpctx->sh_video)
1273 return M_PROPERTY_UNAVAILABLE;
1274 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1277 /// Video display width (RO)
1278 static int mp_property_width(m_option_t *prop, int action, void *arg,
1279 MPContext *mpctx)
1281 if (!mpctx->sh_video)
1282 return M_PROPERTY_UNAVAILABLE;
1283 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1286 /// Video display height (RO)
1287 static int mp_property_height(m_option_t *prop, int action, void *arg,
1288 MPContext *mpctx)
1290 if (!mpctx->sh_video)
1291 return M_PROPERTY_UNAVAILABLE;
1292 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1295 /// Video fps (RO)
1296 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1297 MPContext *mpctx)
1299 if (!mpctx->sh_video)
1300 return M_PROPERTY_UNAVAILABLE;
1301 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1304 /// Video aspect (RO)
1305 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1306 MPContext *mpctx)
1308 if (!mpctx->sh_video)
1309 return M_PROPERTY_UNAVAILABLE;
1310 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1313 ///@}
1315 /// \defgroup SubProprties Subtitles properties
1316 /// \ingroup Properties
1317 ///@{
1319 /// Text subtitle position (RW)
1320 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1321 MPContext *mpctx)
1323 if (!mpctx->sh_video)
1324 return M_PROPERTY_UNAVAILABLE;
1326 switch (action) {
1327 case M_PROPERTY_SET:
1328 if (!arg)
1329 return M_PROPERTY_ERROR;
1330 case M_PROPERTY_STEP_UP:
1331 case M_PROPERTY_STEP_DOWN:
1332 vo_osd_changed(OSDTYPE_SUBTITLE);
1333 default:
1334 return m_property_int_range(prop, action, arg, &sub_pos);
1338 /// Selected subtitles (RW)
1339 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1340 MPContext *mpctx)
1342 struct MPOpts *opts = &mpctx->opts;
1343 demux_stream_t *const d_sub = mpctx->d_sub;
1344 const int global_sub_size = mpctx->global_sub_size;
1345 int source = -1, reset_spu = 0;
1346 char *sub_name;
1348 if (global_sub_size <= 0)
1349 return M_PROPERTY_UNAVAILABLE;
1351 switch (action) {
1352 case M_PROPERTY_GET:
1353 if (!arg)
1354 return M_PROPERTY_ERROR;
1355 *(int *) arg = mpctx->global_sub_pos;
1356 return M_PROPERTY_OK;
1357 case M_PROPERTY_PRINT:
1358 if (!arg)
1359 return M_PROPERTY_ERROR;
1360 *(char **) arg = malloc(64);
1361 (*(char **) arg)[63] = 0;
1362 sub_name = 0;
1363 if (subdata)
1364 sub_name = subdata->filename;
1365 #ifdef CONFIG_ASS
1366 if (ass_track && ass_track->name)
1367 sub_name = ass_track->name;
1368 #endif
1369 if (sub_name) {
1370 char *tmp, *tmp2;
1371 tmp = sub_name;
1372 if ((tmp2 = strrchr(tmp, '/')))
1373 tmp = tmp2 + 1;
1375 snprintf(*(char **) arg, 63, "(%d) %s%s",
1376 mpctx->set_of_sub_pos + 1,
1377 strlen(tmp) < 20 ? "" : "...",
1378 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1379 return M_PROPERTY_OK;
1381 #ifdef CONFIG_DVDNAV
1382 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1383 if (vo_spudec && opts->sub_id >= 0) {
1384 unsigned char lang[3];
1385 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1386 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1387 return M_PROPERTY_OK;
1391 #endif
1393 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1394 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1395 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1396 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1397 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1398 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1399 if (!lang) lang = _("unknown");
1400 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1401 return M_PROPERTY_OK;
1404 if (vo_vobsub && vobsub_id >= 0) {
1405 const char *language = _("unknown");
1406 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1407 snprintf(*(char **) arg, 63, "(%d) %s",
1408 vobsub_id, language ? language : _("unknown"));
1409 return M_PROPERTY_OK;
1411 #ifdef CONFIG_DVDREAD
1412 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1413 && opts->sub_id >= 0) {
1414 char lang[3];
1415 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1416 lang[0] = code >> 8;
1417 lang[1] = code;
1418 lang[2] = 0;
1419 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1420 return M_PROPERTY_OK;
1422 #endif
1423 if (opts->sub_id >= 0) {
1424 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, _("unknown"));
1425 return M_PROPERTY_OK;
1427 snprintf(*(char **) arg, 63, _("disabled"));
1428 return M_PROPERTY_OK;
1430 case M_PROPERTY_SET:
1431 if (!arg)
1432 return M_PROPERTY_ERROR;
1433 if (*(int *) arg < -1)
1434 *(int *) arg = -1;
1435 else if (*(int *) arg >= global_sub_size)
1436 *(int *) arg = global_sub_size - 1;
1437 mpctx->global_sub_pos = *(int *) arg;
1438 break;
1439 case M_PROPERTY_STEP_UP:
1440 mpctx->global_sub_pos += 2;
1441 mpctx->global_sub_pos =
1442 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1443 break;
1444 case M_PROPERTY_STEP_DOWN:
1445 mpctx->global_sub_pos += global_sub_size + 1;
1446 mpctx->global_sub_pos =
1447 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1448 break;
1449 default:
1450 return M_PROPERTY_NOT_IMPLEMENTED;
1453 if (mpctx->global_sub_pos >= 0)
1454 source = sub_source(mpctx);
1456 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1457 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1458 global_sub_size,
1459 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1460 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1461 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1462 mpctx->global_sub_pos, source);
1464 mpctx->set_of_sub_pos = -1;
1465 subdata = NULL;
1467 vobsub_id = -1;
1468 opts->sub_id = -1;
1469 if (d_sub) {
1470 if (d_sub->id > -2)
1471 reset_spu = 1;
1472 d_sub->id = -2;
1474 #ifdef CONFIG_ASS
1475 ass_track = 0;
1476 #endif
1478 if (source == SUB_SOURCE_VOBSUB) {
1479 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1480 } else if (source == SUB_SOURCE_SUBS) {
1481 mpctx->set_of_sub_pos =
1482 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1483 #ifdef CONFIG_ASS
1484 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1485 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1486 else
1487 #endif
1489 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1490 vo_osd_changed(OSDTYPE_SUBTITLE);
1492 } else if (source == SUB_SOURCE_DEMUX) {
1493 opts->sub_id =
1494 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1495 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1496 int i = 0;
1497 // default: assume 1:1 mapping of sid and stream id
1498 d_sub->id = opts->sub_id;
1499 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1500 ds_free_packs(d_sub);
1501 for (i = 0; i < MAX_S_STREAMS; i++) {
1502 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1503 if (sh && sh->sid == opts->sub_id) {
1504 d_sub->id = i;
1505 d_sub->sh = sh;
1506 break;
1509 if (d_sub->sh && d_sub->id >= 0) {
1510 sh_sub_t *sh = d_sub->sh;
1511 if (sh->type == 'v')
1512 init_vo_spudec(mpctx);
1513 #ifdef CONFIG_ASS
1514 else if (ass_enabled)
1515 ass_track = sh->ass_track;
1516 #endif
1517 } else {
1518 d_sub->id = -2;
1519 d_sub->sh = NULL;
1523 #ifdef CONFIG_DVDREAD
1524 if (vo_spudec
1525 && (mpctx->stream->type == STREAMTYPE_DVD
1526 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1527 && opts->sub_id < 0 && reset_spu) {
1528 opts->sub_id = -2;
1529 d_sub->id = opts->sub_id;
1531 #endif
1533 update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, 0, 0, d_sub, 1);
1535 return M_PROPERTY_OK;
1538 /// Selected sub source (RW)
1539 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1540 MPContext *mpctx)
1542 int source;
1543 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1544 return M_PROPERTY_UNAVAILABLE;
1546 switch (action) {
1547 case M_PROPERTY_GET:
1548 if (!arg)
1549 return M_PROPERTY_ERROR;
1550 *(int *) arg = sub_source(mpctx);
1551 return M_PROPERTY_OK;
1552 case M_PROPERTY_PRINT:
1553 if (!arg)
1554 return M_PROPERTY_ERROR;
1555 *(char **) arg = malloc(64);
1556 (*(char **) arg)[63] = 0;
1557 switch (sub_source(mpctx))
1559 case SUB_SOURCE_SUBS:
1560 snprintf(*(char **) arg, 63, _("file"));
1561 break;
1562 case SUB_SOURCE_VOBSUB:
1563 snprintf(*(char **) arg, 63, _("vobsub"));
1564 break;
1565 case SUB_SOURCE_DEMUX:
1566 snprintf(*(char **) arg, 63, _("embedded"));
1567 break;
1568 default:
1569 snprintf(*(char **) arg, 63, _("disabled"));
1571 return M_PROPERTY_OK;
1572 case M_PROPERTY_SET:
1573 if (!arg)
1574 return M_PROPERTY_ERROR;
1575 M_PROPERTY_CLAMP(prop, *(int*)arg);
1576 if (*(int *) arg < 0)
1577 mpctx->global_sub_pos = -1;
1578 else if (*(int *) arg != sub_source(mpctx)) {
1579 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1580 return M_PROPERTY_UNAVAILABLE;
1581 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1583 break;
1584 case M_PROPERTY_STEP_UP:
1585 case M_PROPERTY_STEP_DOWN: {
1586 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1587 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1588 int step = (step_all > 0) ? 1 : -1;
1589 int cur_source = sub_source(mpctx);
1590 source = cur_source;
1591 while (step_all) {
1592 source += step;
1593 if (source >= SUB_SOURCES)
1594 source = -1;
1595 else if (source < -1)
1596 source = SUB_SOURCES - 1;
1597 if (source == cur_source || source == -1 ||
1598 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1599 step_all -= step;
1601 if (source == cur_source)
1602 return M_PROPERTY_OK;
1603 if (source == -1)
1604 mpctx->global_sub_pos = -1;
1605 else
1606 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1607 break;
1609 default:
1610 return M_PROPERTY_NOT_IMPLEMENTED;
1612 --mpctx->global_sub_pos;
1613 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1616 /// Selected subtitles from specific source (RW)
1617 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1618 MPContext *mpctx)
1620 int source, is_cur_source, offset;
1621 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1622 return M_PROPERTY_UNAVAILABLE;
1624 if (!strcmp(prop->name, "sub_file"))
1625 source = SUB_SOURCE_SUBS;
1626 else if (!strcmp(prop->name, "sub_vob"))
1627 source = SUB_SOURCE_VOBSUB;
1628 else if (!strcmp(prop->name, "sub_demux"))
1629 source = SUB_SOURCE_DEMUX;
1630 else
1631 return M_PROPERTY_ERROR;
1633 offset = mpctx->global_sub_indices[source];
1634 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1635 return M_PROPERTY_UNAVAILABLE;
1637 is_cur_source = sub_source(mpctx) == source;
1638 switch (action) {
1639 case M_PROPERTY_GET:
1640 if (!arg)
1641 return M_PROPERTY_ERROR;
1642 if (is_cur_source) {
1643 *(int *) arg = mpctx->global_sub_pos - offset;
1644 if (source == SUB_SOURCE_VOBSUB)
1645 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1647 else
1648 *(int *) arg = -1;
1649 return M_PROPERTY_OK;
1650 case M_PROPERTY_PRINT:
1651 if (!arg)
1652 return M_PROPERTY_ERROR;
1653 if (is_cur_source)
1654 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1655 *(char **) arg = malloc(64);
1656 (*(char **) arg)[63] = 0;
1657 snprintf(*(char **) arg, 63, _("disabled"));
1658 return M_PROPERTY_OK;
1659 case M_PROPERTY_SET:
1660 if (!arg)
1661 return M_PROPERTY_ERROR;
1662 if (*(int *) arg >= 0) {
1663 int index = *(int *)arg;
1664 if (source == SUB_SOURCE_VOBSUB)
1665 index = vobsub_get_index_by_id(vo_vobsub, index);
1666 mpctx->global_sub_pos = offset + index;
1667 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1668 || sub_source(mpctx) != source) {
1669 mpctx->global_sub_pos = -1;
1670 *(int *) arg = -1;
1673 else
1674 mpctx->global_sub_pos = -1;
1675 break;
1676 case M_PROPERTY_STEP_UP:
1677 case M_PROPERTY_STEP_DOWN: {
1678 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1679 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1680 int step = (step_all > 0) ? 1 : -1;
1681 int max_sub_pos_for_source = -1;
1682 if (!is_cur_source)
1683 mpctx->global_sub_pos = -1;
1684 while (step_all) {
1685 if (mpctx->global_sub_pos == -1) {
1686 if (step > 0)
1687 mpctx->global_sub_pos = offset;
1688 else if (max_sub_pos_for_source == -1) {
1689 // Find max pos for specific source
1690 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1691 while (mpctx->global_sub_pos >= 0
1692 && sub_source(mpctx) != source)
1693 --mpctx->global_sub_pos;
1695 else
1696 mpctx->global_sub_pos = max_sub_pos_for_source;
1698 else {
1699 mpctx->global_sub_pos += step;
1700 if (mpctx->global_sub_pos < offset ||
1701 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1702 sub_source(mpctx) != source)
1703 mpctx->global_sub_pos = -1;
1705 step_all -= step;
1707 break;
1709 default:
1710 return M_PROPERTY_NOT_IMPLEMENTED;
1712 --mpctx->global_sub_pos;
1713 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1716 /// Subtitle delay (RW)
1717 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1718 MPContext *mpctx)
1720 if (!mpctx->sh_video)
1721 return M_PROPERTY_UNAVAILABLE;
1722 return m_property_delay(prop, action, arg, &sub_delay);
1725 /// Alignment of text subtitles (RW)
1726 static int mp_property_sub_alignment(m_option_t *prop, int action,
1727 void *arg, MPContext *mpctx)
1729 char *name[] = { _("top"), _("center"), _("bottom") };
1731 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1732 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1733 return M_PROPERTY_UNAVAILABLE;
1735 switch (action) {
1736 case M_PROPERTY_PRINT:
1737 if (!arg)
1738 return M_PROPERTY_ERROR;
1739 M_PROPERTY_CLAMP(prop, sub_alignment);
1740 *(char **) arg = strdup(name[sub_alignment]);
1741 return M_PROPERTY_OK;
1742 case M_PROPERTY_SET:
1743 if (!arg)
1744 return M_PROPERTY_ERROR;
1745 case M_PROPERTY_STEP_UP:
1746 case M_PROPERTY_STEP_DOWN:
1747 vo_osd_changed(OSDTYPE_SUBTITLE);
1748 default:
1749 return m_property_choice(prop, action, arg, &sub_alignment);
1753 /// Subtitle visibility (RW)
1754 static int mp_property_sub_visibility(m_option_t *prop, int action,
1755 void *arg, MPContext *mpctx)
1757 if (!mpctx->sh_video)
1758 return M_PROPERTY_UNAVAILABLE;
1760 switch (action) {
1761 case M_PROPERTY_SET:
1762 if (!arg)
1763 return M_PROPERTY_ERROR;
1764 case M_PROPERTY_STEP_UP:
1765 case M_PROPERTY_STEP_DOWN:
1766 vo_osd_changed(OSDTYPE_SUBTITLE);
1767 if (vo_spudec)
1768 vo_osd_changed(OSDTYPE_SPU);
1769 default:
1770 return m_property_flag(prop, action, arg, &sub_visibility);
1774 #ifdef CONFIG_ASS
1775 /// Use margins for libass subtitles (RW)
1776 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1777 void *arg, MPContext *mpctx)
1779 if (!mpctx->sh_video)
1780 return M_PROPERTY_UNAVAILABLE;
1782 switch (action) {
1783 case M_PROPERTY_SET:
1784 if (!arg)
1785 return M_PROPERTY_ERROR;
1786 case M_PROPERTY_STEP_UP:
1787 case M_PROPERTY_STEP_DOWN:
1788 ass_force_reload = 1;
1789 default:
1790 return m_property_flag(prop, action, arg, &ass_use_margins);
1793 #endif
1795 /// Show only forced subtitles (RW)
1796 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1797 void *arg, MPContext *mpctx)
1799 if (!vo_spudec)
1800 return M_PROPERTY_UNAVAILABLE;
1802 switch (action) {
1803 case M_PROPERTY_SET:
1804 if (!arg)
1805 return M_PROPERTY_ERROR;
1806 case M_PROPERTY_STEP_UP:
1807 case M_PROPERTY_STEP_DOWN:
1808 m_property_flag(prop, action, arg, &forced_subs_only);
1809 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1810 return M_PROPERTY_OK;
1811 default:
1812 return m_property_flag(prop, action, arg, &forced_subs_only);
1817 #ifdef CONFIG_FREETYPE
1818 /// Subtitle scale (RW)
1819 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1820 MPContext *mpctx)
1823 switch (action) {
1824 case M_PROPERTY_SET:
1825 if (!arg)
1826 return M_PROPERTY_ERROR;
1827 M_PROPERTY_CLAMP(prop, *(float *) arg);
1828 #ifdef CONFIG_ASS
1829 if (ass_enabled) {
1830 ass_font_scale = *(float *) arg;
1831 ass_force_reload = 1;
1833 #endif
1834 text_font_scale_factor = *(float *) arg;
1835 force_load_font = 1;
1836 return M_PROPERTY_OK;
1837 case M_PROPERTY_STEP_UP:
1838 case M_PROPERTY_STEP_DOWN:
1839 #ifdef CONFIG_ASS
1840 if (ass_enabled) {
1841 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1842 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1843 M_PROPERTY_CLAMP(prop, ass_font_scale);
1844 ass_force_reload = 1;
1846 #endif
1847 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1848 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1849 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1850 force_load_font = 1;
1851 return M_PROPERTY_OK;
1852 default:
1853 #ifdef CONFIG_ASS
1854 if (ass_enabled)
1855 return m_property_float_ro(prop, action, arg, ass_font_scale);
1856 else
1857 #endif
1858 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1861 #endif
1863 ///@}
1865 /// \defgroup TVProperties TV properties
1866 /// \ingroup Properties
1867 ///@{
1869 #ifdef CONFIG_TV
1871 /// TV color settings (RW)
1872 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1873 MPContext *mpctx)
1875 int r, val;
1876 tvi_handle_t *tvh = mpctx->demuxer->priv;
1877 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1878 return M_PROPERTY_UNAVAILABLE;
1880 switch (action) {
1881 case M_PROPERTY_SET:
1882 if (!arg)
1883 return M_PROPERTY_ERROR;
1884 M_PROPERTY_CLAMP(prop, *(int *) arg);
1885 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1886 case M_PROPERTY_GET:
1887 return tv_get_color_options(tvh, (int) prop->priv, arg);
1888 case M_PROPERTY_STEP_UP:
1889 case M_PROPERTY_STEP_DOWN:
1890 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1891 if (!r)
1892 return M_PROPERTY_ERROR;
1893 val += (arg ? *(int *) arg : 1) *
1894 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1895 M_PROPERTY_CLAMP(prop, val);
1896 return tv_set_color_options(tvh, (int) prop->priv, val);
1898 return M_PROPERTY_ERROR;
1900 return M_PROPERTY_NOT_IMPLEMENTED;
1903 #endif
1905 #ifdef CONFIG_TV_TELETEXT
1906 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1907 MPContext *mpctx)
1909 int val,result;
1910 int base_ioctl=(int)prop->priv;
1912 for teletext's GET,SET,STEP ioctls this is not 0
1913 SET is GET+1
1914 STEP is GET+2
1916 tvi_handle_t *tvh = mpctx->demuxer->priv;
1917 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1918 return M_PROPERTY_UNAVAILABLE;
1919 if(!base_ioctl)
1920 return M_PROPERTY_ERROR;
1922 switch (action) {
1923 case M_PROPERTY_GET:
1924 if (!arg)
1925 return M_PROPERTY_ERROR;
1926 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1927 break;
1928 case M_PROPERTY_SET:
1929 if (!arg)
1930 return M_PROPERTY_ERROR;
1931 M_PROPERTY_CLAMP(prop, *(int *) arg);
1932 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1933 break;
1934 case M_PROPERTY_STEP_UP:
1935 case M_PROPERTY_STEP_DOWN:
1936 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1937 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1938 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1939 break;
1940 default:
1941 return M_PROPERTY_NOT_IMPLEMENTED;
1944 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1947 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
1948 MPContext *mpctx)
1950 tvi_handle_t *tvh = mpctx->demuxer->priv;
1951 int result;
1952 int val;
1954 //with tvh==NULL will fail too
1955 result=mp_property_teletext_common(prop,action,arg,mpctx);
1956 if(result!=M_PROPERTY_OK)
1957 return result;
1959 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1960 mp_input_set_section(mpctx->input, "teletext");
1961 else
1962 mp_input_set_section(mpctx->input, "tv");
1963 return M_PROPERTY_OK;
1966 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
1967 MPContext *mpctx)
1969 tvi_handle_t *tvh = mpctx->demuxer->priv;
1970 int result;
1971 int val;
1972 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1973 return M_PROPERTY_UNAVAILABLE;
1974 switch(action){
1975 case M_PROPERTY_STEP_UP:
1976 case M_PROPERTY_STEP_DOWN:
1977 //This should be handled separately
1978 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1979 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1980 break;
1981 default:
1982 result=mp_property_teletext_common(prop,action,arg,mpctx);
1984 return result;
1988 #endif /* CONFIG_TV_TELETEXT */
1990 ///@}
1992 /// All properties available in MPlayer.
1993 /** \ingroup Properties
1995 static const m_option_t mp_properties[] = {
1996 // General
1997 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1998 M_OPT_RANGE, 0, 3, NULL },
1999 { "loop", mp_property_loop, CONF_TYPE_INT,
2000 M_OPT_MIN, -1, 0, NULL },
2001 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2002 M_OPT_RANGE, 0.01, 100.0, NULL },
2003 { "filename", mp_property_filename, CONF_TYPE_STRING,
2004 0, 0, 0, NULL },
2005 { "path", mp_property_path, CONF_TYPE_STRING,
2006 0, 0, 0, NULL },
2007 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2008 0, 0, 0, NULL },
2009 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2010 M_OPT_MIN, 0, 0, NULL },
2011 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2012 M_OPT_MIN, 0, 0, NULL },
2013 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2014 M_OPT_MIN, 0, 0, NULL },
2015 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2016 M_OPT_MIN, 0, 0, NULL },
2017 { "length", mp_property_length, CONF_TYPE_TIME,
2018 M_OPT_MIN, 0, 0, NULL },
2019 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2020 M_OPT_RANGE, 0, 100, NULL },
2021 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2022 M_OPT_MIN, 0, 0, NULL },
2023 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2024 M_OPT_MIN, 0, 0, NULL },
2025 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2026 0, 0, 0, NULL },
2027 { "angle", mp_property_angle, CONF_TYPE_INT,
2028 CONF_RANGE, -2, 10, NULL },
2029 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2030 0, 0, 0, NULL },
2031 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2032 M_OPT_RANGE, 0, 1, NULL },
2034 // Audio
2035 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2036 M_OPT_RANGE, 0, 100, NULL },
2037 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2038 M_OPT_RANGE, 0, 1, NULL },
2039 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2040 M_OPT_RANGE, -100, 100, NULL },
2041 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2042 0, 0, 0, NULL },
2043 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2044 0, 0, 0, NULL },
2045 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2046 0, 0, 0, NULL },
2047 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2048 0, 0, 0, NULL },
2049 { "channels", mp_property_channels, CONF_TYPE_INT,
2050 0, 0, 0, NULL },
2051 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2052 CONF_RANGE, -2, 65535, NULL },
2053 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2054 M_OPT_RANGE, -1, 1, NULL },
2056 // Video
2057 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2058 M_OPT_RANGE, 0, 1, NULL },
2059 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2060 M_OPT_RANGE, 0, 1, NULL },
2061 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2062 M_OPT_RANGE, 0, 1, NULL },
2063 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2064 M_OPT_RANGE, 0, 1, NULL },
2065 { "border", mp_property_border, CONF_TYPE_FLAG,
2066 M_OPT_RANGE, 0, 1, NULL },
2067 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2068 M_OPT_RANGE, 0, 2, NULL },
2069 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2070 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2071 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2072 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2073 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2074 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2075 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2076 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2077 { "hue", mp_property_gamma, CONF_TYPE_INT,
2078 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2079 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2080 M_OPT_RANGE, 0, 1, NULL },
2081 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2082 M_OPT_RANGE, 0, 1, NULL },
2083 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2084 0, 0, 0, NULL },
2085 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2086 0, 0, 0, NULL },
2087 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2088 0, 0, 0, NULL },
2089 { "width", mp_property_width, CONF_TYPE_INT,
2090 0, 0, 0, NULL },
2091 { "height", mp_property_height, CONF_TYPE_INT,
2092 0, 0, 0, NULL },
2093 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2094 0, 0, 0, NULL },
2095 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2096 0, 0, 0, NULL },
2097 { "switch_video", mp_property_video, CONF_TYPE_INT,
2098 CONF_RANGE, -2, 65535, NULL },
2099 { "switch_program", mp_property_program, CONF_TYPE_INT,
2100 CONF_RANGE, -1, 65535, NULL },
2102 // Subs
2103 { "sub", mp_property_sub, CONF_TYPE_INT,
2104 M_OPT_MIN, -1, 0, NULL },
2105 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2106 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2107 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2108 M_OPT_MIN, -1, 0, NULL },
2109 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2110 M_OPT_MIN, -1, 0, NULL },
2111 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2112 M_OPT_MIN, -1, 0, NULL },
2113 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2114 0, 0, 0, NULL },
2115 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2116 M_OPT_RANGE, 0, 100, NULL },
2117 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2118 M_OPT_RANGE, 0, 2, NULL },
2119 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2120 M_OPT_RANGE, 0, 1, NULL },
2121 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2122 M_OPT_RANGE, 0, 1, NULL },
2123 #ifdef CONFIG_FREETYPE
2124 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2125 M_OPT_RANGE, 0, 100, NULL },
2126 #endif
2127 #ifdef CONFIG_ASS
2128 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2129 M_OPT_RANGE, 0, 1, NULL },
2130 #endif
2132 #ifdef CONFIG_TV
2133 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2134 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2135 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2136 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2137 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2138 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2139 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2140 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2141 #endif
2143 #ifdef CONFIG_TV_TELETEXT
2144 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2145 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2146 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2147 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2148 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2149 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2150 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2151 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2152 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2153 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2154 #endif
2156 { NULL, NULL, NULL, 0, 0, 0, NULL }
2160 int mp_property_do(const char *name, int action, void *val, void *ctx)
2162 return m_property_do(mp_properties, name, action, val, ctx);
2165 char* mp_property_print(const char *name, void* ctx)
2167 char* ret = NULL;
2168 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2169 return NULL;
2170 return ret;
2173 char *property_expand_string(MPContext *mpctx, char *str)
2175 return m_properties_expand_string(mp_properties, str, mpctx);
2178 void property_print_help(void)
2180 m_properties_print_help_list(mp_properties);
2184 /* List of default ways to show a property on OSD.
2186 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2187 * a bar showing the current position between min/max values of the
2188 * property. In this case osd_msg is only used for terminal output
2189 * if there is no video; it'll be a label shown together with percentage.
2191 * Otherwise setting osd_msg will show the string on OSD, formatted with
2192 * the text value of the property as argument.
2194 static struct property_osd_display {
2195 /// property name
2196 const char *name;
2197 /// progressbar type
2198 int osd_progbar; // -1 is special value for seek indicators
2199 /// osd msg id if it must be shared
2200 int osd_id;
2201 /// osd msg template
2202 const char *osd_msg;
2203 } property_osd_display[] = {
2204 // general
2205 { "loop", 0, -1, _("Loop: %s") },
2206 { "chapter", -1, -1, NULL },
2207 // audio
2208 { "volume", OSD_VOLUME, -1, _("Volume") },
2209 { "mute", 0, -1, _("Mute: %s") },
2210 { "audio_delay", 0, -1, _("A-V delay: %s") },
2211 { "switch_audio", 0, -1, _("Audio: %s") },
2212 { "balance", OSD_BALANCE, -1, _("Balance") },
2213 // video
2214 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2215 { "ontop", 0, -1, _("Stay on top: %s") },
2216 { "rootwin", 0, -1, _("Rootwin: %s") },
2217 { "border", 0, -1, _("Border: %s") },
2218 { "framedropping", 0, -1, _("Framedropping: %s") },
2219 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2220 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2221 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2222 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2223 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2224 { "hue", OSD_HUE, -1, _("Hue") },
2225 { "vsync", 0, -1, _("VSync: %s") },
2226 // subs
2227 { "sub", 0, -1, _("Subtitles: %s") },
2228 { "sub_source", 0, -1, _("Sub source: %s") },
2229 { "sub_vob", 0, -1, _("Subtitles: %s") },
2230 { "sub_demux", 0, -1, _("Subtitles: %s") },
2231 { "sub_file", 0, -1, _("Subtitles: %s") },
2232 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2233 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2234 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2235 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2236 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2237 #ifdef CONFIG_FREETYPE
2238 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2239 #endif
2240 #ifdef CONFIG_TV
2241 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2242 { "tv_hue", OSD_HUE, -1, _("Hue") },
2243 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2244 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2245 #endif
2249 static int show_property_osd(MPContext *mpctx, const char *pname)
2251 struct MPOpts *opts = &mpctx->opts;
2252 int r;
2253 m_option_t* prop;
2254 struct property_osd_display *p;
2256 // look for the command
2257 for (p = property_osd_display; p->name; p++)
2258 if (!strcmp(p->name, pname))
2259 break;
2260 if (!p->name)
2261 return -1;
2263 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2264 return -1;
2266 if (p->osd_progbar == -1)
2267 mpctx->add_osd_seek_info = true;
2268 else if (p->osd_progbar) {
2269 if (prop->type == CONF_TYPE_INT) {
2270 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2271 set_osd_bar(mpctx, p->osd_progbar, p->osd_msg,
2272 prop->min, prop->max, r);
2273 } else if (prop->type == CONF_TYPE_FLOAT) {
2274 float f;
2275 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2276 set_osd_bar(mpctx, p->osd_progbar, p->osd_msg,
2277 prop->min, prop->max, f);
2278 } else {
2279 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2280 "Property use an unsupported type.\n");
2281 return -1;
2283 return 0;
2286 if (p->osd_msg) {
2287 char *val = mp_property_print(pname, mpctx);
2288 if (val) {
2289 int index = p - property_osd_display;
2290 set_osd_msg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2291 1, opts->osd_duration, p->osd_msg, val);
2292 free(val);
2295 return 0;
2300 * \defgroup Command2Property Command to property bridge
2302 * It is used to handle most commands that just set a property
2303 * and optionally display something on the OSD.
2304 * Two kinds of commands are handled: adjust or toggle.
2306 * Adjust commands take 1 or 2 parameters: <value> <abs>
2307 * If <abs> is non-zero the property is set to the given value
2308 * otherwise it is adjusted.
2310 * Toggle commands take 0 or 1 parameters. With no parameter
2311 * or a value less than the property minimum it just steps the
2312 * property to its next value. Otherwise it sets it to the given
2313 * value.
2318 /// List of the commands that can be handled by setting a property.
2319 static struct {
2320 /// property name
2321 const char *name;
2322 /// cmd id
2323 int cmd;
2324 /// set/adjust or toggle command
2325 int toggle;
2326 } set_prop_cmd[] = {
2327 // general
2328 { "loop", MP_CMD_LOOP, 0},
2329 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2330 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2331 { "pause", MP_CMD_PAUSE, 0},
2332 // audio
2333 { "volume", MP_CMD_VOLUME, 0},
2334 { "mute", MP_CMD_MUTE, 1},
2335 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2336 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2337 { "balance", MP_CMD_BALANCE, 0},
2338 // video
2339 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2340 { "panscan", MP_CMD_PANSCAN, 0},
2341 { "ontop", MP_CMD_VO_ONTOP, 1},
2342 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2343 { "border", MP_CMD_VO_BORDER, 1},
2344 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2345 { "gamma", MP_CMD_GAMMA, 0},
2346 { "brightness", MP_CMD_BRIGHTNESS, 0},
2347 { "contrast", MP_CMD_CONTRAST, 0},
2348 { "saturation", MP_CMD_SATURATION, 0},
2349 { "hue", MP_CMD_HUE, 0},
2350 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2351 // subs
2352 { "sub", MP_CMD_SUB_SELECT, 1},
2353 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2354 { "sub_vob", MP_CMD_SUB_VOB, 1},
2355 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2356 { "sub_file", MP_CMD_SUB_FILE, 1},
2357 { "sub_pos", MP_CMD_SUB_POS, 0},
2358 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2359 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2360 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2361 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2362 #ifdef CONFIG_FREETYPE
2363 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2364 #endif
2365 #ifdef CONFIG_ASS
2366 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2367 #endif
2368 #ifdef CONFIG_TV
2369 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2370 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2371 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2372 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2373 #endif
2377 /// Handle commands that set a property.
2378 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2380 int i, r;
2381 m_option_t* prop;
2382 const char *pname;
2384 // look for the command
2385 for (i = 0; set_prop_cmd[i].name; i++)
2386 if (set_prop_cmd[i].cmd == cmd->id)
2387 break;
2388 if (!(pname = set_prop_cmd[i].name))
2389 return 0;
2391 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2392 return 0;
2394 // toggle command
2395 if (set_prop_cmd[i].toggle) {
2396 // set to value
2397 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2398 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2399 else
2400 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2401 } else if (cmd->args[1].v.i) //set
2402 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2403 else // adjust
2404 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2406 if (r <= 0)
2407 return 1;
2409 show_property_osd(mpctx, pname);
2411 return 1;
2414 #ifdef CONFIG_DVDNAV
2415 static const struct {
2416 const char *name;
2417 const mp_command_type cmd;
2418 } mp_dvdnav_bindings[] = {
2419 { "up", MP_CMD_DVDNAV_UP },
2420 { "down", MP_CMD_DVDNAV_DOWN },
2421 { "left", MP_CMD_DVDNAV_LEFT },
2422 { "right", MP_CMD_DVDNAV_RIGHT },
2423 { "menu", MP_CMD_DVDNAV_MENU },
2424 { "select", MP_CMD_DVDNAV_SELECT },
2425 { "prev", MP_CMD_DVDNAV_PREVMENU },
2426 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2429 * keep old dvdnav sub-command options for a while in order not to
2430 * break slave-mode API too suddenly.
2432 { "1", MP_CMD_DVDNAV_UP },
2433 { "2", MP_CMD_DVDNAV_DOWN },
2434 { "3", MP_CMD_DVDNAV_LEFT },
2435 { "4", MP_CMD_DVDNAV_RIGHT },
2436 { "5", MP_CMD_DVDNAV_MENU },
2437 { "6", MP_CMD_DVDNAV_SELECT },
2438 { "7", MP_CMD_DVDNAV_PREVMENU },
2439 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2440 { NULL, 0 }
2442 #endif
2444 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2446 struct MPOpts *opts = &mpctx->opts;
2447 sh_audio_t * const sh_audio = mpctx->sh_audio;
2448 sh_video_t * const sh_video = mpctx->sh_video;
2449 int osd_duration = opts->osd_duration;
2450 int case_fallthrough_hack = 0;
2451 if (!set_property_command(mpctx, cmd))
2452 switch (cmd->id) {
2453 case MP_CMD_SEEK:{
2454 float v;
2455 int abs;
2456 mpctx->add_osd_seek_info = true;
2457 v = cmd->args[0].v.f;
2458 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2459 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2460 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2461 if (sh_video)
2462 mpctx->osd_function =
2463 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2464 mpctx->rel_seek_secs = v;
2465 } else if (abs) { /* Absolute seek by percentage */
2466 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2467 if (sh_video)
2468 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2469 mpctx->rel_seek_secs = v / 100.0;
2470 } else {
2471 mpctx->rel_seek_secs += v;
2472 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2475 break;
2477 case MP_CMD_SET_PROPERTY_OSD:
2478 case_fallthrough_hack = 1;
2480 case MP_CMD_SET_PROPERTY:{
2481 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2482 cmd->args[1].v.s, mpctx);
2483 if (r == M_PROPERTY_UNKNOWN)
2484 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2485 "Unknown property: '%s'\n", cmd->args[0].v.s);
2486 else if (r <= 0)
2487 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2488 "Failed to set property '%s' to '%s'.\n",
2489 cmd->args[0].v.s, cmd->args[1].v.s);
2490 else if (case_fallthrough_hack)
2491 show_property_osd(mpctx, cmd->args[0].v.s);
2493 break;
2495 case MP_CMD_STEP_PROPERTY_OSD:
2496 case_fallthrough_hack = 1;
2498 case MP_CMD_STEP_PROPERTY:{
2499 void* arg = NULL;
2500 int r,i;
2501 double d;
2502 off_t o;
2503 if (cmd->args[1].v.f) {
2504 m_option_t* prop;
2505 if((r = mp_property_do(cmd->args[0].v.s,
2506 M_PROPERTY_GET_TYPE,
2507 &prop, mpctx)) <= 0)
2508 goto step_prop_err;
2509 if(prop->type == CONF_TYPE_INT ||
2510 prop->type == CONF_TYPE_FLAG)
2511 i = cmd->args[1].v.f, arg = &i;
2512 else if(prop->type == CONF_TYPE_FLOAT)
2513 arg = &cmd->args[1].v.f;
2514 else if(prop->type == CONF_TYPE_DOUBLE ||
2515 prop->type == CONF_TYPE_TIME)
2516 d = cmd->args[1].v.f, arg = &d;
2517 else if(prop->type == CONF_TYPE_POSITION)
2518 o = cmd->args[1].v.f, arg = &o;
2519 else
2520 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2521 "Ignoring step size stepping property '%s'.\n",
2522 cmd->args[0].v.s);
2524 r = mp_property_do(cmd->args[0].v.s,
2525 cmd->args[2].v.i < 0 ?
2526 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2527 arg, mpctx);
2528 step_prop_err:
2529 if (r == M_PROPERTY_UNKNOWN)
2530 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2531 "Unknown property: '%s'\n", cmd->args[0].v.s);
2532 else if (r <= 0)
2533 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2534 "Failed to increment property '%s' by %f.\n",
2535 cmd->args[0].v.s, cmd->args[1].v.f);
2536 else if (case_fallthrough_hack)
2537 show_property_osd(mpctx, cmd->args[0].v.s);
2539 break;
2541 case MP_CMD_GET_PROPERTY:{
2542 char *tmp;
2543 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2544 &tmp, mpctx) <= 0) {
2545 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2546 "Failed to get value of property '%s'.\n",
2547 cmd->args[0].v.s);
2548 break;
2550 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2551 cmd->args[0].v.s, tmp);
2552 free(tmp);
2554 break;
2556 case MP_CMD_EDL_MARK:
2557 if (edl_fd) {
2558 float v = sh_video ? sh_video->pts :
2559 playing_audio_pts(mpctx);
2560 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2561 mpctx->begin_skip = v;
2562 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2563 } else {
2564 if (mpctx->begin_skip > v)
2565 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2566 else {
2567 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2568 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2570 mpctx->begin_skip = MP_NOPTS_VALUE;
2573 break;
2575 case MP_CMD_SWITCH_RATIO:
2576 if (!sh_video)
2577 break;
2578 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2579 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2580 else
2581 opts->movie_aspect = cmd->args[0].v.f;
2582 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2583 break;
2585 case MP_CMD_SPEED_INCR:{
2586 float v = cmd->args[0].v.f;
2587 opts->playback_speed += v;
2588 build_afilter_chain(mpctx, sh_audio, &ao_data);
2589 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2590 opts->playback_speed);
2591 } break;
2593 case MP_CMD_SPEED_MULT:{
2594 float v = cmd->args[0].v.f;
2595 opts->playback_speed *= v;
2596 build_afilter_chain(mpctx, sh_audio, &ao_data);
2597 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2598 opts->playback_speed);
2599 } break;
2601 case MP_CMD_SPEED_SET:{
2602 float v = cmd->args[0].v.f;
2603 opts->playback_speed = v;
2604 build_afilter_chain(mpctx, sh_audio, &ao_data);
2605 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2606 opts->playback_speed);
2607 } break;
2609 case MP_CMD_FRAME_STEP:
2610 add_step_frame(mpctx);
2611 break;
2613 case MP_CMD_FILE_FILTER:
2614 file_filter = cmd->args[0].v.i;
2615 break;
2617 case MP_CMD_QUIT:
2618 exit_player_with_rc(mpctx, EXIT_QUIT,
2619 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2621 case MP_CMD_PLAY_TREE_STEP:{
2622 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2623 int force = cmd->args[1].v.i;
2626 if (!force && mpctx->playtree_iter) {
2627 play_tree_iter_t *i =
2628 play_tree_iter_new_copy(mpctx->playtree_iter);
2629 if (play_tree_iter_step(i, n, 0) ==
2630 PLAY_TREE_ITER_ENTRY)
2631 mpctx->stop_play =
2632 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2633 play_tree_iter_free(i);
2634 } else
2635 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2636 if (mpctx->stop_play)
2637 mpctx->play_tree_step = n;
2640 break;
2642 case MP_CMD_PLAY_TREE_UP_STEP:{
2643 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2644 int force = cmd->args[1].v.i;
2646 if (!force && mpctx->playtree_iter) {
2647 play_tree_iter_t *i =
2648 play_tree_iter_new_copy(mpctx->playtree_iter);
2649 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2650 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2651 play_tree_iter_free(i);
2652 } else
2653 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2655 break;
2657 case MP_CMD_PLAY_ALT_SRC_STEP:
2658 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2659 int v = cmd->args[0].v.i;
2660 if (v > 0
2661 && mpctx->playtree_iter->file <
2662 mpctx->playtree_iter->num_files)
2663 mpctx->stop_play = PT_NEXT_SRC;
2664 else if (v < 0 && mpctx->playtree_iter->file > 1)
2665 mpctx->stop_play = PT_PREV_SRC;
2667 break;
2669 case MP_CMD_SUB_STEP:
2670 if (sh_video) {
2671 int movement = cmd->args[0].v.i;
2672 step_sub(subdata, sh_video->pts, movement);
2673 #ifdef CONFIG_ASS
2674 if (ass_track)
2675 sub_delay +=
2676 ass_step_sub(ass_track,
2677 (sh_video->pts +
2678 sub_delay) * 1000 + .5, movement) / 1000.;
2679 #endif
2680 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2681 _("Sub delay: %d ms"), ROUND(sub_delay * 1000));
2683 break;
2685 case MP_CMD_SUB_LOG:
2686 log_sub(mpctx);
2687 break;
2689 case MP_CMD_OSD:{
2690 int v = cmd->args[0].v.i;
2691 int max = (term_osd
2692 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2693 if (opts->osd_level > max)
2694 opts->osd_level = max;
2695 if (v < 0)
2696 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2697 else
2698 opts->osd_level = v > max ? max : v;
2699 /* Show OSD state when disabled, but not when an explicit
2700 argument is given to the OSD command, i.e. in slave mode. */
2701 if (v == -1 && opts->osd_level <= 1)
2702 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2703 _("OSD: %s"),
2704 opts->osd_level ? _("enabled") :
2705 _("disabled"));
2706 else
2707 rm_osd_msg(OSD_MSG_OSD_STATUS);
2709 break;
2711 case MP_CMD_OSD_SHOW_TEXT:
2712 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2713 (cmd->args[1].v.i <
2714 0 ? osd_duration : cmd->args[1].v.i),
2715 "%-.63s", cmd->args[0].v.s);
2716 break;
2718 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2719 char *txt = m_properties_expand_string(mp_properties,
2720 cmd->args[0].v.s,
2721 mpctx);
2722 /* if no argument supplied take default osd_duration, else <arg> ms. */
2723 if (txt) {
2724 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2725 (cmd->args[1].v.i <
2726 0 ? osd_duration : cmd->args[1].v.i),
2727 "%-.63s", txt);
2728 free(txt);
2731 break;
2733 case MP_CMD_LOADFILE:{
2734 play_tree_t *e = play_tree_new();
2735 play_tree_add_file(e, cmd->args[0].v.s);
2737 if (cmd->args[1].v.i) // append
2738 play_tree_append_entry(mpctx->playtree->child, e);
2739 else {
2740 // Go back to the starting point.
2741 while (play_tree_iter_up_step
2742 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2743 /* NOP */ ;
2744 play_tree_free_list(mpctx->playtree->child, 1);
2745 play_tree_set_child(mpctx->playtree, e);
2746 pt_iter_goto_head(mpctx->playtree_iter);
2747 mpctx->stop_play = PT_NEXT_SRC;
2750 break;
2752 case MP_CMD_LOADLIST:{
2753 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2754 if (!e)
2755 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2756 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2757 else {
2758 if (cmd->args[1].v.i) // append
2759 play_tree_append_entry(mpctx->playtree->child, e);
2760 else {
2761 // Go back to the starting point.
2762 while (play_tree_iter_up_step
2763 (mpctx->playtree_iter, 0, 1)
2764 != PLAY_TREE_ITER_END)
2765 /* NOP */ ;
2766 play_tree_free_list(mpctx->playtree->child, 1);
2767 play_tree_set_child(mpctx->playtree, e);
2768 pt_iter_goto_head(mpctx->playtree_iter);
2769 mpctx->stop_play = PT_NEXT_SRC;
2773 break;
2775 case MP_CMD_STOP:
2776 // Go back to the starting point.
2777 while (play_tree_iter_up_step
2778 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2779 /* NOP */ ;
2780 mpctx->stop_play = PT_STOP;
2781 break;
2783 #ifdef CONFIG_RADIO
2784 case MP_CMD_RADIO_STEP_CHANNEL:
2785 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2786 int v = cmd->args[0].v.i;
2787 if (v > 0)
2788 radio_step_channel(mpctx->demuxer->stream,
2789 RADIO_CHANNEL_HIGHER);
2790 else
2791 radio_step_channel(mpctx->demuxer->stream,
2792 RADIO_CHANNEL_LOWER);
2793 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2794 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2795 _("Channel: %s"),
2796 radio_get_channel_name(mpctx->demuxer->stream));
2799 break;
2801 case MP_CMD_RADIO_SET_CHANNEL:
2802 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2803 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2804 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2805 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2806 _("Channel: %s"),
2807 radio_get_channel_name(mpctx->demuxer->stream));
2810 break;
2812 case MP_CMD_RADIO_SET_FREQ:
2813 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2814 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2815 break;
2817 case MP_CMD_RADIO_STEP_FREQ:
2818 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2819 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2820 break;
2821 #endif
2823 #ifdef CONFIG_TV
2824 case MP_CMD_TV_START_SCAN:
2825 if (mpctx->file_format == DEMUXER_TYPE_TV)
2826 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2827 break;
2828 case MP_CMD_TV_SET_FREQ:
2829 if (mpctx->file_format == DEMUXER_TYPE_TV)
2830 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2831 cmd->args[0].v.f * 16.0);
2832 #ifdef CONFIG_PVR
2833 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2834 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2835 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2836 pvr_get_current_channelname (mpctx->stream),
2837 pvr_get_current_stationname (mpctx->stream));
2839 #endif /* CONFIG_PVR */
2840 break;
2842 case MP_CMD_TV_STEP_FREQ:
2843 if (mpctx->file_format == DEMUXER_TYPE_TV)
2844 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2845 cmd->args[0].v.f * 16.0);
2846 #ifdef CONFIG_PVR
2847 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2848 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2849 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2850 pvr_get_current_channelname (mpctx->stream),
2851 pvr_get_current_frequency (mpctx->stream));
2853 #endif /* CONFIG_PVR */
2854 break;
2856 case MP_CMD_TV_SET_NORM:
2857 if (mpctx->file_format == DEMUXER_TYPE_TV)
2858 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2859 cmd->args[0].v.s);
2860 break;
2862 case MP_CMD_TV_STEP_CHANNEL:{
2863 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2864 int v = cmd->args[0].v.i;
2865 if (v > 0) {
2866 tv_step_channel((tvi_handle_t *) (mpctx->
2867 demuxer->priv),
2868 TV_CHANNEL_HIGHER);
2869 } else {
2870 tv_step_channel((tvi_handle_t *) (mpctx->
2871 demuxer->priv),
2872 TV_CHANNEL_LOWER);
2874 if (tv_channel_list) {
2875 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2876 _("Channel: %s"), tv_channel_current->name);
2877 //vo_osd_changed(OSDTYPE_SUBTITLE);
2880 #ifdef CONFIG_PVR
2881 else if (mpctx->stream &&
2882 mpctx->stream->type == STREAMTYPE_PVR) {
2883 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2884 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2885 pvr_get_current_channelname (mpctx->stream),
2886 pvr_get_current_stationname (mpctx->stream));
2888 #endif /* CONFIG_PVR */
2890 #ifdef CONFIG_DVBIN
2891 if (mpctx->stream->type == STREAMTYPE_DVB) {
2892 int dir;
2893 int v = cmd->args[0].v.i;
2895 mpctx->last_dvb_step = v;
2896 if (v > 0)
2897 dir = DVB_CHANNEL_HIGHER;
2898 else
2899 dir = DVB_CHANNEL_LOWER;
2902 if (dvb_step_channel(mpctx->stream, dir)) {
2903 mpctx->stop_play = PT_NEXT_ENTRY;
2904 mpctx->dvbin_reopen = 1;
2907 #endif /* CONFIG_DVBIN */
2908 break;
2910 case MP_CMD_TV_SET_CHANNEL:
2911 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2912 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2913 cmd->args[0].v.s);
2914 if (tv_channel_list) {
2915 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2916 _("Channel: %s"), tv_channel_current->name);
2917 //vo_osd_changed(OSDTYPE_SUBTITLE);
2920 #ifdef CONFIG_PVR
2921 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2922 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2923 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2924 pvr_get_current_channelname (mpctx->stream),
2925 pvr_get_current_stationname (mpctx->stream));
2927 #endif /* CONFIG_PVR */
2928 break;
2930 #ifdef CONFIG_DVBIN
2931 case MP_CMD_DVB_SET_CHANNEL:
2932 if (mpctx->stream->type == STREAMTYPE_DVB) {
2933 mpctx->last_dvb_step = 1;
2935 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
2936 cmd->args[0].v.i)) {
2937 mpctx->stop_play = PT_NEXT_ENTRY;
2938 mpctx->dvbin_reopen = 1;
2941 break;
2942 #endif /* CONFIG_DVBIN */
2944 case MP_CMD_TV_LAST_CHANNEL:
2945 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2946 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2947 if (tv_channel_list) {
2948 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2949 _("Channel: %s"), tv_channel_current->name);
2950 //vo_osd_changed(OSDTYPE_SUBTITLE);
2953 #ifdef CONFIG_PVR
2954 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2955 pvr_set_lastchannel (mpctx->stream);
2956 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2957 pvr_get_current_channelname (mpctx->stream),
2958 pvr_get_current_stationname (mpctx->stream));
2960 #endif /* CONFIG_PVR */
2961 break;
2963 case MP_CMD_TV_STEP_NORM:
2964 if (mpctx->file_format == DEMUXER_TYPE_TV)
2965 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2966 break;
2968 case MP_CMD_TV_STEP_CHANNEL_LIST:
2969 if (mpctx->file_format == DEMUXER_TYPE_TV)
2970 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2971 break;
2972 #ifdef CONFIG_TV_TELETEXT
2973 case MP_CMD_TV_TELETEXT_ADD_DEC:
2975 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2976 if (mpctx->file_format == DEMUXER_TYPE_TV)
2977 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2978 break;
2980 case MP_CMD_TV_TELETEXT_GO_LINK:
2982 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2983 if (mpctx->file_format == DEMUXER_TYPE_TV)
2984 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2985 break;
2987 #endif /* CONFIG_TV_TELETEXT */
2988 #endif /* CONFIG_TV */
2990 case MP_CMD_SUB_LOAD:
2991 if (sh_video) {
2992 int n = mpctx->set_of_sub_size;
2993 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
2994 if (n != mpctx->set_of_sub_size) {
2995 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2996 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2997 mpctx->global_sub_size;
2998 ++mpctx->global_sub_size;
3001 break;
3003 case MP_CMD_SUB_REMOVE:
3004 if (sh_video) {
3005 int v = cmd->args[0].v.i;
3006 sub_data *subd;
3007 if (v < 0) {
3008 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
3009 subd = mpctx->set_of_subtitles[v];
3010 mp_tmsg(MSGT_CPLAYER, MSGL_STATUS,
3011 "SUB: Removed subtitle file (%d): %s\n", v + 1,
3012 filename_recode(subd->filename));
3013 sub_free(subd);
3014 mpctx->set_of_subtitles[v] = NULL;
3016 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
3017 mpctx->global_sub_size -= mpctx->set_of_sub_size;
3018 mpctx->set_of_sub_size = 0;
3019 if (mpctx->set_of_sub_pos >= 0) {
3020 mpctx->global_sub_pos = -2;
3021 subdata = NULL;
3022 mp_input_queue_cmd(mpctx->input,
3023 mp_input_parse_cmd("sub_select"));
3025 } else if (v < mpctx->set_of_sub_size) {
3026 subd = mpctx->set_of_subtitles[v];
3027 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
3028 "SUB: Removed subtitle file (%d): %s\n", v + 1,
3029 filename_recode(subd->filename));
3030 sub_free(subd);
3031 if (mpctx->set_of_sub_pos == v) {
3032 mpctx->global_sub_pos = -2;
3033 subdata = NULL;
3034 mp_input_queue_cmd(mpctx->input,
3035 mp_input_parse_cmd("sub_select"));
3036 } else if (mpctx->set_of_sub_pos > v) {
3037 --mpctx->set_of_sub_pos;
3038 --mpctx->global_sub_pos;
3040 while (++v < mpctx->set_of_sub_size)
3041 mpctx->set_of_subtitles[v - 1] =
3042 mpctx->set_of_subtitles[v];
3043 --mpctx->set_of_sub_size;
3044 --mpctx->global_sub_size;
3045 if (mpctx->set_of_sub_size <= 0)
3046 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
3047 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
3050 break;
3052 case MP_CMD_GET_SUB_VISIBILITY:
3053 if (sh_video) {
3054 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3055 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3057 break;
3059 case MP_CMD_SCREENSHOT:
3060 if (mpctx->video_out && mpctx->video_out->config_ok) {
3061 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3062 if (CONTROL_OK !=
3063 ((vf_instance_t *) sh_video->vfilter)->
3064 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3065 &cmd->args[0].v.i))
3066 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3068 break;
3070 case MP_CMD_AF_EQ_SET:{
3071 af_instance_t* m1=af_get(sh_audio->afilter, "equalizer");
3072 if (m1) m1->control( m1, AF_CONTROL_COMMAND_LINE, cmd->args[0].v.s);
3073 else mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -af equalizer=0:0 ?)\n");
3075 break;
3077 case MP_CMD_VF_CHANGE_RECTANGLE:
3078 if (!sh_video)
3079 break;
3080 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3081 break;
3083 case MP_CMD_GET_TIME_LENGTH:{
3084 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
3085 demuxer_get_time_length(mpctx->demuxer));
3087 break;
3089 case MP_CMD_GET_FILENAME:{
3090 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3091 get_metadata(mpctx, META_NAME));
3093 break;
3095 case MP_CMD_GET_VIDEO_CODEC:{
3096 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3097 if (!inf)
3098 inf = strdup("");
3099 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3100 free(inf);
3102 break;
3104 case MP_CMD_GET_VIDEO_BITRATE:{
3105 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3106 if (!inf)
3107 inf = strdup("");
3108 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3109 free(inf);
3111 break;
3113 case MP_CMD_GET_VIDEO_RESOLUTION:{
3114 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3115 if (!inf)
3116 inf = strdup("");
3117 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3118 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3119 free(inf);
3121 break;
3123 case MP_CMD_GET_AUDIO_CODEC:{
3124 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3125 if (!inf)
3126 inf = strdup("");
3127 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3128 free(inf);
3130 break;
3132 case MP_CMD_GET_AUDIO_BITRATE:{
3133 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3134 if (!inf)
3135 inf = strdup("");
3136 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3137 free(inf);
3139 break;
3141 case MP_CMD_GET_AUDIO_SAMPLES:{
3142 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3143 if (!inf)
3144 inf = strdup("");
3145 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3146 free(inf);
3148 break;
3150 case MP_CMD_GET_META_TITLE:{
3151 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3152 if (!inf)
3153 inf = strdup("");
3154 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3155 free(inf);
3157 break;
3159 case MP_CMD_GET_META_ARTIST:{
3160 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3161 if (!inf)
3162 inf = strdup("");
3163 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3164 free(inf);
3166 break;
3168 case MP_CMD_GET_META_ALBUM:{
3169 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3170 if (!inf)
3171 inf = strdup("");
3172 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3173 free(inf);
3175 break;
3177 case MP_CMD_GET_META_YEAR:{
3178 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3179 if (!inf)
3180 inf = strdup("");
3181 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3182 free(inf);
3184 break;
3186 case MP_CMD_GET_META_COMMENT:{
3187 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3188 if (!inf)
3189 inf = strdup("");
3190 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3191 free(inf);
3193 break;
3195 case MP_CMD_GET_META_TRACK:{
3196 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3197 if (!inf)
3198 inf = strdup("");
3199 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3200 free(inf);
3202 break;
3204 case MP_CMD_GET_META_GENRE:{
3205 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3206 if (!inf)
3207 inf = strdup("");
3208 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3209 free(inf);
3211 break;
3213 case MP_CMD_GET_VO_FULLSCREEN:
3214 if (mpctx->video_out && mpctx->video_out->config_ok)
3215 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3216 break;
3218 case MP_CMD_GET_PERCENT_POS:
3219 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3220 demuxer_get_percent_pos(mpctx->demuxer));
3221 break;
3223 case MP_CMD_GET_TIME_POS:{
3224 float pos = 0;
3225 if (sh_video)
3226 pos = sh_video->pts;
3227 else if (sh_audio && mpctx->audio_out)
3228 pos = playing_audio_pts(mpctx);
3229 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3231 break;
3233 case MP_CMD_RUN:
3234 #ifndef __MINGW32__
3235 if (!fork()) {
3236 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3237 exit(0);
3239 #endif
3240 break;
3242 case MP_CMD_KEYDOWN_EVENTS:
3243 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3244 break;
3246 case MP_CMD_SET_MOUSE_POS:{
3247 int pointer_x, pointer_y;
3248 double dx, dy;
3249 pointer_x = cmd->args[0].v.i;
3250 pointer_y = cmd->args[1].v.i;
3251 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3252 #ifdef CONFIG_DVDNAV
3253 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3254 && dx > 0.0 && dy > 0.0) {
3255 int button = -1;
3256 pointer_x = (int) (dx * (double) sh_video->disp_w);
3257 pointer_y = (int) (dy * (double) sh_video->disp_h);
3258 mp_dvdnav_update_mouse_pos(mpctx->stream,
3259 pointer_x, pointer_y, &button);
3260 if (opts->osd_level > 1 && button > 0)
3261 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3262 "Selected button number %d", button);
3264 #endif
3265 #ifdef CONFIG_MENU
3266 if (use_menu && dx >= 0.0 && dy >= 0.0)
3267 menu_update_mouse_pos(dx, dy);
3268 #endif
3270 break;
3272 #ifdef CONFIG_DVDNAV
3273 case MP_CMD_DVDNAV:{
3274 int button = -1;
3275 int i;
3276 mp_command_type command = 0;
3277 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3278 break;
3280 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3281 if (cmd->args[0].v.s &&
3282 !strcasecmp (cmd->args[0].v.s,
3283 mp_dvdnav_bindings[i].name))
3284 command = mp_dvdnav_bindings[i].cmd;
3286 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3287 if (opts->osd_level > 1 && button > 0)
3288 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3289 "Selected button number %d", button);
3291 break;
3293 case MP_CMD_SWITCH_TITLE:
3294 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3295 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3296 break;
3298 #endif
3300 default:
3301 mp_msg(MSGT_CPLAYER, MSGL_V,
3302 "Received unknown cmd %s\n", cmd->name);
3305 switch (cmd->pausing) {
3306 case 1: // "pausing"
3307 pause_player(mpctx);
3308 break;
3309 case 3: // "pausing_toggle"
3310 if (mpctx->paused)
3311 unpause_player(mpctx);
3312 else
3313 pause_player(mpctx);
3314 break;