2
#include <SDL_thread.h>
3
#include <ffmpeg/avformat.h>
7
#define MAX_SOURCENAME 1024
8
#define MAX_AUDIOQ_SIZE (5 * 16 * 1024)
10
/* SDL audio buffer size, in samples. Should be small to have precise
11
A/V sync as SDL does not have hardware buffer fullness info. */
12
#define SDL_AUDIO_BUFFER_SIZE 1024
14
/* no AV sync correction is done if below the AV sync threshold */
15
#define AV_SYNC_THRESHOLD 0.08
16
/* no AV correction is done if too big error */
17
#define AV_NOSYNC_THRESHOLD 10.0
19
/* maximum audio speed change to get correct sync */
20
#define SAMPLE_CORRECTION_PERCENT_MAX 10
22
/* we use about AUDIO_DIFF_AVG_NB A-V differences to make the average */
23
#define AUDIO_DIFF_AVG_NB 20
25
/* NOTE: the size must be big enough to compensate the hardware audio buffersize size */
26
#define SAMPLE_ARRAY_SIZE (2*65536)
32
typedef struct PacketQueue {
33
AVPacketList *first_pkt, *last_pkt;
43
typedef struct FFMovie {
44
SDL_Thread *decode_thread;
47
AVFormatContext *context;
49
double external_clock; /* external clock base */
50
int64_t external_clock_time;
53
double audio_diff_cum; /* used for AV difference average computation */
54
double audio_diff_avg_coef;
55
double audio_diff_threshold;
56
int audio_diff_avg_count;
59
int audio_hw_buf_size;
60
/* samples output by the codec. we reserve more space for avsync compensation */
61
uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
62
int audio_buf_size; /* in bytes */
63
int audio_buf_index; /* in bytes */
65
uint8_t *audio_pkt_data;
67
int64_t audio_pkt_ipts;
68
int audio_volume; /*must self implement*/
70
int16_t sample_array[SAMPLE_ARRAY_SIZE];
71
int sample_array_index;
75
double frame_last_pts;
76
double frame_last_delay;
77
double frame_delay; /*display time of each frame, based on fps*/
78
double video_clock; /*seconds of video frame decoded*/
80
int64_t vidpkt_timestamp;
82
double video_last_P_pts; /* pts of the last P picture (needed if B
83
frames are present) */
84
double video_current_pts; /* current displayed pts (different from
85
video_clock if frame fifos are used) */
87
SDL_mutex *dest_mutex;
88
double dest_showtime; /*when to next show the dest_overlay*/
89
SDL_Overlay *dest_overlay;
90
SDL_Surface *dest_surface;
93
double time_offset; /*track paused time*/
97
const char *sourcename;
103
FFMovie *ffmovie_open(const char *filename);
104
FFMovie *ffmovie_reopen(FFMovie *movie);
105
void ffmovie_close(FFMovie *movie);
106
void ffmovie_play(FFMovie *movie);
107
void ffmovie_stop(FFMovie *movie);
108
void ffmovie_pause(FFMovie *movie);
109
void ffmovie_setvolume(FFMovie *movie, int volume);
110
void ffmovie_setdisplay(FFMovie *movie, SDL_Surface *dest, SDL_Rect *rect);
111
void ffmovie_abortall(void);