void CProgressiveDownloadMonitor::MonitorFileSize() { MLOG_PD(NULL, "CProgressiveDownloadMonitor::MonitorFileSize() this=0x%08x tick=%lu\n", this, HX_GET_BETTERTICKCOUNT()); // Save the current m_bIsProgressive value HXBOOL bTmp = m_bIsProgressive; // Get the file size and tick count UINT32 ulFileSize = GetFileSizeNow(); UINT32 ulTick = HX_GET_BETTERTICKCOUNT(); // Is the file size the same as m_ulLastFileSize? if (ulFileSize != m_ulLastFileSize) { MLOG_PD(NULL, "\tNewFileSize=%lu\n", ulFileSize); // The filesize has changed, so we know // this file is progressive m_bIsProgressive = TRUE; // Reset the former progressive retry count to // its initial value m_ulFormerProgRetryCount = m_ulFormerProgRetryInit; // Reset the not progressive retry count to // its initial value m_ulNotProgRetryCount = m_ulNotProgRetryInit; // If the file size is different even once, // then this file has a history of being progressive. // We keep this variable around in addition to // m_bIsProgressive since m_bIsProgressive can change // when the file finishes downloading or when the // download agent pauses. Since we want to treat files // which have a history of being progressive differently // than files which don't, we need to keep m_bHasBeenProgressive. m_bHasBeenProgressive = TRUE; // Update the last file size m_ulLastFileSize = ulFileSize; // Update the tick count m_ulTickAtLastFileSize = ulTick; } else { // The filesize is the same. How // long has it been the same? UINT32 ulDiff = CALCULATE_ELAPSED_TICKS(m_ulTickAtLastFileSize, ulTick); // If the file size has been the // same for at least m_ulFinishedTime // milliseconds, then we assume it has // finished downloading if (ulDiff > m_ulFinishedTime && m_bIsProgressive) { MLOG_PD(NULL, "\tFile has been %lu bytes for %lu ms. DECLARING FINISHED.\n", ulFileSize, ulDiff); m_bIsProgressive = FALSE; } } // Did the value of m_bIsProgressive change? if (bTmp != m_bIsProgressive) { // Update the registry statistics UpdateRegistryStats(); } }
int main(int argc, char* argv[]) { int ret = 0; unsigned int numCycles = DFLT_NUM_CYCLES; unsigned int base1 = DFLT_BASE1; unsigned int base2 = DFLT_BASE2; unsigned int step = DFLT_STEP; if (argc >= 2) { ret = -1; if (UTParamUtil::GetUInt(argv[1], numCycles)) { ret = 0; } } if (ret == 0) { CHXTimestampConverter tsConverter; unsigned int base1TS = 0; unsigned int base2TS = 0; unsigned int cycleCounter = numCycles; UINT32 t1; UINT32 t2; UINT32 dt; tsConverter.ReInit(CHXTimestampConverter::FACTORS, base1, base2); t1 = HX_GET_BETTERTICKCOUNT(); for (; cycleCounter != 0; cycleCounter--) { base2TS = tsConverter.hxa2rtp(base1TS); base1TS += step; } t2 = HX_GET_BETTERTICKCOUNT(); dt = t2 - t1; DPRINTF(D_INFO, ("%s: %u cycle completed in %u ms\n", argv[0], numCycles, dt)); DPRINTF(D_INFO, ("%s: Last converted TS = %u\n", argv[0], base2TS)); } else { DPRINTF(D_ERROR, ("%s: Invalid Input. Usage: %s [cycles]", argv[0], argv[0])); } return ret; }
HX_RESULT CProgressiveDownloadMonitor::BeginSizeMonitoring() { HX_RESULT retVal = HXR_FAIL; // Create the stat callback if it doesn't // already exist if (!m_pStatCallback) { m_pStatCallback = new CHXGenericCallback(this, CProgressiveDownloadMonitor::StatCallback); if (m_pStatCallback) { m_pStatCallback->AddRef(); } } if (m_pStatCallback) { // Clear the return value retVal = HXR_OK; // Do we already have a callback scheduled? If so, // then we have already begun size monitoring. if (!m_pStatCallback->IsCallbackPending()) { // Initialize the progressive state variables m_ulLastFileSize = GetFileSizeNow(); m_ulTickAtLastFileSize = HX_GET_BETTERTICKCOUNT(); m_ulCurStatInterval = PROGDOWN_STAT_INTERVAL_INITIAL; // Kick off the callbacks, if monitoring is enabled ScheduleStatCallback(); } } return retVal; }
HX_RESULT CProgressiveDownloadMonitor::ScheduleCallback() { MLOG_PD(NULL, "CProgressiveDownloadMonitor::ScheduleCallback() this=0x%08x tick=%lu\n", this, HX_GET_BETTERTICKCOUNT()); HX_RESULT retVal = HXR_FAIL; if (m_pScheduler) { if (!m_pProgCallback) { m_pProgCallback = new CHXGenericCallback(this, CProgressiveDownloadMonitor::ProgCallback); if (m_pProgCallback) { m_pProgCallback->AddRef(); } } if (m_pProgCallback) { // Clear the return value retVal = HXR_OK; // Do we already have a callback pending? if (!m_pProgCallback->IsCallbackPending()) { // No callback pending, schedule one m_pProgCallback->ScheduleRelative(m_pScheduler, m_ulProgCallbackInterval); } } } return retVal; }
HX_RESULT CProgressiveDownloadMonitor::Init(IUnknown* pContext, IHXDataFile* pFile, CProgressiveDownloadMonitorResponse* pResponse) { MLOG_PD(NULL, "CProgressiveDownloadMonitor::Init() this=0x%08x\n", this); HX_RESULT retVal = HXR_FAIL; if (pContext && pFile && pResponse) { // Clear out any current state Close(); // Save the context m_pContext = pContext; m_pContext->AddRef(); // Save the file m_pDataFile = pFile; // XXXMEH - We will not AddRef the IHXDataFile for now, because // some users of the IHXFileObject do not call IHXFileObject::Close() // before releasing the file object. If that is the case, then // the IHXDataFile never destructs. If we ever exhaustively go through // and verify that all users of smplfsys correctly call ::Close(), // then we can remove the commented-out AddRef(). // m_pDataFile->AddRef(); // Save the response pointer m_pResponse = pResponse; m_pResponse->AddRef(); // Get the schedule interface retVal = m_pContext->QueryInterface(IID_IHXScheduler, (void**) &m_pScheduler); if (SUCCEEDED(retVal)) { // Get the IHXRegistry interface m_pContext->QueryInterface(IID_IHXRegistry, (void**) &m_pRegistry); // Check preferences to see if alternate values // for stat callback interval, fail callback interval // and finished duration are specified CheckPreferenceValues(m_bMonitorEnabled, m_ulStatCallbackInterval, m_ulProgCallbackInterval, m_ulFinishedTime, m_ulFormerProgRetryInit, m_ulNotProgRetryInit); // Initialize the progressive state variables m_ulLastFileSize = GetFileSizeNow(); m_ulTickAtLastFileSize = HX_GET_BETTERTICKCOUNT(); // Initialize the number of times to retry // if the file has not been progressive m_ulNotProgRetryCount = m_ulNotProgRetryInit; // Init the registry stats InitRegistryStats(); } } return retVal; }
WebkitClientAdviseSink::WebkitClientAdviseSink(IUnknown* pUnknown, WebkitClientContext* pContext) : m_lRefCount(0) , m_pUnknown(NULL) , m_pRegistry(NULL) , m_pPlayer(NULL) , m_bOpened(FALSE) , m_bPrepared(FALSE) , m_bSendPlayBackComplete(FALSE) , m_lDuration(-1) , m_ulFileDurationFromHeader(0) , m_ulPos(0) , m_pWebkitContext(NULL) , m_ulStartTime(0) , m_ulWidth(0) , m_ulHeight(0) , m_bIsLiveOrAdaptiveHTTP(FALSE) { m_pWebkitContext = pContext; m_pUnknown = pUnknown; HX_ADDREF(m_pWebkitContext); HX_ADDREF(m_pUnknown); if (m_pUnknown) { m_pUnknown->QueryInterface(IID_IHXRegistry, (void**)&m_pRegistry); m_pUnknown->QueryInterface(IID_IHXPlayer, (void**)&m_pPlayer); } if (m_pPlayer) { IHXGroupManager* pGroupMgr = NULL; if(HXR_OK == m_pPlayer->QueryInterface(IID_IHXGroupManager, (void**)&pGroupMgr)) { pGroupMgr->AddSink((IHXGroupSink*)this); HX_RELEASE(pGroupMgr); } IHXClientStateAdviseSinkControl* pControl=NULL; if(HXR_OK == m_pPlayer->QueryInterface(IID_IHXClientStateAdviseSinkControl, (void**)&pControl)) { pControl->AddClientStateAdviseSink(this); HX_RELEASE(pControl); } HX_RESULT retVal = HXR_FAIL; retVal = m_pPlayer->AddAdviseSink((IHXClientAdviseSink*)this); m_ulStartTime = HX_GET_BETTERTICKCOUNT(); printf("HelixOverWebkit [%s] [%s] [%d] WebkitClientAdviseSink::AddAdviseSink() returned %d\n", __FILE__, __FUNCTION__, __LINE__, retVal); } }
void CProgressiveDownloadMonitor::ProgCallback(void* pArg) { MLOG_PD(NULL, "CProgressiveDownloadMonitor::ProgCallback(0x%08x) tick=%lu\n", pArg, HX_GET_BETTERTICKCOUNT()); if (pArg) { CProgressiveDownloadMonitor* pObj = (CProgressiveDownloadMonitor*) pArg; if (pObj->m_pResponse) { pObj->m_pResponse->ProgressiveCallback(); } } }