amrff.cpp

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

CPP
914
字号
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
 *      
 * The contents of this file, and the files included with this file, are 
 * subject to the current version of the RealNetworks Public Source License 
 * Version 1.0 (the "RPSL") available at 
 * http://www.helixcommunity.org/content/rpsl unless you have licensed 
 * the file under the RealNetworks Community Source License Version 1.0 
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
 * in which case the RCSL will apply. You may also obtain the license terms 
 * directly from RealNetworks.  You may not use this file except in 
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
 * applicable to this file, the RCSL.  Please see the applicable RPSL or 
 * RCSL for the rights, obligations and limitations governing use of the 
 * contents of the file.  
 *  
 * This file is part of the Helix DNA Technology. RealNetworks is the 
 * developer of the Original Code and owns the copyrights in the portions 
 * it created. 
 *  
 * This file, and the files included with this file, is distributed and made 
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
 * 
 * Technology Compatibility Kit Test Suite(s) Location: 
 *    http://www.helixcommunity.org/content/tck 
 * 
 * Contributor(s): 
 *  
 * ***** END LICENSE BLOCK ***** */ 

#include "hxtypes.h"
#include "hxcom.h"
#include "hxplugn.h"
#include "ihxpckts.h"
#include "hxformt.h"
#include "hxccf.h"
#include "hxfiles.h"
#include "hxengin.h"
#include "baseobj.h"
#include "pckunpck.h"
#include "hxver.h"
#include "hxamrpack.h"
#include "amr_frame_info.h"
#include "amr_frame_hdr.h"
#include "amrffmlog.h"
#include "amrff.h"
#include "amrff.ver"
#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE
static const char HX_THIS_FILE[] = __FILE__;
#endif

const char* const CAMRFileFormat::m_pszDescription        = "Helix AMR File Format Plugin";
const char* const CAMRFileFormat::m_pszCopyright          = HXVER_COPYRIGHT;
const char* const CAMRFileFormat::m_pszMoreInfoURL        = HXVER_MOREINFO;
const char* const CAMRFileFormat::m_ppszFileMimeTypes[]   = {"audio/amr", "audio/awb", NULL};
const char* const CAMRFileFormat::m_ppszFileExtensions[]  = {"amr", "awb", NULL};
const char* const CAMRFileFormat::m_ppszFileOpenNames[]   = {"AMR Files (*.amr,*.awb)", NULL};
const char* const CAMRFileFormat::m_ppszStreamMimeTypes[] = {"audio/amr",
                                                             "audio/awb",
                                                             "audio/X-RN-3GPP-AMR",
                                                             "audio/X-RN-3GPP-AMR-WB",
                                                             NULL};
const BYTE        CAMRFileFormat::m_pMagicSingle[6]       = {0x23,0x21,0x41,0x4d,0x52,0x0a};
const BYTE        CAMRFileFormat::m_pMagicSingleWB[9]     = {0x23,0x21,0x41,0x4d,0x52,0x2d,0x57,0x42,0x0a};
const BYTE        CAMRFileFormat::m_pMagicMulti[12]       = {0x23,0x21,0x41,0x4d,0x52,0x5F,0x4D,0x43,0x31,
                                                             0x2E,0x30,0x0a};
const BYTE        CAMRFileFormat::m_pMagicMultiWB[15]     = {0x23,0x21,0x41,0x4d,0x52,0x2d,0x57,0x42,0x5F,
                                                             0x4D,0x43,0x31,0x2E,0x30,0x0a};
const BYTE        CAMRFileFormat::m_ucNumChannelsMap[16]  = {0,2,3,4,4,5,6,0,0,0,0,0,0,0,0,0};

//#define DEBUG_TEST_FRAME_SCAN

CAMRFileFormat::CAMRFileFormat()
{
    MLOG_LEAK("CON CAMRFileFormat this=0x%08x\n", this);
    m_lRefCount           = 0;
    m_pContext            = NULL;
    m_pCommonClassFactory = NULL;
    m_pFileObject         = NULL;
    m_pFormatResponse     = NULL;
    m_pFileStat           = NULL;
    m_eState              = StateReady;
    m_ulHeaderSize        = 0;
    m_ulBytesPerFrame     = 0;
    m_ulFileSize          = 0;
    m_ulNumChannels       = 0;
    m_ulNextFileOffset    = 0;
    m_ulNextTimeStamp     = 0;
    m_pPayloadFormat      = NULL;
    m_bWideBand           = FALSE;
    m_bScanForFrameBegin  = FALSE;
}

CAMRFileFormat::~CAMRFileFormat()
{
    MLOG_LEAK("DES CAMRFileFormat this=0x%08x\n", this);
    Close();
}

STDMETHODIMP CAMRFileFormat::QueryInterface(REFIID riid, void** ppvObj)
{
    HX_RESULT retVal = HXR_OK;

    if (ppvObj)
    {
        // NULL out by default
        *ppvObj = NULL;
        // Switch based on IID
        if (IsEqualIID(riid, IID_IUnknown))
        {
            AddRef();
            *ppvObj = (IUnknown*) (IHXPlugin*) this;
        }
        else if (IsEqualIID(riid, IID_IHXPlugin))
        {
            AddRef();
            *ppvObj = (IHXPlugin*) this;
        }
        else if (IsEqualIID(riid, IID_IHXFileFormatObject))
        {
            AddRef();
            *ppvObj = (IHXFileFormatObject*) this;
        }
        else if (IsEqualIID(riid, IID_IHXFileResponse))
        {
            AddRef();
            *ppvObj = (IHXFileResponse*) this;
        }
        else if (IsEqualIID(riid, IID_IHXFileStatResponse))
        {
            AddRef();
            *ppvObj = (IHXFileStatResponse*) this;
        }
        else if (IsEqualIID(riid, IID_IHXInterruptSafe))
        {
            AddRef();
            *ppvObj = (IHXInterruptSafe*) this;
        }
        else
        {
            retVal = HXR_NOINTERFACE;
        }
    }
    else
    {
        retVal = HXR_FAIL;
    }

    return retVal;
}

STDMETHODIMP_(ULONG32) CAMRFileFormat::AddRef()
{
    return InterlockedIncrement(&m_lRefCount);
}

STDMETHODIMP_(ULONG32) CAMRFileFormat::Release()
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
        return m_lRefCount;
    }

    delete this;
    return 0;
}

STDMETHODIMP CAMRFileFormat::InitPlugin(IUnknown* pContext)
{
    HX_RESULT retVal = HXR_FAIL;

    if (pContext)
    {
        // Save the context
        HX_RELEASE(m_pContext);
        m_pContext = pContext;
        m_pContext->AddRef();
        // Get the commom class factory
        HX_RELEASE(m_pCommonClassFactory);
        retVal = m_pContext->QueryInterface(IID_IHXCommonClassFactory,
                                            (void**) &m_pCommonClassFactory);
    }

    return retVal;
}

STDMETHODIMP CAMRFileFormat::GetPluginInfo(REF(BOOL)        rbLoadMultiple,
                                           REF(const char*) rpszDescription,
                                           REF(const char*) rpszCopyright,
                                           REF(const char*) rpszMoreInfoURL,
                                           REF(ULONG32)     rulVersionNumber)
{
    rbLoadMultiple   = TRUE;   // Must be true for file formats.
    rpszDescription  = (const char*) m_pszDescription;
    rpszCopyright    = (const char*) m_pszCopyright;
    rpszMoreInfoURL  = (const char*) m_pszMoreInfoURL;
    rulVersionNumber = TARVER_ULONG32_VERSION;

    return HXR_OK;
}

STDMETHODIMP CAMRFileFormat::GetFileFormatInfo(REF(const char**) rppszFileMimeTypes,
                                               REF(const char**) rppszFileExtensions,
                                               REF(const char**) rppszFileOpenNames)
{
    rppszFileMimeTypes  = (const char**) m_ppszFileMimeTypes;
    rppszFileExtensions = (const char**) m_ppszFileExtensions;
    rppszFileOpenNames  = (const char**) m_ppszFileOpenNames;

    return HXR_OK;
}

STDMETHODIMP CAMRFileFormat::InitFileFormat(IHXRequest*        pRequest, 
                                            IHXFormatResponse* pFormatResponse,
                                            IHXFileObject*     pFileObject)
{
    HX_RESULT retVal = HXR_UNEXPECTED;

    if (m_eState == StateReady)
    {
        retVal = HXR_FAIL;
        if (pFormatResponse && pFileObject)
        {
            // Save response interface
            HX_RELEASE(m_pFormatResponse);
            m_pFormatResponse = pFormatResponse;
            m_pFormatResponse->AddRef();
            // Save file object
            HX_RELEASE(m_pFileObject);
            m_pFileObject = pFileObject;
            m_pFileObject->AddRef();
            // Get our own IHXFileResponse interface
            IHXFileResponse* pResponse = NULL;
            retVal = QueryInterface(IID_IHXFileResponse, (void**) &pResponse);
            if (pResponse)
            {
                // Set the state
                m_eState = StateInitFileFormatInitDonePending;
                // Init the file object
                retVal   = m_pFileObject->Init(HX_FILE_READ | HX_FILE_BINARY, pResponse);
            }
            HX_RELEASE(pResponse);
        }
        if (FAILED(retVal) && pFormatResponse)
        {
            pFormatResponse->InitDone(retVal);
        }
    }

    return retVal;
}

STDMETHODIMP CAMRFileFormat::Close()
{
    if (m_pFileObject)
    {
        m_pFileObject->Close();
    }
    HX_RELEASE(m_pContext);
    HX_RELEASE(m_pCommonClassFactory);
    HX_RELEASE(m_pFileObject);
    HX_RELEASE(m_pFormatResponse);
    HX_RELEASE(m_pFileStat);
    HX_DELETE(m_pPayloadFormat);
    m_eState            = StateReady;
    m_ulFileSize        = 0;
    m_ulNumChannels     = 0;
    m_ulNextFileOffset  = 0;
    m_ulNextTimeStamp   = 0;
    m_bWideBand         = FALSE;

    return HXR_OK;
}

STDMETHODIMP CAMRFileFormat::GetFileHeader()
{
    HX_RESULT retVal = HXR_OK;

    if (m_eState == StateReady)
    {
        // Set our new state
        m_eState = StateFileHeaderSeekDonePending;
        // Seek back to the beginning of the file
        retVal = m_pFileObject->Seek(0, FALSE);
    }
    else
    {
        retVal = HXR_UNEXPECTED;
    }

    return retVal;
}

STDMETHODIMP CAMRFileFormat::GetStreamHeader(UINT16 unStreamNumber)
{
    HX_RESULT retVal = HXR_OK;

    if (m_eState == StateReady)

⌨️ 快捷键说明

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