Mercurial > mplayer.hg
annotate libmpdemux/parse_es.c @ 16593:1c13fb2ba5a9
Allow specifying a custom (ppm) texture for texture unit 3
author | reimar |
---|---|
date | Sun, 25 Sep 2005 16:31:58 +0000 |
parents | 8ea2e7ab3106 |
children | 0b17629dbade |
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 | |
16369 | 56 if (VIDEOBUFFER_SIZE - videobuf_len < 5) |
57 return 0; | |
1 | 58 // SYNC STREAM |
59 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF) | |
60 | |
61 // COPY STARTCODE: | |
62 packet_start=videobuf_len; | |
63 videobuffer[videobuf_len+0]=videobuf_code[0]; | |
64 videobuffer[videobuf_len+1]=videobuf_code[1]; | |
65 videobuffer[videobuf_len+2]=videobuf_code[2]; | |
66 videobuffer[videobuf_len+3]=videobuf_code[3]; | |
67 videobuf_len+=4; | |
68 | |
69 // READ PACKET: | |
16369 | 70 { |
71 register uint32_t head = 0xffffffff; | |
72 register unsigned char *buf = &videobuffer[VIDEOBUFFER_SIZE]; | |
73 register int pos = videobuf_len - VIDEOBUFFER_SIZE; | |
74 do { | |
1 | 75 int c=demux_getc(ds); |
76 if(c<0) break; // EOF | |
16369 | 77 buf[pos]=c; |
1 | 78 head<<=8; |
79 if(head==0x100) break; // synced | |
80 head|=c; | |
16369 | 81 } while (++pos); |
82 if (pos) pos++; // increment missed because of break | |
83 videobuf_len = &buf[pos] - videobuffer; | |
1 | 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 | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1430
diff
changeset
|
93 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 | 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 } |