201 lines
7.3 KiB
C++
201 lines
7.3 KiB
C++
#include <avifile/vidc.hpp>
|
|
#include <avifile/fourcc.hpp>
|
|
|
|
VideoCodec::ReturnCode VideoCodec::openDriver(const DriverName &driverName)
|
|
{
|
|
return openDriver(driverName.driverLoadName());
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::openDriver(DWORD fccHandler)
|
|
{
|
|
DriverName driverName;
|
|
|
|
if(!locateDriver(fccHandler,driverName))return FailResult;
|
|
return openDriver(driverName);
|
|
}
|
|
|
|
WORD VideoCodec::enumerateDrivers(Block<DriverName> &driverStrings)
|
|
{
|
|
Profile systemProfile("SYSTEM.INI","UNSET");
|
|
String sectionName("DRIVERS32");
|
|
String videoCodecID("VIDC");
|
|
String driverType;
|
|
String driverName;
|
|
String driverLoadName;
|
|
Block<String> driversBlock;
|
|
|
|
driverStrings.remove();
|
|
systemProfile.readProfileBlock(sectionName,driversBlock);
|
|
if(!driversBlock.size())return FALSE;
|
|
for(short itemIndex=0;itemIndex<driversBlock.size();itemIndex++)
|
|
{
|
|
driverType=driversBlock[itemIndex].betweenString(0,'.');
|
|
if(driverType.isNull())continue;
|
|
driverType.upper();
|
|
if(!(driverType==videoCodecID))continue;
|
|
driverName=driversBlock[itemIndex].betweenString('.','=');
|
|
if(driverName.isNull())continue;
|
|
driverLoadName=driversBlock[itemIndex].betweenString('=',0);
|
|
if(driverLoadName.isNull())continue;
|
|
driverStrings.insert(&DriverName(driverName,driverLoadName));
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
WORD VideoCodec::locateDriver(DWORD fccType,DriverName &driverName)
|
|
{
|
|
Block<DriverName> driverNames;
|
|
String fccString;
|
|
WORD driverCount;
|
|
|
|
::OutputDebugString(String("\nsearching for a driver to handle type '")+FOURCC(fccType).toString()+String("'\n"));
|
|
enumerateDrivers(driverNames);
|
|
if(0==(driverCount=driverNames.size()))return FALSE;
|
|
for(short itemIndex=0;itemIndex<driverCount;itemIndex++)
|
|
{
|
|
fccString=driverNames[itemIndex].driverName();
|
|
::OutputDebugString(driverNames[itemIndex].driverName()+String(":")+driverNames[itemIndex].driverLoadName()+String("\n"));
|
|
if(fccType==FOURCC(fccString)){driverName=driverNames[itemIndex];return TRUE;}
|
|
fccString.lower();
|
|
if(fccType==FOURCC(fccString)){driverName=driverNames[itemIndex];return TRUE;}
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::openDriver(const String &driverLoadName)
|
|
{
|
|
closeDriver();
|
|
if((mhVideoCodec=::LoadLibrary(driverLoadName))<(HINSTANCE)HINSTANCE_ERROR)mhVideoCodec=(HINSTANCE)0;
|
|
if(!mhVideoCodec)return FailResult;
|
|
mlpfnDriverProc=(LPFNDRIVERPROC)::GetProcAddress(mhVideoCodec,"DriverProc");
|
|
if(!mlpfnDriverProc){closeDriver();return FailResult;}
|
|
return OkResult;
|
|
}
|
|
|
|
void VideoCodec::closeDriver(void)
|
|
{
|
|
if(!mhVideoCodec)return;
|
|
::FreeLibrary(mhVideoCodec);
|
|
mhVideoCodec=(HINSTANCE)0;
|
|
mlpfnDriverProc=0;
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::driverProc(ICMOpen &someICMOpen)
|
|
{
|
|
ReturnCode returnCode(FailResult);
|
|
if(!mlpfnDriverProc)return returnCode;
|
|
mDriverID=(DWORD)((mlpfnDriverProc)(DriverID,(HDRVR)DriverHandle,DRV_OPEN,0L,(LONG)&someICMOpen));
|
|
return (ReturnCode)mDriverID;
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::driverProc(ICMInfo &someICMInfo)
|
|
{
|
|
ReturnCode returnCode(FailResult);
|
|
if(!mlpfnDriverProc)return returnCode;
|
|
return (ReturnCode)((mlpfnDriverProc)(mDriverID,(HDRVR)DriverHandle,ICM_GETINFO,(LONG)&someICMInfo,(LONG)someICMInfo.size()));
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::canDecompress(AVIBitmap &someAVIBitmap)
|
|
{
|
|
ReturnCode returnCode(FailResult);
|
|
|
|
if(!mlpfnDriverProc)return returnCode;
|
|
returnCode=(ReturnCode)((mlpfnDriverProc)(mDriverID,(HDRVR)DriverHandle,ICM_DECOMPRESS_QUERY,(LONG)((BITMAPINFO*)someAVIBitmap),0L));
|
|
return returnCode;
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::canDecompress(AVIBitmap &srcAVIBitmap,AVIBitmap &dstAVIBitmap)
|
|
{
|
|
ReturnCode returnCode(FailResult);
|
|
|
|
if(!mlpfnDriverProc)return returnCode;
|
|
returnCode=(ReturnCode)((mlpfnDriverProc)(mDriverID,(HDRVR)DriverHandle,ICM_DECOMPRESS_QUERY,(LONG)((BITMAPINFO*)srcAVIBitmap),(LONG)((BITMAPINFO*)dstAVIBitmap)));
|
|
return returnCode;
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::getFormat(AVIBitmap &srcAVIBitmap)
|
|
{
|
|
if(!mlpfnDriverProc)return FailResult;
|
|
return (ReturnCode)((mlpfnDriverProc)(mDriverID,(HDRVR)DriverHandle,ICM_DECOMPRESS_GET_FORMAT,(LONG)((BITMAPINFO*)srcAVIBitmap),0L));
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::getFormat(AVIBitmap &srcAVIBitmap,AVIBitmap &dstAVIBitmap)
|
|
{
|
|
if(!mlpfnDriverProc)return FailResult;
|
|
return (ReturnCode)((mlpfnDriverProc)(mDriverID,(HDRVR)DriverHandle,ICM_DECOMPRESS_GET_FORMAT,(LONG)((BITMAPINFO*)srcAVIBitmap),(LONG)((BITMAPINFO*)dstAVIBitmap)));
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::getPalette(AVIBitmap &srcAVIBitmap,AVIBitmap &dstAVIBitmap)
|
|
{
|
|
if(!mlpfnDriverProc)return FailResult;
|
|
return (ReturnCode)((mlpfnDriverProc)(mDriverID,(HDRVR)DriverHandle,ICM_DECOMPRESS_GET_PALETTE,(LONG)((BITMAPINFOHEADER*)srcAVIBitmap),(LONG)((BITMAPINFOHEADER*)dstAVIBitmap)));
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::driverLoad(void)
|
|
{
|
|
if(!mlpfnDriverProc)return FailResult;
|
|
return (ReturnCode)((mlpfnDriverProc)(mDriverID,(HDRVR)DriverHandle,DRV_LOAD,0L,0L));
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::driverEnable(void)
|
|
{
|
|
if(!mlpfnDriverProc)return FailResult;
|
|
return (ReturnCode)((mlpfnDriverProc)(mDriverID,(HDRVR)DriverHandle,DRV_ENABLE,0L,0L));
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::icmDecompressBegin(AVIBitmap &srcAVIBitmap,AVIBitmap &dstAVIBitmap)
|
|
{
|
|
if(!mlpfnDriverProc)return BadFormatResult;
|
|
return (ReturnCode)((mlpfnDriverProc)(mDriverID,(HDRVR)DriverHandle,ICM_DECOMPRESS_BEGIN,(LONG)((BITMAPINFO*)srcAVIBitmap),(LONG)((BITMAPINFO*)dstAVIBitmap)));
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::icmDecompressEnd(void)
|
|
{
|
|
if(!mlpfnDriverProc)return FailResult;
|
|
return (ReturnCode)((mlpfnDriverProc)(mDriverID,(HDRVR)DriverHandle,ICM_DECOMPRESS_END,0L,0L));
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::icmDecompress(AVIBitmap &srcAVIBitmap,AVIBitmap &dstAVIBitmap,MovieData &srcMovieData,MovieData &dstMovieData)
|
|
{
|
|
ICMDecompress icmDecompress;
|
|
|
|
if(!mlpfnDriverProc)return BadFormatResult;
|
|
icmDecompress.flags(ICMDecompress::HurryUp);
|
|
icmDecompress.srcBitmapInfoHeaderPtr(srcAVIBitmap);
|
|
icmDecompress.dstBitmapInfoHeaderPtr(dstAVIBitmap);
|
|
icmDecompress.srcInputPtr(srcMovieData);
|
|
icmDecompress.dstInputPtr(dstMovieData);
|
|
icmDecompress.chunkID(0x01);
|
|
return (ReturnCode)((mlpfnDriverProc)(mDriverID,(HDRVR)DriverHandle,ICM_DECOMPRESS,(LONG)&icmDecompress,(LONG)sizeof(ICMDecompress)));
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::icmConfigure(HWND hDisplayWindow)
|
|
{
|
|
if(!mlpfnDriverProc)return FailResult;
|
|
|
|
return (ReturnCode)((mlpfnDriverProc)(mDriverID,(HDRVR)DriverHandle,ICM_CONFIGURE,(LONG)hDisplayWindow,0L));
|
|
}
|
|
|
|
VideoCodec::ReturnCode VideoCodec::decompressFrame(AVIBitmap &srcAVIBitmap,AVIBitmap &dstAVIBitmap,MovieData &srcMovieData,MovieData &dstMovieData)
|
|
{
|
|
ReturnCode returnCode(FailResult);
|
|
|
|
if(!mlpfnDriverProc)return returnCode;
|
|
if(BadFormatResult==canDecompress(srcAVIBitmap))return FailResult;
|
|
if(BadFormatResult==getFormat(srcAVIBitmap))return FailResult;
|
|
if(BadFormatResult==getFormat(srcAVIBitmap,dstAVIBitmap))return FailResult;
|
|
dstMovieData.size(dstAVIBitmap.sizeImage());
|
|
if(BitmapInfo::TrueColor==dstAVIBitmap.bitCount())
|
|
{
|
|
dstAVIBitmap.bitCount(BitmapInfo::Bit8);
|
|
if(BadFormatResult==canDecompress(srcAVIBitmap,dstAVIBitmap))return FailResult;
|
|
if(OkResult!=getPalette(srcAVIBitmap,dstAVIBitmap))return FailResult;
|
|
dstMovieData.size(dstAVIBitmap.sizeImage());
|
|
}
|
|
if(BadFormatResult==icmDecompressBegin(srcAVIBitmap,dstAVIBitmap))return FailResult;
|
|
if(BadFormatResult==icmDecompress(srcAVIBitmap,dstAVIBitmap,srcMovieData,dstMovieData))return FailResult;
|
|
if(OkResult!=icmDecompressEnd())return FailResult;
|
|
return OkResult;
|
|
}
|
|
|