-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.c
3538 lines (3238 loc) · 116 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.
*/
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>
#include "config.h"
#include "talloc.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 "mplayer.h"
#include "sub/sub.h"
#include "sub/dec_sub.h"
#include "m_option.h"
#include "m_property.h"
#include "m_config.h"
#include "metadata.h"
#include "libmpcodecs/vf.h"
#include "libmpcodecs/vd.h"
#include "mp_osd.h"
#include "libvo/video_out.h"
#include "libvo/csputils.h"
#include "playtree.h"
#include "libao2/audio_out.h"
#include "mpcommon.h"
#include "mixer.h"
#include "libmpcodecs/dec_video.h"
#include "libmpcodecs/dec_audio.h"
#include "libmpcodecs/dec_teletext.h"
#include "osdep/strsep.h"
#include "sub/vobsub.h"
#include "sub/spudec.h"
#include "path.h"
#include "sub/ass_mp.h"
#include "stream/tv.h"
#include "stream/stream_radio.h"
#include "stream/pvr.h"
#ifdef CONFIG_DVBIN
#include "stream/dvbin.h"
#endif
#ifdef CONFIG_DVDREAD
#include "stream/stream_dvd.h"
#endif
#include "stream/stream_dvdnav.h"
#include "m_struct.h"
#include "screenshot.h"
#include "mp_core.h"
#include "mp_fifo.h"
#include "libavutil/avstring.h"
static void rescale_input_coordinates(struct MPContext *mpctx, int ix, int iy,
double *dx, double *dy)
{
struct MPOpts *opts = &mpctx->opts;
struct vo *vo = mpctx->video_out;
//remove the borders, if any, and rescale to the range [0,1],[0,1]
if (vo_fs) { //we are in full-screen mode
if (opts->vo_screenwidth > vo->dwidth)
// there are borders along the x axis
ix -= (opts->vo_screenwidth - vo->dwidth) / 2;
if (opts->vo_screenheight > vo->dheight)
// there are borders along the y axis (usual way)
iy -= (opts->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: %.3f, %.3f, screen (%d x %d), vodisplay: (%d, %d), fullscreen: %d\r\n",
*dx, *dy, opts->vo_screenwidth, opts->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;
}
static 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)
{
struct MPOpts *opts = &mpctx->opts;
int i;
int cnt = 0;
// update number of demuxer sub streams
for (i = 0; i < MAX_S_STREAMS; i++)
if (mpctx->d_sub->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->sub)
sub_id = mpctx->demuxer->sub->id;
if (sub_id < 0)
sub_id = opts->sub_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(struct MPContext *mpctx)
{
char *fname;
FILE *f;
int i;
struct subtitle *vo_sub_last = mpctx->vo_sub_last;
if (mpctx->subdata == NULL || vo_sub_last == NULL)
return;
fname = get_path("subtitle_log");
f = fopen(fname, "a");
if (!f)
return;
fprintf(f, "----------------------------------------------------------\n");
if (mpctx->subdata->sub_uses_time) {
fprintf(f,
"N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n",
mpctx->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", mpctx->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);
}
static int mp_property_generic_option(struct m_option *prop, int action,
void *arg, MPContext *mpctx)
{
char *optname = prop->priv;
const struct m_option *opt = m_config_get_option(mpctx->mconfig,
bstr(optname));
void *valptr = m_option_get_ptr(opt, &mpctx->opts);
switch (action) {
case M_PROPERTY_GET_TYPE:
*(const struct m_option **)arg = opt;
return M_PROPERTY_OK;
case M_PROPERTY_GET:
m_option_copy(opt, arg, valptr);
return M_PROPERTY_OK;
case M_PROPERTY_SET:
m_option_copy(opt, valptr, arg);
return M_PROPERTY_OK;
case M_PROPERTY_STEP:
if (opt->type == &m_option_type_choice) {
int v = *(int *) valptr;
int best = v;
struct m_opt_choice_alternatives *alt;
for (alt = opt->priv; alt->name; alt++)
if ((unsigned) alt->value - v - 1 < (unsigned) best - v - 1)
best = alt->value;
*(int *) valptr = best;
return M_PROPERTY_OK;
}
break;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
/// 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, &mpctx->opts.osd_level);
}
/// Loop (RW)
static int mp_property_loop(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
struct MPOpts *opts = &mpctx->opts;
switch (action) {
case M_PROPERTY_PRINT:
if (!arg)
return M_PROPERTY_ERROR;
if (opts->loop_times < 0)
*(char **)arg = talloc_strdup(NULL, "off");
else if (opts->loop_times == 0)
*(char **)arg = talloc_strdup(NULL, "inf");
else
break;
return M_PROPERTY_OK;
}
return m_property_int_range(prop, action, arg, &opts->loop_times);
}
/// Playback speed (RW)
static int mp_property_playback_speed(m_option_t *prop, int action,
void *arg, MPContext *mpctx)
{
struct MPOpts *opts = &mpctx->opts;
double orig_speed = opts->playback_speed;
switch (action) {
case M_PROPERTY_SET:
if (!arg)
return M_PROPERTY_ERROR;
opts->playback_speed = *(float *) arg;
goto set;
case M_PROPERTY_STEP:
opts->playback_speed += (arg ? *(float *) arg : 0.1);
set:
M_PROPERTY_CLAMP(prop, opts->playback_speed);
if (opts->playback_speed == orig_speed)
return M_PROPERTY_OK;
// Adjust time until next frame flip for nosound mode
mpctx->time_frame *= orig_speed / opts->playback_speed;
if (mpctx->sh_audio) {
double a = ao_get_delay(mpctx->ao);
mpctx->delay += (opts->playback_speed - orig_speed) * a;
}
reinit_audio_chain(mpctx);
return M_PROPERTY_OK;
}
return m_property_float_range(prop, action, arg, &opts->playback_speed);
}
/// filename with path (RO)
static int mp_property_path(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
if (!mpctx->filename)
return M_PROPERTY_UNAVAILABLE;
return m_property_string_ro(prop, action, arg, mpctx->filename);
}
/// filename without path (RO)
static int mp_property_filename(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
char *f;
if (!mpctx->filename)
return M_PROPERTY_UNAVAILABLE;
f = (char *)mp_basename(mpctx->filename);
if (!*f)
f = mpctx->filename;
return m_property_string_ro(prop, action, arg, f);
}
static int mp_property_media_title(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
char *name = NULL;
if (mpctx->resolve_result)
name = mpctx->resolve_result->title;
if (name && name[0])
return m_property_string_ro(prop, action, arg, name);
return mp_property_filename(prop, action, arg, mpctx);
}
static int mp_property_stream_path(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
struct stream *stream = mpctx->stream;
if (!stream || !stream->url)
return M_PROPERTY_UNAVAILABLE;
return m_property_string_ro(prop, action, arg, stream->url);
}
/// 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 = get_time_length(mpctx)))
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:
pos = get_percent_pos(mpctx);
pos += (arg ? *(int *)arg : 10);
M_PROPERTY_CLAMP(prop, pos);
break;
default:
return m_property_int_ro(prop, action, arg, get_percent_pos(mpctx));
}
queue_seek(mpctx, MPSEEK_FACTOR, pos / 100.0, 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))
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_SET:
if (!arg)
return M_PROPERTY_ERROR;
M_PROPERTY_CLAMP(prop, *(double *)arg);
queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double *)arg, 0);
return M_PROPERTY_OK;
case M_PROPERTY_STEP:
queue_seek(mpctx, MPSEEK_RELATIVE, (arg ? *(double *)arg : 10.0), 0);
return M_PROPERTY_OK;
}
return m_property_time_ro(prop, action, arg, get_current_time(mpctx));
}
/// Current chapter (RW)
static int mp_property_chapter(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
struct MPOpts *opts = &mpctx->opts;
int chapter = -1;
int step_all;
char *chapter_name = NULL;
if (mpctx->demuxer)
chapter = get_current_chapter(mpctx);
if (chapter < -1)
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 = chapter_display_name(mpctx, 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: {
step_all = (arg && *(int *)arg != 0 ? *(int *)arg : 1);
chapter += step_all;
if (chapter < 0)
chapter = 0;
break;
}
default:
return M_PROPERTY_NOT_IMPLEMENTED;
}
double next_pts = 0;
queue_seek(mpctx, MPSEEK_NONE, 0, 0);
chapter = seek_chapter(mpctx, chapter, &next_pts);
if (chapter >= 0) {
if (next_pts > -1.0)
queue_seek(mpctx, MPSEEK_ABSOLUTE, next_pts, 0);
chapter_name = chapter_display_name(mpctx, chapter);
set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
"Chapter: %s", chapter_name);
} else if (step_all > 0)
queue_seek(mpctx, MPSEEK_RELATIVE, 1000000000, 0);
else
set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
"Chapter: (%d) %s", 0, mp_gtext("unknown"));
talloc_free(chapter_name);
return M_PROPERTY_OK;
}
/// 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;
int count = get_chapter_count(mpctx);
return m_property_int_ro(prop, action, arg, count);
}
/// Current dvd angle (RW)
static int mp_property_angle(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
struct MPOpts *opts = &mpctx->opts;
int angle = -1;
int angles;
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;
*(char **) arg = talloc_asprintf(NULL, "%d/%d", angle, angles);
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: {
int step = 0;
if (arg)
step = *(int *)arg;
if (!step)
step = 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);
if (angle >= 0) {
struct sh_video *sh_video = mpctx->demuxer->video->sh;
if (sh_video)
resync_video_stream(sh_video);
struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
if (sh_audio)
resync_audio_stream(sh_audio);
}
set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
"Angle: %d/%d", angle, angles);
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,
void *ctx)
{
MPContext *mpctx = ctx;
switch (action) {
case M_PROPERTY_SET:
if (!arg)
return M_PROPERTY_ERROR;
if (mpctx->paused == (bool) * (int *)arg)
return M_PROPERTY_OK;
case M_PROPERTY_STEP:
if (mpctx->paused) {
unpause_player(mpctx);
} else {
pause_player(mpctx);
}
return M_PROPERTY_OK;
default:
return m_property_flag(prop, action, arg, &mpctx->paused);
}
}
/// 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_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:
if (arg && *(float *) arg <= 0)
mixer_decvolume(&mpctx->mixer);
else
mixer_incvolume(&mpctx->mixer);
return M_PROPERTY_OK;
default:
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 (!arg)
return M_PROPERTY_ERROR;
mixer_setmute(&mpctx->mixer, *(int *) arg);
return M_PROPERTY_OK;
case M_PROPERTY_STEP:
mixer_setmute(&mpctx->mixer, !mixer_getmute(&mpctx->mixer));
return M_PROPERTY_OK;
default:
return m_property_flag_ro(prop, action, arg,
mixer_getmute(&mpctx->mixer));
}
}
/// 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: {
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,
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 = talloc_asprintf(NULL, "%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 = talloc_strdup(NULL, "mono");
break;
case 2:
*(char **) arg = talloc_strdup(NULL, "stereo");
break;
default:
*(char **) arg = talloc_asprintf(NULL, "%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;
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 = talloc_strdup(NULL, "center");
else if (bal == -1.f)
*str = talloc_strdup(NULL, "left only");
else if (bal == 1.f)
*str = talloc_strdup(NULL, "right only");
else {
unsigned right = (bal + 1.f) / 2.f * 100.f;
*str = talloc_asprintf(NULL, "left %d%%, right %d%%",
100 - right, right);
}
return M_PROPERTY_OK;
}
case M_PROPERTY_STEP:
mixer_getbalance(&mpctx->mixer, &bal);
bal += (arg ? *(float *)arg : .1f);
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->d_audio)
return M_PROPERTY_UNAVAILABLE;
struct sh_audio *sh = mpctx->sh_audio;
current_id = sh ? sh->aid : -2;
switch (action) {
case M_PROPERTY_GET:
if (!arg)
return M_PROPERTY_ERROR;
*(int *) arg = current_id;
return M_PROPERTY_OK;
case M_PROPERTY_PRINT:
if (!arg)
return M_PROPERTY_ERROR;
if (current_id < 0)
*(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
else if (sh && (sh->lang || sh->title)) {
char *lang = sh->lang ? sh->lang : mp_gtext("unknown");
if (sh->title)
*(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")",
current_id, lang, sh->title);
else
*(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id,
lang);
} else {
char lang[40];
strncpy(lang, mp_gtext("unknown"), sizeof(lang));
if (0) ;
#ifdef CONFIG_DVDREAD
else if (mpctx->stream->type == STREAMTYPE_DVD) {
int code = dvd_lang_from_aid(mpctx->stream, current_id);
if (code) {
lang[0] = code >> 8;
lang[1] = code;
lang[2] = 0;
}
}
#endif
#ifdef CONFIG_DVDNAV
else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
#endif
*(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id, lang);
}
return M_PROPERTY_OK;
case M_PROPERTY_STEP:
case M_PROPERTY_SET:
if (action == M_PROPERTY_SET && arg)
tmp = *((int *) arg);
else
tmp = -1;
int new_id = demuxer_switch_audio(mpctx->d_audio->demuxer, tmp);
if (new_id != current_id)
uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_ACODEC);
if (new_id != current_id && new_id >= 0) {
sh_audio_t *sh2;
sh2 = mpctx->d_audio->demuxer->a_streams[mpctx->d_audio->id];
sh2->ds = mpctx->d_audio;
mpctx->sh_audio = sh2;
reinit_audio_chain(mpctx);
}
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_TRACK=%d\n", new_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)
{
struct MPOpts *opts = &mpctx->opts;
int current_id, tmp;
if (!mpctx->demuxer || !mpctx->d_video)
return M_PROPERTY_UNAVAILABLE;
current_id = mpctx->sh_video ? mpctx->sh_video->vid : -2;
switch (action) {
case M_PROPERTY_GET:
if (!arg)
return M_PROPERTY_ERROR;