annotate libmpdemux/parse_es.c @ 30993:d3143f6ec4b3

typo fix found by ubitux
author compn
date Tue, 13 Apr 2010 01:26:20 +0000
parents 0f1b5b68af32
children b9c9e72a37b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29238
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
1 /*
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
2 * MPEG-ES video parser
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
3 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
4 * This file is part of MPlayer.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
5 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
7 * it under the terms of the GNU General Public License as published by
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
9 * (at your option) any later version.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
10 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
14 * GNU General Public License for more details.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
15 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
16 * You should have received a copy of the GNU General Public License along
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 23440
diff changeset
19 */
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
20
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
21 #include <stdio.h>
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
22 #include <stdlib.h>
1430
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1376
diff changeset
23 #include <unistd.h>
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
24
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
25 #include "config.h"
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1430
diff changeset
26 #include "mp_msg.h"
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1430
diff changeset
27 #include "help_mp.h"
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
28
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 17420
diff changeset
29 #include "stream/stream.h"
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
30 #include "demuxer.h"
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
31 #include "parse_es.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 //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
34 unsigned char* videobuffer=NULL;
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
35 int videobuf_len=0;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
36 int next_nal = -1;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
37 ///! 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
38 int videobuf_code_len=0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
40 #define MAX_SYNCLEN (10 * 1024 * 1024)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 // sync video stream, and returns next packet code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 int sync_video_packet(demux_stream_t *ds){
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
43 if (!videobuf_code_len) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 int skipped=0;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
45 if (!demux_pattern_3(ds, NULL, MAX_SYNCLEN, &skipped, 0x100)) {
17420
a9e2922e91fd suppress error message at eof
reimar
parents: 17418
diff changeset
46 if (skipped == MAX_SYNCLEN)
23440
1a4f46c395eb Remove unused parameter for mp_msg
zuxy
parents: 22605
diff changeset
47 mp_msg(MSGT_DEMUXER, MSGL_ERR, "parse_es: could not sync video stream!\n");
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
48 goto eof_out;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
49 }
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
50 next_nal = demux_getc(ds);
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
51 if (next_nal < 0)
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
52 goto eof_out;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
53 videobuf_code_len = 4;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
54 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
55 }
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
56 return 0x100|next_nal;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
57
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
58 eof_out:
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
59 next_nal = -1;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
60 videobuf_code_len = 0;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
61 return 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 // return: packet length
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 int read_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 int packet_start;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
67 int res, read;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
68
16369
8ea2e7ab3106 faster mpg and much faster gxf demuxing
reimar
parents: 2555
diff changeset
69 if (VIDEOBUFFER_SIZE - videobuf_len < 5)
8ea2e7ab3106 faster mpg and much faster gxf demuxing
reimar
parents: 2555
diff changeset
70 return 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 // SYNC STREAM
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 // COPY STARTCODE:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 packet_start=videobuf_len;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
76 videobuffer[videobuf_len+0]=0;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
77 videobuffer[videobuf_len+1]=0;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
78 videobuffer[videobuf_len+2]=1;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
79 videobuffer[videobuf_len+3]=next_nal;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 videobuf_len+=4;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
81
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 // READ PACKET:
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
83 res = demux_pattern_3(ds, &videobuffer[videobuf_len],
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
84 VIDEOBUFFER_SIZE - videobuf_len, &read, 0x100);
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
85 videobuf_len += read;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
86 if (!res)
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
87 goto eof_out;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
88
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
89 videobuf_len-=3;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1430
diff changeset
91 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
92
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 // Save next packet code:
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
94 next_nal = demux_getc(ds);
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
95 if (next_nal < 0)
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
96 goto eof_out;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 videobuf_code_len=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 return videobuf_len-packet_start;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
100
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
101 eof_out:
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
102 next_nal = -1;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
103 videobuf_code_len = 0;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
104 return videobuf_len - packet_start;
1
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)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
112
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 videobuf_code_len=0; // force resync
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
114
1
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 }