RealMediaSplitter.h

00001 /* 
00002  *      Copyright (C) 2003-2005 Gabest
00003  *      http://www.gabest.org
00004  *
00005  *  This Program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2, or (at your option)
00008  *  any later version.
00009  *   
00010  *  This Program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  *  GNU General Public License for more details.
00014  *   
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with GNU Make; see the file COPYING.  If not, write to
00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
00018  *  http://www.gnu.org/copyleft/gpl.html
00019  *
00020  */
00021 
00022 #pragma once
00023 
00024 #include <atlbase.h>
00025 #include <atlcoll.h>
00026 #include <afxtempl.h>
00027 #include "..\BaseSplitter\BaseSplitter.h"
00028 #include "..\..\transform\BaseVideoFilter\BaseVideoFilter.h"
00029 
00030 #pragma pack(push, 1)
00031 
00032 namespace RMFF
00033 {
00034         typedef struct {union {char id[4]; UINT32 object_id;}; UINT32 size; UINT16 object_version;} ChunkHdr;
00035         typedef struct {UINT32 version, nHeaders;} FileHdr;
00036         typedef struct 
00037         {
00038                 UINT32 maxBitRate, avgBitRate;
00039                 UINT32 maxPacketSize, avgPacketSize, nPackets;
00040                 UINT32 tDuration, tPreroll;
00041                 UINT32 ptrIndex, ptrData;
00042                 UINT16 nStreams;
00043                 enum flags_t {PN_SAVE_ENABLED=1, PN_PERFECT_PLAY_ENABLED=2, PN_LIVE_BROADCAST=4} flags; 
00044         } Properies;
00045         typedef struct 
00046         {
00047                 UINT16 stream;
00048                 UINT32 maxBitRate, avgBitRate;
00049                 UINT32 maxPacketSize, avgPacketSize;
00050                 UINT32 tStart, tPreroll, tDuration;
00051                 CStringA name, mime;
00052                 CArray<BYTE> typeSpecData;
00053                 UINT32 width, height;
00054                 bool interlaced, top_field_first;
00055         } MediaProperies;
00056         typedef struct {CStringA title, author, copyright, comment;} ContentDesc;
00057         typedef struct {UINT64 pos; UINT32 nPackets, ptrNext;} DataChunk;
00058         typedef struct 
00059         {
00060                 UINT16 len, stream;
00061                 UINT32 tStart;
00062                 UINT8 reserved;
00063                 enum flag_t {PN_RELIABLE_FLAG=1, PN_KEYFRAME_FLAG=2} flags; // UINT8
00064                 CArray<BYTE> pData;
00065         } MediaPacketHeader;
00066         typedef struct {UINT32 nIndices; UINT16 stream; UINT32 ptrNext;} IndexChunkHeader;
00067         typedef struct {UINT32 tStart, ptrFilePos, packet;} IndexRecord;
00068 }
00069 
00070 struct rvinfo
00071 {
00072         DWORD dwSize, fcc1, fcc2; 
00073         WORD w, h, bpp; 
00074         DWORD unk1, fps, type1, type2;
00075         BYTE morewh[14];
00076         void bswap();
00077 };
00078 
00079 struct rainfo
00080 {
00081         DWORD fourcc1;             // '.', 'r', 'a', 0xfd
00082         WORD version1;            // 4 or 5
00083         WORD unknown1;            // 00 000
00084         DWORD fourcc2;             // .ra4 or .ra5
00085         DWORD unknown2;            // ???
00086         WORD version2;            // 4 or 5
00087         DWORD header_size;         // == 0x4e
00088         WORD flavor;              // codec flavor id
00089         DWORD coded_frame_size;    // coded frame size
00090         DWORD unknown3;            // big number
00091         DWORD unknown4;            // bigger number
00092         DWORD unknown5;            // yet another number
00093         WORD sub_packet_h;
00094         WORD frame_size;
00095         WORD sub_packet_size;
00096         WORD unknown6;            // 00 00
00097         void bswap();
00098 };
00099 
00100 struct rainfo4 : rainfo
00101 {
00102         WORD sample_rate;
00103         WORD unknown8;            // 0
00104         WORD sample_size;
00105         WORD channels;
00106         void bswap();
00107 };
00108 
00109 struct rainfo5 : rainfo
00110 {
00111         BYTE unknown7[6];          // 0, srate, 0
00112         WORD sample_rate;
00113         WORD unknown8;            // 0
00114         WORD sample_size;
00115         WORD channels;
00116         DWORD genr;                // "genr"
00117         DWORD fourcc3;             // fourcc
00118         void bswap();
00119 };
00120 
00121 #pragma pack(pop)
00122 
00123 class CRMFile : public CBaseSplitterFile
00124 {
00125         using CBaseSplitterFile::Read;
00126 
00127         HRESULT Init();
00128         void GetDimensions();
00129 
00130 public:
00131         CRMFile(IAsyncReader* pAsyncReader, HRESULT& hr);
00132 
00133         template<typename T> HRESULT Read(T& var);
00134         HRESULT Read(RMFF::ChunkHdr& hdr);
00135         HRESULT Read(RMFF::MediaPacketHeader& mph, bool fFull = true);
00136 
00137         RMFF::FileHdr m_fh;
00138         RMFF::ContentDesc m_cd;
00139         RMFF::Properies m_p;
00140         CAutoPtrList<RMFF::MediaProperies> m_mps;
00141         CAutoPtrList<RMFF::DataChunk> m_dcs;
00142         CAutoPtrList<RMFF::IndexRecord> m_irs;
00143 
00144         typedef struct {CStringA name, data;} subtitle;
00145         CList<subtitle> m_subs;
00146 
00147         int GetMasterStream();
00148 };
00149 
00150 class CRealMediaSplitterOutputPin : public CBaseSplitterOutputPin
00151 {
00152 private:
00153         typedef struct {CArray<BYTE> data; DWORD offset;} segment;
00154 
00155         class CSegments : public CAutoPtrList<segment>, public CCritSec
00156         {
00157         public:
00158                 REFERENCE_TIME rtStart; 
00159                 bool fDiscontinuity, fSyncPoint, fMerged;
00160                 void Clear()
00161                 {
00162                         CAutoLock cAutoLock(this);
00163                         rtStart = 0;
00164                         fDiscontinuity = fSyncPoint = fMerged = false;
00165                         RemoveAll();
00166                 }
00167         } m_segments;
00168 
00169         CCritSec m_csQueue;
00170 
00171         HRESULT DeliverSegments();
00172 
00173 protected:
00174         HRESULT DeliverPacket(CAutoPtr<Packet> p);
00175 
00176 public:
00177         CRealMediaSplitterOutputPin(CArray<CMediaType>& mts, LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr);
00178         virtual ~CRealMediaSplitterOutputPin();
00179 
00180         HRESULT DeliverEndFlush();
00181 };
00182 
00183 [uuid("E21BE468-5C18-43EB-B0CC-DB93A847D769")]
00184 class CRealMediaSplitterFilter : public CBaseSplitterFilter
00185 {
00186 protected:
00187         CAutoPtr<CRMFile> m_pFile;
00188         HRESULT CreateOutputs(IAsyncReader* pAsyncReader);
00189 
00190         bool DemuxInit();
00191         void DemuxSeek(REFERENCE_TIME rt);
00192         bool DemuxLoop();
00193 
00194         POSITION m_seekpos;
00195         UINT32 m_seekpacket;
00196         UINT64 m_seekfilepos;
00197 
00198 public:
00199         CRealMediaSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr);
00200         virtual ~CRealMediaSplitterFilter();
00201 
00202         // IKeyFrameInfo
00203 
00204         STDMETHODIMP_(HRESULT) GetKeyFrameCount(UINT& nKFs);
00205         STDMETHODIMP_(HRESULT) GetKeyFrames(const GUID* pFormat, REFERENCE_TIME* pKFs, UINT& nKFs);
00206 };
00207 
00208 [uuid("765035B3-5944-4A94-806B-20EE3415F26F")]
00209 class CRealMediaSourceFilter : public CRealMediaSplitterFilter
00210 {
00211 public:
00212         CRealMediaSourceFilter(LPUNKNOWN pUnk, HRESULT* phr);
00213 };
00214 
00216 
00217 [uuid("238D0F23-5DC9-45A6-9BE2-666160C324DD")]
00218 class CRealVideoDecoder : public CBaseVideoFilter
00219 {
00220         typedef HRESULT (WINAPI *PRVCustomMessage)(void*, DWORD);
00221         typedef HRESULT (WINAPI *PRVFree)(DWORD);
00222         typedef HRESULT (WINAPI *PRVHiveMessage)(void*, DWORD);
00223         typedef HRESULT (WINAPI *PRVInit)(void*, DWORD* dwCookie);
00224         typedef HRESULT (WINAPI *PRVTransform)(BYTE*, BYTE*, void*, void*, DWORD);
00225 
00226         PRVCustomMessage RVCustomMessage;
00227         PRVFree RVFree;
00228         PRVHiveMessage RVHiveMessage;
00229         PRVInit RVInit;
00230         PRVTransform RVTransform;
00231 
00232         HMODULE m_hDrvDll;
00233         DWORD m_dwCookie;
00234 
00235         HRESULT InitRV(const CMediaType* pmt);
00236         void FreeRV();
00237 
00238         REFERENCE_TIME m_tStart;
00239 
00240         void Resize(BYTE* pIn, DWORD wi, DWORD hi, BYTE* pOut, DWORD wo, DWORD ho);
00241         void ResizeWidth(BYTE* pIn, DWORD wi, DWORD hi, BYTE* pOut, DWORD wo, DWORD ho);
00242         void ResizeHeight(BYTE* pIn, DWORD wi, DWORD hi, BYTE* pOut, DWORD wo, DWORD ho);
00243         void ResizeRow(BYTE* pIn, DWORD wi, DWORD dpi, BYTE* pOut, DWORD wo, DWORD dpo);
00244 
00245         CAutoVectorPtr<BYTE> m_pI420, m_pI420Tmp;
00246 
00247 public:
00248         CRealVideoDecoder(LPUNKNOWN lpunk, HRESULT* phr);
00249         virtual ~CRealVideoDecoder();
00250 
00251         HRESULT Transform(IMediaSample* pIn);
00252         HRESULT CheckInputType(const CMediaType* mtIn);
00253         HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
00254 
00255         HRESULT StartStreaming();
00256         HRESULT StopStreaming();
00257 
00258         HRESULT NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
00259 
00260         DWORD m_timestamp;
00261         bool m_fDropFrames;
00262         HRESULT AlterQuality(Quality q);
00263 };
00264 
00265 [uuid("941A4793-A705-4312-8DFC-C11CA05F397E")]
00266 class CRealAudioDecoder : public CTransformFilter
00267 {
00268         typedef HRESULT (WINAPI *PCloseCodec)(DWORD);
00269         typedef HRESULT (WINAPI *PDecode)(DWORD,BYTE*,long,BYTE*,long*,long);
00270         typedef HRESULT (WINAPI *PFlush)(DWORD,DWORD,DWORD);
00271         typedef HRESULT (WINAPI *PFreeDecoder)(DWORD);
00272         typedef void* (WINAPI *PGetFlavorProperty)(void*,DWORD,DWORD,int*);
00273         typedef HRESULT (WINAPI *PInitDecoder)(DWORD, void*);
00274         typedef HRESULT (WINAPI *POpenCodec)(void*);
00275         typedef HRESULT (WINAPI *POpenCodec2)(void*, const char*);
00276         typedef HRESULT (WINAPI *PSetFlavor)(DWORD, WORD);
00277         typedef void (WINAPI *PSetDLLAccessPath)(const char*);
00278         typedef void (WINAPI *PSetPwd)(DWORD, const char*);
00279 
00280         PCloseCodec RACloseCodec;
00281         PDecode RADecode;
00282         PFlush RAFlush;
00283         PFreeDecoder RAFreeDecoder;
00284         PGetFlavorProperty RAGetFlavorProperty;
00285         PInitDecoder RAInitDecoder;
00286         POpenCodec RAOpenCodec;
00287         POpenCodec2 RAOpenCodec2;
00288         PSetFlavor RASetFlavor;
00289         PSetDLLAccessPath RASetDLLAccessPath;
00290         PSetPwd RASetPwd;
00291 
00292         CStringA m_dllpath;
00293         HMODULE m_hDrvDll;
00294         DWORD m_dwCookie;
00295 
00296         HRESULT InitRA(const CMediaType* pmt);
00297         void FreeRA();
00298 
00299         REFERENCE_TIME m_tStart;
00300 
00301         rainfo m_rai;
00302         CAutoVectorPtr<BYTE> m_buff;
00303         int m_bufflen;
00304         REFERENCE_TIME m_rtBuffStart;
00305         bool m_fBuffDiscontinuity;
00306 
00307 public:
00308         CRealAudioDecoder(LPUNKNOWN lpunk, HRESULT* phr);
00309         virtual ~CRealAudioDecoder();
00310 
00311         HRESULT Receive(IMediaSample* pIn);
00312         HRESULT CheckInputType(const CMediaType* mtIn);
00313         HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
00314         HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
00315         HRESULT GetMediaType(int iPosition, CMediaType* pMediaType);
00316 
00317         HRESULT StartStreaming();
00318         HRESULT StopStreaming();
00319 
00320     HRESULT EndOfStream();
00321     HRESULT BeginFlush();
00322     HRESULT EndFlush();
00323     HRESULT NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
00324 };
00325 
00326 

Generated on Tue Dec 13 14:47:22 2005 for guliverkli by  doxygen 1.4.5