-
Notifications
You must be signed in to change notification settings - Fork 8.1k
/
ff_ffplay_def.h
executable file
·895 lines (771 loc) · 25.1 KB
/
ff_ffplay_def.h
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
/*
* Copyright (c) 2003 Bilibili
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2013-2015 Zhang Rui <bbcallen@gmail.com>
*
* This file is part of ijkPlayer.
*
* ijkPlayer is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ijkPlayer 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ijkPlayer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef FFPLAY__FF_FFPLAY_DEF_H
#define FFPLAY__FF_FFPLAY_DEF_H
/**
* @file
* simple media player based on the FFmpeg libraries
*/
#include "config.h"
#include <inttypes.h>
#include <math.h>
#include <limits.h>
#include <signal.h>
#include <stdint.h>
#include "libavutil/avstring.h"
#include "libavutil/eval.h"
#include "libavutil/mathematics.h"
#include "libavutil/pixdesc.h"
#include "libavutil/imgutils.h"
#include "libavutil/dict.h"
#include "libavutil/parseutils.h"
#include "libavutil/samplefmt.h"
#include "libavutil/avassert.h"
#include "libavutil/time.h"
#include "libavformat/avformat.h"
// FFP_MERGE: #include "libavdevice/avdevice.h"
#include "libswscale/swscale.h"
#include "libavutil/opt.h"
#include "libavcodec/avfft.h"
#include "libswresample/swresample.h"
#if CONFIG_AVFILTER
# include "libavfilter/avfilter.h"
# include "libavfilter/buffersink.h"
# include "libavfilter/buffersrc.h"
#endif
#include <stdbool.h>
#include "ijkavformat/ijkiomanager.h"
#include "ijkavformat/ijkioapplication.h"
#include "ff_ffinc.h"
#include "ff_ffmsg_queue.h"
#include "ff_ffpipenode.h"
#include "ijkmeta.h"
#define DEFAULT_HIGH_WATER_MARK_IN_BYTES (256 * 1024)
/*
* START: buffering after prepared/seeked
* NEXT: buffering for the second time after START
* MAX: ...
*/
#define DEFAULT_FIRST_HIGH_WATER_MARK_IN_MS (100)
#define DEFAULT_NEXT_HIGH_WATER_MARK_IN_MS (1 * 1000)
#define DEFAULT_LAST_HIGH_WATER_MARK_IN_MS (5 * 1000)
#define BUFFERING_CHECK_PER_BYTES (512)
#define BUFFERING_CHECK_PER_MILLISECONDS (500)
#define FAST_BUFFERING_CHECK_PER_MILLISECONDS (50)
#define MAX_RETRY_CONVERT_IMAGE (3)
#define MAX_QUEUE_SIZE (15 * 1024 * 1024)
#define MAX_ACCURATE_SEEK_TIMEOUT (5000)
#ifdef FFP_MERGE
#define MIN_FRAMES 25
#endif
#define DEFAULT_MIN_FRAMES 50000
#define MIN_MIN_FRAMES 2
#define MAX_MIN_FRAMES 50000
#define MIN_FRAMES (ffp->dcc.min_frames)
#define EXTERNAL_CLOCK_MIN_FRAMES 2
#define EXTERNAL_CLOCK_MAX_FRAMES 10
/* Minimum SDL audio buffer size, in samples. */
#define SDL_AUDIO_MIN_BUFFER_SIZE 512
/* Calculate actual buffer size keeping in mind not cause too frequent audio callbacks */
#define SDL_AUDIO_MAX_CALLBACKS_PER_SEC 30
/* Step size for volume control */
#define SDL_VOLUME_STEP (SDL_MIX_MAXVOLUME / 50)
/* no AV sync correction is done if below the minimum AV sync threshold */
#define AV_SYNC_THRESHOLD_MIN 0.04
/* AV sync correction is done if above the maximum AV sync threshold */
#define AV_SYNC_THRESHOLD_MAX 0.1
/* If a frame duration is longer than this, it will not be duplicated to compensate AV sync */
#define AV_SYNC_FRAMEDUP_THRESHOLD 0.15
/* no AV correction is done if too big error */
#define AV_NOSYNC_THRESHOLD 100.0
/* maximum audio speed change to get correct sync */
#define SAMPLE_CORRECTION_PERCENT_MAX 10
/* external clock speed adjustment constants for realtime sources based on buffer fullness */
#define EXTERNAL_CLOCK_SPEED_MIN 0.900
#define EXTERNAL_CLOCK_SPEED_MAX 1.010
#define EXTERNAL_CLOCK_SPEED_STEP 0.001
/* we use about AUDIO_DIFF_AVG_NB A-V differences to make the average */
#define AUDIO_DIFF_AVG_NB 20
/* polls for possible required screen refresh at least this often, should be less than 1/fps */
#define REFRESH_RATE 0.01
/* NOTE: the size must be big enough to compensate the hardware audio buffersize size */
/* TODO: We assume that a decoded and resampled frame fits into this buffer */
#define SAMPLE_ARRAY_SIZE (8 * 65536)
#define MIN_PKT_DURATION 15
#ifdef FFP_MERGE
#define CURSOR_HIDE_DELAY 1000000
#define USE_ONEPASS_SUBTITLE_RENDER 1
static unsigned sws_flags = SWS_BICUBIC;
#endif
#define HD_IMAGE 2 // 640*360
#define SD_IMAGE 1 // 320*180
#define LD_IMAGE 0 // 160*90
#define MAX_DEVIATION 1200000 // 1200ms
typedef struct GetImgInfo {
char *img_path;
int64_t start_time;
int64_t end_time;
int64_t frame_interval;
int num;
int count;
int width;
int height;
AVCodecContext *frame_img_codec_ctx;
struct SwsContext *frame_img_convert_ctx;
} GetImgInfo;
typedef struct MyAVPacketList {
AVPacket pkt;
struct MyAVPacketList *next;
int serial;
} MyAVPacketList;
typedef struct PacketQueue {
MyAVPacketList *first_pkt, *last_pkt;
int nb_packets;
int size;
int64_t duration;
int abort_request;
int serial;
SDL_mutex *mutex;
SDL_cond *cond;
MyAVPacketList *recycle_pkt;
int recycle_count;
int alloc_count;
int is_buffer_indicator;
} PacketQueue;
// #define VIDEO_PICTURE_QUEUE_SIZE 3
#define VIDEO_PICTURE_QUEUE_SIZE_MIN (3)
#define VIDEO_PICTURE_QUEUE_SIZE_MAX (16)
#define VIDEO_PICTURE_QUEUE_SIZE_DEFAULT (VIDEO_PICTURE_QUEUE_SIZE_MIN)
#define SUBPICTURE_QUEUE_SIZE 16
#define SAMPLE_QUEUE_SIZE 9
#define FRAME_QUEUE_SIZE FFMAX(SAMPLE_QUEUE_SIZE, FFMAX(VIDEO_PICTURE_QUEUE_SIZE_MAX, SUBPICTURE_QUEUE_SIZE))
#define VIDEO_MAX_FPS_DEFAULT 30
typedef struct AudioParams {
int freq;
int channels;
int64_t channel_layout;
enum AVSampleFormat fmt;
int frame_size;
int bytes_per_sec;
} AudioParams;
typedef struct Clock {
double pts; /* clock base */
double pts_drift; /* clock base minus time at which we updated the clock */
double last_updated;
double speed;
int serial; /* clock is based on a packet with this serial */
int paused;
int *queue_serial; /* pointer to the current packet queue serial, used for obsolete clock detection */
} Clock;
/* Common struct for handling all types of decoded data and allocated render buffers. */
typedef struct Frame {
AVFrame *frame;
AVSubtitle sub;
int serial;
double pts; /* presentation timestamp for the frame */
double duration; /* estimated duration of the frame */
int64_t pos; /* byte position of the frame in the input file */
#ifdef FFP_MERGE
SDL_Texture *bmp;
#else
SDL_VoutOverlay *bmp;
#endif
int allocated;
int width;
int height;
int format;
AVRational sar;
int uploaded;
} Frame;
typedef struct FrameQueue {
Frame queue[FRAME_QUEUE_SIZE];
int rindex;
int windex;
int size;
int max_size;
int keep_last;
int rindex_shown;
SDL_mutex *mutex;
SDL_cond *cond;
PacketQueue *pktq;
} FrameQueue;
enum {
AV_SYNC_AUDIO_MASTER, /* default choice */
AV_SYNC_VIDEO_MASTER,
AV_SYNC_EXTERNAL_CLOCK, /* synchronize to an external clock */
};
typedef struct Decoder {
AVPacket pkt;
AVPacket pkt_temp;
PacketQueue *queue;
AVCodecContext *avctx;
int pkt_serial;
int finished;
int packet_pending;
int bfsc_ret;
uint8_t *bfsc_data;
SDL_cond *empty_queue_cond;
int64_t start_pts;
AVRational start_pts_tb;
int64_t next_pts;
AVRational next_pts_tb;
SDL_Thread *decoder_tid;
SDL_Thread _decoder_tid;
SDL_Profiler decode_profiler;
Uint64 first_frame_decoded_time;
int first_frame_decoded;
} Decoder;
typedef struct VideoState {
SDL_Thread *read_tid;
SDL_Thread _read_tid;
AVInputFormat *iformat;
int abort_request;
int force_refresh;
int paused;
int last_paused;
int queue_attachments_req;
int seek_req;
int seek_flags;
int64_t seek_pos;
int64_t seek_rel;
#ifdef FFP_MERGE
int read_pause_return;
#endif
AVFormatContext *ic;
int realtime;
Clock audclk;
Clock vidclk;
Clock extclk;
FrameQueue pictq;
FrameQueue subpq;
FrameQueue sampq;
Decoder auddec;
Decoder viddec;
Decoder subdec;
int audio_stream;
int av_sync_type;
void *handle;
double audio_clock;
int audio_clock_serial;
double audio_diff_cum; /* used for AV difference average computation */
double audio_diff_avg_coef;
double audio_diff_threshold;
int audio_diff_avg_count;
AVStream *audio_st;
PacketQueue audioq;
int audio_hw_buf_size;
uint8_t *audio_buf;
uint8_t *audio_buf1;
short *audio_new_buf; /* for soundtouch buf */
unsigned int audio_buf_size; /* in bytes */
unsigned int audio_buf1_size;
unsigned int audio_new_buf_size;
int audio_buf_index; /* in bytes */
int audio_write_buf_size;
int audio_volume;
int muted;
struct AudioParams audio_src;
#if CONFIG_AVFILTER
struct AudioParams audio_filter_src;
#endif
struct AudioParams audio_tgt;
struct SwrContext *swr_ctx;
int frame_drops_early;
int frame_drops_late;
int continuous_frame_drops_early;
enum ShowMode {
SHOW_MODE_NONE = -1, SHOW_MODE_VIDEO = 0, SHOW_MODE_WAVES, SHOW_MODE_RDFT, SHOW_MODE_NB
} show_mode;
int16_t sample_array[SAMPLE_ARRAY_SIZE];
int sample_array_index;
int last_i_start;
#ifdef FFP_MERGE
RDFTContext *rdft;
int rdft_bits;
FFTSample *rdft_data;
int xpos;
#endif
double last_vis_time;
#ifdef FFP_MERGE
SDL_Texture *vis_texture;
SDL_Texture *sub_texture;
#endif
int subtitle_stream;
AVStream *subtitle_st;
PacketQueue subtitleq;
double frame_timer;
double frame_last_returned_time;
double frame_last_filter_delay;
int video_stream;
AVStream *video_st;
PacketQueue videoq;
double max_frame_duration; // maximum duration of a frame - above this, we consider the jump a timestamp discontinuity
struct SwsContext *img_convert_ctx;
#ifdef FFP_SUB
struct SwsContext *sub_convert_ctx;
#endif
int eof;
char *filename;
int width, height, xleft, ytop;
int step;
#if CONFIG_AVFILTER
int vfilter_idx;
AVFilterContext *in_video_filter; // the first filter in the video chain
AVFilterContext *out_video_filter; // the last filter in the video chain
AVFilterContext *in_audio_filter; // the first filter in the audio chain
AVFilterContext *out_audio_filter; // the last filter in the audio chain
AVFilterGraph *agraph; // audio filter graph
#endif
int last_video_stream, last_audio_stream, last_subtitle_stream;
SDL_cond *continue_read_thread;
/* extra fields */
SDL_mutex *play_mutex; // only guard state, do not block any long operation
SDL_Thread *video_refresh_tid;
SDL_Thread _video_refresh_tid;
int buffering_on;
int pause_req;
int dropping_frame;
int is_video_high_fps; // above 30fps
int is_video_high_res; // above 1080p
PacketQueue *buffer_indicator_queue;
volatile int latest_video_seek_load_serial;
volatile int latest_audio_seek_load_serial;
volatile int64_t latest_seek_load_start_at;
int drop_aframe_count;
int drop_vframe_count;
int64_t accurate_seek_start_time;
volatile int64_t accurate_seek_vframe_pts;
volatile int64_t accurate_seek_aframe_pts;
int audio_accurate_seek_req;
int video_accurate_seek_req;
SDL_mutex *accurate_seek_mutex;
SDL_cond *video_accurate_seek_cond;
SDL_cond *audio_accurate_seek_cond;
volatile int initialized_decoder;
int seek_buffering;
} VideoState;
/* options specified by the user */
#ifdef FFP_MERGE
static AVInputFormat *file_iformat;
static const char *input_filename;
static const char *window_title;
static int default_width = 640;
static int default_height = 480;
static int screen_width = 0;
static int screen_height = 0;
static int audio_disable;
static int video_disable;
static int subtitle_disable;
static const char* wanted_stream_spec[AVMEDIA_TYPE_NB] = {0};
static int seek_by_bytes = -1;
static int display_disable;
static int show_status = 1;
static int av_sync_type = AV_SYNC_AUDIO_MASTER;
static int64_t start_time = AV_NOPTS_VALUE;
static int64_t duration = AV_NOPTS_VALUE;
static int fast = 0;
static int genpts = 0;
static int lowres = 0;
static int decoder_reorder_pts = -1;
static int autoexit;
static int exit_on_keydown;
static int exit_on_mousedown;
static int loop = 1;
static int framedrop = -1;
static int infinite_buffer = -1;
static enum ShowMode show_mode = SHOW_MODE_NONE;
static const char *audio_codec_name;
static const char *subtitle_codec_name;
static const char *video_codec_name;
double rdftspeed = 0.02;
static int64_t cursor_last_shown;
static int cursor_hidden = 0;
#if CONFIG_AVFILTER
static const char **vfilters_list = NULL;
static int nb_vfilters = 0;
static char *afilters = NULL;
#endif
static int autorotate = 1;
static int find_stream_info = 1;
/* current context */
static int is_full_screen;
static int64_t audio_callback_time;
static AVPacket flush_pkt;
static AVPacket eof_pkt;
#define FF_ALLOC_EVENT (SDL_USEREVENT)
#define FF_QUIT_EVENT (SDL_USEREVENT + 2)
static SDL_Window *window;
static SDL_Renderer *renderer;
#endif
/*****************************************************************************
* end at line 330 in ffplay.c
* near packet_queue_put
****************************************************************************/
typedef struct FFTrackCacheStatistic
{
int64_t duration;
int64_t bytes;
int64_t packets;
} FFTrackCacheStatistic;
typedef struct FFStatistic
{
int64_t vdec_type;
float vfps;
float vdps;
float avdelay;
float avdiff;
int64_t bit_rate;
FFTrackCacheStatistic video_cache;
FFTrackCacheStatistic audio_cache;
int64_t buf_backwards;
int64_t buf_forwards;
int64_t buf_capacity;
SDL_SpeedSampler2 tcp_read_sampler;
int64_t latest_seek_load_duration;
int64_t byte_count;
int64_t cache_physical_pos;
int64_t cache_file_forwards;
int64_t cache_file_pos;
int64_t cache_count_bytes;
int64_t logical_file_size;
int drop_frame_count;
int decode_frame_count;
float drop_frame_rate;
} FFStatistic;
#define FFP_TCP_READ_SAMPLE_RANGE 2000
inline static void ffp_reset_statistic(FFStatistic *dcc)
{
memset(dcc, 0, sizeof(FFStatistic));
SDL_SpeedSampler2Reset(&dcc->tcp_read_sampler, FFP_TCP_READ_SAMPLE_RANGE);
}
typedef struct FFDemuxCacheControl
{
int min_frames;
int max_buffer_size;
int high_water_mark_in_bytes;
int first_high_water_mark_in_ms;
int next_high_water_mark_in_ms;
int last_high_water_mark_in_ms;
int current_high_water_mark_in_ms;
} FFDemuxCacheControl;
inline static void ffp_reset_demux_cache_control(FFDemuxCacheControl *dcc)
{
dcc->min_frames = DEFAULT_MIN_FRAMES;
dcc->max_buffer_size = MAX_QUEUE_SIZE;
dcc->high_water_mark_in_bytes = DEFAULT_HIGH_WATER_MARK_IN_BYTES;
dcc->first_high_water_mark_in_ms = DEFAULT_FIRST_HIGH_WATER_MARK_IN_MS;
dcc->next_high_water_mark_in_ms = DEFAULT_NEXT_HIGH_WATER_MARK_IN_MS;
dcc->last_high_water_mark_in_ms = DEFAULT_LAST_HIGH_WATER_MARK_IN_MS;
dcc->current_high_water_mark_in_ms = DEFAULT_FIRST_HIGH_WATER_MARK_IN_MS;
}
/* ffplayer */
struct IjkMediaMeta;
struct IJKFF_Pipeline;
typedef struct FFPlayer {
const AVClass *av_class;
/* ffplay context */
VideoState *is;
/* format/codec options */
AVDictionary *format_opts;
AVDictionary *codec_opts;
AVDictionary *sws_dict;
AVDictionary *player_opts;
AVDictionary *swr_opts;
AVDictionary *swr_preset_opts;
/* ffplay options specified by the user */
#ifdef FFP_MERGE
AVInputFormat *file_iformat;
#endif
char *input_filename;
#ifdef FFP_MERGE
const char *window_title;
int fs_screen_width;
int fs_screen_height;
int default_width;
int default_height;
int screen_width;
int screen_height;
#endif
int audio_disable;
int video_disable;
int subtitle_disable;
const char* wanted_stream_spec[AVMEDIA_TYPE_NB];
int seek_by_bytes;
int display_disable;
int show_status;
int av_sync_type;
int64_t start_time;
int64_t duration;
int fast;
int genpts;
int lowres;
int decoder_reorder_pts;
int autoexit;
#ifdef FFP_MERGE
int exit_on_keydown;
int exit_on_mousedown;
#endif
int loop;
int framedrop;
int64_t seek_at_start;
int subtitle;
int infinite_buffer;
enum ShowMode show_mode;
char *audio_codec_name;
char *subtitle_codec_name;
char *video_codec_name;
double rdftspeed;
#ifdef FFP_MERGE
int64_t cursor_last_shown;
int cursor_hidden;
#endif
#if CONFIG_AVFILTER
const char **vfilters_list;
int nb_vfilters;
char *afilters;
char *vfilter0;
#endif
int autorotate;
int find_stream_info;
unsigned sws_flags;
/* current context */
#ifdef FFP_MERGE
int is_full_screen;
#endif
int64_t audio_callback_time;
#ifdef FFP_MERGE
SDL_Surface *screen;
#endif
/* extra fields */
SDL_Aout *aout;
SDL_Vout *vout;
struct IJKFF_Pipeline *pipeline;
struct IJKFF_Pipenode *node_vdec;
int sar_num;
int sar_den;
char *video_codec_info;
char *audio_codec_info;
char *subtitle_codec_info;
Uint32 overlay_format;
int last_error;
int prepared;
int auto_resume;
int error;
int error_count;
int start_on_prepared;
int first_video_frame_rendered;
int first_audio_frame_rendered;
int sync_av_start;
MessageQueue msg_queue;
int64_t playable_duration_ms;
int packet_buffering;
int pictq_size;
int max_fps;
int startup_volume;
int videotoolbox;
int vtb_max_frame_width;
int vtb_async;
int vtb_wait_async;
int vtb_handle_resolution_change;
int mediacodec_all_videos;
int mediacodec_avc;
int mediacodec_hevc;
int mediacodec_mpeg2;
int mediacodec_mpeg4;
int mediacodec_handle_resolution_change;
int mediacodec_auto_rotate;
int opensles;
int soundtouch_enable;
char *iformat_name;
int no_time_adjust;
double preset_5_1_center_mix_level;
struct IjkMediaMeta *meta;
SDL_SpeedSampler vfps_sampler;
SDL_SpeedSampler vdps_sampler;
/* filters */
SDL_mutex *vf_mutex;
SDL_mutex *af_mutex;
int vf_changed;
int af_changed;
float pf_playback_rate;
int pf_playback_rate_changed;
float pf_playback_volume;
int pf_playback_volume_changed;
void *inject_opaque;
void *ijkio_inject_opaque;
FFStatistic stat;
FFDemuxCacheControl dcc;
AVApplicationContext *app_ctx;
IjkIOManagerContext *ijkio_manager_ctx;
int enable_accurate_seek;
int accurate_seek_timeout;
int mediacodec_sync;
int skip_calc_frame_rate;
int get_frame_mode;
GetImgInfo *get_img_info;
int async_init_decoder;
char *video_mime_type;
char *mediacodec_default_name;
int ijkmeta_delay_init;
int render_wait_start;
} FFPlayer;
#define fftime_to_milliseconds(ts) (av_rescale(ts, 1000, AV_TIME_BASE))
#define milliseconds_to_fftime(ms) (av_rescale(ms, AV_TIME_BASE, 1000))
inline static void ffp_reset_internal(FFPlayer *ffp)
{
/* ffp->is closed in stream_close() */
av_opt_free(ffp);
/* format/codec options */
av_dict_free(&ffp->format_opts);
av_dict_free(&ffp->codec_opts);
av_dict_free(&ffp->sws_dict);
av_dict_free(&ffp->player_opts);
av_dict_free(&ffp->swr_opts);
av_dict_free(&ffp->swr_preset_opts);
/* ffplay options specified by the user */
av_freep(&ffp->input_filename);
ffp->audio_disable = 0;
ffp->video_disable = 0;
memset(ffp->wanted_stream_spec, 0, sizeof(ffp->wanted_stream_spec));
ffp->seek_by_bytes = -1;
ffp->display_disable = 0;
ffp->show_status = 0;
ffp->av_sync_type = AV_SYNC_AUDIO_MASTER;
ffp->start_time = AV_NOPTS_VALUE;
ffp->duration = AV_NOPTS_VALUE;
ffp->fast = 1;
ffp->genpts = 0;
ffp->lowres = 0;
ffp->decoder_reorder_pts = -1;
ffp->autoexit = 0;
ffp->loop = 1;
ffp->framedrop = 0; // option
ffp->seek_at_start = 0;
ffp->infinite_buffer = -1;
ffp->show_mode = SHOW_MODE_NONE;
av_freep(&ffp->audio_codec_name);
av_freep(&ffp->video_codec_name);
ffp->rdftspeed = 0.02;
#if CONFIG_AVFILTER
av_freep(&ffp->vfilters_list);
ffp->nb_vfilters = 0;
ffp->afilters = NULL;
ffp->vfilter0 = NULL;
#endif
ffp->autorotate = 1;
ffp->find_stream_info = 1;
ffp->sws_flags = SWS_FAST_BILINEAR;
/* current context */
ffp->audio_callback_time = 0;
/* extra fields */
ffp->aout = NULL; /* reset outside */
ffp->vout = NULL; /* reset outside */
ffp->pipeline = NULL;
ffp->node_vdec = NULL;
ffp->sar_num = 0;
ffp->sar_den = 0;
av_freep(&ffp->video_codec_info);
av_freep(&ffp->audio_codec_info);
av_freep(&ffp->subtitle_codec_info);
ffp->overlay_format = SDL_FCC_RV32;
ffp->last_error = 0;
ffp->prepared = 0;
ffp->auto_resume = 0;
ffp->error = 0;
ffp->error_count = 0;
ffp->start_on_prepared = 1;
ffp->first_video_frame_rendered = 0;
ffp->sync_av_start = 1;
ffp->enable_accurate_seek = 0;
ffp->accurate_seek_timeout = MAX_ACCURATE_SEEK_TIMEOUT;
ffp->playable_duration_ms = 0;
ffp->packet_buffering = 1;
ffp->pictq_size = VIDEO_PICTURE_QUEUE_SIZE_DEFAULT; // option
ffp->max_fps = 31; // option
ffp->videotoolbox = 0; // option
ffp->vtb_max_frame_width = 0; // option
ffp->vtb_async = 0; // option
ffp->vtb_handle_resolution_change = 0; // option
ffp->vtb_wait_async = 0; // option
ffp->mediacodec_all_videos = 0; // option
ffp->mediacodec_avc = 0; // option
ffp->mediacodec_hevc = 0; // option
ffp->mediacodec_mpeg2 = 0; // option
ffp->mediacodec_handle_resolution_change = 0; // option
ffp->mediacodec_auto_rotate = 0; // option
ffp->opensles = 0; // option
ffp->soundtouch_enable = 0; // option
ffp->iformat_name = NULL; // option
ffp->no_time_adjust = 0; // option
ffp->async_init_decoder = 0; // option
ffp->video_mime_type = NULL; // option
ffp->mediacodec_default_name = NULL; // option
ffp->ijkmeta_delay_init = 0; // option
ffp->render_wait_start = 0;
ijkmeta_reset(ffp->meta);
SDL_SpeedSamplerReset(&ffp->vfps_sampler);
SDL_SpeedSamplerReset(&ffp->vdps_sampler);
/* filters */
ffp->vf_changed = 0;
ffp->af_changed = 0;
ffp->pf_playback_rate = 1.0f;
ffp->pf_playback_rate_changed = 0;
ffp->pf_playback_volume = 1.0f;
ffp->pf_playback_volume_changed = 0;
av_application_closep(&ffp->app_ctx);
ijkio_manager_destroyp(&ffp->ijkio_manager_ctx);
msg_queue_flush(&ffp->msg_queue);
ffp->inject_opaque = NULL;
ffp->ijkio_inject_opaque = NULL;
ffp_reset_statistic(&ffp->stat);
ffp_reset_demux_cache_control(&ffp->dcc);
}
inline static void ffp_notify_msg1(FFPlayer *ffp, int what) {
msg_queue_put_simple3(&ffp->msg_queue, what, 0, 0);
}
inline static void ffp_notify_msg2(FFPlayer *ffp, int what, int arg1) {
msg_queue_put_simple3(&ffp->msg_queue, what, arg1, 0);
}
inline static void ffp_notify_msg3(FFPlayer *ffp, int what, int arg1, int arg2) {
msg_queue_put_simple3(&ffp->msg_queue, what, arg1, arg2);
}
inline static void ffp_notify_msg4(FFPlayer *ffp, int what, int arg1, int arg2, void *obj, int obj_len) {
msg_queue_put_simple4(&ffp->msg_queue, what, arg1, arg2, obj, obj_len);
}
inline static void ffp_remove_msg(FFPlayer *ffp, int what) {
msg_queue_remove(&ffp->msg_queue, what);
}
inline static const char *ffp_get_error_string(int error) {
switch (error) {
case AVERROR(ENOMEM): return "AVERROR(ENOMEM)"; // 12
case AVERROR(EINVAL): return "AVERROR(EINVAL)"; // 22
case AVERROR(EAGAIN): return "AVERROR(EAGAIN)"; // 35
case AVERROR(ETIMEDOUT): return "AVERROR(ETIMEDOUT)"; // 60
case AVERROR_EOF: return "AVERROR_EOF";
case AVERROR_EXIT: return "AVERROR_EXIT";
}
return "unknown";
}
#define FFTRACE ALOGW
#define AVCODEC_MODULE_NAME "avcodec"
#define MEDIACODEC_MODULE_NAME "MediaCodec"
#endif