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 f8652576c8
commit 6f6d1bdf3a
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);
}
FFMS_API(enum PixelFormat) FFMS_GetPixFmt(const char *Name) {
FFMS_API(int) FFMS_GetPixFmt(const char *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);
enum PixelFormat;
enum FFMS_SeekMode {
FFMS_SEEK_LINEAR_NO_RW = -1,
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_ReadIndex(const char *IndexFile, 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

View file

@ -60,9 +60,9 @@ int main(int argc, char *argv[]) {
FFMS_NoLog();
#endif
enum PixelFormat FMT_YV12A = FFMS_GetPixFmt("PIX_FMT_YUV420P)");
enum PixelFormat FMT_YV12B = FFMS_GetPixFmt("PIX_FMT_YUVJ420P");
enum PixelFormat FMT_YUY2 = FFMS_GetPixFmt("PIX_FMT_YUV422P");
int FMT_YV12A = FFMS_GetPixFmt("PIX_FMT_YUV420P)");
int FMT_YV12B = FFMS_GetPixFmt("PIX_FMT_YUVJ420P");
int FMT_YUY2 = FFMS_GetPixFmt("PIX_FMT_YUV422P");
av_md5_init(ctx);
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
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) {
if (CloseCodec)
avcodec_close(CodecContext);
av_free(CodecContext);
free(CodecPrivate);
delete[] CodecPrivate;
}
HaaliVideoSource::HaaliVideoSource(const char *SourceFile, int Track,
@ -684,12 +663,12 @@ HaaliVideoSource::HaaliVideoSource(const char *SourceFile, int Track,
if (pBag) {
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;
if (pBag->Read(L"CodecPrivate", &pV, NULL) == S_OK) {
if (SUCCEEDED(pBag->Read(L"CodecPrivate", &pV, NULL))) {
CodecPrivateSize = vtSize(pV);
CodecPrivate = static_cast<uint8_t*>(malloc(CodecPrivateSize));
CodecPrivate = new uint8_t[CodecPrivateSize];
vtCopy(pV, CodecPrivate);
}
}
@ -759,9 +738,9 @@ HaaliVideoSource::HaaliVideoSource(const char *SourceFile, int Track,
// Set AR variables
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;
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;
}

View file

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

View file

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

View file

@ -137,6 +137,31 @@ void init_null_packet(AVPacket *pkt) {
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
typedef struct BITMAPINFOHEADER {
uint32_t biSize;
@ -152,6 +177,8 @@ typedef struct BITMAPINFOHEADER {
uint32_t biClrImportant;
} BITMAPINFOHEADER;
#endif
#define MAKEFOURCC(ch0, ch1, ch2, ch3)\
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) |\
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))

View file

@ -31,6 +31,17 @@ extern "C" {
#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 {
public:
StdIoStream ST;
@ -52,6 +63,10 @@ int GetCPUFlags();
int ReadFrame(uint64_t FilePos, unsigned int &FrameSize, CompressedStream *CS, MatroskaReaderContext &Context, char *ErrorMsg, unsigned MsgSize);
bool AudioFMTIsFloat(SampleFormat FMT);
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);
#endif