Mercurial > mplayer.hg
annotate libmpdemux/parse_es.c @ 15453:d7a2ffc6e694
compilation/link fix with --disable-qtx --disable-dshow
patch by Gianluigi Tiesi <mplayer at netfarm dot it>
author | diego |
---|---|
date | Sat, 14 May 2005 09:03:00 +0000 |
parents | 66837325b929 |
children | 8ea2e7ab3106 |
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 #include "config.h" |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1430
diff
changeset
|
8 #include "mp_msg.h" |
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1430
diff
changeset
|
9 #include "help_mp.h" |
1376
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 #include "parse_es.h" |
1 | 14 |
15 //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
|
16 unsigned char* videobuffer=NULL; |
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
17 int videobuf_len=0; |
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
18 unsigned char videobuf_code[4]; |
d1fb303707d3
parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents:
400
diff
changeset
|
19 int videobuf_code_len=0; |
1 | 20 |
21 // sync video stream, and returns next packet code | |
22 int sync_video_packet(demux_stream_t *ds){ | |
23 int skipped=0; | |
24 // we need enough bytes in the buffer: | |
25 while(videobuf_code_len<4){ | |
26 #if 0 | |
27 int c; | |
28 c=demux_getc(ds);if(c<0){ return 0;} // EOF | |
29 videobuf_code[videobuf_code_len++]=c; | |
30 #else | |
31 videobuf_code[videobuf_code_len++]=demux_getc(ds); | |
32 #endif | |
33 } | |
34 // sync packet: | |
35 while(1){ | |
36 int c; | |
37 if(videobuf_code[0]==0 && | |
38 videobuf_code[1]==0 && | |
39 videobuf_code[2]==1) break; // synced | |
40 // shift buffer, drop first byte | |
41 ++skipped; | |
42 videobuf_code[0]=videobuf_code[1]; | |
43 videobuf_code[1]=videobuf_code[2]; | |
44 videobuf_code[2]=videobuf_code[3]; | |
45 c=demux_getc(ds);if(c<0){ return 0;} // EOF | |
46 videobuf_code[3]=c; | |
47 } | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1430
diff
changeset
|
48 if(skipped) mp_dbg(MSGT_PARSEES,MSGL_DBG2,"videobuf: %d bytes skipped (next: 0x1%02X)\n",skipped,videobuf_code[3]); |
1 | 49 return 0x100|videobuf_code[3]; |
50 } | |
51 | |
52 // return: packet length | |
53 int read_video_packet(demux_stream_t *ds){ | |
54 int packet_start; | |
55 | |
56 // SYNC STREAM | |
57 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF) | |
58 | |
59 // COPY STARTCODE: | |
60 packet_start=videobuf_len; | |
61 videobuffer[videobuf_len+0]=videobuf_code[0]; | |
62 videobuffer[videobuf_len+1]=videobuf_code[1]; | |
63 videobuffer[videobuf_len+2]=videobuf_code[2]; | |
64 videobuffer[videobuf_len+3]=videobuf_code[3]; | |
65 videobuf_len+=4; | |
66 | |
67 // READ PACKET: | |
68 { unsigned int head=-1; | |
69 while(videobuf_len<VIDEOBUFFER_SIZE){ | |
70 int c=demux_getc(ds); | |
71 if(c<0) break; // EOF | |
72 videobuffer[videobuf_len++]=c; | |
73 #if 1 | |
74 head<<=8; | |
75 if(head==0x100) break; // synced | |
76 head|=c; | |
77 #else | |
78 if(videobuffer[videobuf_len-4]==0 && | |
79 videobuffer[videobuf_len-3]==0 && | |
80 videobuffer[videobuf_len-2]==1) break; // synced | |
81 #endif | |
82 } | |
83 } | |
84 | |
85 if(ds->eof){ | |
86 videobuf_code_len=0; // EOF, no next code | |
87 return videobuf_len-packet_start; | |
88 } | |
89 | |
90 videobuf_len-=4; | |
91 | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1430
diff
changeset
|
92 mp_dbg(MSGT_PARSEES,MSGL_DBG2,"videobuf: packet 0x1%02X len=%d (total=%d)\n",videobuffer[packet_start+3],videobuf_len-packet_start,videobuf_len); |
1 | 93 |
94 // Save next packet code: | |
95 videobuf_code[0]=videobuffer[videobuf_len]; | |
96 videobuf_code[1]=videobuffer[videobuf_len+1]; | |
97 videobuf_code[2]=videobuffer[videobuf_len+2]; | |
98 videobuf_code[3]=videobuffer[videobuf_len+3]; | |
99 videobuf_code_len=4; | |
100 | |
101 return videobuf_len-packet_start; | |
102 } | |
103 | |
104 // return: next packet code | |
105 int skip_video_packet(demux_stream_t *ds){ | |
106 | |
107 // SYNC STREAM | |
108 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF) | |
109 | |
110 videobuf_code_len=0; // force resync | |
111 | |
112 // SYNC AGAIN: | |
113 return sync_video_packet(ds); | |
114 } |