annotate libmpdemux/parse_es.c @ 33234:2f5d6ec5c131

rpm: Delete reference to remove --enable-largefiles configure option.
author diego
date Sun, 24 Apr 2011 10:44:12 +0000
parents b9c9e72a37b2
children
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
31850
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
21 #include <stdint.h>
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
22 #include <stdio.h>
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
23 #include <stdlib.h>
1430
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1376
diff changeset
24 #include <unistd.h>
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
25
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
26 #include "config.h"
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1430
diff changeset
27 #include "mp_msg.h"
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1430
diff changeset
28 #include "help_mp.h"
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
29
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 17420
diff changeset
30 #include "stream/stream.h"
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
31 #include "demuxer.h"
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
32 #include "parse_es.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 //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
35 unsigned char* videobuffer=NULL;
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
36 int videobuf_len=0;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
37 int next_nal = -1;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
38 ///! 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
39 int videobuf_code_len=0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
41 #define MAX_SYNCLEN (10 * 1024 * 1024)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 // sync video stream, and returns next packet code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 int sync_video_packet(demux_stream_t *ds){
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
44 if (!videobuf_code_len) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 int skipped=0;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
46 if (!demux_pattern_3(ds, NULL, MAX_SYNCLEN, &skipped, 0x100)) {
17420
a9e2922e91fd suppress error message at eof
reimar
parents: 17418
diff changeset
47 if (skipped == MAX_SYNCLEN)
23440
1a4f46c395eb Remove unused parameter for mp_msg
zuxy
parents: 22605
diff changeset
48 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
49 goto eof_out;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
50 }
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
51 next_nal = demux_getc(ds);
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
52 if (next_nal < 0)
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
53 goto eof_out;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
54 videobuf_code_len = 4;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
55 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
56 }
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
57 return 0x100|next_nal;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
58
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
59 eof_out:
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
60 next_nal = -1;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
61 videobuf_code_len = 0;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
62 return 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 // return: packet length
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 int read_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 int packet_start;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
68 int res, read;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
69
16369
8ea2e7ab3106 faster mpg and much faster gxf demuxing
reimar
parents: 2555
diff changeset
70 if (VIDEOBUFFER_SIZE - videobuf_len < 5)
8ea2e7ab3106 faster mpg and much faster gxf demuxing
reimar
parents: 2555
diff changeset
71 return 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 // SYNC STREAM
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 // COPY STARTCODE:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 packet_start=videobuf_len;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
77 videobuffer[videobuf_len+0]=0;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
78 videobuffer[videobuf_len+1]=0;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
79 videobuffer[videobuf_len+2]=1;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
80 videobuffer[videobuf_len+3]=next_nal;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 videobuf_len+=4;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
82
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 // READ PACKET:
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
84 res = demux_pattern_3(ds, &videobuffer[videobuf_len],
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
85 VIDEOBUFFER_SIZE - videobuf_len, &read, 0x100);
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
86 videobuf_len += read;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
87 if (!res)
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
88 goto eof_out;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
89
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
90 videobuf_len-=3;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1430
diff changeset
92 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
93
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 // Save next packet code:
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
95 next_nal = demux_getc(ds);
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
96 if (next_nal < 0)
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
97 goto eof_out;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 videobuf_code_len=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 return videobuf_len-packet_start;
17418
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
101
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
102 eof_out:
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
103 next_nal = -1;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
104 videobuf_code_len = 0;
0b17629dbade faster and (IMHO) cleaner code.
reimar
parents: 16369
diff changeset
105 return videobuf_len - packet_start;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 // return: next packet code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 int skip_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 // SYNC STREAM
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
113
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 videobuf_code_len=0; // force resync
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
115
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 // SYNC AGAIN:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 return sync_video_packet(ds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 }
31850
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
119
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
120 /* stripped down version of a52_syncinfo() from liba52
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
121 * copyright belongs to Michel Lespinasse <walken@zoy.org>
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
122 * and Aaron Holtzman <aholtzma@ess.engr.uvic.ca> */
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
123 int mp_a52_framesize(uint8_t * buf, int *srate)
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
124 {
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
125 int rate[] = { 32, 40, 48, 56, 64, 80, 96, 112,
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
126 128, 160, 192, 224, 256, 320, 384, 448,
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
127 512, 576, 640
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
128 };
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
129 uint8_t halfrate[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 };
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
130 int frmsizecod, bitrate, half;
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
131
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
132 if ((buf[0] != 0x0b) || (buf[1] != 0x77)) /* syncword */
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
133 return 0;
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
134
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
135 if (buf[5] >= 0x60) /* bsid >= 12 */
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
136 return 0;
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
137
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
138 half = halfrate[buf[5] >> 3];
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
139
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
140 frmsizecod = buf[4] & 63;
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
141 if (frmsizecod >= 38)
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
142 return 0;
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
143
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
144 bitrate = rate[frmsizecod >> 1];
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
145
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
146 switch (buf[4] & 0xc0) {
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
147 case 0: /* 48 KHz */
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
148 *srate = 48000 >> half;
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
149 return 4 * bitrate;
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
150 case 0x40: /* 44.1 KHz */
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
151 *srate = 44100 >> half;
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
152 return 2 * (320 * bitrate / 147 + (frmsizecod & 1));
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
153 case 0x80: /* 32 KHz */
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
154 *srate = 32000 >> half;
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
155 return 6 * bitrate;
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
156 }
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
157
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
158 return 0;
b9c9e72a37b2 Move mp_a52_framesize from demux_ts.c to parse_es.c.
diego
parents: 29263
diff changeset
159 }