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

📄 ogg_page_reader.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: ogg_page_reader.cpp,v 1.1.2.3 2004/11/24 18:02:52 acolwell Exp $ *  * Portions Copyright (c) 1995-2004 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 (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (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. *  * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. *  * 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 "hlxclib/stdlib.h"#include "ogg_page_reader.h"#include "ihxpckts.h" // IHXBuffer#include "debug.h" // DPRINTF()#define D_OGG_PAGE_READER 0 //0x4000000const UINT32 DefaultReadSize = 8192;COggPageReader::COggPageReader() :    m_lRefCount(0),    m_state(rsStart),    m_pResponse(NULL),    m_pFile(NULL),    m_pStat(NULL),    m_bSeekable(FALSE),    m_ulFileSize(0),    m_ulPendingSeekOffset(0),    m_ulCurrentFileOffset(0),    m_ulFileObjectOffset(0),    m_bEndOfFile(FALSE),    m_pOy(NULL){#ifdef _DEBUG    debug_level() |= D_OGG_PAGE_READER;#endif    DPRINTF(D_OGG_PAGE_READER, ("COggPageReader::COggPageReader()\n"));}COggPageReader::~COggPageReader(){    DPRINTF(D_OGG_PAGE_READER, ("COggPageReader::~COggPageReader()\n"));    Close();}HX_RESULT COggPageReader::Init(IHXOggPageReaderResponse* pResponse,                               IHXFileObject* pFileObject){    DPRINTF(D_OGG_PAGE_READER, ("COggPageReader::Init()\n"));    HX_RESULT res = HXR_FAILED;    if (rsStart != m_state)    {        res = HXR_UNEXPECTED;    }    else if (pResponse && pFileObject)    {        HX_RELEASE(m_pResponse);        m_pResponse = pResponse;        m_pResponse->AddRef();            HX_RELEASE(m_pFile);        HX_RELEASE(m_pStat);        m_ulFileSize = 0;        m_pFile = pFileObject;        m_pFile->AddRef();        m_pFile->QueryInterface(IID_IHXFileStat, (void**)&m_pStat);        m_pOy = (ogg_sync_state*) _ogg_malloc(sizeof(ogg_sync_state));        if (m_pOy)        {            ogg_sync_init(m_pOy);            ChangeState(rsInitPending);            res = m_pFile->Init(HX_FILE_READ | HX_FILE_BINARY, this);        }        else        {            res = HXR_OUTOFMEMORY;        }    }    DPRINTF(D_OGG_PAGE_READER, ("COggPageReader::Init() : res 0x%08x\n", res));    return res;}HX_RESULT COggPageReader::Seek(ULONG32 ulFileOffset){    DPRINTF(D_OGG_PAGE_READER, ("COggPageReader::Seek(%lu)\n", ulFileOffset));    HX_RESULT res = HXR_OK;    if (m_bSeekable && (ulFileOffset < m_ulFileSize))    {        switch(m_state) {        case rsReady:            res = DoSeek(ulFileOffset);            break;        case rsSeekPending:        case rsReadPending:        case rsDispatchReadPageDone:        case rsReadDuringDispatch:            ChangeState(rsSeekDuringPending);            /* fall through intentional */        case rsSeekDuringPending:            m_ulPendingSeekOffset = ulFileOffset;            break;        default:            res = HXR_UNEXPECTED;            break;        };    }    else    {        res = HXR_UNEXPECTED;    }    DPRINTF(D_OGG_PAGE_READER, ("COggPageReader::Seek() : done %08x\n", res));    return res;}HX_RESULT COggPageReader::ReadNextPage(){    DPRINTF(D_OGG_PAGE_READER, ("COggPageReader::ReadNextPage()\n"));    HX_RESULT res = HXR_UNEXPECTED;    if (rsReady == m_state)    {        res = DoReadNextPage(FALSE);        if ((HXR_OK == res) && (rsSeekDuringPending == m_state))        {            res = DoSeek(m_ulPendingSeekOffset);        }    }    else if (rsDispatchReadPageDone == m_state)    {        ChangeState(rsReadDuringDispatch);        res = HXR_OK;    }    DPRINTF(D_OGG_PAGE_READER, ("COggPageReader::ReadNextPage() : done\n"));    return res;}HX_RESULT COggPageReader::CurrentPosition(REF(ULONG32) ulPos) const{    HX_RESULT res = HXR_UNEXPECTED;    if (m_pFile)    {        ulPos = m_ulCurrentFileOffset;        res = HXR_OK;    }    return res;}BOOL COggPageReader::IsSeekable() const{    return m_bSeekable;}ULONG32 COggPageReader::FileSize() const{    return m_ulFileSize;}HX_RESULT COggPageReader::Close(){    DPRINTF(D_OGG_PAGE_READER, ("COggPageReader::Close()\n"));    HX_RELEASE(m_pResponse);    if (m_pFile)    {        m_pFile->Close();    }    HX_RELEASE(m_pFile);    HX_RELEASE(m_pStat);    if (m_pOy)    {        ogg_sync_destroy(m_pOy);        m_pOy = NULL;    }    return HXR_OK;}/* *      IUnknown methods */STDMETHODIMP COggPageReader::QueryInterface(THIS_ REFIID riid, void** ppvObj){    HX_RESULT res = HXR_OK;    if (IsEqualIID(riid, IID_IUnknown)) {        *ppvObj = (IUnknown *)(IHXFileResponse *)this;    } else if (IsEqualIID(riid, IID_IHXFileResponse)) {        *ppvObj = (IHXFileResponse *)this;    } else if (IsEqualIID(riid, IID_IHXFileStatResponse)) {        *ppvObj = (IHXFileStatResponse *)this;    }    else    {        *ppvObj = NULL;        res =  HXR_NOINTERFACE;    }    if (HXR_OK == res)    {        AddRef();    }    return res;}STDMETHODIMP_(ULONG32) COggPageReader::AddRef(THIS){        return InterlockedIncrement(&m_lRefCount);}STDMETHODIMP_(ULONG32) COggPageReader::Release(THIS){    if (InterlockedDecrement(&m_lRefCount) > 0)        return m_lRefCount;    delete this;    return 0;}/* *      IHXFileResponse methods */STDMETHODIMP COggPageReader::InitDone(THIS_ HX_RESULT status){    DPRINTF(D_OGG_PAGE_READER, ("COggPageReader::InitDone(0x%08x)\n", status));    BOOL bCallInitDone = TRUE;    if (HXR_OK == status)    {        /* Only do a Stat() if we have a IHXFileStat object,         * and the file will allow random access         */        HX_RESULT tmpRes = m_pFile->Advise(HX_FILEADVISE_RANDOMACCESS);        if (m_pStat && (HXR_ADVISE_PREFER_LINEAR != tmpRes))        {            ChangeState(rsStatPending);            status = m_pStat->Stat(this);        }        else        {            ChangeState(rsReady);            if (m_pResponse)            {                m_pResponse->PageReaderInitDone(HXR_OK);            }        }    }    if (HXR_OK != status)    {        ChangeState(rsStart);        if (m_pResponse)        {            m_pResponse->PageReaderInitDone(status);        }    }    DPRINTF(D_OGG_PAGE_READER, ("COggPageReader::InitDone() : done\n"));

⌨️ 快捷键说明

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