comimgff.cpp

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

CPP
1,025
字号
}

STDMETHODIMP CCommonImageFileFormat::Seek(UINT32 ulOffset)
{
    HX_RESULT retVal = HXR_UNEXPECTED;

    if (m_pFormatResponse)
    {
        // Clear the return value
        retVal = HXR_OK;
        // Set the desired file offset back to the beginning
        m_ulDesiredFileOffset = 0;
        // Is the file object currently open?
        if (m_bFileObjectOpen)
        {
            // The file object is still currently open,
            // so all we have to do is start reading
            // again back at the beginning of the file.
            //
            // Tell the response we're ready to start
            // giving packets again.
            m_pFormatResponse->SeekDone(HXR_OK);
        }
        else
        {
            // The file object has been closed. We need
            // to reopen it.
            //
            // Set the state
            m_ulState = kStateSeekInitDonePending;
            // Init the file object
            m_pFileObject->Init(HX_FILE_READ | HX_FILE_BINARY, this);
        }
    }

    return retVal;
}

STDMETHODIMP CCommonImageFileFormat::Close()
{
    HX_RESULT retVal = HXR_OK;

    if (m_pFileObject)
    {
        m_pFileObject->Close();
    }
    HX_RELEASE(m_pContext);
    HX_RELEASE(m_pFileObject);
    HX_RELEASE(m_pFormatResponse);
    HX_RELEASE(m_pCommonClassFactory);
    HX_RELEASE(m_pFileMimeMapper);
    HX_RELEASE(m_pURLStr);
    HX_RELEASE(m_pMimeTypeStr);
    m_ulState               = kStateReady;
    m_ulFileOffset          = 0;
    m_ulDesiredFileOffset   = 0;
    m_ulRequestedFileOffset = 0;

    return retVal;
}

STDMETHODIMP CCommonImageFileFormat::InitDone(HX_RESULT status)
{
    HX_RESULT retVal = HXR_UNEXPECTED;

    if (m_ulState == kStateIFFInitDonePending)
    {
        // Clear the return value
        retVal = HXR_OK;
        // Did the init succeed?
        if (SUCCEEDED(status))
        {
            // Set the flag saying the file is open
            m_bFileObjectOpen = TRUE;
            // Try and get the IHXFileMimeMapper interface
            HX_RELEASE(m_pFileMimeMapper);
            m_pFileObject->QueryInterface(IID_IHXFileMimeMapper, (void**) &m_pFileMimeMapper);
            if (m_pFileMimeMapper)
            {
                // We got the IHXFileMimeMapper interface,
                // so get our own IHXFileMimeMapperResponse interface
                IHXFileMimeMapperResponse* pResponse = NULL;
                QueryInterface(IID_IHXFileMimeMapperResponse, (void**) &pResponse);
                // Set the state
                m_ulState = kStateIFFMimeTypeFoundPending;
                // Get the mime type
                m_pFileMimeMapper->FindMimeType((const char*) m_pURLStr->GetBuffer(), pResponse);
                // Now we can release our response interface
                HX_RELEASE(pResponse);
            }
            else
            {
                // We didn't get an IHXFileMimeMapper interface,
                // but that's not a reason to fail
                //
                // Set state
                m_ulState = kStateReady;
                // Call back to response interface
                m_pFormatResponse->InitDone(status);
            }
        }
        else
        {
            // Set the state
            m_ulState = kStateIFFCloseDonePending;
            // Close the file
            m_pFileObject->Close();
        }
    }
    else if (m_ulState == kStateSeekInitDonePending)
    {
        // Clear the return value
        retVal = HXR_OK;
        // Set the state
        m_ulState = kStateReady;
        // Did the init succeed?
        if (SUCCEEDED(status))
        {
            // Set the flag saying the file is open
            m_bFileObjectOpen = TRUE;
        }
        // Tell the response interface whether
        // or not the seek succeeded
        m_pFormatResponse->SeekDone(status);
    }

    return retVal;
}

STDMETHODIMP CCommonImageFileFormat::ReadDone(HX_RESULT status, IHXBuffer* pBuffer)
{
    HX_RESULT retVal = HXR_UNEXPECTED;

    if (m_ulState == kStateGSHReadDonePending)
    {
        retVal = status;
        if (SUCCEEDED(retVal))
        {
            // Update the file offset
            m_ulFileOffset += pBuffer->GetSize();
            // Determine if this is a WBMP file based on the mime
            // type and the URL. We need to know this because WBMP
            // does not have any kind of identifying magic number
            // at the beginning of the file
            BOOL bIsWBMP = IsWBMP(m_pMimeTypeStr, m_pURLStr);
            // Determine width and height
            UINT32 ulWidth     = 0;
            UINT32 ulHeight    = 0;
            UINT32 ulImageType = 0;
            retVal = ParseWidthHeight(pBuffer, bIsWBMP, ulWidth, ulHeight, ulImageType);
            if (SUCCEEDED(retVal))
            {
                // Create a stream header
                IHXValues* pValues = NULL;
                retVal = m_pCommonClassFactory->CreateInstance(CLSID_IHXValues, (void**) &pValues);
                if (SUCCEEDED(retVal))
                {
                    // Set the mime type
                    SetCStringProperty(pValues,
                                       "MimeType",
                                       m_ppszStreamMimeType[ulImageType],
                                       m_pContext);
                    // Set the intrinsic duration property
                    SetCStringProperty(pValues,
                                       "intrinsicDurationType",
                                       "intrinsicDurationDiscrete",
                                       m_pContext);
                    // Set the ASM rulebook
                    SetCStringProperty(pValues,
                                       "ASMRuleBook",
                                       "AverageBandwidth=12000,Priority=5;",
                                       m_pContext);
                    // Set some ULONG32 properties
                    pValues->SetPropertyULONG32("StreamNumber",     0);
                    pValues->SetPropertyULONG32("MaxBitRate",       kBitrate);
                    pValues->SetPropertyULONG32("AvgBitRate",       kBitrate);
                    pValues->SetPropertyULONG32("MaxPacketSize",    kPacketSize);
                    pValues->SetPropertyULONG32("AvgPacketSize",    kPacketSize);
                    pValues->SetPropertyULONG32("StartTime",        0);
                    pValues->SetPropertyULONG32("PreRoll",          kPreroll);
                    pValues->SetPropertyULONG32("Duration",         kDuration);
                    pValues->SetPropertyULONG32("ContentVersion",   0);
                    pValues->SetPropertyULONG32("StreamVersion",    0);
                    pValues->SetPropertyULONG32("ImageWidth",       ulWidth);
                    pValues->SetPropertyULONG32("ImageHeight",      ulHeight);
                    // Set the state
                    m_ulState = kStateReady;
                    // Set the desired offset
                    m_ulDesiredFileOffset = 0;
                    // Send the stream header
                    m_pFormatResponse->StreamHeaderReady(HXR_OK, pValues);
                }
                HX_RELEASE(pValues);
            }
            else
            {
                // We failed to find a supported image signature in the
                // amount of header of header we read. This may not be
                // a JPEG, PNG, or WBMP; or we just may not have read enough.
                // Sometimes JPEGs have lots of unnecessary header information
                // at the beginning of the file left there by Photoshop or
                // other image-editing tools. We will keep increasing the 
                // header size that we read until we have read the entire
                // file. At that point, we will fail. We know we are not yet
                // reading the entire file when our buffer size matches
                // the header read size
                if (pBuffer->GetSize() == m_ulHeaderReadSize)
                {
                    // We will assume we just haven't read enough bytes
                    // at the beginning of the file, so double the header
                    // read size
                    m_ulHeaderReadSize = (m_ulHeaderReadSize << 1);
                    // Clear the return value
                    retVal = HXR_OK;
                    // Init the seeked file offset
                    m_ulRequestedFileOffset = 0;
                    // Set the state
                    m_ulState = kStateGSHSeekDonePending;
                    // Seek the file object to the beginning
                    m_pFileObject->Seek(m_ulRequestedFileOffset, FALSE);
                }
            }
        }

        if (FAILED(retVal))
        {
            // Set the state
            m_ulState = kStateGSHCloseDonePending;
            // Close the file
            m_pFileObject->Close();
        }
    }
    else if (m_ulState == kStateGPReadDonePending)
    {
        // Copy the read status
        retVal = status;
        // Did the read succeed?
        if (SUCCEEDED(retVal))
        {
            // Update the file offset
            m_ulFileOffset += pBuffer->GetSize();
            // Create a packet
            IHXPacket* pPacket = NULL;
            retVal = m_pCommonClassFactory->CreateInstance(CLSID_IHXPacket, (void**) &pPacket);
            if (SUCCEEDED(retVal))
            {
                // Set the packet
                retVal = pPacket->Set(pBuffer,           // data
                                      0,                 // time stamp
                                      0,                 // stream 0
                                      HX_ASM_SWITCH_ON,  // ASM flag
                                      0);                // ASM rule
                if (SUCCEEDED(retVal))
                {
                    // Update the desired file offset
                    m_ulDesiredFileOffset = m_ulFileOffset;
                    // Set the state
                    m_ulState = kStateReady;
                    // Return the packet
                    m_pFormatResponse->PacketReady(HXR_OK, pPacket);
                }
            }
            HX_RELEASE(pPacket);
        }
        if (FAILED(retVal))
        {
            // Clear the return value
            retVal = HXR_OK;
            // Set the state
            m_ulState = kStateGPCloseDonePending;
            // Close the file
            m_pFileObject->Close();
        }
    }

    return retVal;
}


STDMETHODIMP CCommonImageFileFormat::SeekDone(HX_RESULT status)
{
    HX_RESULT retVal = HXR_UNEXPECTED;

    if (m_ulState == kStateGSHSeekDonePending)
    {
        // Clear the return value
        retVal = HXR_OK;
        // Did the seek succeed?
        if (SUCCEEDED(status))
        {
            // Assign the actual file offset
            m_ulFileOffset = m_ulRequestedFileOffset;
            // Set the state
            m_ulState = kStateGSHReadDonePending;
            // Read the header
            m_pFileObject->Read(m_ulHeaderReadSize);
        }
        else
        {
            // Set the state
            m_ulState = kStateGSHCloseDonePending;
            // Close the file
            m_pFileObject->Close();
        }
    }
    else if (m_ulState == kStateGPSeekDonePending)
    {
        // Clear the return value
        retVal = HXR_OK;
        // Did the seek succeed?
        if (SUCCEEDED(status))
        {
            // Set the actual file offset
            m_ulFileOffset = m_ulRequestedFileOffset;
            // Set the state
            m_ulState = kStateGPReadDonePending;
            // Read kPacketSize bytes
            m_pFileObject->Read(kPacketSize);
        }
        else
        {
            // Set the state
            m_ulState = kStateGPCloseDonePending;
            // Close the file
            m_pFileObject->Close();
        }
    }

    return retVal;
}

STDMETHODIMP CCommonImageFileFormat::CloseDone(HX_RESULT status)
{
    HX_RESULT retVal = HXR_UNEXPECTED;

    // Clear the file open flag
    m_bFileObjectOpen = FALSE;

    if (m_ulState == kStateIFFCloseDonePending)
    {
        // Clear the return value
        retVal = HXR_OK;

⌨️ 快捷键说明

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