⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pxpngff.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
}STDMETHODIMP PXPNGFileFormat::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            IHXBuffer* pMimeStr = NULL;            retVal = m_pCommonClassFactory->CreateInstance(CLSID_IHXBuffer,                                                           (void **) &pMimeStr);            if (SUCCEEDED(retVal))            {                // Fill in the mime type                retVal = pMimeStr->Set((const BYTE*) m_pszStreamMimeType,                                       strlen(m_pszStreamMimeType) + 1);                if (SUCCEEDED(retVal))                {                    // Create an opaque data buffer object                    IHXBuffer* pOpaque = NULL;                    retVal = m_pCommonClassFactory->CreateInstance(CLSID_IHXBuffer,                                                                   (void**) &pOpaque);		    IHXBuffer* pIntrinsicDurationType = NULL;		    if (SUCCEEDED(retVal))		    {			// /Create intrinsicDurationType IHXBuffer:			retVal= m_pCommonClassFactory->CreateInstance(				CLSID_IHXBuffer,				(void **) &pIntrinsicDurationType);			if (SUCCEEDED(retVal))			{			    // /This is a "discrete" media stream; it has no			    // intrinsic (native) duration; we want to			    // continue declaring 5000 for the duration,			    // however, since we may be serving this stream			    // to an old, SMIL 1.0 presentation or as a			    // stand-alone play in which the author expects			    // the old 5000-msec duration:			    retVal = pIntrinsicDurationType->Set(				  (const BYTE*)"intrinsicDurationDiscrete",				  strlen("intrinsicDurationDiscrete") + 1);			}		    }                    if (SUCCEEDED(retVal))                    {                        // Compute the size of the opaque buffer                        UINT32 ulOpaqueSize = 4 + // image width                                              4 + // image height                                              4 + // number of packets                                              4 + // background color                                              2 + // url buffer size                                              (m_pURLStr ? m_pURLStr->GetSize() : 0); // url buffer                        // Set the size of the opaque buffer                        retVal = pOpaque->SetSize(ulOpaqueSize);                        if (SUCCEEDED(retVal))                        {                            // Pack the opaque data                            BYTE* pBuf = pOpaque->GetBuffer();                            Pack32(pBuf, m_ulImageWidth);                            Pack32(pBuf, m_ulImageHeight);                            Pack32(pBuf, m_ulNumPacketBuffers);                            Pack32(pBuf, m_ulBackgroundColor);                            Pack16(pBuf, (UINT16) (m_pURLStr ? m_pURLStr->GetSize() : 0));                            if (m_pURLStr)                            {                                memcpy(pBuf, m_pURLStr->GetBuffer(), m_pURLStr->GetSize()); /* Flawfinder: ignore */                            }                            // Create ASM rulebook string                            char szASM[256]; /* Flawfinder: ignore */                            if (m_bReliable)                            {                                sprintf(szASM, "AverageBandwidth=%lu,Priority=10;", m_ulBitrate); /* Flawfinder: ignore */                            }                            else                            {                                // XXXMEH-TODO: compute % of high priority packets                                sprintf(szASM, /* Flawfinder: ignore */                                        "AverageBandwidth=%lu,Priority=5;AverageBandwidth=0,Priority=10;",                                        m_ulBitrate);                            }                            // Create ASM rulebook buffer                            IHXBuffer* pASMStr = NULL;                            retVal = m_pCommonClassFactory->CreateInstance(CLSID_IHXBuffer,                                                                           (void**) &pASMStr);                            if (SUCCEEDED(retVal))                            {                                retVal = pASMStr->Set((const BYTE*) szASM,                                                      (UINT32) strlen(szASM) + 1);                                if (SUCCEEDED(retVal))                                {                                    // Set the properties                                    pStreamHeader->SetPropertyBuffer ("OpaqueData",       pOpaque);                                    pStreamHeader->SetPropertyULONG32("StreamNumber",     0);                                    pStreamHeader->SetPropertyULONG32("MaxBitRate",       m_ulBitrate);                                    pStreamHeader->SetPropertyULONG32("AvgBitRate",       m_ulBitrate);                                    pStreamHeader->SetPropertyULONG32("MaxPacketSize",    m_ulMaxPacketSize);                                    pStreamHeader->SetPropertyULONG32("AvgPacketSize",    m_ulAvgPacketSize);                                    pStreamHeader->SetPropertyULONG32("StartTime",        0);                                    pStreamHeader->SetPropertyULONG32("PreDataAtStart",   1);                                    pStreamHeader->SetPropertyULONG32("PreRollAfterSeek", 1);                                    pStreamHeader->SetPropertyULONG32("PreData",          m_ulTotalBytesToSend);                                    pStreamHeader->SetPropertyULONG32("PreRoll",          kDefaultPreroll);                                    pStreamHeader->SetPropertyULONG32("Duration",         m_ulDuration);                                    pStreamHeader->SetPropertyCString("MimeType",         pMimeStr);                                    pStreamHeader->SetPropertyULONG32("ContentVersion",   m_ulContentVersion);                                    pStreamHeader->SetPropertyCString("ASMRuleBook",      pASMStr);                                    pStreamHeader->SetPropertyULONG32("StreamVersion",    m_ulStreamVersion);                                    // We need to declare that this is a                                    // discrete media type so that the SMIL 2                                    // renderer can treat it as such.  We                                    // don't want to just set the duration to                                    // 0 for this as that would break old SMIL                                    // 1.0 and non-SMIL content when someone                                    // switched image servers to include a new                                    // build of this png file format plug-in:                                    pStreamHeader->SetPropertyCString("intrinsicDurationType",                                                                      pIntrinsicDurationType);                                    // Set the new state                                    m_ulState = kStateStreamHeaderSent;                                    // Reset the next packet counter                                    m_ulNextPacketIndex = 0;                                    // Pass the stream header back to the server                                    m_pFormatResponse->StreamHeaderReady(HXR_OK, pStreamHeader);                                }                            }                            HX_RELEASE(pASMStr);                        }                    }                    HX_RELEASE(pOpaque);		    HX_RELEASE(pIntrinsicDurationType);                }            }            HX_RELEASE(pMimeStr);        }        HX_RELEASE(pStreamHeader);        if (FAILED(retVal))        {            m_pFormatResponse->StreamHeaderReady(retVal, NULL);        }    }    else    {        retVal = HXR_UNEXPECTED;    }    return retVal;}STDMETHODIMP PXPNGFileFormat::GetPacket(UINT16 usStreamNum){    HX_RESULT retVal = HXR_OK;    if (m_ulState == kStateStreamHeaderSent)    {        if (usStreamNum == 0)        {            if (m_ulNextPacketIndex < m_ulNumPacketBuffers)            {                // Get the opaque buffer from the array                IHXBuffer* pBuffer = m_ppPacketBuffer[m_ulNextPacketIndex];                if (pBuffer)                {                    // AddRef the buffer                    pBuffer->AddRef();                    // Create an IHXPacket                    IHXPacket* pPacket = NULL;                    retVal              = m_pCommonClassFactory->CreateInstance(CLSID_IHXPacket,                                                                                (void**) &pPacket);                    if (SUCCEEDED(retVal))                    {                        // Set the values in the packet                        // We use ASM rule 1 if this is the first packet; otherwise                        // we rule ASM rule 0                        UINT16 usASMRule = (UINT16) (m_ulNextPacketIndex ? 0 : 1);                        retVal = pPacket->Set(pBuffer,           // opaque data                                              0,                 // time stamp                                              0,                 // stream 0                                              HX_ASM_SWITCH_ON, // ASM flag                                              usASMRule);        // ASM rule                        if (SUCCEEDED(retVal))                        {                            // Increment the packet counter                            m_ulNextPacketIndex++;                            // Return the packet                            m_pFormatResponse->PacketReady(HXR_OK, pPacket);                        }                    }                    HX_RELEASE(pPacket);                }                HX_RELEASE(pBuffer);            }            else            {                // We're finished                m_pFormatResponse->StreamDone(0);            }        }        else        {            retVal = HXR_INVALID_PARAMETER;        }    }    else    {        retVal = HXR_UNEXPECTED;    }    return retVal;}STDMETHODIMP PXPNGFileFormat::Seek(UINT32 ulOffset){    HX_RESULT retVal = HXR_OK;    if (m_pFormatResponse)    {        m_pFormatResponse->SeekDone(HXR_OK);    }    else    {        retVal = HXR_UNEXPECTED;    }    return retVal;}STDMETHODIMP PXPNGFileFormat::Close(){    HX_RESULT retVal = HXR_OK;    Deallocate();    return retVal;}STDMETHODIMP PXPNGFileFormat::InitDone(HX_RESULT status){    HX_RESULT retVal = HXR_OK;    if (m_ulState == kStateFileInitPending)    {        if (SUCCEEDED(status))        {            // Create an IHXFragmentedBuffer object            CHXFragmentedBuffer* pFragBuffer = NULL;            retVal = CHXFragmentedBuffer::CreateObject(&pFragBuffer);            if (SUCCEEDED(retVal))            {                // AddRef the object                pFragBuffer->AddRef();                // QI it for IHXFragmentedBuffer                retVal = pFragBuffer->QueryInterface(IID_IHXFragmentedBuffer,                                                     (void**) &m_pFragBuffer);            }            HX_RELEASE(pFragBuffer);            if (SUCCEEDED(retVal))            {                // Reset the bytes read counter                m_ulNumBytesRead = 0;                // Set the state                m_ulState = kStateFileReadPending;                // Do the first read from the file                m_pFileObject->Read(kReadSize);            }        }        else        {            retVal = status;        }        if (FAILED(retVal))        {            m_pFormatResponse->InitDone(retVal);        }    }    else    {        retVal = HXR_UNEXPECTED;    }    return retVal;}STDMETHODIMP PXPNGFileFormat::ReadDone(HX_RESULT status, IHXBuffer* pBuffer){    HX_RESULT retVal = HXR_OK;    if (m_ulState == kStateFileReadPending)    {        if (SUCCEEDED(status))        {            retVal = m_pFragBuffer->Append(pBuffer, 0, pBuffer->GetSize());            if (SUCCEEDED(retVal))            {                m_ulNumBytesRead += pBuffer->GetSize();            }        }        if (SUCCEEDED(retVal))        {            if ((SUCCEEDED(status) && pBuffer->GetSize() < kReadSize) || FAILED(status))            {                if (m_ulNumBytesRead > 0)

⌨️ 快捷键说明

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