From 4e7bff9bd6c1f42d68b7b0051da2adec78463cf5 Mon Sep 17 00:00:00 2001 From: Fredrik Mellbin Date: Sat, 25 Apr 2009 08:55:14 +0000 Subject: [PATCH] FFMS2: Less enum forward declaration? Originally committed to SVN as r2849. --- aegisub/FFmpegSource2/ffms.cpp | 2 +- aegisub/FFmpegSource2/ffms.h | 4 +-- aegisub/FFmpegSource2/ffms2rt.cpp | 6 ++--- aegisub/FFmpegSource2/ffvideosource.cpp | 33 +++++-------------------- aegisub/FFmpegSource2/indexing.cpp | 20 +++++++++------ aegisub/FFmpegSource2/indexing.h | 2 +- aegisub/FFmpegSource2/utils.cpp | 27 ++++++++++++++++++++ aegisub/FFmpegSource2/utils.h | 15 +++++++++++ 8 files changed, 66 insertions(+), 43 deletions(-) diff --git a/aegisub/FFmpegSource2/ffms.cpp b/aegisub/FFmpegSource2/ffms.cpp index 3f9bd8a09..6d20f4f83 100644 --- a/aegisub/FFmpegSource2/ffms.cpp +++ b/aegisub/FFmpegSource2/ffms.cpp @@ -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); } \ No newline at end of file diff --git a/aegisub/FFmpegSource2/ffms.h b/aegisub/FFmpegSource2/ffms.h index b85ca3131..74fa78fe3 100644 --- a/aegisub/FFmpegSource2/ffms.h +++ b/aegisub/FFmpegSource2/ffms.h @@ -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 diff --git a/aegisub/FFmpegSource2/ffms2rt.cpp b/aegisub/FFmpegSource2/ffms2rt.cpp index 0ecef3b08..0256030ae 100644 --- a/aegisub/FFmpegSource2/ffms2rt.cpp +++ b/aegisub/FFmpegSource2/ffms2rt.cpp @@ -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)); diff --git a/aegisub/FFmpegSource2/ffvideosource.cpp b/aegisub/FFmpegSource2/ffvideosource.cpp index a601d6b39..9cb7a7710 100644 --- a/aegisub/FFmpegSource2/ffvideosource.cpp +++ b/aegisub/FFmpegSource2/ffvideosource.cpp @@ -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(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; } diff --git a/aegisub/FFmpegSource2/indexing.cpp b/aegisub/FFmpegSource2/indexing.cpp index 1444e401d..3af86a0f1 100644 --- a/aegisub/FFmpegSource2/indexing.cpp +++ b/aegisub/FFmpegSource2/indexing.cpp @@ -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 pMA; + CComPtr pMA; if (FAILED(pMA.CoCreateInstance(CLSID_MemAlloc))) { _snprintf(ErrorMsg, MsgSize, "Can't create memory allocator"); return NULL; } - CComPtr pMS; + CComPtr 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(); diff --git a/aegisub/FFmpegSource2/indexing.h b/aegisub/FFmpegSource2/indexing.h index 9f677a8a9..cd512ee32 100644 --- a/aegisub/FFmpegSource2/indexing.h +++ b/aegisub/FFmpegSource2/indexing.h @@ -25,7 +25,7 @@ #include "utils.h" #include "ffms.h" -#define INDEXVERSION 17 +#define INDEXVERSION 18 #define INDEXID 0x53920873 struct IndexHeader { diff --git a/aegisub/FFmpegSource2/utils.cpp b/aegisub/FFmpegSource2/utils.cpp index 3d296df21..38ff3c5db 100644 --- a/aegisub/FFmpegSource2/utils.cpp +++ b/aegisub/FFmpegSource2/utils.cpp @@ -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 )) diff --git a/aegisub/FFmpegSource2/utils.h b/aegisub/FFmpegSource2/utils.h index 770cd0f60..a96732773 100644 --- a/aegisub/FFmpegSource2/utils.h +++ b/aegisub/FFmpegSource2/utils.h @@ -31,6 +31,17 @@ extern "C" { #include "stdiostream.h" } +#ifdef HAALISOURCE +# define _WIN32_DCOM +# include +# include +# include +# include +# include "CoParser.h" +# include +# 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