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

📄 audiofilter.c

📁 传输流分析
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * audiofilter - remove audio from dvb stream * Copyright (C) Marcus Metzler 2002  * * 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. * Or, point your browser to http://www.gnu.org/copyleft/gpl.html *   * The author can be reached at mocm@metzlerbros.de,   */#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <getopt.h>#include <stdio.h>#include <stdlib.h>#include <stdint.h>#include <netinet/in.h>#include <stdio.h>#include <unistd.h>#include <string.h>#define PROG_STREAM_MAP  0xBC#define PRIVATE_STREAM1  0xBD#define PADDING_STREAM   0xBE#define PRIVATE_STREAM2  0xBF#define AUDIO_STREAM_S   0xC0#define AUDIO_STREAM_E   0xDF#define VIDEO_STREAM_S   0xE0#define VIDEO_STREAM_E   0xEF#define ECM_STREAM       0xF0#define EMM_STREAM       0xF1#define DSM_CC_STREAM    0xF2#define ISO13522_STREAM  0xF3#define PROG_STREAM_DIR  0xFF#define P2P_LENGTH 2048#define PTS_DTS_FLAGS    0xC0#define PTS_ONLY         0x80#define PTS_DTS          0xC0#define MAX_PLENGTH 0xFFFF#define MMAX_PLENGTH (8*MAX_PLENGTH)enum{NOPES, AUDIO, VIDEO};typedef struct p2pstruct{        int found;        uint8_t buf[MMAX_PLENGTH];        uint8_t cid;        uint8_t subid;        uint32_t plength;        uint8_t plen[2];        uint8_t flag1;        uint8_t flag2;        uint8_t hlength;        uint8_t pts[5];        int mpeg;        uint8_t check;        int fd1;        int filter;        int which;        int done;        void (*func)(uint8_t *buf, int count, void *p);        int fill;        uint8_t vobbuf[2048], *b;}p2p;int filter_pes (uint8_t *buf, int count, p2p *p, int (*func)(p2p *p)){        int l;        unsigned short *pl;        int c=0;        int ret = 1;        uint8_t headr[3] = { 0x00, 0x00, 0x01} ;        while (c < count && (p->mpeg == 0 ||                             (p->mpeg == 1 && p->found < 7) ||                             (p->mpeg == 2 && p->found < 9))                        &&  (p->found < 5 || !p->done)) {                switch ( p->found ) {                case 0:                case 1:                        if (buf[c] == 0x00)                                p->found++;                        else {                                if (p->fd1 >= 0)                                        write(p->fd1,buf+c,1);                                p->found = 0;                        }                        c++;                        break;                case 2:                        if (buf[c] == 0x01)                                p->found++;                        else if (buf[c] == 0) {                                p->found = 2;                        } else {                                if (p->fd1 >= 0)                                        write(p->fd1,buf+c,1);                                p->found = 0;                        }                        c++;                        break;                case 3:                        p->cid = 0;                        switch (buf[c]) {                        case PROG_STREAM_MAP:                        case PRIVATE_STREAM2:                        case PROG_STREAM_DIR:                        case ECM_STREAM     :                        case EMM_STREAM     :                        case PADDING_STREAM :                        case DSM_CC_STREAM  :                        case ISO13522_STREAM:                                if (p->fd1 >= 0)                                        write(p->fd1,buf+c,1);                                p->done = 1;                        case PRIVATE_STREAM1:                        case VIDEO_STREAM_S ... VIDEO_STREAM_E:                        case AUDIO_STREAM_S ... AUDIO_STREAM_E:                                p->found++;                                p->cid = buf[c];                                c++;                                break;                        default:                                if (p->fd1 >= 0)                                        write(p->fd1,buf+c,1);                                p->found = 0;                                break;                        }                        break;                case 4:                        if (count-c > 1) {                                pl = (unsigned short *) (buf+c);                                p->plength =  ntohs(*pl);                                p->plen[0] = buf[c];                                c++;                                p->plen[1] = buf[c];                                c++;                                p->found+=2;                        } else {                                p->plen[0] = buf[c];                                p->found++;                                return 1;                        }                        break;                case 5:                        p->plen[1] = buf[c];                        c++;                        pl = (unsigned short *) p->plen;                        p->plength = ntohs(*pl);                        p->found++;                        break;                case 6:                        if (!p->done) {                                p->flag1 = buf[c];                                c++;                                p->found++;                                if ( (p->flag1 & 0xC0) == 0x80 )                                        p->mpeg = 2;                                else {                                        p->hlength = 0;                                        p->which = 0;                                        p->mpeg = 1;                                        p->flag2 = 0;                                }                        }                        break;                case 7:                        if ( !p->done && p->mpeg == 2) {                                p->flag2 = buf[c];                                c++;                                p->found++;                        }                        break;                case 8:                        if ( !p->done && p->mpeg == 2) {                                p->hlength = buf[c];                                c++;                                p->found++;                        }                        break;                default:                        break;                }        }        if (!p->plength)                p->plength = MMAX_PLENGTH-6;        if ( p->done || ((p->mpeg == 2 && p->found >= 9)  ||                         (p->mpeg == 1 && p->found >= 7)) ) {                switch (p->cid) {                case AUDIO_STREAM_S ... AUDIO_STREAM_E:                case VIDEO_STREAM_S ... VIDEO_STREAM_E:                case PRIVATE_STREAM1:                        memcpy(p->buf, headr, 3);                        p->buf[3] = p->cid;                        memcpy(p->buf+4,p->plen,2);                        if (p->mpeg == 2 && p->found == 9) {                                p->buf[6] = p->flag1;                                p->buf[7] = p->flag2;                                p->buf[8] = p->hlength;                        }                        if (p->mpeg == 1 && p->found == 7) {                                p->buf[6] = p->flag1;                        }                        if (p->mpeg == 2 && (p->flag2 & PTS_ONLY) &&                                        p->found < 14) {                                while (c < count && p->found < 14) {                                        p->pts[p->found-9] = buf[c];                                        p->buf[p->found] = buf[c];                                        c++;                                        p->found++;                                }                                if (c == count)                                        return 1;                        }                        if (p->mpeg == 1 && p->which < 2000) {                                if (p->found == 7) {                                        p->check = p->flag1;                                        p->hlength = 1;                                }                                while (!p->which && c < count &&                                                p->check == 0xFF) {                                        p->check = buf[c];                                        p->buf[p->found] = buf[c];                                        c++;                                        p->found++;                                        p->hlength++;                                }                                if ( c == count)                                        return 1;                                if ( (p->check & 0xC0) == 0x40 && !p->which) {                                        p->check = buf[c];                                        p->buf[p->found] = buf[c];

⌨️ 快捷键说明

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