pxgifff.cpp

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

CPP
1,531
字号
        ReportError(IDS_ERR_GIF_BADURL);
        return m_pFormatResponse->InitDone(retVal);
    }
    if (cTmp.GetLength() > 0)
    {
        HX_DELETE(m_pURL);
        m_pURL = new CHXString((const char*) cTmp);
    }
    CHXString cTarget;
    retVal = ExtractValueString(pValues, "target", "_browser", cTarget);
    if (retVal != HXR_OK)
    {
        HX_RELEASE(pValues);
        ReportError(IDS_ERR_GIF_BADTARGET);
        return m_pFormatResponse->InitDone(retVal);
    }
    retVal = ExtractValueColor(pValues, "bgcolor", 0x00FFFFFF, m_ulBackgroundColor);
    if (retVal != HXR_OK)
    {
        HX_RELEASE(pValues);
        ReportError(IDS_ERR_GIF_BADBGCOLOR);
        return m_pFormatResponse->InitDone(retVal);
    }
    retVal = ExtractValueBOOL(pValues, "reliable", FALSE, m_bReliable);
    if (retVal != HXR_OK)
    {
        HX_RELEASE(pValues);
        ReportError(IDS_ERR_GIF_BADRELFLAG);
        return m_pFormatResponse->InitDone(retVal);
    }
    // Get the media repeat string
    pValues->GetPropertyCString("mediaRepeat", m_pMediaRepeatStr);

    // Release the IHXValues object
    HX_RELEASE(pValues);

    // Check url encoded bitrate
    if (!m_ulBitRate)
    {
        ReportError(IDS_ERR_GIF_BITRATEZERO);
        return m_pFormatResponse->InitDone(retVal);
    }

    // Check target string
    if (cTarget == "_player")
    {
        m_ucTarget = kTargetPlayer;

    }
    else if (cTarget == "_browser")
    {
        m_ucTarget = kTargetBrowser;
    }
    else
    {
        ReportError(IDS_ERR_GIF_ILLEGALTARGET);
        return m_pFormatResponse->InitDone(retVal);
    }

    // Set some defaults
    m_ucURLType  = kURLTypeNormal;
    m_ulSeekTime = 0;

    // Check the URL if present
    if (m_pURL && m_pURL->GetLength() > 0)
    {
        // Check to see if it's a command
        if (m_pURL->Left(8) == "command:")
        {
            // Yes it is a command. Make sure it's either seek, pause, or play
            if (*m_pURL == "command:pause()")
            {
                m_ucURLType = kURLTypeCommandPause;
            }
            else if (*m_pURL == "command:play()")
            {
                m_ucURLType = kURLTypeCommandPlay;
            }
            else if (*m_pURL == "command:stop()")
            {
                m_ucURLType = kURLTypeCommandStop;
            }
            else if (m_pURL->Mid(8,5) == "seek(" &&
                     m_pURL->Right(1) == ")")
            {
                m_ucURLType = kURLTypeCommandSeek;

                // Make sure there's a valid seek time
                CHXString cSeekStr   = m_pURL->Mid(13, m_pURL->GetLength() - 14);
                BOOL bRet = ConvertTimeStringToULONG32((char*) (const char*) cSeekStr,
                                                       cSeekStr.GetLength(),
                                                       m_ulSeekTime);
                if (bRet == FALSE)
                {
                    ReportError(IDS_ERR_GIF_BADTIMEFORMAT);
                    return m_pFormatResponse->InitDone(retVal);
                }
            }
            else
            {
                ReportError(IDS_ERR_GIF_UNKPLAYERCOMMAND);
                return m_pFormatResponse->InitDone(retVal);
            }
        }
    }

    // Reconcile the URL and the target
    if (m_ucTarget == kTargetBrowser && m_ucURLType != kURLTypeNormal)
    {
        ReportError(IDS_ERR_GIF_NOTARGETBROWSER);
        return m_pFormatResponse->InitDone(retVal);
    }

    // Save a copy of the file object
    m_pFileObject = pFileObject;
    m_pFileObject->AddRef();

    // Set the new state
    m_ulState = kStateFileInit;

    // Init the file object - see InitDone for response
    return m_pFileObject->Init(HX_FILE_READ | HX_FILE_BINARY, this);
}

STDMETHODIMP CGIFFileFormat::InitDone(HX_RESULT status)
{
#ifdef XXXMEH_DEBUG_LOG
    DEBUG_OUTF("pxgifff.log", (s, "0x%08x::InitDone(0x%08x)\n", this, status));
#endif
    // Check state
    if (m_ulState != kStateFileInit)
    {
        return HXR_UNEXPECTED;
    }

    // Check for input error
    if (status != HXR_OK)
    {
        return m_pFormatResponse->InitDone(status);
    }

    // Now we must get the IHXFileStat interface from the IHXFileObject
    HX_RELEASE(m_pFileStat);
    HX_RESULT retVal = m_pFileObject->QueryInterface(IID_IHXFileStat, (void **) &m_pFileStat);
    if (retVal != HXR_OK)
    {
        return m_pFormatResponse->InitDone(retVal);
    }

    // Set the new state
    m_ulState = kStateFileStat;

    // Now we find out how big is the file
    return m_pFileStat->Stat(this);
}

STDMETHODIMP CGIFFileFormat::StatDone(HX_RESULT status, UINT32 ulSize, UINT32 ulCreationTime,
                                      UINT32 ulAccessTime, UINT32 ulModificationTime, UINT32 ulMode)
{
#ifdef XXXMEH_DEBUG_LOG
    DEBUG_OUTF("pxgifff.log", (s, "0x%08x::StatDone(0x%08x,%lu,,,,)\n", this, status, ulSize));
#endif
    HX_RESULT retVal = HXR_OK;

    if (m_ulState == kStateFileStat)
    {
        if (SUCCEEDED(status))
        {
            // Set the file size
            m_ulFileSize = ulSize;

            // Now we no longer need the IHXFileStat interface
            HX_RELEASE(m_pFileStat);

            // Create an IHXFragmentedBuffer to hold the file
            CHXFragmentedBuffer* pTmp = NULL;
            retVal                     = CHXFragmentedBuffer::CreateObject(&pTmp);
            if (SUCCEEDED(retVal))
            {
                HX_RELEASE(m_pFragFileBuffer);
                retVal = pTmp->QueryInterface(IID_IHXFragmentedBuffer, (void**) &m_pFragFileBuffer);
                if (SUCCEEDED(retVal))
                {
                    // Set the new state
                    m_ulState        = kStateFileRead;
                    // Clear the bytes read counter
                    m_ulNumBytesRead = 0;
                    // Now we read, 2k at a time
                    retVal           = m_pFileObject->Read(2048);
                }
                else
                {
                    retVal = m_pFormatResponse->InitDone(retVal);
                }
            }
            else
            {
                retVal = m_pFormatResponse->InitDone(retVal);
            }
        }
        else
        {
            retVal = m_pFormatResponse->InitDone(status);
        }
    }
    else
    {
        retVal = HXR_UNEXPECTED;
    }

    return retVal;
}

STDMETHODIMP CGIFFileFormat::ReadDone(HX_RESULT status, IHXBuffer *pBuffer)
{
#ifdef XXXMEH_DEBUG_LOG
    UINT32 ulSize = (SUCCEEDED(status) && pBuffer ? pBuffer->GetSize() : 0);
    DEBUG_OUTF("pxgifff.log", (s, "0x%08x::ReadDone(0x%08x,0x%08x): pBuffer->GetSize() = %lu\n",
               this, status, pBuffer, ulSize));
#endif
    HX_RESULT retVal = HXR_OK;

    if (m_ulState == kStateFileRead)
    {
        if (SUCCEEDED(status))
        {
            // Append the buffer to the fragmented buffer
            retVal = m_pFragFileBuffer->Append(pBuffer, 0, pBuffer->GetSize());
            if (SUCCEEDED(retVal))
            {
                // Update the number of bytes read
                m_ulNumBytesRead += pBuffer->GetSize();

                // Have we read all we were supposed to?
                if (m_ulFileSize > 0 && m_ulNumBytesRead >= m_ulFileSize)
                {
                    retVal = ParseFile();
                    if (SUCCEEDED(retVal))
                    {
                        // Set the new state
                        m_ulState = kStateInitialized;
                    }
                    else
                    {
                        m_bParseFailed = TRUE;
                        const char* pszStr = (m_pRequestURL ? (const char*) *m_pRequestURL : NULL);
                        ReportError(IDS_ERR_GIF_CORRUPTFILE, pszStr);
                        retVal = HXR_OK;
                        // Set the new state
                        m_ulState = kStateInitialized;
                    }

                    // Tell the response interface we're ready
                    retVal = m_pFormatResponse->InitDone(retVal);
                }
                else
                {
                    // No, either we haven't read enough or we don't
                    // know how big the file really is. Either way,
                    // we need to do another read.
                    retVal = m_pFileObject->Read(2048);
                }
            }
        }
        else
        {
            // We might have gotten here if we didn't know the file size
            // and we're reading until we got an error. Therefore, if
            // we're here AND we've read some bytes OK, then we'll try
            // parsing the file. If we have NOT read any bytes successfully,
            // then we'll fail
            //
            if (m_ulNumBytesRead > 0)
            {
                retVal = ParseFile();
                if (SUCCEEDED(retVal))
                {
                    // Set the new state
                    m_ulState = kStateInitialized;
                }
                else
                {
                    m_bParseFailed = TRUE;
                    const char* pszStr = (m_pRequestURL ? (const char*) *m_pRequestURL : NULL);
                    ReportError(IDS_ERR_GIF_CORRUPTFILE, pszStr);
                    retVal = HXR_OK;
                    // Set the new state
                    m_ulState = kStateInitialized;
                }
            }
            else
            {
                retVal = status;
            }

            retVal = m_pFormatResponse->InitDone(retVal);
        }
    }
    else
    {
        retVal = HXR_UNEXPECTED;
    }

    return retVal;
}


STDMETHODIMP CGIFFileFormat::GetFileHeader()
{
#ifdef XXXMEH_DEBUG_LOG
    DEBUG_OUTF("pxgifff.log", (s, "0x%08x::GetFileHeader()\n", this));
#endif
    // Check the state
    if (m_ulState != kStateInitialized)
    {
        return HXR_UNEXPECTED;
    }

    // Create an IHXValues object
    IHXValues *pHeader = NULL;
    HX_RESULT   retVal  = m_pCommonClassFactory->CreateInstance(CLSID_IHXValues, (void **) &pHeader);
    if (retVal != HXR_OK)
    {
        m_pFormatResponse->FileHeaderReady(retVal, NULL);
    }

    // Set the StreamCount propery - we always only have 1 stream
    pHeader->SetPropertyULONG32("StreamCount", 1);
    pHeader->SetPropertyULONG32("IsRealDataType", 1);

    // Set the width and height
    if (m_pGIFCodec)
    {
        pHeader->SetPropertyULONG32("Width",  m_pGIFCodec->GetLogicalScreenWidth());
        pHeader->SetPropertyULONG32("Height", m_pGIFCodec->GetLogicalScreenHeight());
    }

    // Set the new state
    m_ulState = kStateFileHeaderSent;

    // Inform the response interface that we have the file header
    retVal = m_pFormatResponse->FileHeaderReady(HXR_OK, pHeader);

    // Release our reference on the IHXValues object
    HX_RELEASE(pHeader);

    return retVal;
}

STDMETHODIMP CGIFFileFormat::GetStreamHeader(UINT16 usStreamNum)
{
#ifdef XXXMEH_DEBUG_LOG
    DEBUG_OUTF("pxgifff.log", (s, "0x%08x::GetStreamHeader(%u)\n", this, usStreamNum));
#endif
    // Check the state
    if (m_ulState != kStateFileHeaderSent)
    {
        return HXR_UNEXPECTED;
    }

    // Check for input error
    if (usStreamNum != 0)
    {
        return m_pFormatResponse->StreamHeaderReady(HXR_FAIL, NULL);
    }

    UINT32 ulPreDataBytes = 0;
    if (m_pGIFCodec && !m_bParseFailed)
    {
        // Resolve the minimum duration with the requested duration.
        //
        // Here's the rule: if the duration was not specified (i.e. - the
        // duration is equal to the default, then take the duration that's
        // in the GIF file, as long as it HAS some duration
        if (m_ulDuration == kDefaultDuration &&
            m_pGIFCodec->IsGIF89a()          &&
            m_pGIFCodec->GetDelayTimeSum() > 0)
        {
            m_ulDuration = m_pGIFCodec->GetDelayTimeSum();
        }

        // Allocate space for the array of scheduling times
        INT32 lNumImages = (INT32) m_pGIFCodec->GetNumImages();

⌨️ 快捷键说明

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