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
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"
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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 // sync video stream, and returns next packet code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 int sync_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 int skipped=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 // we need enough bytes in the buffer:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 while(videobuf_code_len<4){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 int c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 c=demux_getc(ds);if(c<0){ return 0;} // EOF
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 videobuf_code[videobuf_code_len++]=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 videobuf_code[videobuf_code_len++]=demux_getc(ds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 // sync packet:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 while(1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 int c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 if(videobuf_code[0]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 videobuf_code[1]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 videobuf_code[2]==1) break; // synced
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 // shift buffer, drop first byte
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 ++skipped;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 videobuf_code[0]=videobuf_code[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 videobuf_code[1]=videobuf_code[2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 videobuf_code[2]=videobuf_code[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 c=demux_getc(ds);if(c<0){ return 0;} // EOF
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 videobuf_code[3]=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 return 0x100|videobuf_code[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 // return: packet length
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 int read_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 int packet_start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 // SYNC STREAM
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 // COPY STARTCODE:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 packet_start=videobuf_len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 videobuffer[videobuf_len+0]=videobuf_code[0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 videobuffer[videobuf_len+1]=videobuf_code[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 videobuffer[videobuf_len+2]=videobuf_code[2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 videobuffer[videobuf_len+3]=videobuf_code[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 videobuf_len+=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 // READ PACKET:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 { unsigned int head=-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 while(videobuf_len<VIDEOBUFFER_SIZE){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 int c=demux_getc(ds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 if(c<0) break; // EOF
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 videobuffer[videobuf_len++]=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 #if 1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 head<<=8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 if(head==0x100) break; // synced
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 head|=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 if(videobuffer[videobuf_len-4]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 videobuffer[videobuf_len-3]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 videobuffer[videobuf_len-2]==1) break; // synced
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 if(ds->eof){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 videobuf_code_len=0; // EOF, no next code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 return videobuf_len-packet_start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 videobuf_len-=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 // Save next packet code:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 videobuf_code[0]=videobuffer[videobuf_len];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 videobuf_code[1]=videobuffer[videobuf_len+1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 videobuf_code[2]=videobuffer[videobuf_len+2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 videobuf_code[3]=videobuffer[videobuf_len+3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 videobuf_code_len=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 return videobuf_len-packet_start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 // return: next packet code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 int skip_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 // SYNC STREAM
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 videobuf_code_len=0; // force resync
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 // SYNC AGAIN:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 return sync_video_packet(ds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 }