⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpeg_demux.h

📁 linux下实现视频播放的播放器
💻 H
字号:
/* *  Copyright (C) 2005-2007  gulikoza * *  This program 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. * *  This program 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. *//* $Id$ */#ifndef MPEGDEMUX_H#define MPEGDEMUX_H#define TS_PACKET_SIZE 188#define MAX_PAT_ENTRIES 5#define MODULE "mpeg_reader"class mpeg_reader {private:    unsigned char * buffer;    int size, offset;public:    mpeg_reader():buffer(NULL),size(0),offset(0) { }    unsigned char * GetPacket() {	unsigned char * buf = buffer + offset;	if(!buffer) return NULL;	while(offset+TS_PACKET_SIZE <= size) {	    if(*buf == 0x47) {		DEBUG_MSG("Found sync @%d", offset);		offset += TS_PACKET_SIZE;		return buf;	    } else if(buf[12] == 0x47) {		// Skip RTP header when present		offset += 12; buf += 12;		continue;	    }	    buf++;	    offset++;	}	if(size != offset) {	    LOG_MSG("No valid sync points found, %d bytes unused", size-offset);	}	return NULL;    }    void SetBuffer(unsigned char * b, int s) {	buffer = b; size = s; offset = 0;    }    int LeftBytes(void) { return size-offset; }    ~mpeg_reader() { }};#undef MODULE#define MODULE "mpeg_demux"class mpeg_demux : public Splitter {private:    // PAT/PMT tables    PAT_entry pat_entries[MAX_PAT_ENTRIES];    unsigned int num_pat_entries;    unsigned int num_valid_pmts;    bool first_pat, valid_pat;    bool m_audio, m_video;    bool wait;    int pcr_count;    // PIDs to decode    unsigned int MPEG2_Transport_VideoPID;    unsigned int MPEG2_Transport_AudioPID;    // TS reader & current packet being processed    mpeg_reader rdr;    unsigned char * pkt;    int   ProcessHeader(bool);    bool  ParsePAT();    bool  ParsePMT(unsigned int);    void  ProcessVideoPacket();    void  ProcessAudioPacket();    bool (*SeqHeader)(unsigned char *);    static bool MpegHDR(unsigned char * p) {	if((p[3] == 0xB3) && (p[0] == 0x0) && (p[1] == 0x0) && (p[2] == 0x1))	    return true;	return false;    }    static bool defaultHDR(unsigned char * p) {	return true;    }public:    mpeg_demux(bool w):num_pat_entries(0),num_valid_pmts(0),		    first_pat(true),valid_pat(false),		    m_audio(false),m_video(false),		    wait(w),pcr_count(0),pkt(NULL),SeqHeader(defaultHDR) { }    int ProcessData(unsigned char*, int);    ~mpeg_demux() {	timer->Reset();    }};#undef MODULE#endif // MPEGDEMUX_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -