📄 oggfformat.cpp
字号:
/******************************************************************** * * * THIS FILE IS PART OF THE OGG VORBIS PROJECT SOURCE CODE. * * * * THE OGG VORBIS PROJECT SOURCE CODE IS (C) COPYRIGHT 1994-2001 * * by the XIPHOPHORUS Company http://www.xiph.org/ * ******************************************************************** function: implementation of the file format plugin for RealSystem********************************************************************//* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: oggfformat.cpp,v 1.3.2.6 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 ***** */#define INITGUID#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ogg/ogg.h>#include "hxtypes.h"#include "hxcom.h"#include "hxcomm.h"#include "ihxpckts.h"#include "hxplugn.h"#include "hxfiles.h"#include "hxformt.h"#include "chxpckts.h" // CHXHeader::mergeHeaders#include "oggfformat.h"#include "codec_info.h"#include "group_info.h"#include "oggutil.h"#include "ogg_stream.h"#include "debug.h" // DPRINTF()#define D_OGG_FF 0 //0x4000000// static variablesconst char *COggFileFormat::zm_pDescription = DESCRIPTION;const char *COggFileFormat::zm_pCopyright = COPYRIGHT;const char *COggFileFormat::zm_pMoreInfoURL = MORE_INFO_URL;const char *COggFileFormat::zm_pFileMimeTypes[] = FILE_MIME_TYPES;const char *COggFileFormat::zm_pFileExtensions[] = FILE_EXTENSIONS;const char *COggFileFormat::zm_pFileOpenNames[] = FILE_OPEN_NAMES;STDAPI RMACreateInstance(IUnknown **ppExFileFormatObj){#ifdef _DEBUG debug_level() |= D_OGG_FF;#endif /* _DEBUG */ DPRINTF(D_OGG_FF, ("RMACreateInstance() called\n")); *ppExFileFormatObj = (IUnknown *)(IHXPlugin *)new COggFileFormat(); if (*ppExFileFormatObj != NULL) { (*ppExFileFormatObj)->AddRef(); return HXR_OK; } return HXR_OUTOFMEMORY;}// constructorCOggFileFormat::COggFileFormat(void) : m_RefCount(0), m_pResponse(NULL), m_pPageReader(NULL), m_State(Start), m_pGetPacketPending(NULL), m_bInDispatchPendingRequest(FALSE), m_pCurrentStrategy(NULL), m_ulLastCachedPageOffset(0), m_bIsLive(FALSE), m_uCurrentGroup(0){ DPRINTF(D_OGG_FF, ("COFF::COggFileFormat()\n"));}STDMETHODIMP COggFileFormat::GetPluginInfo( REF(BOOL) bLoadMultiple, REF(const char *) pDescription, REF(const char *) pCopyright, REF(const char *) pMoreInfoURL, REF(UINT32) versionNumber ){ DPRINTF(D_OGG_FF, ("Entering GetPluginInfo()\n")); // File Format plugins must be able to be multiply instantiated bLoadMultiple = TRUE; pDescription = zm_pDescription; pCopyright = zm_pCopyright; pMoreInfoURL = zm_pMoreInfoURL; versionNumber = PLUGIN_VERSION_NUM; DPRINTF(D_OGG_FF, ("Exiting GetPluginInfo()\n")); return HXR_OK;}STDMETHODIMP COggFileFormat::GetFileFormatInfo( REF(const char **) pFileMimeTypes, REF(const char **) pFileExtensions, REF(const char **) pFileOpenNames ){ DPRINTF(D_OGG_FF, ("Entering GetFileFormatInfo()\n")); pFileMimeTypes = zm_pFileMimeTypes; pFileExtensions = zm_pFileExtensions; pFileOpenNames = zm_pFileOpenNames; DPRINTF(D_OGG_FF, ("Exiting GetFileFormatInfo()\n")); return HXR_OK;}STDMETHODIMP COggFileFormat::InitPlugin(IUnknown* pContext){ DPRINTF(D_OGG_FF, ("Entering InitPlugin()\n")); HX_RESULT res = HXR_FAILED; if (pContext) { res = m_streamHdlr.Init(pContext); } DPRINTF(D_OGG_FF, ("Exiting InitPlugin()\n")); return res;}STDMETHODIMP COggFileFormat::InitFileFormat( IHXRequest *pRequest, IHXFormatResponse *pFormatResponse, IHXFileObject *pFileObject ){ HX_RESULT res = HXR_FAILED; if (pRequest && pFormatResponse && pFileObject) { DPRINTF(D_OGG_FF, ("Entering InitFileFormat()\n")); // the format response object is used to notify rma core of our status m_pResponse = pFormatResponse; HX_ADDREF(m_pResponse); HX_RELEASE(m_pPageReader); m_pPageReader = new COggPageReader(); if (m_pPageReader) { changeState(InitPending); m_pPageReader->AddRef(); res = m_pPageReader->Init(this, pFileObject); if (HXR_OK != res) { changeState(Start); } } else { res = HXR_OUTOFMEMORY; } } DPRINTF(D_OGG_FF, ("Exiting InitFileFormat()\n")); return HXR_OK;}STDMETHODIMP COggFileFormat::GetFileHeader(void){ DPRINTF(D_OGG_FF, ("Entering GetFileHeader()\n")); HX_RESULT res = HXR_UNEXPECTED; if (Ready == m_State) { changeState(GetFirstStreamInfo); m_pCurrentStrategy = &m_streamInfoStrategy; res = m_streamInfoStrategy.Init(m_pPageReader); if (HXR_OK == res) { res = m_pPageReader->ReadNextPage(); } } DPRINTF(D_OGG_FF, ("Exiting GetFileHeader()\n")); return res;}STDMETHODIMP COggFileFormat::GetStreamHeader(UINT16 streamNo){ DPRINTF(D_OGG_FF, ("Entering GetStreamHeader(%u)\n", streamNo)); IHXValues* pStreamHdr = NULL; HX_RESULT res = m_streamHdlr.CreateStreamHeader(streamNo, pStreamHdr); if (HXR_OK == res) { if (!m_bIsLive) { COggTimestamp duration; res = m_fileInfo.GetDuration(duration); if (HXR_OK == res) { duration.SetSampleRate(1000); res = pStreamHdr->SetPropertyULONG32("Duration", duration.Samples()); } } if (HXR_OK == res) { res = pStreamHdr->SetPropertyULONG32("StreamNumber", streamNo); } if (HXR_OK == res) { m_pResponse->StreamHeaderReady(HX_STATUS_OK, pStreamHdr); } } HX_RELEASE(pStreamHdr); DPRINTF(D_OGG_FF, ("Exiting GetStreamHeader()\n")); return res;}STDMETHODIMP COggFileFormat::GetPacket(UINT16 streamNo){ DPRINTF(D_OGG_FF, ("Entering GetPacket(%u)\n", streamNo)); HX_RESULT res = HXR_UNEXPECTED; if (m_pPageReader && m_pGetPacketPending) { if (Error == m_State) { m_pResponse->PacketReady(HXR_UNEXPECTED, NULL); res = HXR_OK; } else if (m_streamHdlr.EndOfStream(streamNo)) { m_pResponse->StreamDone(streamNo); } else { m_pGetPacketPending[streamNo] = TRUE; res = dispatchPendingRequests(); if (HXR_OK != res) { if (Ready == m_State) { // Request the next page changeState(GetPacketReadPending); res = m_pPageReader->ReadNextPage(); } else { // A file operation is already pending. // This request will be serviced when the // pending operation completes res = HXR_OK; } } } } DPRINTF(D_OGG_FF, ("Exiting GetPacket()\n")); return res;}STDMETHODIMP COggFileFormat::Seek(UINT32 requestedTime){ DPRINTF(D_OGG_FF, ("COFF::Seek(%u)\n", requestedTime)); HX_RESULT res = HXR_FAILED; if (m_pPageReader && m_pPageReader->IsSeekable()) { // Clear all pending GetPacket() requests if (m_pGetPacketPending) { memset(m_pGetPacketPending, 0, sizeof(BOOL) * m_streamHdlr.StreamCount()); } res = m_streamHdlr.OnSeek(requestedTime); if (HXR_OK == res) { const COggGroupInfo* pGroupInfo = NULL; UINT32 uGroupIndex; res = m_fileInfo.GetGroupByTimestamp(requestedTime, uGroupIndex); if (HXR_OK == res) { DPRINTF(D_OGG_FF, ("COFF::Seek() : GroupIndex %u\n", uGroupIndex)); res = m_fileInfo.GetGroupInfo(uGroupIndex, pGroupInfo); } if (HXR_OK == res) { res = setupStreamHandlerFromGroupInfo(uGroupIndex); } if (HXR_OK == res) { changeState(FindSeekPointOffset); m_pCurrentStrategy = &m_seekStrategy; res = m_seekStrategy.Init(m_pPageReader, pGroupInfo, requestedTime); } } } DPRINTF(D_OGG_FF, ("COFF::Seek() : done %08x\n", res)); return res;}STDMETHODIMP COggFileFormat::Close(void){ DPRINTF(D_OGG_FF, ("Entering Close()\n")); HX_RELEASE(m_pResponse); m_streamInfoStrategy.Close(); m_findEOFStrategy.Close(); m_groupEndTimeStrategy.Close(); m_findGroupEndStrategy.Close(); if (m_pPageReader) { m_pPageReader->Close(); HX_RELEASE(m_pPageReader); } HX_VECTOR_DELETE(m_pGetPacketPending); flushPageCache(); DPRINTF(D_OGG_FF, ("Exiting Close()\n")); return HXR_OK;}COggFileFormat::~COggFileFormat(void){ DPRINTF(D_OGG_FF, ("Entering ~COggFileFormat()\n")); Close(); DPRINTF(D_OGG_FF, ("Exiting ~COggFileFormat()\n"));}STDMETHODIMP_(UINT32) COggFileFormat::AddRef(void){ return InterlockedIncrement(&m_RefCount);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -