FFMS2: Less enum forward declaration?

Originally committed to SVN as r2849.
This commit is contained in:
Fredrik Mellbin 2009-04-25 08:55:14 +00:00
parent ac63f69e06
commit 4e7bff9bd6
8 changed files with 66 additions and 43 deletions

View File

@ -209,6 +209,6 @@ FFMS_API(int) FFMS_WriteIndex(const char *IndexFile, FrameIndex *TrackIndices, c
return WriteIndex(IndexFile, TrackIndices, ErrorMsg, MsgSize); return WriteIndex(IndexFile, TrackIndices, ErrorMsg, MsgSize);
} }
FFMS_API(enum PixelFormat) FFMS_GetPixFmt(const char *Name) { FFMS_API(int) FFMS_GetPixFmt(const char *Name) {
return avcodec_get_pix_fmt(Name); return avcodec_get_pix_fmt(Name);
} }

View File

@ -48,8 +48,6 @@ class FrameInfoVector;
typedef int (FFMS_CC *IndexCallback)(int State, int64_t Current, int64_t Total, void *Private); typedef int (FFMS_CC *IndexCallback)(int State, int64_t Current, int64_t Total, void *Private);
enum PixelFormat;
enum FFMS_SeekMode { enum FFMS_SeekMode {
FFMS_SEEK_LINEAR_NO_RW = -1, FFMS_SEEK_LINEAR_NO_RW = -1,
FFMS_SEEK_LINEAR = 0, FFMS_SEEK_LINEAR = 0,
@ -148,5 +146,5 @@ FFMS_API(int) FFMS_WriteTimecodes(FrameInfoVector *FIV, const char *TimecodeFile
FFMS_API(FrameIndex *) FFMS_MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, bool IgnoreDecodeErrors, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize); FFMS_API(FrameIndex *) FFMS_MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, bool IgnoreDecodeErrors, IndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize);
FFMS_API(FrameIndex *) FFMS_ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize); FFMS_API(FrameIndex *) FFMS_ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize);
FFMS_API(int) FFMS_WriteIndex(const char *IndexFile, FrameIndex *TrackIndices, char *ErrorMsg, unsigned MsgSize); FFMS_API(int) FFMS_WriteIndex(const char *IndexFile, FrameIndex *TrackIndices, char *ErrorMsg, unsigned MsgSize);
FFMS_API(PixelFormat) FFMS_GetPixFmt(const char *Name); FFMS_API(int) FFMS_GetPixFmt(const char *Name);
#endif #endif

View File

@ -60,9 +60,9 @@ int main(int argc, char *argv[]) {
FFMS_NoLog(); FFMS_NoLog();
#endif #endif
enum PixelFormat FMT_YV12A = FFMS_GetPixFmt("PIX_FMT_YUV420P)"); int FMT_YV12A = FFMS_GetPixFmt("PIX_FMT_YUV420P)");
enum PixelFormat FMT_YV12B = FFMS_GetPixFmt("PIX_FMT_YUVJ420P"); int FMT_YV12B = FFMS_GetPixFmt("PIX_FMT_YUVJ420P");
enum PixelFormat FMT_YUY2 = FFMS_GetPixFmt("PIX_FMT_YUV422P"); int FMT_YUY2 = FFMS_GetPixFmt("PIX_FMT_YUV422P");
av_md5_init(ctx); av_md5_init(ctx);
FrameIndex *FI = FFMS_MakeIndex(argv[1], -1, 0, NULL, false, UpdateProgress, argv[1], ErrorMsg, sizeof(ErrorMsg)); FrameIndex *FI = FFMS_MakeIndex(argv[1], -1, 0, NULL, false, UpdateProgress, argv[1], ErrorMsg, sizeof(ErrorMsg));

View File

@ -591,32 +591,11 @@ AVFrameLite *MatroskaVideoSource::GetFrame(int n, char *ErrorMsg, unsigned MsgSi
#ifdef HAALISOURCE #ifdef HAALISOURCE
static unsigned vtSize(VARIANT &vt) {
if (V_VT(&vt) != (VT_ARRAY | VT_UI1))
return 0;
long lb,ub;
if (FAILED(SafeArrayGetLBound(V_ARRAY(&vt),1,&lb)) ||
FAILED(SafeArrayGetUBound(V_ARRAY(&vt),1,&ub)))
return 0;
return ub - lb + 1;
}
static void vtCopy(VARIANT& vt,void *dest) {
unsigned sz = vtSize(vt);
if (sz > 0) {
void *vp;
if (SUCCEEDED(SafeArrayAccessData(V_ARRAY(&vt),&vp))) {
memcpy(dest,vp,sz);
SafeArrayUnaccessData(V_ARRAY(&vt));
}
}
}
void HaaliVideoSource::Free(bool CloseCodec) { void HaaliVideoSource::Free(bool CloseCodec) {
if (CloseCodec) if (CloseCodec)
avcodec_close(CodecContext); avcodec_close(CodecContext);
av_free(CodecContext); av_free(CodecContext);
free(CodecPrivate); delete[] CodecPrivate;
} }
HaaliVideoSource::HaaliVideoSource(const char *SourceFile, int Track, HaaliVideoSource::HaaliVideoSource(const char *SourceFile, int Track,
@ -684,12 +663,12 @@ HaaliVideoSource::HaaliVideoSource(const char *SourceFile, int Track,
if (pBag) { if (pBag) {
CComVariant pV; CComVariant pV;
if (pBag->Read(L"CodecID", &pV, NULL) == S_OK) if (SUCCEEDED(pBag->Read(L"CodecID", &pV, NULL)) && SUCCEEDED(pV.ChangeType(VT_BSTR)))
CodecID = pV.bstrVal; CodecID = pV.bstrVal;
if (pBag->Read(L"CodecPrivate", &pV, NULL) == S_OK) { if (SUCCEEDED(pBag->Read(L"CodecPrivate", &pV, NULL))) {
CodecPrivateSize = vtSize(pV); CodecPrivateSize = vtSize(pV);
CodecPrivate = static_cast<uint8_t*>(malloc(CodecPrivateSize)); CodecPrivate = new uint8_t[CodecPrivateSize];
vtCopy(pV, CodecPrivate); vtCopy(pV, CodecPrivate);
} }
} }
@ -759,9 +738,9 @@ HaaliVideoSource::HaaliVideoSource(const char *SourceFile, int Track,
// Set AR variables // Set AR variables
CComVariant pV; CComVariant pV;
if (pBag->Read(L"Video.DisplayWidth", &pV, NULL) == S_OK) if (SUCCEEDED(pBag->Read(L"Video.DisplayWidth", &pV, NULL)) && SUCCEEDED(pV.ChangeType(VT_UI4)))
VP.SARNum = pV.uiVal; VP.SARNum = pV.uiVal;
if (pBag->Read(L"Video.DisplayHeight", &pV, NULL) == S_OK) if (SUCCEEDED(pBag->Read(L"Video.DisplayHeight", &pV, NULL)) && SUCCEEDED(pV.ChangeType(VT_UI4)))
VP.SARDen = pV.uiVal; VP.SARDen = pV.uiVal;
} }

View File

@ -57,15 +57,18 @@ public:
AVCodecContext *CTX; AVCodecContext *CTX;
CompressedStream *CS; CompressedStream *CS;
int64_t CurrentSample; int64_t CurrentSample;
uint8_t *CodecPrivate;
MatroskaAudioContext() { MatroskaAudioContext() {
W64W = NULL; W64W = NULL;
CTX = NULL; CTX = NULL;
CS = NULL; CS = NULL;
CurrentSample = 0; CurrentSample = 0;
CodecPrivate = NULL;
} }
~MatroskaAudioContext() { ~MatroskaAudioContext() {
delete[] CodecPrivate;
delete W64W; delete W64W;
if (CTX) { if (CTX) {
avcodec_close(CTX); avcodec_close(CTX);
@ -216,13 +219,13 @@ static FrameIndex *MakeHaaliIndex(const char *SourceFile, int IndexMask, int Dum
return NULL; return NULL;
} }
CComPtr<IMemAlloc> pMA; CComPtr<IMemAlloc> pMA;
if (FAILED(pMA.CoCreateInstance(CLSID_MemAlloc))) { if (FAILED(pMA.CoCreateInstance(CLSID_MemAlloc))) {
_snprintf(ErrorMsg, MsgSize, "Can't create memory allocator"); _snprintf(ErrorMsg, MsgSize, "Can't create memory allocator");
return NULL; return NULL;
} }
CComPtr<IMMStream> pMS; CComPtr<IMMStream> pMS;
if (FAILED(pMS.CoCreateInstance(CLSID_DiskFile))) { if (FAILED(pMS.CoCreateInstance(CLSID_DiskFile))) {
_snprintf(ErrorMsg, MsgSize, "Can't create disk file reader"); _snprintf(ErrorMsg, MsgSize, "Can't create disk file reader");
return NULL; return NULL;
@ -277,15 +280,16 @@ static FrameIndex *MakeHaaliIndex(const char *SourceFile, int IndexMask, int Dum
if (pBag) { if (pBag) {
CComVariant pV; CComVariant pV;
if (pBag->Read(L"CodecID", &pV, NULL) == S_OK) if (SUCCEEDED(pBag->Read(L"CodecID", &pV, NULL)) && SUCCEEDED(pV.ChangeType(VT_BSTR)))
CodecID = pV.bstrVal; CodecID = pV.bstrVal;
if (pBag->Read(L"Type", &pV, NULL) == S_OK) if (SUCCEEDED(pBag->Read(L"Type", &pV, NULL)) && SUCCEEDED(pV.ChangeType(VT_UI4)))
TrackTypes[CurrentTrack] = pV.uintVal; TrackTypes[CurrentTrack] = pV.uintVal;
if (pBag->Read(L"CodecPrivate", &pV, NULL) == S_OK) { if (SUCCEEDED(pBag->Read(L"CodecPrivate", &pV, NULL))) {
CodecPrivate = (uint8_t *)pV.parray->pvData; CodecPrivateSize = vtSize(pV);
CodecPrivateSize = pV.parray->cbElements; CodecPrivate = new uint8_t[CodecPrivateSize];
vtCopy(pV, CodecPrivate);
} }
} }
@ -339,7 +343,7 @@ static FrameIndex *MakeHaaliIndex(const char *SourceFile, int IndexMask, int Dum
if (pMMC->ReadFrame(NULL, &pMMF) != S_OK) if (pMMC->ReadFrame(NULL, &pMMF) != S_OK)
break; break;
REFERENCE_TIME Ts, Te; REFERENCE_TIME Ts, Te;
HRESULT hr = pMMF->GetTime(&Ts, &Te); HRESULT hr = pMMF->GetTime(&Ts, &Te);
unsigned int CurrentTrack = pMMF->GetTrack(); unsigned int CurrentTrack = pMMF->GetTrack();

View File

@ -25,7 +25,7 @@
#include "utils.h" #include "utils.h"
#include "ffms.h" #include "ffms.h"
#define INDEXVERSION 17 #define INDEXVERSION 18
#define INDEXID 0x53920873 #define INDEXID 0x53920873
struct IndexHeader { struct IndexHeader {

View File

@ -137,6 +137,31 @@ void init_null_packet(AVPacket *pkt) {
pkt->size = 0; pkt->size = 0;
} }
#ifdef HAALISOURCE
unsigned vtSize(VARIANT &vt) {
if (V_VT(&vt) != (VT_ARRAY | VT_UI1))
return 0;
long lb,ub;
if (FAILED(SafeArrayGetLBound(V_ARRAY(&vt),1,&lb)) ||
FAILED(SafeArrayGetUBound(V_ARRAY(&vt),1,&ub)))
return 0;
return ub - lb + 1;
}
void vtCopy(VARIANT& vt,void *dest) {
unsigned sz = vtSize(vt);
if (sz > 0) {
void *vp;
if (SUCCEEDED(SafeArrayAccessData(V_ARRAY(&vt),&vp))) {
memcpy(dest,vp,sz);
SafeArrayUnaccessData(V_ARRAY(&vt));
}
}
}
#else
// used for matroska<->ffmpeg codec ID mapping to avoid Win32 dependency // used for matroska<->ffmpeg codec ID mapping to avoid Win32 dependency
typedef struct BITMAPINFOHEADER { typedef struct BITMAPINFOHEADER {
uint32_t biSize; uint32_t biSize;
@ -152,6 +177,8 @@ typedef struct BITMAPINFOHEADER {
uint32_t biClrImportant; uint32_t biClrImportant;
} BITMAPINFOHEADER; } BITMAPINFOHEADER;
#endif
#define MAKEFOURCC(ch0, ch1, ch2, ch3)\ #define MAKEFOURCC(ch0, ch1, ch2, ch3)\
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) |\ ((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) |\
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 )) ((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))

View File

@ -31,6 +31,17 @@ extern "C" {
#include "stdiostream.h" #include "stdiostream.h"
} }
#ifdef HAALISOURCE
# define _WIN32_DCOM
# include <windows.h>
# include <tchar.h>
# include <atlbase.h>
# include <dshow.h>
# include "CoParser.h"
# include <initguid.h>
# include "guids.h"
#endif
struct MatroskaReaderContext { struct MatroskaReaderContext {
public: public:
StdIoStream ST; StdIoStream ST;
@ -52,6 +63,10 @@ int GetCPUFlags();
int ReadFrame(uint64_t FilePos, unsigned int &FrameSize, CompressedStream *CS, MatroskaReaderContext &Context, char *ErrorMsg, unsigned MsgSize); int ReadFrame(uint64_t FilePos, unsigned int &FrameSize, CompressedStream *CS, MatroskaReaderContext &Context, char *ErrorMsg, unsigned MsgSize);
bool AudioFMTIsFloat(SampleFormat FMT); bool AudioFMTIsFloat(SampleFormat FMT);
void init_null_packet(AVPacket *pkt); void init_null_packet(AVPacket *pkt);
#ifdef HAALISOURCE
unsigned vtSize(VARIANT &vt);
void vtCopy(VARIANT& vt,void *dest);
#endif
CodecID MatroskaToFFCodecID(char *Codec, void *CodecPrivate); CodecID MatroskaToFFCodecID(char *Codec, void *CodecPrivate);
#endif #endif