home *** CD-ROM | disk | FTP | other *** search
- /*
- * demux.h
- *
- * Copyright (C) Alberto Vigata - January 2000 - ultraflask@yahoo.com
- *
- * This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
- *
- * FlasKMPEG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * FlasKMPEG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
- #ifndef DEMUX_H
- #define DEMUX_H
-
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- #include <windows.h>
- #include <winbase.h>
- extern "C"{
- #include "..\FlasKMPEG.h"
- }
- #include "..\input\inputStream.h"
-
-
- #define BUFFER_SIZE 32000
-
- #define IDCT_MMX 1
- #define IDCT_NORMAL 2
- #define IDCT_IEEE 3
-
- #define MPEG1_CLK_REF (i64)90000
- #define MPEG2_CLK_REF (i64)27000000
-
-
-
- #include "..\BitsGetter.h"
-
- // Stream IDs
- #define PACK_ID 0xBA
- #define PROGRAM_STREAM_MAP 0xBC
- #define PRIVATE_STREAM_1 0xBD
- #define PADDING_STREAM 0xBE
- #define PRIVATE_STREAM_2 0xBF
- #define ECM_STREAM 0xF0
- #define EMM_STREAM 0xF1
- #define PROGRAM_STREAM_DIRECTORY 0xFF
- #define DSMCC_STREAM 0xF2
- #define ITUTRECH222TYPEE_STREAM 0xF8
- #define SUBSTREAM_AC3 0x80
- #define VIDEO_STREAM 0xE0
- #define AUDIO_STREAM 0xC0
-
- // MPEG2 PACK HEADER
- // SCRbase and SCRext
- // 32 .......................................0 9.........0
- // [PACK_START_CODE][01---1--][--------][-----1--][--------][-----1--][-------1]
-
- #define ZERO (i64)0
- #define GET_SCRBASE(x) ( ((ui64)x[4]&0xF8)>>3 | \
- (ui64)x[3]<<5 | \
- ((ui64)x[2]&0x03)<<13 | \
- ((ui64)x[2]&0xF8)<<12 | \
- (ui64)x[1]<<20 | \
- ((ui64)x[0]&0x03)<<28 | \
- (ui64)x[0]&0x38 <<27 )
-
- #define GET_SCREXT(x) ( ((ui64)x[5]&0xFE)>>1 | \
- ((ui64)x[4]&0x03)<<7 )
-
- // muxrate
- // 22 ......................0 stl
- // ... [--------][--------][------11][rrrrr---]
- #define GET_MPEG2MUXRATE(x) ( (ui32)x[6]<<14 | ((ui32)x[7])<<6 | ((ui32)x[8]&0x03)>>2)
-
- #define GET_MPEG2STUFFING(x) ((x[9]&0x07))
- // MPEG1 PACK HEADER
- // SCR muxrate
- // 32........................................0 22.......................0
- // [PACK_START_CODE][0010---1][--------][-------1][--------][-------1][1-------][--------][-------1]
- #define GET_SCR(x) ( ((ui64)x[4]&0xFE) >>1 | \
- ((ui64)x[3]) <<7 | \
- ((ui64)x[2]&0xFE) <<14 | \
- ((ui64)x[1]) <<22 | \
- ((ui64)x[0]&0x0E) <<29 )
- #define GET_MPEG1_PTS(x) (GET_SCR(x)) //they follow the same pattern
-
- #define GET_MPEG1_MUXRATE(x) ( ((ui32)x[7]&0xFE) >>1 | \
- ((ui32)x[6]) <<7 | \
- ((ui32)x[5]&0x7F) <<15 )
-
- // MPEG2 PES packet (first 5 bytes)
- // Packet lenght PTS Header length
- // 15...............0 7......0
- // [PACKET_START_CODE][--------][--------][10------][xx------][--------]
- #define GET_MPEG_PACKET_LENGHT(x) ( ((ui16)x[0]<<8) | (ui16)x[1] )
- #define GET_MPEG2_PTS_FLAGS(x) ( ((ui8)x[3]&0xC0)>>6 )
- // MPEG2 PES packet (optional parameters)
- // PTS
- // 32........................................0
- // [PACKET_START_CODE][001x---1][--------][-------1][--------][-------1]
- #define GET_MPEG2_PTS(x) ( ((ui64)x[4]&0xFE) >>1 | \
- ((ui64)x[3]) <<7 | \
- ((ui64)x[2]&0xFE) <<14 | \
- ((ui64)x[1]) <<22 | \
- ((ui64)x[0]&0x0E) <<29 )
-
-
- #define GET_UINT16(x) ( ((ui16)x[0]<<8)|((ui16)x[1]))
-
- class CDemux: public CBitSource
- {
- public:
- int SetWorkingMode(int mode);
- void StartReadLPES();
- int ReadLPES(unsigned char **buffer, PESinfo *PES);
- i64 GetTime();
-
- CDemux();
- ~CDemux();
-
- int ReadPES(unsigned char **buffer, PESinfo *PES);
-
- ResetSCR();
- ResetPTS();
-
- i64 getSCR();
- i64 getPTS();
-
- int isMPEG2;
- ui32 muxRate;
-
-
- bool PTSread;
- int SetInput(char *inputfile);
- int SetInput(CinputStream *inpStream);
- int UnSetInput();
-
-
- bool EndOfFile;
-
- protected:
- ui8 inbuf[65536];
- i64 SCR, SCRbase,SCRext, PTS;
- int AlignPack();
- CinputStream *inp,*myInputStream;
-
- private:
- bool firstTime;
- i64 delta;
- i64 lastSCR;
- ui32 lastPackBytes;
- ui32 lastMuxRate;
- };
-
-
-
-
- #endif DEMUX_H