-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideosource.h
303 lines (204 loc) · 5.81 KB
/
videosource.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
/**
* John Bradley ([email protected])
*/
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "xdw_list.h"
#include "threads.h"
#include <SDL/SDL.h>
#include <SDL/SDL_thread.h>
#include "vlc.h"
#include <string>
#include <string.h>
#include <ctype.h>
#include <vector>
#define CHROMA "YUYV"
#define __STDC_CONSTANT_MACROS
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavutil/time.h>
#include <libavutil/parseutils.h>
#include <libavutil/opt.h>
#include <libswresample/swresample.h>
#include <libswscale/swscale.h>
}
#define MAX_CACHED_AFRAME_NUM 100
#define MAX_CACHED_VFRAME_NUM 10
typedef struct __xdw_air_decoder_q
{
struct xdw_q_head video_pkt_q; // raw packet q that not be decoded
struct xdw_q_head audio_pkt_q;
}xdw_air_decoder_q;
typedef struct __xdw_pkt_audio_qnode_t
{
unsigned char *abuffer;
int len;
struct xdw_list_head list;
}xdw_pkt_audio_qnode_t;
typedef struct __xdw_video_frm_t
{
int pts;
int size;
int is_key;
int width;
int height;
unsigned char *data;
}xdw_video_frm_t;
typedef struct _VideoPktBufferPool
{
xdw_video_frm_t *VideoBuffer;
struct xdw_list_head list;
}xdw_pkt_video_qnode_t;
#define MAX_AUDIOQ_SIZE (5 * 16 * 1024)
#define MAX_VIDEOQ_SIZE (5 * 256 * 1024)
#define AV_SYNC_THRESHOLD 0.01
#define AV_NOSYNC_THRESHOLD 10.0
#define AUDIO_DIFF_AVG_NB 20
#define VIDEO_PICTURE_QUEUE_SIZE 1
enum
{
AV_SYNC_AUDIO_MASTER,
AV_SYNC_VIDEO_MASTER,
AV_SYNC_EXTERNAL_MASTER,
AV_SYNC_DEFAULT = AV_SYNC_EXTERNAL_MASTER
};
//typedef double(* GetAudioClockHandle)(void);
struct VideoState;
struct VideoSource;
typedef struct _SDLConfig
{
//SDL
//int screen_w, screen_h;
SDL_Surface *screen;
//SDL_VideoInfo *vi;
SDL_Overlay *bmp;
SDL_Rect rect;
}SDLconfig;
struct VideoState
{
VideoState()
: sws_context(NULL), pFrameYUV(NULL)
, video_quit(false), xdw_decoder_q_video(NULL), width(0), height(0)
{
// Register all formats and codecs
av_register_all();
}
~VideoState()
{
deinit();
}
int init(xdw_air_decoder_q *xdw_decoder_q,const void *privatedata, int privatedatalen);
void deinit();
static void video_thread_loop(VideoState *is);
int queue_picture(AVFrame *pFrame);
//GetAudioClockHandle audioClock;
SwsContext* sws_context;
AVFrame* pFrameYUV; // used as buffer for the frame converted from its native format to RGBA
thread_handle_t video_thread;
thread_handle_t refresh_thread;
mutex_handle_t pictq_mutex;
event_handle_t pictq_cond;
xdw_air_decoder_q *xdw_decoder_q_video;
volatile bool video_quit;
AVCodec *codec;
AVCodecContext *codecCtx;
int width;
int height;
struct VideoSource *vsource;
};
class VideoSource
{
public:
VideoSource(SDLconfig *config);
~VideoSource();
private:
libvlc_instance_t *vlc;
// be careful when accessing these
//libvlc_media_list_player_t *mediaListPlayer;
//libvlc_media_list_t *mediaList;
public:
xdw_air_decoder_q xdw_decoder_q;
struct VideoState *vs;
//void start_airplay();
//void stop_airplay();
volatile bool audio_quit;
int audio_volume;
void SetDeviceMac(const std::string& strDeviceMac);
const std::string& GetDeviceMac();
const void ClearDeviceMac();
std::string m_strDeviceMac;
public:
libvlc_media_player_t *mediaPlayer;
mutex_handle_t textureLock;
void *pixelData;
unsigned int mediaWidth;
unsigned int mediaHeight;
// should only be set inside texture lock
bool isRendering;
int remainingVideos;
SwsContext* media_sws_context;
AVFrame* pMediaFrame;
AVFrame* pMediaFrameYUV; // used as buffer for the frame converted from its native format to RGBA
public:
//SDL
int screen_w, screen_h;
SDL_Surface *screen;
//SDL_VideoInfo *vi;
SDL_Overlay *bmp;
SDL_Rect rect;
public:
void vlcplay(char *url, float fPosition);
long long totalDuration;
long currentPosition;
int isPlaying;
int isPaused;
public:
// Vlc
static unsigned videoFormatProxy(
void **opaque,
char *chroma,
unsigned *width,
unsigned *height,
unsigned *pitches,
unsigned *lines)
{
return reinterpret_cast<VideoSource *>(*opaque)->VideoFormatCallback(chroma, width, height, pitches, lines);
}
static void videoCleanupProxy(void *opaque)
{
reinterpret_cast<VideoSource *>(opaque)->VideoFormatCleanup();
};
unsigned int VideoFormatCallback(char *chroma, unsigned *width, unsigned *height, unsigned *pitches, unsigned *lines);
void VideoFormatCleanup();
//class AirPlayOutputFunctions
//{
public:
void airplay_open(void *cls, char *url, float fPosition);
void airplay_play(void *cls);
void airplay_pause(void *cls);
void airplay_stop(void *cls);
void airplay_seek(void *cls, long fPosition);
void airplay_setvolume(void *cls, int volume);
void airplay_showphoto(void *cls, unsigned char *data, long long size);
long airplay_getduration(void *cls);
long airplay_getpostion(void *cls);
int airplay_isplaying(void *cls);
int airplay_ispaused(void *cls);
void audio_init(void *cls, int bits, int channels, int samplerate, int isaudio);
void audio_process(void *cls, const void *buffer, int buflen, double timestamp, uint32_t seqnum);
void audio_destory(void *cls);
void audio_setvolume(void *cls, int volume);//1-100
void audio_setmetadata(void *cls, const void *buffer, int buflen);
void audio_setcoverart(void *cls, const void *buffer, int buflen);
void audio_flush(void *cls);
void mirroring_play(void *cls, int width, int height, const void *buffer, int buflen, int payloadtype, double timestamp);
void mirroring_process(void *cls, const void *buffer, int buflen, int payloadtype, double timestamp);
void mirroring_stop(void *cls);
static void sdl_audio_callback(void *cls, uint8_t *stream, int len);
//};
};