annotate libmpdemux/demux_real.c @ 3841:25600d0bdc63

SSE2 support
author arpi
date Fri, 28 Dec 2001 18:29:12 +0000
parents 15745f11e717
children a3c73266f81f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
1 /*
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
2 Real parser & demuxer
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
3
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
4 (C) Alex Beregszaszi <alex@naxine.org>
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
5
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
6 Based on FFmpeg's libav/rm.c.
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
7 */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
8
3788
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
9 /*
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
10 Some codecs for Real (from Mike Melanson):
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
11
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
12 RV10: As has been mentioned, H.263-based; not an unreasonable guess
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
13 RV20: RealVideo 2.0, nothing known
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
14 RV30: RealVideo 3.0,nothing known, but I don't believe I've ever seen any
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
15 media encoded with it
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
16 DNET: apparently one of their original audio codecs, to be used with music
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
17 SIPR: SiprNet, based on ACELP, and is great for compressing voice
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
18 COKR(?): Cooker, the fabled G2 audio codec
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
19
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
20 New infos:
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
21
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
22 Audio codecs: (supported by RealPlayer8 for Linux)
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
23 ATRC - RealAudio 8 (ATRAC3)
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
24 COOK - RealAudio G2
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
25 DNET - RealAudio 3.0
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
26 SIPR - SiproLab's audio codec
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
27
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
28 Video codecs: (supported by RealPlayer8 for Linux)
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
29 RV10
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
30 RV20
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
31 RV30
3788
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
32 */
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
33
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
34 #include <stdio.h>
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
35 #include <stdlib.h>
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
36 #include <unistd.h>
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
37
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
38 #include "config.h"
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
39 #include "mp_msg.h"
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
40 #include "help_mp.h"
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
41
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
42 #include "stream.h"
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
43 #include "demuxer.h"
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
44 #include "stheader.h"
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
45 #include "bswap.h"
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
46
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
47 #define MKTAG(a, b, c, d) (a | (b << 8) | (c << 16) | (d << 24))
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
48
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
49 #define MAX_STREAMS 10
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
50
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
51 typedef struct {
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
52 int data_chunk_offset; /* i think for seeking */
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
53 int num_of_packets;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
54 int last_a_stream;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
55 int a_streams[MAX_STREAMS];
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
56 int last_v_stream;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
57 int v_streams[MAX_STREAMS];
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
58 } real_priv_t;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
59
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
60 static void get_str(int isbyte, demuxer_t *demuxer, char *buf, int buf_size)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
61 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
62 int len, i;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
63 char *q;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
64
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
65 if (isbyte)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
66 len = stream_read_char(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
67 else
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
68 len = stream_read_word(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
69 #if 1
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
70 q = buf;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
71 for (i = 0; i < len; i++)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
72 if (i < (buf_size - 1))
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
73 *q++ = stream_read_char(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
74 *q = 0;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
75 #else
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
76 stream_read(demuxer->stream, buf, buf_size);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
77 #endif
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
78 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
79
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
80 static void skip_str(int isbyte, demuxer_t *demuxer)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
81 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
82 int len;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
83
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
84 if (isbyte)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
85 len = stream_read_char(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
86 else
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
87 len = stream_read_word(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
88
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
89 stream_skip(demuxer->stream, len);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
90
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
91 printf("skip_str: %d bytes skipped\n", len);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
92 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
93
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
94 int real_check_file(demuxer_t* demuxer)
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
95 {
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
96 real_priv_t *priv;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
97 int c;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
98
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
99 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for REAL\n");
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
100
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
101 c = stream_read_dword_le(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
102 if (c == -256)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
103 return 0; /* EOF */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
104 if (c != MKTAG('.', 'R', 'M', 'F'))
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
105 return 0; /* bad magic */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
106
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
107 priv = malloc(sizeof(real_priv_t));
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
108 memset(priv, 0, sizeof(real_priv_t));
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
109 demuxer->priv = priv;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
110
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
111 return 1;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
112 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
113
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
114 // return value:
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
115 // 0 = EOF or no stream found
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
116 // 1 = successfully read a packet
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
117 int demux_real_fill_buffer(demuxer_t *demuxer)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
118 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
119 real_priv_t *priv = demuxer->priv;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
120 demux_stream_t *ds = NULL;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
121 int len;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
122 int timestamp;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
123 int stream_id;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
124 int i;
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
125 int flags;
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
126
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
127 // printf("num_of_packets: %d\n", priv->num_of_packets);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
128
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
129 loop:
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
130 if (priv->num_of_packets == 0)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
131 return 0; /* EOF */
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
132 stream_skip(demuxer->stream, 2); /* version */
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
133 len = stream_read_word(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
134 if (len == -256) /* EOF */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
135 return 0;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
136 if (len < 12)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
137 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
138 printf("bad packet len (%d)\n", len);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
139 stream_skip(demuxer->stream, len);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
140 goto loop;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
141 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
142 stream_id = stream_read_word(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
143 timestamp = stream_read_dword(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
144
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
145 stream_skip(demuxer->stream, 1); /* reserved */
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
146 flags = stream_read_char(demuxer->stream);
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
147 /* flags: */
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
148 /* 0x2 - keyframe */
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
149
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
150 printf("packet#%d: len: %d, stream_id: %d, timestamp: %d, flags: %x\n",
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
151 priv->num_of_packets, len, stream_id, timestamp, flags);
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
152
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
153 priv->num_of_packets--;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
154 len -= 12;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
155
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
156 /* check if stream_id is audio stream */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
157 for (i = 0; i < priv->last_a_stream; i++)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
158 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
159 if (priv->a_streams[i] == stream_id)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
160 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
161 // printf("packet is audio (id: %d)\n", stream_id);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
162 ds = demuxer->audio; /* FIXME */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
163 break;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
164 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
165 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
166 /* check if stream_id is video stream */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
167 for (i = 0; i < priv->last_v_stream; i++)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
168 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
169 if (priv->v_streams[i] == stream_id)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
170 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
171 // printf("packet is video (id: %d)\n", stream_id);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
172 ds = demuxer->video; /* FIXME */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
173 break;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
174 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
175 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
176
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
177 /* id not found */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
178 if (ds == NULL)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
179 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
180 printf("unknown stream id (%d)\n", stream_id);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
181 stream_skip(demuxer->stream, len);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
182 goto loop;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
183 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
184
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
185 demuxer->filepos = stream_tell(demuxer->stream);
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
186 ds_read_packet(ds, demuxer->stream, len, timestamp/90000.0f,
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
187 demuxer->filepos, (flags & 0x2) ? 0x10 : 0);
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
188
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
189 return 1;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
190 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
191
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
192 void demux_open_real(demuxer_t* demuxer)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
193 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
194 real_priv_t* priv = demuxer->priv;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
195 int num_of_headers;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
196 int i;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
197
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
198 stream_skip(demuxer->stream, 4); /* header size */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
199 stream_skip(demuxer->stream, 2);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
200 stream_skip(demuxer->stream, 4);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
201 num_of_headers = stream_read_dword(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
202 // stream_skip(demuxer->stream, 4); /* number of headers */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
203
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
204 /* parse chunks */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
205 for (i = 1; i < num_of_headers; i++)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
206 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
207 int chunk, chunk_size;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
208
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
209 chunk = stream_read_dword_le(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
210 chunk_size = stream_read_dword(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
211
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
212 stream_skip(demuxer->stream, 2);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
213
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
214 if (chunk_size < 10)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
215 goto fail;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
216
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
217 printf("Chunk: %.4s (size: %d)\n",
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
218 (char *)&chunk, chunk_size);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
219
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
220 switch(chunk)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
221 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
222 case MKTAG('P', 'R', 'O', 'P'):
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
223 // printf("Properties chunk\n");
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
224 stream_skip(demuxer->stream, 4); /* max bitrate */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
225 stream_skip(demuxer->stream, 4); /* avg bitrate */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
226 stream_skip(demuxer->stream, 4); /* max packet size */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
227 stream_skip(demuxer->stream, 4); /* avg packet size */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
228 stream_skip(demuxer->stream, 4); /* nb packets */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
229 stream_skip(demuxer->stream, 4); /* duration */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
230 stream_skip(demuxer->stream, 4); /* preroll */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
231 stream_skip(demuxer->stream, 4); /* index offset */
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
232 // stream_skip(demuxer->stream, 4); /* data offset */
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
233 priv->data_chunk_offset = stream_read_dword(demuxer->stream)+10;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
234 printf("Data chunk offset: 0x%x\n", priv->data_chunk_offset);
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
235 stream_skip(demuxer->stream, 2); /* nb streams */
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
236 #if 0
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
237 stream_skip(demuxer->stream, 2); /* flags */
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
238 #else
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
239 {
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
240 int flags = stream_read_word(demuxer->stream);
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
241 printf("Flags (%x): ", flags);
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
242 if (flags & 0x1)
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
243 printf("[save allowed] ");
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
244 if (flags & 0x2)
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
245 printf("[perfect play (?)] ");
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
246 if (flags & 0x4)
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
247 printf("[live broadcast] ");
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
248 printf("\n");
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
249 }
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
250 #endif
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
251 break;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
252 case MKTAG('C', 'O', 'N', 'T'):
3788
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
253 {
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
254 char *buf;
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
255 int len;
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
256
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
257 // printf("Broadcasting informations (title, author, copyright, comment)\n");
3788
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
258
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
259 len = stream_read_word(demuxer->stream);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
260 if (len > 0)
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
261 {
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
262 buf = malloc(len+1);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
263 stream_read(demuxer->stream, buf, len);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
264 demux_info_add(demuxer, "name", buf);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
265 free(buf);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
266 }
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
267
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
268 len = stream_read_word(demuxer->stream);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
269 if (len > 0)
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
270 {
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
271 buf = malloc(len+1);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
272 stream_read(demuxer->stream, buf, len);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
273 demux_info_add(demuxer, "author", buf);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
274 free(buf);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
275 }
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
276
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
277 len = stream_read_word(demuxer->stream);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
278 if (len > 0)
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
279 {
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
280 buf = malloc(len+1);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
281 stream_read(demuxer->stream, buf, len);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
282 demux_info_add(demuxer, "copyright", buf);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
283 free(buf);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
284 }
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
285
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
286 len = stream_read_word(demuxer->stream);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
287 if (len > 0)
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
288 {
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
289 buf = malloc(len+1);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
290 stream_read(demuxer->stream, buf, len);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
291 demux_info_add(demuxer, "comment", buf);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
292 free(buf);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
293 }
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
294
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
295 // skip_str(0, demuxer); /* title */
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
296 // skip_str(0, demuxer); /* author */
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
297 // skip_str(0, demuxer); /* copyright */
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
298 // skip_str(0, demuxer); /* comment */
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
299 break;
3788
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
300 }
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
301 case MKTAG('M', 'D', 'P', 'R'):
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
302 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
303 /* new stream */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
304 int stream_id;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
305 int bitrate;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
306 int codec_data_size;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
307 int codec_pos;
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
308 int tmp;
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
309
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
310 stream_id = stream_read_word(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
311 printf("Found new stream (id: %d)\n", stream_id);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
312
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
313 stream_skip(demuxer->stream, 4); /* max bitrate */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
314 bitrate = stream_read_dword(demuxer->stream); /* bitrate */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
315 stream_skip(demuxer->stream, 4); /* max packet size */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
316 stream_skip(demuxer->stream, 4); /* avg packet size */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
317 stream_skip(demuxer->stream, 4); /* start time */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
318 stream_skip(demuxer->stream, 4); /* preroll */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
319 stream_skip(demuxer->stream, 4); /* duration */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
320
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
321 skip_str(1, demuxer); /* stream description */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
322 skip_str(1, demuxer); /* mimetype */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
323
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
324 codec_data_size = stream_read_dword(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
325 codec_pos = stream_tell(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
326
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
327 tmp = stream_read_dword(demuxer->stream);
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
328 if (tmp == MKTAG(0xfd, 'a', 'r', '.')) /* audio header */
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
329 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
330 sh_audio_t *sh = new_sh_audio(demuxer, stream_id);
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
331 char buf[128]; /* for codec name */
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
332 int frame_size;
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
333
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
334 printf("Found audio stream!\n");
3788
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
335 stream_skip(demuxer->stream, 2); /* version (4 or 5) */
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
336 stream_skip(demuxer->stream, 2);
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
337 stream_skip(demuxer->stream, 4); /* .ra4 or .ra5 */
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
338 stream_skip(demuxer->stream, 4);
3788
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
339 stream_skip(demuxer->stream, 2); /* version (4 or 5) */
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
340 stream_skip(demuxer->stream, 4); /* header size */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
341 stream_skip(demuxer->stream, 2); /* add codec info */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
342 stream_skip(demuxer->stream, 4); /* coded frame size */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
343 stream_skip(demuxer->stream, 4);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
344 stream_skip(demuxer->stream, 4);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
345 stream_skip(demuxer->stream, 4);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
346 stream_skip(demuxer->stream, 2); /* 1 */
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
347 // stream_skip(demuxer->stream, 2); /* coded frame size */
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
348 frame_size = stream_read_word(demuxer->stream);
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
349 printf("frame_size: %d\n", frame_size);
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
350 stream_skip(demuxer->stream, 4);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
351
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
352 sh->samplerate = stream_read_word(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
353 stream_skip(demuxer->stream, 4);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
354 sh->channels = stream_read_word(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
355
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
356 /* Desc #1 */
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
357 skip_str(1, demuxer);
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
358 /* Desc #2 */
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
359 get_str(1, demuxer, buf, sizeof(buf));
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
360
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
361 tmp = 1; /* supported audio codec */
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
362 switch (MKTAG(buf[0], buf[1], buf[2], buf[3]))
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
363 {
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
364 case MKTAG('a', 't', 'r', 'c'):
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
365 break;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
366 case MKTAG('d', 'n', 'e', 't'):
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
367 printf("Audio: DNET -> AC3\n");
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
368 sh->format = 0x2000;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
369 break;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
370 case MKTAG('s', 'i', 'p', 'r'):
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
371 printf("Audio: SiproLab's ACELP.net\n");
3788
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
372 sh->format = 0x130;
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
373 break;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
374 case MKTAG('c', 'o', 'o', 'k'):
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
375 printf("Audio: Real's GeneralCooker (unsupported)\n");
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
376 tmp = 0;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
377 break;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
378 default:
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
379 printf("Audio: Unknown (%s)\n", buf);
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
380 tmp = 0;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
381 sh->format = MKTAG(buf[0], buf[1], buf[2], buf[3]);
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
382 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
383
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
384 if (tmp)
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
385 {
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
386 /* Emulate WAVEFORMATEX struct: */
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
387 sh->wf = malloc(sizeof(WAVEFORMATEX));
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
388 memset(sh->wf, 0, sizeof(WAVEFORMATEX));
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
389 sh->wf->wFormatTag = sh->format;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
390 sh->wf->nChannels = sh->channels;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
391 sh->wf->wBitsPerSample = 16;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
392 sh->wf->nSamplesPerSec = sh->samplerate;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
393 sh->wf->nAvgBytesPerSec = bitrate;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
394 sh->wf->nBlockAlign = frame_size; /* 19 for acelp, pff */
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
395 sh->wf->cbSize = 0;
3788
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
396
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
397 /* insert as stream */
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
398 demuxer->audio->sh = sh;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
399 sh->ds = demuxer->audio;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
400 demuxer->audio->id = stream_id;
3788
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
401
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
402 if (priv->last_a_stream+1 < MAX_STREAMS)
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
403 {
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
404 priv->a_streams[priv->last_a_stream] = stream_id;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
405 priv->last_a_stream++;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
406 }
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
407 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
408 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
409 else
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
410 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
411 /* video header */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
412 sh_video_t *sh = new_sh_video(demuxer, stream_id);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
413
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
414 tmp = stream_read_dword_le(demuxer->stream);
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
415 printf("video: %.4s (%x)\n", (char *)&tmp, tmp);
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
416 if (tmp != MKTAG('V', 'I', 'D', 'O'))
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
417 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
418 mp_msg(MSGT_DEMUX, MSGL_ERR, "Unsupported video codec\n");
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
419 goto skip_this_chunk;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
420 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
421
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
422 sh->format = stream_read_dword_le(demuxer->stream); /* fourcc */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
423 printf("video fourcc: %.4s (%x)\n", (char *)&sh->format, sh->format);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
424
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
425 /* emulate BITMAPINFOHEADER */
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
426 sh->bih = malloc(sizeof(BITMAPINFOHEADER));
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
427 memset(sh->bih, 0, sizeof(BITMAPINFOHEADER));
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
428 sh->bih->biSize = 40;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
429 sh->disp_w = sh->bih->biWidth = stream_read_word(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
430 sh->disp_h = sh->bih->biHeight = stream_read_word(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
431 sh->bih->biPlanes = 1;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
432 sh->bih->biBitCount = 24;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
433 sh->bih->biCompression = sh->format;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
434 sh->bih->biSizeImage= sh->bih->biWidth*sh->bih->biHeight*3;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
435
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
436 sh->fps = stream_read_word(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
437 sh->frametime = 1.0f/sh->fps;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
438
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
439 stream_skip(demuxer->stream, 4);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
440 stream_skip(demuxer->stream, 2);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
441 stream_skip(demuxer->stream, 4);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
442 stream_skip(demuxer->stream, 2);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
443
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
444 /* h263 hack */
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
445 tmp = stream_read_dword(demuxer->stream);
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
446 switch (tmp)
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
447 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
448 case 0x10000000:
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
449 /* sub id: 0 */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
450 /* codec id: rv10 */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
451 break;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
452 case 0x10003000:
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
453 case 0x10003001:
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
454 /* sub id: 3 */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
455 /* codec id: rv10 */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
456 break;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
457 case 0x20001000:
3788
d554b5b33d76 improved audio codec detection
alex
parents: 3777
diff changeset
458 case 0x20100001:
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
459 /* codec id: rv20 */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
460 break;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
461 default:
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
462 /* codec id: none */
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
463 printf("unknown id: %x\n", tmp);
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
464 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
465
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
466 /* insert as stream */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
467 demuxer->video->sh = sh;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
468 sh->ds = demuxer->video;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
469 demuxer->video->id = stream_id;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
470 if (priv->last_v_stream+1 < MAX_STREAMS)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
471 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
472 priv->v_streams[priv->last_v_stream] = stream_id;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
473 priv->last_v_stream++;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
474 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
475 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
476
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
477 skip_this_chunk:
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
478 /* skip codec info */
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
479 tmp = stream_tell(demuxer->stream) - codec_pos;
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
480 stream_skip(demuxer->stream, codec_data_size - tmp);
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
481 break;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
482 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
483 case MKTAG('D', 'A', 'T', 'A'):
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
484 goto header_end;
3795
15745f11e717 fixed audio detection code and improved ;)
alex
parents: 3788
diff changeset
485 case MKTAG('I', 'N', 'D', 'X'):
3777
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
486 default:
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
487 printf("Unknown chunk: %x\n", chunk);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
488 stream_skip(demuxer->stream, chunk_size - 10);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
489 break;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
490 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
491 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
492
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
493 header_end:
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
494 priv->num_of_packets = stream_read_dword(demuxer->stream);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
495 // stream_skip(demuxer->stream, 4); /* number of packets */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
496 stream_skip(demuxer->stream, 4); /* next data header */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
497
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
498 printf("Packets in file: %d\n", priv->num_of_packets);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
499
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
500 /* disable seeking */
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
501 demuxer->seekable = 0;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
502
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
503 fail:
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
504 return;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
505 }
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
506
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
507 void demux_close_real(demuxer_t *demuxer)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
508 {
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
509 real_priv_t* priv = demuxer->priv;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
510
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
511 if (priv)
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
512 free(priv);
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
513
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
514 return;
026ccd3dc489 added real demuxer
alex
parents:
diff changeset
515 }