vidrend.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 2,506 行 · 第 1/5 页

CPP
2,506
字号
    {
    case HX_SURFACE_UPDATE:
	m_pVSMutex->Lock();
	retVal = UpdateDisplay(pEvent, TRUE);
	m_pVSMutex->Unlock();
	break;

#if defined(HELIX_FEATURE_VIDREND_OPTIMIZEDVIDEO)
    case HX_SURFACE_MODE_CHANGE:
	switch ((int) pEvent->param2)
	{
	case HX_VIDEOSURFACE1_RECOMMENDED:
	    pEvent->result = SwitchToVideoSurface1();

	    if (SUCCEEDED(pEvent->result))
	    {
		pEvent->handled = TRUE;
	    }
	    break;

	case HX_VIDEOSURFACE1_NOT_RECOMMENDED:
	    pEvent->result = SwitchToVideoSurface2();

	    if (SUCCEEDED(pEvent->result))
	    {
		pEvent->handled = TRUE;
	    }
	    break;

	default:
	    HX_ASSERT(FALSE);
	    break;
	}
	break;
#endif	// HELIX_FEATURE_VIDREND_OPTIMIZEDVIDEO

    default:
	// nothing to do
	break;
    }

    return retVal;
}

// *** IUnknown methods ***

/****************************************************************************
*  IUnknown::AddRef                                            ref:  hxcom.h
*
*  This routine increases the object reference count in a thread safe
*  manner. The reference count is used to manage the lifetime of an object.
*  This method must be explicitly called by the user whenever a new
*  reference to an object is used.
*/
STDMETHODIMP_(ULONG32) CVideoRenderer::AddRef()
{
    return InterlockedIncrement(&m_lRefCount);
}

/****************************************************************************
*  IUnknown::Release                                           ref:  hxcom.h
*
*  This routine decreases the object reference count in a thread safe
*  manner, and deletes the object if no more references to it exist. It must
*  be called explicitly by the user whenever an object is no longer needed.
*/
STDMETHODIMP_(ULONG32) CVideoRenderer::Release()
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
        return m_lRefCount;
    }

    delete this;
    return 0;
}

/****************************************************************************
*  IUnknown::QueryInterface                                    ref:  hxcom.h
*
*  This routine indicates which interfaces this object supports. If a given
*  interface is supported, the object's reference count is incremented, and
*  a reference to that interface is returned. Otherwise a NULL object and
*  error code are returned. This method is called by other objects to
*  discover the functionality of this object.
*/
STDMETHODIMP CVideoRenderer::QueryInterface(REFIID riid, void** ppvObj)
{
    QInterfaceList  qiList[] =
    {
	{ GET_IIDHANDLE(IID_IHXCallback), (IHXCallback*)this},
	{ GET_IIDHANDLE(IID_IHXInterruptSafe), (IHXInterruptSafe*)this},
	{ GET_IIDHANDLE(IID_IHXUpdateProperties), (IHXUpdateProperties*)this},
	{ GET_IIDHANDLE(IID_IHXRenderTimeLine), (IHXRenderTimeLine*)this},

#ifdef HELIX_FEATURE_VIDREND_UNTIMED_DECODE

	{ GET_IIDHANDLE(IID_IHXUntimedRenderer), (IHXUntimedRenderer*)this},

#endif

	{ GET_IIDHANDLE(IID_IHXPaceMakerResponse), (IHXPaceMakerResponse*)this},
	{ GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXPlugin*) this},
	{ GET_IIDHANDLE(IID_IHXPlugin), (IHXPlugin*)this},
	{ GET_IIDHANDLE(IID_IHXRenderer), (IHXRenderer*)this},
	{ GET_IIDHANDLE(IID_IHXSiteUser), (IHXSiteUser*)this},
	{ GET_IIDHANDLE(IID_IHXStatistics), (IHXStatistics*)this},
    };

    if (QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj) == HXR_OK)
    {
	return HXR_OK ;
    }
    else if (m_pMISUS && IsEqualIID(riid, IID_IHXSiteUserSupplier))
    {
	return m_pMISUS->QueryInterface(IID_IHXSiteUserSupplier,ppvObj);
    }
    else
    {
	*ppvObj = NULL;
	return HXR_NOINTERFACE;
    }
}


/****************************************************************************
 *  Renderer's customizable fuctions - can be called any time
 */
/****************************************************************************
 *  GetStreamVersion
 */
void CVideoRenderer::GetStreamVersion(ULONG32 &ulThisMajorVersion,
					      ULONG32 &ulThisMinorVersion)
{
    ulThisMajorVersion = STREAM_MAJOR_VERSION;
    ulThisMinorVersion = STREAM_MINOR_VERSION;
}

/****************************************************************************
 *  GetContentVersion
 */
void CVideoRenderer::GetContentVersion(ULONG32 &ulThisMajorVersion,
					       ULONG32 &ulThisMinorVersion)
{
    ulThisMajorVersion = CONTENT_MAJOR_VERSION;
    ulThisMinorVersion = CONTENT_MINOR_VERSION;
}

/****************************************************************************
 *  GetUpgradeMimeType
 */
const char* CVideoRenderer::GetUpgradeMimeType(void)
{
    const char** pStreamMimeTypes = NULL;
    UINT32 ulInitialGranularity;

    GetRendererInfo(pStreamMimeTypes, ulInitialGranularity);

    if (pStreamMimeTypes)
    {
	return pStreamMimeTypes[0];
    }

    return NULL;
}

/****************************************************************************
 *  GetRendererName
 */
const char* CVideoRenderer::GetRendererName(void)
{
    return BASE_VIDEO_RENDERER_NAME;
}

/****************************************************************************
 *  GetCodecName
 */
const char* CVideoRenderer::GetCodecName(void)
{
    return NULL;
}

/****************************************************************************
 *  GetCodecFourCC
 */
const char* CVideoRenderer::GetCodecFourCC(void)
{
    return NULL;
}

/****************************************************************************
 *  GetLateFrameTolerance
 */
ULONG32 CVideoRenderer::GetLateFrameTolerance(void)
{
    return LATE_FRAME_TOL;
}

/****************************************************************************
 *  GetEarlyFrameTolerance
 */
ULONG32 CVideoRenderer::GetEarlyFrameTolerance(void)
{
    return EARLY_FRAME_TOL;
}

/****************************************************************************
 *  GetMaxOptimizedVideoLead
 */
ULONG32 CVideoRenderer::GetMaxOptimizedVideoLead(void)
{
    return MAX_OPTIMIZED_VIDEO_LEAD;
}

/****************************************************************************
 *  GetBltPacketQueueSize
 */
ULONG32 CVideoRenderer::GetBltPacketQueueSize(void)
{
    ULONG32 ulSize = BLT_PACKET_QUEUE_SIZE;

    if (m_pVideoFormat)
    {
	m_pVideoFormat->GetMaxDecodedFrames();
    }

    return ulSize;
}

/****************************************************************************
 *  GetSyncGoalSmoothingDepth
 */
ULONG32 CVideoRenderer::GetSyncGoalSmoothingDepth(void)
{
    return SYNC_GOAL_SMOOTHING_DEPTH;
}

/****************************************************************************
 *  GetSpeedupGoalSmoothingDepth
 */
ULONG32 CVideoRenderer::GetSpeedupGoalSmoothingDepth(void)
{
    return SPEEDUP_GOAL_SMOOTHING_DEPTH;
}

/****************************************************************************
 *  GetNoFramesPollingInterval
 */
ULONG32 CVideoRenderer::GetNoFramesPollingInterval(void)
{
    return NO_FRAMES_POLLING_INTERVAL;
}

/****************************************************************************
 *  GetMaxSleepTime
 */
ULONG32 CVideoRenderer::GetMaxSleepTime(void)
{
    return m_ulMaxSleepTime;
}


/****************************************************************************
 *  GetMaxSleepTime
 */
ULONG32 CVideoRenderer::GetMaxBadSeqSamples(void)
{
    return MAX_BAD_SAMPLE_INTERVAL / m_ulSyncInterval;
}


/****************************************************************************
 *  GetDecodePriority
 */
LONG32 CVideoRenderer::GetDecodePriority(void)
{
    return m_lDecodePriority;
}


HX_RESULT CVideoRenderer::SetDecodePriority(LONG32 lPriority)
{
    HX_RESULT retVal = HXR_OK;

    if (m_pDecoderPump)
    {
	retVal = m_pDecoderPump->SetPriority(lPriority);
    }

    if (SUCCEEDED(retVal))
    {
	m_lDecodePriority = lPriority;
    }

    return retVal;
}


/****************************************************************************
 *  CreateFormatObject
 */
CVideoFormat* CVideoRenderer::CreateFormatObject(IHXValues* pHeader)
{
    return new CVideoFormat(m_pCommonClassFactory,
			    this);
}

/****************************************************************************
 *  SetupBitmapDefaults
 */
void CVideoRenderer::SetupBitmapDefaults(IHXValues* pHeader,
					   HXBitmapInfoHeader &bitmapInfoHeader)
{
    // size calculation is taken from crvvideo
    bitmapInfoHeader.biSize = sizeof (HXBitmapInfoHeader);
    bitmapInfoHeader.biWidth = 0; // 352;	// unknown
    bitmapInfoHeader.biHeight = 0; // 288;	// unknown
    bitmapInfoHeader.biPlanes = 1;
    bitmapInfoHeader.biBitCount = 24;
    bitmapInfoHeader.biCompression = HX_I420;
    bitmapInfoHeader.biSizeImage = bitmapInfoHeader.biWidth *
				     bitmapInfoHeader.biHeight *
				     bitmapInfoHeader.biBitCount /
				     8;
    bitmapInfoHeader.biXPelsPerMeter = 0;
    bitmapInfoHeader.biYPelsPerMeter = 0;
    bitmapInfoHeader.biClrUsed = 0;
    bitmapInfoHeader.biClrImportant = 0;
    bitmapInfoHeader.rcolor	= 0;
    bitmapInfoHeader.gcolor	= 0;
    bitmapInfoHeader.bcolor	= 0;
}

/****************************************************************************
 *  FormatAndSetViewFrame
 */
void CVideoRenderer::FormatAndSetViewFrame(HXxRect* pClipRect,
					   HXBitmapInfoHeader &bitmapInfoHeader,
					   HXxRect &rViewRect,
					   BOOL bMutex)
{
    BOOL bAsDefault = TRUE;
    HXxSize szViewFrame;

    if (bMutex)
    {
	DisplayMutex_Lock();
    }

    if (pClipRect)
    {
	rViewRect = *pClipRect;

	// Insure the ViewRect is inside the bitmap Rect
	// Clip x
	rViewRect.left = (rViewRect.left > 0) ?
	    rViewRect.left : 0;
	rViewRect.right = (rViewRect.right > 0) ?
	    rViewRect.right : 0;
	rViewRect.left = (rViewRect.left < bitmapInfoHeader.biWidth) ?
	    rViewRect.left : bitmapInfoHeader.biWidth;
	rViewRect.right = (rViewRect.right < bitmapInfoHeader.biWidth) ?
	    rViewRect.right : bitmapInfoHeader.biWidth;

	// Clip y
	rViewRect.top = (rViewRect.top > 0) ?
	    rViewRect.top : 0;
	rViewRect.bottom = (rViewRect.bottom > 0) ?
	    rViewRect.bottom : 0;
	rViewRect.top = (rViewRect.top < bitmapInfoHeader.biHeight) ?
	    rViewRect.top : bitmapInfoHeader.biHeight;
	rViewRect.bottom = (rViewRect.bottom < bitmapInfoHeader.biHeight) ?
	    rViewRect.bottom : bitmapInfoHeader.biHeight;
    }
    else
    {
	rViewRect.left = 0;
	rViewRect.top = 0;
	rViewRect.right = bitmapInfoHeader.biWidth;
	rViewRect.bottom = bitmapInfoHeader.biHeight;
    }

    // Compute Size
    szViewFrame.cx = rViewRect.right - rViewRect.left;
    szViewFrame.cy = rViewRect.bottom - rViewRect.top;

    if ((szViewFrame.cx <= 0) || (szViewFrame.cy <= 0))
    {
	if (m_pClipRect)
	{
	    szViewFrame.cx = m_pClipRect->right - m_pClipRect->left;
	    szViewFrame.cy = m_pClipRect->bottom - m_pClipRect->top;
	}

	if ((szViewFrame.cx <= 0) || (szViewFrame.cy <= 0))
	{
	    szViewFrame.cx = DEFAULT_WIN_SIZE_X;
	    szViewFrame.cy = DEFAULT_WIN_SIZE_Y;
	}
    }

    if (m_pClipRect)
    {
	bAsDefault = FALSE;
    }

    _ResizeViewFrame(szViewFrame, FALSE, TRUE, bAsDefault);

    if (bMutex)
    {
	DisplayMutex_Unlock();
    }
}


/****************************************************************************
 *  ResizeViewFrame
 */
BOOL CVideoRenderer::ResizeViewFrame(HXxSize szViewFrame,
				     BOOL bMutex)
{
    HX_RESULT retVal;

    retVal = _ResizeViewFrame(szViewFrame,
			      bMutex,
			      FALSE,
			      FALSE);

    return retVal;
}

BOOL CVideoRenderer::_ResizeViewFrame(HXxSize szViewFrame,
				      BOOL bMutex,
				      BOOL bForceSyncResize,
				      BOOL bAsDefault)
{
    BOOL bRetVal = FALSE;

    if (m_bFrameSizeInitialized)
    {
	return bRetVal;
    }

    if (bMutex)
    {
	DisplayMutex_Lock();
    }

    if (!m_bFrameSizeInitialized)
    {
	// If window size is already set, ignore further attempts to
	// resize
	if (m_bWinSizeFixed)
	{
	    szViewFrame.cx = m_SetWinSize.cx;
	    szViewFrame.cy = m_SetWinSize.cy;
	}

	// If resulting size invalid, default to cliprect or bitmap size
	if ((szViewFrame.cx <= 0) || (szViewFrame.cy <= 0))
	{
	    if (((szViewFrame.cx <= 0) || (szViewFrame.cy <= 0)) &&
		m_pClipRect)
	    {
		szViewFrame.cx = m_pClipRect->right - m_pClipRect->left;
		szViewFrame.cy = m_pClipRect->bottom - m_pClipRect->top;
	    }

	    if ((szViewFrame.cx <= 0) || (szViewFrame.cy <= 0))
	    {
		szViewFrame.cx = m_BitmapInfoHeader.biWidth;
		szViewFrame.cy = m_BitmapInfoHeader.biHeight;
	    }
	}

	m_SetWinSize.cx = szViewFrame.cx;
	m_SetWinSize.cy = szViewFrame.cy;

#if !defined(HELIX_FEATURE_VIDREND_DYNAMIC_RESIZE)
	m_bWinSizeFixed = (m_bWinSizeFixed || (!bAsDefault));
#else
        HX_ASSERT(!m_bWinSizeFixed);
#endif

#ifdef RESIZE_AFTER_SITE_ATTACHED
	if (m_bSiteAttached)
#endif	// RESIZE_AFTER_SITE_ATTACHED
	{
#ifdef SET_NONZERO_VIEWFRAME_ONLY
	    if ((szViewFrame.cx > 0) && (szViewFrame.cy > 0))
#endif	// SET_NONZERO_VIEWFRAME_ONLY
	    {
#ifdef SYNC_RESIZE_OK
		bForceSyncResize = TRUE;
#endif	// SYNC_RESIZE_OK

		if ((m_LastSetSize.cx != szViewFrame.cx) ||
		    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?