-
Notifications
You must be signed in to change notification settings - Fork 7
/
command.c
executable file
·2809 lines (2560 loc) · 79.1 KB
/
command.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include "config.h"
#include "input/input.h"
#include "stream/stream.h"
#include "libmpdemux/demuxer.h"
#include "libmpdemux/stheader.h"
#include "codec-cfg.h"
#include "mplayer.h"
#include "libvo/sub.h"
#include "m_option.h"
#include "m_property.h"
#include "help_mp.h"
#include "metadata.h"
#include "libmpcodecs/mp_image.h"
#include "libmpcodecs/vf.h"
#include "libmpcodecs/vd.h"
#include "libvo/video_out.h"
#include "libvo/font_load.h"
#include "playtree.h"
#include "libao2/audio_out.h"
#include "mpcommon.h"
#include "mixer.h"
#include "libmpdemux/matroska.h"
#include "libmpcodecs/dec_video.h"
#include "vobsub.h"
#include "spudec.h"
#include "get_path.h"
#ifdef USE_TV
#include "stream/tv.h"
#endif
#ifdef USE_RADIO
#include "stream/stream_radio.h"
#endif
#ifdef HAVE_PVR
#include "stream/pvr.h"
#endif
#ifdef HAS_DVBIN_SUPPORT
#include "stream/dvbin.h"
#endif
#ifdef USE_DVDREAD
#include "stream/stream_dvd.h"
#endif
#ifdef USE_DVDNAV
#include "stream/stream_dvdnav.h"
#endif
#ifdef USE_ASS
#include "libass/ass.h"
#include "libass/ass_mp.h"
#endif
#ifdef HAVE_NEW_GUI
#include "gui/interface.h"
#endif
#include "mp_core.h"
#include "mp_fifo.h"
#define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy)
{
//remove the borders, if any, and rescale to the range [0,1],[0,1]
if (vo_fs) { //we are in full-screen mode
if (vo_screenwidth > vo_dwidth) //there are borders along the x axis
ix -= (vo_screenwidth - vo_dwidth) / 2;
if (vo_screenheight > vo_dheight) //there are borders along the y axis (usual way)
iy -= (vo_screenheight - vo_dheight) / 2;
if (ix < 0 || ix > vo_dwidth) {
*dx = *dy = -1.0;
return;
} //we are on one of the borders
if (iy < 0 || iy > vo_dheight) {
*dx = *dy = -1.0;
return;
} //we are on one of the borders
}
*dx = (double) ix / (double) vo_dwidth;
*dy = (double) iy / (double) vo_dheight;
mp_msg(MSGT_CPLAYER, MSGL_V,
"\r\nrescaled coordinates: %.3lf, %.3lf, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
*dx, *dy, vo_screenwidth, vo_screenheight, vo_dwidth,
vo_dheight, vo_fs);
}
static int sub_source(MPContext * mpctx)
{
int source = -1;
int top = -1;
int i;
for (i = 0; i < SUB_SOURCES; i++) {
int j = mpctx->global_sub_indices[i];
if ((j >= 0) && (j > top) && (mpctx->global_sub_pos >= j)) {
source = i;
top = j;
}
}
return source;
}
/**
* \brief Log the currently displayed subtitle to a file
*
* Logs the current or last displayed subtitle together with filename
* and time information to ~/.mplayer/subtitle_log
*
* Intended purpose is to allow convenient marking of bogus subtitles
* which need to be fixed while watching the movie.
*/
static void log_sub(void)
{
char *fname;
FILE *f;
int i;
if (subdata == NULL || vo_sub_last == NULL)
return;
fname = get_path("subtitle_log");
f = fopen(fname, "a");
if (!f)
return;
fprintf(f, "----------------------------------------------------------\n");
if (subdata->sub_uses_time) {
fprintf(f,
"N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
filename, vo_sub_last->start / 360000,
(vo_sub_last->start / 6000) % 60,
(vo_sub_last->start / 100) % 60, vo_sub_last->start % 100,
vo_sub_last->end / 360000, (vo_sub_last->end / 6000) % 60,
(vo_sub_last->end / 100) % 60, vo_sub_last->end % 100);
} else {
fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start,
vo_sub_last->end);
}
for (i = 0; i < vo_sub_last->lines; i++) {
fprintf(f, "%s\n", vo_sub_last->text[i]);
}
fclose(f);
}
/// \defgroup Properties
///@{
/// \defgroup GeneralProperties General properties
/// \ingroup Properties
///@{
/// OSD level (RW)
static int mp_property_osdlevel(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
return m_property_choice(prop, action, arg, &osd_level);
}
/// Loop (RW)
static int mp_property_loop(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
switch (action) {
case M_PROPERTY_PRINT:
if (!arg) return M_PROPERTY_ERROR;
if (mpctx->loop_times < 0)
*(char**)arg = strdup("off");
else if (mpctx->loop_times == 0)
*(char**)arg = strdup("inf");
else
break;
return M_PROPERTY_OK;
}
return m_property_int_range(prop, action, arg, &mpctx->loop_times);
}
/// Playback speed (RW)
static int mp_property_playback_speed(m_option_t * prop, int action,
void *arg, MPContext * mpctx)
{
switch (action) {
case M_PROPERTY_SET:
if (!arg)
return M_PROPERTY_ERROR;
M_PROPERTY_CLAMP(prop, *(float *) arg);
playback_speed = *(float *) arg;
build_afilter_chain(mpctx->sh_audio, &ao_data);
return M_PROPERTY_OK;
case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN:
playback_speed += (arg ? *(float *) arg : 0.1) *
(action == M_PROPERTY_STEP_DOWN ? -1 : 1);
M_PROPERTY_CLAMP(prop, playback_speed);
build_afilter_chain(mpctx->sh_audio, &ao_data);
return M_PROPERTY_OK;
}
return m_property_float_range(prop, action, arg, &playback_speed);
}
/// filename with path (RO)
static int mp_property_path(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
return m_property_string_ro(prop, action, arg, filename);
}
/// filename without path (RO)
static int mp_property_filename(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
char *f;
if (!filename)
return M_PROPERTY_UNAVAILABLE;
if (((f = strrchr(filename, '/')) || (f = strrchr(filename, '\\'))) && f[1])
f++;
else
f = filename;
return m_property_string_ro(prop, action, arg, f);
}
/// Demuxer name (RO)
static int mp_property_demuxer(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
if (!mpctx->demuxer)
return M_PROPERTY_UNAVAILABLE;
return m_property_string_ro(prop, action, arg,
(char *) mpctx->demuxer->desc->name);
}
/// Position in the stream (RW)
static int mp_property_stream_pos(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
if (!mpctx->demuxer || !mpctx->demuxer->stream)
return M_PROPERTY_UNAVAILABLE;
if (!arg)
return M_PROPERTY_ERROR;
switch (action) {
case M_PROPERTY_GET:
*(off_t *) arg = stream_tell(mpctx->demuxer->stream);
return M_PROPERTY_OK;
case M_PROPERTY_SET:
M_PROPERTY_CLAMP(prop, *(off_t *) arg);
stream_seek(mpctx->demuxer->stream, *(off_t *) arg);
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
/// Stream start offset (RO)
static int mp_property_stream_start(m_option_t * prop, int action,
void *arg, MPContext * mpctx)
{
if (!mpctx->demuxer || !mpctx->demuxer->stream)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_GET:
*(off_t *) arg = mpctx->demuxer->stream->start_pos;
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
/// Stream end offset (RO)
static int mp_property_stream_end(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
if (!mpctx->demuxer || !mpctx->demuxer->stream)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_GET:
*(off_t *) arg = mpctx->demuxer->stream->end_pos;
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
/// Stream length (RO)
static int mp_property_stream_length(m_option_t * prop, int action,
void *arg, MPContext * mpctx)
{
if (!mpctx->demuxer || !mpctx->demuxer->stream)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_GET:
*(off_t *) arg =
mpctx->demuxer->stream->end_pos - mpctx->demuxer->stream->start_pos;
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
/// Media length in seconds (RO)
static int mp_property_length(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
double len;
if (!mpctx->demuxer ||
!(int) (len = demuxer_get_time_length(mpctx->demuxer)))
return M_PROPERTY_UNAVAILABLE;
return m_property_time_ro(prop, action, arg, len);
}
/// Current position in percent (RW)
static int mp_property_percent_pos(m_option_t * prop, int action,
void *arg, MPContext * mpctx) {
int pos;
if (!mpctx->demuxer)
return M_PROPERTY_UNAVAILABLE;
switch(action) {
case M_PROPERTY_SET:
if(!arg) return M_PROPERTY_ERROR;
M_PROPERTY_CLAMP(prop, *(int*)arg);
pos = *(int*)arg;
break;
case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN:
pos = demuxer_get_percent_pos(mpctx->demuxer);
pos += (arg ? *(int*)arg : 10) *
(action == M_PROPERTY_STEP_UP ? 1 : -1);
M_PROPERTY_CLAMP(prop, pos);
break;
default:
return m_property_int_ro(prop, action, arg,
demuxer_get_percent_pos(mpctx->demuxer));
}
abs_seek_pos = 3;
rel_seek_secs = pos / 100.0;
return M_PROPERTY_OK;
}
/// Current position in seconds (RW)
static int mp_property_time_pos(m_option_t * prop, int action,
void *arg, MPContext * mpctx) {
if (!(mpctx->sh_video || (mpctx->sh_audio && mpctx->audio_out)))
return M_PROPERTY_UNAVAILABLE;
switch(action) {
case M_PROPERTY_SET:
if(!arg) return M_PROPERTY_ERROR;
M_PROPERTY_CLAMP(prop, *(double*)arg);
abs_seek_pos = 1;
rel_seek_secs = *(double*)arg;
return M_PROPERTY_OK;
case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN:
rel_seek_secs += (arg ? *(double*)arg : 10.0) *
(action == M_PROPERTY_STEP_UP ? 1.0 : -1.0);
return M_PROPERTY_OK;
}
return m_property_time_ro(prop, action, arg,
mpctx->sh_video ? mpctx->sh_video->pts :
playing_audio_pts(mpctx->sh_audio,
mpctx->d_audio,
mpctx->audio_out));
}
/// Demuxer meta data
static int mp_property_metadata(m_option_t * prop, int action, void *arg,
MPContext * mpctx) {
m_property_action_t* ka;
char* meta;
static m_option_t key_type =
{ "metadata", NULL, CONF_TYPE_STRING, 0, 0, 0, NULL };
if (!mpctx->demuxer)
return M_PROPERTY_UNAVAILABLE;
switch(action) {
case M_PROPERTY_GET:
if(!arg) return M_PROPERTY_ERROR;
*(char***)arg = mpctx->demuxer->info;
return M_PROPERTY_OK;
case M_PROPERTY_KEY_ACTION:
if(!arg) return M_PROPERTY_ERROR;
ka = arg;
if(!(meta = demux_info_get(mpctx->demuxer,ka->key)))
return M_PROPERTY_UNKNOWN;
switch(ka->action) {
case M_PROPERTY_GET:
if(!ka->arg) return M_PROPERTY_ERROR;
*(char**)ka->arg = meta;
return M_PROPERTY_OK;
case M_PROPERTY_GET_TYPE:
if(!ka->arg) return M_PROPERTY_ERROR;
*(m_option_t**)ka->arg = &key_type;
return M_PROPERTY_OK;
}
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
///@}
/// \defgroup AudioProperties Audio properties
/// \ingroup Properties
///@{
/// Volume (RW)
static int mp_property_volume(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
if (!mpctx->sh_audio)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_GET:
if (!arg)
return M_PROPERTY_ERROR;
mixer_getbothvolume(&mpctx->mixer, arg);
return M_PROPERTY_OK;
case M_PROPERTY_PRINT:{
float vol;
if (!arg)
return M_PROPERTY_ERROR;
mixer_getbothvolume(&mpctx->mixer, &vol);
return m_property_float_range(prop, action, arg, &vol);
}
case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN:
case M_PROPERTY_SET:
break;
default:
return M_PROPERTY_NOT_IMPLEMENTED;
}
if (mpctx->edl_muted)
return M_PROPERTY_DISABLED;
mpctx->user_muted = 0;
switch (action) {
case M_PROPERTY_SET:
if (!arg)
return M_PROPERTY_ERROR;
M_PROPERTY_CLAMP(prop, *(float *) arg);
mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
return M_PROPERTY_OK;
case M_PROPERTY_STEP_UP:
if (arg && *(float *) arg <= 0)
mixer_decvolume(&mpctx->mixer);
else
mixer_incvolume(&mpctx->mixer);
return M_PROPERTY_OK;
case M_PROPERTY_STEP_DOWN:
if (arg && *(float *) arg <= 0)
mixer_incvolume(&mpctx->mixer);
else
mixer_decvolume(&mpctx->mixer);
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
/// Mute (RW)
static int mp_property_mute(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
if (!mpctx->sh_audio)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_SET:
if (mpctx->edl_muted)
return M_PROPERTY_DISABLED;
if (!arg)
return M_PROPERTY_ERROR;
if ((!!*(int *) arg) != mpctx->mixer.muted)
mixer_mute(&mpctx->mixer);
mpctx->user_muted = mpctx->mixer.muted;
return M_PROPERTY_OK;
case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN:
if (mpctx->edl_muted)
return M_PROPERTY_DISABLED;
mixer_mute(&mpctx->mixer);
mpctx->user_muted = mpctx->mixer.muted;
return M_PROPERTY_OK;
case M_PROPERTY_PRINT:
if (!arg)
return M_PROPERTY_ERROR;
if (mpctx->edl_muted) {
*(char **) arg = strdup(MSGTR_EnabledEdl);
return M_PROPERTY_OK;
}
default:
return m_property_flag(prop, action, arg, &mpctx->mixer.muted);
}
}
/// Audio delay (RW)
static int mp_property_audio_delay(m_option_t * prop, int action,
void *arg, MPContext * mpctx)
{
if (!(mpctx->sh_audio && mpctx->sh_video))
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_SET:
case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN:
if (!arg)
return M_PROPERTY_ERROR;
else {
float delay = audio_delay;
m_property_delay(prop, action, arg, &audio_delay);
if (mpctx->sh_audio)
mpctx->delay -= audio_delay - delay;
}
return M_PROPERTY_OK;
default:
return m_property_delay(prop, action, arg, &audio_delay);
}
}
/// Audio codec tag (RO)
static int mp_property_audio_format(m_option_t * prop, int action,
void *arg, MPContext * mpctx)
{
if (!mpctx->sh_audio)
return M_PROPERTY_UNAVAILABLE;
return m_property_int_ro(prop, action, arg, mpctx->sh_audio->format);
}
/// Audio codec name (RO)
static int mp_property_audio_codec(m_option_t * prop, int action,
void *arg, MPContext * mpctx)
{
if (!mpctx->sh_audio || !mpctx->sh_audio->codec)
return M_PROPERTY_UNAVAILABLE;
return m_property_string_ro(prop, action, arg, mpctx->sh_audio->codec->name);
}
/// Audio bitrate (RO)
static int mp_property_audio_bitrate(m_option_t * prop, int action,
void *arg, MPContext * mpctx)
{
if (!mpctx->sh_audio)
return M_PROPERTY_UNAVAILABLE;
return m_property_bitrate(prop, action, arg, mpctx->sh_audio->i_bps);
}
/// Samplerate (RO)
static int mp_property_samplerate(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
if (!mpctx->sh_audio)
return M_PROPERTY_UNAVAILABLE;
switch(action) {
case M_PROPERTY_PRINT:
if(!arg) return M_PROPERTY_ERROR;
*(char**)arg = malloc(16);
sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
return M_PROPERTY_OK;
}
return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
}
/// Number of channels (RO)
static int mp_property_channels(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
if (!mpctx->sh_audio)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_PRINT:
if (!arg)
return M_PROPERTY_ERROR;
switch (mpctx->sh_audio->channels) {
case 1:
*(char **) arg = strdup("mono");
break;
case 2:
*(char **) arg = strdup("stereo");
break;
default:
*(char **) arg = malloc(32);
sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
}
return M_PROPERTY_OK;
}
return m_property_int_ro(prop, action, arg, mpctx->sh_audio->channels);
}
/// Balance (RW)
static int mp_property_balance(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
float bal;
if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_GET:
if (!arg)
return M_PROPERTY_ERROR;
mixer_getbalance(&mpctx->mixer, arg);
return M_PROPERTY_OK;
case M_PROPERTY_PRINT: {
char** str = arg;
if (!arg)
return M_PROPERTY_ERROR;
mixer_getbalance(&mpctx->mixer, &bal);
if (bal == 0.f)
*str = strdup("center");
else if (bal == -1.f)
*str = strdup("left only");
else if (bal == 1.f)
*str = strdup("right only");
else {
unsigned right = (bal + 1.f) / 2.f * 100.f;
*str = malloc(sizeof("left xxx%, right xxx%"));
sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
}
return M_PROPERTY_OK;
}
case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN:
mixer_getbalance(&mpctx->mixer, &bal);
bal += (arg ? *(float*)arg : .1f) *
(action == M_PROPERTY_STEP_UP ? 1.f : -1.f);
M_PROPERTY_CLAMP(prop, bal);
mixer_setbalance(&mpctx->mixer, bal);
return M_PROPERTY_OK;
case M_PROPERTY_SET:
if (!arg)
return M_PROPERTY_ERROR;
M_PROPERTY_CLAMP(prop, *(float*)arg);
mixer_setbalance(&mpctx->mixer, *(float*)arg);
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
/// Selected audio id (RW)
static int mp_property_audio(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
int current_id = -1, tmp;
switch (action) {
case M_PROPERTY_GET:
if (!mpctx->sh_audio)
return M_PROPERTY_UNAVAILABLE;
if (!arg)
return M_PROPERTY_ERROR;
*(int *) arg = audio_id;
return M_PROPERTY_OK;
case M_PROPERTY_PRINT:
if (!mpctx->sh_audio)
return M_PROPERTY_UNAVAILABLE;
if (!arg)
return M_PROPERTY_ERROR;
if (audio_id < 0)
*(char **) arg = strdup(MSGTR_Disabled);
else {
char lang[40] = MSGTR_Unknown;
if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA)
demux_mkv_get_audio_lang(mpctx->demuxer, audio_id, lang, 9);
#ifdef USE_DVDREAD
else if (mpctx->stream->type == STREAMTYPE_DVD) {
int code = dvd_lang_from_aid(mpctx->stream, audio_id);
if (code) {
lang[0] = code >> 8;
lang[1] = code;
lang[2] = 0;
}
}
#endif
#ifdef USE_DVDNAV
else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
dvdnav_lang_from_aid(mpctx->stream, audio_id, lang);
#endif
*(char **) arg = malloc(64);
snprintf(*(char **) arg, 64, "(%d) %s", audio_id, lang);
}
return M_PROPERTY_OK;
case M_PROPERTY_STEP_UP:
case M_PROPERTY_SET:
if (action == M_PROPERTY_SET && arg)
tmp = *((int *) arg);
else
tmp = -1;
current_id = mpctx->demuxer->audio->id;
audio_id = demuxer_switch_audio(mpctx->demuxer, tmp);
if (audio_id == -2
|| (audio_id > -1
&& mpctx->demuxer->audio->id != current_id && current_id != -2))
uninit_player(INITED_AO | INITED_ACODEC);
if (audio_id > -1 && mpctx->demuxer->audio->id != current_id) {
sh_audio_t *sh2;
sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
if (sh2) {
sh2->ds = mpctx->demuxer->audio;
mpctx->sh_audio = sh2;
reinit_audio_chain();
}
}
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", audio_id);
return M_PROPERTY_OK;
default:
return M_PROPERTY_NOT_IMPLEMENTED;
}
}
/// Selected video id (RW)
static int mp_property_video(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
int current_id = -1, tmp;
switch (action) {
case M_PROPERTY_GET:
if (!mpctx->sh_video)
return M_PROPERTY_UNAVAILABLE;
if (!arg)
return M_PROPERTY_ERROR;
*(int *) arg = video_id;
return M_PROPERTY_OK;
case M_PROPERTY_PRINT:
if (!mpctx->sh_video)
return M_PROPERTY_UNAVAILABLE;
if (!arg)
return M_PROPERTY_ERROR;
if (video_id < 0)
*(char **) arg = strdup(MSGTR_Disabled);
else {
char lang[40] = MSGTR_Unknown;
*(char **) arg = malloc(64);
snprintf(*(char **) arg, 64, "(%d) %s", video_id, lang);
}
return M_PROPERTY_OK;
case M_PROPERTY_STEP_UP:
case M_PROPERTY_SET:
current_id = mpctx->demuxer->video->id;
if (action == M_PROPERTY_SET && arg)
tmp = *((int *) arg);
else
tmp = -1;
video_id = demuxer_switch_video(mpctx->demuxer, tmp);
if (video_id == -2
|| (video_id > -1 && mpctx->demuxer->video->id != current_id
&& current_id != -2))
uninit_player(INITED_VCODEC |
(fixed_vo && video_id != -2 ? 0 : INITED_VO));
if (video_id > -1 && mpctx->demuxer->video->id != current_id) {
sh_video_t *sh2;
sh2 = mpctx->demuxer->v_streams[mpctx->demuxer->video->id];
if (sh2) {
sh2->ds = mpctx->demuxer->video;
mpctx->sh_video = sh2;
reinit_video_chain();
}
}
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_TRACK=%d\n", video_id);
return M_PROPERTY_OK;
default:
return M_PROPERTY_NOT_IMPLEMENTED;
}
}
static int mp_property_program(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
demux_program_t prog;
switch (action) {
case M_PROPERTY_STEP_UP:
case M_PROPERTY_SET:
if (action == M_PROPERTY_SET && arg)
prog.progid = *((int *) arg);
else
prog.progid = -1;
if (demux_control
(mpctx->demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM,
&prog) == DEMUXER_CTRL_NOTIMPL)
return M_PROPERTY_ERROR;
mp_property_do("switch_audio", M_PROPERTY_SET, &prog.aid, mpctx);
mp_property_do("switch_video", M_PROPERTY_SET, &prog.vid, mpctx);
return M_PROPERTY_OK;
default:
return M_PROPERTY_NOT_IMPLEMENTED;
}
}
///@}
/// \defgroup VideoProperties Video properties
/// \ingroup Properties
///@{
/// Fullscreen state (RW)
static int mp_property_fullscreen(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
if (!mpctx->video_out)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_SET:
if (!arg)
return M_PROPERTY_ERROR;
M_PROPERTY_CLAMP(prop, *(int *) arg);
if (vo_fs == !!*(int *) arg)
return M_PROPERTY_OK;
case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN:
#ifdef HAVE_NEW_GUI
if (use_gui)
guiGetEvent(guiIEvent, (char *) MP_CMD_GUI_FULLSCREEN);
else
#endif
if (vo_config_count)
mpctx->video_out->control(VOCTRL_FULLSCREEN, 0);
return M_PROPERTY_OK;
default:
return m_property_flag(prop, action, arg, &vo_fs);
}
}
static int mp_property_deinterlace(m_option_t * prop, int action,
void *arg, MPContext * mpctx)
{
int deinterlace;
vf_instance_t *vf;
if (!mpctx->sh_video || !mpctx->sh_video->vfilter)
return M_PROPERTY_UNAVAILABLE;
vf = mpctx->sh_video->vfilter;
switch (action) {
case M_PROPERTY_GET:
if (!arg)
return M_PROPERTY_ERROR;
vf->control(vf, VFCTRL_GET_DEINTERLACE, arg);
return M_PROPERTY_OK;
case M_PROPERTY_SET:
if (!arg)
return M_PROPERTY_ERROR;
M_PROPERTY_CLAMP(prop, *(int *) arg);
vf->control(vf, VFCTRL_SET_DEINTERLACE, arg);
return M_PROPERTY_OK;
case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN:
vf->control(vf, VFCTRL_GET_DEINTERLACE, &deinterlace);
deinterlace = !deinterlace;
vf->control(vf, VFCTRL_SET_DEINTERLACE, &deinterlace);
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
/// Panscan (RW)
static int mp_property_panscan(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
if (!mpctx->video_out
|| mpctx->video_out->control(VOCTRL_GET_PANSCAN, NULL) != VO_TRUE)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_SET:
if (!arg)
return M_PROPERTY_ERROR;
M_PROPERTY_CLAMP(prop, *(float *) arg);
vo_panscan = *(float *) arg;
mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
return M_PROPERTY_OK;
case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN:
vo_panscan += (arg ? *(float *) arg : 0.1) *
(action == M_PROPERTY_STEP_DOWN ? -1 : 1);
if (vo_panscan > 1)
vo_panscan = 1;
else if (vo_panscan < 0)
vo_panscan = 0;
mpctx->video_out->control(VOCTRL_SET_PANSCAN, NULL);
return M_PROPERTY_OK;
default:
return m_property_float_range(prop, action, arg, &vo_panscan);
}
}
/// Helper to set vo flags.
/** \ingroup PropertyImplHelper
*/
static int mp_property_vo_flag(m_option_t * prop, int action, void *arg,
int vo_ctrl, int *vo_var, MPContext * mpctx)
{
if (!mpctx->video_out)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_SET:
if (!arg)
return M_PROPERTY_ERROR;
M_PROPERTY_CLAMP(prop, *(int *) arg);
if (*vo_var == !!*(int *) arg)
return M_PROPERTY_OK;
case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN:
if (vo_config_count)
mpctx->video_out->control(vo_ctrl, 0);
return M_PROPERTY_OK;
default:
return m_property_flag(prop, action, arg, vo_var);
}
}
/// Window always on top (RW)
static int mp_property_ontop(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
return mp_property_vo_flag(prop, action, arg, VOCTRL_ONTOP, &vo_ontop,
mpctx);
}
/// Display in the root window (RW)
static int mp_property_rootwin(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
return mp_property_vo_flag(prop, action, arg, VOCTRL_ROOTWIN,
&vo_rootwin, mpctx);
}
/// Show window borders (RW)
static int mp_property_border(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
return mp_property_vo_flag(prop, action, arg, VOCTRL_BORDER,
&vo_border, mpctx);
}
/// Framedropping state (RW)
static int mp_property_framedropping(m_option_t * prop, int action,
void *arg, MPContext * mpctx)
{
if (!mpctx->sh_video)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_PRINT:
if (!arg)
return M_PROPERTY_ERROR;
*(char **) arg = strdup(frame_dropping == 1 ? MSGTR_Enabled :
(frame_dropping == 2 ? MSGTR_HardFrameDrop :
MSGTR_Disabled));
return M_PROPERTY_OK;
default:
return m_property_choice(prop, action, arg, &frame_dropping);
}
}
/// Color settings, try to use vf/vo then fall back on TV. (RW)
static int mp_property_gamma(m_option_t * prop, int action, void *arg,
MPContext * mpctx)
{
int *gamma = prop->priv, r;
if (!mpctx->sh_video)
return M_PROPERTY_UNAVAILABLE;
if (gamma[0] == 1000) {
gamma[0] = 0;
get_video_colors(mpctx->sh_video, prop->name, gamma);
}
switch (action) {
case M_PROPERTY_SET:
if (!arg)
return M_PROPERTY_ERROR;
M_PROPERTY_CLAMP(prop, *(int *) arg);
*gamma = *(int *) arg;
r = set_video_colors(mpctx->sh_video, prop->name, *gamma);
if (r <= 0)
break;
return r;
case M_PROPERTY_GET: