Mercurial > mplayer.hg
annotate parse_es.c @ 1905:8d773b35751e
*** empty log message ***
author | gabucino |
---|---|
date | Mon, 17 Sep 2001 18:15:18 +0000 |
parents | 1728d249c783 |
children | 5216f108cb4f |
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 | 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 | 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 | 15 |
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 | 21 |
22 // sync video stream, and returns next packet code | |
23 int sync_video_packet(demux_stream_t *ds){ | |
24 int skipped=0; | |
25 // we need enough bytes in the buffer: | |
26 while(videobuf_code_len<4){ | |
27 #if 0 | |
28 int c; | |
29 c=demux_getc(ds);if(c<0){ return 0;} // EOF | |
30 videobuf_code[videobuf_code_len++]=c; | |
31 #else | |
32 videobuf_code[videobuf_code_len++]=demux_getc(ds); | |
33 #endif | |
34 } | |
35 // sync packet: | |
36 while(1){ | |
37 int c; | |
38 if(videobuf_code[0]==0 && | |
39 videobuf_code[1]==0 && | |
40 videobuf_code[2]==1) break; // synced | |
41 // shift buffer, drop first byte | |
42 ++skipped; | |
43 videobuf_code[0]=videobuf_code[1]; | |
44 videobuf_code[1]=videobuf_code[2]; | |
45 videobuf_code[2]=videobuf_code[3]; | |
46 c=demux_getc(ds);if(c<0){ return 0;} // EOF | |
47 videobuf_code[3]=c; | |
48 } | |
400 | 49 if(verbose>=2) if(skipped) printf("videobuf: %d bytes skipped (next: 0x1%02X)\n",skipped,videobuf_code[3]); |
1 | 50 return 0x100|videobuf_code[3]; |
51 } | |
52 | |
53 // return: packet length | |
54 int read_video_packet(demux_stream_t *ds){ | |
55 int packet_start; | |
56 | |
57 // SYNC STREAM | |
58 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF) | |
59 | |
60 // COPY STARTCODE: | |
61 packet_start=videobuf_len; | |
62 videobuffer[videobuf_len+0]=videobuf_code[0]; | |
63 videobuffer[videobuf_len+1]=videobuf_code[1]; | |
64 videobuffer[videobuf_len+2]=videobuf_code[2]; | |
65 videobuffer[videobuf_len+3]=videobuf_code[3]; | |
66 videobuf_len+=4; | |
67 | |
68 // READ PACKET: | |
69 { unsigned int head=-1; | |
70 while(videobuf_len<VIDEOBUFFER_SIZE){ | |
71 int c=demux_getc(ds); | |
72 if(c<0) break; // EOF | |
73 videobuffer[videobuf_len++]=c; | |
74 #if 1 | |
75 head<<=8; | |
76 if(head==0x100) break; // synced | |
77 head|=c; | |
78 #else | |
79 if(videobuffer[videobuf_len-4]==0 && | |
80 videobuffer[videobuf_len-3]==0 && | |
81 videobuffer[videobuf_len-2]==1) break; // synced | |
82 #endif | |
83 } | |
84 } | |
85 | |
86 if(ds->eof){ | |
87 videobuf_code_len=0; // EOF, no next code | |
88 return videobuf_len-packet_start; | |
89 } | |
90 | |
91 videobuf_len-=4; | |
92 | |
400 | 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 | 94 |
95 // Save next packet code: | |
96 videobuf_code[0]=videobuffer[videobuf_len]; | |
97 videobuf_code[1]=videobuffer[videobuf_len+1]; | |
98 videobuf_code[2]=videobuffer[videobuf_len+2]; | |
99 videobuf_code[3]=videobuffer[videobuf_len+3]; | |
100 videobuf_code_len=4; | |
101 | |
102 return videobuf_len-packet_start; | |
103 } | |
104 | |
105 // return: next packet code | |
106 int skip_video_packet(demux_stream_t *ds){ | |
107 | |
108 // SYNC STREAM | |
109 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF) | |
110 | |
111 videobuf_code_len=0; // force resync | |
112 | |
113 // SYNC AGAIN: | |
114 return sync_video_packet(ds); | |
115 } |