Add colorspace option to vo_vdpau.
[mplayer/glamo.git] / command.c
blob3269db594922d8b398925e7efe75f7471bb27aa7
1 #include <stdlib.h>
2 #include <inttypes.h>
3 #include <unistd.h>
4 #include <string.h>
6 #include "config.h"
7 #include "command.h"
8 #include "input/input.h"
9 #include "stream/stream.h"
10 #include "libmpdemux/demuxer.h"
11 #include "libmpdemux/stheader.h"
12 #include "codec-cfg.h"
13 #include "mplayer.h"
14 #include "libvo/sub.h"
15 #include "m_option.h"
16 #include "m_property.h"
17 #include "help_mp.h"
18 #include "metadata.h"
19 #include "libmpcodecs/vf.h"
20 #include "libmpcodecs/vd.h"
21 #include "libvo/video_out.h"
22 #include "libvo/font_load.h"
23 #include "playtree.h"
24 #include "libao2/audio_out.h"
25 #include "mpcommon.h"
26 #include "mixer.h"
27 #include "libmpcodecs/dec_video.h"
28 #include "vobsub.h"
29 #include "spudec.h"
30 #include "get_path.h"
31 #include "stream/tv.h"
32 #include "stream/stream_radio.h"
33 #include "stream/pvr.h"
34 #ifdef CONFIG_DVBIN
35 #include "stream/dvbin.h"
36 #endif
37 #ifdef CONFIG_DVDREAD
38 #include "stream/stream_dvd.h"
39 #endif
40 #include "stream/stream_dvdnav.h"
41 #include "libass/ass.h"
42 #include "libass/ass_mp.h"
43 #include "m_struct.h"
44 #include "libmenu/menu.h"
45 #include "gui/interface.h"
47 #include "mp_core.h"
48 #include "mp_fifo.h"
49 #include "libavutil/avstring.h"
51 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
53 extern int use_menu;
55 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy)
57 //remove the borders, if any, and rescale to the range [0,1],[0,1]
58 if (vo_fs) { //we are in full-screen mode
59 if (vo_screenwidth > vo_dwidth) //there are borders along the x axis
60 ix -= (vo_screenwidth - vo_dwidth) / 2;
61 if (vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
62 iy -= (vo_screenheight - vo_dheight) / 2;
64 if (ix < 0 || ix > vo_dwidth) {
65 *dx = *dy = -1.0;
66 return;
67 } //we are on one of the borders
68 if (iy < 0 || iy > vo_dheight) {
69 *dx = *dy = -1.0;
70 return;
71 } //we are on one of the borders
74 *dx = (double) ix / (double) vo_dwidth;
75 *dy = (double) iy / (double) vo_dheight;
77 mp_msg(MSGT_CPLAYER, MSGL_V,
78 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
79 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth,
80 vo_dheight, vo_fs);
83 static int sub_source_by_pos(MPContext * mpctx, int pos)
85 int source = -1;
86 int top = -1;
87 int i;
88 for (i = 0; i < SUB_SOURCES; i++) {
89 int j = mpctx->global_sub_indices[i];
90 if ((j >= 0) && (j > top) && (pos >= j)) {
91 source = i;
92 top = j;
95 return source;
98 static int sub_source(MPContext * mpctx)
100 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
104 * \brief Log the currently displayed subtitle to a file
106 * Logs the current or last displayed subtitle together with filename
107 * and time information to ~/.mplayer/subtitle_log
109 * Intended purpose is to allow convenient marking of bogus subtitles
110 * which need to be fixed while watching the movie.
113 static void log_sub(void)
115 char *fname;
116 FILE *f;
117 int i;
119 if (subdata == NULL || vo_sub_last == NULL)
120 return;
121 fname = get_path("subtitle_log");
122 f = fopen(fname, "a");
123 if (!f)
124 return;
125 fprintf(f, "----------------------------------------------------------\n");
126 if (subdata->sub_uses_time) {
127 fprintf(f,
128 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
129 filename, vo_sub_last->start / 360000,
130 (vo_sub_last->start / 6000) % 60,
131 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
132 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
133 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
134 } else {
135 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start,
136 vo_sub_last->end);
138 for (i = 0; i < vo_sub_last->lines; i++) {
139 fprintf(f, "%s\n", vo_sub_last->text[i]);
141 fclose(f);
145 /// \defgroup Properties
146 ///@{
148 /// \defgroup GeneralProperties General properties
149 /// \ingroup Properties
150 ///@{
152 /// OSD level (RW)
153 static int mp_property_osdlevel(m_option_t * prop, int action, void *arg,
154 MPContext * mpctx)
156 return m_property_choice(prop, action, arg, &osd_level);
159 /// Loop (RW)
160 static int mp_property_loop(m_option_t * prop, int action, void *arg,
161 MPContext * mpctx)
163 switch (action) {
164 case M_PROPERTY_PRINT:
165 if (!arg) return M_PROPERTY_ERROR;
166 if (mpctx->loop_times < 0)
167 *(char**)arg = strdup("off");
168 else if (mpctx->loop_times == 0)
169 *(char**)arg = strdup("inf");
170 else
171 break;
172 return M_PROPERTY_OK;
174 return m_property_int_range(prop, action, arg, &mpctx->loop_times);
177 /// Playback speed (RW)
178 static int mp_property_playback_speed(m_option_t * prop, int action,
179 void *arg, MPContext * mpctx)
181 switch (action) {
182 case M_PROPERTY_SET:
183 if (!arg)
184 return M_PROPERTY_ERROR;
185 M_PROPERTY_CLAMP(prop, *(float *) arg);
186 playback_speed = *(float *) arg;
187 build_afilter_chain(mpctx->sh_audio, &ao_data);
188 return M_PROPERTY_OK;
189 case M_PROPERTY_STEP_UP:
190 case M_PROPERTY_STEP_DOWN:
191 playback_speed += (arg ? *(float *) arg : 0.1) *
192 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
193 M_PROPERTY_CLAMP(prop, playback_speed);
194 build_afilter_chain(mpctx->sh_audio, &ao_data);
195 return M_PROPERTY_OK;
197 return m_property_float_range(prop, action, arg, &playback_speed);
200 /// filename with path (RO)
201 static int mp_property_path(m_option_t * prop, int action, void *arg,
202 MPContext * mpctx)
204 return m_property_string_ro(prop, action, arg, filename);
207 /// filename without path (RO)
208 static int mp_property_filename(m_option_t * prop, int action, void *arg,
209 MPContext * mpctx)
211 char *f;
212 if (!filename)
213 return M_PROPERTY_UNAVAILABLE;
214 if (((f = strrchr(filename, '/')) || (f = strrchr(filename, '\\'))) && f[1])
215 f++;
216 else
217 f = filename;
218 return m_property_string_ro(prop, action, arg, f);
221 /// Demuxer name (RO)
222 static int mp_property_demuxer(m_option_t * prop, int action, void *arg,
223 MPContext * mpctx)
225 if (!mpctx->demuxer)
226 return M_PROPERTY_UNAVAILABLE;
227 return m_property_string_ro(prop, action, arg,
228 (char *) mpctx->demuxer->desc->name);
231 /// Position in the stream (RW)
232 static int mp_property_stream_pos(m_option_t * prop, int action, void *arg,
233 MPContext * mpctx)
235 if (!mpctx->demuxer || !mpctx->demuxer->stream)
236 return M_PROPERTY_UNAVAILABLE;
237 if (!arg)
238 return M_PROPERTY_ERROR;
239 switch (action) {
240 case M_PROPERTY_GET:
241 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
242 return M_PROPERTY_OK;
243 case M_PROPERTY_SET:
244 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
245 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
246 return M_PROPERTY_OK;
248 return M_PROPERTY_NOT_IMPLEMENTED;
251 /// Stream start offset (RO)
252 static int mp_property_stream_start(m_option_t * prop, int action,
253 void *arg, MPContext * mpctx)
255 if (!mpctx->demuxer || !mpctx->demuxer->stream)
256 return M_PROPERTY_UNAVAILABLE;
257 switch (action) {
258 case M_PROPERTY_GET:
259 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
260 return M_PROPERTY_OK;
262 return M_PROPERTY_NOT_IMPLEMENTED;
265 /// Stream end offset (RO)
266 static int mp_property_stream_end(m_option_t * prop, int action, void *arg,
267 MPContext * mpctx)
269 if (!mpctx->demuxer || !mpctx->demuxer->stream)
270 return M_PROPERTY_UNAVAILABLE;
271 switch (action) {
272 case M_PROPERTY_GET:
273 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
274 return M_PROPERTY_OK;
276 return M_PROPERTY_NOT_IMPLEMENTED;
279 /// Stream length (RO)
280 static int mp_property_stream_length(m_option_t * prop, int action,
281 void *arg, MPContext * mpctx)
283 if (!mpctx->demuxer || !mpctx->demuxer->stream)
284 return M_PROPERTY_UNAVAILABLE;
285 switch (action) {
286 case M_PROPERTY_GET:
287 *(off_t *) arg =
288 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
289 return M_PROPERTY_OK;
291 return M_PROPERTY_NOT_IMPLEMENTED;
294 /// Media length in seconds (RO)
295 static int mp_property_length(m_option_t * prop, int action, void *arg,
296 MPContext * mpctx)
298 double len;
300 if (!mpctx->demuxer ||
301 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
302 return M_PROPERTY_UNAVAILABLE;
304 return m_property_time_ro(prop, action, arg, len);
307 /// Current position in percent (RW)
308 static int mp_property_percent_pos(m_option_t * prop, int action,
309 void *arg, MPContext * mpctx) {
310 int pos;
312 if (!mpctx->demuxer)
313 return M_PROPERTY_UNAVAILABLE;
315 switch(action) {
316 case M_PROPERTY_SET:
317 if(!arg) return M_PROPERTY_ERROR;
318 M_PROPERTY_CLAMP(prop, *(int*)arg);
319 pos = *(int*)arg;
320 break;
321 case M_PROPERTY_STEP_UP:
322 case M_PROPERTY_STEP_DOWN:
323 pos = demuxer_get_percent_pos(mpctx->demuxer);
324 pos += (arg ? *(int*)arg : 10) *
325 (action == M_PROPERTY_STEP_UP ? 1 : -1);
326 M_PROPERTY_CLAMP(prop, pos);
327 break;
328 default:
329 return m_property_int_ro(prop, action, arg,
330 demuxer_get_percent_pos(mpctx->demuxer));
333 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
334 rel_seek_secs = pos / 100.0;
335 return M_PROPERTY_OK;
338 /// Current position in seconds (RW)
339 static int mp_property_time_pos(m_option_t * prop, int action,
340 void *arg, MPContext * mpctx) {
341 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
342 return M_PROPERTY_UNAVAILABLE;
344 switch(action) {
345 case M_PROPERTY_SET:
346 if(!arg) return M_PROPERTY_ERROR;
347 M_PROPERTY_CLAMP(prop, *(double*)arg);
348 abs_seek_pos = SEEK_ABSOLUTE;
349 rel_seek_secs = *(double*)arg;
350 return M_PROPERTY_OK;
351 case M_PROPERTY_STEP_UP:
352 case M_PROPERTY_STEP_DOWN:
353 rel_seek_secs += (arg ? *(double*)arg : 10.0) *
354 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
355 return M_PROPERTY_OK;
357 return m_property_time_ro(prop, action, arg,
358 mpctx->sh_video ? mpctx->sh_video->pts :
359 playing_audio_pts(mpctx->sh_audio,
360 mpctx->d_audio,
361 mpctx->audio_out));
364 /// Current chapter (RW)
365 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
366 MPContext *mpctx)
368 int chapter = -1;
369 float next_pts = 0;
370 int chapter_num;
371 int step_all;
372 char *chapter_name = NULL;
374 if (mpctx->demuxer)
375 chapter = demuxer_get_current_chapter(mpctx->demuxer);
376 if (chapter < 0)
377 return M_PROPERTY_UNAVAILABLE;
379 switch (action) {
380 case M_PROPERTY_GET:
381 if (!arg)
382 return M_PROPERTY_ERROR;
383 *(int *) arg = chapter;
384 return M_PROPERTY_OK;
385 case M_PROPERTY_PRINT: {
386 if (!arg)
387 return M_PROPERTY_ERROR;
388 chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter);
389 if (!chapter_name)
390 return M_PROPERTY_UNAVAILABLE;
391 *(char **) arg = chapter_name;
392 return M_PROPERTY_OK;
394 case M_PROPERTY_SET:
395 if (!arg)
396 return M_PROPERTY_ERROR;
397 M_PROPERTY_CLAMP(prop, *(int*)arg);
398 step_all = *(int *)arg - chapter;
399 chapter += step_all;
400 break;
401 case M_PROPERTY_STEP_UP:
402 case M_PROPERTY_STEP_DOWN: {
403 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
404 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
405 chapter += step_all;
406 if (chapter < 0)
407 chapter = 0;
408 break;
410 default:
411 return M_PROPERTY_NOT_IMPLEMENTED;
413 rel_seek_secs = 0;
414 abs_seek_pos = 0;
415 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
416 &next_pts, &chapter_num, &chapter_name);
417 if (chapter >= 0) {
418 if (next_pts > -1.0) {
419 abs_seek_pos = SEEK_ABSOLUTE;
420 rel_seek_secs = next_pts;
422 if (chapter_name)
423 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
424 MSGTR_OSDChapter, chapter + 1, chapter_name);
426 else if (step_all > 0)
427 rel_seek_secs = 1000000000.;
428 else
429 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
430 MSGTR_OSDChapter, 0, MSGTR_Unknown);
431 if (chapter_name)
432 free(chapter_name);
433 return M_PROPERTY_OK;
436 /// Number of chapters in file
437 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
438 MPContext *mpctx)
440 if (!mpctx->demuxer)
441 return M_PROPERTY_UNAVAILABLE;
442 if (mpctx->demuxer->num_chapters == 0)
443 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
444 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
447 /// Current dvd angle (RW)
448 static int mp_property_angle(m_option_t *prop, int action, void *arg,
449 MPContext *mpctx)
451 int angle = -1;
452 int angles;
453 char *angle_name = NULL;
455 if (mpctx->demuxer)
456 angle = demuxer_get_current_angle(mpctx->demuxer);
457 if (angle < 0)
458 return M_PROPERTY_UNAVAILABLE;
459 angles = demuxer_angles_count(mpctx->demuxer);
460 if (angles <= 1)
461 return M_PROPERTY_UNAVAILABLE;
463 switch (action) {
464 case M_PROPERTY_GET:
465 if (!arg)
466 return M_PROPERTY_ERROR;
467 *(int *) arg = angle;
468 return M_PROPERTY_OK;
469 case M_PROPERTY_PRINT: {
470 if (!arg)
471 return M_PROPERTY_ERROR;
472 angle_name = calloc(1, 64);
473 if (!angle_name)
474 return M_PROPERTY_UNAVAILABLE;
475 snprintf(angle_name, 64, "%d/%d", angle, angles);
476 *(char **) arg = angle_name;
477 return M_PROPERTY_OK;
479 case M_PROPERTY_SET:
480 if (!arg)
481 return M_PROPERTY_ERROR;
482 angle = *(int *)arg;
483 M_PROPERTY_CLAMP(prop, angle);
484 break;
485 case M_PROPERTY_STEP_UP:
486 case M_PROPERTY_STEP_DOWN: {
487 int step = 0;
488 if(arg)
489 step = *(int*)arg;
490 if(!step)
491 step = 1;
492 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
493 angle += step;
494 if (angle < 1) //cycle
495 angle = angles;
496 break;
498 default:
499 return M_PROPERTY_NOT_IMPLEMENTED;
501 angle = demuxer_set_angle(mpctx->demuxer, angle);
502 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
503 MSGTR_OSDAngle, angle, angles);
504 if (angle_name)
505 free(angle_name);
506 return M_PROPERTY_OK;
509 /// Demuxer meta data
510 static int mp_property_metadata(m_option_t * prop, int action, void *arg,
511 MPContext * mpctx) {
512 m_property_action_t* ka;
513 char* meta;
514 static m_option_t key_type =
515 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
516 if (!mpctx->demuxer)
517 return M_PROPERTY_UNAVAILABLE;
519 switch(action) {
520 case M_PROPERTY_GET:
521 if(!arg) return M_PROPERTY_ERROR;
522 *(char***)arg = mpctx->demuxer->info;
523 return M_PROPERTY_OK;
524 case M_PROPERTY_KEY_ACTION:
525 if(!arg) return M_PROPERTY_ERROR;
526 ka = arg;
527 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
528 return M_PROPERTY_UNKNOWN;
529 switch(ka->action) {
530 case M_PROPERTY_GET:
531 if(!ka->arg) return M_PROPERTY_ERROR;
532 *(char**)ka->arg = meta;
533 return M_PROPERTY_OK;
534 case M_PROPERTY_GET_TYPE:
535 if(!ka->arg) return M_PROPERTY_ERROR;
536 *(m_option_t**)ka->arg = &key_type;
537 return M_PROPERTY_OK;
540 return M_PROPERTY_NOT_IMPLEMENTED;
543 static int mp_property_pause(m_option_t * prop, int action, void *arg,
544 MPContext * mpctx)
546 return m_property_flag_ro(prop, action, arg, mpctx->osd_function == OSD_PAUSE);
550 ///@}
552 /// \defgroup AudioProperties Audio properties
553 /// \ingroup Properties
554 ///@{
556 /// Volume (RW)
557 static int mp_property_volume(m_option_t * prop, int action, void *arg,
558 MPContext * mpctx)
561 if (!mpctx->sh_audio)
562 return M_PROPERTY_UNAVAILABLE;
564 switch (action) {
565 case M_PROPERTY_GET:
566 if (!arg)
567 return M_PROPERTY_ERROR;
568 mixer_getbothvolume(&mpctx->mixer, arg);
569 return M_PROPERTY_OK;
570 case M_PROPERTY_PRINT:{
571 float vol;
572 if (!arg)
573 return M_PROPERTY_ERROR;
574 mixer_getbothvolume(&mpctx->mixer, &vol);
575 return m_property_float_range(prop, action, arg, &vol);
577 case M_PROPERTY_STEP_UP:
578 case M_PROPERTY_STEP_DOWN:
579 case M_PROPERTY_SET:
580 break;
581 default:
582 return M_PROPERTY_NOT_IMPLEMENTED;
585 if (mpctx->edl_muted)
586 return M_PROPERTY_DISABLED;
587 mpctx->user_muted = 0;
589 switch (action) {
590 case M_PROPERTY_SET:
591 if (!arg)
592 return M_PROPERTY_ERROR;
593 M_PROPERTY_CLAMP(prop, *(float *) arg);
594 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
595 return M_PROPERTY_OK;
596 case M_PROPERTY_STEP_UP:
597 if (arg && *(float *) arg <= 0)
598 mixer_decvolume(&mpctx->mixer);
599 else
600 mixer_incvolume(&mpctx->mixer);
601 return M_PROPERTY_OK;
602 case M_PROPERTY_STEP_DOWN:
603 if (arg && *(float *) arg <= 0)
604 mixer_incvolume(&mpctx->mixer);
605 else
606 mixer_decvolume(&mpctx->mixer);
607 return M_PROPERTY_OK;
609 return M_PROPERTY_NOT_IMPLEMENTED;
612 /// Mute (RW)
613 static int mp_property_mute(m_option_t * prop, int action, void *arg,
614 MPContext * mpctx)
617 if (!mpctx->sh_audio)
618 return M_PROPERTY_UNAVAILABLE;
620 switch (action) {
621 case M_PROPERTY_SET:
622 if (mpctx->edl_muted)
623 return M_PROPERTY_DISABLED;
624 if (!arg)
625 return M_PROPERTY_ERROR;
626 if ((!!*(int *) arg) != mpctx->mixer.muted)
627 mixer_mute(&mpctx->mixer);
628 mpctx->user_muted = mpctx->mixer.muted;
629 return M_PROPERTY_OK;
630 case M_PROPERTY_STEP_UP:
631 case M_PROPERTY_STEP_DOWN:
632 if (mpctx->edl_muted)
633 return M_PROPERTY_DISABLED;
634 mixer_mute(&mpctx->mixer);
635 mpctx->user_muted = mpctx->mixer.muted;
636 return M_PROPERTY_OK;
637 case M_PROPERTY_PRINT:
638 if (!arg)
639 return M_PROPERTY_ERROR;
640 if (mpctx->edl_muted) {
641 *(char **) arg = strdup(MSGTR_EnabledEdl);
642 return M_PROPERTY_OK;
644 default:
645 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
650 /// Audio delay (RW)
651 static int mp_property_audio_delay(m_option_t * prop, int action,
652 void *arg, MPContext * mpctx)
654 if (!(mpctx->sh_audio && mpctx->sh_video))
655 return M_PROPERTY_UNAVAILABLE;
656 switch (action) {
657 case M_PROPERTY_SET:
658 case M_PROPERTY_STEP_UP:
659 case M_PROPERTY_STEP_DOWN: {
660 int ret;
661 float delay = audio_delay;
662 ret = m_property_delay(prop, action, arg, &audio_delay);
663 if (ret != M_PROPERTY_OK)
664 return ret;
665 if (mpctx->sh_audio)
666 mpctx->delay -= audio_delay - delay;
668 return M_PROPERTY_OK;
669 default:
670 return m_property_delay(prop, action, arg, &audio_delay);
674 /// Audio codec tag (RO)
675 static int mp_property_audio_format(m_option_t * prop, int action,
676 void *arg, MPContext * mpctx)
678 if (!mpctx->sh_audio)
679 return M_PROPERTY_UNAVAILABLE;
680 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
683 /// Audio codec name (RO)
684 static int mp_property_audio_codec(m_option_t * prop, int action,
685 void *arg, MPContext * mpctx)
687 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
688 return M_PROPERTY_UNAVAILABLE;
689 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
692 /// Audio bitrate (RO)
693 static int mp_property_audio_bitrate(m_option_t * prop, int action,
694 void *arg, MPContext * mpctx)
696 if (!mpctx->sh_audio)
697 return M_PROPERTY_UNAVAILABLE;
698 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
701 /// Samplerate (RO)
702 static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
703 MPContext * mpctx)
705 if (!mpctx->sh_audio)
706 return M_PROPERTY_UNAVAILABLE;
707 switch(action) {
708 case M_PROPERTY_PRINT:
709 if(!arg) return M_PROPERTY_ERROR;
710 *(char**)arg = malloc(16);
711 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
712 return M_PROPERTY_OK;
714 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
717 /// Number of channels (RO)
718 static int mp_property_channels(m_option_t * prop, int action, void *arg,
719 MPContext * mpctx)
721 if (!mpctx->sh_audio)
722 return M_PROPERTY_UNAVAILABLE;
723 switch (action) {
724 case M_PROPERTY_PRINT:
725 if (!arg)
726 return M_PROPERTY_ERROR;
727 switch (mpctx->sh_audio->channels) {
728 case 1:
729 *(char **) arg = strdup("mono");
730 break;
731 case 2:
732 *(char **) arg = strdup("stereo");
733 break;
734 default:
735 *(char **) arg = malloc(32);
736 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
738 return M_PROPERTY_OK;
740 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
743 /// Balance (RW)
744 static int mp_property_balance(m_option_t * prop, int action, void *arg,
745 MPContext * mpctx)
747 float bal;
749 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
750 return M_PROPERTY_UNAVAILABLE;
752 switch (action) {
753 case M_PROPERTY_GET:
754 if (!arg)
755 return M_PROPERTY_ERROR;
756 mixer_getbalance(&mpctx->mixer, arg);
757 return M_PROPERTY_OK;
758 case M_PROPERTY_PRINT: {
759 char** str = arg;
760 if (!arg)
761 return M_PROPERTY_ERROR;
762 mixer_getbalance(&mpctx->mixer, &bal);
763 if (bal == 0.f)
764 *str = strdup("center");
765 else if (bal == -1.f)
766 *str = strdup("left only");
767 else if (bal == 1.f)
768 *str = strdup("right only");
769 else {
770 unsigned right = (bal + 1.f) / 2.f * 100.f;
771 *str = malloc(sizeof("left xxx%, right xxx%"));
772 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
774 return M_PROPERTY_OK;
776 case M_PROPERTY_STEP_UP:
777 case M_PROPERTY_STEP_DOWN:
778 mixer_getbalance(&mpctx->mixer, &bal);
779 bal += (arg ? *(float*)arg : .1f) *
780 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
781 M_PROPERTY_CLAMP(prop, bal);
782 mixer_setbalance(&mpctx->mixer, bal);
783 return M_PROPERTY_OK;
784 case M_PROPERTY_SET:
785 if (!arg)
786 return M_PROPERTY_ERROR;
787 M_PROPERTY_CLAMP(prop, *(float*)arg);
788 mixer_setbalance(&mpctx->mixer, *(float*)arg);
789 return M_PROPERTY_OK;
791 return M_PROPERTY_NOT_IMPLEMENTED;
794 /// Selected audio id (RW)
795 static int mp_property_audio(m_option_t * prop, int action, void *arg,
796 MPContext * mpctx)
798 int current_id = -1, tmp;
800 switch (action) {
801 case M_PROPERTY_GET:
802 if (!mpctx->sh_audio)
803 return M_PROPERTY_UNAVAILABLE;
804 if (!arg)
805 return M_PROPERTY_ERROR;
806 *(int *) arg = audio_id;
807 return M_PROPERTY_OK;
808 case M_PROPERTY_PRINT:
809 if (!mpctx->sh_audio)
810 return M_PROPERTY_UNAVAILABLE;
811 if (!arg)
812 return M_PROPERTY_ERROR;
814 if (audio_id < 0)
815 *(char **) arg = strdup(MSGTR_Disabled);
816 else {
817 char lang[40] = MSGTR_Unknown;
818 sh_audio_t* sh = mpctx->sh_audio;
819 if (sh && sh->lang)
820 av_strlcpy(lang, sh->lang, 40);
821 #ifdef CONFIG_DVDREAD
822 else if (mpctx->stream->type == STREAMTYPE_DVD) {
823 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
824 if (code) {
825 lang[0] = code >> 8;
826 lang[1] = code;
827 lang[2] = 0;
830 #endif
832 #ifdef CONFIG_DVDNAV
833 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
834 mp_dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
835 #endif
836 *(char **) arg = malloc(64);
837 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
839 return M_PROPERTY_OK;
841 case M_PROPERTY_STEP_UP:
842 case M_PROPERTY_SET:
843 if (!mpctx->demuxer)
844 return M_PROPERTY_UNAVAILABLE;
845 if (action == M_PROPERTY_SET && arg)
846 tmp = *((int *) arg);
847 else
848 tmp = -1;
849 current_id = mpctx->demuxer->audio->id;
850 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
851 if (audio_id == -2
852 || (audio_id > -1
853 && mpctx->demuxer->audio->id != current_id && current_id != -2))
854 uninit_player(INITIALIZED_AO | INITIALIZED_ACODEC);
855 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
856 sh_audio_t *sh2;
857 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
858 if (sh2) {
859 sh2->ds = mpctx->demuxer->audio;
860 mpctx->sh_audio = sh2;
861 reinit_audio_chain();
864 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
865 return M_PROPERTY_OK;
866 default:
867 return M_PROPERTY_NOT_IMPLEMENTED;
872 /// Selected video id (RW)
873 static int mp_property_video(m_option_t * prop, int action, void *arg,
874 MPContext * mpctx)
876 int current_id = -1, tmp;
878 switch (action) {
879 case M_PROPERTY_GET:
880 if (!mpctx->sh_video)
881 return M_PROPERTY_UNAVAILABLE;
882 if (!arg)
883 return M_PROPERTY_ERROR;
884 *(int *) arg = video_id;
885 return M_PROPERTY_OK;
886 case M_PROPERTY_PRINT:
887 if (!mpctx->sh_video)
888 return M_PROPERTY_UNAVAILABLE;
889 if (!arg)
890 return M_PROPERTY_ERROR;
892 if (video_id < 0)
893 *(char **) arg = strdup(MSGTR_Disabled);
894 else {
895 char lang[40] = MSGTR_Unknown;
896 *(char **) arg = malloc(64);
897 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
899 return M_PROPERTY_OK;
901 case M_PROPERTY_STEP_UP:
902 case M_PROPERTY_SET:
903 current_id = mpctx->demuxer->video->id;
904 if (action == M_PROPERTY_SET && arg)
905 tmp = *((int *) arg);
906 else
907 tmp = -1;
908 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
909 if (video_id == -2
910 || (video_id > -1 && mpctx->demuxer->video->id != current_id
911 && current_id != -2))
912 uninit_player(INITIALIZED_VCODEC |
913 (fixed_vo && video_id != -2 ? 0 : INITIALIZED_VO));
914 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
915 sh_video_t *sh2;
916 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
917 if (sh2) {
918 sh2->ds = mpctx->demuxer->video;
919 mpctx->sh_video = sh2;
920 reinit_video_chain();
923 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
924 return M_PROPERTY_OK;
926 default:
927 return M_PROPERTY_NOT_IMPLEMENTED;
931 static int mp_property_program(m_option_t * prop, int action, void *arg,
932 MPContext * mpctx)
934 demux_program_t prog;
936 switch (action) {
937 case M_PROPERTY_STEP_UP:
938 case M_PROPERTY_SET:
939 if (action == M_PROPERTY_SET && arg)
940 prog.progid = *((int *) arg);
941 else
942 prog.progid = -1;
943 if (demux_control
944 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
945 &prog) == DEMUXER_CTRL_NOTIMPL)
946 return M_PROPERTY_ERROR;
948 if (prog.aid < 0 && prog.vid < 0) {
949 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
950 return M_PROPERTY_ERROR;
952 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
953 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
954 return M_PROPERTY_OK;
956 default:
957 return M_PROPERTY_NOT_IMPLEMENTED;
961 ///@}
963 /// \defgroup VideoProperties Video properties
964 /// \ingroup Properties
965 ///@{
967 /// Fullscreen state (RW)
968 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
969 MPContext * mpctx)
972 if (!mpctx->video_out)
973 return M_PROPERTY_UNAVAILABLE;
975 switch (action) {
976 case M_PROPERTY_SET:
977 if (!arg)
978 return M_PROPERTY_ERROR;
979 M_PROPERTY_CLAMP(prop, *(int *) arg);
980 if (vo_fs == !!*(int *) arg)
981 return M_PROPERTY_OK;
982 case M_PROPERTY_STEP_UP:
983 case M_PROPERTY_STEP_DOWN:
984 #ifdef CONFIG_GUI
985 if (use_gui)
986 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
987 else
988 #endif
989 if (vo_config_count)
990 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
991 return M_PROPERTY_OK;
992 default:
993 return m_property_flag(prop, action, arg, &vo_fs);
997 static int mp_property_deinterlace(m_option_t * prop, int action,
998 void *arg, MPContext * mpctx)
1000 int deinterlace;
1001 vf_instance_t *vf;
1002 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1003 return M_PROPERTY_UNAVAILABLE;
1004 vf = mpctx->sh_video->vfilter;
1005 switch (action) {
1006 case M_PROPERTY_GET:
1007 if (!arg)
1008 return M_PROPERTY_ERROR;
1009 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1010 return M_PROPERTY_OK;
1011 case M_PROPERTY_SET:
1012 if (!arg)
1013 return M_PROPERTY_ERROR;
1014 M_PROPERTY_CLAMP(prop, *(int *) arg);
1015 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1016 return M_PROPERTY_OK;
1017 case M_PROPERTY_STEP_UP:
1018 case M_PROPERTY_STEP_DOWN:
1019 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1020 deinterlace = !deinterlace;
1021 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1022 return M_PROPERTY_OK;
1024 return M_PROPERTY_NOT_IMPLEMENTED;
1027 /// Panscan (RW)
1028 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
1029 MPContext * mpctx)
1032 if (!mpctx->video_out
1033 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1034 return M_PROPERTY_UNAVAILABLE;
1036 switch (action) {
1037 case M_PROPERTY_SET:
1038 if (!arg)
1039 return M_PROPERTY_ERROR;
1040 M_PROPERTY_CLAMP(prop, *(float *) arg);
1041 vo_panscan = *(float *) arg;
1042 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1043 return M_PROPERTY_OK;
1044 case M_PROPERTY_STEP_UP:
1045 case M_PROPERTY_STEP_DOWN:
1046 vo_panscan += (arg ? *(float *) arg : 0.1) *
1047 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1048 if (vo_panscan > 1)
1049 vo_panscan = 1;
1050 else if (vo_panscan < 0)
1051 vo_panscan = 0;
1052 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1053 return M_PROPERTY_OK;
1054 default:
1055 return m_property_float_range(prop, action, arg, &vo_panscan);
1059 /// Helper to set vo flags.
1060 /** \ingroup PropertyImplHelper
1062 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
1063 int vo_ctrl, int *vo_var, MPContext * mpctx)
1066 if (!mpctx->video_out)
1067 return M_PROPERTY_UNAVAILABLE;
1069 switch (action) {
1070 case M_PROPERTY_SET:
1071 if (!arg)
1072 return M_PROPERTY_ERROR;
1073 M_PROPERTY_CLAMP(prop, *(int *) arg);
1074 if (*vo_var == !!*(int *) arg)
1075 return M_PROPERTY_OK;
1076 case M_PROPERTY_STEP_UP:
1077 case M_PROPERTY_STEP_DOWN:
1078 if (vo_config_count)
1079 mpctx->video_out->control(vo_ctrl, 0);
1080 return M_PROPERTY_OK;
1081 default:
1082 return m_property_flag(prop, action, arg, vo_var);
1086 /// Window always on top (RW)
1087 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
1088 MPContext * mpctx)
1090 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
1091 mpctx);
1094 /// Display in the root window (RW)
1095 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
1096 MPContext * mpctx)
1098 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1099 &vo_rootwin, mpctx);
1102 /// Show window borders (RW)
1103 static int mp_property_border(m_option_t * prop, int action, void *arg,
1104 MPContext * mpctx)
1106 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1107 &vo_border, mpctx);
1110 /// Framedropping state (RW)
1111 static int mp_property_framedropping(m_option_t * prop, int action,
1112 void *arg, MPContext * mpctx)
1115 if (!mpctx->sh_video)
1116 return M_PROPERTY_UNAVAILABLE;
1118 switch (action) {
1119 case M_PROPERTY_PRINT:
1120 if (!arg)
1121 return M_PROPERTY_ERROR;
1122 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1123 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1124 MSGTR_Disabled));
1125 return M_PROPERTY_OK;
1126 default:
1127 return m_property_choice(prop, action, arg, &frame_dropping);
1131 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1132 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
1133 MPContext * mpctx)
1135 int *gamma = prop->priv, r, val;
1137 if (!mpctx->sh_video)
1138 return M_PROPERTY_UNAVAILABLE;
1140 if (gamma[0] == 1000) {
1141 gamma[0] = 0;
1142 get_video_colors(mpctx->sh_video, prop->name, gamma);
1145 switch (action) {
1146 case M_PROPERTY_SET:
1147 if (!arg)
1148 return M_PROPERTY_ERROR;
1149 M_PROPERTY_CLAMP(prop, *(int *) arg);
1150 *gamma = *(int *) arg;
1151 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1152 if (r <= 0)
1153 break;
1154 return r;
1155 case M_PROPERTY_GET:
1156 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1157 if (!arg)
1158 return M_PROPERTY_ERROR;
1159 *(int *)arg = val;
1160 return M_PROPERTY_OK;
1162 break;
1163 case M_PROPERTY_STEP_UP:
1164 case M_PROPERTY_STEP_DOWN:
1165 *gamma += (arg ? *(int *) arg : 1) *
1166 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1167 M_PROPERTY_CLAMP(prop, *gamma);
1168 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1169 if (r <= 0)
1170 break;
1171 return r;
1172 default:
1173 return M_PROPERTY_NOT_IMPLEMENTED;
1176 #ifdef CONFIG_TV
1177 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1178 int l = strlen(prop->name);
1179 char tv_prop[3 + l + 1];
1180 sprintf(tv_prop, "tv_%s", prop->name);
1181 return mp_property_do(tv_prop, action, arg, mpctx);
1183 #endif
1185 return M_PROPERTY_UNAVAILABLE;
1188 /// VSync (RW)
1189 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1190 MPContext * mpctx)
1192 return m_property_flag(prop, action, arg, &vo_vsync);
1195 /// Video codec tag (RO)
1196 static int mp_property_video_format(m_option_t * prop, int action,
1197 void *arg, MPContext * mpctx)
1199 char* meta;
1200 if (!mpctx->sh_video)
1201 return M_PROPERTY_UNAVAILABLE;
1202 switch(action) {
1203 case M_PROPERTY_PRINT:
1204 if (!arg)
1205 return M_PROPERTY_ERROR;
1206 switch(mpctx->sh_video->format) {
1207 case 0x10000001:
1208 meta = strdup ("mpeg1"); break;
1209 case 0x10000002:
1210 meta = strdup ("mpeg2"); break;
1211 case 0x10000004:
1212 meta = strdup ("mpeg4"); break;
1213 case 0x10000005:
1214 meta = strdup ("h264"); break;
1215 default:
1216 if(mpctx->sh_video->format >= 0x20202020) {
1217 meta = malloc(5);
1218 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1219 } else {
1220 meta = malloc(20);
1221 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1224 *(char**)arg = meta;
1225 return M_PROPERTY_OK;
1227 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1230 /// Video codec name (RO)
1231 static int mp_property_video_codec(m_option_t * prop, int action,
1232 void *arg, MPContext * mpctx)
1234 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1235 return M_PROPERTY_UNAVAILABLE;
1236 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1240 /// Video bitrate (RO)
1241 static int mp_property_video_bitrate(m_option_t * prop, int action,
1242 void *arg, MPContext * mpctx)
1244 if (!mpctx->sh_video)
1245 return M_PROPERTY_UNAVAILABLE;
1246 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1249 /// Video display width (RO)
1250 static int mp_property_width(m_option_t * prop, int action, void *arg,
1251 MPContext * mpctx)
1253 if (!mpctx->sh_video)
1254 return M_PROPERTY_UNAVAILABLE;
1255 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1258 /// Video display height (RO)
1259 static int mp_property_height(m_option_t * prop, int action, void *arg,
1260 MPContext * mpctx)
1262 if (!mpctx->sh_video)
1263 return M_PROPERTY_UNAVAILABLE;
1264 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1267 /// Video fps (RO)
1268 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1269 MPContext * mpctx)
1271 if (!mpctx->sh_video)
1272 return M_PROPERTY_UNAVAILABLE;
1273 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1276 /// Video aspect (RO)
1277 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1278 MPContext * mpctx)
1280 if (!mpctx->sh_video)
1281 return M_PROPERTY_UNAVAILABLE;
1282 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1285 ///@}
1287 /// \defgroup SubProprties Subtitles properties
1288 /// \ingroup Properties
1289 ///@{
1291 /// Text subtitle position (RW)
1292 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1293 MPContext * mpctx)
1295 if (!mpctx->sh_video)
1296 return M_PROPERTY_UNAVAILABLE;
1298 switch (action) {
1299 case M_PROPERTY_SET:
1300 if (!arg)
1301 return M_PROPERTY_ERROR;
1302 case M_PROPERTY_STEP_UP:
1303 case M_PROPERTY_STEP_DOWN:
1304 vo_osd_changed(OSDTYPE_SUBTITLE);
1305 default:
1306 return m_property_int_range(prop, action, arg, &sub_pos);
1310 /// Selected subtitles (RW)
1311 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1312 MPContext * mpctx)
1314 demux_stream_t *const d_sub = mpctx->d_sub;
1315 const int global_sub_size = mpctx->global_sub_size;
1316 int source = -1, reset_spu = 0;
1317 double pts = 0;
1318 char *sub_name;
1320 if (global_sub_size <= 0)
1321 return M_PROPERTY_UNAVAILABLE;
1323 switch (action) {
1324 case M_PROPERTY_GET:
1325 if (!arg)
1326 return M_PROPERTY_ERROR;
1327 *(int *) arg = mpctx->global_sub_pos;
1328 return M_PROPERTY_OK;
1329 case M_PROPERTY_PRINT:
1330 if (!arg)
1331 return M_PROPERTY_ERROR;
1332 *(char **) arg = malloc(64);
1333 (*(char **) arg)[63] = 0;
1334 sub_name = 0;
1335 if (subdata)
1336 sub_name = subdata->filename;
1337 #ifdef CONFIG_ASS
1338 if (ass_track && ass_track->name)
1339 sub_name = ass_track->name;
1340 #endif
1341 if (sub_name) {
1342 char *tmp, *tmp2;
1343 tmp = sub_name;
1344 if ((tmp2 = strrchr(tmp, '/')))
1345 tmp = tmp2 + 1;
1347 snprintf(*(char **) arg, 63, "(%d) %s%s",
1348 mpctx->set_of_sub_pos + 1,
1349 strlen(tmp) < 20 ? "" : "...",
1350 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1351 return M_PROPERTY_OK;
1353 #ifdef CONFIG_DVDNAV
1354 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1355 if (vo_spudec && dvdsub_id >= 0) {
1356 unsigned char lang[3];
1357 if (mp_dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1358 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1359 return M_PROPERTY_OK;
1363 #endif
1365 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1366 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1367 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1368 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1369 && d_sub && d_sub->sh && dvdsub_id >= 0) {
1370 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1371 if (!lang) lang = MSGTR_Unknown;
1372 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1373 return M_PROPERTY_OK;
1376 if (vo_vobsub && vobsub_id >= 0) {
1377 const char *language = MSGTR_Unknown;
1378 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1379 snprintf(*(char **) arg, 63, "(%d) %s",
1380 vobsub_id, language ? language : MSGTR_Unknown);
1381 return M_PROPERTY_OK;
1383 #ifdef CONFIG_DVDREAD
1384 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1385 && dvdsub_id >= 0) {
1386 char lang[3];
1387 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1388 lang[0] = code >> 8;
1389 lang[1] = code;
1390 lang[2] = 0;
1391 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1392 return M_PROPERTY_OK;
1394 #endif
1395 if (dvdsub_id >= 0) {
1396 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1397 return M_PROPERTY_OK;
1399 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1400 return M_PROPERTY_OK;
1402 case M_PROPERTY_SET:
1403 if (!arg)
1404 return M_PROPERTY_ERROR;
1405 if (*(int *) arg < -1)
1406 *(int *) arg = -1;
1407 else if (*(int *) arg >= global_sub_size)
1408 *(int *) arg = global_sub_size - 1;
1409 mpctx->global_sub_pos = *(int *) arg;
1410 break;
1411 case M_PROPERTY_STEP_UP:
1412 mpctx->global_sub_pos += 2;
1413 mpctx->global_sub_pos =
1414 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1415 break;
1416 case M_PROPERTY_STEP_DOWN:
1417 mpctx->global_sub_pos += global_sub_size + 1;
1418 mpctx->global_sub_pos =
1419 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1420 break;
1421 default:
1422 return M_PROPERTY_NOT_IMPLEMENTED;
1425 if (mpctx->global_sub_pos >= 0)
1426 source = sub_source(mpctx);
1428 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1429 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1430 global_sub_size,
1431 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1432 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1433 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1434 mpctx->global_sub_pos, source);
1436 mpctx->set_of_sub_pos = -1;
1437 subdata = NULL;
1439 vobsub_id = -1;
1440 dvdsub_id = -1;
1441 if (d_sub) {
1442 if (d_sub->id > -2)
1443 reset_spu = 1;
1444 d_sub->id = -2;
1446 #ifdef CONFIG_ASS
1447 ass_track = 0;
1448 #endif
1450 if (source == SUB_SOURCE_VOBSUB) {
1451 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1452 } else if (source == SUB_SOURCE_SUBS) {
1453 mpctx->set_of_sub_pos =
1454 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1455 #ifdef CONFIG_ASS
1456 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1457 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1458 else
1459 #endif
1461 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1462 vo_osd_changed(OSDTYPE_SUBTITLE);
1464 } else if (source == SUB_SOURCE_DEMUX) {
1465 dvdsub_id =
1466 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1467 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1468 int i = 0;
1469 // default: assume 1:1 mapping of sid and stream id
1470 d_sub->id = dvdsub_id;
1471 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1472 ds_free_packs(d_sub);
1473 for (i = 0; i < MAX_S_STREAMS; i++) {
1474 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1475 if (sh && sh->sid == dvdsub_id) {
1476 d_sub->id = i;
1477 d_sub->sh = sh;
1478 break;
1481 if (d_sub->sh && d_sub->id >= 0) {
1482 sh_sub_t *sh = d_sub->sh;
1483 if (sh->type == 'v')
1484 init_vo_spudec();
1485 #ifdef CONFIG_ASS
1486 else if (ass_enabled)
1487 ass_track = sh->ass_track;
1488 #endif
1489 } else {
1490 d_sub->id = -2;
1491 d_sub->sh = NULL;
1495 #ifdef CONFIG_DVDREAD
1496 if (vo_spudec
1497 && (mpctx->stream->type == STREAMTYPE_DVD
1498 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1499 && dvdsub_id < 0 && reset_spu) {
1500 dvdsub_id = -2;
1501 d_sub->id = dvdsub_id;
1503 #endif
1504 if (mpctx->sh_audio)
1505 pts = mpctx->sh_audio->pts;
1506 if (mpctx->sh_video)
1507 pts = mpctx->sh_video->pts;
1508 update_subtitles(mpctx->sh_video, pts, d_sub, 1);
1510 return M_PROPERTY_OK;
1513 /// Selected sub source (RW)
1514 static int mp_property_sub_source(m_option_t * prop, int action, void *arg,
1515 MPContext * mpctx)
1517 int source;
1518 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1519 return M_PROPERTY_UNAVAILABLE;
1521 switch (action) {
1522 case M_PROPERTY_GET:
1523 if (!arg)
1524 return M_PROPERTY_ERROR;
1525 *(int *) arg = sub_source(mpctx);
1526 return M_PROPERTY_OK;
1527 case M_PROPERTY_PRINT:
1528 if (!arg)
1529 return M_PROPERTY_ERROR;
1530 *(char **) arg = malloc(64);
1531 (*(char **) arg)[63] = 0;
1532 switch (sub_source(mpctx))
1534 case SUB_SOURCE_SUBS:
1535 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1536 break;
1537 case SUB_SOURCE_VOBSUB:
1538 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1539 break;
1540 case SUB_SOURCE_DEMUX:
1541 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1542 break;
1543 default:
1544 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1546 return M_PROPERTY_OK;
1547 case M_PROPERTY_SET:
1548 if (!arg)
1549 return M_PROPERTY_ERROR;
1550 M_PROPERTY_CLAMP(prop, *(int*)arg);
1551 if (*(int *) arg < 0)
1552 mpctx->global_sub_pos = -1;
1553 else if (*(int *) arg != sub_source(mpctx)) {
1554 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1555 return M_PROPERTY_UNAVAILABLE;
1556 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1558 break;
1559 case M_PROPERTY_STEP_UP:
1560 case M_PROPERTY_STEP_DOWN: {
1561 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1562 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1563 int step = (step_all > 0) ? 1 : -1;
1564 int cur_source = sub_source(mpctx);
1565 source = cur_source;
1566 while (step_all) {
1567 source += step;
1568 if (source >= SUB_SOURCES)
1569 source = -1;
1570 else if (source < -1)
1571 source = SUB_SOURCES - 1;
1572 if (source == cur_source || source == -1 ||
1573 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1574 step_all -= step;
1576 if (source == cur_source)
1577 return M_PROPERTY_OK;
1578 if (source == -1)
1579 mpctx->global_sub_pos = -1;
1580 else
1581 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1582 break;
1584 default:
1585 return M_PROPERTY_NOT_IMPLEMENTED;
1587 --mpctx->global_sub_pos;
1588 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1591 /// Selected subtitles from specific source (RW)
1592 static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg,
1593 MPContext * mpctx)
1595 int source, is_cur_source, offset;
1596 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1597 return M_PROPERTY_UNAVAILABLE;
1599 if (!strcmp(prop->name, "sub_file"))
1600 source = SUB_SOURCE_SUBS;
1601 else if (!strcmp(prop->name, "sub_vob"))
1602 source = SUB_SOURCE_VOBSUB;
1603 else if (!strcmp(prop->name, "sub_demux"))
1604 source = SUB_SOURCE_DEMUX;
1605 else
1606 return M_PROPERTY_ERROR;
1608 offset = mpctx->global_sub_indices[source];
1609 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1610 return M_PROPERTY_UNAVAILABLE;
1612 is_cur_source = sub_source(mpctx) == source;
1613 switch (action) {
1614 case M_PROPERTY_GET:
1615 if (!arg)
1616 return M_PROPERTY_ERROR;
1617 if (is_cur_source) {
1618 *(int *) arg = mpctx->global_sub_pos - offset;
1619 if (source == SUB_SOURCE_VOBSUB)
1620 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1622 else
1623 *(int *) arg = -1;
1624 return M_PROPERTY_OK;
1625 case M_PROPERTY_PRINT:
1626 if (!arg)
1627 return M_PROPERTY_ERROR;
1628 if (is_cur_source)
1629 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1630 *(char **) arg = malloc(64);
1631 (*(char **) arg)[63] = 0;
1632 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1633 return M_PROPERTY_OK;
1634 case M_PROPERTY_SET:
1635 if (!arg)
1636 return M_PROPERTY_ERROR;
1637 if (*(int *) arg >= 0) {
1638 int index = *(int *)arg;
1639 if (source == SUB_SOURCE_VOBSUB)
1640 index = vobsub_get_index_by_id(vo_vobsub, index);
1641 mpctx->global_sub_pos = offset + index;
1642 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1643 || sub_source(mpctx) != source) {
1644 mpctx->global_sub_pos = -1;
1645 *(int *) arg = -1;
1648 else
1649 mpctx->global_sub_pos = -1;
1650 break;
1651 case M_PROPERTY_STEP_UP:
1652 case M_PROPERTY_STEP_DOWN: {
1653 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1654 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1655 int step = (step_all > 0) ? 1 : -1;
1656 int max_sub_pos_for_source = -1;
1657 if (!is_cur_source)
1658 mpctx->global_sub_pos = -1;
1659 while (step_all) {
1660 if (mpctx->global_sub_pos == -1) {
1661 if (step > 0)
1662 mpctx->global_sub_pos = offset;
1663 else if (max_sub_pos_for_source == -1) {
1664 // Find max pos for specific source
1665 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1666 while (mpctx->global_sub_pos >= 0
1667 && sub_source(mpctx) != source)
1668 --mpctx->global_sub_pos;
1670 else
1671 mpctx->global_sub_pos = max_sub_pos_for_source;
1673 else {
1674 mpctx->global_sub_pos += step;
1675 if (mpctx->global_sub_pos < offset ||
1676 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1677 sub_source(mpctx) != source)
1678 mpctx->global_sub_pos = -1;
1680 step_all -= step;
1682 break;
1684 default:
1685 return M_PROPERTY_NOT_IMPLEMENTED;
1687 --mpctx->global_sub_pos;
1688 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1691 /// Subtitle delay (RW)
1692 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1693 MPContext * mpctx)
1695 if (!mpctx->sh_video)
1696 return M_PROPERTY_UNAVAILABLE;
1697 return m_property_delay(prop, action, arg, &sub_delay);
1700 /// Alignment of text subtitles (RW)
1701 static int mp_property_sub_alignment(m_option_t * prop, int action,
1702 void *arg, MPContext * mpctx)
1704 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1706 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1707 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1708 return M_PROPERTY_UNAVAILABLE;
1710 switch (action) {
1711 case M_PROPERTY_PRINT:
1712 if (!arg)
1713 return M_PROPERTY_ERROR;
1714 M_PROPERTY_CLAMP(prop, sub_alignment);
1715 *(char **) arg = strdup(name[sub_alignment]);
1716 return M_PROPERTY_OK;
1717 case M_PROPERTY_SET:
1718 if (!arg)
1719 return M_PROPERTY_ERROR;
1720 case M_PROPERTY_STEP_UP:
1721 case M_PROPERTY_STEP_DOWN:
1722 vo_osd_changed(OSDTYPE_SUBTITLE);
1723 default:
1724 return m_property_choice(prop, action, arg, &sub_alignment);
1728 /// Subtitle visibility (RW)
1729 static int mp_property_sub_visibility(m_option_t * prop, int action,
1730 void *arg, MPContext * mpctx)
1732 if (!mpctx->sh_video)
1733 return M_PROPERTY_UNAVAILABLE;
1735 switch (action) {
1736 case M_PROPERTY_SET:
1737 if (!arg)
1738 return M_PROPERTY_ERROR;
1739 case M_PROPERTY_STEP_UP:
1740 case M_PROPERTY_STEP_DOWN:
1741 vo_osd_changed(OSDTYPE_SUBTITLE);
1742 if (vo_spudec)
1743 vo_osd_changed(OSDTYPE_SPU);
1744 default:
1745 return m_property_flag(prop, action, arg, &sub_visibility);
1749 #ifdef CONFIG_ASS
1750 /// Use margins for libass subtitles (RW)
1751 static int mp_property_ass_use_margins(m_option_t * prop, int action,
1752 void *arg, MPContext * mpctx)
1754 if (!mpctx->sh_video)
1755 return M_PROPERTY_UNAVAILABLE;
1757 switch (action) {
1758 case M_PROPERTY_SET:
1759 if (!arg)
1760 return M_PROPERTY_ERROR;
1761 case M_PROPERTY_STEP_UP:
1762 case M_PROPERTY_STEP_DOWN:
1763 ass_force_reload = 1;
1764 default:
1765 return m_property_flag(prop, action, arg, &ass_use_margins);
1768 #endif
1770 /// Show only forced subtitles (RW)
1771 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1772 void *arg, MPContext * mpctx)
1774 if (!vo_spudec)
1775 return M_PROPERTY_UNAVAILABLE;
1777 switch (action) {
1778 case M_PROPERTY_SET:
1779 if (!arg)
1780 return M_PROPERTY_ERROR;
1781 case M_PROPERTY_STEP_UP:
1782 case M_PROPERTY_STEP_DOWN:
1783 m_property_flag(prop, action, arg, &forced_subs_only);
1784 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1785 return M_PROPERTY_OK;
1786 default:
1787 return m_property_flag(prop, action, arg, &forced_subs_only);
1792 #ifdef CONFIG_FREETYPE
1793 /// Subtitle scale (RW)
1794 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1795 MPContext * mpctx)
1798 switch (action) {
1799 case M_PROPERTY_SET:
1800 if (!arg)
1801 return M_PROPERTY_ERROR;
1802 M_PROPERTY_CLAMP(prop, *(float *) arg);
1803 #ifdef CONFIG_ASS
1804 if (ass_enabled) {
1805 ass_font_scale = *(float *) arg;
1806 ass_force_reload = 1;
1808 #endif
1809 text_font_scale_factor = *(float *) arg;
1810 force_load_font = 1;
1811 return M_PROPERTY_OK;
1812 case M_PROPERTY_STEP_UP:
1813 case M_PROPERTY_STEP_DOWN:
1814 #ifdef CONFIG_ASS
1815 if (ass_enabled) {
1816 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1817 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1818 M_PROPERTY_CLAMP(prop, ass_font_scale);
1819 ass_force_reload = 1;
1821 #endif
1822 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1823 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1824 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1825 force_load_font = 1;
1826 return M_PROPERTY_OK;
1827 default:
1828 #ifdef CONFIG_ASS
1829 if (ass_enabled)
1830 return m_property_float_ro(prop, action, arg, ass_font_scale);
1831 else
1832 #endif
1833 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1836 #endif
1838 ///@}
1840 /// \defgroup TVProperties TV properties
1841 /// \ingroup Properties
1842 ///@{
1844 #ifdef CONFIG_TV
1846 /// TV color settings (RW)
1847 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1848 MPContext * mpctx)
1850 int r, val;
1851 tvi_handle_t *tvh = mpctx->demuxer->priv;
1852 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1853 return M_PROPERTY_UNAVAILABLE;
1855 switch (action) {
1856 case M_PROPERTY_SET:
1857 if (!arg)
1858 return M_PROPERTY_ERROR;
1859 M_PROPERTY_CLAMP(prop, *(int *) arg);
1860 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1861 case M_PROPERTY_GET:
1862 return tv_get_color_options(tvh, (int) prop->priv, arg);
1863 case M_PROPERTY_STEP_UP:
1864 case M_PROPERTY_STEP_DOWN:
1865 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1866 if (!r)
1867 return M_PROPERTY_ERROR;
1868 val += (arg ? *(int *) arg : 1) *
1869 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1870 M_PROPERTY_CLAMP(prop, val);
1871 return tv_set_color_options(tvh, (int) prop->priv, val);
1873 return M_PROPERTY_ERROR;
1875 return M_PROPERTY_NOT_IMPLEMENTED;
1878 #endif
1880 #ifdef CONFIG_TV_TELETEXT
1881 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1882 MPContext * mpctx)
1884 int val,result;
1885 int base_ioctl=(int)prop->priv;
1887 for teletext's GET,SET,STEP ioctls this is not 0
1888 SET is GET+1
1889 STEP is GET+2
1891 tvi_handle_t *tvh = mpctx->demuxer->priv;
1892 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1893 return M_PROPERTY_UNAVAILABLE;
1894 if(!base_ioctl)
1895 return M_PROPERTY_ERROR;
1897 switch (action) {
1898 case M_PROPERTY_GET:
1899 if (!arg)
1900 return M_PROPERTY_ERROR;
1901 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1902 break;
1903 case M_PROPERTY_SET:
1904 if (!arg)
1905 return M_PROPERTY_ERROR;
1906 M_PROPERTY_CLAMP(prop, *(int *) arg);
1907 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1908 break;
1909 case M_PROPERTY_STEP_UP:
1910 case M_PROPERTY_STEP_DOWN:
1911 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1912 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1913 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1914 break;
1915 default:
1916 return M_PROPERTY_NOT_IMPLEMENTED;
1919 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1922 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1923 MPContext * mpctx)
1925 tvi_handle_t *tvh = mpctx->demuxer->priv;
1926 int result;
1927 int val;
1929 //with tvh==NULL will fail too
1930 result=mp_property_teletext_common(prop,action,arg,mpctx);
1931 if(result!=M_PROPERTY_OK)
1932 return result;
1934 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1935 mp_input_set_section("teletext");
1936 else
1937 mp_input_set_section("tv");
1938 return M_PROPERTY_OK;
1941 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1942 MPContext * mpctx)
1944 tvi_handle_t *tvh = mpctx->demuxer->priv;
1945 int result;
1946 int val;
1947 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1948 return M_PROPERTY_UNAVAILABLE;
1949 switch(action){
1950 case M_PROPERTY_STEP_UP:
1951 case M_PROPERTY_STEP_DOWN:
1952 //This should be handled separately
1953 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1954 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1955 break;
1956 default:
1957 result=mp_property_teletext_common(prop,action,arg,mpctx);
1959 return result;
1963 #endif /* CONFIG_TV_TELETEXT */
1965 ///@}
1967 /// All properties available in MPlayer.
1968 /** \ingroup Properties
1970 static const m_option_t mp_properties[] = {
1971 // General
1972 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1973 M_OPT_RANGE, 0, 3, NULL },
1974 { "loop", mp_property_loop, CONF_TYPE_INT,
1975 M_OPT_MIN, -1, 0, NULL },
1976 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1977 M_OPT_RANGE, 0.01, 100.0, NULL },
1978 { "filename", mp_property_filename, CONF_TYPE_STRING,
1979 0, 0, 0, NULL },
1980 { "path", mp_property_path, CONF_TYPE_STRING,
1981 0, 0, 0, NULL },
1982 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1983 0, 0, 0, NULL },
1984 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1985 M_OPT_MIN, 0, 0, NULL },
1986 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1987 M_OPT_MIN, 0, 0, NULL },
1988 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1989 M_OPT_MIN, 0, 0, NULL },
1990 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1991 M_OPT_MIN, 0, 0, NULL },
1992 { "length", mp_property_length, CONF_TYPE_TIME,
1993 M_OPT_MIN, 0, 0, NULL },
1994 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1995 M_OPT_RANGE, 0, 100, NULL },
1996 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1997 M_OPT_MIN, 0, 0, NULL },
1998 { "chapter", mp_property_chapter, CONF_TYPE_INT,
1999 M_OPT_MIN, 0, 0, NULL },
2000 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2001 0, 0, 0, NULL },
2002 { "angle", mp_property_angle, CONF_TYPE_INT,
2003 CONF_RANGE, -2, 10, NULL },
2004 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2005 0, 0, 0, NULL },
2006 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2007 M_OPT_RANGE, 0, 1, NULL },
2009 // Audio
2010 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2011 M_OPT_RANGE, 0, 100, NULL },
2012 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2013 M_OPT_RANGE, 0, 1, NULL },
2014 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2015 M_OPT_RANGE, -100, 100, NULL },
2016 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2017 0, 0, 0, NULL },
2018 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2019 0, 0, 0, NULL },
2020 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2021 0, 0, 0, NULL },
2022 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2023 0, 0, 0, NULL },
2024 { "channels", mp_property_channels, CONF_TYPE_INT,
2025 0, 0, 0, NULL },
2026 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2027 CONF_RANGE, -2, 65535, NULL },
2028 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2029 M_OPT_RANGE, -1, 1, NULL },
2031 // Video
2032 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2033 M_OPT_RANGE, 0, 1, NULL },
2034 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2035 M_OPT_RANGE, 0, 1, NULL },
2036 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2037 M_OPT_RANGE, 0, 1, NULL },
2038 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2039 M_OPT_RANGE, 0, 1, NULL },
2040 { "border", mp_property_border, CONF_TYPE_FLAG,
2041 M_OPT_RANGE, 0, 1, NULL },
2042 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2043 M_OPT_RANGE, 0, 2, NULL },
2044 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2045 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2046 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2047 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2048 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2049 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2050 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2051 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2052 { "hue", mp_property_gamma, CONF_TYPE_INT,
2053 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2054 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2055 M_OPT_RANGE, 0, 1, NULL },
2056 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2057 M_OPT_RANGE, 0, 1, NULL },
2058 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2059 0, 0, 0, NULL },
2060 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2061 0, 0, 0, NULL },
2062 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2063 0, 0, 0, NULL },
2064 { "width", mp_property_width, CONF_TYPE_INT,
2065 0, 0, 0, NULL },
2066 { "height", mp_property_height, CONF_TYPE_INT,
2067 0, 0, 0, NULL },
2068 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2069 0, 0, 0, NULL },
2070 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2071 0, 0, 0, NULL },
2072 { "switch_video", mp_property_video, CONF_TYPE_INT,
2073 CONF_RANGE, -2, 65535, NULL },
2074 { "switch_program", mp_property_program, CONF_TYPE_INT,
2075 CONF_RANGE, -1, 65535, NULL },
2077 // Subs
2078 { "sub", mp_property_sub, CONF_TYPE_INT,
2079 M_OPT_MIN, -1, 0, NULL },
2080 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2081 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2082 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2083 M_OPT_MIN, -1, 0, NULL },
2084 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2085 M_OPT_MIN, -1, 0, NULL },
2086 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2087 M_OPT_MIN, -1, 0, NULL },
2088 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2089 0, 0, 0, NULL },
2090 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2091 M_OPT_RANGE, 0, 100, NULL },
2092 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2093 M_OPT_RANGE, 0, 2, NULL },
2094 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2095 M_OPT_RANGE, 0, 1, NULL },
2096 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2097 M_OPT_RANGE, 0, 1, NULL },
2098 #ifdef CONFIG_FREETYPE
2099 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2100 M_OPT_RANGE, 0, 100, NULL },
2101 #endif
2102 #ifdef CONFIG_ASS
2103 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2104 M_OPT_RANGE, 0, 1, NULL },
2105 #endif
2107 #ifdef CONFIG_TV
2108 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2109 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2110 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2111 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2112 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2113 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2114 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2115 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2116 #endif
2118 #ifdef CONFIG_TV_TELETEXT
2119 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2120 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2121 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2122 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2123 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2124 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2125 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2126 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2127 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2128 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2129 #endif
2131 { NULL, NULL, NULL, 0, 0, 0, NULL }
2135 int mp_property_do(const char *name, int action, void *val, void *ctx)
2137 return m_property_do(mp_properties, name, action, val, ctx);
2140 char* mp_property_print(const char *name, void* ctx)
2142 char* ret = NULL;
2143 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2144 return NULL;
2145 return ret;
2148 char *property_expand_string(MPContext * mpctx, char *str)
2150 return m_properties_expand_string(mp_properties, str, mpctx);
2153 void property_print_help(void)
2155 m_properties_print_help_list(mp_properties);
2159 ///@}
2160 // Properties group
2164 * \defgroup Command2Property Command to property bridge
2166 * It is used to handle most commands that just set a property
2167 * and optionally display something on the OSD.
2168 * Two kinds of commands are handled: adjust or toggle.
2170 * Adjust commands take 1 or 2 parameters: <value> <abs>
2171 * If <abs> is non-zero the property is set to the given value
2172 * otherwise it is adjusted.
2174 * Toggle commands take 0 or 1 parameters. With no parameter
2175 * or a value less than the property minimum it just steps the
2176 * property to its next value. Otherwise it sets it to the given
2177 * value.
2182 /// List of the commands that can be handled by setting a property.
2183 static struct {
2184 /// property name
2185 const char *name;
2186 /// cmd id
2187 int cmd;
2188 /// set/adjust or toggle command
2189 int toggle;
2190 /// progressbar type
2191 int osd_progbar;
2192 /// osd msg id if it must be shared
2193 int osd_id;
2194 /// osd msg template
2195 const char *osd_msg;
2196 } set_prop_cmd[] = {
2197 // general
2198 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2199 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2200 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2201 // audio
2202 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2203 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2204 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2205 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2206 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2207 // video
2208 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2209 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2210 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2211 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2212 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2213 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2214 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2215 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2216 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2217 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2218 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2219 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2220 // subs
2221 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2222 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2223 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2224 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2225 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2226 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2227 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2228 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2229 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2230 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2231 #ifdef CONFIG_FREETYPE
2232 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2233 #endif
2234 #ifdef CONFIG_ASS
2235 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2236 #endif
2237 #ifdef CONFIG_TV
2238 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2239 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2240 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2241 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2242 #endif
2243 { NULL, 0, 0, 0, -1, NULL }
2247 /// Handle commands that set a property.
2248 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
2250 int i, r;
2251 m_option_t* prop;
2252 const char *pname;
2254 // look for the command
2255 for (i = 0; set_prop_cmd[i].name; i++)
2256 if (set_prop_cmd[i].cmd == cmd->id)
2257 break;
2258 if (!(pname = set_prop_cmd[i].name))
2259 return 0;
2261 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2262 return 0;
2264 // toggle command
2265 if (set_prop_cmd[i].toggle) {
2266 // set to value
2267 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2268 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2269 else
2270 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2271 } else if (cmd->args[1].v.i) //set
2272 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2273 else // adjust
2274 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2276 if (r <= 0)
2277 return 1;
2279 if (set_prop_cmd[i].osd_progbar) {
2280 if (prop->type == CONF_TYPE_INT) {
2281 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2282 set_osd_bar(set_prop_cmd[i].osd_progbar,
2283 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2284 } else if (prop->type == CONF_TYPE_FLOAT) {
2285 float f;
2286 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2287 set_osd_bar(set_prop_cmd[i].osd_progbar,
2288 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2289 } else
2290 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2291 "Property use an unsupported type.\n");
2292 return 1;
2295 if (set_prop_cmd[i].osd_msg) {
2296 char *val = mp_property_print(pname, mpctx);
2297 if (val) {
2298 set_osd_msg(set_prop_cmd[i].osd_id >=
2299 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2300 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2301 free(val);
2304 return 1;
2307 #ifdef CONFIG_DVDNAV
2308 static const struct {
2309 const char *name;
2310 const mp_command_type cmd;
2311 } mp_dvdnav_bindings[] = {
2312 { "up", MP_CMD_DVDNAV_UP },
2313 { "down", MP_CMD_DVDNAV_DOWN },
2314 { "left", MP_CMD_DVDNAV_LEFT },
2315 { "right", MP_CMD_DVDNAV_RIGHT },
2316 { "menu", MP_CMD_DVDNAV_MENU },
2317 { "select", MP_CMD_DVDNAV_SELECT },
2318 { "prev", MP_CMD_DVDNAV_PREVMENU },
2319 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2322 * keep old dvdnav sub-command options for a while in order not to
2323 * break slave-mode API too suddenly.
2325 { "1", MP_CMD_DVDNAV_UP },
2326 { "2", MP_CMD_DVDNAV_DOWN },
2327 { "3", MP_CMD_DVDNAV_LEFT },
2328 { "4", MP_CMD_DVDNAV_RIGHT },
2329 { "5", MP_CMD_DVDNAV_MENU },
2330 { "6", MP_CMD_DVDNAV_SELECT },
2331 { "7", MP_CMD_DVDNAV_PREVMENU },
2332 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2333 { NULL, 0 }
2335 #endif
2337 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
2339 sh_audio_t * const sh_audio = mpctx->sh_audio;
2340 sh_video_t * const sh_video = mpctx->sh_video;
2341 int brk_cmd = 0;
2342 if (!set_property_command(mpctx, cmd))
2343 switch (cmd->id) {
2344 case MP_CMD_SEEK:{
2345 float v;
2346 int abs;
2347 if (sh_video)
2348 mpctx->osd_show_percentage = sh_video->fps;
2349 v = cmd->args[0].v.f;
2350 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2351 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2352 abs_seek_pos = SEEK_ABSOLUTE;
2353 if (sh_video)
2354 mpctx->osd_function =
2355 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2356 rel_seek_secs = v;
2357 } else if (abs) { /* Absolute seek by percentage */
2358 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2359 if (sh_video)
2360 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2361 rel_seek_secs = v / 100.0;
2362 } else {
2363 rel_seek_secs += v;
2364 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2366 brk_cmd = 1;
2368 break;
2370 case MP_CMD_SET_PROPERTY:{
2371 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2372 cmd->args[1].v.s, mpctx);
2373 if (r == M_PROPERTY_UNKNOWN)
2374 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2375 "Unknown property: '%s'\n", cmd->args[0].v.s);
2376 else if (r <= 0)
2377 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2378 "Failed to set property '%s' to '%s'.\n",
2379 cmd->args[0].v.s, cmd->args[1].v.s);
2381 break;
2383 case MP_CMD_STEP_PROPERTY:{
2384 void* arg = NULL;
2385 int r,i;
2386 double d;
2387 off_t o;
2388 if (cmd->args[1].v.f) {
2389 m_option_t* prop;
2390 if((r = mp_property_do(cmd->args[0].v.s,
2391 M_PROPERTY_GET_TYPE,
2392 &prop, mpctx)) <= 0)
2393 goto step_prop_err;
2394 if(prop->type == CONF_TYPE_INT ||
2395 prop->type == CONF_TYPE_FLAG)
2396 i = cmd->args[1].v.f, arg = &i;
2397 else if(prop->type == CONF_TYPE_FLOAT)
2398 arg = &cmd->args[1].v.f;
2399 else if(prop->type == CONF_TYPE_DOUBLE ||
2400 prop->type == CONF_TYPE_TIME)
2401 d = cmd->args[1].v.f, arg = &d;
2402 else if(prop->type == CONF_TYPE_POSITION)
2403 o = cmd->args[1].v.f, arg = &o;
2404 else
2405 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2406 "Ignoring step size stepping property '%s'.\n",
2407 cmd->args[0].v.s);
2409 r = mp_property_do(cmd->args[0].v.s,
2410 cmd->args[2].v.i < 0 ?
2411 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2412 arg, mpctx);
2413 step_prop_err:
2414 if (r == M_PROPERTY_UNKNOWN)
2415 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2416 "Unknown property: '%s'\n", cmd->args[0].v.s);
2417 else if (r <= 0)
2418 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2419 "Failed to increment property '%s' by %f.\n",
2420 cmd->args[0].v.s, cmd->args[1].v.f);
2422 break;
2424 case MP_CMD_GET_PROPERTY:{
2425 char *tmp;
2426 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2427 &tmp, mpctx) <= 0) {
2428 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2429 "Failed to get value of property '%s'.\n",
2430 cmd->args[0].v.s);
2431 break;
2433 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2434 cmd->args[0].v.s, tmp);
2435 free(tmp);
2437 break;
2439 case MP_CMD_EDL_MARK:
2440 if (edl_fd) {
2441 float v = sh_video ? sh_video->pts :
2442 playing_audio_pts(sh_audio, mpctx->d_audio,
2443 mpctx->audio_out);
2445 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2446 mpctx->begin_skip = v;
2447 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2448 } else {
2449 if (mpctx->begin_skip > v)
2450 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2451 else {
2452 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2453 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2455 mpctx->begin_skip = MP_NOPTS_VALUE;
2458 break;
2460 case MP_CMD_SWITCH_RATIO:
2461 if (!sh_video)
2462 break;
2463 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2464 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2465 else
2466 movie_aspect = cmd->args[0].v.f;
2467 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2468 break;
2470 case MP_CMD_SPEED_INCR:{
2471 float v = cmd->args[0].v.f;
2472 playback_speed += v;
2473 build_afilter_chain(sh_audio, &ao_data);
2474 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2475 playback_speed);
2476 } break;
2478 case MP_CMD_SPEED_MULT:{
2479 float v = cmd->args[0].v.f;
2480 playback_speed *= v;
2481 build_afilter_chain(sh_audio, &ao_data);
2482 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2483 playback_speed);
2484 } break;
2486 case MP_CMD_SPEED_SET:{
2487 float v = cmd->args[0].v.f;
2488 playback_speed = v;
2489 build_afilter_chain(sh_audio, &ao_data);
2490 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2491 playback_speed);
2492 } break;
2494 case MP_CMD_FRAME_STEP:
2495 case MP_CMD_PAUSE:
2496 cmd->pausing = 1;
2497 brk_cmd = 1;
2498 break;
2500 case MP_CMD_FILE_FILTER:
2501 file_filter = cmd->args[0].v.i;
2502 break;
2504 case MP_CMD_QUIT:
2505 exit_player_with_rc(EXIT_QUIT,
2506 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2508 case MP_CMD_PLAY_TREE_STEP:{
2509 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2510 int force = cmd->args[1].v.i;
2512 #ifdef CONFIG_GUI
2513 if (use_gui) {
2514 int i = 0;
2515 if (n > 0)
2516 for (i = 0; i < n; i++)
2517 mplNext();
2518 else
2519 for (i = 0; i < -1 * n; i++)
2520 mplPrev();
2521 } else
2522 #endif
2524 if (!force && mpctx->playtree_iter) {
2525 play_tree_iter_t *i =
2526 play_tree_iter_new_copy(mpctx->playtree_iter);
2527 if (play_tree_iter_step(i, n, 0) ==
2528 PLAY_TREE_ITER_ENTRY)
2529 mpctx->eof =
2530 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2531 play_tree_iter_free(i);
2532 } else
2533 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2534 if (mpctx->eof)
2535 mpctx->play_tree_step = n;
2536 brk_cmd = 1;
2539 break;
2541 case MP_CMD_PLAY_TREE_UP_STEP:{
2542 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2543 int force = cmd->args[1].v.i;
2545 if (!force && mpctx->playtree_iter) {
2546 play_tree_iter_t *i =
2547 play_tree_iter_new_copy(mpctx->playtree_iter);
2548 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2549 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2550 play_tree_iter_free(i);
2551 } else
2552 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2553 brk_cmd = 1;
2555 break;
2557 case MP_CMD_PLAY_ALT_SRC_STEP:
2558 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2559 int v = cmd->args[0].v.i;
2560 if (v > 0
2561 && mpctx->playtree_iter->file <
2562 mpctx->playtree_iter->num_files)
2563 mpctx->eof = PT_NEXT_SRC;
2564 else if (v < 0 && mpctx->playtree_iter->file > 1)
2565 mpctx->eof = PT_PREV_SRC;
2567 brk_cmd = 1;
2568 break;
2570 case MP_CMD_SUB_STEP:
2571 if (sh_video) {
2572 int movement = cmd->args[0].v.i;
2573 step_sub(subdata, sh_video->pts, movement);
2574 #ifdef CONFIG_ASS
2575 if (ass_track)
2576 sub_delay +=
2577 ass_step_sub(ass_track,
2578 (sh_video->pts +
2579 sub_delay) * 1000 + .5, movement) / 1000.;
2580 #endif
2581 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2582 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2584 break;
2586 case MP_CMD_SUB_LOG:
2587 log_sub();
2588 break;
2590 case MP_CMD_OSD:{
2591 int v = cmd->args[0].v.i;
2592 int max = (term_osd
2593 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2594 if (osd_level > max)
2595 osd_level = max;
2596 if (v < 0)
2597 osd_level = (osd_level + 1) % (max + 1);
2598 else
2599 osd_level = v > max ? max : v;
2600 /* Show OSD state when disabled, but not when an explicit
2601 argument is given to the OSD command, i.e. in slave mode. */
2602 if (v == -1 && osd_level <= 1)
2603 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2604 MSGTR_OSDosd,
2605 osd_level ? MSGTR_OSDenabled :
2606 MSGTR_OSDdisabled);
2607 else
2608 rm_osd_msg(OSD_MSG_OSD_STATUS);
2610 break;
2612 case MP_CMD_OSD_SHOW_TEXT:
2613 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2614 (cmd->args[1].v.i <
2615 0 ? osd_duration : cmd->args[1].v.i),
2616 "%-.63s", cmd->args[0].v.s);
2617 break;
2619 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2620 char *txt = m_properties_expand_string(mp_properties,
2621 cmd->args[0].v.s,
2622 mpctx);
2623 /* if no argument supplied take default osd_duration, else <arg> ms. */
2624 if (txt) {
2625 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2626 (cmd->args[1].v.i <
2627 0 ? osd_duration : cmd->args[1].v.i),
2628 "%-.63s", txt);
2629 free(txt);
2632 break;
2634 case MP_CMD_LOADFILE:{
2635 play_tree_t *e = play_tree_new();
2636 play_tree_add_file(e, cmd->args[0].v.s);
2638 if (cmd->args[1].v.i) // append
2639 play_tree_append_entry(mpctx->playtree->child, e);
2640 else {
2641 // Go back to the starting point.
2642 while (play_tree_iter_up_step
2643 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2644 /* NOP */ ;
2645 play_tree_free_list(mpctx->playtree->child, 1);
2646 play_tree_set_child(mpctx->playtree, e);
2647 pt_iter_goto_head(mpctx->playtree_iter);
2648 mpctx->eof = PT_NEXT_SRC;
2650 brk_cmd = 1;
2652 break;
2654 case MP_CMD_LOADLIST:{
2655 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2656 if (!e)
2657 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2658 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2659 else {
2660 if (cmd->args[1].v.i) // append
2661 play_tree_append_entry(mpctx->playtree->child, e);
2662 else {
2663 // Go back to the starting point.
2664 while (play_tree_iter_up_step
2665 (mpctx->playtree_iter, 0, 1)
2666 != PLAY_TREE_ITER_END)
2667 /* NOP */ ;
2668 play_tree_free_list(mpctx->playtree->child, 1);
2669 play_tree_set_child(mpctx->playtree, e);
2670 pt_iter_goto_head(mpctx->playtree_iter);
2671 mpctx->eof = PT_NEXT_SRC;
2674 brk_cmd = 1;
2676 break;
2678 case MP_CMD_STOP:
2679 // Go back to the starting point.
2680 while (play_tree_iter_up_step
2681 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2682 /* NOP */ ;
2683 mpctx->eof = PT_STOP;
2684 brk_cmd = 1;
2685 break;
2687 #ifdef CONFIG_RADIO
2688 case MP_CMD_RADIO_STEP_CHANNEL:
2689 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2690 int v = cmd->args[0].v.i;
2691 if (v > 0)
2692 radio_step_channel(mpctx->demuxer->stream,
2693 RADIO_CHANNEL_HIGHER);
2694 else
2695 radio_step_channel(mpctx->demuxer->stream,
2696 RADIO_CHANNEL_LOWER);
2697 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2698 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2699 MSGTR_OSDChannel,
2700 radio_get_channel_name(mpctx->demuxer->stream));
2703 break;
2705 case MP_CMD_RADIO_SET_CHANNEL:
2706 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2707 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2708 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2709 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2710 MSGTR_OSDChannel,
2711 radio_get_channel_name(mpctx->demuxer->stream));
2714 break;
2716 case MP_CMD_RADIO_SET_FREQ:
2717 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2718 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2719 break;
2721 case MP_CMD_RADIO_STEP_FREQ:
2722 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2723 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2724 break;
2725 #endif
2727 #ifdef CONFIG_TV
2728 case MP_CMD_TV_START_SCAN:
2729 if (mpctx->file_format == DEMUXER_TYPE_TV)
2730 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2731 break;
2732 case MP_CMD_TV_SET_FREQ:
2733 if (mpctx->file_format == DEMUXER_TYPE_TV)
2734 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2735 cmd->args[0].v.f * 16.0);
2736 #ifdef CONFIG_PVR
2737 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2738 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2739 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2740 pvr_get_current_channelname (mpctx->stream),
2741 pvr_get_current_stationname (mpctx->stream));
2743 #endif /* CONFIG_PVR */
2744 break;
2746 case MP_CMD_TV_STEP_FREQ:
2747 if (mpctx->file_format == DEMUXER_TYPE_TV)
2748 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2749 cmd->args[0].v.f * 16.0);
2750 #ifdef CONFIG_PVR
2751 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2752 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2753 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2754 pvr_get_current_channelname (mpctx->stream),
2755 pvr_get_current_frequency (mpctx->stream));
2757 #endif /* CONFIG_PVR */
2758 break;
2760 case MP_CMD_TV_SET_NORM:
2761 if (mpctx->file_format == DEMUXER_TYPE_TV)
2762 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2763 cmd->args[0].v.s);
2764 break;
2766 case MP_CMD_TV_STEP_CHANNEL:{
2767 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2768 int v = cmd->args[0].v.i;
2769 if (v > 0) {
2770 tv_step_channel((tvi_handle_t *) (mpctx->
2771 demuxer->priv),
2772 TV_CHANNEL_HIGHER);
2773 } else {
2774 tv_step_channel((tvi_handle_t *) (mpctx->
2775 demuxer->priv),
2776 TV_CHANNEL_LOWER);
2778 if (tv_channel_list) {
2779 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2780 MSGTR_OSDChannel, tv_channel_current->name);
2781 //vo_osd_changed(OSDTYPE_SUBTITLE);
2784 #ifdef CONFIG_PVR
2785 else if (mpctx->stream &&
2786 mpctx->stream->type == STREAMTYPE_PVR) {
2787 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2788 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2789 pvr_get_current_channelname (mpctx->stream),
2790 pvr_get_current_stationname (mpctx->stream));
2792 #endif /* CONFIG_PVR */
2794 #ifdef CONFIG_DVBIN
2795 if (mpctx->stream->type == STREAMTYPE_DVB) {
2796 int dir;
2797 int v = cmd->args[0].v.i;
2799 mpctx->last_dvb_step = v;
2800 if (v > 0)
2801 dir = DVB_CHANNEL_HIGHER;
2802 else
2803 dir = DVB_CHANNEL_LOWER;
2806 if (dvb_step_channel(mpctx->stream, dir))
2807 mpctx->eof = mpctx->dvbin_reopen = 1;
2809 #endif /* CONFIG_DVBIN */
2810 break;
2812 case MP_CMD_TV_SET_CHANNEL:
2813 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2814 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2815 cmd->args[0].v.s);
2816 if (tv_channel_list) {
2817 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2818 MSGTR_OSDChannel, tv_channel_current->name);
2819 //vo_osd_changed(OSDTYPE_SUBTITLE);
2822 #ifdef CONFIG_PVR
2823 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2824 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2825 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2826 pvr_get_current_channelname (mpctx->stream),
2827 pvr_get_current_stationname (mpctx->stream));
2829 #endif /* CONFIG_PVR */
2830 break;
2832 #ifdef CONFIG_DVBIN
2833 case MP_CMD_DVB_SET_CHANNEL:
2834 if (mpctx->stream->type == STREAMTYPE_DVB) {
2835 mpctx->last_dvb_step = 1;
2837 if (dvb_set_channel
2838 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2839 mpctx->eof = mpctx->dvbin_reopen = 1;
2841 break;
2842 #endif /* CONFIG_DVBIN */
2844 case MP_CMD_TV_LAST_CHANNEL:
2845 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2846 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2847 if (tv_channel_list) {
2848 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2849 MSGTR_OSDChannel, tv_channel_current->name);
2850 //vo_osd_changed(OSDTYPE_SUBTITLE);
2853 #ifdef CONFIG_PVR
2854 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2855 pvr_set_lastchannel (mpctx->stream);
2856 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2857 pvr_get_current_channelname (mpctx->stream),
2858 pvr_get_current_stationname (mpctx->stream));
2860 #endif /* CONFIG_PVR */
2861 break;
2863 case MP_CMD_TV_STEP_NORM:
2864 if (mpctx->file_format == DEMUXER_TYPE_TV)
2865 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2866 break;
2868 case MP_CMD_TV_STEP_CHANNEL_LIST:
2869 if (mpctx->file_format == DEMUXER_TYPE_TV)
2870 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2871 break;
2872 #ifdef CONFIG_TV_TELETEXT
2873 case MP_CMD_TV_TELETEXT_ADD_DEC:
2875 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2876 if (mpctx->file_format == DEMUXER_TYPE_TV)
2877 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2878 break;
2880 case MP_CMD_TV_TELETEXT_GO_LINK:
2882 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2883 if (mpctx->file_format == DEMUXER_TYPE_TV)
2884 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2885 break;
2887 #endif /* CONFIG_TV_TELETEXT */
2888 #endif /* CONFIG_TV */
2890 case MP_CMD_SUB_LOAD:
2891 if (sh_video) {
2892 int n = mpctx->set_of_sub_size;
2893 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2894 if (n != mpctx->set_of_sub_size) {
2895 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2896 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2897 mpctx->global_sub_size;
2898 ++mpctx->global_sub_size;
2901 break;
2903 case MP_CMD_SUB_REMOVE:
2904 if (sh_video) {
2905 int v = cmd->args[0].v.i;
2906 sub_data *subd;
2907 if (v < 0) {
2908 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2909 subd = mpctx->set_of_subtitles[v];
2910 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2911 MSGTR_RemovedSubtitleFile, v + 1,
2912 filename_recode(subd->filename));
2913 sub_free(subd);
2914 mpctx->set_of_subtitles[v] = NULL;
2916 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2917 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2918 mpctx->set_of_sub_size = 0;
2919 if (mpctx->set_of_sub_pos >= 0) {
2920 mpctx->global_sub_pos = -2;
2921 subdata = NULL;
2922 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2924 } else if (v < mpctx->set_of_sub_size) {
2925 subd = mpctx->set_of_subtitles[v];
2926 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2927 MSGTR_RemovedSubtitleFile, v + 1,
2928 filename_recode(subd->filename));
2929 sub_free(subd);
2930 if (mpctx->set_of_sub_pos == v) {
2931 mpctx->global_sub_pos = -2;
2932 subdata = NULL;
2933 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2934 } else if (mpctx->set_of_sub_pos > v) {
2935 --mpctx->set_of_sub_pos;
2936 --mpctx->global_sub_pos;
2938 while (++v < mpctx->set_of_sub_size)
2939 mpctx->set_of_subtitles[v - 1] =
2940 mpctx->set_of_subtitles[v];
2941 --mpctx->set_of_sub_size;
2942 --mpctx->global_sub_size;
2943 if (mpctx->set_of_sub_size <= 0)
2944 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2945 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2948 break;
2950 case MP_CMD_GET_SUB_VISIBILITY:
2951 if (sh_video) {
2952 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2953 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2955 break;
2957 case MP_CMD_SCREENSHOT:
2958 if (vo_config_count) {
2959 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2960 if (CONTROL_OK !=
2961 ((vf_instance_t *) sh_video->vfilter)->
2962 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2963 &cmd->args[0].v.i))
2964 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2966 break;
2968 case MP_CMD_VF_CHANGE_RECTANGLE:
2969 if (!sh_video)
2970 break;
2971 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2972 break;
2974 case MP_CMD_GET_TIME_LENGTH:{
2975 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2976 demuxer_get_time_length(mpctx->demuxer));
2978 break;
2980 case MP_CMD_GET_FILENAME:{
2981 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2982 get_metadata(META_NAME));
2984 break;
2986 case MP_CMD_GET_VIDEO_CODEC:{
2987 char *inf = get_metadata(META_VIDEO_CODEC);
2988 if (!inf)
2989 inf = strdup("");
2990 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2991 free(inf);
2993 break;
2995 case MP_CMD_GET_VIDEO_BITRATE:{
2996 char *inf = get_metadata(META_VIDEO_BITRATE);
2997 if (!inf)
2998 inf = strdup("");
2999 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3000 free(inf);
3002 break;
3004 case MP_CMD_GET_VIDEO_RESOLUTION:{
3005 char *inf = get_metadata(META_VIDEO_RESOLUTION);
3006 if (!inf)
3007 inf = strdup("");
3008 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3009 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3010 free(inf);
3012 break;
3014 case MP_CMD_GET_AUDIO_CODEC:{
3015 char *inf = get_metadata(META_AUDIO_CODEC);
3016 if (!inf)
3017 inf = strdup("");
3018 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3019 free(inf);
3021 break;
3023 case MP_CMD_GET_AUDIO_BITRATE:{
3024 char *inf = get_metadata(META_AUDIO_BITRATE);
3025 if (!inf)
3026 inf = strdup("");
3027 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3028 free(inf);
3030 break;
3032 case MP_CMD_GET_AUDIO_SAMPLES:{
3033 char *inf = get_metadata(META_AUDIO_SAMPLES);
3034 if (!inf)
3035 inf = strdup("");
3036 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3037 free(inf);
3039 break;
3041 case MP_CMD_GET_META_TITLE:{
3042 char *inf = get_metadata(META_INFO_TITLE);
3043 if (!inf)
3044 inf = strdup("");
3045 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3046 free(inf);
3048 break;
3050 case MP_CMD_GET_META_ARTIST:{
3051 char *inf = get_metadata(META_INFO_ARTIST);
3052 if (!inf)
3053 inf = strdup("");
3054 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3055 free(inf);
3057 break;
3059 case MP_CMD_GET_META_ALBUM:{
3060 char *inf = get_metadata(META_INFO_ALBUM);
3061 if (!inf)
3062 inf = strdup("");
3063 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3064 free(inf);
3066 break;
3068 case MP_CMD_GET_META_YEAR:{
3069 char *inf = get_metadata(META_INFO_YEAR);
3070 if (!inf)
3071 inf = strdup("");
3072 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3073 free(inf);
3075 break;
3077 case MP_CMD_GET_META_COMMENT:{
3078 char *inf = get_metadata(META_INFO_COMMENT);
3079 if (!inf)
3080 inf = strdup("");
3081 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3082 free(inf);
3084 break;
3086 case MP_CMD_GET_META_TRACK:{
3087 char *inf = get_metadata(META_INFO_TRACK);
3088 if (!inf)
3089 inf = strdup("");
3090 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3091 free(inf);
3093 break;
3095 case MP_CMD_GET_META_GENRE:{
3096 char *inf = get_metadata(META_INFO_GENRE);
3097 if (!inf)
3098 inf = strdup("");
3099 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3100 free(inf);
3102 break;
3104 case MP_CMD_GET_VO_FULLSCREEN:
3105 if (mpctx->video_out && vo_config_count)
3106 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3107 break;
3109 case MP_CMD_GET_PERCENT_POS:
3110 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3111 demuxer_get_percent_pos(mpctx->demuxer));
3112 break;
3114 case MP_CMD_GET_TIME_POS:{
3115 float pos = 0;
3116 if (sh_video)
3117 pos = sh_video->pts;
3118 else if (sh_audio && mpctx->audio_out)
3119 pos =
3120 playing_audio_pts(sh_audio, mpctx->d_audio,
3121 mpctx->audio_out);
3122 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3124 break;
3126 case MP_CMD_RUN:
3127 #ifndef __MINGW32__
3128 if (!fork()) {
3129 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3130 exit(0);
3132 #endif
3133 break;
3135 case MP_CMD_KEYDOWN_EVENTS:
3136 mplayer_put_key(cmd->args[0].v.i);
3137 break;
3139 case MP_CMD_SET_MOUSE_POS:{
3140 int pointer_x, pointer_y;
3141 double dx, dy;
3142 pointer_x = cmd->args[0].v.i;
3143 pointer_y = cmd->args[1].v.i;
3144 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
3145 #ifdef CONFIG_DVDNAV
3146 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3147 && dx > 0.0 && dy > 0.0) {
3148 int button = -1;
3149 pointer_x = (int) (dx * (double) sh_video->disp_w);
3150 pointer_y = (int) (dy * (double) sh_video->disp_h);
3151 mp_dvdnav_update_mouse_pos(mpctx->stream,
3152 pointer_x, pointer_y, &button);
3153 if (osd_level > 1 && button > 0)
3154 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3155 "Selected button number %d", button);
3157 #endif
3158 #ifdef CONFIG_MENU
3159 if (use_menu && dx >= 0.0 && dy >= 0.0)
3160 menu_update_mouse_pos(dx, dy);
3161 #endif
3163 break;
3165 #ifdef CONFIG_DVDNAV
3166 case MP_CMD_DVDNAV:{
3167 int button = -1;
3168 int i;
3169 mp_command_type command = 0;
3170 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3171 break;
3173 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3174 if (cmd->args[0].v.s &&
3175 !strcasecmp (cmd->args[0].v.s,
3176 mp_dvdnav_bindings[i].name))
3177 command = mp_dvdnav_bindings[i].cmd;
3179 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3180 if (osd_level > 1 && button > 0)
3181 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3182 "Selected button number %d", button);
3184 break;
3186 case MP_CMD_SWITCH_TITLE:
3187 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3188 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3189 break;
3191 #endif
3193 default:
3194 #ifdef CONFIG_GUI
3195 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3196 guiGetEvent(guiIEvent, (char *) cmd->id);
3197 else
3198 #endif
3199 mp_msg(MSGT_CPLAYER, MSGL_V,
3200 "Received unknown cmd %s\n", cmd->name);
3203 switch (cmd->pausing) {
3204 case 1: // "pausing"
3205 mpctx->osd_function = OSD_PAUSE;
3206 break;
3207 case 3: // "pausing_toggle"
3208 mpctx->was_paused = !mpctx->was_paused;
3209 if (mpctx->was_paused)
3210 mpctx->osd_function = OSD_PAUSE;
3211 else if (mpctx->osd_function == OSD_PAUSE)
3212 mpctx->osd_function = OSD_PLAY;
3213 break;
3214 case 2: // "pausing_keep"
3215 if (mpctx->was_paused)
3216 mpctx->osd_function = OSD_PAUSE;
3218 return brk_cmd;