Mercurial > mplayer.hg
annotate libmpdemux/parse_es.c @ 33704:22093568b553
Fix linking order to allow compiling against Debian unstable version of LIVE555.
author | reimar |
---|---|
date | Fri, 01 Jul 2011 19:08:13 +0000 |
parents | b9c9e72a37b2 |
children |
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 | 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 | 33 |
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 | 37 int next_nal = -1; |
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 | 40 |
17418 | 41 #define MAX_SYNCLEN (10 * 1024 * 1024) |
1 | 42 // sync video stream, and returns next packet code |
43 int sync_video_packet(demux_stream_t *ds){ | |
17418 | 44 if (!videobuf_code_len) { |
1 | 45 int skipped=0; |
17418 | 46 if (!demux_pattern_3(ds, NULL, MAX_SYNCLEN, &skipped, 0x100)) { |
17420 | 47 if (skipped == MAX_SYNCLEN) |
23440 | 48 mp_msg(MSGT_DEMUXER, MSGL_ERR, "parse_es: could not sync video stream!\n"); |
17418 | 49 goto eof_out; |
50 } | |
51 next_nal = demux_getc(ds); | |
52 if (next_nal < 0) | |
53 goto eof_out; | |
54 videobuf_code_len = 4; | |
55 if(skipped) mp_dbg(MSGT_PARSEES,MSGL_DBG2,"videobuf: %d bytes skipped (next: 0x1%02X)\n",skipped,next_nal); | |
1 | 56 } |
17418 | 57 return 0x100|next_nal; |
58 | |
59 eof_out: | |
60 next_nal = -1; | |
61 videobuf_code_len = 0; | |
62 return 0; | |
1 | 63 } |
64 | |
65 // return: packet length | |
66 int read_video_packet(demux_stream_t *ds){ | |
67 int packet_start; | |
17418 | 68 int res, read; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
69 |
16369 | 70 if (VIDEOBUFFER_SIZE - videobuf_len < 5) |
71 return 0; | |
1 | 72 // SYNC STREAM |
73 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF) | |
74 | |
75 // COPY STARTCODE: | |
76 packet_start=videobuf_len; | |
17418 | 77 videobuffer[videobuf_len+0]=0; |
78 videobuffer[videobuf_len+1]=0; | |
79 videobuffer[videobuf_len+2]=1; | |
80 videobuffer[videobuf_len+3]=next_nal; | |
1 | 81 videobuf_len+=4; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
82 |
1 | 83 // READ PACKET: |
17418 | 84 res = demux_pattern_3(ds, &videobuffer[videobuf_len], |
85 VIDEOBUFFER_SIZE - videobuf_len, &read, 0x100); | |
86 videobuf_len += read; | |
87 if (!res) | |
88 goto eof_out; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
89 |
17418 | 90 videobuf_len-=3; |
1 | 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 | 93 |
94 // Save next packet code: | |
17418 | 95 next_nal = demux_getc(ds); |
96 if (next_nal < 0) | |
97 goto eof_out; | |
1 | 98 videobuf_code_len=4; |
99 | |
100 return videobuf_len-packet_start; | |
17418 | 101 |
102 eof_out: | |
103 next_nal = -1; | |
104 videobuf_code_len = 0; | |
105 return videobuf_len - packet_start; | |
1 | 106 } |
107 | |
108 // return: next packet code | |
109 int skip_video_packet(demux_stream_t *ds){ | |
110 | |
111 // SYNC STREAM | |
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 | 114 videobuf_code_len=0; // force resync |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
115 |
1 | 116 // SYNC AGAIN: |
117 return sync_video_packet(ds); | |
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 } |