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