-
Notifications
You must be signed in to change notification settings - Fork 21
/
command.c
3865 lines (3565 loc) · 132 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
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define _BSD_SOURCE
#include <windows.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include "config.h"
#include "command.h"
#include "input/input.h"
#include "stream/stream.h"
#include "libmpdemux/demuxer.h"
#include "libmpdemux/stheader.h"
#include "codec-cfg.h"
#include "mp_msg.h"
#include "mplayer.h"
#include "sub/sub.h"
#include "m_option.h"
#include "m_property.h"
#include "help_mp.h"
#include "metadata.h"
#include "libmpcodecs/vf.h"
#include "libmpcodecs/vd.h"
#include "libvo/video_out.h"
#include "libvo/aspect.h"
#include "sub/font_load.h"
#include "playtree.h"
#include "libao2/audio_out.h"
#include "mpcommon.h"
#include "mixer.h"
#include "libmpcodecs/dec_video.h"
#include "libmpcodecs/dec_teletext.h"
#include "osdep/strsep.h"
#include "sub/vobsub.h"
#include "sub/spudec.h"
#include "path.h"
#include "stream/tv.h"
#include "stream/stream_radio.h"
#include "stream/pvr.h"
#ifdef CONFIG_DVBIN
#include "stream/dvbin.h"
#endif
#include "stream/stream_bd.h"
#ifdef CONFIG_DVDREAD
#include "stream/stream_dvd.h"
#endif
#include "stream/stream_dvdnav.h"
#include "sub/ass_mp.h"
#include "m_struct.h"
#include "libmenu/menu.h"
#include "gui/interface.h"
#include "sub/eosd.h"
#include "pnm_loader.h"
#include "mp_core.h"
#include "mp_fifo.h"
#include "libavutil/avstring.h"
#include "edl.h"
#include "m_config.h"
#include "winstuff.h"
#include "help/help_mp_lang-utf.h"
extern int sys_Language;
extern m_config_t *mconfig;
extern int force_load_font;
extern int need_update_playtree;
extern int vo_dirver;
extern int have_audio;
extern int loop_break;
extern int not_save_status;
//extern int screenshot_pts;
int channel_state = 0; // 0: Both 1: Right 2: Left
int bChannel = 0;
extern int import_playtree_into_playlist(play_tree_t *tree, m_config_t *config);
static char *channel_state_text[] = {"both", "right", "left"};
#define IS_STREAMTYPE(t) (mpctx->stream && mpctx->stream->type == STREAMTYPE_##t)
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]
int w = vo_dwidth, h = vo_dheight;
if (aspect_scaling()) {
aspect(&w, &h, A_WINZOOM);
panscan_calc_windowed();
w += vo_panscan_x;
h += vo_panscan_y;
ix -= (vo_dwidth - w) / 2;
iy -= (vo_dheight - h) / 2;
}
if (ix < 0 || ix > w || iy < 0 || iy > h) {
// ignore movements outside movie area
*dx = *dy = -1.0;
return;
}
*dx = (double) ix / (double) w;
*dy = (double) iy / (double) h;
mp_msg(MSGT_CPLAYER, MSGL_V,
"\r\nrescaled coordinates: %.3f, %.3f, 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_pos_by_source(MPContext *mpctx, int src)
{
int i, cnt = 0;
if (src >= SUB_SOURCES || mpctx->sub_counts[src] == 0)
return -1;
for (i = 0; i < src; i++)
cnt += mpctx->sub_counts[i];
return cnt;
}
static int sub_source_and_index_by_pos(MPContext *mpctx, int *pos)
{
int start = 0;
int i;
for (i = 0; i < SUB_SOURCES; i++) {
int cnt = mpctx->sub_counts[i];
if (*pos >= start && *pos < start + cnt) {
*pos -= start;
return i;
}
start += cnt;
}
*pos = -1;
return -1;
}
int sub_source_by_pos(MPContext *mpctx, int pos)
{
return sub_source_and_index_by_pos(mpctx, &pos);
}
static int sub_source_pos(MPContext *mpctx)
{
int pos = mpctx->global_sub_pos;
sub_source_and_index_by_pos(mpctx, &pos);
return pos;
}
static int sub_source(MPContext *mpctx)
{
return sub_source_by_pos(mpctx, mpctx->global_sub_pos);
}
static void update_global_sub_size(MPContext *mpctx)
{
int i;
int cnt = 0;
// update number of demuxer sub streams
for (i = 0; i < MAX_S_STREAMS; i++)
if (mpctx->demuxer && mpctx->demuxer->s_streams[i])
cnt++;
if (cnt > mpctx->sub_counts[SUB_SOURCE_DEMUX])
mpctx->sub_counts[SUB_SOURCE_DEMUX] = cnt;
// update global size
mpctx->global_sub_size = 0;
for (i = 0; i < SUB_SOURCES; i++)
mpctx->global_sub_size += mpctx->sub_counts[i];
// update global_sub_pos if we auto-detected a demuxer sub
if (mpctx->global_sub_pos == -1) {
int sub_id = -1;
if (mpctx->demuxer && mpctx->demuxer->sub)
sub_id = mpctx->demuxer->sub->id;
if (sub_id < 0)
sub_id = dvdsub_id;
if (sub_id >= 0 && sub_id < mpctx->sub_counts[SUB_SOURCE_DEMUX])
mpctx->global_sub_pos = sub_pos_by_source(mpctx, SUB_SOURCE_DEMUX) +
sub_id;
}
}
/**
* \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)
goto out;
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);
out:
free(fname);
}
/// \defgroup properties 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) {
if(sys_Language == 1)
*(char **) arg = strdup(GB_MSGTR_LoopStatus1);
else if(sys_Language == 3 || sys_Language == 4)
*(char **) arg = strdup(BIG5_MSGTR_LoopStatus1);
else
*(char**)arg = strdup("off");
} else if (mpctx->loop_times == 0) {
if(sys_Language == 1)
*(char **) arg = strdup(GB_MSGTR_LoopStatus2);
else if(sys_Language == 3 || sys_Language == 4)
*(char **) arg = strdup(BIG5_MSGTR_LoopStatus2);
else
*(char**)arg = strdup("inf");
} else if(mpctx->loop_times > 10) {
mpctx->loop_times = -1;
if(sys_Language == 1)
*(char **) arg = strdup(GB_MSGTR_LoopStatus1);
else if(sys_Language == 3 || sys_Language == 4)
*(char **) arg = strdup(BIG5_MSGTR_LoopStatus1);
else
*(char**)arg = strdup("off");
}
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;
reinit_audio_chain();
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);
reinit_audio_chain();
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;
f = (char *)mp_basename(filename);
if (!*f)
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;
}
/// Current stream position in seconds (RO)
static int mp_property_stream_time_pos(m_option_t *prop, int action,
void *arg, MPContext *mpctx)
{
if (!mpctx->demuxer || mpctx->demuxer->stream_pts == MP_NOPTS_VALUE)
return M_PROPERTY_UNAVAILABLE;
return m_property_time_ro(prop, action, arg, mpctx->demuxer->stream_pts);
}
/// 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 = SEEK_ABSOLUTE | SEEK_FACTOR;
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 = SEEK_ABSOLUTE;
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));
}
/// Current chapter (RW)
static int mp_property_chapter(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
int chapter;
float next_pts = 0;
int chapter_num;
int step_all;
char *chapter_name = NULL;
if (mpctx->demuxer)
chapter = demuxer_get_current_chapter(mpctx->demuxer);
if (chapter < 0)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_GET:
if (!arg)
return M_PROPERTY_ERROR;
*(int *) arg = chapter;
return M_PROPERTY_OK;
case M_PROPERTY_PRINT: {
if (!arg)
return M_PROPERTY_ERROR;
chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter);
if (!chapter_name)
return M_PROPERTY_UNAVAILABLE;
*(char **) arg = chapter_name;
return M_PROPERTY_OK;
}
case M_PROPERTY_SET:
if (!arg)
return M_PROPERTY_ERROR;
M_PROPERTY_CLAMP(prop, *(int*)arg);
step_all = *(int *)arg - chapter;
chapter += step_all;
break;
case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN: {
step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1)
* (action == M_PROPERTY_STEP_UP ? 1 : -1);
chapter += step_all;
if (chapter < 0)
chapter = 0;
break;
}
default:
return M_PROPERTY_NOT_IMPLEMENTED;
}
rel_seek_secs = 0;
abs_seek_pos = 0;
chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
&next_pts, &chapter_num, &chapter_name);
if (chapter >= 0) {
if (next_pts > -1.0) {
abs_seek_pos = SEEK_ABSOLUTE;
rel_seek_secs = next_pts;
}
if (chapter_name)
set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
MSGTR_OSDChapter, chapter + 1, chapter_name);
}
else if (step_all > 0)
rel_seek_secs = 1000000000.;
else
set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
MSGTR_OSDChapter, 0, MSGTR_Unknown);
free(chapter_name);
return M_PROPERTY_OK;
}
/// Number of titles in file
static int mp_property_titles(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
if (!mpctx->demuxer)
return M_PROPERTY_UNAVAILABLE;
if (mpctx->demuxer->num_titles == 0)
stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_TITLES, &mpctx->demuxer->num_titles);
return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_titles);
}
/// Number of chapters in file
static int mp_property_chapters(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
if (!mpctx->demuxer)
return M_PROPERTY_UNAVAILABLE;
if (mpctx->demuxer->num_chapters == 0)
stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters);
return m_property_int_ro(prop, action, arg, mpctx->demuxer->num_chapters);
}
/// Current dvd angle (RW)
static int mp_property_angle(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
int angle = -1;
int angles;
char *angle_name = NULL;
if (mpctx->demuxer)
angle = demuxer_get_current_angle(mpctx->demuxer);
if (angle < 0)
return M_PROPERTY_UNAVAILABLE;
angles = demuxer_angles_count(mpctx->demuxer);
if (angles <= 1)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_GET:
if (!arg)
return M_PROPERTY_ERROR;
*(int *) arg = angle;
return M_PROPERTY_OK;
case M_PROPERTY_PRINT: {
if (!arg)
return M_PROPERTY_ERROR;
angle_name = calloc(1, 64);
if (!angle_name)
return M_PROPERTY_UNAVAILABLE;
snprintf(angle_name, 64, "%d/%d", angle, angles);
*(char **) arg = angle_name;
return M_PROPERTY_OK;
}
case M_PROPERTY_SET:
if (!arg)
return M_PROPERTY_ERROR;
angle = *(int *)arg;
M_PROPERTY_CLAMP(prop, angle);
break;
case M_PROPERTY_STEP_UP:
case M_PROPERTY_STEP_DOWN: {
int step = 0;
if(arg)
step = *(int*)arg;
if(!step)
step = 1;
step *= (action == M_PROPERTY_STEP_UP ? 1 : -1);
angle += step;
if (angle < 1) //cycle
angle = angles;
else if (angle > angles)
angle = 1;
break;
}
default:
return M_PROPERTY_NOT_IMPLEMENTED;
}
angle = demuxer_set_angle(mpctx->demuxer, angle);
set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
MSGTR_OSDAngle, angle, angles);
free(angle_name);
return M_PROPERTY_OK;
}
/// 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 const 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;
*(const m_option_t**)ka->arg = &key_type;
return M_PROPERTY_OK;
}
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
static int mp_property_pause(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
return m_property_flag_ro(prop, action, arg, mpctx->osd_function == OSD_PAUSE);
}
///@}
/// \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);
break;
case M_PROPERTY_STEP_UP:
if (arg && *(float *) arg <= 0)
mixer_decvolume(&mpctx->mixer);
else
mixer_incvolume(&mpctx->mixer);
break;
case M_PROPERTY_STEP_DOWN:
if (arg && *(float *) arg <= 0)
mixer_incvolume(&mpctx->mixer);
else
mixer_decvolume(&mpctx->mixer);
break;
default:
return M_PROPERTY_NOT_IMPLEMENTED;
}
float vol;
mixer_getbothvolume(&mpctx->mixer, &vol);
save_volume = vol;
guiCommand(CMD_UPDATE_VOLUME, save_volume);
return M_PROPERTY_OK;
}
/// 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) {
if(sys_Language == 1)
*(char **) arg = strdup(GB_MSGTR_EnabledEdl);
else if(sys_Language == 3 || sys_Language == 4)
*(char **) arg = strdup(BIG5_MSGTR_EnabledEdl);
else
*(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: {
int ret;
float delay = audio_delay;
ret = m_property_delay(prop, action, arg, &audio_delay);
if (ret != M_PROPERTY_OK)
return ret;
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, codec_idx2str(mpctx->sh_audio->codec->name_idx));
}
/// 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, tmp;
if (!mpctx->demuxer || !mpctx->demuxer->audio)
return M_PROPERTY_UNAVAILABLE;
current_id = mpctx->demuxer->audio->id;
if (current_id >= 0)
audio_id = ((sh_audio_t *)mpctx->demuxer->a_streams[current_id])->aid;
switch (action) {
case M_PROPERTY_GET:
if (!arg)
return M_PROPERTY_ERROR;
*(int *) arg = audio_id;
return M_PROPERTY_OK;
case M_PROPERTY_PRINT:
if (!arg)
return M_PROPERTY_ERROR;
if (current_id < 0)
*(char **) arg = strdup(MSGTR_Disabled);
else if (channel_state)
*(char **) arg = strdup(channel_state_text[channel_state]);
else {
char lang[40] = MSGTR_Unknown;
demuxer_audio_lang(mpctx->demuxer, current_id, lang, sizeof(lang));
*(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;
tmp = demuxer_switch_audio(mpctx->demuxer, tmp);
if (tmp == -2
|| (tmp > -1
&& mpctx->demuxer->audio->id != current_id && current_id != -2)) {
uninit_player(INITIALIZED_AO | INITIALIZED_ACODEC);
audio_id = tmp;
}
if (tmp > -1 && mpctx->demuxer->audio->id != current_id) {
sh_audio_t *sh2;
sh2 = mpctx->demuxer->a_streams[mpctx->demuxer->audio->id];
if (sh2) {
audio_id = sh2->aid;
sh2->ds = mpctx->demuxer->audio;
mpctx->sh_audio = sh2;
reinit_audio_chain();
}