annotate libmpdemux/parse_es.c @ 21533:390b966a0f8c

cscd produces BGR15, not BGR16
author reimar
date Sat, 09 Dec 2006 13:32:46 +0000
parents a9e2922e91fd
children 4d81dbdf46b9
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 #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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
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;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
18 int next_nal = -1;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
19 ///! legacy variable, 4 if stream is synced, 0 if not
1376
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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
22 #define MAX_SYNCLEN (10 * 1024 * 1024)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 // sync video stream, and returns next packet code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 int sync_video_packet(demux_stream_t *ds){
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
25 if (!videobuf_code_len) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 int skipped=0;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
27 if (!demux_pattern_3(ds, NULL, MAX_SYNCLEN, &skipped, 0x100)) {
17420
a9e2922e91fd suppress error message at eof
reimar
parents: 17418
diff changeset
28 if (skipped == MAX_SYNCLEN)
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
29 mp_msg(MSGT_DEMUXER, MSGL_ERR, "parse_es: could not sync video stream!\n", skipped);
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
30 goto eof_out;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
31 }
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
32 next_nal = demux_getc(ds);
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
33 if (next_nal < 0)
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
34 goto eof_out;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
35 videobuf_code_len = 4;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
36 if(skipped) mp_dbg(MSGT_PARSEES,MSGL_DBG2,"videobuf: %d bytes skipped (next: 0x1%02X)\n",skipped,next_nal);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 }
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
38 return 0x100|next_nal;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
39
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
40 eof_out:
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
41 next_nal = -1;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
42 videobuf_code_len = 0;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
43 return 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 // return: packet length
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 int read_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 int packet_start;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
49 int res, read;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50
16369
8ea2e7ab3106 faster mpg and much faster gxf demuxing
reimar
parents: 2555
diff changeset
51 if (VIDEOBUFFER_SIZE - videobuf_len < 5)
8ea2e7ab3106 faster mpg and much faster gxf demuxing
reimar
parents: 2555
diff changeset
52 return 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 // SYNC STREAM
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 // COPY STARTCODE:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 packet_start=videobuf_len;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
58 videobuffer[videobuf_len+0]=0;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
59 videobuffer[videobuf_len+1]=0;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
60 videobuffer[videobuf_len+2]=1;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
61 videobuffer[videobuf_len+3]=next_nal;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 videobuf_len+=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 // READ PACKET:
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
65 res = demux_pattern_3(ds, &videobuffer[videobuf_len],
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
66 VIDEOBUFFER_SIZE - videobuf_len, &read, 0x100);
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
67 videobuf_len += read;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
68 if (!res)
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
69 goto eof_out;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
70
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
71 videobuf_len-=3;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1430
diff changeset
73 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
74
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 // Save next packet code:
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
76 next_nal = demux_getc(ds);
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
77 if (next_nal < 0)
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
78 goto eof_out;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 videobuf_code_len=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 return videobuf_len-packet_start;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
82
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
83 eof_out:
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
84 next_nal = -1;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
85 videobuf_code_len = 0;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
86 return videobuf_len - packet_start;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 // return: next packet code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 int skip_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 // SYNC STREAM
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 videobuf_code_len=0; // force resync
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 // SYNC AGAIN:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 return sync_video_packet(ds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 }