rpfile.cpp

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

CPP
1,170
字号
                        LISTPOSITION pos = m_pEffectsList->GetHeadPosition();
                        while (pos)
                        {
                            PXEffect *pListEffect = (PXEffect *) m_pEffectsList->GetAt(pos);
                            if (pListEffect)
                            {
                                if (pListEffect->GetStart() > pEffect->GetStart())
                                {
                                    // Addref effect before insertion
                                    pEffect->AddRef();
                                    // Insert into the list
                                    m_pEffectsList->InsertBefore(pos, (void *) pEffect);
                                    break;
                                }
                                m_pEffectsList->GetNext(pos);
                            }
                            else
                            {
                                retVal = HXR_FAIL;
                                break;
                            }
                        }

                        // If we added ourselves in the above loop, then pos will be non-NULL.
                        // If we DIDN'T add ourselves in the above loop, then pos will be NULL.
                        if (!pos)
                        {
                            // We didn't find an effect with a start time greater, so
                            // this effect must be the new largest start time, so
                            // we add this effect to the tail of the list. 
                            //
                            pEffect->AddRef();
                            m_pEffectsList->AddTail((void *) pEffect);
                        }
                    }
                    else
                    {
                        // Addref before adding to the list
                        pEffect->AddRef();
                        // Add it to the list
                        m_pEffectsList->AddTail((void *) pEffect);
                    }
                }
                else
                {
                    retVal = HXR_FAIL;
                }
            }
            else
            {
                // Addref the effect object before adding to the list
                pEffect->AddRef();
                // Add it to the list
                m_pEffectsList->AddTail((void *) pEffect);
            }
        }
    }
    else
    {
        retVal = HXR_INVALID_PARAMETER;
    }

    return retVal;
}

UINT32 PXRealPixFile::GetNumEffects() const
{
    UINT32 ulRet = 0;

    if (m_pEffectsList)
    {
        ulRet = m_pEffectsList->GetCount();
    }

    return ulRet;
}

HX_RESULT PXRealPixFile::GetEffectHeadIterator(REF(void*) rpIterator)
{
    HX_RESULT retVal = HXR_OK;

    if (m_pEffectsList)
    {
        LISTPOSITION pos = m_pEffectsList->GetHeadPosition();
        if (pos)
        {
            rpIterator = pos;
        }
        else
        {
            retVal = HXR_FAIL;
        }
    }
    else
    {
        retVal = HXR_FAIL;
    }

    return retVal;
}

HX_RESULT PXRealPixFile::GetEffectTailIterator(REF(void*) rpIterator)
{
    HX_RESULT retVal = HXR_OK;

    if (m_pEffectsList)
    {
        LISTPOSITION pos = m_pEffectsList->GetTailPosition();
        if (pos)
        {
            rpIterator = pos;
        }
        else
        {
            retVal = HXR_FAIL;
        }
    }
    else
    {
        retVal = HXR_FAIL;
    }

    return retVal;
}

HX_RESULT PXRealPixFile::GetAtNextEffect(REF(void*) rpIterator, REF(PXEffect*) rpEffect)
{
    HX_RESULT retVal = HXR_OK;

    if (m_pEffectsList)
    {
        if (rpIterator)
        {
            rpEffect = (PXEffect*) m_pEffectsList->GetAtNext(rpIterator);
            if (rpEffect)
            {
                rpEffect->AddRef();
            }
            else
            {
                retVal = HXR_FAIL;
            }
        }
        else
        {
            retVal = HXR_FAIL;
        }
    }
    else
    {
        retVal = HXR_NOT_INITIALIZED;
    }

    return retVal;
}

HX_RESULT PXRealPixFile::GetNextEffect(REF(void*) rpIterator, REF(PXEffect*) rpEffect)
{
    HX_RESULT retVal = HXR_OK;

    if (m_pEffectsList)
    {
        if (rpIterator)
        {
            rpEffect = (PXEffect*) m_pEffectsList->GetNext(rpIterator);
            if (rpEffect)
            {
                rpEffect->AddRef();
            }
            else
            {
                retVal = HXR_FAIL;
            }
        }
        else
        {
            retVal = HXR_FAIL;
        }
    }
    else
    {
        retVal = HXR_NOT_INITIALIZED;
    }

    return retVal;
}

HX_RESULT PXRealPixFile::GetPrevEffect(REF(void*) rpIterator, REF(PXEffect*) rpEffect)
{
    HX_RESULT retVal = HXR_OK;

    if (m_pEffectsList)
    {
        if (rpIterator)
        {
            rpEffect = (PXEffect*) m_pEffectsList->GetPrev(rpIterator);
            if (rpEffect)
            {
                rpEffect->AddRef();
            }
            else
            {
                retVal = HXR_FAIL;
            }
        }
        else
        {
            retVal = HXR_FAIL;
        }
    }
    else
    {
        retVal = HXR_NOT_INITIALIZED;
    }

    return retVal;
}

HX_RESULT PXRealPixFile::GetCurrentEffect(void* pIterator, REF(PXEffect*) rpEffect)
{
    HX_RESULT retVal = HXR_OK;

    if (m_pEffectsList)
    {
        if (pIterator)
        {
            rpEffect = (PXEffect*) m_pEffectsList->GetAt(pIterator);
            if (rpEffect)
            {
                rpEffect->AddRef();
            }
            else
            {
                retVal = HXR_FAIL;
            }
        }
        else
        {
            retVal = HXR_FAIL;
        }
    }
    else
    {
        retVal = HXR_NOT_INITIALIZED;
    }

    return retVal;
}

HX_RESULT PXRealPixFile::GetImageInfo(UINT32 ulHandle, REF(PXImageInfo*) rpInfo)
{
    HX_RESULT retVal = HXR_OK;

    if (m_pImageMap)
    {
        void *pVoid   = NULL;
        BOOL bPresent = m_pImageMap->Lookup((LONG32) ulHandle, pVoid);
        if (bPresent && pVoid)
        {
            rpInfo = (PXImageInfo*) pVoid;
        }
        else
        {
            retVal = HXR_FAIL;
        }
    }
    else
    {
        retVal = HXR_NOT_INITIALIZED;
    }

    return retVal;
}

HX_RESULT PXRealPixFile::PostParseInit()
{
    HX_RESULT retVal = HXR_OK;

    // First we need to set the first and last use effect flags.
    // To set the first use flags, we initialize a map and
    // run forward through the list of effects. Whenever we see
    // an image used, we check to see if there's an entry in the
    // map already. If not, then it's the first time this image
    // has been used, so we mark the first use flag as true
    // and then put an entry in the map. For last use flags,
    // we do the same thing, but run through the effects in reverse.
    //
    // First, create the map
    CHXMapLongToObj* pMap = new CHXMapLongToObj();
    if (pMap)
    {
        // Now do a forward run through the effects
        PXEffect*    pEffect = NULL;
        LISTPOSITION pos     = m_pEffectsList->GetHeadPosition();
        while (pos)
        {
            pEffect = (PXEffect*) m_pEffectsList->GetNext(pos);
            if (pEffect)
            {
                if (pEffect->HasTarget())
                {
                    // Is there already an entry in the map for this image?
                    void* pVoid    = NULL;
                    BOOL  bPresent = pMap->Lookup((LONG32) pEffect->GetTarget(), pVoid);
                    if (bPresent)
                    {
                        // This image has already been used, so clear the FirstUse flag
                        pEffect->SetFirstUse(FALSE);
                    }
                    else
                    {
                        // This image has NOT been used so far, so set the FirstUse flag
                        pEffect->SetFirstUse(TRUE);
                        // And also put an entry in the map for this image. It
                        // doesn't matter what the entry is, just that there IS
                        // an entry in the map
                        pMap->SetAt((LONG32) pEffect->GetTarget(), (void*) 1);
                    }
                }
            }
        }
        // Now clear the map to get ready for a backwards run
        pMap->RemoveAll();
        // Now run through the effects in reverse, doing the same thing
        pos = m_pEffectsList->GetTailPosition();
        while (pos)
        {
            PXEffect* pEffect = (PXEffect*) m_pEffectsList->GetPrev(pos);
            if (pEffect)
            {
                if (pEffect->HasTarget())
                {
                    // Is there already an entry in the map for this image?
                    void* pVoid    = NULL;
                    BOOL  bPresent = pMap->Lookup((LONG32) pEffect->GetTarget(), pVoid);
                    if (bPresent)
                    {
                        // This image has already been used, so clear the LastUse flag
                        pEffect->SetLastUse(FALSE);
                    }
                    else
                    {
                        // This image has NOT been used so far, so set the LastUse flag
                        pEffect->SetLastUse(TRUE);
                        // And also put an entry in the map for this image. It
                        // doesn't matter what the entry is, just that there IS
                        // an entry in the map
                        pMap->SetAt((LONG32) pEffect->GetTarget(), (void*) 1);
                    }
                }
            }
        }
    }
    else
    {
        retVal = HXR_OUTOFMEMORY;
    }
    HX_DELETE(pMap);

    // Now we need to check if we need to compute the duration. If the duration is
    // still zero at this point, then it was never set in parsing. Therefore,
    // we need to calculate it from the effects
    if (!m_ulDuration)
    {
        // Run through the effects list, find the max end time.
        UINT32       ulMaxTime = 0;
        LISTPOSITION pos       = m_pEffectsList->GetHeadPosition();
        while (pos)
        {
            PXEffect* pEffect = (PXEffect*) m_pEffectsList->GetNext(pos);
            if (pEffect)
            {
                if (pEffect->GetEnd() > ulMaxTime)
                {
                    ulMaxTime = pEffect->GetEnd();
                }
            }
        }
        // We don't let the duration be exactly zero.
        if (!ulMaxTime)
        {
            ulMaxTime = kMinDuration;
        }
        // Now set the duration of the presentation to this duration
        m_ulDuration = ulMaxTime;
    }

    return retVal;
}

⌨️ 快捷键说明

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