Mercurial > mplayer.hg
comparison command.c @ 22280:a5e5b0c45c03
Split command/property handling from mplayer.c to a new file command.c.
Move some global and static variables under a struct that can be given
as a parameter. Add a context argument to the property functions so that
they do not have to depend on global/static variables.
author | uau |
---|---|
date | Wed, 21 Feb 2007 00:49:24 +0000 |
parents | |
children | 53f0cbf238cf |
comparison
equal
deleted
inserted
replaced
22279:856feaa9cb61 | 22280:a5e5b0c45c03 |
---|---|
1 #include <stdlib.h> | |
2 #include <inttypes.h> | |
3 #include <unistd.h> | |
4 | |
5 #include "config.h" | |
6 #include "input/input.h" | |
7 #include "stream/stream.h" | |
8 #include "libmpdemux/demuxer.h" | |
9 #include "libmpdemux/stheader.h" | |
10 #include "mplayer.h" | |
11 #include "libvo/sub.h" | |
12 #include "m_option.h" | |
13 #include "m_property.h" | |
14 #include "help_mp.h" | |
15 #include "metadata.h" | |
16 #include "libmpcodecs/mp_image.h" | |
17 #include "libmpcodecs/vf.h" | |
18 #include "libmpcodecs/vd.h" | |
19 #include "libvo/video_out.h" | |
20 #include "playtree.h" | |
21 #include "libao2/audio_out.h" | |
22 #include "mpcommon.h" | |
23 #include "mixer.h" | |
24 #include "libmpdemux/matroska.h" | |
25 #include "libmpcodecs/dec_video.h" | |
26 #include "vobsub.h" | |
27 #include "spudec.h" | |
28 #ifdef USE_TV | |
29 #include "stream/tv.h" | |
30 #endif | |
31 #ifdef USE_RADIO | |
32 #include "stream/stream_radio.h" | |
33 #endif | |
34 #ifdef HAS_DVBIN_SUPPORT | |
35 #include "stream/dvbin.h" | |
36 #endif | |
37 #ifdef USE_DVDREAD | |
38 #include "stream/stream_dvd.h" | |
39 #endif | |
40 #ifdef USE_DVDNAV | |
41 #include "stream/stream_dvdnav.h" | |
42 #endif | |
43 #ifdef USE_ASS | |
44 #include "libass/ass.h" | |
45 #include "libass/ass_mp.h" | |
46 #endif | |
47 #ifdef HAVE_NEW_GUI | |
48 #include "Gui/interface.h" | |
49 #endif | |
50 | |
51 #include "mp_core.h" | |
52 | |
53 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5)) | |
54 | |
55 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy) | |
56 { | |
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; | |
63 | |
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 | |
72 } | |
73 | |
74 *dx = (double) ix / (double) vo_dwidth; | |
75 *dy = (double) iy / (double) vo_dheight; | |
76 | |
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); | |
81 } | |
82 | |
83 static int sub_source(MPContext * mpctx) | |
84 { | |
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) && (mpctx->global_sub_pos >= j)) { | |
91 source = i; | |
92 top = j; | |
93 } | |
94 } | |
95 return source; | |
96 } | |
97 | |
98 /** | |
99 * \brief Log the currently displayed subtitle to a file | |
100 * | |
101 * Logs the current or last displayed subtitle together with filename | |
102 * and time information to ~/.mplayer/subtitle_log | |
103 * | |
104 * Intended purpose is to allow convenient marking of bogus subtitles | |
105 * which need to be fixed while watching the movie. | |
106 */ | |
107 | |
108 static void log_sub(void) | |
109 { | |
110 char *fname; | |
111 FILE *f; | |
112 int i; | |
113 | |
114 if (subdata == NULL || vo_sub_last == NULL) | |
115 return; | |
116 fname = get_path("subtitle_log"); | |
117 f = fopen(fname, "a"); | |
118 if (!f) | |
119 return; | |
120 fprintf(f, "----------------------------------------------------------\n"); | |
121 if (subdata->sub_uses_time) { | |
122 fprintf(f, | |
123 "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n", | |
124 filename, vo_sub_last->start / 360000, | |
125 (vo_sub_last->start / 6000) % 60, | |
126 (vo_sub_last->start / 100) % 60, vo_sub_last->start % 100, | |
127 vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60, | |
128 (vo_sub_last->end / 100) % 60, vo_sub_last->end % 100); | |
129 } else { | |
130 fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start, | |
131 vo_sub_last->end); | |
132 } | |
133 for (i = 0; i < vo_sub_last->lines; i++) { | |
134 fprintf(f, "%s\n", vo_sub_last->text[i]); | |
135 } | |
136 fclose(f); | |
137 } | |
138 | |
139 | |
140 /// \defgroup Properties | |
141 ///@{ | |
142 | |
143 /// \defgroup GeneralProperties General properties | |
144 /// \ingroup Properties | |
145 ///@{ | |
146 | |
147 /// OSD level (RW) | |
148 static int mp_property_osdlevel(m_option_t * prop, int action, void *arg, | |
149 MPContext * mpctx) | |
150 { | |
151 return m_property_choice(prop, action, arg, &osd_level); | |
152 } | |
153 | |
154 /// Playback speed (RW) | |
155 static int mp_property_playback_speed(m_option_t * prop, int action, | |
156 void *arg, MPContext * mpctx) | |
157 { | |
158 switch (action) { | |
159 case M_PROPERTY_SET: | |
160 if (!arg) | |
161 return M_PROPERTY_ERROR; | |
162 M_PROPERTY_CLAMP(prop, *(float *) arg); | |
163 playback_speed = *(float *) arg; | |
164 build_afilter_chain(mpctx->sh_audio, &ao_data); | |
165 return M_PROPERTY_OK; | |
166 case M_PROPERTY_STEP_UP: | |
167 case M_PROPERTY_STEP_DOWN: | |
168 playback_speed += (arg ? *(float *) arg : 0.1) * | |
169 (action == M_PROPERTY_STEP_DOWN ? -1 : 1); | |
170 M_PROPERTY_CLAMP(prop, playback_speed); | |
171 build_afilter_chain(mpctx->sh_audio, &ao_data); | |
172 return M_PROPERTY_OK; | |
173 } | |
174 return m_property_float_range(prop, action, arg, &playback_speed); | |
175 } | |
176 | |
177 /// filename with path (RO) | |
178 static int mp_property_path(m_option_t * prop, int action, void *arg, | |
179 MPContext * mpctx) | |
180 { | |
181 return m_property_string_ro(prop, action, arg, filename); | |
182 } | |
183 | |
184 /// filename without path (RO) | |
185 static int mp_property_filename(m_option_t * prop, int action, void *arg, | |
186 MPContext * mpctx) | |
187 { | |
188 char *f; | |
189 if (!filename) | |
190 return M_PROPERTY_UNAVAILABLE; | |
191 if (((f = strrchr(filename, '/')) || (f = strrchr(filename, '\\'))) && f[1]) | |
192 f++; | |
193 else | |
194 f = filename; | |
195 return m_property_string_ro(prop, action, arg, f); | |
196 } | |
197 | |
198 /// Demuxer name (RO) | |
199 static int mp_property_demuxer(m_option_t * prop, int action, void *arg, | |
200 MPContext * mpctx) | |
201 { | |
202 if (!mpctx->demuxer) | |
203 return M_PROPERTY_UNAVAILABLE; | |
204 return m_property_string_ro(prop, action, arg, | |
205 (char *) mpctx->demuxer->desc->name); | |
206 } | |
207 | |
208 /// Position in the stream (RW) | |
209 static int mp_property_stream_pos(m_option_t * prop, int action, void *arg, | |
210 MPContext * mpctx) | |
211 { | |
212 if (!mpctx->demuxer || !mpctx->demuxer->stream) | |
213 return M_PROPERTY_UNAVAILABLE; | |
214 if (!arg) | |
215 return M_PROPERTY_ERROR; | |
216 switch (action) { | |
217 case M_PROPERTY_GET: | |
218 *(off_t *) arg = stream_tell(mpctx->demuxer->stream); | |
219 return M_PROPERTY_OK; | |
220 case M_PROPERTY_SET: | |
221 M_PROPERTY_CLAMP(prop, *(off_t *) arg); | |
222 stream_seek(mpctx->demuxer->stream, *(off_t *) arg); | |
223 return M_PROPERTY_OK; | |
224 } | |
225 return M_PROPERTY_NOT_IMPLEMENTED; | |
226 } | |
227 | |
228 /// Stream start offset (RO) | |
229 static int mp_property_stream_start(m_option_t * prop, int action, | |
230 void *arg, MPContext * mpctx) | |
231 { | |
232 if (!mpctx->demuxer || !mpctx->demuxer->stream) | |
233 return M_PROPERTY_UNAVAILABLE; | |
234 switch (action) { | |
235 case M_PROPERTY_GET: | |
236 *(off_t *) arg = mpctx->demuxer->stream->start_pos; | |
237 return M_PROPERTY_OK; | |
238 } | |
239 return M_PROPERTY_NOT_IMPLEMENTED; | |
240 } | |
241 | |
242 /// Stream end offset (RO) | |
243 static int mp_property_stream_end(m_option_t * prop, int action, void *arg, | |
244 MPContext * mpctx) | |
245 { | |
246 if (!mpctx->demuxer || !mpctx->demuxer->stream) | |
247 return M_PROPERTY_UNAVAILABLE; | |
248 switch (action) { | |
249 case M_PROPERTY_GET: | |
250 *(off_t *) arg = mpctx->demuxer->stream->end_pos; | |
251 return M_PROPERTY_OK; | |
252 } | |
253 return M_PROPERTY_NOT_IMPLEMENTED; | |
254 } | |
255 | |
256 /// Stream length (RO) | |
257 static int mp_property_stream_length(m_option_t * prop, int action, | |
258 void *arg, MPContext * mpctx) | |
259 { | |
260 if (!mpctx->demuxer || !mpctx->demuxer->stream) | |
261 return M_PROPERTY_UNAVAILABLE; | |
262 switch (action) { | |
263 case M_PROPERTY_GET: | |
264 *(off_t *) arg = | |
265 mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos; | |
266 return M_PROPERTY_OK; | |
267 } | |
268 return M_PROPERTY_NOT_IMPLEMENTED; | |
269 } | |
270 | |
271 /// Media length in seconds (RO) | |
272 static int mp_property_length(m_option_t * prop, int action, void *arg, | |
273 MPContext * mpctx) | |
274 { | |
275 double len; | |
276 | |
277 if (!mpctx->demuxer || | |
278 !(int) (len = demuxer_get_time_length(mpctx->demuxer))) | |
279 return M_PROPERTY_UNAVAILABLE; | |
280 | |
281 switch (action) { | |
282 case M_PROPERTY_PRINT: | |
283 if (!arg) | |
284 return M_PROPERTY_ERROR; | |
285 else { | |
286 int h, m, s = len; | |
287 h = s / 3600; | |
288 s -= h * 3600; | |
289 m = s / 60; | |
290 s -= m * 60; | |
291 *(char **) arg = malloc(20); | |
292 if (h > 0) | |
293 sprintf(*(char **) arg, "%d:%02d:%02d", h, m, s); | |
294 else if (m > 0) | |
295 sprintf(*(char **) arg, "%d:%02d", m, s); | |
296 else | |
297 sprintf(*(char **) arg, "%d", s); | |
298 return M_PROPERTY_OK; | |
299 } | |
300 break; | |
301 } | |
302 return m_property_double_ro(prop, action, arg, len); | |
303 } | |
304 | |
305 ///@} | |
306 | |
307 /// \defgroup AudioProperties Audio properties | |
308 /// \ingroup Properties | |
309 ///@{ | |
310 | |
311 /// Volume (RW) | |
312 static int mp_property_volume(m_option_t * prop, int action, void *arg, | |
313 MPContext * mpctx) | |
314 { | |
315 | |
316 if (!mpctx->sh_audio) | |
317 return M_PROPERTY_UNAVAILABLE; | |
318 | |
319 switch (action) { | |
320 case M_PROPERTY_GET: | |
321 if (!arg) | |
322 return M_PROPERTY_ERROR; | |
323 mixer_getbothvolume(&mpctx->mixer, arg); | |
324 return M_PROPERTY_OK; | |
325 case M_PROPERTY_PRINT:{ | |
326 float vol; | |
327 if (!arg) | |
328 return M_PROPERTY_ERROR; | |
329 mixer_getbothvolume(&mpctx->mixer, &vol); | |
330 return m_property_float_range(prop, action, arg, &vol); | |
331 } | |
332 case M_PROPERTY_STEP_UP: | |
333 case M_PROPERTY_STEP_DOWN: | |
334 case M_PROPERTY_SET: | |
335 break; | |
336 default: | |
337 return M_PROPERTY_NOT_IMPLEMENTED; | |
338 } | |
339 | |
340 if (mpctx->edl_muted) | |
341 return M_PROPERTY_DISABLED; | |
342 mpctx->user_muted = 0; | |
343 | |
344 switch (action) { | |
345 case M_PROPERTY_SET: | |
346 if (!arg) | |
347 return M_PROPERTY_ERROR; | |
348 M_PROPERTY_CLAMP(prop, *(float *) arg); | |
349 mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg); | |
350 return M_PROPERTY_OK; | |
351 case M_PROPERTY_STEP_UP: | |
352 if (arg && *(float *) arg <= 0) | |
353 mixer_decvolume(&mpctx->mixer); | |
354 else | |
355 mixer_incvolume(&mpctx->mixer); | |
356 return M_PROPERTY_OK; | |
357 case M_PROPERTY_STEP_DOWN: | |
358 if (arg && *(float *) arg <= 0) | |
359 mixer_incvolume(&mpctx->mixer); | |
360 else | |
361 mixer_decvolume(&mpctx->mixer); | |
362 return M_PROPERTY_OK; | |
363 } | |
364 return M_PROPERTY_NOT_IMPLEMENTED; | |
365 } | |
366 | |
367 /// Mute (RW) | |
368 static int mp_property_mute(m_option_t * prop, int action, void *arg, | |
369 MPContext * mpctx) | |
370 { | |
371 | |
372 if (!mpctx->sh_audio) | |
373 return M_PROPERTY_UNAVAILABLE; | |
374 | |
375 switch (action) { | |
376 case M_PROPERTY_SET: | |
377 if (mpctx->edl_muted) | |
378 return M_PROPERTY_DISABLED; | |
379 if (!arg) | |
380 return M_PROPERTY_ERROR; | |
381 if ((!!*(int *) arg) != mpctx->mixer.muted) | |
382 mixer_mute(&mpctx->mixer); | |
383 mpctx->user_muted = mpctx->mixer.muted; | |
384 return M_PROPERTY_OK; | |
385 case M_PROPERTY_STEP_UP: | |
386 case M_PROPERTY_STEP_DOWN: | |
387 if (mpctx->edl_muted) | |
388 return M_PROPERTY_DISABLED; | |
389 mixer_mute(&mpctx->mixer); | |
390 mpctx->user_muted = mpctx->mixer.muted; | |
391 return M_PROPERTY_OK; | |
392 case M_PROPERTY_PRINT: | |
393 if (!arg) | |
394 return M_PROPERTY_ERROR; | |
395 if (mpctx->edl_muted) { | |
396 *(char **) arg = strdup(MSGTR_EnabledEdl); | |
397 return M_PROPERTY_OK; | |
398 } | |
399 default: | |
400 return m_property_flag(prop, action, arg, &mpctx->mixer.muted); | |
401 | |
402 } | |
403 } | |
404 | |
405 /// Audio delay (RW) | |
406 static int mp_property_audio_delay(m_option_t * prop, int action, | |
407 void *arg, MPContext * mpctx) | |
408 { | |
409 if (!(mpctx->sh_audio && mpctx->sh_video)) | |
410 return M_PROPERTY_UNAVAILABLE; | |
411 switch (action) { | |
412 case M_PROPERTY_SET: | |
413 case M_PROPERTY_STEP_UP: | |
414 case M_PROPERTY_STEP_DOWN: | |
415 if (!arg) | |
416 return M_PROPERTY_ERROR; | |
417 else { | |
418 float delay = audio_delay; | |
419 m_property_delay(prop, action, arg, &audio_delay); | |
420 if (mpctx->sh_audio) | |
421 mpctx->sh_audio->delay -= audio_delay - delay; | |
422 } | |
423 return M_PROPERTY_OK; | |
424 default: | |
425 return m_property_delay(prop, action, arg, &audio_delay); | |
426 } | |
427 } | |
428 | |
429 /// Audio codec tag (RO) | |
430 static int mp_property_audio_format(m_option_t * prop, int action, | |
431 void *arg, MPContext * mpctx) | |
432 { | |
433 if (!mpctx->sh_audio) | |
434 return M_PROPERTY_UNAVAILABLE; | |
435 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format); | |
436 } | |
437 | |
438 /// Audio bitrate (RO) | |
439 static int mp_property_audio_bitrate(m_option_t * prop, int action, | |
440 void *arg, MPContext * mpctx) | |
441 { | |
442 if (!mpctx->sh_audio) | |
443 return M_PROPERTY_UNAVAILABLE; | |
444 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->i_bps); | |
445 } | |
446 | |
447 /// Samplerate (RO) | |
448 static int mp_property_samplerate(m_option_t * prop, int action, void *arg, | |
449 MPContext * mpctx) | |
450 { | |
451 if (!mpctx->sh_audio) | |
452 return M_PROPERTY_UNAVAILABLE; | |
453 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate); | |
454 } | |
455 | |
456 /// Number of channels (RO) | |
457 static int mp_property_channels(m_option_t * prop, int action, void *arg, | |
458 MPContext * mpctx) | |
459 { | |
460 if (!mpctx->sh_audio) | |
461 return M_PROPERTY_UNAVAILABLE; | |
462 switch (action) { | |
463 case M_PROPERTY_PRINT: | |
464 if (!arg) | |
465 return M_PROPERTY_ERROR; | |
466 switch (mpctx->sh_audio->channels) { | |
467 case 1: | |
468 *(char **) arg = strdup("mono"); | |
469 break; | |
470 case 2: | |
471 *(char **) arg = strdup("stereo"); | |
472 break; | |
473 default: | |
474 *(char **) arg = malloc(32); | |
475 sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels); | |
476 } | |
477 return M_PROPERTY_OK; | |
478 } | |
479 return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels); | |
480 } | |
481 | |
482 /// Selected audio id (RW) | |
483 static int mp_property_audio(m_option_t * prop, int action, void *arg, | |
484 MPContext * mpctx) | |
485 { | |
486 int current_id = -1, tmp; | |
487 | |
488 switch (action) { | |
489 case M_PROPERTY_GET: | |
490 if (!mpctx->sh_audio) | |
491 return M_PROPERTY_UNAVAILABLE; | |
492 if (!arg) | |
493 return M_PROPERTY_ERROR; | |
494 *(int *) arg = audio_id; | |
495 return M_PROPERTY_OK; | |
496 case M_PROPERTY_PRINT: | |
497 if (!mpctx->sh_audio) | |
498 return M_PROPERTY_UNAVAILABLE; | |
499 if (!arg) | |
500 return M_PROPERTY_ERROR; | |
501 | |
502 if (audio_id < 0) | |
503 *(char **) arg = strdup(MSGTR_Disabled); | |
504 else { | |
505 char lang[40] = MSGTR_Unknown; | |
506 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA) | |
507 demux_mkv_get_audio_lang(mpctx->demuxer, audio_id, lang, 9); | |
508 #ifdef USE_DVDREAD | |
509 else if (mpctx->stream->type == STREAMTYPE_DVD) { | |
510 int code = dvd_lang_from_aid(mpctx->stream, audio_id); | |
511 if (code) { | |
512 lang[0] = code >> 8; | |
513 lang[1] = code; | |
514 lang[2] = 0; | |
515 } | |
516 } | |
517 #endif | |
518 | |
519 #ifdef USE_DVDNAV | |
520 else if (mpctx->stream->type == STREAMTYPE_DVDNAV) | |
521 dvdnav_lang_from_aid(mpctx->stream, audio_id, lang); | |
522 #endif | |
523 *(char **) arg = malloc(64); | |
524 snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang); | |
525 } | |
526 return M_PROPERTY_OK; | |
527 | |
528 case M_PROPERTY_STEP_UP: | |
529 case M_PROPERTY_SET: | |
530 if (action == M_PROPERTY_SET && arg) | |
531 tmp = *((int *) arg); | |
532 else | |
533 tmp = -1; | |
534 current_id = mpctx->demuxer->audio->id; | |
535 audio_id = demuxer_switch_audio(mpctx->demuxer, tmp); | |
536 if (audio_id == -2 | |
537 || (audio_id > -1 | |
538 && mpctx->demuxer->audio->id != current_id && current_id != -2)) | |
539 uninit_player(INITED_AO | INITED_ACODEC); | |
540 if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) { | |
541 sh_audio_t *sh2; | |
542 sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id]; | |
543 if (sh2) { | |
544 sh2->ds = mpctx->demuxer->audio; | |
545 mpctx->sh_audio = sh2; | |
546 reinit_audio_chain(); | |
547 } | |
548 } | |
549 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id); | |
550 return M_PROPERTY_OK; | |
551 default: | |
552 return M_PROPERTY_NOT_IMPLEMENTED; | |
553 } | |
554 | |
555 } | |
556 | |
557 /// Selected video id (RW) | |
558 static int mp_property_video(m_option_t * prop, int action, void *arg, | |
559 MPContext * mpctx) | |
560 { | |
561 int current_id = -1, tmp; | |
562 | |
563 switch (action) { | |
564 case M_PROPERTY_GET: | |
565 if (!mpctx->sh_video) | |
566 return M_PROPERTY_UNAVAILABLE; | |
567 if (!arg) | |
568 return M_PROPERTY_ERROR; | |
569 *(int *) arg = video_id; | |
570 return M_PROPERTY_OK; | |
571 case M_PROPERTY_PRINT: | |
572 if (!mpctx->sh_video) | |
573 return M_PROPERTY_UNAVAILABLE; | |
574 if (!arg) | |
575 return M_PROPERTY_ERROR; | |
576 | |
577 if (video_id < 0) | |
578 *(char **) arg = strdup(MSGTR_Disabled); | |
579 else { | |
580 char lang[40] = MSGTR_Unknown; | |
581 *(char **) arg = malloc(64); | |
582 snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang); | |
583 } | |
584 return M_PROPERTY_OK; | |
585 | |
586 case M_PROPERTY_STEP_UP: | |
587 case M_PROPERTY_SET: | |
588 current_id = mpctx->demuxer->video->id; | |
589 if (action == M_PROPERTY_SET && arg) | |
590 tmp = *((int *) arg); | |
591 else | |
592 tmp = -1; | |
593 video_id = demuxer_switch_video(mpctx->demuxer, tmp); | |
594 if (video_id == -2 | |
595 || (video_id > -1 && mpctx->demuxer->video->id != current_id | |
596 && current_id != -2)) | |
597 uninit_player(INITED_VCODEC | | |
598 (fixed_vo && video_id != -2 ? 0 : INITED_VO)); | |
599 if (video_id > -1 && mpctx->demuxer->video->id != current_id) { | |
600 sh_video_t *sh2; | |
601 sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id]; | |
602 if (sh2) { | |
603 sh2->ds = mpctx->demuxer->video; | |
604 mpctx->sh_video = sh2; | |
605 reinit_video_chain(); | |
606 } | |
607 } | |
608 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id); | |
609 return M_PROPERTY_OK; | |
610 | |
611 default: | |
612 return M_PROPERTY_NOT_IMPLEMENTED; | |
613 } | |
614 } | |
615 | |
616 static int mp_property_program(m_option_t * prop, int action, void *arg, | |
617 MPContext * mpctx) | |
618 { | |
619 demux_program_t prog; | |
620 | |
621 switch (action) { | |
622 case M_PROPERTY_STEP_UP: | |
623 case M_PROPERTY_SET: | |
624 if (action == M_PROPERTY_SET && arg) | |
625 prog.progid = *((int *) arg); | |
626 else | |
627 prog.progid = -1; | |
628 if (demux_control | |
629 (mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM, | |
630 &prog) == DEMUXER_CTRL_NOTIMPL) | |
631 return M_PROPERTY_ERROR; | |
632 | |
633 mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx); | |
634 mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx); | |
635 return M_PROPERTY_OK; | |
636 | |
637 default: | |
638 return M_PROPERTY_NOT_IMPLEMENTED; | |
639 } | |
640 } | |
641 | |
642 ///@} | |
643 | |
644 /// \defgroup VideoProperties Video properties | |
645 /// \ingroup Properties | |
646 ///@{ | |
647 | |
648 /// Fullscreen state (RW) | |
649 static int mp_property_fullscreen(m_option_t * prop, int action, void *arg, | |
650 MPContext * mpctx) | |
651 { | |
652 | |
653 if (!mpctx->video_out) | |
654 return M_PROPERTY_UNAVAILABLE; | |
655 | |
656 switch (action) { | |
657 case M_PROPERTY_SET: | |
658 if (!arg) | |
659 return M_PROPERTY_ERROR; | |
660 M_PROPERTY_CLAMP(prop, *(int *) arg); | |
661 if (vo_fs == !!*(int *) arg) | |
662 return M_PROPERTY_OK; | |
663 case M_PROPERTY_STEP_UP: | |
664 case M_PROPERTY_STEP_DOWN: | |
665 #ifdef HAVE_NEW_GUI | |
666 if (use_gui) | |
667 guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN); | |
668 else | |
669 #endif | |
670 if (vo_config_count) | |
671 mpctx->video_out->control(VOCTRL_FULLSCREEN, 0); | |
672 return M_PROPERTY_OK; | |
673 default: | |
674 return m_property_flag(prop, action, arg, &vo_fs); | |
675 } | |
676 } | |
677 | |
678 static int mp_property_deinterlace(m_option_t * prop, int action, | |
679 void *arg, MPContext * mpctx) | |
680 { | |
681 int deinterlace; | |
682 vf_instance_t *vf; | |
683 if (!mpctx->sh_video || !mpctx->sh_video->vfilter) | |
684 return M_PROPERTY_UNAVAILABLE; | |
685 vf = mpctx->sh_video->vfilter; | |
686 switch (action) { | |
687 case M_PROPERTY_GET: | |
688 if (!arg) | |
689 return M_PROPERTY_ERROR; | |
690 vf->control(vf, VFCTRL_GET_DEINTERLACE, arg); | |
691 return M_PROPERTY_OK; | |
692 case M_PROPERTY_SET: | |
693 if (!arg) | |
694 return M_PROPERTY_ERROR; | |
695 M_PROPERTY_CLAMP(prop, *(int *) arg); | |
696 vf->control(vf, VFCTRL_SET_DEINTERLACE, arg); | |
697 return M_PROPERTY_OK; | |
698 case M_PROPERTY_STEP_UP: | |
699 case M_PROPERTY_STEP_DOWN: | |
700 vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace); | |
701 deinterlace = !deinterlace; | |
702 vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace); | |
703 return M_PROPERTY_OK; | |
704 } | |
705 return M_PROPERTY_NOT_IMPLEMENTED; | |
706 } | |
707 | |
708 /// Panscan (RW) | |
709 static int mp_property_panscan(m_option_t * prop, int action, void *arg, | |
710 MPContext * mpctx) | |
711 { | |
712 | |
713 if (!mpctx->video_out | |
714 || mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE) | |
715 return M_PROPERTY_UNAVAILABLE; | |
716 | |
717 switch (action) { | |
718 case M_PROPERTY_SET: | |
719 if (!arg) | |
720 return M_PROPERTY_ERROR; | |
721 M_PROPERTY_CLAMP(prop, *(float *) arg); | |
722 vo_panscan = *(float *) arg; | |
723 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL); | |
724 return M_PROPERTY_OK; | |
725 case M_PROPERTY_STEP_UP: | |
726 case M_PROPERTY_STEP_DOWN: | |
727 vo_panscan += (arg ? *(float *) arg : 0.1) * | |
728 (action == M_PROPERTY_STEP_DOWN ? -1 : 1); | |
729 if (vo_panscan > 1) | |
730 vo_panscan = 1; | |
731 else if (vo_panscan < 0) | |
732 vo_panscan = 0; | |
733 mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL); | |
734 return M_PROPERTY_OK; | |
735 default: | |
736 return m_property_float_range(prop, action, arg, &vo_panscan); | |
737 } | |
738 } | |
739 | |
740 /// Helper to set vo flags. | |
741 /** \ingroup PropertyImplHelper | |
742 */ | |
743 static int mp_property_vo_flag(m_option_t * prop, int action, void *arg, | |
744 int vo_ctrl, int *vo_var, MPContext * mpctx) | |
745 { | |
746 | |
747 if (!mpctx->video_out) | |
748 return M_PROPERTY_UNAVAILABLE; | |
749 | |
750 switch (action) { | |
751 case M_PROPERTY_SET: | |
752 if (!arg) | |
753 return M_PROPERTY_ERROR; | |
754 M_PROPERTY_CLAMP(prop, *(int *) arg); | |
755 if (*vo_var == !!*(int *) arg) | |
756 return M_PROPERTY_OK; | |
757 case M_PROPERTY_STEP_UP: | |
758 case M_PROPERTY_STEP_DOWN: | |
759 if (vo_config_count) | |
760 mpctx->video_out->control(vo_ctrl, 0); | |
761 return M_PROPERTY_OK; | |
762 default: | |
763 return m_property_flag(prop, action, arg, vo_var); | |
764 } | |
765 } | |
766 | |
767 /// Window always on top (RW) | |
768 static int mp_property_ontop(m_option_t * prop, int action, void *arg, | |
769 MPContext * mpctx) | |
770 { | |
771 return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop, | |
772 mpctx); | |
773 } | |
774 | |
775 /// Display in the root window (RW) | |
776 static int mp_property_rootwin(m_option_t * prop, int action, void *arg, | |
777 MPContext * mpctx) | |
778 { | |
779 return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN, | |
780 &vo_rootwin, mpctx); | |
781 } | |
782 | |
783 /// Show window borders (RW) | |
784 static int mp_property_border(m_option_t * prop, int action, void *arg, | |
785 MPContext * mpctx) | |
786 { | |
787 return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER, | |
788 &vo_border, mpctx); | |
789 } | |
790 | |
791 /// Framedropping state (RW) | |
792 static int mp_property_framedropping(m_option_t * prop, int action, | |
793 void *arg, MPContext * mpctx) | |
794 { | |
795 | |
796 if (!mpctx->sh_video) | |
797 return M_PROPERTY_UNAVAILABLE; | |
798 | |
799 switch (action) { | |
800 case M_PROPERTY_PRINT: | |
801 if (!arg) | |
802 return M_PROPERTY_ERROR; | |
803 *(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled : | |
804 (frame_dropping == 2 ? MSGTR_HardFrameDrop : | |
805 MSGTR_Disabled)); | |
806 return M_PROPERTY_OK; | |
807 default: | |
808 return m_property_choice(prop, action, arg, &frame_dropping); | |
809 } | |
810 } | |
811 | |
812 /// Color settings, try to use vf/vo then fall back on TV. (RW) | |
813 static int mp_property_gamma(m_option_t * prop, int action, void *arg, | |
814 MPContext * mpctx) | |
815 { | |
816 int *gamma = prop->priv, r; | |
817 | |
818 if (!mpctx->sh_video) | |
819 return M_PROPERTY_UNAVAILABLE; | |
820 | |
821 if (gamma[0] == 1000) { | |
822 gamma[0] = 0; | |
823 get_video_colors(mpctx->sh_video, prop->name, gamma); | |
824 } | |
825 | |
826 switch (action) { | |
827 case M_PROPERTY_SET: | |
828 if (!arg) | |
829 return M_PROPERTY_ERROR; | |
830 M_PROPERTY_CLAMP(prop, *(int *) arg); | |
831 *gamma = *(int *) arg; | |
832 r = set_video_colors(mpctx->sh_video, prop->name, *gamma); | |
833 if (r <= 0) | |
834 break; | |
835 return r; | |
836 case M_PROPERTY_GET: | |
837 if (!arg) | |
838 return M_PROPERTY_ERROR; | |
839 r = get_video_colors(mpctx->sh_video, prop->name, arg); | |
840 if (r <= 0) | |
841 break; | |
842 return r; | |
843 case M_PROPERTY_STEP_UP: | |
844 case M_PROPERTY_STEP_DOWN: | |
845 *gamma += (arg ? *(int *) arg : 1) * | |
846 (action == M_PROPERTY_STEP_DOWN ? -1 : 1); | |
847 M_PROPERTY_CLAMP(prop, *gamma); | |
848 r = set_video_colors(mpctx->sh_video, prop->name, *gamma); | |
849 if (r <= 0) | |
850 break; | |
851 return r; | |
852 default: | |
853 return M_PROPERTY_NOT_IMPLEMENTED; | |
854 } | |
855 | |
856 #ifdef USE_TV | |
857 if (mpctx->demuxer->type == DEMUXER_TYPE_TV) { | |
858 int l = strlen(prop->name); | |
859 char tv_prop[3 + l + 1]; | |
860 sprintf(tv_prop, "tv_%s", prop->name); | |
861 return mp_property_do(tv_prop, action, arg, mpctx); | |
862 } | |
863 #endif | |
864 | |
865 return M_PROPERTY_UNAVAILABLE; | |
866 } | |
867 | |
868 /// VSync (RW) | |
869 static int mp_property_vsync(m_option_t * prop, int action, void *arg, | |
870 MPContext * mpctx) | |
871 { | |
872 return m_property_flag(prop, action, arg, &vo_vsync); | |
873 } | |
874 | |
875 /// Video codec tag (RO) | |
876 static int mp_property_video_format(m_option_t * prop, int action, | |
877 void *arg, MPContext * mpctx) | |
878 { | |
879 if (!mpctx->sh_video) | |
880 return M_PROPERTY_UNAVAILABLE; | |
881 return m_property_int_ro(prop, action, arg, mpctx->sh_video->format); | |
882 } | |
883 | |
884 /// Video bitrate (RO) | |
885 static int mp_property_video_bitrate(m_option_t * prop, int action, | |
886 void *arg, MPContext * mpctx) | |
887 { | |
888 if (!mpctx->sh_video) | |
889 return M_PROPERTY_UNAVAILABLE; | |
890 return m_property_int_ro(prop, action, arg, mpctx->sh_video->i_bps); | |
891 } | |
892 | |
893 /// Video display width (RO) | |
894 static int mp_property_width(m_option_t * prop, int action, void *arg, | |
895 MPContext * mpctx) | |
896 { | |
897 if (!mpctx->sh_video) | |
898 return M_PROPERTY_UNAVAILABLE; | |
899 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_w); | |
900 } | |
901 | |
902 /// Video display height (RO) | |
903 static int mp_property_height(m_option_t * prop, int action, void *arg, | |
904 MPContext * mpctx) | |
905 { | |
906 if (!mpctx->sh_video) | |
907 return M_PROPERTY_UNAVAILABLE; | |
908 return m_property_int_ro(prop, action, arg, mpctx->sh_video->disp_h); | |
909 } | |
910 | |
911 /// Video fps (RO) | |
912 static int mp_property_fps(m_option_t * prop, int action, void *arg, | |
913 MPContext * mpctx) | |
914 { | |
915 if (!mpctx->sh_video) | |
916 return M_PROPERTY_UNAVAILABLE; | |
917 return m_property_float_ro(prop, action, arg, mpctx->sh_video->fps); | |
918 } | |
919 | |
920 /// Video aspect (RO) | |
921 static int mp_property_aspect(m_option_t * prop, int action, void *arg, | |
922 MPContext * mpctx) | |
923 { | |
924 if (!mpctx->sh_video) | |
925 return M_PROPERTY_UNAVAILABLE; | |
926 return m_property_float_ro(prop, action, arg, mpctx->sh_video->aspect); | |
927 } | |
928 | |
929 ///@} | |
930 | |
931 /// \defgroup SubProprties Subtitles properties | |
932 /// \ingroup Properties | |
933 ///@{ | |
934 | |
935 /// Text subtitle position (RW) | |
936 static int mp_property_sub_pos(m_option_t * prop, int action, void *arg, | |
937 MPContext * mpctx) | |
938 { | |
939 if (!mpctx->sh_video) | |
940 return M_PROPERTY_UNAVAILABLE; | |
941 | |
942 switch (action) { | |
943 case M_PROPERTY_SET: | |
944 if (!arg) | |
945 return M_PROPERTY_ERROR; | |
946 case M_PROPERTY_STEP_UP: | |
947 case M_PROPERTY_STEP_DOWN: | |
948 vo_osd_changed(OSDTYPE_SUBTITLE); | |
949 default: | |
950 return m_property_int_range(prop, action, arg, &sub_pos); | |
951 } | |
952 } | |
953 | |
954 /// Selected subtitles (RW) | |
955 static int mp_property_sub(m_option_t * prop, int action, void *arg, | |
956 MPContext * mpctx) | |
957 { | |
958 demux_stream_t *const d_sub = mpctx->d_sub; | |
959 const int global_sub_size = mpctx->global_sub_size; | |
960 int source = -1, reset_spu = 0; | |
961 char *sub_name; | |
962 | |
963 if (global_sub_size <= 0) | |
964 return M_PROPERTY_UNAVAILABLE; | |
965 | |
966 switch (action) { | |
967 case M_PROPERTY_GET: | |
968 if (!arg) | |
969 return M_PROPERTY_ERROR; | |
970 *(int *) arg = mpctx->global_sub_pos; | |
971 return M_PROPERTY_OK; | |
972 case M_PROPERTY_PRINT: | |
973 if (!arg) | |
974 return M_PROPERTY_ERROR; | |
975 *(char **) arg = malloc(64); | |
976 (*(char **) arg)[63] = 0; | |
977 sub_name = 0; | |
978 if (subdata) | |
979 sub_name = subdata->filename; | |
980 #ifdef USE_ASS | |
981 if (ass_track && ass_track->name) | |
982 sub_name = ass_track->name; | |
983 #endif | |
984 if (sub_name) { | |
985 char *tmp, *tmp2; | |
986 tmp = sub_name; | |
987 if ((tmp2 = strrchr(tmp, '/'))) | |
988 tmp = tmp2 + 1; | |
989 | |
990 snprintf(*(char **) arg, 63, "(%d) %s%s", | |
991 mpctx->set_of_sub_pos + 1, | |
992 strlen(tmp) < 20 ? "" : "...", | |
993 strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19); | |
994 return M_PROPERTY_OK; | |
995 } | |
996 #ifdef USE_DVDNAV | |
997 if (mpctx->stream->type == STREAMTYPE_DVDNAV) { | |
998 if (vo_spudec && dvdsub_id >= 0) { | |
999 unsigned char lang[3]; | |
1000 if (dvdnav_lang_from_sid(mpctx->stream, dvdsub_id, lang)) { | |
1001 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang); | |
1002 return M_PROPERTY_OK; | |
1003 } | |
1004 } | |
1005 } | |
1006 #endif | |
1007 | |
1008 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) { | |
1009 char lang[40] = MSGTR_Unknown; | |
1010 demux_mkv_get_sub_lang(mpctx->demuxer, dvdsub_id, lang, 9); | |
1011 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang); | |
1012 return M_PROPERTY_OK; | |
1013 } | |
1014 #ifdef HAVE_OGGVORBIS | |
1015 if (mpctx->demuxer->type == DEMUXER_TYPE_OGG && d_sub && dvdsub_id >= 0) { | |
1016 char *lang = demux_ogg_sub_lang(mpctx->demuxer, dvdsub_id); | |
1017 if (!lang) | |
1018 lang = MSGTR_Unknown; | |
1019 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang); | |
1020 return M_PROPERTY_OK; | |
1021 } | |
1022 #endif | |
1023 if (vo_vobsub && vobsub_id >= 0) { | |
1024 const char *language = MSGTR_Unknown; | |
1025 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id); | |
1026 snprintf(*(char **) arg, 63, "(%d) %s", | |
1027 vobsub_id, language ? language : MSGTR_Unknown); | |
1028 return M_PROPERTY_OK; | |
1029 } | |
1030 #ifdef USE_DVDREAD | |
1031 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD | |
1032 && dvdsub_id >= 0) { | |
1033 char lang[3]; | |
1034 int code = dvd_lang_from_sid(mpctx->stream, dvdsub_id); | |
1035 lang[0] = code >> 8; | |
1036 lang[1] = code; | |
1037 lang[2] = 0; | |
1038 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang); | |
1039 return M_PROPERTY_OK; | |
1040 } | |
1041 #endif | |
1042 if (dvdsub_id >= 0) { | |
1043 snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, MSGTR_Unknown); | |
1044 return M_PROPERTY_OK; | |
1045 } | |
1046 snprintf(*(char **) arg, 63, MSGTR_Disabled); | |
1047 return M_PROPERTY_OK; | |
1048 | |
1049 case M_PROPERTY_SET: | |
1050 if (!arg) | |
1051 return M_PROPERTY_ERROR; | |
1052 if (*(int *) arg < -1) | |
1053 *(int *) arg = -1; | |
1054 else if (*(int *) arg >= global_sub_size) | |
1055 *(int *) arg = global_sub_size - 1; | |
1056 mpctx->global_sub_pos = *(int *) arg; | |
1057 break; | |
1058 case M_PROPERTY_STEP_UP: | |
1059 mpctx->global_sub_pos += 2; | |
1060 mpctx->global_sub_pos = | |
1061 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1; | |
1062 break; | |
1063 case M_PROPERTY_STEP_DOWN: | |
1064 mpctx->global_sub_pos += global_sub_size + 1; | |
1065 mpctx->global_sub_pos = | |
1066 (mpctx->global_sub_pos % (global_sub_size + 1)) - 1; | |
1067 break; | |
1068 default: | |
1069 return M_PROPERTY_NOT_IMPLEMENTED; | |
1070 } | |
1071 | |
1072 if (mpctx->global_sub_pos >= 0) | |
1073 source = sub_source(mpctx); | |
1074 | |
1075 mp_msg(MSGT_CPLAYER, MSGL_DBG3, | |
1076 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n", | |
1077 global_sub_size, | |
1078 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB], | |
1079 mpctx->global_sub_indices[SUB_SOURCE_SUBS], | |
1080 mpctx->global_sub_indices[SUB_SOURCE_DEMUX], | |
1081 mpctx->global_sub_pos, source); | |
1082 | |
1083 mpctx->set_of_sub_pos = -1; | |
1084 subdata = NULL; | |
1085 vo_sub_last = vo_sub = NULL; | |
1086 | |
1087 vobsub_id = -1; | |
1088 dvdsub_id = -1; | |
1089 if (d_sub) { | |
1090 if (d_sub->id > -2) | |
1091 reset_spu = 1; | |
1092 d_sub->id = -2; | |
1093 } | |
1094 #ifdef USE_ASS | |
1095 ass_track = 0; | |
1096 #endif | |
1097 | |
1098 if (source == SUB_SOURCE_VOBSUB) { | |
1099 vobsub_id = | |
1100 mpctx->global_sub_pos - | |
1101 mpctx->global_sub_indices[SUB_SOURCE_VOBSUB]; | |
1102 } else if (source == SUB_SOURCE_SUBS) { | |
1103 mpctx->set_of_sub_pos = | |
1104 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_SUBS]; | |
1105 #ifdef USE_ASS | |
1106 if (ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]) | |
1107 ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]; | |
1108 else | |
1109 #endif | |
1110 { | |
1111 subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos]; | |
1112 vo_osd_changed(OSDTYPE_SUBTITLE); | |
1113 } | |
1114 } else if (source == SUB_SOURCE_DEMUX) { | |
1115 dvdsub_id = | |
1116 mpctx->global_sub_pos - mpctx->global_sub_indices[SUB_SOURCE_DEMUX]; | |
1117 if (d_sub) { | |
1118 #ifdef USE_DVDREAD | |
1119 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVD) { | |
1120 d_sub->id = dvdsub_id; | |
1121 } | |
1122 #endif | |
1123 | |
1124 #ifdef USE_DVDNAV | |
1125 if (vo_spudec && mpctx->stream->type == STREAMTYPE_DVDNAV) { | |
1126 d_sub->id = dvdsub_id; | |
1127 } | |
1128 #endif | |
1129 if (mpctx->stream->type != STREAMTYPE_DVD | |
1130 && mpctx->stream->type != STREAMTYPE_DVDNAV) { | |
1131 int i = 0; | |
1132 for (d_sub->id = 0; d_sub->id < MAX_S_STREAMS; d_sub->id++) { | |
1133 if (mpctx->demuxer->s_streams[d_sub->id]) { | |
1134 if (i == dvdsub_id) | |
1135 break; | |
1136 i++; | |
1137 } | |
1138 } | |
1139 d_sub->sh = mpctx->demuxer->s_streams[d_sub->id]; | |
1140 } | |
1141 if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA) | |
1142 d_sub->id = demux_mkv_change_subs(mpctx->demuxer, dvdsub_id); | |
1143 if (d_sub->sh && d_sub->id >= 0) { | |
1144 sh_sub_t *sh = d_sub->sh; | |
1145 if (sh->type == 'v') | |
1146 init_vo_spudec(); | |
1147 #ifdef USE_ASS | |
1148 else if (ass_enabled && sh->type == 'a') | |
1149 ass_track = sh->ass_track; | |
1150 #endif | |
1151 } | |
1152 } | |
1153 } | |
1154 #ifdef USE_DVDREAD | |
1155 if (vo_spudec | |
1156 && (mpctx->stream->type == STREAMTYPE_DVD | |
1157 || mpctx->stream->type == STREAMTYPE_DVDNAV) | |
1158 && dvdsub_id < 0 && reset_spu) { | |
1159 dvdsub_id = -2; | |
1160 d_sub->id = dvdsub_id; | |
1161 } | |
1162 #endif | |
1163 update_subtitles(mpctx->sh_video, d_sub, 1); | |
1164 | |
1165 return M_PROPERTY_OK; | |
1166 } | |
1167 | |
1168 /// Subtitle delay (RW) | |
1169 static int mp_property_sub_delay(m_option_t * prop, int action, void *arg, | |
1170 MPContext * mpctx) | |
1171 { | |
1172 if (!mpctx->sh_video) | |
1173 return M_PROPERTY_UNAVAILABLE; | |
1174 return m_property_delay(prop, action, arg, &sub_delay); | |
1175 } | |
1176 | |
1177 /// Alignment of text subtitles (RW) | |
1178 static int mp_property_sub_alignment(m_option_t * prop, int action, | |
1179 void *arg, MPContext * mpctx) | |
1180 { | |
1181 char *name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom }; | |
1182 | |
1183 if (!mpctx->sh_video || mpctx->global_sub_pos < 0 | |
1184 || sub_source(mpctx) != SUB_SOURCE_SUBS) | |
1185 return M_PROPERTY_UNAVAILABLE; | |
1186 | |
1187 switch (action) { | |
1188 case M_PROPERTY_PRINT: | |
1189 if (!arg) | |
1190 return M_PROPERTY_ERROR; | |
1191 M_PROPERTY_CLAMP(prop, sub_alignment); | |
1192 *(char **) arg = strdup(name[sub_alignment]); | |
1193 return M_PROPERTY_OK; | |
1194 case M_PROPERTY_SET: | |
1195 if (!arg) | |
1196 return M_PROPERTY_ERROR; | |
1197 case M_PROPERTY_STEP_UP: | |
1198 case M_PROPERTY_STEP_DOWN: | |
1199 vo_osd_changed(OSDTYPE_SUBTITLE); | |
1200 default: | |
1201 return m_property_choice(prop, action, arg, &sub_alignment); | |
1202 } | |
1203 } | |
1204 | |
1205 /// Subtitle visibility (RW) | |
1206 static int mp_property_sub_visibility(m_option_t * prop, int action, | |
1207 void *arg, MPContext * mpctx) | |
1208 { | |
1209 if (!mpctx->sh_video) | |
1210 return M_PROPERTY_UNAVAILABLE; | |
1211 | |
1212 switch (action) { | |
1213 case M_PROPERTY_SET: | |
1214 if (!arg) | |
1215 return M_PROPERTY_ERROR; | |
1216 case M_PROPERTY_STEP_UP: | |
1217 case M_PROPERTY_STEP_DOWN: | |
1218 vo_osd_changed(OSDTYPE_SUBTITLE); | |
1219 if (vo_spudec) | |
1220 vo_osd_changed(OSDTYPE_SPU); | |
1221 default: | |
1222 return m_property_flag(prop, action, arg, &sub_visibility); | |
1223 } | |
1224 } | |
1225 | |
1226 /// Show only forced subtitles (RW) | |
1227 static int mp_property_sub_forced_only(m_option_t * prop, int action, | |
1228 void *arg, MPContext * mpctx) | |
1229 { | |
1230 if (!vo_spudec) | |
1231 return M_PROPERTY_UNAVAILABLE; | |
1232 | |
1233 switch (action) { | |
1234 case M_PROPERTY_SET: | |
1235 if (!arg) | |
1236 return M_PROPERTY_ERROR; | |
1237 case M_PROPERTY_STEP_UP: | |
1238 case M_PROPERTY_STEP_DOWN: | |
1239 m_property_flag(prop, action, arg, &forced_subs_only); | |
1240 spudec_set_forced_subs_only(vo_spudec, forced_subs_only); | |
1241 return M_PROPERTY_OK; | |
1242 default: | |
1243 return m_property_flag(prop, action, arg, &forced_subs_only); | |
1244 } | |
1245 | |
1246 } | |
1247 | |
1248 ///@} | |
1249 | |
1250 /// \defgroup TVProperties TV properties | |
1251 /// \ingroup Properties | |
1252 ///@{ | |
1253 | |
1254 #ifdef USE_TV | |
1255 | |
1256 /// TV color settings (RW) | |
1257 static int mp_property_tv_color(m_option_t * prop, int action, void *arg, | |
1258 MPContext * mpctx) | |
1259 { | |
1260 int r, val; | |
1261 tvi_handle_t *tvh = mpctx->demuxer->priv; | |
1262 if (mpctx->demuxer->type != DEMUXER_TYPE_TV || !tvh) | |
1263 return M_PROPERTY_UNAVAILABLE; | |
1264 | |
1265 switch (action) { | |
1266 case M_PROPERTY_SET: | |
1267 if (!arg) | |
1268 return M_PROPERTY_ERROR; | |
1269 M_PROPERTY_CLAMP(prop, *(int *) arg); | |
1270 return tv_set_color_options(tvh, (int) prop->priv, *(int *) arg); | |
1271 case M_PROPERTY_GET: | |
1272 return tv_get_color_options(tvh, (int) prop->priv, arg); | |
1273 case M_PROPERTY_STEP_UP: | |
1274 case M_PROPERTY_STEP_DOWN: | |
1275 if ((r = tv_get_color_options(tvh, (int) prop->priv, &val)) >= 0) { | |
1276 if (!r) | |
1277 return M_PROPERTY_ERROR; | |
1278 val += (arg ? *(int *) arg : 1) * | |
1279 (action == M_PROPERTY_STEP_DOWN ? -1 : 1); | |
1280 M_PROPERTY_CLAMP(prop, val); | |
1281 return tv_set_color_options(tvh, (int) prop->priv, val); | |
1282 } | |
1283 return M_PROPERTY_ERROR; | |
1284 } | |
1285 return M_PROPERTY_NOT_IMPLEMENTED; | |
1286 } | |
1287 | |
1288 #endif | |
1289 | |
1290 ///@} | |
1291 | |
1292 /// All properties available in MPlayer. | |
1293 /** \ingroup Properties | |
1294 */ | |
1295 static m_option_t mp_properties[] = { | |
1296 // General | |
1297 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT, | |
1298 M_OPT_RANGE, 0, 3, NULL }, | |
1299 { "speed", mp_property_playback_speed, CONF_TYPE_FLOAT, | |
1300 M_OPT_RANGE, 0.01, 100.0, NULL }, | |
1301 { "filename", mp_property_filename, CONF_TYPE_STRING, | |
1302 0, 0, 0, NULL }, | |
1303 { "path", mp_property_path, CONF_TYPE_STRING, | |
1304 0, 0, 0, NULL }, | |
1305 { "demuxer", mp_property_demuxer, CONF_TYPE_STRING, | |
1306 0, 0, 0, NULL }, | |
1307 { "stream_pos", mp_property_stream_pos, CONF_TYPE_POSITION, | |
1308 M_OPT_MIN, 0, 0, NULL }, | |
1309 { "stream_start", mp_property_stream_start, CONF_TYPE_POSITION, | |
1310 M_OPT_MIN, 0, 0, NULL }, | |
1311 { "stream_end", mp_property_stream_end, CONF_TYPE_POSITION, | |
1312 M_OPT_MIN, 0, 0, NULL }, | |
1313 { "stream_length", mp_property_stream_length, CONF_TYPE_POSITION, | |
1314 M_OPT_MIN, 0, 0, NULL }, | |
1315 { "length", mp_property_length, CONF_TYPE_DOUBLE, | |
1316 0, 0, 0, NULL }, | |
1317 | |
1318 // Audio | |
1319 { "volume", mp_property_volume, CONF_TYPE_FLOAT, | |
1320 M_OPT_RANGE, 0, 100, NULL }, | |
1321 { "mute", mp_property_mute, CONF_TYPE_FLAG, | |
1322 M_OPT_RANGE, 0, 1, NULL }, | |
1323 { "audio_delay", mp_property_audio_delay, CONF_TYPE_FLOAT, | |
1324 M_OPT_RANGE, -100, 100, NULL }, | |
1325 { "audio_format", mp_property_audio_format, CONF_TYPE_INT, | |
1326 0, 0, 0, NULL }, | |
1327 { "audio_bitrate", mp_property_audio_bitrate, CONF_TYPE_INT, | |
1328 0, 0, 0, NULL }, | |
1329 { "samplerate", mp_property_samplerate, CONF_TYPE_INT, | |
1330 0, 0, 0, NULL }, | |
1331 { "channels", mp_property_channels, CONF_TYPE_INT, | |
1332 0, 0, 0, NULL }, | |
1333 { "switch_audio", mp_property_audio, CONF_TYPE_INT, | |
1334 CONF_RANGE, -2, MAX_A_STREAMS - 1, NULL }, | |
1335 | |
1336 // Video | |
1337 { "fullscreen", mp_property_fullscreen, CONF_TYPE_FLAG, | |
1338 M_OPT_RANGE, 0, 1, NULL }, | |
1339 { "deinterlace", mp_property_deinterlace, CONF_TYPE_FLAG, | |
1340 M_OPT_RANGE, 0, 1, NULL }, | |
1341 { "ontop", mp_property_ontop, CONF_TYPE_FLAG, | |
1342 M_OPT_RANGE, 0, 1, NULL }, | |
1343 { "rootwin", mp_property_rootwin, CONF_TYPE_FLAG, | |
1344 M_OPT_RANGE, 0, 1, NULL }, | |
1345 { "border", mp_property_border, CONF_TYPE_FLAG, | |
1346 M_OPT_RANGE, 0, 1, NULL }, | |
1347 { "framedropping", mp_property_framedropping, CONF_TYPE_INT, | |
1348 M_OPT_RANGE, 0, 2, NULL }, | |
1349 { "gamma", mp_property_gamma, CONF_TYPE_INT, | |
1350 M_OPT_RANGE, -100, 100, &vo_gamma_gamma }, | |
1351 { "brightness", mp_property_gamma, CONF_TYPE_INT, | |
1352 M_OPT_RANGE, -100, 100, &vo_gamma_brightness }, | |
1353 { "contrast", mp_property_gamma, CONF_TYPE_INT, | |
1354 M_OPT_RANGE, -100, 100, &vo_gamma_contrast }, | |
1355 { "saturation", mp_property_gamma, CONF_TYPE_INT, | |
1356 M_OPT_RANGE, -100, 100, &vo_gamma_saturation }, | |
1357 { "hue", mp_property_gamma, CONF_TYPE_INT, | |
1358 M_OPT_RANGE, -100, 100, &vo_gamma_hue }, | |
1359 { "panscan", mp_property_panscan, CONF_TYPE_FLOAT, | |
1360 M_OPT_RANGE, 0, 1, NULL }, | |
1361 { "vsync", mp_property_vsync, CONF_TYPE_FLAG, | |
1362 M_OPT_RANGE, 0, 1, NULL }, | |
1363 { "video_format", mp_property_video_format, CONF_TYPE_INT, | |
1364 0, 0, 0, NULL }, | |
1365 { "video_bitrate", mp_property_video_bitrate, CONF_TYPE_INT, | |
1366 0, 0, 0, NULL }, | |
1367 { "width", mp_property_width, CONF_TYPE_INT, | |
1368 0, 0, 0, NULL }, | |
1369 { "height", mp_property_height, CONF_TYPE_INT, | |
1370 0, 0, 0, NULL }, | |
1371 { "fps", mp_property_fps, CONF_TYPE_FLOAT, | |
1372 0, 0, 0, NULL }, | |
1373 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT, | |
1374 0, 0, 0, NULL }, | |
1375 { "switch_video", mp_property_video, CONF_TYPE_INT, | |
1376 CONF_RANGE, -2, MAX_V_STREAMS - 1, NULL }, | |
1377 { "switch_program", mp_property_program, CONF_TYPE_INT, | |
1378 CONF_RANGE, -1, 65535, NULL }, | |
1379 | |
1380 // Subs | |
1381 { "sub", mp_property_sub, CONF_TYPE_INT, | |
1382 M_OPT_MIN, -1, 0, NULL }, | |
1383 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT, | |
1384 0, 0, 0, NULL }, | |
1385 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT, | |
1386 M_OPT_RANGE, 0, 100, NULL }, | |
1387 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT, | |
1388 M_OPT_RANGE, 0, 2, NULL }, | |
1389 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG, | |
1390 M_OPT_RANGE, 0, 1, NULL }, | |
1391 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG, | |
1392 M_OPT_RANGE, 0, 1, NULL }, | |
1393 | |
1394 #ifdef USE_TV | |
1395 { "tv_brightness", mp_property_tv_color, CONF_TYPE_INT, | |
1396 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_BRIGHTNESS }, | |
1397 { "tv_contrast", mp_property_tv_color, CONF_TYPE_INT, | |
1398 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_CONTRAST }, | |
1399 { "tv_saturation", mp_property_tv_color, CONF_TYPE_INT, | |
1400 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_SATURATION }, | |
1401 { "tv_hue", mp_property_tv_color, CONF_TYPE_INT, | |
1402 M_OPT_RANGE, -100, 100, (void *) TV_COLOR_HUE }, | |
1403 #endif | |
1404 | |
1405 { NULL, NULL, NULL, 0, 0, 0, NULL } | |
1406 }; | |
1407 | |
1408 | |
1409 m_option_t *mp_property_find(const char *name) | |
1410 { | |
1411 return m_option_list_find(mp_properties, name); | |
1412 } | |
1413 | |
1414 int mp_property_do(const char *name, int action, void *val, void *ctx) | |
1415 { | |
1416 m_option_t *p = mp_property_find(name); | |
1417 if (!p) | |
1418 return M_PROPERTY_UNAVAILABLE; | |
1419 return m_property_do(p, action, val, ctx); | |
1420 } | |
1421 | |
1422 char *property_expand_string(MPContext * mpctx, char *str) | |
1423 { | |
1424 return m_properties_expand_string(mp_properties, str, mpctx); | |
1425 } | |
1426 | |
1427 void property_print_help(void) | |
1428 { | |
1429 m_properties_print_help_list(mp_properties); | |
1430 } | |
1431 | |
1432 | |
1433 ///@} | |
1434 // Properties group | |
1435 | |
1436 | |
1437 /** | |
1438 * \defgroup Command2Property Command to property bridge | |
1439 * | |
1440 * It is used to handle most commands that just set a property | |
1441 * and optionally display something on the OSD. | |
1442 * Two kinds of commands are handled: adjust or toggle. | |
1443 * | |
1444 * Adjust commands take 1 or 2 parameters: <value> <abs> | |
1445 * If <abs> is non-zero the property is set to the given value | |
1446 * otherwise it is adjusted. | |
1447 * | |
1448 * Toggle commands take 0 or 1 parameters. With no parameter | |
1449 * or a value less than the property minimum it just steps the | |
1450 * property to its next value. Otherwise it sets it to the given | |
1451 * value. | |
1452 * | |
1453 *@{ | |
1454 */ | |
1455 | |
1456 /// List of the commands that can be handled by setting a property. | |
1457 static struct { | |
1458 /// property name | |
1459 const char *name; | |
1460 /// cmd id | |
1461 int cmd; | |
1462 /// set/adjust or toggle command | |
1463 int toggle; | |
1464 /// progressbar type | |
1465 int osd_progbar; | |
1466 /// osd msg id if it must be shared | |
1467 int osd_id; | |
1468 /// osd msg template | |
1469 const char *osd_msg; | |
1470 } set_prop_cmd[] = { | |
1471 // audio | |
1472 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume }, | |
1473 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus }, | |
1474 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus }, | |
1475 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio }, | |
1476 // video | |
1477 { "fullscreen", MP_CMD_VO_FULLSCREEN, 1, 0, -1, NULL }, | |
1478 { "panscan", MP_CMD_PANSCAN, 0, OSD_PANSCAN, -1, MSGTR_Panscan }, | |
1479 { "ontop", MP_CMD_VO_ONTOP, 1, 0, -1, MSGTR_OnTopStatus }, | |
1480 { "rootwin", MP_CMD_VO_ROOTWIN, 1, 0, -1, MSGTR_RootwinStatus }, | |
1481 { "border", MP_CMD_VO_BORDER, 1, 0, -1, MSGTR_BorderStatus }, | |
1482 { "framedropping", MP_CMD_FRAMEDROPPING, 1, 0, -1, MSGTR_FramedroppingStatus }, | |
1483 { "gamma", MP_CMD_GAMMA, 0, OSD_BRIGHTNESS, -1, MSGTR_Gamma }, | |
1484 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness }, | |
1485 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast }, | |
1486 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation }, | |
1487 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue }, | |
1488 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus }, | |
1489 // subs | |
1490 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus }, | |
1491 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus }, | |
1492 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus }, | |
1493 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus }, | |
1494 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus }, | |
1495 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus }, | |
1496 #ifdef USE_TV | |
1497 { "tv_brightness", MP_CMD_TV_SET_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness }, | |
1498 { "tv_hue", MP_CMD_TV_SET_HUE, 0, OSD_HUE, -1, MSGTR_Hue }, | |
1499 { "tv_saturation", MP_CMD_TV_SET_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation }, | |
1500 { "tv_contrast", MP_CMD_TV_SET_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast }, | |
1501 #endif | |
1502 { NULL, 0, 0, 0, -1, NULL } | |
1503 }; | |
1504 | |
1505 | |
1506 /// Handle commands that set a property. | |
1507 static int set_property_command(MPContext * mpctx, mp_cmd_t * cmd) | |
1508 { | |
1509 int i, r; | |
1510 m_option_t *prop; | |
1511 | |
1512 // look for the command | |
1513 for (i = 0; set_prop_cmd[i].name; i++) | |
1514 if (set_prop_cmd[i].cmd == cmd->id) | |
1515 break; | |
1516 if (!set_prop_cmd[i].name) | |
1517 return 0; | |
1518 | |
1519 // get the property | |
1520 prop = mp_property_find(set_prop_cmd[i].name); | |
1521 if (!prop) | |
1522 return 0; | |
1523 | |
1524 // toggle command | |
1525 if (set_prop_cmd[i].toggle) { | |
1526 // set to value | |
1527 if (cmd->nargs > 0 && cmd->args[0].v.i >= prop->min) | |
1528 r = m_property_do(prop, M_PROPERTY_SET, &cmd->args[0].v.i, mpctx); | |
1529 else | |
1530 r = m_property_do(prop, M_PROPERTY_STEP_UP, NULL, mpctx); | |
1531 } else if (cmd->args[1].v.i) //set | |
1532 r = m_property_do(prop, M_PROPERTY_SET, &cmd->args[0].v, mpctx); | |
1533 else // adjust | |
1534 r = m_property_do(prop, M_PROPERTY_STEP_UP, &cmd->args[0].v, mpctx); | |
1535 | |
1536 if (r <= 0) | |
1537 return 1; | |
1538 | |
1539 if (set_prop_cmd[i].osd_progbar) { | |
1540 if (prop->type == CONF_TYPE_INT) { | |
1541 if (m_property_do(prop, M_PROPERTY_GET, &r, mpctx) > 0) | |
1542 set_osd_bar(set_prop_cmd[i].osd_progbar, | |
1543 set_prop_cmd[i].osd_msg, prop->min, prop->max, r); | |
1544 } else if (prop->type == CONF_TYPE_FLOAT) { | |
1545 float f; | |
1546 if (m_property_do(prop, M_PROPERTY_GET, &f, mpctx) > 0) | |
1547 set_osd_bar(set_prop_cmd[i].osd_progbar, | |
1548 set_prop_cmd[i].osd_msg, prop->min, prop->max, f); | |
1549 } else | |
1550 mp_msg(MSGT_CPLAYER, MSGL_ERR, | |
1551 "Property use an unsupported type.\n"); | |
1552 return 1; | |
1553 } | |
1554 | |
1555 if (set_prop_cmd[i].osd_msg) { | |
1556 char *val = m_property_print(prop, mpctx); | |
1557 if (val) { | |
1558 set_osd_msg(set_prop_cmd[i].osd_id >= | |
1559 0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i, | |
1560 1, osd_duration, set_prop_cmd[i].osd_msg, val); | |
1561 free(val); | |
1562 } | |
1563 } | |
1564 return 1; | |
1565 } | |
1566 | |
1567 | |
1568 int run_command(MPContext * mpctx, mp_cmd_t * cmd) | |
1569 { | |
1570 sh_audio_t * const sh_audio = mpctx->sh_audio; | |
1571 sh_video_t * const sh_video = mpctx->sh_video; | |
1572 int brk_cmd = 0; | |
1573 if (!set_property_command(mpctx, cmd)) | |
1574 switch (cmd->id) { | |
1575 case MP_CMD_SEEK:{ | |
1576 float v; | |
1577 int abs; | |
1578 if (sh_video) | |
1579 mpctx->osd_show_percentage = sh_video->fps; | |
1580 v = cmd->args[0].v.f; | |
1581 abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0; | |
1582 if (abs == 2) { /* Absolute seek to a specific timestamp in seconds */ | |
1583 abs_seek_pos = 1; | |
1584 if (sh_video) | |
1585 mpctx->osd_function = | |
1586 (v > sh_video->pts) ? OSD_FFW : OSD_REW; | |
1587 rel_seek_secs = v; | |
1588 } else if (abs) { /* Absolute seek by percentage */ | |
1589 abs_seek_pos = 3; | |
1590 if (sh_video) | |
1591 mpctx->osd_function = OSD_FFW; // Direction isn't set correctly | |
1592 rel_seek_secs = v / 100.0; | |
1593 } else { | |
1594 rel_seek_secs += v; | |
1595 mpctx->osd_function = (v > 0) ? OSD_FFW : OSD_REW; | |
1596 } | |
1597 brk_cmd = 1; | |
1598 } | |
1599 break; | |
1600 | |
1601 case MP_CMD_SET_PROPERTY:{ | |
1602 m_option_t *prop = mp_property_find(cmd->args[0].v.s); | |
1603 if (!prop) | |
1604 mp_msg(MSGT_CPLAYER, MSGL_WARN, | |
1605 "Unknown property: '%s'\n", cmd->args[0].v.s); | |
1606 else if (m_property_parse(prop, cmd->args[1].v.s, mpctx) <= 0) | |
1607 mp_msg(MSGT_CPLAYER, MSGL_WARN, | |
1608 "Failed to set property '%s' to '%s'.\n", | |
1609 cmd->args[0].v.s, cmd->args[1].v.s); | |
1610 } | |
1611 break; | |
1612 | |
1613 case MP_CMD_STEP_PROPERTY:{ | |
1614 m_option_t *prop = mp_property_find(cmd->args[0].v.s); | |
1615 float arg = cmd->args[1].v.f; | |
1616 if (!prop) | |
1617 mp_msg(MSGT_CPLAYER, MSGL_WARN, | |
1618 "Unknown property: '%s'\n", cmd->args[0].v.s); | |
1619 else if (m_property_do | |
1620 (prop, M_PROPERTY_STEP_UP, | |
1621 arg ? &arg : NULL, mpctx) <= 0) | |
1622 mp_msg(MSGT_CPLAYER, MSGL_WARN, | |
1623 "Failed to increment property '%s' by %f.\n", | |
1624 cmd->args[0].v.s, arg); | |
1625 } | |
1626 break; | |
1627 | |
1628 case MP_CMD_GET_PROPERTY:{ | |
1629 m_option_t *prop; | |
1630 void *val; | |
1631 prop = mp_property_find(cmd->args[0].v.s); | |
1632 if (!prop) { | |
1633 mp_msg(MSGT_CPLAYER, MSGL_WARN, | |
1634 "Unknown property: '%s'\n", cmd->args[0].v.s); | |
1635 break; | |
1636 } | |
1637 /* Use m_option_print directly to get easily parseable values. */ | |
1638 val = calloc(1, prop->type->size); | |
1639 if (m_property_do(prop, M_PROPERTY_GET, val, mpctx) <= 0) { | |
1640 mp_msg(MSGT_CPLAYER, MSGL_WARN, | |
1641 "Failed to get value of property '%s'.\n", | |
1642 cmd->args[0].v.s); | |
1643 break; | |
1644 } | |
1645 char *tmp = m_option_print(prop, val); | |
1646 if (!tmp || tmp == (char *) -1) { | |
1647 mp_msg(MSGT_CPLAYER, MSGL_WARN, | |
1648 "Failed to print value of property '%s'.\n", | |
1649 cmd->args[0].v.s); | |
1650 break; | |
1651 } | |
1652 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n", | |
1653 cmd->args[0].v.s, tmp); | |
1654 free(tmp); | |
1655 } | |
1656 break; | |
1657 | |
1658 case MP_CMD_EDL_MARK: | |
1659 if (edl_fd) { | |
1660 float v = sh_video ? sh_video->pts : | |
1661 playing_audio_pts(sh_audio, mpctx->d_audio, | |
1662 mpctx->audio_out); | |
1663 | |
1664 if (mpctx->begin_skip == MP_NOPTS_VALUE) { | |
1665 mpctx->begin_skip = v; | |
1666 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutStartSkip); | |
1667 } else { | |
1668 if (mpctx->begin_skip > v) | |
1669 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdloutBadStop); | |
1670 else { | |
1671 fprintf(edl_fd, "%f %f %d\n", mpctx->begin_skip, v, 0); | |
1672 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdloutEndSkip); | |
1673 } | |
1674 mpctx->begin_skip = MP_NOPTS_VALUE; | |
1675 } | |
1676 } | |
1677 break; | |
1678 | |
1679 case MP_CMD_SWITCH_RATIO: | |
1680 if (cmd->nargs == 0 || cmd->args[0].v.f == -1) | |
1681 movie_aspect = (float) sh_video->disp_w / sh_video->disp_h; | |
1682 else | |
1683 movie_aspect = cmd->args[0].v.f; | |
1684 mpcodecs_config_vo(sh_video, sh_video->disp_w, sh_video->disp_h, 0); | |
1685 break; | |
1686 | |
1687 case MP_CMD_SPEED_INCR:{ | |
1688 float v = cmd->args[0].v.f; | |
1689 playback_speed += v; | |
1690 build_afilter_chain(sh_audio, &ao_data); | |
1691 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed, | |
1692 playback_speed); | |
1693 } break; | |
1694 | |
1695 case MP_CMD_SPEED_MULT:{ | |
1696 float v = cmd->args[0].v.f; | |
1697 playback_speed *= v; | |
1698 build_afilter_chain(sh_audio, &ao_data); | |
1699 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed, | |
1700 playback_speed); | |
1701 } break; | |
1702 | |
1703 case MP_CMD_SPEED_SET:{ | |
1704 float v = cmd->args[0].v.f; | |
1705 playback_speed = v; | |
1706 build_afilter_chain(sh_audio, &ao_data); | |
1707 set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDSpeed, | |
1708 playback_speed); | |
1709 } break; | |
1710 | |
1711 case MP_CMD_FRAME_STEP: | |
1712 case MP_CMD_PAUSE: | |
1713 cmd->pausing = 1; | |
1714 brk_cmd = 1; | |
1715 break; | |
1716 | |
1717 case MP_CMD_FILE_FILTER: | |
1718 file_filter = cmd->args[0].v.i; | |
1719 break; | |
1720 | |
1721 case MP_CMD_QUIT: | |
1722 exit_player_with_rc(MSGTR_Exit_quit, | |
1723 (cmd->nargs > 0) ? cmd->args[0].v.i : 0); | |
1724 | |
1725 case MP_CMD_PLAY_TREE_STEP:{ | |
1726 int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i; | |
1727 int force = cmd->args[1].v.i; | |
1728 | |
1729 #ifdef HAVE_NEW_GUI | |
1730 if (use_gui) { | |
1731 int i = 0; | |
1732 if (n > 0) | |
1733 for (i = 0; i < n; i++) | |
1734 mplNext(); | |
1735 else | |
1736 for (i = 0; i < -1 * n; i++) | |
1737 mplPrev(); | |
1738 } else | |
1739 #endif | |
1740 { | |
1741 if (!force && mpctx->playtree_iter) { | |
1742 play_tree_iter_t *i = | |
1743 play_tree_iter_new_copy(mpctx->playtree_iter); | |
1744 if (play_tree_iter_step(i, n, 0) == | |
1745 PLAY_TREE_ITER_ENTRY) | |
1746 mpctx->eof = | |
1747 (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY; | |
1748 play_tree_iter_free(i); | |
1749 } else | |
1750 mpctx->eof = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY; | |
1751 if (mpctx->eof) | |
1752 mpctx->play_tree_step = n; | |
1753 brk_cmd = 1; | |
1754 } | |
1755 } | |
1756 break; | |
1757 | |
1758 case MP_CMD_PLAY_TREE_UP_STEP:{ | |
1759 int n = cmd->args[0].v.i > 0 ? 1 : -1; | |
1760 int force = cmd->args[1].v.i; | |
1761 | |
1762 if (!force && mpctx->playtree_iter) { | |
1763 play_tree_iter_t *i = | |
1764 play_tree_iter_new_copy(mpctx->playtree_iter); | |
1765 if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY) | |
1766 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV; | |
1767 play_tree_iter_free(i); | |
1768 } else | |
1769 mpctx->eof = (n > 0) ? PT_UP_NEXT : PT_UP_PREV; | |
1770 brk_cmd = 1; | |
1771 } | |
1772 break; | |
1773 | |
1774 case MP_CMD_PLAY_ALT_SRC_STEP: | |
1775 if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) { | |
1776 int v = cmd->args[0].v.i; | |
1777 if (v > 0 | |
1778 && mpctx->playtree_iter->file < | |
1779 mpctx->playtree_iter->num_files) | |
1780 mpctx->eof = PT_NEXT_SRC; | |
1781 else if (v < 0 && mpctx->playtree_iter->file > 1) | |
1782 mpctx->eof = PT_PREV_SRC; | |
1783 } | |
1784 brk_cmd = 1; | |
1785 break; | |
1786 | |
1787 case MP_CMD_SUB_STEP: | |
1788 if (sh_video) { | |
1789 int movement = cmd->args[0].v.i; | |
1790 step_sub(subdata, sh_video->pts, movement); | |
1791 #ifdef USE_ASS | |
1792 if (ass_track) | |
1793 sub_delay += | |
1794 ass_step_sub(ass_track, | |
1795 (sh_video->pts + | |
1796 sub_delay) * 1000 + .5, movement) / 1000.; | |
1797 #endif | |
1798 set_osd_msg(OSD_MSG_SUB_DELAY, 1, osd_duration, | |
1799 MSGTR_OSDSubDelay, ROUND(sub_delay * 1000)); | |
1800 } | |
1801 break; | |
1802 | |
1803 case MP_CMD_SUB_LOG: | |
1804 log_sub(); | |
1805 break; | |
1806 | |
1807 case MP_CMD_OSD:{ | |
1808 int v = cmd->args[0].v.i; | |
1809 int max = (term_osd | |
1810 && !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL; | |
1811 if (osd_level > max) | |
1812 osd_level = max; | |
1813 if (v < 0) | |
1814 osd_level = (osd_level + 1) % (max + 1); | |
1815 else | |
1816 osd_level = v > max ? max : v; | |
1817 /* Show OSD state when disabled, but not when an explicit | |
1818 argument is given to the OSD command, i.e. in slave mode. */ | |
1819 if (v == -1 && osd_level <= 1) | |
1820 set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration, | |
1821 MSGTR_OSDosd, | |
1822 osd_level ? MSGTR_OSDenabled : | |
1823 MSGTR_OSDdisabled); | |
1824 else | |
1825 rm_osd_msg(OSD_MSG_OSD_STATUS); | |
1826 } | |
1827 break; | |
1828 | |
1829 case MP_CMD_OSD_SHOW_TEXT: | |
1830 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i, | |
1831 (cmd->args[1].v.i < | |
1832 0 ? osd_duration : cmd->args[1].v.i), | |
1833 "%-.63s", cmd->args[0].v.s); | |
1834 break; | |
1835 | |
1836 case MP_CMD_OSD_SHOW_PROPERTY_TEXT:{ | |
1837 char *txt = m_properties_expand_string(mp_properties, | |
1838 cmd->args[0].v.s, | |
1839 mpctx); | |
1840 /* if no argument supplied take default osd_duration, else <arg> ms. */ | |
1841 if (txt) { | |
1842 set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i, | |
1843 (cmd->args[1].v.i < | |
1844 0 ? osd_duration : cmd->args[1].v.i), | |
1845 "%-.63s", txt); | |
1846 free(txt); | |
1847 } | |
1848 } | |
1849 break; | |
1850 | |
1851 case MP_CMD_LOADFILE:{ | |
1852 play_tree_t *e = play_tree_new(); | |
1853 play_tree_add_file(e, cmd->args[0].v.s); | |
1854 | |
1855 if (cmd->args[1].v.i) // append | |
1856 play_tree_append_entry(mpctx->playtree, e); | |
1857 else { | |
1858 // Go back to the starting point. | |
1859 while (play_tree_iter_up_step | |
1860 (mpctx->playtree_iter, 0, 1) != PLAY_TREE_ITER_END) | |
1861 /* NOP */ ; | |
1862 play_tree_free_list(mpctx->playtree->child, 1); | |
1863 play_tree_set_child(mpctx->playtree, e); | |
1864 play_tree_iter_step(mpctx->playtree_iter, 0, 0); | |
1865 mpctx->eof = PT_NEXT_SRC; | |
1866 } | |
1867 brk_cmd = 1; | |
1868 } | |
1869 break; | |
1870 | |
1871 case MP_CMD_LOADLIST:{ | |
1872 play_tree_t *e = parse_playlist_file(cmd->args[0].v.s); | |
1873 if (!e) | |
1874 mp_msg(MSGT_CPLAYER, MSGL_ERR, | |
1875 MSGTR_PlaylistLoadUnable, cmd->args[0].v.s); | |
1876 else { | |
1877 if (cmd->args[1].v.i) // append | |
1878 play_tree_append_entry(mpctx->playtree, e); | |
1879 else { | |
1880 // Go back to the starting point. | |
1881 while (play_tree_iter_up_step | |
1882 (mpctx->playtree_iter, 0, 1) | |
1883 != PLAY_TREE_ITER_END) | |
1884 /* NOP */ ; | |
1885 play_tree_free_list(mpctx->playtree->child, 1); | |
1886 play_tree_set_child(mpctx->playtree, e); | |
1887 play_tree_iter_step(mpctx->playtree_iter, 0, 0); | |
1888 mpctx->eof = PT_NEXT_SRC; | |
1889 } | |
1890 } | |
1891 brk_cmd = 1; | |
1892 } | |
1893 break; | |
1894 | |
1895 #ifdef USE_RADIO | |
1896 case MP_CMD_RADIO_STEP_CHANNEL: | |
1897 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) { | |
1898 int v = cmd->args[0].v.i; | |
1899 if (v > 0) | |
1900 radio_step_channel(mpctx->demuxer->stream, | |
1901 RADIO_CHANNEL_HIGHER); | |
1902 else | |
1903 radio_step_channel(mpctx->demuxer->stream, | |
1904 RADIO_CHANNEL_LOWER); | |
1905 if (radio_get_channel_name(mpctx->demuxer->stream)) { | |
1906 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration, | |
1907 MSGTR_OSDChannel, | |
1908 radio_get_channel_name(mpctx->demuxer->stream)); | |
1909 } | |
1910 } | |
1911 break; | |
1912 | |
1913 case MP_CMD_RADIO_SET_CHANNEL: | |
1914 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) { | |
1915 radio_set_channel(mpctx->demuxer->stream, cmd->args[0].v.s); | |
1916 if (radio_get_channel_name(mpctx->demuxer->stream)) { | |
1917 set_osd_msg(OSD_MSG_RADIO_CHANNEL, 1, osd_duration, | |
1918 MSGTR_OSDChannel, | |
1919 radio_get_channel_name(mpctx->demuxer->stream)); | |
1920 } | |
1921 } | |
1922 break; | |
1923 | |
1924 case MP_CMD_RADIO_SET_FREQ: | |
1925 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) | |
1926 radio_set_freq(mpctx->demuxer->stream, cmd->args[0].v.f); | |
1927 break; | |
1928 | |
1929 case MP_CMD_RADIO_STEP_FREQ: | |
1930 if (mpctx->demuxer->stream->type == STREAMTYPE_RADIO) | |
1931 radio_step_freq(mpctx->demuxer->stream, cmd->args[0].v.f); | |
1932 break; | |
1933 #endif | |
1934 | |
1935 #ifdef USE_TV | |
1936 case MP_CMD_TV_SET_FREQ: | |
1937 if (mpctx->file_format == DEMUXER_TYPE_TV) | |
1938 tv_set_freq((tvi_handle_t *) (mpctx->demuxer->priv), | |
1939 cmd->args[0].v.f * 16.0); | |
1940 break; | |
1941 | |
1942 case MP_CMD_TV_SET_NORM: | |
1943 if (mpctx->file_format == DEMUXER_TYPE_TV) | |
1944 tv_set_norm((tvi_handle_t *) (mpctx->demuxer->priv), | |
1945 cmd->args[0].v.s); | |
1946 break; | |
1947 | |
1948 case MP_CMD_TV_STEP_CHANNEL:{ | |
1949 if (mpctx->file_format == DEMUXER_TYPE_TV) { | |
1950 int v = cmd->args[0].v.i; | |
1951 if (v > 0) { | |
1952 tv_step_channel((tvi_handle_t *) (mpctx-> | |
1953 demuxer->priv), | |
1954 TV_CHANNEL_HIGHER); | |
1955 } else { | |
1956 tv_step_channel((tvi_handle_t *) (mpctx-> | |
1957 demuxer->priv), | |
1958 TV_CHANNEL_LOWER); | |
1959 } | |
1960 if (tv_channel_list) { | |
1961 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, | |
1962 MSGTR_OSDChannel, tv_channel_current->name); | |
1963 //vo_osd_changed(OSDTYPE_SUBTITLE); | |
1964 } | |
1965 } | |
1966 } | |
1967 #ifdef HAS_DVBIN_SUPPORT | |
1968 if ((mpctx->stream->type == STREAMTYPE_DVB) | |
1969 && mpctx->stream->priv) { | |
1970 dvb_priv_t *priv = (dvb_priv_t *) mpctx->stream->priv; | |
1971 if (priv->is_on) { | |
1972 int dir; | |
1973 int v = cmd->args[0].v.i; | |
1974 | |
1975 mpctx->last_dvb_step = v; | |
1976 if (v > 0) | |
1977 dir = DVB_CHANNEL_HIGHER; | |
1978 else | |
1979 dir = DVB_CHANNEL_LOWER; | |
1980 | |
1981 | |
1982 if (dvb_step_channel(priv, dir)) | |
1983 mpctx->eof = mpctx->dvbin_reopen = 1; | |
1984 } | |
1985 } | |
1986 #endif /* HAS_DVBIN_SUPPORT */ | |
1987 break; | |
1988 | |
1989 case MP_CMD_TV_SET_CHANNEL: | |
1990 if (mpctx->file_format == DEMUXER_TYPE_TV) { | |
1991 tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv), | |
1992 cmd->args[0].v.s); | |
1993 if (tv_channel_list) { | |
1994 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, | |
1995 MSGTR_OSDChannel, tv_channel_current->name); | |
1996 //vo_osd_changed(OSDTYPE_SUBTITLE); | |
1997 } | |
1998 } | |
1999 break; | |
2000 | |
2001 #ifdef HAS_DVBIN_SUPPORT | |
2002 case MP_CMD_DVB_SET_CHANNEL: | |
2003 if ((mpctx->stream->type == STREAMTYPE_DVB) | |
2004 && mpctx->stream->priv) { | |
2005 dvb_priv_t *priv = (dvb_priv_t *) mpctx->stream->priv; | |
2006 if (priv->is_on) { | |
2007 if (priv->list->current <= cmd->args[0].v.i) | |
2008 mpctx->last_dvb_step = 1; | |
2009 else | |
2010 mpctx->last_dvb_step = -1; | |
2011 | |
2012 if (dvb_set_channel | |
2013 (priv, cmd->args[1].v.i, cmd->args[0].v.i)) | |
2014 mpctx->eof = mpctx->dvbin_reopen = 1; | |
2015 } | |
2016 } | |
2017 break; | |
2018 #endif /* HAS_DVBIN_SUPPORT */ | |
2019 | |
2020 case MP_CMD_TV_LAST_CHANNEL: | |
2021 if (mpctx->file_format == DEMUXER_TYPE_TV) { | |
2022 tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv)); | |
2023 if (tv_channel_list) { | |
2024 set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, | |
2025 MSGTR_OSDChannel, tv_channel_current->name); | |
2026 //vo_osd_changed(OSDTYPE_SUBTITLE); | |
2027 } | |
2028 } | |
2029 break; | |
2030 | |
2031 case MP_CMD_TV_STEP_NORM: | |
2032 if (mpctx->file_format == DEMUXER_TYPE_TV) | |
2033 tv_step_norm((tvi_handle_t *) (mpctx->demuxer->priv)); | |
2034 break; | |
2035 | |
2036 case MP_CMD_TV_STEP_CHANNEL_LIST: | |
2037 if (mpctx->file_format == DEMUXER_TYPE_TV) | |
2038 tv_step_chanlist((tvi_handle_t *) (mpctx->demuxer->priv)); | |
2039 break; | |
2040 #endif /* USE_TV */ | |
2041 | |
2042 case MP_CMD_SUB_LOAD: | |
2043 if (sh_video) { | |
2044 int n = mpctx->set_of_sub_size; | |
2045 add_subtitles(cmd->args[0].v.s, sh_video->fps, 0); | |
2046 if (n != mpctx->set_of_sub_size) { | |
2047 if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] < 0) | |
2048 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = | |
2049 mpctx->global_sub_size; | |
2050 ++mpctx->global_sub_size; | |
2051 } | |
2052 } | |
2053 break; | |
2054 | |
2055 case MP_CMD_SUB_REMOVE: | |
2056 if (sh_video) { | |
2057 int v = cmd->args[0].v.i; | |
2058 sub_data *subd; | |
2059 if (v < 0) { | |
2060 for (v = 0; v < mpctx->set_of_sub_size; ++v) { | |
2061 subd = mpctx->set_of_subtitles[v]; | |
2062 mp_msg(MSGT_CPLAYER, MSGL_STATUS, | |
2063 MSGTR_RemovedSubtitleFile, v + 1, | |
2064 filename_recode(subd->filename)); | |
2065 sub_free(subd); | |
2066 mpctx->set_of_subtitles[v] = NULL; | |
2067 } | |
2068 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1; | |
2069 mpctx->global_sub_size -= mpctx->set_of_sub_size; | |
2070 mpctx->set_of_sub_size = 0; | |
2071 if (mpctx->set_of_sub_pos >= 0) { | |
2072 mpctx->global_sub_pos = -2; | |
2073 vo_sub_last = vo_sub = NULL; | |
2074 vo_osd_changed(OSDTYPE_SUBTITLE); | |
2075 vo_update_osd(sh_video->disp_w, sh_video->disp_h); | |
2076 mp_input_queue_cmd(mp_input_parse_cmd("sub_select")); | |
2077 } | |
2078 } else if (v < mpctx->set_of_sub_size) { | |
2079 subd = mpctx->set_of_subtitles[v]; | |
2080 mp_msg(MSGT_CPLAYER, MSGL_STATUS, | |
2081 MSGTR_RemovedSubtitleFile, v + 1, | |
2082 filename_recode(subd->filename)); | |
2083 sub_free(subd); | |
2084 if (mpctx->set_of_sub_pos == v) { | |
2085 mpctx->global_sub_pos = -2; | |
2086 vo_sub_last = vo_sub = NULL; | |
2087 vo_osd_changed(OSDTYPE_SUBTITLE); | |
2088 vo_update_osd(sh_video->disp_w, sh_video->disp_h); | |
2089 mp_input_queue_cmd(mp_input_parse_cmd("sub_select")); | |
2090 } else if (mpctx->set_of_sub_pos > v) { | |
2091 --mpctx->set_of_sub_pos; | |
2092 --mpctx->global_sub_pos; | |
2093 } | |
2094 while (++v < mpctx->set_of_sub_size) | |
2095 mpctx->set_of_subtitles[v - 1] = | |
2096 mpctx->set_of_subtitles[v]; | |
2097 --mpctx->set_of_sub_size; | |
2098 --mpctx->global_sub_size; | |
2099 if (mpctx->set_of_sub_size <= 0) | |
2100 mpctx->global_sub_indices[SUB_SOURCE_SUBS] = -1; | |
2101 mpctx->set_of_subtitles[mpctx->set_of_sub_size] = NULL; | |
2102 } | |
2103 } | |
2104 break; | |
2105 | |
2106 case MP_CMD_GET_SUB_VISIBILITY: | |
2107 if (sh_video) { | |
2108 mp_msg(MSGT_GLOBAL, MSGL_INFO, | |
2109 "ANS_SUB_VISIBILITY=%d\n", sub_visibility); | |
2110 } | |
2111 break; | |
2112 | |
2113 case MP_CMD_SCREENSHOT: | |
2114 if (vo_config_count) { | |
2115 mp_msg(MSGT_CPLAYER, MSGL_INFO, "sending VFCTRL_SCREENSHOT!\n"); | |
2116 if (CONTROL_OK != | |
2117 ((vf_instance_t *) sh_video->vfilter)-> | |
2118 control(sh_video->vfilter, VFCTRL_SCREENSHOT, | |
2119 &cmd->args[0].v.i)) | |
2120 mpctx->video_out->control(VOCTRL_SCREENSHOT, NULL); | |
2121 } | |
2122 break; | |
2123 | |
2124 case MP_CMD_VF_CHANGE_RECTANGLE: | |
2125 set_rectangle(sh_video, cmd->args[0].v.i, cmd->args[1].v.i); | |
2126 break; | |
2127 | |
2128 case MP_CMD_GET_TIME_LENGTH:{ | |
2129 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_LENGTH=%.2lf\n", | |
2130 demuxer_get_time_length(mpctx->demuxer)); | |
2131 } | |
2132 break; | |
2133 | |
2134 case MP_CMD_GET_FILENAME:{ | |
2135 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_FILENAME='%s'\n", | |
2136 get_metadata(META_NAME)); | |
2137 } | |
2138 break; | |
2139 | |
2140 case MP_CMD_GET_VIDEO_CODEC:{ | |
2141 char *inf = get_metadata(META_VIDEO_CODEC); | |
2142 if (!inf) | |
2143 inf = strdup(""); | |
2144 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_CODEC='%s'\n", inf); | |
2145 free(inf); | |
2146 } | |
2147 break; | |
2148 | |
2149 case MP_CMD_GET_VIDEO_BITRATE:{ | |
2150 char *inf = get_metadata(META_VIDEO_BITRATE); | |
2151 if (!inf) | |
2152 inf = strdup(""); | |
2153 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VIDEO_BITRATE='%s'\n", inf); | |
2154 free(inf); | |
2155 } | |
2156 break; | |
2157 | |
2158 case MP_CMD_GET_VIDEO_RESOLUTION:{ | |
2159 char *inf = get_metadata(META_VIDEO_RESOLUTION); | |
2160 if (!inf) | |
2161 inf = strdup(""); | |
2162 mp_msg(MSGT_GLOBAL, MSGL_INFO, | |
2163 "ANS_VIDEO_RESOLUTION='%s'\n", inf); | |
2164 free(inf); | |
2165 } | |
2166 break; | |
2167 | |
2168 case MP_CMD_GET_AUDIO_CODEC:{ | |
2169 char *inf = get_metadata(META_AUDIO_CODEC); | |
2170 if (!inf) | |
2171 inf = strdup(""); | |
2172 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_CODEC='%s'\n", inf); | |
2173 free(inf); | |
2174 } | |
2175 break; | |
2176 | |
2177 case MP_CMD_GET_AUDIO_BITRATE:{ | |
2178 char *inf = get_metadata(META_AUDIO_BITRATE); | |
2179 if (!inf) | |
2180 inf = strdup(""); | |
2181 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_BITRATE='%s'\n", inf); | |
2182 free(inf); | |
2183 } | |
2184 break; | |
2185 | |
2186 case MP_CMD_GET_AUDIO_SAMPLES:{ | |
2187 char *inf = get_metadata(META_AUDIO_SAMPLES); | |
2188 if (!inf) | |
2189 inf = strdup(""); | |
2190 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_AUDIO_SAMPLES='%s'\n", inf); | |
2191 free(inf); | |
2192 } | |
2193 break; | |
2194 | |
2195 case MP_CMD_GET_META_TITLE:{ | |
2196 char *inf = get_metadata(META_INFO_TITLE); | |
2197 if (!inf) | |
2198 inf = strdup(""); | |
2199 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TITLE='%s'\n", inf); | |
2200 free(inf); | |
2201 } | |
2202 break; | |
2203 | |
2204 case MP_CMD_GET_META_ARTIST:{ | |
2205 char *inf = get_metadata(META_INFO_ARTIST); | |
2206 if (!inf) | |
2207 inf = strdup(""); | |
2208 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ARTIST='%s'\n", inf); | |
2209 free(inf); | |
2210 } | |
2211 break; | |
2212 | |
2213 case MP_CMD_GET_META_ALBUM:{ | |
2214 char *inf = get_metadata(META_INFO_ALBUM); | |
2215 if (!inf) | |
2216 inf = strdup(""); | |
2217 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_ALBUM='%s'\n", inf); | |
2218 free(inf); | |
2219 } | |
2220 break; | |
2221 | |
2222 case MP_CMD_GET_META_YEAR:{ | |
2223 char *inf = get_metadata(META_INFO_YEAR); | |
2224 if (!inf) | |
2225 inf = strdup(""); | |
2226 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_YEAR='%s'\n", inf); | |
2227 free(inf); | |
2228 } | |
2229 break; | |
2230 | |
2231 case MP_CMD_GET_META_COMMENT:{ | |
2232 char *inf = get_metadata(META_INFO_COMMENT); | |
2233 if (!inf) | |
2234 inf = strdup(""); | |
2235 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_COMMENT='%s'\n", inf); | |
2236 free(inf); | |
2237 } | |
2238 break; | |
2239 | |
2240 case MP_CMD_GET_META_TRACK:{ | |
2241 char *inf = get_metadata(META_INFO_TRACK); | |
2242 if (!inf) | |
2243 inf = strdup(""); | |
2244 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_TRACK='%s'\n", inf); | |
2245 free(inf); | |
2246 } | |
2247 break; | |
2248 | |
2249 case MP_CMD_GET_META_GENRE:{ | |
2250 char *inf = get_metadata(META_INFO_GENRE); | |
2251 if (!inf) | |
2252 inf = strdup(""); | |
2253 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_META_GENRE='%s'\n", inf); | |
2254 free(inf); | |
2255 } | |
2256 break; | |
2257 | |
2258 case MP_CMD_GET_VO_FULLSCREEN: | |
2259 if (mpctx->video_out && vo_config_count) | |
2260 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_VO_FULLSCREEN=%d\n", vo_fs); | |
2261 break; | |
2262 | |
2263 case MP_CMD_GET_PERCENT_POS: | |
2264 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_PERCENT_POSITION=%d\n", | |
2265 demuxer_get_percent_pos(mpctx->demuxer)); | |
2266 break; | |
2267 | |
2268 case MP_CMD_GET_TIME_POS:{ | |
2269 float pos = 0; | |
2270 if (sh_video) | |
2271 pos = sh_video->pts; | |
2272 else if (sh_audio && mpctx->audio_out) | |
2273 pos = | |
2274 playing_audio_pts(sh_audio, mpctx->d_audio, | |
2275 mpctx->audio_out); | |
2276 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_TIME_POSITION=%.1f\n", pos); | |
2277 } | |
2278 break; | |
2279 | |
2280 case MP_CMD_RUN: | |
2281 #ifndef __MINGW32__ | |
2282 if (!fork()) { | |
2283 execl("/bin/sh", "sh", "-c", cmd->args[0].v.s, NULL); | |
2284 exit(0); | |
2285 } | |
2286 #endif | |
2287 break; | |
2288 | |
2289 case MP_CMD_KEYDOWN_EVENTS: | |
2290 mplayer_put_key(cmd->args[0].v.i); | |
2291 break; | |
2292 | |
2293 case MP_CMD_SEEK_CHAPTER:{ | |
2294 int seek = cmd->args[0].v.i; | |
2295 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0; | |
2296 int chap; | |
2297 float next_pts = 0; | |
2298 int num_chapters; | |
2299 char *chapter_name; | |
2300 | |
2301 rel_seek_secs = 0; | |
2302 abs_seek_pos = 0; | |
2303 chap = | |
2304 demuxer_seek_chapter(mpctx->demuxer, seek, abs, | |
2305 &next_pts, &num_chapters, | |
2306 &chapter_name); | |
2307 if (chap != -1) { | |
2308 if (next_pts > -1.0) { | |
2309 abs_seek_pos = 1; | |
2310 rel_seek_secs = next_pts; | |
2311 } | |
2312 if (chapter_name) { | |
2313 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, | |
2314 MSGTR_OSDChapter, chap + 1, chapter_name); | |
2315 free(chapter_name); | |
2316 } | |
2317 } else { | |
2318 if (seek > 0) | |
2319 rel_seek_secs = 1000000000.; | |
2320 else | |
2321 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, | |
2322 MSGTR_OSDChapter, 0, MSGTR_Unknown); | |
2323 } | |
2324 break; | |
2325 } | |
2326 break; | |
2327 | |
2328 case MP_CMD_SET_MOUSE_POS:{ | |
2329 int button = -1, pointer_x, pointer_y; | |
2330 double dx, dy; | |
2331 pointer_x = cmd->args[0].v.i; | |
2332 pointer_y = cmd->args[1].v.i; | |
2333 rescale_input_coordinates(pointer_x, pointer_y, &dx, &dy); | |
2334 #ifdef USE_DVDNAV | |
2335 if (mpctx->stream->type == STREAMTYPE_DVDNAV | |
2336 && dx > 0.0 && dy > 0.0) { | |
2337 pointer_x = (int) (dx * (double) sh_video->disp_w); | |
2338 pointer_y = (int) (dy * (double) sh_video->disp_h); | |
2339 mp_dvdnav_update_mouse_pos(mpctx->stream, | |
2340 pointer_x, pointer_y, &button); | |
2341 if (button > 0) | |
2342 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, | |
2343 "Selected button number %d", button); | |
2344 } | |
2345 #endif | |
2346 } | |
2347 break; | |
2348 | |
2349 #ifdef USE_DVDNAV | |
2350 case MP_CMD_DVDNAV:{ | |
2351 int button = -1; | |
2352 if (mpctx->stream->type != STREAMTYPE_DVDNAV) | |
2353 break; | |
2354 | |
2355 if (mp_dvdnav_handle_input | |
2356 (mpctx->stream, cmd->args[0].v.i, &button)) { | |
2357 uninit_player(INITED_ALL - (INITED_STREAM | INITED_INPUT | | |
2358 (fixed_vo ? INITED_VO : 0))); | |
2359 brk_cmd = 2; | |
2360 } else if (button > 0) | |
2361 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, | |
2362 "Selected button number %d", button); | |
2363 } | |
2364 break; | |
2365 #endif | |
2366 | |
2367 default: | |
2368 #ifdef HAVE_NEW_GUI | |
2369 if ((use_gui) && (cmd->id > MP_CMD_GUI_EVENTS)) | |
2370 guiGetEvent(guiIEvent, (char *) cmd->id); | |
2371 else | |
2372 #endif | |
2373 mp_msg(MSGT_CPLAYER, MSGL_V, | |
2374 "Received unknown cmd %s\n", cmd->name); | |
2375 } | |
2376 | |
2377 switch (cmd->pausing) { | |
2378 case 1: // "pausing" | |
2379 mpctx->osd_function = OSD_PAUSE; | |
2380 break; | |
2381 case 3: // "pausing_toggle" | |
2382 mpctx->was_paused = !mpctx->was_paused; | |
2383 // fall through | |
2384 case 2: // "pausing_keep" | |
2385 if (mpctx->was_paused) | |
2386 mpctx->osd_function = OSD_PAUSE; | |
2387 } | |
2388 return brk_cmd; | |
2389 } |