【VC开源代码栏目提醒】:本文主要为网学会员提供AVIReadHandler.cpp,希望对需要AVIReadHandler.cpp网友有所帮助,学习一下!
// VirtualDub - Video processing and capture application
// Copyright (C) 1998-2001 Avery Lee
//
// This program 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.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <crtdbg.h>
#include <windows.h>
#include "AVIReadHandler.h"
#include "FastReadStream.h"
//#include "ProgressDialog.h"
#include "AVIIndex.h"
#include "Error.h"
#include "List.h"
#include "Fixes.h"
#include "File64.h"
#include "Avisynth.h"
//#define STREAMING_DEBUG
// HACK!!!!
CRITICAL_SECTION g_diskcs;
bool g_disklockinited=false;
///////////////////////////////////////////
typedef __int64 QUADWORD;
// The following comes from the OpenDML 1.0 spec for extended AVI files
// bIndexType codes
//
#define AVI_INDEX_OF_INDEXES 0x00 // when each entry in aIndex
// array points to an index chunk
#define AVI_INDEX_OF_CHUNKS 0x01 // when each entry in aIndex
// array points to a chunk in the file
#define AVI_INDEX_IS_DATA 0x80 // when each entry is aIndex is
// really the data
// bIndexSubtype codes for INDEX_OF_CHUNKS
#define AVI_INDEX_2FIELD 0x01 // when fields within frames
// are also indexed
struct _avisuperindex_entry {
QUADWORD qwOffset; // absolute file offset, offset 0 is
// unused entry??
DWORD dwSize; // size of index chunk at this offset
DWORD dwDuration; // time span in stream ticks
};
struct _avistdindex_entry {
DWORD dwOffset; // qwBaseOffset + this is absolute file offset
DWORD dwSize; // bit 31 is set if this is NOT a keyframe
};
struct _avifieldindex_entry {
DWORD dwOffset;
DWORD dwSize;
DWORD dwOffsetField2;
};
#pragma pack(push)
#pragma pack(2)
typedef struct _avisuperindex_chunk {
FOURCC fcc; // 抜x##?
DWORD cb; // size of this structure
WORD wLongsPerEntry; // must be 4 (size of each entry in aIndex array)
BYTE bIndexSubType; // must be 0 or AVI_INDEX_2FIELD
BYTE bIndexType; // must be AVI_INDEX_OF_INDEXES
DWORD nEntriesInUse; // number of entries in aIndex array that
// are used
DWORD dwChunkId; // ?#dc?or ?#db?or ?#wb? etc
DWORD dwReserved[3]; // must be 0
struct _avisuperindex_entry aIndex[];
} AVISUPERINDEX, * PAVISUPERINDEX;
typedef struct _avistdindex_chunk {
FOURCC fcc; // 抜x##?
DWORD cb;
WORD wLongsPerEntry; // must be sizeof(aIndex[0])/sizeof(DWORD)
BYTE bIndexSubType; // must be 0
BYTE bIndexType; // must be AVI_INDEX_OF_CHUNKS
DWORD nEntriesInUse; //
DWORD dwChunkId; // ?#dc?or ?#db?or ?#wb?etc..
QUADWORD qwBaseOffset; // all dwOffsets in aIndex array are
// relative to this
DWORD dwReserved3; // must be 0
struct _avistdindex_entry aIndex[];
} AVISTDINDEX, * PAVISTDINDEX;
typedef struct _avifieldindex_chunk {
FOURCC fcc;
DWORD cb;
WORD wLongsPerEntry;
BYTE bIndexSubType;
BYTE bIndexType;
DWORD nEntriesInUse;
DWORD dwChunkId;
QUADWORD qwBaseOffset;
DWORD dwReserved3;
struct _avifieldindex_entry aIndex[];
} AVIFIELDINDEX, * PAVIFIELDINDEX;
#pragma pack(pop)
///////////////////////////////////////////////////////////////////////////
IAVIReadStream::~IAVIReadStream() {
}
///////////////////////////////////////////////////////////////////////////
class AVIStreamNode;
class AVIReadHandler;
class AVIReadCache {
public:
long cache_hit_bytes, cache_miss_bytes;
int reads;
AVIReadCache(int nlines, int nstream, AVIReadHandler *root, AVIStreamNode *psnData);
~AVIReadCache();
void ResetStatistics();
bool WriteBegin(__int64 pos, long len);
void Write(void *buffer, long len);
void WriteEnd();
long Read(void *dest, __int64 chunk_pos, __int64 pos, long len);
private:
AVIStreamNode *psnData;
__int64 (*buffer)[2];
int lines_max, lines;
long read_tail, write_tail, write_hdr;
int write_offset;
int stream;
AVIReadHandler *source;
};
class AVIStreamNode : public ListNode2<AVIStreamNode> {
public:
AVIStreamHeader_fixed hdr;
void *pFormat;
long lFormatLen;
AVIIndex index;
__int64 bytes;
bool keyframe_only;
int handler_count;
class AVIReadCache *cache;
int streaming_count;
__int64 stream_push_pos;
__int64 stream_bytes;
int stream_pushes;
long length;
long frames;
List2<class AVIReadStream> listHandlers;
AVIStreamNode();
~AVIStreamNode();
};
AVIStreamNode::AVIStreamNode() {
pFormat = NULL;
bytes = 0;
handler_count = 0;
streaming_count = 0;
stream_bytes = 0;
stream_pushes = 0;
cache = NULL;
}
AVIStreamNode::~AVIStreamNode() {
delete pFormat;
delete cache;
}
///////////////////////////////////////////////////////////////////////////
class AVIFileDesc : public ListNode2<AVIFileDesc> {
public:
HANDLE hFile;
HANDLE hFileUnbuffered;
__int64 i64Size;
};
class AVIStreamNode;
class AVIReadHandler : public IAVIReadHandler, private File64 {
public:
bool fDisableFastIO;
AVIReadHandler(const char *);
AVIReadHandler(PAVIFILE);
~AVIReadHandler();
void AddRef();
void Release();
IAVIReadStream *GetStream(DWORD fccType, LONG lParam);
void EnableFastIO(bool);
bool isOptimizedForRealtime();
bool isStreaming();
bool isIndexFabricated();
bool AppendFile(const char *pszFile);
bool getSegmentHint(const char **ppszPath);
void EnableStreaming(int stream);
void DisableStreaming(int stream);
void AdjustRealTime(bool fRealTime);
bool Stream(AVIStreamNode *, _int64 pos);
__int64 getStreamPtr();
void FixCacheProblems(class AVIReadStream *);
long ReadData(int stream, void *buffer, __int64 position, long len);
private:
// enum { STREAM_SIZE = 65536 };
enum { STREAM_SIZE = 1048576 };
enum { STREAM_RT_SIZE = 65536 };
enum { STREAM_BLOCK_SIZE = 4096 };
IAvisynthClipInfo *pAvisynthClipInfo;
PAVIFILE paf;
int ref_count;
__int64 i64StreamPosition;
int streams;
char *streamBuffer;
int sbPosition;
int sbSize;
long fStreamsActive;
int nRealTime;
int nActiveStreamers;
bool fFakeIndex;
__int64 i64Size;
int nFiles, nCurrentFile;
char * pSegmentHint;
List2<AVIStreamNode> listStreams;
List2<AVIFileDesc> listFiles;
void _construct(const char *pszFile);
void _parseFile(List2<AVIStreamNode>& streams);
上一篇:
AVIIndex.cpp
下一篇:
首鼠两端