sync with en/mplayer.1 r29805
[mplayer/glamo.git] / command.c
blob37a0780cbd71383f22c8c572122b1f8bc664678f
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 "libmpcodecs/dec_teletext.h"
29 #include "vobsub.h"
30 #include "spudec.h"
31 #include "get_path.h"
32 #include "stream/tv.h"
33 #include "stream/stream_radio.h"
34 #include "stream/pvr.h"
35 #ifdef CONFIG_DVBIN
36 #include "stream/dvbin.h"
37 #endif
38 #ifdef CONFIG_DVDREAD
39 #include "stream/stream_dvd.h"
40 #endif
41 #include "stream/stream_dvdnav.h"
42 #include "libass/ass.h"
43 #include "libass/ass_mp.h"
44 #include "m_struct.h"
45 #include "libmenu/menu.h"
46 #include "gui/interface.h"
48 #include "mp_core.h"
49 #include "mp_fifo.h"
50 #include "libavutil/avstring.h"
52 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
54 extern int use_menu;
56 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy)
58 //remove the borders, if any, and rescale to the range [0,1],[0,1]
59 if (vo_fs) { //we are in full-screen mode
60 if (vo_screenwidth > vo_dwidth) //there are borders along the x axis
61 ix -= (vo_screenwidth - vo_dwidth) / 2;
62 if (vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
63 iy -= (vo_screenheight - vo_dheight) / 2;
65 if (ix < 0 || ix > vo_dwidth) {
66 *dx = *dy = -1.0;
67 return;
68 } //we are on one of the borders
69 if (iy < 0 || iy > vo_dheight) {
70 *dx = *dy = -1.0;
71 return;
72 } //we are on one of the borders
75 *dx = (double) ix / (double) vo_dwidth;
76 *dy = (double) iy / (double) vo_dheight;
78 mp_msg(MSGT_CPLAYER, MSGL_V,
79 "\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
80 *dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth,
81 vo_dheight, vo_fs);
84 static int sub_source_by_pos(MPContext * mpctx, int pos)
86 int source = -1;
87 int top = -1;
88 int i;
89 for (i = 0; i < SUB_SOURCES; i++) {
90 int j = mpctx->global_sub_indices[i];
91 if ((j >= 0) && (j > top) && (pos >= j)) {
92 source = i;
93 top = j;
96 return source;
99 static int sub_source(MPContext * mpctx)
101 return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
105 * \brief Log the currently displayed subtitle to a file
107 * Logs the current or last displayed subtitle together with filename
108 * and time information to ~/.mplayer/subtitle_log
110 * Intended purpose is to allow convenient marking of bogus subtitles
111 * which need to be fixed while watching the movie.
114 static void log_sub(void)
116 char *fname;
117 FILE *f;
118 int i;
120 if (subdata == NULL || vo_sub_last == NULL)
121 return;
122 fname = get_path("subtitle_log");
123 f = fopen(fname, "a");
124 if (!f)
125 return;
126 fprintf(f, "----------------------------------------------------------\n");
127 if (subdata->sub_uses_time) {
128 fprintf(f,
129 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
130 filename, vo_sub_last->start / 360000,
131 (vo_sub_last->start / 6000) % 60,
132 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
133 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
134 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
135 } else {
136 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start,
137 vo_sub_last->end);
139 for (i = 0; i < vo_sub_last->lines; i++) {
140 fprintf(f, "%s\n", vo_sub_last->text[i]);
142 fclose(f);
146 /// \defgroup Properties
147 ///@{
149 /// \defgroup GeneralProperties General properties
150 /// \ingroup Properties
151 ///@{
153 /// OSD level (RW)
154 static int mp_property_osdlevel(m_option_t * prop, int action, void *arg,
155 MPContext * mpctx)
157 return m_property_choice(prop, action, arg, &osd_level);
160 /// Loop (RW)
161 static int mp_property_loop(m_option_t * prop, int action, void *arg,
162 MPContext * mpctx)
164 switch (action) {
165 case M_PROPERTY_PRINT:
166 if (!arg) return M_PROPERTY_ERROR;
167 if (mpctx->loop_times < 0)
168 *(char**)arg = strdup("off");
169 else if (mpctx->loop_times == 0)
170 *(char**)arg = strdup("inf");
171 else
172 break;
173 return M_PROPERTY_OK;
175 return m_property_int_range(prop, action, arg, &mpctx->loop_times);
178 /// Playback speed (RW)
179 static int mp_property_playback_speed(m_option_t * prop, int action,
180 void *arg, MPContext * mpctx)
182 switch (action) {
183 case M_PROPERTY_SET:
184 if (!arg)
185 return M_PROPERTY_ERROR;
186 M_PROPERTY_CLAMP(prop, *(float *) arg);
187 playback_speed = *(float *) arg;
188 build_afilter_chain(mpctx->sh_audio, &ao_data);
189 return M_PROPERTY_OK;
190 case M_PROPERTY_STEP_UP:
191 case M_PROPERTY_STEP_DOWN:
192 playback_speed += (arg ? *(float *) arg : 0.1) *
193 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
194 M_PROPERTY_CLAMP(prop, playback_speed);
195 build_afilter_chain(mpctx->sh_audio, &ao_data);
196 return M_PROPERTY_OK;
198 return m_property_float_range(prop, action, arg, &playback_speed);
201 /// filename with path (RO)
202 static int mp_property_path(m_option_t * prop, int action, void *arg,
203 MPContext * mpctx)
205 return m_property_string_ro(prop, action, arg, filename);
208 /// filename without path (RO)
209 static int mp_property_filename(m_option_t * prop, int action, void *arg,
210 MPContext * mpctx)
212 char *f;
213 if (!filename)
214 return M_PROPERTY_UNAVAILABLE;
215 if (((f = strrchr(filename, '/')) || (f = strrchr(filename, '\\'))) && f[1])
216 f++;
217 else
218 f = filename;
219 return m_property_string_ro(prop, action, arg, f);
222 /// Demuxer name (RO)
223 static int mp_property_demuxer(m_option_t * prop, int action, void *arg,
224 MPContext * mpctx)
226 if (!mpctx->demuxer)
227 return M_PROPERTY_UNAVAILABLE;
228 return m_property_string_ro(prop, action, arg,
229 (char *) mpctx->demuxer->desc->name);
232 /// Position in the stream (RW)
233 static int mp_property_stream_pos(m_option_t * prop, int action, void *arg,
234 MPContext * mpctx)
236 if (!mpctx->demuxer || !mpctx->demuxer->stream)
237 return M_PROPERTY_UNAVAILABLE;
238 if (!arg)
239 return M_PROPERTY_ERROR;
240 switch (action) {
241 case M_PROPERTY_GET:
242 *(off_t *) arg = stream_tell(mpctx->demuxer->stream);
243 return M_PROPERTY_OK;
244 case M_PROPERTY_SET:
245 M_PROPERTY_CLAMP(prop, *(off_t *) arg);
246 stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
247 return M_PROPERTY_OK;
249 return M_PROPERTY_NOT_IMPLEMENTED;
252 /// Stream start offset (RO)
253 static int mp_property_stream_start(m_option_t * prop, int action,
254 void *arg, MPContext * mpctx)
256 if (!mpctx->demuxer || !mpctx->demuxer->stream)
257 return M_PROPERTY_UNAVAILABLE;
258 switch (action) {
259 case M_PROPERTY_GET:
260 *(off_t *) arg = mpctx->demuxer->stream->start_pos;
261 return M_PROPERTY_OK;
263 return M_PROPERTY_NOT_IMPLEMENTED;
266 /// Stream end offset (RO)
267 static int mp_property_stream_end(m_option_t * prop, int action, void *arg,
268 MPContext * mpctx)
270 if (!mpctx->demuxer || !mpctx->demuxer->stream)
271 return M_PROPERTY_UNAVAILABLE;
272 switch (action) {
273 case M_PROPERTY_GET:
274 *(off_t *) arg = mpctx->demuxer->stream->end_pos;
275 return M_PROPERTY_OK;
277 return M_PROPERTY_NOT_IMPLEMENTED;
280 /// Stream length (RO)
281 static int mp_property_stream_length(m_option_t * prop, int action,
282 void *arg, MPContext * mpctx)
284 if (!mpctx->demuxer || !mpctx->demuxer->stream)
285 return M_PROPERTY_UNAVAILABLE;
286 switch (action) {
287 case M_PROPERTY_GET:
288 *(off_t *) arg =
289 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
290 return M_PROPERTY_OK;
292 return M_PROPERTY_NOT_IMPLEMENTED;
295 /// Media length in seconds (RO)
296 static int mp_property_length(m_option_t * prop, int action, void *arg,
297 MPContext * mpctx)
299 double len;
301 if (!mpctx->demuxer ||
302 !(int) (len = demuxer_get_time_length(mpctx->demuxer)))
303 return M_PROPERTY_UNAVAILABLE;
305 return m_property_time_ro(prop, action, arg, len);
308 /// Current position in percent (RW)
309 static int mp_property_percent_pos(m_option_t * prop, int action,
310 void *arg, MPContext * mpctx) {
311 int pos;
313 if (!mpctx->demuxer)
314 return M_PROPERTY_UNAVAILABLE;
316 switch(action) {
317 case M_PROPERTY_SET:
318 if(!arg) return M_PROPERTY_ERROR;
319 M_PROPERTY_CLAMP(prop, *(int*)arg);
320 pos = *(int*)arg;
321 break;
322 case M_PROPERTY_STEP_UP:
323 case M_PROPERTY_STEP_DOWN:
324 pos = demuxer_get_percent_pos(mpctx->demuxer);
325 pos += (arg ? *(int*)arg : 10) *
326 (action == M_PROPERTY_STEP_UP ? 1 : -1);
327 M_PROPERTY_CLAMP(prop, pos);
328 break;
329 default:
330 return m_property_int_ro(prop, action, arg,
331 demuxer_get_percent_pos(mpctx->demuxer));
334 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
335 rel_seek_secs = pos / 100.0;
336 return M_PROPERTY_OK;
339 /// Current position in seconds (RW)
340 static int mp_property_time_pos(m_option_t * prop, int action,
341 void *arg, MPContext * mpctx) {
342 if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
343 return M_PROPERTY_UNAVAILABLE;
345 switch(action) {
346 case M_PROPERTY_SET:
347 if(!arg) return M_PROPERTY_ERROR;
348 M_PROPERTY_CLAMP(prop, *(double*)arg);
349 abs_seek_pos = SEEK_ABSOLUTE;
350 rel_seek_secs = *(double*)arg;
351 return M_PROPERTY_OK;
352 case M_PROPERTY_STEP_UP:
353 case M_PROPERTY_STEP_DOWN:
354 rel_seek_secs += (arg ? *(double*)arg : 10.0) *
355 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
356 return M_PROPERTY_OK;
358 return m_property_time_ro(prop, action, arg,
359 mpctx->sh_video ? mpctx->sh_video->pts :
360 playing_audio_pts(mpctx->sh_audio,
361 mpctx->d_audio,
362 mpctx->audio_out));
365 /// Current chapter (RW)
366 static int mp_property_chapter(m_option_t *prop, int action, void *arg,
367 MPContext *mpctx)
369 int chapter = -1;
370 float next_pts = 0;
371 int chapter_num;
372 int step_all;
373 char *chapter_name = NULL;
375 if (mpctx->demuxer)
376 chapter = demuxer_get_current_chapter(mpctx->demuxer);
377 if (chapter < 0)
378 return M_PROPERTY_UNAVAILABLE;
380 switch (action) {
381 case M_PROPERTY_GET:
382 if (!arg)
383 return M_PROPERTY_ERROR;
384 *(int *) arg = chapter;
385 return M_PROPERTY_OK;
386 case M_PROPERTY_PRINT: {
387 if (!arg)
388 return M_PROPERTY_ERROR;
389 chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter);
390 if (!chapter_name)
391 return M_PROPERTY_UNAVAILABLE;
392 *(char **) arg = chapter_name;
393 return M_PROPERTY_OK;
395 case M_PROPERTY_SET:
396 if (!arg)
397 return M_PROPERTY_ERROR;
398 M_PROPERTY_CLAMP(prop, *(int*)arg);
399 step_all = *(int *)arg - chapter;
400 chapter += step_all;
401 break;
402 case M_PROPERTY_STEP_UP:
403 case M_PROPERTY_STEP_DOWN: {
404 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
405 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
406 chapter += step_all;
407 if (chapter < 0)
408 chapter = 0;
409 break;
411 default:
412 return M_PROPERTY_NOT_IMPLEMENTED;
414 rel_seek_secs = 0;
415 abs_seek_pos = 0;
416 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
417 &next_pts, &chapter_num, &chapter_name);
418 if (chapter >= 0) {
419 if (next_pts > -1.0) {
420 abs_seek_pos = SEEK_ABSOLUTE;
421 rel_seek_secs = next_pts;
423 if (chapter_name)
424 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
425 MSGTR_OSDChapter, chapter + 1, chapter_name);
427 else if (step_all > 0)
428 rel_seek_secs = 1000000000.;
429 else
430 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
431 MSGTR_OSDChapter, 0, MSGTR_Unknown);
432 if (chapter_name)
433 free(chapter_name);
434 return M_PROPERTY_OK;
437 /// Number of chapters in file
438 static int mp_property_chapters(m_option_t *prop, int action, void *arg,
439 MPContext *mpctx)
441 if (!mpctx->demuxer)
442 return M_PROPERTY_UNAVAILABLE;
443 if (mpctx->demuxer->num_chapters == 0)
444 stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
445 return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
448 /// Current dvd angle (RW)
449 static int mp_property_angle(m_option_t *prop, int action, void *arg,
450 MPContext *mpctx)
452 int angle = -1;
453 int angles;
454 char *angle_name = NULL;
456 if (mpctx->demuxer)
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;
544 static int mp_property_pause(m_option_t * prop, int action, void *arg,
545 MPContext * mpctx)
547 return m_property_flag_ro(prop, action, arg, mpctx->osd_function == OSD_PAUSE);
551 ///@}
553 /// \defgroup AudioProperties Audio properties
554 /// \ingroup Properties
555 ///@{
557 /// Volume (RW)
558 static int mp_property_volume(m_option_t * prop, int action, void *arg,
559 MPContext * mpctx)
562 if (!mpctx->sh_audio)
563 return M_PROPERTY_UNAVAILABLE;
565 switch (action) {
566 case M_PROPERTY_GET:
567 if (!arg)
568 return M_PROPERTY_ERROR;
569 mixer_getbothvolume(&mpctx->mixer, arg);
570 return M_PROPERTY_OK;
571 case M_PROPERTY_PRINT:{
572 float vol;
573 if (!arg)
574 return M_PROPERTY_ERROR;
575 mixer_getbothvolume(&mpctx->mixer, &vol);
576 return m_property_float_range(prop, action, arg, &vol);
578 case M_PROPERTY_STEP_UP:
579 case M_PROPERTY_STEP_DOWN:
580 case M_PROPERTY_SET:
581 break;
582 default:
583 return M_PROPERTY_NOT_IMPLEMENTED;
586 if (mpctx->edl_muted)
587 return M_PROPERTY_DISABLED;
588 mpctx->user_muted = 0;
590 switch (action) {
591 case M_PROPERTY_SET:
592 if (!arg)
593 return M_PROPERTY_ERROR;
594 M_PROPERTY_CLAMP(prop, *(float *) arg);
595 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
596 return M_PROPERTY_OK;
597 case M_PROPERTY_STEP_UP:
598 if (arg && *(float *) arg <= 0)
599 mixer_decvolume(&mpctx->mixer);
600 else
601 mixer_incvolume(&mpctx->mixer);
602 return M_PROPERTY_OK;
603 case M_PROPERTY_STEP_DOWN:
604 if (arg && *(float *) arg <= 0)
605 mixer_incvolume(&mpctx->mixer);
606 else
607 mixer_decvolume(&mpctx->mixer);
608 return M_PROPERTY_OK;
610 return M_PROPERTY_NOT_IMPLEMENTED;
613 /// Mute (RW)
614 static int mp_property_mute(m_option_t * prop, int action, void *arg,
615 MPContext * mpctx)
618 if (!mpctx->sh_audio)
619 return M_PROPERTY_UNAVAILABLE;
621 switch (action) {
622 case M_PROPERTY_SET:
623 if (mpctx->edl_muted)
624 return M_PROPERTY_DISABLED;
625 if (!arg)
626 return M_PROPERTY_ERROR;
627 if ((!!*(int *) arg) != mpctx->mixer.muted)
628 mixer_mute(&mpctx->mixer);
629 mpctx->user_muted = mpctx->mixer.muted;
630 return M_PROPERTY_OK;
631 case M_PROPERTY_STEP_UP:
632 case M_PROPERTY_STEP_DOWN:
633 if (mpctx->edl_muted)
634 return M_PROPERTY_DISABLED;
635 mixer_mute(&mpctx->mixer);
636 mpctx->user_muted = mpctx->mixer.muted;
637 return M_PROPERTY_OK;
638 case M_PROPERTY_PRINT:
639 if (!arg)
640 return M_PROPERTY_ERROR;
641 if (mpctx->edl_muted) {
642 *(char **) arg = strdup(MSGTR_EnabledEdl);
643 return M_PROPERTY_OK;
645 default:
646 return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
651 /// Audio delay (RW)
652 static int mp_property_audio_delay(m_option_t * prop, int action,
653 void *arg, MPContext * mpctx)
655 if (!(mpctx->sh_audio && mpctx->sh_video))
656 return M_PROPERTY_UNAVAILABLE;
657 switch (action) {
658 case M_PROPERTY_SET:
659 case M_PROPERTY_STEP_UP:
660 case M_PROPERTY_STEP_DOWN: {
661 int ret;
662 float delay = audio_delay;
663 ret = m_property_delay(prop, action, arg, &audio_delay);
664 if (ret != M_PROPERTY_OK)
665 return ret;
666 if (mpctx->sh_audio)
667 mpctx->delay -= audio_delay - delay;
669 return M_PROPERTY_OK;
670 default:
671 return m_property_delay(prop, action, arg, &audio_delay);
675 /// Audio codec tag (RO)
676 static int mp_property_audio_format(m_option_t * prop, int action,
677 void *arg, MPContext * mpctx)
679 if (!mpctx->sh_audio)
680 return M_PROPERTY_UNAVAILABLE;
681 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
684 /// Audio codec name (RO)
685 static int mp_property_audio_codec(m_option_t * prop, int action,
686 void *arg, MPContext * mpctx)
688 if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
689 return M_PROPERTY_UNAVAILABLE;
690 return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
693 /// Audio bitrate (RO)
694 static int mp_property_audio_bitrate(m_option_t * prop, int action,
695 void *arg, MPContext * mpctx)
697 if (!mpctx->sh_audio)
698 return M_PROPERTY_UNAVAILABLE;
699 return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
702 /// Samplerate (RO)
703 static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
704 MPContext * mpctx)
706 if (!mpctx->sh_audio)
707 return M_PROPERTY_UNAVAILABLE;
708 switch(action) {
709 case M_PROPERTY_PRINT:
710 if(!arg) return M_PROPERTY_ERROR;
711 *(char**)arg = malloc(16);
712 sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
713 return M_PROPERTY_OK;
715 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
718 /// Number of channels (RO)
719 static int mp_property_channels(m_option_t * prop, int action, void *arg,
720 MPContext * mpctx)
722 if (!mpctx->sh_audio)
723 return M_PROPERTY_UNAVAILABLE;
724 switch (action) {
725 case M_PROPERTY_PRINT:
726 if (!arg)
727 return M_PROPERTY_ERROR;
728 switch (mpctx->sh_audio->channels) {
729 case 1:
730 *(char **) arg = strdup("mono");
731 break;
732 case 2:
733 *(char **) arg = strdup("stereo");
734 break;
735 default:
736 *(char **) arg = malloc(32);
737 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
739 return M_PROPERTY_OK;
741 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
744 /// Balance (RW)
745 static int mp_property_balance(m_option_t * prop, int action, void *arg,
746 MPContext * mpctx)
748 float bal;
750 if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
751 return M_PROPERTY_UNAVAILABLE;
753 switch (action) {
754 case M_PROPERTY_GET:
755 if (!arg)
756 return M_PROPERTY_ERROR;
757 mixer_getbalance(&mpctx->mixer, arg);
758 return M_PROPERTY_OK;
759 case M_PROPERTY_PRINT: {
760 char** str = arg;
761 if (!arg)
762 return M_PROPERTY_ERROR;
763 mixer_getbalance(&mpctx->mixer, &bal);
764 if (bal == 0.f)
765 *str = strdup("center");
766 else if (bal == -1.f)
767 *str = strdup("left only");
768 else if (bal == 1.f)
769 *str = strdup("right only");
770 else {
771 unsigned right = (bal + 1.f) / 2.f * 100.f;
772 *str = malloc(sizeof("left xxx%, right xxx%"));
773 sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
775 return M_PROPERTY_OK;
777 case M_PROPERTY_STEP_UP:
778 case M_PROPERTY_STEP_DOWN:
779 mixer_getbalance(&mpctx->mixer, &bal);
780 bal += (arg ? *(float*)arg : .1f) *
781 (action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
782 M_PROPERTY_CLAMP(prop, bal);
783 mixer_setbalance(&mpctx->mixer, bal);
784 return M_PROPERTY_OK;
785 case M_PROPERTY_SET:
786 if (!arg)
787 return M_PROPERTY_ERROR;
788 M_PROPERTY_CLAMP(prop, *(float*)arg);
789 mixer_setbalance(&mpctx->mixer, *(float*)arg);
790 return M_PROPERTY_OK;
792 return M_PROPERTY_NOT_IMPLEMENTED;
795 /// Selected audio id (RW)
796 static int mp_property_audio(m_option_t * prop, int action, void *arg,
797 MPContext * mpctx)
799 int current_id = -1, tmp;
801 switch (action) {
802 case M_PROPERTY_GET:
803 if (!mpctx->sh_audio)
804 return M_PROPERTY_UNAVAILABLE;
805 if (!arg)
806 return M_PROPERTY_ERROR;
807 *(int *) arg = audio_id;
808 return M_PROPERTY_OK;
809 case M_PROPERTY_PRINT:
810 if (!mpctx->sh_audio)
811 return M_PROPERTY_UNAVAILABLE;
812 if (!arg)
813 return M_PROPERTY_ERROR;
815 if (audio_id < 0)
816 *(char **) arg = strdup(MSGTR_Disabled);
817 else {
818 char lang[40] = MSGTR_Unknown;
819 sh_audio_t* sh = mpctx->sh_audio;
820 if (sh && sh->lang)
821 av_strlcpy(lang, sh->lang, 40);
822 #ifdef CONFIG_DVDREAD
823 else if (mpctx->stream->type == STREAMTYPE_DVD) {
824 int code = dvd_lang_from_aid(mpctx->stream, audio_id);
825 if (code) {
826 lang[0] = code >> 8;
827 lang[1] = code;
828 lang[2] = 0;
831 #endif
833 #ifdef CONFIG_DVDNAV
834 else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
835 mp_dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
836 #endif
837 *(char **) arg = malloc(64);
838 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
840 return M_PROPERTY_OK;
842 case M_PROPERTY_STEP_UP:
843 case M_PROPERTY_SET:
844 if (!mpctx->demuxer)
845 return M_PROPERTY_UNAVAILABLE;
846 if (action == M_PROPERTY_SET && arg)
847 tmp = *((int *) arg);
848 else
849 tmp = -1;
850 current_id = mpctx->demuxer->audio->id;
851 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
852 if (audio_id == -2
853 || (audio_id > -1
854 && mpctx->demuxer->audio->id != current_id && current_id != -2))
855 uninit_player(INITIALIZED_AO | INITIALIZED_ACODEC);
856 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
857 sh_audio_t *sh2;
858 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
859 if (sh2) {
860 sh2->ds = mpctx->demuxer->audio;
861 mpctx->sh_audio = sh2;
862 reinit_audio_chain();
865 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
866 return M_PROPERTY_OK;
867 default:
868 return M_PROPERTY_NOT_IMPLEMENTED;
873 /// Selected video id (RW)
874 static int mp_property_video(m_option_t * prop, int action, void *arg,
875 MPContext * mpctx)
877 int current_id = -1, tmp;
879 switch (action) {
880 case M_PROPERTY_GET:
881 if (!mpctx->sh_video)
882 return M_PROPERTY_UNAVAILABLE;
883 if (!arg)
884 return M_PROPERTY_ERROR;
885 *(int *) arg = video_id;
886 return M_PROPERTY_OK;
887 case M_PROPERTY_PRINT:
888 if (!mpctx->sh_video)
889 return M_PROPERTY_UNAVAILABLE;
890 if (!arg)
891 return M_PROPERTY_ERROR;
893 if (video_id < 0)
894 *(char **) arg = strdup(MSGTR_Disabled);
895 else {
896 char lang[40] = MSGTR_Unknown;
897 *(char **) arg = malloc(64);
898 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
900 return M_PROPERTY_OK;
902 case M_PROPERTY_STEP_UP:
903 case M_PROPERTY_SET:
904 current_id = mpctx->demuxer->video->id;
905 if (action == M_PROPERTY_SET && arg)
906 tmp = *((int *) arg);
907 else
908 tmp = -1;
909 video_id = demuxer_switch_video(mpctx->demuxer, tmp);
910 if (video_id == -2
911 || (video_id > -1 && mpctx->demuxer->video->id != current_id
912 && current_id != -2))
913 uninit_player(INITIALIZED_VCODEC |
914 (fixed_vo && video_id != -2 ? 0 : INITIALIZED_VO));
915 if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
916 sh_video_t *sh2;
917 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
918 if (sh2) {
919 sh2->ds = mpctx->demuxer->video;
920 mpctx->sh_video = sh2;
921 reinit_video_chain();
924 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
925 return M_PROPERTY_OK;
927 default:
928 return M_PROPERTY_NOT_IMPLEMENTED;
932 static int mp_property_program(m_option_t * prop, int action, void *arg,
933 MPContext * mpctx)
935 demux_program_t prog;
937 switch (action) {
938 case M_PROPERTY_STEP_UP:
939 case M_PROPERTY_SET:
940 if (action == M_PROPERTY_SET && arg)
941 prog.progid = *((int *) arg);
942 else
943 prog.progid = -1;
944 if (demux_control
945 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
946 &prog) == DEMUXER_CTRL_NOTIMPL)
947 return M_PROPERTY_ERROR;
949 if (prog.aid < 0 && prog.vid < 0) {
950 mp_msg(MSGT_CPLAYER, MSGL_ERR, "Selected program contains no audio or video streams!\n");
951 return M_PROPERTY_ERROR;
953 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
954 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
955 return M_PROPERTY_OK;
957 default:
958 return M_PROPERTY_NOT_IMPLEMENTED;
962 ///@}
964 /// \defgroup VideoProperties Video properties
965 /// \ingroup Properties
966 ///@{
968 /// Fullscreen state (RW)
969 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
970 MPContext * mpctx)
973 if (!mpctx->video_out)
974 return M_PROPERTY_UNAVAILABLE;
976 switch (action) {
977 case M_PROPERTY_SET:
978 if (!arg)
979 return M_PROPERTY_ERROR;
980 M_PROPERTY_CLAMP(prop, *(int *) arg);
981 if (vo_fs == !!*(int *) arg)
982 return M_PROPERTY_OK;
983 case M_PROPERTY_STEP_UP:
984 case M_PROPERTY_STEP_DOWN:
985 #ifdef CONFIG_GUI
986 if (use_gui)
987 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
988 else
989 #endif
990 if (vo_config_count)
991 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
992 return M_PROPERTY_OK;
993 default:
994 return m_property_flag(prop, action, arg, &vo_fs);
998 static int mp_property_deinterlace(m_option_t * prop, int action,
999 void *arg, MPContext * mpctx)
1001 int deinterlace;
1002 vf_instance_t *vf;
1003 if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
1004 return M_PROPERTY_UNAVAILABLE;
1005 vf = mpctx->sh_video->vfilter;
1006 switch (action) {
1007 case M_PROPERTY_GET:
1008 if (!arg)
1009 return M_PROPERTY_ERROR;
1010 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
1011 return M_PROPERTY_OK;
1012 case M_PROPERTY_SET:
1013 if (!arg)
1014 return M_PROPERTY_ERROR;
1015 M_PROPERTY_CLAMP(prop, *(int *) arg);
1016 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
1017 return M_PROPERTY_OK;
1018 case M_PROPERTY_STEP_UP:
1019 case M_PROPERTY_STEP_DOWN:
1020 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
1021 deinterlace = !deinterlace;
1022 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
1023 return M_PROPERTY_OK;
1025 return M_PROPERTY_NOT_IMPLEMENTED;
1028 /// Panscan (RW)
1029 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
1030 MPContext * mpctx)
1033 if (!mpctx->video_out
1034 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1035 return M_PROPERTY_UNAVAILABLE;
1037 switch (action) {
1038 case M_PROPERTY_SET:
1039 if (!arg)
1040 return M_PROPERTY_ERROR;
1041 M_PROPERTY_CLAMP(prop, *(float *) arg);
1042 vo_panscan = *(float *) arg;
1043 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1044 return M_PROPERTY_OK;
1045 case M_PROPERTY_STEP_UP:
1046 case M_PROPERTY_STEP_DOWN:
1047 vo_panscan += (arg ? *(float *) arg : 0.1) *
1048 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1049 if (vo_panscan > 1)
1050 vo_panscan = 1;
1051 else if (vo_panscan < 0)
1052 vo_panscan = 0;
1053 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1054 return M_PROPERTY_OK;
1055 default:
1056 return m_property_float_range(prop, action, arg, &vo_panscan);
1060 /// Helper to set vo flags.
1061 /** \ingroup PropertyImplHelper
1063 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
1064 int vo_ctrl, int *vo_var, MPContext * mpctx)
1067 if (!mpctx->video_out)
1068 return M_PROPERTY_UNAVAILABLE;
1070 switch (action) {
1071 case M_PROPERTY_SET:
1072 if (!arg)
1073 return M_PROPERTY_ERROR;
1074 M_PROPERTY_CLAMP(prop, *(int *) arg);
1075 if (*vo_var == !!*(int *) arg)
1076 return M_PROPERTY_OK;
1077 case M_PROPERTY_STEP_UP:
1078 case M_PROPERTY_STEP_DOWN:
1079 if (vo_config_count)
1080 mpctx->video_out->control(vo_ctrl, 0);
1081 return M_PROPERTY_OK;
1082 default:
1083 return m_property_flag(prop, action, arg, vo_var);
1087 /// Window always on top (RW)
1088 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
1089 MPContext * mpctx)
1091 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
1092 mpctx);
1095 /// Display in the root window (RW)
1096 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
1097 MPContext * mpctx)
1099 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1100 &vo_rootwin, mpctx);
1103 /// Show window borders (RW)
1104 static int mp_property_border(m_option_t * prop, int action, void *arg,
1105 MPContext * mpctx)
1107 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1108 &vo_border, mpctx);
1111 /// Framedropping state (RW)
1112 static int mp_property_framedropping(m_option_t * prop, int action,
1113 void *arg, MPContext * mpctx)
1116 if (!mpctx->sh_video)
1117 return M_PROPERTY_UNAVAILABLE;
1119 switch (action) {
1120 case M_PROPERTY_PRINT:
1121 if (!arg)
1122 return M_PROPERTY_ERROR;
1123 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1124 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1125 MSGTR_Disabled));
1126 return M_PROPERTY_OK;
1127 default:
1128 return m_property_choice(prop, action, arg, &frame_dropping);
1132 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1133 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
1134 MPContext * mpctx)
1136 int *gamma = prop->priv, r, val;
1138 if (!mpctx->sh_video)
1139 return M_PROPERTY_UNAVAILABLE;
1141 if (gamma[0] == 1000) {
1142 gamma[0] = 0;
1143 get_video_colors(mpctx->sh_video, prop->name, gamma);
1146 switch (action) {
1147 case M_PROPERTY_SET:
1148 if (!arg)
1149 return M_PROPERTY_ERROR;
1150 M_PROPERTY_CLAMP(prop, *(int *) arg);
1151 *gamma = *(int *) arg;
1152 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1153 if (r <= 0)
1154 break;
1155 return r;
1156 case M_PROPERTY_GET:
1157 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1158 if (!arg)
1159 return M_PROPERTY_ERROR;
1160 *(int *)arg = val;
1161 return M_PROPERTY_OK;
1163 break;
1164 case M_PROPERTY_STEP_UP:
1165 case M_PROPERTY_STEP_DOWN:
1166 *gamma += (arg ? *(int *) arg : 1) *
1167 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1168 M_PROPERTY_CLAMP(prop, *gamma);
1169 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1170 if (r <= 0)
1171 break;
1172 return r;
1173 default:
1174 return M_PROPERTY_NOT_IMPLEMENTED;
1177 #ifdef CONFIG_TV
1178 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1179 int l = strlen(prop->name);
1180 char tv_prop[3 + l + 1];
1181 sprintf(tv_prop, "tv_%s", prop->name);
1182 return mp_property_do(tv_prop, action, arg, mpctx);
1184 #endif
1186 return M_PROPERTY_UNAVAILABLE;
1189 /// VSync (RW)
1190 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1191 MPContext * mpctx)
1193 return m_property_flag(prop, action, arg, &vo_vsync);
1196 /// Video codec tag (RO)
1197 static int mp_property_video_format(m_option_t * prop, int action,
1198 void *arg, MPContext * mpctx)
1200 char* meta;
1201 if (!mpctx->sh_video)
1202 return M_PROPERTY_UNAVAILABLE;
1203 switch(action) {
1204 case M_PROPERTY_PRINT:
1205 if (!arg)
1206 return M_PROPERTY_ERROR;
1207 switch(mpctx->sh_video->format) {
1208 case 0x10000001:
1209 meta = strdup ("mpeg1"); break;
1210 case 0x10000002:
1211 meta = strdup ("mpeg2"); break;
1212 case 0x10000004:
1213 meta = strdup ("mpeg4"); break;
1214 case 0x10000005:
1215 meta = strdup ("h264"); break;
1216 default:
1217 if(mpctx->sh_video->format >= 0x20202020) {
1218 meta = malloc(5);
1219 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1220 } else {
1221 meta = malloc(20);
1222 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1225 *(char**)arg = meta;
1226 return M_PROPERTY_OK;
1228 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1231 /// Video codec name (RO)
1232 static int mp_property_video_codec(m_option_t * prop, int action,
1233 void *arg, MPContext * mpctx)
1235 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1236 return M_PROPERTY_UNAVAILABLE;
1237 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1241 /// Video bitrate (RO)
1242 static int mp_property_video_bitrate(m_option_t * prop, int action,
1243 void *arg, MPContext * mpctx)
1245 if (!mpctx->sh_video)
1246 return M_PROPERTY_UNAVAILABLE;
1247 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1250 /// Video display width (RO)
1251 static int mp_property_width(m_option_t * prop, int action, void *arg,
1252 MPContext * mpctx)
1254 if (!mpctx->sh_video)
1255 return M_PROPERTY_UNAVAILABLE;
1256 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1259 /// Video display height (RO)
1260 static int mp_property_height(m_option_t * prop, int action, void *arg,
1261 MPContext * mpctx)
1263 if (!mpctx->sh_video)
1264 return M_PROPERTY_UNAVAILABLE;
1265 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1268 /// Video fps (RO)
1269 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1270 MPContext * mpctx)
1272 if (!mpctx->sh_video)
1273 return M_PROPERTY_UNAVAILABLE;
1274 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1277 /// Video aspect (RO)
1278 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1279 MPContext * mpctx)
1281 if (!mpctx->sh_video)
1282 return M_PROPERTY_UNAVAILABLE;
1283 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1286 ///@}
1288 /// \defgroup SubProprties Subtitles properties
1289 /// \ingroup Properties
1290 ///@{
1292 /// Text subtitle position (RW)
1293 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1294 MPContext * mpctx)
1296 if (!mpctx->sh_video)
1297 return M_PROPERTY_UNAVAILABLE;
1299 switch (action) {
1300 case M_PROPERTY_SET:
1301 if (!arg)
1302 return M_PROPERTY_ERROR;
1303 case M_PROPERTY_STEP_UP:
1304 case M_PROPERTY_STEP_DOWN:
1305 vo_osd_changed(OSDTYPE_SUBTITLE);
1306 default:
1307 return m_property_int_range(prop, action, arg, &sub_pos);
1311 /// Selected subtitles (RW)
1312 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1313 MPContext * mpctx)
1315 demux_stream_t *const d_sub = mpctx->d_sub;
1316 const int global_sub_size = mpctx->global_sub_size;
1317 int source = -1, reset_spu = 0;
1318 double pts = 0;
1319 char *sub_name;
1321 if (global_sub_size <= 0)
1322 return M_PROPERTY_UNAVAILABLE;
1324 switch (action) {
1325 case M_PROPERTY_GET:
1326 if (!arg)
1327 return M_PROPERTY_ERROR;
1328 *(int *) arg = mpctx->global_sub_pos;
1329 return M_PROPERTY_OK;
1330 case M_PROPERTY_PRINT:
1331 if (!arg)
1332 return M_PROPERTY_ERROR;
1333 *(char **) arg = malloc(64);
1334 (*(char **) arg)[63] = 0;
1335 sub_name = 0;
1336 if (subdata)
1337 sub_name = subdata->filename;
1338 #ifdef CONFIG_ASS
1339 if (ass_track && ass_track->name)
1340 sub_name = ass_track->name;
1341 #endif
1342 if (sub_name) {
1343 char *tmp, *tmp2;
1344 tmp = sub_name;
1345 if ((tmp2 = strrchr(tmp, '/')))
1346 tmp = tmp2 + 1;
1348 snprintf(*(char **) arg, 63, "(%d) %s%s",
1349 mpctx->set_of_sub_pos + 1,
1350 strlen(tmp) < 20 ? "" : "...",
1351 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1352 return M_PROPERTY_OK;
1354 #ifdef CONFIG_DVDNAV
1355 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1356 if (vo_spudec && dvdsub_id >= 0) {
1357 unsigned char lang[3];
1358 if (mp_dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1359 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1360 return M_PROPERTY_OK;
1364 #endif
1366 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1367 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1368 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1369 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1370 && d_sub && d_sub->sh && dvdsub_id >= 0) {
1371 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1372 if (!lang) lang = MSGTR_Unknown;
1373 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1374 return M_PROPERTY_OK;
1377 if (vo_vobsub && vobsub_id >= 0) {
1378 const char *language = MSGTR_Unknown;
1379 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1380 snprintf(*(char **) arg, 63, "(%d) %s",
1381 vobsub_id, language ? language : MSGTR_Unknown);
1382 return M_PROPERTY_OK;
1384 #ifdef CONFIG_DVDREAD
1385 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1386 && dvdsub_id >= 0) {
1387 char lang[3];
1388 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1389 lang[0] = code >> 8;
1390 lang[1] = code;
1391 lang[2] = 0;
1392 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1393 return M_PROPERTY_OK;
1395 #endif
1396 if (dvdsub_id >= 0) {
1397 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1398 return M_PROPERTY_OK;
1400 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1401 return M_PROPERTY_OK;
1403 case M_PROPERTY_SET:
1404 if (!arg)
1405 return M_PROPERTY_ERROR;
1406 if (*(int *) arg < -1)
1407 *(int *) arg = -1;
1408 else if (*(int *) arg >= global_sub_size)
1409 *(int *) arg = global_sub_size - 1;
1410 mpctx->global_sub_pos = *(int *) arg;
1411 break;
1412 case M_PROPERTY_STEP_UP:
1413 mpctx->global_sub_pos += 2;
1414 mpctx->global_sub_pos =
1415 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1416 break;
1417 case M_PROPERTY_STEP_DOWN:
1418 mpctx->global_sub_pos += global_sub_size + 1;
1419 mpctx->global_sub_pos =
1420 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1421 break;
1422 default:
1423 return M_PROPERTY_NOT_IMPLEMENTED;
1426 if (mpctx->global_sub_pos >= 0)
1427 source = sub_source(mpctx);
1429 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1430 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1431 global_sub_size,
1432 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1433 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1434 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1435 mpctx->global_sub_pos, source);
1437 mpctx->set_of_sub_pos = -1;
1438 subdata = NULL;
1440 vobsub_id = -1;
1441 dvdsub_id = -1;
1442 if (d_sub) {
1443 if (d_sub->id > -2)
1444 reset_spu = 1;
1445 d_sub->id = -2;
1447 #ifdef CONFIG_ASS
1448 ass_track = 0;
1449 #endif
1451 if (source == SUB_SOURCE_VOBSUB) {
1452 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1453 } else if (source == SUB_SOURCE_SUBS) {
1454 mpctx->set_of_sub_pos =
1455 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1456 #ifdef CONFIG_ASS
1457 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1458 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1459 else
1460 #endif
1462 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1463 vo_osd_changed(OSDTYPE_SUBTITLE);
1465 } else if (source == SUB_SOURCE_DEMUX) {
1466 dvdsub_id =
1467 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1468 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1469 int i = 0;
1470 // default: assume 1:1 mapping of sid and stream id
1471 d_sub->id = dvdsub_id;
1472 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1473 ds_free_packs(d_sub);
1474 for (i = 0; i < MAX_S_STREAMS; i++) {
1475 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1476 if (sh && sh->sid == dvdsub_id) {
1477 d_sub->id = i;
1478 d_sub->sh = sh;
1479 break;
1482 if (d_sub->sh && d_sub->id >= 0) {
1483 sh_sub_t *sh = d_sub->sh;
1484 if (sh->type == 'v')
1485 init_vo_spudec();
1486 #ifdef CONFIG_ASS
1487 else if (ass_enabled)
1488 ass_track = sh->ass_track;
1489 #endif
1490 } else {
1491 d_sub->id = -2;
1492 d_sub->sh = NULL;
1496 #ifdef CONFIG_DVDREAD
1497 if (vo_spudec
1498 && (mpctx->stream->type == STREAMTYPE_DVD
1499 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1500 && dvdsub_id < 0 && reset_spu) {
1501 dvdsub_id = -2;
1502 d_sub->id = dvdsub_id;
1504 #endif
1505 if (mpctx->sh_audio)
1506 pts = mpctx->sh_audio->pts;
1507 if (mpctx->sh_video)
1508 pts = mpctx->sh_video->pts;
1509 update_subtitles(mpctx->sh_video, pts, d_sub, 1);
1511 return M_PROPERTY_OK;
1514 /// Selected sub source (RW)
1515 static int mp_property_sub_source(m_option_t * prop, int action, void *arg,
1516 MPContext * mpctx)
1518 int source;
1519 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1520 return M_PROPERTY_UNAVAILABLE;
1522 switch (action) {
1523 case M_PROPERTY_GET:
1524 if (!arg)
1525 return M_PROPERTY_ERROR;
1526 *(int *) arg = sub_source(mpctx);
1527 return M_PROPERTY_OK;
1528 case M_PROPERTY_PRINT:
1529 if (!arg)
1530 return M_PROPERTY_ERROR;
1531 *(char **) arg = malloc(64);
1532 (*(char **) arg)[63] = 0;
1533 switch (sub_source(mpctx))
1535 case SUB_SOURCE_SUBS:
1536 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1537 break;
1538 case SUB_SOURCE_VOBSUB:
1539 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1540 break;
1541 case SUB_SOURCE_DEMUX:
1542 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1543 break;
1544 default:
1545 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1547 return M_PROPERTY_OK;
1548 case M_PROPERTY_SET:
1549 if (!arg)
1550 return M_PROPERTY_ERROR;
1551 M_PROPERTY_CLAMP(prop, *(int*)arg);
1552 if (*(int *) arg < 0)
1553 mpctx->global_sub_pos = -1;
1554 else if (*(int *) arg != sub_source(mpctx)) {
1555 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1556 return M_PROPERTY_UNAVAILABLE;
1557 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1559 break;
1560 case M_PROPERTY_STEP_UP:
1561 case M_PROPERTY_STEP_DOWN: {
1562 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1563 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1564 int step = (step_all > 0) ? 1 : -1;
1565 int cur_source = sub_source(mpctx);
1566 source = cur_source;
1567 while (step_all) {
1568 source += step;
1569 if (source >= SUB_SOURCES)
1570 source = -1;
1571 else if (source < -1)
1572 source = SUB_SOURCES - 1;
1573 if (source == cur_source || source == -1 ||
1574 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1575 step_all -= step;
1577 if (source == cur_source)
1578 return M_PROPERTY_OK;
1579 if (source == -1)
1580 mpctx->global_sub_pos = -1;
1581 else
1582 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1583 break;
1585 default:
1586 return M_PROPERTY_NOT_IMPLEMENTED;
1588 --mpctx->global_sub_pos;
1589 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1592 /// Selected subtitles from specific source (RW)
1593 static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg,
1594 MPContext * mpctx)
1596 int source, is_cur_source, offset;
1597 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1598 return M_PROPERTY_UNAVAILABLE;
1600 if (!strcmp(prop->name, "sub_file"))
1601 source = SUB_SOURCE_SUBS;
1602 else if (!strcmp(prop->name, "sub_vob"))
1603 source = SUB_SOURCE_VOBSUB;
1604 else if (!strcmp(prop->name, "sub_demux"))
1605 source = SUB_SOURCE_DEMUX;
1606 else
1607 return M_PROPERTY_ERROR;
1609 offset = mpctx->global_sub_indices[source];
1610 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1611 return M_PROPERTY_UNAVAILABLE;
1613 is_cur_source = sub_source(mpctx) == source;
1614 switch (action) {
1615 case M_PROPERTY_GET:
1616 if (!arg)
1617 return M_PROPERTY_ERROR;
1618 if (is_cur_source) {
1619 *(int *) arg = mpctx->global_sub_pos - offset;
1620 if (source == SUB_SOURCE_VOBSUB)
1621 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1623 else
1624 *(int *) arg = -1;
1625 return M_PROPERTY_OK;
1626 case M_PROPERTY_PRINT:
1627 if (!arg)
1628 return M_PROPERTY_ERROR;
1629 if (is_cur_source)
1630 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1631 *(char **) arg = malloc(64);
1632 (*(char **) arg)[63] = 0;
1633 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1634 return M_PROPERTY_OK;
1635 case M_PROPERTY_SET:
1636 if (!arg)
1637 return M_PROPERTY_ERROR;
1638 if (*(int *) arg >= 0) {
1639 int index = *(int *)arg;
1640 if (source == SUB_SOURCE_VOBSUB)
1641 index = vobsub_get_index_by_id(vo_vobsub, index);
1642 mpctx->global_sub_pos = offset + index;
1643 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1644 || sub_source(mpctx) != source) {
1645 mpctx->global_sub_pos = -1;
1646 *(int *) arg = -1;
1649 else
1650 mpctx->global_sub_pos = -1;
1651 break;
1652 case M_PROPERTY_STEP_UP:
1653 case M_PROPERTY_STEP_DOWN: {
1654 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1655 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1656 int step = (step_all > 0) ? 1 : -1;
1657 int max_sub_pos_for_source = -1;
1658 if (!is_cur_source)
1659 mpctx->global_sub_pos = -1;
1660 while (step_all) {
1661 if (mpctx->global_sub_pos == -1) {
1662 if (step > 0)
1663 mpctx->global_sub_pos = offset;
1664 else if (max_sub_pos_for_source == -1) {
1665 // Find max pos for specific source
1666 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1667 while (mpctx->global_sub_pos >= 0
1668 && sub_source(mpctx) != source)
1669 --mpctx->global_sub_pos;
1671 else
1672 mpctx->global_sub_pos = max_sub_pos_for_source;
1674 else {
1675 mpctx->global_sub_pos += step;
1676 if (mpctx->global_sub_pos < offset ||
1677 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1678 sub_source(mpctx) != source)
1679 mpctx->global_sub_pos = -1;
1681 step_all -= step;
1683 break;
1685 default:
1686 return M_PROPERTY_NOT_IMPLEMENTED;
1688 --mpctx->global_sub_pos;
1689 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1692 /// Subtitle delay (RW)
1693 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1694 MPContext * mpctx)
1696 if (!mpctx->sh_video)
1697 return M_PROPERTY_UNAVAILABLE;
1698 return m_property_delay(prop, action, arg, &sub_delay);
1701 /// Alignment of text subtitles (RW)
1702 static int mp_property_sub_alignment(m_option_t * prop, int action,
1703 void *arg, MPContext * mpctx)
1705 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1707 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1708 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1709 return M_PROPERTY_UNAVAILABLE;
1711 switch (action) {
1712 case M_PROPERTY_PRINT:
1713 if (!arg)
1714 return M_PROPERTY_ERROR;
1715 M_PROPERTY_CLAMP(prop, sub_alignment);
1716 *(char **) arg = strdup(name[sub_alignment]);
1717 return M_PROPERTY_OK;
1718 case M_PROPERTY_SET:
1719 if (!arg)
1720 return M_PROPERTY_ERROR;
1721 case M_PROPERTY_STEP_UP:
1722 case M_PROPERTY_STEP_DOWN:
1723 vo_osd_changed(OSDTYPE_SUBTITLE);
1724 default:
1725 return m_property_choice(prop, action, arg, &sub_alignment);
1729 /// Subtitle visibility (RW)
1730 static int mp_property_sub_visibility(m_option_t * prop, int action,
1731 void *arg, MPContext * mpctx)
1733 if (!mpctx->sh_video)
1734 return M_PROPERTY_UNAVAILABLE;
1736 switch (action) {
1737 case M_PROPERTY_SET:
1738 if (!arg)
1739 return M_PROPERTY_ERROR;
1740 case M_PROPERTY_STEP_UP:
1741 case M_PROPERTY_STEP_DOWN:
1742 vo_osd_changed(OSDTYPE_SUBTITLE);
1743 if (vo_spudec)
1744 vo_osd_changed(OSDTYPE_SPU);
1745 default:
1746 return m_property_flag(prop, action, arg, &sub_visibility);
1750 #ifdef CONFIG_ASS
1751 /// Use margins for libass subtitles (RW)
1752 static int mp_property_ass_use_margins(m_option_t * prop, int action,
1753 void *arg, MPContext * mpctx)
1755 if (!mpctx->sh_video)
1756 return M_PROPERTY_UNAVAILABLE;
1758 switch (action) {
1759 case M_PROPERTY_SET:
1760 if (!arg)
1761 return M_PROPERTY_ERROR;
1762 case M_PROPERTY_STEP_UP:
1763 case M_PROPERTY_STEP_DOWN:
1764 ass_force_reload = 1;
1765 default:
1766 return m_property_flag(prop, action, arg, &ass_use_margins);
1769 #endif
1771 /// Show only forced subtitles (RW)
1772 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1773 void *arg, MPContext * mpctx)
1775 if (!vo_spudec)
1776 return M_PROPERTY_UNAVAILABLE;
1778 switch (action) {
1779 case M_PROPERTY_SET:
1780 if (!arg)
1781 return M_PROPERTY_ERROR;
1782 case M_PROPERTY_STEP_UP:
1783 case M_PROPERTY_STEP_DOWN:
1784 m_property_flag(prop, action, arg, &forced_subs_only);
1785 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1786 return M_PROPERTY_OK;
1787 default:
1788 return m_property_flag(prop, action, arg, &forced_subs_only);
1793 #ifdef CONFIG_FREETYPE
1794 /// Subtitle scale (RW)
1795 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1796 MPContext * mpctx)
1799 switch (action) {
1800 case M_PROPERTY_SET:
1801 if (!arg)
1802 return M_PROPERTY_ERROR;
1803 M_PROPERTY_CLAMP(prop, *(float *) arg);
1804 #ifdef CONFIG_ASS
1805 if (ass_enabled) {
1806 ass_font_scale = *(float *) arg;
1807 ass_force_reload = 1;
1809 #endif
1810 text_font_scale_factor = *(float *) arg;
1811 force_load_font = 1;
1812 return M_PROPERTY_OK;
1813 case M_PROPERTY_STEP_UP:
1814 case M_PROPERTY_STEP_DOWN:
1815 #ifdef CONFIG_ASS
1816 if (ass_enabled) {
1817 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1818 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1819 M_PROPERTY_CLAMP(prop, ass_font_scale);
1820 ass_force_reload = 1;
1822 #endif
1823 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1824 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1825 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1826 force_load_font = 1;
1827 return M_PROPERTY_OK;
1828 default:
1829 #ifdef CONFIG_ASS
1830 if (ass_enabled)
1831 return m_property_float_ro(prop, action, arg, ass_font_scale);
1832 else
1833 #endif
1834 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1837 #endif
1839 ///@}
1841 /// \defgroup TVProperties TV properties
1842 /// \ingroup Properties
1843 ///@{
1845 #ifdef CONFIG_TV
1847 /// TV color settings (RW)
1848 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1849 MPContext * mpctx)
1851 int r, val;
1852 tvi_handle_t *tvh = mpctx->demuxer->priv;
1853 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1854 return M_PROPERTY_UNAVAILABLE;
1856 switch (action) {
1857 case M_PROPERTY_SET:
1858 if (!arg)
1859 return M_PROPERTY_ERROR;
1860 M_PROPERTY_CLAMP(prop, *(int *) arg);
1861 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1862 case M_PROPERTY_GET:
1863 return tv_get_color_options(tvh, (int) prop->priv, arg);
1864 case M_PROPERTY_STEP_UP:
1865 case M_PROPERTY_STEP_DOWN:
1866 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1867 if (!r)
1868 return M_PROPERTY_ERROR;
1869 val += (arg ? *(int *) arg : 1) *
1870 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1871 M_PROPERTY_CLAMP(prop, val);
1872 return tv_set_color_options(tvh, (int) prop->priv, val);
1874 return M_PROPERTY_ERROR;
1876 return M_PROPERTY_NOT_IMPLEMENTED;
1879 #endif
1881 #ifdef CONFIG_TV_TELETEXT
1882 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1883 MPContext * mpctx)
1885 int val,result;
1886 int base_ioctl=(int)prop->priv;
1888 for teletext's GET,SET,STEP ioctls this is not 0
1889 SET is GET+1
1890 STEP is GET+2
1892 tvi_handle_t *tvh = mpctx->demuxer->priv;
1893 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1894 return M_PROPERTY_UNAVAILABLE;
1895 if(!base_ioctl)
1896 return M_PROPERTY_ERROR;
1898 switch (action) {
1899 case M_PROPERTY_GET:
1900 if (!arg)
1901 return M_PROPERTY_ERROR;
1902 result=tvh->functions->control(tvh->priv, base_ioctl, arg);
1903 break;
1904 case M_PROPERTY_SET:
1905 if (!arg)
1906 return M_PROPERTY_ERROR;
1907 M_PROPERTY_CLAMP(prop, *(int *) arg);
1908 result=tvh->functions->control(tvh->priv, base_ioctl+1, arg);
1909 break;
1910 case M_PROPERTY_STEP_UP:
1911 case M_PROPERTY_STEP_DOWN:
1912 result=tvh->functions->control(tvh->priv, base_ioctl, &val);
1913 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1914 result=tvh->functions->control(tvh->priv, base_ioctl+1, &val);
1915 break;
1916 default:
1917 return M_PROPERTY_NOT_IMPLEMENTED;
1920 return result == TVI_CONTROL_TRUE ? M_PROPERTY_OK : M_PROPERTY_ERROR;
1923 static int mp_property_teletext_mode(m_option_t * prop, int action, void *arg,
1924 MPContext * mpctx)
1926 tvi_handle_t *tvh = mpctx->demuxer->priv;
1927 int result;
1928 int val;
1930 //with tvh==NULL will fail too
1931 result=mp_property_teletext_common(prop,action,arg,mpctx);
1932 if(result!=M_PROPERTY_OK)
1933 return result;
1935 if(tvh->functions->control(tvh->priv, prop->priv, &val)==TVI_CONTROL_TRUE && val)
1936 mp_input_set_section("teletext");
1937 else
1938 mp_input_set_section("tv");
1939 return M_PROPERTY_OK;
1942 static int mp_property_teletext_page(m_option_t * prop, int action, void *arg,
1943 MPContext * mpctx)
1945 tvi_handle_t *tvh = mpctx->demuxer->priv;
1946 int result;
1947 int val;
1948 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1949 return M_PROPERTY_UNAVAILABLE;
1950 switch(action){
1951 case M_PROPERTY_STEP_UP:
1952 case M_PROPERTY_STEP_DOWN:
1953 //This should be handled separately
1954 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1955 result=tvh->functions->control(tvh->priv, TV_VBI_CONTROL_STEP_PAGE, &val);
1956 break;
1957 default:
1958 result=mp_property_teletext_common(prop,action,arg,mpctx);
1960 return result;
1964 #endif /* CONFIG_TV_TELETEXT */
1966 ///@}
1968 /// All properties available in MPlayer.
1969 /** \ingroup Properties
1971 static const m_option_t mp_properties[] = {
1972 // General
1973 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1974 M_OPT_RANGE, 0, 3, NULL },
1975 { "loop", mp_property_loop, CONF_TYPE_INT,
1976 M_OPT_MIN, -1, 0, NULL },
1977 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1978 M_OPT_RANGE, 0.01, 100.0, NULL },
1979 { "filename", mp_property_filename, CONF_TYPE_STRING,
1980 0, 0, 0, NULL },
1981 { "path", mp_property_path, CONF_TYPE_STRING,
1982 0, 0, 0, NULL },
1983 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1984 0, 0, 0, NULL },
1985 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1986 M_OPT_MIN, 0, 0, NULL },
1987 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1988 M_OPT_MIN, 0, 0, NULL },
1989 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1990 M_OPT_MIN, 0, 0, NULL },
1991 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1992 M_OPT_MIN, 0, 0, NULL },
1993 { "length", mp_property_length, CONF_TYPE_TIME,
1994 M_OPT_MIN, 0, 0, NULL },
1995 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1996 M_OPT_RANGE, 0, 100, NULL },
1997 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1998 M_OPT_MIN, 0, 0, NULL },
1999 { "chapter", mp_property_chapter, CONF_TYPE_INT,
2000 M_OPT_MIN, 0, 0, NULL },
2001 { "chapters", mp_property_chapters, CONF_TYPE_INT,
2002 0, 0, 0, NULL },
2003 { "angle", mp_property_angle, CONF_TYPE_INT,
2004 CONF_RANGE, -2, 10, NULL },
2005 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2006 0, 0, 0, NULL },
2007 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2008 M_OPT_RANGE, 0, 1, NULL },
2010 // Audio
2011 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2012 M_OPT_RANGE, 0, 100, NULL },
2013 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2014 M_OPT_RANGE, 0, 1, NULL },
2015 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2016 M_OPT_RANGE, -100, 100, NULL },
2017 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2018 0, 0, 0, NULL },
2019 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2020 0, 0, 0, NULL },
2021 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2022 0, 0, 0, NULL },
2023 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2024 0, 0, 0, NULL },
2025 { "channels", mp_property_channels, CONF_TYPE_INT,
2026 0, 0, 0, NULL },
2027 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2028 CONF_RANGE, -2, 65535, NULL },
2029 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2030 M_OPT_RANGE, -1, 1, NULL },
2032 // Video
2033 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2034 M_OPT_RANGE, 0, 1, NULL },
2035 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2036 M_OPT_RANGE, 0, 1, NULL },
2037 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2038 M_OPT_RANGE, 0, 1, NULL },
2039 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2040 M_OPT_RANGE, 0, 1, NULL },
2041 { "border", mp_property_border, CONF_TYPE_FLAG,
2042 M_OPT_RANGE, 0, 1, NULL },
2043 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2044 M_OPT_RANGE, 0, 2, NULL },
2045 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2046 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2047 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2048 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2049 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2050 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2051 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2052 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2053 { "hue", mp_property_gamma, CONF_TYPE_INT,
2054 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2055 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2056 M_OPT_RANGE, 0, 1, NULL },
2057 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2058 M_OPT_RANGE, 0, 1, NULL },
2059 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2060 0, 0, 0, NULL },
2061 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2062 0, 0, 0, NULL },
2063 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2064 0, 0, 0, NULL },
2065 { "width", mp_property_width, CONF_TYPE_INT,
2066 0, 0, 0, NULL },
2067 { "height", mp_property_height, CONF_TYPE_INT,
2068 0, 0, 0, NULL },
2069 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2070 0, 0, 0, NULL },
2071 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2072 0, 0, 0, NULL },
2073 { "switch_video", mp_property_video, CONF_TYPE_INT,
2074 CONF_RANGE, -2, 65535, NULL },
2075 { "switch_program", mp_property_program, CONF_TYPE_INT,
2076 CONF_RANGE, -1, 65535, NULL },
2078 // Subs
2079 { "sub", mp_property_sub, CONF_TYPE_INT,
2080 M_OPT_MIN, -1, 0, NULL },
2081 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2082 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2083 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2084 M_OPT_MIN, -1, 0, NULL },
2085 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2086 M_OPT_MIN, -1, 0, NULL },
2087 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2088 M_OPT_MIN, -1, 0, NULL },
2089 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2090 0, 0, 0, NULL },
2091 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2092 M_OPT_RANGE, 0, 100, NULL },
2093 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2094 M_OPT_RANGE, 0, 2, NULL },
2095 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2096 M_OPT_RANGE, 0, 1, NULL },
2097 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2098 M_OPT_RANGE, 0, 1, NULL },
2099 #ifdef CONFIG_FREETYPE
2100 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2101 M_OPT_RANGE, 0, 100, NULL },
2102 #endif
2103 #ifdef CONFIG_ASS
2104 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2105 M_OPT_RANGE, 0, 1, NULL },
2106 #endif
2108 #ifdef CONFIG_TV
2109 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2110 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2111 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2112 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2113 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2114 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2115 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2116 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2117 #endif
2119 #ifdef CONFIG_TV_TELETEXT
2120 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2121 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2122 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2123 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2124 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2125 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2126 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2127 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2128 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2129 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2130 #endif
2132 { NULL, NULL, NULL, 0, 0, 0, NULL }
2136 int mp_property_do(const char *name, int action, void *val, void *ctx)
2138 return m_property_do(mp_properties, name, action, val, ctx);
2141 char* mp_property_print(const char *name, void* ctx)
2143 char* ret = NULL;
2144 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2145 return NULL;
2146 return ret;
2149 char *property_expand_string(MPContext * mpctx, char *str)
2151 return m_properties_expand_string(mp_properties, str, mpctx);
2154 void property_print_help(void)
2156 m_properties_print_help_list(mp_properties);
2160 ///@}
2161 // Properties group
2165 * \defgroup Command2Property Command to property bridge
2167 * It is used to handle most commands that just set a property
2168 * and optionally display something on the OSD.
2169 * Two kinds of commands are handled: adjust or toggle.
2171 * Adjust commands take 1 or 2 parameters: <value> <abs>
2172 * If <abs> is non-zero the property is set to the given value
2173 * otherwise it is adjusted.
2175 * Toggle commands take 0 or 1 parameters. With no parameter
2176 * or a value less than the property minimum it just steps the
2177 * property to its next value. Otherwise it sets it to the given
2178 * value.
2183 /// List of the commands that can be handled by setting a property.
2184 static struct {
2185 /// property name
2186 const char *name;
2187 /// cmd id
2188 int cmd;
2189 /// set/adjust or toggle command
2190 int toggle;
2191 /// progressbar type
2192 int osd_progbar;
2193 /// osd msg id if it must be shared
2194 int osd_id;
2195 /// osd msg template
2196 const char *osd_msg;
2197 } set_prop_cmd[] = {
2198 // general
2199 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2200 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2201 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2202 // audio
2203 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2204 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2205 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2206 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2207 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2208 // video
2209 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2210 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2211 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2212 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2213 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2214 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2215 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2216 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2217 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2218 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2219 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2220 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2221 // subs
2222 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2223 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2224 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2225 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2226 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2227 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2228 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2229 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2230 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2231 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2232 #ifdef CONFIG_FREETYPE
2233 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2234 #endif
2235 #ifdef CONFIG_ASS
2236 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2237 #endif
2238 #ifdef CONFIG_TV
2239 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2240 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2241 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2242 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2243 #endif
2244 { NULL, 0, 0, 0, -1, NULL }
2248 /// Handle commands that set a property.
2249 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
2251 int i, r;
2252 m_option_t* prop;
2253 const char *pname;
2255 // look for the command
2256 for (i = 0; set_prop_cmd[i].name; i++)
2257 if (set_prop_cmd[i].cmd == cmd->id)
2258 break;
2259 if (!(pname = set_prop_cmd[i].name))
2260 return 0;
2262 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2263 return 0;
2265 // toggle command
2266 if (set_prop_cmd[i].toggle) {
2267 // set to value
2268 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2269 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2270 else
2271 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2272 } else if (cmd->args[1].v.i) //set
2273 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2274 else // adjust
2275 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2277 if (r <= 0)
2278 return 1;
2280 if (set_prop_cmd[i].osd_progbar) {
2281 if (prop->type == CONF_TYPE_INT) {
2282 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2283 set_osd_bar(set_prop_cmd[i].osd_progbar,
2284 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2285 } else if (prop->type == CONF_TYPE_FLOAT) {
2286 float f;
2287 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2288 set_osd_bar(set_prop_cmd[i].osd_progbar,
2289 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2290 } else
2291 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2292 "Property use an unsupported type.\n");
2293 return 1;
2296 if (set_prop_cmd[i].osd_msg) {
2297 char *val = mp_property_print(pname, mpctx);
2298 if (val) {
2299 set_osd_msg(set_prop_cmd[i].osd_id >=
2300 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2301 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2302 free(val);
2305 return 1;
2308 #ifdef CONFIG_DVDNAV
2309 static const struct {
2310 const char *name;
2311 const mp_command_type cmd;
2312 } mp_dvdnav_bindings[] = {
2313 { "up", MP_CMD_DVDNAV_UP },
2314 { "down", MP_CMD_DVDNAV_DOWN },
2315 { "left", MP_CMD_DVDNAV_LEFT },
2316 { "right", MP_CMD_DVDNAV_RIGHT },
2317 { "menu", MP_CMD_DVDNAV_MENU },
2318 { "select", MP_CMD_DVDNAV_SELECT },
2319 { "prev", MP_CMD_DVDNAV_PREVMENU },
2320 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2323 * keep old dvdnav sub-command options for a while in order not to
2324 * break slave-mode API too suddenly.
2326 { "1", MP_CMD_DVDNAV_UP },
2327 { "2", MP_CMD_DVDNAV_DOWN },
2328 { "3", MP_CMD_DVDNAV_LEFT },
2329 { "4", MP_CMD_DVDNAV_RIGHT },
2330 { "5", MP_CMD_DVDNAV_MENU },
2331 { "6", MP_CMD_DVDNAV_SELECT },
2332 { "7", MP_CMD_DVDNAV_PREVMENU },
2333 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2334 { NULL, 0 }
2336 #endif
2338 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
2340 sh_audio_t * const sh_audio = mpctx->sh_audio;
2341 sh_video_t * const sh_video = mpctx->sh_video;
2342 int brk_cmd = 0;
2343 if (!set_property_command(mpctx, cmd))
2344 switch (cmd->id) {
2345 case MP_CMD_SEEK:{
2346 float v;
2347 int abs;
2348 if (sh_video)
2349 mpctx->osd_show_percentage = sh_video->fps;
2350 v = cmd->args[0].v.f;
2351 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2352 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2353 abs_seek_pos = SEEK_ABSOLUTE;
2354 if (sh_video)
2355 mpctx->osd_function =
2356 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2357 rel_seek_secs = v;
2358 } else if (abs) { /* Absolute seek by percentage */
2359 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2360 if (sh_video)
2361 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2362 rel_seek_secs = v / 100.0;
2363 } else {
2364 rel_seek_secs += v;
2365 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2367 brk_cmd = 1;
2369 break;
2371 case MP_CMD_SET_PROPERTY:{
2372 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2373 cmd->args[1].v.s, mpctx);
2374 if (r == M_PROPERTY_UNKNOWN)
2375 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2376 "Unknown property: '%s'\n", cmd->args[0].v.s);
2377 else if (r <= 0)
2378 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2379 "Failed to set property '%s' to '%s'.\n",
2380 cmd->args[0].v.s, cmd->args[1].v.s);
2382 break;
2384 case MP_CMD_STEP_PROPERTY:{
2385 void* arg = NULL;
2386 int r,i;
2387 double d;
2388 off_t o;
2389 if (cmd->args[1].v.f) {
2390 m_option_t* prop;
2391 if((r = mp_property_do(cmd->args[0].v.s,
2392 M_PROPERTY_GET_TYPE,
2393 &prop, mpctx)) <= 0)
2394 goto step_prop_err;
2395 if(prop->type == CONF_TYPE_INT ||
2396 prop->type == CONF_TYPE_FLAG)
2397 i = cmd->args[1].v.f, arg = &i;
2398 else if(prop->type == CONF_TYPE_FLOAT)
2399 arg = &cmd->args[1].v.f;
2400 else if(prop->type == CONF_TYPE_DOUBLE ||
2401 prop->type == CONF_TYPE_TIME)
2402 d = cmd->args[1].v.f, arg = &d;
2403 else if(prop->type == CONF_TYPE_POSITION)
2404 o = cmd->args[1].v.f, arg = &o;
2405 else
2406 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2407 "Ignoring step size stepping property '%s'.\n",
2408 cmd->args[0].v.s);
2410 r = mp_property_do(cmd->args[0].v.s,
2411 cmd->args[2].v.i < 0 ?
2412 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2413 arg, mpctx);
2414 step_prop_err:
2415 if (r == M_PROPERTY_UNKNOWN)
2416 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2417 "Unknown property: '%s'\n", cmd->args[0].v.s);
2418 else if (r <= 0)
2419 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2420 "Failed to increment property '%s' by %f.\n",
2421 cmd->args[0].v.s, cmd->args[1].v.f);
2423 break;
2425 case MP_CMD_GET_PROPERTY:{
2426 char *tmp;
2427 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2428 &tmp, mpctx) <= 0) {
2429 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2430 "Failed to get value of property '%s'.\n",
2431 cmd->args[0].v.s);
2432 break;
2434 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2435 cmd->args[0].v.s, tmp);
2436 free(tmp);
2438 break;
2440 case MP_CMD_EDL_MARK:
2441 if (edl_fd) {
2442 float v = sh_video ? sh_video->pts :
2443 playing_audio_pts(sh_audio, mpctx->d_audio,
2444 mpctx->audio_out);
2446 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2447 mpctx->begin_skip = v;
2448 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2449 } else {
2450 if (mpctx->begin_skip > v)
2451 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2452 else {
2453 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2454 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2456 mpctx->begin_skip = MP_NOPTS_VALUE;
2459 break;
2461 case MP_CMD_SWITCH_RATIO:
2462 if (!sh_video)
2463 break;
2464 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2465 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2466 else
2467 movie_aspect = cmd->args[0].v.f;
2468 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2469 break;
2471 case MP_CMD_SPEED_INCR:{
2472 float v = cmd->args[0].v.f;
2473 playback_speed += v;
2474 build_afilter_chain(sh_audio, &ao_data);
2475 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2476 playback_speed);
2477 } break;
2479 case MP_CMD_SPEED_MULT:{
2480 float v = cmd->args[0].v.f;
2481 playback_speed *= v;
2482 build_afilter_chain(sh_audio, &ao_data);
2483 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2484 playback_speed);
2485 } break;
2487 case MP_CMD_SPEED_SET:{
2488 float v = cmd->args[0].v.f;
2489 playback_speed = v;
2490 build_afilter_chain(sh_audio, &ao_data);
2491 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2492 playback_speed);
2493 } break;
2495 case MP_CMD_FRAME_STEP:
2496 case MP_CMD_PAUSE:
2497 cmd->pausing = 1;
2498 brk_cmd = 1;
2499 break;
2501 case MP_CMD_FILE_FILTER:
2502 file_filter = cmd->args[0].v.i;
2503 break;
2505 case MP_CMD_QUIT:
2506 exit_player_with_rc(EXIT_QUIT,
2507 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2509 case MP_CMD_PLAY_TREE_STEP:{
2510 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2511 int force = cmd->args[1].v.i;
2513 #ifdef CONFIG_GUI
2514 if (use_gui) {
2515 int i = 0;
2516 if (n > 0)
2517 for (i = 0; i < n; i++)
2518 mplNext();
2519 else
2520 for (i = 0; i < -1 * n; i++)
2521 mplPrev();
2522 } else
2523 #endif
2525 if (!force && mpctx->playtree_iter) {
2526 play_tree_iter_t *i =
2527 play_tree_iter_new_copy(mpctx->playtree_iter);
2528 if (play_tree_iter_step(i, n, 0) ==
2529 PLAY_TREE_ITER_ENTRY)
2530 mpctx->eof =
2531 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2532 play_tree_iter_free(i);
2533 } else
2534 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2535 if (mpctx->eof)
2536 mpctx->play_tree_step = n;
2537 brk_cmd = 1;
2540 break;
2542 case MP_CMD_PLAY_TREE_UP_STEP:{
2543 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2544 int force = cmd->args[1].v.i;
2546 if (!force && mpctx->playtree_iter) {
2547 play_tree_iter_t *i =
2548 play_tree_iter_new_copy(mpctx->playtree_iter);
2549 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2550 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2551 play_tree_iter_free(i);
2552 } else
2553 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2554 brk_cmd = 1;
2556 break;
2558 case MP_CMD_PLAY_ALT_SRC_STEP:
2559 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2560 int v = cmd->args[0].v.i;
2561 if (v > 0
2562 && mpctx->playtree_iter->file <
2563 mpctx->playtree_iter->num_files)
2564 mpctx->eof = PT_NEXT_SRC;
2565 else if (v < 0 && mpctx->playtree_iter->file > 1)
2566 mpctx->eof = PT_PREV_SRC;
2568 brk_cmd = 1;
2569 break;
2571 case MP_CMD_SUB_STEP:
2572 if (sh_video) {
2573 int movement = cmd->args[0].v.i;
2574 step_sub(subdata, sh_video->pts, movement);
2575 #ifdef CONFIG_ASS
2576 if (ass_track)
2577 sub_delay +=
2578 ass_step_sub(ass_track,
2579 (sh_video->pts +
2580 sub_delay) * 1000 + .5, movement) / 1000.;
2581 #endif
2582 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2583 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2585 break;
2587 case MP_CMD_SUB_LOG:
2588 log_sub();
2589 break;
2591 case MP_CMD_OSD:{
2592 int v = cmd->args[0].v.i;
2593 int max = (term_osd
2594 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2595 if (osd_level > max)
2596 osd_level = max;
2597 if (v < 0)
2598 osd_level = (osd_level + 1) % (max + 1);
2599 else
2600 osd_level = v > max ? max : v;
2601 /* Show OSD state when disabled, but not when an explicit
2602 argument is given to the OSD command, i.e. in slave mode. */
2603 if (v == -1 && osd_level <= 1)
2604 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2605 MSGTR_OSDosd,
2606 osd_level ? MSGTR_OSDenabled :
2607 MSGTR_OSDdisabled);
2608 else
2609 rm_osd_msg(OSD_MSG_OSD_STATUS);
2611 break;
2613 case MP_CMD_OSD_SHOW_TEXT:
2614 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2615 (cmd->args[1].v.i <
2616 0 ? osd_duration : cmd->args[1].v.i),
2617 "%-.63s", cmd->args[0].v.s);
2618 break;
2620 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2621 char *txt = m_properties_expand_string(mp_properties,
2622 cmd->args[0].v.s,
2623 mpctx);
2624 /* if no argument supplied take default osd_duration, else <arg> ms. */
2625 if (txt) {
2626 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2627 (cmd->args[1].v.i <
2628 0 ? osd_duration : cmd->args[1].v.i),
2629 "%-.63s", txt);
2630 free(txt);
2633 break;
2635 case MP_CMD_LOADFILE:{
2636 play_tree_t *e = play_tree_new();
2637 play_tree_add_file(e, cmd->args[0].v.s);
2639 if (cmd->args[1].v.i) // append
2640 play_tree_append_entry(mpctx->playtree->child, e);
2641 else {
2642 // Go back to the starting point.
2643 while (play_tree_iter_up_step
2644 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2645 /* NOP */ ;
2646 play_tree_free_list(mpctx->playtree->child, 1);
2647 play_tree_set_child(mpctx->playtree, e);
2648 pt_iter_goto_head(mpctx->playtree_iter);
2649 mpctx->eof = PT_NEXT_SRC;
2651 brk_cmd = 1;
2653 break;
2655 case MP_CMD_LOADLIST:{
2656 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2657 if (!e)
2658 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2659 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2660 else {
2661 if (cmd->args[1].v.i) // append
2662 play_tree_append_entry(mpctx->playtree->child, e);
2663 else {
2664 // Go back to the starting point.
2665 while (play_tree_iter_up_step
2666 (mpctx->playtree_iter, 0, 1)
2667 != PLAY_TREE_ITER_END)
2668 /* NOP */ ;
2669 play_tree_free_list(mpctx->playtree->child, 1);
2670 play_tree_set_child(mpctx->playtree, e);
2671 pt_iter_goto_head(mpctx->playtree_iter);
2672 mpctx->eof = PT_NEXT_SRC;
2675 brk_cmd = 1;
2677 break;
2679 case MP_CMD_STOP:
2680 // Go back to the starting point.
2681 while (play_tree_iter_up_step
2682 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2683 /* NOP */ ;
2684 mpctx->eof = PT_STOP;
2685 brk_cmd = 1;
2686 break;
2688 #ifdef CONFIG_RADIO
2689 case MP_CMD_RADIO_STEP_CHANNEL:
2690 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2691 int v = cmd->args[0].v.i;
2692 if (v > 0)
2693 radio_step_channel(mpctx->demuxer->stream,
2694 RADIO_CHANNEL_HIGHER);
2695 else
2696 radio_step_channel(mpctx->demuxer->stream,
2697 RADIO_CHANNEL_LOWER);
2698 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2699 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2700 MSGTR_OSDChannel,
2701 radio_get_channel_name(mpctx->demuxer->stream));
2704 break;
2706 case MP_CMD_RADIO_SET_CHANNEL:
2707 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2708 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2709 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2710 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2711 MSGTR_OSDChannel,
2712 radio_get_channel_name(mpctx->demuxer->stream));
2715 break;
2717 case MP_CMD_RADIO_SET_FREQ:
2718 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2719 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2720 break;
2722 case MP_CMD_RADIO_STEP_FREQ:
2723 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2724 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2725 break;
2726 #endif
2728 #ifdef CONFIG_TV
2729 case MP_CMD_TV_START_SCAN:
2730 if (mpctx->file_format == DEMUXER_TYPE_TV)
2731 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2732 break;
2733 case MP_CMD_TV_SET_FREQ:
2734 if (mpctx->file_format == DEMUXER_TYPE_TV)
2735 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2736 cmd->args[0].v.f * 16.0);
2737 #ifdef CONFIG_PVR
2738 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2739 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2740 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2741 pvr_get_current_channelname (mpctx->stream),
2742 pvr_get_current_stationname (mpctx->stream));
2744 #endif /* CONFIG_PVR */
2745 break;
2747 case MP_CMD_TV_STEP_FREQ:
2748 if (mpctx->file_format == DEMUXER_TYPE_TV)
2749 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2750 cmd->args[0].v.f * 16.0);
2751 #ifdef CONFIG_PVR
2752 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2753 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2754 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2755 pvr_get_current_channelname (mpctx->stream),
2756 pvr_get_current_frequency (mpctx->stream));
2758 #endif /* CONFIG_PVR */
2759 break;
2761 case MP_CMD_TV_SET_NORM:
2762 if (mpctx->file_format == DEMUXER_TYPE_TV)
2763 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2764 cmd->args[0].v.s);
2765 break;
2767 case MP_CMD_TV_STEP_CHANNEL:{
2768 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2769 int v = cmd->args[0].v.i;
2770 if (v > 0) {
2771 tv_step_channel((tvi_handle_t *) (mpctx->
2772 demuxer->priv),
2773 TV_CHANNEL_HIGHER);
2774 } else {
2775 tv_step_channel((tvi_handle_t *) (mpctx->
2776 demuxer->priv),
2777 TV_CHANNEL_LOWER);
2779 if (tv_channel_list) {
2780 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2781 MSGTR_OSDChannel, tv_channel_current->name);
2782 //vo_osd_changed(OSDTYPE_SUBTITLE);
2785 #ifdef CONFIG_PVR
2786 else if (mpctx->stream &&
2787 mpctx->stream->type == STREAMTYPE_PVR) {
2788 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2789 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2790 pvr_get_current_channelname (mpctx->stream),
2791 pvr_get_current_stationname (mpctx->stream));
2793 #endif /* CONFIG_PVR */
2795 #ifdef CONFIG_DVBIN
2796 if (mpctx->stream->type == STREAMTYPE_DVB) {
2797 int dir;
2798 int v = cmd->args[0].v.i;
2800 mpctx->last_dvb_step = v;
2801 if (v > 0)
2802 dir = DVB_CHANNEL_HIGHER;
2803 else
2804 dir = DVB_CHANNEL_LOWER;
2807 if (dvb_step_channel(mpctx->stream, dir))
2808 mpctx->eof = mpctx->dvbin_reopen = 1;
2810 #endif /* CONFIG_DVBIN */
2811 break;
2813 case MP_CMD_TV_SET_CHANNEL:
2814 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2815 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2816 cmd->args[0].v.s);
2817 if (tv_channel_list) {
2818 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2819 MSGTR_OSDChannel, tv_channel_current->name);
2820 //vo_osd_changed(OSDTYPE_SUBTITLE);
2823 #ifdef CONFIG_PVR
2824 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2825 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2826 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2827 pvr_get_current_channelname (mpctx->stream),
2828 pvr_get_current_stationname (mpctx->stream));
2830 #endif /* CONFIG_PVR */
2831 break;
2833 #ifdef CONFIG_DVBIN
2834 case MP_CMD_DVB_SET_CHANNEL:
2835 if (mpctx->stream->type == STREAMTYPE_DVB) {
2836 mpctx->last_dvb_step = 1;
2838 if (dvb_set_channel
2839 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2840 mpctx->eof = mpctx->dvbin_reopen = 1;
2842 break;
2843 #endif /* CONFIG_DVBIN */
2845 case MP_CMD_TV_LAST_CHANNEL:
2846 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2847 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2848 if (tv_channel_list) {
2849 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2850 MSGTR_OSDChannel, tv_channel_current->name);
2851 //vo_osd_changed(OSDTYPE_SUBTITLE);
2854 #ifdef CONFIG_PVR
2855 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2856 pvr_set_lastchannel (mpctx->stream);
2857 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2858 pvr_get_current_channelname (mpctx->stream),
2859 pvr_get_current_stationname (mpctx->stream));
2861 #endif /* CONFIG_PVR */
2862 break;
2864 case MP_CMD_TV_STEP_NORM:
2865 if (mpctx->file_format == DEMUXER_TYPE_TV)
2866 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2867 break;
2869 case MP_CMD_TV_STEP_CHANNEL_LIST:
2870 if (mpctx->file_format == DEMUXER_TYPE_TV)
2871 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2872 break;
2873 #ifdef CONFIG_TV_TELETEXT
2874 case MP_CMD_TV_TELETEXT_ADD_DEC:
2876 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2877 if (mpctx->file_format == DEMUXER_TYPE_TV)
2878 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_ADD_DEC,&(cmd->args[0].v.s));
2879 break;
2881 case MP_CMD_TV_TELETEXT_GO_LINK:
2883 tvi_handle_t* tvh=(tvi_handle_t *)(mpctx->demuxer->priv);
2884 if (mpctx->file_format == DEMUXER_TYPE_TV)
2885 tvh->functions->control(tvh->priv,TV_VBI_CONTROL_GO_LINK,&(cmd->args[0].v.i));
2886 break;
2888 #endif /* CONFIG_TV_TELETEXT */
2889 #endif /* CONFIG_TV */
2891 case MP_CMD_SUB_LOAD:
2892 if (sh_video) {
2893 int n = mpctx->set_of_sub_size;
2894 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2895 if (n != mpctx->set_of_sub_size) {
2896 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2897 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2898 mpctx->global_sub_size;
2899 ++mpctx->global_sub_size;
2902 break;
2904 case MP_CMD_SUB_REMOVE:
2905 if (sh_video) {
2906 int v = cmd->args[0].v.i;
2907 sub_data *subd;
2908 if (v < 0) {
2909 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2910 subd = mpctx->set_of_subtitles[v];
2911 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2912 MSGTR_RemovedSubtitleFile, v + 1,
2913 filename_recode(subd->filename));
2914 sub_free(subd);
2915 mpctx->set_of_subtitles[v] = NULL;
2917 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2918 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2919 mpctx->set_of_sub_size = 0;
2920 if (mpctx->set_of_sub_pos >= 0) {
2921 mpctx->global_sub_pos = -2;
2922 subdata = NULL;
2923 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2925 } else if (v < mpctx->set_of_sub_size) {
2926 subd = mpctx->set_of_subtitles[v];
2927 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2928 MSGTR_RemovedSubtitleFile, v + 1,
2929 filename_recode(subd->filename));
2930 sub_free(subd);
2931 if (mpctx->set_of_sub_pos == v) {
2932 mpctx->global_sub_pos = -2;
2933 subdata = NULL;
2934 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2935 } else if (mpctx->set_of_sub_pos > v) {
2936 --mpctx->set_of_sub_pos;
2937 --mpctx->global_sub_pos;
2939 while (++v < mpctx->set_of_sub_size)
2940 mpctx->set_of_subtitles[v - 1] =
2941 mpctx->set_of_subtitles[v];
2942 --mpctx->set_of_sub_size;
2943 --mpctx->global_sub_size;
2944 if (mpctx->set_of_sub_size <= 0)
2945 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2946 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2949 break;
2951 case MP_CMD_GET_SUB_VISIBILITY:
2952 if (sh_video) {
2953 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2954 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2956 break;
2958 case MP_CMD_SCREENSHOT:
2959 if (vo_config_count) {
2960 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2961 if (CONTROL_OK !=
2962 ((vf_instance_t *) sh_video->vfilter)->
2963 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2964 &cmd->args[0].v.i))
2965 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2967 break;
2969 case MP_CMD_VF_CHANGE_RECTANGLE:
2970 if (!sh_video)
2971 break;
2972 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2973 break;
2975 case MP_CMD_GET_TIME_LENGTH:{
2976 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2977 demuxer_get_time_length(mpctx->demuxer));
2979 break;
2981 case MP_CMD_GET_FILENAME:{
2982 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2983 get_metadata(META_NAME));
2985 break;
2987 case MP_CMD_GET_VIDEO_CODEC:{
2988 char *inf = get_metadata(META_VIDEO_CODEC);
2989 if (!inf)
2990 inf = strdup("");
2991 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2992 free(inf);
2994 break;
2996 case MP_CMD_GET_VIDEO_BITRATE:{
2997 char *inf = get_metadata(META_VIDEO_BITRATE);
2998 if (!inf)
2999 inf = strdup("");
3000 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
3001 free(inf);
3003 break;
3005 case MP_CMD_GET_VIDEO_RESOLUTION:{
3006 char *inf = get_metadata(META_VIDEO_RESOLUTION);
3007 if (!inf)
3008 inf = strdup("");
3009 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3010 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3011 free(inf);
3013 break;
3015 case MP_CMD_GET_AUDIO_CODEC:{
3016 char *inf = get_metadata(META_AUDIO_CODEC);
3017 if (!inf)
3018 inf = strdup("");
3019 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3020 free(inf);
3022 break;
3024 case MP_CMD_GET_AUDIO_BITRATE:{
3025 char *inf = get_metadata(META_AUDIO_BITRATE);
3026 if (!inf)
3027 inf = strdup("");
3028 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3029 free(inf);
3031 break;
3033 case MP_CMD_GET_AUDIO_SAMPLES:{
3034 char *inf = get_metadata(META_AUDIO_SAMPLES);
3035 if (!inf)
3036 inf = strdup("");
3037 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3038 free(inf);
3040 break;
3042 case MP_CMD_GET_META_TITLE:{
3043 char *inf = get_metadata(META_INFO_TITLE);
3044 if (!inf)
3045 inf = strdup("");
3046 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3047 free(inf);
3049 break;
3051 case MP_CMD_GET_META_ARTIST:{
3052 char *inf = get_metadata(META_INFO_ARTIST);
3053 if (!inf)
3054 inf = strdup("");
3055 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3056 free(inf);
3058 break;
3060 case MP_CMD_GET_META_ALBUM:{
3061 char *inf = get_metadata(META_INFO_ALBUM);
3062 if (!inf)
3063 inf = strdup("");
3064 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3065 free(inf);
3067 break;
3069 case MP_CMD_GET_META_YEAR:{
3070 char *inf = get_metadata(META_INFO_YEAR);
3071 if (!inf)
3072 inf = strdup("");
3073 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3074 free(inf);
3076 break;
3078 case MP_CMD_GET_META_COMMENT:{
3079 char *inf = get_metadata(META_INFO_COMMENT);
3080 if (!inf)
3081 inf = strdup("");
3082 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3083 free(inf);
3085 break;
3087 case MP_CMD_GET_META_TRACK:{
3088 char *inf = get_metadata(META_INFO_TRACK);
3089 if (!inf)
3090 inf = strdup("");
3091 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3092 free(inf);
3094 break;
3096 case MP_CMD_GET_META_GENRE:{
3097 char *inf = get_metadata(META_INFO_GENRE);
3098 if (!inf)
3099 inf = strdup("");
3100 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3101 free(inf);
3103 break;
3105 case MP_CMD_GET_VO_FULLSCREEN:
3106 if (mpctx->video_out && vo_config_count)
3107 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3108 break;
3110 case MP_CMD_GET_PERCENT_POS:
3111 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3112 demuxer_get_percent_pos(mpctx->demuxer));
3113 break;
3115 case MP_CMD_GET_TIME_POS:{
3116 float pos = 0;
3117 if (sh_video)
3118 pos = sh_video->pts;
3119 else if (sh_audio && mpctx->audio_out)
3120 pos =
3121 playing_audio_pts(sh_audio, mpctx->d_audio,
3122 mpctx->audio_out);
3123 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3125 break;
3127 case MP_CMD_RUN:
3128 #ifndef __MINGW32__
3129 if (!fork()) {
3130 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3131 exit(0);
3133 #endif
3134 break;
3136 case MP_CMD_KEYDOWN_EVENTS:
3137 mplayer_put_key(cmd->args[0].v.i);
3138 break;
3140 case MP_CMD_SET_MOUSE_POS:{
3141 int pointer_x, pointer_y;
3142 double dx, dy;
3143 pointer_x = cmd->args[0].v.i;
3144 pointer_y = cmd->args[1].v.i;
3145 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
3146 #ifdef CONFIG_DVDNAV
3147 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3148 && dx > 0.0 && dy > 0.0) {
3149 int button = -1;
3150 pointer_x = (int) (dx * (double) sh_video->disp_w);
3151 pointer_y = (int) (dy * (double) sh_video->disp_h);
3152 mp_dvdnav_update_mouse_pos(mpctx->stream,
3153 pointer_x, pointer_y, &button);
3154 if (osd_level > 1 && button > 0)
3155 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3156 "Selected button number %d", button);
3158 #endif
3159 #ifdef CONFIG_MENU
3160 if (use_menu && dx >= 0.0 && dy >= 0.0)
3161 menu_update_mouse_pos(dx, dy);
3162 #endif
3164 break;
3166 #ifdef CONFIG_DVDNAV
3167 case MP_CMD_DVDNAV:{
3168 int button = -1;
3169 int i;
3170 mp_command_type command = 0;
3171 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3172 break;
3174 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3175 if (cmd->args[0].v.s &&
3176 !strcasecmp (cmd->args[0].v.s,
3177 mp_dvdnav_bindings[i].name))
3178 command = mp_dvdnav_bindings[i].cmd;
3180 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3181 if (osd_level > 1 && button > 0)
3182 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3183 "Selected button number %d", button);
3185 break;
3187 case MP_CMD_SWITCH_TITLE:
3188 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3189 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3190 break;
3192 #endif
3194 default:
3195 #ifdef CONFIG_GUI
3196 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3197 guiGetEvent(guiIEvent, (char *) cmd->id);
3198 else
3199 #endif
3200 mp_msg(MSGT_CPLAYER, MSGL_V,
3201 "Received unknown cmd %s\n", cmd->name);
3204 switch (cmd->pausing) {
3205 case 1: // "pausing"
3206 mpctx->osd_function = OSD_PAUSE;
3207 break;
3208 case 3: // "pausing_toggle"
3209 mpctx->was_paused = !mpctx->was_paused;
3210 if (mpctx->was_paused)
3211 mpctx->osd_function = OSD_PAUSE;
3212 else if (mpctx->osd_function == OSD_PAUSE)
3213 mpctx->osd_function = OSD_PLAY;
3214 break;
3215 case 2: // "pausing_keep"
3216 if (mpctx->was_paused)
3217 mpctx->osd_function = OSD_PAUSE;
3219 return brk_cmd;