annotate parse_es.c @ 1908:b27a56d158de

Enable Alpha Code.
author atmos4
date Tue, 18 Sep 2001 13:45:38 +0000
parents 1728d249c783
children 5216f108cb4f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
1 //=================== MPEG-ES VIDEO PARSER =========================
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
2
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
3 #include <stdio.h>
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
4 #include <stdlib.h>
1430
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1376
diff changeset
5 #include <unistd.h>
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
6
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
7 extern int verbose; // defined in mplayer.c
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
9 #include "config.h"
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
10
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
11 #include "stream.h"
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
12 #include "demuxer.h"
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
13
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
14 #include "parse_es.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 //static unsigned char videobuffer[MAX_VIDEO_PACKET_SIZE];
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
17 unsigned char* videobuffer=NULL;
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
18 int videobuf_len=0;
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
19 unsigned char videobuf_code[4];
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
20 int videobuf_code_len=0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 // sync video stream, and returns next packet code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 int sync_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 int skipped=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 // we need enough bytes in the buffer:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 while(videobuf_code_len<4){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 int c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 c=demux_getc(ds);if(c<0){ return 0;} // EOF
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 videobuf_code[videobuf_code_len++]=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 videobuf_code[videobuf_code_len++]=demux_getc(ds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 // sync packet:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 while(1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 int c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 if(videobuf_code[0]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 videobuf_code[1]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 videobuf_code[2]==1) break; // synced
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 // shift buffer, drop first byte
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 ++skipped;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 videobuf_code[0]=videobuf_code[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 videobuf_code[1]=videobuf_code[2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 videobuf_code[2]=videobuf_code[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 c=demux_getc(ds);if(c<0){ return 0;} // EOF
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 videobuf_code[3]=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 }
400
ae91bfef2a94 fixed debug printfs
arpi_esp
parents: 1
diff changeset
49 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
50 return 0x100|videobuf_code[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 // return: packet length
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 int read_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 int packet_start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 // SYNC STREAM
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 // COPY STARTCODE:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 packet_start=videobuf_len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 videobuffer[videobuf_len+0]=videobuf_code[0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 videobuffer[videobuf_len+1]=videobuf_code[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 videobuffer[videobuf_len+2]=videobuf_code[2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 videobuffer[videobuf_len+3]=videobuf_code[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 videobuf_len+=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 // READ PACKET:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 { unsigned int head=-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 while(videobuf_len<VIDEOBUFFER_SIZE){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 int c=demux_getc(ds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 if(c<0) break; // EOF
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 videobuffer[videobuf_len++]=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 #if 1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 head<<=8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 if(head==0x100) break; // synced
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 head|=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 if(videobuffer[videobuf_len-4]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 videobuffer[videobuf_len-3]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 videobuffer[videobuf_len-2]==1) break; // synced
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 if(ds->eof){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 videobuf_code_len=0; // EOF, no next code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 return videobuf_len-packet_start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 videobuf_len-=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92
400
ae91bfef2a94 fixed debug printfs
arpi_esp
parents: 1
diff changeset
93 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
94
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 // Save next packet code:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 videobuf_code[0]=videobuffer[videobuf_len];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 videobuf_code[1]=videobuffer[videobuf_len+1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 videobuf_code[2]=videobuffer[videobuf_len+2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 videobuf_code[3]=videobuffer[videobuf_len+3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 videobuf_code_len=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 return videobuf_len-packet_start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 // return: next packet code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 int skip_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 // SYNC STREAM
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 videobuf_code_len=0; // force resync
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 // SYNC AGAIN:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 return sync_video_packet(ds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 }