📄 brushff.cpp
字号:
/* ***** BEGIN LICENSE BLOCK *****
* Version: RCSL 1.0/RPSL 1.0
*
* Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
*
* The contents of this file, and the files included with this file, are
* subject to the current version of the RealNetworks Public Source License
* Version 1.0 (the "RPSL") available at
* http://www.helixcommunity.org/content/rpsl unless you have licensed
* the file under the RealNetworks Community Source License Version 1.0
* (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
* in which case the RCSL will apply. You may also obtain the license terms
* directly from RealNetworks. You may not use this file except in
* compliance with the RPSL or, if you have a valid RCSL with RealNetworks
* applicable to this file, the RCSL. Please see the applicable RPSL or
* RCSL for the rights, obligations and limitations governing use of the
* contents of the file.
*
* This file is part of the Helix DNA Technology. RealNetworks is the
* developer of the Original Code and owns the copyrights in the portions
* it created.
*
* This file, and the files included with this file, is distributed and made
* available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
*
* Technology Compatibility Kit Test Suite(s) Location:
* http://www.helixcommunity.org/content/tck
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
// system
#include <stdio.h>
// include
#include "hxcom.h"
#include "hxtypes.h"
#include "hxcomm.h"
#include "ihxpckts.h"
#include "hxfiles.h"
#include "hxformt.h"
#include "hxplugn.h"
#include "hxver.h"
// pnmisc
#include "baseobj.h"
// pxcomlib
#include "buffutil.h"
// brushff
#include "brushff.h"
#include "brushff.ver"
// pndebug
#include "errdbg.h"
#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE
static const char HX_THIS_FILE[] = __FILE__;
#endif
const char* const CBrushFileFormat::m_pszDescription = "RealNetworks Brush File Format Plugin";
const char* const CBrushFileFormat::m_pszCopyright = HXVER_COPYRIGHT;
const char* const CBrushFileFormat::m_pszMoreInfoURL = HXVER_MOREINFO;
const char* const CBrushFileFormat::m_ppszFileMimeTypes[] = {"text/brush", NULL};
const char* const CBrushFileFormat::m_ppszFileExtensions[] = {"bsh", NULL};
const char* const CBrushFileFormat::m_ppszFileOpenNames[] = {"Brush Files (*.bsh)", NULL};
const char* const CBrushFileFormat::m_pszStreamMimeType = "application/vnd.rn-brushstream";
const UINT32 CBrushFileFormat::m_ulContentVersion = HX_ENCODE_PROD_VERSION(0, 0, 0, 0);
const UINT32 CBrushFileFormat::m_ulStreamVersion = HX_ENCODE_PROD_VERSION(0, 0, 0, 0);
CBrushFileFormat::CBrushFileFormat()
{
m_lRefCount = 0;
Reset();
};
CBrushFileFormat::~CBrushFileFormat()
{
Deallocate();
};
STDMETHODIMP CBrushFileFormat::QueryInterface(REFIID riid, void** ppvObj)
{
HX_RESULT retVal = HXR_OK;
if (IsEqualIID(riid, IID_IUnknown))
{
AddRef();
*ppvObj = (IUnknown*) (IHXPlugin*) this;
}
else if (IsEqualIID(riid, IID_IHXPlugin))
{
AddRef();
*ppvObj = (IHXPlugin*) this;
}
else if (IsEqualIID(riid, IID_IHXFileFormatObject))
{
AddRef();
*ppvObj = (IHXFileFormatObject*) this;
}
else if (IsEqualIID(riid, IID_IHXFileResponse))
{
AddRef();
*ppvObj = (IHXFileResponse*) this;
}
else
{
*ppvObj = NULL;
retVal = HXR_NOINTERFACE;
}
return retVal;
}
STDMETHODIMP_(UINT32) CBrushFileFormat::AddRef()
{
return InterlockedIncrement(&m_lRefCount);
}
STDMETHODIMP_(UINT32) CBrushFileFormat::Release()
{
if (InterlockedDecrement(&m_lRefCount) > 0)
{
return m_lRefCount;
}
delete this;
return 0;
}
STDMETHODIMP CBrushFileFormat::GetPluginInfo(REF(BOOL) rbLoadMultiple,
REF(const char*) rpszDescription,
REF(const char*) rpszCopyright,
REF(const char*) rpszMoreInfoURL,
REF(UINT32) rulVersionNumber)
{
rbLoadMultiple = TRUE;
rpszDescription = (const char*) m_pszDescription;
rpszCopyright = (const char*) m_pszCopyright;
rpszMoreInfoURL = (const char*) m_pszMoreInfoURL;
rulVersionNumber = TARVER_ULONG32_VERSION;
return HXR_OK;
}
STDMETHODIMP CBrushFileFormat::InitPlugin(IUnknown* pContext)
{
HX_RESULT retVal = HXR_FAIL;
if (pContext)
{
// Clear out everything
Deallocate();
// Save a copy of the calling context
m_pContext = pContext;
m_pContext->AddRef();
// Get an interface to the common class factory
retVal = m_pContext->QueryInterface(IID_IHXCommonClassFactory,
(void**) &m_pCommonClassFactory);
if (SUCCEEDED(retVal))
{
// Set the state
m_ulState = kStatePluginInitialized;
}
}
return retVal;
}
STDMETHODIMP CBrushFileFormat::GetFileFormatInfo(REF(const char**) rppszFileMimeTypes,
REF(const char**) rppszFileExtensions,
REF(const char**) rppszFileOpenNames)
{
rppszFileMimeTypes = (const char**) m_ppszFileMimeTypes;
rppszFileExtensions = (const char**) m_ppszFileExtensions;
rppszFileOpenNames = (const char**) m_ppszFileOpenNames;
return HXR_OK;
}
STDMETHODIMP CBrushFileFormat::InitFileFormat(IHXRequest* pRequest,
IHXFormatResponse* pFormatResponse,
IHXFileObject* pFileObject)
{
HX_RESULT retVal = HXR_OK;
if (pRequest && pFormatResponse && pFileObject)
{
if (m_ulState == kStatePluginInitialized)
{
// Find out from the 822 headers if this
// is a NULL brush
m_bNullBrush = IsNullBrush(pRequest);
// Save members
HX_RELEASE(m_pFormatResponse);
m_pFormatResponse = pFormatResponse;
m_pFormatResponse->AddRef();
HX_RELEASE(m_pFileObject);
m_pFileObject = pFileObject;
m_pFileObject->AddRef();
// Set the state
m_ulState = kStateFileInitPending;
// Init the file object
m_pFileObject->Init(HX_FILE_READ | HX_FILE_BINARY, this);
}
else
{
retVal = HXR_UNEXPECTED;
}
}
else
{
retVal = HXR_FAIL;
}
if (FAILED(retVal) && pFormatResponse)
{
pFormatResponse->InitDone(retVal);
}
return retVal;
}
STDMETHODIMP CBrushFileFormat::GetFileHeader()
{
HX_RESULT retVal = HXR_OK;
if (m_ulState == kStateFileFormatInitialized)
{
// Get an IHXValues object
IHXValues* pFileHeader = NULL;
retVal = m_pCommonClassFactory->CreateInstance(CLSID_IHXValues,
(void**) &pFileHeader);
if (SUCCEEDED(retVal))
{
// Set the stream count
pFileHeader->SetPropertyULONG32("StreamCount", 1);
pFileHeader->SetPropertyULONG32("IsRealDataType", 1);
// Set the new state
m_ulState = kStateFileHeaderSent;
// Call the response interface
m_pFormatResponse->FileHeaderReady(HXR_OK, pFileHeader);
}
HX_RELEASE(pFileHeader);
if (FAILED(retVal))
{
m_pFormatResponse->FileHeaderReady(retVal, NULL);
}
}
else
{
retVal = HXR_UNEXPECTED;
}
return retVal;
}
STDMETHODIMP CBrushFileFormat::GetStreamHeader(UINT16 usStreamNum)
{
HX_RESULT retVal = HXR_OK;
if (m_ulState == kStateFileHeaderSent)
{
// Create an IHXValues object
IHXValues* pStreamHeader = NULL;
retVal = m_pCommonClassFactory->CreateInstance(CLSID_IHXValues,
(void**) &pStreamHeader);
if (SUCCEEDED(retVal))
{
// Create mime type IHXBuffer string
IHXBuffer* pMimeStr = NULL;
retVal = PXUtilities::CreateStringBuffer((const char*) m_pszStreamMimeType,
m_pContext,
pMimeStr);
if (SUCCEEDED(retVal))
{
// Create intrinsic duration type string buffer
IHXBuffer* pIntrin = NULL;
retVal = PXUtilities::CreateStringBuffer("intrinsicDurationDiscrete",
m_pContext,
pIntrin);
if (SUCCEEDED(retVal))
{
// Create ASM rulebook string buffer
char szASM[64]; /* Flawfinder: ignore */
sprintf(szASM, "AverageBandwidth=%lu,Priority=5;", kDefaultBitrate); /* Flawfinder: ignore */
IHXBuffer* pASM = NULL;
retVal = PXUtilities::CreateStringBuffer((const char*) szASM,
m_pContext, pASM);
if (SUCCEEDED(retVal))
{
// Set the properties
pStreamHeader->SetPropertyULONG32("StreamNumber", 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -