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