www.pudn.com > mediator15src.zip > unpacketizer.h


/* 
 * unpacketizer.h 
 * Copyright (C) 2001-2002 Arno Hornberger  
 * 
 * This file is part of MPEG Mediator, a free MPEG stream converter. 
 * 
 * MPEG Mediator 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 of the License, or 
 * (at your option) any later version. 
 * 
 * MPEG Mediator 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 this program; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */ 
 
#ifndef UNPACKETIZER_H 
#define UNPACKETIZER_H 
 
#include "asyncstream.h" 
#include "startcodes.h" 
 
class Unpacketizer 
{ 
  private: 
    bool mpeg2; 
    bool sync_pack; 
 
    AsyncStream *bs; 
 
    __int64 scr_offset, scr_base, scr_pack; // in units of 27.000.000 Hz 
    __int64 program_mux_base;               // stream position at scr_pack  
    unsigned long program_mux_rate;         // datarate 
 
    __int64 pts, dts; 
    int pts_dts_flags; 
 
    int stream_id, substream_id; 
 
    __int64 payload_start; 
    __int64 payload_pos; 
    int payload_bytes; 
 
    __int64 seek_pos; 
 
    int audio_framecount, audio_frameoffset; 
		int lpcm_type; 
 
    __int64 GetSCR(__int64 streampos); 
 
  public: 
    Unpacketizer() { bs = 0; } 
    ~Unpacketizer() { } 
 
    void SetStream(AsyncStream *stream); 
    __int64 StreamSize() { return bs->Size(); } 
    __int64 Tell(); 
    void Seek(__int64 pos); 
    void NextPacket(); 
 
    __int64 GetSCR(); 
    bool IsMPEG2() { return mpeg2; } 
    int GetStreamID() { return stream_id; } 
    int GetSubstreamID() { return substream_id; } 
 
    void Resync(); 
    int GetPayloadSize() { return payload_bytes; } 
    void GetPayloadBytes(unsigned char *dest, int numbytes); 
    void FlushPayloadBytes(int numbytes); 
    unsigned char GetPayloadByte(); 
    bool HasPTS() { return (pts_dts_flags & 2) != 0; } 
    __int64 GetPTS() { return pts; } 
 
    int GetAudioFrameCount() { return audio_framecount; } 
    int GetAudioFrameOffset() { return audio_frameoffset; } 
		int GetLPCMType() { return lpcm_type; } 
}; 
 
inline __int64 Unpacketizer::GetSCR() 
{ 
  // computation *must* be in 64-bit range in order 
  // to prevent overflow errors 
 
  if (!sync_pack) 
    return scr_offset + scr_pack - scr_base + 
          ((payload_pos - program_mux_base) * 540000) / program_mux_rate; 
  else 
    return 0; 
} 
 
inline __int64 Unpacketizer::GetSCR(__int64 streampos) 
{ 
  return scr_offset + scr_pack - scr_base + 
         ((streampos - program_mux_base) * 540000) / program_mux_rate; 
} 
 
#endif