annotate parse_es.c @ 644:88eb1a3f7bfb

Changed code, should be faster on Athlon/K6 but slower on PIII with SSE, more portable.
author atmosfear
date Thu, 26 Apr 2001 20:35:58 +0000
parents ae91bfef2a94
children d1fb303707d3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 //=================== VIDEO PARSER =========================
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 #define MAX_VIDEO_PACKET_SIZE (224*1024+4)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 #define VIDEOBUFFER_SIZE 0x100000
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 //static unsigned char videobuffer[MAX_VIDEO_PACKET_SIZE];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 static unsigned char* videobuffer=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 static int videobuf_len=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 static unsigned char videobuf_code[4];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 static int videobuf_code_len=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 // sync video stream, and returns next packet code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 int sync_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 int skipped=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 // we need enough bytes in the buffer:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 while(videobuf_code_len<4){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 int c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 c=demux_getc(ds);if(c<0){ return 0;} // EOF
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 videobuf_code[videobuf_code_len++]=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 videobuf_code[videobuf_code_len++]=demux_getc(ds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 // sync packet:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 while(1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 int c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 if(videobuf_code[0]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 videobuf_code[1]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 videobuf_code[2]==1) break; // synced
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 // shift buffer, drop first byte
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 ++skipped;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 videobuf_code[0]=videobuf_code[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 videobuf_code[1]=videobuf_code[2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 videobuf_code[2]=videobuf_code[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 c=demux_getc(ds);if(c<0){ return 0;} // EOF
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 videobuf_code[3]=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 }
400
ae91bfef2a94 fixed debug printfs
arpi_esp
parents: 1
diff changeset
40 if(verbose>=2) if(skipped) printf("videobuf: %d bytes skipped (next: 0x1%02X)\n",skipped,videobuf_code[3]);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 return 0x100|videobuf_code[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 // return: packet length
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 int read_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 int packet_start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 // SYNC STREAM
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 // COPY STARTCODE:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 packet_start=videobuf_len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 videobuffer[videobuf_len+0]=videobuf_code[0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 videobuffer[videobuf_len+1]=videobuf_code[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 videobuffer[videobuf_len+2]=videobuf_code[2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 videobuffer[videobuf_len+3]=videobuf_code[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 videobuf_len+=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 // READ PACKET:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 { unsigned int head=-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 while(videobuf_len<VIDEOBUFFER_SIZE){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 int c=demux_getc(ds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 if(c<0) break; // EOF
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 videobuffer[videobuf_len++]=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 #if 1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 head<<=8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 if(head==0x100) break; // synced
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 head|=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 if(videobuffer[videobuf_len-4]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 videobuffer[videobuf_len-3]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 videobuffer[videobuf_len-2]==1) break; // synced
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 if(ds->eof){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 videobuf_code_len=0; // EOF, no next code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 return videobuf_len-packet_start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 videobuf_len-=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83
400
ae91bfef2a94 fixed debug printfs
arpi_esp
parents: 1
diff changeset
84 if(verbose>=2) printf("videobuf: packet 0x1%02X len=%d (total=%d)\n",videobuffer[packet_start+3],videobuf_len-packet_start,videobuf_len);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 // Save next packet code:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 videobuf_code[0]=videobuffer[videobuf_len];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 videobuf_code[1]=videobuffer[videobuf_len+1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 videobuf_code[2]=videobuffer[videobuf_len+2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 videobuf_code[3]=videobuffer[videobuf_len+3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 videobuf_code_len=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 return videobuf_len-packet_start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 // return: next packet code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 int skip_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 // SYNC STREAM
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 videobuf_code_len=0; // force resync
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 // SYNC AGAIN:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 return sync_video_packet(ds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 }