NativeFLACSourceFilter.h

Go to the documentation of this file.
00001 //===========================================================================
00002 //Copyright (C) 2003, 2004 Zentaro Kavanagh
00003 //
00004 //Redistribution and use in source and binary forms, with or without
00005 //modification, are permitted provided that the following conditions
00006 //are met:
00007 //
00008 //- Redistributions of source code must retain the above copyright
00009 //  notice, this list of conditions and the following disclaimer.
00010 //
00011 //- Redistributions in binary form must reproduce the above copyright
00012 //  notice, this list of conditions and the following disclaimer in the
00013 //  documentation and/or other materials provided with the distribution.
00014 //
00015 //- Neither the name of Zentaro Kavanagh nor the names of contributors 
00016 //  may be used to endorse or promote products derived from this software 
00017 //  without specific prior written permission.
00018 //
00019 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020 //``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00022 //PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
00023 //CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00024 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00025 //PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00026 //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00027 //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00028 //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 //===========================================================================
00031 #pragma once
00032 //Local Includes
00033 #include "dsfNativeFLACSource.h"
00034 #include "NativeFLACSourcePin.h"
00035 
00036 //Library Includes
00037 #include "FLAC++/decoder.h"
00038 #include <libilliCore/StringHelper.h>
00039 #include <libilliCore/iBE_Math.h>
00040 using namespace FLAC::Decoder;
00041 
00042 //STL Includes
00043 #include <string>
00044 using namespace std;
00045 
00046 //Forward Declarations
00047 class NativeFLACSourcePin;
00048 
00049 class NativeFLACSourceFilter
00050         //Base Classes
00051         :       public CBaseFilter
00052         ,       public IFileSourceFilter
00053         ,       public IAMFilterMiscFlags
00054         ,       public IMediaSeeking
00055         ,       public CAMThread
00056         ,       protected FLAC::Decoder::SeekableStream
00057 {
00058 public:
00059         //Friends
00060         friend class NativeFLACSourcePin;
00061 
00062         //Constants
00063         enum eThreadCommands {
00064                 THREAD_EXIT = 0,
00065                 THREAD_PAUSE = 1,
00066                 THREAD_RUN = 2
00067         };
00068 
00069         //COM Stuff
00070         DECLARE_IUNKNOWN
00071         STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv);
00072         static CUnknown* WINAPI CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr);
00073 
00074         //Constructors
00075         NativeFLACSourceFilter(void);
00076         virtual ~NativeFLACSourceFilter(void);
00077 
00078         //IBaseFilter Pure Virtuals
00079         virtual int GetPinCount();
00080         virtual CBasePin* GetPin(int inPinNo);
00081 
00082         //IAMFilterMiscFlags Interface
00083         ULONG STDMETHODCALLTYPE GetMiscFlags(void);
00084 
00085         //IFileSource Interface
00086         virtual STDMETHODIMP GetCurFile(LPOLESTR* outFileName, AM_MEDIA_TYPE* outMediaType);
00087         virtual STDMETHODIMP Load(LPCOLESTR inFileName, const AM_MEDIA_TYPE* inMediaType);
00088 
00089         //Streaming MEthods
00090         STDMETHODIMP Run(REFERENCE_TIME tStart);
00091         STDMETHODIMP Pause(void);
00092         STDMETHODIMP Stop(void);
00093 
00094         //CAMThread
00095         virtual DWORD ThreadProc(void);
00096 
00097         //FLAC Virtuals
00098         virtual ::FLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte outBuffer[], unsigned int* outNumBytes);
00099         virtual ::FLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 inSeekPos);
00100         virtual ::FLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64* outTellPos);
00101         virtual ::FLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64* outLength);
00102         virtual ::FLAC__StreamDecoderWriteStatus write_callback(const FLAC__Frame* outFrame,const FLAC__int32 *const outBuffer[]);
00103         virtual void metadata_callback(const FLAC__StreamMetadata* inMetaData);
00104         virtual void error_callback(FLAC__StreamDecoderErrorStatus inStatus);
00105         virtual bool eof_callback(void);
00106 
00107         //IMediaSeeking Interface
00108         virtual STDMETHODIMP GetCapabilities(DWORD *pCapabilities);
00109         virtual STDMETHODIMP CheckCapabilities(DWORD *pCapabilities);
00110         virtual STDMETHODIMP IsFormatSupported(const GUID *pFormat);
00111         virtual STDMETHODIMP QueryPreferredFormat(GUID *pFormat);
00112         virtual STDMETHODIMP SetTimeFormat(const GUID *pFormat);
00113         virtual STDMETHODIMP GetTimeFormat( GUID *pFormat);
00114         virtual STDMETHODIMP GetDuration(LONGLONG *pDuration);
00115         virtual STDMETHODIMP GetStopPosition(LONGLONG *pStop);
00116         virtual STDMETHODIMP GetCurrentPosition(LONGLONG *pCurrent);
00117         virtual STDMETHODIMP ConvertTimeFormat(LONGLONG *pTarget, const GUID *pTargetFormat, LONGLONG Source, const GUID *pSourceFormat);
00118         virtual STDMETHODIMP SetPositions(LONGLONG *pCurrent,DWORD dwCurrentFlags,LONGLONG *pStop,DWORD dwStopFlags);
00119         virtual STDMETHODIMP GetPositions(LONGLONG *pCurrent, LONGLONG *pStop);
00120         virtual STDMETHODIMP GetAvailable(LONGLONG *pEarliest, LONGLONG *pLatest);
00121         virtual STDMETHODIMP SetRate(double dRate);
00122         virtual STDMETHODIMP GetRate(double *dRate);
00123         virtual STDMETHODIMP GetPreroll(LONGLONG *pllPreroll);
00124         virtual STDMETHODIMP IsUsingTimeFormat(const GUID *pFormat);
00125 
00126 protected:
00127         //Helper Methods
00128         HRESULT DataProcessLoop();
00129 
00130         //Pin Class
00131         NativeFLACSourcePin* mFLACSourcePin;
00132 
00133         //Source File Members
00134         wstring mFileName;
00135         fstream mInputFile;
00136         unsigned long mFileSize;
00137 
00138         //State Variables
00139         bool mBegun;
00140         bool mJustSeeked;
00141         __int64 mSeekRequest;
00142         bool mWasEOF;
00143         unsigned long mUpto;
00144 
00145         //Stream info data.
00146         unsigned long mNumChannels;
00147         unsigned long mFrameSize;
00148         unsigned long mSampleRate;
00149         unsigned long mBitsPerSample;
00150         __int64 mTotalNumSamples;
00151 
00152         //Critical Section to protect codec.
00153         CCritSec* mCodecLock;
00154 
00155 };

Generated on Tue Feb 15 14:54:15 2005 for oggdsf by  doxygen 1.3.9