Synced with help_mp-en.h r29549
[mplayer/greg.git] / command.c
blob29d3cf2e94fd5d3a59f1b5f80f064cf374254a09
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 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
949 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
950 return M_PROPERTY_OK;
952 default:
953 return M_PROPERTY_NOT_IMPLEMENTED;
957 ///@}
959 /// \defgroup VideoProperties Video properties
960 /// \ingroup Properties
961 ///@{
963 /// Fullscreen state (RW)
964 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
965 MPContext * mpctx)
968 if (!mpctx->video_out)
969 return M_PROPERTY_UNAVAILABLE;
971 switch (action) {
972 case M_PROPERTY_SET:
973 if (!arg)
974 return M_PROPERTY_ERROR;
975 M_PROPERTY_CLAMP(prop, *(int *) arg);
976 if (vo_fs == !!*(int *) arg)
977 return M_PROPERTY_OK;
978 case M_PROPERTY_STEP_UP:
979 case M_PROPERTY_STEP_DOWN:
980 #ifdef CONFIG_GUI
981 if (use_gui)
982 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
983 else
984 #endif
985 if (vo_config_count)
986 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
987 return M_PROPERTY_OK;
988 default:
989 return m_property_flag(prop, action, arg, &vo_fs);
993 static int mp_property_deinterlace(m_option_t * prop, int action,
994 void *arg, MPContext * mpctx)
996 int deinterlace;
997 vf_instance_t *vf;
998 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
999 return M_PROPERTY_UNAVAILABLE;
1000 vf = mpctx->sh_video->vfilter;
1001 switch (action) {
1002 case M_PROPERTY_GET:
1003 if (!arg)
1004 return M_PROPERTY_ERROR;
1005 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1006 return M_PROPERTY_OK;
1007 case M_PROPERTY_SET:
1008 if (!arg)
1009 return M_PROPERTY_ERROR;
1010 M_PROPERTY_CLAMP(prop, *(int *) arg);
1011 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1012 return M_PROPERTY_OK;
1013 case M_PROPERTY_STEP_UP:
1014 case M_PROPERTY_STEP_DOWN:
1015 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1016 deinterlace = !deinterlace;
1017 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1018 return M_PROPERTY_OK;
1020 return M_PROPERTY_NOT_IMPLEMENTED;
1023 /// Panscan (RW)
1024 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
1025 MPContext * mpctx)
1028 if (!mpctx->video_out
1029 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1030 return M_PROPERTY_UNAVAILABLE;
1032 switch (action) {
1033 case M_PROPERTY_SET:
1034 if (!arg)
1035 return M_PROPERTY_ERROR;
1036 M_PROPERTY_CLAMP(prop, *(float *) arg);
1037 vo_panscan = *(float *) arg;
1038 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1039 return M_PROPERTY_OK;
1040 case M_PROPERTY_STEP_UP:
1041 case M_PROPERTY_STEP_DOWN:
1042 vo_panscan += (arg ? *(float *) arg : 0.1) *
1043 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1044 if (vo_panscan > 1)
1045 vo_panscan = 1;
1046 else if (vo_panscan < 0)
1047 vo_panscan = 0;
1048 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1049 return M_PROPERTY_OK;
1050 default:
1051 return m_property_float_range(prop, action, arg, &vo_panscan);
1055 /// Helper to set vo flags.
1056 /** \ingroup PropertyImplHelper
1058 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
1059 int vo_ctrl, int *vo_var, MPContext * mpctx)
1062 if (!mpctx->video_out)
1063 return M_PROPERTY_UNAVAILABLE;
1065 switch (action) {
1066 case M_PROPERTY_SET:
1067 if (!arg)
1068 return M_PROPERTY_ERROR;
1069 M_PROPERTY_CLAMP(prop, *(int *) arg);
1070 if (*vo_var == !!*(int *) arg)
1071 return M_PROPERTY_OK;
1072 case M_PROPERTY_STEP_UP:
1073 case M_PROPERTY_STEP_DOWN:
1074 if (vo_config_count)
1075 mpctx->video_out->control(vo_ctrl, 0);
1076 return M_PROPERTY_OK;
1077 default:
1078 return m_property_flag(prop, action, arg, vo_var);
1082 /// Window always on top (RW)
1083 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
1084 MPContext * mpctx)
1086 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
1087 mpctx);
1090 /// Display in the root window (RW)
1091 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
1092 MPContext * mpctx)
1094 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1095 &vo_rootwin, mpctx);
1098 /// Show window borders (RW)
1099 static int mp_property_border(m_option_t * prop, int action, void *arg,
1100 MPContext * mpctx)
1102 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1103 &vo_border, mpctx);
1106 /// Framedropping state (RW)
1107 static int mp_property_framedropping(m_option_t * prop, int action,
1108 void *arg, MPContext * mpctx)
1111 if (!mpctx->sh_video)
1112 return M_PROPERTY_UNAVAILABLE;
1114 switch (action) {
1115 case M_PROPERTY_PRINT:
1116 if (!arg)
1117 return M_PROPERTY_ERROR;
1118 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1119 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1120 MSGTR_Disabled));
1121 return M_PROPERTY_OK;
1122 default:
1123 return m_property_choice(prop, action, arg, &frame_dropping);
1127 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1128 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
1129 MPContext * mpctx)
1131 int *gamma = prop->priv, r, val;
1133 if (!mpctx->sh_video)
1134 return M_PROPERTY_UNAVAILABLE;
1136 if (gamma[0] == 1000) {
1137 gamma[0] = 0;
1138 get_video_colors(mpctx->sh_video, prop->name, gamma);
1141 switch (action) {
1142 case M_PROPERTY_SET:
1143 if (!arg)
1144 return M_PROPERTY_ERROR;
1145 M_PROPERTY_CLAMP(prop, *(int *) arg);
1146 *gamma = *(int *) arg;
1147 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1148 if (r <= 0)
1149 break;
1150 return r;
1151 case M_PROPERTY_GET:
1152 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1153 if (!arg)
1154 return M_PROPERTY_ERROR;
1155 *(int *)arg = val;
1156 return M_PROPERTY_OK;
1158 break;
1159 case M_PROPERTY_STEP_UP:
1160 case M_PROPERTY_STEP_DOWN:
1161 *gamma += (arg ? *(int *) arg : 1) *
1162 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1163 M_PROPERTY_CLAMP(prop, *gamma);
1164 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1165 if (r <= 0)
1166 break;
1167 return r;
1168 default:
1169 return M_PROPERTY_NOT_IMPLEMENTED;
1172 #ifdef CONFIG_TV
1173 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1174 int l = strlen(prop->name);
1175 char tv_prop[3 + l + 1];
1176 sprintf(tv_prop, "tv_%s", prop->name);
1177 return mp_property_do(tv_prop, action, arg, mpctx);
1179 #endif
1181 return M_PROPERTY_UNAVAILABLE;
1184 /// VSync (RW)
1185 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1186 MPContext * mpctx)
1188 return m_property_flag(prop, action, arg, &vo_vsync);
1191 /// Video codec tag (RO)
1192 static int mp_property_video_format(m_option_t * prop, int action,
1193 void *arg, MPContext * mpctx)
1195 char* meta;
1196 if (!mpctx->sh_video)
1197 return M_PROPERTY_UNAVAILABLE;
1198 switch(action) {
1199 case M_PROPERTY_PRINT:
1200 if (!arg)
1201 return M_PROPERTY_ERROR;
1202 switch(mpctx->sh_video->format) {
1203 case 0x10000001:
1204 meta = strdup ("mpeg1"); break;
1205 case 0x10000002:
1206 meta = strdup ("mpeg2"); break;
1207 case 0x10000004:
1208 meta = strdup ("mpeg4"); break;
1209 case 0x10000005:
1210 meta = strdup ("h264"); break;
1211 default:
1212 if(mpctx->sh_video->format >= 0x20202020) {
1213 meta = malloc(5);
1214 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1215 } else {
1216 meta = malloc(20);
1217 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1220 *(char**)arg = meta;
1221 return M_PROPERTY_OK;
1223 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1226 /// Video codec name (RO)
1227 static int mp_property_video_codec(m_option_t * prop, int action,
1228 void *arg, MPContext * mpctx)
1230 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1231 return M_PROPERTY_UNAVAILABLE;
1232 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1236 /// Video bitrate (RO)
1237 static int mp_property_video_bitrate(m_option_t * prop, int action,
1238 void *arg, MPContext * mpctx)
1240 if (!mpctx->sh_video)
1241 return M_PROPERTY_UNAVAILABLE;
1242 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1245 /// Video display width (RO)
1246 static int mp_property_width(m_option_t * prop, int action, void *arg,
1247 MPContext * mpctx)
1249 if (!mpctx->sh_video)
1250 return M_PROPERTY_UNAVAILABLE;
1251 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1254 /// Video display height (RO)
1255 static int mp_property_height(m_option_t * prop, int action, void *arg,
1256 MPContext * mpctx)
1258 if (!mpctx->sh_video)
1259 return M_PROPERTY_UNAVAILABLE;
1260 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1263 /// Video fps (RO)
1264 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1265 MPContext * mpctx)
1267 if (!mpctx->sh_video)
1268 return M_PROPERTY_UNAVAILABLE;
1269 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1272 /// Video aspect (RO)
1273 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1274 MPContext * mpctx)
1276 if (!mpctx->sh_video)
1277 return M_PROPERTY_UNAVAILABLE;
1278 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1281 ///@}
1283 /// \defgroup SubProprties Subtitles properties
1284 /// \ingroup Properties
1285 ///@{
1287 /// Text subtitle position (RW)
1288 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1289 MPContext * mpctx)
1291 if (!mpctx->sh_video)
1292 return M_PROPERTY_UNAVAILABLE;
1294 switch (action) {
1295 case M_PROPERTY_SET:
1296 if (!arg)
1297 return M_PROPERTY_ERROR;
1298 case M_PROPERTY_STEP_UP:
1299 case M_PROPERTY_STEP_DOWN:
1300 vo_osd_changed(OSDTYPE_SUBTITLE);
1301 default:
1302 return m_property_int_range(prop, action, arg, &sub_pos);
1306 /// Selected subtitles (RW)
1307 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1308 MPContext * mpctx)
1310 demux_stream_t *const d_sub = mpctx->d_sub;
1311 const int global_sub_size = mpctx->global_sub_size;
1312 int source = -1, reset_spu = 0;
1313 char *sub_name;
1315 if (global_sub_size <= 0)
1316 return M_PROPERTY_UNAVAILABLE;
1318 switch (action) {
1319 case M_PROPERTY_GET:
1320 if (!arg)
1321 return M_PROPERTY_ERROR;
1322 *(int *) arg = mpctx->global_sub_pos;
1323 return M_PROPERTY_OK;
1324 case M_PROPERTY_PRINT:
1325 if (!arg)
1326 return M_PROPERTY_ERROR;
1327 *(char **) arg = malloc(64);
1328 (*(char **) arg)[63] = 0;
1329 sub_name = 0;
1330 if (subdata)
1331 sub_name = subdata->filename;
1332 #ifdef CONFIG_ASS
1333 if (ass_track && ass_track->name)
1334 sub_name = ass_track->name;
1335 #endif
1336 if (sub_name) {
1337 char *tmp, *tmp2;
1338 tmp = sub_name;
1339 if ((tmp2 = strrchr(tmp, '/')))
1340 tmp = tmp2 + 1;
1342 snprintf(*(char **) arg, 63, "(%d) %s%s",
1343 mpctx->set_of_sub_pos + 1,
1344 strlen(tmp) < 20 ? "" : "...",
1345 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1346 return M_PROPERTY_OK;
1348 #ifdef CONFIG_DVDNAV
1349 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1350 if (vo_spudec && dvdsub_id >= 0) {
1351 unsigned char lang[3];
1352 if (mp_dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1353 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1354 return M_PROPERTY_OK;
1358 #endif
1360 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1361 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1362 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1363 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1364 && d_sub && d_sub->sh && dvdsub_id >= 0) {
1365 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1366 if (!lang) lang = MSGTR_Unknown;
1367 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1368 return M_PROPERTY_OK;
1371 if (vo_vobsub && vobsub_id >= 0) {
1372 const char *language = MSGTR_Unknown;
1373 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1374 snprintf(*(char **) arg, 63, "(%d) %s",
1375 vobsub_id, language ? language : MSGTR_Unknown);
1376 return M_PROPERTY_OK;
1378 #ifdef CONFIG_DVDREAD
1379 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1380 && dvdsub_id >= 0) {
1381 char lang[3];
1382 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1383 lang[0] = code >> 8;
1384 lang[1] = code;
1385 lang[2] = 0;
1386 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1387 return M_PROPERTY_OK;
1389 #endif
1390 if (dvdsub_id >= 0) {
1391 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1392 return M_PROPERTY_OK;
1394 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1395 return M_PROPERTY_OK;
1397 case M_PROPERTY_SET:
1398 if (!arg)
1399 return M_PROPERTY_ERROR;
1400 if (*(int *) arg < -1)
1401 *(int *) arg = -1;
1402 else if (*(int *) arg >= global_sub_size)
1403 *(int *) arg = global_sub_size - 1;
1404 mpctx->global_sub_pos = *(int *) arg;
1405 break;
1406 case M_PROPERTY_STEP_UP:
1407 mpctx->global_sub_pos += 2;
1408 mpctx->global_sub_pos =
1409 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1410 break;
1411 case M_PROPERTY_STEP_DOWN:
1412 mpctx->global_sub_pos += global_sub_size + 1;
1413 mpctx->global_sub_pos =
1414 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1415 break;
1416 default:
1417 return M_PROPERTY_NOT_IMPLEMENTED;
1420 if (mpctx->global_sub_pos >= 0)
1421 source = sub_source(mpctx);
1423 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1424 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1425 global_sub_size,
1426 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1427 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1428 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1429 mpctx->global_sub_pos, source);
1431 mpctx->set_of_sub_pos = -1;
1432 subdata = NULL;
1434 vobsub_id = -1;
1435 dvdsub_id = -1;
1436 if (d_sub) {
1437 if (d_sub->id > -2)
1438 reset_spu = 1;
1439 d_sub->id = -2;
1441 #ifdef CONFIG_ASS
1442 ass_track = 0;
1443 #endif
1445 if (source == SUB_SOURCE_VOBSUB) {
1446 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1447 } else if (source == SUB_SOURCE_SUBS) {
1448 mpctx->set_of_sub_pos =
1449 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1450 #ifdef CONFIG_ASS
1451 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1452 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1453 else
1454 #endif
1456 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1457 vo_osd_changed(OSDTYPE_SUBTITLE);
1459 } else if (source == SUB_SOURCE_DEMUX) {
1460 dvdsub_id =
1461 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1462 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1463 int i = 0;
1464 // default: assume 1:1 mapping of sid and stream id
1465 d_sub->id = dvdsub_id;
1466 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1467 ds_free_packs(d_sub);
1468 for (i = 0; i < MAX_S_STREAMS; i++) {
1469 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1470 if (sh && sh->sid == dvdsub_id) {
1471 d_sub->id = i;
1472 d_sub->sh = sh;
1473 break;
1476 if (d_sub->sh && d_sub->id >= 0) {
1477 sh_sub_t *sh = d_sub->sh;
1478 if (sh->type == 'v')
1479 init_vo_spudec();
1480 #ifdef CONFIG_ASS
1481 else if (ass_enabled)
1482 ass_track = sh->ass_track;
1483 #endif
1484 } else {
1485 d_sub->id = -2;
1486 d_sub->sh = NULL;
1490 #ifdef CONFIG_DVDREAD
1491 if (vo_spudec
1492 && (mpctx->stream->type == STREAMTYPE_DVD
1493 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1494 && dvdsub_id < 0 && reset_spu) {
1495 dvdsub_id = -2;
1496 d_sub->id = dvdsub_id;
1498 #endif
1499 update_subtitles(mpctx->sh_video, d_sub, 1);
1501 return M_PROPERTY_OK;
1504 /// Selected sub source (RW)
1505 static int mp_property_sub_source(m_option_t * prop, int action, void *arg,
1506 MPContext * mpctx)
1508 int source;
1509 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1510 return M_PROPERTY_UNAVAILABLE;
1512 switch (action) {
1513 case M_PROPERTY_GET:
1514 if (!arg)
1515 return M_PROPERTY_ERROR;
1516 *(int *) arg = sub_source(mpctx);
1517 return M_PROPERTY_OK;
1518 case M_PROPERTY_PRINT:
1519 if (!arg)
1520 return M_PROPERTY_ERROR;
1521 *(char **) arg = malloc(64);
1522 (*(char **) arg)[63] = 0;
1523 switch (sub_source(mpctx))
1525 case SUB_SOURCE_SUBS:
1526 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1527 break;
1528 case SUB_SOURCE_VOBSUB:
1529 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1530 break;
1531 case SUB_SOURCE_DEMUX:
1532 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1533 break;
1534 default:
1535 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1537 return M_PROPERTY_OK;
1538 case M_PROPERTY_SET:
1539 if (!arg)
1540 return M_PROPERTY_ERROR;
1541 M_PROPERTY_CLAMP(prop, *(int*)arg);
1542 if (*(int *) arg < 0)
1543 mpctx->global_sub_pos = -1;
1544 else if (*(int *) arg != sub_source(mpctx)) {
1545 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1546 return M_PROPERTY_UNAVAILABLE;
1547 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1549 break;
1550 case M_PROPERTY_STEP_UP:
1551 case M_PROPERTY_STEP_DOWN: {
1552 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1553 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1554 int step = (step_all > 0) ? 1 : -1;
1555 int cur_source = sub_source(mpctx);
1556 source = cur_source;
1557 while (step_all) {
1558 source += step;
1559 if (source >= SUB_SOURCES)
1560 source = -1;
1561 else if (source < -1)
1562 source = SUB_SOURCES - 1;
1563 if (source == cur_source || source == -1 ||
1564 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1565 step_all -= step;
1567 if (source == cur_source)
1568 return M_PROPERTY_OK;
1569 if (source == -1)
1570 mpctx->global_sub_pos = -1;
1571 else
1572 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1573 break;
1575 default:
1576 return M_PROPERTY_NOT_IMPLEMENTED;
1578 --mpctx->global_sub_pos;
1579 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1582 /// Selected subtitles from specific source (RW)
1583 static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg,
1584 MPContext * mpctx)
1586 int source, is_cur_source, offset;
1587 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1588 return M_PROPERTY_UNAVAILABLE;
1590 if (!strcmp(prop->name, "sub_file"))
1591 source = SUB_SOURCE_SUBS;
1592 else if (!strcmp(prop->name, "sub_vob"))
1593 source = SUB_SOURCE_VOBSUB;
1594 else if (!strcmp(prop->name, "sub_demux"))
1595 source = SUB_SOURCE_DEMUX;
1596 else
1597 return M_PROPERTY_ERROR;
1599 offset = mpctx->global_sub_indices[source];
1600 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1601 return M_PROPERTY_UNAVAILABLE;
1603 is_cur_source = sub_source(mpctx) == source;
1604 switch (action) {
1605 case M_PROPERTY_GET:
1606 if (!arg)
1607 return M_PROPERTY_ERROR;
1608 if (is_cur_source) {
1609 *(int *) arg = mpctx->global_sub_pos - offset;
1610 if (source == SUB_SOURCE_VOBSUB)
1611 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1613 else
1614 *(int *) arg = -1;
1615 return M_PROPERTY_OK;
1616 case M_PROPERTY_PRINT:
1617 if (!arg)
1618 return M_PROPERTY_ERROR;
1619 if (is_cur_source)
1620 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1621 *(char **) arg = malloc(64);
1622 (*(char **) arg)[63] = 0;
1623 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1624 return M_PROPERTY_OK;
1625 case M_PROPERTY_SET:
1626 if (!arg)
1627 return M_PROPERTY_ERROR;
1628 if (*(int *) arg >= 0) {
1629 int index = *(int *)arg;
1630 if (source == SUB_SOURCE_VOBSUB)
1631 index = vobsub_get_index_by_id(vo_vobsub, index);
1632 mpctx->global_sub_pos = offset + index;
1633 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1634 || sub_source(mpctx) != source) {
1635 mpctx->global_sub_pos = -1;
1636 *(int *) arg = -1;
1639 else
1640 mpctx->global_sub_pos = -1;
1641 break;
1642 case M_PROPERTY_STEP_UP:
1643 case M_PROPERTY_STEP_DOWN: {
1644 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1645 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1646 int step = (step_all > 0) ? 1 : -1;
1647 int max_sub_pos_for_source = -1;
1648 if (!is_cur_source)
1649 mpctx->global_sub_pos = -1;
1650 while (step_all) {
1651 if (mpctx->global_sub_pos == -1) {
1652 if (step > 0)
1653 mpctx->global_sub_pos = offset;
1654 else if (max_sub_pos_for_source == -1) {
1655 // Find max pos for specific source
1656 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1657 while (mpctx->global_sub_pos >= 0
1658 && sub_source(mpctx) != source)
1659 --mpctx->global_sub_pos;
1661 else
1662 mpctx->global_sub_pos = max_sub_pos_for_source;
1664 else {
1665 mpctx->global_sub_pos += step;
1666 if (mpctx->global_sub_pos < offset ||
1667 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1668 sub_source(mpctx) != source)
1669 mpctx->global_sub_pos = -1;
1671 step_all -= step;
1673 break;
1675 default:
1676 return M_PROPERTY_NOT_IMPLEMENTED;
1678 --mpctx->global_sub_pos;
1679 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1682 /// Subtitle delay (RW)
1683 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1684 MPContext * mpctx)
1686 if (!mpctx->sh_video)
1687 return M_PROPERTY_UNAVAILABLE;
1688 return m_property_delay(prop, action, arg, &sub_delay);
1691 /// Alignment of text subtitles (RW)
1692 static int mp_property_sub_alignment(m_option_t * prop, int action,
1693 void *arg, MPContext * mpctx)
1695 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1697 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1698 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1699 return M_PROPERTY_UNAVAILABLE;
1701 switch (action) {
1702 case M_PROPERTY_PRINT:
1703 if (!arg)
1704 return M_PROPERTY_ERROR;
1705 M_PROPERTY_CLAMP(prop, sub_alignment);
1706 *(char **) arg = strdup(name[sub_alignment]);
1707 return M_PROPERTY_OK;
1708 case M_PROPERTY_SET:
1709 if (!arg)
1710 return M_PROPERTY_ERROR;
1711 case M_PROPERTY_STEP_UP:
1712 case M_PROPERTY_STEP_DOWN:
1713 vo_osd_changed(OSDTYPE_SUBTITLE);
1714 default:
1715 return m_property_choice(prop, action, arg, &sub_alignment);
1719 /// Subtitle visibility (RW)
1720 static int mp_property_sub_visibility(m_option_t * prop, int action,
1721 void *arg, MPContext * mpctx)
1723 if (!mpctx->sh_video)
1724 return M_PROPERTY_UNAVAILABLE;
1726 switch (action) {
1727 case M_PROPERTY_SET:
1728 if (!arg)
1729 return M_PROPERTY_ERROR;
1730 case M_PROPERTY_STEP_UP:
1731 case M_PROPERTY_STEP_DOWN:
1732 vo_osd_changed(OSDTYPE_SUBTITLE);
1733 if (vo_spudec)
1734 vo_osd_changed(OSDTYPE_SPU);
1735 default:
1736 return m_property_flag(prop, action, arg, &sub_visibility);
1740 #ifdef CONFIG_ASS
1741 /// Use margins for libass subtitles (RW)
1742 static int mp_property_ass_use_margins(m_option_t * prop, int action,
1743 void *arg, MPContext * mpctx)
1745 if (!mpctx->sh_video)
1746 return M_PROPERTY_UNAVAILABLE;
1748 switch (action) {
1749 case M_PROPERTY_SET:
1750 if (!arg)
1751 return M_PROPERTY_ERROR;
1752 case M_PROPERTY_STEP_UP:
1753 case M_PROPERTY_STEP_DOWN:
1754 ass_force_reload = 1;
1755 default:
1756 return m_property_flag(prop, action, arg, &ass_use_margins);
1759 #endif
1761 /// Show only forced subtitles (RW)
1762 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1763 void *arg, MPContext * mpctx)
1765 if (!vo_spudec)
1766 return M_PROPERTY_UNAVAILABLE;
1768 switch (action) {
1769 case M_PROPERTY_SET:
1770 if (!arg)
1771 return M_PROPERTY_ERROR;
1772 case M_PROPERTY_STEP_UP:
1773 case M_PROPERTY_STEP_DOWN:
1774 m_property_flag(prop, action, arg, &forced_subs_only);
1775 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1776 return M_PROPERTY_OK;
1777 default:
1778 return m_property_flag(prop, action, arg, &forced_subs_only);
1783 #ifdef CONFIG_FREETYPE
1784 /// Subtitle scale (RW)
1785 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1786 MPContext * mpctx)
1789 switch (action) {
1790 case M_PROPERTY_SET:
1791 if (!arg)
1792 return M_PROPERTY_ERROR;
1793 M_PROPERTY_CLAMP(prop, *(float *) arg);
1794 #ifdef CONFIG_ASS
1795 if (ass_enabled) {
1796 ass_font_scale = *(float *) arg;
1797 ass_force_reload = 1;
1799 #endif
1800 text_font_scale_factor = *(float *) arg;
1801 force_load_font = 1;
1802 return M_PROPERTY_OK;
1803 case M_PROPERTY_STEP_UP:
1804 case M_PROPERTY_STEP_DOWN:
1805 #ifdef CONFIG_ASS
1806 if (ass_enabled) {
1807 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1808 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1809 M_PROPERTY_CLAMP(prop, ass_font_scale);
1810 ass_force_reload = 1;
1812 #endif
1813 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1814 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1815 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1816 force_load_font = 1;
1817 return M_PROPERTY_OK;
1818 default:
1819 #ifdef CONFIG_ASS
1820 if (ass_enabled)
1821 return m_property_float_ro(prop, action, arg, ass_font_scale);
1822 else
1823 #endif
1824 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1827 #endif
1829 ///@}
1831 /// \defgroup TVProperties TV properties
1832 /// \ingroup Properties
1833 ///@{
1835 #ifdef CONFIG_TV
1837 /// TV color settings (RW)
1838 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1839 MPContext * mpctx)
1841 int r, val;
1842 tvi_handle_t *tvh = mpctx->demuxer->priv;
1843 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1844 return M_PROPERTY_UNAVAILABLE;
1846 switch (action) {
1847 case M_PROPERTY_SET:
1848 if (!arg)
1849 return M_PROPERTY_ERROR;
1850 M_PROPERTY_CLAMP(prop, *(int *) arg);
1851 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1852 case M_PROPERTY_GET:
1853 return tv_get_color_options(tvh, (int) prop->priv, arg);
1854 case M_PROPERTY_STEP_UP:
1855 case M_PROPERTY_STEP_DOWN:
1856 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1857 if (!r)
1858 return M_PROPERTY_ERROR;
1859 val += (arg ? *(int *) arg : 1) *
1860 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1861 M_PROPERTY_CLAMP(prop, val);
1862 return tv_set_color_options(tvh, (int) prop->priv, val);
1864 return M_PROPERTY_ERROR;
1866 return M_PROPERTY_NOT_IMPLEMENTED;
1869 #endif
1871 #ifdef CONFIG_TV_TELETEXT
1872 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1873 MPContext * mpctx)
1875 int val,result;
1876 int base_ioctl=(int)prop->priv;
1878 for teletext's GET,SET,STEP ioctls this is not 0
1879 SET is GET+1
1880 STEP is GET+2
1882 tvi_handle_t *tvh = mpctx->demuxer->priv;
1883 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1884 return M_PROPERTY_UNAVAILABLE;
1885 if(!base_ioctl)
1886 return M_PROPERTY_ERROR;
1888 switch (action) {
1889 case M_PROPERTY_GET:
1890 if (!arg)
1891 return M_PROPERTY_ERROR;
1892 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1893 break;
1894 case M_PROPERTY_SET:
1895 if (!arg)
1896 return M_PROPERTY_ERROR;
1897 M_PROPERTY_CLAMP(prop, *(int *) arg);
1898 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1899 break;
1900 case M_PROPERTY_STEP_UP:
1901 case M_PROPERTY_STEP_DOWN:
1902 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1903 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1904 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1905 break;
1906 default:
1907 return M_PROPERTY_NOT_IMPLEMENTED;
1910 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1913 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1914 MPContext * mpctx)
1916 tvi_handle_t *tvh = mpctx->demuxer->priv;
1917 int result;
1918 int val;
1920 //with tvh==NULL will fail too
1921 result=mp_property_teletext_common(prop,action,arg,mpctx);
1922 if(result!=M_PROPERTY_OK)
1923 return result;
1925 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1926 mp_input_set_section("teletext");
1927 else
1928 mp_input_set_section("tv");
1929 return M_PROPERTY_OK;
1932 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1933 MPContext * mpctx)
1935 tvi_handle_t *tvh = mpctx->demuxer->priv;
1936 int result;
1937 int val;
1938 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1939 return M_PROPERTY_UNAVAILABLE;
1940 switch(action){
1941 case M_PROPERTY_STEP_UP:
1942 case M_PROPERTY_STEP_DOWN:
1943 //This should be handled separately
1944 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1945 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1946 break;
1947 default:
1948 result=mp_property_teletext_common(prop,action,arg,mpctx);
1950 return result;
1954 #endif /* CONFIG_TV_TELETEXT */
1956 ///@}
1958 /// All properties available in MPlayer.
1959 /** \ingroup Properties
1961 static const m_option_t mp_properties[] = {
1962 // General
1963 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1964 M_OPT_RANGE, 0, 3, NULL },
1965 { "loop", mp_property_loop, CONF_TYPE_INT,
1966 M_OPT_MIN, -1, 0, NULL },
1967 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1968 M_OPT_RANGE, 0.01, 100.0, NULL },
1969 { "filename", mp_property_filename, CONF_TYPE_STRING,
1970 0, 0, 0, NULL },
1971 { "path", mp_property_path, CONF_TYPE_STRING,
1972 0, 0, 0, NULL },
1973 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1974 0, 0, 0, NULL },
1975 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1976 M_OPT_MIN, 0, 0, NULL },
1977 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1978 M_OPT_MIN, 0, 0, NULL },
1979 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1980 M_OPT_MIN, 0, 0, NULL },
1981 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1982 M_OPT_MIN, 0, 0, NULL },
1983 { "length", mp_property_length, CONF_TYPE_TIME,
1984 M_OPT_MIN, 0, 0, NULL },
1985 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1986 M_OPT_RANGE, 0, 100, NULL },
1987 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1988 M_OPT_MIN, 0, 0, NULL },
1989 { "chapter", mp_property_chapter, CONF_TYPE_INT,
1990 M_OPT_MIN, 0, 0, NULL },
1991 { "chapters", mp_property_chapters, CONF_TYPE_INT,
1992 0, 0, 0, NULL },
1993 { "angle", mp_property_angle, CONF_TYPE_INT,
1994 CONF_RANGE, -2, 10, NULL },
1995 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
1996 0, 0, 0, NULL },
1997 { "pause", mp_property_pause, CONF_TYPE_FLAG,
1998 M_OPT_RANGE, 0, 1, NULL },
2000 // Audio
2001 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2002 M_OPT_RANGE, 0, 100, NULL },
2003 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2004 M_OPT_RANGE, 0, 1, NULL },
2005 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2006 M_OPT_RANGE, -100, 100, NULL },
2007 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2008 0, 0, 0, NULL },
2009 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2010 0, 0, 0, NULL },
2011 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2012 0, 0, 0, NULL },
2013 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2014 0, 0, 0, NULL },
2015 { "channels", mp_property_channels, CONF_TYPE_INT,
2016 0, 0, 0, NULL },
2017 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2018 CONF_RANGE, -2, 65535, NULL },
2019 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2020 M_OPT_RANGE, -1, 1, NULL },
2022 // Video
2023 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2024 M_OPT_RANGE, 0, 1, NULL },
2025 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2026 M_OPT_RANGE, 0, 1, NULL },
2027 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2028 M_OPT_RANGE, 0, 1, NULL },
2029 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2030 M_OPT_RANGE, 0, 1, NULL },
2031 { "border", mp_property_border, CONF_TYPE_FLAG,
2032 M_OPT_RANGE, 0, 1, NULL },
2033 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2034 M_OPT_RANGE, 0, 2, NULL },
2035 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2036 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2037 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2038 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2039 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2040 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2041 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2042 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2043 { "hue", mp_property_gamma, CONF_TYPE_INT,
2044 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2045 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2046 M_OPT_RANGE, 0, 1, NULL },
2047 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2048 M_OPT_RANGE, 0, 1, NULL },
2049 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2050 0, 0, 0, NULL },
2051 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2052 0, 0, 0, NULL },
2053 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2054 0, 0, 0, NULL },
2055 { "width", mp_property_width, CONF_TYPE_INT,
2056 0, 0, 0, NULL },
2057 { "height", mp_property_height, CONF_TYPE_INT,
2058 0, 0, 0, NULL },
2059 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2060 0, 0, 0, NULL },
2061 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2062 0, 0, 0, NULL },
2063 { "switch_video", mp_property_video, CONF_TYPE_INT,
2064 CONF_RANGE, -2, 65535, NULL },
2065 { "switch_program", mp_property_program, CONF_TYPE_INT,
2066 CONF_RANGE, -1, 65535, NULL },
2068 // Subs
2069 { "sub", mp_property_sub, CONF_TYPE_INT,
2070 M_OPT_MIN, -1, 0, NULL },
2071 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2072 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2073 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2074 M_OPT_MIN, -1, 0, NULL },
2075 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2076 M_OPT_MIN, -1, 0, NULL },
2077 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2078 M_OPT_MIN, -1, 0, NULL },
2079 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2080 0, 0, 0, NULL },
2081 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2082 M_OPT_RANGE, 0, 100, NULL },
2083 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2084 M_OPT_RANGE, 0, 2, NULL },
2085 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2086 M_OPT_RANGE, 0, 1, NULL },
2087 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2088 M_OPT_RANGE, 0, 1, NULL },
2089 #ifdef CONFIG_FREETYPE
2090 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2091 M_OPT_RANGE, 0, 100, NULL },
2092 #endif
2093 #ifdef CONFIG_ASS
2094 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2095 M_OPT_RANGE, 0, 1, NULL },
2096 #endif
2098 #ifdef CONFIG_TV
2099 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2100 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2101 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2102 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2103 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2104 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2105 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2106 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2107 #endif
2109 #ifdef CONFIG_TV_TELETEXT
2110 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2111 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2112 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2113 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2114 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2115 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2116 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2117 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2118 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2119 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2120 #endif
2122 { NULL, NULL, NULL, 0, 0, 0, NULL }
2126 int mp_property_do(const char *name, int action, void *val, void *ctx)
2128 return m_property_do(mp_properties, name, action, val, ctx);
2131 char* mp_property_print(const char *name, void* ctx)
2133 char* ret = NULL;
2134 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2135 return NULL;
2136 return ret;
2139 char *property_expand_string(MPContext * mpctx, char *str)
2141 return m_properties_expand_string(mp_properties, str, mpctx);
2144 void property_print_help(void)
2146 m_properties_print_help_list(mp_properties);
2150 ///@}
2151 // Properties group
2155 * \defgroup Command2Property Command to property bridge
2157 * It is used to handle most commands that just set a property
2158 * and optionally display something on the OSD.
2159 * Two kinds of commands are handled: adjust or toggle.
2161 * Adjust commands take 1 or 2 parameters: <value> <abs>
2162 * If <abs> is non-zero the property is set to the given value
2163 * otherwise it is adjusted.
2165 * Toggle commands take 0 or 1 parameters. With no parameter
2166 * or a value less than the property minimum it just steps the
2167 * property to its next value. Otherwise it sets it to the given
2168 * value.
2173 /// List of the commands that can be handled by setting a property.
2174 static struct {
2175 /// property name
2176 const char *name;
2177 /// cmd id
2178 int cmd;
2179 /// set/adjust or toggle command
2180 int toggle;
2181 /// progressbar type
2182 int osd_progbar;
2183 /// osd msg id if it must be shared
2184 int osd_id;
2185 /// osd msg template
2186 const char *osd_msg;
2187 } set_prop_cmd[] = {
2188 // general
2189 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2190 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2191 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2192 // audio
2193 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2194 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2195 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2196 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2197 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2198 // video
2199 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2200 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2201 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2202 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2203 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2204 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2205 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2206 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2207 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2208 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2209 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2210 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2211 // subs
2212 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2213 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2214 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2215 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2216 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2217 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2218 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2219 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2220 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2221 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2222 #ifdef CONFIG_FREETYPE
2223 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2224 #endif
2225 #ifdef CONFIG_ASS
2226 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2227 #endif
2228 #ifdef CONFIG_TV
2229 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2230 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2231 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2232 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2233 #endif
2234 { NULL, 0, 0, 0, -1, NULL }
2238 /// Handle commands that set a property.
2239 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
2241 int i, r;
2242 m_option_t* prop;
2243 const char *pname;
2245 // look for the command
2246 for (i = 0; set_prop_cmd[i].name; i++)
2247 if (set_prop_cmd[i].cmd == cmd->id)
2248 break;
2249 if (!(pname = set_prop_cmd[i].name))
2250 return 0;
2252 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2253 return 0;
2255 // toggle command
2256 if (set_prop_cmd[i].toggle) {
2257 // set to value
2258 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2259 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2260 else
2261 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2262 } else if (cmd->args[1].v.i) //set
2263 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2264 else // adjust
2265 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2267 if (r <= 0)
2268 return 1;
2270 if (set_prop_cmd[i].osd_progbar) {
2271 if (prop->type == CONF_TYPE_INT) {
2272 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2273 set_osd_bar(set_prop_cmd[i].osd_progbar,
2274 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2275 } else if (prop->type == CONF_TYPE_FLOAT) {
2276 float f;
2277 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2278 set_osd_bar(set_prop_cmd[i].osd_progbar,
2279 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2280 } else
2281 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2282 "Property use an unsupported type.\n");
2283 return 1;
2286 if (set_prop_cmd[i].osd_msg) {
2287 char *val = mp_property_print(pname, mpctx);
2288 if (val) {
2289 set_osd_msg(set_prop_cmd[i].osd_id >=
2290 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2291 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2292 free(val);
2295 return 1;
2298 #ifdef CONFIG_DVDNAV
2299 static const struct {
2300 const char *name;
2301 const mp_command_type cmd;
2302 } mp_dvdnav_bindings[] = {
2303 { "up", MP_CMD_DVDNAV_UP },
2304 { "down", MP_CMD_DVDNAV_DOWN },
2305 { "left", MP_CMD_DVDNAV_LEFT },
2306 { "right", MP_CMD_DVDNAV_RIGHT },
2307 { "menu", MP_CMD_DVDNAV_MENU },
2308 { "select", MP_CMD_DVDNAV_SELECT },
2309 { "prev", MP_CMD_DVDNAV_PREVMENU },
2310 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2313 * keep old dvdnav sub-command options for a while in order not to
2314 * break slave-mode API too suddenly.
2316 { "1", MP_CMD_DVDNAV_UP },
2317 { "2", MP_CMD_DVDNAV_DOWN },
2318 { "3", MP_CMD_DVDNAV_LEFT },
2319 { "4", MP_CMD_DVDNAV_RIGHT },
2320 { "5", MP_CMD_DVDNAV_MENU },
2321 { "6", MP_CMD_DVDNAV_SELECT },
2322 { "7", MP_CMD_DVDNAV_PREVMENU },
2323 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2324 { NULL, 0 }
2326 #endif
2328 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
2330 sh_audio_t * const sh_audio = mpctx->sh_audio;
2331 sh_video_t * const sh_video = mpctx->sh_video;
2332 int brk_cmd = 0;
2333 if (!set_property_command(mpctx, cmd))
2334 switch (cmd->id) {
2335 case MP_CMD_SEEK:{
2336 float v;
2337 int abs;
2338 if (sh_video)
2339 mpctx->osd_show_percentage = sh_video->fps;
2340 v = cmd->args[0].v.f;
2341 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2342 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2343 abs_seek_pos = SEEK_ABSOLUTE;
2344 if (sh_video)
2345 mpctx->osd_function =
2346 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2347 rel_seek_secs = v;
2348 } else if (abs) { /* Absolute seek by percentage */
2349 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2350 if (sh_video)
2351 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2352 rel_seek_secs = v / 100.0;
2353 } else {
2354 rel_seek_secs += v;
2355 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2357 brk_cmd = 1;
2359 break;
2361 case MP_CMD_SET_PROPERTY:{
2362 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2363 cmd->args[1].v.s, mpctx);
2364 if (r == M_PROPERTY_UNKNOWN)
2365 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2366 "Unknown property: '%s'\n", cmd->args[0].v.s);
2367 else if (r <= 0)
2368 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2369 "Failed to set property '%s' to '%s'.\n",
2370 cmd->args[0].v.s, cmd->args[1].v.s);
2372 break;
2374 case MP_CMD_STEP_PROPERTY:{
2375 void* arg = NULL;
2376 int r,i;
2377 double d;
2378 off_t o;
2379 if (cmd->args[1].v.f) {
2380 m_option_t* prop;
2381 if((r = mp_property_do(cmd->args[0].v.s,
2382 M_PROPERTY_GET_TYPE,
2383 &prop, mpctx)) <= 0)
2384 goto step_prop_err;
2385 if(prop->type == CONF_TYPE_INT ||
2386 prop->type == CONF_TYPE_FLAG)
2387 i = cmd->args[1].v.f, arg = &i;
2388 else if(prop->type == CONF_TYPE_FLOAT)
2389 arg = &cmd->args[1].v.f;
2390 else if(prop->type == CONF_TYPE_DOUBLE ||
2391 prop->type == CONF_TYPE_TIME)
2392 d = cmd->args[1].v.f, arg = &d;
2393 else if(prop->type == CONF_TYPE_POSITION)
2394 o = cmd->args[1].v.f, arg = &o;
2395 else
2396 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2397 "Ignoring step size stepping property '%s'.\n",
2398 cmd->args[0].v.s);
2400 r = mp_property_do(cmd->args[0].v.s,
2401 cmd->args[2].v.i < 0 ?
2402 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2403 arg, mpctx);
2404 step_prop_err:
2405 if (r == M_PROPERTY_UNKNOWN)
2406 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2407 "Unknown property: '%s'\n", cmd->args[0].v.s);
2408 else if (r <= 0)
2409 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2410 "Failed to increment property '%s' by %f.\n",
2411 cmd->args[0].v.s, cmd->args[1].v.f);
2413 break;
2415 case MP_CMD_GET_PROPERTY:{
2416 char *tmp;
2417 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2418 &tmp, mpctx) <= 0) {
2419 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2420 "Failed to get value of property '%s'.\n",
2421 cmd->args[0].v.s);
2422 break;
2424 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2425 cmd->args[0].v.s, tmp);
2426 free(tmp);
2428 break;
2430 case MP_CMD_EDL_MARK:
2431 if (edl_fd) {
2432 float v = sh_video ? sh_video->pts :
2433 playing_audio_pts(sh_audio, mpctx->d_audio,
2434 mpctx->audio_out);
2436 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2437 mpctx->begin_skip = v;
2438 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2439 } else {
2440 if (mpctx->begin_skip > v)
2441 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2442 else {
2443 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2444 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2446 mpctx->begin_skip = MP_NOPTS_VALUE;
2449 break;
2451 case MP_CMD_SWITCH_RATIO:
2452 if (!sh_video)
2453 break;
2454 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2455 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2456 else
2457 movie_aspect = cmd->args[0].v.f;
2458 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2459 break;
2461 case MP_CMD_SPEED_INCR:{
2462 float v = cmd->args[0].v.f;
2463 playback_speed += v;
2464 build_afilter_chain(sh_audio, &ao_data);
2465 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2466 playback_speed);
2467 } break;
2469 case MP_CMD_SPEED_MULT:{
2470 float v = cmd->args[0].v.f;
2471 playback_speed *= v;
2472 build_afilter_chain(sh_audio, &ao_data);
2473 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2474 playback_speed);
2475 } break;
2477 case MP_CMD_SPEED_SET:{
2478 float v = cmd->args[0].v.f;
2479 playback_speed = v;
2480 build_afilter_chain(sh_audio, &ao_data);
2481 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2482 playback_speed);
2483 } break;
2485 case MP_CMD_FRAME_STEP:
2486 case MP_CMD_PAUSE:
2487 cmd->pausing = 1;
2488 brk_cmd = 1;
2489 break;
2491 case MP_CMD_FILE_FILTER:
2492 file_filter = cmd->args[0].v.i;
2493 break;
2495 case MP_CMD_QUIT:
2496 exit_player_with_rc(EXIT_QUIT,
2497 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2499 case MP_CMD_PLAY_TREE_STEP:{
2500 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2501 int force = cmd->args[1].v.i;
2503 #ifdef CONFIG_GUI
2504 if (use_gui) {
2505 int i = 0;
2506 if (n > 0)
2507 for (i = 0; i < n; i++)
2508 mplNext();
2509 else
2510 for (i = 0; i < -1 * n; i++)
2511 mplPrev();
2512 } else
2513 #endif
2515 if (!force && mpctx->playtree_iter) {
2516 play_tree_iter_t *i =
2517 play_tree_iter_new_copy(mpctx->playtree_iter);
2518 if (play_tree_iter_step(i, n, 0) ==
2519 PLAY_TREE_ITER_ENTRY)
2520 mpctx->eof =
2521 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2522 play_tree_iter_free(i);
2523 } else
2524 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2525 if (mpctx->eof)
2526 mpctx->play_tree_step = n;
2527 brk_cmd = 1;
2530 break;
2532 case MP_CMD_PLAY_TREE_UP_STEP:{
2533 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2534 int force = cmd->args[1].v.i;
2536 if (!force && mpctx->playtree_iter) {
2537 play_tree_iter_t *i =
2538 play_tree_iter_new_copy(mpctx->playtree_iter);
2539 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2540 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2541 play_tree_iter_free(i);
2542 } else
2543 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2544 brk_cmd = 1;
2546 break;
2548 case MP_CMD_PLAY_ALT_SRC_STEP:
2549 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2550 int v = cmd->args[0].v.i;
2551 if (v > 0
2552 && mpctx->playtree_iter->file <
2553 mpctx->playtree_iter->num_files)
2554 mpctx->eof = PT_NEXT_SRC;
2555 else if (v < 0 && mpctx->playtree_iter->file > 1)
2556 mpctx->eof = PT_PREV_SRC;
2558 brk_cmd = 1;
2559 break;
2561 case MP_CMD_SUB_STEP:
2562 if (sh_video) {
2563 int movement = cmd->args[0].v.i;
2564 step_sub(subdata, sh_video->pts, movement);
2565 #ifdef CONFIG_ASS
2566 if (ass_track)
2567 sub_delay +=
2568 ass_step_sub(ass_track,
2569 (sh_video->pts +
2570 sub_delay) * 1000 + .5, movement) / 1000.;
2571 #endif
2572 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2573 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2575 break;
2577 case MP_CMD_SUB_LOG:
2578 log_sub();
2579 break;
2581 case MP_CMD_OSD:{
2582 int v = cmd->args[0].v.i;
2583 int max = (term_osd
2584 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2585 if (osd_level > max)
2586 osd_level = max;
2587 if (v < 0)
2588 osd_level = (osd_level + 1) % (max + 1);
2589 else
2590 osd_level = v > max ? max : v;
2591 /* Show OSD state when disabled, but not when an explicit
2592 argument is given to the OSD command, i.e. in slave mode. */
2593 if (v == -1 && osd_level <= 1)
2594 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2595 MSGTR_OSDosd,
2596 osd_level ? MSGTR_OSDenabled :
2597 MSGTR_OSDdisabled);
2598 else
2599 rm_osd_msg(OSD_MSG_OSD_STATUS);
2601 break;
2603 case MP_CMD_OSD_SHOW_TEXT:
2604 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2605 (cmd->args[1].v.i <
2606 0 ? osd_duration : cmd->args[1].v.i),
2607 "%-.63s", cmd->args[0].v.s);
2608 break;
2610 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2611 char *txt = m_properties_expand_string(mp_properties,
2612 cmd->args[0].v.s,
2613 mpctx);
2614 /* if no argument supplied take default osd_duration, else <arg> ms. */
2615 if (txt) {
2616 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2617 (cmd->args[1].v.i <
2618 0 ? osd_duration : cmd->args[1].v.i),
2619 "%-.63s", txt);
2620 free(txt);
2623 break;
2625 case MP_CMD_LOADFILE:{
2626 play_tree_t *e = play_tree_new();
2627 play_tree_add_file(e, cmd->args[0].v.s);
2629 if (cmd->args[1].v.i) // append
2630 play_tree_append_entry(mpctx->playtree->child, e);
2631 else {
2632 // Go back to the starting point.
2633 while (play_tree_iter_up_step
2634 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2635 /* NOP */ ;
2636 play_tree_free_list(mpctx->playtree->child, 1);
2637 play_tree_set_child(mpctx->playtree, e);
2638 pt_iter_goto_head(mpctx->playtree_iter);
2639 mpctx->eof = PT_NEXT_SRC;
2641 brk_cmd = 1;
2643 break;
2645 case MP_CMD_LOADLIST:{
2646 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2647 if (!e)
2648 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2649 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2650 else {
2651 if (cmd->args[1].v.i) // append
2652 play_tree_append_entry(mpctx->playtree->child, e);
2653 else {
2654 // Go back to the starting point.
2655 while (play_tree_iter_up_step
2656 (mpctx->playtree_iter, 0, 1)
2657 != PLAY_TREE_ITER_END)
2658 /* NOP */ ;
2659 play_tree_free_list(mpctx->playtree->child, 1);
2660 play_tree_set_child(mpctx->playtree, e);
2661 pt_iter_goto_head(mpctx->playtree_iter);
2662 mpctx->eof = PT_NEXT_SRC;
2665 brk_cmd = 1;
2667 break;
2669 case MP_CMD_STOP:
2670 // Go back to the starting point.
2671 while (play_tree_iter_up_step
2672 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2673 /* NOP */ ;
2674 mpctx->eof = PT_STOP;
2675 brk_cmd = 1;
2676 break;
2678 #ifdef CONFIG_RADIO
2679 case MP_CMD_RADIO_STEP_CHANNEL:
2680 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2681 int v = cmd->args[0].v.i;
2682 if (v > 0)
2683 radio_step_channel(mpctx->demuxer->stream,
2684 RADIO_CHANNEL_HIGHER);
2685 else
2686 radio_step_channel(mpctx->demuxer->stream,
2687 RADIO_CHANNEL_LOWER);
2688 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2689 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2690 MSGTR_OSDChannel,
2691 radio_get_channel_name(mpctx->demuxer->stream));
2694 break;
2696 case MP_CMD_RADIO_SET_CHANNEL:
2697 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2698 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2699 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2700 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2701 MSGTR_OSDChannel,
2702 radio_get_channel_name(mpctx->demuxer->stream));
2705 break;
2707 case MP_CMD_RADIO_SET_FREQ:
2708 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2709 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2710 break;
2712 case MP_CMD_RADIO_STEP_FREQ:
2713 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2714 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2715 break;
2716 #endif
2718 #ifdef CONFIG_TV
2719 case MP_CMD_TV_START_SCAN:
2720 if (mpctx->file_format == DEMUXER_TYPE_TV)
2721 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2722 break;
2723 case MP_CMD_TV_SET_FREQ:
2724 if (mpctx->file_format == DEMUXER_TYPE_TV)
2725 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2726 cmd->args[0].v.f * 16.0);
2727 #ifdef CONFIG_PVR
2728 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2729 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2730 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2731 pvr_get_current_channelname (mpctx->stream),
2732 pvr_get_current_stationname (mpctx->stream));
2734 #endif /* CONFIG_PVR */
2735 break;
2737 case MP_CMD_TV_STEP_FREQ:
2738 if (mpctx->file_format == DEMUXER_TYPE_TV)
2739 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2740 cmd->args[0].v.f * 16.0);
2741 #ifdef CONFIG_PVR
2742 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2743 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2744 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2745 pvr_get_current_channelname (mpctx->stream),
2746 pvr_get_current_frequency (mpctx->stream));
2748 #endif /* CONFIG_PVR */
2749 break;
2751 case MP_CMD_TV_SET_NORM:
2752 if (mpctx->file_format == DEMUXER_TYPE_TV)
2753 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2754 cmd->args[0].v.s);
2755 break;
2757 case MP_CMD_TV_STEP_CHANNEL:{
2758 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2759 int v = cmd->args[0].v.i;
2760 if (v > 0) {
2761 tv_step_channel((tvi_handle_t *) (mpctx->
2762 demuxer->priv),
2763 TV_CHANNEL_HIGHER);
2764 } else {
2765 tv_step_channel((tvi_handle_t *) (mpctx->
2766 demuxer->priv),
2767 TV_CHANNEL_LOWER);
2769 if (tv_channel_list) {
2770 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2771 MSGTR_OSDChannel, tv_channel_current->name);
2772 //vo_osd_changed(OSDTYPE_SUBTITLE);
2775 #ifdef CONFIG_PVR
2776 else if (mpctx->stream &&
2777 mpctx->stream->type == STREAMTYPE_PVR) {
2778 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2779 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2780 pvr_get_current_channelname (mpctx->stream),
2781 pvr_get_current_stationname (mpctx->stream));
2783 #endif /* CONFIG_PVR */
2785 #ifdef CONFIG_DVBIN
2786 if (mpctx->stream->type == STREAMTYPE_DVB) {
2787 int dir;
2788 int v = cmd->args[0].v.i;
2790 mpctx->last_dvb_step = v;
2791 if (v > 0)
2792 dir = DVB_CHANNEL_HIGHER;
2793 else
2794 dir = DVB_CHANNEL_LOWER;
2797 if (dvb_step_channel(mpctx->stream, dir))
2798 mpctx->eof = mpctx->dvbin_reopen = 1;
2800 #endif /* CONFIG_DVBIN */
2801 break;
2803 case MP_CMD_TV_SET_CHANNEL:
2804 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2805 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2806 cmd->args[0].v.s);
2807 if (tv_channel_list) {
2808 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2809 MSGTR_OSDChannel, tv_channel_current->name);
2810 //vo_osd_changed(OSDTYPE_SUBTITLE);
2813 #ifdef CONFIG_PVR
2814 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2815 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2816 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2817 pvr_get_current_channelname (mpctx->stream),
2818 pvr_get_current_stationname (mpctx->stream));
2820 #endif /* CONFIG_PVR */
2821 break;
2823 #ifdef CONFIG_DVBIN
2824 case MP_CMD_DVB_SET_CHANNEL:
2825 if (mpctx->stream->type == STREAMTYPE_DVB) {
2826 mpctx->last_dvb_step = 1;
2828 if (dvb_set_channel
2829 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2830 mpctx->eof = mpctx->dvbin_reopen = 1;
2832 break;
2833 #endif /* CONFIG_DVBIN */
2835 case MP_CMD_TV_LAST_CHANNEL:
2836 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2837 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2838 if (tv_channel_list) {
2839 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2840 MSGTR_OSDChannel, tv_channel_current->name);
2841 //vo_osd_changed(OSDTYPE_SUBTITLE);
2844 #ifdef CONFIG_PVR
2845 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2846 pvr_set_lastchannel (mpctx->stream);
2847 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2848 pvr_get_current_channelname (mpctx->stream),
2849 pvr_get_current_stationname (mpctx->stream));
2851 #endif /* CONFIG_PVR */
2852 break;
2854 case MP_CMD_TV_STEP_NORM:
2855 if (mpctx->file_format == DEMUXER_TYPE_TV)
2856 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2857 break;
2859 case MP_CMD_TV_STEP_CHANNEL_LIST:
2860 if (mpctx->file_format == DEMUXER_TYPE_TV)
2861 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2862 break;
2863 #ifdef CONFIG_TV_TELETEXT
2864 case MP_CMD_TV_TELETEXT_ADD_DEC:
2866 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2867 if (mpctx->file_format == DEMUXER_TYPE_TV)
2868 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2869 break;
2871 case MP_CMD_TV_TELETEXT_GO_LINK:
2873 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2874 if (mpctx->file_format == DEMUXER_TYPE_TV)
2875 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2876 break;
2878 #endif /* CONFIG_TV_TELETEXT */
2879 #endif /* CONFIG_TV */
2881 case MP_CMD_SUB_LOAD:
2882 if (sh_video) {
2883 int n = mpctx->set_of_sub_size;
2884 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2885 if (n != mpctx->set_of_sub_size) {
2886 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2887 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2888 mpctx->global_sub_size;
2889 ++mpctx->global_sub_size;
2892 break;
2894 case MP_CMD_SUB_REMOVE:
2895 if (sh_video) {
2896 int v = cmd->args[0].v.i;
2897 sub_data *subd;
2898 if (v < 0) {
2899 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2900 subd = mpctx->set_of_subtitles[v];
2901 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2902 MSGTR_RemovedSubtitleFile, v + 1,
2903 filename_recode(subd->filename));
2904 sub_free(subd);
2905 mpctx->set_of_subtitles[v] = NULL;
2907 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2908 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2909 mpctx->set_of_sub_size = 0;
2910 if (mpctx->set_of_sub_pos >= 0) {
2911 mpctx->global_sub_pos = -2;
2912 subdata = NULL;
2913 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2915 } else if (v < mpctx->set_of_sub_size) {
2916 subd = mpctx->set_of_subtitles[v];
2917 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2918 MSGTR_RemovedSubtitleFile, v + 1,
2919 filename_recode(subd->filename));
2920 sub_free(subd);
2921 if (mpctx->set_of_sub_pos == v) {
2922 mpctx->global_sub_pos = -2;
2923 subdata = NULL;
2924 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2925 } else if (mpctx->set_of_sub_pos > v) {
2926 --mpctx->set_of_sub_pos;
2927 --mpctx->global_sub_pos;
2929 while (++v < mpctx->set_of_sub_size)
2930 mpctx->set_of_subtitles[v - 1] =
2931 mpctx->set_of_subtitles[v];
2932 --mpctx->set_of_sub_size;
2933 --mpctx->global_sub_size;
2934 if (mpctx->set_of_sub_size <= 0)
2935 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2936 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2939 break;
2941 case MP_CMD_GET_SUB_VISIBILITY:
2942 if (sh_video) {
2943 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2944 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2946 break;
2948 case MP_CMD_SCREENSHOT:
2949 if (vo_config_count) {
2950 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2951 if (CONTROL_OK !=
2952 ((vf_instance_t *) sh_video->vfilter)->
2953 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2954 &cmd->args[0].v.i))
2955 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2957 break;
2959 case MP_CMD_VF_CHANGE_RECTANGLE:
2960 if (!sh_video)
2961 break;
2962 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2963 break;
2965 case MP_CMD_GET_TIME_LENGTH:{
2966 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2967 demuxer_get_time_length(mpctx->demuxer));
2969 break;
2971 case MP_CMD_GET_FILENAME:{
2972 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2973 get_metadata(META_NAME));
2975 break;
2977 case MP_CMD_GET_VIDEO_CODEC:{
2978 char *inf = get_metadata(META_VIDEO_CODEC);
2979 if (!inf)
2980 inf = strdup("");
2981 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2982 free(inf);
2984 break;
2986 case MP_CMD_GET_VIDEO_BITRATE:{
2987 char *inf = get_metadata(META_VIDEO_BITRATE);
2988 if (!inf)
2989 inf = strdup("");
2990 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2991 free(inf);
2993 break;
2995 case MP_CMD_GET_VIDEO_RESOLUTION:{
2996 char *inf = get_metadata(META_VIDEO_RESOLUTION);
2997 if (!inf)
2998 inf = strdup("");
2999 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3000 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3001 free(inf);
3003 break;
3005 case MP_CMD_GET_AUDIO_CODEC:{
3006 char *inf = get_metadata(META_AUDIO_CODEC);
3007 if (!inf)
3008 inf = strdup("");
3009 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3010 free(inf);
3012 break;
3014 case MP_CMD_GET_AUDIO_BITRATE:{
3015 char *inf = get_metadata(META_AUDIO_BITRATE);
3016 if (!inf)
3017 inf = strdup("");
3018 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3019 free(inf);
3021 break;
3023 case MP_CMD_GET_AUDIO_SAMPLES:{
3024 char *inf = get_metadata(META_AUDIO_SAMPLES);
3025 if (!inf)
3026 inf = strdup("");
3027 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3028 free(inf);
3030 break;
3032 case MP_CMD_GET_META_TITLE:{
3033 char *inf = get_metadata(META_INFO_TITLE);
3034 if (!inf)
3035 inf = strdup("");
3036 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3037 free(inf);
3039 break;
3041 case MP_CMD_GET_META_ARTIST:{
3042 char *inf = get_metadata(META_INFO_ARTIST);
3043 if (!inf)
3044 inf = strdup("");
3045 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3046 free(inf);
3048 break;
3050 case MP_CMD_GET_META_ALBUM:{
3051 char *inf = get_metadata(META_INFO_ALBUM);
3052 if (!inf)
3053 inf = strdup("");
3054 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3055 free(inf);
3057 break;
3059 case MP_CMD_GET_META_YEAR:{
3060 char *inf = get_metadata(META_INFO_YEAR);
3061 if (!inf)
3062 inf = strdup("");
3063 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3064 free(inf);
3066 break;
3068 case MP_CMD_GET_META_COMMENT:{
3069 char *inf = get_metadata(META_INFO_COMMENT);
3070 if (!inf)
3071 inf = strdup("");
3072 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3073 free(inf);
3075 break;
3077 case MP_CMD_GET_META_TRACK:{
3078 char *inf = get_metadata(META_INFO_TRACK);
3079 if (!inf)
3080 inf = strdup("");
3081 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3082 free(inf);
3084 break;
3086 case MP_CMD_GET_META_GENRE:{
3087 char *inf = get_metadata(META_INFO_GENRE);
3088 if (!inf)
3089 inf = strdup("");
3090 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3091 free(inf);
3093 break;
3095 case MP_CMD_GET_VO_FULLSCREEN:
3096 if (mpctx->video_out && vo_config_count)
3097 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3098 break;
3100 case MP_CMD_GET_PERCENT_POS:
3101 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3102 demuxer_get_percent_pos(mpctx->demuxer));
3103 break;
3105 case MP_CMD_GET_TIME_POS:{
3106 float pos = 0;
3107 if (sh_video)
3108 pos = sh_video->pts;
3109 else if (sh_audio && mpctx->audio_out)
3110 pos =
3111 playing_audio_pts(sh_audio, mpctx->d_audio,
3112 mpctx->audio_out);
3113 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3115 break;
3117 case MP_CMD_RUN:
3118 #ifndef __MINGW32__
3119 if (!fork()) {
3120 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3121 exit(0);
3123 #endif
3124 break;
3126 case MP_CMD_KEYDOWN_EVENTS:
3127 mplayer_put_key(cmd->args[0].v.i);
3128 break;
3130 case MP_CMD_SET_MOUSE_POS:{
3131 int pointer_x, pointer_y;
3132 double dx, dy;
3133 pointer_x = cmd->args[0].v.i;
3134 pointer_y = cmd->args[1].v.i;
3135 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
3136 #ifdef CONFIG_DVDNAV
3137 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3138 && dx > 0.0 && dy > 0.0) {
3139 int button = -1;
3140 pointer_x = (int) (dx * (double) sh_video->disp_w);
3141 pointer_y = (int) (dy * (double) sh_video->disp_h);
3142 mp_dvdnav_update_mouse_pos(mpctx->stream,
3143 pointer_x, pointer_y, &button);
3144 if (osd_level > 1 && button > 0)
3145 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3146 "Selected button number %d", button);
3148 #endif
3149 #ifdef CONFIG_MENU
3150 if (use_menu && dx >= 0.0 && dy >= 0.0)
3151 menu_update_mouse_pos(dx, dy);
3152 #endif
3154 break;
3156 #ifdef CONFIG_DVDNAV
3157 case MP_CMD_DVDNAV:{
3158 int button = -1;
3159 int i;
3160 mp_command_type command = 0;
3161 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3162 break;
3164 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3165 if (cmd->args[0].v.s &&
3166 !strcasecmp (cmd->args[0].v.s,
3167 mp_dvdnav_bindings[i].name))
3168 command = mp_dvdnav_bindings[i].cmd;
3170 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3171 if (osd_level > 1 && button > 0)
3172 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3173 "Selected button number %d", button);
3175 break;
3177 case MP_CMD_SWITCH_TITLE:
3178 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3179 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3180 break;
3182 #endif
3184 default:
3185 #ifdef CONFIG_GUI
3186 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3187 guiGetEvent(guiIEvent, (char *) cmd->id);
3188 else
3189 #endif
3190 mp_msg(MSGT_CPLAYER, MSGL_V,
3191 "Received unknown cmd %s\n", cmd->name);
3194 switch (cmd->pausing) {
3195 case 1: // "pausing"
3196 mpctx->osd_function = OSD_PAUSE;
3197 break;
3198 case 3: // "pausing_toggle"
3199 mpctx->was_paused = !mpctx->was_paused;
3200 if (mpctx->was_paused)
3201 mpctx->osd_function = OSD_PAUSE;
3202 else if (mpctx->osd_function == OSD_PAUSE)
3203 mpctx->osd_function = OSD_PLAY;
3204 break;
3205 case 2: // "pausing_keep"
3206 if (mpctx->was_paused)
3207 mpctx->osd_function = OSD_PAUSE;
3209 return brk_cmd;