This repository was archived by the owner on May 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoSource2.h
More file actions
215 lines (182 loc) · 5.97 KB
/
VideoSource2.h
File metadata and controls
215 lines (182 loc) · 5.97 KB
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
#pragma once
#include <vd2/plugin/vdinputdriver.h>
#include <vd2/VDXFrame/Unknown.h>
extern "C"
{
#include <libavutil/frame.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}
#include <windows.h>
class VDFFInputFile;
class VDFFVideoSource : public vdxunknown<IVDXStreamSource>,
public IVDXStreamSourceV5,
public IVDXStreamSourceV3,
public IVDXVideoSource,
public IVDXVideoDecoder,
public IVDXVideoDecoderModel,
public IFilterModVideoDecoder
{
public:
VDFFVideoSource(const VDXInputDriverContext& context);
~VDFFVideoSource();
int VDXAPIENTRY AddRef();
int VDXAPIENTRY Release();
void *VDXAPIENTRY AsInterface(uint32_t iid);
//Stream Interface
void VDXAPIENTRY GetStreamSourceInfo(VDXStreamSourceInfo&);
void VDXAPIENTRY GetStreamSourceInfoV3(VDXStreamSourceInfoV3&);
bool VDXAPIENTRY Read(int64_t lStart, uint32_t lCount, void *lpBuffer, uint32_t cbBuffer, uint32_t *lBytesRead, uint32_t *lSamplesRead);
void VDXAPIENTRY ApplyStreamMode(uint32 flags);
bool VDXAPIENTRY QueryStreamMode(uint32 flags);
const void *VDXAPIENTRY GetDirectFormat();
int VDXAPIENTRY GetDirectFormatLen();
ErrorMode VDXAPIENTRY GetDecodeErrorMode();
void VDXAPIENTRY SetDecodeErrorMode(ErrorMode mode);
bool VDXAPIENTRY IsDecodeErrorModeSupported(ErrorMode mode);
bool VDXAPIENTRY IsVBR(){ return false; }
sint64 VDXAPIENTRY TimeToPositionVBR(int64_t us){ return 0; }
sint64 VDXAPIENTRY PositionToTimeVBR(int64_t samples){ return 0; }
void VDXAPIENTRY GetVideoSourceInfo(VDXVideoSourceInfo& info);
bool VDXAPIENTRY CreateVideoDecoderModel(IVDXVideoDecoderModel **ppModel);
bool VDXAPIENTRY CreateVideoDecoder(IVDXVideoDecoder **ppDecoder);
void VDXAPIENTRY GetSampleInfo(int64_t sample_num, VDXVideoFrameInfo& frameInfo);
bool VDXAPIENTRY IsKey(int64_t lSample);
int64_t VDXAPIENTRY GetFrameNumberForSample(int64_t sample_num);
int64_t VDXAPIENTRY GetSampleNumberForFrame(int64_t display_num);
int64_t VDXAPIENTRY GetRealFrame(int64_t display_num);
int64_t VDXAPIENTRY GetSampleBytePosition(int64_t sample_num);
//Model Interface
void VDXAPIENTRY Reset();
void VDXAPIENTRY SetDesiredFrame(int64_t frame_num);
int64_t VDXAPIENTRY GetNextRequiredSample(bool& is_preroll);
int VDXAPIENTRY GetRequiredCount();
//Decoder Interface
const void *VDXAPIENTRY DecodeFrame(const void *inputBuffer, uint32_t data_len, bool is_preroll, int64_t streamFrame, int64_t targetFrame);
uint32_t VDXAPIENTRY GetDecodePadding();
bool VDXAPIENTRY IsFrameBufferValid();
const VDXPixmap& VDXAPIENTRY GetFrameBuffer();
const FilterModPixmapInfo& VDXAPIENTRY GetFrameBufferInfo();
bool VDXAPIENTRY SetTargetFormat(int format, bool useDIBAlignment);
bool SetTargetFormat(nsVDXPixmap::VDXPixmapFormat format, bool useDIBAlignment, VDFFVideoSource* head);
bool VDXAPIENTRY SetDecompressedFormat(const VDXBITMAPINFOHEADER *pbih);
const void *VDXAPIENTRY GetFrameBufferBase();
bool VDXAPIENTRY IsDecodable(int64_t sample_num);
public:
//Internal
const VDXInputDriverContext& mContext;
VDFFInputFile* m_pSource;
int m_streamIndex;
AVFormatContext* m_pFormatCtx;
AVStream* m_pStreamCtx;
AVCodecContext* m_pCodecCtx;
VDXStreamSourceInfoV3 m_streamInfo;
void* direct_format;
int direct_format_len;
AVRational time_base;
int64_t start_time;
AVFrame* frame;
SwsContext* m_pSwsCtx;
VDXPixmapAlpha m_pixmap;
FilterModPixmapInfo m_pixmap_info;
uint8_t* m_pixmap_data;
int m_pixmap_frame;
struct ConvertInfo{
nsVDXPixmap::VDXPixmapFormat req_format;
nsVDXPixmap::VDXPixmapFormat ext_format;
bool req_dib;
AVPixelFormat av_fmt;
bool direct_copy;
bool in_yuv;
bool in_subs;
bool out_rgb;
bool out_garbage;
ConvertInfo(){
req_format = nsVDXPixmap::kPixFormat_Null;
ext_format = nsVDXPixmap::kPixFormat_Null;
av_fmt = AV_PIX_FMT_NONE;
}
} convertInfo;
ErrorMode errorMode;
struct BufferPage{
enum {
err_badformat = 1,
err_memory = 2
};
int i;
int target;
int refs;
int error;
volatile LONG access;
void* map_base;
uint8_t* p;
};
BufferPage* buffer;
int buffer_count;
int buffer_reserve;
HANDLE mem;
int sample_count;
BufferPage** frame_array;
char* frame_type;
int64_t desired_frame;
int required_count;
int last_request;
int next_frame;
int first_frame;
int last_frame;
int last_seek_frame;
int used_frames;
int keyframe_gap;
int fw_seek_threshold;
int decoded_count;
AVPixelFormat frame_fmt;
int frame_width;
int frame_height;
int frame_size;
bool flip_image;
bool trust_index;
bool avi_drop_index;
bool sparse_index;
bool has_vfr;
bool average_fr;
bool direct_buffer;
bool direct_cfhd;
bool is_image_list;
bool copy_mode;
bool decode_mode;
bool small_cache_mode;
bool enable_prefetch;
int small_buffer_count;
int64_t dead_range_start;
int64_t dead_range_end;
AVPacket copy_pkt;
//uint64 kPixFormat_XRGB64;
int initStream(VDFFInputFile* pSource, int indexStream);
int init_duration(const AVRational fr);
void init_format();
void set_pixmap_layout(uint8_t* p);
int handle_frame_num(int64_t pts, int64_t dts);
int handle_frame();
bool check_frame_format();
void set_start_time();
bool read_frame(sint64 desired_frame, bool init=false);
void alloc_direct_buffer();
void alloc_page(int pos);
BufferPage* remove_page(int play_pos, bool before=true, bool after=true);
void dealloc_page(BufferPage* p);
void free_buffers();
void open_page(BufferPage* p, int flag);
void open_read(BufferPage* p){ open_page(p,1); }
void open_write(BufferPage* p){ open_page(p,2); }
void copy_page(int start, int end, BufferPage* p);
int64_t frame_to_pts_next(sint64 start);
void setCopyMode(bool v);
void setDecodeMode(bool v);
void setCacheMode(bool v);
bool is_intra();
bool allow_copy();
bool possible_delay();
int calc_sparse_key(int64_t sample, int64_t& pos);
int calc_seek(int jump, int64_t& pos);
int calc_prefetch(int jump);
};