Fix build on SuperH.
[mplayer/glamo.git] / command.c
blob1edcc42bcb73208e8e81eabe56d9fde2a6e492aa
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 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDDeinterlace,
1024 deinterlace ? MSGTR_Enabled : MSGTR_Disabled);
1025 return M_PROPERTY_OK;
1027 return M_PROPERTY_NOT_IMPLEMENTED;
1030 /// Panscan (RW)
1031 static int mp_property_panscan(m_option_t * prop, int action, void *arg,
1032 MPContext * mpctx)
1035 if (!mpctx->video_out
1036 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
1037 return M_PROPERTY_UNAVAILABLE;
1039 switch (action) {
1040 case M_PROPERTY_SET:
1041 if (!arg)
1042 return M_PROPERTY_ERROR;
1043 M_PROPERTY_CLAMP(prop, *(float *) arg);
1044 vo_panscan = *(float *) arg;
1045 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1046 return M_PROPERTY_OK;
1047 case M_PROPERTY_STEP_UP:
1048 case M_PROPERTY_STEP_DOWN:
1049 vo_panscan += (arg ? *(float *) arg : 0.1) *
1050 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1051 if (vo_panscan > 1)
1052 vo_panscan = 1;
1053 else if (vo_panscan < 0)
1054 vo_panscan = 0;
1055 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
1056 return M_PROPERTY_OK;
1057 default:
1058 return m_property_float_range(prop, action, arg, &vo_panscan);
1062 /// Helper to set vo flags.
1063 /** \ingroup PropertyImplHelper
1065 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
1066 int vo_ctrl, int *vo_var, MPContext * mpctx)
1069 if (!mpctx->video_out)
1070 return M_PROPERTY_UNAVAILABLE;
1072 switch (action) {
1073 case M_PROPERTY_SET:
1074 if (!arg)
1075 return M_PROPERTY_ERROR;
1076 M_PROPERTY_CLAMP(prop, *(int *) arg);
1077 if (*vo_var == !!*(int *) arg)
1078 return M_PROPERTY_OK;
1079 case M_PROPERTY_STEP_UP:
1080 case M_PROPERTY_STEP_DOWN:
1081 if (vo_config_count)
1082 mpctx->video_out->control(vo_ctrl, 0);
1083 return M_PROPERTY_OK;
1084 default:
1085 return m_property_flag(prop, action, arg, vo_var);
1089 /// Window always on top (RW)
1090 static int mp_property_ontop(m_option_t * prop, int action, void *arg,
1091 MPContext * mpctx)
1093 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
1094 mpctx);
1097 /// Display in the root window (RW)
1098 static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
1099 MPContext * mpctx)
1101 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
1102 &vo_rootwin, mpctx);
1105 /// Show window borders (RW)
1106 static int mp_property_border(m_option_t * prop, int action, void *arg,
1107 MPContext * mpctx)
1109 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
1110 &vo_border, mpctx);
1113 /// Framedropping state (RW)
1114 static int mp_property_framedropping(m_option_t * prop, int action,
1115 void *arg, MPContext * mpctx)
1118 if (!mpctx->sh_video)
1119 return M_PROPERTY_UNAVAILABLE;
1121 switch (action) {
1122 case M_PROPERTY_PRINT:
1123 if (!arg)
1124 return M_PROPERTY_ERROR;
1125 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
1126 (frame_dropping == 2 ? MSGTR_HardFrameDrop :
1127 MSGTR_Disabled));
1128 return M_PROPERTY_OK;
1129 default:
1130 return m_property_choice(prop, action, arg, &frame_dropping);
1134 /// Color settings, try to use vf/vo then fall back on TV. (RW)
1135 static int mp_property_gamma(m_option_t * prop, int action, void *arg,
1136 MPContext * mpctx)
1138 int *gamma = prop->priv, r, val;
1140 if (!mpctx->sh_video)
1141 return M_PROPERTY_UNAVAILABLE;
1143 if (gamma[0] == 1000) {
1144 gamma[0] = 0;
1145 get_video_colors(mpctx->sh_video, prop->name, gamma);
1148 switch (action) {
1149 case M_PROPERTY_SET:
1150 if (!arg)
1151 return M_PROPERTY_ERROR;
1152 M_PROPERTY_CLAMP(prop, *(int *) arg);
1153 *gamma = *(int *) arg;
1154 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1155 if (r <= 0)
1156 break;
1157 return r;
1158 case M_PROPERTY_GET:
1159 if (get_video_colors(mpctx->sh_video, prop->name, &val) > 0) {
1160 if (!arg)
1161 return M_PROPERTY_ERROR;
1162 *(int *)arg = val;
1163 return M_PROPERTY_OK;
1165 break;
1166 case M_PROPERTY_STEP_UP:
1167 case M_PROPERTY_STEP_DOWN:
1168 *gamma += (arg ? *(int *) arg : 1) *
1169 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1170 M_PROPERTY_CLAMP(prop, *gamma);
1171 r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
1172 if (r <= 0)
1173 break;
1174 return r;
1175 default:
1176 return M_PROPERTY_NOT_IMPLEMENTED;
1179 #ifdef CONFIG_TV
1180 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) {
1181 int l = strlen(prop->name);
1182 char tv_prop[3 + l + 1];
1183 sprintf(tv_prop, "tv_%s", prop->name);
1184 return mp_property_do(tv_prop, action, arg, mpctx);
1186 #endif
1188 return M_PROPERTY_UNAVAILABLE;
1191 /// VSync (RW)
1192 static int mp_property_vsync(m_option_t * prop, int action, void *arg,
1193 MPContext * mpctx)
1195 return m_property_flag(prop, action, arg, &vo_vsync);
1198 /// Video codec tag (RO)
1199 static int mp_property_video_format(m_option_t * prop, int action,
1200 void *arg, MPContext * mpctx)
1202 char* meta;
1203 if (!mpctx->sh_video)
1204 return M_PROPERTY_UNAVAILABLE;
1205 switch(action) {
1206 case M_PROPERTY_PRINT:
1207 if (!arg)
1208 return M_PROPERTY_ERROR;
1209 switch(mpctx->sh_video->format) {
1210 case 0x10000001:
1211 meta = strdup ("mpeg1"); break;
1212 case 0x10000002:
1213 meta = strdup ("mpeg2"); break;
1214 case 0x10000004:
1215 meta = strdup ("mpeg4"); break;
1216 case 0x10000005:
1217 meta = strdup ("h264"); break;
1218 default:
1219 if(mpctx->sh_video->format >= 0x20202020) {
1220 meta = malloc(5);
1221 sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
1222 } else {
1223 meta = malloc(20);
1224 sprintf (meta, "0x%08X", mpctx->sh_video->format);
1227 *(char**)arg = meta;
1228 return M_PROPERTY_OK;
1230 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format);
1233 /// Video codec name (RO)
1234 static int mp_property_video_codec(m_option_t * prop, int action,
1235 void *arg, MPContext * mpctx)
1237 if (!mpctx->sh_video || !mpctx->sh_video->codec)
1238 return M_PROPERTY_UNAVAILABLE;
1239 return m_property_string_ro(prop, action, arg, mpctx->sh_video->codec->name);
1243 /// Video bitrate (RO)
1244 static int mp_property_video_bitrate(m_option_t * prop, int action,
1245 void *arg, MPContext * mpctx)
1247 if (!mpctx->sh_video)
1248 return M_PROPERTY_UNAVAILABLE;
1249 return m_property_bitrate(prop, action, arg, mpctx->sh_video->i_bps);
1252 /// Video display width (RO)
1253 static int mp_property_width(m_option_t * prop, int action, void *arg,
1254 MPContext * mpctx)
1256 if (!mpctx->sh_video)
1257 return M_PROPERTY_UNAVAILABLE;
1258 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w);
1261 /// Video display height (RO)
1262 static int mp_property_height(m_option_t * prop, int action, void *arg,
1263 MPContext * mpctx)
1265 if (!mpctx->sh_video)
1266 return M_PROPERTY_UNAVAILABLE;
1267 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h);
1270 /// Video fps (RO)
1271 static int mp_property_fps(m_option_t * prop, int action, void *arg,
1272 MPContext * mpctx)
1274 if (!mpctx->sh_video)
1275 return M_PROPERTY_UNAVAILABLE;
1276 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps);
1279 /// Video aspect (RO)
1280 static int mp_property_aspect(m_option_t * prop, int action, void *arg,
1281 MPContext * mpctx)
1283 if (!mpctx->sh_video)
1284 return M_PROPERTY_UNAVAILABLE;
1285 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect);
1288 ///@}
1290 /// \defgroup SubProprties Subtitles properties
1291 /// \ingroup Properties
1292 ///@{
1294 /// Text subtitle position (RW)
1295 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg,
1296 MPContext * mpctx)
1298 if (!mpctx->sh_video)
1299 return M_PROPERTY_UNAVAILABLE;
1301 switch (action) {
1302 case M_PROPERTY_SET:
1303 if (!arg)
1304 return M_PROPERTY_ERROR;
1305 case M_PROPERTY_STEP_UP:
1306 case M_PROPERTY_STEP_DOWN:
1307 vo_osd_changed(OSDTYPE_SUBTITLE);
1308 default:
1309 return m_property_int_range(prop, action, arg, &sub_pos);
1313 /// Selected subtitles (RW)
1314 static int mp_property_sub(m_option_t * prop, int action, void *arg,
1315 MPContext * mpctx)
1317 demux_stream_t *const d_sub = mpctx->d_sub;
1318 const int global_sub_size = mpctx->global_sub_size;
1319 int source = -1, reset_spu = 0;
1320 double pts = 0;
1321 char *sub_name;
1323 if (global_sub_size <= 0)
1324 return M_PROPERTY_UNAVAILABLE;
1326 switch (action) {
1327 case M_PROPERTY_GET:
1328 if (!arg)
1329 return M_PROPERTY_ERROR;
1330 *(int *) arg = mpctx->global_sub_pos;
1331 return M_PROPERTY_OK;
1332 case M_PROPERTY_PRINT:
1333 if (!arg)
1334 return M_PROPERTY_ERROR;
1335 *(char **) arg = malloc(64);
1336 (*(char **) arg)[63] = 0;
1337 sub_name = 0;
1338 if (subdata)
1339 sub_name = subdata->filename;
1340 #ifdef CONFIG_ASS
1341 if (ass_track && ass_track->name)
1342 sub_name = ass_track->name;
1343 #endif
1344 if (sub_name) {
1345 char *tmp, *tmp2;
1346 tmp = sub_name;
1347 if ((tmp2 = strrchr(tmp, '/')))
1348 tmp = tmp2 + 1;
1350 snprintf(*(char **) arg, 63, "(%d) %s%s",
1351 mpctx->set_of_sub_pos + 1,
1352 strlen(tmp) < 20 ? "" : "...",
1353 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
1354 return M_PROPERTY_OK;
1356 #ifdef CONFIG_DVDNAV
1357 if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
1358 if (vo_spudec && dvdsub_id >= 0) {
1359 unsigned char lang[3];
1360 if (mp_dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) {
1361 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1362 return M_PROPERTY_OK;
1366 #endif
1368 if ((mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA
1369 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF
1370 || mpctx->demuxer->type == DEMUXER_TYPE_LAVF_PREFERRED
1371 || mpctx->demuxer->type == DEMUXER_TYPE_OGG)
1372 && d_sub && d_sub->sh && dvdsub_id >= 0) {
1373 const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
1374 if (!lang) lang = MSGTR_Unknown;
1375 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1376 return M_PROPERTY_OK;
1379 if (vo_vobsub && vobsub_id >= 0) {
1380 const char *language = MSGTR_Unknown;
1381 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1382 snprintf(*(char **) arg, 63, "(%d) %s",
1383 vobsub_id, language ? language : MSGTR_Unknown);
1384 return M_PROPERTY_OK;
1386 #ifdef CONFIG_DVDREAD
1387 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD
1388 && dvdsub_id >= 0) {
1389 char lang[3];
1390 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id);
1391 lang[0] = code >> 8;
1392 lang[1] = code;
1393 lang[2] = 0;
1394 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
1395 return M_PROPERTY_OK;
1397 #endif
1398 if (dvdsub_id >= 0) {
1399 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown);
1400 return M_PROPERTY_OK;
1402 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1403 return M_PROPERTY_OK;
1405 case M_PROPERTY_SET:
1406 if (!arg)
1407 return M_PROPERTY_ERROR;
1408 if (*(int *) arg < -1)
1409 *(int *) arg = -1;
1410 else if (*(int *) arg >= global_sub_size)
1411 *(int *) arg = global_sub_size - 1;
1412 mpctx->global_sub_pos = *(int *) arg;
1413 break;
1414 case M_PROPERTY_STEP_UP:
1415 mpctx->global_sub_pos += 2;
1416 mpctx->global_sub_pos =
1417 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1418 break;
1419 case M_PROPERTY_STEP_DOWN:
1420 mpctx->global_sub_pos += global_sub_size + 1;
1421 mpctx->global_sub_pos =
1422 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1;
1423 break;
1424 default:
1425 return M_PROPERTY_NOT_IMPLEMENTED;
1428 if (mpctx->global_sub_pos >= 0)
1429 source = sub_source(mpctx);
1431 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1432 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1433 global_sub_size,
1434 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB],
1435 mpctx->global_sub_indices[SUB_SOURCE_SUBS],
1436 mpctx->global_sub_indices[SUB_SOURCE_DEMUX],
1437 mpctx->global_sub_pos, source);
1439 mpctx->set_of_sub_pos = -1;
1440 subdata = NULL;
1442 vobsub_id = -1;
1443 dvdsub_id = -1;
1444 if (d_sub) {
1445 if (d_sub->id > -2)
1446 reset_spu = 1;
1447 d_sub->id = -2;
1449 #ifdef CONFIG_ASS
1450 ass_track = 0;
1451 #endif
1453 if (source == SUB_SOURCE_VOBSUB) {
1454 vobsub_id = vobsub_get_id_by_index(vo_vobsub, mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]);
1455 } else if (source == SUB_SOURCE_SUBS) {
1456 mpctx->set_of_sub_pos =
1457 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS];
1458 #ifdef CONFIG_ASS
1459 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos])
1460 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos];
1461 else
1462 #endif
1464 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos];
1465 vo_osd_changed(OSDTYPE_SUBTITLE);
1467 } else if (source == SUB_SOURCE_DEMUX) {
1468 dvdsub_id =
1469 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX];
1470 if (d_sub && dvdsub_id < MAX_S_STREAMS) {
1471 int i = 0;
1472 // default: assume 1:1 mapping of sid and stream id
1473 d_sub->id = dvdsub_id;
1474 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id];
1475 ds_free_packs(d_sub);
1476 for (i = 0; i < MAX_S_STREAMS; i++) {
1477 sh_sub_t *sh = mpctx->demuxer->s_streams[i];
1478 if (sh && sh->sid == dvdsub_id) {
1479 d_sub->id = i;
1480 d_sub->sh = sh;
1481 break;
1484 if (d_sub->sh && d_sub->id >= 0) {
1485 sh_sub_t *sh = d_sub->sh;
1486 if (sh->type == 'v')
1487 init_vo_spudec();
1488 #ifdef CONFIG_ASS
1489 else if (ass_enabled)
1490 ass_track = sh->ass_track;
1491 #endif
1492 } else {
1493 d_sub->id = -2;
1494 d_sub->sh = NULL;
1498 #ifdef CONFIG_DVDREAD
1499 if (vo_spudec
1500 && (mpctx->stream->type == STREAMTYPE_DVD
1501 || mpctx->stream->type == STREAMTYPE_DVDNAV)
1502 && dvdsub_id < 0 && reset_spu) {
1503 d_sub->id = -2;
1504 d_sub->sh = NULL;
1506 #endif
1507 if (mpctx->sh_audio)
1508 pts = mpctx->sh_audio->pts;
1509 if (mpctx->sh_video)
1510 pts = mpctx->sh_video->pts;
1511 update_subtitles(mpctx->sh_video, pts, d_sub, 1);
1513 return M_PROPERTY_OK;
1516 /// Selected sub source (RW)
1517 static int mp_property_sub_source(m_option_t * prop, int action, void *arg,
1518 MPContext * mpctx)
1520 int source;
1521 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1522 return M_PROPERTY_UNAVAILABLE;
1524 switch (action) {
1525 case M_PROPERTY_GET:
1526 if (!arg)
1527 return M_PROPERTY_ERROR;
1528 *(int *) arg = sub_source(mpctx);
1529 return M_PROPERTY_OK;
1530 case M_PROPERTY_PRINT:
1531 if (!arg)
1532 return M_PROPERTY_ERROR;
1533 *(char **) arg = malloc(64);
1534 (*(char **) arg)[63] = 0;
1535 switch (sub_source(mpctx))
1537 case SUB_SOURCE_SUBS:
1538 snprintf(*(char **) arg, 63, MSGTR_SubSourceFile);
1539 break;
1540 case SUB_SOURCE_VOBSUB:
1541 snprintf(*(char **) arg, 63, MSGTR_SubSourceVobsub);
1542 break;
1543 case SUB_SOURCE_DEMUX:
1544 snprintf(*(char **) arg, 63, MSGTR_SubSourceDemux);
1545 break;
1546 default:
1547 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1549 return M_PROPERTY_OK;
1550 case M_PROPERTY_SET:
1551 if (!arg)
1552 return M_PROPERTY_ERROR;
1553 M_PROPERTY_CLAMP(prop, *(int*)arg);
1554 if (*(int *) arg < 0)
1555 mpctx->global_sub_pos = -1;
1556 else if (*(int *) arg != sub_source(mpctx)) {
1557 if (*(int *) arg != sub_source_by_pos(mpctx, mpctx->global_sub_indices[*(int *) arg]))
1558 return M_PROPERTY_UNAVAILABLE;
1559 mpctx->global_sub_pos = mpctx->global_sub_indices[*(int *) arg];
1561 break;
1562 case M_PROPERTY_STEP_UP:
1563 case M_PROPERTY_STEP_DOWN: {
1564 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1565 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1566 int step = (step_all > 0) ? 1 : -1;
1567 int cur_source = sub_source(mpctx);
1568 source = cur_source;
1569 while (step_all) {
1570 source += step;
1571 if (source >= SUB_SOURCES)
1572 source = -1;
1573 else if (source < -1)
1574 source = SUB_SOURCES - 1;
1575 if (source == cur_source || source == -1 ||
1576 source == sub_source_by_pos(mpctx, mpctx->global_sub_indices[source]))
1577 step_all -= step;
1579 if (source == cur_source)
1580 return M_PROPERTY_OK;
1581 if (source == -1)
1582 mpctx->global_sub_pos = -1;
1583 else
1584 mpctx->global_sub_pos = mpctx->global_sub_indices[source];
1585 break;
1587 default:
1588 return M_PROPERTY_NOT_IMPLEMENTED;
1590 --mpctx->global_sub_pos;
1591 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1594 /// Selected subtitles from specific source (RW)
1595 static int mp_property_sub_by_type(m_option_t * prop, int action, void *arg,
1596 MPContext * mpctx)
1598 int source, is_cur_source, offset;
1599 if (!mpctx->sh_video || mpctx->global_sub_size <= 0)
1600 return M_PROPERTY_UNAVAILABLE;
1602 if (!strcmp(prop->name, "sub_file"))
1603 source = SUB_SOURCE_SUBS;
1604 else if (!strcmp(prop->name, "sub_vob"))
1605 source = SUB_SOURCE_VOBSUB;
1606 else if (!strcmp(prop->name, "sub_demux"))
1607 source = SUB_SOURCE_DEMUX;
1608 else
1609 return M_PROPERTY_ERROR;
1611 offset = mpctx->global_sub_indices[source];
1612 if (offset < 0 || source != sub_source_by_pos(mpctx, offset))
1613 return M_PROPERTY_UNAVAILABLE;
1615 is_cur_source = sub_source(mpctx) == source;
1616 switch (action) {
1617 case M_PROPERTY_GET:
1618 if (!arg)
1619 return M_PROPERTY_ERROR;
1620 if (is_cur_source) {
1621 *(int *) arg = mpctx->global_sub_pos - offset;
1622 if (source == SUB_SOURCE_VOBSUB)
1623 *(int *) arg = vobsub_get_id_by_index(vo_vobsub, *(int *) arg);
1625 else
1626 *(int *) arg = -1;
1627 return M_PROPERTY_OK;
1628 case M_PROPERTY_PRINT:
1629 if (!arg)
1630 return M_PROPERTY_ERROR;
1631 if (is_cur_source)
1632 return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
1633 *(char **) arg = malloc(64);
1634 (*(char **) arg)[63] = 0;
1635 snprintf(*(char **) arg, 63, MSGTR_Disabled);
1636 return M_PROPERTY_OK;
1637 case M_PROPERTY_SET:
1638 if (!arg)
1639 return M_PROPERTY_ERROR;
1640 if (*(int *) arg >= 0) {
1641 int index = *(int *)arg;
1642 if (source == SUB_SOURCE_VOBSUB)
1643 index = vobsub_get_index_by_id(vo_vobsub, index);
1644 mpctx->global_sub_pos = offset + index;
1645 if (index < 0 || mpctx->global_sub_pos >= mpctx->global_sub_size
1646 || sub_source(mpctx) != source) {
1647 mpctx->global_sub_pos = -1;
1648 *(int *) arg = -1;
1651 else
1652 mpctx->global_sub_pos = -1;
1653 break;
1654 case M_PROPERTY_STEP_UP:
1655 case M_PROPERTY_STEP_DOWN: {
1656 int step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
1657 * (action == M_PROPERTY_STEP_UP ? 1 : -1);
1658 int step = (step_all > 0) ? 1 : -1;
1659 int max_sub_pos_for_source = -1;
1660 if (!is_cur_source)
1661 mpctx->global_sub_pos = -1;
1662 while (step_all) {
1663 if (mpctx->global_sub_pos == -1) {
1664 if (step > 0)
1665 mpctx->global_sub_pos = offset;
1666 else if (max_sub_pos_for_source == -1) {
1667 // Find max pos for specific source
1668 mpctx->global_sub_pos = mpctx->global_sub_size - 1;
1669 while (mpctx->global_sub_pos >= 0
1670 && sub_source(mpctx) != source)
1671 --mpctx->global_sub_pos;
1673 else
1674 mpctx->global_sub_pos = max_sub_pos_for_source;
1676 else {
1677 mpctx->global_sub_pos += step;
1678 if (mpctx->global_sub_pos < offset ||
1679 mpctx->global_sub_pos >= mpctx->global_sub_size ||
1680 sub_source(mpctx) != source)
1681 mpctx->global_sub_pos = -1;
1683 step_all -= step;
1685 break;
1687 default:
1688 return M_PROPERTY_NOT_IMPLEMENTED;
1690 --mpctx->global_sub_pos;
1691 return mp_property_sub(prop, M_PROPERTY_STEP_UP, NULL, mpctx);
1694 /// Subtitle delay (RW)
1695 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg,
1696 MPContext * mpctx)
1698 if (!mpctx->sh_video)
1699 return M_PROPERTY_UNAVAILABLE;
1700 return m_property_delay(prop, action, arg, &sub_delay);
1703 /// Alignment of text subtitles (RW)
1704 static int mp_property_sub_alignment(m_option_t * prop, int action,
1705 void *arg, MPContext * mpctx)
1707 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1709 if (!mpctx->sh_video || mpctx->global_sub_pos < 0
1710 || sub_source(mpctx) != SUB_SOURCE_SUBS)
1711 return M_PROPERTY_UNAVAILABLE;
1713 switch (action) {
1714 case M_PROPERTY_PRINT:
1715 if (!arg)
1716 return M_PROPERTY_ERROR;
1717 M_PROPERTY_CLAMP(prop, sub_alignment);
1718 *(char **) arg = strdup(name[sub_alignment]);
1719 return M_PROPERTY_OK;
1720 case M_PROPERTY_SET:
1721 if (!arg)
1722 return M_PROPERTY_ERROR;
1723 case M_PROPERTY_STEP_UP:
1724 case M_PROPERTY_STEP_DOWN:
1725 vo_osd_changed(OSDTYPE_SUBTITLE);
1726 default:
1727 return m_property_choice(prop, action, arg, &sub_alignment);
1731 /// Subtitle visibility (RW)
1732 static int mp_property_sub_visibility(m_option_t * prop, int action,
1733 void *arg, MPContext * mpctx)
1735 if (!mpctx->sh_video)
1736 return M_PROPERTY_UNAVAILABLE;
1738 switch (action) {
1739 case M_PROPERTY_SET:
1740 if (!arg)
1741 return M_PROPERTY_ERROR;
1742 case M_PROPERTY_STEP_UP:
1743 case M_PROPERTY_STEP_DOWN:
1744 vo_osd_changed(OSDTYPE_SUBTITLE);
1745 if (vo_spudec)
1746 vo_osd_changed(OSDTYPE_SPU);
1747 default:
1748 return m_property_flag(prop, action, arg, &sub_visibility);
1752 #ifdef CONFIG_ASS
1753 /// Use margins for libass subtitles (RW)
1754 static int mp_property_ass_use_margins(m_option_t * prop, int action,
1755 void *arg, MPContext * mpctx)
1757 if (!mpctx->sh_video)
1758 return M_PROPERTY_UNAVAILABLE;
1760 switch (action) {
1761 case M_PROPERTY_SET:
1762 if (!arg)
1763 return M_PROPERTY_ERROR;
1764 case M_PROPERTY_STEP_UP:
1765 case M_PROPERTY_STEP_DOWN:
1766 ass_force_reload = 1;
1767 default:
1768 return m_property_flag(prop, action, arg, &ass_use_margins);
1771 #endif
1773 /// Show only forced subtitles (RW)
1774 static int mp_property_sub_forced_only(m_option_t * prop, int action,
1775 void *arg, MPContext * mpctx)
1777 if (!vo_spudec)
1778 return M_PROPERTY_UNAVAILABLE;
1780 switch (action) {
1781 case M_PROPERTY_SET:
1782 if (!arg)
1783 return M_PROPERTY_ERROR;
1784 case M_PROPERTY_STEP_UP:
1785 case M_PROPERTY_STEP_DOWN:
1786 m_property_flag(prop, action, arg, &forced_subs_only);
1787 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
1788 return M_PROPERTY_OK;
1789 default:
1790 return m_property_flag(prop, action, arg, &forced_subs_only);
1795 #ifdef CONFIG_FREETYPE
1796 /// Subtitle scale (RW)
1797 static int mp_property_sub_scale(m_option_t * prop, int action, void *arg,
1798 MPContext * mpctx)
1801 switch (action) {
1802 case M_PROPERTY_SET:
1803 if (!arg)
1804 return M_PROPERTY_ERROR;
1805 M_PROPERTY_CLAMP(prop, *(float *) arg);
1806 #ifdef CONFIG_ASS
1807 if (ass_enabled) {
1808 ass_font_scale = *(float *) arg;
1809 ass_force_reload = 1;
1811 #endif
1812 text_font_scale_factor = *(float *) arg;
1813 force_load_font = 1;
1814 return M_PROPERTY_OK;
1815 case M_PROPERTY_STEP_UP:
1816 case M_PROPERTY_STEP_DOWN:
1817 #ifdef CONFIG_ASS
1818 if (ass_enabled) {
1819 ass_font_scale += (arg ? *(float *) arg : 0.1)*
1820 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1821 M_PROPERTY_CLAMP(prop, ass_font_scale);
1822 ass_force_reload = 1;
1824 #endif
1825 text_font_scale_factor += (arg ? *(float *) arg : 0.1)*
1826 (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
1827 M_PROPERTY_CLAMP(prop, text_font_scale_factor);
1828 force_load_font = 1;
1829 return M_PROPERTY_OK;
1830 default:
1831 #ifdef CONFIG_ASS
1832 if (ass_enabled)
1833 return m_property_float_ro(prop, action, arg, ass_font_scale);
1834 else
1835 #endif
1836 return m_property_float_ro(prop, action, arg, text_font_scale_factor);
1839 #endif
1841 ///@}
1843 /// \defgroup TVProperties TV properties
1844 /// \ingroup Properties
1845 ///@{
1847 #ifdef CONFIG_TV
1849 /// TV color settings (RW)
1850 static int mp_property_tv_color(m_option_t * prop, int action, void *arg,
1851 MPContext * mpctx)
1853 int r, val;
1854 tvi_handle_t *tvh = mpctx->demuxer->priv;
1855 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh)
1856 return M_PROPERTY_UNAVAILABLE;
1858 switch (action) {
1859 case M_PROPERTY_SET:
1860 if (!arg)
1861 return M_PROPERTY_ERROR;
1862 M_PROPERTY_CLAMP(prop, *(int *) arg);
1863 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg);
1864 case M_PROPERTY_GET:
1865 return tv_get_color_options(tvh, (int) prop->priv, arg);
1866 case M_PROPERTY_STEP_UP:
1867 case M_PROPERTY_STEP_DOWN:
1868 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) {
1869 if (!r)
1870 return M_PROPERTY_ERROR;
1871 val += (arg ? *(int *) arg : 1) *
1872 (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1873 M_PROPERTY_CLAMP(prop, val);
1874 return tv_set_color_options(tvh, (int) prop->priv, val);
1876 return M_PROPERTY_ERROR;
1878 return M_PROPERTY_NOT_IMPLEMENTED;
1881 #endif
1883 static int mp_property_teletext_common(m_option_t * prop, int action, void *arg,
1884 MPContext * mpctx)
1886 int val,result;
1887 int base_ioctl=(int)prop->priv;
1889 for teletext's GET,SET,STEP ioctls this is not 0
1890 SET is GET+1
1891 STEP is GET+2
1893 if (!mpctx->demuxer || !mpctx->demuxer->teletext)
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=teletext_control(mpctx->demuxer->teletext, 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=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, arg);
1909 break;
1910 case M_PROPERTY_STEP_UP:
1911 case M_PROPERTY_STEP_DOWN:
1912 result=teletext_control(mpctx->demuxer->teletext, base_ioctl, &val);
1913 val += (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1914 result=teletext_control(mpctx->demuxer->teletext, base_ioctl+1, &val);
1915 break;
1916 default:
1917 return M_PROPERTY_NOT_IMPLEMENTED;
1920 return result == VBI_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 int result;
1927 int val;
1929 //with tvh==NULL will fail too
1930 result=mp_property_teletext_common(prop,action,arg,mpctx);
1931 if(result!=M_PROPERTY_OK)
1932 return result;
1934 if(teletext_control(mpctx->demuxer->teletext,
1935 (int)prop->priv, &val)==VBI_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 int result;
1946 int val;
1947 if (!mpctx->demuxer->teletext)
1948 return M_PROPERTY_UNAVAILABLE;
1949 switch(action){
1950 case M_PROPERTY_STEP_UP:
1951 case M_PROPERTY_STEP_DOWN:
1952 //This should be handled separately
1953 val = (arg ? *(int *) arg : 1) * (action == M_PROPERTY_STEP_DOWN ? -1 : 1);
1954 result=teletext_control(mpctx->demuxer->teletext,
1955 TV_VBI_CONTROL_STEP_PAGE, &val);
1956 break;
1957 default:
1958 result=mp_property_teletext_common(prop,action,arg,mpctx);
1960 return result;
1963 ///@}
1965 /// All properties available in MPlayer.
1966 /** \ingroup Properties
1968 static const m_option_t mp_properties[] = {
1969 // General
1970 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1971 M_OPT_RANGE, 0, 3, NULL },
1972 { "loop", mp_property_loop, CONF_TYPE_INT,
1973 M_OPT_MIN, -1, 0, NULL },
1974 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT,
1975 M_OPT_RANGE, 0.01, 100.0, NULL },
1976 { "filename", mp_property_filename, CONF_TYPE_STRING,
1977 0, 0, 0, NULL },
1978 { "path", mp_property_path, CONF_TYPE_STRING,
1979 0, 0, 0, NULL },
1980 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING,
1981 0, 0, 0, NULL },
1982 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION,
1983 M_OPT_MIN, 0, 0, NULL },
1984 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION,
1985 M_OPT_MIN, 0, 0, NULL },
1986 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION,
1987 M_OPT_MIN, 0, 0, NULL },
1988 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION,
1989 M_OPT_MIN, 0, 0, NULL },
1990 { "length", mp_property_length, CONF_TYPE_TIME,
1991 M_OPT_MIN, 0, 0, NULL },
1992 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT,
1993 M_OPT_RANGE, 0, 100, NULL },
1994 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME,
1995 M_OPT_MIN, 0, 0, NULL },
1996 { "chapter", mp_property_chapter, CONF_TYPE_INT,
1997 M_OPT_MIN, 0, 0, NULL },
1998 { "chapters", mp_property_chapters, CONF_TYPE_INT,
1999 0, 0, 0, NULL },
2000 { "angle", mp_property_angle, CONF_TYPE_INT,
2001 CONF_RANGE, -2, 10, NULL },
2002 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
2003 0, 0, 0, NULL },
2004 { "pause", mp_property_pause, CONF_TYPE_FLAG,
2005 M_OPT_RANGE, 0, 1, NULL },
2007 // Audio
2008 { "volume", mp_property_volume, CONF_TYPE_FLOAT,
2009 M_OPT_RANGE, 0, 100, NULL },
2010 { "mute", mp_property_mute, CONF_TYPE_FLAG,
2011 M_OPT_RANGE, 0, 1, NULL },
2012 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT,
2013 M_OPT_RANGE, -100, 100, NULL },
2014 { "audio_format", mp_property_audio_format, CONF_TYPE_INT,
2015 0, 0, 0, NULL },
2016 { "audio_codec", mp_property_audio_codec, CONF_TYPE_STRING,
2017 0, 0, 0, NULL },
2018 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT,
2019 0, 0, 0, NULL },
2020 { "samplerate", mp_property_samplerate, CONF_TYPE_INT,
2021 0, 0, 0, NULL },
2022 { "channels", mp_property_channels, CONF_TYPE_INT,
2023 0, 0, 0, NULL },
2024 { "switch_audio", mp_property_audio, CONF_TYPE_INT,
2025 CONF_RANGE, -2, 65535, NULL },
2026 { "balance", mp_property_balance, CONF_TYPE_FLOAT,
2027 M_OPT_RANGE, -1, 1, NULL },
2029 // Video
2030 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG,
2031 M_OPT_RANGE, 0, 1, NULL },
2032 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG,
2033 M_OPT_RANGE, 0, 1, NULL },
2034 { "ontop", mp_property_ontop, CONF_TYPE_FLAG,
2035 M_OPT_RANGE, 0, 1, NULL },
2036 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG,
2037 M_OPT_RANGE, 0, 1, NULL },
2038 { "border", mp_property_border, CONF_TYPE_FLAG,
2039 M_OPT_RANGE, 0, 1, NULL },
2040 { "framedropping", mp_property_framedropping, CONF_TYPE_INT,
2041 M_OPT_RANGE, 0, 2, NULL },
2042 { "gamma", mp_property_gamma, CONF_TYPE_INT,
2043 M_OPT_RANGE, -100, 100, &vo_gamma_gamma },
2044 { "brightness", mp_property_gamma, CONF_TYPE_INT,
2045 M_OPT_RANGE, -100, 100, &vo_gamma_brightness },
2046 { "contrast", mp_property_gamma, CONF_TYPE_INT,
2047 M_OPT_RANGE, -100, 100, &vo_gamma_contrast },
2048 { "saturation", mp_property_gamma, CONF_TYPE_INT,
2049 M_OPT_RANGE, -100, 100, &vo_gamma_saturation },
2050 { "hue", mp_property_gamma, CONF_TYPE_INT,
2051 M_OPT_RANGE, -100, 100, &vo_gamma_hue },
2052 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT,
2053 M_OPT_RANGE, 0, 1, NULL },
2054 { "vsync", mp_property_vsync, CONF_TYPE_FLAG,
2055 M_OPT_RANGE, 0, 1, NULL },
2056 { "video_format", mp_property_video_format, CONF_TYPE_INT,
2057 0, 0, 0, NULL },
2058 { "video_codec", mp_property_video_codec, CONF_TYPE_STRING,
2059 0, 0, 0, NULL },
2060 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT,
2061 0, 0, 0, NULL },
2062 { "width", mp_property_width, CONF_TYPE_INT,
2063 0, 0, 0, NULL },
2064 { "height", mp_property_height, CONF_TYPE_INT,
2065 0, 0, 0, NULL },
2066 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
2067 0, 0, 0, NULL },
2068 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
2069 0, 0, 0, NULL },
2070 { "switch_video", mp_property_video, CONF_TYPE_INT,
2071 CONF_RANGE, -2, 65535, NULL },
2072 { "switch_program", mp_property_program, CONF_TYPE_INT,
2073 CONF_RANGE, -1, 65535, NULL },
2075 // Subs
2076 { "sub", mp_property_sub, CONF_TYPE_INT,
2077 M_OPT_MIN, -1, 0, NULL },
2078 { "sub_source", mp_property_sub_source, CONF_TYPE_INT,
2079 M_OPT_RANGE, -1, SUB_SOURCES - 1, NULL },
2080 { "sub_vob", mp_property_sub_by_type, CONF_TYPE_INT,
2081 M_OPT_MIN, -1, 0, NULL },
2082 { "sub_demux", mp_property_sub_by_type, CONF_TYPE_INT,
2083 M_OPT_MIN, -1, 0, NULL },
2084 { "sub_file", mp_property_sub_by_type, CONF_TYPE_INT,
2085 M_OPT_MIN, -1, 0, NULL },
2086 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2087 0, 0, 0, NULL },
2088 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2089 M_OPT_RANGE, 0, 100, NULL },
2090 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2091 M_OPT_RANGE, 0, 2, NULL },
2092 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2093 M_OPT_RANGE, 0, 1, NULL },
2094 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2095 M_OPT_RANGE, 0, 1, NULL },
2096 #ifdef CONFIG_FREETYPE
2097 { "sub_scale", mp_property_sub_scale, CONF_TYPE_FLOAT,
2098 M_OPT_RANGE, 0, 100, NULL },
2099 #endif
2100 #ifdef CONFIG_ASS
2101 { "ass_use_margins", mp_property_ass_use_margins, CONF_TYPE_FLAG,
2102 M_OPT_RANGE, 0, 1, NULL },
2103 #endif
2105 #ifdef CONFIG_TV
2106 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT,
2107 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS },
2108 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT,
2109 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST },
2110 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT,
2111 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION },
2112 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT,
2113 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE },
2114 #endif
2115 { "teletext_page", mp_property_teletext_page, CONF_TYPE_INT,
2116 M_OPT_RANGE, 100, 899, (void*)TV_VBI_CONTROL_GET_PAGE },
2117 { "teletext_subpage", mp_property_teletext_common, CONF_TYPE_INT,
2118 M_OPT_RANGE, 0, 64, (void*)TV_VBI_CONTROL_GET_SUBPAGE },
2119 { "teletext_mode", mp_property_teletext_mode, CONF_TYPE_FLAG,
2120 M_OPT_RANGE, 0, 1, (void*)TV_VBI_CONTROL_GET_MODE },
2121 { "teletext_format", mp_property_teletext_common, CONF_TYPE_INT,
2122 M_OPT_RANGE, 0, 3, (void*)TV_VBI_CONTROL_GET_FORMAT },
2123 { "teletext_half_page", mp_property_teletext_common, CONF_TYPE_INT,
2124 M_OPT_RANGE, 0, 2, (void*)TV_VBI_CONTROL_GET_HALF_PAGE },
2125 { NULL, NULL, NULL, 0, 0, 0, NULL }
2129 int mp_property_do(const char *name, int action, void *val, void *ctx)
2131 return m_property_do(mp_properties, name, action, val, ctx);
2134 char* mp_property_print(const char *name, void* ctx)
2136 char* ret = NULL;
2137 if(mp_property_do(name,M_PROPERTY_PRINT,&ret,ctx) <= 0)
2138 return NULL;
2139 return ret;
2142 char *property_expand_string(MPContext * mpctx, char *str)
2144 return m_properties_expand_string(mp_properties, str, mpctx);
2147 void property_print_help(void)
2149 m_properties_print_help_list(mp_properties);
2153 ///@}
2154 // Properties group
2158 * \defgroup Command2Property Command to property bridge
2160 * It is used to handle most commands that just set a property
2161 * and optionally display something on the OSD.
2162 * Two kinds of commands are handled: adjust or toggle.
2164 * Adjust commands take 1 or 2 parameters: <value> <abs>
2165 * If <abs> is non-zero the property is set to the given value
2166 * otherwise it is adjusted.
2168 * Toggle commands take 0 or 1 parameters. With no parameter
2169 * or a value less than the property minimum it just steps the
2170 * property to its next value. Otherwise it sets it to the given
2171 * value.
2176 /// List of the commands that can be handled by setting a property.
2177 static struct {
2178 /// property name
2179 const char *name;
2180 /// cmd id
2181 int cmd;
2182 /// set/adjust or toggle command
2183 int toggle;
2184 /// progressbar type
2185 int osd_progbar;
2186 /// osd msg id if it must be shared
2187 int osd_id;
2188 /// osd msg template
2189 const char *osd_msg;
2190 } set_prop_cmd[] = {
2191 // general
2192 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
2193 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
2194 { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
2195 // audio
2196 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
2197 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },
2198 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus },
2199 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio },
2200 { "balance", MP_CMD_BALANCE, 0, OSD_BALANCE, -1, MSGTR_Balance },
2201 // video
2202 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL },
2203 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan },
2204 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus },
2205 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus },
2206 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus },
2207 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus },
2208 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma },
2209 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2210 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2211 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2212 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2213 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2214 // subs
2215 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2216 { "sub_source", MP_CMD_SUB_SOURCE, 1, 0, -1, MSGTR_SubSourceStatus },
2217 { "sub_vob", MP_CMD_SUB_VOB, 1, 0, -1, MSGTR_SubSelectStatus },
2218 { "sub_demux", MP_CMD_SUB_DEMUX, 1, 0, -1, MSGTR_SubSelectStatus },
2219 { "sub_file", MP_CMD_SUB_FILE, 1, 0, -1, MSGTR_SubSelectStatus },
2220 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2221 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2222 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2223 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2224 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
2225 #ifdef CONFIG_FREETYPE
2226 { "sub_scale", MP_CMD_SUB_SCALE, 0, 0, -1, MSGTR_SubScale},
2227 #endif
2228 #ifdef CONFIG_ASS
2229 { "ass_use_margins", MP_CMD_ASS_USE_MARGINS, 1, 0, -1, NULL },
2230 #endif
2231 #ifdef CONFIG_TV
2232 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
2233 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
2234 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
2235 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
2236 #endif
2237 { NULL, 0, 0, 0, -1, NULL }
2241 /// Handle commands that set a property.
2242 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd)
2244 int i, r;
2245 m_option_t* prop;
2246 const char *pname;
2248 // look for the command
2249 for (i = 0; set_prop_cmd[i].name; i++)
2250 if (set_prop_cmd[i].cmd == cmd->id)
2251 break;
2252 if (!(pname = set_prop_cmd[i].name))
2253 return 0;
2255 if (mp_property_do(pname,M_PROPERTY_GET_TYPE,&prop,mpctx) <= 0 || !prop)
2256 return 0;
2258 // toggle command
2259 if (set_prop_cmd[i].toggle) {
2260 // set to value
2261 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min)
2262 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx);
2263 else
2264 r = mp_property_do(pname, M_PROPERTY_STEP_UP, NULL, mpctx);
2265 } else if (cmd->args[1].v.i) //set
2266 r = mp_property_do(pname, M_PROPERTY_SET, &cmd->args[0].v, mpctx);
2267 else // adjust
2268 r = mp_property_do(pname, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx);
2270 if (r <= 0)
2271 return 1;
2273 if (set_prop_cmd[i].osd_progbar) {
2274 if (prop->type == CONF_TYPE_INT) {
2275 if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
2276 set_osd_bar(set_prop_cmd[i].osd_progbar,
2277 set_prop_cmd[i].osd_msg, prop->min, prop->max, r);
2278 } else if (prop->type == CONF_TYPE_FLOAT) {
2279 float f;
2280 if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
2281 set_osd_bar(set_prop_cmd[i].osd_progbar,
2282 set_prop_cmd[i].osd_msg, prop->min, prop->max, f);
2283 } else
2284 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2285 "Property use an unsupported type.\n");
2286 return 1;
2289 if (set_prop_cmd[i].osd_msg) {
2290 char *val = mp_property_print(pname, mpctx);
2291 if (val) {
2292 set_osd_msg(set_prop_cmd[i].osd_id >=
2293 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
2294 1, osd_duration, set_prop_cmd[i].osd_msg, val);
2295 free(val);
2298 return 1;
2301 #ifdef CONFIG_DVDNAV
2302 static const struct {
2303 const char *name;
2304 const mp_command_type cmd;
2305 } mp_dvdnav_bindings[] = {
2306 { "up", MP_CMD_DVDNAV_UP },
2307 { "down", MP_CMD_DVDNAV_DOWN },
2308 { "left", MP_CMD_DVDNAV_LEFT },
2309 { "right", MP_CMD_DVDNAV_RIGHT },
2310 { "menu", MP_CMD_DVDNAV_MENU },
2311 { "select", MP_CMD_DVDNAV_SELECT },
2312 { "prev", MP_CMD_DVDNAV_PREVMENU },
2313 { "mouse", MP_CMD_DVDNAV_MOUSECLICK },
2316 * keep old dvdnav sub-command options for a while in order not to
2317 * break slave-mode API too suddenly.
2319 { "1", MP_CMD_DVDNAV_UP },
2320 { "2", MP_CMD_DVDNAV_DOWN },
2321 { "3", MP_CMD_DVDNAV_LEFT },
2322 { "4", MP_CMD_DVDNAV_RIGHT },
2323 { "5", MP_CMD_DVDNAV_MENU },
2324 { "6", MP_CMD_DVDNAV_SELECT },
2325 { "7", MP_CMD_DVDNAV_PREVMENU },
2326 { "8", MP_CMD_DVDNAV_MOUSECLICK },
2327 { NULL, 0 }
2329 #endif
2331 int run_command(MPContext * mpctx, mp_cmd_t * cmd)
2333 sh_audio_t * const sh_audio = mpctx->sh_audio;
2334 sh_video_t * const sh_video = mpctx->sh_video;
2335 int brk_cmd = 0;
2336 if (!set_property_command(mpctx, cmd))
2337 switch (cmd->id) {
2338 case MP_CMD_SEEK:{
2339 float v;
2340 int abs;
2341 if (sh_video)
2342 mpctx->osd_show_percentage = sh_video->fps;
2343 v = cmd->args[0].v.f;
2344 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0;
2345 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */
2346 abs_seek_pos = SEEK_ABSOLUTE;
2347 if (sh_video)
2348 mpctx->osd_function =
2349 (v > sh_video->pts) ? OSD_FFW : OSD_REW;
2350 rel_seek_secs = v;
2351 } else if (abs) { /* Absolute seek by percentage */
2352 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR;
2353 if (sh_video)
2354 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly
2355 rel_seek_secs = v / 100.0;
2356 } else {
2357 rel_seek_secs += v;
2358 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW;
2360 brk_cmd = 1;
2362 break;
2364 case MP_CMD_SET_PROPERTY:{
2365 int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_PARSE,
2366 cmd->args[1].v.s, mpctx);
2367 if (r == M_PROPERTY_UNKNOWN)
2368 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2369 "Unknown property: '%s'\n", cmd->args[0].v.s);
2370 else if (r <= 0)
2371 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2372 "Failed to set property '%s' to '%s'.\n",
2373 cmd->args[0].v.s, cmd->args[1].v.s);
2375 break;
2377 case MP_CMD_STEP_PROPERTY:{
2378 void* arg = NULL;
2379 int r,i;
2380 double d;
2381 off_t o;
2382 if (cmd->args[1].v.f) {
2383 m_option_t* prop;
2384 if((r = mp_property_do(cmd->args[0].v.s,
2385 M_PROPERTY_GET_TYPE,
2386 &prop, mpctx)) <= 0)
2387 goto step_prop_err;
2388 if(prop->type == CONF_TYPE_INT ||
2389 prop->type == CONF_TYPE_FLAG)
2390 i = cmd->args[1].v.f, arg = &i;
2391 else if(prop->type == CONF_TYPE_FLOAT)
2392 arg = &cmd->args[1].v.f;
2393 else if(prop->type == CONF_TYPE_DOUBLE ||
2394 prop->type == CONF_TYPE_TIME)
2395 d = cmd->args[1].v.f, arg = &d;
2396 else if(prop->type == CONF_TYPE_POSITION)
2397 o = cmd->args[1].v.f, arg = &o;
2398 else
2399 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2400 "Ignoring step size stepping property '%s'.\n",
2401 cmd->args[0].v.s);
2403 r = mp_property_do(cmd->args[0].v.s,
2404 cmd->args[2].v.i < 0 ?
2405 M_PROPERTY_STEP_DOWN : M_PROPERTY_STEP_UP,
2406 arg, mpctx);
2407 step_prop_err:
2408 if (r == M_PROPERTY_UNKNOWN)
2409 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2410 "Unknown property: '%s'\n", cmd->args[0].v.s);
2411 else if (r <= 0)
2412 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2413 "Failed to increment property '%s' by %f.\n",
2414 cmd->args[0].v.s, cmd->args[1].v.f);
2416 break;
2418 case MP_CMD_GET_PROPERTY:{
2419 char *tmp;
2420 if (mp_property_do(cmd->args[0].v.s, M_PROPERTY_TO_STRING,
2421 &tmp, mpctx) <= 0) {
2422 mp_msg(MSGT_CPLAYER, MSGL_WARN,
2423 "Failed to get value of property '%s'.\n",
2424 cmd->args[0].v.s);
2425 break;
2427 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
2428 cmd->args[0].v.s, tmp);
2429 free(tmp);
2431 break;
2433 case MP_CMD_EDL_MARK:
2434 if (edl_fd) {
2435 float v = sh_video ? sh_video->pts :
2436 playing_audio_pts(sh_audio, mpctx->d_audio,
2437 mpctx->audio_out);
2439 if (mpctx->begin_skip == MP_NOPTS_VALUE) {
2440 mpctx->begin_skip = v;
2441 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip);
2442 } else {
2443 if (mpctx->begin_skip > v)
2444 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop);
2445 else {
2446 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0);
2447 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip);
2449 mpctx->begin_skip = MP_NOPTS_VALUE;
2452 break;
2454 case MP_CMD_SWITCH_RATIO:
2455 if (!sh_video)
2456 break;
2457 if (cmd->nargs == 0 || cmd->args[0].v.f == -1)
2458 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h;
2459 else
2460 movie_aspect = cmd->args[0].v.f;
2461 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0);
2462 break;
2464 case MP_CMD_SPEED_INCR:{
2465 float v = cmd->args[0].v.f;
2466 playback_speed += v;
2467 build_afilter_chain(sh_audio, &ao_data);
2468 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2469 playback_speed);
2470 } break;
2472 case MP_CMD_SPEED_MULT:{
2473 float v = cmd->args[0].v.f;
2474 playback_speed *= v;
2475 build_afilter_chain(sh_audio, &ao_data);
2476 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2477 playback_speed);
2478 } break;
2480 case MP_CMD_SPEED_SET:{
2481 float v = cmd->args[0].v.f;
2482 playback_speed = v;
2483 build_afilter_chain(sh_audio, &ao_data);
2484 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed,
2485 playback_speed);
2486 } break;
2488 case MP_CMD_FRAME_STEP:
2489 case MP_CMD_PAUSE:
2490 cmd->pausing = 1;
2491 brk_cmd = 1;
2492 break;
2494 case MP_CMD_FILE_FILTER:
2495 file_filter = cmd->args[0].v.i;
2496 break;
2498 case MP_CMD_QUIT:
2499 exit_player_with_rc(EXIT_QUIT,
2500 (cmd->nargs > 0) ? cmd->args[0].v.i : 0);
2502 case MP_CMD_PLAY_TREE_STEP:{
2503 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i;
2504 int force = cmd->args[1].v.i;
2506 #ifdef CONFIG_GUI
2507 if (use_gui) {
2508 int i = 0;
2509 if (n > 0)
2510 for (i = 0; i < n; i++)
2511 mplNext();
2512 else
2513 for (i = 0; i < -1 * n; i++)
2514 mplPrev();
2515 } else
2516 #endif
2518 if (!force && mpctx->playtree_iter) {
2519 play_tree_iter_t *i =
2520 play_tree_iter_new_copy(mpctx->playtree_iter);
2521 if (play_tree_iter_step(i, n, 0) ==
2522 PLAY_TREE_ITER_ENTRY)
2523 mpctx->eof =
2524 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2525 play_tree_iter_free(i);
2526 } else
2527 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
2528 if (mpctx->eof)
2529 mpctx->play_tree_step = n;
2530 brk_cmd = 1;
2533 break;
2535 case MP_CMD_PLAY_TREE_UP_STEP:{
2536 int n = cmd->args[0].v.i > 0 ? 1 : -1;
2537 int force = cmd->args[1].v.i;
2539 if (!force && mpctx->playtree_iter) {
2540 play_tree_iter_t *i =
2541 play_tree_iter_new_copy(mpctx->playtree_iter);
2542 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY)
2543 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2544 play_tree_iter_free(i);
2545 } else
2546 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV;
2547 brk_cmd = 1;
2549 break;
2551 case MP_CMD_PLAY_ALT_SRC_STEP:
2552 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) {
2553 int v = cmd->args[0].v.i;
2554 if (v > 0
2555 && mpctx->playtree_iter->file <
2556 mpctx->playtree_iter->num_files)
2557 mpctx->eof = PT_NEXT_SRC;
2558 else if (v < 0 && mpctx->playtree_iter->file > 1)
2559 mpctx->eof = PT_PREV_SRC;
2561 brk_cmd = 1;
2562 break;
2564 case MP_CMD_SUB_STEP:
2565 if (sh_video) {
2566 int movement = cmd->args[0].v.i;
2567 step_sub(subdata, sh_video->pts, movement);
2568 #ifdef CONFIG_ASS
2569 if (ass_track)
2570 sub_delay +=
2571 ass_step_sub(ass_track,
2572 (sh_video->pts +
2573 sub_delay) * 1000 + .5, movement) / 1000.;
2574 #endif
2575 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration,
2576 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000));
2578 break;
2580 case MP_CMD_SUB_LOG:
2581 log_sub();
2582 break;
2584 case MP_CMD_OSD:{
2585 int v = cmd->args[0].v.i;
2586 int max = (term_osd
2587 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
2588 if (osd_level > max)
2589 osd_level = max;
2590 if (v < 0)
2591 osd_level = (osd_level + 1) % (max + 1);
2592 else
2593 osd_level = v > max ? max : v;
2594 /* Show OSD state when disabled, but not when an explicit
2595 argument is given to the OSD command, i.e. in slave mode. */
2596 if (v == -1 && osd_level <= 1)
2597 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
2598 MSGTR_OSDosd,
2599 osd_level ? MSGTR_OSDenabled :
2600 MSGTR_OSDdisabled);
2601 else
2602 rm_osd_msg(OSD_MSG_OSD_STATUS);
2604 break;
2606 case MP_CMD_OSD_SHOW_TEXT:
2607 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2608 (cmd->args[1].v.i <
2609 0 ? osd_duration : cmd->args[1].v.i),
2610 "%-.63s", cmd->args[0].v.s);
2611 break;
2613 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{
2614 char *txt = m_properties_expand_string(mp_properties,
2615 cmd->args[0].v.s,
2616 mpctx);
2617 /* if no argument supplied take default osd_duration, else <arg> ms. */
2618 if (txt) {
2619 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i,
2620 (cmd->args[1].v.i <
2621 0 ? osd_duration : cmd->args[1].v.i),
2622 "%-.63s", txt);
2623 free(txt);
2626 break;
2628 case MP_CMD_LOADFILE:{
2629 play_tree_t *e = play_tree_new();
2630 play_tree_add_file(e, cmd->args[0].v.s);
2632 if (cmd->args[1].v.i) // append
2633 play_tree_append_entry(mpctx->playtree->child, e);
2634 else {
2635 // Go back to the starting point.
2636 while (play_tree_iter_up_step
2637 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2638 /* NOP */ ;
2639 play_tree_free_list(mpctx->playtree->child, 1);
2640 play_tree_set_child(mpctx->playtree, e);
2641 pt_iter_goto_head(mpctx->playtree_iter);
2642 mpctx->eof = PT_NEXT_SRC;
2644 brk_cmd = 1;
2646 break;
2648 case MP_CMD_LOADLIST:{
2649 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s);
2650 if (!e)
2651 mp_msg(MSGT_CPLAYER, MSGL_ERR,
2652 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s);
2653 else {
2654 if (cmd->args[1].v.i) // append
2655 play_tree_append_entry(mpctx->playtree->child, e);
2656 else {
2657 // Go back to the starting point.
2658 while (play_tree_iter_up_step
2659 (mpctx->playtree_iter, 0, 1)
2660 != PLAY_TREE_ITER_END)
2661 /* NOP */ ;
2662 play_tree_free_list(mpctx->playtree->child, 1);
2663 play_tree_set_child(mpctx->playtree, e);
2664 pt_iter_goto_head(mpctx->playtree_iter);
2665 mpctx->eof = PT_NEXT_SRC;
2668 brk_cmd = 1;
2670 break;
2672 case MP_CMD_STOP:
2673 // Go back to the starting point.
2674 while (play_tree_iter_up_step
2675 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END)
2676 /* NOP */ ;
2677 mpctx->eof = PT_STOP;
2678 brk_cmd = 1;
2679 break;
2681 #ifdef CONFIG_RADIO
2682 case MP_CMD_RADIO_STEP_CHANNEL:
2683 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2684 int v = cmd->args[0].v.i;
2685 if (v > 0)
2686 radio_step_channel(mpctx->demuxer->stream,
2687 RADIO_CHANNEL_HIGHER);
2688 else
2689 radio_step_channel(mpctx->demuxer->stream,
2690 RADIO_CHANNEL_LOWER);
2691 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2692 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2693 MSGTR_OSDChannel,
2694 radio_get_channel_name(mpctx->demuxer->stream));
2697 break;
2699 case MP_CMD_RADIO_SET_CHANNEL:
2700 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) {
2701 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s);
2702 if (radio_get_channel_name(mpctx->demuxer->stream)) {
2703 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration,
2704 MSGTR_OSDChannel,
2705 radio_get_channel_name(mpctx->demuxer->stream));
2708 break;
2710 case MP_CMD_RADIO_SET_FREQ:
2711 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2712 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2713 break;
2715 case MP_CMD_RADIO_STEP_FREQ:
2716 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO)
2717 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f);
2718 break;
2719 #endif
2721 #ifdef CONFIG_TV
2722 case MP_CMD_TV_START_SCAN:
2723 if (mpctx->file_format == DEMUXER_TYPE_TV)
2724 tv_start_scan((tvi_handle_t *) (mpctx->demuxer->priv),1);
2725 break;
2726 case MP_CMD_TV_SET_FREQ:
2727 if (mpctx->file_format == DEMUXER_TYPE_TV)
2728 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2729 cmd->args[0].v.f * 16.0);
2730 #ifdef CONFIG_PVR
2731 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2732 pvr_set_freq (mpctx->stream, ROUND (cmd->args[0].v.f));
2733 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2734 pvr_get_current_channelname (mpctx->stream),
2735 pvr_get_current_stationname (mpctx->stream));
2737 #endif /* CONFIG_PVR */
2738 break;
2740 case MP_CMD_TV_STEP_FREQ:
2741 if (mpctx->file_format == DEMUXER_TYPE_TV)
2742 tv_step_freq((tvi_handle_t *) (mpctx->demuxer->priv),
2743 cmd->args[0].v.f * 16.0);
2744 #ifdef CONFIG_PVR
2745 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2746 pvr_force_freq_step (mpctx->stream, ROUND (cmd->args[0].v.f));
2747 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d",
2748 pvr_get_current_channelname (mpctx->stream),
2749 pvr_get_current_frequency (mpctx->stream));
2751 #endif /* CONFIG_PVR */
2752 break;
2754 case MP_CMD_TV_SET_NORM:
2755 if (mpctx->file_format == DEMUXER_TYPE_TV)
2756 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv),
2757 cmd->args[0].v.s);
2758 break;
2760 case MP_CMD_TV_STEP_CHANNEL:{
2761 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2762 int v = cmd->args[0].v.i;
2763 if (v > 0) {
2764 tv_step_channel((tvi_handle_t *) (mpctx->
2765 demuxer->priv),
2766 TV_CHANNEL_HIGHER);
2767 } else {
2768 tv_step_channel((tvi_handle_t *) (mpctx->
2769 demuxer->priv),
2770 TV_CHANNEL_LOWER);
2772 if (tv_channel_list) {
2773 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2774 MSGTR_OSDChannel, tv_channel_current->name);
2775 //vo_osd_changed(OSDTYPE_SUBTITLE);
2778 #ifdef CONFIG_PVR
2779 else if (mpctx->stream &&
2780 mpctx->stream->type == STREAMTYPE_PVR) {
2781 pvr_set_channel_step (mpctx->stream, cmd->args[0].v.i);
2782 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2783 pvr_get_current_channelname (mpctx->stream),
2784 pvr_get_current_stationname (mpctx->stream));
2786 #endif /* CONFIG_PVR */
2788 #ifdef CONFIG_DVBIN
2789 if (mpctx->stream->type == STREAMTYPE_DVB) {
2790 int dir;
2791 int v = cmd->args[0].v.i;
2793 mpctx->last_dvb_step = v;
2794 if (v > 0)
2795 dir = DVB_CHANNEL_HIGHER;
2796 else
2797 dir = DVB_CHANNEL_LOWER;
2800 if (dvb_step_channel(mpctx->stream, dir))
2801 mpctx->eof = mpctx->dvbin_reopen = 1;
2803 #endif /* CONFIG_DVBIN */
2804 break;
2806 case MP_CMD_TV_SET_CHANNEL:
2807 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2808 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv),
2809 cmd->args[0].v.s);
2810 if (tv_channel_list) {
2811 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2812 MSGTR_OSDChannel, tv_channel_current->name);
2813 //vo_osd_changed(OSDTYPE_SUBTITLE);
2816 #ifdef CONFIG_PVR
2817 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2818 pvr_set_channel (mpctx->stream, cmd->args[0].v.s);
2819 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2820 pvr_get_current_channelname (mpctx->stream),
2821 pvr_get_current_stationname (mpctx->stream));
2823 #endif /* CONFIG_PVR */
2824 break;
2826 #ifdef CONFIG_DVBIN
2827 case MP_CMD_DVB_SET_CHANNEL:
2828 if (mpctx->stream->type == STREAMTYPE_DVB) {
2829 mpctx->last_dvb_step = 1;
2831 if (dvb_set_channel
2832 (mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i))
2833 mpctx->eof = mpctx->dvbin_reopen = 1;
2835 break;
2836 #endif /* CONFIG_DVBIN */
2838 case MP_CMD_TV_LAST_CHANNEL:
2839 if (mpctx->file_format == DEMUXER_TYPE_TV) {
2840 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv));
2841 if (tv_channel_list) {
2842 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration,
2843 MSGTR_OSDChannel, tv_channel_current->name);
2844 //vo_osd_changed(OSDTYPE_SUBTITLE);
2847 #ifdef CONFIG_PVR
2848 else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) {
2849 pvr_set_lastchannel (mpctx->stream);
2850 set_osd_msg (OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s",
2851 pvr_get_current_channelname (mpctx->stream),
2852 pvr_get_current_stationname (mpctx->stream));
2854 #endif /* CONFIG_PVR */
2855 break;
2857 case MP_CMD_TV_STEP_NORM:
2858 if (mpctx->file_format == DEMUXER_TYPE_TV)
2859 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv));
2860 break;
2862 case MP_CMD_TV_STEP_CHANNEL_LIST:
2863 if (mpctx->file_format == DEMUXER_TYPE_TV)
2864 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv));
2865 break;
2866 #endif /* CONFIG_TV */
2867 case MP_CMD_TV_TELETEXT_ADD_DEC:
2869 if (mpctx->demuxer->teletext)
2870 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_ADD_DEC,
2871 &(cmd->args[0].v.s));
2872 break;
2874 case MP_CMD_TV_TELETEXT_GO_LINK:
2876 if (mpctx->demuxer->teletext)
2877 teletext_control(mpctx->demuxer->teletext,TV_VBI_CONTROL_GO_LINK,
2878 &(cmd->args[0].v.i));
2879 break;
2882 case MP_CMD_SUB_LOAD:
2883 if (sh_video) {
2884 int n = mpctx->set_of_sub_size;
2885 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0);
2886 if (n != mpctx->set_of_sub_size) {
2887 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0)
2888 mpctx->global_sub_indices[SUB_SOURCE_SUBS] =
2889 mpctx->global_sub_size;
2890 ++mpctx->global_sub_size;
2893 break;
2895 case MP_CMD_SUB_REMOVE:
2896 if (sh_video) {
2897 int v = cmd->args[0].v.i;
2898 sub_data *subd;
2899 if (v < 0) {
2900 for (v = 0; v < mpctx->set_of_sub_size; ++v) {
2901 subd = mpctx->set_of_subtitles[v];
2902 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2903 MSGTR_RemovedSubtitleFile, v + 1,
2904 filename_recode(subd->filename));
2905 sub_free(subd);
2906 mpctx->set_of_subtitles[v] = NULL;
2908 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2909 mpctx->global_sub_size -= mpctx->set_of_sub_size;
2910 mpctx->set_of_sub_size = 0;
2911 if (mpctx->set_of_sub_pos >= 0) {
2912 mpctx->global_sub_pos = -2;
2913 subdata = NULL;
2914 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2916 } else if (v < mpctx->set_of_sub_size) {
2917 subd = mpctx->set_of_subtitles[v];
2918 mp_msg(MSGT_CPLAYER, MSGL_STATUS,
2919 MSGTR_RemovedSubtitleFile, v + 1,
2920 filename_recode(subd->filename));
2921 sub_free(subd);
2922 if (mpctx->set_of_sub_pos == v) {
2923 mpctx->global_sub_pos = -2;
2924 subdata = NULL;
2925 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
2926 } else if (mpctx->set_of_sub_pos > v) {
2927 --mpctx->set_of_sub_pos;
2928 --mpctx->global_sub_pos;
2930 while (++v < mpctx->set_of_sub_size)
2931 mpctx->set_of_subtitles[v - 1] =
2932 mpctx->set_of_subtitles[v];
2933 --mpctx->set_of_sub_size;
2934 --mpctx->global_sub_size;
2935 if (mpctx->set_of_sub_size <= 0)
2936 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1;
2937 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL;
2940 break;
2942 case MP_CMD_GET_SUB_VISIBILITY:
2943 if (sh_video) {
2944 mp_msg(MSGT_GLOBAL, MSGL_INFO,
2945 "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
2947 break;
2949 case MP_CMD_SCREENSHOT:
2950 if (vo_config_count) {
2951 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n");
2952 if (CONTROL_OK !=
2953 ((vf_instance_t *) sh_video->vfilter)->
2954 control(sh_video->vfilter, VFCTRL_SCREENSHOT,
2955 &cmd->args[0].v.i))
2956 mp_msg(MSGT_CPLAYER, MSGL_INFO, "failed (forgot -vf screenshot?)\n");
2958 break;
2960 case MP_CMD_VF_CHANGE_RECTANGLE:
2961 if (!sh_video)
2962 break;
2963 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i);
2964 break;
2966 case MP_CMD_GET_TIME_LENGTH:{
2967 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n",
2968 demuxer_get_time_length(mpctx->demuxer));
2970 break;
2972 case MP_CMD_GET_FILENAME:{
2973 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n",
2974 get_metadata(META_NAME));
2976 break;
2978 case MP_CMD_GET_VIDEO_CODEC:{
2979 char *inf = get_metadata(META_VIDEO_CODEC);
2980 if (!inf)
2981 inf = strdup("");
2982 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf);
2983 free(inf);
2985 break;
2987 case MP_CMD_GET_VIDEO_BITRATE:{
2988 char *inf = get_metadata(META_VIDEO_BITRATE);
2989 if (!inf)
2990 inf = strdup("");
2991 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf);
2992 free(inf);
2994 break;
2996 case MP_CMD_GET_VIDEO_RESOLUTION:{
2997 char *inf = get_metadata(META_VIDEO_RESOLUTION);
2998 if (!inf)
2999 inf = strdup("");
3000 mp_msg(MSGT_GLOBAL, MSGL_INFO,
3001 "ANS_VIDEO_RESOLUTION='%s'\n", inf);
3002 free(inf);
3004 break;
3006 case MP_CMD_GET_AUDIO_CODEC:{
3007 char *inf = get_metadata(META_AUDIO_CODEC);
3008 if (!inf)
3009 inf = strdup("");
3010 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf);
3011 free(inf);
3013 break;
3015 case MP_CMD_GET_AUDIO_BITRATE:{
3016 char *inf = get_metadata(META_AUDIO_BITRATE);
3017 if (!inf)
3018 inf = strdup("");
3019 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf);
3020 free(inf);
3022 break;
3024 case MP_CMD_GET_AUDIO_SAMPLES:{
3025 char *inf = get_metadata(META_AUDIO_SAMPLES);
3026 if (!inf)
3027 inf = strdup("");
3028 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf);
3029 free(inf);
3031 break;
3033 case MP_CMD_GET_META_TITLE:{
3034 char *inf = get_metadata(META_INFO_TITLE);
3035 if (!inf)
3036 inf = strdup("");
3037 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf);
3038 free(inf);
3040 break;
3042 case MP_CMD_GET_META_ARTIST:{
3043 char *inf = get_metadata(META_INFO_ARTIST);
3044 if (!inf)
3045 inf = strdup("");
3046 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf);
3047 free(inf);
3049 break;
3051 case MP_CMD_GET_META_ALBUM:{
3052 char *inf = get_metadata(META_INFO_ALBUM);
3053 if (!inf)
3054 inf = strdup("");
3055 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf);
3056 free(inf);
3058 break;
3060 case MP_CMD_GET_META_YEAR:{
3061 char *inf = get_metadata(META_INFO_YEAR);
3062 if (!inf)
3063 inf = strdup("");
3064 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf);
3065 free(inf);
3067 break;
3069 case MP_CMD_GET_META_COMMENT:{
3070 char *inf = get_metadata(META_INFO_COMMENT);
3071 if (!inf)
3072 inf = strdup("");
3073 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf);
3074 free(inf);
3076 break;
3078 case MP_CMD_GET_META_TRACK:{
3079 char *inf = get_metadata(META_INFO_TRACK);
3080 if (!inf)
3081 inf = strdup("");
3082 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf);
3083 free(inf);
3085 break;
3087 case MP_CMD_GET_META_GENRE:{
3088 char *inf = get_metadata(META_INFO_GENRE);
3089 if (!inf)
3090 inf = strdup("");
3091 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf);
3092 free(inf);
3094 break;
3096 case MP_CMD_GET_VO_FULLSCREEN:
3097 if (mpctx->video_out && vo_config_count)
3098 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs);
3099 break;
3101 case MP_CMD_GET_PERCENT_POS:
3102 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n",
3103 demuxer_get_percent_pos(mpctx->demuxer));
3104 break;
3106 case MP_CMD_GET_TIME_POS:{
3107 float pos = 0;
3108 if (sh_video)
3109 pos = sh_video->pts;
3110 else if (sh_audio && mpctx->audio_out)
3111 pos =
3112 playing_audio_pts(sh_audio, mpctx->d_audio,
3113 mpctx->audio_out);
3114 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos);
3116 break;
3118 case MP_CMD_RUN:
3119 #ifndef __MINGW32__
3120 if (!fork()) {
3121 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL);
3122 exit(0);
3124 #endif
3125 break;
3127 case MP_CMD_KEYDOWN_EVENTS:
3128 mplayer_put_key(cmd->args[0].v.i);
3129 break;
3131 case MP_CMD_SET_MOUSE_POS:{
3132 int pointer_x, pointer_y;
3133 double dx, dy;
3134 pointer_x = cmd->args[0].v.i;
3135 pointer_y = cmd->args[1].v.i;
3136 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy);
3137 #ifdef CONFIG_DVDNAV
3138 if (mpctx->stream->type == STREAMTYPE_DVDNAV
3139 && dx > 0.0 && dy > 0.0) {
3140 int button = -1;
3141 pointer_x = (int) (dx * (double) sh_video->disp_w);
3142 pointer_y = (int) (dy * (double) sh_video->disp_h);
3143 mp_dvdnav_update_mouse_pos(mpctx->stream,
3144 pointer_x, pointer_y, &button);
3145 if (osd_level > 1 && button > 0)
3146 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3147 "Selected button number %d", button);
3149 #endif
3150 #ifdef CONFIG_MENU
3151 if (use_menu && dx >= 0.0 && dy >= 0.0)
3152 menu_update_mouse_pos(dx, dy);
3153 #endif
3155 break;
3157 #ifdef CONFIG_DVDNAV
3158 case MP_CMD_DVDNAV:{
3159 int button = -1;
3160 int i;
3161 mp_command_type command = 0;
3162 if (mpctx->stream->type != STREAMTYPE_DVDNAV)
3163 break;
3165 for (i = 0; mp_dvdnav_bindings[i].name; i++)
3166 if (cmd->args[0].v.s &&
3167 !strcasecmp (cmd->args[0].v.s,
3168 mp_dvdnav_bindings[i].name))
3169 command = mp_dvdnav_bindings[i].cmd;
3171 mp_dvdnav_handle_input(mpctx->stream,command,&button);
3172 if (osd_level > 1 && button > 0)
3173 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3174 "Selected button number %d", button);
3176 break;
3178 case MP_CMD_SWITCH_TITLE:
3179 if (mpctx->stream->type == STREAMTYPE_DVDNAV)
3180 mp_dvdnav_switch_title(mpctx->stream, cmd->args[0].v.i);
3181 break;
3183 #endif
3185 default:
3186 #ifdef CONFIG_GUI
3187 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS))
3188 guiGetEvent(guiIEvent, (char *) cmd->id);
3189 else
3190 #endif
3191 mp_msg(MSGT_CPLAYER, MSGL_V,
3192 "Received unknown cmd %s\n", cmd->name);
3195 switch (cmd->pausing) {
3196 case 1: // "pausing"
3197 mpctx->osd_function = OSD_PAUSE;
3198 break;
3199 case 3: // "pausing_toggle"
3200 mpctx->was_paused = !mpctx->was_paused;
3201 if (mpctx->was_paused)
3202 mpctx->osd_function = OSD_PAUSE;
3203 else if (mpctx->osd_function == OSD_PAUSE)
3204 mpctx->osd_function = OSD_PLAY;
3205 break;
3206 case 2: // "pausing_keep"
3207 if (mpctx->was_paused)
3208 mpctx->osd_function = OSD_PAUSE;
3210 return brk_cmd;