?? hspadvisesink.cpp
字號(hào):
/* * * This software is released under the provisions of the GPL version 2. * see file "COPYING". If that file is not available, the full statement * of the license can be found at * * http://www.fsf.org/licensing/licenses/gpl.txt * * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. * Portions (c) Paul Cifarelli 2005 */#include <stdio.h>#include "hxcomm.h"#include "hxmon.h"#include "hxcore.h"#include "hxengin.h"#include "hxclsnk.h"#include "ihxpckts.h"#include "hxausvc.h"#include "helix-sp.h"#include "hspadvisesink.h"#include "utils.h"#if defined(__cplusplus)extern "C" {#endif /* defined(__cplusplus) */#if defined(__cplusplus)}#endif /* defined(__cplusplus) */HSPClientAdviceSink::HSPClientAdviceSink(IUnknown* pUnknown, LONG32 lClientIndex, HelixSimplePlayer *pSplay) : m_splayer(pSplay) , m_lRefCount (0) , m_lClientIndex (lClientIndex) , m_pUnknown (NULL) , m_pRegistry (NULL) , m_pScheduler (NULL) , m_position(0) , m_duration(0) , m_lCurrentBandwidth(0) , m_lAverageBandwidth(0) , m_bOnStop(0){ //m_splayer->bEnableAdviceSink = true; if (pUnknown) { m_pUnknown = pUnknown; m_pUnknown->AddRef(); if (HXR_OK != m_pUnknown->QueryInterface(IID_IHXRegistry, (void**)&m_pRegistry)) { m_pRegistry = NULL; } if (HXR_OK != m_pUnknown->QueryInterface(IID_IHXScheduler, (void**)&m_pScheduler)) { m_pScheduler = NULL; } IHXPlayer* pPlayer; if(HXR_OK == m_pUnknown->QueryInterface(IID_IHXPlayer, (void**)&pPlayer)) { pPlayer->AddAdviseSink(this); pPlayer->Release(); } }}HSPClientAdviceSink::~HSPClientAdviceSink(void){ if (m_pScheduler) { m_pScheduler->Release(); m_pScheduler = NULL; } if (m_pRegistry) { m_pRegistry->Release(); m_pRegistry = NULL; } if (m_pUnknown) { m_pUnknown->Release(); m_pUnknown = NULL; }}// *** IUnknown methods ***/////////////////////////////////////////////////////////////////////////// Method:// IUnknown::QueryInterface// Purpose:// Implement this to export the interfaces supported by your // object.//STDMETHODIMP HSPClientAdviceSink::QueryInterface(REFIID riid, void** ppvObj){ if (IsEqualIID(riid, IID_IUnknown)) { AddRef(); *ppvObj = (IUnknown*)(IHXClientAdviseSink*)this; return HXR_OK; } else if (IsEqualIID(riid, IID_IHXClientAdviseSink)) { AddRef(); *ppvObj = (IHXClientAdviseSink*)this; return HXR_OK; } *ppvObj = NULL; return HXR_NOINTERFACE;}/////////////////////////////////////////////////////////////////////////// Method:// IUnknown::AddRef// Purpose:// Everyone usually implements this the same... feel free to use// this implementation.//STDMETHODIMP_(ULONG32) HSPClientAdviceSink::AddRef(){ return InterlockedIncrement(&m_lRefCount);}/////////////////////////////////////////////////////////////////////////// Method:// IUnknown::Release// Purpose:// Everyone usually implements this the same... feel free to use// this implementation.//STDMETHODIMP_(ULONG32) HSPClientAdviceSink::Release(){ if (InterlockedDecrement(&m_lRefCount) > 0) { return m_lRefCount; } delete this; return 0;}/* * IHXClientAdviseSink methods *//************************************************************************ * Method: * IHXClientAdviseSink::OnPosLength * Purpose: * Called to advise the client that the position or length of the * current playback context has changed. */STDMETHODIMPHSPClientAdviceSink::OnPosLength(UINT32 ulPosition, UINT32 ulLength){ if (m_splayer->bEnableAdviceSink) { m_splayer->print2stdout("OnPosLength(%ld, %ld)\n", ulPosition, ulLength); } m_position = ulPosition; m_duration = ulLength; return HXR_OK;}/************************************************************************ * Method: * IHXClientAdviseSink::OnPresentationOpened * Purpose: * Called to advise the client a presentation has been opened. */STDMETHODIMP HSPClientAdviceSink::OnPresentationOpened(){/* if (m_splayer && m_splayer->xf().crossfading && m_lClientIndex == m_splayer->xf().toIndex) { m_splayer->print2stderr("Crossfading...\n"); m_splayer->xf().toStream = 0; m_splayer->xf().toStream = m_splayer->getAudioPlayer(m_lClientIndex)->GetAudioStream(0); if (m_splayer->xf().toStream) { m_splayer->print2stderr("Got Stream 2\n"); m_splayer->startCrossFade(); } else m_splayer->stop(m_lClientIndex); }*/ //m_splayer->bEnableAdviceSink = true; if (m_splayer->bEnableAdviceSink) { m_splayer->print2stdout("OnPresentationOpened()\n"); } return HXR_OK;}/************************************************************************ * Method: * IHXClientAdviseSink::OnPresentationClosed * Purpose: * Called to advise the client a presentation has been closed. */STDMETHODIMP HSPClientAdviceSink::OnPresentationClosed(){ if (m_splayer->bEnableAdviceSink) { m_splayer->print2stdout("OnPresentationClosed()\n"); } return HXR_OK;}void HSPClientAdviceSink::GetStatistics (char* pszRegistryKey){ char szRegistryValue[MAX_DISPLAY_NAME] = {0}; /* Flawfinder: ignore */ INT32 lValue = 0; INT32 i = 0; INT32 lStatistics = 8; UINT32 *plValue; // collect statistic for (i = 0; i < lStatistics; i++) { plValue = NULL; switch (i) { case 0: SafeSprintf(szRegistryValue, MAX_DISPLAY_NAME, "%s.Normal", pszRegistryKey); break; case 1: SafeSprintf(szRegistryValue, MAX_DISPLAY_NAME, "%s.Recovered", pszRegistryKey); break; case 2: SafeSprintf(szRegistryValue, MAX_DISPLAY_NAME, "%s.Received", pszRegistryKey); break; case 3: SafeSprintf(szRegistryValue, MAX_DISPLAY_NAME, "%s.Lost", pszRegistryKey); break; case 4: SafeSprintf(szRegistryValue, MAX_DISPLAY_NAME, "%s.Late", pszRegistryKey); break; case 5: SafeSprintf(szRegistryValue, MAX_DISPLAY_NAME, "%s.ClipBandwidth", pszRegistryKey); break; case 6: SafeSprintf(szRegistryValue, MAX_DISPLAY_NAME, "%s.AverageBandwidth", pszRegistryKey); plValue = &m_lAverageBandwidth; break; case 7: SafeSprintf(szRegistryValue, MAX_DISPLAY_NAME, "%s.CurrentBandwidth", pszRegistryKey); plValue = &m_lCurrentBandwidth; break; default: break; } m_pRegistry->GetIntByName(szRegistryValue, lValue); if (plValue) { if (m_bOnStop || lValue == 0) { lValue = *plValue; } else { *plValue = lValue; } } if (m_splayer->bEnableAdviceSink || (m_splayer->bEnableVerboseMode && m_bOnStop)) { m_splayer->print2stdout("%s = %ld\n", szRegistryValue, lValue); } }}void HSPClientAdviceSink::GetAllStatistics(void){ UINT32 unPlayerIndex = 0; UINT32 unSourceIndex = 0; UINT32 unStreamIndex = 0; const char* pszRegistryPrefix = "Statistics"; char szRegistryName[MAX_DISPLAY_NAME] = {0}; /* Flawfinder: ignore */ // display the content of whole statistic registry if (m_pRegistry) { // ok, let's start from the top (player) SafeSprintf(szRegistryName, MAX_DISPLAY_NAME, "%s.Player%ld", pszRegistryPrefix, m_lClientIndex); if (PT_COMPOSITE == m_pRegistry->GetTypeByName(szRegistryName)) { // display player statistic GetStatistics(szRegistryName); SafeSprintf(szRegistryName, MAX_DISPLAY_NAME, "%s.Source%ld", szRegistryName, unSourceIndex); while (PT_COMPOSITE == m_pRegistry->GetTypeByName(szRegistryName)) { // display source statistic GetStatistics(szRegistryName); SafeSprintf(szRegistryName, MAX_DISPLAY_NAME, "%s.Stream%ld", szRegistryName, unStreamIndex); while (PT_COMPOSITE == m_pRegistry->GetTypeByName(szRegistryName)) { // display stream statistic GetStatistics(szRegistryName); unStreamIndex++; SafeSprintf(szRegistryName, MAX_DISPLAY_NAME, "%s.Player%ld.Source%ld.Stream%ld", pszRegistryPrefix, unPlayerIndex, unSourceIndex, unStreamIndex); } unSourceIndex++; SafeSprintf(szRegistryName, MAX_DISPLAY_NAME, "%s.Player%ld.Source%ld", pszRegistryPrefix, unPlayerIndex, unSourceIndex); }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -