📄 chxphook.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 ***** */
#include "hlxclib/stdio.h"
#include "hlxclib/string.h"
#include "hxtypes.h"
#include "hxcom.h"
#include "hxcomm.h"
#include "hxbuffer.h"
#include "chxpckts.h"
#include "hxmap.h"
#include "ihxpckts.h"
#include "hxfiles.h"
#include "plghand2.h"
#include "hxcore.h"
#include "hxengin.h"
#include "hxrendr.h"
#include "chxphook.h"
#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE
static const char HX_THIS_FILE[] = __FILE__;
#endif
PacketHookManager::PacketHookManager(IHXPlayer* pPlayer)
: m_lRefCount(0)
, m_pPlayer(NULL)
, m_pPacketHook(NULL)
, m_ulTotalStreams(0)
, m_ulRecordableStreams(0)
{
if (pPlayer)
{
m_pPlayer = pPlayer;
m_pPlayer->AddRef();
}
}
PacketHookManager::~PacketHookManager()
{
HX_RELEASE(m_pPacketHook);
HX_RELEASE(m_pPlayer);
}
STDMETHODIMP
PacketHookManager::QueryInterface(REFIID riid, void**ppvObj)
{
QInterfaceList qiList[] =
{
{ GET_IIDHANDLE(IID_IHXPacketHookManager), (IHXPacketHookManager*)this },
{ GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXPacketHookManager*)this },
};
return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
}
/////////////////////////////////////////////////////////////////////////
// Method:
// IUnknown::AddRef
// Purpose:
// Everyone usually implements this the same... feel free to use
// this implementation.
//
STDMETHODIMP_(ULONG32)
PacketHookManager::AddRef()
{
return InterlockedIncrement(&m_lRefCount);
}
/////////////////////////////////////////////////////////////////////////
// Method:
// IUnknown::Release
// Purpose:
// Everyone usually implements this the same... feel free to use
// this implementation.
//
STDMETHODIMP_(ULONG32)
PacketHookManager::Release()
{
if (InterlockedDecrement(&m_lRefCount) > 0)
{
return m_lRefCount;
}
delete this;
return 0;
}
/*
* IHXPacketHookManager methods
*/
/************************************************************************
* Method:
* IHXPacketHookManager::InitHook
* Purpose:
* called by the top level client to pass the IHXPacketHook object
*/
STDMETHODIMP
PacketHookManager::InitHook (IHXPacketHook* pPacketHook)
{
HX_RESULT hr = HXR_OK;
if (!m_pPlayer || !pPacketHook)
{
return HXR_FAILED;
}
m_pPacketHook = pPacketHook;
m_pPacketHook->AddRef();
BOOL bRecordAllowed = FALSE;
UINT16 ulSources = 0;
UINT16 ulStreams = 0;
IUnknown* pUnknown = NULL;
IHXStreamSource* pSource = NULL;
IHXPrivateStreamSource *pPrivateSource = NULL; // for IsSaveAllowed, take this out; XXXCP
// caculate the total number of streams + TAC info.
if (!(ulSources = m_pPlayer->GetSourceCount()))
{
return HXR_FAILED;
}
for (UINT16 i = 0; i < ulSources; i++)
{
if (m_pPlayer->GetSource(i, pUnknown) != HXR_OK)
{
continue;
}
BOOL bIsSaveAllowed = FALSE;
if (pUnknown->QueryInterface(IID_IHXPrivateStreamSource, (void**)&pPrivateSource) == HXR_OK)
{
bIsSaveAllowed = pPrivateSource->IsSaveAllowed();
HX_RELEASE(pPrivateSource);
if (!bIsSaveAllowed)
{
HX_RELEASE(pUnknown);
continue;
}
}
if(bIsSaveAllowed)
bRecordAllowed = TRUE;
hr = pUnknown->QueryInterface(IID_IHXStreamSource, (void**)&pSource);
HX_RELEASE(pUnknown);
if (hr != HXR_OK)
{
break;
}
ulStreams = pSource->GetStreamCount();
for (UINT16 j = 0; j < ulStreams; j++)
{
IHXStream* pStream = NULL;
pSource->GetStream(j, (IUnknown*&)pStream);
UINT16 ulRenderers = pStream->GetRendererCount();
for (UINT16 k = 0; k < ulRenderers; k++)
{
IHXRenderer* pRenderer = NULL;
IHXPacketHookSink* pSink = NULL;
pStream->GetRenderer(k, (IUnknown*&)pRenderer);
if (HXR_OK == pRenderer->QueryInterface(IID_IHXPacketHookSink,
(void**)&pSink))
{
pSink->StartSink();
HX_RELEASE(pSink);
}
HX_RELEASE(pRenderer);
}
HX_RELEASE(pStream);
}
HX_RELEASE(pSource);
}
if (!bRecordAllowed)
{
hr = HXR_NO_DATA;
}
return hr;
}
/************************************************************************
* Method:
* IHXPacketHookManager::CloseHook
* Purpose:
* called by the top level client to close the hook connection
*/
STDMETHODIMP
PacketHookManager::CloseHook ()
{
HX_RESULT hr = HXR_OK;
HX_RELEASE(m_pPacketHook);
return hr;
}
/************************************************************************
* Method:
* IHXPacketHookManager::StartHook
* Purpose:
* called by the top level client to start recording
*/
STDMETHODIMP
PacketHookManager::StartHook ()
{
HX_RESULT hr = HXR_OK;
UINT16 i = 0;
UINT16 j = 0;
UINT16 k = 0;
UINT16 ulSources = 0;
UINT16 ulStreams = 0;
UINT16 ulStreamIndex = 0;
CHXBuffer* pTitle = NULL;
CHXBuffer* pAuthor = NULL;
CHXBuffer* pCopyright = NULL;
CHXHeader* pFileHeader = NULL;
CHXHeader* pStreamHeader = NULL;
IUnknown* pUnknown = NULL;
IHXPrivateStreamSource *pPrivateSource = NULL; // for IsSaveAllowed, take this out; XXXCP
IHXStreamSource* pSource = NULL;
IHXInfoLogger* pInfoLogger = NULL;
// make sure everything has been initialized
if (!m_pPlayer || !m_pPacketHook)
{
hr = HXR_FAILED;
goto cleanup;
}
// caculate the total number of streams + TAC info.
if (!(ulSources = m_pPlayer->GetSourceCount()))
{
hr = HXR_FAILED;
goto cleanup;
}
m_ulTotalStreams = 0;
for (i = 0; i < ulSources; i++)
{
if (HXR_OK != m_pPlayer->GetSource(i, pUnknown))
{
continue;
}
if (HXR_OK != pUnknown->QueryInterface(IID_IHXStreamSource, (void**)&pSource))
{
HX_RELEASE(pUnknown);
continue;
}
if (HXR_OK == pUnknown->QueryInterface(IID_IHXPrivateStreamSource, (void**)&pPrivateSource))
{
if (!(pPrivateSource->IsSaveAllowed()))
{
pPrivateSource->Release();
continue;
}
pPrivateSource->Release();
}
m_ulTotalStreams += pSource->GetStreamCount();
HX_RELEASE(pSource);
HX_RELEASE(pUnknown);
}
if (!m_ulTotalStreams)
{
hr = HXR_FAILED;
goto cleanup;
}
// prepare the file header
pTitle = new CHXBuffer();
pAuthor = new CHXBuffer();
pCopyright = new CHXBuffer();
pTitle->AddRef();
pAuthor->AddRef();
pCopyright->AddRef();
// XXX HP: find better way to collect TAC info
#define szTitle "title"
#define szAuthor "author"
#define szCopyright "copyright"
pTitle->Set((const unsigned char*)szTitle, strlen(szTitle)+1);
pAuthor->Set((const unsigned char*)szAuthor, strlen(szAuthor)+1);
pCopyright->Set((const unsigned char*)szCopyright, strlen(szCopyright)+1);
pFileHeader = new CHXHeader();
pFileHeader->AddRef();
// set attributes(i.e. num. of streams + TAC)
pFileHeader->SetPropertyBuffer("Title", pTitle);
pFileHeader->SetPropertyBuffer("Author", pAuthor);
pFileHeader->SetPropertyBuffer("Copyright", pCopyright);
pFileHeader->SetPropertyULONG32("StreamCount", m_ulTotalStreams);
// signal the top level client of upcoming content
m_pPacketHook->OnStart();
// send file header to its top level client
hr = m_pPacketHook->OnFileHeader(pFileHeader);
if (hr != HXR_OK)
{
HX_RELEASE(m_pPacketHook);
goto cleanup;
}
// prepare the stream headers
m_ulRecordableStreams = 0;
ulStreamIndex = 0;
for (i = 0; i < ulSources; i++)
{
if (HXR_OK != m_pPlayer->GetSource(i, pUnknown))
{
HX_RELEASE(pUnknown);
continue;
}
if (HXR_OK != pUnknown->QueryInterface(IID_IHXStreamSource, (void**)&pSource))
{
HX_RELEASE(pSource);
continue;
}
if (HXR_OK == pUnknown->QueryInterface(IID_IHXPrivateStreamSource, (void**)&pPrivateSource))
{
if (!(pPrivateSource->IsSaveAllowed()))
{
pPrivateSource->Release();
continue;
}
pPrivateSource->Release();
}
if (HXR_OK == pUnknown->QueryInterface(IID_IHXInfoLogger, (void**)&pInfoLogger))
{
pInfoLogger->LogInformation("RECSTART", NULL);
}
HX_RELEASE(pInfoLogger);
ulStreams = pSource->GetStreamCount();
for (j = 0; j < ulStreams; j++)
{
const char* pszPropName = NULL;
UINT16 ulRenderers = 0;
ULONG32 ulPropValue = 0;
BOOL bRecordable = FALSE;
CHXHeader* pHeader = NULL;
CHXBuffer* pPropValueSource = NULL;
CHXBuffer* pPropValueTarget = NULL;
IHXStream* pStream = NULL;
// retrieve the stream info
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -