Explicitly include inttypes.h in ad_imaadpcm
[mplayer/glamo.git] / command.c
blob675b5977f389420f574030f11b9393528b64ebf2
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 #ifdef USE_TV
32 #include "stream/tv.h"
33 #endif
34 #ifdef USE_RADIO
35 #include "stream/stream_radio.h"
36 #endif
37 #ifdef HAVE_PVR
38 #include "stream/pvr.h"
39 #endif
40 #ifdef HAS_DVBIN_SUPPORT
41 #include "stream/dvbin.h"
42 #endif
43 #ifdef USE_DVDREAD
44 #include "stream/stream_dvd.h"
45 #endif
46 #ifdef USE_DVDNAV
47 #include "stream/stream_dvdnav.h"
48 #endif
49 #ifdef USE_ASS
50 #include "libass/ass.h"
51 #include "libass/ass_mp.h"
52 #endif
53 #ifdef HAVE_MENU
54 #include "m_struct.h"
55 #include "libmenu/menu.h"
56 #endif
57 #ifdef HAVE_NEW_GUI
58 #include "gui/interface.h"
59 #endif
61 #include "mp_core.h"
62 #include "mp_fifo.h"
63 #include "libavutil/avstring.h"
65 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
67 extern int use_menu;
69 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy)
71 //remove the borders, if any, and rescale to the range [0,1],[0,1]
72 if (vo_fs) { //we are in full-screen mode
73 if (vo_screenwidth > vo_dwidth) //there are borders along the x axis
74 ix -= (vo_screenwidth - vo_dwidth) / 2;
75 if (vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
76 iy -= (vo_screenheight - vo_dheight) / 2;
78 if (ix < 0 || ix > vo_dwidth) {
79 *dx = *dy = -1.0;
80 return;
81 } //we are on one of the borders
82 if (iy < 0 || iy > vo_dheight) {
83 *dx = *dy = -1.0;
84 return;
85 } //we are on one of the borders
88 *dx = (double) ix / (double) vo_dwidth;
89 *dy = (double) iy / (double) vo_dheight;
91 mp_msg(MSGT_CPLAYER, MSGL_V,
92 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
93 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth,
94 vo_dheight, vo_fs);
97 static int sub_source_by_pos(MPContext * mpctx, int pos)
99 int source = -1;
100 int top = -1;
101 int i;
102 for (i = 0; i < SUB_SOURCES; i++) {
103 int j = mpctx->global_sub_indices[i];
104 if ((j >= 0) && (j > top) && (pos >= j)) {
105 source = i;
106 top = j;
109 return source;
112 static int sub_source(MPContext * mpctx)
114 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
118 * \brief Log the currently displayed subtitle to a file
120 * Logs the current or last displayed subtitle together with filename
121 * and time information to ~/.mplayer/subtitle_log
123 * Intended purpose is to allow convenient marking of bogus subtitles
124 * which need to be fixed while watching the movie.
127 static void log_sub(void)
129 char *fname;
130 FILE *f;
131 int i;
133 if (subdata == NULL || vo_sub_last == NULL)
134 return;
135 fname = get_path("subtitle_log");
136 f = fopen(fname, "a");
137 if (!f)
138 return;
139 fprintf(f, "----------------------------------------------------------\n");
140 if (subdata->sub_uses_time) {
141 fprintf(f,
142 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
143 filename, vo_sub_last->start / 360000,
144 (vo_sub_last->start / 6000) % 60,
145 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
146 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
147 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
148 } else {
149 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start,
150 vo_sub_last->end);
152 for (i = 0; i < vo_sub_last->lines; i++) {
153 fprintf(f, "%s\n", vo_sub_last->text[i]);
155 fclose(f);
159 /// \defgroup Properties
160 ///@{
162 /// \defgroup GeneralProperties General properties
163 /// \ingroup Properties
164 ///@{
166 /// OSD level (RW)
167 static int mp_property_osdlevel(m_option_t * prop, int action, void *arg,
168 MPContext * mpctx)
170 return m_property_choice(prop, action, arg, &osd_level);
173 /// Loop (RW)
174 static int mp_property_loop(m_option_t * prop, int action, void *arg,
175 MPContext * mpctx)
177 switch (action) {
178 case M_PROPERTY_PRINT:
179 if (!arg) return M_PROPERTY_ERROR;
180 if (mpctx->loop_times < 0)
181 *(char**)arg = strdup("off");
182 else if (mpctx->loop_times == 0)
183 *(char**)arg = strdup("inf");
184 else
185 break;
186 return M_PROPERTY_OK;
188 return m_property_int_range(prop, action, arg, &mpctx->loop_times);
191 /// Playback speed (RW)
192 static int mp_property_playback_speed(m_option_t * prop, int action,
193 void *arg, MPContext * mpctx)
195 switch (action) {
196 case M_PROPERTY_SET:
197 if (!arg)
198 return M_PROPERTY_ERROR;
199 M_PROPERTY_CLAMP(prop, *(float *) arg);
200 playback_speed = *(float *) arg;
201 build_afilter_chain(mpctx->sh_audio, &ao_data);
202 return M_PROPERTY_OK;
203 case M_PROPERTY_STEP_UP:
204 case M_PROPERTY_STEP_DOWN:
205 playback_speed += (arg ? *(float *) arg : 0.1) *
206 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
207 M_PROPERTY_CLAMP(prop, playback_speed);
208 build_afilter_chain(mpctx->sh_audio, &ao_data);
209 return M_PROPERTY_OK;
211 return m_property_float_range(prop, action, arg, &playback_speed);
214 /// filename with path (RO)
215 static int mp_property_path(m_option_t * prop, int action, void *arg,
216 MPContext * mpctx)
218 return m_property_string_ro(prop, action, arg, filename);
221 /// filename without path (RO)
222 static int mp_property_filename(m_option_t * prop, int action, void *arg,
223 MPContext * mpctx)
225 char *f;
226 if (!filename)
227 return M_PROPERTY_UNAVAILABLE;
228 if (((f = strrchr(filename, '/')) || (f = strrchr(filename, '\\'))) && f[1])
229 f++;
230 else
231 f = filename;
232 return m_property_string_ro(prop, action, arg, f);
235 /// Demuxer name (RO)
236 static int mp_property_demuxer(m_option_t * prop, int action, void *arg,
237 MPContext * mpctx)
239 if (!mpctx->demuxer)
240 return M_PROPERTY_UNAVAILABLE;
241 return m_property_string_ro(prop, action, arg,
242 (char *) mpctx->demuxer->desc->name);
245 /// Position in the stream (RW)
246 static int mp_property_stream_pos(m_option_t * prop, int action, void *arg,
247 MPContext * mpctx)
249 if (!mpctx->demuxer || !mpctx->demuxer->stream)
250 return M_PROPERTY_UNAVAILABLE;
251 if (!arg)
252 return M_PROPERTY_ERROR;
253 switch (action) {
254 case M_PROPERTY_GET:
255 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
256 return M_PROPERTY_OK;
257 case M_PROPERTY_SET:
258 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
259 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
260 return M_PROPERTY_OK;
262 return M_PROPERTY_NOT_IMPLEMENTED;
265 /// Stream start offset (RO)
266 static int mp_property_stream_start(m_option_t * prop, int action,
267 void *arg, 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->start_pos;
274 return M_PROPERTY_OK;
276 return M_PROPERTY_NOT_IMPLEMENTED;
279 /// Stream end offset (RO)
280 static int mp_property_stream_end(m_option_t * prop, int action, void *arg,
281 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 = mpctx->demuxer->stream->end_pos;
288 return M_PROPERTY_OK;
290 return M_PROPERTY_NOT_IMPLEMENTED;
293 /// Stream length (RO)
294 static int mp_property_stream_length(m_option_t * prop, int action,
295 void *arg, MPContext * mpctx)
297 if (!mpctx->demuxer || !mpctx->demuxer->stream)
298 return M_PROPERTY_UNAVAILABLE;
299 switch (action) {
300 case M_PROPERTY_GET:
301 *(off_t *) arg =
302 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
303 return M_PROPERTY_OK;
305 return M_PROPERTY_NOT_IMPLEMENTED;
308 /// Media length in seconds (RO)
309 static int mp_property_length(m_option_t * prop, int action, void *arg,
310 MPContext * mpctx)
312 double len;
314 if (!mpctx->demuxer ||
315 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
316 return M_PROPERTY_UNAVAILABLE;
318 return m_property_time_ro(prop, action, arg, len);
321 /// Current position in percent (RW)
322 static int mp_property_percent_pos(m_option_t * prop, int action,
323 void *arg, MPContext * mpctx) {
324 int pos;
326 if (!mpctx->demuxer)
327 return M_PROPERTY_UNAVAILABLE;
329 switch(action) {
330 case M_PROPERTY_SET:
331 if(!arg) return M_PROPERTY_ERROR;
332 M_PROPERTY_CLAMP(prop, *(int*)arg);
333 pos = *(int*)arg;
334 break;
335 case M_PROPERTY_STEP_UP:
336 case M_PROPERTY_STEP_DOWN:
337 pos = demuxer_get_percent_pos(mpctx->demuxer);
338 pos += (arg ? *(int*)arg : 10) *
339 (action == M_PROPERTY_STEP_UP ? 1 : -1);
340 M_PROPERTY_CLAMP(prop, pos);
341 break;
342 default:
343 return m_property_int_ro(prop, action, arg,
344 demuxer_get_percent_pos(mpctx->demuxer));
347 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
348 rel_seek_secs = pos / 100.0;
349 return M_PROPERTY_OK;
352 /// Current position in seconds (RW)
353 static int mp_property_time_pos(m_option_t * prop, int action,
354 void *arg, MPContext * mpctx) {
355 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
356 return M_PROPERTY_UNAVAILABLE;
358 switch(action) {
359 case M_PROPERTY_SET:
360 if(!arg) return M_PROPERTY_ERROR;
361 M_PROPERTY_CLAMP(prop, *(double*)arg);
362 abs_seek_pos = SEEK_ABSOLUTE;
363 rel_seek_secs = *(double*)arg;
364 return M_PROPERTY_OK;
365 case M_PROPERTY_STEP_UP:
366 case M_PROPERTY_STEP_DOWN:
367 rel_seek_secs += (arg ? *(double*)arg : 10.0) *
368 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
369 return M_PROPERTY_OK;
371 return m_property_time_ro(prop, action, arg,
372 mpctx->sh_video ? mpctx->sh_video->pts :
373 playing_audio_pts(mpctx->sh_audio,
374 mpctx->d_audio,
375 mpctx->audio_out));
378 /// Current chapter (RW)
379 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
380 MPContext *mpctx)
382 int chapter;
383 float next_pts = 0;
384 int chapter_num;
385 int step_all;
386 char *chapter_name = NULL;
388 chapter = demuxer_get_current_chapter(mpctx->demuxer);
389 if (chapter < 0)
390 return M_PROPERTY_UNAVAILABLE;
392 switch (action) {
393 case M_PROPERTY_GET:
394 if (!arg)
395 return M_PROPERTY_ERROR;
396 *(int *) arg = chapter;
397 return M_PROPERTY_OK;
398 case M_PROPERTY_PRINT: {
399 if (!arg)
400 return M_PROPERTY_ERROR;
401 chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter);
402 if (!chapter_name)
403 return M_PROPERTY_UNAVAILABLE;
404 *(char **) arg = chapter_name;
405 return M_PROPERTY_OK;
407 case M_PROPERTY_SET:
408 if (!arg)
409 return M_PROPERTY_ERROR;
410 M_PROPERTY_CLAMP(prop, *(int*)arg);
411 step_all = *(int *)arg - (chapter + 1);
412 chapter += step_all;
413 break;
414 case M_PROPERTY_STEP_UP:
415 case M_PROPERTY_STEP_DOWN: {
416 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
417 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
418 chapter += step_all;
419 if (chapter < 0)
420 chapter = 0;
421 break;
423 default:
424 return M_PROPERTY_NOT_IMPLEMENTED;
426 rel_seek_secs = 0;
427 abs_seek_pos = 0;
428 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
429 &next_pts, &chapter_num, &chapter_name);
430 if (chapter >= 0) {
431 if (next_pts > -1.0) {
432 abs_seek_pos = SEEK_ABSOLUTE;
433 rel_seek_secs = next_pts;
435 if (chapter_name)
436 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
437 MSGTR_OSDChapter, chapter + 1, chapter_name);
439 else if (step_all > 0)
440 rel_seek_secs = 1000000000.;
441 else
442 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
443 MSGTR_OSDChapter, 0, MSGTR_Unknown);
444 if (chapter_name)
445 free(chapter_name);
446 return M_PROPERTY_OK;
449 /// Current dvd angle (RW)
450 static int mp_property_angle(m_option_t *prop, int action, void *arg,
451 MPContext *mpctx)
453 int angle;
454 int angles;
455 char *angle_name = NULL;
457 angle = demuxer_get_current_angle(mpctx->demuxer);
458 if (angle < 0)
459 return M_PROPERTY_UNAVAILABLE;
460 angles = demuxer_angles_count(mpctx->demuxer);
461 if (angles <= 1)
462 return M_PROPERTY_UNAVAILABLE;
464 switch (action) {
465 case M_PROPERTY_GET:
466 if (!arg)
467 return M_PROPERTY_ERROR;
468 *(int *) arg = angle;
469 return M_PROPERTY_OK;
470 case M_PROPERTY_PRINT: {
471 if (!arg)
472 return M_PROPERTY_ERROR;
473 angle_name = calloc(1, 64);
474 if (!angle_name)
475 return M_PROPERTY_UNAVAILABLE;
476 snprintf(angle_name, 64, "%d/%d", angle, angles);
477 *(char **) arg = angle_name;
478 return M_PROPERTY_OK;
480 case M_PROPERTY_SET:
481 if (!arg)
482 return M_PROPERTY_ERROR;
483 angle = *(int *)arg;
484 M_PROPERTY_CLAMP(prop, angle);
485 break;
486 case M_PROPERTY_STEP_UP:
487 case M_PROPERTY_STEP_DOWN: {
488 int step = 0;
489 if(arg)
490 step = *(int*)arg;
491 if(!step)
492 step = 1;
493 step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
494 angle += step;
495 if (angle < 1) //cycle
496 angle = angles;
497 break;
499 default:
500 return M_PROPERTY_NOT_IMPLEMENTED;
502 angle = demuxer_set_angle(mpctx->demuxer, angle);
503 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
504 MSGTR_OSDAngle, angle, angles);
505 if (angle_name)
506 free(angle_name);
507 return M_PROPERTY_OK;
510 /// Demuxer meta data
511 static int mp_property_metadata(m_option_t * prop, int action, void *arg,
512 MPContext * mpctx) {
513 m_property_action_t* ka;
514 char* meta;
515 static m_option_t key_type =
516 { "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
517 if (!mpctx->demuxer)
518 return M_PROPERTY_UNAVAILABLE;
520 switch(action) {
521 case M_PROPERTY_GET:
522 if(!arg) return M_PROPERTY_ERROR;
523 *(char***)arg = mpctx->demuxer->info;
524 return M_PROPERTY_OK;
525 case M_PROPERTY_KEY_ACTION:
526 if(!arg) return M_PROPERTY_ERROR;
527 ka = arg;
528 if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
529 return M_PROPERTY_UNKNOWN;
530 switch(ka->action) {
531 case M_PROPERTY_GET:
532 if(!ka->arg) return M_PROPERTY_ERROR;
533 *(char**)ka->arg = meta;
534 return M_PROPERTY_OK;
535 case M_PROPERTY_GET_TYPE:
536 if(!ka->arg) return M_PROPERTY_ERROR;
537 *(m_option_t**)ka->arg = &key_type;
538 return M_PROPERTY_OK;
541 return M_PROPERTY_NOT_IMPLEMENTED;
545 ///@}
547 /// \defgroup AudioProperties Audio properties
548 /// \ingroup Properties
549 ///@{
551 /// Volume (RW)
552 static int mp_property_volume(m_option_t * prop, int action, void *arg,
553 MPContext * mpctx)
556 if (!mpctx->sh_audio)
557 return M_PROPERTY_UNAVAILABLE;
559 switch (action) {
560 case M_PROPERTY_GET:
561 if (!arg)
562 return M_PROPERTY_ERROR;
563 mixer_getbothvolume(&mpctx->mixer, arg);
564 return M_PROPERTY_OK;
565 case M_PROPERTY_PRINT:{
566 float vol;
567 if (!arg)
568 return M_PROPERTY_ERROR;
569 mixer_getbothvolume(&mpctx->mixer, &vol);
570 return m_property_float_range(prop, action, arg, &vol);
572 case M_PROPERTY_STEP_UP:
573 case M_PROPERTY_STEP_DOWN:
574 case M_PROPERTY_SET:
575 break;
576 default:
577 return M_PROPERTY_NOT_IMPLEMENTED;
580 if (mpctx->edl_muted)
581 return M_PROPERTY_DISABLED;
582 mpctx->user_muted = 0;
584 switch (action) {
585 case M_PROPERTY_SET:
586 if (!arg)
587 return M_PROPERTY_ERROR;
588 M_PROPERTY_CLAMP(prop, *(float *) arg);
589 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
590 return M_PROPERTY_OK;
591 case M_PROPERTY_STEP_UP:
592 if (arg && *(float *) arg <= 0)
593 mixer_decvolume(&mpctx->mixer);
594 else
595 mixer_incvolume(&mpctx->mixer);
596 return M_PROPERTY_OK;
597 case M_PROPERTY_STEP_DOWN:
598 if (arg && *(float *) arg <= 0)
599 mixer_incvolume(&mpctx->mixer);
600 else
601 mixer_decvolume(&mpctx->mixer);
602 return M_PROPERTY_OK;
604 return M_PROPERTY_NOT_IMPLEMENTED;
607 /// Mute (RW)
608 static int mp_property_mute(m_option_t * prop, int action, void *arg,
609 MPContext * mpctx)
612 if (!mpctx->sh_audio)
613 return M_PROPERTY_UNAVAILABLE;
615 switch (action) {
616 case M_PROPERTY_SET:
617 if (mpctx->edl_muted)
618 return M_PROPERTY_DISABLED;
619 if (!arg)
620 return M_PROPERTY_ERROR;
621 if ((!!*(int *) arg) != mpctx->mixer.muted)
622 mixer_mute(&mpctx->mixer);
623 mpctx->user_muted = mpctx->mixer.muted;
624 return M_PROPERTY_OK;
625 case M_PROPERTY_STEP_UP:
626 case M_PROPERTY_STEP_DOWN:
627 if (mpctx->edl_muted)
628 return M_PROPERTY_DISABLED;
629 mixer_mute(&mpctx->mixer);
630 mpctx->user_muted = mpctx->mixer.muted;
631 return M_PROPERTY_OK;
632 case M_PROPERTY_PRINT:
633 if (!arg)
634 return M_PROPERTY_ERROR;
635 if (mpctx->edl_muted) {
636 *(char **) arg = strdup(MSGTR_EnabledEdl);
637 return M_PROPERTY_OK;
639 default:
640 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
645 /// Audio delay (RW)
646 static int mp_property_audio_delay(m_option_t * prop, int action,
647 void *arg, MPContext * mpctx)
649 if (!(mpctx->sh_audio && mpctx->sh_video))
650 return M_PROPERTY_UNAVAILABLE;
651 switch (action) {
652 case M_PROPERTY_SET:
653 case M_PROPERTY_STEP_UP:
654 case M_PROPERTY_STEP_DOWN: {
655 int ret;
656 float delay = audio_delay;
657 ret = m_property_delay(prop, action, arg, &audio_delay);
658 if (ret != M_PROPERTY_OK)
659 return ret;
660 if (mpctx->sh_audio)
661 mpctx->delay -= audio_delay - delay;
663 return M_PROPERTY_OK;
664 default:
665 return m_property_delay(prop, action, arg, &audio_delay);
669 /// Audio codec tag (RO)
670 static int mp_property_audio_format(m_option_t * prop, int action,
671 void *arg, MPContext * mpctx)
673 if (!mpctx->sh_audio)
674 return M_PROPERTY_UNAVAILABLE;
675 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
678 /// Audio codec name (RO)
679 static int mp_property_audio_codec(m_option_t * prop, int action,
680 void *arg, MPContext * mpctx)
682 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
683 return M_PROPERTY_UNAVAILABLE;
684 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
687 /// Audio bitrate (RO)
688 static int mp_property_audio_bitrate(m_option_t * prop, int action,
689 void *arg, MPContext * mpctx)
691 if (!mpctx->sh_audio)
692 return M_PROPERTY_UNAVAILABLE;
693 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
696 /// Samplerate (RO)
697 static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
698 MPContext * mpctx)
700 if (!mpctx->sh_audio)
701 return M_PROPERTY_UNAVAILABLE;
702 switch(action) {
703 case M_PROPERTY_PRINT:
704 if(!arg) return M_PROPERTY_ERROR;
705 *(char**)arg = malloc(16);
706 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
707 return M_PROPERTY_OK;
709 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
712 /// Number of channels (RO)
713 static int mp_property_channels(m_option_t * prop, int action, void *arg,
714 MPContext * mpctx)
716 if (!mpctx->sh_audio)
717 return M_PROPERTY_UNAVAILABLE;
718 switch (action) {
719 case M_PROPERTY_PRINT:
720 if (!arg)
721 return M_PROPERTY_ERROR;
722 switch (mpctx->sh_audio->channels) {
723 case 1:
724 *(char **) arg = strdup("mono");
725 break;
726 case 2:
727 *(char **) arg = strdup("stereo");
728 break;
729 default:
730 *(char **) arg = malloc(32);
731 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
733 return M_PROPERTY_OK;
735 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
738 /// Balance (RW)
739 static int mp_property_balance(m_option_t * prop, int action, void *arg,
740 MPContext * mpctx)
742 float bal;
744 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
745 return M_PROPERTY_UNAVAILABLE;
747 switch (action) {
748 case M_PROPERTY_GET:
749 if (!arg)
750 return M_PROPERTY_ERROR;
751 mixer_getbalance(&mpctx->mixer, arg);
752 return M_PROPERTY_OK;
753 case M_PROPERTY_PRINT: {
754 char** str = arg;
755 if (!arg)
756 return M_PROPERTY_ERROR;
757 mixer_getbalance(&mpctx->mixer, &bal);
758 if (bal == 0.f)
759 *str = strdup("center");
760 else if (bal == -1.f)
761 *str = strdup("left only");
762 else if (bal == 1.f)
763 *str = strdup("right only");
764 else {
765 unsigned right = (bal + 1.f) / 2.f * 100.f;
766 *str = malloc(sizeof("left xxx%, right xxx%"));
767 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
769 return M_PROPERTY_OK;
771 case M_PROPERTY_STEP_UP:
772 case M_PROPERTY_STEP_DOWN:
773 mixer_getbalance(&mpctx->mixer, &bal);
774 bal += (arg ? *(float*)arg : .1f) *
775 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
776 M_PROPERTY_CLAMP(prop, bal);
777 mixer_setbalance(&mpctx->mixer, bal);
778 return M_PROPERTY_OK;
779 case M_PROPERTY_SET:
780 if (!arg)
781 return M_PROPERTY_ERROR;
782 M_PROPERTY_CLAMP(prop, *(float*)arg);
783 mixer_setbalance(&mpctx->mixer, *(float*)arg);
784 return M_PROPERTY_OK;
786 return M_PROPERTY_NOT_IMPLEMENTED;
789 /// Selected audio id (RW)
790 static int mp_property_audio(m_option_t * prop, int action, void *arg,
791 MPContext * mpctx)
793 int current_id = -1, tmp;
795 switch (action) {
796 case M_PROPERTY_GET:
797 if (!mpctx->sh_audio)
798 return M_PROPERTY_UNAVAILABLE;
799 if (!arg)
800 return M_PROPERTY_ERROR;
801 *(int *) arg = audio_id;
802 return M_PROPERTY_OK;
803 case M_PROPERTY_PRINT:
804 if (!mpctx->sh_audio)
805 return M_PROPERTY_UNAVAILABLE;
806 if (!arg)
807 return M_PROPERTY_ERROR;
809 if (audio_id < 0)
810 *(char **) arg = strdup(MSGTR_Disabled);
811 else {
812 char lang[40] = MSGTR_Unknown;
813 sh_audio_t* sh = mpctx->sh_audio;
814 if (sh && sh->lang)
815 av_strlcpy(lang, sh->lang, 40);
816 #ifdef USE_DVDREAD
817 else if (mpctx->stream->type == STREAMTYPE_DVD) {
818 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
819 if (code) {
820 lang[0] = code >> 8;
821 lang[1] = code;
822 lang[2] = 0;
825 #endif
827 #ifdef USE_DVDNAV
828 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
829 mp_dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
830 #endif
831 *(char **) arg = malloc(64);
832 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
834 return M_PROPERTY_OK;
836 case M_PROPERTY_STEP_UP:
837 case M_PROPERTY_SET:
838 if (action == M_PROPERTY_SET && arg)
839 tmp = *((int *) arg);
840 else
841 tmp = -1;
842 current_id = mpctx->demuxer->audio->id;
843 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
844 if (audio_id == -2
845 || (audio_id > -1
846 && mpctx->demuxer->audio->id != current_id && current_id != -2))
847 uninit_player(INITIALIZED_AO | INITIALIZED_ACODEC);
848 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
849 sh_audio_t *sh2;
850 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
851 if (sh2) {
852 sh2->ds = mpctx->demuxer->audio;
853 mpctx->sh_audio = sh2;
854 reinit_audio_chain();
857 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
858 return M_PROPERTY_OK;
859 default:
860 return M_PROPERTY_NOT_IMPLEMENTED;
865 /// Selected video id (RW)
866 static int mp_property_video(m_option_t * prop, int action, void *arg,
867 MPContext * mpctx)
869 int current_id = -1, tmp;
871 switch (action) {
872 case M_PROPERTY_GET:
873 if (!mpctx->sh_video)
874 return M_PROPERTY_UNAVAILABLE;
875 if (!arg)
876 return M_PROPERTY_ERROR;
877 *(int *) arg = video_id;
878 return M_PROPERTY_OK;
879 case M_PROPERTY_PRINT:
880 if (!mpctx->sh_video)
881 return M_PROPERTY_UNAVAILABLE;
882 if (!arg)
883 return M_PROPERTY_ERROR;
885 if (video_id < 0)
886 *(char **) arg = strdup(MSGTR_Disabled);
887 else {
888 char lang[40] = MSGTR_Unknown;
889 *(char **) arg = malloc(64);
890 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
892 return M_PROPERTY_OK;
894 case M_PROPERTY_STEP_UP:
895 case M_PROPERTY_SET:
896 current_id = mpctx->demuxer->video->id;
897 if (action == M_PROPERTY_SET && arg)
898 tmp = *((int *) arg);
899 else
900 tmp = -1;
901 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
902 if (video_id == -2
903 || (video_id > -1 && mpctx->demuxer->video->id != current_id
904 && current_id != -2))
905 uninit_player(INITIALIZED_VCODEC |
906 (fixed_vo && video_id != -2 ? 0 : INITIALIZED_VO));
907 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
908 sh_video_t *sh2;
909 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
910 if (sh2) {
911 sh2->ds = mpctx->demuxer->video;
912 mpctx->sh_video = sh2;
913 reinit_video_chain();
916 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
917 return M_PROPERTY_OK;
919 default:
920 return M_PROPERTY_NOT_IMPLEMENTED;
924 static int mp_property_program(m_option_t * prop, int action, void *arg,
925 MPContext * mpctx)
927 demux_program_t prog;
929 switch (action) {
930 case M_PROPERTY_STEP_UP:
931 case M_PROPERTY_SET:
932 if (action == M_PROPERTY_SET && arg)
933 prog.progid = *((int *) arg);
934 else
935 prog.progid = -1;
936 if (demux_control
937 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
938 &prog) == DEMUXER_CTRL_NOTIMPL)
939 return M_PROPERTY_ERROR;
941 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
942 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
943 return M_PROPERTY_OK;
945 default:
946 return M_PROPERTY_NOT_IMPLEMENTED;
950 ///@}
952 /// \defgroup VideoProperties Video properties
953 /// \ingroup Properties
954 ///@{
956 /// Fullscreen state (RW)
957 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
958 MPContext * mpctx)
961 if (!mpctx->video_out)
962 return M_PROPERTY_UNAVAILABLE;
964 switch (action) {
965 case M_PROPERTY_SET:
966 if (!arg)
967 return M_PROPERTY_ERROR;
968 M_PROPERTY_CLAMP(prop, *(int *) arg);
969 if (vo_fs == !!*(int *) arg)
970 return M_PROPERTY_OK;
971 case M_PROPERTY_STEP_UP:
972 case M_PROPERTY_STEP_DOWN:
973 #ifdef HAVE_NEW_GUI
974 if (use_gui)
975 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
976 else
977 #endif
978 if (vo_config_count)
979 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
980 return M_PROPERTY_OK;
981 default:
982 return m_property_flag(prop, action, arg, &vo_fs);
986 static int mp_property_deinterlace(m_option_t * prop, int action,
987 void *arg, MPContext * mpctx)
989 int deinterlace;
990 vf_instance_t *vf;
991 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
992 return M_PROPERTY_UNAVAILABLE;
993 vf = mpctx->sh_video->vfilter;
994 switch (action) {
995 case M_PROPERTY_GET:
996 if (!arg)
997 return M_PROPERTY_ERROR;
998 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
999 return M_PROPERTY_OK;
1000 case M_PROPERTY_SET:
1001 if (!arg)
1002 return M_PROPERTY_ERROR;
1003 M_PROPERTY_CLAMP(prop, *(int *) arg);
1004 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1005 return M_PROPERTY_OK;
1006 case M_PROPERTY_STEP_UP:
1007 case M_PROPERTY_STEP_DOWN:
1008 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1009 deinterlace = !deinterlace;
1010 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1011 return M_PROPERTY_OK;
1013 return M_PROPERTY_NOT_IMPLEMENTED;
1016 /// Panscan (RW)
1017 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
1018 MPContext * mpctx)
1021 if (!mpctx->video_out
1022 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1023 return M_PROPERTY_UNAVAILABLE;
1025 switch (action) {
1026 case M_PROPERTY_SET:
1027 if (!arg)
1028 return M_PROPERTY_ERROR;
1029 M_PROPERTY_CLAMP(prop, *(float *) arg);
1030 vo_panscan = *(float *) arg;
1031 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1032 return M_PROPERTY_OK;
1033 case M_PROPERTY_STEP_UP:
1034 case M_PROPERTY_STEP_DOWN:
1035 vo_panscan += (arg ? *(float *) arg : 0.1) *
1036 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1037 if (vo_panscan > 1)
1038 vo_panscan = 1;
1039 else if (vo_panscan < 0)
1040 vo_panscan = 0;
1041 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1042 return M_PROPERTY_OK;
1043 default:
1044 return m_property_float_range(prop, action, arg, &vo_panscan);
1048 /// Helper to set vo flags.
1049 /** \ingroup PropertyImplHelper
1051 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
1052 int vo_ctrl, int *vo_var, MPContext * mpctx)
1055 if (!mpctx->video_out)
1056 return M_PROPERTY_UNAVAILABLE;
1058 switch (action) {
1059 case M_PROPERTY_SET:
1060 if (!arg)
1061 return M_PROPERTY_ERROR;
1062 M_PROPERTY_CLAMP(prop, *(int *) arg);
1063 if (*vo_var == !!*(int *) arg)
1064 return M_PROPERTY_OK;
1065 case M_PROPERTY_STEP_UP:
1066 case M_PROPERTY_STEP_DOWN:
1067 if (vo_config_count)
1068 mpctx->video_out->control(vo_ctrl, 0);
1069 return M_PROPERTY_OK;
1070 default:
1071 return m_property_flag(prop, action, arg, vo_var);
1075 /// Window always on top (RW)
1076 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
1077 MPContext * mpctx)
1079 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
1080 mpctx);
1083 /// Display in the root window (RW)
1084 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
1085 MPContext * mpctx)
1087 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1088 &vo_rootwin, mpctx);
1091 /// Show window borders (RW)
1092 static int mp_property_border(m_option_t * prop, int action, void *arg,
1093 MPContext * mpctx)
1095 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1096 &vo_border, mpctx);
1099 /// Framedropping state (RW)
1100 static int mp_property_framedropping(m_option_t * prop, int action,
1101 void *arg, MPContext * mpctx)
1104 if (!mpctx->sh_video)
1105 return M_PROPERTY_UNAVAILABLE;
1107 switch (action) {
1108 case M_PROPERTY_PRINT:
1109 if (!arg)
1110 return M_PROPERTY_ERROR;
1111 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1112 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1113 MSGTR_Disabled));
1114 return M_PROPERTY_OK;
1115 default:
1116 return m_property_choice(prop, action, arg, &frame_dropping);
1120 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1121 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
1122 MPContext * mpctx)
1124 int *gamma = prop->priv, r, val;
1126 if (!mpctx->sh_video)
1127 return M_PROPERTY_UNAVAILABLE;
1129 if (gamma[0] == 1000) {
1130 gamma[0] = 0;
1131 get_video_colors(mpctx->sh_video, prop->name, gamma);
1134 switch (action) {
1135 case M_PROPERTY_SET:
1136 if (!arg)
1137 return M_PROPERTY_ERROR;
1138 M_PROPERTY_CLAMP(prop, *(int *) arg);
1139 *gamma = *(int *) arg;
1140 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1141 if (r <= 0)
1142 break;
1143 return r;
1144 case M_PROPERTY_GET:
1145 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1146 if (!arg)
1147 return M_PROPERTY_ERROR;
1148 *(int *)arg = val;
1149 return M_PROPERTY_OK;
1151 break;
1152 case M_PROPERTY_STEP_UP:
1153 case M_PROPERTY_STEP_DOWN:
1154 *gamma += (arg ? *(int *) arg : 1) *
1155 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1156 M_PROPERTY_CLAMP(prop, *gamma);
1157 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1158 if (r <= 0)
1159 break;
1160 return r;
1161 default:
1162 return M_PROPERTY_NOT_IMPLEMENTED;
1165 #ifdef USE_TV
1166 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1167 int l = strlen(prop->name);
1168 char tv_prop[3 + l + 1];
1169 sprintf(tv_prop, "tv_%s", prop->name);
1170 return mp_property_do(tv_prop, action, arg, mpctx);
1172 #endif
1174 return M_PROPERTY_UNAVAILABLE;
1177 /// VSync (RW)
1178 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1179 MPContext * mpctx)
1181 return m_property_flag(prop, action, arg, &vo_vsync);
1184 /// Video codec tag (RO)
1185 static int mp_property_video_format(m_option_t * prop, int action,
1186 void *arg, MPContext * mpctx)
1188 char* meta;
1189 if (!mpctx->sh_video)
1190 return M_PROPERTY_UNAVAILABLE;
1191 switch(action) {
1192 case M_PROPERTY_PRINT:
1193 if (!arg)
1194 return M_PROPERTY_ERROR;
1195 switch(mpctx->sh_video->format) {
1196 case 0x10000001:
1197 meta = strdup ("mpeg1"); break;
1198 case 0x10000002:
1199 meta = strdup ("mpeg2"); break;
1200 case 0x10000004:
1201 meta = strdup ("mpeg4"); break;
1202 case 0x10000005:
1203 meta = strdup ("h264"); break;
1204 default:
1205 if(mpctx->sh_video->format >= 0x20202020) {
1206 meta = malloc(5);
1207 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1208 } else {
1209 meta = malloc(20);
1210 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1213 *(char**)arg = meta;
1214 return M_PROPERTY_OK;
1216 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1219 /// Video codec name (RO)
1220 static int mp_property_video_codec(m_option_t * prop, int action,
1221 void *arg, MPContext * mpctx)
1223 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1224 return M_PROPERTY_UNAVAILABLE;
1225 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1229 /// Video bitrate (RO)
1230 static int mp_property_video_bitrate(m_option_t * prop, int action,
1231 void *arg, MPContext * mpctx)
1233 if (!mpctx->sh_video)
1234 return M_PROPERTY_UNAVAILABLE;
1235 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1238 /// Video display width (RO)
1239 static int mp_property_width(m_option_t * prop, int action, void *arg,
1240 MPContext * mpctx)
1242 if (!mpctx->sh_video)
1243 return M_PROPERTY_UNAVAILABLE;
1244 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1247 /// Video display height (RO)
1248 static int mp_property_height(m_option_t * prop, int action, void *arg,
1249 MPContext * mpctx)
1251 if (!mpctx->sh_video)
1252 return M_PROPERTY_UNAVAILABLE;
1253 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1256 /// Video fps (RO)
1257 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1258 MPContext * mpctx)
1260 if (!mpctx->sh_video)
1261 return M_PROPERTY_UNAVAILABLE;
1262 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1265 /// Video aspect (RO)
1266 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1267 MPContext * mpctx)
1269 if (!mpctx->sh_video)
1270 return M_PROPERTY_UNAVAILABLE;
1271 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1274 ///@}
1276 /// \defgroup SubProprties Subtitles properties
1277 /// \ingroup Properties
1278 ///@{
1280 /// Text subtitle position (RW)
1281 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1282 MPContext * mpctx)
1284 if (!mpctx->sh_video)
1285 return M_PROPERTY_UNAVAILABLE;
1287 switch (action) {
1288 case M_PROPERTY_SET:
1289 if (!arg)
1290 return M_PROPERTY_ERROR;
1291 case M_PROPERTY_STEP_UP:
1292 case M_PROPERTY_STEP_DOWN:
1293 vo_osd_changed(OSDTYPE_SUBTITLE);
1294 default:
1295 return m_property_int_range(prop, action, arg, &sub_pos);
1299 /// Selected subtitles (RW)
1300 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1301 MPContext * mpctx)
1303 demux_stream_t *const d_sub = mpctx->d_sub;
1304 const int global_sub_size = mpctx->global_sub_size;
1305 int source = -1, reset_spu = 0;
1306 char *sub_name;
1308 if (global_sub_size <= 0)
1309 return M_PROPERTY_UNAVAILABLE;
1311 switch (action) {
1312 case M_PROPERTY_GET:
1313 if (!arg)
1314 return M_PROPERTY_ERROR;
1315 *(int *) arg = mpctx->global_sub_pos;
1316 return M_PROPERTY_OK;
1317 case M_PROPERTY_PRINT:
1318 if (!arg)
1319 return M_PROPERTY_ERROR;
1320 *(char **) arg = malloc(64);
1321 (*(char **) arg)[63] = 0;
1322 sub_name = 0;
1323 if (subdata)
1324 sub_name = subdata->filename;
1325 #ifdef USE_ASS
1326 if (ass_track && ass_track->name)
1327 sub_name = ass_track->name;
1328 #endif
1329 if (sub_name) {
1330 char *tmp, *tmp2;
1331 tmp = sub_name;
1332 if ((tmp2 = strrchr(tmp, '/')))
1333 tmp = tmp2 + 1;
1335 snprintf(*(char **) arg, 63, "(%d) %s%s",
1336 mpctx->set_of_sub_pos + 1,
1337 strlen(tmp) < 20 ? "" : "...",
1338 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1339 return M_PROPERTY_OK;
1341 #ifdef USE_DVDNAV
1342 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1343 if (vo_spudec && dvdsub_id >= 0) {
1344 unsigned char lang[3];
1345 if (mp_dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1346 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1347 return M_PROPERTY_OK;
1351 #endif
1353 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1354 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1355 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1356 && d_sub && d_sub->sh && dvdsub_id >= 0) {
1357 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1358 if (!lang) lang = MSGTR_Unknown;
1359 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1360 return M_PROPERTY_OK;
1363 if (vo_vobsub && vobsub_id >= 0) {
1364 const char *language = MSGTR_Unknown;
1365 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1366 snprintf(*(char **) arg, 63, "(%d) %s",
1367 vobsub_id, language ? language : MSGTR_Unknown);
1368 return M_PROPERTY_OK;
1370 #ifdef USE_DVDREAD
1371 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1372 && dvdsub_id >= 0) {
1373 char lang[3];
1374 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1375 lang[0] = code >> 8;
1376 lang[1] = code;
1377 lang[2] = 0;
1378 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1379 return M_PROPERTY_OK;
1381 #endif
1382 if (dvdsub_id >= 0) {
1383 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1384 return M_PROPERTY_OK;
1386 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1387 return M_PROPERTY_OK;
1389 case M_PROPERTY_SET:
1390 if (!arg)
1391 return M_PROPERTY_ERROR;
1392 if (*(int *) arg < -1)
1393 *(int *) arg = -1;
1394 else if (*(int *) arg >= global_sub_size)
1395 *(int *) arg = global_sub_size - 1;
1396 mpctx->global_sub_pos = *(int *) arg;
1397 break;
1398 case M_PROPERTY_STEP_UP:
1399 mpctx->global_sub_pos += 2;
1400 mpctx->global_sub_pos =
1401 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1402 break;
1403 case M_PROPERTY_STEP_DOWN:
1404 mpctx->global_sub_pos += global_sub_size + 1;
1405 mpctx->global_sub_pos =
1406 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1407 break;
1408 default:
1409 return M_PROPERTY_NOT_IMPLEMENTED;
1412 if (mpctx->global_sub_pos >= 0)
1413 source = sub_source(mpctx);
1415 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1416 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1417 global_sub_size,
1418 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1419 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1420 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1421 mpctx->global_sub_pos, source);
1423 mpctx->set_of_sub_pos = -1;
1424 subdata = NULL;
1426 vobsub_id = -1;
1427 dvdsub_id = -1;
1428 if (d_sub) {
1429 if (d_sub->id > -2)
1430 reset_spu = 1;
1431 d_sub->id = -2;
1433 #ifdef USE_ASS
1434 ass_track = 0;
1435 #endif
1437 if (source == SUB_SOURCE_VOBSUB) {
1438 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1439 } else if (source == SUB_SOURCE_SUBS) {
1440 mpctx->set_of_sub_pos =
1441 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1442 #ifdef USE_ASS
1443 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1444 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1445 else
1446 #endif
1448 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1449 vo_osd_changed(OSDTYPE_SUBTITLE);
1451 } else if (source == SUB_SOURCE_DEMUX) {
1452 dvdsub_id =
1453 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1454 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1455 int i = 0;
1456 // default: assume 1:1 mapping of sid and stream id
1457 d_sub->id = dvdsub_id;
1458 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1459 ds_free_packs(d_sub);
1460 for (i = 0; i < MAX_S_STREAMS; i++) {
1461 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1462 if (sh && sh->sid == dvdsub_id) {
1463 d_sub->id = i;
1464 d_sub->sh = sh;
1465 break;
1468 if (d_sub->sh && d_sub->id >= 0) {
1469 sh_sub_t *sh = d_sub->sh;
1470 if (sh->type == 'v')
1471 init_vo_spudec();
1472 #ifdef USE_ASS
1473 else if (ass_enabled)
1474 ass_track = sh->ass_track;
1475 #endif
1476 } else {
1477 d_sub->id = -2;
1478 d_sub->sh = NULL;
1482 #ifdef USE_DVDREAD
1483 if (vo_spudec
1484 && (mpctx->stream->type == STREAMTYPE_DVD
1485 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1486 && dvdsub_id < 0 && reset_spu) {
1487 dvdsub_id = -2;
1488 d_sub->id = dvdsub_id;
1490 #endif
1491 update_subtitles(mpctx->sh_video, d_sub, 1);
1493 return M_PROPERTY_OK;
1496 /// Selected sub source (RW)
1497 static int mp_property_sub_source(m_option_t * prop, int action, void *arg,
1498 MPContext * mpctx)
1500 int source;
1501 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1502 return M_PROPERTY_UNAVAILABLE;
1504 switch (action) {
1505 case M_PROPERTY_GET:
1506 if (!arg)
1507 return M_PROPERTY_ERROR;
1508 *(int *) arg = sub_source(mpctx);
1509 return M_PROPERTY_OK;
1510 case M_PROPERTY_PRINT:
1511 if (!arg)
1512 return M_PROPERTY_ERROR;
1513 *(char **) arg = malloc(64);
1514 (*(char **) arg)[63] = 0;
1515 switch (sub_source(mpctx))
1517 case SUB_SOURCE_SUBS:
1518 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1519 break;
1520 case SUB_SOURCE_VOBSUB:
1521 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1522 break;
1523 case SUB_SOURCE_DEMUX:
1524 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1525 break;
1526 default:
1527 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1529 return M_PROPERTY_OK;
1530 case M_PROPERTY_SET:
1531 if (!arg)
1532 return M_PROPERTY_ERROR;
1533 M_PROPERTY_CLAMP(prop, *(int*)arg);
1534 if (*(int *) arg < 0)
1535 mpctx->global_sub_pos = -1;
1536 else if (*(int *) arg != sub_source(mpctx)) {
1537 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1538 return M_PROPERTY_UNAVAILABLE;
1539 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1541 break;
1542 case M_PROPERTY_STEP_UP:
1543 case M_PROPERTY_STEP_DOWN: {
1544 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1545 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1546 int step = (step_all > 0) ? 1 : -1;
1547 int cur_source = sub_source(mpctx);
1548 source = cur_source;
1549 while (step_all) {
1550 source += step;
1551 if (source >= SUB_SOURCES)
1552 source = -1;
1553 else if (source < -1)
1554 source = SUB_SOURCES - 1;
1555 if (source == cur_source || source == -1 ||
1556 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1557 step_all -= step;
1559 if (source == cur_source)
1560 return M_PROPERTY_OK;
1561 if (source == -1)
1562 mpctx->global_sub_pos = -1;
1563 else
1564 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1565 break;
1567 default:
1568 return M_PROPERTY_NOT_IMPLEMENTED;
1570 --mpctx->global_sub_pos;
1571 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1574 /// Selected subtitles from specific source (RW)
1575 static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg,
1576 MPContext * mpctx)
1578 int source, is_cur_source, offset;
1579 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1580 return M_PROPERTY_UNAVAILABLE;
1582 if (!strcmp(prop->name, "sub_file"))
1583 source = SUB_SOURCE_SUBS;
1584 else if (!strcmp(prop->name, "sub_vob"))
1585 source = SUB_SOURCE_VOBSUB;
1586 else if (!strcmp(prop->name, "sub_demux"))
1587 source = SUB_SOURCE_DEMUX;
1588 else
1589 return M_PROPERTY_ERROR;
1591 offset = mpctx->global_sub_indices[source];
1592 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1593 return M_PROPERTY_UNAVAILABLE;
1595 is_cur_source = sub_source(mpctx) == source;
1596 switch (action) {
1597 case M_PROPERTY_GET:
1598 if (!arg)
1599 return M_PROPERTY_ERROR;
1600 if (is_cur_source) {
1601 *(int *) arg = mpctx->global_sub_pos - offset;
1602 if (source == SUB_SOURCE_VOBSUB)
1603 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1605 else
1606 *(int *) arg = -1;
1607 return M_PROPERTY_OK;
1608 case M_PROPERTY_PRINT:
1609 if (!arg)
1610 return M_PROPERTY_ERROR;
1611 if (is_cur_source)
1612 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1613 *(char **) arg = malloc(64);
1614 (*(char **) arg)[63] = 0;
1615 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1616 return M_PROPERTY_OK;
1617 case M_PROPERTY_SET:
1618 if (!arg)
1619 return M_PROPERTY_ERROR;
1620 if (*(int *) arg >= 0) {
1621 int index = *(int *)arg;
1622 if (source == SUB_SOURCE_VOBSUB)
1623 index = vobsub_get_index_by_id(vo_vobsub, index);
1624 mpctx->global_sub_pos = offset + index;
1625 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1626 || sub_source(mpctx) != source) {
1627 mpctx->global_sub_pos = -1;
1628 *(int *) arg = -1;
1631 else
1632 mpctx->global_sub_pos = -1;
1633 break;
1634 case M_PROPERTY_STEP_UP:
1635 case M_PROPERTY_STEP_DOWN: {
1636 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1637 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1638 int step = (step_all > 0) ? 1 : -1;
1639 int max_sub_pos_for_source = -1;
1640 if (!is_cur_source)
1641 mpctx->global_sub_pos = -1;
1642 while (step_all) {
1643 if (mpctx->global_sub_pos == -1) {
1644 if (step > 0)
1645 mpctx->global_sub_pos = offset;
1646 else if (max_sub_pos_for_source == -1) {
1647 // Find max pos for specific source
1648 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1649 while (mpctx->global_sub_pos >= 0
1650 && sub_source(mpctx) != source)
1651 --mpctx->global_sub_pos;
1653 else
1654 mpctx->global_sub_pos = max_sub_pos_for_source;
1656 else {
1657 mpctx->global_sub_pos += step;
1658 if (mpctx->global_sub_pos < offset ||
1659 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1660 sub_source(mpctx) != source)
1661 mpctx->global_sub_pos = -1;
1663 step_all -= step;
1665 break;
1667 default:
1668 return M_PROPERTY_NOT_IMPLEMENTED;
1670 --mpctx->global_sub_pos;
1671 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1674 /// Subtitle delay (RW)
1675 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1676 MPContext * mpctx)
1678 if (!mpctx->sh_video)
1679 return M_PROPERTY_UNAVAILABLE;
1680 return m_property_delay(prop, action, arg, &sub_delay);
1683 /// Alignment of text subtitles (RW)
1684 static int mp_property_sub_alignment(m_option_t * prop, int action,
1685 void *arg, MPContext * mpctx)
1687 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1689 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1690 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1691 return M_PROPERTY_UNAVAILABLE;
1693 switch (action) {
1694 case M_PROPERTY_PRINT:
1695 if (!arg)
1696 return M_PROPERTY_ERROR;
1697 M_PROPERTY_CLAMP(prop, sub_alignment);
1698 *(char **) arg = strdup(name[sub_alignment]);
1699 return M_PROPERTY_OK;
1700 case M_PROPERTY_SET:
1701 if (!arg)
1702 return M_PROPERTY_ERROR;
1703 case M_PROPERTY_STEP_UP:
1704 case M_PROPERTY_STEP_DOWN:
1705 vo_osd_changed(OSDTYPE_SUBTITLE);
1706 default:
1707 return m_property_choice(prop, action, arg, &sub_alignment);
1711 /// Subtitle visibility (RW)
1712 static int mp_property_sub_visibility(m_option_t * prop, int action,
1713 void *arg, MPContext * mpctx)
1715 if (!mpctx->sh_video)
1716 return M_PROPERTY_UNAVAILABLE;
1718 switch (action) {
1719 case M_PROPERTY_SET:
1720 if (!arg)
1721 return M_PROPERTY_ERROR;
1722 case M_PROPERTY_STEP_UP:
1723 case M_PROPERTY_STEP_DOWN:
1724 vo_osd_changed(OSDTYPE_SUBTITLE);
1725 if (vo_spudec)
1726 vo_osd_changed(OSDTYPE_SPU);
1727 default:
1728 return m_property_flag(prop, action, arg, &sub_visibility);
1732 #ifdef USE_ASS
1733 /// Use margins for libass subtitles (RW)
1734 static int mp_property_ass_use_margins(m_option_t * prop, int action,
1735 void *arg, MPContext * mpctx)
1737 if (!mpctx->sh_video)
1738 return M_PROPERTY_UNAVAILABLE;
1740 switch (action) {
1741 case M_PROPERTY_SET:
1742 if (!arg)
1743 return M_PROPERTY_ERROR;
1744 case M_PROPERTY_STEP_UP:
1745 case M_PROPERTY_STEP_DOWN:
1746 ass_force_reload = 1;
1747 default:
1748 return m_property_flag(prop, action, arg, &ass_use_margins);
1751 #endif
1753 /// Show only forced subtitles (RW)
1754 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1755 void *arg, MPContext * mpctx)
1757 if (!vo_spudec)
1758 return M_PROPERTY_UNAVAILABLE;
1760 switch (action) {
1761 case M_PROPERTY_SET:
1762 if (!arg)
1763 return M_PROPERTY_ERROR;
1764 case M_PROPERTY_STEP_UP:
1765 case M_PROPERTY_STEP_DOWN:
1766 m_property_flag(prop, action, arg, &forced_subs_only);
1767 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1768 return M_PROPERTY_OK;
1769 default:
1770 return m_property_flag(prop, action, arg, &forced_subs_only);
1775 #ifdef HAVE_FREETYPE
1776 /// Subtitle scale (RW)
1777 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1778 MPContext * mpctx)
1781 switch (action) {
1782 case M_PROPERTY_SET:
1783 if (!arg)
1784 return M_PROPERTY_ERROR;
1785 M_PROPERTY_CLAMP(prop, *(float *) arg);
1786 #ifdef USE_ASS
1787 if (ass_enabled) {
1788 ass_font_scale = *(float *) arg;
1789 ass_force_reload = 1;
1791 #endif
1792 text_font_scale_factor = *(float *) arg;
1793 force_load_font = 1;
1794 return M_PROPERTY_OK;
1795 case M_PROPERTY_STEP_UP:
1796 case M_PROPERTY_STEP_DOWN:
1797 #ifdef USE_ASS
1798 if (ass_enabled) {
1799 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1800 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1801 M_PROPERTY_CLAMP(prop, ass_font_scale);
1802 ass_force_reload = 1;
1804 #endif
1805 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1806 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1807 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1808 force_load_font = 1;
1809 return M_PROPERTY_OK;
1810 default:
1811 #ifdef USE_ASS
1812 if (ass_enabled)
1813 return m_property_float_ro(prop, action, arg, ass_font_scale);
1814 else
1815 #endif
1816 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1819 #endif
1821 ///@}
1823 /// \defgroup TVProperties TV properties
1824 /// \ingroup Properties
1825 ///@{
1827 #ifdef USE_TV
1829 /// TV color settings (RW)
1830 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1831 MPContext * mpctx)
1833 int r, val;
1834 tvi_handle_t *tvh = mpctx->demuxer->priv;
1835 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1836 return M_PROPERTY_UNAVAILABLE;
1838 switch (action) {
1839 case M_PROPERTY_SET:
1840 if (!arg)
1841 return M_PROPERTY_ERROR;
1842 M_PROPERTY_CLAMP(prop, *(int *) arg);
1843 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1844 case M_PROPERTY_GET:
1845 return tv_get_color_options(tvh, (int) prop->priv, arg);
1846 case M_PROPERTY_STEP_UP:
1847 case M_PROPERTY_STEP_DOWN:
1848 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1849 if (!r)
1850 return M_PROPERTY_ERROR;
1851 val += (arg ? *(int *) arg : 1) *
1852 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1853 M_PROPERTY_CLAMP(prop, val);
1854 return tv_set_color_options(tvh, (int) prop->priv, val);
1856 return M_PROPERTY_ERROR;
1858 return M_PROPERTY_NOT_IMPLEMENTED;
1861 #endif
1863 #ifdef HAVE_TV_TELETEXT
1864 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1865 MPContext * mpctx)
1867 int val,result;
1868 int base_ioctl=(int)prop->priv;
1870 for teletext's GET,SET,STEP ioctls this is not 0
1871 SET is GET+1
1872 STEP is GET+2
1874 tvi_handle_t *tvh = mpctx->demuxer->priv;
1875 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1876 return M_PROPERTY_UNAVAILABLE;
1877 if(!base_ioctl)
1878 return M_PROPERTY_ERROR;
1880 switch (action) {
1881 case M_PROPERTY_GET:
1882 if (!arg)
1883 return M_PROPERTY_ERROR;
1884 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1885 break;
1886 case M_PROPERTY_SET:
1887 if (!arg)
1888 return M_PROPERTY_ERROR;
1889 M_PROPERTY_CLAMP(prop, *(int *) arg);
1890 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1891 break;
1892 case M_PROPERTY_STEP_UP:
1893 case M_PROPERTY_STEP_DOWN:
1894 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1895 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1896 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1897 break;
1898 default:
1899 return M_PROPERTY_NOT_IMPLEMENTED;
1902 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1905 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1906 MPContext * mpctx)
1908 tvi_handle_t *tvh = mpctx->demuxer->priv;
1909 int result;
1910 int val;
1912 //with tvh==NULL will fail too
1913 result=mp_property_teletext_common(prop,action,arg,mpctx);
1914 if(result!=M_PROPERTY_OK)
1915 return result;
1917 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1918 mp_input_set_section("teletext");
1919 else
1920 mp_input_set_section("tv");
1921 return M_PROPERTY_OK;
1924 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1925 MPContext * mpctx)
1927 tvi_handle_t *tvh = mpctx->demuxer->priv;
1928 int result;
1929 int val;
1930 switch(action){
1931 case M_PROPERTY_STEP_UP:
1932 case M_PROPERTY_STEP_DOWN:
1933 //This should be handled separately
1934 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1935 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1936 break;
1937 default:
1938 result=mp_property_teletext_common(prop,action,arg,mpctx);
1940 return result;
1944 #endif /* HAVE_TV_TELETEXT */
1946 ///@}
1948 /// All properties available in MPlayer.
1949 /** \ingroup Properties
1951 static const m_option_t mp_properties[] = {
1952 // General
1953 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1954 M_OPT_RANGE, 0, 3, NULL },
1955 { "loop", mp_property_loop, CONF_TYPE_INT,
1956 M_OPT_MIN, -1, 0, NULL },
1957 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1958 M_OPT_RANGE, 0.01, 100.0, NULL },
1959 { "filename", mp_property_filename, CONF_TYPE_STRING,
1960 0, 0, 0, NULL },
1961 { "path", mp_property_path, CONF_TYPE_STRING,
1962 0, 0, 0, NULL },
1963 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1964 0, 0, 0, NULL },
1965 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1966 M_OPT_MIN, 0, 0, NULL },
1967 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1968 M_OPT_MIN, 0, 0, NULL },
1969 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1970 M_OPT_MIN, 0, 0, NULL },
1971 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1972 M_OPT_MIN, 0, 0, NULL },
1973 { "length", mp_property_length, CONF_TYPE_TIME,
1974 M_OPT_MIN, 0, 0, NULL },
1975 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1976 M_OPT_RANGE, 0, 100, NULL },
1977 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1978 M_OPT_MIN, 0, 0, NULL },
1979 { "chapter", mp_property_chapter, CONF_TYPE_INT,
1980 M_OPT_MIN, 1, 0, NULL },
1981 { "angle", mp_property_angle, CONF_TYPE_INT,
1982 CONF_RANGE, -2, 10, NULL },
1983 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
1984 0, 0, 0, NULL },
1986 // Audio
1987 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
1988 M_OPT_RANGE, 0, 100, NULL },
1989 { "mute", mp_property_mute, CONF_TYPE_FLAG,
1990 M_OPT_RANGE, 0, 1, NULL },
1991 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
1992 M_OPT_RANGE, -100, 100, NULL },
1993 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
1994 0, 0, 0, NULL },
1995 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
1996 0, 0, 0, NULL },
1997 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
1998 0, 0, 0, NULL },
1999 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2000 0, 0, 0, NULL },
2001 { "channels", mp_property_channels, CONF_TYPE_INT,
2002 0, 0, 0, NULL },
2003 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2004 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL },
2005 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2006 M_OPT_RANGE, -1, 1, NULL },
2008 // Video
2009 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2010 M_OPT_RANGE, 0, 1, NULL },
2011 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2012 M_OPT_RANGE, 0, 1, NULL },
2013 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2014 M_OPT_RANGE, 0, 1, NULL },
2015 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2016 M_OPT_RANGE, 0, 1, NULL },
2017 { "border", mp_property_border, CONF_TYPE_FLAG,
2018 M_OPT_RANGE, 0, 1, NULL },
2019 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2020 M_OPT_RANGE, 0, 2, NULL },
2021 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2022 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2023 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2024 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2025 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2026 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2027 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2028 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2029 { "hue", mp_property_gamma, CONF_TYPE_INT,
2030 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2031 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2032 M_OPT_RANGE, 0, 1, NULL },
2033 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2034 M_OPT_RANGE, 0, 1, NULL },
2035 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2036 0, 0, 0, NULL },
2037 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2038 0, 0, 0, NULL },
2039 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2040 0, 0, 0, NULL },
2041 { "width", mp_property_width, CONF_TYPE_INT,
2042 0, 0, 0, NULL },
2043 { "height", mp_property_height, CONF_TYPE_INT,
2044 0, 0, 0, NULL },
2045 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2046 0, 0, 0, NULL },
2047 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2048 0, 0, 0, NULL },
2049 { "switch_video", mp_property_video, CONF_TYPE_INT,
2050 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL },
2051 { "switch_program", mp_property_program, CONF_TYPE_INT,
2052 CONF_RANGE, -1, 65535, NULL },
2054 // Subs
2055 { "sub", mp_property_sub, CONF_TYPE_INT,
2056 M_OPT_MIN, -1, 0, NULL },
2057 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2058 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2059 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2060 M_OPT_MIN, -1, 0, NULL },
2061 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2062 M_OPT_MIN, -1, 0, NULL },
2063 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2064 M_OPT_MIN, -1, 0, NULL },
2065 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2066 0, 0, 0, NULL },
2067 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2068 M_OPT_RANGE, 0, 100, NULL },
2069 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2070 M_OPT_RANGE, 0, 2, NULL },
2071 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2072 M_OPT_RANGE, 0, 1, NULL },
2073 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2074 M_OPT_RANGE, 0, 1, NULL },
2075 #ifdef HAVE_FREETYPE
2076 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2077 M_OPT_RANGE, 0, 100, NULL },
2078 #endif
2079 #ifdef USE_ASS
2080 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2081 M_OPT_RANGE, 0, 1, NULL },
2082 #endif
2084 #ifdef USE_TV
2085 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2086 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2087 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2088 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2089 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2090 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2091 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2092 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2093 #endif
2095 #ifdef HAVE_TV_TELETEXT
2096 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2097 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2098 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2099 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2100 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2101 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2102 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2103 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2104 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2105 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2106 #endif
2108 { NULL, NULL, NULL, 0, 0, 0, NULL }
2112 int mp_property_do(const char *name, int action, void *val, void *ctx)
2114 return m_property_do(mp_properties, name, action, val, ctx);
2117 char* mp_property_print(const char *name, void* ctx)
2119 char* ret = NULL;
2120 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2121 return NULL;
2122 return ret;
2125 char *property_expand_string(MPContext * mpctx, char *str)
2127 return m_properties_expand_string(mp_properties, str, mpctx);
2130 void property_print_help(void)
2132 m_properties_print_help_list(mp_properties);
2136 ///@}
2137 // Properties group
2141 * \defgroup Command2Property Command to property bridge
2143 * It is used to handle most commands that just set a property
2144 * and optionally display something on the OSD.
2145 * Two kinds of commands are handled: adjust or toggle.
2147 * Adjust commands take 1 or 2 parameters: <value> <abs>
2148 * If <abs> is non-zero the property is set to the given value
2149 * otherwise it is adjusted.
2151 * Toggle commands take 0 or 1 parameters. With no parameter
2152 * or a value less than the property minimum it just steps the
2153 * property to its next value. Otherwise it sets it to the given
2154 * value.
2159 /// List of the commands that can be handled by setting a property.
2160 static struct {
2161 /// property name
2162 const char *name;
2163 /// cmd id
2164 int cmd;
2165 /// set/adjust or toggle command
2166 int toggle;
2167 /// progressbar type
2168 int osd_progbar;
2169 /// osd msg id if it must be shared
2170 int osd_id;
2171 /// osd msg template
2172 const char *osd_msg;
2173 } set_prop_cmd[] = {
2174 // general
2175 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2176 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2177 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2178 // audio
2179 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2180 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2181 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2182 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2183 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2184 // video
2185 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2186 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2187 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2188 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2189 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2190 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2191 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2192 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2193 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2194 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2195 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2196 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2197 // subs
2198 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2199 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2200 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2201 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2202 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2203 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2204 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2205 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2206 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2207 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2208 #ifdef HAVE_FREETYPE
2209 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2210 #endif
2211 #ifdef USE_ASS
2212 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2213 #endif
2214 #ifdef USE_TV
2215 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2216 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2217 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2218 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2219 #endif
2220 { NULL, 0, 0, 0, -1, NULL }
2224 /// Handle commands that set a property.
2225 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
2227 int i, r;
2228 m_option_t* prop;
2229 const char *pname;
2231 // look for the command
2232 for (i = 0; set_prop_cmd[i].name; i++)
2233 if (set_prop_cmd[i].cmd == cmd->id)
2234 break;
2235 if (!(pname = set_prop_cmd[i].name))
2236 return 0;
2238 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2239 return 0;
2241 // toggle command
2242 if (set_prop_cmd[i].toggle) {
2243 // set to value
2244 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2245 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2246 else
2247 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2248 } else if (cmd->args[1].v.i) //set
2249 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2250 else // adjust
2251 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2253 if (r <= 0)
2254 return 1;
2256 if (set_prop_cmd[i].osd_progbar) {
2257 if (prop->type == CONF_TYPE_INT) {
2258 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2259 set_osd_bar(set_prop_cmd[i].osd_progbar,
2260 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2261 } else if (prop->type == CONF_TYPE_FLOAT) {
2262 float f;
2263 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2264 set_osd_bar(set_prop_cmd[i].osd_progbar,
2265 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2266 } else
2267 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2268 "Property use an unsupported type.\n");
2269 return 1;
2272 if (set_prop_cmd[i].osd_msg) {
2273 char *val = mp_property_print(pname, mpctx);
2274 if (val) {
2275 set_osd_msg(set_prop_cmd[i].osd_id >=
2276 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2277 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2278 free(val);
2281 return 1;
2284 #ifdef USE_DVDNAV
2285 static const struct {
2286 const char *name;
2287 const mp_command_type cmd;
2288 } mp_dvdnav_bindings[] = {
2289 { "up", MP_CMD_DVDNAV_UP },
2290 { "down", MP_CMD_DVDNAV_DOWN },
2291 { "left", MP_CMD_DVDNAV_LEFT },
2292 { "right", MP_CMD_DVDNAV_RIGHT },
2293 { "menu", MP_CMD_DVDNAV_MENU },
2294 { "select", MP_CMD_DVDNAV_SELECT },
2295 { "prev", MP_CMD_DVDNAV_PREVMENU },
2296 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2299 * keep old dvdnav sub-command options for a while in order not to
2300 * break slave-mode API too suddenly.
2302 { "1", MP_CMD_DVDNAV_UP },
2303 { "2", MP_CMD_DVDNAV_DOWN },
2304 { "3", MP_CMD_DVDNAV_LEFT },
2305 { "4", MP_CMD_DVDNAV_RIGHT },
2306 { "5", MP_CMD_DVDNAV_MENU },
2307 { "6", MP_CMD_DVDNAV_SELECT },
2308 { "7", MP_CMD_DVDNAV_PREVMENU },
2309 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2310 { NULL, 0 }
2312 #endif
2314 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
2316 sh_audio_t * const sh_audio = mpctx->sh_audio;
2317 sh_video_t * const sh_video = mpctx->sh_video;
2318 int brk_cmd = 0;
2319 if (!set_property_command(mpctx, cmd))
2320 switch (cmd->id) {
2321 case MP_CMD_SEEK:{
2322 float v;
2323 int abs;
2324 if (sh_video)
2325 mpctx->osd_show_percentage = sh_video->fps;
2326 v = cmd->args[0].v.f;
2327 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2328 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2329 abs_seek_pos = SEEK_ABSOLUTE;
2330 if (sh_video)
2331 mpctx->osd_function =
2332 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2333 rel_seek_secs = v;
2334 } else if (abs) { /* Absolute seek by percentage */
2335 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2336 if (sh_video)
2337 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2338 rel_seek_secs = v / 100.0;
2339 } else {
2340 rel_seek_secs += v;
2341 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2343 brk_cmd = 1;
2345 break;
2347 case MP_CMD_SET_PROPERTY:{
2348 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2349 cmd->args[1].v.s, mpctx);
2350 if (r == M_PROPERTY_UNKNOWN)
2351 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2352 "Unknown property: '%s'\n", cmd->args[0].v.s);
2353 else if (r <= 0)
2354 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2355 "Failed to set property '%s' to '%s'.\n",
2356 cmd->args[0].v.s, cmd->args[1].v.s);
2358 break;
2360 case MP_CMD_STEP_PROPERTY:{
2361 void* arg = NULL;
2362 int r,i;
2363 double d;
2364 off_t o;
2365 if (cmd->args[1].v.f) {
2366 m_option_t* prop;
2367 if((r = mp_property_do(cmd->args[0].v.s,
2368 M_PROPERTY_GET_TYPE,
2369 &prop, mpctx)) <= 0)
2370 goto step_prop_err;
2371 if(prop->type == CONF_TYPE_INT ||
2372 prop->type == CONF_TYPE_FLAG)
2373 i = cmd->args[1].v.f, arg = &i;
2374 else if(prop->type == CONF_TYPE_FLOAT)
2375 arg = &cmd->args[1].v.f;
2376 else if(prop->type == CONF_TYPE_DOUBLE ||
2377 prop->type == CONF_TYPE_TIME)
2378 d = cmd->args[1].v.f, arg = &d;
2379 else if(prop->type == CONF_TYPE_POSITION)
2380 o = cmd->args[1].v.f, arg = &o;
2381 else
2382 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2383 "Ignoring step size stepping property '%s'.\n",
2384 cmd->args[0].v.s);
2386 r = mp_property_do(cmd->args[0].v.s,
2387 cmd->args[2].v.i < 0 ?
2388 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2389 arg, mpctx);
2390 step_prop_err:
2391 if (r == M_PROPERTY_UNKNOWN)
2392 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2393 "Unknown property: '%s'\n", cmd->args[0].v.s);
2394 else if (r <= 0)
2395 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2396 "Failed to increment property '%s' by %f.\n",
2397 cmd->args[0].v.s, cmd->args[1].v.f);
2399 break;
2401 case MP_CMD_GET_PROPERTY:{
2402 char *tmp;
2403 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2404 &tmp, mpctx) <= 0) {
2405 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2406 "Failed to get value of property '%s'.\n",
2407 cmd->args[0].v.s);
2408 break;
2410 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2411 cmd->args[0].v.s, tmp);
2412 free(tmp);
2414 break;
2416 case MP_CMD_EDL_MARK:
2417 if (edl_fd) {
2418 float v = sh_video ? sh_video->pts :
2419 playing_audio_pts(sh_audio, mpctx->d_audio,
2420 mpctx->audio_out);
2422 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2423 mpctx->begin_skip = v;
2424 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2425 } else {
2426 if (mpctx->begin_skip > v)
2427 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2428 else {
2429 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2430 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2432 mpctx->begin_skip = MP_NOPTS_VALUE;
2435 break;
2437 case MP_CMD_SWITCH_RATIO:
2438 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2439 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2440 else
2441 movie_aspect = cmd->args[0].v.f;
2442 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2443 break;
2445 case MP_CMD_SPEED_INCR:{
2446 float v = cmd->args[0].v.f;
2447 playback_speed += v;
2448 build_afilter_chain(sh_audio, &ao_data);
2449 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2450 playback_speed);
2451 } break;
2453 case MP_CMD_SPEED_MULT:{
2454 float v = cmd->args[0].v.f;
2455 playback_speed *= v;
2456 build_afilter_chain(sh_audio, &ao_data);
2457 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2458 playback_speed);
2459 } break;
2461 case MP_CMD_SPEED_SET:{
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_FRAME_STEP:
2470 case MP_CMD_PAUSE:
2471 cmd->pausing = 1;
2472 brk_cmd = 1;
2473 break;
2475 case MP_CMD_FILE_FILTER:
2476 file_filter = cmd->args[0].v.i;
2477 break;
2479 case MP_CMD_QUIT:
2480 exit_player_with_rc(MSGTR_Exit_quit,
2481 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2483 case MP_CMD_PLAY_TREE_STEP:{
2484 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2485 int force = cmd->args[1].v.i;
2487 #ifdef HAVE_NEW_GUI
2488 if (use_gui) {
2489 int i = 0;
2490 if (n > 0)
2491 for (i = 0; i < n; i++)
2492 mplNext();
2493 else
2494 for (i = 0; i < -1 * n; i++)
2495 mplPrev();
2496 } else
2497 #endif
2499 if (!force && mpctx->playtree_iter) {
2500 play_tree_iter_t *i =
2501 play_tree_iter_new_copy(mpctx->playtree_iter);
2502 if (play_tree_iter_step(i, n, 0) ==
2503 PLAY_TREE_ITER_ENTRY)
2504 mpctx->eof =
2505 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2506 play_tree_iter_free(i);
2507 } else
2508 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2509 if (mpctx->eof)
2510 mpctx->play_tree_step = n;
2511 brk_cmd = 1;
2514 break;
2516 case MP_CMD_PLAY_TREE_UP_STEP:{
2517 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2518 int force = cmd->args[1].v.i;
2520 if (!force && mpctx->playtree_iter) {
2521 play_tree_iter_t *i =
2522 play_tree_iter_new_copy(mpctx->playtree_iter);
2523 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2524 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2525 play_tree_iter_free(i);
2526 } else
2527 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2528 brk_cmd = 1;
2530 break;
2532 case MP_CMD_PLAY_ALT_SRC_STEP:
2533 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2534 int v = cmd->args[0].v.i;
2535 if (v > 0
2536 && mpctx->playtree_iter->file <
2537 mpctx->playtree_iter->num_files)
2538 mpctx->eof = PT_NEXT_SRC;
2539 else if (v < 0 && mpctx->playtree_iter->file > 1)
2540 mpctx->eof = PT_PREV_SRC;
2542 brk_cmd = 1;
2543 break;
2545 case MP_CMD_SUB_STEP:
2546 if (sh_video) {
2547 int movement = cmd->args[0].v.i;
2548 step_sub(subdata, sh_video->pts, movement);
2549 #ifdef USE_ASS
2550 if (ass_track)
2551 sub_delay +=
2552 ass_step_sub(ass_track,
2553 (sh_video->pts +
2554 sub_delay) * 1000 + .5, movement) / 1000.;
2555 #endif
2556 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2557 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2559 break;
2561 case MP_CMD_SUB_LOG:
2562 log_sub();
2563 break;
2565 case MP_CMD_OSD:{
2566 int v = cmd->args[0].v.i;
2567 int max = (term_osd
2568 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2569 if (osd_level > max)
2570 osd_level = max;
2571 if (v < 0)
2572 osd_level = (osd_level + 1) % (max + 1);
2573 else
2574 osd_level = v > max ? max : v;
2575 /* Show OSD state when disabled, but not when an explicit
2576 argument is given to the OSD command, i.e. in slave mode. */
2577 if (v == -1 && osd_level <= 1)
2578 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2579 MSGTR_OSDosd,
2580 osd_level ? MSGTR_OSDenabled :
2581 MSGTR_OSDdisabled);
2582 else
2583 rm_osd_msg(OSD_MSG_OSD_STATUS);
2585 break;
2587 case MP_CMD_OSD_SHOW_TEXT:
2588 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2589 (cmd->args[1].v.i <
2590 0 ? osd_duration : cmd->args[1].v.i),
2591 "%-.63s", cmd->args[0].v.s);
2592 break;
2594 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2595 char *txt = m_properties_expand_string(mp_properties,
2596 cmd->args[0].v.s,
2597 mpctx);
2598 /* if no argument supplied take default osd_duration, else <arg> ms. */
2599 if (txt) {
2600 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2601 (cmd->args[1].v.i <
2602 0 ? osd_duration : cmd->args[1].v.i),
2603 "%-.63s", txt);
2604 free(txt);
2607 break;
2609 case MP_CMD_LOADFILE:{
2610 play_tree_t *e = play_tree_new();
2611 play_tree_add_file(e, cmd->args[0].v.s);
2613 if (cmd->args[1].v.i) // append
2614 play_tree_append_entry(mpctx->playtree, e);
2615 else {
2616 // Go back to the starting point.
2617 while (play_tree_iter_up_step
2618 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2619 /* NOP */ ;
2620 play_tree_free_list(mpctx->playtree->child, 1);
2621 play_tree_set_child(mpctx->playtree, e);
2622 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2623 mpctx->eof = PT_NEXT_SRC;
2625 brk_cmd = 1;
2627 break;
2629 case MP_CMD_LOADLIST:{
2630 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2631 if (!e)
2632 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2633 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2634 else {
2635 if (cmd->args[1].v.i) // append
2636 play_tree_append_entry(mpctx->playtree, e);
2637 else {
2638 // Go back to the starting point.
2639 while (play_tree_iter_up_step
2640 (mpctx->playtree_iter, 0, 1)
2641 != PLAY_TREE_ITER_END)
2642 /* NOP */ ;
2643 play_tree_free_list(mpctx->playtree->child, 1);
2644 play_tree_set_child(mpctx->playtree, e);
2645 play_tree_iter_step(mpctx->playtree_iter, 0, 0);
2646 mpctx->eof = PT_NEXT_SRC;
2649 brk_cmd = 1;
2651 break;
2653 case MP_CMD_STOP:
2654 mpctx->eof = PT_STOP;
2655 brk_cmd = 1;
2656 break;
2658 #ifdef USE_RADIO
2659 case MP_CMD_RADIO_STEP_CHANNEL:
2660 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2661 int v = cmd->args[0].v.i;
2662 if (v > 0)
2663 radio_step_channel(mpctx->demuxer->stream,
2664 RADIO_CHANNEL_HIGHER);
2665 else
2666 radio_step_channel(mpctx->demuxer->stream,
2667 RADIO_CHANNEL_LOWER);
2668 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2669 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2670 MSGTR_OSDChannel,
2671 radio_get_channel_name(mpctx->demuxer->stream));
2674 break;
2676 case MP_CMD_RADIO_SET_CHANNEL:
2677 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2678 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2679 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2680 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2681 MSGTR_OSDChannel,
2682 radio_get_channel_name(mpctx->demuxer->stream));
2685 break;
2687 case MP_CMD_RADIO_SET_FREQ:
2688 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2689 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2690 break;
2692 case MP_CMD_RADIO_STEP_FREQ:
2693 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2694 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2695 break;
2696 #endif
2698 #ifdef USE_TV
2699 case MP_CMD_TV_START_SCAN:
2700 if (mpctx->file_format == DEMUXER_TYPE_TV)
2701 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2702 break;
2703 case MP_CMD_TV_SET_FREQ:
2704 if (mpctx->file_format == DEMUXER_TYPE_TV)
2705 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2706 cmd->args[0].v.f * 16.0);
2707 #ifdef HAVE_PVR
2708 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2709 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2710 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2711 pvr_get_current_channelname (mpctx->stream),
2712 pvr_get_current_stationname (mpctx->stream));
2714 #endif /* HAVE_PVR */
2715 break;
2717 case MP_CMD_TV_STEP_FREQ:
2718 if (mpctx->file_format == DEMUXER_TYPE_TV)
2719 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2720 cmd->args[0].v.f * 16.0);
2721 #ifdef HAVE_PVR
2722 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2723 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2724 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2725 pvr_get_current_channelname (mpctx->stream),
2726 pvr_get_current_frequency (mpctx->stream));
2728 #endif /* HAVE_PVR */
2729 break;
2731 case MP_CMD_TV_SET_NORM:
2732 if (mpctx->file_format == DEMUXER_TYPE_TV)
2733 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2734 cmd->args[0].v.s);
2735 break;
2737 case MP_CMD_TV_STEP_CHANNEL:{
2738 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2739 int v = cmd->args[0].v.i;
2740 if (v > 0) {
2741 tv_step_channel((tvi_handle_t *) (mpctx->
2742 demuxer->priv),
2743 TV_CHANNEL_HIGHER);
2744 } else {
2745 tv_step_channel((tvi_handle_t *) (mpctx->
2746 demuxer->priv),
2747 TV_CHANNEL_LOWER);
2749 if (tv_channel_list) {
2750 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2751 MSGTR_OSDChannel, tv_channel_current->name);
2752 //vo_osd_changed(OSDTYPE_SUBTITLE);
2755 #ifdef HAVE_PVR
2756 else if (mpctx->stream &&
2757 mpctx->stream->type == STREAMTYPE_PVR) {
2758 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2759 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2760 pvr_get_current_channelname (mpctx->stream),
2761 pvr_get_current_stationname (mpctx->stream));
2763 #endif /* HAVE_PVR */
2765 #ifdef HAS_DVBIN_SUPPORT
2766 if (mpctx->stream->type == STREAMTYPE_DVB) {
2767 int dir;
2768 int v = cmd->args[0].v.i;
2770 mpctx->last_dvb_step = v;
2771 if (v > 0)
2772 dir = DVB_CHANNEL_HIGHER;
2773 else
2774 dir = DVB_CHANNEL_LOWER;
2777 if (dvb_step_channel(mpctx->stream, dir))
2778 mpctx->eof = mpctx->dvbin_reopen = 1;
2780 #endif /* HAS_DVBIN_SUPPORT */
2781 break;
2783 case MP_CMD_TV_SET_CHANNEL:
2784 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2785 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2786 cmd->args[0].v.s);
2787 if (tv_channel_list) {
2788 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2789 MSGTR_OSDChannel, tv_channel_current->name);
2790 //vo_osd_changed(OSDTYPE_SUBTITLE);
2793 #ifdef HAVE_PVR
2794 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2795 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2796 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2797 pvr_get_current_channelname (mpctx->stream),
2798 pvr_get_current_stationname (mpctx->stream));
2800 #endif /* HAVE_PVR */
2801 break;
2803 #ifdef HAS_DVBIN_SUPPORT
2804 case MP_CMD_DVB_SET_CHANNEL:
2805 if (mpctx->stream->type == STREAMTYPE_DVB) {
2806 mpctx->last_dvb_step = 1;
2808 if (dvb_set_channel
2809 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2810 mpctx->eof = mpctx->dvbin_reopen = 1;
2812 break;
2813 #endif /* HAS_DVBIN_SUPPORT */
2815 case MP_CMD_TV_LAST_CHANNEL:
2816 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2817 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2818 if (tv_channel_list) {
2819 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2820 MSGTR_OSDChannel, tv_channel_current->name);
2821 //vo_osd_changed(OSDTYPE_SUBTITLE);
2824 #ifdef HAVE_PVR
2825 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2826 pvr_set_lastchannel (mpctx->stream);
2827 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2828 pvr_get_current_channelname (mpctx->stream),
2829 pvr_get_current_stationname (mpctx->stream));
2831 #endif /* HAVE_PVR */
2832 break;
2834 case MP_CMD_TV_STEP_NORM:
2835 if (mpctx->file_format == DEMUXER_TYPE_TV)
2836 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2837 break;
2839 case MP_CMD_TV_STEP_CHANNEL_LIST:
2840 if (mpctx->file_format == DEMUXER_TYPE_TV)
2841 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2842 break;
2843 #ifdef HAVE_TV_TELETEXT
2844 case MP_CMD_TV_TELETEXT_ADD_DEC:
2846 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2847 if (mpctx->file_format == DEMUXER_TYPE_TV)
2848 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2849 break;
2851 case MP_CMD_TV_TELETEXT_GO_LINK:
2853 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2854 if (mpctx->file_format == DEMUXER_TYPE_TV)
2855 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2856 break;
2858 #endif /* HAVE_TV_TELETEXT */
2859 #endif /* USE_TV */
2861 case MP_CMD_SUB_LOAD:
2862 if (sh_video) {
2863 int n = mpctx->set_of_sub_size;
2864 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2865 if (n != mpctx->set_of_sub_size) {
2866 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2867 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2868 mpctx->global_sub_size;
2869 ++mpctx->global_sub_size;
2872 break;
2874 case MP_CMD_SUB_REMOVE:
2875 if (sh_video) {
2876 int v = cmd->args[0].v.i;
2877 sub_data *subd;
2878 if (v < 0) {
2879 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2880 subd = mpctx->set_of_subtitles[v];
2881 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2882 MSGTR_RemovedSubtitleFile, v + 1,
2883 filename_recode(subd->filename));
2884 sub_free(subd);
2885 mpctx->set_of_subtitles[v] = NULL;
2887 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2888 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2889 mpctx->set_of_sub_size = 0;
2890 if (mpctx->set_of_sub_pos >= 0) {
2891 mpctx->global_sub_pos = -2;
2892 subdata = NULL;
2893 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2895 } else if (v < mpctx->set_of_sub_size) {
2896 subd = mpctx->set_of_subtitles[v];
2897 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2898 MSGTR_RemovedSubtitleFile, v + 1,
2899 filename_recode(subd->filename));
2900 sub_free(subd);
2901 if (mpctx->set_of_sub_pos == v) {
2902 mpctx->global_sub_pos = -2;
2903 subdata = NULL;
2904 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2905 } else if (mpctx->set_of_sub_pos > v) {
2906 --mpctx->set_of_sub_pos;
2907 --mpctx->global_sub_pos;
2909 while (++v < mpctx->set_of_sub_size)
2910 mpctx->set_of_subtitles[v - 1] =
2911 mpctx->set_of_subtitles[v];
2912 --mpctx->set_of_sub_size;
2913 --mpctx->global_sub_size;
2914 if (mpctx->set_of_sub_size <= 0)
2915 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2916 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2919 break;
2921 case MP_CMD_GET_SUB_VISIBILITY:
2922 if (sh_video) {
2923 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2924 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2926 break;
2928 case MP_CMD_SCREENSHOT:
2929 if (vo_config_count) {
2930 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2931 if (CONTROL_OK !=
2932 ((vf_instance_t *) sh_video->vfilter)->
2933 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2934 &cmd->args[0].v.i))
2935 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2937 break;
2939 case MP_CMD_VF_CHANGE_RECTANGLE:
2940 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2941 break;
2943 case MP_CMD_GET_TIME_LENGTH:{
2944 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2945 demuxer_get_time_length(mpctx->demuxer));
2947 break;
2949 case MP_CMD_GET_FILENAME:{
2950 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2951 get_metadata(META_NAME));
2953 break;
2955 case MP_CMD_GET_VIDEO_CODEC:{
2956 char *inf = get_metadata(META_VIDEO_CODEC);
2957 if (!inf)
2958 inf = strdup("");
2959 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2960 free(inf);
2962 break;
2964 case MP_CMD_GET_VIDEO_BITRATE:{
2965 char *inf = get_metadata(META_VIDEO_BITRATE);
2966 if (!inf)
2967 inf = strdup("");
2968 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2969 free(inf);
2971 break;
2973 case MP_CMD_GET_VIDEO_RESOLUTION:{
2974 char *inf = get_metadata(META_VIDEO_RESOLUTION);
2975 if (!inf)
2976 inf = strdup("");
2977 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2978 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
2979 free(inf);
2981 break;
2983 case MP_CMD_GET_AUDIO_CODEC:{
2984 char *inf = get_metadata(META_AUDIO_CODEC);
2985 if (!inf)
2986 inf = strdup("");
2987 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
2988 free(inf);
2990 break;
2992 case MP_CMD_GET_AUDIO_BITRATE:{
2993 char *inf = get_metadata(META_AUDIO_BITRATE);
2994 if (!inf)
2995 inf = strdup("");
2996 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
2997 free(inf);
2999 break;
3001 case MP_CMD_GET_AUDIO_SAMPLES:{
3002 char *inf = get_metadata(META_AUDIO_SAMPLES);
3003 if (!inf)
3004 inf = strdup("");
3005 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3006 free(inf);
3008 break;
3010 case MP_CMD_GET_META_TITLE:{
3011 char *inf = get_metadata(META_INFO_TITLE);
3012 if (!inf)
3013 inf = strdup("");
3014 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3015 free(inf);
3017 break;
3019 case MP_CMD_GET_META_ARTIST:{
3020 char *inf = get_metadata(META_INFO_ARTIST);
3021 if (!inf)
3022 inf = strdup("");
3023 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3024 free(inf);
3026 break;
3028 case MP_CMD_GET_META_ALBUM:{
3029 char *inf = get_metadata(META_INFO_ALBUM);
3030 if (!inf)
3031 inf = strdup("");
3032 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3033 free(inf);
3035 break;
3037 case MP_CMD_GET_META_YEAR:{
3038 char *inf = get_metadata(META_INFO_YEAR);
3039 if (!inf)
3040 inf = strdup("");
3041 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3042 free(inf);
3044 break;
3046 case MP_CMD_GET_META_COMMENT:{
3047 char *inf = get_metadata(META_INFO_COMMENT);
3048 if (!inf)
3049 inf = strdup("");
3050 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3051 free(inf);
3053 break;
3055 case MP_CMD_GET_META_TRACK:{
3056 char *inf = get_metadata(META_INFO_TRACK);
3057 if (!inf)
3058 inf = strdup("");
3059 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3060 free(inf);
3062 break;
3064 case MP_CMD_GET_META_GENRE:{
3065 char *inf = get_metadata(META_INFO_GENRE);
3066 if (!inf)
3067 inf = strdup("");
3068 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3069 free(inf);
3071 break;
3073 case MP_CMD_GET_VO_FULLSCREEN:
3074 if (mpctx->video_out && vo_config_count)
3075 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3076 break;
3078 case MP_CMD_GET_PERCENT_POS:
3079 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3080 demuxer_get_percent_pos(mpctx->demuxer));
3081 break;
3083 case MP_CMD_GET_TIME_POS:{
3084 float pos = 0;
3085 if (sh_video)
3086 pos = sh_video->pts;
3087 else if (sh_audio && mpctx->audio_out)
3088 pos =
3089 playing_audio_pts(sh_audio, mpctx->d_audio,
3090 mpctx->audio_out);
3091 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3093 break;
3095 case MP_CMD_RUN:
3096 #ifndef __MINGW32__
3097 if (!fork()) {
3098 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3099 exit(0);
3101 #endif
3102 break;
3104 case MP_CMD_KEYDOWN_EVENTS:
3105 mplayer_put_key(cmd->args[0].v.i);
3106 break;
3108 case MP_CMD_SET_MOUSE_POS:{
3109 int pointer_x, pointer_y;
3110 double dx, dy;
3111 pointer_x = cmd->args[0].v.i;
3112 pointer_y = cmd->args[1].v.i;
3113 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
3114 #ifdef USE_DVDNAV
3115 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3116 && dx > 0.0 && dy > 0.0) {
3117 int button = -1;
3118 pointer_x = (int) (dx * (double) sh_video->disp_w);
3119 pointer_y = (int) (dy * (double) sh_video->disp_h);
3120 mp_dvdnav_update_mouse_pos(mpctx->stream,
3121 pointer_x, pointer_y, &button);
3122 if (osd_level > 1 && button > 0)
3123 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3124 "Selected button number %d", button);
3126 #endif
3127 #ifdef HAVE_MENU
3128 if (use_menu && dx >= 0.0 && dy >= 0.0)
3129 menu_update_mouse_pos(dx, dy);
3130 #endif
3132 break;
3134 #ifdef USE_DVDNAV
3135 case MP_CMD_DVDNAV:{
3136 int button = -1;
3137 int i;
3138 mp_command_type command = 0;
3139 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3140 break;
3142 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3143 if (cmd->args[0].v.s &&
3144 !strcasecmp (cmd->args[0].v.s,
3145 mp_dvdnav_bindings[i].name))
3146 command = mp_dvdnav_bindings[i].cmd;
3148 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3149 if (osd_level > 1 && button > 0)
3150 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3151 "Selected button number %d", button);
3153 break;
3155 case MP_CMD_SWITCH_TITLE:
3156 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3157 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3158 break;
3160 #endif
3162 default:
3163 #ifdef HAVE_NEW_GUI
3164 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3165 guiGetEvent(guiIEvent, (char *) cmd->id);
3166 else
3167 #endif
3168 mp_msg(MSGT_CPLAYER, MSGL_V,
3169 "Received unknown cmd %s\n", cmd->name);
3172 switch (cmd->pausing) {
3173 case 1: // "pausing"
3174 mpctx->osd_function = OSD_PAUSE;
3175 break;
3176 case 3: // "pausing_toggle"
3177 mpctx->was_paused = !mpctx->was_paused;
3178 if (mpctx->was_paused)
3179 mpctx->osd_function = OSD_PAUSE;
3180 else if (mpctx->osd_function == OSD_PAUSE)
3181 mpctx->osd_function = OSD_PLAY;
3182 break;
3183 case 2: // "pausing_keep"
3184 if (mpctx->was_paused)
3185 mpctx->osd_function = OSD_PAUSE;
3187 return brk_cmd;