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

📄 audiofilter.c

📁 传输流分析
💻 C
📖 第 1 页 / 共 2 页
字号:
                                        c++;                                        p->found++;                                        p->hlength++;                                        p->which = 1;                                        if ( c == count)                                                return 1;                                        p->check = buf[c];                                        p->buf[p->found] = buf[c];                                        c++;                                        p->found++;                                        p->hlength++;                                        p->which = 2;                                        if ( c == count)                                                return 1;                                }                                if (p->which == 1) {                                        p->check = buf[c];                                        p->buf[p->found] = buf[c];                                        c++;                                        p->found++;                                        p->hlength++;                                        p->which = 2;                                        if ( c == count)                                                return 1;                                }                                if ( (p->check & 0x30) && p->check != 0xFF) {                                        p->flag2 = (p->check & 0xF0) << 2;                                        p->pts[0] = p->check;                                        p->which = 3;                                }                                if ( c == count)                                        return 1;                                if (p->which > 2) {                                        if ((p->flag2 & PTS_DTS_FLAGS)                                                        == PTS_ONLY) {                                                while (c < count &&                                                                p->which < 7) {                                                        p->pts[p->which-2] =                                                                buf[c];                                                        p->buf[p->found] =                                                                buf[c];                                                        c++;                                                        p->found++;                                                        p->which++;                                                        p->hlength++;                                                }                                                if ( c == count)                                                        return 1;                                        } else if ((p->flag2 & PTS_DTS_FLAGS)                                                        == PTS_DTS) {                                                while (c < count &&                                                                p->which< 12) {                                                        if (p->which< 7)                                                                p->pts[p->which                                                                       -2] =                                                                               buf[c];                                                        p->buf[p->found] =                                                                buf[c];                                                        c++;                                                        p->found++;                                                        p->which++;                                                        p->hlength++;                                                }                                                if ( c == count)                                                        return 1;                                        }                                        p->which = 2000;                                }                        }                        while (c < count && p->found < p->plength+6) {                                l = count -c;                                if (l+p->found > p->plength+6)                                        l = p->plength+6-p->found;                                memcpy(p->buf+p->found, buf+c, l);                                p->found += l;                                c += l;                        }                        if(p->found == p->plength+6) {                                if (func(p)) {                                        if (p->fd1 >= 0) {                                                write(p->fd1,p->buf,                                                      p->plength+6);                                        }                                } else                                        ret = 0;                        }                        break;                }                if ( p->done ) {                        if( p->found + count - c < p->plength+6) {                                p->found += count-c;                                c = count;                        } else {                                c += p->plength+6 - p->found;                                p->found = p->plength+6;                        }                }                if (p->plength && p->found == p->plength+6) {                        p->found = 0;                        p->done = 0;                        p->plength = 0;                        memset(p->buf, 0, MAX_PLENGTH);                        if (c < count)                                return filter_pes(buf+c, count-c, p, func);                }        }        return ret;}int audio_pes_filt(p2p *p){        uint8_t off;        switch(p->cid) {        case PRIVATE_STREAM1:                if ( p->cid == p->filter) {                        off = 9+p->buf[8];                        if (p->buf[off] == p->subid) {                                return 1;                        }                }                break;        case AUDIO_STREAM_S ... AUDIO_STREAM_E:                if ( p->cid == p->filter)                        return 1;                break;        default:                return 1;                break;        }        return 0;}void buf_audio_filter(int fdout, uint8_t *dat, int count, p2p *p){        int rest = 0;        if (count > 0) {                if ( p->fill+count <= 2048) {                        memcpy(p->b, dat, count);                        p->fill+=count;                        p->b += count;                        if(p->fill == 2048) {                                if (filter_pes(p->vobbuf,2048,                                                p,audio_pes_filt))                                        write(fdout,p->vobbuf,2048);                                p->b = p->vobbuf;                                p->fill = 0;                        }                } else {                        rest = 2048 - p->fill;                        memcpy(p->b , dat, rest );                        if (filter_pes(p->vobbuf,2048,                                        p,audio_pes_filt))                                write(fdout,p->vobbuf,2048);                        p->b = p->vobbuf;                        p->fill = 0;                        buf_audio_filter(fdout, dat+rest, count-rest, p);                }        }}void filter_audio_from_pes(int fdin, int fdout, uint8_t id, uint8_t subid){        p2p p;        int count = 1;        uint8_t buf[2048];        p.found = 0;        p.cid = 0;        p.mpeg = 0;        memset(p.buf,0,MMAX_PLENGTH);        memset(p.vobbuf,0,2048);        p.done = 0;        p.fd1 = -1;        p.filter = id;        p.subid = subid;        p.fill = 0;        p.b = p.vobbuf;        while (count > 0) {                count = read(fdin,buf,100);                buf_audio_filter(fdout, buf, count, &p);        }}void usage(char *progname){        fprintf(stderr,"usage: %s --pid <pid> [options]\n",progname);        fprintf(stderr,"options:\n");        fprintf(stderr,"--help,     -h              show this message\n");        fprintf(stderr,"--infile,   -i  <filename>  input (default=stdin)\n");        fprintf(stderr,"--outfile,  -o  <filename>  output (default=stdout)\n");        fprintf(stderr,"--id,       -a  <id>        audio id (default=0xc0)\n");        fprintf(stderr,"--subid,    -s  <subid>     subid for privat stream (e.g. -a 0xbd -s 0x80 for first AC3)\n");        fprintf(stderr,"\n");        exit(1);}int main(int argc, char **argv){        int fdin=STDIN_FILENO,fdout=STDOUT_FILENO;        uint8_t id=0xc0, subid=0;        int c;        while (1) {                int option_index = 0;                static struct option long_options[] = {                                                              {"infile", required_argument, NULL, 'i'                                                              },                                                              {"outfile", required_argument, NULL, 'o'},                                                              {"id", required_argument, NULL, 'a'},                                                              {"subid", required_argument, NULL, 's'},                                                              {"help", no_argument , NULL, 'h'},                                                              {0, 0, 0, 0}                                                      };                c = getopt_long (argc, argv, "hi:o:a:s:",                                 long_options, &option_index);                if (c == -1)                        break;                switch (c) {                case 'i':                        if ((fdin = open(optarg,O_RDONLY|O_LARGEFILE)) <0) {                                perror(optarg);                                exit(1);                        }                        break;                case 'o':                        if ((fdout = open(optarg,O_WRONLY|O_CREAT|O_TRUNC                                          |O_LARGEFILE,                                          S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|                                          S_IROTH|S_IWOTH)) <0) {                                perror(optarg);                                exit(1);                        }                        break;                case 'a':                        id = strtol(optarg,(char **)NULL,0);                        break;                case 's':                        subid = strtol(optarg,(char **)NULL,0);                        break;                case 'h':                default:                        usage(argv[0]);                }        }        filter_audio_from_pes(fdin, fdout, id, subid);        return(0);}

⌨️ 快捷键说明

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