BaseSplitterFileEx.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 "BaseSplitterFile.h"
00025 
00026 class CBaseSplitterFileEx : public CBaseSplitterFile
00027 {
00028         int m_tslen; // transport stream packet length (188 or 192 bytes, auto-detected)
00029 
00030 public:
00031         CBaseSplitterFileEx(IAsyncReader* pReader, HRESULT& hr, int cachelen = DEFAULT_CACHELEN);
00032         virtual ~CBaseSplitterFileEx();
00033 
00034         using CBaseSplitterFile::Read;
00035 
00036         bool NextMpegStartCode(BYTE& b, __int64 len = 65536);
00037 
00038 #pragma pack(push, 1)
00039 
00040         enum mpeg_t {mpegunk, mpeg1, mpeg2};
00041 
00042         struct pshdr
00043         {
00044                 mpeg_t type;
00045                 UINT64 scr, bitrate;
00046         };
00047 
00048         struct pssyshdr
00049         {
00050                 DWORD rate_bound;
00051                 BYTE video_bound, audio_bound;
00052                 bool fixed_rate, csps;
00053                 bool sys_video_loc_flag, sys_audio_loc_flag;
00054         };
00055 
00056         struct peshdr
00057         {
00058                 WORD len;
00059 
00060                 BYTE type:2, fpts:1, fdts:1;
00061                 REFERENCE_TIME pts, dts;
00062 
00063                 // mpeg1 stuff
00064                 UINT64 std_buff_size;
00065 
00066                 // mpeg2 stuff
00067                 BYTE scrambling:2, priority:1, alignment:1, copyright:1, original:1;
00068                 BYTE escr:1, esrate:1, dsmtrickmode:1, morecopyright:1, crc:1, extension:1;
00069                 BYTE hdrlen;
00070 
00071                 struct peshdr() {memset(this, 0, sizeof(*this));}
00072         };
00073 
00074         class seqhdr
00075         {
00076         public:
00077                 WORD width;
00078                 WORD height;
00079                 BYTE ar:4;
00080                 DWORD ifps;
00081                 DWORD bitrate;
00082                 DWORD vbv;
00083                 BYTE constrained:1;
00084                 BYTE fiqm:1;
00085                 BYTE iqm[64];
00086                 BYTE fniqm:1;
00087                 BYTE niqm[64];
00088                 // ext
00089                 BYTE startcodeid:4;
00090                 BYTE profile_levelescape:1;
00091                 BYTE profile:3;
00092                 BYTE level:4;
00093                 BYTE progressive:1;
00094                 BYTE chroma:2;
00095                 BYTE lowdelay:1;
00096                 // misc
00097                 int arx, ary;
00098         };
00099 
00100         class mpahdr
00101         {
00102         public:
00103                 WORD sync:11;
00104                 WORD version:2;
00105                 WORD layer:2;
00106                 WORD crc:1;
00107                 WORD bitrate:4;
00108                 WORD freq:2;
00109                 WORD padding:1;
00110                 WORD privatebit:1;
00111                 WORD channels:2;
00112                 WORD modeext:2;
00113                 WORD copyright:1;
00114                 WORD original:1;
00115                 WORD emphasis:2;
00116                 
00117                 int nSamplesPerSec, FrameSize, nBytesPerSec;
00118                 REFERENCE_TIME rtDuration;
00119         };
00120 
00121         class aachdr
00122         {
00123         public:
00124                 WORD sync:12;
00125                 WORD version:1;
00126                 WORD layer:2;
00127                 WORD fcrc:1;
00128                 WORD profile:2;
00129                 WORD freq:4;
00130                 WORD privatebit:1;
00131                 WORD channels:3;
00132                 WORD original:1;
00133                 WORD home:1; // ?
00134 
00135                 WORD copyright_id_bit:1;
00136                 WORD copyright_id_start:1;
00137                 WORD aac_frame_length:13;
00138                 WORD adts_buffer_fullness:11;
00139                 WORD no_raw_data_blocks_in_frame:2;
00140 
00141                 WORD crc;
00142 
00143                 int FrameSize, nBytesPerSec;
00144                 REFERENCE_TIME rtDuration;
00145         };
00146 
00147         class ac3hdr
00148         {
00149         public:
00150                 WORD sync;
00151                 WORD crc1;
00152                 BYTE fscod:2;
00153                 BYTE frmsizecod:6;
00154                 BYTE bsid:5;
00155                 BYTE bsmod:3;
00156                 BYTE acmod:3;
00157                 BYTE cmixlev:2;
00158                 BYTE surmixlev:2;
00159                 BYTE dsurmod:2;
00160                 BYTE lfeon:1;
00161                 // the rest is unimportant for us
00162         };
00163 
00164         class dtshdr
00165         {
00166         public:
00167                 DWORD sync;
00168                 BYTE frametype:1;
00169                 BYTE deficitsamplecount:5;
00170         BYTE fcrc:1;
00171                 BYTE nblocks:7;
00172                 WORD framebytes;
00173                 BYTE amode:6;
00174                 BYTE sfreq:4;
00175                 BYTE rate:5;
00176         };
00177 
00178         class lpcmhdr
00179         {
00180         public:
00181                 BYTE emphasis:1;
00182                 BYTE mute:1;
00183                 BYTE reserved1:1;
00184                 BYTE framenum:5;
00185                 BYTE quantwordlen:2;
00186                 BYTE freq:2; // 48, 96, 44.1, 32
00187                 BYTE reserved2:1;
00188                 BYTE channels:3; // +1
00189                 BYTE drc; // 0x80: off
00190         };
00191 
00192         class dvdspuhdr
00193         {
00194         public:
00195                 // nothing ;)
00196         };
00197         
00198         class svcdspuhdr
00199         {
00200         public:
00201                 // nothing ;)
00202         };
00203 
00204         class cvdspuhdr
00205         {
00206         public:
00207                 // nothing ;)
00208         };
00209 
00210         class ps2audhdr
00211         {
00212         public:
00213                 // 'SShd' + len (0x18)
00214                 DWORD unk1;
00215                 DWORD freq;
00216                 DWORD channels;
00217                 DWORD interleave; // bytes per channel
00218                 // padding: FF .. FF
00219                 // 'SSbd' + len
00220                 // pcm or adpcm data
00221         };
00222 
00223         class ps2subhdr
00224         {
00225         public:
00226                 // nothing ;)
00227         };
00228 
00229         struct trhdr
00230         {
00231                 BYTE sync; // 0x47
00232                 BYTE error:1;
00233                 BYTE payloadstart:1;
00234                 BYTE transportpriority:1;
00235                 WORD pid:13;
00236                 BYTE scrambling:2;
00237                 BYTE adapfield:1;
00238                 BYTE payload:1;
00239                 BYTE counter:4;
00240                 // if adapfield set
00241                 BYTE length;
00242                 BYTE discontinuity:1;
00243                 BYTE randomaccess:1;
00244                 BYTE priority:1;
00245                 BYTE PCR:1;
00246                 BYTE OPCR:1;
00247                 BYTE splicingpoint:1;
00248                 BYTE privatedata:1;
00249                 BYTE extension:1;
00250                 // TODO: add more fields here when the flags above are set (they aren't very interesting...)
00251 
00252                 int bytes;
00253                 __int64 next;
00254         };
00255 
00256         // http://www.technotrend.de/download/av_format_v1.pdf
00257 
00258         struct pvahdr
00259         {
00260                 WORD sync; // 'VA'
00261                 BYTE streamid; // 1 - video, 2 - audio
00262                 BYTE counter;
00263                 BYTE res1; // 0x55
00264                 BYTE res2:3;
00265                 BYTE fpts:1;
00266                 BYTE postbytes:2;
00267                 BYTE prebytes:2;
00268                 WORD length;
00269                 REFERENCE_TIME pts;
00270         };
00271 
00272         struct avchdr
00273         {
00274                 BYTE profile, level;
00275                 unsigned int width, height;
00276         };
00277 
00278 #pragma pack(pop)
00279 
00280         bool Read(pshdr& h);
00281         bool Read(pssyshdr& h);
00282         bool Read(peshdr& h, BYTE code);
00283         bool Read(seqhdr& h, int len, CMediaType* pmt = NULL);
00284         bool Read(mpahdr& h, int len, bool fAllowV25, CMediaType* pmt = NULL);
00285         bool Read(aachdr& h, int len, CMediaType* pmt = NULL);
00286         bool Read(ac3hdr& h, int len, CMediaType* pmt = NULL);
00287         bool Read(dtshdr& h, int len, CMediaType* pmt = NULL);
00288         bool Read(lpcmhdr& h, CMediaType* pmt = NULL);
00289         bool Read(dvdspuhdr& h, CMediaType* pmt = NULL);
00290         bool Read(svcdspuhdr& h, CMediaType* pmt = NULL);
00291         bool Read(cvdspuhdr& h, CMediaType* pmt = NULL);
00292         bool Read(ps2audhdr& h, CMediaType* pmt = NULL);
00293         bool Read(ps2subhdr& h, CMediaType* pmt = NULL);
00294         bool Read(trhdr& h, bool fSync = true);
00295         bool Read(pvahdr& h, bool fSync = true);
00296         bool Read(avchdr& h, int len, CMediaType* pmt = NULL);
00297 };

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