vo_vdpau: Free buffers allocated by FFmpeg on uninit
[mplayer/kovensky.git] / command.c
blobb52cfaf07d9ed3e8a22ef2c94b5d0c5004191d3f
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 static int mp_property_yuv_colorspace(m_option_t *prop, int action,
1055 void *arg, MPContext *mpctx)
1057 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1058 return M_PROPERTY_UNAVAILABLE;
1060 struct vf_instance *vf = mpctx->sh_video->vfilter;
1061 int colorspace;
1062 switch (action) {
1063 case M_PROPERTY_GET:
1064 if (!arg)
1065 return M_PROPERTY_ERROR;
1066 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, arg) != true)
1067 return M_PROPERTY_UNAVAILABLE;
1068 return M_PROPERTY_OK;
1069 case M_PROPERTY_PRINT:
1070 if (!arg)
1071 return M_PROPERTY_ERROR;
1072 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1073 return M_PROPERTY_UNAVAILABLE;
1074 char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
1075 if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
1076 *(char **)arg = strdup("Unknown");
1077 else
1078 *(char**)arg = strdup(names[colorspace]);
1079 return M_PROPERTY_OK;
1080 case M_PROPERTY_SET:
1081 if (!arg)
1082 return M_PROPERTY_ERROR;
1083 M_PROPERTY_CLAMP(prop, *(int *) arg);
1084 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, arg);
1085 return M_PROPERTY_OK;
1086 case M_PROPERTY_STEP_UP:;
1087 if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &colorspace) != true)
1088 return M_PROPERTY_UNAVAILABLE;
1089 colorspace += 1;
1090 vf->control(vf, VFCTRL_SET_YUV_COLORSPACE, &colorspace);
1091 return M_PROPERTY_OK;
1093 return M_PROPERTY_NOT_IMPLEMENTED;
1096 /// Panscan (RW)
1097 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
1098 MPContext *mpctx)
1101 if (!mpctx->video_out
1102 || vo_control(mpctx->video_out, VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1103 return M_PROPERTY_UNAVAILABLE;
1105 switch (action) {
1106 case M_PROPERTY_SET:
1107 if (!arg)
1108 return M_PROPERTY_ERROR;
1109 M_PROPERTY_CLAMP(prop, *(float *) arg);
1110 vo_panscan = *(float *) arg;
1111 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1112 return M_PROPERTY_OK;
1113 case M_PROPERTY_STEP_UP:
1114 case M_PROPERTY_STEP_DOWN:
1115 vo_panscan += (arg ? *(float *) arg : 0.1) *
1116 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1117 if (vo_panscan > 1)
1118 vo_panscan = 1;
1119 else if (vo_panscan < 0)
1120 vo_panscan = 0;
1121 vo_control(mpctx->video_out, VOCTRL_SET_PANSCAN, NULL);
1122 return M_PROPERTY_OK;
1123 default:
1124 return m_property_float_range(prop, action, arg, &vo_panscan);
1128 /// Helper to set vo flags.
1129 /** \ingroup PropertyImplHelper
1131 static int mp_property_vo_flag(m_option_t *prop, int action, void *arg,
1132 int vo_ctrl, int *vo_var, MPContext *mpctx)
1135 if (!mpctx->video_out)
1136 return M_PROPERTY_UNAVAILABLE;
1138 switch (action) {
1139 case M_PROPERTY_SET:
1140 if (!arg)
1141 return M_PROPERTY_ERROR;
1142 M_PROPERTY_CLAMP(prop, *(int *) arg);
1143 if (*vo_var == !!*(int *) arg)
1144 return M_PROPERTY_OK;
1145 case M_PROPERTY_STEP_UP:
1146 case M_PROPERTY_STEP_DOWN:
1147 if (mpctx->video_out->config_ok)
1148 vo_control(mpctx->video_out, vo_ctrl, 0);
1149 return M_PROPERTY_OK;
1150 default:
1151 return m_property_flag(prop, action, arg, vo_var);
1155 /// Window always on top (RW)
1156 static int mp_property_ontop(m_option_t *prop, int action, void *arg,
1157 MPContext *mpctx)
1159 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP,
1160 &mpctx->opts.vo_ontop, mpctx);
1163 /// Display in the root window (RW)
1164 static int mp_property_rootwin(m_option_t *prop, int action, void *arg,
1165 MPContext *mpctx)
1167 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1168 &vo_rootwin, mpctx);
1171 /// Show window borders (RW)
1172 static int mp_property_border(m_option_t *prop, int action, void *arg,
1173 MPContext *mpctx)
1175 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1176 &vo_border, mpctx);
1179 /// Framedropping state (RW)
1180 static int mp_property_framedropping(m_option_t *prop, int action,
1181 void *arg, MPContext *mpctx)
1184 if (!mpctx->sh_video)
1185 return M_PROPERTY_UNAVAILABLE;
1187 switch (action) {
1188 case M_PROPERTY_PRINT:
1189 if (!arg)
1190 return M_PROPERTY_ERROR;
1191 *(char **) arg = strdup(frame_dropping == 1 ? _("enabled") :
1192 (frame_dropping == 2 ? _("hard") :
1193 _("disabled")));
1194 return M_PROPERTY_OK;
1195 default:
1196 return m_property_choice(prop, action, arg, &frame_dropping);
1200 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1201 static int mp_property_gamma(m_option_t *prop, int action, void *arg,
1202 MPContext *mpctx)
1204 int *gamma = (int *)((char *)&mpctx->opts + (int)prop->priv);
1205 int r, val;
1207 if (!mpctx->sh_video)
1208 return M_PROPERTY_UNAVAILABLE;
1210 if (gamma[0] == 1000) {
1211 gamma[0] = 0;
1212 get_video_colors(mpctx->sh_video, prop->name, gamma);
1215 switch (action) {
1216 case M_PROPERTY_SET:
1217 if (!arg)
1218 return M_PROPERTY_ERROR;
1219 M_PROPERTY_CLAMP(prop, *(int *) arg);
1220 *gamma = *(int *) arg;
1221 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1222 if (r <= 0)
1223 break;
1224 return r;
1225 case M_PROPERTY_GET:
1226 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1227 if (!arg)
1228 return M_PROPERTY_ERROR;
1229 *(int *)arg = val;
1230 return M_PROPERTY_OK;
1232 break;
1233 case M_PROPERTY_STEP_UP:
1234 case M_PROPERTY_STEP_DOWN:
1235 *gamma += (arg ? *(int *) arg : 1) *
1236 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1237 M_PROPERTY_CLAMP(prop, *gamma);
1238 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1239 if (r <= 0)
1240 break;
1241 return r;
1242 default:
1243 return M_PROPERTY_NOT_IMPLEMENTED;
1246 #ifdef CONFIG_TV
1247 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1248 int l = strlen(prop->name);
1249 char tv_prop[3 + l + 1];
1250 sprintf(tv_prop, "tv_%s", prop->name);
1251 return mp_property_do(tv_prop, action, arg, mpctx);
1253 #endif
1255 return M_PROPERTY_UNAVAILABLE;
1258 /// VSync (RW)
1259 static int mp_property_vsync(m_option_t *prop, int action, void *arg,
1260 MPContext *mpctx)
1262 return m_property_flag(prop, action, arg, &vo_vsync);
1265 /// Video codec tag (RO)
1266 static int mp_property_video_format(m_option_t *prop, int action,
1267 void *arg, MPContext *mpctx)
1269 char* meta;
1270 if (!mpctx->sh_video)
1271 return M_PROPERTY_UNAVAILABLE;
1272 switch(action) {
1273 case M_PROPERTY_PRINT:
1274 if (!arg)
1275 return M_PROPERTY_ERROR;
1276 switch(mpctx->sh_video->format) {
1277 case 0x10000001:
1278 meta = strdup ("mpeg1"); break;
1279 case 0x10000002:
1280 meta = strdup ("mpeg2"); break;
1281 case 0x10000004:
1282 meta = strdup ("mpeg4"); break;
1283 case 0x10000005:
1284 meta = strdup ("h264"); break;
1285 default:
1286 if(mpctx->sh_video->format >= 0x20202020) {
1287 meta = malloc(5);
1288 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1289 } else {
1290 meta = malloc(20);
1291 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1294 *(char**)arg = meta;
1295 return M_PROPERTY_OK;
1297 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1300 /// Video codec name (RO)
1301 static int mp_property_video_codec(m_option_t *prop, int action,
1302 void *arg, MPContext *mpctx)
1304 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1305 return M_PROPERTY_UNAVAILABLE;
1306 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1310 /// Video bitrate (RO)
1311 static int mp_property_video_bitrate(m_option_t *prop, int action,
1312 void *arg, MPContext *mpctx)
1314 if (!mpctx->sh_video)
1315 return M_PROPERTY_UNAVAILABLE;
1316 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1319 /// Video display width (RO)
1320 static int mp_property_width(m_option_t *prop, int action, void *arg,
1321 MPContext *mpctx)
1323 if (!mpctx->sh_video)
1324 return M_PROPERTY_UNAVAILABLE;
1325 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1328 /// Video display height (RO)
1329 static int mp_property_height(m_option_t *prop, int action, void *arg,
1330 MPContext *mpctx)
1332 if (!mpctx->sh_video)
1333 return M_PROPERTY_UNAVAILABLE;
1334 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1337 /// Video fps (RO)
1338 static int mp_property_fps(m_option_t *prop, int action, void *arg,
1339 MPContext *mpctx)
1341 if (!mpctx->sh_video)
1342 return M_PROPERTY_UNAVAILABLE;
1343 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1346 /// Video aspect (RO)
1347 static int mp_property_aspect(m_option_t *prop, int action, void *arg,
1348 MPContext *mpctx)
1350 if (!mpctx->sh_video)
1351 return M_PROPERTY_UNAVAILABLE;
1352 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1355 ///@}
1357 /// \defgroup SubProprties Subtitles properties
1358 /// \ingroup Properties
1359 ///@{
1361 /// Text subtitle position (RW)
1362 static int mp_property_sub_pos(m_option_t *prop, int action, void *arg,
1363 MPContext *mpctx)
1365 if (!mpctx->sh_video)
1366 return M_PROPERTY_UNAVAILABLE;
1368 switch (action) {
1369 case M_PROPERTY_SET:
1370 if (!arg)
1371 return M_PROPERTY_ERROR;
1372 case M_PROPERTY_STEP_UP:
1373 case M_PROPERTY_STEP_DOWN:
1374 vo_osd_changed(OSDTYPE_SUBTITLE);
1375 default:
1376 return m_property_int_range(prop, action, arg, &sub_pos);
1380 /// Selected subtitles (RW)
1381 static int mp_property_sub(m_option_t *prop, int action, void *arg,
1382 MPContext *mpctx)
1384 struct MPOpts *opts = &mpctx->opts;
1385 demux_stream_t *const d_sub = mpctx->d_sub;
1386 const int global_sub_size = mpctx->global_sub_size;
1387 int source = -1, reset_spu = 0;
1388 char *sub_name;
1390 if (global_sub_size <= 0)
1391 return M_PROPERTY_UNAVAILABLE;
1393 switch (action) {
1394 case M_PROPERTY_GET:
1395 if (!arg)
1396 return M_PROPERTY_ERROR;
1397 *(int *) arg = mpctx->global_sub_pos;
1398 return M_PROPERTY_OK;
1399 case M_PROPERTY_PRINT:
1400 if (!arg)
1401 return M_PROPERTY_ERROR;
1402 *(char **) arg = malloc(64);
1403 (*(char **) arg)[63] = 0;
1404 sub_name = 0;
1405 if (subdata)
1406 sub_name = subdata->filename;
1407 #ifdef CONFIG_ASS
1408 if (ass_track && ass_track->name)
1409 sub_name = ass_track->name;
1410 #endif
1411 if (sub_name) {
1412 char *tmp, *tmp2;
1413 tmp = sub_name;
1414 if ((tmp2 = strrchr(tmp, '/')))
1415 tmp = tmp2 + 1;
1417 snprintf(*(char **) arg, 63, "(%d) %s%s",
1418 mpctx->set_of_sub_pos + 1,
1419 strlen(tmp) < 20 ? "" : "...",
1420 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1421 return M_PROPERTY_OK;
1423 #ifdef CONFIG_DVDNAV
1424 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1425 if (vo_spudec && opts->sub_id >= 0) {
1426 unsigned char lang[3];
1427 if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
1428 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1429 return M_PROPERTY_OK;
1433 #endif
1435 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1436 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1437 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1438 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1439 && d_sub && d_sub->sh && opts->sub_id >= 0) {
1440 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1441 if (!lang) lang = _("unknown");
1442 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1443 return M_PROPERTY_OK;
1446 if (vo_vobsub && vobsub_id >= 0) {
1447 const char *language = _("unknown");
1448 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1449 snprintf(*(char **) arg, 63, "(%d) %s",
1450 vobsub_id, language ? language : _("unknown"));
1451 return M_PROPERTY_OK;
1453 #ifdef CONFIG_DVDREAD
1454 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1455 && opts->sub_id >= 0) {
1456 char lang[3];
1457 int code = dvd_lang_from_sid(mpctx->stream, opts->sub_id);
1458 lang[0] = code >> 8;
1459 lang[1] = code;
1460 lang[2] = 0;
1461 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
1462 return M_PROPERTY_OK;
1464 #endif
1465 if (opts->sub_id >= 0) {
1466 snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, _("unknown"));
1467 return M_PROPERTY_OK;
1469 snprintf(*(char **) arg, 63, _("disabled"));
1470 return M_PROPERTY_OK;
1472 case M_PROPERTY_SET:
1473 if (!arg)
1474 return M_PROPERTY_ERROR;
1475 if (*(int *) arg < -1)
1476 *(int *) arg = -1;
1477 else if (*(int *) arg >= global_sub_size)
1478 *(int *) arg = global_sub_size - 1;
1479 mpctx->global_sub_pos = *(int *) arg;
1480 break;
1481 case M_PROPERTY_STEP_UP:
1482 mpctx->global_sub_pos += 2;
1483 mpctx->global_sub_pos =
1484 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1485 break;
1486 case M_PROPERTY_STEP_DOWN:
1487 mpctx->global_sub_pos += global_sub_size + 1;
1488 mpctx->global_sub_pos =
1489 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1490 break;
1491 default:
1492 return M_PROPERTY_NOT_IMPLEMENTED;
1495 if (mpctx->global_sub_pos >= 0)
1496 source = sub_source(mpctx);
1498 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1499 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1500 global_sub_size,
1501 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1502 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1503 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1504 mpctx->global_sub_pos, source);
1506 mpctx->set_of_sub_pos = -1;
1507 subdata = NULL;
1509 vobsub_id = -1;
1510 opts->sub_id = -1;
1511 if (d_sub) {
1512 if (d_sub->id > -2)
1513 reset_spu = 1;
1514 d_sub->id = -2;
1516 #ifdef CONFIG_ASS
1517 ass_track = 0;
1518 #endif
1520 if (source == SUB_SOURCE_VOBSUB) {
1521 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1522 } else if (source == SUB_SOURCE_SUBS) {
1523 mpctx->set_of_sub_pos =
1524 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1525 #ifdef CONFIG_ASS
1526 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1527 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1528 else
1529 #endif
1531 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1532 vo_osd_changed(OSDTYPE_SUBTITLE);
1534 } else if (source == SUB_SOURCE_DEMUX) {
1535 opts->sub_id =
1536 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1537 if (d_sub && opts->sub_id < MAX_S_STREAMS) {
1538 int i = 0;
1539 // default: assume 1:1 mapping of sid and stream id
1540 d_sub->id = opts->sub_id;
1541 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1542 ds_free_packs(d_sub);
1543 for (i = 0; i < MAX_S_STREAMS; i++) {
1544 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1545 if (sh && sh->sid == opts->sub_id) {
1546 d_sub->id = i;
1547 d_sub->sh = sh;
1548 break;
1551 if (d_sub->sh && d_sub->id >= 0) {
1552 sh_sub_t *sh = d_sub->sh;
1553 if (sh->type == 'v')
1554 init_vo_spudec(mpctx);
1555 #ifdef CONFIG_ASS
1556 else if (ass_enabled)
1557 ass_track = sh->ass_track;
1558 #endif
1559 } else {
1560 d_sub->id = -2;
1561 d_sub->sh = NULL;
1565 #ifdef CONFIG_DVDREAD
1566 if (vo_spudec
1567 && (mpctx->stream->type == STREAMTYPE_DVD
1568 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1569 && opts->sub_id < 0 && reset_spu) {
1570 opts->sub_id = -2;
1571 d_sub->id = opts->sub_id;
1573 #endif
1575 update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, 0, 0, d_sub, 1);
1577 return M_PROPERTY_OK;
1580 /// Selected sub source (RW)
1581 static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
1582 MPContext *mpctx)
1584 int source;
1585 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1586 return M_PROPERTY_UNAVAILABLE;
1588 switch (action) {
1589 case M_PROPERTY_GET:
1590 if (!arg)
1591 return M_PROPERTY_ERROR;
1592 *(int *) arg = sub_source(mpctx);
1593 return M_PROPERTY_OK;
1594 case M_PROPERTY_PRINT:
1595 if (!arg)
1596 return M_PROPERTY_ERROR;
1597 *(char **) arg = malloc(64);
1598 (*(char **) arg)[63] = 0;
1599 switch (sub_source(mpctx))
1601 case SUB_SOURCE_SUBS:
1602 snprintf(*(char **) arg, 63, _("file"));
1603 break;
1604 case SUB_SOURCE_VOBSUB:
1605 snprintf(*(char **) arg, 63, _("vobsub"));
1606 break;
1607 case SUB_SOURCE_DEMUX:
1608 snprintf(*(char **) arg, 63, _("embedded"));
1609 break;
1610 default:
1611 snprintf(*(char **) arg, 63, _("disabled"));
1613 return M_PROPERTY_OK;
1614 case M_PROPERTY_SET:
1615 if (!arg)
1616 return M_PROPERTY_ERROR;
1617 M_PROPERTY_CLAMP(prop, *(int*)arg);
1618 if (*(int *) arg < 0)
1619 mpctx->global_sub_pos = -1;
1620 else if (*(int *) arg != sub_source(mpctx)) {
1621 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1622 return M_PROPERTY_UNAVAILABLE;
1623 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1625 break;
1626 case M_PROPERTY_STEP_UP:
1627 case M_PROPERTY_STEP_DOWN: {
1628 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1629 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1630 int step = (step_all > 0) ? 1 : -1;
1631 int cur_source = sub_source(mpctx);
1632 source = cur_source;
1633 while (step_all) {
1634 source += step;
1635 if (source >= SUB_SOURCES)
1636 source = -1;
1637 else if (source < -1)
1638 source = SUB_SOURCES - 1;
1639 if (source == cur_source || source == -1 ||
1640 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1641 step_all -= step;
1643 if (source == cur_source)
1644 return M_PROPERTY_OK;
1645 if (source == -1)
1646 mpctx->global_sub_pos = -1;
1647 else
1648 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1649 break;
1651 default:
1652 return M_PROPERTY_NOT_IMPLEMENTED;
1654 --mpctx->global_sub_pos;
1655 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1658 /// Selected subtitles from specific source (RW)
1659 static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
1660 MPContext *mpctx)
1662 int source, is_cur_source, offset;
1663 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1664 return M_PROPERTY_UNAVAILABLE;
1666 if (!strcmp(prop->name, "sub_file"))
1667 source = SUB_SOURCE_SUBS;
1668 else if (!strcmp(prop->name, "sub_vob"))
1669 source = SUB_SOURCE_VOBSUB;
1670 else if (!strcmp(prop->name, "sub_demux"))
1671 source = SUB_SOURCE_DEMUX;
1672 else
1673 return M_PROPERTY_ERROR;
1675 offset = mpctx->global_sub_indices[source];
1676 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1677 return M_PROPERTY_UNAVAILABLE;
1679 is_cur_source = sub_source(mpctx) == source;
1680 switch (action) {
1681 case M_PROPERTY_GET:
1682 if (!arg)
1683 return M_PROPERTY_ERROR;
1684 if (is_cur_source) {
1685 *(int *) arg = mpctx->global_sub_pos - offset;
1686 if (source == SUB_SOURCE_VOBSUB)
1687 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1689 else
1690 *(int *) arg = -1;
1691 return M_PROPERTY_OK;
1692 case M_PROPERTY_PRINT:
1693 if (!arg)
1694 return M_PROPERTY_ERROR;
1695 if (is_cur_source)
1696 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1697 *(char **) arg = malloc(64);
1698 (*(char **) arg)[63] = 0;
1699 snprintf(*(char **) arg, 63, _("disabled"));
1700 return M_PROPERTY_OK;
1701 case M_PROPERTY_SET:
1702 if (!arg)
1703 return M_PROPERTY_ERROR;
1704 if (*(int *) arg >= 0) {
1705 int index = *(int *)arg;
1706 if (source == SUB_SOURCE_VOBSUB)
1707 index = vobsub_get_index_by_id(vo_vobsub, index);
1708 mpctx->global_sub_pos = offset + index;
1709 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1710 || sub_source(mpctx) != source) {
1711 mpctx->global_sub_pos = -1;
1712 *(int *) arg = -1;
1715 else
1716 mpctx->global_sub_pos = -1;
1717 break;
1718 case M_PROPERTY_STEP_UP:
1719 case M_PROPERTY_STEP_DOWN: {
1720 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1721 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1722 int step = (step_all > 0) ? 1 : -1;
1723 int max_sub_pos_for_source = -1;
1724 if (!is_cur_source)
1725 mpctx->global_sub_pos = -1;
1726 while (step_all) {
1727 if (mpctx->global_sub_pos == -1) {
1728 if (step > 0)
1729 mpctx->global_sub_pos = offset;
1730 else if (max_sub_pos_for_source == -1) {
1731 // Find max pos for specific source
1732 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1733 while (mpctx->global_sub_pos >= 0
1734 && sub_source(mpctx) != source)
1735 --mpctx->global_sub_pos;
1737 else
1738 mpctx->global_sub_pos = max_sub_pos_for_source;
1740 else {
1741 mpctx->global_sub_pos += step;
1742 if (mpctx->global_sub_pos < offset ||
1743 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1744 sub_source(mpctx) != source)
1745 mpctx->global_sub_pos = -1;
1747 step_all -= step;
1749 break;
1751 default:
1752 return M_PROPERTY_NOT_IMPLEMENTED;
1754 --mpctx->global_sub_pos;
1755 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1758 /// Subtitle delay (RW)
1759 static int mp_property_sub_delay(m_option_t *prop, int action, void *arg,
1760 MPContext *mpctx)
1762 if (!mpctx->sh_video)
1763 return M_PROPERTY_UNAVAILABLE;
1764 return m_property_delay(prop, action, arg, &sub_delay);
1767 /// Alignment of text subtitles (RW)
1768 static int mp_property_sub_alignment(m_option_t *prop, int action,
1769 void *arg, MPContext *mpctx)
1771 char *name[] = { _("top"), _("center"), _("bottom") };
1773 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1774 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1775 return M_PROPERTY_UNAVAILABLE;
1777 switch (action) {
1778 case M_PROPERTY_PRINT:
1779 if (!arg)
1780 return M_PROPERTY_ERROR;
1781 M_PROPERTY_CLAMP(prop, sub_alignment);
1782 *(char **) arg = strdup(name[sub_alignment]);
1783 return M_PROPERTY_OK;
1784 case M_PROPERTY_SET:
1785 if (!arg)
1786 return M_PROPERTY_ERROR;
1787 case M_PROPERTY_STEP_UP:
1788 case M_PROPERTY_STEP_DOWN:
1789 vo_osd_changed(OSDTYPE_SUBTITLE);
1790 default:
1791 return m_property_choice(prop, action, arg, &sub_alignment);
1795 /// Subtitle visibility (RW)
1796 static int mp_property_sub_visibility(m_option_t *prop, int action,
1797 void *arg, MPContext *mpctx)
1799 if (!mpctx->sh_video)
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 vo_osd_changed(OSDTYPE_SUBTITLE);
1809 if (vo_spudec)
1810 vo_osd_changed(OSDTYPE_SPU);
1811 default:
1812 return m_property_flag(prop, action, arg, &sub_visibility);
1816 #ifdef CONFIG_ASS
1817 /// Use margins for libass subtitles (RW)
1818 static int mp_property_ass_use_margins(m_option_t *prop, int action,
1819 void *arg, MPContext *mpctx)
1821 if (!mpctx->sh_video)
1822 return M_PROPERTY_UNAVAILABLE;
1824 switch (action) {
1825 case M_PROPERTY_SET:
1826 if (!arg)
1827 return M_PROPERTY_ERROR;
1828 case M_PROPERTY_STEP_UP:
1829 case M_PROPERTY_STEP_DOWN:
1830 ass_force_reload = 1;
1831 default:
1832 return m_property_flag(prop, action, arg, &ass_use_margins);
1835 #endif
1837 /// Show only forced subtitles (RW)
1838 static int mp_property_sub_forced_only(m_option_t *prop, int action,
1839 void *arg, MPContext *mpctx)
1841 if (!vo_spudec)
1842 return M_PROPERTY_UNAVAILABLE;
1844 switch (action) {
1845 case M_PROPERTY_SET:
1846 if (!arg)
1847 return M_PROPERTY_ERROR;
1848 case M_PROPERTY_STEP_UP:
1849 case M_PROPERTY_STEP_DOWN:
1850 m_property_flag(prop, action, arg, &forced_subs_only);
1851 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1852 return M_PROPERTY_OK;
1853 default:
1854 return m_property_flag(prop, action, arg, &forced_subs_only);
1859 #ifdef CONFIG_FREETYPE
1860 /// Subtitle scale (RW)
1861 static int mp_property_sub_scale(m_option_t *prop, int action, void *arg,
1862 MPContext *mpctx)
1865 switch (action) {
1866 case M_PROPERTY_SET:
1867 if (!arg)
1868 return M_PROPERTY_ERROR;
1869 M_PROPERTY_CLAMP(prop, *(float *) arg);
1870 #ifdef CONFIG_ASS
1871 if (ass_enabled) {
1872 ass_font_scale = *(float *) arg;
1873 ass_force_reload = 1;
1875 #endif
1876 text_font_scale_factor = *(float *) arg;
1877 force_load_font = 1;
1878 return M_PROPERTY_OK;
1879 case M_PROPERTY_STEP_UP:
1880 case M_PROPERTY_STEP_DOWN:
1881 #ifdef CONFIG_ASS
1882 if (ass_enabled) {
1883 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1884 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1885 M_PROPERTY_CLAMP(prop, ass_font_scale);
1886 ass_force_reload = 1;
1888 #endif
1889 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1890 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1891 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1892 force_load_font = 1;
1893 return M_PROPERTY_OK;
1894 default:
1895 #ifdef CONFIG_ASS
1896 if (ass_enabled)
1897 return m_property_float_ro(prop, action, arg, ass_font_scale);
1898 else
1899 #endif
1900 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1903 #endif
1905 ///@}
1907 /// \defgroup TVProperties TV properties
1908 /// \ingroup Properties
1909 ///@{
1911 #ifdef CONFIG_TV
1913 /// TV color settings (RW)
1914 static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
1915 MPContext *mpctx)
1917 int r, val;
1918 tvi_handle_t *tvh = mpctx->demuxer->priv;
1919 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1920 return M_PROPERTY_UNAVAILABLE;
1922 switch (action) {
1923 case M_PROPERTY_SET:
1924 if (!arg)
1925 return M_PROPERTY_ERROR;
1926 M_PROPERTY_CLAMP(prop, *(int *) arg);
1927 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1928 case M_PROPERTY_GET:
1929 return tv_get_color_options(tvh, (int) prop->priv, arg);
1930 case M_PROPERTY_STEP_UP:
1931 case M_PROPERTY_STEP_DOWN:
1932 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1933 if (!r)
1934 return M_PROPERTY_ERROR;
1935 val += (arg ? *(int *) arg : 1) *
1936 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1937 M_PROPERTY_CLAMP(prop, val);
1938 return tv_set_color_options(tvh, (int) prop->priv, val);
1940 return M_PROPERTY_ERROR;
1942 return M_PROPERTY_NOT_IMPLEMENTED;
1945 #endif
1947 #ifdef CONFIG_TV_TELETEXT
1948 static int mp_property_teletext_common(m_option_t *prop, int action, void *arg,
1949 MPContext *mpctx)
1951 int val,result;
1952 int base_ioctl=(int)prop->priv;
1954 for teletext's GET,SET,STEP ioctls this is not 0
1955 SET is GET+1
1956 STEP is GET+2
1958 tvi_handle_t *tvh = mpctx->demuxer->priv;
1959 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1960 return M_PROPERTY_UNAVAILABLE;
1961 if(!base_ioctl)
1962 return M_PROPERTY_ERROR;
1964 switch (action) {
1965 case M_PROPERTY_GET:
1966 if (!arg)
1967 return M_PROPERTY_ERROR;
1968 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1969 break;
1970 case M_PROPERTY_SET:
1971 if (!arg)
1972 return M_PROPERTY_ERROR;
1973 M_PROPERTY_CLAMP(prop, *(int *) arg);
1974 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1975 break;
1976 case M_PROPERTY_STEP_UP:
1977 case M_PROPERTY_STEP_DOWN:
1978 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1979 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1980 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1981 break;
1982 default:
1983 return M_PROPERTY_NOT_IMPLEMENTED;
1986 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1989 static int mp_property_teletext_mode(m_option_t *prop, int action, void *arg,
1990 MPContext *mpctx)
1992 tvi_handle_t *tvh = mpctx->demuxer->priv;
1993 int result;
1994 int val;
1996 //with tvh==NULL will fail too
1997 result=mp_property_teletext_common(prop,action,arg,mpctx);
1998 if(result!=M_PROPERTY_OK)
1999 return result;
2001 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
2002 mp_input_set_section(mpctx->input, "teletext");
2003 else
2004 mp_input_set_section(mpctx->input, "tv");
2005 return M_PROPERTY_OK;
2008 static int mp_property_teletext_page(m_option_t *prop, int action, void *arg,
2009 MPContext *mpctx)
2011 tvi_handle_t *tvh = mpctx->demuxer->priv;
2012 int result;
2013 int val;
2014 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
2015 return M_PROPERTY_UNAVAILABLE;
2016 switch(action){
2017 case M_PROPERTY_STEP_UP:
2018 case M_PROPERTY_STEP_DOWN:
2019 //This should be handled separately
2020 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
2021 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
2022 break;
2023 default:
2024 result=mp_property_teletext_common(prop,action,arg,mpctx);
2026 return result;
2030 #endif /* CONFIG_TV_TELETEXT */
2032 ///@}
2034 /// All properties available in MPlayer.
2035 /** \ingroup Properties
2037 static const m_option_t mp_properties[] = {
2038 // General
2039 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
2040 M_OPT_RANGE, 0, 3, NULL },
2041 { "loop", mp_property_loop, CONF_TYPE_INT,
2042 M_OPT_MIN, -1, 0, NULL },
2043 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
2044 M_OPT_RANGE, 0.01, 100.0, NULL },
2045 { "filename", mp_property_filename, CONF_TYPE_STRING,
2046 0, 0, 0, NULL },
2047 { "path", mp_property_path, CONF_TYPE_STRING,
2048 0, 0, 0, NULL },
2049 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
2050 0, 0, 0, NULL },
2051 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
2052 M_OPT_MIN, 0, 0, NULL },
2053 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
2054 M_OPT_MIN, 0, 0, NULL },
2055 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
2056 M_OPT_MIN, 0, 0, NULL },
2057 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
2058 M_OPT_MIN, 0, 0, NULL },
2059 { "length", mp_property_length, CONF_TYPE_TIME,
2060 M_OPT_MIN, 0, 0, NULL },
2061 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
2062 M_OPT_RANGE, 0, 100, NULL },
2063 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
2064 M_OPT_MIN, 0, 0, NULL },
2065 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2066 M_OPT_MIN, 0, 0, NULL },
2067 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2068 0, 0, 0, NULL },
2069 { "angle", mp_property_angle, CONF_TYPE_INT,
2070 CONF_RANGE, -2, 10, NULL },
2071 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2072 0, 0, 0, NULL },
2073 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2074 M_OPT_RANGE, 0, 1, NULL },
2076 // Audio
2077 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2078 M_OPT_RANGE, 0, 100, NULL },
2079 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2080 M_OPT_RANGE, 0, 1, NULL },
2081 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2082 M_OPT_RANGE, -100, 100, NULL },
2083 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2084 0, 0, 0, NULL },
2085 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2086 0, 0, 0, NULL },
2087 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2088 0, 0, 0, NULL },
2089 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2090 0, 0, 0, NULL },
2091 { "channels", mp_property_channels, CONF_TYPE_INT,
2092 0, 0, 0, NULL },
2093 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2094 CONF_RANGE, -2, 65535, NULL },
2095 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2096 M_OPT_RANGE, -1, 1, NULL },
2098 // Video
2099 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2100 M_OPT_RANGE, 0, 1, NULL },
2101 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2102 M_OPT_RANGE, 0, 1, NULL },
2103 { "yuv_colorspace", mp_property_yuv_colorspace, CONF_TYPE_INT,
2104 M_OPT_RANGE, 0, 2, NULL },
2105 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2106 M_OPT_RANGE, 0, 1, NULL },
2107 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2108 M_OPT_RANGE, 0, 1, NULL },
2109 { "border", mp_property_border, CONF_TYPE_FLAG,
2110 M_OPT_RANGE, 0, 1, NULL },
2111 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2112 M_OPT_RANGE, 0, 2, NULL },
2113 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2114 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_gamma)},
2115 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2116 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_brightness) },
2117 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2118 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_contrast) },
2119 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2120 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_saturation) },
2121 { "hue", mp_property_gamma, CONF_TYPE_INT,
2122 M_OPT_RANGE, -100, 100, (void *)offsetof(struct MPOpts, vo_gamma_hue) },
2123 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2124 M_OPT_RANGE, 0, 1, NULL },
2125 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2126 M_OPT_RANGE, 0, 1, NULL },
2127 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2128 0, 0, 0, NULL },
2129 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2130 0, 0, 0, NULL },
2131 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2132 0, 0, 0, NULL },
2133 { "width", mp_property_width, CONF_TYPE_INT,
2134 0, 0, 0, NULL },
2135 { "height", mp_property_height, CONF_TYPE_INT,
2136 0, 0, 0, NULL },
2137 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2138 0, 0, 0, NULL },
2139 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2140 0, 0, 0, NULL },
2141 { "switch_video", mp_property_video, CONF_TYPE_INT,
2142 CONF_RANGE, -2, 65535, NULL },
2143 { "switch_program", mp_property_program, CONF_TYPE_INT,
2144 CONF_RANGE, -1, 65535, NULL },
2146 // Subs
2147 { "sub", mp_property_sub, CONF_TYPE_INT,
2148 M_OPT_MIN, -1, 0, NULL },
2149 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2150 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2151 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2152 M_OPT_MIN, -1, 0, NULL },
2153 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2154 M_OPT_MIN, -1, 0, NULL },
2155 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2156 M_OPT_MIN, -1, 0, NULL },
2157 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2158 0, 0, 0, NULL },
2159 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2160 M_OPT_RANGE, 0, 100, NULL },
2161 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2162 M_OPT_RANGE, 0, 2, NULL },
2163 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2164 M_OPT_RANGE, 0, 1, NULL },
2165 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2166 M_OPT_RANGE, 0, 1, NULL },
2167 #ifdef CONFIG_FREETYPE
2168 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2169 M_OPT_RANGE, 0, 100, NULL },
2170 #endif
2171 #ifdef CONFIG_ASS
2172 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2173 M_OPT_RANGE, 0, 1, NULL },
2174 #endif
2176 #ifdef CONFIG_TV
2177 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2178 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2179 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2180 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2181 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2182 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2183 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2184 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2185 #endif
2187 #ifdef CONFIG_TV_TELETEXT
2188 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2189 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2190 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2191 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2192 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2193 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2194 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2195 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2196 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2197 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2198 #endif
2200 { NULL, NULL, NULL, 0, 0, 0, NULL }
2204 int mp_property_do(const char *name, int action, void *val, void *ctx)
2206 return m_property_do(mp_properties, name, action, val, ctx);
2209 char* mp_property_print(const char *name, void* ctx)
2211 char* ret = NULL;
2212 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2213 return NULL;
2214 return ret;
2217 char *property_expand_string(MPContext *mpctx, char *str)
2219 return m_properties_expand_string(mp_properties, str, mpctx);
2222 void property_print_help(void)
2224 m_properties_print_help_list(mp_properties);
2228 /* List of default ways to show a property on OSD.
2230 * Setting osd_progbar to -1 displays seek bar, other nonzero displays
2231 * a bar showing the current position between min/max values of the
2232 * property. In this case osd_msg is only used for terminal output
2233 * if there is no video; it'll be a label shown together with percentage.
2235 * Otherwise setting osd_msg will show the string on OSD, formatted with
2236 * the text value of the property as argument.
2238 static struct property_osd_display {
2239 /// property name
2240 const char *name;
2241 /// progressbar type
2242 int osd_progbar; // -1 is special value for seek indicators
2243 /// osd msg id if it must be shared
2244 int osd_id;
2245 /// osd msg template
2246 const char *osd_msg;
2247 } property_osd_display[] = {
2248 // general
2249 { "loop", 0, -1, _("Loop: %s") },
2250 { "chapter", -1, -1, NULL },
2251 // audio
2252 { "volume", OSD_VOLUME, -1, _("Volume") },
2253 { "mute", 0, -1, _("Mute: %s") },
2254 { "audio_delay", 0, -1, _("A-V delay: %s") },
2255 { "switch_audio", 0, -1, _("Audio: %s") },
2256 { "balance", OSD_BALANCE, -1, _("Balance") },
2257 // video
2258 { "panscan", OSD_PANSCAN, -1, _("Panscan") },
2259 { "ontop", 0, -1, _("Stay on top: %s") },
2260 { "rootwin", 0, -1, _("Rootwin: %s") },
2261 { "border", 0, -1, _("Border: %s") },
2262 { "framedropping", 0, -1, _("Framedropping: %s") },
2263 { "deinterlace", 0, -1, _("Deinterlace: %s") },
2264 { "yuv_colorspace", 0, -1, _("YUV colorspace: %s") },
2265 { "gamma", OSD_BRIGHTNESS, -1, _("Gamma") },
2266 { "brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2267 { "contrast", OSD_CONTRAST, -1, _("Contrast") },
2268 { "saturation", OSD_SATURATION, -1, _("Saturation") },
2269 { "hue", OSD_HUE, -1, _("Hue") },
2270 { "vsync", 0, -1, _("VSync: %s") },
2271 // subs
2272 { "sub", 0, -1, _("Subtitles: %s") },
2273 { "sub_source", 0, -1, _("Sub source: %s") },
2274 { "sub_vob", 0, -1, _("Subtitles: %s") },
2275 { "sub_demux", 0, -1, _("Subtitles: %s") },
2276 { "sub_file", 0, -1, _("Subtitles: %s") },
2277 { "sub_pos", 0, -1, _("Sub position: %s/100") },
2278 { "sub_alignment", 0, -1, _("Sub alignment: %s") },
2279 { "sub_delay", 0, OSD_MSG_SUB_DELAY, _("Sub delay: %s") },
2280 { "sub_visibility", 0, -1, _("Subtitles: %s") },
2281 { "sub_forced_only", 0, -1, _("Forced sub only: %s") },
2282 #ifdef CONFIG_FREETYPE
2283 { "sub_scale", 0, -1, _("Sub Scale: %s")},
2284 #endif
2285 #ifdef CONFIG_TV
2286 { "tv_brightness", OSD_BRIGHTNESS, -1, _("Brightness") },
2287 { "tv_hue", OSD_HUE, -1, _("Hue") },
2288 { "tv_saturation", OSD_SATURATION, -1, _("Saturation") },
2289 { "tv_contrast", OSD_CONTRAST, -1, _("Contrast") },
2290 #endif
2294 static int show_property_osd(MPContext *mpctx, const char *pname)
2296 struct MPOpts *opts = &mpctx->opts;
2297 int r;
2298 m_option_t* prop;
2299 struct property_osd_display *p;
2301 // look for the command
2302 for (p = property_osd_display; p->name; p++)
2303 if (!strcmp(p->name, pname))
2304 break;
2305 if (!p->name)
2306 return -1;
2308 if (mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0 || !prop)
2309 return -1;
2311 if (p->osd_progbar == -1)
2312 mpctx->add_osd_seek_info = true;
2313 else if (p->osd_progbar) {
2314 if (prop->type == CONF_TYPE_INT) {
2315 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2316 set_osd_bar(mpctx, p->osd_progbar, p->osd_msg,
2317 prop->min, prop->max, r);
2318 } else if (prop->type == CONF_TYPE_FLOAT) {
2319 float f;
2320 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2321 set_osd_bar(mpctx, p->osd_progbar, p->osd_msg,
2322 prop->min, prop->max, f);
2323 } else {
2324 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2325 "Property use an unsupported type.\n");
2326 return -1;
2328 return 0;
2331 if (p->osd_msg) {
2332 char *val = mp_property_print(pname, mpctx);
2333 if (val) {
2334 int index = p - property_osd_display;
2335 set_osd_msg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
2336 1, opts->osd_duration, p->osd_msg, val);
2337 free(val);
2340 return 0;
2345 * \defgroup Command2Property Command to property bridge
2347 * It is used to handle most commands that just set a property
2348 * and optionally display something on the OSD.
2349 * Two kinds of commands are handled: adjust or toggle.
2351 * Adjust commands take 1 or 2 parameters: <value> <abs>
2352 * If <abs> is non-zero the property is set to the given value
2353 * otherwise it is adjusted.
2355 * Toggle commands take 0 or 1 parameters. With no parameter
2356 * or a value less than the property minimum it just steps the
2357 * property to its next value. Otherwise it sets it to the given
2358 * value.
2363 /// List of the commands that can be handled by setting a property.
2364 static struct {
2365 /// property name
2366 const char *name;
2367 /// cmd id
2368 int cmd;
2369 /// set/adjust or toggle command
2370 int toggle;
2371 } set_prop_cmd[] = {
2372 // general
2373 { "loop", MP_CMD_LOOP, 0},
2374 { "chapter", MP_CMD_SEEK_CHAPTER, 0},
2375 { "angle", MP_CMD_SWITCH_ANGLE, 0},
2376 { "pause", MP_CMD_PAUSE, 0},
2377 // audio
2378 { "volume", MP_CMD_VOLUME, 0},
2379 { "mute", MP_CMD_MUTE, 1},
2380 { "audio_delay", MP_CMD_AUDIO_DELAY, 0},
2381 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1},
2382 { "balance", MP_CMD_BALANCE, 0},
2383 // video
2384 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1},
2385 { "panscan", MP_CMD_PANSCAN, 0},
2386 { "ontop", MP_CMD_VO_ONTOP, 1},
2387 { "rootwin", MP_CMD_VO_ROOTWIN, 1},
2388 { "border", MP_CMD_VO_BORDER, 1},
2389 { "framedropping", MP_CMD_FRAMEDROPPING, 1},
2390 { "gamma", MP_CMD_GAMMA, 0},
2391 { "brightness", MP_CMD_BRIGHTNESS, 0},
2392 { "contrast", MP_CMD_CONTRAST, 0},
2393 { "saturation", MP_CMD_SATURATION, 0},
2394 { "hue", MP_CMD_HUE, 0},
2395 { "vsync", MP_CMD_SWITCH_VSYNC, 1},
2396 // subs
2397 { "sub", MP_CMD_SUB_SELECT, 1},
2398 { "sub_source", MP_CMD_SUB_SOURCE, 1},
2399 { "sub_vob", MP_CMD_SUB_VOB, 1},
2400 { "sub_demux", MP_CMD_SUB_DEMUX, 1},
2401 { "sub_file", MP_CMD_SUB_FILE, 1},
2402 { "sub_pos", MP_CMD_SUB_POS, 0},
2403 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1},
2404 { "sub_delay", MP_CMD_SUB_DELAY, 0},
2405 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1},
2406 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1},
2407 #ifdef CONFIG_FREETYPE
2408 { "sub_scale", MP_CMD_SUB_SCALE, 0},
2409 #endif
2410 #ifdef CONFIG_ASS
2411 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1},
2412 #endif
2413 #ifdef CONFIG_TV
2414 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0},
2415 { "tv_hue", MP_CMD_TV_SET_HUE, 0},
2416 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0},
2417 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0},
2418 #endif
2422 /// Handle commands that set a property.
2423 static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
2425 int i, r;
2426 m_option_t* prop;
2427 const char *pname;
2429 // look for the command
2430 for (i = 0; set_prop_cmd[i].name; i++)
2431 if (set_prop_cmd[i].cmd == cmd->id)
2432 break;
2433 if (!(pname = set_prop_cmd[i].name))
2434 return 0;
2436 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2437 return 0;
2439 // toggle command
2440 if (set_prop_cmd[i].toggle) {
2441 // set to value
2442 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2443 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2444 else
2445 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2446 } else if (cmd->args[1].v.i) //set
2447 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2448 else // adjust
2449 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2451 if (r <= 0)
2452 return 1;
2454 show_property_osd(mpctx, pname);
2456 return 1;
2459 #ifdef CONFIG_DVDNAV
2460 static const struct {
2461 const char *name;
2462 const mp_command_type cmd;
2463 } mp_dvdnav_bindings[] = {
2464 { "up", MP_CMD_DVDNAV_UP },
2465 { "down", MP_CMD_DVDNAV_DOWN },
2466 { "left", MP_CMD_DVDNAV_LEFT },
2467 { "right", MP_CMD_DVDNAV_RIGHT },
2468 { "menu", MP_CMD_DVDNAV_MENU },
2469 { "select", MP_CMD_DVDNAV_SELECT },
2470 { "prev", MP_CMD_DVDNAV_PREVMENU },
2471 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2474 * keep old dvdnav sub-command options for a while in order not to
2475 * break slave-mode API too suddenly.
2477 { "1", MP_CMD_DVDNAV_UP },
2478 { "2", MP_CMD_DVDNAV_DOWN },
2479 { "3", MP_CMD_DVDNAV_LEFT },
2480 { "4", MP_CMD_DVDNAV_RIGHT },
2481 { "5", MP_CMD_DVDNAV_MENU },
2482 { "6", MP_CMD_DVDNAV_SELECT },
2483 { "7", MP_CMD_DVDNAV_PREVMENU },
2484 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2485 { NULL, 0 }
2487 #endif
2489 void run_command(MPContext *mpctx, mp_cmd_t *cmd)
2491 struct MPOpts *opts = &mpctx->opts;
2492 sh_audio_t * const sh_audio = mpctx->sh_audio;
2493 sh_video_t * const sh_video = mpctx->sh_video;
2494 int osd_duration = opts->osd_duration;
2495 int case_fallthrough_hack = 0;
2496 if (!set_property_command(mpctx, cmd))
2497 switch (cmd->id) {
2498 case MP_CMD_SEEK:{
2499 float v;
2500 int abs;
2501 mpctx->add_osd_seek_info = true;
2502 v = cmd->args[0].v.f;
2503 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2504 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2505 mpctx->abs_seek_pos = SEEK_ABSOLUTE;
2506 if (sh_video)
2507 mpctx->osd_function =
2508 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2509 mpctx->rel_seek_secs = v;
2510 } else if (abs) { /* Absolute seek by percentage */
2511 mpctx->abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2512 if (sh_video)
2513 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2514 mpctx->rel_seek_secs = v / 100.0;
2515 } else {
2516 mpctx->rel_seek_secs += v;
2517 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2520 break;
2522 case MP_CMD_SET_PROPERTY_OSD:
2523 case_fallthrough_hack = 1;
2525 case MP_CMD_SET_PROPERTY:{
2526 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2527 cmd->args[1].v.s, mpctx);
2528 if (r == M_PROPERTY_UNKNOWN)
2529 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2530 "Unknown property: '%s'\n", cmd->args[0].v.s);
2531 else if (r <= 0)
2532 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2533 "Failed to set property '%s' to '%s'.\n",
2534 cmd->args[0].v.s, cmd->args[1].v.s);
2535 else if (case_fallthrough_hack)
2536 show_property_osd(mpctx, cmd->args[0].v.s);
2538 break;
2540 case MP_CMD_STEP_PROPERTY_OSD:
2541 case_fallthrough_hack = 1;
2543 case MP_CMD_STEP_PROPERTY:{
2544 void* arg = NULL;
2545 int r,i;
2546 double d;
2547 off_t o;
2548 if (cmd->args[1].v.f) {
2549 m_option_t* prop;
2550 if((r = mp_property_do(cmd->args[0].v.s,
2551 M_PROPERTY_GET_TYPE,
2552 &prop, mpctx)) <= 0)
2553 goto step_prop_err;
2554 if(prop->type == CONF_TYPE_INT ||
2555 prop->type == CONF_TYPE_FLAG)
2556 i = cmd->args[1].v.f, arg = &i;
2557 else if(prop->type == CONF_TYPE_FLOAT)
2558 arg = &cmd->args[1].v.f;
2559 else if(prop->type == CONF_TYPE_DOUBLE ||
2560 prop->type == CONF_TYPE_TIME)
2561 d = cmd->args[1].v.f, arg = &d;
2562 else if(prop->type == CONF_TYPE_POSITION)
2563 o = cmd->args[1].v.f, arg = &o;
2564 else
2565 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2566 "Ignoring step size stepping property '%s'.\n",
2567 cmd->args[0].v.s);
2569 r = mp_property_do(cmd->args[0].v.s,
2570 cmd->args[2].v.i < 0 ?
2571 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2572 arg, mpctx);
2573 step_prop_err:
2574 if (r == M_PROPERTY_UNKNOWN)
2575 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2576 "Unknown property: '%s'\n", cmd->args[0].v.s);
2577 else if (r <= 0)
2578 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2579 "Failed to increment property '%s' by %f.\n",
2580 cmd->args[0].v.s, cmd->args[1].v.f);
2581 else if (case_fallthrough_hack)
2582 show_property_osd(mpctx, cmd->args[0].v.s);
2584 break;
2586 case MP_CMD_GET_PROPERTY:{
2587 char *tmp;
2588 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2589 &tmp, mpctx) <= 0) {
2590 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2591 "Failed to get value of property '%s'.\n",
2592 cmd->args[0].v.s);
2593 break;
2595 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2596 cmd->args[0].v.s, tmp);
2597 free(tmp);
2599 break;
2601 case MP_CMD_EDL_MARK:
2602 if (edl_fd) {
2603 float v = sh_video ? sh_video->pts :
2604 playing_audio_pts(mpctx);
2605 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2606 mpctx->begin_skip = v;
2607 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip start, press 'i' again to end block.\n");
2608 } else {
2609 if (mpctx->begin_skip > v)
2610 mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "EDL skip canceled, last start > stop\n");
2611 else {
2612 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2613 mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "EDL skip end, line written.\n");
2615 mpctx->begin_skip = MP_NOPTS_VALUE;
2618 break;
2620 case MP_CMD_SWITCH_RATIO:
2621 if (!sh_video)
2622 break;
2623 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2624 opts->movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2625 else
2626 opts->movie_aspect = cmd->args[0].v.f;
2627 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2628 break;
2630 case MP_CMD_SPEED_INCR:{
2631 float v = cmd->args[0].v.f;
2632 opts->playback_speed += v;
2633 build_afilter_chain(mpctx, sh_audio, &ao_data);
2634 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2635 opts->playback_speed);
2636 } break;
2638 case MP_CMD_SPEED_MULT:{
2639 float v = cmd->args[0].v.f;
2640 opts->playback_speed *= v;
2641 build_afilter_chain(mpctx, sh_audio, &ao_data);
2642 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2643 opts->playback_speed);
2644 } break;
2646 case MP_CMD_SPEED_SET:{
2647 float v = cmd->args[0].v.f;
2648 opts->playback_speed = v;
2649 build_afilter_chain(mpctx, sh_audio, &ao_data);
2650 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, _("Speed: x %6.2f"),
2651 opts->playback_speed);
2652 } break;
2654 case MP_CMD_FRAME_STEP:
2655 add_step_frame(mpctx);
2656 break;
2658 case MP_CMD_FILE_FILTER:
2659 file_filter = cmd->args[0].v.i;
2660 break;
2662 case MP_CMD_QUIT:
2663 exit_player_with_rc(mpctx, EXIT_QUIT,
2664 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2666 case MP_CMD_PLAY_TREE_STEP:{
2667 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2668 int force = cmd->args[1].v.i;
2671 if (!force && mpctx->playtree_iter) {
2672 play_tree_iter_t *i =
2673 play_tree_iter_new_copy(mpctx->playtree_iter);
2674 if (play_tree_iter_step(i, n, 0) ==
2675 PLAY_TREE_ITER_ENTRY)
2676 mpctx->stop_play =
2677 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2678 play_tree_iter_free(i);
2679 } else
2680 mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2681 if (mpctx->stop_play)
2682 mpctx->play_tree_step = n;
2685 break;
2687 case MP_CMD_PLAY_TREE_UP_STEP:{
2688 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2689 int force = cmd->args[1].v.i;
2691 if (!force && mpctx->playtree_iter) {
2692 play_tree_iter_t *i =
2693 play_tree_iter_new_copy(mpctx->playtree_iter);
2694 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2695 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2696 play_tree_iter_free(i);
2697 } else
2698 mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2700 break;
2702 case MP_CMD_PLAY_ALT_SRC_STEP:
2703 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2704 int v = cmd->args[0].v.i;
2705 if (v > 0
2706 && mpctx->playtree_iter->file <
2707 mpctx->playtree_iter->num_files)
2708 mpctx->stop_play = PT_NEXT_SRC;
2709 else if (v < 0 && mpctx->playtree_iter->file > 1)
2710 mpctx->stop_play = PT_PREV_SRC;
2712 break;
2714 case MP_CMD_SUB_STEP:
2715 if (sh_video) {
2716 int movement = cmd->args[0].v.i;
2717 step_sub(subdata, sh_video->pts, movement);
2718 #ifdef CONFIG_ASS
2719 if (ass_track)
2720 sub_delay +=
2721 ass_step_sub(ass_track,
2722 (sh_video->pts +
2723 sub_delay) * 1000 + .5, movement) / 1000.;
2724 #endif
2725 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2726 _("Sub delay: %d ms"), ROUND(sub_delay * 1000));
2728 break;
2730 case MP_CMD_SUB_LOG:
2731 log_sub(mpctx);
2732 break;
2734 case MP_CMD_OSD:{
2735 int v = cmd->args[0].v.i;
2736 int max = (term_osd
2737 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2738 if (opts->osd_level > max)
2739 opts->osd_level = max;
2740 if (v < 0)
2741 opts->osd_level = (opts->osd_level + 1) % (max + 1);
2742 else
2743 opts->osd_level = v > max ? max : v;
2744 /* Show OSD state when disabled, but not when an explicit
2745 argument is given to the OSD command, i.e. in slave mode. */
2746 if (v == -1 && opts->osd_level <= 1)
2747 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2748 _("OSD: %s"),
2749 opts->osd_level ? _("enabled") :
2750 _("disabled"));
2751 else
2752 rm_osd_msg(OSD_MSG_OSD_STATUS);
2754 break;
2756 case MP_CMD_OSD_SHOW_TEXT:
2757 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2758 (cmd->args[1].v.i <
2759 0 ? osd_duration : cmd->args[1].v.i),
2760 "%-.63s", cmd->args[0].v.s);
2761 break;
2763 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2764 char *txt = m_properties_expand_string(mp_properties,
2765 cmd->args[0].v.s,
2766 mpctx);
2767 /* if no argument supplied take default osd_duration, else <arg> ms. */
2768 if (txt) {
2769 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2770 (cmd->args[1].v.i <
2771 0 ? osd_duration : cmd->args[1].v.i),
2772 "%-.63s", txt);
2773 free(txt);
2776 break;
2778 case MP_CMD_LOADFILE:{
2779 play_tree_t *e = play_tree_new();
2780 play_tree_add_file(e, cmd->args[0].v.s);
2782 if (cmd->args[1].v.i) // append
2783 play_tree_append_entry(mpctx->playtree->child, e);
2784 else {
2785 // Go back to the starting point.
2786 while (play_tree_iter_up_step
2787 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2788 /* NOP */ ;
2789 play_tree_free_list(mpctx->playtree->child, 1);
2790 play_tree_set_child(mpctx->playtree, e);
2791 pt_iter_goto_head(mpctx->playtree_iter);
2792 mpctx->stop_play = PT_NEXT_SRC;
2795 break;
2797 case MP_CMD_LOADLIST:{
2798 play_tree_t *e = parse_playlist_file(mpctx->mconfig, cmd->args[0].v.s);
2799 if (!e)
2800 mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
2801 "\nUnable to load playlist %s.\n", cmd->args[0].v.s);
2802 else {
2803 if (cmd->args[1].v.i) // append
2804 play_tree_append_entry(mpctx->playtree->child, e);
2805 else {
2806 // Go back to the starting point.
2807 while (play_tree_iter_up_step
2808 (mpctx->playtree_iter, 0, 1)
2809 != PLAY_TREE_ITER_END)
2810 /* NOP */ ;
2811 play_tree_free_list(mpctx->playtree->child, 1);
2812 play_tree_set_child(mpctx->playtree, e);
2813 pt_iter_goto_head(mpctx->playtree_iter);
2814 mpctx->stop_play = PT_NEXT_SRC;
2818 break;
2820 case MP_CMD_STOP:
2821 // Go back to the starting point.
2822 while (play_tree_iter_up_step
2823 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2824 /* NOP */ ;
2825 mpctx->stop_play = PT_STOP;
2826 break;
2828 #ifdef CONFIG_RADIO
2829 case MP_CMD_RADIO_STEP_CHANNEL:
2830 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2831 int v = cmd->args[0].v.i;
2832 if (v > 0)
2833 radio_step_channel(mpctx->demuxer->stream,
2834 RADIO_CHANNEL_HIGHER);
2835 else
2836 radio_step_channel(mpctx->demuxer->stream,
2837 RADIO_CHANNEL_LOWER);
2838 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2839 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2840 _("Channel: %s"),
2841 radio_get_channel_name(mpctx->demuxer->stream));
2844 break;
2846 case MP_CMD_RADIO_SET_CHANNEL:
2847 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2848 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2849 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2850 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2851 _("Channel: %s"),
2852 radio_get_channel_name(mpctx->demuxer->stream));
2855 break;
2857 case MP_CMD_RADIO_SET_FREQ:
2858 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2859 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2860 break;
2862 case MP_CMD_RADIO_STEP_FREQ:
2863 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2864 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2865 break;
2866 #endif
2868 #ifdef CONFIG_TV
2869 case MP_CMD_TV_START_SCAN:
2870 if (mpctx->file_format == DEMUXER_TYPE_TV)
2871 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2872 break;
2873 case MP_CMD_TV_SET_FREQ:
2874 if (mpctx->file_format == DEMUXER_TYPE_TV)
2875 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2876 cmd->args[0].v.f * 16.0);
2877 #ifdef CONFIG_PVR
2878 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2879 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2880 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2881 pvr_get_current_channelname (mpctx->stream),
2882 pvr_get_current_stationname (mpctx->stream));
2884 #endif /* CONFIG_PVR */
2885 break;
2887 case MP_CMD_TV_STEP_FREQ:
2888 if (mpctx->file_format == DEMUXER_TYPE_TV)
2889 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2890 cmd->args[0].v.f * 16.0);
2891 #ifdef CONFIG_PVR
2892 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2893 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2894 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2895 pvr_get_current_channelname (mpctx->stream),
2896 pvr_get_current_frequency (mpctx->stream));
2898 #endif /* CONFIG_PVR */
2899 break;
2901 case MP_CMD_TV_SET_NORM:
2902 if (mpctx->file_format == DEMUXER_TYPE_TV)
2903 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2904 cmd->args[0].v.s);
2905 break;
2907 case MP_CMD_TV_STEP_CHANNEL:{
2908 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2909 int v = cmd->args[0].v.i;
2910 if (v > 0) {
2911 tv_step_channel((tvi_handle_t *) (mpctx->
2912 demuxer->priv),
2913 TV_CHANNEL_HIGHER);
2914 } else {
2915 tv_step_channel((tvi_handle_t *) (mpctx->
2916 demuxer->priv),
2917 TV_CHANNEL_LOWER);
2919 if (tv_channel_list) {
2920 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2921 _("Channel: %s"), tv_channel_current->name);
2922 //vo_osd_changed(OSDTYPE_SUBTITLE);
2925 #ifdef CONFIG_PVR
2926 else if (mpctx->stream &&
2927 mpctx->stream->type == STREAMTYPE_PVR) {
2928 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2929 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2930 pvr_get_current_channelname (mpctx->stream),
2931 pvr_get_current_stationname (mpctx->stream));
2933 #endif /* CONFIG_PVR */
2935 #ifdef CONFIG_DVBIN
2936 if (mpctx->stream->type == STREAMTYPE_DVB) {
2937 int dir;
2938 int v = cmd->args[0].v.i;
2940 mpctx->last_dvb_step = v;
2941 if (v > 0)
2942 dir = DVB_CHANNEL_HIGHER;
2943 else
2944 dir = DVB_CHANNEL_LOWER;
2947 if (dvb_step_channel(mpctx->stream, dir)) {
2948 mpctx->stop_play = PT_NEXT_ENTRY;
2949 mpctx->dvbin_reopen = 1;
2952 #endif /* CONFIG_DVBIN */
2953 break;
2955 case MP_CMD_TV_SET_CHANNEL:
2956 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2957 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2958 cmd->args[0].v.s);
2959 if (tv_channel_list) {
2960 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2961 _("Channel: %s"), tv_channel_current->name);
2962 //vo_osd_changed(OSDTYPE_SUBTITLE);
2965 #ifdef CONFIG_PVR
2966 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2967 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2968 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2969 pvr_get_current_channelname (mpctx->stream),
2970 pvr_get_current_stationname (mpctx->stream));
2972 #endif /* CONFIG_PVR */
2973 break;
2975 #ifdef CONFIG_DVBIN
2976 case MP_CMD_DVB_SET_CHANNEL:
2977 if (mpctx->stream->type == STREAMTYPE_DVB) {
2978 mpctx->last_dvb_step = 1;
2980 if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i,
2981 cmd->args[0].v.i)) {
2982 mpctx->stop_play = PT_NEXT_ENTRY;
2983 mpctx->dvbin_reopen = 1;
2986 break;
2987 #endif /* CONFIG_DVBIN */
2989 case MP_CMD_TV_LAST_CHANNEL:
2990 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2991 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2992 if (tv_channel_list) {
2993 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2994 _("Channel: %s"), tv_channel_current->name);
2995 //vo_osd_changed(OSDTYPE_SUBTITLE);
2998 #ifdef CONFIG_PVR
2999 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
3000 pvr_set_lastchannel (mpctx->stream);
3001 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
3002 pvr_get_current_channelname (mpctx->stream),
3003 pvr_get_current_stationname (mpctx->stream));
3005 #endif /* CONFIG_PVR */
3006 break;
3008 case MP_CMD_TV_STEP_NORM:
3009 if (mpctx->file_format == DEMUXER_TYPE_TV)
3010 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
3011 break;
3013 case MP_CMD_TV_STEP_CHANNEL_LIST:
3014 if (mpctx->file_format == DEMUXER_TYPE_TV)
3015 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
3016 break;
3017 #ifdef CONFIG_TV_TELETEXT
3018 case MP_CMD_TV_TELETEXT_ADD_DEC:
3020 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
3021 if (mpctx->file_format == DEMUXER_TYPE_TV)
3022 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
3023 break;
3025 case MP_CMD_TV_TELETEXT_GO_LINK:
3027 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
3028 if (mpctx->file_format == DEMUXER_TYPE_TV)
3029 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
3030 break;
3032 #endif /* CONFIG_TV_TELETEXT */
3033 #endif /* CONFIG_TV */
3035 case MP_CMD_SUB_LOAD:
3036 if (sh_video) {
3037 int n = mpctx->set_of_sub_size;
3038 add_subtitles(mpctx, cmd->args[0].v.s, sh_video->fps, 0);
3039 if (n != mpctx->set_of_sub_size) {
3040 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
3041 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
3042 mpctx->global_sub_size;
3043 ++mpctx->global_sub_size;
3046 break;
3048 case MP_CMD_SUB_REMOVE:
3049 if (sh_video) {
3050 int v = cmd->args[0].v.i;
3051 sub_data *subd;
3052 if (v < 0) {
3053 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
3054 subd = mpctx->set_of_subtitles[v];
3055 mp_tmsg(MSGT_CPLAYER, MSGL_STATUS,
3056 "SUB: Removed subtitle file (%d): %s\n", v + 1,
3057 filename_recode(subd->filename));
3058 sub_free(subd);
3059 mpctx->set_of_subtitles[v] = NULL;
3061 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
3062 mpctx->global_sub_size -= mpctx->set_of_sub_size;
3063 mpctx->set_of_sub_size = 0;
3064 if (mpctx->set_of_sub_pos >= 0) {
3065 mpctx->global_sub_pos = -2;
3066 subdata = NULL;
3067 mp_input_queue_cmd(mpctx->input,
3068 mp_input_parse_cmd("sub_select"));
3070 } else if (v < mpctx->set_of_sub_size) {
3071 subd = mpctx->set_of_subtitles[v];
3072 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
3073 "SUB: Removed subtitle file (%d): %s\n", v + 1,
3074 filename_recode(subd->filename));
3075 sub_free(subd);
3076 if (mpctx->set_of_sub_pos == v) {
3077 mpctx->global_sub_pos = -2;
3078 subdata = NULL;
3079 mp_input_queue_cmd(mpctx->input,
3080 mp_input_parse_cmd("sub_select"));
3081 } else if (mpctx->set_of_sub_pos > v) {
3082 --mpctx->set_of_sub_pos;
3083 --mpctx->global_sub_pos;
3085 while (++v < mpctx->set_of_sub_size)
3086 mpctx->set_of_subtitles[v - 1] =
3087 mpctx->set_of_subtitles[v];
3088 --mpctx->set_of_sub_size;
3089 --mpctx->global_sub_size;
3090 if (mpctx->set_of_sub_size <= 0)
3091 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
3092 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
3095 break;
3097 case MP_CMD_GET_SUB_VISIBILITY:
3098 if (sh_video) {
3099 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3100 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
3102 break;
3104 case MP_CMD_SCREENSHOT:
3105 if (mpctx->video_out && mpctx->video_out->config_ok) {
3106 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
3107 if (CONTROL_OK !=
3108 ((vf_instance_t *) sh_video->vfilter)->
3109 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
3110 &cmd->args[0].v.i))
3111 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
3113 break;
3115 case MP_CMD_VF_CHANGE_RECTANGLE:
3116 if (!sh_video)
3117 break;
3118 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
3119 break;
3121 case MP_CMD_GET_TIME_LENGTH:{
3122 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
3123 demuxer_get_time_length(mpctx->demuxer));
3125 break;
3127 case MP_CMD_GET_FILENAME:{
3128 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
3129 get_metadata(mpctx, META_NAME));
3131 break;
3133 case MP_CMD_GET_VIDEO_CODEC:{
3134 char *inf = get_metadata(mpctx, META_VIDEO_CODEC);
3135 if (!inf)
3136 inf = strdup("");
3137 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
3138 free(inf);
3140 break;
3142 case MP_CMD_GET_VIDEO_BITRATE:{
3143 char *inf = get_metadata(mpctx, META_VIDEO_BITRATE);
3144 if (!inf)
3145 inf = strdup("");
3146 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3147 free(inf);
3149 break;
3151 case MP_CMD_GET_VIDEO_RESOLUTION:{
3152 char *inf = get_metadata(mpctx, META_VIDEO_RESOLUTION);
3153 if (!inf)
3154 inf = strdup("");
3155 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3156 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3157 free(inf);
3159 break;
3161 case MP_CMD_GET_AUDIO_CODEC:{
3162 char *inf = get_metadata(mpctx, META_AUDIO_CODEC);
3163 if (!inf)
3164 inf = strdup("");
3165 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3166 free(inf);
3168 break;
3170 case MP_CMD_GET_AUDIO_BITRATE:{
3171 char *inf = get_metadata(mpctx, META_AUDIO_BITRATE);
3172 if (!inf)
3173 inf = strdup("");
3174 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3175 free(inf);
3177 break;
3179 case MP_CMD_GET_AUDIO_SAMPLES:{
3180 char *inf = get_metadata(mpctx, META_AUDIO_SAMPLES);
3181 if (!inf)
3182 inf = strdup("");
3183 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3184 free(inf);
3186 break;
3188 case MP_CMD_GET_META_TITLE:{
3189 char *inf = get_metadata(mpctx, META_INFO_TITLE);
3190 if (!inf)
3191 inf = strdup("");
3192 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3193 free(inf);
3195 break;
3197 case MP_CMD_GET_META_ARTIST:{
3198 char *inf = get_metadata(mpctx, META_INFO_ARTIST);
3199 if (!inf)
3200 inf = strdup("");
3201 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3202 free(inf);
3204 break;
3206 case MP_CMD_GET_META_ALBUM:{
3207 char *inf = get_metadata(mpctx, META_INFO_ALBUM);
3208 if (!inf)
3209 inf = strdup("");
3210 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3211 free(inf);
3213 break;
3215 case MP_CMD_GET_META_YEAR:{
3216 char *inf = get_metadata(mpctx, META_INFO_YEAR);
3217 if (!inf)
3218 inf = strdup("");
3219 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3220 free(inf);
3222 break;
3224 case MP_CMD_GET_META_COMMENT:{
3225 char *inf = get_metadata(mpctx, META_INFO_COMMENT);
3226 if (!inf)
3227 inf = strdup("");
3228 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3229 free(inf);
3231 break;
3233 case MP_CMD_GET_META_TRACK:{
3234 char *inf = get_metadata(mpctx, META_INFO_TRACK);
3235 if (!inf)
3236 inf = strdup("");
3237 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3238 free(inf);
3240 break;
3242 case MP_CMD_GET_META_GENRE:{
3243 char *inf = get_metadata(mpctx, META_INFO_GENRE);
3244 if (!inf)
3245 inf = strdup("");
3246 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3247 free(inf);
3249 break;
3251 case MP_CMD_GET_VO_FULLSCREEN:
3252 if (mpctx->video_out && mpctx->video_out->config_ok)
3253 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3254 break;
3256 case MP_CMD_GET_PERCENT_POS:
3257 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3258 demuxer_get_percent_pos(mpctx->demuxer));
3259 break;
3261 case MP_CMD_GET_TIME_POS:{
3262 float pos = 0;
3263 if (sh_video)
3264 pos = sh_video->pts;
3265 else if (sh_audio && mpctx->audio_out)
3266 pos = playing_audio_pts(mpctx);
3267 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3269 break;
3271 case MP_CMD_RUN:
3272 #ifndef __MINGW32__
3273 if (!fork()) {
3274 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3275 exit(0);
3277 #endif
3278 break;
3280 case MP_CMD_KEYDOWN_EVENTS:
3281 mplayer_put_key(mpctx->key_fifo, cmd->args[0].v.i);
3282 break;
3284 case MP_CMD_SET_MOUSE_POS:{
3285 int pointer_x, pointer_y;
3286 double dx, dy;
3287 pointer_x = cmd->args[0].v.i;
3288 pointer_y = cmd->args[1].v.i;
3289 rescale_input_coordinates(mpctx, pointer_x, pointer_y, &dx, &dy);
3290 #ifdef CONFIG_DVDNAV
3291 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3292 && dx > 0.0 && dy > 0.0) {
3293 int button = -1;
3294 pointer_x = (int) (dx * (double) sh_video->disp_w);
3295 pointer_y = (int) (dy * (double) sh_video->disp_h);
3296 mp_dvdnav_update_mouse_pos(mpctx->stream,
3297 pointer_x, pointer_y, &button);
3298 if (opts->osd_level > 1 && button > 0)
3299 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3300 "Selected button number %d", button);
3302 #endif
3303 #ifdef CONFIG_MENU
3304 if (use_menu && dx >= 0.0 && dy >= 0.0)
3305 menu_update_mouse_pos(dx, dy);
3306 #endif
3308 break;
3310 #ifdef CONFIG_DVDNAV
3311 case MP_CMD_DVDNAV:{
3312 int button = -1;
3313 int i;
3314 mp_command_type command = 0;
3315 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3316 break;
3318 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3319 if (cmd->args[0].v.s &&
3320 !strcasecmp (cmd->args[0].v.s,
3321 mp_dvdnav_bindings[i].name))
3322 command = mp_dvdnav_bindings[i].cmd;
3324 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3325 if (opts->osd_level > 1 && button > 0)
3326 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3327 "Selected button number %d", button);
3329 break;
3331 case MP_CMD_SWITCH_TITLE:
3332 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3333 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3334 break;
3336 #endif
3338 default:
3339 mp_msg(MSGT_CPLAYER, MSGL_V,
3340 "Received unknown cmd %s\n", cmd->name);
3343 switch (cmd->pausing) {
3344 case 1: // "pausing"
3345 pause_player(mpctx);
3346 break;
3347 case 3: // "pausing_toggle"
3348 if (mpctx->paused)
3349 unpause_player(mpctx);
3350 else
3351 pause_player(mpctx);
3352 break;